Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / js / resources / select-options-remove.js
blob61c0d7c187d1aaff07a034da7b9f4ced45b33af3
1 description("This test checks the behavior of the remove() method on the select.options object.");
3 var select1 = document.getElementById("select1");
4 var value;
6 debug("1.1 Remove (object) from empty Options");
7 value = document.createElement("DIV");
8 shouldBe("select1.options.remove(value)", "undefined");
9 shouldBe("select1.options.length", "0");
10 shouldBe("select1.selectedIndex", "-1");
11 debug("");
13 debug("1.2 Remove (string) from empty Options");
14 value = "o";
15 shouldBe("select1.options.remove(value)", "undefined");
16 shouldBe("select1.options.length", "0");
17 shouldBe("select1.selectedIndex", "-1");
18 debug("");
20 debug("1.3 Remove (float) from empty Options");
21 value = 3.14;
22 shouldBe("select1.options.remove(value)", "undefined");
23 shouldBe("select1.options.length", "0");
24 shouldBe("select1.selectedIndex", "-1");
25 debug("");
27 debug("1.4 Remove (boolean) from empty Options");
28 value = true;
29 shouldBe("select1.options.remove(value)", "undefined");
30 shouldBe("select1.options.length", "0");
31 shouldBe("select1.selectedIndex", "-1");
32 debug("");
34 debug("1.5 Remove (undefined) from empty Options");
35 value = undefined;
36 shouldBe("select1.options.remove(value)", "undefined");
37 shouldBe("select1.options.length", "0");
38 shouldBe("select1.selectedIndex", "-1");
39 debug("");
41 debug("1.6 Remove (null) from empty Options");
42 value = null;
43 shouldBe("select1.options.remove(value)", "undefined");
44 shouldBe("select1.options.length", "0");
45 shouldBe("select1.selectedIndex", "-1");
46 debug("");
48 debug("1.7 Remove (negative infinity) from empty Options");
49 value = -1/0;
50 shouldBe("select1.options.remove(value)", "undefined");
51 shouldBe("select1.options.length", "0");
52 shouldBe("select1.selectedIndex", "-1");
53 debug("");
55 debug("1.8 Remove (NaN) from empty Options");
56 value = 0/0;
57 shouldBe("select1.options.remove(value)", "undefined");
58 shouldBe("select1.options.length", "0");
59 shouldBe("select1.selectedIndex", "-1");
60 debug("");
62 debug("1.9 Remove (positive infinity) from empty Options");
63 value = 1/0;
64 shouldBe("select1.options.remove(value)", "undefined");
65 shouldBe("select1.options.length", "0");
66 shouldBe("select1.selectedIndex", "-1");
67 debug("");
69 debug("1.10 Remove no args from empty Options");
70 shouldThrow("select1.options.remove()");
71 shouldBe("select1.options.length", "0");
72 shouldBe("select1.selectedIndex", "-1");
73 debug("");
75 debug("1.11 Remove too many args from empty Options");
76 shouldBe("select1.options.remove(0, 'foo')", "undefined");
77 shouldBe("select1.options.length", "0");
78 shouldBe("select1.selectedIndex", "-1");
79 debug("");
81 debug("1.12 Remove invalid index -2 from empty Options");
82 shouldBe("select1.options.remove(-2)", "undefined");
83 shouldBe("select1.options.length", "0");
84 shouldBe("select1.selectedIndex", "-1");
85 debug("");
87 debug("1.13 Remove invalid index -1 from empty Options");
88 shouldBe("select1.options.remove(-1)", "undefined");
89 shouldBe("select1.options.length", "0");
90 shouldBe("select1.selectedIndex", "-1");
91 debug("");
93 debug("1.14 Remove index 0 from empty Options");
94 shouldBe("select1.options.remove(0)", "undefined");
95 shouldBe("select1.options.length", "0");
96 shouldBe("select1.selectedIndex", "-1");
97 debug("");
99 debug("1.15 Remove index 1 from empty Options");
100 shouldBe("select1.options.remove(1)", "undefined");
101 shouldBe("select1.options.length", "0");
102 shouldBe("select1.selectedIndex", "-1");
103 debug("");
105 debug("1.16 Detach select element");
106 shouldNotBe("select1.parentNode", "null");
107 shouldBe("select1.remove()", "undefined");
108 shouldBeNull("select1.parentNode");
109 debug("");
111 // ------------------------------------------------
113 i = 0;
114 var select2 = document.getElementById("select2");
116 debug("2.1 Remove (object) from non-empty Options");
117 value = document.createElement("DIV");
118 shouldBe("select2.options.remove(value)", "undefined");
119 shouldBe("select2.options.length", "15");
120 shouldBe("select2.selectedIndex", "13");
121 shouldBe("select2.options[0].value", "'B'");
122 debug("");
124 debug("2.2 Remove (string) from non-empty Options");
125 value = "o";
126 shouldBe("select2.options.remove(value)", "undefined");
127 shouldBe("select2.options.length", "14");
128 shouldBe("select2.selectedIndex", "12");
129 shouldBe("select2.options[0].value", "'C'");
130 debug("");
132 debug("2.3 Remove (float) from non-empty Options");
133 value = 3.14;
134 shouldBe("select2.options.remove(value)", "undefined");
135 shouldBe("select2.options.length", "13");
136 shouldBe("select2.selectedIndex", "11");
137 shouldBe("select2.options[3].value", "'G'");
138 debug("");
140 debug("2.4 Remove (boolean true) from non-empty Options");
141 value = true;
142 shouldBe("select2.options.remove(value)", "undefined");
143 shouldBe("select2.options.length", "12");
144 shouldBe("select2.selectedIndex", "10");
145 shouldBe("select2.options[1].value", "'E'");
146 debug("");
148 debug("2.5 Remove (boolean false) from non-empty Options");
149 value = false;
150 shouldBe("select2.options.remove(value)", "undefined");
151 shouldBe("select2.options.length", "11");
152 shouldBe("select2.selectedIndex", "9");
153 shouldBe("select2.options[1].value", "'G'");
154 debug("");
156 debug("2.6 Remove (undefined) from non-empty Options");
157 value = undefined;
158 shouldBe("select2.options.remove(value)", "undefined");
159 shouldBe("select2.options.length", "10");
160 shouldBe("select2.selectedIndex", "8");
161 shouldBe("select2.options[0].value", "'G'");
162 debug("");
164 debug("2.7 Remove (null) from non-empty Options");
165 value = null;
166 shouldBe("select2.options.remove(value)", "undefined");
167 shouldBe("select2.options.length", "9");
168 shouldBe("select2.selectedIndex", "7");
169 shouldBe("select2.options[0].value", "'H'");
170 debug("");
172 debug("2.8 Remove (negative infinity) from non-empty Options");
173 value = -1/0;
174 shouldBe("select2.options.remove(value)", "undefined");
175 shouldBe("select2.options.length", "8");
176 shouldBe("select2.selectedIndex", "6");
177 shouldBe("select2.options[0].value", "'I'");
178 debug("");
180 debug("2.9 Remove (NaN) from non-empty Options");
181 value = 0/0;
182 shouldBe("select2.options.remove(value)", "undefined");
183 shouldBe("select2.options.length", "7");
184 shouldBe("select2.selectedIndex", "5");
185 shouldBe("select2.options[0].value", "'J'");
186 debug("");
188 debug("2.10 Remove (positive infinity) from non-empty Options");
189 value = 1/0;
190 shouldBe("select2.options.remove(value)", "undefined");
191 shouldBe("select2.options.length", "6");
192 shouldBe("select2.selectedIndex", "4");
193 shouldBe("select2.options[0].value", "'K'");
194 debug("");
196 debug("2.11 Remove no args from non-empty Options");
197 shouldThrow("select2.options.remove()");
198 shouldBe("select2.options.length", "6");
199 shouldBe("select2.selectedIndex", "4");
200 shouldBe("select2.options[0].value", "'K'");
201 debug("");
203 debug("2.12 Remove too many args from non-empty Options");
204 shouldBe("select2.options.remove(0, 'foo')", "undefined");
205 shouldBe("select2.options.length", "5");
206 shouldBe("select2.selectedIndex", "3");
207 shouldBe("select2.options[0].value", "'L'");
208 debug("");
210 debug("2.13 Remove invalid index -2 from non-empty Options");
211 shouldBe("select2.options.remove(-2)", "undefined");
212 shouldBe("select2.options.length", "5");
213 shouldBe("select2.selectedIndex", "3");
214 shouldBe("select2.options[2].value", "'N'");
215 debug("");
217 debug("2.14 Remove invalid index -1 from non-empty Options");
218 shouldBe("select2.options.remove(-1)", "undefined");
219 shouldBe("select2.options.length", "5");
220 shouldBe("select2.selectedIndex", "3");
221 shouldBe("select2.options[3].value", "'O'");
222 debug("");
224 debug("2.15 Remove index 0 from non-empty Options");
225 shouldBe("select2.options.remove(0)", "undefined");
226 shouldBe("select2.options.length", "4");
227 shouldBe("select2.selectedIndex", "2");
228 shouldBe("select2.options[0].value", "'M'");
229 debug("");
231 debug("2.16 Remove index 1 from non-empty Options");
232 shouldBe("select2.options.remove(1)", "undefined");
233 shouldBe("select2.options.length", "3");
234 shouldBe("select2.selectedIndex", "1");
235 shouldBe("select2.options[1].value", "'O'");
236 debug("");
238 debug("2.17 Detach select element");
239 shouldNotBe("select2.parentNode", "null");
240 shouldBe("select2.remove()", "undefined");
241 shouldBeNull("select2.parentNode");
242 debug("");