Bug 1538546 - Hide incognito checkbox in addon-installed notification for not_allowed extensions. r=mixedpuppy,kmag

Differential Revision: https://phabricator.services.mozilla.com/D24719

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Luca Greco 2019-03-26 18:31:57 +00:00
parent f12d23ae3d
commit 6ae82211f6
7 changed files with 120 additions and 17 deletions

View File

@ -455,7 +455,7 @@ var ExtensionsUI = {
function setCheckbox(win) {
let checkbox = win.document.getElementById("addon-incognito-checkbox");
checkbox.checked = false;
checkbox.hidden = allowPrivateBrowsingByDefault || addon.type !== "extension";
checkbox.hidden = !(addon.permissions & AddonManager.PERM_CAN_CHANGE_PRIVATEBROWSING_ACCESS);
}
setCheckbox(window);

View File

@ -40,6 +40,9 @@ XPCOMUtils.defineLazyModuleGetters(this, {
verifyBundleSignedState: "resource://gre/modules/addons/XPIInstall.jsm",
});
XPCOMUtils.defineLazyPreferenceGetter(this, "allowPrivateBrowsingByDefault",
"extensions.allowPrivateBrowsingByDefault", true);
const {nsIBlocklistService} = Ci;
// These are injected from XPIProvider.jsm
@ -619,7 +622,8 @@ class AddonInternal {
// The permission to "toggle the private browsing access" is locked down
// when the extension has opted out or it gets the permission automatically
// on every extension startup (as system, privileged and builtin addons).
if (this.incognito !== "not_allowed" &&
if (!allowPrivateBrowsingByDefault && this.type === "extension" &&
this.incognito !== "not_allowed" &&
this.signedState !== AddonManager.SIGNEDSTATE_PRIVILEGED &&
this.signedState !== AddonManager.SIGNEDSTATE_SYSTEM &&
!this.location.isBuiltin) {

View File

@ -80,7 +80,7 @@ add_task(async function test() {
panel = await popupPromise;
ok(PopupNotifications.isPanelOpen, "Permission popup should be visible");
let notificationPromise = acceptAppMenuNotificationWhenShown("addon-installed", "extension");
let notificationPromise = acceptAppMenuNotificationWhenShown("addon-installed", ADDON_ID);
panel.button.click();
ok(!PopupNotifications.isPanelOpen, "Permission popup should be closed / closing");

View File

@ -1,5 +1,6 @@
const TESTPAGE = `${SECURE_TESTROOT}webapi_checkavailable.html`;
const XPI_URL = `${SECURE_TESTROOT}../xpinstall/amosigned.xpi`;
const XPI_ADDON_ID = "amosigned-xpi@tests.mozilla.org";
const XPI_SHA = "sha256:91121ed2c27f670f2307b9aebdd30979f147318c7fb9111c254c14ddbb84e4b0";
@ -204,7 +205,7 @@ function makeRegularTest(options, what) {
panel.button.click();
});
let promptPromise = acceptAppMenuNotificationWhenShown("addon-installed", "extension");
let promptPromise = acceptAppMenuNotificationWhenShown("addon-installed", options.addonId);
await testInstall(browser, options, steps, what);
@ -230,10 +231,11 @@ function makeRegularTest(options, what) {
});
}
add_task(makeRegularTest({url: XPI_URL}, "a basic install works"));
add_task(makeRegularTest({url: XPI_URL, hash: null}, "install with hash=null works"));
add_task(makeRegularTest({url: XPI_URL, hash: ""}, "install with empty string for hash works"));
add_task(makeRegularTest({url: XPI_URL, hash: XPI_SHA}, "install with hash works"));
let addonId = XPI_ADDON_ID;
add_task(makeRegularTest({url: XPI_URL, addonId}, "a basic install works"));
add_task(makeRegularTest({url: XPI_URL, addonId, hash: null}, "install with hash=null works"));
add_task(makeRegularTest({url: XPI_URL, addonId, hash: ""}, "install with empty string for hash works"));
add_task(makeRegularTest({url: XPI_URL, addonId, hash: XPI_SHA}, "install with hash works"));
add_task(makeInstallTest(async function(browser) {
let steps = [

View File

@ -22,7 +22,7 @@ add_task(async function test_theme_install() {
});
let prompt1 = waitAppMenuNotificationShown("addon-installed", "theme", false);
let prompt1 = waitAppMenuNotificationShown("addon-installed", "theme@tests.mozilla.org", false);
let installPromise = ContentTask.spawn(browser, URL, async (url) => {
let install = await content.navigator.mozAddonManager.createInstall({url});
return install.install();
@ -32,7 +32,7 @@ add_task(async function test_theme_install() {
// Open a new window and test the app menu panel from there. This verifies the
// incognito checkbox as well as finishing install in this case.
let newWin = await BrowserTestUtils.openNewBrowserWindow();
await waitAppMenuNotificationShown("addon-installed", "theme", true, newWin);
await waitAppMenuNotificationShown("addon-installed", "theme@tests.mozilla.org", true, newWin);
await installPromise;
ok(true, "Theme install completed");

View File

@ -2,10 +2,13 @@
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
const {AddonTestUtils} = ChromeUtils.import("resource://testing-common/AddonTestUtils.jsm");
const {ExtensionPermissions} = ChromeUtils.import("resource://gre/modules/ExtensionPermissions.jsm");
var gManagerWindow;
AddonTestUtils.initMochitest(this);
function get_test_items() {
var items = {};
@ -274,3 +277,94 @@ add_task(async function test_addon_preferences_button() {
await runTest(true);
await runTest(false);
});
add_task(async function test_addon_postinstall_incognito_hidden_checkbox() {
await SpecialPowers.pushPrefEnv({set: [
["extensions.allowPrivateBrowsingByDefault", false],
["extensions.langpacks.signatures.required", false],
]});
const TEST_ADDONS = [
{
manifest: {
name: "Extension incognito default opt-in",
applications: {gecko: {id: "ext-incognito-default-opt-in@mozilla.com"}},
},
},
{
manifest: {
name: "Extension incognito not_allowed",
applications: {gecko: {id: "ext-incognito-not-allowed@mozilla.com"}},
incognito: "not_allowed",
},
},
{
manifest: {
name: "Static Theme",
applications: {gecko: {id: "static-theme@mozilla.com"}},
theme: {
colors: {
accentcolor: "#FFFFFF",
textcolor: "#000",
},
},
},
},
{
manifest: {
name: "Dictionary",
applications: {gecko: {id: "dictionary@mozilla.com"}},
dictionaries: {
"und": "dictionaries/und.dic",
},
},
files: {
"dictionaries/und.dic": "",
"dictionaries/und.aff": "",
},
},
{
manifest: {
name: "Langpack",
applications: {gecko: {id: "langpack@mozilla.com"}},
langpack_id: "und",
languages: {
und: {
chrome_resources: {
global: "chrome/und/locale/und/global",
},
version: "20190326174300",
},
},
},
},
];
for (let definition of TEST_ADDONS) {
let {id} = definition.manifest.applications.gecko;
info(`Testing incognito checkbox visibility on ${id} post install notification`);
const xpi = AddonTestUtils.createTempWebExtensionFile(definition);
let install = await AddonManager.getInstallForFile(xpi);
await Promise.all([
waitAppMenuNotificationShown("addon-installed", id, true),
install.install().then(() => {
Services.obs.notifyObservers({
addon: install.addon, target: gBrowser.selectedBrowser,
}, "webextension-install-notify");
}),
]);
const {permissions} = install.addon;
const canChangePBAccess = Boolean(permissions & AddonManager.PERM_CAN_CHANGE_PRIVATEBROWSING_ACCESS);
if (id === "ext-incognito-default-opt-in@mozilla.com") {
ok(canChangePBAccess, `${id} should have the PERM_CAN_CHANGE_PRIVATEBROWSING_ACCESS permission`);
} else {
ok(!canChangePBAccess, `${id} should not have the PERM_CAN_CHANGE_PRIVATEBROWSING_ACCESS permission`);
}
await install.addon.uninstall();
}
});

View File

@ -1400,12 +1400,12 @@ function promisePopupNotificationShown(name = "addon-webext-permissions") {
});
}
function waitAppMenuNotificationShown(id, type, accept = false, win = window) {
function waitAppMenuNotificationShown(id, addonId, accept = false, win = window) {
const {AppMenuNotifications} = ChromeUtils.import("resource://gre/modules/AppMenuNotifications.jsm");
return new Promise(resolve => {
let {document, PanelUI} = win;
function popupshown() {
async function popupshown() {
let notification = AppMenuNotifications.activeNotification;
if (!notification) { return; }
@ -1414,9 +1414,12 @@ function waitAppMenuNotificationShown(id, type, accept = false, win = window) {
PanelUI.notificationPanel.removeEventListener("popupshown", popupshown);
if (id == "addon-installed" && type) {
let hidden = type !== "extension" ||
Services.prefs.getBoolPref("extensions.allowPrivateBrowsingByDefault", true);
if (id == "addon-installed" && addonId) {
let addon = await AddonManager.getAddonByID(addonId);
if (!addon) {
ok(false, `Addon with id "${addonId}" not found`);
}
let hidden = !(addon.permissions & AddonManager.PERM_CAN_CHANGE_PRIVATEBROWSING_ACCESS);
let checkbox = document.getElementById("addon-incognito-checkbox");
is(checkbox.hidden, hidden, "checkbox visibility is correct");
}
@ -1438,8 +1441,8 @@ function waitAppMenuNotificationShown(id, type, accept = false, win = window) {
});
}
function acceptAppMenuNotificationWhenShown(id, type) {
return waitAppMenuNotificationShown(id, type, true);
function acceptAppMenuNotificationWhenShown(id, addonId) {
return waitAppMenuNotificationShown(id, addonId, true);
}
function assertTelemetryMatches(events, {filterMethods} = {}) {