Skip to content
Closed
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<meta name="variant" content="?no-currententrychange">
<meta name="variant" content="?currententrychange">

<script type="module">
import { Recorder, hasVariant } from "./resources/helpers.mjs";

// This test verifies that the "get a promise for waiting for all" algorithm
// (https://webidl.spec.whatwg.org/#dfn-get-a-promise-for-waiting-for-all)
// provides the correct microtask timing: navigatesuccess fires one microtask
// deeper than the handler promise reactions, not deferred to a separate task.
//
// A single-level Promise.resolve().then() microtask should fire BEFORE
// navigatesuccess, while a two-level chained microtask should fire AFTER it,
// since both navigatesuccess and the double microtask are at the same depth
// but navigatesuccess is queued first.

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));

const from = navigation.currentEntry;

const recorder = new Recorder({
skipCurrentChange: !hasVariant("currententrychange"),
finalExpectedEvent: "transition.finished fulfilled"
});

recorder.setUpNavigationAPIListeners();

navigation.addEventListener("navigate", e => {
e.intercept({ handler() { recorder.record("handler run"); } });
});

const result = navigation.navigate("#1");
recorder.setUpResultListeners(result);

Promise.resolve().then(() => recorder.record("promise microtask"));
Promise.resolve().then(() => {
Promise.resolve().then(() => recorder.record("double promise microtask"));
});

await recorder.readyToAssert;

recorder.assert([
/* event name, location.hash value, navigation.transition properties */
["navigate", "", null],
["currententrychange", "#1", { from, navigationType: "push" }],
["handler run", "#1", { from, navigationType: "push" }],
["committed fulfilled", "#1", { from, navigationType: "push" }],
["transition.committed fulfilled", "#1", { from, navigationType: "push" }],
["promise microtask", "#1", { from, navigationType: "push" }],
["navigatesuccess", "#1", { from, navigationType: "push" }],
["double promise microtask", "#1", null],
["finished fulfilled", "#1", null],
["transition.finished fulfilled", "#1", null],
]);
}, "navigatesuccess fires at the correct microtask depth relative to handler promise reactions");
</script>
Loading