
Pier Angelo Vendrame pushed to branch tor-browser-140.3.0esr-15.0-1 at The Tor Project / Applications / Tor Browser Commits: 3f0921ce by Pier Angelo Vendrame at 2025-10-08T14:22:13+02:00 fixup! BB 43664: Automatically check the PBM checkbox when in always-on PBM. This reverts commit 513f129ea336d1e0bd513eb2c1f7d6b029f0dd47. - - - - - 40d762f3 by Pier Angelo Vendrame at 2025-10-08T14:22:16+02:00 Bug 1987183 - Automatically check the addon PBM checkbox when in always-on PBM. r=robwu Differential Revision: https://phabricator.services.mozilla.com/D263934 - - - - - 4 changed files: - browser/base/content/browser-addons.js - browser/components/extensions/test/browser/browser-private.toml - + browser/components/extensions/test/browser/browser_always_on_pbm_prompt.js - browser/modules/ExtensionsUI.sys.mjs Changes: ===================================== browser/base/content/browser-addons.js ===================================== @@ -20,7 +20,6 @@ ChromeUtils.defineESModuleGetters(lazy, { ExtensionPermissions: "resource://gre/modules/ExtensionPermissions.sys.mjs", OriginControls: "resource://gre/modules/ExtensionPermissions.sys.mjs", PERMISSION_L10N: "resource://gre/modules/ExtensionPermissionMessages.sys.mjs", - PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs", SITEPERMS_ADDON_TYPE: "resource://gre/modules/addons/siteperms-addon-utils.sys.mjs", }); @@ -467,9 +466,7 @@ customElements.define( this.notification.options.customElementOptions; let checkboxEl = this.ownerDocument.createElement("moz-checkbox"); - checkboxEl.checked = - grantPrivateBrowsingAllowed || - lazy.PrivateBrowsingUtils.permanentPrivateBrowsing; + checkboxEl.checked = grantPrivateBrowsingAllowed; checkboxEl.addEventListener("change", () => { // NOTE: the popupnotification instances will be reused // and so the callback function is destructured here to ===================================== browser/components/extensions/test/browser/browser-private.toml ===================================== @@ -6,6 +6,8 @@ tags = "webextensions" prefs = ["browser.privatebrowsing.autostart=true"] support-files = ["head.js"] +["browser_always_on_pbm_prompt.js"] + ["browser_ext_tabs_cookieStoreId_private.js"] ["browser_ext_tabs_newtab_private.js"] ===================================== browser/components/extensions/test/browser/browser_always_on_pbm_prompt.js ===================================== @@ -0,0 +1,95 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { AddonTestUtils } = ChromeUtils.importESModule( + "resource://testing-common/AddonTestUtils.sys.mjs" +); + +AddonTestUtils.initMochitest(this); + +const addonId = "test@pbm-checkbox"; +let xpi; + +async function testCheckbox(allowPbm, expectedCheckboxValue) { + const readyPromise = AddonTestUtils.promiseWebExtensionStartup(addonId); + + window.gURLBar.value = xpi.path; + window.gURLBar.focus(); + EventUtils.synthesizeKey("KEY_Enter", {}, window); + + const panel = await promisePopupNotificationShown("addon-webext-permissions"); + const checkbox = panel.querySelector( + "li.webext-perm-privatebrowsing > moz-checkbox" + ); + ok(checkbox, "We found the PBM checkbox"); + + is( + checkbox.checked, + expectedCheckboxValue, + `We expected the PBM checkbox ${expectedCheckboxValue ? "" : "not "}to be checked for this test case.` + ); + + if (checkbox.checked != allowPbm) { + let { promise, resolve } = Promise.withResolvers(); + checkbox.addEventListener("change", resolve, { once: true }); + checkbox.click(); + await promise; + } + + is(checkbox.checked, allowPbm, "The checkbox matches allowPbm."); + + // Accept the installation + panel.button.click(); + + await readyPromise; + + let policy = WebExtensionPolicy.getByID(addonId); + is( + policy.privateBrowsingAllowed, + allowPbm, + `Private browsing permission has ${allowPbm ? "" : "not "}been granted` + ); +} + +async function uninstall() { + const addon = await AddonManager.getAddonByID(addonId); + await addon.uninstall(); +} + +add_task(async function () { + is( + PrivateBrowsingUtils.permanentPrivateBrowsing, + true, + "We are in permanent PBM for this test" + ); + + xpi = AddonTestUtils.createTempWebExtensionFile({ + manifest: { + browser_specific_settings: { gecko: { id: addonId } }, + }, + }); + + await BrowserTestUtils.withNewTab({ gBrowser: window.gBrowser }, async () => { + // First run: install the addon for the first time. We do not let it run in + // PBM. + await testCheckbox(false, true); + // Second run: reinstall the already installed addon, to check the + // permission denial prevails on being in always-on PBM. + await testCheckbox(false, false); + }); + + await uninstall(); + + await BrowserTestUtils.withNewTab({ gBrowser: window.gBrowser }, async () => { + // Third run: install the addon for the first time, and let it run also in + // PBM. + await testCheckbox(true, true); + // Fourth run: reinstall the already installed addon, to check permission + // approval is persisted. + await testCheckbox(true, true); + }); + + await uninstall(); +}); ===================================== browser/modules/ExtensionsUI.sys.mjs ===================================== @@ -15,6 +15,7 @@ ChromeUtils.defineESModuleGetters(lazy, { AppMenuNotifications: "resource://gre/modules/AppMenuNotifications.sys.mjs", ExtensionData: "resource://gre/modules/Extension.sys.mjs", ExtensionPermissions: "resource://gre/modules/ExtensionPermissions.sys.mjs", + PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs", OriginControls: "resource://gre/modules/ExtensionPermissions.sys.mjs", QuarantinedDomains: "resource://gre/modules/ExtensionPermissions.sys.mjs", }); @@ -413,7 +414,8 @@ export var ExtensionsUI = { !!strings.dataCollectionPermissions?.collectsTechnicalAndInteractionData; const incognitoPermissionName = "internal:privateBrowsingAllowed"; - let grantPrivateBrowsingAllowed = false; + let grantPrivateBrowsingAllowed = + lazy.PrivateBrowsingUtils.permanentPrivateBrowsing; if (showIncognitoCheckbox) { let { permissions } = await lazy.ExtensionPermissions.get(addon.id); grantPrivateBrowsingAllowed = permissions.includes( View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/dc86ff0... -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/dc86ff0... You're receiving this email because of your account on gitlab.torproject.org.
participants (1)
-
Pier Angelo Vendrame (@pierov)