Files
sousa-gecko/testing/web-platform/tests/navigation-api/precommit-handler/precommitHandler-addHandler.html
T
Noam Rosenthal 920daa3259 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
2025-12-11 08:59:29 +00:00

54 lines
1.5 KiB
HTML

<!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>