test_bug1327129.html (10618B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=935876 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 1327129</title> 9 <script src="/tests/SimpleTest/SimpleTest.js"></script> 10 <script src="/tests/SimpleTest/EventUtils.js"></script> 11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 12 </head> 13 <body> 14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1327129">Mozilla Bug 1327129</a> 15 <p id="display"></p> 16 <div> 17 <select size="3" firstNonDisabledIndex="0"> 18 <option>1</option> 19 <option>2</option> 20 <option>3</option> 21 <option>4</option> 22 <option>5</option> 23 </select> 24 <select size="3" firstNonDisabledIndex="1"> 25 <option disabled>1</option> 26 <option>2</option> 27 <option>3</option> 28 <option>4</option> 29 <option>5</option> 30 </select> 31 <select size="3" firstNonDisabledIndex="0"> 32 <optgroup><option>1</option></optgroup> 33 <option>2</option> 34 <option>3</option> 35 <option>4</option> 36 <option>5</option> 37 </select> 38 <select size="3" firstNonDisabledIndex="1"> 39 <option disabled>1</option> 40 <optgroup><option>2</option></optgroup> 41 <option>3</option> 42 <option>4</option> 43 <option>5</option> 44 </select> 45 <select size="3" firstNonDisabledIndex="2"> 46 <option disabled>1</option> 47 <optgroup><option disabled>2</option></optgroup> 48 <option>3</option> 49 <option>4</option> 50 <option>5</option> 51 </select> 52 <select size="3" firstNonDisabledIndex="-1"> 53 <option disabled>1</option> 54 <optgroup><option disabled>2</option></optgroup> 55 <option disabled>3</option> 56 <option disabled>4</option> 57 <option disabled>5</option> 58 </select> 59 <select size="3" multiple firstNonDisabledIndex="0"> 60 <option>1</option> 61 <option>2</option> 62 <option>3</option> 63 <option>4</option> 64 <option>5</option> 65 </select> 66 <select size="3" multiple firstNonDisabledIndex="0"> 67 <option>1</option> 68 <option>2</option> 69 <option>3</option> 70 <option>4</option> 71 <option>5</option> 72 </select> 73 <select size="3" multiple firstNonDisabledIndex="0"> 74 <optgroup><option>1</option></optgroup> 75 <option>2</option> 76 <option>3</option> 77 <option>4</option> 78 <option>5</option> 79 </select> 80 <select size="3" multiple firstNonDisabledIndex="1"> 81 <option disabled>1</option> 82 <option>2</option> 83 <option>3</option> 84 <option>4</option> 85 <option>5</option> 86 </select> 87 <select size="3" multiple firstNonDisabledIndex="3"> 88 <option disabled>1</option> 89 <optgroup><option disabled>2</option></optgroup> 90 <option disabled>3</option> 91 <option>4</option> 92 <option>5</option> 93 </select> 94 <select size="3" multiple firstNonDisabledIndex="-1"> 95 <option disabled>1</option> 96 <optgroup><option disabled>2</option></optgroup> 97 <option disabled>3</option> 98 <option disabled>4</option> 99 <option disabled>5</option> 100 </select> 101 <select size="1" firstNonDisabledIndex="0"> 102 <option>1</option> 103 <option>2</option> 104 <option>3</option> 105 <option>4</option> 106 <option>5</option> 107 </select> 108 <select size="1" firstNonDisabledIndex="0"> 109 <optgroup><option>1</option></optgroup> 110 <option>2</option> 111 <option>3</option> 112 <option>4</option> 113 <option>5</option> 114 </select> 115 <select size="1" firstNonDisabledIndex="1"> 116 <optgroup disabled><option>1</option></optgroup> 117 <option>2</option> 118 <option>3</option> 119 <option>4</option> 120 <option>5</option> 121 </select> 122 <select size="1" firstNonDisabledIndex="1"> 123 <option disabled>1</option> 124 <option>2</option> 125 <option>3</option> 126 <option>4</option> 127 <option>5</option> 128 </select> 129 <select size="1" firstNonDisabledIndex="1"> 130 <option disabled>1</option> 131 <optgroup><option>2</option></optgroup> 132 <option>3</option> 133 <option>4</option> 134 <option>5</option> 135 </select> 136 <select size="1" firstNonDisabledIndex="2"> 137 <option disabled>1</option> 138 <optgroup><option disabled>2</option></optgroup> 139 <option>3</option> 140 <option>4</option> 141 <option>5</option> 142 </select> 143 <select size="1" firstNonDisabledIndex="3"> 144 <option disabled>1</option> 145 <optgroup><option disabled>2</option></optgroup> 146 <option disabled>3</option> 147 <option>4</option> 148 <option>5</option> 149 </select> 150 <select size="1" firstNonDisabledIndex="-1"> 151 <option disabled>1</option> 152 <optgroup><option disabled>2</option></optgroup> 153 <option disabled>3</option> 154 <option disabled>4</option> 155 <option disabled>5</option> 156 </select> 157 </div> 158 <pre id="test"> 159 </pre> 160 161 <script type="application/javascript"> 162 163 SimpleTest.waitForExplicitFinish(); 164 165 const kIsMac = navigator.platform.indexOf("Mac") == 0; 166 167 function runTests() 168 { 169 const all = Array.from(document.querySelectorAll('select')); 170 let i = 0; 171 all.forEach((elem) => { 172 elem.selectedIndex = -1; 173 ++i; 174 if (!elem.id) 175 elem.id = "element " + i; 176 }); 177 178 // 179 // Test DOWN key on a <select> with no selected options. 180 // 181 const listboxes = Array.from(document.querySelectorAll('select[size="3"]')); 182 listboxes.forEach((elem) => { 183 elem.focus(); 184 synthesizeKey("KEY_ArrowDown"); 185 is(""+elem.selectedIndex, 186 elem.getAttribute('firstNonDisabledIndex'), 187 elem.id + ": DOWN selected first non-disabled option"); 188 }); 189 190 const comboboxes = Array.from(document.querySelectorAll('select[size="1"]')); 191 // Mac shows the drop-down menu for DOWN, so skip this test there. 192 if (!kIsMac) { 193 comboboxes.forEach((elem) => { 194 elem.focus(); 195 synthesizeKey("KEY_ArrowDown"); 196 is(""+elem.selectedIndex, 197 elem.getAttribute('firstNonDisabledIndex'), 198 elem.id + ": DOWN selected first non-disabled option"); 199 }); 200 } 201 202 all.forEach((elem) => { 203 elem.selectedIndex = -1; 204 elem.blur(); 205 }); 206 207 // 208 // Test SHIFT+DOWN on a <select> with no selected options. 209 // 210 listboxes.forEach((elem) => { 211 elem.focus(); 212 synthesizeKey("KEY_ArrowDown", {shiftKey:true}); 213 is(""+elem.selectedIndex, 214 elem.getAttribute('firstNonDisabledIndex'), 215 elem.id + ": SHIFT+DOWN selected first non-disabled option"); 216 }); 217 218 // Mac shows the drop-down menu for SHIFT+DOWN, so skip this test there. 219 if (!kIsMac) { 220 comboboxes.forEach((elem) => { 221 elem.focus(); 222 synthesizeKey("KEY_ArrowDown", {shiftKey:true}); 223 is(""+elem.selectedIndex, 224 elem.getAttribute('firstNonDisabledIndex'), 225 elem.id + ": SHIFT+DOWN selected first non-disabled option"); 226 }); 227 } 228 229 all.forEach((elem) => { 230 elem.selectedIndex = -1; 231 elem.blur(); 232 }); 233 234 // 235 // Test CTRL+DOWN on a <select> with no selected options. 236 // 237 listboxes.forEach((elem) => { 238 elem.focus(); 239 synthesizeKey("KEY_ArrowDown", {ctrlKey:true}); 240 if (!elem.multiple) 241 is(""+elem.selectedIndex, 242 elem.getAttribute('firstNonDisabledIndex'), 243 elem.id + ": CTRL+DOWN selected first non-disabled option"); 244 else 245 is(elem.selectedIndex, -1, elem.id + ": CTRL+DOWN did NOT select first any option"); 246 }); 247 248 // Mac shows the drop-down menu for CTRL+DOWN, so skip this test there. 249 if (!kIsMac) { 250 comboboxes.forEach((elem) => { 251 elem.focus(); 252 synthesizeKey("KEY_ArrowDown", {ctrlKey:true}); 253 is(""+elem.selectedIndex, 254 elem.getAttribute('firstNonDisabledIndex'), 255 elem.id + ": CTRL+DOWN selected first non-disabled option"); 256 }); 257 } 258 259 all.forEach((elem) => { 260 elem.selectedIndex = -1; 261 elem.blur(); 262 }); 263 264 // 265 // Test SPACE on a <select> with no selected options. 266 // 267 listboxes.forEach((elem) => { 268 elem.focus(); 269 sendString(" "); 270 is(""+elem.selectedIndex, 271 elem.getAttribute('firstNonDisabledIndex'), 272 elem.id + ": SPACE selected first non-disabled option"); 273 }); 274 275 // All platforms shows the drop-down menu for SPACE so skip testing that 276 // on the comboboxes. 277 278 all.forEach((elem) => { 279 elem.selectedIndex = -1; 280 elem.blur(); 281 }); 282 283 // 284 // Test CTRL+SPACE on a <select> with no selected options. 285 // 286 listboxes.forEach((elem) => { 287 elem.focus(); 288 synthesizeKey(" ", {ctrlKey:true}); 289 is(""+elem.selectedIndex, 290 elem.getAttribute('firstNonDisabledIndex'), 291 elem.id + ": CTRL+SPACE selected first non-disabled option"); 292 }); 293 294 // non-Mac shows the drop-down menu for CTRL+SPACE, so skip this test there. 295 if (kIsMac) { 296 comboboxes.forEach((elem) => { 297 elem.focus(); 298 synthesizeKey(" ", {ctrlKey:true}); 299 is(""+elem.selectedIndex, 300 elem.getAttribute('firstNonDisabledIndex'), 301 elem.id + ": CTRL+SPACE selected first non-disabled option"); 302 }); 303 } 304 305 all.forEach((elem) => { 306 elem.selectedIndex = -1; 307 elem.blur(); 308 }); 309 310 // 311 // Test SHIFT+SPACE on a <select> with no selected options. 312 // 313 listboxes.forEach((elem) => { 314 elem.focus(); 315 synthesizeKey(" ", {shiftKey:true}); 316 is(""+elem.selectedIndex, 317 elem.getAttribute('firstNonDisabledIndex'), 318 elem.id + ": SHIFT+SPACE selected first non-disabled option"); 319 }); 320 321 // All platforms shows the drop-down menu for SHIFT+SPACE so skip testing that 322 // on the comboboxes. 323 324 all.forEach((elem) => { 325 elem.selectedIndex = -1; 326 elem.blur(); 327 }); 328 329 // 330 // Test CTRL+SHIFT+DOWN on a <select> with no selected options. 331 // 332 listboxes.forEach((elem) => { 333 elem.focus(); 334 synthesizeKey("KEY_ArrowDown", {ctrlKey:true, shiftKey:true}); 335 is(""+elem.selectedIndex, 336 elem.getAttribute('firstNonDisabledIndex'), 337 elem.id + ": CTRL+SHIFT+DOWN selected first non-disabled option"); 338 }); 339 340 // Mac shows the drop-down menu for CTRL+SHIFT+DOWN, so skip this test there. 341 if (!kIsMac) { 342 comboboxes.forEach((elem) => { 343 elem.focus(); 344 synthesizeKey("KEY_ArrowDown", {ctrlKey:true, shiftKey:true}); 345 is(""+elem.selectedIndex, 346 elem.getAttribute('firstNonDisabledIndex'), 347 elem.id + ": CTRL+SHIFT+DOWN selected first non-disabled option"); 348 }); 349 } 350 351 all.forEach((elem) => { 352 elem.selectedIndex = -1; 353 elem.blur(); 354 }); 355 356 // 357 // Test CTRL+SHIFT+SPACE on a <select> with no selected options. 358 // 359 listboxes.forEach((elem) => { 360 elem.focus(); 361 synthesizeKey(" ", {ctrlKey:true, shiftKey:true}); 362 is(""+elem.selectedIndex, 363 elem.getAttribute('firstNonDisabledIndex'), 364 elem.id + ": CTRL+SHIFT+SPACE selected first non-disabled option"); 365 }); 366 367 // non-Mac shows the drop-down menu for CTRL+SHIFT+SPACE, so skip this test there. 368 if (kIsMac) { 369 comboboxes.forEach((elem) => { 370 elem.focus(); 371 synthesizeKey(" ", {ctrlKey:true, shiftKey:true}); 372 is(""+elem.selectedIndex, 373 elem.getAttribute('firstNonDisabledIndex'), 374 elem.id + ": CTRL+SHIFT+SPACE selected first non-disabled option"); 375 }); 376 } 377 378 SimpleTest.finish(); 379 } 380 381 382 SimpleTest.waitForFocus(runTests); 383 </script> 384 </body> 385 </html>