3 <title>SELECT pop-up page keys test
</title>
7 document
.getElementById('console').appendChild(document
.createTextNode(s
+ "\n"));
10 function sendKey(element
, key
) {
11 if (window
.testRunner
) {
12 key
= key
.substr(0,1).toLowerCase() + key
.substr(1); // lowercase 1st letter for eventSender
13 eventSender
.keyDown(key
);
15 var event
= document
.createEvent("KeyboardEvents");
16 event
.initKeyboardEvent("keydown", true, true, document
.defaultView
, key
, 0,
17 false, false, false, false, false);
18 element
.dispatchEvent(event
);
22 function sendKeyAndExpectIndex(selectId
, key
, initialIndex
, expectedIndex
) {
23 var select
= document
.getElementById(selectId
);
24 clearSelection(select
);
26 select
.selectedIndex
= initialIndex
;
27 if (select
.selectedIndex
!= initialIndex
) {
28 log("FAIL: can't set selectedIndex to " + initialIndex
+ ' (is '
29 + select
.selectedIndex
+ ')');
33 if (select
.selectedIndex
!= expectedIndex
) {
34 log('FAIL: selectedIndex should be ' + expectedIndex
+ ' (is ' +
35 select
.selectedIndex
+ ') after a ' + key
+
36 ' from index ' + initialIndex
);
42 function clearSelection(select
) {
43 for (i
= 0; i
< select
.options
.length
; i
++)
44 select
.options
[i
].selected
= false;
47 function testPageDownNoDisabledElements() {
50 passed
= sendKeyAndExpectIndex('ss', "PageDown", 0, 3) && passed
;
51 passed
= sendKeyAndExpectIndex('ss', "PageDown", 1, 4) && passed
;
52 passed
= sendKeyAndExpectIndex('ss', "PageDown", 2, 5) && passed
;
53 passed
= sendKeyAndExpectIndex('ss', "PageDown", 3, 6) && passed
;
54 passed
= sendKeyAndExpectIndex('ss', "PageDown", 4, 6) && passed
;
55 passed
= sendKeyAndExpectIndex('ss', "PageDown", 5, 6) && passed
;
56 passed
= sendKeyAndExpectIndex('ss', "PageDown", 6, 6) && passed
;
59 log('PASS: testPageDownNoDisabledElements passed');
63 function testPageUpNoDisabledElements() {
66 passed
= sendKeyAndExpectIndex('ss', "PageUp", 6, 3) && passed
;
67 passed
= sendKeyAndExpectIndex('ss', "PageUp", 5, 2) && passed
;
68 passed
= sendKeyAndExpectIndex('ss', "PageUp", 4, 1) && passed
;
69 passed
= sendKeyAndExpectIndex('ss', "PageUp", 3, 0) && passed
;
70 passed
= sendKeyAndExpectIndex('ss', "PageUp", 2, 0) && passed
;
71 passed
= sendKeyAndExpectIndex('ss', "PageUp", 1, 0) && passed
;
72 passed
= sendKeyAndExpectIndex('ss', "PageUp", 0, 0) && passed
;
75 log('PASS: testPageUpNoDisabledElements passed');
79 function testHomeNoDisabledElements() {
82 passed
= sendKeyAndExpectIndex('ss', "Home", 6, 0) && passed
;
83 passed
= sendKeyAndExpectIndex('ss', "Home", 5, 0) && passed
;
84 passed
= sendKeyAndExpectIndex('ss', "Home", 4, 0) && passed
;
85 passed
= sendKeyAndExpectIndex('ss', "Home", 3, 0) && passed
;
86 passed
= sendKeyAndExpectIndex('ss', "Home", 2, 0) && passed
;
87 passed
= sendKeyAndExpectIndex('ss', "Home", 1, 0) && passed
;
88 passed
= sendKeyAndExpectIndex('ss', "Home", 0, 0) && passed
;
91 log('PASS: testHomeNoDisabledElements passed');
95 function testEndNoDisabledElements() {
98 passed
= sendKeyAndExpectIndex('ss', "End", 6, 6) && passed
;
99 passed
= sendKeyAndExpectIndex('ss', "End", 5, 6) && passed
;
100 passed
= sendKeyAndExpectIndex('ss', "End", 4, 6) && passed
;
101 passed
= sendKeyAndExpectIndex('ss', "End", 3, 6) && passed
;
102 passed
= sendKeyAndExpectIndex('ss', "End", 2, 6) && passed
;
103 passed
= sendKeyAndExpectIndex('ss', "End", 1, 6) && passed
;
104 passed
= sendKeyAndExpectIndex('ss', "End", 0, 6) && passed
;
107 log('PASS: testEndNoDisabledElements passed');
111 function testPageDownWithDisabledElements() {
114 passed
= sendKeyAndExpectIndex('ssd', "PageDown", 1, 4) && passed
;
115 passed
= sendKeyAndExpectIndex('ssd', "PageDown", 2, 5) && passed
;
116 passed
= sendKeyAndExpectIndex('ssd', "PageDown", 4, 6) && passed
;
117 passed
= sendKeyAndExpectIndex('ssd', "PageDown", 5, 6) && passed
;
118 passed
= sendKeyAndExpectIndex('ssd', "PageDown", 6, 6) && passed
;
121 log('PASS: testPageDownWithDisabledElements passed');
125 function testPageUpWithDisabledElements() {
128 passed
= sendKeyAndExpectIndex('ssd', "PageUp", 6, 2) && passed
;
129 passed
= sendKeyAndExpectIndex('ssd', "PageUp", 5, 2) && passed
;
130 passed
= sendKeyAndExpectIndex('ssd', "PageUp", 4, 1) && passed
;
131 passed
= sendKeyAndExpectIndex('ssd', "PageUp", 2, 1) && passed
;
132 passed
= sendKeyAndExpectIndex('ssd', "PageUp", 1, 1) && passed
;
135 log('PASS: testPageUpWithDisabledElements passed');
139 function testHomeWithDisabledElements() {
142 passed
= sendKeyAndExpectIndex('ssd', "Home", 7, 1) && passed
;
143 passed
= sendKeyAndExpectIndex('ssd', "Home", 6, 1) && passed
;
144 passed
= sendKeyAndExpectIndex('ssd', "Home", 5, 1) && passed
;
145 passed
= sendKeyAndExpectIndex('ssd', "Home", 4, 1) && passed
;
146 passed
= sendKeyAndExpectIndex('ssd', "Home", 3, 1) && passed
;
147 passed
= sendKeyAndExpectIndex('ssd', "Home", 2, 1) && passed
;
148 passed
= sendKeyAndExpectIndex('ssd', "Home", 1, 1) && passed
;
149 passed
= sendKeyAndExpectIndex('ssd', "Home", 0, 1) && passed
;
152 log('PASS: testHomeWithDisabledElements passed');
156 function testEndWithDisabledElements() {
159 passed
= sendKeyAndExpectIndex('ssd', "End", 7, 6) && passed
;
160 passed
= sendKeyAndExpectIndex('ssd', "End", 6, 6) && passed
;
161 passed
= sendKeyAndExpectIndex('ssd', "End", 5, 6) && passed
;
162 passed
= sendKeyAndExpectIndex('ssd', "End", 4, 6) && passed
;
163 passed
= sendKeyAndExpectIndex('ssd', "End", 3, 6) && passed
;
164 passed
= sendKeyAndExpectIndex('ssd', "End", 2, 6) && passed
;
165 passed
= sendKeyAndExpectIndex('ssd', "End", 1, 6) && passed
;
166 passed
= sendKeyAndExpectIndex('ssd', "End", 0, 6) && passed
;
169 log('PASS: testEndWithDisabledElements passed');
176 if (window
.testRunner
)
177 testRunner
.dumpAsText();
179 passed
= testPageDownNoDisabledElements() && passed
;
180 passed
= testPageUpNoDisabledElements() && passed
;
181 passed
= testHomeNoDisabledElements() && passed
;
182 passed
= testEndNoDisabledElements() && passed
;
184 passed
= testPageDownWithDisabledElements() && passed
;
185 passed
= testPageUpWithDisabledElements() && passed
;
186 passed
= testHomeWithDisabledElements() && passed
;
187 passed
= testEndWithDisabledElements() && passed
;
190 log('\nPASS: ALL TESTS SUCCEEDED');
192 log('\nFAIL: SOME TESTS FAILED (SEE ABOVE)');
194 } catch (exception
) {
195 log('\nFAIL: Threw exception: ' + exception
);
200 <body onload=
"test()">
201 <p>This test verifies that the Home/End/PageUp/PageDown keys work correctly
202 for pop-up
<select
> elements that have focus but are not currently popped-up.
</p>
203 <p>Output below is a series of PASS or FAIL lines showing expected and actual selection indexes,
204 followed by a single PASS or FAIL for the status of the entire test.
<p>
205 <p>NOTE: This test will fail on Mac OS, on which these keys are NOT supposed to change
206 the selection of a focused pop-up.
</p>
209 <select name=
"singleselect" id=
"ss">
210 <option value=
"0">0 </option>
211 <option value=
"1">1 </option>
212 <option value=
"2">2 </option>
213 <option value=
"3">3 </option>
214 <option value=
"4">4 </option>
215 <option value=
"5">5 </option>
216 <option value=
"6">6 </option>
218 <select name=
"singleselectwithdisabled" id=
"ssd">
219 <option value=
"0" disabled=
"true">0 </option>
220 <option value=
"1">1 </option>
221 <option value=
"2">2 </option>
222 <option value=
"3" disabled=
"true">3 </option>
223 <option value=
"4">4 </option>
224 <option value=
"5">5 </option>
225 <option value=
"6">6 </option>
226 <option value=
"7" disabled =
"true">7 </option>
229 <pre id=
"console"></pre>