forked from mirrors/gecko-dev
--HG-- extra : commitid : 1MtGEuPZNu4 extra : rebase_source : c9cb987df2c9f868d08d5f45603e7fc59e3547e8 extra : amend_source : 68d394e13cdf7288538526ed09ae56de98607d7f
71 lines
2.5 KiB
JavaScript
71 lines
2.5 KiB
JavaScript
"use strict";
|
|
|
|
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,
|
|
url: "about:robots"
|
|
}, function* dummyTabTask(aBrowser) {
|
|
let tabPromise = BrowserTestUtils.waitForNewTab(gBrowser, "about:preferences#content");
|
|
info("simulate a notifications-open-settings notification");
|
|
let uri = NetUtil.newURI("https://example.com");
|
|
let principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
|
|
Services.obs.notifyObservers(principal, "notifications-open-settings", null);
|
|
let tab = yield tabPromise;
|
|
ok(tab, "The notification settings tab opened");
|
|
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");
|
|
}
|
|
});
|