mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1219097 - Stop using incorrect CPOWs in these tests. r=felipe
This commit is contained in:
parent
6ab3f2d98e
commit
2db708974f
@ -1,53 +1,50 @@
|
||||
"use strict";
|
||||
|
||||
let tab;
|
||||
let notification;
|
||||
let notificationURL = "http://example.org/browser/browser/base/content/test/alerts/file_dom_notifications.html";
|
||||
|
||||
add_task(function* test_notificationClose() {
|
||||
let pm = Services.perms;
|
||||
pm.add(makeURI(notificationURL), "desktop-notification", pm.ALLOW_ACTION);
|
||||
|
||||
yield BrowserTestUtils.withNewTab({
|
||||
gBrowser,
|
||||
url: notificationURL
|
||||
}, function* dummyTabTask(aBrowser) {
|
||||
let win = aBrowser.contentWindow.wrappedJSObject;
|
||||
notification = win.showNotification2();
|
||||
yield BrowserTestUtils.waitForEvent(notification, "show");
|
||||
|
||||
info("Notification alert showing");
|
||||
|
||||
let alertWindow = Services.wm.getMostRecentWindow("alert:alert");
|
||||
if (!alertWindow) {
|
||||
ok(true, "Notifications don't use XUL windows on all platforms.");
|
||||
notification.close();
|
||||
return;
|
||||
}
|
||||
|
||||
let alertTitleLabel = alertWindow.document.getElementById("alertTitleLabel");
|
||||
is(alertTitleLabel.value, "Test title", "Title text of notification should be present");
|
||||
let alertTextLabel = alertWindow.document.getElementById("alertTextLabel");
|
||||
is(alertTextLabel.textContent, "Test body 2", "Body text of notification should be present");
|
||||
|
||||
let alertCloseButton = alertWindow.document.querySelector(".alertCloseButton");
|
||||
is(alertCloseButton.localName, "toolbarbutton", "close button found");
|
||||
let promiseBeforeUnloadEvent =
|
||||
BrowserTestUtils.waitForEvent(alertWindow, "beforeunload");
|
||||
let closedTime = alertWindow.Date.now();
|
||||
alertCloseButton.click();
|
||||
info("Clicked on close button");
|
||||
let beforeUnloadEvent = yield promiseBeforeUnloadEvent;
|
||||
|
||||
ok(true, "Alert should close when the close button is clicked");
|
||||
let currentTime = alertWindow.Date.now();
|
||||
// The notification will self-close at 12 seconds, so this checks
|
||||
// that the notification closed before the timeout.
|
||||
ok(currentTime - closedTime < 5000,
|
||||
"Close requested at " + closedTime + ", actually closed at " + currentTime);
|
||||
});
|
||||
});
|
||||
|
||||
add_task(function* cleanup() {
|
||||
Services.perms.remove(makeURI(notificationURL), "desktop-notification");
|
||||
});
|
||||
"use strict";
|
||||
|
||||
let tab;
|
||||
let notificationURL = "http://example.org/browser/browser/base/content/test/alerts/file_dom_notifications.html";
|
||||
|
||||
add_task(function* test_notificationClose() {
|
||||
let pm = Services.perms;
|
||||
pm.add(makeURI(notificationURL), "desktop-notification", pm.ALLOW_ACTION);
|
||||
|
||||
yield BrowserTestUtils.withNewTab({
|
||||
gBrowser,
|
||||
url: notificationURL
|
||||
}, function* dummyTabTask(aBrowser) {
|
||||
yield openNotification(aBrowser, "showNotification2");
|
||||
|
||||
info("Notification alert showing");
|
||||
|
||||
let alertWindow = Services.wm.getMostRecentWindow("alert:alert");
|
||||
if (!alertWindow) {
|
||||
ok(true, "Notifications don't use XUL windows on all platforms.");
|
||||
yield closeNotification(aBrowser);
|
||||
return;
|
||||
}
|
||||
|
||||
let alertTitleLabel = alertWindow.document.getElementById("alertTitleLabel");
|
||||
is(alertTitleLabel.value, "Test title", "Title text of notification should be present");
|
||||
let alertTextLabel = alertWindow.document.getElementById("alertTextLabel");
|
||||
is(alertTextLabel.textContent, "Test body 2", "Body text of notification should be present");
|
||||
|
||||
let alertCloseButton = alertWindow.document.querySelector(".alertCloseButton");
|
||||
is(alertCloseButton.localName, "toolbarbutton", "close button found");
|
||||
let promiseBeforeUnloadEvent =
|
||||
BrowserTestUtils.waitForEvent(alertWindow, "beforeunload");
|
||||
let closedTime = alertWindow.Date.now();
|
||||
alertCloseButton.click();
|
||||
info("Clicked on close button");
|
||||
let beforeUnloadEvent = yield promiseBeforeUnloadEvent;
|
||||
|
||||
ok(true, "Alert should close when the close button is clicked");
|
||||
let currentTime = alertWindow.Date.now();
|
||||
// The notification will self-close at 12 seconds, so this checks
|
||||
// that the notification closed before the timeout.
|
||||
ok(currentTime - closedTime < 5000,
|
||||
"Close requested at " + closedTime + ", actually closed at " + currentTime);
|
||||
});
|
||||
});
|
||||
|
||||
add_task(function* cleanup() {
|
||||
Services.perms.remove(makeURI(notificationURL), "desktop-notification");
|
||||
});
|
||||
|
@ -1,91 +1,80 @@
|
||||
"use strict";
|
||||
|
||||
var tab;
|
||||
var notification;
|
||||
var notification2;
|
||||
var notificationURL = "http://example.org/browser/browser/base/content/test/alerts/file_dom_notifications.html";
|
||||
|
||||
const ALERT_SERVICE = Cc["@mozilla.org/alerts-service;1"]
|
||||
.getService(Ci.nsIAlertsService)
|
||||
.QueryInterface(Ci.nsIAlertsDoNotDisturb);
|
||||
|
||||
function test () {
|
||||
waitForExplicitFinish();
|
||||
|
||||
try {
|
||||
// Only run the test if the do-not-disturb
|
||||
// interface has been implemented.
|
||||
ALERT_SERVICE.manualDoNotDisturb;
|
||||
ok(true, "Alert service implements do-not-disturb interface");
|
||||
} catch (e) {
|
||||
ok(true, "Alert service doesn't implement do-not-disturb interface, exiting test");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
let pm = Services.perms;
|
||||
registerCleanupFunction(function() {
|
||||
ALERT_SERVICE.manualDoNotDisturb = false;
|
||||
pm.remove(makeURI(notificationURL), "desktop-notification");
|
||||
gBrowser.removeTab(tab);
|
||||
window.restore();
|
||||
});
|
||||
|
||||
pm.add(makeURI(notificationURL), "desktop-notification", pm.ALLOW_ACTION);
|
||||
|
||||
// Make sure that do-not-disturb is not enabled.
|
||||
ok(!ALERT_SERVICE.manualDoNotDisturb, "Alert service should not be disabled when test starts");
|
||||
ALERT_SERVICE.manualDoNotDisturb = false;
|
||||
|
||||
tab = gBrowser.addTab(notificationURL);
|
||||
gBrowser.selectedTab = tab;
|
||||
tab.linkedBrowser.addEventListener("load", onLoad, true);
|
||||
}
|
||||
|
||||
function onLoad() {
|
||||
tab.linkedBrowser.removeEventListener("load", onLoad, true);
|
||||
let win = tab.linkedBrowser.contentWindow.wrappedJSObject;
|
||||
notification = win.showNotification2();
|
||||
notification.addEventListener("show", onAlertShowing);
|
||||
}
|
||||
|
||||
function onAlertShowing() {
|
||||
info("Notification alert showing");
|
||||
notification.removeEventListener("show", onAlertShowing);
|
||||
|
||||
let alertWindow = Services.wm.getMostRecentWindow("alert:alert");
|
||||
if (!alertWindow) {
|
||||
ok(true, "Notifications don't use XUL windows on all platforms.");
|
||||
notification.close();
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
let doNotDisturbMenuItem = alertWindow.document.getElementById("doNotDisturbMenuItem");
|
||||
is(doNotDisturbMenuItem.localName, "menuitem", "menuitem found");
|
||||
alertWindow.addEventListener("beforeunload", onAlertClosing);
|
||||
doNotDisturbMenuItem.click();
|
||||
info("Clicked on do-not-disturb menuitem");
|
||||
}
|
||||
|
||||
function onAlertClosing(event) {
|
||||
event.target.removeEventListener("beforeunload", onAlertClosing);
|
||||
|
||||
ok(ALERT_SERVICE.manualDoNotDisturb, "Alert service should be disabled after clicking menuitem");
|
||||
let win = tab.linkedBrowser.contentWindow.wrappedJSObject;
|
||||
notification2 = win.showNotification2();
|
||||
notification2.addEventListener("show", onAlert2Showing);
|
||||
|
||||
// The notification should not appear, but there is
|
||||
// no way from the client-side to know that it was
|
||||
// blocked, except for waiting some time and realizing
|
||||
// that the "onshow" event never fired.
|
||||
setTimeout(function() {
|
||||
notification2.removeEventListener("show", onAlert2Showing);
|
||||
finish();
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
function onAlert2Showing() {
|
||||
ok(false, "the second alert should not have been shown");
|
||||
notification2.close();
|
||||
}
|
||||
"use strict";
|
||||
|
||||
var tab;
|
||||
var notificationURL = "http://example.org/browser/browser/base/content/test/alerts/file_dom_notifications.html";
|
||||
|
||||
const ALERT_SERVICE = Cc["@mozilla.org/alerts-service;1"]
|
||||
.getService(Ci.nsIAlertsService)
|
||||
.QueryInterface(Ci.nsIAlertsDoNotDisturb);
|
||||
|
||||
function test () {
|
||||
waitForExplicitFinish();
|
||||
|
||||
try {
|
||||
// Only run the test if the do-not-disturb
|
||||
// interface has been implemented.
|
||||
ALERT_SERVICE.manualDoNotDisturb;
|
||||
ok(true, "Alert service implements do-not-disturb interface");
|
||||
} catch (e) {
|
||||
ok(true, "Alert service doesn't implement do-not-disturb interface, exiting test");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
let pm = Services.perms;
|
||||
registerCleanupFunction(function() {
|
||||
ALERT_SERVICE.manualDoNotDisturb = false;
|
||||
pm.remove(makeURI(notificationURL), "desktop-notification");
|
||||
gBrowser.removeTab(tab);
|
||||
window.restore();
|
||||
});
|
||||
|
||||
pm.add(makeURI(notificationURL), "desktop-notification", pm.ALLOW_ACTION);
|
||||
|
||||
// Make sure that do-not-disturb is not enabled.
|
||||
ok(!ALERT_SERVICE.manualDoNotDisturb, "Alert service should not be disabled when test starts");
|
||||
ALERT_SERVICE.manualDoNotDisturb = false;
|
||||
|
||||
tab = gBrowser.addTab(notificationURL);
|
||||
gBrowser.selectedTab = tab;
|
||||
tab.linkedBrowser.addEventListener("load", onLoad, true);
|
||||
}
|
||||
|
||||
function onLoad() {
|
||||
tab.linkedBrowser.removeEventListener("load", onLoad, true);
|
||||
openNotification(tab.linkedBrowser, "showNotification2").then(onAlertShowing);
|
||||
}
|
||||
|
||||
function onAlertShowing() {
|
||||
info("Notification alert showing");
|
||||
|
||||
let alertWindow = Services.wm.getMostRecentWindow("alert:alert");
|
||||
if (!alertWindow) {
|
||||
ok(true, "Notifications don't use XUL windows on all platforms.");
|
||||
closeNotification(tab.linkedBrowser).then(finish);
|
||||
return;
|
||||
}
|
||||
let doNotDisturbMenuItem = alertWindow.document.getElementById("doNotDisturbMenuItem");
|
||||
is(doNotDisturbMenuItem.localName, "menuitem", "menuitem found");
|
||||
alertWindow.addEventListener("beforeunload", onAlertClosing);
|
||||
doNotDisturbMenuItem.click();
|
||||
info("Clicked on do-not-disturb menuitem");
|
||||
}
|
||||
|
||||
function onAlertClosing(event) {
|
||||
event.target.removeEventListener("beforeunload", onAlertClosing);
|
||||
|
||||
ok(ALERT_SERVICE.manualDoNotDisturb, "Alert service should be disabled after clicking menuitem");
|
||||
|
||||
// The notification should not appear, but there is
|
||||
// no way from the client-side to know that it was
|
||||
// blocked, except for waiting some time and realizing
|
||||
// that the "onshow" event never fired.
|
||||
openNotification(tab.linkedBrowser, "showNotification2", 2000)
|
||||
.then(onAlert2Showing, finish);
|
||||
}
|
||||
|
||||
function onAlert2Showing() {
|
||||
ok(false, "the second alert should not have been shown");
|
||||
closeNotification(tab.linkedBrowser).then(finish);
|
||||
}
|
||||
|
@ -29,15 +29,13 @@ add_task(function* test_settingsOpen_button() {
|
||||
gBrowser,
|
||||
url: notificationURL
|
||||
}, function* tabTask(aBrowser) {
|
||||
let notification = aBrowser.contentWindow.wrappedJSObject.showNotification2();
|
||||
|
||||
info("Waiting for notification");
|
||||
yield BrowserTestUtils.waitForEvent(notification, "show");
|
||||
yield openNotification(aBrowser, "showNotification2");
|
||||
|
||||
let alertWindow = Services.wm.getMostRecentWindow("alert:alert");
|
||||
if (!alertWindow) {
|
||||
ok(true, "Notifications don't use XUL windows on all platforms.");
|
||||
notification.close();
|
||||
yield closeNotification(aBrowser);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,79 +1,72 @@
|
||||
"use strict";
|
||||
|
||||
var tab;
|
||||
var notification;
|
||||
var notificationURL = "http://example.org/browser/browser/base/content/test/alerts/file_dom_notifications.html";
|
||||
var alertWindowClosed = false;
|
||||
var permRemoved = false;
|
||||
|
||||
function test () {
|
||||
waitForExplicitFinish();
|
||||
|
||||
let pm = Services.perms;
|
||||
registerCleanupFunction(function() {
|
||||
pm.remove(makeURI(notificationURL), "desktop-notification");
|
||||
gBrowser.removeTab(tab);
|
||||
window.restore();
|
||||
});
|
||||
|
||||
pm.add(makeURI(notificationURL), "desktop-notification", pm.ALLOW_ACTION);
|
||||
|
||||
tab = gBrowser.addTab(notificationURL);
|
||||
gBrowser.selectedTab = tab;
|
||||
tab.linkedBrowser.addEventListener("load", onLoad, true);
|
||||
}
|
||||
|
||||
function onLoad() {
|
||||
tab.linkedBrowser.removeEventListener("load", onLoad, true);
|
||||
let win = tab.linkedBrowser.contentWindow.wrappedJSObject;
|
||||
notification = win.showNotification2();
|
||||
notification.addEventListener("show", onAlertShowing);
|
||||
}
|
||||
|
||||
function onAlertShowing() {
|
||||
info("Notification alert showing");
|
||||
notification.removeEventListener("show", onAlertShowing);
|
||||
|
||||
let alertWindow = Services.wm.getMostRecentWindow("alert:alert");
|
||||
if (!alertWindow) {
|
||||
ok(true, "Notifications don't use XUL windows on all platforms.");
|
||||
notification.close();
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
ok(Services.perms.testExactPermission(makeURI(notificationURL), "desktop-notification"),
|
||||
"Permission should exist prior to removal");
|
||||
let disableForOriginMenuItem = alertWindow.document.getElementById("disableForOriginMenuItem");
|
||||
is(disableForOriginMenuItem.localName, "menuitem", "menuitem found");
|
||||
Services.obs.addObserver(permObserver, "perm-changed", false);
|
||||
alertWindow.addEventListener("beforeunload", onAlertClosing);
|
||||
disableForOriginMenuItem.click();
|
||||
info("Clicked on disable-for-origin menuitem")
|
||||
}
|
||||
|
||||
function permObserver(subject, topic, data) {
|
||||
if (topic != "perm-changed") {
|
||||
return;
|
||||
}
|
||||
|
||||
let permission = subject.QueryInterface(Ci.nsIPermission);
|
||||
is(permission.type, "desktop-notification", "desktop-notification permission changed");
|
||||
is(data, "deleted", "desktop-notification permission deleted");
|
||||
|
||||
Services.obs.removeObserver(permObserver, "perm-changed");
|
||||
permRemoved = true;
|
||||
if (alertWindowClosed) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
function onAlertClosing(event) {
|
||||
event.target.removeEventListener("beforeunload", onAlertClosing);
|
||||
|
||||
alertWindowClosed = true;
|
||||
if (permRemoved) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
"use strict";
|
||||
|
||||
var tab;
|
||||
var notificationURL = "http://example.org/browser/browser/base/content/test/alerts/file_dom_notifications.html";
|
||||
var alertWindowClosed = false;
|
||||
var permRemoved = false;
|
||||
|
||||
function test () {
|
||||
waitForExplicitFinish();
|
||||
|
||||
let pm = Services.perms;
|
||||
registerCleanupFunction(function() {
|
||||
pm.remove(makeURI(notificationURL), "desktop-notification");
|
||||
gBrowser.removeTab(tab);
|
||||
window.restore();
|
||||
});
|
||||
|
||||
pm.add(makeURI(notificationURL), "desktop-notification", pm.ALLOW_ACTION);
|
||||
|
||||
tab = gBrowser.addTab(notificationURL);
|
||||
gBrowser.selectedTab = tab;
|
||||
tab.linkedBrowser.addEventListener("load", onLoad, true);
|
||||
}
|
||||
|
||||
function onLoad() {
|
||||
tab.linkedBrowser.removeEventListener("load", onLoad, true);
|
||||
openNotification(tab.linkedBrowser, "showNotification2").then(onAlertShowing);
|
||||
}
|
||||
|
||||
function onAlertShowing() {
|
||||
info("Notification alert showing");
|
||||
|
||||
let alertWindow = Services.wm.getMostRecentWindow("alert:alert");
|
||||
if (!alertWindow) {
|
||||
ok(true, "Notifications don't use XUL windows on all platforms.");
|
||||
closeNotification(tab.linkedBrowser).then(finish);
|
||||
return;
|
||||
}
|
||||
ok(Services.perms.testExactPermission(makeURI(notificationURL), "desktop-notification"),
|
||||
"Permission should exist prior to removal");
|
||||
let disableForOriginMenuItem = alertWindow.document.getElementById("disableForOriginMenuItem");
|
||||
is(disableForOriginMenuItem.localName, "menuitem", "menuitem found");
|
||||
Services.obs.addObserver(permObserver, "perm-changed", false);
|
||||
alertWindow.addEventListener("beforeunload", onAlertClosing);
|
||||
disableForOriginMenuItem.click();
|
||||
info("Clicked on disable-for-origin menuitem")
|
||||
}
|
||||
|
||||
function permObserver(subject, topic, data) {
|
||||
if (topic != "perm-changed") {
|
||||
return;
|
||||
}
|
||||
|
||||
let permission = subject.QueryInterface(Ci.nsIPermission);
|
||||
is(permission.type, "desktop-notification", "desktop-notification permission changed");
|
||||
is(data, "deleted", "desktop-notification permission deleted");
|
||||
|
||||
Services.obs.removeObserver(permObserver, "perm-changed");
|
||||
permRemoved = true;
|
||||
if (alertWindowClosed) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
function onAlertClosing(event) {
|
||||
event.target.removeEventListener("beforeunload", onAlertClosing);
|
||||
|
||||
alertWindowClosed = true;
|
||||
if (permRemoved) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
@ -23,30 +23,44 @@ add_task(function* test_notificationPreventDefaultAndSwitchTabs() {
|
||||
isnot(gBrowser.selectedBrowser, aBrowser, "Notification page loaded as a background tab");
|
||||
|
||||
// First, show a notification that will be have the tab-switching prevented.
|
||||
let win = aBrowser.contentWindow.wrappedJSObject;
|
||||
let notification = win.showNotification1();
|
||||
yield BrowserTestUtils.waitForEvent(notification, "show");
|
||||
function promiseNotificationEvent(evt) {
|
||||
return ContentTask.spawn(aBrowser, evt, function* (evt) {
|
||||
return yield new Promise(resolve => {
|
||||
let notification = content.wrappedJSObject._notification;
|
||||
notification.addEventListener(evt, function l(event) {
|
||||
notification.removeEventListener(evt, l);
|
||||
resolve({ defaultPrevented: event.defaultPrevented });
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
yield openNotification(aBrowser, "showNotification1");
|
||||
info("Notification alert showing");
|
||||
let alertWindow = Services.wm.getMostRecentWindow("alert:alert");
|
||||
if (!alertWindow) {
|
||||
ok(true, "Notifications don't use XUL windows on all platforms.");
|
||||
notification.close();
|
||||
yield closeNotification(aBrowser);
|
||||
return;
|
||||
}
|
||||
info("Clicking on notification");
|
||||
let promiseClickEvent = BrowserTestUtils.waitForEvent(notification, "click");
|
||||
EventUtils.synthesizeMouseAtCenter(alertWindow.document.getElementById("alertTitleLabel"),
|
||||
{},
|
||||
alertWindow);
|
||||
let promiseClickEvent = promiseNotificationEvent("click");
|
||||
|
||||
// NB: This executeSoon is needed to allow the non-e10s runs of this test
|
||||
// a chance to set the event listener on the page. Otherwise, we
|
||||
// synchronously fire the click event before we listen for the event.
|
||||
executeSoon(() => {
|
||||
EventUtils.synthesizeMouseAtCenter(alertWindow.document.getElementById("alertTitleLabel"),
|
||||
{}, alertWindow);
|
||||
});
|
||||
let clickEvent = yield promiseClickEvent;
|
||||
ok(clickEvent.defaultPrevented, "The event handler for the first notification cancels the event");
|
||||
isnot(gBrowser.selectedBrowser, aBrowser, "Notification page still a background tab");
|
||||
notification.close();
|
||||
yield BrowserTestUtils.waitForEvent(notification, "close");
|
||||
let notificationClosed = promiseNotificationEvent("close");
|
||||
yield closeNotification(aBrowser);
|
||||
yield notificationClosed;
|
||||
|
||||
// Second, show a notification that will cause the tab to get switched.
|
||||
let notification2 = win.showNotification2();
|
||||
yield BrowserTestUtils.waitForEvent(notification2, "show");
|
||||
yield openNotification(aBrowser, "showNotification2");
|
||||
alertWindow = Services.wm.getMostRecentWindow("alert:alert");
|
||||
let promiseTabSelect = BrowserTestUtils.waitForEvent(gBrowser.tabContainer, "TabSelect");
|
||||
EventUtils.synthesizeMouseAtCenter(alertWindow.document.getElementById("alertTitleLabel"),
|
||||
@ -55,8 +69,9 @@ add_task(function* test_notificationPreventDefaultAndSwitchTabs() {
|
||||
yield promiseTabSelect;
|
||||
is(gBrowser.selectedBrowser.currentURI.spec, notificationURL,
|
||||
"Clicking on the second notification should select its originating tab");
|
||||
notification2.close();
|
||||
yield BrowserTestUtils.waitForEvent(notification2, "close");
|
||||
notificationClosed = promiseNotificationEvent("close");
|
||||
yield closeNotification(aBrowser);
|
||||
yield notificationClosed;
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -32,3 +32,40 @@ function promiseWindowClosed(window) {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* These two functions work with file_dom_notifications.html to open the
|
||||
* notification and close it.
|
||||
*
|
||||
* |fn| can be showNotification1 or showNotification2.
|
||||
* if |timeout| is passed, then the promise returned from this function is
|
||||
* rejected after the requested number of miliseconds.
|
||||
*/
|
||||
function openNotification(aBrowser, fn, timeout) {
|
||||
return ContentTask.spawn(aBrowser, { fn, timeout }, function* ({ fn, timeout }) {
|
||||
let win = content.wrappedJSObject;
|
||||
let notification = win[fn]();
|
||||
win._notification = notification;
|
||||
yield new Promise((resolve, reject) => {
|
||||
function listener() {
|
||||
notification.removeEventListener("show", listener);
|
||||
resolve();
|
||||
}
|
||||
|
||||
notification.addEventListener("show", listener);
|
||||
|
||||
if (timeout) {
|
||||
content.setTimeout(() => {
|
||||
notification.removeEventListener("show", listener);
|
||||
reject("timed out");
|
||||
}, timeout);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function closeNotification(aBrowser) {
|
||||
return ContentTask.spawn(aBrowser, null, function() {
|
||||
content.wrappedJSObject._notification.close();
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user