diff --git a/soft-navigation-heuristics/navigation-api-preventDefault.tentative.html b/soft-navigation-heuristics/navigation-api-preventDefault.tentative.html index 8fc159d28dc08e..d6c61efb3cbc3d 100644 --- a/soft-navigation-heuristics/navigation-api-preventDefault.tentative.html +++ b/soft-navigation-heuristics/navigation-api-preventDefault.tentative.html @@ -16,16 +16,19 @@ diff --git a/soft-navigation-heuristics/replacestate-null-then-push.tentative.html b/soft-navigation-heuristics/replacestate-null-then-push.tentative.html new file mode 100644 index 00000000000000..8a81c6be20237d --- /dev/null +++ b/soft-navigation-heuristics/replacestate-null-then-push.tentative.html @@ -0,0 +1,34 @@ + + + + +Detect soft navigation with replaceState that has a null URL, then + pushState with the URL. + + + + + + + +
+ Click me! +
+ + + + + diff --git a/soft-navigation-heuristics/replacestate.tentative.html b/soft-navigation-heuristics/replacestate.tentative.html new file mode 100644 index 00000000000000..42e9a718997bec --- /dev/null +++ b/soft-navigation-heuristics/replacestate.tentative.html @@ -0,0 +1,28 @@ + + + + +Detect soft navigation with replaceState. + + + + + + + +
+ Click me! +
+ + + + diff --git a/soft-navigation-heuristics/resources/soft-navigation-helper.js b/soft-navigation-heuristics/resources/soft-navigation-helper.js index 08e9fd4a5b5711..a24fe2264233a3 100644 --- a/soft-navigation-heuristics/resources/soft-navigation-helper.js +++ b/soft-navigation-heuristics/resources/soft-navigation-helper.js @@ -58,22 +58,24 @@ const testNavigationApi = (testName, navigateEventHandler, link) => { }, testName); }; -const testNavigationApiNotDetected = - (testName, navigateEventHandler, link) => { - promise_test(async t => { - const preClickLcp = await getLcpEntries(); - navigation.addEventListener('navigate', navigateEventHandler); - click(link); - await new Promise((resolve, reject) => { - (new PerformanceObserver(() => reject())).observe({ - type: 'soft-navigation' - }); - t.step_timeout(resolve, 1000); +const testSoftNavigationNotDetected = options => { + promise_test(async t => { + const preClickLcp = await getLcpEntries(); + options.eventTarget.addEventListener(options.eventName, options.eventHandler); + click(options.link); + await new Promise((resolve, reject) => { + (new PerformanceObserver(() => + reject("Soft navigation should not be triggered"))).observe({ + type: 'soft-navigation', + buffered: true }); - assert_equals( - document.softNavigations, 0, 'Soft Navigation not detected'); - }, testName); - }; + t.step_timeout(resolve, 1000); + }); + assert_equals( + document.softNavigations, 0, 'Soft Navigation not detected'); + }, options.testName); + }; + const runEntryValidations = async preClickLcp => { await doubleRaf(); validatePaintEntries('first-contentful-paint'); @@ -109,14 +111,11 @@ const setEvent = (t, button, pushState, addContent, pushUrl, eventType) => { // Jump through a task, to ensure task tracking is working properly. await new Promise(r => t.step_timeout(r, 0)); - // Fetch some content - const response = await fetch("/soft-navigation-heuristics/resources/content.json"); - const json = await response.json(); - + const url = URL + "?" + counter; if (pushState) { // Change the URL if (pushUrl) { - pushState(URL + "?" + counter); + pushState(url); } else { pushState(); } @@ -125,7 +124,7 @@ const setEvent = (t, button, pushState, addContent, pushUrl, eventType) => { // Wait 10 ms to make sure the timestamps are correct. await new Promise(r => t.step_timeout(r, 10)); - await addContent(json); + await addContent(url); ++counter; clicked = true; diff --git a/soft-navigation-heuristics/soft-navigation-no-url.tentative.html b/soft-navigation-heuristics/soft-navigation-no-url.tentative.html index d1a11111e03374..a0055c654c2049 100644 --- a/soft-navigation-heuristics/soft-navigation-no-url.tentative.html +++ b/soft-navigation-heuristics/soft-navigation-no-url.tentative.html @@ -15,14 +15,16 @@