Skip to content

Commit

Permalink
Bug 1762023 [wpt PR 33408] - Navigation API: focusReset should reset …
Browse files Browse the repository at this point in the history
…SFNSP, a=testonly

Automatic update from web-platform-tests
Navigation API: focusReset should reset SFNSP

SFNSP = sequential focus navigation starting point.

This was noticed while writing the spec at
WICG/navigation-api#201.

Bug: 1183545
Change-Id: If13f3c12e9c6ef2dbed628a65b823754ae04cd3d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3550462
Reviewed-by: Nate Chapin <japhet@chromium.org>
Commit-Queue: Domenic Denicola <domenic@chromium.org>
Cr-Commit-Position: refs/heads/main@{#986705}

--

wpt-commits: 9ab820e5ba017bac6d8729281c983618b79b7637
wpt-pr: 33408
  • Loading branch information
domenic authored and moz-wptsync-bot committed Apr 1, 2022
1 parent 0b3a849 commit 9e7fe94
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>

<script type="module">
import { testFocusWasReset, testFocusWasNotReset } from "./resources/helpers.mjs";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>

<script type="module">
import { testFocusWasReset, testFocusWasNotReset } from "./resources/helpers.mjs";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
// clean up any navigate event listeners, e.g. by using { once: true }, between
// tests.

const TAB_KEY = "\uE004";

export function testFocusWasReset(setupFunc, description) {
promise_test(async t => {
setupFunc(t);

const button = document.body.appendChild(document.createElement("button"));
t.add_cleanup(() => { button.remove(); });
const button2 = document.body.appendChild(document.createElement("button"));
button2.tabIndex = 0;
t.add_cleanup(() => {
button.remove();
button2.remove();
});

assert_equals(document.activeElement, document.body, "Start on body");
button.focus();
Expand All @@ -20,6 +27,11 @@ export function testFocusWasReset(setupFunc, description) {

await finished.catch(() => {});
assert_equals(document.activeElement, document.body, "Focus reset after the transition");

button2.onfocus = t.unreached_func("button2 must not be focused after pressing Tab");
const focusPromise = waitForFocus(t, button);
await test_driver.send_keys(document.body, TAB_KEY);
await focusPromise;
}, description);
}

Expand All @@ -28,7 +40,12 @@ export function testFocusWasNotReset(setupFunc, description) {
setupFunc(t);

const button = document.body.appendChild(document.createElement("button"));
t.add_cleanup(() => { button.remove(); });
const button2 = document.body.appendChild(document.createElement("button"));
button2.tabIndex = 0;
t.add_cleanup(() => {
button.remove();
button2.remove();
});

assert_equals(document.activeElement, document.body, "Start on body");
button.focus();
Expand All @@ -41,5 +58,16 @@ export function testFocusWasNotReset(setupFunc, description) {

await finished.catch(() => {});
assert_equals(document.activeElement, button, "Focus stays on the button after the transition");

button.onfocus = t.unreached_func("button must not be focused after pressing Tab");
const focusPromise = waitForFocus(t, button2);
await test_driver.send_keys(document.body, TAB_KEY);
await focusPromise;
}, description);
}

function waitForFocus(t, target) {
return new Promise(resolve => {
target.addEventListener("focus", () => resolve(), { once: true });
});
}

0 comments on commit 9e7fe94

Please sign in to comment.