From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../tests/browser/browser_quit_multiple_tabs.js | 110 +++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 browser/components/tests/browser/browser_quit_multiple_tabs.js (limited to 'browser/components/tests/browser/browser_quit_multiple_tabs.js') diff --git a/browser/components/tests/browser/browser_quit_multiple_tabs.js b/browser/components/tests/browser/browser_quit_multiple_tabs.js new file mode 100644 index 0000000000..fa0cbc7a4c --- /dev/null +++ b/browser/components/tests/browser/browser_quit_multiple_tabs.js @@ -0,0 +1,110 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +/** + * Ensure that when different combinations of warnings are enabled, + * quitting produces the correct warning (if any), and the checkbox + * is also correct. + */ +add_task(async function test_check_right_prompt() { + let tests = [ + { + warnOnQuitShortcut: true, + warnOnClose: false, + expectedDialog: "shortcut", + messageSuffix: "with shortcut but no tabs warning", + }, + { + warnOnQuitShortcut: false, + warnOnClose: true, + expectedDialog: "tabs", + messageSuffix: "with tabs but no shortcut warning", + }, + { + warnOnQuitShortcut: false, + warnOnClose: false, + messageSuffix: "with no warning", + expectedDialog: null, + }, + { + warnOnQuitShortcut: true, + warnOnClose: true, + messageSuffix: "with both warnings", + // Note: this is somewhat arbitrary; I don't think there's a right/wrong + // here, so if this changes due to implementation details, updating the + // text expectation to be "tabs" should be OK. + expectedDialog: "shortcut", + }, + ]; + let tab = BrowserTestUtils.addTab(gBrowser); + + function checkDialog(dialog, expectedDialog, messageSuffix) { + let dialogElement = dialog.document.getElementById("commonDialog"); + let acceptLabel = dialogElement.getButton("accept").label; + is( + acceptLabel.startsWith("Quit"), + expectedDialog == "shortcut", + `dialog label ${ + expectedDialog == "shortcut" ? "should" : "should not" + } start with Quit ${messageSuffix}` + ); + let checkLabel = dialogElement.querySelector("checkbox").label; + is( + checkLabel.includes("before quitting with"), + expectedDialog == "shortcut", + `checkbox label ${ + expectedDialog == "shortcut" ? "should" : "should not" + } be for quitting ${messageSuffix}` + ); + + dialogElement.getButton("cancel").click(); + } + + let dialogOpened = false; + function setDialogOpened() { + dialogOpened = true; + } + Services.obs.addObserver(setDialogOpened, "common-dialog-loaded"); + for (let { + warnOnClose, + warnOnQuitShortcut, + expectedDialog, + messageSuffix, + } of tests) { + dialogOpened = false; + let promise = null; + await SpecialPowers.pushPrefEnv({ + set: [ + ["browser.tabs.warnOnClose", warnOnClose], + ["browser.warnOnQuitShortcut", warnOnQuitShortcut], + ["browser.warnOnQuit", true], + ], + }); + if (expectedDialog) { + promise = BrowserTestUtils.promiseAlertDialogOpen("", undefined, { + callback(win) { + checkDialog(win, expectedDialog, messageSuffix); + }, + }); + } + is( + !canQuitApplication(undefined, "shortcut"), + !!expectedDialog, + `canQuitApplication ${ + expectedDialog ? "should" : "should not" + } block ${messageSuffix}.` + ); + await promise; + is( + dialogOpened, + !!expectedDialog, + `Should ${ + expectedDialog ? "" : "not " + }have opened a dialog ${messageSuffix}.` + ); + } + Services.obs.removeObserver(setDialogOpened, "common-dialog-loaded"); + BrowserTestUtils.removeTab(tab); +}); -- cgit v1.2.3