1
0
Fork 0
firefox/extensions/permissions/test/unit/test_permmanager_getAllForPrincipal.js
Daniel Baumann 5e9a113729
Adding upstream version 140.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
2025-06-25 09:37:52 +02:00

72 lines
2.3 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
function check_enumerator(principal, permissions) {
let perms = Services.perms.getAllForPrincipal(principal);
for (let [type, capability] of permissions) {
let perm = perms.shift();
Assert.ok(perm != null);
Assert.equal(perm.type, type);
Assert.equal(perm.capability, capability);
Assert.equal(perm.expireType, Services.perms.EXPIRE_NEVER);
}
Assert.ok(!perms.length);
}
function run_test() {
let pm = Services.perms;
let principal =
Services.scriptSecurityManager.createContentPrincipalFromOrigin(
"http://example.com"
);
let subPrincipal =
Services.scriptSecurityManager.createContentPrincipalFromOrigin(
"http://sub.example.com"
);
check_enumerator(principal, []);
pm.addFromPrincipal(principal, "test/getallforuri", pm.ALLOW_ACTION);
check_enumerator(principal, [["test/getallforuri", pm.ALLOW_ACTION]]);
// check that uris are matched exactly
check_enumerator(subPrincipal, []);
pm.addFromPrincipal(subPrincipal, "test/getallforuri", pm.PROMPT_ACTION);
pm.addFromPrincipal(subPrincipal, "test/getallforuri2", pm.DENY_ACTION);
check_enumerator(subPrincipal, [
["test/getallforuri", pm.PROMPT_ACTION],
["test/getallforuri2", pm.DENY_ACTION],
]);
// check that the original uri list has not changed
check_enumerator(principal, [["test/getallforuri", pm.ALLOW_ACTION]]);
// check that UNKNOWN_ACTION permissions are ignored
pm.addFromPrincipal(principal, "test/getallforuri2", pm.UNKNOWN_ACTION);
pm.addFromPrincipal(principal, "test/getallforuri3", pm.DENY_ACTION);
check_enumerator(principal, [
["test/getallforuri", pm.ALLOW_ACTION],
["test/getallforuri3", pm.DENY_ACTION],
]);
// check that permission updates are reflected
pm.addFromPrincipal(principal, "test/getallforuri", pm.PROMPT_ACTION);
check_enumerator(principal, [
["test/getallforuri", pm.PROMPT_ACTION],
["test/getallforuri3", pm.DENY_ACTION],
]);
// check that permission removals are reflected
pm.removeFromPrincipal(principal, "test/getallforuri");
check_enumerator(principal, [["test/getallforuri3", pm.DENY_ACTION]]);
pm.removeAll();
check_enumerator(principal, []);
check_enumerator(subPrincipal, []);
}