Skip to content

Commit c167edf

Browse files
powdercloudlutien
authored andcommitted
Bug 1966172 [wpt PR 52499] - [soft navs] Add smoke test for almost soft navigations.,
Automatic update from web-platform-tests [soft navs] Add smoke test for almost soft navigations. These are situations that come very close to a soft navigation, but fail satisfying one of the criteria - e.g., that the DOM nodes created must be attached to the DOM. The test ensures that in these cases, we don't detect a soft nav. Bug: 416748595 Change-Id: I1a81bf06bb04b1829f8d6c37753d97bb89e308d7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6532369 Commit-Queue: Johannes Henkel <[email protected]> Reviewed-by: Michal Mocny <[email protected]> Reviewed-by: Scott Haseley <[email protected]> Cr-Commit-Position: refs/heads/main@{#1459511} -- wpt-commits: 5c990c46cc35e10c2c7d379d6395c108c238c6c3 wpt-pr: 52499 Differential Revision: https://phabricator.services.mozilla.com/D250148
1 parent 87f2a89 commit c167edf

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>No Detection of Almost Soft Navigations.</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>
11+
// This click handler *does* cause a soft navigation, and *each test
12+
// ends with detecting it*. This is by design a very simple soft
13+
// navigation which we reliably detect - the same as in basic.html.
14+
function actualSoftNavigation() {
15+
const greeting = document.createElement("div");
16+
greeting.textContent = "Hello, World.";
17+
document.body.appendChild(greeting);
18+
history.pushState({}, "", "/actual-softnavigation");
19+
}
20+
21+
// This click handler won't cause a soft navigation, because it
22+
// doesn't change the URL.
23+
function noUrlChange() {
24+
const greeting = document.createElement("div");
25+
greeting.textContent = "Hello, World.";
26+
document.body.appendChild(greeting);
27+
}
28+
29+
// This click handler won't cause a soft navigation, because the
30+
// element isn't attached to the DOM.
31+
function domNotAttached() {
32+
const greeting = document.createElement("div");
33+
greeting.textContent = "Hello, World.";
34+
history.pushState({}, "", "/dom-not-attached");
35+
}
36+
37+
// This click handler won't cause a soft navigation, because it
38+
// doesn't change the DOM.
39+
function noDomChange() {
40+
history.pushState({}, "", "/no-dom-change");
41+
}
42+
43+
// This click handler won't cause a soft navigation, because it
44+
// doesn't paint, even though the element is attached to the DOM.
45+
function noPaint() {
46+
const greeting = document.createElement("div");
47+
greeting.textContent = "Hello, World.";
48+
greeting.style.display = "none";
49+
document.body.appendChild(greeting);
50+
history.pushState({}, "", "/no-paint");
51+
}
52+
53+
// This click handler won't cause a soft navigation, because it
54+
// uses history.replaceState() instead of history.pushState().
55+
function replaceState() {
56+
const greeting = document.createElement("div");
57+
greeting.textContent = "Hello, World.";
58+
document.body.appendChild(greeting);
59+
history.replaceState({}, "", "/replace-state");
60+
}
61+
</script>
62+
</head>
63+
<body>
64+
<div id="actual-softnavigation" onclick="actualSoftNavigation()">Click here!</div>
65+
<div id="no-url-change" onclick="noUrlChange()">Click here!</div>
66+
<div id="dom-not-attached" onclick="domNotAttached()">Click here!</div>
67+
<div id="no-dom-change" onclick="noDomChange()">Click here!</div>
68+
<div id="no-paint" onclick="noPaint()">Click here!</div>
69+
<div id="replace-state" onclick="replaceState()">Click here!</div>
70+
71+
<script>
72+
function test_template(test_id, description) {
73+
promise_test(() => {
74+
return new Promise((resolve) => {
75+
const entries = [];
76+
new PerformanceObserver((list, observer) => {
77+
entries.push(...list.getEntries());
78+
if (entries[entries.length - 1].name.endsWith("actual-softnavigation")) {
79+
observer.disconnect();
80+
resolve(entries);
81+
}
82+
}).observe({ type: "soft-navigation" });
83+
if (test_driver) {
84+
test_driver.click(document.getElementById(test_id));
85+
test_driver.click(document.getElementById("actual-softnavigation"));
86+
}
87+
}).then((entries) => {
88+
assert_equals(
89+
entries.length,
90+
1,
91+
"Expected only one soft navigation (test_id=" + test_id + ").",
92+
);
93+
});
94+
}, description);
95+
}
96+
97+
test_template("no-url-change", "The URL change is missing.");
98+
test_template("dom-not-attached", "Creates an element but doesn't attach it to the DOM.");
99+
test_template("no-paint", "Doesn't paint because the element is hidden.");
100+
test_template("no-dom-change", "The DOM change is missing.");
101+
test_template("replace-state", "Uses replaceState() instead of pushState().");
102+
</script>
103+
</body>
104+
</html>

0 commit comments

Comments
 (0)