fune/testing/web-platform/tests/navigation-api/ordering-and-transition/navigate-cross-document-event-order.html
Nate Chapin 2b5683556c Bug 1863646 [wpt PR 43008] - Fire the navigate event earlier for cross-document traversals, a=testonly
Automatic update from web-platform-tests
Fire the navigate event earlier for cross-document traversals

This earlier timing ensures that we fire the navigate event in the old
document when a traversal is served from the bfcache, and is more consistent with non-history cross-document navigate events.

Currently, cross-document traversals fire the navigate event at the
last possible time: during commit in the renderer, the navigate event
is fired in the old document immediately before it is unloaded. The
navigate event is not allowed to cancel or intercept a cross-document
traversal, otherwise this timing would be too late. We did not
reach a firm conclusion on when to fire the navigate event for
cross-document traversals during the design of the Navigation API
(see https://github.com/WICG/navigation-api/issues/207), and this
was the latest of the options considered.

This timing has two problems:
1. Traversals served by the back forward cache don't "commit". So
   the navigate event is erroneously omitted.
2. The navigate event fires after redirects, where for other
   cross-document navigations, it fires before redirects.

This CL adds plumbing for the browser to trigger the navigate event
to fire in the renderer in the cross-document traversal case, and
moves the time of the navigate event earlier. It now fires after
the browser process has decided to allow the traversal to start
(i.e., after beforeunload has been fired in any relevant frames, and
after start throttles). In the cross-document traversal case where
the navigation is not served from bfcache, this will fire the
navigate event in parallel with the network request (which is ok
because the navigate event can't intercept or cancel the navigation,
this timing would not be permissible for other navigation types where
the navigate event has more power over the navigation). In the case
where no network request is needed (bfcache, about:blank, etc.), the
navigate event task gets sent to the renderer immediately before the
commit/activation task.

Bug: 1475907
Change-Id: I1ef7337e2d85f9cdbfc0110f9f4fe3bcd4dea75d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5011394
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Commit-Queue: Nate Chapin <japhet@chromium.org>
Reviewed-by: Charlie Reis <creis@chromium.org>
Reviewed-by: Will Harris <wfh@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1229455}

--

wpt-commits: b92c3a8c78b102518261a78e17a27b5e6f2efb8a
wpt-pr: 43008
2023-12-01 09:23:30 +00:00

33 lines
1.5 KiB
HTML

<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<iframe id="i" src="resources/notify-top-early.html"></iframe>
<script>
async_test(t => {
let events = [];
function finish() {
assert_array_equals(events, ["onnavigate", "onunload", "readystateinteractive", "domcontentloaded", "readystatecomplete", "onload", "onpageshow"]);
t.done();
};
window.onload = t.step_func(() => {
window.childStarted = () => {
i.contentWindow.navigation.onnavigatesuccess = () => events.push("onnavigatesuccess");
i.contentWindow.navigation.onnavigateerror = () => events.push("onnavigateerror");
i.contentWindow.onpageshow = () => events.push("onpageshow");
i.contentWindow.onhashchange = () => events.push("onhashchange");
i.contentWindow.onpopstate = () => events.push("onpopstate");
i.onload = t.step_func(() => {
events.push("onload");
t.step_timeout(finish, 0);
});
i.contentDocument.addEventListener("DOMContentLoaded", () => events.push("domcontentloaded"));
i.contentDocument.onreadystatechange = () => events.push("readystate" + i.contentDocument.readyState);
};
i.contentWindow.onunload = () => events.push("onunload");
i.contentWindow.navigation.onnavigate = () => events.push("onnavigate");
i.contentWindow.navigation.navigate("?1").committed.then(
() => events.push("promisefulfilled"), () => events.push("promiserejected"));
});
}, "navigate() event ordering for cross-document navigation");
</script>