diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /testing/web-platform/tests/navigation-api/commit-behavior/resources/after-transition-commit-helpers.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/navigation-api/commit-behavior/resources/after-transition-commit-helpers.js')
-rw-r--r-- | testing/web-platform/tests/navigation-api/commit-behavior/resources/after-transition-commit-helpers.js | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/testing/web-platform/tests/navigation-api/commit-behavior/resources/after-transition-commit-helpers.js b/testing/web-platform/tests/navigation-api/commit-behavior/resources/after-transition-commit-helpers.js new file mode 100644 index 0000000000..664e8d7280 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/commit-behavior/resources/after-transition-commit-helpers.js @@ -0,0 +1,90 @@ +window.testAfterTransitionCommit = async (t, navigationType, mode, destinationIndex = 0) => { + let startHash = location.hash; + let destinationHash; + const err = new Error("boo!"); + + let popstate_fired = false; + window.addEventListener("popstate", () => popstate_fired = true, { once : true }); + let navigatesuccess_fired = false; + navigation.addEventListener("navigatesuccess", () => navigatesuccess_fired = true, { once : true }); + let navigateerror_fired = false; + navigation.addEventListener("navigateerror", () => navigateerror_fired = true, { once : true }); + + // mode-specific logic for the navigate event handler + let navigate_helpers = { + rejectBeforeCommit : async (e) => { + return Promise.reject(err); + }, + rejectAfterCommit : async (e) => { + e.commit(); + assert_equals(location.hash, destinationHash, "hash after commit"); + assert_true(popstate_fired, "popstate fired after commit"); + await new Promise(resolve => t.step_timeout(resolve, 0)); + return Promise.reject(err); + }, + successExplicitCommit : async (e) => { + e.commit(); + assert_equals(location.hash, destinationHash, "hash after commit"); + assert_true(popstate_fired, "popstate fired after commit"); + return new Promise(resolve => t.step_timeout(resolve, 0)); + }, + successNoExplicitCommit : async (e) => { + assert_equals(location.hash, startHash, "start has after first async step"); + assert_false(popstate_fired, "popstate fired after first async step"); + await new Promise(resolve => t.step_timeout(resolve, 0)); + assert_equals(location.hash, startHash, "start has after second async step"); + assert_false(popstate_fired, "popstate fired after second async step"); + return new Promise(resolve => t.step_timeout(resolve, 0)); + } + } + + navigation.addEventListener("navigate", e => { + e.intercept({ commit: "after-transition", + handler: t.step_func(async () => { + assert_equals(e.navigationType, navigationType); + assert_equals(location.hash, startHash, "start hash"); + assert_false(popstate_fired, "popstate fired at handler start"); + + await new Promise(resolve => t.step_timeout(resolve, 0)); + assert_equals(location.hash, startHash, "hash after first async step"); + assert_false(popstate_fired, "popstate fired after first async step"); + + return navigate_helpers[mode](e); + })}); + }, { once: true }); + + let promises; + if (navigationType === "push" || navigationType === "replace") { + destinationHash = (startHash === "" ? "#" : startHash) + "a"; + promises = navigation.navigate(destinationHash, { history: navigationType }); + } else if (navigationType === "reload") { + destinationHash = startHash; + promises = navigation.reload(); + } else if (navigationType === "traverse") { + let destinationEntry = navigation.entries()[destinationIndex]; + destinationHash = new URL(destinationEntry.url).hash; + promises = navigation.traverseTo(destinationEntry.key); + } + + if (mode === "rejectBeforeCommit") { + await assertBothRejectExactly(t, promises, err); + assert_equals(location.hash, startHash, "hash after promise resolution"); + assert_false(popstate_fired, "popstate fired after promise resolution"); + assert_false(navigatesuccess_fired, "navigatesuccess fired"); + assert_true(navigateerror_fired, "navigateerror fired"); + } else if (mode === "rejectAfterCommit") { + await promises.committed; + await assertCommittedFulfillsFinishedRejectsExactly(t, promises, navigation.currentEntry, err); + assert_equals(location.hash, destinationHash, "hash after promise resolution"); + assert_true(popstate_fired, "popstate fired after promise resolution"); + assert_false(navigatesuccess_fired, "navigatesuccess fired"); + assert_true(navigateerror_fired, "navigateerror fired"); + } else { + await promises.committed; + await assertBothFulfill(t, promises, navigation.currentEntry); + assert_equals(location.hash, destinationHash, "hash after promise resolution"); + assert_true(popstate_fired, "popstate fired after promise resolution"); + assert_true(navigatesuccess_fired, "navigatesuccess fired"); + assert_false(navigateerror_fired, "navigateerror fired"); + } +} |