From 4c07a5d51dfca4f268631a18592fb79935ddd386 Mon Sep 17 00:00:00 2001 From: Yoav Weiss Date: Tue, 5 Sep 2023 02:38:29 -0700 Subject: [PATCH] [soft navigations] Enable keyboard shortcuts as soft navigation triggers Following the discussion on issue #3 [1], this CL adds support to soft navigations triggered by keyboard shortcuts, by adding unfocused keydown events to the events that can trigger the soft navigation heuristic. [1] https://github.com/WICG/soft-navigations/issues/3 Bug: 1478772 Change-Id: Ib423a3cfc09eaf4dd9a2221b3494ab1016fa8668 --- .../keydown.tentative.html | 30 +++++++++++++++++++ .../resources/soft-navigation-helper.js | 23 +++++++++----- 2 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 soft-navigation-heuristics/keydown.tentative.html diff --git a/soft-navigation-heuristics/keydown.tentative.html b/soft-navigation-heuristics/keydown.tentative.html new file mode 100644 index 00000000000000..f7d83119f34eec --- /dev/null +++ b/soft-navigation-heuristics/keydown.tentative.html @@ -0,0 +1,30 @@ + + + + +Detect hashchange event. + + + + + + + +
+
+ First LCP! +
+
+ + + + diff --git a/soft-navigation-heuristics/resources/soft-navigation-helper.js b/soft-navigation-heuristics/resources/soft-navigation-helper.js index edc9331c26375e..f279a88e81e621 100644 --- a/soft-navigation-heuristics/resources/soft-navigation-helper.js +++ b/soft-navigation-heuristics/resources/soft-navigation-helper.js @@ -20,6 +20,7 @@ const testSoftNavigation = const testName = options.testName; const pushUrl = readValue(options.pushUrl, true); const eventType = readValue(options.eventType, "click"); + const interactionType = readValue(options.interactionType, 'click'); const expectLCP = options.validate != 'no-lcp'; promise_test(async t => { await waitInitialLCP(); @@ -30,7 +31,7 @@ const testSoftNavigation = let paint_entries_promise = waitOnPaintEntriesPromise(expectLCP && firstClick); clicked = false; - click(link); + click(link, interactionType); await new Promise(resolve => { (new PerformanceObserver(() => resolve())).observe({ @@ -128,15 +129,21 @@ const runEntryValidations = } }; -const click = link => { - if (test_driver) { - test_driver.click(link); - timestamps[counter] = {"syncPostClick": performance.now()}; - } -} +const click = + (link, interactionType = 'click') => { + if (test_driver) { + if (interactionType == 'click') { + test_driver.click(link); + } else { + test_driver.send_keys(link, 'j'); + } + timestamps[counter] = {"syncPostClick": performance.now()}; + } + } const setEvent = (t, button, pushState, addContent, pushUrl, eventType) => { - const eventObject = (eventType == "click") ? button : window; + const eventObject = + (eventType == 'click' || eventType == 'keydown') ? button : window; eventObject.addEventListener(eventType, async e => { timestamps[counter]["eventStart"] = performance.now(); // Jump through a task, to ensure task tracking is working properly.