0

Refactor focus navigation tests

There was a very common pattern in these tests:

  assert_focus_navigation_forward(elements);
  elements.reverse();
  assert_focus_navigation_backward(elements);

so I pulled this pattern out into a new function:

  assert_focus_navigation_bidirectional(elements);

Note that there are two versions of the focus-utils.js utility, and
they work differently. The WPT version uses test_driver.Actions() and
is therefore async, while the non-WPT version uses eventSender and is
therefore sync. Some of the non-WPT tests were nevertheless calling
these functions with `await` - that has been removed.

This should not introduce any functional changes in these tests.

Change-Id: I90fc6718cfd1154523e12740218948e8f5f285b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4834580
Reviewed-by: Di Zhang <dizhangg@chromium.org>
Commit-Queue: Mason Freed <masonf@chromium.org>
Auto-Submit: Mason Freed <masonf@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1192562}
This commit is contained in:
Mason Freed
2023-09-05 17:45:59 +00:00
committed by Chromium LUCI CQ
parent d8244dfdae
commit da7c45abd2
32 changed files with 64 additions and 135 deletions

@ -66,9 +66,7 @@ promise_test(async () => {
'host/i7'
];
await assert_focus_navigation_forward(elements);
elements.reverse();
await assert_focus_navigation_backward(elements);
await assert_focus_navigation_bidirectional(elements);
}, 'Default tabindex for a slot node should be 0.');
</script>

@ -64,8 +64,6 @@ promise_test(async () => {
'x-foo/l1'
];
await assert_focus_navigation_forward(elements);
elements.reverse();
await assert_focus_navigation_backward(elements);
await assert_focus_navigation_bidirectional(elements);
}, 'Focus should jump to fallback elements when a slot does not have any assigned nodes.');
</script>

@ -56,8 +56,6 @@ promise_test(async () => {
'i1'
];
await assert_focus_navigation_forward(elements);
elements.reverse();
await assert_focus_navigation_backward(elements);
await assert_focus_navigation_bidirectional(elements);
}, 'Focus controller should treat each slot as a focus scope.');
</script>

@ -44,8 +44,6 @@ promise_test(async () => {
'i1'
];
await assert_focus_navigation_forward(elements);
elements.reverse();
await assert_focus_navigation_backward(elements);
await assert_focus_navigation_bidirectional(elements);
}, 'Focus controller should treat each slot as a focus scope.');
</script>

@ -63,9 +63,7 @@ promise_test(async () => {
'sixth'
];
await assert_focus_navigation_forward(elements);
elements.reverse();
await assert_focus_navigation_backward(elements);
await assert_focus_navigation_bidirectional(elements);
}, 'Focus should cover assigned elements of an assigned slot espacially there are fallback contents.');
</script>

@ -44,8 +44,6 @@ promise_test(async () => {
'i1'
];
await assert_focus_navigation_forward(elements);
elements.reverse();
await assert_focus_navigation_backward(elements);
await assert_focus_navigation_bidirectional(elements);
}, 'Focus controller should treat each slot as a focus scope.');
</script>

@ -41,8 +41,6 @@ promise_test(async () => {
'fallback/x-foo/a2'
];
await assert_focus_navigation_forward(elements);
elements.reverse();
await assert_focus_navigation_backward(elements);
await assert_focus_navigation_bidirectional(elements);
}, 'Focus should cover assigned elements of an assigned slot, as well as elements that are directly assigned to a slot.');
</script>

@ -40,8 +40,6 @@ promise_test(async () => {
'assigned/x-foo/a2'
];
await assert_focus_navigation_forward(elements);
elements.reverse();
await assert_focus_navigation_backward(elements);
await assert_focus_navigation_bidirectional(elements);
}, 'Focus should cover assigned elements of an assigned slot, as well as elements that are directly assigned to a slot.');
</script>

@ -58,8 +58,6 @@ promise_test(async () => {
'x-foo/x-bar/k1',
];
await assert_focus_navigation_forward(elements);
elements.reverse();
await assert_focus_navigation_backward(elements);
await assert_focus_navigation_bidirectional(elements);
}, 'Slots tabindex should be considred in focus navigation.');
</script>

@ -63,9 +63,7 @@ promise_test(async () => {
'b2',
];
await assert_focus_navigation_forward(elements);
elements.reverse();
await assert_focus_navigation_backward(elements);
await assert_focus_navigation_bidirectional(elements);
}, 'Focus should cover assigned nodes of slot, especially for nested slots in slot scope.');
</script>

