2008-11-04 Anders Carlsson <andersca@apple.com>
[webkit/qt.git] / LayoutTests / fast / dom / select-selectedIndex.html
blobe5f7aec32d41d91bd13540d716ba873799767a57
1 <link rel="stylesheet" href="../js/resources/js-test-style.css">
2 <select id="test" size="3">
3 </select>
4 <div id="console"></div>
5 <script src="../js/resources/js-test-pre.js"></script>
6 <script>
7 function reset(mySelect) {
8 mySelect.length = 0;
9 mySelect.options[mySelect.length] = new Option("one", "value", true, true);
10 mySelect.options[mySelect.length] = new Option("two", "value", true, true);
13 var mySelect = document.getElementById("test");
14 reset(mySelect);
15 var i = 0;
17 debug((++i) + ") setting length to a negative length");
18 shouldThrow("mySelect.options.length = -1;");
19 shouldBe("mySelect.options.length", "2");
20 shouldBe("mySelect.selectedIndex", "1");
22 debug((++i) + ") setting length to a larger length");
23 mySelect.options.length = 5;
24 shouldBe("mySelect.options.length", "5");
25 shouldBe("mySelect.selectedIndex", "1");
27 debug((++i) + ") setting length to a smaller length");
28 mySelect.options.length = 2;
29 shouldBe("mySelect.options.length", "2");
30 shouldBe("mySelect.selectedIndex", "1");
32 mySelect.options.length = 1;
33 shouldBe("mySelect.options.length", "1");
34 shouldBe("mySelect.selectedIndex", "-1");
35 reset(mySelect);
37 debug((++i) + ") setting length to the same length");
38 mySelect.options.length = 2;
39 shouldBe("mySelect.options.length", "2");
40 shouldBe("mySelect.selectedIndex", "1");
42 debug((++i) + ") setting length to non-integer value: null");
43 mySelect.options.length = null;
44 shouldBe("mySelect.options.length", "0");
45 shouldBe("mySelect.selectedIndex", "-1");
46 reset(mySelect);
48 debug((++i) + ") setting length to non-integer value: undefined");
49 mySelect.options.length = undefined;
50 shouldBe("mySelect.options.length", "0");
51 shouldBe("mySelect.selectedIndex", "-1");
52 reset(mySelect);
54 debug((++i) + ") setting length to non-integer value: true");
55 mySelect.options.length = true;
56 shouldBe("mySelect.options.length", "1");
57 shouldBe("mySelect.selectedIndex", "-1");
58 reset(mySelect);
60 debug((++i) + ") setting length to non-integer value: false");
61 mySelect.options.length = false;
62 shouldBe("mySelect.options.length", "0");
63 shouldBe("mySelect.selectedIndex", "-1");
64 reset(mySelect);
66 debug((++i) + ") setting length to non-integer value: non-numeric string");
67 mySelect.options.length = "apple";
68 shouldBe("mySelect.options.length", "0");
69 shouldBe("mySelect.selectedIndex", "-1");
70 reset(mySelect);
72 debug((++i) + ") setting length to non-integer value: object");
73 mySelect.options.length = new Object();
74 shouldBe("mySelect.options.length", "0");
75 shouldBe("mySelect.selectedIndex", "-1");
76 reset(mySelect);
78 debug((++i) + ") setting length to non-integer value: negative infinity");
79 mySelect.options.length = -1/0;
80 shouldBe("mySelect.options.length", "0");
81 shouldBe("mySelect.selectedIndex", "-1");
82 reset(mySelect);
84 debug((++i) + ") setting length to non-integer value: NaN");
85 mySelect.options.length = 0/0;
86 shouldBe("mySelect.options.length", "0");
87 shouldBe("mySelect.selectedIndex", "-1");
88 reset(mySelect);
90 debug((++i) + ") setting length to non-integer value: positive infinity");
91 mySelect.options.length = 1/0;
92 shouldBe("mySelect.options.length", "0");
93 shouldBe("mySelect.selectedIndex", "-1");
94 reset(mySelect);
96 debug((++i) + ") setting length to non-integer value: floating point number");
97 mySelect.options.length = 2.1;
98 shouldBe("mySelect.options.length", "2");
99 shouldBe("mySelect.selectedIndex", "1");
101 debug((++i) + ") setting an element by index past the end of the current list");
102 mySelect.options[10] = new Option("ten", "value", true, true);
103 shouldBe("mySelect.options.length", "11");
104 shouldBe("mySelect.selectedIndex", "10");
106 debug((++i) + ") setting an existing element by index");
107 mySelect.options[10] = mySelect.options[10];
108 shouldBe("mySelect.options.length", "11");
109 shouldBe("mySelect.selectedIndex", "10");
111 debug((++i) + ") trying to set an element that's not an option: null");
112 mySelect.options[10] = null;
113 shouldBe("mySelect.options.length", "10");
114 shouldBe("mySelect.selectedIndex", "-1");
116 debug((++i) + ") trying to set an element that's not an option: undefined");
117 mySelect.options[10] = undefined;
118 shouldBe("mySelect.options.length", "10");
119 shouldBe("mySelect.selectedIndex", "-1");
121 debug((++i) + ") trying to set an element that's not an option: select element");
122 shouldThrow("mySelect.options[10] = mySelect;");
123 shouldBe("mySelect.options.length", "10");
124 shouldBe("mySelect.selectedIndex", "-1");
126 debug((++i) + ") trying to set a option element using an invalid index: negative infinity");
127 mySelect.options[-1/0] = document.createElement("option");
128 shouldBe("mySelect.options.length", "10");
129 shouldBe("mySelect.selectedIndex", "-1");
131 debug((++i) + ") trying to set a option element using an invalid index: NaN");
132 mySelect.options[0/0] = document.createElement("option");
133 shouldBe("mySelect.options.length", "10");
134 shouldBe("mySelect.selectedIndex", "-1");
136 debug((++i) + ") trying to set a option element using an invalid index: positive infinity");
137 mySelect.options[1/0] = document.createElement("option");
138 shouldBe("mySelect.options.length", "10");
139 shouldBe("mySelect.selectedIndex", "-1");
141 debug("");
142 var successfullyParsed = true;
143 </script>
144 <script src="../js/resources/js-test-post.js"></script>