diff --git a/soft-navigation-heuristics/click-event-bubbles.tentative.html b/soft-navigation-heuristics/click-event-bubbles.tentative.html new file mode 100644 index 00000000000000..ee9d1e12335c8d --- /dev/null +++ b/soft-navigation-heuristics/click-event-bubbles.tentative.html @@ -0,0 +1,28 @@ + + + + + + + + + + + +
+ Click me! +
+ + + diff --git a/soft-navigation-heuristics/multiple_nested_events.tentative.html b/soft-navigation-heuristics/multiple-nested-events.tentative.html similarity index 94% rename from soft-navigation-heuristics/multiple_nested_events.tentative.html rename to soft-navigation-heuristics/multiple-nested-events.tentative.html index 196cfa06868ca9..e51841865d654a 100644 --- a/soft-navigation-heuristics/multiple_nested_events.tentative.html +++ b/soft-navigation-heuristics/multiple-nested-events.tentative.html @@ -24,7 +24,6 @@ }); testSoftNavigation({ eventPrepWork: url => { - timestamps[counter]["eventStart"] = performance.now(); addTextToDivOnMain(); history.pushState({}, '', 'foobar1.html'); // Here we're bypassing the regular test's event logic, as this test is diff --git a/soft-navigation-heuristics/navigation-api-after-transition-commit.tentative.html b/soft-navigation-heuristics/navigation-api-after-transition-commit.tentative.html index 5c7d8f4f7a4fa4..ae17db7d59f4c5 100644 --- a/soft-navigation-heuristics/navigation-api-after-transition-commit.tentative.html +++ b/soft-navigation-heuristics/navigation-api-after-transition-commit.tentative.html @@ -16,11 +16,11 @@ diff --git a/soft-navigation-heuristics/navigation-api-hash.tentative.html b/soft-navigation-heuristics/navigation-api-hash.tentative.html index a63b177a63f497..e20578ea79ed7a 100644 --- a/soft-navigation-heuristics/navigation-api-hash.tentative.html +++ b/soft-navigation-heuristics/navigation-api-hash.tentative.html @@ -16,11 +16,11 @@ diff --git a/soft-navigation-heuristics/navigation-api-preventDefault.tentative.html b/soft-navigation-heuristics/navigation-api-preventDefault.tentative.html index d6c61efb3cbc3d..b7b2a24c942030 100644 --- a/soft-navigation-heuristics/navigation-api-preventDefault.tentative.html +++ b/soft-navigation-heuristics/navigation-api-preventDefault.tentative.html @@ -19,12 +19,12 @@ testSoftNavigationNotDetected({ testName: "Aborted navigate event is not a soft navigation", eventHandler: e => { - timestamps[counter]["eventStart"] = performance.now(); e.intercept({handler: async () => { await addImageToMain(); main.appendChild(img); }}); e.preventDefault(); + timestamps[counter]["eventEnd"] = performance.now(); }, eventTarget: navigation, eventName: "navigate", diff --git a/soft-navigation-heuristics/navigation-api-rejected.tentative.html b/soft-navigation-heuristics/navigation-api-rejected.tentative.html index bcc0451d5bd802..693f876b6e188b 100644 --- a/soft-navigation-heuristics/navigation-api-rejected.tentative.html +++ b/soft-navigation-heuristics/navigation-api-rejected.tentative.html @@ -16,11 +16,11 @@ diff --git a/soft-navigation-heuristics/navigation-api-view-transition.tentative.html b/soft-navigation-heuristics/navigation-api-view-transition.tentative.html index 2755f9f9ac75b9..4d88f3d0b7d9be 100644 --- a/soft-navigation-heuristics/navigation-api-view-transition.tentative.html +++ b/soft-navigation-heuristics/navigation-api-view-transition.tentative.html @@ -23,7 +23,6 @@ await new Promise(r => step_timeout(r, 0)); const navigate_callback = e => { - timestamps[counter]["eventStart"] = performance.now(); e.intercept({ async handler() { const lcp_promise = new Promise(resolve => { @@ -41,6 +40,7 @@ await lcp_promise; } }); + timestamps[counter]["eventEnd"] = performance.now(); }; const link = document.getElementById("link"); diff --git a/soft-navigation-heuristics/navigation-api.tentative.html b/soft-navigation-heuristics/navigation-api.tentative.html index ca11f684f49908..2d61736a486127 100644 --- a/soft-navigation-heuristics/navigation-api.tentative.html +++ b/soft-navigation-heuristics/navigation-api.tentative.html @@ -16,10 +16,10 @@ diff --git a/soft-navigation-heuristics/popstate-multiple-backs.tentative.html b/soft-navigation-heuristics/popstate-multiple-backs.tentative.html index 2a12a352bffc3f..fd87f5f03e753b 100644 --- a/soft-navigation-heuristics/popstate-multiple-backs.tentative.html +++ b/soft-navigation-heuristics/popstate-multiple-backs.tentative.html @@ -39,7 +39,10 @@ return t.popped == 2; } const link = document.getElementById("link"); - link.addEventListener("click", () => history.back()); + link.addEventListener("click", () => { + history.back(); + timestamps[counter]["eventEnd"] = performance.now(); + }); testSoftNavigation({ addContent: () => { // Add the content to the main element diff --git a/soft-navigation-heuristics/popstate.tentative.html b/soft-navigation-heuristics/popstate.tentative.html index 60a5ff72292c15..f89991d76b044c 100644 --- a/soft-navigation-heuristics/popstate.tentative.html +++ b/soft-navigation-heuristics/popstate.tentative.html @@ -22,7 +22,10 @@ history.pushState({}, "", "another_one.html"); const link = document.getElementById("link"); - link.addEventListener("click", () => history.back()); + link.addEventListener("click", () => { + history.back(); + timestamps[counter]["eventEnd"] = performance.now(); + }); testSoftNavigation({ addContent: () => { // Add the content to the main element diff --git a/soft-navigation-heuristics/resources/soft-navigation-helper.js b/soft-navigation-heuristics/resources/soft-navigation-helper.js index 58ca9c22657b68..685bc21f43c034 100644 --- a/soft-navigation-heuristics/resources/soft-navigation-helper.js +++ b/soft-navigation-heuristics/resources/soft-navigation-helper.js @@ -144,10 +144,17 @@ const setEvent = (t, button, pushState, addContent, pushUrl, eventType, prepWork const eventObject = (eventType == 'click' || eventType.startsWith("key")) ? button : window; eventObject.addEventListener(eventType, async e => { + let prepWorkFailed = false; if (prepWork &&!prepWork(t)) { + prepWorkFailed = true; + } + // This is the end of the event's sync processing. + if (!timestamps[counter]["eventEnd"]) { + timestamps[counter]["eventEnd"] = performance.now(); + } + if (prepWorkFailed) { return; } - timestamps[counter]["eventStart"] = performance.now(); // Jump through a task, to ensure task tracking is working properly. await new Promise(r => t.step_timeout(r, 0)); @@ -165,9 +172,9 @@ const setEvent = (t, button, pushState, addContent, pushUrl, eventType, prepWork await new Promise(r => t.step_timeout(r, 10)); await addContent(url); - ++counter; interacted = true; + ++counter; }); }; @@ -190,7 +197,7 @@ const validateSoftNavigationEntry = async (clicks, extraValidations, assert_less_than_equal(timestamps[i]["syncPostInteraction"], entryTimestamp, "Entry timestamp is lower than the post interaction one"); assert_greater_than_equal( - timestamps[i]['eventStart'], entryTimestamp, + entryTimestamp, timestamps[i]['eventEnd'], 'Event start timestamp matches'); assert_not_equals(entry.navigationId, performance.getEntriesByType("navigation")[0].navigationId,