Bug 1341742 - Split secondary action for push notification permission prompt into "not now" and "never". r=johannh

MozReview-Commit-ID: DTkUuWabNjH

--HG--
extra : rebase_source : cd0188b641c858a8a631b1112be593dc4085aa8c
This commit is contained in:
Nihanth Subramanya 2017-02-24 18:42:36 -08:00
Родитель 02a7a5d571
Коммит d5ac420cfd
6 изменённых файлов: 91 добавлений и 37 удалений

Просмотреть файл

@ -491,12 +491,13 @@ geolocation.shareWithSite3=Will you allow %S to access your location?
geolocation.shareWithFile3=Will you allow this local file to access your location?
geolocation.remember=Remember this decision
webNotifications.remember=Remember this decision
webNotifications.rememberForSession=Remember decision for this session
webNotifications.allow=Allow Notifications
webNotifications.allow.accesskey=A
webNotifications.dontAllow=Dont Allow
webNotifications.dontAllow.accesskey=n
webNotifications.notNow=Not Now
webNotifications.notNow.accesskey=n
webNotifications.never=Never Allow
webNotifications.neverForSession=Never For This Session
webNotifications.never.accesskey=v
webNotifications.receiveFromSite2=Will you allow %S to send notifications?
# LOCALIZATION NOTE (webNotifications.upgradeTitle): When using native notifications on OS X, the title may be truncated around 32 characters.
webNotifications.upgradeTitle=Upgraded notifications

Просмотреть файл

