Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<a id="a" href="#foo"></a>
<script>
async_test(t => {
// Wait for after the load event so that the navigation doesn't get converted
// into a replace navigation.
window.onload = () => t.step_timeout(() => {
const navState = { carryOver: "carriedOver" };
navigation.updateCurrentEntry({ state: navState });
// This is a user-initiated fragment navigation with no state supplied, so
// the destination's navigation API state is carried over from the
// previous (current) entry, which had its state set above.
navigation.onnavigate = t.step_func_done(e => {
assert_equals(e.navigationType, "push");
assert_not_equals(e.destination, null);
assert_not_equals(e.destination.getState(), undefined);
assert_equals(e.destination.getState().carryOver, "carriedOver");
e.preventDefault();
});
// location.href = "#foo" works here, just as well
// Compared to navigation.navigate("#foo"), this will cause carry-over from current entry
// as spec'ed.
document.getElementById("a").click();
}, 0);
}, "navigate event destination.getState() carries over the previous entry's " +
"state on a user-initiated fragment navigation");
</script>