diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /browser/base/content/test/tabdialogs/browser_tabdialogbox_navigation.js | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/base/content/test/tabdialogs/browser_tabdialogbox_navigation.js')
-rw-r--r-- | browser/base/content/test/tabdialogs/browser_tabdialogbox_navigation.js | 162 |
1 files changed, 162 insertions, 0 deletions
diff --git a/browser/base/content/test/tabdialogs/browser_tabdialogbox_navigation.js b/browser/base/content/test/tabdialogs/browser_tabdialogbox_navigation.js new file mode 100644 index 0000000000..01a6e0395e --- /dev/null +++ b/browser/base/content/test/tabdialogs/browser_tabdialogbox_navigation.js @@ -0,0 +1,162 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const TEST_ROOT_CHROME = getRootDirectory(gTestPath); +const TEST_DIALOG_PATH = TEST_ROOT_CHROME + "subdialog.xhtml"; + +/** + * Tests that all tab dialogs are closed on navigation. + */ +add_task(async function test_tabdialogbox_multiple_close_on_nav() { + await BrowserTestUtils.withNewTab("https://example.com", async function( + browser + ) { + // Open two dialogs and wait for them to be ready. + let dialogBox = gBrowser.getTabDialogBox(browser); + let closedPromises = [ + dialogBox.open(TEST_DIALOG_PATH).closedPromise, + dialogBox.open(TEST_DIALOG_PATH).closedPromise, + ]; + + let dialogs = dialogBox.getTabDialogManager()._dialogs; + + is(dialogs.length, 2, "Dialog manager has two dialogs."); + + info("Waiting for dialogs to open."); + await Promise.all(dialogs.map(dialog => dialog._dialogReady)); + + // Navigate to a different page + BrowserTestUtils.loadURI(browser, "https://example.org"); + + info("Waiting for dialogs to close."); + await closedPromises; + + ok(true, "All open dialogs should close on navigation"); + }); +}); + +/** + * Tests dialog close on navigation triggered by web content. + */ +add_task(async function test_tabdialogbox_close_on_content_nav() { + await BrowserTestUtils.withNewTab("https://example.com", async function( + browser + ) { + // Open a dialog and wait for it to be ready + let dialogBox = gBrowser.getTabDialogBox(browser); + let { closedPromise } = dialogBox.open(TEST_DIALOG_PATH); + + let dialog = dialogBox.getTabDialogManager()._topDialog; + + is( + dialogBox.getTabDialogManager()._dialogs.length, + 1, + "Dialog manager has one dialog." + ); + + info("Waiting for dialog to open."); + await dialog._dialogReady; + + // Trigger a same origin navigation by the content + await ContentTask.spawn(browser, {}, () => { + content.location = "http://example.com/1"; + }); + + info("Waiting for dialog to close."); + await closedPromise; + ok(true, "Dialog should close for same origin navigation by the content."); + + // Open a new dialog + closedPromise = dialogBox.open(TEST_DIALOG_PATH, { + keepOpenSameOriginNav: true, + }).closedPromise; + + info("Waiting for dialog to open."); + await dialog._dialogReady; + + SimpleTest.requestFlakyTimeout("Waiting to ensure dialog does not close"); + let race = Promise.race([ + closedPromise, + // eslint-disable-next-line mozilla/no-arbitrary-setTimeout + new Promise(resolve => setTimeout(() => resolve("success"), 1000)), + ]); + + // Trigger a same origin navigation by the content + await ContentTask.spawn(browser, {}, () => { + content.location = "http://example.com/test"; + }); + + is( + await race, + "success", + "Dialog should not close for same origin navigation by the content." + ); + + // Trigger a cross origin navigation by the content + await ContentTask.spawn(browser, {}, () => { + content.location = "http://example.org/test2"; + }); + + info("Waiting for dialog to close"); + await closedPromise; + + ok(true, "Dialog should close for cross origin navigation by the content."); + }); +}); + +/** + * Hides a dialog stack and tests that behavior doesn't change. Ensures + * navigation triggered by web content still closes all dialogs. + */ +add_task(async function test_tabdialogbox_hide() { + await BrowserTestUtils.withNewTab("https://example.com", async function( + browser + ) { + // Open a dialog and wait for it to be ready + let dialogBox = gBrowser.getTabDialogBox(browser); + let dialogBoxManager = dialogBox.getTabDialogManager(); + let closedPromises = [ + dialogBox.open(TEST_DIALOG_PATH).closedPromise, + dialogBox.open(TEST_DIALOG_PATH).closedPromise, + ]; + + let dialogs = dialogBox.getTabDialogManager()._dialogs; + + is( + dialogBox.getTabDialogManager()._dialogs.length, + 2, + "Dialog manager has two dialogs." + ); + + info("Waiting for dialogs to open."); + await Promise.all(dialogs.map(dialog => dialog._dialogReady)); + + ok( + !BrowserTestUtils.is_hidden(dialogBoxManager._dialogStack), + "Dialog stack is showing" + ); + + dialogBoxManager.hideDialog(browser); + + is( + dialogBoxManager._dialogs.length, + 2, + "Dialog manager still has two dialogs." + ); + + ok( + BrowserTestUtils.is_hidden(dialogBoxManager._dialogStack), + "Dialog stack is hidden" + ); + + // Navigate to a different page + BrowserTestUtils.loadURI(browser, "https://example.org"); + + info("Waiting for dialogs to close."); + await closedPromises; + + ok(true, "All open dialogs should still close on navigation"); + }); +}); |