extensions/cookie/test/test_app_uninstall_permissions.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=786296
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <meta charset="utf-8">
michael@0 8 <title>Tests that uninstalling app removes the permissions</title>
michael@0 9 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
michael@0 11 </head>
michael@0 12 <body>
michael@0 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=786296">Mozilla Bug 786296</a>
michael@0 14 <p id="display"></p>
michael@0 15 <div id="content">
michael@0 16
michael@0 17 </div>
michael@0 18 <pre id="test">
michael@0 19 <script type="application/javascript;version=1.7">
michael@0 20
michael@0 21 /** Test for Bug 786296 **/
michael@0 22
michael@0 23 var Ci = Components.interfaces;
michael@0 24 var Cc = Components.classes;
michael@0 25
michael@0 26 SimpleTest.waitForExplicitFinish();
michael@0 27
michael@0 28 var permManager = Cc["@mozilla.org/permissionmanager;1"]
michael@0 29 .getService(Ci.nsIPermissionManager);
michael@0 30 var appsService = Cc['@mozilla.org/AppsService;1']
michael@0 31 .getService(Ci.nsIAppsService);
michael@0 32 var secMan = Cc['@mozilla.org/scriptsecuritymanager;1']
michael@0 33 .getService(Ci.nsIScriptSecurityManager);
michael@0 34 var ioService = Cc["@mozilla.org/network/io-service;1"]
michael@0 35 .getService(Components.interfaces.nsIIOService);
michael@0 36
michael@0 37 // If aAppId = -1, returns permissions count, regardless of app.
michael@0 38 function getPermissionCountForApp(aAppId) {
michael@0 39 var nbPermissions = 0;
michael@0 40 var enumerator = permManager.enumerator;
michael@0 41
michael@0 42 while (enumerator.hasMoreElements()) {
michael@0 43 var permission = enumerator.getNext().QueryInterface(Ci.nsIPermission);
michael@0 44
michael@0 45 if (permission.appId == aAppId || aAppId == -1) {
michael@0 46 nbPermissions++;
michael@0 47 }
michael@0 48 }
michael@0 49
michael@0 50 return nbPermissions;
michael@0 51 }
michael@0 52
michael@0 53 permManager.addFromPrincipal(window.document.nodePrincipal, "webapps-manage",
michael@0 54 Ci.nsIPermissionManager.ALLOW_ACTION);
michael@0 55
michael@0 56 SimpleTest.registerCleanupFunction(() =>
michael@0 57 permManager.removeFromPrincipal(window.document.nodePrincipal, "webapps-manage",
michael@0 58 Ci.nsIPermissionManager.ALLOW_ACTION)
michael@0 59 );
michael@0 60
michael@0 61 var gManifestURL = "http://www.example.com/chrome/dom/tests/mochitest/webapps/apps/basic.webapp";
michael@0 62
michael@0 63 function onInstall() {
michael@0 64 var testAppId = appsService.getAppLocalIdByManifestURL(gManifestURL);
michael@0 65
michael@0 66 is(getPermissionCountForApp(testAppId), 0, "App should have no permission");
michael@0 67
michael@0 68 var currentPermissionCount = getPermissionCountForApp(-1);
michael@0 69
michael@0 70 var principal = secMan.getAppCodebasePrincipal(ioService.newURI("http://www.example.com", null, null),
michael@0 71 testAppId, false);
michael@0 72
michael@0 73 permManager.addFromPrincipal(principal, "foobar", Ci.nsIPermissionManager.ALLOW_ACTION);
michael@0 74 permManager.addFromPrincipal(principal, "foo", Ci.nsIPermissionManager.DENY_ACTION);
michael@0 75 permManager.addFromPrincipal(principal, "bar", Ci.nsIPermissionManager.ALLOW_ACTION, Ci.nsIPermissionManager.EXPIRE_SESSION, 0);
michael@0 76
michael@0 77 principal = secMan.getAppCodebasePrincipal(ioService.newURI("http://www.example.com", null, null),
michael@0 78 testAppId, true);
michael@0 79 permManager.addFromPrincipal(principal, "foobar", Ci.nsIPermissionManager.ALLOW_ACTION);
michael@0 80
michael@0 81 principal = secMan.getAppCodebasePrincipal(ioService.newURI("http://www.example.org", null, null),
michael@0 82 testAppId, false);
michael@0 83 permManager.addFromPrincipal(principal, "foobar", Ci.nsIPermissionManager.ALLOW_ACTION);
michael@0 84
michael@0 85 is(getPermissionCountForApp(testAppId), 5, "App should have 5 permissions");
michael@0 86
michael@0 87 // Not installed means not installed as native app.
michael@0 88 navigator.mozApps.mgmt.getNotInstalled().onsuccess = function() {
michael@0 89 for (i in this.result) {
michael@0 90 var app = this.result[i];
michael@0 91 if (app.manifestURL == gManifestURL) {
michael@0 92 navigator.mozApps.mgmt.uninstall(app).onsuccess = function() {
michael@0 93 is(getPermissionCountForApp(testAppId), 0, "App should have no permissions");
michael@0 94
michael@0 95 is(getPermissionCountForApp(-1), currentPermissionCount,
michael@0 96 "Number of permissions should not have changed");
michael@0 97
michael@0 98 SimpleTest.finish();
michael@0 99 };
michael@0 100 }
michael@0 101 }
michael@0 102 };
michael@0 103 }
michael@0 104
michael@0 105 SpecialPowers.autoConfirmAppInstall(() =>
michael@0 106 navigator.mozApps.install(gManifestURL, null).onsuccess = onInstall
michael@0 107 );
michael@0 108
michael@0 109 </script>
michael@0 110 </pre>
michael@0 111 </body>
michael@0 112 </html>

mercurial