@ -60,8 +60,6 @@ promise_test(async () => {
'i5'
];
await assert_focus_navigation_forward(elements);
elements.reverse();
await assert_focus_navigation_backward(elements);
await assert_focus_navigation_bidirectional(elements);
}, 'Focus should cover assigned elements of an assigned slot, as well as elements that are directly assigned to a slot.');
</script>

@ -54,9 +54,7 @@ promise_test(async () => {
'input-after',
];
await assert_focus_navigation_forward(elements, false);
elements.reverse();
await assert_focus_navigation_backward(elements, false);
await assert_focus_navigation_bidirectional(elements);
}, 'Testing tab navigation order with mode open, no tabindex and delegatesFocus=false.');
promise_test(async () => {
@ -70,9 +68,7 @@ promise_test(async () => {
'input-after',
];
await assert_focus_navigation_forward(elements, false);
elements.reverse();
await assert_focus_navigation_backward(elements, false);
await assert_focus_navigation_bidirectional(elements);
}, 'Testing tab navigation order with mode open, no tabindex and delegatesFocus=true.');
promise_test(async () => {
@ -87,9 +83,7 @@ promise_test(async () => {
'input-after',
];
await assert_focus_navigation_forward(elements, false);
elements.reverse();
await assert_focus_navigation_backward(elements, false);
await assert_focus_navigation_bidirectional(elements);
}, 'Testing tab navigation order with mode open, tabindex=0 and delegatesFocus=false.');
promise_test(async () => {
@ -104,9 +98,7 @@ promise_test(async () => {
'input-after',
];
await assert_focus_navigation_forward(elements, false);
elements.reverse();
await assert_focus_navigation_backward(elements, false);
await assert_focus_navigation_bidirectional(elements);
}, 'Testing tab navigation order with mode open, tabindex=0 and delegatesFocus=true.');
promise_test(async () => {
@ -119,9 +111,7 @@ promise_test(async () => {
'input-after',
];
await assert_focus_navigation_forward(elements, false);
elements.reverse();
await assert_focus_navigation_backward(elements, false);
await assert_focus_navigation_bidirectional(elements);
}, 'Testing tab navigation order with mode open, tabindex=-1 and delegatesFocus=false.');
promise_test(async () => {
@ -135,9 +125,7 @@ promise_test(async () => {
'input-after',
];
await assert_focus_navigation_forward(elements, false);
elements.reverse();
await assert_focus_navigation_backward(elements, false);
await assert_focus_navigation_bidirectional(elements);
}, 'Testing tab navigation order with mode open, tabindex=-1 and delegatesFocus=true.');
promise_test(async () => {
@ -152,9 +140,7 @@ promise_test(async () => {
'input-after',
];
await assert_focus_navigation_forward(elements, false);
elements.reverse();
await assert_focus_navigation_backward(elements, false);
await assert_focus_navigation_bidirectional(elements);
}, 'Testing tab navigation order with mode open, tabindex=1 and delegatesFocus=false.');
promise_test(async () => {
@ -169,9 +155,7 @@ promise_test(async () => {
'input-after',
];
await assert_focus_navigation_forward(elements, false);
elements.reverse();
await assert_focus_navigation_backward(elements, false);
await assert_focus_navigation_bidirectional(elements);
}, 'Testing tab navigation order with mode open, tabindex=1 and delegatesFocus=true.');
@ -192,9 +176,7 @@ promise_test(async () => {
[inputAfter],
];
await assert_focus_navigation_forward_with_shadow_root(elements, false);
elements.reverse();
await assert_focus_navigation_backward_with_shadow_root(elements, false);
await assert_focus_navigation_bidirectional_with_shadow_root(elements, false);
}, 'Testing tab navigation order with mode closed, no tabindex and delegatesFocus=false.');
promise_test(async () => {
@ -214,9 +196,7 @@ promise_test(async () => {
[inputAfter],
];
await assert_focus_navigation_forward_with_shadow_root(elements, false);
elements.reverse();
await assert_focus_navigation_backward_with_shadow_root(elements, false);
await assert_focus_navigation_bidirectional_with_shadow_root(elements, false);
}, 'Testing tab navigation order with mode closed, no tabindex and delegatesFocus=true.');
promise_test(async () => {
@ -237,9 +217,7 @@ promise_test(async () => {
[inputAfter],
];
await assert_focus_navigation_forward_with_shadow_root(elements, false);
elements.reverse();
await assert_focus_navigation_backward_with_shadow_root(elements, false);
await assert_focus_navigation_bidirectional_with_shadow_root(elements, false);
}, 'Testing tab navigation order with mode closed, tabindex=0 and delegatesFocus=false.');
promise_test(async () => {
@ -260,9 +238,7 @@ promise_test(async () => {
[inputAfter],
];
await assert_focus_navigation_forward_with_shadow_root(elements, false);
elements.reverse();
await assert_focus_navigation_backward_with_shadow_root(elements, false);
await assert_focus_navigation_bidirectional_with_shadow_root(elements, false);
}, 'Testing tab navigation order with mode closed, tabindex=0 and delegatesFocus=true.');
promise_test(async () => {
@ -281,9 +257,7 @@ promise_test(async () => {
[inputAfter],
];
await assert_focus_navigation_forward_with_shadow_root(elements, false);
elements.reverse();
await assert_focus_navigation_backward_with_shadow_root(elements, false);
await assert_focus_navigation_bidirectional_with_shadow_root(elements, false);
}, 'Testing tab navigation order with mode closed, tabindex=-1 and delegatesFocus=false.');
promise_test(async () => {
@ -303,9 +277,7 @@ promise_test(async () => {
[inputAfter],
];
await assert_focus_navigation_forward_with_shadow_root(elements, false);
elements.reverse();
await assert_focus_navigation_backward_with_shadow_root(elements, false);
await assert_focus_navigation_bidirectional_with_shadow_root(elements, false);
}, 'Testing tab navigation order with mode closed, tabindex=-1 and delegatesFocus=true.');
promise_test(async () => {
@ -326,9 +298,7 @@ promise_test(async () => {
[inputAfter],
];
await assert_focus_navigation_forward_with_shadow_root(elements, false);
elements.reverse();
await assert_focus_navigation_backward_with_shadow_root(elements, false);
await assert_focus_navigation_bidirectional_with_shadow_root(elements, false);
}, 'Testing tab navigation order with mode closed, tabindex=1 and delegatesFocus=false.');
promise_test(async () => {
@ -349,9 +319,7 @@ promise_test(async () => {
[inputAfter],
];
await assert_focus_navigation_forward_with_shadow_root(elements, false);
elements.reverse();
await assert_focus_navigation_backward_with_shadow_root(elements, false);
await assert_focus_navigation_bidirectional_with_shadow_root(elements, false);
}, 'Testing tab navigation order with mode closed, tabindex=1 and delegatesFocus=true.');

@ -66,8 +66,6 @@ promise_test(async () => {
'x-foo/j6'
];
await assert_focus_navigation_forward(elements);
elements.reverse();
await assert_focus_navigation_backward(elements);
await assert_focus_navigation_bidirectional(elements);
}, 'Focus controller should treat slots as a focus scope.');
</script>

@ -64,9 +64,7 @@ promise_test(async () => {
'x-foo/j6'
];
await assert_focus_navigation_forward(elements);
elements.reverse();
await assert_focus_navigation_backward(elements);
await assert_focus_navigation_bidirectional(elements);
}, 'Focus controller should treat slots as a focus scope.');
promise_test(async () => {

@ -85,6 +85,12 @@ async function assert_focus_navigation_backward(elements) {
return assert_focus_navigation_elements(elements, 'backward');
}
async function assert_focus_navigation_bidirectional(elements) {
await assert_focus_navigation_forward(elements);
elements.reverse();
await assert_focus_navigation_backward(elements);
}
// If shadow root is closed, need to pass shadowRoot and element to find
// innermost active element
@ -149,3 +155,10 @@ async function assert_focus_navigation_forward_with_shadow_root(elements) {
async function assert_focus_navigation_backward_with_shadow_root(elements) {
return assert_focus_navigation_elements_with_shadow_root(elements, 'backward');
}
async function assert_focus_navigation_bidirectional_with_shadow_root(elements) {
await assert_focus_navigation_forward_with_shadow_root(elements);
elements.reverse();
await assert_focus_navigation_backward_with_shadow_root(elements);
}

@ -23,8 +23,6 @@ test(() => {
'host',
'input-after'
];
assert_focus_navigation_forward(elements);
elements.reverse();
assert_focus_navigation_backward(elements);
assert_focus_navigation_bidirectional(elements);
}, 'Focus navigation should not get stuck.');
</script>

@ -63,9 +63,7 @@
'end'
];
await assert_focus_navigation_forward(elements);
elements.reverse();
await assert_focus_navigation_backward(elements);
assert_focus_navigation_bidirectional(elements);
}, 'Should focus on scroller across shadow boundaries depending on delegatesFocus value.');
</script>

@ -74,9 +74,7 @@ promise_test(async () => {
'end',
];
await assert_focus_navigation_forward(elements);
elements.reverse();
await assert_focus_navigation_backward(elements);
assert_focus_navigation_bidirectional(elements);
}, 'Should focus on scroller depending on tabindex value.');
</script>

@ -63,9 +63,7 @@ test(() => {
'host/i7'
];
assert_focus_navigation_forward(elements);
elements.reverse();
assert_focus_navigation_backward(elements);
assert_focus_navigation_bidirectional(elements);
}, 'Default tabindex for a slot node should be 0.');
</script>

@ -61,8 +61,6 @@ test(() => {
'x-foo/l1'
];
assert_focus_navigation_forward(elements);
elements.reverse();
assert_focus_navigation_backward(elements);
assert_focus_navigation_bidirectional(elements);
}, 'Focus should jump to fallback elements when a slot does not have any assigned nodes.');
</script>

@ -53,8 +53,6 @@ test(function() {
'i1'
];
assert_focus_navigation_forward(elements);
elements.reverse();
assert_focus_navigation_backward(elements);
assert_focus_navigation_bidirectional(elements);
}, 'Focus controller should treat each slot as a focus scope.');
</script>

@ -41,8 +41,6 @@ test(function() {
'i1'
];
assert_focus_navigation_forward(elements);
elements.reverse();
assert_focus_navigation_backward(elements);
assert_focus_navigation_bidirectional(elements);
}, 'Focus controller should treat each slot as a focus scope.');
</script>

@ -60,9 +60,7 @@ test(() => {
'sixth'
];
assert_focus_navigation_forward(elements);
elements.reverse();
assert_focus_navigation_backward(elements);
assert_focus_navigation_bidirectional(elements);
}, 'Focus should cover assigned elements of an assigned slot espacially there are fallback contents.');
</script>

@ -41,8 +41,6 @@ test(function() {
'i1'
];
assert_focus_navigation_forward(elements);
elements.reverse();
assert_focus_navigation_backward(elements);
assert_focus_navigation_bidirectional(elements);
}, 'Focus controller should treat each slot as a focus scope.');
</script>

@ -38,8 +38,6 @@ test(() => {
'fallback/x-foo/a2'
];
assert_focus_navigation_forward(elements);
elements.reverse();
assert_focus_navigation_backward(elements);
assert_focus_navigation_bidirectional(elements);
}, 'Focus should cover assigned elements of an assigned slot, as well as elements that are directly assigned to a slot.');
</script>

@ -37,8 +37,6 @@ test(() => {
'assigned/x-foo/a2'
];
assert_focus_navigation_forward(elements);
elements.reverse();
assert_focus_navigation_backward(elements);
assert_focus_navigation_bidirectional(elements);
}, 'Focus should cover assigned elements of an assigned slot, as well as elements that are directly assigned to a slot.');
</script>

@ -55,8 +55,6 @@ test(() => {
'x-foo/x-bar/k1',
];
assert_focus_navigation_forward(elements);
elements.reverse();
assert_focus_navigation_backward(elements);
assert_focus_navigation_bidirectional(elements);
}, 'Slots tabindex should be considred in focus navigation.');
</script>

