diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /toolkit/components/contextualidentity/tests/browser | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/contextualidentity/tests/browser')
-rw-r--r-- | toolkit/components/contextualidentity/tests/browser/browser.toml | 3 | ||||
-rw-r--r-- | toolkit/components/contextualidentity/tests/browser/browser_closeContainerTabs.js | 81 |
2 files changed, 84 insertions, 0 deletions
diff --git a/toolkit/components/contextualidentity/tests/browser/browser.toml b/toolkit/components/contextualidentity/tests/browser/browser.toml new file mode 100644 index 0000000000..0678c38171 --- /dev/null +++ b/toolkit/components/contextualidentity/tests/browser/browser.toml @@ -0,0 +1,3 @@ +[DEFAULT] + +["browser_closeContainerTabs.js"] diff --git a/toolkit/components/contextualidentity/tests/browser/browser_closeContainerTabs.js b/toolkit/components/contextualidentity/tests/browser/browser_closeContainerTabs.js new file mode 100644 index 0000000000..16fa28e306 --- /dev/null +++ b/toolkit/components/contextualidentity/tests/browser/browser_closeContainerTabs.js @@ -0,0 +1,81 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { PromptTestUtils } = ChromeUtils.importESModule( + "resource://testing-common/PromptTestUtils.sys.mjs" +); + +const BUILDER_URL = "https://example.com/document-builder.sjs?html="; +const PAGE_MARKUP = ` +<html> +<head> + <script> + window.onbeforeunload = function() { + return true; + }; + </script> +</head> +<body>TEST PAGE</body> +</html> +`; +const TEST_URL = BUILDER_URL + encodeURI(PAGE_MARKUP); + +add_task(async function test_skipPermitUnload() { + await SpecialPowers.pushPrefEnv({ + set: [["dom.require_user_interaction_for_beforeunload", false]], + }); + + info("Create a test user context"); + const userContextId = ContextualIdentityService.create("test").userContextId; + + // Run tests in a new window to avoid affecting the main test window. + const win = await BrowserTestUtils.openNewBrowserWindow(); + registerCleanupFunction(async () => { + await BrowserTestUtils.closeWindow(win); + }); + + info("Create a tab owned by the test user context"); + const tab = await BrowserTestUtils.addTab(win.gBrowser, TEST_URL, { + userContextId, + }); + registerCleanupFunction(() => win.gBrowser.removeTab(tab)); + await BrowserTestUtils.browserLoaded(tab.linkedBrowser); + + info("Call closeContainerTabs without skipPermitUnload"); + const unloadDialogPromise = PromptTestUtils.handleNextPrompt( + tab.linkedBrowser, + { + modalType: Ci.nsIPrompt.MODAL_TYPE_CONTENT, + promptType: "confirmEx", + }, + // Click the cancel button. + { buttonNumClick: 1 } + ); + + const tabCountBeforeClose = win.gBrowser.tabs.length; + ContextualIdentityService.closeContainerTabs(userContextId); + + info("Wait for the unload dialog"); + await unloadDialogPromise; + is( + win.gBrowser.tabs.length, + tabCountBeforeClose, + "Tab was not closed because of the before unload prompt" + ); + + info("Call closeContainerTabs with skipPermitUnload"); + const closePromise = BrowserTestUtils.waitForTabClosing(tab); + ContextualIdentityService.closeContainerTabs(userContextId, { + skipPermitUnload: true, + }); + + info("Wait for the tab to be closed"); + await closePromise; + is( + win.gBrowser.tabs.length, + tabCountBeforeClose - 1, + "Tab was closed after ignoring the before unload prompt" + ); +}); |