Files
sousa-gecko/testing/web-platform/tests/navigation-api/precommit-handler/precommitHandler-traversal-window-stop-before-commit.html
T
Noam Rosenthal be72978a5f Bug 2045060 [wpt PR 60386] - window.stop() should be able to cancel intercepted hash navigations, a=testonly
Automatic update from web-platform-tests
`window.stop()` should be able to cancel intercepted hash navigations (#60386)

See https://github.com/whatwg/html/pull/12519
--

wpt-commits: 86f7d9f9f3656576f8c32aed865efda91e531eae
wpt-pr: 60386
2026-06-09 18:46:41 +00:00

44 lines
1.6 KiB
HTML

<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../navigation-methods/return-value/resources/helpers.js"></script>
<body>
<script>
promise_test(async t => {
// Wait for after the load event because window.stop() hangs the test harness
// if called before the load event.
await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0));
let start_length = navigation.entries().length;
let start_index = navigation.currentEntry.index;
await navigation.navigate("#1").finished;
await navigation.navigate("#2").finished;
assert_equals(navigation.entries().length, start_length + 2);
assert_equals(navigation.currentEntry.index, start_index + 2);
navigation.onnavigate = t.step_func(e => {
t.step_timeout(() => window.stop(), 0);
e.intercept({ precommitHandler: () => new Promise(r => t.step_timeout(r, 10)) });
});
let navigateerror_called = false;
navigation.onnavigateerror = t.step_func(() => {
navigateerror_called = true;
assert_equals(location.hash, "#2");
})
let navigatesuccess_called = false;
navigation.onnavigatesuccess = t.step_func(() => {
navigatesuccess_called = true;
assert_equals(location.hash, "#1");
});
await assertBothRejectDOM(t, navigation.back(), "AbortError");
assert_equals(navigation.currentEntry.index, start_index + 2);
assert_equals(location.hash, "#2");
assert_true(navigateerror_called);
}, "precommitHandler traversal is not aborted by window.stop() before commit");
</script>
</body>