gecko/extensions/cookie/test/test_app_cleardata_permissions.html
Andrea Marchesini 72c8687e50 Bug 827050 - Clear cookies and stored data in the browser clears remember my choice permissions for PROMPT_ACTION WebAPIs, r=mounir
--HG--
rename : dom/tests/mochitest/localstorage/frame_clear_browser_data.html => extensions/cookie/test/frame_clear_browser_data.html
rename : extensions/cookie/test/test_app_uninstall_permissions.html => extensions/cookie/test/test_app_cleardata_permissions.html
2013-01-07 18:37:01 +01:00

214 lines
7.4 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Tests that clearing mozbrowser private data removes the onlyInBrowser 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>
<p id="display"></p>
<div id="content">
<iframe src="http://example.com/tests/error404"></iframe>
</div>
<pre id="test">
<script type="application/javascript;version=1.7">
const Ci = Components.interfaces;
const Cc = Components.classes;
const Cu = Components.utils;
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);
var Webapps = {};
Cu.import("resource://gre/modules/Webapps.jsm", Webapps);
/**
* This function will make sure that the next applications we try to install
* will be installed. That means it will behave like if the user allowed the app
* to be installed in the door hanger.
*/
function confirmNextInstall() {
var panel = window.top.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell)
.chromeEventHandler.ownerDocument.defaultView
.PopupNotifications.panel
panel.addEventListener("popupshown", function() {
panel.removeEventListener("popupshown", arguments.callee, false);
this.childNodes[0].button.doCommand();
}, false);
}
// 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.appId == aAppId || aAppId == -1) {
nbPermissions++;
}
}
return nbPermissions;
}
permManager.addFromPrincipal(window.document.nodePrincipal, "webapps-manage",
Ci.nsIPermissionManager.ALLOW_ACTION);
permManager.addFromPrincipal(window.document.nodePrincipal, "browser",
Ci.nsIPermissionManager.ALLOW_ACTION);
var previousPrefs = {
mozBrowserFramesEnabled: null,
installerDryRun: null,
};
// Save the prefs we want to change (so we can re-set them later) and set them
// to the needed value.
try {
previousPrefs.mozBrowserFramesEnabled = SpecialPowers.getBoolPref('dom.mozBrowserFramesEnabled');
} catch(e)
{
}
SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', true);
try {
previousPrefs.installerDryRun = SpecialPowers.getBoolPref('browser.mozApps.installer.dry_run');
} catch(e) {
}
SpecialPowers.setBoolPref('browser.mozApps.installer.dry_run', true);
// We want to simulate that all apps are launchable, for testing purpose.
var gPreviousLaunchableValue = Webapps.DOMApplicationRegistry.allAppsLaunchable;
Webapps.DOMApplicationRegistry.allAppsLaunchable = true;
// URL of the manifest of the app we want to install.
const gManifestURL = "http://www.example.com:80/chrome/dom/tests/mochitest/webapps/apps/basic.webapp";
// ID of the installed app.
var gTestAppId = 0;
addLoadEvent(function() {
confirmNextInstall();
navigator.mozApps.install(gManifestURL, null).onsuccess = function() {
gTestAppId = appsService.getAppLocalIdByManifestURL(gManifestURL);
is(getPermissionCountForApp(gTestAppId), 0, "App should have no permission");
var currentPermissionCount = getPermissionCountForApp(-1);
var principal = secMan.getAppCodebasePrincipal(ioService.newURI("http://www.example.com", null, null),
gTestAppId, true);
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.org", null, null),
gTestAppId, true);
permManager.addFromPrincipal(principal, "foobar", Ci.nsIPermissionManager.ALLOW_ACTION);
is(getPermissionCountForApp(gTestAppId), 4, "App should have 4 permissions");
var frame = document.createElement('iframe');
frame.setAttribute('mozbrowser', '');
frame.setAttribute('mozapp', gManifestURL);
frame.src = 'http://www.example.com/chrome/extensions/cookie/test/frame_clear_browser_data.html';
frame.name = 'app';
frame.addEventListener('load', appFrameLoadEvent);
document.body.appendChild(frame);
};
});
function appFrameLoadEvent() {
/*
* The app frame has been loaded. We can now add permissions for the app to
* create browsers and we will load a page in this browser and wait for the
* load event.
*/
permManager.addFromPrincipal(window.frames[1].document.nodePrincipal, "browser",
Ci.nsIPermissionManager.ALLOW_ACTION);
var frame = document.createElement('iframe');
frame.setAttribute('mozbrowser', '');
frame.src = 'http://example.com/tests/error404_2';
frame.addEventListener('load', browserLoadEvent);
document.getElementsByName('app')[0].contentDocument.body.appendChild(frame);
}
function browserLoadEvent() {
/*
* The browser inside the app has loaded.
*/
frames[1].postMessage("clear", "http://www.example.com");
waitForClearBrowserData();
};
function waitForClearBrowserData() {
SimpleTest.executeSoon(function() {
if (frames[1].document.getElementsByTagName('done').length == 0) {
waitForClearBrowserData();
} else {
checks();
}
});
}
function checks() {
navigator.mozApps.mgmt.getAll().onsuccess = function() {
for (i in this.result) {
var app = this.result[i];
if (app.manifestURL == gManifestURL) {
is(getPermissionCountForApp(gTestAppId), 0, "App should have 0 permissions");
Webapps.DOMApplicationRegistry.allAppsLaunchable = gPreviousLaunchableValue;
// Now we uninstall the app and make sure everything is clean.
app.uninstall().onsuccess = function() {
is(getPermissionCountForApp(gTestAppId), 0, "App should have 0 permissions");
finish();
};
}
}
};
}
/**
* This method will be called when the test will be done. It is going to clear
* all storage data, permissions, etc.
*/
function finish() {
permManager.removeFromPrincipal(window.document.nodePrincipal, "webapps-manage",
Ci.nsIPermissionManager.ALLOW_ACTION);
permManager.removeFromPrincipal(window.document.nodePrincipal, "browser",
Ci.nsIPermissionManager.ALLOW_ACTION);
SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', previousPrefs.mozBrowserFramesEnabled);
SpecialPowers.setBoolPref('browser.mozApps.installer.dry_run', previousPrefs.installerDryRun);
SimpleTest.finish();
}
</script>
</pre>
</body>
</html>