Bug 1959534 - T&I checkbox should be checked by default. r=rpl

Differential Revision: https://phabricator.services.mozilla.com/D245443
This commit is contained in:
William Durand
2025-04-16 14:25:29 +00:00
parent 8e299a4727
commit e252c25099
3 changed files with 191 additions and 18 deletions

View File

@@ -412,27 +412,18 @@ export var ExtensionsUI = {
shouldShowTechnicalAndInteractionCheckbox &&
!!strings.dataCollectionPermissions?.collectsTechnicalAndInteractionData;
// Retrieve the permissions only once when we need them for one or both
// checkboxes.
let permissions;
if (showIncognitoCheckbox || showTechnicalAndInteractionCheckbox) {
permissions = await lazy.ExtensionPermissions.get(addon.id);
}
const incognitoPermissionName = "internal:privateBrowsingAllowed";
let grantPrivateBrowsingAllowed = false;
if (showIncognitoCheckbox) {
grantPrivateBrowsingAllowed = permissions.permissions.includes(
let { permissions } = await lazy.ExtensionPermissions.get(addon.id);
grantPrivateBrowsingAllowed = permissions.includes(
incognitoPermissionName
);
}
const technicalAndInteractionDataName = "technicalAndInteraction";
let grantTechnicalAndInteractionDataCollection = false;
if (showTechnicalAndInteractionCheckbox) {
grantTechnicalAndInteractionDataCollection =
permissions.data_collection.includes(technicalAndInteractionDataName);
}
// This is an opt-out setting.
let grantTechnicalAndInteractionDataCollection = true;
// Wait for any pending prompts to complete before showing the next one.
let pending;

View File

@@ -6,6 +6,7 @@ const { AddonTestUtils } = ChromeUtils.importESModule(
ChromeUtils.defineESModuleGetters(this, {
PERMISSION_L10N: "resource://gre/modules/ExtensionPermissionMessages.sys.mjs",
ExtensionPermissions: "resource://gre/modules/ExtensionPermissions.sys.mjs",
});
AddonTestUtils.initMochitest(this);
@@ -591,3 +592,80 @@ add_task(async function test_pending_update_with_no_prompted_permission() {
await SpecialPowers.popPrefEnv();
});
add_task(
async function test_pending_update_does_not_grant_technicalAndInteraction() {
await SpecialPowers.pushPrefEnv({
set: [["extensions.dataCollectionPermissions.enabled", true]],
});
const id = "@test-id";
const { extension } = createTestExtension({
id,
oldManifest: {
browser_specific_settings: {
gecko: {
id,
data_collection_permissions: {},
},
},
},
newManifest: {
permissions: ["bookmarks"],
browser_specific_settings: {
gecko: {
id,
data_collection_permissions: {
optional: ["technicalAndInteraction"],
},
},
},
},
});
await extension.startup();
await extension.awaitMessage("bgpage-ready");
const win = await loadInitialView("extension");
const dialogPromise = promisePopupNotificationShown(
"addon-webext-permissions"
);
win.checkForUpdates();
const popupContentEl = await dialogPromise;
// Confirm the update, and proceed.
const waitForManagementUpdate = new Promise(resolve => {
const { Management } = ChromeUtils.importESModule(
"resource://gre/modules/Extension.sys.mjs"
);
Management.once("update", resolve);
});
popupContentEl.button.click();
await promiseUpdateAvailable(extension);
await completePostponedUpdate({ id, win });
// Ensure that the bootstrap scope update method has been executed
// successfully and emitted the update Management event.
info("Wait for the Management update to be emitted");
await waitForManagementUpdate;
// This test verifies that we don't accidentally grant the
// "technicalAndInteraction" data collection permission on update because
// that's controlled by the `showTechnicalAndInteractionCheckbox` value in
// `ExtensionUI.showPermissionsPrompt()`.
const perms = await ExtensionPermissions.get(id);
Assert.deepEqual(
perms,
{
permissions: [],
origins: [],
data_collection: [],
},
"Expected no stored permission"
);
await closeView(win);
await extension.unload();
await SpecialPowers.popPrefEnv();
}
);

View File

@@ -14,6 +14,7 @@ const DEFAULT_THEME_ID = "default-theme@mozilla.org";
ChromeUtils.defineESModuleGetters(this, {
PERMISSION_L10N: "resource://gre/modules/ExtensionPermissionMessages.sys.mjs",
ExtensionPermissions: "resource://gre/modules/ExtensionPermissions.sys.mjs",
});
AddonTestUtils.initMochitest(this);
@@ -849,12 +850,11 @@ add_task(async function testInstallDialogShowsDataCollectionPermissions() {
2,
"Expected two permission entries in the list"
);
Assert.ok(
popupContentEl.permsListEl.querySelector(
"li.webext-data-collection-perm-optional > checkbox"
),
"Expected technical and interaction checkbox"
let checkbox = popupContentEl.permsListEl.querySelector(
"li.webext-data-collection-perm-optional > checkbox"
);
Assert.ok(checkbox, "Expected technical and interaction checkbox");
Assert.ok(checkbox.checked, "Expected checkbox to be checked");
Assert.equal(
popupContentEl.permsListEl.firstChild.textContent,
PERMISSION_L10N.formatValueSync(
@@ -1101,3 +1101,107 @@ add_task(async function testInstallDialogShowsDataCollectionPermissions() {
await SpecialPowers.popPrefEnv();
});
add_task(async function testTechnicalAndInteractionData() {
await SpecialPowers.pushPrefEnv({
set: [["extensions.dataCollectionPermissions.enabled", true]],
});
const extensionId = "@test-id";
const extension = AddonTestUtils.createTempWebExtensionFile({
manifest: {
version: "1.0",
browser_specific_settings: {
gecko: {
id: extensionId,
data_collection_permissions: {
optional: ["technicalAndInteraction"],
},
},
},
},
});
let perms = await ExtensionPermissions.get(extensionId);
Assert.deepEqual(
perms,
{ permissions: [], origins: [], data_collection: [] },
"Expected no permissions"
);
await BrowserTestUtils.withNewTab("about:blank", async () => {
const dialogPromise = promisePopupNotificationShown(
"addon-webext-permissions"
);
gURLBar.value = extension.path;
gURLBar.focus();
EventUtils.synthesizeKey("KEY_Enter");
const popupContentEl = await dialogPromise;
// Install the add-on.
let notificationPromise = acceptAppMenuNotificationWhenShown(
"addon-installed",
extensionId
);
popupContentEl.button.click();
await notificationPromise;
perms = await ExtensionPermissions.get(extensionId);
Assert.deepEqual(
perms,
{
permissions: [],
origins: [],
data_collection: ["technicalAndInteraction"],
},
"Expected data collection permission"
);
const addon = await AddonManager.getAddonByID(extensionId);
Assert.ok(addon, "Expected add-on");
await addon.uninstall();
});
// Repeat but uncheck the checkbox this time.
await BrowserTestUtils.withNewTab("about:blank", async () => {
const dialogPromise = promisePopupNotificationShown(
"addon-webext-permissions"
);
gURLBar.value = extension.path;
gURLBar.focus();
EventUtils.synthesizeKey("KEY_Enter");
const popupContentEl = await dialogPromise;
const checkboxEl = popupContentEl.permsListEl.querySelector(
"li.webext-data-collection-perm-optional > checkbox"
);
checkboxEl.click();
// Install the add-on.
let notificationPromise = acceptAppMenuNotificationWhenShown(
"addon-installed",
extensionId
);
popupContentEl.button.click();
await notificationPromise;
perms = await ExtensionPermissions.get(extensionId);
Assert.deepEqual(
perms,
{
permissions: [],
origins: [],
data_collection: [],
},
"Expected no data collection permission"
);
const addon = await AddonManager.getAddonByID(extensionId);
Assert.ok(addon, "Expected add-on");
await addon.uninstall();
});
await SpecialPowers.popPrefEnv();
});