Bug 1491438 move addon-installed notification to the appMenu, r=Gijs

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Shane Caraveo 2018-10-08 14:56:39 +00:00
Родитель 79d34cff75
Коммит e84b2e0788
11 изменённых файлов: 128 добавлений и 29 удалений

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

@ -80,12 +80,6 @@
</popupnotificationcontent>
</popupnotification>
<popupnotification id="addon-installed-notification" hidden="true">
<popupnotificationcontent class="addon-installed-notification-content" orient="vertical">
<description>&addonPostInstallMessage.label;</description>
</popupnotificationcontent>
</popupnotification>
<popupnotification id="contextual-feature-recommendation-notification" hidden="true">
<popupnotificationheader id="cfr-notification-header">
<stack id="cfr-notification-header-stack">

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

@ -39,6 +39,27 @@ function promisePopupNotificationShown(name) {
});
}
function promiseAppMenuNotificationShown(id) {
ChromeUtils.import("resource://gre/modules/AppMenuNotifications.jsm");
return new Promise(resolve => {
function popupshown() {
let notification = AppMenuNotifications.activeNotification;
if (!notification) { return; }
is(notification.id, id, `${id} notification shown`);
ok(PanelUI.isNotificationPanelOpen, "notification panel open");
PanelUI.notificationPanel.removeEventListener("popupshown", popupshown);
let popupnotificationID = PanelUI._getPopupId(notification);
let popupnotification = document.getElementById(popupnotificationID);
resolve(popupnotification);
}
PanelUI.notificationPanel.addEventListener("popupshown", popupshown);
});
}
/**
* Wait for a specific install event to fire for a given addon
*
@ -307,7 +328,7 @@ async function testInstallMethod(installFn, telemetryBase) {
} catch (err) {}
} else {
// Look for post-install notification
let postInstallPromise = promisePopupNotificationShown("addon-installed");
let postInstallPromise = promiseAppMenuNotificationShown("addon-installed");
panel.button.click();
// Press OK on the post-install notification

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

@ -147,6 +147,19 @@
<description id="update-restart-description">&updateRestart.message2;</description>
</popupnotificationcontent>
</popupnotification>
<popupnotification id="appMenu-addon-installed-notification"
popupid="addon-installed"
closebuttonhidden="true"
secondarybuttonhidden="true"
dropmarkerhidden="true"
checkboxhidden="true"
buttonhighlight="true"
hidden="true">
<popupnotificationcontent class="addon-installed-notification-content" orient="vertical">
<description>&addonPostInstallMessage.label;</description>
</popupnotificationcontent>
</popupnotification>
</panel>
<menupopup id="customizationPaletteItemContextMenu"

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

@ -753,6 +753,15 @@ const PanelUI = {
this._clearBannerItem();
},
_formatDescriptionMessage(n) {
let text = {};
let array = n.options.message.split("<>");
text.start = array[0] || "";
text.name = n.options.name || "";
text.end = array[1] || "";
return text;
},
_refreshNotificationPanel(notification) {
this._clearNotificationPanel();
@ -764,6 +773,16 @@ const PanelUI = {
popupnotification.setAttribute("secondarybuttoncommand",
"PanelUI._onNotificationButtonEvent(event, 'secondarybuttoncommand');");
if (notification.options.message) {
let desc = this._formatDescriptionMessage(notification);
popupnotification.setAttribute("label", desc.start);
popupnotification.setAttribute("name", desc.name);
popupnotification.setAttribute("endlabel", desc.end);
}
if (notification.options.popupIconURL) {
popupnotification.setAttribute("icon", notification.options.popupIconURL);
}
popupnotification.notification = notification;
popupnotification.hidden = false;
},

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

@ -401,8 +401,7 @@ var ExtensionsUI = {
},
showInstallNotification(target, addon) {
let {browser, window} = getTabBrowser(target);
let popups = window.PopupNotifications;
let {window} = getTabBrowser(target);
let brandBundle = window.document.getElementById("bundle_brand");
let appName = brandBundle.getString("brandShortName");
@ -421,19 +420,13 @@ var ExtensionsUI = {
AddonManager.getPreferredIconURL(addon, 32, window) || DEFAULT_EXTENSION_ICON :
"chrome://browser/skin/addons/addon-install-installed.svg";
let options = {
hideClose: true,
timeout: Date.now() + 30000,
popupIconURL: icon,
eventCallback(topic) {
if (topic == "dismissed") {
resolve();
}
},
name: addon.name,
message,
popupIconURL: icon,
onDismissed: resolve,
};
popups.show(browser, "addon-installed", message, "addons-notification-icon",
action, null, options);
AppMenuNotifications.showNotification("addon-installed", action, null, options);
});
},
};

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

@ -122,6 +122,9 @@ var AppMenuNotifications = {
notifications.forEach(n => {
n.dismissed = true;
if (n.options.onDismissed) {
n.options.onDismissed();
}
});
this._updateNotifications();
},

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

@ -197,7 +197,7 @@ function makeRegularTest(options, what) {
},
];
let promptPromise = promiseNotification("addon-installed");
let promptPromise = acceptAppMenuNotificationWhenShown("addon-installed");
await testInstall(browser, options, steps, what);

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

@ -20,7 +20,7 @@ add_task(async function test_theme_install() {
Services.obs.removeObserver(observer, "lightweight-theme-styling-update");
});
let promptPromise = promiseNotification("addon-installed");
let promptPromise = acceptAppMenuNotificationWhenShown("addon-installed");
let installPromise = ContentTask.spawn(browser, URL, async (url) => {
let install = await content.navigator.mozAddonManager.createInstall({url});

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

@ -1387,3 +1387,25 @@ function promiseNotification(id = "addon-webext-permissions") {
PopupNotifications.panel.addEventListener("popupshown", popupshown);
});
}
function acceptAppMenuNotificationWhenShown(id) {
ChromeUtils.import("resource://gre/modules/AppMenuNotifications.jsm");
return new Promise(resolve => {
function popupshown() {
let notification = AppMenuNotifications.activeNotification;
if (!notification) { return; }
is(notification.id, id, `${id} notification shown`);
ok(PanelUI.isNotificationPanelOpen, "notification panel open");
PanelUI.notificationPanel.removeEventListener("popupshown", popupshown);
let popupnotificationID = PanelUI._getPopupId(notification);
let popupnotification = document.getElementById(popupnotificationID);
popupnotification.button.click();
resolve();
}
PanelUI.notificationPanel.addEventListener("popupshown", popupshown);
});
}

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

@ -75,6 +75,28 @@ async function waitForProgressNotification(aPanelOpen = false, aExpectedCount =
return PopupNotifications.panel;
}
function acceptAppMenuNotificationWhenShown(id) {
ChromeUtils.import("resource://gre/modules/AppMenuNotifications.jsm");
return new Promise(resolve => {
function popupshown() {
let notification = AppMenuNotifications.activeNotification;
if (!notification) { return; }
is(notification.id, id, `${id} notification shown`);
ok(PanelUI.isNotificationPanelOpen, "notification panel open");
PanelUI.notificationPanel.removeEventListener("popupshown", popupshown);
let popupnotificationID = PanelUI._getPopupId(notification);
let popupnotification = document.getElementById(popupnotificationID);
popupnotification.button.click();
resolve();
}
PanelUI.notificationPanel.addEventListener("popupshown", popupshown);
});
}
async function waitForNotification(aId, aExpectedCount = 1) {
info("Waiting for " + aId + " notification");
@ -123,6 +145,9 @@ async function waitForNotification(aId, aExpectedCount = 1) {
}
function waitForNotificationClose() {
if (!PopupNotifications.isPanelOpen) {
return Promise.resolve();
}
return new Promise(resolve => {
info("Waiting for notification to close");
PopupNotifications.panel.addEventListener("popuphidden", function() {
@ -229,9 +254,9 @@ async function test_blockedInstall() {
let installDialog = await dialogPromise;
notificationPromise = waitForNotification("addon-installed");
notificationPromise = acceptAppMenuNotificationWhenShown("addon-installed");
installDialog.button.click();
panel = await notificationPromise;
await notificationPromise;
let installs = await AddonManager.getAllInstalls();
is(installs.length, 0, "Should be no pending installs");
@ -263,7 +288,7 @@ async function test_whitelistedInstall() {
is(gBrowser.selectedTab, tab,
"tab selected in response to the addon-install-confirmation notification");
let notificationPromise = waitForNotification("addon-installed");
let notificationPromise = acceptAppMenuNotificationWhenShown("addon-installed");
acceptInstallDialog(installDialog);
await notificationPromise;
@ -359,7 +384,7 @@ async function test_restartless() {
await progressPromise;
let installDialog = await dialogPromise;
let notificationPromise = waitForNotification("addon-installed");
let notificationPromise = acceptAppMenuNotificationWhenShown("addon-installed");
acceptInstallDialog(installDialog);
await notificationPromise;
@ -476,7 +501,7 @@ async function test_allUnverified() {
is(container.children[0].firstElementChild.getAttribute("value"), "XPI Test", "Should have the right add-on");
is(container.children[0].children.length, 1, "Shouldn't have the unverified marker");
let notificationPromise = waitForNotification("addon-installed");
let notificationPromise = acceptAppMenuNotificationWhenShown("addon-installed");
acceptInstallDialog(installDialog);
await notificationPromise;
@ -587,7 +612,7 @@ async function test_urlBar() {
await progressPromise;
let installDialog = await dialogPromise;
let notificationPromise = waitForNotification("addon-installed");
let notificationPromise = acceptAppMenuNotificationWhenShown("addon-installed");
installDialog.button.click();
await notificationPromise;

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

@ -113,6 +113,7 @@ var Harness = {
Services.wm.addListener(this);
window.addEventListener("popupshown", this);
PanelUI.notificationPanel.addEventListener("popupshown", this);
var self = this;
registerCleanupFunction(async function() {
@ -131,6 +132,7 @@ var Harness = {
Services.wm.removeListener(self);
window.removeEventListener("popupshown", self);
PanelUI.notificationPanel.removeEventListener("popupshown", self);
let aInstalls = await AddonManager.getAllInstalls();
is(aInstalls.length, 0, "Should be no active installs at the end of the test");
@ -147,6 +149,11 @@ var Harness = {
},
finish() {
// Some tests using this harness somehow finish leaving
// the addon-installed panel open. hiding here addresses
// that which fixes the rest of the tests. Since no test
// here cares about this panel, we just need it to close.
PanelUI.notificationPanel.hidePopup();
finish();
},
@ -236,11 +243,13 @@ var Harness = {
handleEvent(event) {
if (event.type === "popupshown") {
if (event.target.firstElementChild) {
if (event.target == PanelUI.notificationPanel) {
PanelUI.notificationPanel.hidePopup();
} else if (event.target.firstElementChild) {
let popupId = event.target.getAttribute("popupid");
if (popupId === "addon-webext-permissions") {
this.popupReady(event.target.firstElementChild);
} else if (popupId === "addon-installed" || popupId === "addon-install-failed") {
} else if (popupId === "addon-install-failed") {
event.target.firstElementChild.button.click();
}
}