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