Source code
Revision control
Copy as Markdown
Other Tools
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../navigation-methods/return-value/resources/helpers.js"></script>
<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));
await navigation.navigate("#1").finished;
await navigation.navigate("#2").finished;
const index = navigation.currentEntry.index;
navigation.onnavigate = e => e.preventDefault();
await assertBothRejectDOM(t, navigation.back(), "AbortError");
assert_equals(navigation.currentEntry.index, index, "index after the canceled back()");
navigation.onnavigate = null;
await navigation.traverseTo(navigation.entries()[0].key).finished;
assert_equals(navigation.currentEntry.index, 0, "index after traverseTo()");
assert_equals(location.hash, "", "hash after traverseTo()");
}, "navigation.traverseTo() after a same-document navigation.back() is canceled by preventDefault");
</script>