summaryrefslogtreecommitdiffstats
path: root/extensions/cookie/test/unit/test_permmanager_removepermission.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_removepermission.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_removepermission.js')
-rw-r--r--extensions/cookie/test/unit/test_permmanager_removepermission.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/extensions/cookie/test/unit/test_permmanager_removepermission.js b/extensions/cookie/test/unit/test_permmanager_removepermission.js
new file mode 100644
index 000000000..e8f5817e2
--- /dev/null
+++ b/extensions/cookie/test/unit/test_permmanager_removepermission.js
@@ -0,0 +1,67 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function run_test() {
+ // initialize the permission manager service
+ let pm = Cc["@mozilla.org/permissionmanager;1"].
+ getService(Ci.nsIPermissionManager);
+
+ do_check_eq(perm_count(), 0);
+
+ // add some permissions
+ let uri = NetUtil.newURI("http://amazon.com:8080/foobarbaz", null, null);
+ let uri2 = NetUtil.newURI("http://google.com:2048/quxx", null, null);
+
+ pm.add(uri, "apple", 0);
+ pm.add(uri, "apple", 3);
+ pm.add(uri, "pear", 3);
+ pm.add(uri, "pear", 1);
+ pm.add(uri, "cucumber", 1);
+ pm.add(uri, "cucumber", 1);
+ pm.add(uri, "cucumber", 1);
+
+ pm.add(uri2, "apple", 2);
+ pm.add(uri2, "pear", 0);
+ pm.add(uri2, "pear", 2);
+
+ // Make sure that removePermission doesn't remove more than one permission each time
+ do_check_eq(perm_count(), 5);
+
+ remove_one_by_type("apple");
+ do_check_eq(perm_count(), 4);
+
+ remove_one_by_type("apple");
+ do_check_eq(perm_count(), 3);
+
+ remove_one_by_type("pear");
+ do_check_eq(perm_count(), 2);
+
+ remove_one_by_type("cucumber");
+ do_check_eq(perm_count(), 1);
+
+ remove_one_by_type("pear");
+ do_check_eq(perm_count(), 0);
+
+
+ function perm_count() {
+ let enumerator = pm.enumerator;
+ let count = 0;
+ while (enumerator.hasMoreElements()) {
+ count++;
+ enumerator.getNext();
+ }
+
+ return count;
+ }
+
+ function remove_one_by_type(type) {
+ let enumerator = pm.enumerator;
+ while (enumerator.hasMoreElements()) {
+ let it = enumerator.getNext().QueryInterface(Ci.nsIPermission);
+ if (it.type == type) {
+ pm.removePermission(it);
+ break;
+ }
+ }
+ }
+}