|
12 | 12 | }
|
13 | 13 | </style>
|
14 | 14 |
|
15 |
| -<select> |
| 15 | +<select id=s1> |
16 | 16 | <button>button</button>
|
17 | 17 | <option class=one>one</option>
|
18 | 18 | <option>two</option>
|
19 | 19 | </select>
|
20 | 20 |
|
| 21 | +<select id=s2> |
| 22 | + <option class=one>one</option> |
| 23 | + <hr> |
| 24 | + <optgroup></optgroup> |
| 25 | + <option class=two>two</option> |
| 26 | +</select> |
| 27 | + |
21 | 28 | <script>
|
22 |
| -promise_test(async () => { |
23 |
| - const select = document.querySelector('select'); |
24 |
| - const firstOption = document.querySelector('option.one'); |
25 |
| - const arrowUp = '\uE013'; |
| 29 | +const arrowUp = '\uE013'; |
| 30 | +const arrowDown = '\uE015'; |
26 | 31 |
|
| 32 | +promise_test(async () => { |
| 33 | + const select = document.getElementById('s1'); |
| 34 | + const firstOption = select.querySelector('option.one'); |
27 | 35 | assert_equals(getComputedStyle(select).appearance, 'base-select',
|
28 | 36 | 'appearance:base-select must be supported in order to run this test.');
|
29 | 37 |
|
|
38 | 46 | assert_equals(document.activeElement, firstOption,
|
39 | 47 | 'The first option should remain focused after pressing ArrowUp.');
|
40 | 48 | }
|
| 49 | + |
| 50 | + // close select for the next test |
| 51 | + await test_driver.click(select); |
| 52 | + assert_false(select.matches(':open'), |
| 53 | + 'select should be closed at the end of the test.'); |
41 | 54 | }, 'Attempting to focus the previous option while focused on the first option should not crash.');
|
| 55 | + |
| 56 | +promise_test(async () => { |
| 57 | + const select = document.getElementById('s2'); |
| 58 | + const firstOption = select.querySelector('option.one'); |
| 59 | + const secondOption = select.querySelector('option.two'); |
| 60 | + assert_equals(getComputedStyle(select).appearance, 'base-select', |
| 61 | + 'appearance:base-select must be supported in order to run this test.'); |
| 62 | + |
| 63 | + await test_driver.click(select); |
| 64 | + assert_true(select.matches(':open'), |
| 65 | + 'select should open after clicking it.'); |
| 66 | + |
| 67 | + assert_equals(document.activeElement, firstOption, |
| 68 | + 'first option should be focused after opening select.'); |
| 69 | + |
| 70 | + await test_driver.send_keys(document.activeElement, arrowDown); |
| 71 | + assert_equals(document.activeElement, secondOption, |
| 72 | + 'second option should be focused after arrow down.'); |
| 73 | + |
| 74 | + await test_driver.send_keys(document.activeElement, arrowUp); |
| 75 | + assert_equals(document.activeElement, firstOption, |
| 76 | + 'first option should be focused after arrow up.'); |
| 77 | + |
| 78 | + await test_driver.click(select); |
| 79 | + assert_false(select.matches(':open'), |
| 80 | + 'select should be closed at the end of the test.'); |
| 81 | +}, 'Keyboard navigating backwards over an <hr> and <optgroup> should not crash.'); |
42 | 82 | </script>
|
0 commit comments