summaryrefslogtreecommitdiffstats
path: root/extensions/cookie/test/unit/test_permmanager_getAllForURI.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_getAllForURI.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_getAllForURI.js')
-rw-r--r--extensions/cookie/test/unit/test_permmanager_getAllForURI.js78
1 files changed, 78 insertions, 0 deletions
diff --git a/extensions/cookie/test/unit/test_permmanager_getAllForURI.js b/extensions/cookie/test/unit/test_permmanager_getAllForURI.js
new file mode 100644
index 000000000..7fec41826
--- /dev/null
+++ b/extensions/cookie/test/unit/test_permmanager_getAllForURI.js
@@ -0,0 +1,78 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function check_enumerator(uri, permissions) {
+ let pm = Cc["@mozilla.org/permissionmanager;1"]
+ .getService(Ci.nsIPermissionManager);
+
+ let enumerator = pm.getAllForURI(uri);
+ for ([type, capability] of permissions) {
+ let perm = enumerator.getNext();
+ do_check_true(perm != null);
+ do_check_true(perm.principal.URI.equals(uri));
+ do_check_eq(perm.type, type);
+ do_check_eq(perm.capability, capability);
+ do_check_eq(perm.expireType, pm.EXPIRE_NEVER);
+ }
+ do_check_false(enumerator.hasMoreElements());
+}
+
+function run_test() {
+ let pm = Cc["@mozilla.org/permissionmanager;1"]
+ .getService(Ci.nsIPermissionManager);
+
+ let uri = NetUtil.newURI("http://example.com");
+ let sub = NetUtil.newURI("http://sub.example.com");
+
+ check_enumerator(uri, [ ]);
+
+ pm.add(uri, "test/getallforuri", pm.ALLOW_ACTION);
+ check_enumerator(uri, [
+ [ "test/getallforuri", pm.ALLOW_ACTION ]
+ ]);
+
+ // check that uris are matched exactly
+ check_enumerator(sub, [ ]);
+
+ pm.add(sub, "test/getallforuri", pm.PROMPT_ACTION);
+ pm.add(sub, "test/getallforuri2", pm.DENY_ACTION);
+
+ check_enumerator(sub, [
+ [ "test/getallforuri", pm.PROMPT_ACTION ],
+ [ "test/getallforuri2", pm.DENY_ACTION ]
+ ]);
+
+ // check that the original uri list has not changed
+ check_enumerator(uri, [
+ [ "test/getallforuri", pm.ALLOW_ACTION ]
+ ]);
+
+ // check that UNKNOWN_ACTION permissions are ignored
+ pm.add(uri, "test/getallforuri2", pm.UNKNOWN_ACTION);
+ pm.add(uri, "test/getallforuri3", pm.DENY_ACTION);
+
+ check_enumerator(uri, [
+ [ "test/getallforuri", pm.ALLOW_ACTION ],
+ [ "test/getallforuri3", pm.DENY_ACTION ]
+ ]);
+
+ // check that permission updates are reflected
+ pm.add(uri, "test/getallforuri", pm.PROMPT_ACTION);
+
+ check_enumerator(uri, [
+ [ "test/getallforuri", pm.PROMPT_ACTION ],
+ [ "test/getallforuri3", pm.DENY_ACTION ]
+ ]);
+
+ // check that permission removals are reflected
+ pm.remove(uri, "test/getallforuri");
+
+ check_enumerator(uri, [
+ [ "test/getallforuri3", pm.DENY_ACTION ]
+ ]);
+
+ pm.removeAll();
+ check_enumerator(uri, [ ]);
+ check_enumerator(sub, [ ]);
+}
+