Bug 1217621 - Show settings action for XUL notifications. r=jaws

This commit is contained in:
Kit Cambridge 2015-10-23 15:53:15 -06:00
parent 31e87bb62f
commit 9fc8649a52
3 changed files with 64 additions and 1 deletions

View File

@ -1,6 +1,19 @@
"use strict";
add_task(function* test_settingsOpen() {
var notificationURL = "http://example.org/browser/browser/base/content/test/alerts/file_dom_notifications.html";
function waitForCloseWindow(window) {
return new Promise(function(resolve) {
Services.ww.registerNotification(function observer(subject, topic, data) {
if (topic == "domwindowclosed" && subject == window) {
Services.ww.unregisterNotification(observer);
resolve();
}
});
});
}
add_task(function* test_settingsOpen_observer() {
info("Opening a dummy tab so openPreferences=>switchToTabHavingURI doesn't use the blank tab.");
yield BrowserTestUtils.withNewTab({
gBrowser,
@ -16,3 +29,43 @@ add_task(function* test_settingsOpen() {
yield BrowserTestUtils.removeTab(tab);
});
});
add_task(function* test_settingsOpen_button() {
let pm = Services.perms;
info("Adding notification permission");
pm.add(makeURI(notificationURL), "desktop-notification", pm.ALLOW_ACTION);
try {
yield BrowserTestUtils.withNewTab({
gBrowser,
url: notificationURL
}, function* tabTask(aBrowser) {
let notification = aBrowser.contentWindow.wrappedJSObject.showNotification2();
info("Waiting for notification");
yield BrowserTestUtils.waitForEvent(notification, "show");
let alertWindow = Services.wm.getMostRecentWindow("alert:alert");
if (!alertWindow) {
ok(true, "Notifications don't use XUL windows on all platforms.");
notification.close();
return;
}
let closePromise = waitForCloseWindow(alertWindow);
let tabPromise = BrowserTestUtils.waitForNewTab(gBrowser, "about:preferences#content");
let openSettingsMenuItem = alertWindow.document.getElementById("openSettingsMenuItem");
openSettingsMenuItem.click();
info("Waiting for notification settings tab");
let tab = yield tabPromise;
ok(tab, "The notification settings tab opened");
yield closePromise;
yield BrowserTestUtils.removeTab(tab);
});
} finally {
info("Removing notification permission");
pm.remove(makeURI(notificationURL), "desktop-notification");
}
});

View File

@ -62,6 +62,9 @@ function prefillAlertInfo() {
ALERT_BUNDLE.formatStringFromName("webActions.disableForOrigin.label",
[hostPort],
1));
let openSettings = document.getElementById("openSettingsMenuItem");
openSettings.setAttribute("label",
ALERT_BUNDLE.GetStringFromName("webActions.settings.label"));
}
}
case 10:
@ -252,6 +255,11 @@ function disableForOrigin() {
onAlertClose();
}
function openSettings() {
gAlertListener.observe(null, "alertsettingscallback", gAlertCookie);
onAlertClose();
}
function onAlertClose() {
let alertBox = document.getElementById("alertBox");
if (alertBox.getAttribute("animate") == "true") {

View File

@ -51,6 +51,8 @@
<menuseparator/>
<menuitem id="disableForOriginMenuItem"
oncommand="disableForOrigin();"/>
<menuitem id="openSettingsMenuItem"
oncommand="openSettings();"/>
</menupopup>
</button>
</box>