Bug 1960273 - Enable data collection permissions on all channels. r=rpl
Differential Revision: https://phabricator.services.mozilla.com/D247916
This commit is contained in:
committed by
wdurand@mozilla.com
parent
97ab9b4ec7
commit
b64515be3e
@@ -72,11 +72,7 @@ pref("extensions.langpacks.signatures.required", true);
|
|||||||
pref("xpinstall.signatures.required", true);
|
pref("xpinstall.signatures.required", true);
|
||||||
|
|
||||||
// Enable data collection permissions.
|
// Enable data collection permissions.
|
||||||
#ifdef NIGHTLY_BUILD
|
pref("extensions.dataCollectionPermissions.enabled", true);
|
||||||
pref("extensions.dataCollectionPermissions.enabled", true);
|
|
||||||
#else
|
|
||||||
pref("extensions.dataCollectionPermissions.enabled", false);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Dictionary download preference
|
// Dictionary download preference
|
||||||
pref("browser.dictionaries.download.url", "https://addons.mozilla.org/%LOCALE%/firefox/language-tools/");
|
pref("browser.dictionaries.download.url", "https://addons.mozilla.org/%LOCALE%/firefox/language-tools/");
|
||||||
|
|||||||
@@ -15,11 +15,10 @@ const WITH_INSTALL_PROMPT = [
|
|||||||
];
|
];
|
||||||
const NO_INSTALL_PROMPT = [["extensions.originControls.grantByDefault", false]];
|
const NO_INSTALL_PROMPT = [["extensions.originControls.grantByDefault", false]];
|
||||||
|
|
||||||
// TODO: Bug 1960273 - Update this test and remove this pref set when we enable
|
// TODO - Bug 1960551: Get rid of this once the pref is enabled in GeckoView.
|
||||||
// the data collection permissions on all channels.
|
|
||||||
Services.prefs.setBoolPref(
|
Services.prefs.setBoolPref(
|
||||||
"extensions.dataCollectionPermissions.enabled",
|
"extensions.dataCollectionPermissions.enabled",
|
||||||
false
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
// ExtensionParent.sys.mjs is being imported lazily because when it is imported Services.appinfo will be
|
// ExtensionParent.sys.mjs is being imported lazily because when it is imported Services.appinfo will be
|
||||||
@@ -363,6 +362,7 @@ async function test_permissions({
|
|||||||
let allPermissions = {
|
let allPermissions = {
|
||||||
permissions: [...REQUIRED_PERMISSIONS, ...OPTIONAL_PERMISSIONS],
|
permissions: [...REQUIRED_PERMISSIONS, ...OPTIONAL_PERMISSIONS],
|
||||||
origins: [...REQUIRED_ORIGINS_EXPECTED, ...OPTIONAL_ORIGINS_NORMALIZED],
|
origins: [...REQUIRED_ORIGINS_EXPECTED, ...OPTIONAL_ORIGINS_NORMALIZED],
|
||||||
|
data_collection: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
result = await call("getAll");
|
result = await call("getAll");
|
||||||
@@ -406,6 +406,7 @@ async function test_permissions({
|
|||||||
let perms = {
|
let perms = {
|
||||||
permissions: REQUIRED_PERMISSIONS,
|
permissions: REQUIRED_PERMISSIONS,
|
||||||
origins: [...REQUIRED_ORIGINS_EXPECTED, ...OPTIONAL_ORIGINS_NORMALIZED],
|
origins: [...REQUIRED_ORIGINS_EXPECTED, ...OPTIONAL_ORIGINS_NORMALIZED],
|
||||||
|
data_collection: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
result = await call("getAll");
|
result = await call("getAll");
|
||||||
@@ -579,7 +580,10 @@ add_task(async function test_startup() {
|
|||||||
|
|
||||||
async function checkPermissions(extension, permissions) {
|
async function checkPermissions(extension, permissions) {
|
||||||
perms = await extension.awaitMessage("perms");
|
perms = await extension.awaitMessage("perms");
|
||||||
let expect = Object.assign({ permissions: [], origins: [] }, permissions);
|
let expect = Object.assign(
|
||||||
|
{ permissions: [], origins: [], data_collection: [] },
|
||||||
|
permissions
|
||||||
|
);
|
||||||
deepEqual(perms, expect, "Extension got correct permissions on startup");
|
deepEqual(perms, expect, "Extension got correct permissions on startup");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,11 +20,9 @@ AddonTestUtils.createAppInfo(
|
|||||||
"42"
|
"42"
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO: Bug 1960273 - Update this test and remove this pref set when we enable
|
|
||||||
// the data collection permissions on all channels.
|
|
||||||
Services.prefs.setBoolPref(
|
Services.prefs.setBoolPref(
|
||||||
"extensions.dataCollectionPermissions.enabled",
|
"extensions.dataCollectionPermissions.enabled",
|
||||||
false
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
let OptionalPermissions;
|
let OptionalPermissions;
|
||||||
@@ -449,6 +447,7 @@ add_task(
|
|||||||
let permObj = {
|
let permObj = {
|
||||||
permissions: ["privacy"],
|
permissions: ["privacy"],
|
||||||
origins: [],
|
origins: [],
|
||||||
|
data_collection: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
// enable the permissions while the background is stopped
|
// enable the permissions while the background is stopped
|
||||||
@@ -544,462 +543,450 @@ add_task(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
add_task(
|
add_task(async function test_getAll_with_data_collection() {
|
||||||
{ pref_set: [["extensions.dataCollectionPermissions.enabled", true]] },
|
async function background() {
|
||||||
async function test_getAll_with_data_collection() {
|
browser.test.onMessage.addListener(async msg => {
|
||||||
async function background() {
|
browser.test.assertEq("getAll", msg, "expected correct message");
|
||||||
browser.test.onMessage.addListener(async msg => {
|
const permissions = await browser.permissions.getAll();
|
||||||
browser.test.assertEq("getAll", msg, "expected correct message");
|
browser.test.sendMessage("all", permissions);
|
||||||
const permissions = await browser.permissions.getAll();
|
});
|
||||||
browser.test.sendMessage("all", permissions);
|
|
||||||
});
|
|
||||||
|
|
||||||
browser.permissions.onAdded.addListener(details => {
|
browser.permissions.onAdded.addListener(details => {
|
||||||
browser.test.sendMessage("added", details);
|
browser.test.sendMessage("added", details);
|
||||||
});
|
});
|
||||||
|
|
||||||
browser.permissions.onRemoved.addListener(details => {
|
browser.permissions.onRemoved.addListener(details => {
|
||||||
browser.test.sendMessage("removed", details);
|
browser.test.sendMessage("removed", details);
|
||||||
});
|
});
|
||||||
|
|
||||||
browser.test.sendMessage("ready");
|
browser.test.sendMessage("ready");
|
||||||
}
|
}
|
||||||
|
|
||||||
const extension = ExtensionTestUtils.loadExtension({
|
const extension = ExtensionTestUtils.loadExtension({
|
||||||
manifest: {
|
manifest: {
|
||||||
manifest_version: 3,
|
manifest_version: 3,
|
||||||
permissions: ["bookmarks"],
|
permissions: ["bookmarks"],
|
||||||
browser_specific_settings: {
|
browser_specific_settings: {
|
||||||
gecko: {
|
gecko: {
|
||||||
data_collection_permissions: {
|
data_collection_permissions: {
|
||||||
// "none" shouldn't be added to the list of data collection
|
// "none" shouldn't be added to the list of data collection
|
||||||
// permissions returned by `getAll()`.
|
// permissions returned by `getAll()`.
|
||||||
required: ["none"],
|
required: ["none"],
|
||||||
optional: ["technicalAndInteraction", "locationInfo"],
|
optional: ["technicalAndInteraction", "locationInfo"],
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
background,
|
},
|
||||||
});
|
background,
|
||||||
await extension.startup();
|
});
|
||||||
await extension.awaitMessage("ready");
|
await extension.startup();
|
||||||
|
await extension.awaitMessage("ready");
|
||||||
|
|
||||||
const getAllAndVerifyDataCollection = async expected => {
|
const getAllAndVerifyDataCollection = async expected => {
|
||||||
extension.sendMessage("getAll");
|
extension.sendMessage("getAll");
|
||||||
const permissions = await extension.awaitMessage("all");
|
const permissions = await extension.awaitMessage("all");
|
||||||
Assert.deepEqual(
|
Assert.deepEqual(
|
||||||
permissions,
|
permissions,
|
||||||
{
|
{
|
||||||
permissions: ["bookmarks"],
|
permissions: ["bookmarks"],
|
||||||
origins: [],
|
origins: [],
|
||||||
data_collection: expected,
|
data_collection: expected,
|
||||||
},
|
},
|
||||||
"expected permissions with data collection"
|
"expected permissions with data collection"
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Pretend the T&I permission was granted at install time.
|
// Pretend the T&I permission was granted at install time.
|
||||||
let perms = {
|
let perms = {
|
||||||
|
permissions: [],
|
||||||
|
origins: [],
|
||||||
|
data_collection: ["technicalAndInteraction"],
|
||||||
|
};
|
||||||
|
await ExtensionPermissions.add(extension.id, perms, extension.extension);
|
||||||
|
let added = await extension.awaitMessage("added");
|
||||||
|
Assert.deepEqual(
|
||||||
|
added,
|
||||||
|
{
|
||||||
permissions: [],
|
permissions: [],
|
||||||
origins: [],
|
origins: [],
|
||||||
data_collection: ["technicalAndInteraction"],
|
data_collection: ["technicalAndInteraction"],
|
||||||
};
|
},
|
||||||
await ExtensionPermissions.add(extension.id, perms, extension.extension);
|
"expected new permissions granted"
|
||||||
let added = await extension.awaitMessage("added");
|
);
|
||||||
Assert.deepEqual(
|
await getAllAndVerifyDataCollection(["technicalAndInteraction"]);
|
||||||
added,
|
|
||||||
{
|
|
||||||
permissions: [],
|
|
||||||
origins: [],
|
|
||||||
data_collection: ["technicalAndInteraction"],
|
|
||||||
},
|
|
||||||
"expected new permissions granted"
|
|
||||||
);
|
|
||||||
await getAllAndVerifyDataCollection(["technicalAndInteraction"]);
|
|
||||||
|
|
||||||
// Grant another optional data collection permission.
|
// Grant another optional data collection permission.
|
||||||
perms = {
|
perms = {
|
||||||
|
permissions: [],
|
||||||
|
origins: [],
|
||||||
|
data_collection: ["technicalAndInteraction", "locationInfo"],
|
||||||
|
};
|
||||||
|
await ExtensionPermissions.add(extension.id, perms, extension.extension);
|
||||||
|
added = await extension.awaitMessage("added");
|
||||||
|
Assert.deepEqual(
|
||||||
|
added,
|
||||||
|
{
|
||||||
|
permissions: [],
|
||||||
|
origins: [],
|
||||||
|
data_collection: ["locationInfo"],
|
||||||
|
},
|
||||||
|
"expected new permissions granted"
|
||||||
|
);
|
||||||
|
await getAllAndVerifyDataCollection([
|
||||||
|
"technicalAndInteraction",
|
||||||
|
"locationInfo",
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Revoke all optional data collection permissions.
|
||||||
|
await ExtensionPermissions.remove(extension.id, perms, extension.extension);
|
||||||
|
const removed = await extension.awaitMessage("removed");
|
||||||
|
Assert.deepEqual(
|
||||||
|
removed,
|
||||||
|
{
|
||||||
permissions: [],
|
permissions: [],
|
||||||
origins: [],
|
origins: [],
|
||||||
data_collection: ["technicalAndInteraction", "locationInfo"],
|
data_collection: ["technicalAndInteraction", "locationInfo"],
|
||||||
};
|
},
|
||||||
await ExtensionPermissions.add(extension.id, perms, extension.extension);
|
"expected permissions revoked"
|
||||||
added = await extension.awaitMessage("added");
|
);
|
||||||
Assert.deepEqual(
|
await getAllAndVerifyDataCollection([]);
|
||||||
added,
|
|
||||||
{
|
|
||||||
permissions: [],
|
|
||||||
origins: [],
|
|
||||||
data_collection: ["locationInfo"],
|
|
||||||
},
|
|
||||||
"expected new permissions granted"
|
|
||||||
);
|
|
||||||
await getAllAndVerifyDataCollection([
|
|
||||||
"technicalAndInteraction",
|
|
||||||
"locationInfo",
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Revoke all optional data collection permissions.
|
await extension.unload();
|
||||||
await ExtensionPermissions.remove(extension.id, perms, extension.extension);
|
});
|
||||||
const removed = await extension.awaitMessage("removed");
|
|
||||||
Assert.deepEqual(
|
|
||||||
removed,
|
|
||||||
{
|
|
||||||
permissions: [],
|
|
||||||
origins: [],
|
|
||||||
data_collection: ["technicalAndInteraction", "locationInfo"],
|
|
||||||
},
|
|
||||||
"expected permissions revoked"
|
|
||||||
);
|
|
||||||
await getAllAndVerifyDataCollection([]);
|
|
||||||
|
|
||||||
await extension.unload();
|
add_task(async function test_getAll_with_required_data_collection() {
|
||||||
|
async function background() {
|
||||||
|
browser.test.onMessage.addListener(async msg => {
|
||||||
|
browser.test.assertEq("getAll", msg, "expected correct message");
|
||||||
|
const permissions = await browser.permissions.getAll();
|
||||||
|
browser.test.sendMessage("all", permissions);
|
||||||
|
});
|
||||||
|
|
||||||
|
browser.test.sendMessage("ready");
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
|
||||||
add_task(
|
const extension = ExtensionTestUtils.loadExtension({
|
||||||
{ pref_set: [["extensions.dataCollectionPermissions.enabled", true]] },
|
manifest: {
|
||||||
async function test_getAll_with_required_data_collection() {
|
manifest_version: 3,
|
||||||
async function background() {
|
permissions: ["bookmarks"],
|
||||||
browser.test.onMessage.addListener(async msg => {
|
browser_specific_settings: {
|
||||||
browser.test.assertEq("getAll", msg, "expected correct message");
|
gecko: {
|
||||||
const permissions = await browser.permissions.getAll();
|
data_collection_permissions: {
|
||||||
browser.test.sendMessage("all", permissions);
|
required: ["bookmarksInfo"],
|
||||||
});
|
optional: ["technicalAndInteraction", "locationInfo"],
|
||||||
|
|
||||||
browser.test.sendMessage("ready");
|
|
||||||
}
|
|
||||||
|
|
||||||
const extension = ExtensionTestUtils.loadExtension({
|
|
||||||
manifest: {
|
|
||||||
manifest_version: 3,
|
|
||||||
permissions: ["bookmarks"],
|
|
||||||
browser_specific_settings: {
|
|
||||||
gecko: {
|
|
||||||
data_collection_permissions: {
|
|
||||||
required: ["bookmarksInfo"],
|
|
||||||
optional: ["technicalAndInteraction", "locationInfo"],
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
background,
|
},
|
||||||
|
background,
|
||||||
|
});
|
||||||
|
await extension.startup();
|
||||||
|
await extension.awaitMessage("ready");
|
||||||
|
|
||||||
|
extension.sendMessage("getAll");
|
||||||
|
let permissions = await extension.awaitMessage("all");
|
||||||
|
Assert.deepEqual(
|
||||||
|
permissions,
|
||||||
|
{
|
||||||
|
permissions: ["bookmarks"],
|
||||||
|
origins: [],
|
||||||
|
data_collection: ["bookmarksInfo"],
|
||||||
|
},
|
||||||
|
"expected permissions with required data collection"
|
||||||
|
);
|
||||||
|
|
||||||
|
let perms = {
|
||||||
|
permissions: [],
|
||||||
|
origins: [],
|
||||||
|
data_collection: ["technicalAndInteraction"],
|
||||||
|
};
|
||||||
|
await ExtensionPermissions.add(extension.id, perms, extension.extension);
|
||||||
|
extension.sendMessage("getAll");
|
||||||
|
permissions = await extension.awaitMessage("all");
|
||||||
|
Assert.deepEqual(
|
||||||
|
permissions,
|
||||||
|
{
|
||||||
|
permissions: ["bookmarks"],
|
||||||
|
origins: [],
|
||||||
|
data_collection: ["bookmarksInfo", "technicalAndInteraction"],
|
||||||
|
},
|
||||||
|
"expected permissions with newly added data collection"
|
||||||
|
);
|
||||||
|
|
||||||
|
await extension.unload();
|
||||||
|
});
|
||||||
|
|
||||||
|
add_task(async function test_request_with_data_collection() {
|
||||||
|
async function background() {
|
||||||
|
browser.test.onMessage.addListener(async msg => {
|
||||||
|
if (msg === "request-good") {
|
||||||
|
await browser.permissions.request({
|
||||||
|
data_collection: ["technicalAndInteraction"],
|
||||||
|
});
|
||||||
|
|
||||||
|
const permissions = await browser.permissions.getAll();
|
||||||
|
browser.test.sendMessage(`${msg}:done`, permissions);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg === "request-invalid") {
|
||||||
|
try {
|
||||||
|
browser.permissions.request({
|
||||||
|
data_collection: ["invalid-permission"],
|
||||||
|
});
|
||||||
|
browser.test.fail("expected error");
|
||||||
|
} catch (err) {
|
||||||
|
browser.test.assertTrue(
|
||||||
|
/Error processing data_collection.0: Value "invalid-permission" must either:/.test(
|
||||||
|
err.message
|
||||||
|
),
|
||||||
|
"expected error"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
browser.test.sendMessage(`${msg}:done`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg === "request-bad") {
|
||||||
|
await browser.test.assertRejects(
|
||||||
|
browser.permissions.request({
|
||||||
|
data_collection: ["healthInfo"],
|
||||||
|
}),
|
||||||
|
/Cannot request data collection permission healthInfo since it was not declared in data_collection_permissions.optional/,
|
||||||
|
"Expected rejection"
|
||||||
|
);
|
||||||
|
browser.test.sendMessage(`${msg}:done`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
browser.test.fail(`Got unexpected msg "${msg}"`);
|
||||||
});
|
});
|
||||||
await extension.startup();
|
|
||||||
await extension.awaitMessage("ready");
|
|
||||||
|
|
||||||
extension.sendMessage("getAll");
|
browser.test.sendMessage("ready");
|
||||||
let permissions = await extension.awaitMessage("all");
|
}
|
||||||
Assert.deepEqual(
|
|
||||||
permissions,
|
const extension = ExtensionTestUtils.loadExtension({
|
||||||
{
|
manifest: {
|
||||||
permissions: ["bookmarks"],
|
manifest_version: 2,
|
||||||
origins: [],
|
browser_specific_settings: {
|
||||||
data_collection: ["bookmarksInfo"],
|
gecko: {
|
||||||
|
data_collection_permissions: {
|
||||||
|
optional: ["technicalAndInteraction", "locationInfo"],
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"expected permissions with required data collection"
|
},
|
||||||
);
|
background,
|
||||||
|
});
|
||||||
|
await extension.startup();
|
||||||
|
await extension.awaitMessage("ready");
|
||||||
|
|
||||||
let perms = {
|
await withHandlingUserInput(extension, async () => {
|
||||||
|
extension.sendMessage("request-bad");
|
||||||
|
await extension.awaitMessage("request-bad:done");
|
||||||
|
});
|
||||||
|
|
||||||
|
await withHandlingUserInput(extension, async () => {
|
||||||
|
extension.sendMessage("request-invalid");
|
||||||
|
await extension.awaitMessage("request-invalid:done");
|
||||||
|
});
|
||||||
|
|
||||||
|
let permissions;
|
||||||
|
await withHandlingUserInput(extension, async () => {
|
||||||
|
extension.sendMessage("request-good");
|
||||||
|
permissions = await extension.awaitMessage("request-good:done");
|
||||||
|
});
|
||||||
|
Assert.deepEqual(
|
||||||
|
permissions,
|
||||||
|
{
|
||||||
permissions: [],
|
permissions: [],
|
||||||
origins: [],
|
origins: [],
|
||||||
data_collection: ["technicalAndInteraction"],
|
data_collection: ["technicalAndInteraction"],
|
||||||
};
|
},
|
||||||
await ExtensionPermissions.add(extension.id, perms, extension.extension);
|
"expected permissions with data collection"
|
||||||
extension.sendMessage("getAll");
|
);
|
||||||
permissions = await extension.awaitMessage("all");
|
|
||||||
Assert.deepEqual(
|
|
||||||
permissions,
|
|
||||||
{
|
|
||||||
permissions: ["bookmarks"],
|
|
||||||
origins: [],
|
|
||||||
data_collection: ["bookmarksInfo", "technicalAndInteraction"],
|
|
||||||
},
|
|
||||||
"expected permissions with newly added data collection"
|
|
||||||
);
|
|
||||||
|
|
||||||
await extension.unload();
|
// Reequest the same permission again, which should be already granted.
|
||||||
|
await withHandlingUserInput(extension, async () => {
|
||||||
|
extension.sendMessage("request-good");
|
||||||
|
permissions = await extension.awaitMessage("request-good:done");
|
||||||
|
});
|
||||||
|
Assert.deepEqual(
|
||||||
|
permissions,
|
||||||
|
{
|
||||||
|
permissions: [],
|
||||||
|
origins: [],
|
||||||
|
data_collection: ["technicalAndInteraction"],
|
||||||
|
},
|
||||||
|
"expected permissions with data collection"
|
||||||
|
);
|
||||||
|
|
||||||
|
await extension.unload();
|
||||||
|
});
|
||||||
|
|
||||||
|
add_task(async function test_contains_data_collection() {
|
||||||
|
async function background() {
|
||||||
|
browser.test.onMessage.addListener(async (msg, arg) => {
|
||||||
|
if (msg === "contains") {
|
||||||
|
const result = await browser.permissions.contains(arg);
|
||||||
|
browser.test.sendMessage(`${msg}:done`, result);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg === "request") {
|
||||||
|
await browser.permissions.request(arg);
|
||||||
|
browser.test.sendMessage(`${msg}:done`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg === "remove") {
|
||||||
|
await browser.permissions.remove(arg);
|
||||||
|
browser.test.sendMessage(`${msg}:done`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
browser.test.fail(`Got unexpected msg "${msg}"`);
|
||||||
|
});
|
||||||
|
|
||||||
|
browser.test.sendMessage("ready");
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
|
||||||
add_task(
|
const extension = ExtensionTestUtils.loadExtension({
|
||||||
{ pref_set: [["extensions.dataCollectionPermissions.enabled", true]] },
|
manifest: {
|
||||||
async function test_request_with_data_collection() {
|
manifest_version: 2,
|
||||||
async function background() {
|
optional_permissions: ["bookmarks", "http://*.mozilla.org/*"],
|
||||||
browser.test.onMessage.addListener(async msg => {
|
browser_specific_settings: {
|
||||||
if (msg === "request-good") {
|
gecko: {
|
||||||
await browser.permissions.request({
|
data_collection_permissions: {
|
||||||
data_collection: ["technicalAndInteraction"],
|
optional: ["technicalAndInteraction", "locationInfo"],
|
||||||
});
|
|
||||||
|
|
||||||
const permissions = await browser.permissions.getAll();
|
|
||||||
browser.test.sendMessage(`${msg}:done`, permissions);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg === "request-invalid") {
|
|
||||||
try {
|
|
||||||
browser.permissions.request({
|
|
||||||
data_collection: ["invalid-permission"],
|
|
||||||
});
|
|
||||||
browser.test.fail("expected error");
|
|
||||||
} catch (err) {
|
|
||||||
browser.test.assertTrue(
|
|
||||||
/Error processing data_collection.0: Value "invalid-permission" must either:/.test(
|
|
||||||
err.message
|
|
||||||
),
|
|
||||||
"expected error"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
browser.test.sendMessage(`${msg}:done`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg === "request-bad") {
|
|
||||||
await browser.test.assertRejects(
|
|
||||||
browser.permissions.request({
|
|
||||||
data_collection: ["healthInfo"],
|
|
||||||
}),
|
|
||||||
/Cannot request data collection permission healthInfo since it was not declared in data_collection_permissions.optional/,
|
|
||||||
"Expected rejection"
|
|
||||||
);
|
|
||||||
browser.test.sendMessage(`${msg}:done`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
browser.test.fail(`Got unexpected msg "${msg}"`);
|
|
||||||
});
|
|
||||||
|
|
||||||
browser.test.sendMessage("ready");
|
|
||||||
}
|
|
||||||
|
|
||||||
const extension = ExtensionTestUtils.loadExtension({
|
|
||||||
manifest: {
|
|
||||||
manifest_version: 2,
|
|
||||||
browser_specific_settings: {
|
|
||||||
gecko: {
|
|
||||||
data_collection_permissions: {
|
|
||||||
optional: ["technicalAndInteraction", "locationInfo"],
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
background,
|
},
|
||||||
});
|
background,
|
||||||
await extension.startup();
|
});
|
||||||
await extension.awaitMessage("ready");
|
await extension.startup();
|
||||||
|
await extension.awaitMessage("ready");
|
||||||
|
|
||||||
await withHandlingUserInput(extension, async () => {
|
// A list of permission objects with various combination of api/data
|
||||||
extension.sendMessage("request-bad");
|
// collection permissions and origins. This will be used in different
|
||||||
await extension.awaitMessage("request-bad:done");
|
// assertions below.
|
||||||
});
|
const PERMS = [
|
||||||
|
{ permissions: ["bookmarks"] },
|
||||||
await withHandlingUserInput(extension, async () => {
|
{ origins: ["http://*.mozilla.org/*"] },
|
||||||
extension.sendMessage("request-invalid");
|
{ permissions: ["bookmarks"], origins: ["http://*.mozilla.org/*"] },
|
||||||
await extension.awaitMessage("request-invalid:done");
|
{ data_collection: ["technicalAndInteraction"] },
|
||||||
});
|
{ data_collection: ["locationInfo"] },
|
||||||
|
{ data_collection: ["technicalAndInteraction", "locationInfo"] },
|
||||||
let permissions;
|
{
|
||||||
await withHandlingUserInput(extension, async () => {
|
|
||||||
extension.sendMessage("request-good");
|
|
||||||
permissions = await extension.awaitMessage("request-good:done");
|
|
||||||
});
|
|
||||||
Assert.deepEqual(
|
|
||||||
permissions,
|
|
||||||
{
|
|
||||||
permissions: [],
|
|
||||||
origins: [],
|
|
||||||
data_collection: ["technicalAndInteraction"],
|
|
||||||
},
|
|
||||||
"expected permissions with data collection"
|
|
||||||
);
|
|
||||||
|
|
||||||
// Reequest the same permission again, which should be already granted.
|
|
||||||
await withHandlingUserInput(extension, async () => {
|
|
||||||
extension.sendMessage("request-good");
|
|
||||||
permissions = await extension.awaitMessage("request-good:done");
|
|
||||||
});
|
|
||||||
Assert.deepEqual(
|
|
||||||
permissions,
|
|
||||||
{
|
|
||||||
permissions: [],
|
|
||||||
origins: [],
|
|
||||||
data_collection: ["technicalAndInteraction"],
|
|
||||||
},
|
|
||||||
"expected permissions with data collection"
|
|
||||||
);
|
|
||||||
|
|
||||||
await extension.unload();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
add_task(
|
|
||||||
{ pref_set: [["extensions.dataCollectionPermissions.enabled", true]] },
|
|
||||||
async function test_contains_data_collection() {
|
|
||||||
async function background() {
|
|
||||||
browser.test.onMessage.addListener(async (msg, arg) => {
|
|
||||||
if (msg === "contains") {
|
|
||||||
const result = await browser.permissions.contains(arg);
|
|
||||||
browser.test.sendMessage(`${msg}:done`, result);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg === "request") {
|
|
||||||
await browser.permissions.request(arg);
|
|
||||||
browser.test.sendMessage(`${msg}:done`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg === "remove") {
|
|
||||||
await browser.permissions.remove(arg);
|
|
||||||
browser.test.sendMessage(`${msg}:done`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
browser.test.fail(`Got unexpected msg "${msg}"`);
|
|
||||||
});
|
|
||||||
|
|
||||||
browser.test.sendMessage("ready");
|
|
||||||
}
|
|
||||||
|
|
||||||
const extension = ExtensionTestUtils.loadExtension({
|
|
||||||
manifest: {
|
|
||||||
manifest_version: 2,
|
|
||||||
optional_permissions: ["bookmarks", "http://*.mozilla.org/*"],
|
|
||||||
browser_specific_settings: {
|
|
||||||
gecko: {
|
|
||||||
data_collection_permissions: {
|
|
||||||
optional: ["technicalAndInteraction", "locationInfo"],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
background,
|
|
||||||
});
|
|
||||||
await extension.startup();
|
|
||||||
await extension.awaitMessage("ready");
|
|
||||||
|
|
||||||
// A list of permission objects with various combination of api/data
|
|
||||||
// collection permissions and origins. This will be used in different
|
|
||||||
// assertions below.
|
|
||||||
const PERMS = [
|
|
||||||
{ permissions: ["bookmarks"] },
|
|
||||||
{ origins: ["http://*.mozilla.org/*"] },
|
|
||||||
{ permissions: ["bookmarks"], origins: ["http://*.mozilla.org/*"] },
|
|
||||||
{ data_collection: ["technicalAndInteraction"] },
|
|
||||||
{ data_collection: ["locationInfo"] },
|
|
||||||
{ data_collection: ["technicalAndInteraction", "locationInfo"] },
|
|
||||||
{
|
|
||||||
permissions: ["bookmarks"],
|
|
||||||
data_collection: ["technicalAndInteraction", "locationInfo"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
permissions: ["bookmarks"],
|
|
||||||
data_collection: ["locationInfo"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
permissions: ["bookmarks"],
|
|
||||||
origins: ["http://*.mozilla.org/*"],
|
|
||||||
data_collection: ["technicalAndInteraction", "locationInfo"],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
let result;
|
|
||||||
for (const perms of PERMS) {
|
|
||||||
extension.sendMessage("contains", perms);
|
|
||||||
result = await extension.awaitMessage("contains:done");
|
|
||||||
ok(!result, "Expected permission to not be granted");
|
|
||||||
}
|
|
||||||
|
|
||||||
info("request a single data collection permission");
|
|
||||||
await withHandlingUserInput(extension, async () => {
|
|
||||||
extension.sendMessage("request", {
|
|
||||||
data_collection: ["technicalAndInteraction"],
|
|
||||||
});
|
|
||||||
await extension.awaitMessage("request:done");
|
|
||||||
});
|
|
||||||
|
|
||||||
extension.sendMessage("contains", {
|
|
||||||
data_collection: ["technicalAndInteraction"],
|
|
||||||
});
|
|
||||||
result = await extension.awaitMessage("contains:done");
|
|
||||||
ok(result, "Expected permission to be granted");
|
|
||||||
|
|
||||||
extension.sendMessage("contains", {
|
|
||||||
permissions: ["bookmarks"],
|
permissions: ["bookmarks"],
|
||||||
data_collection: ["technicalAndInteraction"],
|
data_collection: ["technicalAndInteraction", "locationInfo"],
|
||||||
});
|
},
|
||||||
result = await extension.awaitMessage("contains:done");
|
{
|
||||||
ok(!result, "Expected false because bookmarks isn't granted");
|
permissions: ["bookmarks"],
|
||||||
|
data_collection: ["locationInfo"],
|
||||||
info("request an API permission");
|
},
|
||||||
await withHandlingUserInput(extension, async () => {
|
{
|
||||||
extension.sendMessage("request", {
|
|
||||||
permissions: ["bookmarks"],
|
|
||||||
});
|
|
||||||
await extension.awaitMessage("request:done");
|
|
||||||
});
|
|
||||||
|
|
||||||
extension.sendMessage("contains", {
|
|
||||||
permissions: ["bookmarks"],
|
permissions: ["bookmarks"],
|
||||||
data_collection: ["technicalAndInteraction"],
|
|
||||||
});
|
|
||||||
result = await extension.awaitMessage("contains:done");
|
|
||||||
ok(result, "Expected permissions to be granted");
|
|
||||||
|
|
||||||
extension.sendMessage("contains", {
|
|
||||||
origins: ["http://*.mozilla.org/*"],
|
origins: ["http://*.mozilla.org/*"],
|
||||||
data_collection: ["technicalAndInteraction"],
|
data_collection: ["technicalAndInteraction", "locationInfo"],
|
||||||
});
|
},
|
||||||
result = await extension.awaitMessage("contains:done");
|
];
|
||||||
ok(!result, "Expected false because origin isn't granted");
|
|
||||||
|
|
||||||
info("remove data collection permission");
|
let result;
|
||||||
extension.sendMessage("remove", {
|
for (const perms of PERMS) {
|
||||||
data_collection: ["technicalAndInteraction"],
|
extension.sendMessage("contains", perms);
|
||||||
});
|
|
||||||
await extension.awaitMessage("remove:done");
|
|
||||||
|
|
||||||
extension.sendMessage("contains", {
|
|
||||||
data_collection: ["technicalAndInteraction"],
|
|
||||||
});
|
|
||||||
result = await extension.awaitMessage("contains:done");
|
result = await extension.awaitMessage("contains:done");
|
||||||
ok(!result, "Expected permission to not be granted");
|
ok(!result, "Expected permission to not be granted");
|
||||||
|
}
|
||||||
|
|
||||||
info("request all optional permissions");
|
info("request a single data collection permission");
|
||||||
await withHandlingUserInput(extension, async () => {
|
await withHandlingUserInput(extension, async () => {
|
||||||
extension.sendMessage("request", {
|
extension.sendMessage("request", {
|
||||||
permissions: ["bookmarks"],
|
data_collection: ["technicalAndInteraction"],
|
||||||
origins: ["http://*.mozilla.org/*"],
|
|
||||||
data_collection: ["technicalAndInteraction", "locationInfo"],
|
|
||||||
});
|
|
||||||
await extension.awaitMessage("request:done");
|
|
||||||
});
|
});
|
||||||
|
await extension.awaitMessage("request:done");
|
||||||
|
});
|
||||||
|
|
||||||
for (const perms of PERMS) {
|
extension.sendMessage("contains", {
|
||||||
extension.sendMessage("contains", perms);
|
data_collection: ["technicalAndInteraction"],
|
||||||
result = await extension.awaitMessage("contains:done");
|
});
|
||||||
ok(result, "Expected permission to be granted");
|
result = await extension.awaitMessage("contains:done");
|
||||||
}
|
ok(result, "Expected permission to be granted");
|
||||||
|
|
||||||
info("remove all");
|
extension.sendMessage("contains", {
|
||||||
extension.sendMessage("remove", {
|
permissions: ["bookmarks"],
|
||||||
|
data_collection: ["technicalAndInteraction"],
|
||||||
|
});
|
||||||
|
result = await extension.awaitMessage("contains:done");
|
||||||
|
ok(!result, "Expected false because bookmarks isn't granted");
|
||||||
|
|
||||||
|
info("request an API permission");
|
||||||
|
await withHandlingUserInput(extension, async () => {
|
||||||
|
extension.sendMessage("request", {
|
||||||
|
permissions: ["bookmarks"],
|
||||||
|
});
|
||||||
|
await extension.awaitMessage("request:done");
|
||||||
|
});
|
||||||
|
|
||||||
|
extension.sendMessage("contains", {
|
||||||
|
permissions: ["bookmarks"],
|
||||||
|
data_collection: ["technicalAndInteraction"],
|
||||||
|
});
|
||||||
|
result = await extension.awaitMessage("contains:done");
|
||||||
|
ok(result, "Expected permissions to be granted");
|
||||||
|
|
||||||
|
extension.sendMessage("contains", {
|
||||||
|
origins: ["http://*.mozilla.org/*"],
|
||||||
|
data_collection: ["technicalAndInteraction"],
|
||||||
|
});
|
||||||
|
result = await extension.awaitMessage("contains:done");
|
||||||
|
ok(!result, "Expected false because origin isn't granted");
|
||||||
|
|
||||||
|
info("remove data collection permission");
|
||||||
|
extension.sendMessage("remove", {
|
||||||
|
data_collection: ["technicalAndInteraction"],
|
||||||
|
});
|
||||||
|
await extension.awaitMessage("remove:done");
|
||||||
|
|
||||||
|
extension.sendMessage("contains", {
|
||||||
|
data_collection: ["technicalAndInteraction"],
|
||||||
|
});
|
||||||
|
result = await extension.awaitMessage("contains:done");
|
||||||
|
ok(!result, "Expected permission to not be granted");
|
||||||
|
|
||||||
|
info("request all optional permissions");
|
||||||
|
await withHandlingUserInput(extension, async () => {
|
||||||
|
extension.sendMessage("request", {
|
||||||
permissions: ["bookmarks"],
|
permissions: ["bookmarks"],
|
||||||
origins: ["http://*.mozilla.org/*"],
|
origins: ["http://*.mozilla.org/*"],
|
||||||
data_collection: ["technicalAndInteraction", "locationInfo"],
|
data_collection: ["technicalAndInteraction", "locationInfo"],
|
||||||
});
|
});
|
||||||
await extension.awaitMessage("remove:done");
|
await extension.awaitMessage("request:done");
|
||||||
|
});
|
||||||
|
|
||||||
for (const perms of PERMS) {
|
for (const perms of PERMS) {
|
||||||
extension.sendMessage("contains", perms);
|
extension.sendMessage("contains", perms);
|
||||||
result = await extension.awaitMessage("contains:done");
|
result = await extension.awaitMessage("contains:done");
|
||||||
ok(!result, "Expected permission to not be granted");
|
ok(result, "Expected permission to be granted");
|
||||||
}
|
|
||||||
|
|
||||||
await extension.unload();
|
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
info("remove all");
|
||||||
|
extension.sendMessage("remove", {
|
||||||
|
permissions: ["bookmarks"],
|
||||||
|
origins: ["http://*.mozilla.org/*"],
|
||||||
|
data_collection: ["technicalAndInteraction", "locationInfo"],
|
||||||
|
});
|
||||||
|
await extension.awaitMessage("remove:done");
|
||||||
|
|
||||||
|
for (const perms of PERMS) {
|
||||||
|
extension.sendMessage("contains", perms);
|
||||||
|
result = await extension.awaitMessage("contains:done");
|
||||||
|
ok(!result, "Expected permission to not be granted");
|
||||||
|
}
|
||||||
|
|
||||||
|
await extension.unload();
|
||||||
|
});
|
||||||
|
|
||||||
// This test verifies that data collection permissions are taken into account when
|
// This test verifies that data collection permissions are taken into account when
|
||||||
// an extension is installed before the `extensions.dataCollectionPermissions.enabled`
|
// an extension is installed before the `extensions.dataCollectionPermissions.enabled`
|
||||||
|
|||||||
@@ -14,6 +14,11 @@ const { PERMISSION_L10N, PERMISSION_L10N_ID_OVERRIDES } =
|
|||||||
|
|
||||||
AddonTestUtils.initMochitest(this);
|
AddonTestUtils.initMochitest(this);
|
||||||
|
|
||||||
|
Services.prefs.setBoolPref(
|
||||||
|
"extensions.dataCollectionPermissions.enabled",
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
const addonsBundle = new Localization(["toolkit/about/aboutAddons.ftl"], true);
|
const addonsBundle = new Localization(["toolkit/about/aboutAddons.ftl"], true);
|
||||||
|
|
||||||
const assertVisibleSections = async (permsSection, expectedHeaders) => {
|
const assertVisibleSections = async (permsSection, expectedHeaders) => {
|
||||||
@@ -623,14 +628,6 @@ async function testPermissionsView({
|
|||||||
await SpecialPowers.popPrefEnv();
|
await SpecialPowers.popPrefEnv();
|
||||||
}
|
}
|
||||||
|
|
||||||
add_setup(async () => {
|
|
||||||
await SpecialPowers.pushPrefEnv({
|
|
||||||
// TODO: Bug 1960273 - Update this test and remove this pref set when we
|
|
||||||
// enable the data collection permissions on all channels.
|
|
||||||
set: [["extensions.dataCollectionPermissions.enabled", false]],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
add_task(async function testPermissionsView_MV2_manifestV3disabled() {
|
add_task(async function testPermissionsView_MV2_manifestV3disabled() {
|
||||||
await testPermissionsView({ manifestV3enabled: false, manifest_version: 2 });
|
await testPermissionsView({ manifestV3enabled: false, manifest_version: 2 });
|
||||||
});
|
});
|
||||||
@@ -920,6 +917,7 @@ add_task(async function test_OneOfMany_AllSites_toggle() {
|
|||||||
Assert.deepEqual(granted, {
|
Assert.deepEqual(granted, {
|
||||||
permissions: [],
|
permissions: [],
|
||||||
origins: ["http://*/*", "https://*/*"],
|
origins: ["http://*/*", "https://*/*"],
|
||||||
|
data_collection: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
await closeView(view);
|
await closeView(view);
|
||||||
@@ -1020,10 +1018,6 @@ webext-perms-description-test-tabs = Custom description for the tabs permission
|
|||||||
});
|
});
|
||||||
|
|
||||||
add_task(async function test_data_collection() {
|
add_task(async function test_data_collection() {
|
||||||
await SpecialPowers.pushPrefEnv({
|
|
||||||
set: [["extensions.dataCollectionPermissions.enabled", true]],
|
|
||||||
});
|
|
||||||
|
|
||||||
const TEST_CASES = [
|
const TEST_CASES = [
|
||||||
{
|
{
|
||||||
title: "no permissions",
|
title: "no permissions",
|
||||||
@@ -1453,15 +1447,9 @@ add_task(async function test_data_collection() {
|
|||||||
await closeView(view);
|
await closeView(view);
|
||||||
await extension.unload();
|
await extension.unload();
|
||||||
}
|
}
|
||||||
|
|
||||||
await SpecialPowers.popPrefEnv();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
add_task(async function test_data_collection_and_disabled_extension() {
|
add_task(async function test_data_collection_and_disabled_extension() {
|
||||||
await SpecialPowers.pushPrefEnv({
|
|
||||||
set: [["extensions.dataCollectionPermissions.enabled", true]],
|
|
||||||
});
|
|
||||||
|
|
||||||
const extensionId = "@some-id";
|
const extensionId = "@some-id";
|
||||||
const extension = ExtensionTestUtils.loadExtension({
|
const extension = ExtensionTestUtils.loadExtension({
|
||||||
manifest: {
|
manifest: {
|
||||||
@@ -1533,6 +1521,4 @@ add_task(async function test_data_collection_and_disabled_extension() {
|
|||||||
|
|
||||||
await closeView(view);
|
await closeView(view);
|
||||||
await extension.unload();
|
await extension.unload();
|
||||||
|
|
||||||
await SpecialPowers.popPrefEnv();
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -15,9 +15,7 @@ add_setup(async () => {
|
|||||||
await SpecialPowers.pushPrefEnv({
|
await SpecialPowers.pushPrefEnv({
|
||||||
set: [
|
set: [
|
||||||
["extensions.userScripts.mv3.enabled", true],
|
["extensions.userScripts.mv3.enabled", true],
|
||||||
// TODO: Bug 1960273 - Update this test and remove this pref set when we
|
["extensions.dataCollectionPermissions.enabled", true],
|
||||||
// enable the data collection permissions on all channels.
|
|
||||||
["extensions.dataCollectionPermissions.enabled", false],
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -33,7 +31,7 @@ function loadUserScriptsExtension(addonId) {
|
|||||||
background() {
|
background() {
|
||||||
browser.permissions.onAdded.addListener(perms => {
|
browser.permissions.onAdded.addListener(perms => {
|
||||||
browser.test.assertDeepEq(
|
browser.test.assertDeepEq(
|
||||||
{ permissions: ["userScripts"], origins: [] },
|
{ permissions: ["userScripts"], origins: [], data_collection: [] },
|
||||||
perms,
|
perms,
|
||||||
"permissions.onAdded for userScripts permission"
|
"permissions.onAdded for userScripts permission"
|
||||||
);
|
);
|
||||||
@@ -42,7 +40,7 @@ function loadUserScriptsExtension(addonId) {
|
|||||||
});
|
});
|
||||||
browser.permissions.onRemoved.addListener(perms => {
|
browser.permissions.onRemoved.addListener(perms => {
|
||||||
browser.test.assertDeepEq(
|
browser.test.assertDeepEq(
|
||||||
{ permissions: ["userScripts"], origins: [] },
|
{ permissions: ["userScripts"], origins: [], data_collection: [] },
|
||||||
perms,
|
perms,
|
||||||
"permissions.onRemoved for userScripts permission"
|
"permissions.onRemoved for userScripts permission"
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user