mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1205172 - Do Not Disturb Button for Push Notifications on Windows. r=MattN
This commit is contained in:
parent
f7047a5a9e
commit
7a053f360d
@ -2,6 +2,7 @@
|
||||
support-files =
|
||||
file_dom_notifications.html
|
||||
|
||||
[browser_notification_do_not_disturb.js]
|
||||
[browser_notification_open_settings.js]
|
||||
[browser_notification_remove_permission.js]
|
||||
skip-if = e10s
|
||||
|
@ -0,0 +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();
|
||||
|
||||
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) {
|
||||
todo(false, "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();
|
||||
}
|
@ -44,11 +44,19 @@ function prefillAlertInfo() {
|
||||
let hostPort = window.arguments[10];
|
||||
const ALERT_BUNDLE = Services.strings.createBundle(
|
||||
"chrome://alerts/locale/alert.properties");
|
||||
const BRAND_BUNDLE = Services.strings.createBundle(
|
||||
"chrome://branding/locale/brand.properties");
|
||||
const BRAND_NAME = BRAND_BUNDLE.GetStringFromName("brandShortName");
|
||||
let label = document.getElementById("alertSourceLabel");
|
||||
label.setAttribute("value",
|
||||
ALERT_BUNDLE.formatStringFromName("source.label",
|
||||
[hostPort],
|
||||
1));
|
||||
let doNotDisturbMenuItem = document.getElementById("doNotDisturbMenuItem");
|
||||
doNotDisturbMenuItem.setAttribute("label",
|
||||
ALERT_BUNDLE.formatStringFromName("doNotDisturb.label",
|
||||
[BRAND_NAME],
|
||||
1));
|
||||
let disableForOrigin = document.getElementById("disableForOriginMenuItem");
|
||||
disableForOrigin.setAttribute("label",
|
||||
ALERT_BUNDLE.formatStringFromName("webActions.disableForOrigin.label",
|
||||
@ -231,6 +239,14 @@ function onAlertClick() {
|
||||
}
|
||||
}
|
||||
|
||||
function doNotDisturb() {
|
||||
const alertService = Cc["@mozilla.org/alerts-service;1"]
|
||||
.getService(Ci.nsIAlertsService)
|
||||
.QueryInterface(Ci.nsIAlertsDoNotDisturb);
|
||||
alertService.manualDoNotDisturb = true;
|
||||
onAlertClose();
|
||||
}
|
||||
|
||||
function disableForOrigin() {
|
||||
gAlertListener.observe(null, "alertdisablecallback", gAlertCookie);
|
||||
onAlertClose();
|
||||
|
@ -46,6 +46,9 @@
|
||||
<button type="menu" id="alertSettings" tooltiptext="&settings.label;"
|
||||
onclick="event.stopPropagation();">
|
||||
<menupopup position="after_end">
|
||||
<menuitem id="doNotDisturbMenuItem"
|
||||
oncommand="doNotDisturb();"/>
|
||||
<menuseparator/>
|
||||
<menuitem id="disableForOriginMenuItem"
|
||||
oncommand="disableForOrigin();"/>
|
||||
</menupopup>
|
||||
|
@ -17,3 +17,7 @@ webActions.disableForOrigin.label = Disable notifications from %S
|
||||
# and port.
|
||||
source.label=via %1$S
|
||||
webActions.settings.label = Notification settings
|
||||
|
||||
# LOCALIZATION NOTE(doNotDisturb.label): %S is replaced with the
|
||||
# brandShortName of the application.
|
||||
doNotDisturb.label = Do not disturb me until I restart %S
|
||||
|
Loading…
Reference in New Issue
Block a user