blob: 4a31fd8bc4e9c752726881e203d76cdddcc57433 [file] [log] [blame]
<select multiple id="test" size="3">
</select>
<div id="console"></div>
<script src="../../../resources/js-test-pre.js"></script>
<script>
function reset(mySelect) {
mySelect.length = 0;
mySelect.options[mySelect.length] = new Option("one", "value", true, true);
mySelect.options[mySelect.length] = new Option("two", "value", true, true);
}
var mySelect = document.getElementById("test");
reset(mySelect);
var i = 0;
debug((++i) + ") setting length to a negative length");
mySelect.options.length = -1;
shouldBe("mySelect.options.length", "2");
shouldBe("mySelect.selectedIndex", "0");
debug((++i) + ") setting length to a larger length");
mySelect.options.length = 5;
shouldBe("mySelect.options.length", "5");
shouldBe("mySelect.selectedIndex", "0");
debug((++i) + ") setting length to a smaller length");
mySelect.options.length = 2;
shouldBe("mySelect.options.length", "2");
shouldBe("mySelect.selectedIndex", "0");
mySelect.options.length = 1;
shouldBe("mySelect.options.length", "1");
shouldBe("mySelect.selectedIndex", "0");
reset(mySelect);
debug((++i) + ") setting length to the same length");
mySelect.options.length = 2;
shouldBe("mySelect.options.length", "2");
shouldBe("mySelect.selectedIndex", "0");
debug((++i) + ") setting length to non-integer value: null");
mySelect.options.length = null;
shouldBe("mySelect.options.length", "0");
shouldBe("mySelect.selectedIndex", "-1");
reset(mySelect);
debug((++i) + ") setting length to non-integer value: undefined");
mySelect.options.length = undefined;
shouldBe("mySelect.options.length", "0");
shouldBe("mySelect.selectedIndex", "-1");
reset(mySelect);
debug((++i) + ") setting length to non-integer value: true");
mySelect.options.length = true;
shouldBe("mySelect.options.length", "1");
shouldBe("mySelect.selectedIndex", "0");
reset(mySelect);
debug((++i) + ") setting length to non-integer value: false");
mySelect.options.length = false;
shouldBe("mySelect.options.length", "0");
shouldBe("mySelect.selectedIndex", "-1");
reset(mySelect);
debug((++i) + ") setting length to non-integer value: non-numeric string");
mySelect.options.length = "apple";
shouldBe("mySelect.options.length", "0");
shouldBe("mySelect.selectedIndex", "-1");
reset(mySelect);
debug((++i) + ") setting length to non-integer value: object");
mySelect.options.length = new Object();
shouldBe("mySelect.options.length", "0");
shouldBe("mySelect.selectedIndex", "-1");
reset(mySelect);
debug((++i) + ") setting length to non-integer value: negative infinity");
mySelect.options.length = -1/0;
shouldBe("mySelect.options.length", "0");
shouldBe("mySelect.selectedIndex", "-1");
reset(mySelect);
debug((++i) + ") setting length to non-integer value: NaN");
mySelect.options.length = 0/0;
shouldBe("mySelect.options.length", "0");
shouldBe("mySelect.selectedIndex", "-1");
reset(mySelect);
debug((++i) + ") setting length to non-integer value: positive infinity");
mySelect.options.length = 1/0;
shouldBe("mySelect.options.length", "0");
shouldBe("mySelect.selectedIndex", "-1");
reset(mySelect);
debug((++i) + ") setting length to non-integer value: floating point number");
mySelect.options.length = 2.1;
shouldBe("mySelect.options.length", "2");
shouldBe("mySelect.selectedIndex", "0");
debug((++i) + ") setting an element by index past the end of the current list");
mySelect.options[10] = new Option("ten", "value", true, true);
shouldBe("mySelect.options.length", "11");
shouldBe("mySelect.selectedIndex", "0");
debug((++i) + ") setting an existing element by index");
mySelect.options[10] = mySelect.options[10];
shouldBe("mySelect.options.length", "11");
shouldBe("mySelect.selectedIndex", "0");
debug((++i) + ") trying to set an element that's not an option: null");
mySelect.options[10] = null;
shouldBe("mySelect.options.length", "10");
shouldBe("mySelect.selectedIndex", "0");
debug((++i) + ") trying to set an element that's not an option: undefined");
mySelect.options[10] = undefined;
shouldBe("mySelect.options.length", "10");
shouldBe("mySelect.selectedIndex", "0");
debug((++i) + ") trying to set an element that's not an option: select element");
shouldThrow("mySelect.options[10] = mySelect;");
shouldBe("mySelect.options.length", "10");
shouldBe("mySelect.selectedIndex", "0");
debug((++i) + ") trying to set a option element using an invalid index: negative infinity");
mySelect.options[-1/0] = document.createElement("option");
shouldBe("mySelect.options.length", "10");
shouldBe("mySelect.selectedIndex", "0");
debug((++i) + ") trying to set a option element using an invalid index: NaN");
mySelect.options[0/0] = document.createElement("option");
shouldBe("mySelect.options.length", "10");
shouldBe("mySelect.selectedIndex", "0");
debug((++i) + ") trying to set a option element using an invalid index: positive infinity");
mySelect.options[1/0] = document.createElement("option");
shouldBe("mySelect.options.length", "10");
shouldBe("mySelect.selectedIndex", "0");
debug("");
</script>
<script src="../../../resources/js-test-post.js"></script>