Files
sousa-gecko/testing/web-platform/tests/navigation-api/focus-reset/basic.html
T
Andreas Farre ebed8d507e Bug 2028907 - Part 2: Re-work tests that don't work with #wait-for-all. r=dom-core,jjaschke
The issue is that when there are no intercept handlers, or the handlers
provide a result immediately by returning or resolving/rejecting. This
will mean that the reactions for committed and finished will run in the
same microtask, which is correct according to spec.

Differential Revision: https://phabricator.services.mozilla.com/D291776
2026-04-17 00:42:11 +00:00

64 lines
2.3 KiB
HTML

<!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";
test(() => {
let throwAssertionHappened = false;
navigation.addEventListener("navigate", e => {
assert_throws_js(TypeError, () => {
e.intercept({ focusReset: "invalid" });
});
throwAssertionHappened = true;
}, { once: true });
navigation.navigate("#1");
assert_true(throwAssertionHappened);
}, "Invalid values for focusReset throw");
testFocusWasNotReset(() => {
// Intentionally left blank.
}, "Does not reset the focus when no navigate handler is present");
testFocusWasReset(t => {
navigation.addEventListener("navigate", e => {
e.intercept({ handler: () => new Promise(r => t.step_timeout(r, 0)) });
}, { once: true });
}, "Resets the focus when no focusReset option is provided");
testFocusWasReset(t => {
navigation.addEventListener("navigate", e => {
e.intercept({ handler: () => new Promise(r => t.step_timeout(r, 0)) });
}, { once: true });
}, "Resets the focus when focusReset is explicitly set to undefined");
testFocusWasReset(t => {
navigation.addEventListener("navigate", e => {
e.intercept({ handler: () => new Promise(r => t.step_timeout(r, 5)) });
}, { once: true });
}, "Resets the focus when no focusReset option is provided (nontrivial fulfilled promise)");
testFocusWasReset(t => {
navigation.addEventListener("navigate", e => {
e.intercept({ handler: () => new Promise((_, r) => t.step_timeout(r, 0)) });
}, { once: true });
}, "Resets the focus when no focusReset option is provided (rejected promise)");
testFocusWasReset(t => {
navigation.addEventListener("navigate", e => {
e.intercept({ handler: () => new Promise(r => t.step_timeout(r, 0)), focusReset: "after-transition" });
}, { once: true });
}, "Resets the focus when focusReset is explicitly set to 'after-transition'");
testFocusWasNotReset(t => {
navigation.addEventListener("navigate", e => {
e.intercept({ focusReset: "manual" });
});
}, "Does not reset the focus when focusReset is set to 'manual'");
</script>