Skip to content

Commit

Permalink
[soft navigations] Enable keyboard shortcuts as soft navigation triggers
Browse files Browse the repository at this point in the history
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] WICG/soft-navigations#3
Bug: 1478772
Change-Id: Ib423a3cfc09eaf4dd9a2221b3494ab1016fa8668
  • Loading branch information
Yoav Weiss authored and chromium-wpt-export-bot committed Sep 5, 2023
1 parent bef6fe4 commit 4c07a5d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
30 changes: 30 additions & 0 deletions soft-navigation-heuristics/keydown.tentative.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Detect hashchange event.</title>
<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="resources/soft-navigation-helper.js"></script>
</head>
<body>
<main id=main>
<div>
First LCP!
</div>
</main>
<script>
testSoftNavigation({
addContent: () => {
addTextToDivOnMain();
},
link: document.body,
interactionType: "keydown",
eventType: "keydown",
test: "Keydown on body triggers SoftNavigationHeuristics"});
</script>
</body>
</html>

23 changes: 15 additions & 8 deletions soft-navigation-heuristics/resources/soft-navigation-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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({
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 4c07a5d

Please sign in to comment.