diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /extensions/cookie/test/unit/test_permmanager_getPermissionObject.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-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_getPermissionObject.js')
-rw-r--r-- | extensions/cookie/test/unit/test_permmanager_getPermissionObject.js | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/extensions/cookie/test/unit/test_permmanager_getPermissionObject.js b/extensions/cookie/test/unit/test_permmanager_getPermissionObject.js new file mode 100644 index 000000000..d01b51923 --- /dev/null +++ b/extensions/cookie/test/unit/test_permmanager_getPermissionObject.js @@ -0,0 +1,95 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +function getPrincipalFromURI(aURI) { + let ssm = Cc["@mozilla.org/scriptsecuritymanager;1"] + .getService(Ci.nsIScriptSecurityManager); + let uri = NetUtil.newURI(aURI); + return ssm.createCodebasePrincipal(uri, {}); +} + +function getSystemPrincipal() { + return Cc["@mozilla.org/scriptsecuritymanager;1"] + .getService(Ci.nsIScriptSecurityManager) + .getSystemPrincipal(); +} + +function run_test() { + var pm = Cc["@mozilla.org/permissionmanager;1"]. + getService(Ci.nsIPermissionManager); + + do_check_null(pm.getPermissionObject(getSystemPrincipal(), "test/pobject", false)); + + let principal = getPrincipalFromURI("http://example.com"); + let subPrincipal = getPrincipalFromURI("http://sub.example.com"); + let subSubPrincipal = getPrincipalFromURI("http://sub.sub.example.com"); + + do_check_null(pm.getPermissionObject(principal, "test/pobject", false)); + do_check_null(pm.getPermissionObject(principal, "test/pobject", true)); + + pm.addFromPrincipal(principal, "test/pobject", pm.ALLOW_ACTION); + var rootPerm = pm.getPermissionObject(principal, "test/pobject", false); + do_check_true(rootPerm != null); + do_check_eq(rootPerm.principal.origin, "http://example.com"); + do_check_eq(rootPerm.type, "test/pobject"); + do_check_eq(rootPerm.capability, pm.ALLOW_ACTION); + do_check_eq(rootPerm.expireType, pm.EXPIRE_NEVER); + + var rootPerm2 = pm.getPermissionObject(principal, "test/pobject", true); + do_check_true(rootPerm != null); + do_check_eq(rootPerm.principal.origin, "http://example.com"); + + var subPerm = pm.getPermissionObject(subPrincipal, "test/pobject", true); + do_check_null(subPerm); + subPerm = pm.getPermissionObject(subPrincipal, "test/pobject", false); + do_check_true(subPerm != null); + do_check_eq(subPerm.principal.origin, "http://example.com"); + do_check_eq(subPerm.type, "test/pobject"); + do_check_eq(subPerm.capability, pm.ALLOW_ACTION); + + subPerm = pm.getPermissionObject(subSubPrincipal, "test/pobject", true); + do_check_null(subPerm); + subPerm = pm.getPermissionObject(subSubPrincipal, "test/pobject", false); + do_check_true(subPerm != null); + do_check_eq(subPerm.principal.origin, "http://example.com"); + + pm.addFromPrincipal(principal, "test/pobject", pm.DENY_ACTION, pm.EXPIRE_SESSION); + + // make sure permission objects are not dynamic + do_check_eq(rootPerm.capability, pm.ALLOW_ACTION); + + // but do update on change + rootPerm = pm.getPermissionObject(principal, "test/pobject", true); + do_check_eq(rootPerm.capability, pm.DENY_ACTION); + do_check_eq(rootPerm.expireType, pm.EXPIRE_SESSION); + + subPerm = pm.getPermissionObject(subPrincipal, "test/pobject", false); + do_check_eq(subPerm.principal.origin, "http://example.com"); + do_check_eq(subPerm.capability, pm.DENY_ACTION); + do_check_eq(subPerm.expireType, pm.EXPIRE_SESSION); + + pm.addFromPrincipal(subPrincipal, "test/pobject", pm.PROMPT_ACTION); + rootPerm = pm.getPermissionObject(principal, "test/pobject", true); + do_check_eq(rootPerm.principal.origin, "http://example.com"); + do_check_eq(rootPerm.capability, pm.DENY_ACTION); + + subPerm = pm.getPermissionObject(subPrincipal, "test/pobject", true); + do_check_eq(subPerm.principal.origin, "http://sub.example.com"); + do_check_eq(subPerm.capability, pm.PROMPT_ACTION); + + subPerm = pm.getPermissionObject(subPrincipal, "test/pobject", false); + do_check_eq(subPerm.principal.origin, "http://sub.example.com"); + do_check_eq(subPerm.capability, pm.PROMPT_ACTION); + + subPerm = pm.getPermissionObject(subSubPrincipal, "test/pobject", true); + do_check_null(subPerm); + + subPerm = pm.getPermissionObject(subSubPrincipal, "test/pobject", false); + do_check_eq(subPerm.principal.origin, "http://sub.example.com"); + do_check_eq(subPerm.capability, pm.PROMPT_ACTION); + + pm.removeFromPrincipal(principal, "test/pobject"); + + rootPerm = pm.getPermissionObject(principal, "test/pobject", true); + do_check_null(rootPerm); +} |