Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | function getPrincipalFromURI(uri) { |
michael@0 | 5 | return Cc["@mozilla.org/scriptsecuritymanager;1"] |
michael@0 | 6 | .getService(Ci.nsIScriptSecurityManager) |
michael@0 | 7 | .getNoAppCodebasePrincipal(NetUtil.newURI(uri)); |
michael@0 | 8 | } |
michael@0 | 9 | |
michael@0 | 10 | function getSystemPrincipal() { |
michael@0 | 11 | return Cc["@mozilla.org/scriptsecuritymanager;1"] |
michael@0 | 12 | .getService(Ci.nsIScriptSecurityManager) |
michael@0 | 13 | .getSystemPrincipal(); |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | function run_test() { |
michael@0 | 17 | var pm = Cc["@mozilla.org/permissionmanager;1"]. |
michael@0 | 18 | getService(Ci.nsIPermissionManager); |
michael@0 | 19 | |
michael@0 | 20 | do_check_null(pm.getPermissionObject(getSystemPrincipal(), "test/pobject", false)); |
michael@0 | 21 | |
michael@0 | 22 | let principal = getPrincipalFromURI("http://example.com"); |
michael@0 | 23 | let subPrincipal = getPrincipalFromURI("http://sub.example.com"); |
michael@0 | 24 | let subSubPrincipal = getPrincipalFromURI("http://sub.sub.example.com"); |
michael@0 | 25 | |
michael@0 | 26 | do_check_null(pm.getPermissionObject(principal, "test/pobject", false)); |
michael@0 | 27 | do_check_null(pm.getPermissionObject(principal, "test/pobject", true)); |
michael@0 | 28 | |
michael@0 | 29 | pm.addFromPrincipal(principal, "test/pobject", pm.ALLOW_ACTION); |
michael@0 | 30 | var rootPerm = pm.getPermissionObject(principal, "test/pobject", false); |
michael@0 | 31 | do_check_true(rootPerm != null); |
michael@0 | 32 | do_check_eq(rootPerm.host, "example.com"); |
michael@0 | 33 | do_check_eq(rootPerm.type, "test/pobject"); |
michael@0 | 34 | do_check_eq(rootPerm.capability, pm.ALLOW_ACTION); |
michael@0 | 35 | do_check_eq(rootPerm.expireType, pm.EXPIRE_NEVER); |
michael@0 | 36 | |
michael@0 | 37 | var rootPerm2 = pm.getPermissionObject(principal, "test/pobject", true); |
michael@0 | 38 | do_check_true(rootPerm != null); |
michael@0 | 39 | do_check_eq(rootPerm.host, "example.com"); |
michael@0 | 40 | |
michael@0 | 41 | var subPerm = pm.getPermissionObject(subPrincipal, "test/pobject", true); |
michael@0 | 42 | do_check_null(subPerm); |
michael@0 | 43 | subPerm = pm.getPermissionObject(subPrincipal, "test/pobject", false); |
michael@0 | 44 | do_check_true(subPerm != null); |
michael@0 | 45 | do_check_eq(subPerm.host, "example.com"); |
michael@0 | 46 | do_check_eq(subPerm.type, "test/pobject"); |
michael@0 | 47 | do_check_eq(subPerm.capability, pm.ALLOW_ACTION); |
michael@0 | 48 | |
michael@0 | 49 | subPerm = pm.getPermissionObject(subSubPrincipal, "test/pobject", true); |
michael@0 | 50 | do_check_null(subPerm); |
michael@0 | 51 | subPerm = pm.getPermissionObject(subSubPrincipal, "test/pobject", false); |
michael@0 | 52 | do_check_true(subPerm != null); |
michael@0 | 53 | do_check_eq(subPerm.host, "example.com"); |
michael@0 | 54 | |
michael@0 | 55 | pm.addFromPrincipal(principal, "test/pobject", pm.DENY_ACTION, pm.EXPIRE_SESSION); |
michael@0 | 56 | |
michael@0 | 57 | // make sure permission objects are not dynamic |
michael@0 | 58 | do_check_eq(rootPerm.capability, pm.ALLOW_ACTION); |
michael@0 | 59 | |
michael@0 | 60 | // but do update on change |
michael@0 | 61 | rootPerm = pm.getPermissionObject(principal, "test/pobject", true); |
michael@0 | 62 | do_check_eq(rootPerm.capability, pm.DENY_ACTION); |
michael@0 | 63 | do_check_eq(rootPerm.expireType, pm.EXPIRE_SESSION); |
michael@0 | 64 | |
michael@0 | 65 | subPerm = pm.getPermissionObject(subPrincipal, "test/pobject", false); |
michael@0 | 66 | do_check_eq(subPerm.host, "example.com"); |
michael@0 | 67 | do_check_eq(subPerm.capability, pm.DENY_ACTION); |
michael@0 | 68 | do_check_eq(subPerm.expireType, pm.EXPIRE_SESSION); |
michael@0 | 69 | |
michael@0 | 70 | pm.addFromPrincipal(subPrincipal, "test/pobject", pm.PROMPT_ACTION); |
michael@0 | 71 | rootPerm = pm.getPermissionObject(principal, "test/pobject", true); |
michael@0 | 72 | do_check_eq(rootPerm.host, "example.com"); |
michael@0 | 73 | do_check_eq(rootPerm.capability, pm.DENY_ACTION); |
michael@0 | 74 | |
michael@0 | 75 | subPerm = pm.getPermissionObject(subPrincipal, "test/pobject", true); |
michael@0 | 76 | do_check_eq(subPerm.host, "sub.example.com"); |
michael@0 | 77 | do_check_eq(subPerm.capability, pm.PROMPT_ACTION); |
michael@0 | 78 | |
michael@0 | 79 | subPerm = pm.getPermissionObject(subPrincipal, "test/pobject", false); |
michael@0 | 80 | do_check_eq(subPerm.host, "sub.example.com"); |
michael@0 | 81 | do_check_eq(subPerm.capability, pm.PROMPT_ACTION); |
michael@0 | 82 | |
michael@0 | 83 | subPerm = pm.getPermissionObject(subSubPrincipal, "test/pobject", true); |
michael@0 | 84 | do_check_null(subPerm); |
michael@0 | 85 | |
michael@0 | 86 | subPerm = pm.getPermissionObject(subSubPrincipal, "test/pobject", false); |
michael@0 | 87 | do_check_eq(subPerm.host, "sub.example.com"); |
michael@0 | 88 | do_check_eq(subPerm.capability, pm.PROMPT_ACTION); |
michael@0 | 89 | |
michael@0 | 90 | pm.removeFromPrincipal(principal, "test/pobject"); |
michael@0 | 91 | |
michael@0 | 92 | rootPerm = pm.getPermissionObject(principal, "test/pobject", true); |
michael@0 | 93 | do_check_null(rootPerm); |
michael@0 | 94 | } |