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_shortcut_warning.js | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 browser/components/tests/browser/browser_quit_shortcut_warning.js (limited to 'browser/components/tests/browser/browser_quit_shortcut_warning.js') diff --git a/browser/components/tests/browser/browser_quit_shortcut_warning.js b/browser/components/tests/browser/browser_quit_shortcut_warning.js new file mode 100644 index 0000000000..7bc67d8562 --- /dev/null +++ b/browser/components/tests/browser/browser_quit_shortcut_warning.js @@ -0,0 +1,54 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +// This test checks that the quit dialog appears correctly when the browser.warnOnQuitShortcut +// preference is set and the quit keyboard shortcut is pressed. +add_task(async function test_quit_shortcut() { + await SpecialPowers.pushPrefEnv({ + set: [ + ["browser.warnOnQuit", true], + ["browser.warnOnQuitShortcut", true], + ], + }); + + function checkDialog(dialog) { + let dialogElement = dialog.document.getElementById("commonDialog"); + let acceptLabel = dialogElement.getButton("accept").label; + is(acceptLabel.indexOf("Quit"), 0, "dialog label"); + dialogElement.getButton("cancel").click(); + } + + let dialogOpened = false; + function setDialogOpened() { + dialogOpened = true; + } + Services.obs.addObserver(setDialogOpened, "common-dialog-loaded"); + + // Test 1: quit using the shortcut key with the preference enabled. + let quitPromise = BrowserTestUtils.promiseAlertDialog("cancel", undefined, { + callback: checkDialog, + }); + ok(!canQuitApplication(undefined, "shortcut"), "can quit with dialog"); + + ok(dialogOpened, "confirmation prompt should have opened"); + + await quitPromise; + + // Test 2: quit without using the shortcut key with the preference enabled. + dialogOpened = false; + ok(canQuitApplication(undefined, ""), "can quit with no dialog"); + ok(!dialogOpened, "confirmation prompt should not have opened"); + + // Test 3: quit using the shortcut key with the preference disabled. + await SpecialPowers.pushPrefEnv({ + set: [["browser.warnOnQuitShortcut", false]], + }); + + dialogOpened = false; + ok(canQuitApplication(undefined, "shortcut"), "can quit with no dialog"); + + ok(!dialogOpened, "confirmation prompt should not have opened"); + Services.obs.removeObserver(setDialogOpened, "common-dialog-loaded"); + + await SpecialPowers.popPrefEnv(); +}); -- cgit v1.2.3