diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /browser/base/content/test/webextensions/browser_permissions_dismiss.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
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..3cd916c3c5 --- /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.isVisible(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); +}); |