@ -60,9 +60,7 @@ test(() => {
'b2',
];
assert_focus_navigation_forward(elements);
elements.reverse();
assert_focus_navigation_backward(elements);
assert_focus_navigation_bidirectional(elements);
}, 'Focus should cover assigned nodes of slot, especially for nested slots in slot scope.');
</script>

@ -57,8 +57,6 @@ test(() => {
'i5'
];
assert_focus_navigation_forward(elements);
elements.reverse();
assert_focus_navigation_backward(elements);
assert_focus_navigation_bidirectional(elements);
}, 'Focus should cover assigned elements of an assigned slot, as well as elements that are directly assigned to a slot.');
</script>

@ -63,8 +63,6 @@ test(function() {
'x-foo/j6'
];
assert_focus_navigation_forward(elements);
elements.reverse();
assert_focus_navigation_backward(elements);
assert_focus_navigation_bidirectional(elements);
}, 'Focus controller should treat slots as a focus scope.');
</script>

@ -61,9 +61,7 @@ test(() => {
'x-foo/j6'
];
assert_focus_navigation_forward(elements);
elements.reverse();
assert_focus_navigation_backward(elements);
assert_focus_navigation_bidirectional(elements);
}, 'Focus controller should treat slots as a focus scope.');
test(function() {

@ -75,3 +75,9 @@ function assert_focus_navigation_backward(elements) {
for (var i = 0; i + 1 < elements.length; ++i)
assert_focus_navigation(elements[i], elements[i + 1], 'backward');
}
function assert_focus_navigation_bidirectional(elements) {
assert_focus_navigation_forward(elements);
elements.reverse();
assert_focus_navigation_backward(elements);
}