fune/browser/components/customizableui/test/browser_panelUINotifications_multiWindow.js
Doug Thayer 646edb5fab Bug 1359733 - Move menu notification state to jsm r=Gijs
Right now, app menu doorhangers/badges have their state managed
directly inside panelUI.js. This is problematic because these
doorhangers and badges usually have to do with Firefox itself,
and not the specific window that's showing them. Accordingly, the
simplest solution was to move panelUI.js's notification state out
into a jsm file, which will fire notifications that all panelUI
instances can listen to.

MozReview-Commit-ID: 7b8w1WsQ29p

--HG--
extra : rebase_source : 23575df8176b862ec0e6a039173b105c45c76de9
2017-05-18 13:22:27 -07:00

130 lines
5.4 KiB
JavaScript

"use strict";
Cu.import("resource://gre/modules/AppMenuNotifications.jsm");
/**
* Tests that when we try to show a notification in a background window, it
* does not display until the window comes back into the foreground. However,
* it should display a badge.
*/
add_task(async function testDoesNotShowDoorhangerForBackgroundWindow() {
let options = {
gBrowser: window.gBrowser,
url: "about:blank"
};
await BrowserTestUtils.withNewTab(options, async function(browser) {
let doc = browser.ownerDocument;
let win = await BrowserTestUtils.openNewBrowserWindow();
let mainActionCalled = false;
let mainAction = {
callback: () => { mainActionCalled = true; }
};
AppMenuNotifications.showNotification("update-manual", mainAction);
is(PanelUI.notificationPanel.state, "closed", "The background window's doorhanger is closed.");
is(PanelUI.menuButton.hasAttribute("badge-status"), true, "The background window has a badge.");
await BrowserTestUtils.closeWindow(win);
await SimpleTest.promiseFocus(window);
isnot(PanelUI.notificationPanel.state, "closed", "update-manual doorhanger is showing.");
let notifications = [...PanelUI.notificationPanel.children].filter(n => !n.hidden);
is(notifications.length, 1, "PanelUI doorhanger is only displaying one notification.");
let doorhanger = notifications[0];
is(doorhanger.id, "appMenu-update-manual-notification", "PanelUI is displaying the update-manual notification.");
let button = doc.getAnonymousElementByAttribute(doorhanger, "anonid", "button");
button.click();
ok(mainActionCalled, "Main action callback was called");
is(PanelUI.notificationPanel.state, "closed", "update-manual doorhanger is closed.");
is(PanelUI.menuButton.hasAttribute("badge-status"), false, "Should not have a badge status");
});
});
/**
* Tests that when we try to show a notification in a background window and in
* a foreground window, if the foreground window's main action is called, the
* background window's doorhanger will be removed.
*/
add_task(async function testBackgroundWindowNotificationsAreRemovedByForeground() {
let options = {
gBrowser: window.gBrowser,
url: "about:blank"
};
await BrowserTestUtils.withNewTab(options, async function(browser) {
let win = await BrowserTestUtils.openNewBrowserWindow();
AppMenuNotifications.showNotification("update-manual", {callback() {}});
let doc = win.gBrowser.ownerDocument;
let notifications = [...win.PanelUI.notificationPanel.children].filter(n => !n.hidden);
is(notifications.length, 1, "PanelUI doorhanger is only displaying one notification.");
let doorhanger = notifications[0];
let button = doc.getAnonymousElementByAttribute(doorhanger, "anonid", "button");
button.click();
await BrowserTestUtils.closeWindow(win);
await SimpleTest.promiseFocus(window);
is(PanelUI.notificationPanel.state, "closed", "update-manual doorhanger is closed.");
is(PanelUI.menuButton.hasAttribute("badge-status"), false, "Should not have a badge status");
});
});
/**
* Tests that when we try to show a notification in a background window and in
* a foreground window, if the foreground window's doorhanger is dismissed,
* the background window's doorhanger will also be dismissed once the window
* regains focus.
*/
add_task(async function testBackgroundWindowNotificationsAreDismissedByForeground() {
let options = {
gBrowser: window.gBrowser,
url: "about:blank"
};
await BrowserTestUtils.withNewTab(options, async function(browser) {
let win = await BrowserTestUtils.openNewBrowserWindow();
AppMenuNotifications.showNotification("update-manual", {callback() {}});
let doc = win.gBrowser.ownerDocument;
let notifications = [...win.PanelUI.notificationPanel.children].filter(n => !n.hidden);
is(notifications.length, 1, "PanelUI doorhanger is only displaying one notification.");
let doorhanger = notifications[0];
let button = doc.getAnonymousElementByAttribute(doorhanger, "anonid", "secondarybutton");
button.click();
await BrowserTestUtils.closeWindow(win);
await SimpleTest.promiseFocus(window);
is(PanelUI.notificationPanel.state, "closed", "The background window's doorhanger is closed.");
is(PanelUI.menuButton.hasAttribute("badge-status"), true,
"The dismissed notification should still have a badge status");
AppMenuNotifications.removeNotification(/.*/);
});
});
/**
* Tests that when we open a new window while a notification is showing, the
* notification also shows on the new window.
*/
add_task(async function testOpenWindowAfterShowingNotification() {
AppMenuNotifications.showNotification("update-manual", {callback() {}});
let win = await BrowserTestUtils.openNewBrowserWindow();
let doc = win.gBrowser.ownerDocument;
let notifications = [...win.PanelUI.notificationPanel.children].filter(n => !n.hidden);
is(notifications.length, 1, "PanelUI doorhanger is only displaying one notification.");
let doorhanger = notifications[0];
let button = doc.getAnonymousElementByAttribute(doorhanger, "anonid", "secondarybutton");
button.click();
await BrowserTestUtils.closeWindow(win);
await SimpleTest.promiseFocus(window);
is(PanelUI.notificationPanel.state, "closed", "The background window's doorhanger is closed.");
is(PanelUI.menuButton.hasAttribute("badge-status"), true,
"The dismissed notification should still have a badge status");
AppMenuNotifications.removeNotification(/.*/);
});