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 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=816847 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 816847</title> |
michael@0 | 8 | <script type="text/javascript" src="/MochiKit/MochiKit.js"></script> |
michael@0 | 9 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 10 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 11 | </head> |
michael@0 | 12 | <body onload="starttest();"> |
michael@0 | 13 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=816847">Mozilla Bug 816847</a> |
michael@0 | 14 | <p id="display"></p> |
michael@0 | 15 | <div id="content" style="display: none"> |
michael@0 | 16 | |
michael@0 | 17 | </div> |
michael@0 | 18 | <pre id="test"> |
michael@0 | 19 | <script class="testbody" type="text/javascript"> |
michael@0 | 20 | /** Test for Bug 816847 **/ |
michael@0 | 21 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 22 | |
michael@0 | 23 | const Cc = SpecialPowers.Cc; |
michael@0 | 24 | const Ci = SpecialPowers.Ci; |
michael@0 | 25 | const Cu = SpecialPowers.Cu; |
michael@0 | 26 | |
michael@0 | 27 | const Services = Cu.import("resource://gre/modules/Services.jsm").Services; |
michael@0 | 28 | const appsSvc = Cc["@mozilla.org/AppsService;1"] |
michael@0 | 29 | .getService(Ci.nsIAppsService) |
michael@0 | 30 | |
michael@0 | 31 | const manifest = "https://example.com/manifest.webapp"; |
michael@0 | 32 | const allow = Ci.nsIPermissionManager.ALLOW_ACTION; |
michael@0 | 33 | const unknown = Ci.nsIPermissionManager.UNKNOWN_ACTION; |
michael@0 | 34 | const perms = ['network-events', 'geolocation', 'camera', 'alarms'] |
michael@0 | 35 | |
michael@0 | 36 | function createPrincipal(aURI, aIsApp, aIsInBrowserElement) { |
michael@0 | 37 | if(aIsApp) { |
michael@0 | 38 | var app = appsSvc.getAppByManifestURL(aURI); |
michael@0 | 39 | var localId = appsSvc.getAppLocalIdByManifestURL(aURI); |
michael@0 | 40 | var uri = Services.io.newURI(app.origin, null, null); |
michael@0 | 41 | return Services.scriptSecurityManager |
michael@0 | 42 | .getAppCodebasePrincipal(uri, |
michael@0 | 43 | localId, |
michael@0 | 44 | aIsInBrowserElement); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | var uri = Services.io.newURI(aURI, null, null); |
michael@0 | 48 | return Services.scriptSecurityManager |
michael@0 | 49 | .getNoAppCodebasePrincipal(uri); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | // test addPermission and removePermission |
michael@0 | 53 | function starttest(){ |
michael@0 | 54 | var app = appsSvc.getAppByManifestURL(manifest); |
michael@0 | 55 | ok(app != null, "Got an app "); |
michael@0 | 56 | |
michael@0 | 57 | var origin = app.origin |
michael@0 | 58 | var nodePrincipal = SpecialPowers.wrap(document).nodePrincipal; |
michael@0 | 59 | var appPrincipal = createPrincipal(manifest, true); |
michael@0 | 60 | var noappPrincipal = createPrincipal(origin, false); |
michael@0 | 61 | |
michael@0 | 62 | SpecialPowers.addPermission(perms[0], true, origin); |
michael@0 | 63 | SpecialPowers.addPermission(perms[1], true, {manifestURL: manifest}); |
michael@0 | 64 | SpecialPowers.addPermission(perms[2], true, document); |
michael@0 | 65 | SpecialPowers.addPermission(perms[3], true, {url: origin, |
michael@0 | 66 | appId: Ci.nsIScriptSecurityManager.NO_APP_ID}); |
michael@0 | 67 | |
michael@0 | 68 | is(Services.perms.testPermissionFromPrincipal(noappPrincipal, perms[0]), |
michael@0 | 69 | allow, "Set permission by string"); |
michael@0 | 70 | is(Services.perms.testPermissionFromPrincipal(appPrincipal, perms[1]), |
michael@0 | 71 | allow, "Set permission by manifestURL"); |
michael@0 | 72 | is(Services.perms.testPermissionFromPrincipal(nodePrincipal, perms[2]), |
michael@0 | 73 | allow, "Set permission by principal"); |
michael@0 | 74 | is(Services.perms.testPermissionFromPrincipal(noappPrincipal, perms[3]), |
michael@0 | 75 | allow, "Set permission by other"); |
michael@0 | 76 | is(Services.perms.testPermissionFromPrincipal(noappPrincipal, perms[1]), |
michael@0 | 77 | unknown, "Check that app permission doesn't leak to normal page"); |
michael@0 | 78 | |
michael@0 | 79 | SpecialPowers.removePermission(perms[0], origin); |
michael@0 | 80 | SpecialPowers.removePermission(perms[1], {manifestURL: manifest}); |
michael@0 | 81 | SpecialPowers.removePermission(perms[2], document); |
michael@0 | 82 | SpecialPowers.removePermission(perms[3], {url: origin, |
michael@0 | 83 | appId: Ci.nsIScriptSecurityManager.NO_APP_ID}); |
michael@0 | 84 | |
michael@0 | 85 | is(Services.perms.testPermissionFromPrincipal(noappPrincipal, perms[0]), |
michael@0 | 86 | unknown, "Removed permission by string"); |
michael@0 | 87 | is(Services.perms.testPermissionFromPrincipal(appPrincipal, perms[1]), |
michael@0 | 88 | unknown, "Removed permission by manifestURL"); |
michael@0 | 89 | is(Services.perms.testPermissionFromPrincipal(nodePrincipal, perms[2]), |
michael@0 | 90 | unknown, "Removed permission by principal"); |
michael@0 | 91 | is(Services.perms.testPermissionFromPrincipal(noappPrincipal, perms[3]), |
michael@0 | 92 | unknown, "Removed permission by other"); |
michael@0 | 93 | |
michael@0 | 94 | SimpleTest.finish(); |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | </script> |
michael@0 | 98 | </pre> |
michael@0 | 99 | </body> |
michael@0 | 100 | </html> |
michael@0 | 101 |