@ -301,7 +301,8 @@ this.PermissionPromptPrototype = {
if (this.permissionKey) {
// Permanently store permission.
if (state && state.checkboxChecked) {
if ((state && state.checkboxChecked) ||
promptAction.scope == SitePermissions.SCOPE_PERSISTENT) {
let scope = SitePermissions.SCOPE_PERSISTENT;
// Only remember permission for session if in PB mode.
if (PrivateBrowsingUtils.isBrowserPrivate(this.browser)) {
@ -539,22 +540,8 @@ DesktopNotificationPermissionPrompt.prototype = {
let learnMoreURL =
Services.urlFormatter.formatURLPref("app.support.baseURL") + "push";
let checkbox = {
show: true,
checked: true,
label: gBrowserBundle.GetStringFromName("webNotifications.remember")
};
// In PB mode, the "always remember" checkbox should only remember for the
// session.
if (PrivateBrowsingUtils.isWindowPrivate(this.browser.ownerGlobal)) {
checkbox.label =
gBrowserBundle.GetStringFromName("webNotifications.rememberForSession");
}
return {
learnMoreURL,
checkbox,
displayURI: false
};
},
@ -583,13 +570,23 @@ DesktopNotificationPermissionPrompt.prototype = {
accessKey:
gBrowserBundle.GetStringFromName("webNotifications.allow.accesskey"),
action: SitePermissions.ALLOW,
scope: SitePermissions.SCOPE_PERSISTENT,
},
{
label: gBrowserBundle.GetStringFromName("webNotifications.dontAllow"),
label: gBrowserBundle.GetStringFromName("webNotifications.notNow"),
accessKey:
gBrowserBundle.GetStringFromName("webNotifications.dontAllow.accesskey"),
gBrowserBundle.GetStringFromName("webNotifications.notNow.accesskey"),
action: SitePermissions.BLOCK,
},
{
label: PrivateBrowsingUtils.isBrowserPrivate(this.browser) ?
gBrowserBundle.GetStringFromName("webNotifications.neverForSession") :
gBrowserBundle.GetStringFromName("webNotifications.never"),
accessKey:
gBrowserBundle.GetStringFromName("webNotifications.never.accesskey"),
action: SitePermissions.BLOCK,
scope: SitePermissions.SCOPE_PERSISTENT,
},
];
},
};

Просмотреть файл

@ -50,8 +50,11 @@ function* testPrompt(Prompt) {
let popupNotification = getPopupNotificationNode();
popupNotification.checkbox.checked = false;
Assert.equal(notification.secondaryActions.length, 1,
"There should only be 1 secondary action");
let isNotificationPrompt = Prompt == PermissionUI.DesktopNotificationPermissionPrompt;
let expectedSecondaryActionsCount = isNotificationPrompt ? 2 : 1;
Assert.equal(notification.secondaryActions.length, expectedSecondaryActionsCount,
"There should only be " + expectedSecondaryActionsCount + " secondary action(s)");
yield clickSecondaryAction();
curPerm = SitePermissions.get(principal.URI, permissionKey, browser);
Assert.deepEqual(curPerm, {
@ -73,13 +76,19 @@ function* testPrompt(Prompt) {
TestPrompt.prompt();
yield shownPromise;
// Test denying the permission request with the checkbox checked.
// Test denying the permission request with the checkbox checked (for geolocation)
// or by clicking the "never" option from the dropdown (for notifications).
popupNotification = getPopupNotificationNode();
popupNotification.checkbox.checked = true;
let secondaryActionToClickIndex = 0;
if (isNotificationPrompt) {
secondaryActionToClickIndex = 1;
} else {
popupNotification.checkbox.checked = true;
}
Assert.equal(notification.secondaryActions.length, 1,
"There should only be 1 secondary action");
yield clickSecondaryAction();
Assert.equal(notification.secondaryActions.length, expectedSecondaryActionsCount,
"There should only be " + expectedSecondaryActionsCount + " secondary action(s)");
yield clickSecondaryAction(secondaryActionToClickIndex);
curPerm = SitePermissions.get(principal.URI, permissionKey);
Assert.deepEqual(curPerm, {
state: SitePermissions.BLOCK,

Просмотреть файл

@ -178,16 +178,39 @@ function clickMainAction() {
* For an opened PopupNotification, clicks on the secondary action,
* and waits for the panel to fully close.
*
* @param actionIndex (Number)
* The index of the secondary action to be clicked. The default
* secondary action (the button shown directly in the panel) is
* treated as having index 0.
*
* @return {Promise}
* Resolves once the panel has fired the "popuphidden"
* event.
*/
function clickSecondaryAction() {
function clickSecondaryAction(actionIndex) {
let removePromise =
BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popuphidden");
let popupNotification = getPopupNotificationNode();
popupNotification.secondaryButton.click();
return removePromise;
if (!actionIndex) {
popupNotification.secondaryButton.click();
return removePromise;
}
return Task.spawn(function* () {
// Click the dropmarker arrow and wait for the menu to show up.
let dropdownPromise =
BrowserTestUtils.waitForEvent(popupNotification.menupopup, "popupshown");
yield EventUtils.synthesizeMouseAtCenter(popupNotification.menubutton, {});
yield dropdownPromise;
// The menuitems in the dropdown are accessible as direct children of the panel,
// because they are injected into a <children> node in the XBL binding.
// The target action is the menuitem at index actionIndex - 1, because the first
// secondary action (index 0) is the button shown directly in the panel.
let actionMenuItem = popupNotification.querySelectorAll("menuitem")[actionIndex - 1];
yield EventUtils.synthesizeMouseAtCenter(actionMenuItem, {});
yield removePromise;
});
}
/**

Просмотреть файл

@ -3,7 +3,8 @@
const ORIGIN_URI = Services.io.newURI("http://mochi.test:8888");
const PERMISSION_NAME = "desktop-notification";
const PROMPT_ALLOW_BUTTON = -1;
const PROMPT_BLOCK_BUTTON = 0;
const PROMPT_NOT_NOW_BUTTON = 0;
const PROMPT_NEVER_BUTTON = 1;
const TEST_URL = "http://mochi.test:8888/browser/dom/notification/test/browser/notification.html";
/**
@ -21,10 +22,16 @@ function clickDoorhangerButton(aButtonIndex) {
let notification = notifications[0];
if (aButtonIndex == PROMPT_ALLOW_BUTTON) {
ok(true, "Triggering main action");
ok(true, "Triggering main action (allow the permission)");
notification.button.doCommand();
} else if (aButtonIndex == PROMPT_NEVER_BUTTON) {
ok(true, "Triggering secondary action (deny the permission permanently)");
// The menuitems in the dropdown are accessible as direct children of the panel,
// because they are injected into a <children> node in the XBL binding.
// The "never" button is the first menuitem in the dropdown.
notification.querySelector("menuitem").doCommand();
} else {
ok(true, "Triggering secondary action");
ok(true, "Triggering secondary action (deny the permission temporarily)");
notification.secondaryButton.doCommand();
}
}
@ -84,9 +91,22 @@ add_task(function* test_requestPermission_granted() {
"Check permission in perm. manager");
});
add_task(function* test_requestPermission_denied() {
add_task(function* test_requestPermission_denied_temporarily() {
yield tabWithRequest(function() {
clickDoorhangerButton(PROMPT_BLOCK_BUTTON);
clickDoorhangerButton(PROMPT_NOT_NOW_BUTTON);
}, "default");
ok(!PopupNotifications.getNotification("web-notifications"),
"Should remove the doorhanger notification icon if denied");
is(Services.perms.testPermission(ORIGIN_URI, PERMISSION_NAME),
Services.perms.UNKNOWN_ACTION,
"Check permission in perm. manager");
});
add_task(function* test_requestPermission_denied_permanently() {
yield tabWithRequest(function*() {
yield clickDoorhangerButton(PROMPT_NEVER_BUTTON);
}, "denied");
ok(!PopupNotifications.getNotification("web-notifications"),

Просмотреть файл

@ -515,7 +515,8 @@
class="popup-notification-button"
xbl:inherits="oncommand=secondarybuttoncommand,label=secondarybuttonlabel,accesskey=secondarybuttonaccesskey,hidden=secondarybuttonhidden"/>
<xul:toolbarseparator xbl:inherits="hidden=dropmarkerhidden"/>
<xul:button type="menu"
<xul:button anonid="menubutton"
type="menu"
class="popup-notification-button popup-notification-dropmarker"
xbl:inherits="onpopupshown=dropmarkerpopupshown,hidden=dropmarkerhidden">
<xul:menupopup anonid="menupopup"
@ -548,6 +549,9 @@
<field name="secondaryButton" readonly="true">
document.getAnonymousElementByAttribute(this, "anonid", "secondarybutton");
</field>
<field name="menubutton" readonly="true">
document.getAnonymousElementByAttribute(this, "anonid", "menubutton");
</field>
<field name="menupopup" readonly="true">
document.getAnonymousElementByAttribute(this, "anonid", "menupopup");
</field>