mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 21:01:08 +00:00
Bug 1273260 - Add a pref to override push permissions. r=wchen
MozReview-Commit-ID: 8nJzACxIJmI --HG-- extra : rebase_source : 05a0f8bae462f40ed78f8c0d2d2926aaf3ec0524
This commit is contained in:
parent
bd3a9d8a05
commit
b9c156e19b
@ -150,8 +150,17 @@ Push.prototype = {
|
||||
},
|
||||
|
||||
_testPermission: function() {
|
||||
return Services.perms.testExactPermissionFromPrincipal(
|
||||
let permission = Services.perms.testExactPermissionFromPrincipal(
|
||||
this._principal, "desktop-notification");
|
||||
if (permission == Ci.nsIPermissionManager.ALLOW_ACTION) {
|
||||
return permission;
|
||||
}
|
||||
try {
|
||||
if (Services.prefs.getBoolPref("dom.push.testing.ignorePermission")) {
|
||||
permission = Ci.nsIPermissionManager.ALLOW_ACTION;
|
||||
}
|
||||
} catch (e) {}
|
||||
return permission;
|
||||
},
|
||||
|
||||
_requestPermission: function(allowCallback, cancelCallback) {
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "mozilla/dom/PushManager.h"
|
||||
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "mozilla/unused.h"
|
||||
#include "mozilla/dom/PushManagerBinding.h"
|
||||
@ -54,7 +55,8 @@ GetPermissionState(nsIPrincipal* aPrincipal,
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (permission == nsIPermissionManager::ALLOW_ACTION) {
|
||||
if (permission == nsIPermissionManager::ALLOW_ACTION ||
|
||||
Preferences::GetBool("dom.push.testing.ignorePermission", false)) {
|
||||
aState = PushPermissionState::Granted;
|
||||
} else if (permission == nsIPermissionManager::DENY_ACTION) {
|
||||
aState = PushPermissionState::Denied;
|
||||
|
@ -83,6 +83,15 @@ http://creativecommons.org/licenses/publicdomain/
|
||||
yield setPushPermission(test.action);
|
||||
var state = yield registration.pushManager.permissionState();
|
||||
is(state, test.state, JSON.stringify(test));
|
||||
try {
|
||||
yield SpecialPowers.pushPrefEnv({ set: [
|
||||
["dom.push.testing.ignorePermission", true]] });
|
||||
state = yield registration.pushManager.permissionState();
|
||||
is(state, "granted", `Should ignore ${
|
||||
test.action} if the override pref is set`);
|
||||
} finally {
|
||||
yield SpecialPowers.flushPrefEnv();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -150,11 +150,9 @@
|
||||
|
||||
// Remove permissions and prefs when the test finishes.
|
||||
SimpleTest.registerCleanupFunction(() => {
|
||||
return new Promise(resolve => {
|
||||
SpecialPowers.flushPermissions(_ => {
|
||||
SpecialPowers.flushPrefEnv(resolve);
|
||||
});
|
||||
}).then(_ => {
|
||||
return new Promise(resolve =>
|
||||
SpecialPowers.flushPermissions(resolve)
|
||||
).then(_ => SpecialPowers.flushPrefEnv()).then(_ => {
|
||||
restorePushService();
|
||||
return teardownMockPushSocket();
|
||||
});
|
||||
@ -169,15 +167,13 @@ function setPushPermission(allow) {
|
||||
}
|
||||
|
||||
function setupPrefs() {
|
||||
return new Promise(resolve => {
|
||||
SpecialPowers.pushPrefEnv({"set": [
|
||||
["dom.push.enabled", true],
|
||||
["dom.push.connection.enabled", true],
|
||||
["dom.serviceWorkers.exemptFromPerDomainMax", true],
|
||||
["dom.serviceWorkers.enabled", true],
|
||||
["dom.serviceWorkers.testing.enabled", true]
|
||||
]}, resolve);
|
||||
});
|
||||
return SpecialPowers.pushPrefEnv({"set": [
|
||||
["dom.push.enabled", true],
|
||||
["dom.push.connection.enabled", true],
|
||||
["dom.serviceWorkers.exemptFromPerDomainMax", true],
|
||||
["dom.serviceWorkers.enabled", true],
|
||||
["dom.serviceWorkers.testing.enabled", true]
|
||||
]});
|
||||
}
|
||||
|
||||
function setupPrefsAndReplaceService(mockService) {
|
||||
|
Loading…
Reference in New Issue
Block a user