Bug 1206252 - Part 3: Add tests for nsIPermissionManager.getAllForURI. r=jdm draft
authorJohann Hofmann <jhofmann@mozilla.com>
Tue, 12 Jul 2016 13:58:07 +0200
changeset 387578 8d0fda9065805190675bcaef6c11a4d777a8fc9e
parent 387577 7925c1ec0ca4676935f4c5f90521a2675d09d9d2
child 525388 4a4c883d4826a17566eeebe1a0d6ba03f23fcb0d
push id23003
push usermail@johann-hofmann.com
push dateThu, 14 Jul 2016 09:54:40 +0000
reviewersjdm
bugs1206252
milestone50.0a1
Bug 1206252 - Part 3: Add tests for nsIPermissionManager.getAllForURI. r=jdm MozReview-Commit-ID: 8XQ11wWxZ3F
extensions/cookie/test/unit/test_permmanager_getAllForURI.js
extensions/cookie/test/unit/xpcshell.ini
new file mode 100644
--- /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, [ ]);
+}
+
--- a/extensions/cookie/test/unit/xpcshell.ini
+++ b/extensions/cookie/test/unit/xpcshell.ini
@@ -17,16 +17,17 @@ skip-if = true # Bug 863738
 [test_cookies_read.js]
 [test_cookies_sync_failure.js]
 [test_cookies_thirdparty.js]
 [test_cookies_thirdparty_session.js]
 [test_domain_eviction.js]
 [test_eviction.js]
 [test_permmanager_defaults.js]
 [test_permmanager_expiration.js]
+[test_permmanager_getAllForURI.js]
 [test_permmanager_getPermissionObject.js]
 [test_permmanager_notifications.js]
 [test_permmanager_removeall.js]
 [test_permmanager_removesince.js]
 [test_permmanager_removeforapp.js]
 [test_permmanager_load_invalid_entries.js]
 skip-if = debug == true
 [test_permmanager_idn.js]