Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft popstate/hashchange/load order tests #32392

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
More
  • Loading branch information
domenic committed Jan 14, 2022
commit bef868c7d56c393baf97813b7e87b2df63a47f67
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
async_test(t => {
assert_array_equals(window.eventOrder, []);

window.addEventListener("load", t.step_func(() => {
// 0 timeout is necessary because if we do pushState before load is finished firing it counts as a replacement.
window.addEventListener("load", () => t.step_timeout(() => {
assert_array_equals(window.eventOrder, ["load"]);

t.step_timeout(t.step_func_done(() => {
assert_array_equals(window.eventOrder, ["load"]);
}), 100);

history.pushState({ state: "new state" }, "");
}));
}, 0));
}, "when pushing state, after the load event");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Popstate/hashchange/load event ordering</title>

<script>
// Set these up super-early before we hit the network for the test harness, just in case.
window.eventOrder = [];
window.onhashchange = () => window.eventOrder.push("hashchange");
window.onpopstate = () => window.eventOrder.push("popstate");
window.onload = () => window.eventOrder.push("load");
</script>

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script>
async_test(t => {
assert_array_equals(window.eventOrder, []);

// 0 timeout is necessary because if we do location.hash assignment before load is finished firing it counts as a replacement.
window.addEventListener("load", () => t.step_timeout(() => {
assert_array_equals(window.eventOrder, ["load"]);

window.addEventListener("hashchange", t.step_func(() => {
assert_array_equals(window.eventOrder, ["load", "popstate", "hashchange"]);

window.addEventListener("hashchange", t.step_func_done(() => {
assert_array_equals(window.eventOrder, ["load", "popstate", "hashchange", "popstate", "hashchange"]);
}));
}), { once: true });

location.hash = "#1";
assert_array_equals(window.eventOrder, ["load", "popstate"]);
history.back();
assert_array_equals(window.eventOrder, ["load", "popstate"]);
}, 0));
}, "when traversing back, before hashchange");
</script>