2012-09-28 15:16:29 -07:00
|
|
|
/* vim:set ts=2 sw=2 sts=2 et: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
const DEBUG = 0;
|
|
|
|
function log()
|
|
|
|
{
|
|
|
|
if (DEBUG) {
|
|
|
|
let output = [];
|
|
|
|
for (let prop in arguments) {
|
|
|
|
output.push(arguments[prop]);
|
|
|
|
}
|
|
|
|
dump("-*- browser_webapps_permissions test: " + output.join(" ") + "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let scope = {};
|
|
|
|
Cu.import("resource://gre/modules/PermissionSettings.jsm", scope);
|
|
|
|
|
2013-03-18 06:24:55 -07:00
|
|
|
var windowMediator = Cc["@mozilla.org/appshell/window-mediator;1"]
|
|
|
|
.getService(Ci.nsIWindowMediator);
|
|
|
|
|
2012-09-28 15:16:29 -07:00
|
|
|
const TEST_URL =
|
|
|
|
"http://mochi.test:8888/browser/dom/tests/browser/test-webapps-permissions.html";
|
|
|
|
const TEST_MANIFEST_URL =
|
|
|
|
"http://mochi.test:8888/browser/dom/tests/browser/test-webapp.webapp";
|
|
|
|
const TEST_ORIGIN_URL = "http://mochi.test:8888";
|
|
|
|
|
|
|
|
const installedPermsToTest = {
|
2013-04-05 16:38:08 -07:00
|
|
|
"storage": "unknown",
|
2012-09-28 15:16:29 -07:00
|
|
|
"geolocation": "prompt",
|
2012-10-10 09:16:49 -07:00
|
|
|
"alarms": "allow",
|
2013-01-09 14:34:13 -08:00
|
|
|
"desktop-notification": "allow",
|
|
|
|
"audio-channel-normal": "allow"
|
2012-09-28 15:16:29 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
const uninstalledPermsToTest = {
|
|
|
|
"geolocation": "unknown",
|
2012-10-10 09:16:49 -07:00
|
|
|
"alarms": "unknown",
|
2013-01-09 14:34:13 -08:00
|
|
|
"desktop-notification": "unknown",
|
|
|
|
"audio-channel-normal": "unknown"
|
2012-09-28 15:16:29 -07:00
|
|
|
};
|
|
|
|
|
2013-01-11 04:50:50 -08:00
|
|
|
var permManager = Cc["@mozilla.org/permissionmanager;1"]
|
|
|
|
.getService(Ci.nsIPermissionManager);
|
|
|
|
permManager.addFromPrincipal(window.document.nodePrincipal,
|
|
|
|
"webapps-manage",
|
|
|
|
Ci.nsIPermissionManager.ALLOW_ACTION);
|
|
|
|
|
2012-09-28 15:16:29 -07:00
|
|
|
var gWindow, gNavigator;
|
|
|
|
|
|
|
|
function test() {
|
|
|
|
waitForExplicitFinish();
|
|
|
|
|
|
|
|
var tab = gBrowser.addTab(TEST_URL);
|
|
|
|
gBrowser.selectedTab = tab;
|
|
|
|
var browser = gBrowser.selectedBrowser;
|
|
|
|
PopupNotifications.panel.addEventListener("popupshown", handlePopup, false);
|
|
|
|
|
|
|
|
registerCleanupFunction(function () {
|
|
|
|
gWindow = null;
|
|
|
|
gBrowser.removeTab(tab);
|
2013-03-18 06:24:55 -07:00
|
|
|
|
|
|
|
// The installation may have created a XUL alert window
|
|
|
|
// (see webappsUI.installationSuccessNotification).
|
|
|
|
// It need to be closed before the test finishes.
|
|
|
|
var browsers = windowMediator.getEnumerator('alert:alert');
|
|
|
|
while (browsers.hasMoreElements()) {
|
|
|
|
browsers.getNext().close();
|
|
|
|
}
|
2012-09-28 15:16:29 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
browser.addEventListener("DOMContentLoaded", function onLoad(event) {
|
|
|
|
browser.removeEventListener("DOMContentLoaded", onLoad, false);
|
|
|
|
gWindow = browser.contentWindow;
|
|
|
|
|
|
|
|
SpecialPowers.setBoolPref("dom.mozPermissionSettings.enabled", true);
|
|
|
|
SpecialPowers.addPermission("permissions", true, browser.contentWindow.document);
|
|
|
|
SpecialPowers.addPermission("permissions", true, browser.contentDocument);
|
2013-01-19 08:56:29 -08:00
|
|
|
SpecialPowers.addPermission("webapps-manage", true, browser.contentWindow.document);
|
2012-09-28 15:16:29 -07:00
|
|
|
|
|
|
|
executeSoon(function (){
|
|
|
|
gWindow.focus();
|
|
|
|
var nav = XPCNativeWrapper.unwrap(browser.contentWindow.navigator);
|
|
|
|
ok(nav.mozApps, "we have a mozApps property");
|
|
|
|
var navMozPerms = nav.mozPermissionSettings;
|
|
|
|
ok(navMozPerms, "mozPermissions is available");
|
2012-11-19 12:31:15 -08:00
|
|
|
|
2012-09-28 15:16:29 -07:00
|
|
|
// INSTALL app
|
|
|
|
var pendingInstall = nav.mozApps.install(TEST_MANIFEST_URL, null);
|
|
|
|
pendingInstall.onsuccess = function onsuccess()
|
|
|
|
{
|
|
|
|
ok(this.result, "we have a result: " + this.result);
|
|
|
|
|
|
|
|
function testPerm(aPerm, aAccess)
|
|
|
|
{
|
|
|
|
var res =
|
|
|
|
navMozPerms.get(aPerm, TEST_MANIFEST_URL, TEST_ORIGIN_URL, false);
|
|
|
|
is(res, aAccess, "install: " + aPerm + " is " + res);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let permName in installedPermsToTest) {
|
|
|
|
testPerm(permName, installedPermsToTest[permName]);
|
|
|
|
}
|
2013-03-18 06:24:55 -07:00
|
|
|
|
2012-09-28 15:16:29 -07:00
|
|
|
// uninstall checks
|
|
|
|
uninstallApp();
|
|
|
|
};
|
|
|
|
|
|
|
|
pendingInstall.onerror = function onerror(e)
|
|
|
|
{
|
|
|
|
ok(false, "install()'s onerror was called: " + e);
|
|
|
|
ok(false, "All permission checks failed, uninstal tests were not run");
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function uninstallApp()
|
|
|
|
{
|
|
|
|
var browser = gBrowser.selectedBrowser;
|
|
|
|
var nav = XPCNativeWrapper.unwrap(browser.contentWindow.navigator);
|
|
|
|
var navMozPerms = nav.mozPermissionSettings;
|
|
|
|
|
|
|
|
var pending = nav.mozApps.getInstalled();
|
|
|
|
pending.onsuccess = function onsuccess() {
|
|
|
|
var m = this.result;
|
|
|
|
for (var i = 0; i < m.length; i++) {
|
|
|
|
var app = m[i];
|
|
|
|
|
|
|
|
function uninstall() {
|
2013-01-11 04:50:50 -08:00
|
|
|
var pendingUninstall = nav.mozApps.mgmt.uninstall(app);
|
2012-09-28 15:16:29 -07:00
|
|
|
|
|
|
|
pendingUninstall.onsuccess = function(r) {
|
|
|
|
// test to make sure all permissions have been removed
|
|
|
|
function testPerm(aPerm, aAccess)
|
|
|
|
{
|
|
|
|
var res =
|
|
|
|
navMozPerms.get(aPerm, TEST_MANIFEST_URL, TEST_ORIGIN_URL, false);
|
|
|
|
is(res, aAccess, "uninstall: " + aPerm + " is " + res);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let permName in uninstalledPermsToTest) {
|
|
|
|
testPerm(permName, uninstalledPermsToTest[permName]);
|
|
|
|
}
|
|
|
|
|
|
|
|
finish();
|
|
|
|
};
|
|
|
|
|
|
|
|
pending.onerror = function _onerror(e) {
|
|
|
|
ok(false, e);
|
|
|
|
ok(false, "All uninstall() permission checks failed!");
|
|
|
|
|
|
|
|
finish();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
uninstall();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function handlePopup(aEvent)
|
|
|
|
{
|
|
|
|
aEvent.target.removeEventListener("popupshown", handlePopup, false);
|
|
|
|
SpecialPowers.wrap(this).childNodes[0].button.doCommand();
|
|
|
|
}
|