From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../unit/test_permmanager_remove_add_update.js | 84 ++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 extensions/permissions/test/unit/test_permmanager_remove_add_update.js (limited to 'extensions/permissions/test/unit/test_permmanager_remove_add_update.js') diff --git a/extensions/permissions/test/unit/test_permmanager_remove_add_update.js b/extensions/permissions/test/unit/test_permmanager_remove_add_update.js new file mode 100644 index 0000000000..6ec7b1f6e5 --- /dev/null +++ b/extensions/permissions/test/unit/test_permmanager_remove_add_update.js @@ -0,0 +1,84 @@ +/* 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, expireType] of permissions) { + let perm = perms.shift(); + Assert.ok(perm != null); + Assert.equal(perm.type, type); + Assert.equal(perm.capability, capability); + Assert.equal(perm.expireType, expireType); + } + Assert.ok(!perms.length); +} + +add_task(async function test() { + Services.prefs.setCharPref("permissions.manager.defaultsUrl", ""); + + // setup a profile directory + do_get_profile(); + + // We need to execute a pm method to be sure that the DB is fully + // initialized. + var pm = Services.perms; + Assert.ok(pm.all.length === 0); + + let principal = + Services.scriptSecurityManager.createContentPrincipalFromOrigin( + "http://example.com" + ); + + info("From session to persistent"); + pm.addFromPrincipal( + principal, + "test/foo", + pm.ALLOW_ACTION, + pm.EXPIRE_SESSION + ); + + check_enumerator(principal, [ + ["test/foo", pm.ALLOW_ACTION, pm.EXPIRE_SESSION], + ]); + + pm.addFromPrincipal(principal, "test/foo", pm.ALLOW_ACTION, pm.EXPIRE_NEVER); + + check_enumerator(principal, [["test/foo", pm.ALLOW_ACTION, pm.EXPIRE_NEVER]]); + + // Let's reload the DB. + Services.obs.notifyObservers(null, "testonly-reload-permissions-from-disk"); + + Assert.ok(pm.all.length === 1); + check_enumerator(principal, [["test/foo", pm.ALLOW_ACTION, pm.EXPIRE_NEVER]]); + + info("From persistent to session"); + pm.addFromPrincipal( + principal, + "test/foo", + pm.ALLOW_ACTION, + pm.EXPIRE_SESSION + ); + + check_enumerator(principal, [ + ["test/foo", pm.ALLOW_ACTION, pm.EXPIRE_SESSION], + ]); + + // Let's reload the DB. + Services.obs.notifyObservers(null, "testonly-reload-permissions-from-disk"); + Assert.ok(pm.all.length === 0); + + info("From persistent to persistent"); + pm.addFromPrincipal(principal, "test/foo", pm.ALLOW_ACTION, pm.EXPIRE_NEVER); + pm.addFromPrincipal(principal, "test/foo", pm.DENY_ACTION, pm.EXPIRE_NEVER); + + check_enumerator(principal, [["test/foo", pm.DENY_ACTION, pm.EXPIRE_NEVER]]); + + // Let's reload the DB. + Services.obs.notifyObservers(null, "testonly-reload-permissions-from-disk"); + Assert.ok(pm.all.length === 1); + check_enumerator(principal, [["test/foo", pm.DENY_ACTION, pm.EXPIRE_NEVER]]); + + info("Cleanup"); + pm.removeAll(); + check_enumerator(principal, []); +}); -- cgit v1.2.3