3 <script src=
"../../resources/js-test.js"></script>
6 <p>This test verifies that the Home/End/PageUp/PageDown keys work correctly for
<select
> elements.
7 Since it requires
<CODE>eventSender.keyDown
</CODE>, it will not run solo in the web browser; it must be run with
<KBD>run-webkit-tests
</KBD>.
</p>
10 <select name=
"singleselect" id=
"ss" size=
"4" multiple=
"true">
11 <option value=
"0">0 </option>
12 <option value=
"1">1 </option>
13 <option value=
"2">2 </option>
14 <option value=
"3">3 </option>
15 <option value=
"4">4 </option>
16 <option value=
"5">5 </option>
17 <option value=
"6">6 </option>
19 <select name=
"singleselectwithdisabled" id=
"ssd" size=
"4" multiple=
"false">
20 <option value=
"0" disabled=
"true">0 </option>
21 <option value=
"1">1 </option>
22 <option value=
"2">2 </option>
23 <option value=
"3" disabled=
"true">3 </option>
24 <option value=
"4">4 </option>
25 <option value=
"5">5 </option>
26 <option value=
"6">6 </option>
27 <option value=
"7" disabled =
"true">7 </option>
29 <select name=
"singleselectwithgroup" id=
"ssg" size=
"4" multiple=
"false">
30 <optgroup label=
"gp0">
31 <option value=
"0">0 </option>
32 <option value=
"1">1 </option>
33 <option value=
"2">2 </option>
35 <optgroup label=
"gp1">
36 <option value=
"3">3 </option>
38 <option value=
"4">4 </option>
39 <optgroup label=
"gp2">
40 <option value=
"5">5 </option>
42 <option value=
"6">6 </option>
46 <p id=
"description"></p>
47 <div id=
"console"></div>
52 function log(message
) {
53 document
.getElementById('log').appendChild(document
.createTextNode(message
+ "\n"));
56 function sendKeyAndExpectIndex(selectId
, key
, initialIndex
, expectedIndex
) {
57 var select
= document
.getElementById(selectId
);
58 clearSelection(select
);
60 select
.selectedIndex
= initialIndex
;
61 if (select
.selectedIndex
!= initialIndex
) {
62 log("can't set selectedIndex to " + initialIndex
+ ' (is ' + select
.selectedIndex
+ ')');
65 if (window
.testRunner
)
66 eventSender
.keyDown(key
);
67 if (select
.selectedIndex
!= expectedIndex
) {
68 log('selectedIndex should be ' + expectedIndex
+ ' (is ' + select
.selectedIndex
+ ') after a ' + key
+ ' from index ' + initialIndex
);
74 function equalArrays(a1
, a2
) {
75 if (a1
.length
!= a2
.length
)
77 for (i
= 0; i
< a1
.length
; i
++) {
84 function dumpArray(a
) {
86 for (i
= 0; i
< a
.length
; i
++) {
94 function getSelectedIndices(select
) {
96 for (i
= 0; i
< select
.options
.length
; i
++)
97 if (select
.options
[i
].selected
)
102 function clearSelection(select
) {
103 for (i
= 0; i
< select
.options
.length
; i
++)
104 select
.options
[i
].selected
= false;
107 // expectedIndices should be in sorted order
108 function sendWithShiftKeyAndExpectIndices(selectId
, key
, expectedIndices
) {
109 var select
= document
.getElementById(selectId
);
111 if (window
.testRunner
)
112 eventSender
.keyDown(key
, ["shiftKey"]);
113 nowSelected
= getSelectedIndices(select
);
114 if (!equalArrays(nowSelected
, expectedIndices
)) {
115 log('selected indices should be ' + dumpArray(expectedIndices
) + ' (is ' +
116 dumpArray(nowSelected
) + ') after a ' + key
);
122 function testPageDownNoDisabledElements() {
123 shouldBe('sendKeyAndExpectIndex("ss", "pageDown", 0, 3)', 'true');
124 shouldBe('sendKeyAndExpectIndex("ss", "pageDown", 1, 4)', 'true');
125 shouldBe('sendKeyAndExpectIndex("ss", "pageDown", 2, 5)', 'true');
126 shouldBe('sendKeyAndExpectIndex("ss", "pageDown", 3, 6)', 'true');
127 shouldBe('sendKeyAndExpectIndex("ss", "pageDown", 4, 6)', 'true');
128 shouldBe('sendKeyAndExpectIndex("ss", "pageDown", 5, 6)', 'true');
129 shouldBe('sendKeyAndExpectIndex("ss", "pageDown", 6, 6)', 'true');
132 function testPageUpNoDisabledElements() {
133 shouldBe('sendKeyAndExpectIndex("ss", "pageUp", 6, 3)', 'true');
134 shouldBe('sendKeyAndExpectIndex("ss", "pageUp", 5, 2)', 'true');
135 shouldBe('sendKeyAndExpectIndex("ss", "pageUp", 4, 1)', 'true');
136 shouldBe('sendKeyAndExpectIndex("ss", "pageUp", 3, 0)', 'true');
137 shouldBe('sendKeyAndExpectIndex("ss", "pageUp", 2, 0)', 'true');
138 shouldBe('sendKeyAndExpectIndex("ss", "pageUp", 1, 0)', 'true');
139 shouldBe('sendKeyAndExpectIndex("ss", "pageUp", 0, 0)', 'true');
142 function testHomeNoDisabledElements() {
143 shouldBe('sendKeyAndExpectIndex("ss", "home", 6, 0)', 'true');
144 shouldBe('sendKeyAndExpectIndex("ss", "home", 5, 0)', 'true');
145 shouldBe('sendKeyAndExpectIndex("ss", "home", 4, 0)', 'true');
146 shouldBe('sendKeyAndExpectIndex("ss", "home", 3, 0)', 'true');
147 shouldBe('sendKeyAndExpectIndex("ss", "home", 2, 0)', 'true');
148 shouldBe('sendKeyAndExpectIndex("ss", "home", 1, 0)', 'true');
149 shouldBe('sendKeyAndExpectIndex("ss", "home", 0, 0)', 'true');
152 function testEndNoDisabledElements() {
153 shouldBe('sendKeyAndExpectIndex("ss", "end", 6, 6)', 'true');
154 shouldBe('sendKeyAndExpectIndex("ss", "end", 5, 6)', 'true');
155 shouldBe('sendKeyAndExpectIndex("ss", "end", 4, 6)', 'true');
156 shouldBe('sendKeyAndExpectIndex("ss", "end", 3, 6)', 'true');
157 shouldBe('sendKeyAndExpectIndex("ss", "end", 2, 6)', 'true');
158 shouldBe('sendKeyAndExpectIndex("ss", "end", 1, 6)', 'true');
159 shouldBe('sendKeyAndExpectIndex("ss", "end", 0, 6)', 'true');
162 function testPageDownWithDisabledElements() {
163 shouldBe('sendKeyAndExpectIndex("ssd", "pageDown", 0, 4)', 'true');
164 shouldBe('sendKeyAndExpectIndex("ssd", "pageDown", 1, 4)', 'true');
165 shouldBe('sendKeyAndExpectIndex("ssd", "pageDown", 2, 5)', 'true');
166 shouldBe('sendKeyAndExpectIndex("ssd", "pageDown", 4, 6)', 'true');
167 shouldBe('sendKeyAndExpectIndex("ssd", "pageDown", 5, 6)', 'true');
168 shouldBe('sendKeyAndExpectIndex("ssd", "pageDown", 6, 6)', 'true');
169 shouldBe('sendKeyAndExpectIndex("ssd", "pageDown", 7, 6)', 'true');
172 function testPageUpWithDisabledElements() {
173 shouldBe('sendKeyAndExpectIndex("ssd", "pageUp", 7, 4)', 'true');
174 shouldBe('sendKeyAndExpectIndex("ssd", "pageUp", 6, 2)', 'true');
175 shouldBe('sendKeyAndExpectIndex("ssd", "pageUp", 5, 2)', 'true');
176 shouldBe('sendKeyAndExpectIndex("ssd", "pageUp", 4, 1)', 'true');
177 shouldBe('sendKeyAndExpectIndex("ssd", "pageUp", 2, 1)', 'true');
178 shouldBe('sendKeyAndExpectIndex("ssd", "pageUp", 1, 1)', 'true');
179 shouldBe('sendKeyAndExpectIndex("ssd", "pageUp", 0, 1)', 'true');
182 function testHomeWithDisabledElements() {
183 shouldBe('sendKeyAndExpectIndex("ssd", "home", 7, 1)', 'true');
184 shouldBe('sendKeyAndExpectIndex("ssd", "home", 6, 1)', 'true');
185 shouldBe('sendKeyAndExpectIndex("ssd", "home", 5, 1)', 'true');
186 shouldBe('sendKeyAndExpectIndex("ssd", "home", 4, 1)', 'true');
187 shouldBe('sendKeyAndExpectIndex("ssd", "home", 3, 1)', 'true');
188 shouldBe('sendKeyAndExpectIndex("ssd", "home", 2, 1)', 'true');
189 shouldBe('sendKeyAndExpectIndex("ssd", "home", 1, 1)', 'true');
190 shouldBe('sendKeyAndExpectIndex("ssd", "home", 0, 1)', 'true');
193 function testEndWithDisabledElements() {
194 shouldBe('sendKeyAndExpectIndex("ssd", "end", 7, 6)', 'true');
195 shouldBe('sendKeyAndExpectIndex("ssd", "end", 6, 6)', 'true');
196 shouldBe('sendKeyAndExpectIndex("ssd", "end", 5, 6)', 'true');
197 shouldBe('sendKeyAndExpectIndex("ssd", "end", 4, 6)', 'true');
198 shouldBe('sendKeyAndExpectIndex("ssd", "end", 3, 6)', 'true');
199 shouldBe('sendKeyAndExpectIndex("ssd", "end", 2, 6)', 'true');
200 shouldBe('sendKeyAndExpectIndex("ssd", "end", 1, 6)', 'true');
201 shouldBe('sendKeyAndExpectIndex("ssd", "end", 0, 6)', 'true');
204 function testVariousShiftKeysNoDisabledElements() {
205 var select
= document
.getElementById("ss");
207 clearSelection(select
);
208 select
.selectedIndex
= 0;
210 shouldBe('sendWithShiftKeyAndExpectIndices("ss", "pageDown", [0, 1, 2, 3])', 'true');
211 shouldBe('sendWithShiftKeyAndExpectIndices("ss", "pageDown", [0, 1, 2, 3, 4, 5, 6])', 'true');
212 shouldBe('sendWithShiftKeyAndExpectIndices("ss", "pageDown", [0, 1, 2, 3, 4, 5, 6])', 'true');
213 shouldBe('sendWithShiftKeyAndExpectIndices("ss", "pageUp", [0, 1, 2, 3])', 'true');
214 shouldBe('sendWithShiftKeyAndExpectIndices("ss", "pageUp", [0])', 'true');
215 shouldBe('sendWithShiftKeyAndExpectIndices("ss", "pageUp", [0])', 'true');
216 shouldBe('sendWithShiftKeyAndExpectIndices("ss", "end", [0, 1, 2, 3, 4, 5, 6])', 'true');
217 shouldBe('sendWithShiftKeyAndExpectIndices("ss", "end", [0, 1, 2, 3, 4, 5, 6])', 'true');
218 shouldBe('sendWithShiftKeyAndExpectIndices("ss", "home", [0])', 'true');
219 shouldBe('sendWithShiftKeyAndExpectIndices("ss", "home", [0])', 'true');
221 clearSelection(select
);
222 select
.selectedIndex
= 3;
223 shouldBe('sendWithShiftKeyAndExpectIndices("ss", "pageDown", [3, 4, 5, 6])', 'true');
224 shouldBe('sendWithShiftKeyAndExpectIndices("ss", "pageDown", [3, 4, 5, 6])', 'true');
225 shouldBe('sendWithShiftKeyAndExpectIndices("ss", "pageUp", [3])', 'true');
226 shouldBe('sendWithShiftKeyAndExpectIndices("ss", "pageUp", [0, 1, 2, 3])', 'true');
227 shouldBe('sendWithShiftKeyAndExpectIndices("ss", "pageUp", [0, 1, 2, 3])', 'true');
228 shouldBe('sendWithShiftKeyAndExpectIndices("ss", "pageUp", [0, 1, 2, 3])', 'true');
229 shouldBe('sendWithShiftKeyAndExpectIndices("ss", "end", [3, 4, 5, 6])', 'true');
230 shouldBe('sendWithShiftKeyAndExpectIndices("ss", "end", [3, 4, 5, 6])', 'true');
231 shouldBe('sendWithShiftKeyAndExpectIndices("ss", "home", [0, 1, 2, 3])', 'true');
232 shouldBe('sendWithShiftKeyAndExpectIndices("ss", "home", [0, 1, 2, 3])', 'true');
235 function testVariousShiftKeysWithDisabledElements() {
236 var select
= document
.getElementById('ssd');
238 clearSelection(select
);
239 select
.selectedIndex
= 1;
241 shouldBe('sendWithShiftKeyAndExpectIndices("ssd", "pageDown", [1, 2, 4])', 'true');
242 shouldBe('sendWithShiftKeyAndExpectIndices("ssd", "pageDown", [1, 2, 4, 5, 6])', 'true');
243 shouldBe('sendWithShiftKeyAndExpectIndices("ssd", "pageDown", [1, 2, 4, 5, 6])', 'true');
244 shouldBe('sendWithShiftKeyAndExpectIndices("ssd", "pageUp", [1, 2])', 'true');
245 shouldBe('sendWithShiftKeyAndExpectIndices("ssd", "pageUp", [1])', 'true');
246 shouldBe('sendWithShiftKeyAndExpectIndices("ssd", "pageUp", [1])', 'true');
247 shouldBe('sendWithShiftKeyAndExpectIndices("ssd", "end", [1, 2, 4, 5, 6])', 'true');
248 shouldBe('sendWithShiftKeyAndExpectIndices("ssd", "end", [1, 2, 4, 5, 6])', 'true');
249 shouldBe('sendWithShiftKeyAndExpectIndices("ssd", "home", [1])', 'true');
250 shouldBe('sendWithShiftKeyAndExpectIndices("ssd", "home", [1])', 'true');
252 clearSelection(select
);
253 select
.selectedIndex
= 4;
254 shouldBe('sendWithShiftKeyAndExpectIndices("ssd", "pageDown", [4, 5, 6])', 'true');
255 shouldBe('sendWithShiftKeyAndExpectIndices("ssd", "pageDown", [4, 5, 6])', 'true');
256 shouldBe('sendWithShiftKeyAndExpectIndices("ssd", "pageUp", [2, 4])', 'true');
257 shouldBe('sendWithShiftKeyAndExpectIndices("ssd", "pageUp", [1, 2, 4])', 'true');
258 shouldBe('sendWithShiftKeyAndExpectIndices("ssd", "pageUp", [1, 2, 4])', 'true');
259 shouldBe('sendWithShiftKeyAndExpectIndices("ssd", "end", [4, 5, 6])', 'true');
260 shouldBe('sendWithShiftKeyAndExpectIndices("ssd", "end", [4, 5, 6])', 'true');
261 shouldBe('sendWithShiftKeyAndExpectIndices("ssd", "home", [1, 2, 4])', 'true');
262 shouldBe('sendWithShiftKeyAndExpectIndices("ssd", "home", [1, 2, 4])', 'true');
265 function testPageDownWithGroup() {
266 shouldBe('sendKeyAndExpectIndex("ssg", "pageDown", 0, 3)', 'true');
267 shouldBe('sendKeyAndExpectIndex("ssg", "pageDown", 1, 3)', 'true');
268 shouldBe('sendKeyAndExpectIndex("ssg", "pageDown", 2, 4)', 'true');
269 shouldBe('sendKeyAndExpectIndex("ssg", "pageDown", 3, 5)', 'true');
270 shouldBe('sendKeyAndExpectIndex("ssg", "pageDown", 4, 6)', 'true');
271 shouldBe('sendKeyAndExpectIndex("ssg", "pageDown", 5, 6)', 'true');
272 shouldBe('sendKeyAndExpectIndex("ssg", "pageDown", 6, 6)', 'true');
275 function testPageUpWithGroup() {
276 shouldBe('sendKeyAndExpectIndex("ssg", "pageUp", 6, 4)', 'true');
277 shouldBe('sendKeyAndExpectIndex("ssg", "pageUp", 5, 3)', 'true');
278 shouldBe('sendKeyAndExpectIndex("ssg", "pageUp", 4, 2)', 'true');
279 shouldBe('sendKeyAndExpectIndex("ssg", "pageUp", 3, 1)', 'true');
280 shouldBe('sendKeyAndExpectIndex("ssg", "pageUp", 2, 0)', 'true');
281 shouldBe('sendKeyAndExpectIndex("ssg", "pageUp", 1, 0)', 'true');
282 shouldBe('sendKeyAndExpectIndex("ssg", "pageUp", 0, 0)', 'true');
285 testPageDownNoDisabledElements();
286 testPageUpNoDisabledElements();
287 testHomeNoDisabledElements();
288 testEndNoDisabledElements();
289 testPageDownWithDisabledElements();
290 testPageUpWithDisabledElements();
291 testHomeWithDisabledElements();
292 testEndWithDisabledElements();
293 testVariousShiftKeysNoDisabledElements();
294 testVariousShiftKeysWithDisabledElements();
295 testPageDownWithGroup();
296 testPageUpWithGroup();