diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:29 +0000 |
commit | 59203c63bb777a3bacec32fb8830fba33540e809 (patch) | |
tree | 58298e711c0ff0575818c30485b44a2f21bf28a0 /browser/base/content/test/tabPrompts | |
parent | Adding upstream version 126.0.1. (diff) | |
download | firefox-59203c63bb777a3bacec32fb8830fba33540e809.tar.xz firefox-59203c63bb777a3bacec32fb8830fba33540e809.zip |
Adding upstream version 127.0.upstream/127.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/base/content/test/tabPrompts')
3 files changed, 116 insertions, 2 deletions
diff --git a/browser/base/content/test/tabPrompts/browser.toml b/browser/base/content/test/tabPrompts/browser.toml index 037f1f0d2b..aa7d4c724e 100644 --- a/browser/base/content/test/tabPrompts/browser.toml +++ b/browser/base/content/test/tabPrompts/browser.toml @@ -39,6 +39,8 @@ support-files = ["file_beforeunload_stop.html"] https_first_disabled = true support-files = ["openPromptOffTimeout.html"] +["browser_promptDelays.js"] + ["browser_promptFocus.js"] ["browser_prompt_close_event.js"] diff --git a/browser/base/content/test/tabPrompts/browser_promptDelays.js b/browser/base/content/test/tabPrompts/browser_promptDelays.js new file mode 100644 index 0000000000..ecd01cdb69 --- /dev/null +++ b/browser/base/content/test/tabPrompts/browser_promptDelays.js @@ -0,0 +1,113 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const PERMISSION_DIALOG = + "chrome://mozapps/content/handling/permissionDialog.xhtml"; + +add_setup(async function () { + // Set a new handler as default. + const protoSvc = Cc[ + "@mozilla.org/uriloader/external-protocol-service;1" + ].getService(Ci.nsIExternalProtocolService); + let protoInfo = protoSvc.getProtocolHandlerInfo("web+testprotocol"); + protoInfo.preferredAction = protoInfo.useHelperApp; + let handler = Cc["@mozilla.org/uriloader/web-handler-app;1"].createInstance( + Ci.nsIWebHandlerApp + ); + handler.uriTemplate = "https://example.com/foobar?uri=%s"; + handler.name = "Test protocol"; + let handlers = protoInfo.possibleApplicationHandlers; + handlers.appendElement(handler); + + protoInfo.preferredApplicationHandler = handler; + protoInfo.alwaysAskBeforeHandling = false; + + const handlerSvc = Cc["@mozilla.org/uriloader/handler-service;1"].getService( + Ci.nsIHandlerService + ); + handlerSvc.store(protoInfo); + + registerCleanupFunction(() => { + handlerSvc.remove(protoInfo); + }); +}); + +add_task(async function test_promptWhileNotForeground() { + await BrowserTestUtils.withNewTab("about:blank", async browser => { + let windowOpened = BrowserTestUtils.waitForNewWindow(); + await SpecialPowers.spawn(browser, [], () => { + content.eval(`window.open('about:blank', "_blank", "height=600");`); + }); + let otherWin = await windowOpened; + info("Opened extra window, now start a prompt."); + + // To ensure we test the delay helper correctly, shorten the delay: + await SpecialPowers.pushPrefEnv({ + set: [["security.dialog_enable_delay", 50]], + }); + + let promptPromise = BrowserTestUtils.promiseAlertDialogOpen( + null, + PERMISSION_DIALOG, + { isSubDialog: true } + ); + await SpecialPowers.spawn(browser, [], () => { + content.document.location.href = "web+testprotocol:hello"; + }); + info("Started opening prompt."); + let prompt = await promptPromise; + info("Opened prompt."); + let dialog = prompt.document.querySelector("dialog"); + let button = dialog.getButton("accept"); + is(button.getAttribute("disabled"), "true", "Button should be disabled"); + + // eslint-disable-next-line mozilla/no-arbitrary-setTimeout + await new Promise(r => setTimeout(r, 500)); + is( + button.getAttribute("disabled"), + "true", + "Button should still be disabled while the dialog is in the background" + ); + + let buttonGetsEnabled = BrowserTestUtils.waitForMutationCondition( + button, + { attributeFilter: ["disabled"] }, + () => button.getAttribute("disabled") != "true" + ); + await BrowserTestUtils.closeWindow(otherWin); + info("Waiting for button to be enabled."); + await buttonGetsEnabled; + ok(true, "The button was enabled."); + dialog.cancelDialog(); + + await SpecialPowers.popPrefEnv(); + }); +}); + +add_task(async function test_promptWhileForeground() { + await BrowserTestUtils.withNewTab("about:blank", async browser => { + let promptPromise = BrowserTestUtils.promiseAlertDialogOpen( + null, + PERMISSION_DIALOG, + { isSubDialog: true } + ); + await SpecialPowers.spawn(browser, [], () => { + content.document.location.href = "web+testprotocol:hello"; + }); + info("Started opening prompt."); + let prompt = await promptPromise; + info("Opened prompt."); + let dialog = prompt.document.querySelector("dialog"); + let button = dialog.getButton("accept"); + is(button.getAttribute("disabled"), "true", "Button should be disabled"); + await BrowserTestUtils.waitForMutationCondition( + button, + { attributeFilter: ["disabled"] }, + () => button.getAttribute("disabled") != "true" + ); + ok(true, "The button was enabled."); + dialog.cancelDialog(); + }); +}); diff --git a/browser/base/content/test/tabPrompts/browser_promptFocus.js b/browser/base/content/test/tabPrompts/browser_promptFocus.js index 89ca064c10..cab812f57b 100644 --- a/browser/base/content/test/tabPrompts/browser_promptFocus.js +++ b/browser/base/content/test/tabPrompts/browser_promptFocus.js @@ -20,8 +20,7 @@ add_task(async function test_tabdialogbox_tab_switch_focus() { tabPromises.push( BrowserTestUtils.openNewForegroundTab( gBrowser, - // eslint-disable-next-line @microsoft/sdl/no-insecure-url - "http://example.com", + "https://example.com", true ) ); |