commit 696e8cc813dbc7faa43937be2cb5604d751cb64e
parent 1e4df318c532ad887cadd3047858e2e0bc7d13e2
Author: Mustaq Ahmed <mustaq@google.com>
Date: Thu, 9 Oct 2025 20:32:15 +0000
Bug 1989427 [wpt PR 54933] - Add a WPT for sticky activation across same-origin navigation., a=testonly
Automatic update from web-platform-tests
Add a WPT for sticky activation across same-origin navigation.
Bug: 433729626
Change-Id: I71aef4971512e7ca8996a28a227d58b572c18881
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6956519
Reviewed-by: Vladimir Levin <vmpstr@chromium.org>
Commit-Queue: Mustaq Ahmed <mustaq@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1522937}
--
wpt-commits: 842cbcd21c65b3a144a47da26089c847e083e11a
wpt-pr: 54933
Diffstat:
3 files changed, 93 insertions(+), 0 deletions(-)
diff --git a/testing/web-platform/tests/html/user-activation/navigate-to-sameorigin.html b/testing/web-platform/tests/html/user-activation/navigate-to-sameorigin.html
@@ -0,0 +1,58 @@
+<!DOCTYPE html>
+<title>User activation propagation across a same-origin navigation</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/testdriver-actions.js"></script>
+<script src="resources/utils.js"></script>
+
+<body>
+ <p>Placeholder</p>
+</body>
+
+<script>
+ 'use strict';
+
+ let w;
+ document.body.onclick = () => {
+ w = window.open("resources/opened-window.html");
+ };
+
+ promise_test(async test => {
+ let window_opened_msg_promise = receiveMessage("window-opened");
+
+ await test_driver.click(document.body);
+ assert_true(!!w, "A window is opened");
+
+ {
+ let window_opened_data = await window_opened_msg_promise;
+ assert_false(window_opened_data.isActive,
+ "Transient activation after window opened");
+ assert_false(window_opened_data.hasBeenActive,
+ "Sticky activation after window opened");
+ }
+
+ let link_clicked_msg_promise = receiveMessage("link-clicked");
+ let window_navigated_msg_promise = receiveMessage("window-navigated");
+
+ const link = w.document.getElementById("link");
+ await test_driver.click(link);
+
+ {
+ let link_clicked_data = await link_clicked_msg_promise;
+ assert_true(link_clicked_data.isActive,
+ "Transient activation after link clicked");
+ assert_true(link_clicked_data.hasBeenActive,
+ "Sticky activation after link clicked");
+ }
+
+ {
+ let window_navigated_data = await window_navigated_msg_promise;
+ assert_false(window_navigated_data.isActive,
+ "Transient activation after window navigated");
+ assert_true(window_navigated_data.hasBeenActive,
+ "Sticky activation after window navigated");
+ }
+ }, "User activation propagation across a same-origin navigation");
+</script>
diff --git a/testing/web-platform/tests/html/user-activation/resources/opened-window.html b/testing/web-platform/tests/html/user-activation/resources/opened-window.html
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+
+<body onload="run()">
+ <a id="link" href="?post-nav">link</a>
+</body>
+
+<script>
+ 'use strict';
+ const post_nav_page = location.search.substring(1) === "post-nav";
+
+ function sendActivationStateToOpener(msg_type) {
+ window.opener.postMessage(JSON.stringify({
+ "type": msg_type,
+ "isActive": navigator.userActivation.isActive,
+ "hasBeenActive": navigator.userActivation.hasBeenActive
+ }), "*");
+ }
+
+ document.getElementById("link").addEventListener("click", () => {
+ assert_false(post_nav_page, "No click in the post-navigation page");
+ sendActivationStateToOpener("link-clicked");
+ });
+
+ function run() {
+ if (!post_nav_page) {
+ sendActivationStateToOpener("window-opened");
+ } else {
+ sendActivationStateToOpener("window-navigated");
+ }
+ }
+</script>
diff --git a/testing/web-platform/tests/html/user-activation/resources/utils.js b/testing/web-platform/tests/html/user-activation/resources/utils.js
@@ -32,6 +32,9 @@ async function consumeTransientActivation() {
}
}
+// Returns a `Promise` that gets resolved when `window` receives a "message"
+// event with an `event.data` JSON string whose "type" field matches the given
+// parameter. The promise is resolved with JSON-parsed `event.data`.
function receiveMessage(type) {
return new Promise((resolve) => {
window.addEventListener("message", function listener(event) {