зеркало из https://github.com/mozilla/gecko-dev.git
115 строки
4.1 KiB
HTML
115 строки
4.1 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<!--
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=786296
|
|
-->
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Tests that uninstalling app removes the permissions</title>
|
|
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
|
|
</head>
|
|
<body>
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=786296">Mozilla Bug 786296</a>
|
|
<p id="display"></p>
|
|
<div id="content">
|
|
|
|
</div>
|
|
<pre id="test">
|
|
<script type="application/javascript;version=1.7">
|
|
|
|
/** Test for Bug 786296 **/
|
|
|
|
var Ci = Components.interfaces;
|
|
var Cc = Components.classes;
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
var permManager = Cc["@mozilla.org/permissionmanager;1"]
|
|
.getService(Ci.nsIPermissionManager);
|
|
var appsService = Cc['@mozilla.org/AppsService;1']
|
|
.getService(Ci.nsIAppsService);
|
|
var secMan = Cc['@mozilla.org/scriptsecuritymanager;1']
|
|
.getService(Ci.nsIScriptSecurityManager);
|
|
var ioService = Cc["@mozilla.org/network/io-service;1"]
|
|
.getService(Components.interfaces.nsIIOService);
|
|
|
|
// If aAppId = -1, returns permissions count, regardless of app.
|
|
function getPermissionCountForApp(aAppId) {
|
|
var nbPermissions = 0;
|
|
var enumerator = permManager.enumerator;
|
|
|
|
while (enumerator.hasMoreElements()) {
|
|
var permission = enumerator.getNext().QueryInterface(Ci.nsIPermission);
|
|
|
|
if (permission.principal.appId == aAppId || aAppId == -1) {
|
|
nbPermissions++;
|
|
}
|
|
}
|
|
|
|
return nbPermissions;
|
|
}
|
|
|
|
permManager.addFromPrincipal(window.document.nodePrincipal, "webapps-manage",
|
|
Ci.nsIPermissionManager.ALLOW_ACTION);
|
|
|
|
SimpleTest.registerCleanupFunction(() =>
|
|
permManager.removeFromPrincipal(window.document.nodePrincipal, "webapps-manage",
|
|
Ci.nsIPermissionManager.ALLOW_ACTION)
|
|
);
|
|
|
|
var gManifestURL = "http://www.example.com/chrome/dom/tests/mochitest/webapps/apps/basic.webapp";
|
|
|
|
function onInstall() {
|
|
var testAppId = appsService.getAppLocalIdByManifestURL(gManifestURL);
|
|
|
|
is(getPermissionCountForApp(testAppId), 0, "App should have no permission");
|
|
|
|
var currentPermissionCount = getPermissionCountForApp(-1);
|
|
|
|
var principal = secMan.getAppCodebasePrincipal(ioService.newURI("http://www.example.com", null, null),
|
|
testAppId, false);
|
|
|
|
permManager.addFromPrincipal(principal, "foobar", Ci.nsIPermissionManager.ALLOW_ACTION);
|
|
permManager.addFromPrincipal(principal, "foo", Ci.nsIPermissionManager.DENY_ACTION);
|
|
permManager.addFromPrincipal(principal, "bar", Ci.nsIPermissionManager.ALLOW_ACTION, Ci.nsIPermissionManager.EXPIRE_SESSION, 0);
|
|
|
|
principal = secMan.getAppCodebasePrincipal(ioService.newURI("http://www.example.com", null, null),
|
|
testAppId, true);
|
|
permManager.addFromPrincipal(principal, "foobar", Ci.nsIPermissionManager.ALLOW_ACTION);
|
|
|
|
principal = secMan.getAppCodebasePrincipal(ioService.newURI("http://www.example.org", null, null),
|
|
testAppId, false);
|
|
permManager.addFromPrincipal(principal, "foobar", Ci.nsIPermissionManager.ALLOW_ACTION);
|
|
|
|
is(getPermissionCountForApp(testAppId), 5, "App should have 5 permissions");
|
|
|
|
// Not installed means not installed as native app.
|
|
navigator.mozApps.mgmt.getNotInstalled().onsuccess = function() {
|
|
for (i in this.result) {
|
|
var app = this.result[i];
|
|
if (app.manifestURL == gManifestURL) {
|
|
navigator.mozApps.mgmt.uninstall(app).onsuccess = function() {
|
|
is(getPermissionCountForApp(testAppId), 0, "App should have no permissions");
|
|
|
|
is(getPermissionCountForApp(-1), currentPermissionCount,
|
|
"Number of permissions should not have changed");
|
|
|
|
SimpleTest.finish();
|
|
};
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
SpecialPowers.autoConfirmAppInstall(() =>
|
|
SpecialPowers.autoConfirmAppUninstall(() =>
|
|
navigator.mozApps.install(gManifestURL, null).onsuccess = onInstall
|
|
)
|
|
);
|
|
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|