diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /browser/base/content/test/contextMenu/browser_contextmenu_save_blocked.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | browser/base/content/test/contextMenu/browser_contextmenu_save_blocked.js | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/browser/base/content/test/contextMenu/browser_contextmenu_save_blocked.js b/browser/base/content/test/contextMenu/browser_contextmenu_save_blocked.js new file mode 100644 index 0000000000..5064d9a316 --- /dev/null +++ b/browser/base/content/test/contextMenu/browser_contextmenu_save_blocked.js @@ -0,0 +1,78 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +var MockFilePicker = SpecialPowers.MockFilePicker; +MockFilePicker.init(window); + +function mockPromptService() { + let { prompt } = Services; + let promptService = { + QueryInterface: ChromeUtils.generateQI(["nsIPromptService"]), + alert: () => {}, + }; + Services.prompt = promptService; + registerCleanupFunction(() => { + Services.prompt = prompt; + }); + return promptService; +} + +add_task(async function test_save_link_blocked_by_extension() { + let ext = ExtensionTestUtils.loadExtension({ + manifest: { + browser_specific_settings: { gecko: { id: "cancel@test" } }, + name: "Cancel Test", + permissions: ["webRequest", "webRequestBlocking", "<all_urls>"], + }, + + background() { + // eslint-disable-next-line no-undef + browser.webRequest.onBeforeRequest.addListener( + details => { + // eslint-disable-next-line @microsoft/sdl/no-insecure-url + return { cancel: details.url === "http://example.com/" }; + }, + { urls: ["*://*/*"] }, + ["blocking"] + ); + }, + }); + await ext.startup(); + + await BrowserTestUtils.withNewTab( + `data:text/html;charset=utf-8,<a href="http://example.com">Download</a>`, + async browser => { + let menu = document.getElementById("contentAreaContextMenu"); + let popupShown = BrowserTestUtils.waitForEvent(menu, "popupshown"); + BrowserTestUtils.synthesizeMouseAtCenter( + "a[href]", + { type: "contextmenu", button: 2 }, + browser + ); + await popupShown; + + await new Promise(resolve => { + let promptService = mockPromptService(); + promptService.alert = (window, title, msg) => { + is( + msg, + "The download cannot be saved because it is blocked by Cancel Test.", + "prompt should be shown" + ); + setTimeout(resolve, 0); + }; + + MockFilePicker.showCallback = function (fp) { + ok(false, "filepicker should never been shown"); + setTimeout(resolve, 0); + return Ci.nsIFilePicker.returnCancel; + }; + menu.activateItem(menu.querySelector("#context-savelink")); + }); + } + ); + + await ext.unload(); +}); |