tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 920daa3259c82028dd98ef472c67e415dfa85ff9
parent f76aa0dcee3eb0125f34425c7795931fe4dc71c4
Author: Noam Rosenthal <nrosenthal@chromium.org>
Date:   Mon,  8 Dec 2025 12:29:36 +0000

Bug 2004569 [wpt PR 56549] - Implement NavigationPrecommitController.addHandler, a=testonly

Automatic update from web-platform-tests
Implement NavigationPrecommitController.addHandler

This allows registering a post-commit navigation handler during the
pre-commit phase, to allow a multi-step navigation process.

Bug: 465487215
Change-Id: I1740cbe73d126d114d935463ff10c5e29b531947
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7222931
Reviewed-by: Nate Chapin <japhet@chromium.org>
Commit-Queue: Noam Rosenthal <nrosenthal@google.com>
Cr-Commit-Position: refs/heads/main@{#1555106}

--

wpt-commits: 3d3d25635ba20b86310c006951dca7b72525868b
wpt-pr: 56549

Diffstat:
Atesting/web-platform/tests/navigation-api/precommit-handler/precommitHandler-addHandler-throws.html | 46++++++++++++++++++++++++++++++++++++++++++++++
Atesting/web-platform/tests/navigation-api/precommit-handler/precommitHandler-addHandler.html | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 99 insertions(+), 0 deletions(-)

diff --git a/testing/web-platform/tests/navigation-api/precommit-handler/precommitHandler-addHandler-throws.html b/testing/web-platform/tests/navigation-api/precommit-handler/precommitHandler-addHandler-throws.html @@ -0,0 +1,46 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<script> + +promise_test(async t => { + let precommit_controller; + navigation.onnavigate = t.step_func(e => { + e.intercept({ precommitHandler: async controller => precommit_controller = controller }); + }); + await navigation.navigate("#").finished; + assert_throws_dom("InvalidStateError", () => precommit_controller.addHandler(() => {})); +}, "addHandler() after finish"); + +promise_test(async t => { + let precommit_controller; + navigation.onnavigate = t.step_func(e => { + e.intercept({ + precommitHandler: async controller => precommit_controller = controller, + handler: t.step_func(async () => { + assert_throws_dom("InvalidStateError", () => precommit_controller.addHandler(() => {})); + }) + }); + }); + await navigation.navigate("#").finished; +}, "addHandler() after commit"); + +promise_test(async t => { + let i = document.createElement("iframe"); + i.src = "about:blank"; + document.body.appendChild(i); + i.contentWindow.navigation.onnavigate = t.step_func(e => { + e.intercept({ + precommitHandler: t.step_func(controller => { + let iframe_constructor = i.contentWindow.DOMException; + i.remove(); + assert_throws_dom("InvalidStateError", iframe_constructor, () => controller.addHandler(() => {})); + }) + }); + }); + i.contentWindow.navigation.navigate("#"); +}, "addHandler() in detached iframe"); + +</script> +</body> diff --git a/testing/web-platform/tests/navigation-api/precommit-handler/precommitHandler-addHandler.html b/testing/web-platform/tests/navigation-api/precommit-handler/precommitHandler-addHandler.html @@ -0,0 +1,53 @@ +<!DOCTYPE html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> + <script> + promise_test(async (t) => { + let did_delay = false; + navigation.onnavigate = t.step_func((e) => { + e.intercept({ + precommitHandler: (controller) => + controller.addHandler( + t.step_func( + () => + new Promise((resolve) => + t.step_timeout(() => { + did_delay = true; + resolve(); + }, 1) + ) + ) + ), + }); + }); + await navigation.navigate("#").finished; + assert_true(did_delay); + }, "handler added in addHandler() delays navigation finish"); + + promise_test(async (t) => { + const events = []; + navigation.onnavigate = t.step_func((e) => { + e.intercept({ + precommitHandler: async (controller) => { + controller.addHandler( + t.step_func(() => { + events.push("added"); + }) + ); + }, + handler: t.step_func(() => { + events.push("handler1"); + }), + }); + e.intercept({ + handler: t.step_func(() => { + events.push("handler2"); + }), + }); + }); + await navigation.navigate("#").finished; + assert_array_equals(events, ["handler1", "handler2", "added"]); + }, "handler added in addHandler() is executed in the correct order"); + </script> +</body>