summaryrefslogtreecommitdiffstats
path: root/extensions/cookie/test/unit/test_permmanager_cleardata.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /extensions/cookie/test/unit/test_permmanager_cleardata.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'extensions/cookie/test/unit/test_permmanager_cleardata.js')
-rw-r--r--extensions/cookie/test/unit/test_permmanager_cleardata.js68
1 files changed, 68 insertions, 0 deletions
diff --git a/extensions/cookie/test/unit/test_permmanager_cleardata.js b/extensions/cookie/test/unit/test_permmanager_cleardata.js
new file mode 100644
index 000000000..faa2579f5
--- /dev/null
+++ b/extensions/cookie/test/unit/test_permmanager_cleardata.js
@@ -0,0 +1,68 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+var pm;
+
+// Create a principal based on the { origin, originAttributes }.
+function createPrincipal(aOrigin, aOriginAttributes)
+{
+ return Services.scriptSecurityManager.createCodebasePrincipal(NetUtil.newURI(aOrigin), aOriginAttributes);
+}
+
+// Return the data required by 'clear-origin-attributes-data' notification.
+function getData(aPattern)
+{
+ return JSON.stringify(aPattern);
+}
+
+// Use aEntries to create principals, add permissions to them and check that they have them.
+// Then, it is notifying 'clear-origin-attributes-data' with the given aData and check if the permissions
+// of principals[i] matches the permission in aResults[i].
+function test(aEntries, aData, aResults)
+{
+ let principals = [];
+
+ for (entry of aEntries) {
+ principals.push(createPrincipal(entry.origin, entry.originAttributes));
+ }
+
+ for (principal of principals) {
+ do_check_eq(pm.testPermissionFromPrincipal(principal, "test/clear-origin"), pm.UNKNOWN_ACTION);
+ pm.addFromPrincipal(principal, "test/clear-origin", pm.ALLOW_ACTION, pm.EXPIRE_NEVER, 0);
+ do_check_eq(pm.testPermissionFromPrincipal(principal, "test/clear-origin"), pm.ALLOW_ACTION);
+ }
+
+ Services.obs.notifyObservers(null, 'clear-origin-attributes-data', aData);
+
+ var length = aEntries.length;
+ for (let i=0; i<length; ++i) {
+ do_check_eq(pm.testPermissionFromPrincipal(principals[i], 'test/clear-origin'), aResults[i]);
+
+ // Remove allowed actions.
+ if (aResults[i] == pm.ALLOW_ACTION) {
+ pm.removeFromPrincipal(principals[i], 'test/clear-origin');
+ }
+ }
+}
+
+function run_test()
+{
+ do_get_profile();
+
+ pm = Cc["@mozilla.org/permissionmanager;1"]
+ .getService(Ci.nsIPermissionManager);
+
+ let entries = [
+ { origin: 'http://example.com', originAttributes: { appId: 1 } },
+ { origin: 'http://example.com', originAttributes: { appId: 1, inIsolatedMozBrowser: true } },
+ { origin: 'http://example.com', originAttributes: {} },
+ { origin: 'http://example.com', originAttributes: { appId: 2 } },
+ ];
+
+ // In that case, all permissions from app 1 should be removed but not the other ones.
+ test(entries, getData({appId: 1}), [ pm.UNKNOWN_ACTION, pm.UNKNOWN_ACTION, pm.ALLOW_ACTION, pm.ALLOW_ACTION ]);
+
+ // In that case, only the permissions of app 1 related to a browserElement should be removed.
+ // All the other permissions should stay.
+ test(entries, getData({appId: 1, inIsolatedMozBrowser: true}), [ pm.ALLOW_ACTION, pm.UNKNOWN_ACTION, pm.ALLOW_ACTION, pm.ALLOW_ACTION ]);
+}