Skip to content

Commit ad50add

Browse files
Fix customizable select keyboard navigation hang
This patch fixes an infinite loop when using the arrow keys to keyboard navigate backwards over an <hr> element. The bug only occurs when the select is opted into customizable select with appearance:base-select. Fixed: 412578717 Change-Id: Ib665e56ddbd4b230194f393f559df82f5b41ba7a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6484650 Commit-Queue: Joey Arhar <[email protected]> Reviewed-by: Di Zhang <[email protected]> Cr-Commit-Position: refs/heads/main@{#1451850}
1 parent 5d324f7 commit ad50add

File tree

1 file changed

+45
-5
lines changed

1 file changed

+45
-5
lines changed

html/semantics/forms/the-select-element/customizable-select/select-iterate-before-beginning.tentative.html

+45-5
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,26 @@
1212
}
1313
</style>
1414

15-
<select>
15+
<select id=s1>
1616
<button>button</button>
1717
<option class=one>one</option>
1818
<option>two</option>
1919
</select>
2020

21+
<select id=s2>
22+
<option class=one>one</option>
23+
<hr>
24+
<optgroup></optgroup>
25+
<option class=two>two</option>
26+
</select>
27+
2128
<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';
2631

32+
promise_test(async () => {
33+
const select = document.getElementById('s1');
34+
const firstOption = select.querySelector('option.one');
2735
assert_equals(getComputedStyle(select).appearance, 'base-select',
2836
'appearance:base-select must be supported in order to run this test.');
2937

@@ -38,5 +46,37 @@
3846
assert_equals(document.activeElement, firstOption,
3947
'The first option should remain focused after pressing ArrowUp.');
4048
}
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.');
4154
}, '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.');
4282
</script>

0 commit comments

Comments
 (0)