Bug 1534714 handle checkbox state when appmenu refreshed across windows r=Gijs

This adds an onRefresh option for app menus so we can update custom controls
in any opened window.  In this case, we need to refresh the checkbox state in the
addon-installed panel.  We test this using the theme install test and verify both
windows do not have the checkbox.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Shane Caraveo 2019-03-14 18:31:07 +00:00
Родитель 68968a150f
Коммит c8a20292a3
4 изменённых файлов: 41 добавлений и 13 удалений

Просмотреть файл

@ -698,7 +698,7 @@ const PanelUI = {
doorhangers.forEach(n => {
n.dismissed = true;
if (n.options.onDismissed) {
n.options.onDismissed();
n.options.onDismissed(window);
}
});
this._hidePopup();
@ -779,6 +779,9 @@ const PanelUI = {
popupnotification.setAttribute("name", desc.name);
popupnotification.setAttribute("endlabel", desc.end);
}
if (notification.options.onRefresh) {
notification.options.onRefresh(window);
}
if (notification.options.popupIconURL) {
popupnotification.setAttribute("icon", notification.options.popupIconURL);
}

Просмотреть файл

@ -442,11 +442,15 @@ var ExtensionsUI = {
["<>", appName]);
return new Promise(resolve => {
// Show or hide private permission ui based on the pref.
let checkbox = window.document.getElementById("addon-incognito-checkbox");
checkbox.checked = false;
checkbox.hidden = allowPrivateBrowsingByDefault || addon.type !== "extension";
function setCheckbox(win) {
let checkbox = win.document.getElementById("addon-incognito-checkbox");
checkbox.checked = false;
checkbox.hidden = allowPrivateBrowsingByDefault || addon.type !== "extension";
}
setCheckbox(window);
async function actionResolve() {
async function actionResolve(win) {
let checkbox = win.document.getElementById("addon-incognito-checkbox");
if (checkbox.checked) {
let perms = {permissions: ["internal:privateBrowsingAllowed"], origins: []};
await ExtensionPermissions.add(addon.id, perms);
@ -479,9 +483,10 @@ var ExtensionsUI = {
name: addon.name,
message,
popupIconURL: icon,
onDismissed: () => {
onRefresh: setCheckbox,
onDismissed: (win) => {
AppMenuNotifications.removeNotification("addon-installed");
actionResolve();
actionResolve(win);
},
};
AppMenuNotifications.showNotification("addon-installed", action, null, options);

Просмотреть файл

@ -21,17 +21,23 @@ add_task(async function test_theme_install() {
Services.obs.removeObserver(observer, "lightweight-theme-styling-update");
});
let promptPromise = acceptAppMenuNotificationWhenShown("addon-installed", "theme");
let prompt1 = waitAppMenuNotificationShown("addon-installed", "theme", false);
let installPromise = ContentTask.spawn(browser, URL, async (url) => {
let install = await content.navigator.mozAddonManager.createInstall({url});
return install.install();
});
await prompt1;
await promptPromise;
// 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 installPromise;
ok(true, "Theme install completed");
await BrowserTestUtils.closeWindow(newWin);
Assert.equal(updates.length, 1, "Got a single theme update");
let parsed = JSON.parse(updates[0]);
ok(parsed.theme.headerURL.endsWith("/testImage.png"),

Просмотреть файл

@ -1399,9 +1399,11 @@ function promisePopupNotificationShown(name = "addon-webext-permissions") {
});
}
function acceptAppMenuNotificationWhenShown(id, type) {
function waitAppMenuNotificationShown(id, type, accept = false, win = window) {
const {AppMenuNotifications} = ChromeUtils.import("resource://gre/modules/AppMenuNotifications.jsm");
return new Promise(resolve => {
let {document, PanelUI} = win;
function popupshown() {
let notification = AppMenuNotifications.activeNotification;
if (!notification) { return; }
@ -1417,16 +1419,28 @@ function acceptAppMenuNotificationWhenShown(id, type) {
let checkbox = document.getElementById("addon-incognito-checkbox");
is(checkbox.hidden, hidden, "checkbox visibility is correct");
}
let popupnotificationID = PanelUI._getPopupId(notification);
let popupnotification = document.getElementById(popupnotificationID);
popupnotification.button.click();
if (accept) {
let popupnotificationID = PanelUI._getPopupId(notification);
let popupnotification = document.getElementById(popupnotificationID);
popupnotification.button.click();
}
resolve();
}
// If it's already open just run the test.
let notification = AppMenuNotifications.activeNotification;
if (notification && PanelUI.isNotificationPanelOpen) {
popupshown();
return;
}
PanelUI.notificationPanel.addEventListener("popupshown", popupshown);
});
}
function acceptAppMenuNotificationWhenShown(id, type) {
return waitAppMenuNotificationShown(id, type, true);
}
function assertTelemetryMatches(events, {filterMethods} = {}) {
let snapshot = Services.telemetry.snapshotEvents(
Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true);