blob: 97ed346f8f717f457c589bf70d0fa39952e45021 [file] [log] [blame]
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.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(r => window.onload = () => t.step_timeout(r, 0));
location.hash = "#1";
location.hash = "#2";
location.hash = "#3";
assert_equals(appHistory.entries().length, 4);
const [entry0, entry1, entry2, entry3] = appHistory.entries();
assert_equals((new URL(entry2.url)).hash, "#2");
assert_equals((new URL(entry3.url)).hash, "#3");
let dispose2Called = false;
entry2.ondispose = t.step_func(e => {
dispose2Called = true;
assert_equals(e.constructor, Event);
assert_equals(e.bubbles, false);
assert_equals(e.cancelable, false);
assert_equals(e.composed, false);
assert_array_equals(
appHistory.entries(),
[entry0, entry1, appHistory.current],
"entries() is updated during dispose for entry 2");
assert_not_equals(appHistory.current, entry1, "current entry must be updated during dispose for entry 3");
assert_true(appHistory.canGoBack, "canGoBack is still true during dispose for entry 2");
assert_false(appHistory.canGoForward, "canGoForward is still false during beforedispose for entry 2");
assert_equals(appHistory.transition.navigationType, "push", "transition navigationType during dispose for entry 2");
assert_equals(appHistory.transition.from, entry1, "transition from during dispose for entry 2");
assert_equals(location.hash, "#fork", "location.hash is updated during dispose for entry 2");
});
entry3.addEventListener("dispose", t.step_func_done(e => {
assert_true(dispose2Called, "dispose for entry 2 must have happened before entry 3");
assert_array_equals(
appHistory.entries(),
[entry0, entry1, appHistory.current],
"entries() is updated during dispose for entry 3");
assert_not_equals(appHistory.current, entry1, "current entry must be updated during dispose for entry 3");
assert_true(appHistory.canGoBack, "canGoBack is still true during dispose for entry 3");
assert_false(appHistory.canGoForward, "canGoForward is still false during beforedispose for entry 3");
assert_equals(appHistory.transition.navigationType, "push", "transition navigationType during dispose for entry 3");
assert_equals(appHistory.transition.from, entry1, "transition from during dispose for entry 3");
assert_equals(location.hash, "#fork", "location.hash is updated during dispose for entry 3");
}));
await appHistory.goTo(entry1.key).committed;
appHistory.addEventListener("navigate", e => {
e.transitionWhile(Promise.resolve());
});
appHistory.navigate("#fork");
assert_equals(appHistory.entries().length, 3);
const [finalEntry0, finalEntry1, finalEntry2] = appHistory.entries();
assert_equals(finalEntry0, entry0);
assert_equals(finalEntry1, entry1);
assert_not_equals(finalEntry2, entry2);
assert_equals(appHistory.current, finalEntry2);
assert_equals((new URL(finalEntry2.url)).hash, "#fork");
}, "dispose events when forward-pruning same-document entries");
</script>