Skip to content

Commit 4c07a5d

Browse files
Yoav Weisschromium-wpt-export-bot
Yoav Weiss
authored andcommitted
[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] WICG/soft-navigations#3 Bug: 1478772 Change-Id: Ib423a3cfc09eaf4dd9a2221b3494ab1016fa8668
1 parent bef6fe4 commit 4c07a5d

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Detect hashchange event.</title>
6+
<script src="/resources/testharness.js"></script>
7+
<script src="/resources/testharnessreport.js"></script>
8+
<script src="/resources/testdriver.js"></script>
9+
<script src="/resources/testdriver-vendor.js"></script>
10+
<script src="resources/soft-navigation-helper.js"></script>
11+
</head>
12+
<body>
13+
<main id=main>
14+
<div>
15+
First LCP!
16+
</div>
17+
</main>
18+
<script>
19+
testSoftNavigation({
20+
addContent: () => {
21+
addTextToDivOnMain();
22+
},
23+
link: document.body,
24+
interactionType: "keydown",
25+
eventType: "keydown",
26+
test: "Keydown on body triggers SoftNavigationHeuristics"});
27+
</script>
28+
</body>
29+
</html>
30+

soft-navigation-heuristics/resources/soft-navigation-helper.js

+15-8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const testSoftNavigation =
2020
const testName = options.testName;
2121
const pushUrl = readValue(options.pushUrl, true);
2222
const eventType = readValue(options.eventType, "click");
23+
const interactionType = readValue(options.interactionType, 'click');
2324
const expectLCP = options.validate != 'no-lcp';
2425
promise_test(async t => {
2526
await waitInitialLCP();
@@ -30,7 +31,7 @@ const testSoftNavigation =
3031
let paint_entries_promise =
3132
waitOnPaintEntriesPromise(expectLCP && firstClick);
3233
clicked = false;
33-
click(link);
34+
click(link, interactionType);
3435

3536
await new Promise(resolve => {
3637
(new PerformanceObserver(() => resolve())).observe({
@@ -128,15 +129,21 @@ const runEntryValidations =
128129
}
129130
};
130131

131-
const click = link => {
132-
if (test_driver) {
133-
test_driver.click(link);
134-
timestamps[counter] = {"syncPostClick": performance.now()};
135-
}
136-
}
132+
const click =
133+
(link, interactionType = 'click') => {
134+
if (test_driver) {
135+
if (interactionType == 'click') {
136+
test_driver.click(link);
137+
} else {
138+
test_driver.send_keys(link, 'j');
139+
}
140+
timestamps[counter] = {"syncPostClick": performance.now()};
141+
}
142+
}
137143

138144
const setEvent = (t, button, pushState, addContent, pushUrl, eventType) => {
139-
const eventObject = (eventType == "click") ? button : window;
145+
const eventObject =
146+
(eventType == 'click' || eventType == 'keydown') ? button : window;
140147
eventObject.addEventListener(eventType, async e => {
141148
timestamps[counter]["eventStart"] = performance.now();
142149
// Jump through a task, to ensure task tracking is working properly.

0 commit comments

Comments
 (0)