Bug 1111961 - Developer mode support r=ferjm,pauljt

This commit is contained in:
Fabrice Desré 2015-04-13 09:49:50 -07:00
parent 3bd6ad2efe
commit 3f828ac331
8 changed files with 169 additions and 3 deletions

View File

@ -507,6 +507,13 @@ this.AppsUtils = {
* @param aStatus : the APP_STATUS_* for this app.
*/
checkAppRole: function(aRole, aStatus) {
try {
// Anything is possible in developer mode.
if (Services.prefs.getBoolPref("dom.apps.developer_mode")) {
return true;
}
} catch(e) {}
if (aRole == "theme" && aStatus !== Ci.nsIPrincipal.APP_STATUS_CERTIFIED) {
return false;
}

View File

@ -102,7 +102,12 @@ this.ImportExport = {
// Exporting certified apps is forbidden, as it is to import them.
// We *have* to do this check in the parent process.
if (aApp.appStatus == Ci.nsIPrincipal.APP_STATUS_CERTIFIED) {
let devMode = false;
try {
devMode = Services.prefs.getBoolPref("dom.apps.developer_mode");
} catch(e) {};
if (aApp.appStatus == Ci.nsIPrincipal.APP_STATUS_CERTIFIED && !devMode) {
throw "CertifiedAppExportForbidden";
}
@ -391,6 +396,12 @@ this.ImportExport = {
yield DOMApplicationRegistry._openPackage(appFile, meta, false);
let maxStatus = isSigned ? Ci.nsIPrincipal.APP_STATUS_PRIVILEGED
: Ci.nsIPrincipal.APP_STATUS_INSTALLED;
try {
// Anything is possible in developer mode.
if (Services.prefs.getBoolPref("dom.apps.developer_mode")) {
maxStatus = Ci.nsIPrincipal.APP_STATUS_CERTIFIED;
}
} catch(e) {};
meta.appStatus = AppsUtils.getAppManifestStatus(manifest);
debug("Signed app? " + isSigned);
if (meta.appStatus > maxStatus) {

View File

@ -178,7 +178,8 @@ this.PermissionsInstaller = {
}
}
catch (ex) {
dump("Caught webapps install permissions error for " + aApp.origin);
dump("Caught webapps install permissions error for " + aApp.origin +
" : " + ex + "\n");
Cu.reportError(ex);
if (aOnError) {
aOnError();

View File

@ -2559,6 +2559,13 @@ this.DOMApplicationRegistry = {
// Hosted apps can't be trusted or certified, so just check that the
// manifest doesn't ask for those.
function checkAppStatus(aManifest) {
try {
// Everything is authorized in developer mode.
if (Services.prefs.getBoolPref("dom.apps.developer_mode")) {
return true;
}
} catch(e) {}
let manifestStatus = aManifest.type || "web";
return manifestStatus === "web" ||
manifestStatus === "trusted";
@ -3904,10 +3911,18 @@ this.DOMApplicationRegistry = {
? Ci.nsIPrincipal.APP_STATUS_PRIVILEGED
: Ci.nsIPrincipal.APP_STATUS_INSTALLED;
try {
// Anything is possible in developer mode.
if (Services.prefs.getBoolPref("dom.apps.developer_mode")) {
maxStatus = Ci.nsIPrincipal.APP_STATUS_CERTIFIED;
}
} catch(e) {};
let allowUnsignedLangpack = false;
try {
allowUnsignedLangpack =
Services.prefs.getBoolPref("dom.apps.allow_unsigned_langpacks");
Services.prefs.getBoolPref("dom.apps.allow_unsigned_langpacks") ||
Services.prefs.getBoolPref("dom.apps.developer_mode");
} catch(e) {}
let isLangPack = newManifest.role === "langpack" &&
(aIsSigned || allowUnsignedLangpack);

View File

@ -0,0 +1,6 @@
{
"name": "Certified hosted app",
"description": "An app that can't only be installed in dev mode.",
"launch_path": "/tests/dom/apps/tests/file_app.sjs?apptype=hosted",
"type": "certified"
}

View File

@ -0,0 +1 @@
Content-Type: application/manifest+json

View File

@ -12,6 +12,8 @@ support-files =
file_cached_app.template.appcache
file_cached_app.template.webapp
file_hosted_app.template.webapp
file_hosted_certified.webapp
file_hosted_certified.webapp^headers^
file_manifest.json
file_manifest.json^headers^
file_trusted_app.template.webapp
@ -40,6 +42,7 @@ skip-if = os == "android" || toolkit == "gonk" # embed-apps doesn't work in moch
skip-if = os == "android" || toolkit == "gonk" # embed-apps doesn't work in mochitest app
[test_bug_795164.html]
[test_import_export.html]
[test_install_dev_mode.html]
[test_install_multiple_apps_origin.html]
[test_install_receipts.html]
[test_langpacks.html]

View File

@ -0,0 +1,122 @@
<!DOCTYPE html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id={1111961}
-->
<head>
<title>Test for Bug {1111961}</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id={1111961}">Mozilla Bug {1111961}</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="application/javascript;version=1.7">
var gManifestURL = "http://test/tests/dom/apps/tests/file_hosted_certified.webapp";
var gGenerator = runTest();
function go() {
SpecialPowers.pushPermissions(
[{ "type": "webapps-manage", "allow": 1, "context": document }],
function() { gGenerator.next() });
}
function continueTest() {
try {
gGenerator.next();
} catch (e if e instanceof StopIteration) {
finish();
}
}
function finish() {
SimpleTest.finish();
}
function cbError(aEvent) {
ok(false, "Error callback invoked " +
aEvent.target.error.name + " " + aEvent.target.error.message);
finish();
}
function cbSuccess(aMsg) {
return function(aEvent) {
ok(true, aMsg);
continueTest();
}
}
SimpleTest.waitForExplicitFinish();
/**
* Install 2 apps from the same origin and uninstall them.
*/
function runTest() {
SpecialPowers.setAllAppsLaunchable(true);
SpecialPowers.autoConfirmAppInstall(continueTest);
yield undefined;
SpecialPowers.autoConfirmAppUninstall(continueTest);
yield undefined;
request = navigator.mozApps.mgmt.getAll();
request.onerror = cbError;
request.onsuccess = continueTest;
yield undefined;
var initialAppsCount = request.result.length;
info("Starting with " + initialAppsCount + " apps installed.");
// We are not in dev mode, so this install will fail.
var request = navigator.mozApps.install(gManifestURL, { });
request.onerror = cbSuccess("Can't install certified app without dev mode");
request.onsuccess = cbError;
yield undefined;
// Turn on dev mode.
SpecialPowers.pushPrefEnv({"set": [["dom.apps.developer_mode", true]]},
continueTest);
yield undefined;
// Installation should succeed now.
request = navigator.mozApps.install(gManifestURL, { });
request.onerror = cbError;
request.onsuccess = cbSuccess("Install certified app in dev mode");;
yield undefined;
// Uninstall and check we cleaned up.
var app = request.result;
navigator.mozApps.mgmt.onuninstall = function(event) {
var app = event.application;
is(app.manifestURL, gManifestURL, "App uninstall event ok.");
continueTest();
}
request = navigator.mozApps.mgmt.uninstall(app);
request.onerror = cbError;
request.onsuccess = continueTest;
yield undefined;
yield undefined;
is(request.result, gManifestURL, "App uninstalled.");
navigator.mozApps.mgmt.onuninstall = null;
request = navigator.mozApps.mgmt.getAll();
request.onerror = cbError;
request.onsuccess = continueTest;
yield undefined;
is(request.result.length, initialAppsCount, "All apps are uninstalled.");
}
addLoadEvent(go);
</script>
</pre>
</body>
</html>