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/webextensions/browser_permissions_dismiss.js | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.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/webextensions/browser_permissions_dismiss.js')
-rw-r--r-- | browser/base/content/test/webextensions/browser_permissions_dismiss.js | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/browser/base/content/test/webextensions/browser_permissions_dismiss.js b/browser/base/content/test/webextensions/browser_permissions_dismiss.js new file mode 100644 index 0000000000..ac1e9c4bd4 --- /dev/null +++ b/browser/base/content/test/webextensions/browser_permissions_dismiss.js @@ -0,0 +1,112 @@ +"use strict"; + +const INSTALL_PAGE = `${BASE}/file_install_extensions.html`; +const INSTALL_XPI = `${BASE}/browser_webext_permissions.xpi`; + +add_setup(async function() { + await SpecialPowers.pushPrefEnv({ + set: [ + ["extensions.webapi.testing", true], + ["extensions.install.requireBuiltInCerts", false], + ], + }); + + registerCleanupFunction(async () => { + await SpecialPowers.popPrefEnv(); + }); +}); + +add_task(async function test_tab_switch_dismiss() { + let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, INSTALL_PAGE); + + let installCanceled = new Promise(resolve => { + let listener = { + onInstallCancelled() { + AddonManager.removeInstallListener(listener); + resolve(); + }, + }; + AddonManager.addInstallListener(listener); + }); + + SpecialPowers.spawn(gBrowser.selectedBrowser, [INSTALL_XPI], function(url) { + content.wrappedJSObject.installMozAM(url); + }); + + await promisePopupNotificationShown("addon-webext-permissions"); + let permsUL = document.getElementById("addon-webext-perm-list"); + is(permsUL.childElementCount, 5, `Permissions list has 5 entries`); + + let permsLearnMore = document.getElementById("addon-webext-perm-info"); + ok( + BrowserTestUtils.is_visible(permsLearnMore), + "Learn more link is shown on Permission popup" + ); + is( + permsLearnMore.href, + Services.urlFormatter.formatURLPref("app.support.baseURL") + + "extension-permissions", + "Learn more link has desired URL" + ); + + // Switching tabs dismisses the notification and cancels the install. + let switchTo = await BrowserTestUtils.openNewForegroundTab(gBrowser); + BrowserTestUtils.removeTab(switchTo); + await installCanceled; + + let addon = await AddonManager.getAddonByID("permissions@test.mozilla.org"); + is(addon, null, "Extension is not installed"); + + BrowserTestUtils.removeTab(tab); +}); + +add_task(async function test_add_tab_by_user_and_switch() { + let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, INSTALL_PAGE); + + let listener = { + onInstallCancelled() { + this.canceledPromise = Promise.resolve(); + }, + }; + AddonManager.addInstallListener(listener); + + SpecialPowers.spawn(gBrowser.selectedBrowser, [INSTALL_XPI], function(url) { + content.wrappedJSObject.installMozAM(url); + }); + + // Show addon permission notification. + await promisePopupNotificationShown("addon-webext-permissions"); + is( + document.getElementById("addon-webext-perm-list").childElementCount, + 5, + "Permissions list has 5 entries" + ); + + // Open about:newtab page in a new tab. + let newTab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + "about:newtab", + false + ); + + // Switch to tab that is opening addon permission notification. + gBrowser.selectedTab = tab; + is( + document.getElementById("addon-webext-perm-list").childElementCount, + 5, + "Permission notification is shown again" + ); + ok(!listener.canceledPromise, "Extension installation is not canceled"); + + // Cancel installation. + document.querySelector(".popup-notification-secondary-button").click(); + await listener.canceledPromise; + info("Extension installation is canceled"); + + let addon = await AddonManager.getAddonByID("permissions@test.mozilla.org"); + is(addon, null, "Extension is not installed"); + + AddonManager.removeInstallListener(listener); + BrowserTestUtils.removeTab(tab); + BrowserTestUtils.removeTab(newTab); +}); |