commit e55d9fb44225f3ca3f0004cbb46c73f9e638686e
parent 192e201394b463850816c8cb4d6dd3afcd4182ee
Author: Scott Haseley <shaseley@chromium.org>
Date: Fri, 3 Oct 2025 08:59:02 +0000
Bug 1991031 [wpt PR 55086] - [soft navs] Add test for Navigation API precommit handler, a=testonly
Automatic update from web-platform-tests
[soft navs] Add test for Navigation API precommit handler
The navigation API now supports asynchronous navigation commit via a
precommit handler, which adds an async hop between running the navigate
event (under a soft nav EventScope) and committing. This extra hop could
be an issue for soft nav detection, but this works because the
navigation API adds a promise .then() handler on the precommit promise,
so we get this for free with CPED (propagation through microtasks). This
CL adds a wpt test to ensure this is tracked properly by soft navs and
continues to be.
Bug: None
Change-Id: Ifac8d683f2591028e6dc7829294b8a8953f44e64
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6980731
Reviewed-by: Johannes Henkel <johannes@chromium.org>
Commit-Queue: Scott Haseley <shaseley@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1520964}
--
wpt-commits: cc114c9cec20b36f3bcbe51df597bb9fb963dac9
wpt-pr: 55086
Diffstat:
1 file changed, 51 insertions(+), 0 deletions(-)
diff --git a/testing/web-platform/tests/soft-navigation-heuristics/detection/tentative/navigation-api-precommit-handler.html b/testing/web-platform/tests/soft-navigation-heuristics/detection/tentative/navigation-api-precommit-handler.html
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<meta charset="utf-8" />
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script src="/soft-navigation-heuristics/resources/soft-navigation-test-helper.js"></script>
+
+<a href="/forward/" id="navigateLink">Click here!</button>
+<h1>Heading!</h1>
+<div id="content"></div>
+
+<script>
+ window.onload = () => {
+ if (test_driver) {
+ test_driver.click(navigateLink);
+ }
+ };
+
+ window.navigation.addEventListener('navigate', e => {
+ e.intercept({
+ async precommitHandler(controller) {
+ // Defer resolving the precommit promise to ensure the navigation is
+ // tracked from the link click through to commit, across tasks.
+ await scheduler.postTask(() => {}, {delay: 20});
+ },
+
+ async handler() {
+ const url = new URL(e.destination.url);
+ if (url.pathname == '/forward/') {
+ // Update the DOM in a separate task to ensure the soft navigation
+ // state continues to be propagated from the commit.
+ await scheduler.yield();
+ content.innerHTML = "<div>The Page Has Navigated</div>";
+ }
+ }
+ });
+ });
+
+ promise_test(async t => {
+ const softNavPromise = SoftNavigationTestHelper.getPerformanceEntries(
+ "soft-navigation", /* minNumEntries= */ 1);
+ const helper = new SoftNavigationTestHelper(t);
+ const softNavs = await helper.withTimeoutMessage(
+ softNavPromise, "Soft navigation not detected.", /*timeout=*/ 3000);
+ assert_equals(softNavs.length, 1, 'Expected exactly one soft navigation.');
+ assert_true(
+ softNavs[0].name.endsWith('/forward/'),
+ `Unexpected Soft Navigation URL. Expected URL to end with "/forward/" but got ${softNavs[0].name}`);
+ }, 'Soft Navigation Detection supports navigation API precommit handlers');
+</script>