Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 1 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /navigation-api/precommit-handler/precommitHandler-redirect-replace.html - WPT Dashboard Interop Dashboard
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
promise_test(async t => {
// Wait for after the load event so that the navigation doesn't get converted
// into a replace navigation.
await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0));
let start_length = navigation.entries().length;
let start_hash = location.hash;
navigation.onnavigate = t.step_func(e => {
e.intercept({
precommitHandler: t.step_func(controller => {
assert_equals(location.hash, start_hash);
assert_equals(new URL(e.destination.url).hash, "#replace");
controller.redirect("#redirect1");
assert_equals(location.hash, start_hash);
assert_equals(new URL(e.destination.url).hash, "#redirect1");
controller.redirect("#redirect2");
assert_equals(location.hash, start_hash);
assert_equals(new URL(e.destination.url).hash, "#redirect2");
}),
});
});
await navigation.navigate("#replace", { history: "replace" }).committed;
assert_equals(location.hash, "#redirect2");
assert_equals(navigation.entries().length, start_length);
}, "precommitHandler redirect() replace");
</script>
</body>