Bug 1209601 - Add do not disturb management UI to preferences when a platform is using XUL alerts. r=MattN

This commit is contained in:
Jared Wein 2015-10-20 15:45:21 -04:00
parent 7a053f360d
commit 3776e84504
7 changed files with 91 additions and 3 deletions

View File

@ -44,7 +44,7 @@ function onAlertShowing() {
let alertWindow = Services.wm.getMostRecentWindow("alert:alert");
if (!alertWindow) {
todo(false, "Notifications don't use XUL windows on all platforms.");
ok(true, "Notifications don't use XUL windows on all platforms.");
notification.close();
finish();
return;

View File

@ -2,6 +2,16 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
XPCOMUtils.defineLazyGetter(this, "AlertsService", function () {
try {
return Cc["@mozilla.org/alerts-service;1"]
.getService(Ci.nsIAlertsService)
.QueryInterface(Ci.nsIAlertsDoNotDisturb);
} catch (ex) {
return;
}
});
var gContentPane = {
init: function ()
{
@ -30,6 +40,18 @@ var gContentPane = {
}
}
let doNotDisturbAlertsEnabled = false;
if (AlertsService) {
let notificationsDoNotDisturbRow =
document.getElementById("notificationsDoNotDisturbRow");
notificationsDoNotDisturbRow.removeAttribute("hidden");
if (AlertsService.manualDoNotDisturb) {
let notificationsDoNotDisturb =
document.getElementById("notificationsDoNotDisturb");
notificationsDoNotDisturb.setAttribute("checked", true);
}
}
setEventListener("font.language.group", "change",
gContentPane._rebuildFonts);
setEventListener("notificationsPolicyButton", "command",
@ -46,6 +68,8 @@ var gContentPane = {
gContentPane.openTranslationProviderAttribution);
setEventListener("translateButton", "command",
gContentPane.showTranslationExceptions);
setEventListener("notificationsDoNotDisturb", "command",
gContentPane.toggleDoNotDisturbNotifications);
let drmInfoURL =
Services.urlFormatter.formatURLPref("app.support.baseURL") + "drm-content";
@ -253,5 +277,10 @@ var gContentPane = {
{
Components.utils.import("resource:///modules/translation/Translation.jsm");
Translation.openProviderAttribution();
}
},
toggleDoNotDisturbNotifications: function (event)
{
AlertsService.manualDoNotDisturb = event.target.checked;
},
};

View File

@ -77,6 +77,15 @@
accesskey="&notificationsPolicyButton.accesskey;"/>
</hbox>
</row>
<row id="notificationsDoNotDisturbRow" hidden="true">
<vbox align="start">
<checkbox id="notificationsDoNotDisturb" label="&notificationsDoNotDisturb.label;"
accesskey="&notificationsDoNotDisturb.accesskey;"/>
<label id="notificationsDoNotDisturbDetails"
class="indent"
value="&notificationsDoNotDisturbDetails.value;"/>
</vbox>
</row>
</rows>
</grid>
</groupbox>

View File

@ -20,6 +20,7 @@ skip-if = os != "win" # This test tests the windows-specific app selection dialo
[browser_cookies_exceptions.js]
[browser_healthreport.js]
skip-if = !healthreport || (os == 'linux' && debug)
[browser_notifications_do_not_disturb.js]
[browser_permissions.js]
[browser_proxy_backup.js]
[browser_privacypane_1.js]

View File

@ -0,0 +1,44 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
registerCleanupFunction(function() {
while (gBrowser.tabs[1])
gBrowser.removeTab(gBrowser.tabs[1]);
});
add_task(function() {
let prefs = yield openPreferencesViaOpenPreferencesAPI("paneContent", undefined, {leaveOpen: true});
is(prefs.selectedPane, "paneContent", "Content pane was selected");
let doc = gBrowser.contentDocument;
let notificationsDoNotDisturbRow = doc.getElementById("notificationsDoNotDisturbRow");
if (notificationsDoNotDisturbRow.hidden) {
todo(false, "Do not disturb is not available on this platform");
return;
}
let alertService;
try {
alertService = Cc["@mozilla.org/alerts-service;1"]
.getService(Ci.nsIAlertsService)
.QueryInterface(Ci.nsIAlertsDoNotDisturb);
} catch (ex) {
ok(true, "Do not disturb is not available on this platform: " + ex.message);
return;
}
let checkbox = doc.getElementById("notificationsDoNotDisturb");
ok(!checkbox.checked, "Checkbox should not be checked by default");
ok(!alertService.manualDoNotDisturb, "Do not disturb should be off by default");
let checkboxChanged = waitForEvent(checkbox, "command")
checkbox.click();
yield checkboxChanged;
ok(alertService.manualDoNotDisturb, "Do not disturb should be enabled when checked");
checkboxChanged = waitForEvent(checkbox, "command")
checkbox.click();
yield checkboxChanged;
ok(!alertService.manualDoNotDisturb, "Do not disturb should be disabled when unchecked");
});

View File

@ -11,6 +11,9 @@
<!ENTITY notificationsPolicyDesc.label "Choose which sites are allowed to show notifications">
<!ENTITY notificationsPolicyButton.accesskey "h">
<!ENTITY notificationsPolicyButton.label "Choose…">
<!ENTITY notificationsDoNotDisturb.label "Do not disturb me">
<!ENTITY notificationsDoNotDisturb.accesskey "n">
<!ENTITY notificationsDoNotDisturbDetails.value "No notification will be shown until you restart &brandShortName;">
<!ENTITY popupExceptions.label "Exceptions…">
<!ENTITY popupExceptions.accesskey "E">

View File

@ -271,7 +271,9 @@ description > html|a {
}
.indent {
-moz-margin-start: 33px;
/* !important needed to override -moz-margin-start:0 !important; rule
define in common.css for labels */
-moz-margin-start: 33px !important;
}
.text-link {