diff --git a/dom/apps/Webapps.jsm b/dom/apps/Webapps.jsm index 02f4a4b42759..2e6a0047f6e4 100755 --- a/dom/apps/Webapps.jsm +++ b/dom/apps/Webapps.jsm @@ -3739,7 +3739,7 @@ this.DOMApplicationRegistry = { this.broadcastMessage("Webapps:UpdateState", { app: aOldApp, error: aError, - id: aNewApp.id + id: aId }); this.broadcastMessage("Webapps:FireEvent", { eventType: "downloaderror", diff --git a/dom/apps/tests/signed_app.sjs b/dom/apps/tests/signed_app.sjs index ff85a80e4afc..5b11e366b086 100644 --- a/dom/apps/tests/signed_app.sjs +++ b/dom/apps/tests/signed_app.sjs @@ -20,6 +20,14 @@ var gDevUrl = "http://dev.url"; function handleRequest(request, response) { var query = getQuery(request); + if ("nextApp" in query) { + setState("nextApp", query.nextApp); + response.write("OK"); + return; + } + + var nextApp = getState("nextApp"); + response.setHeader("Access-Control-Allow-Origin", "*", false); var version = ("version" in query) ? query.version : "1"; @@ -29,7 +37,7 @@ function handleRequest(request, response) { if (version != prevVersion) { setState("version", version); } - var packageName = app + "_app_" + version + ".zip"; + var packageName = (nextApp.length ? nextApp : app) + "_app_" + version + ".zip"; setState("packageName", packageName); var packagePath = "/" + gBasePath + "signed/" + packageName; setState("packagePath", packagePath); @@ -37,13 +45,15 @@ function handleRequest(request, response) { var etag = getEtag(request, version); - if (etagMatches(request, etag)) { + if (!nextApp.length && etagMatches(request, etag)) { dump("Etags Match. Sending 304\n"); response.setStatusLine(request.httpVersion, "304", "Not modified"); return; } response.setHeader("Etag", etag, false); + setState("nextApp", ""); + // Serve the mini-manifest corresponding to the requested app version. var template = gBasePath + gMiniManifestTemplate; diff --git a/dom/apps/tests/test_signed_pkg_install.html b/dom/apps/tests/test_signed_pkg_install.html index 3b3c91663dc5..bf1b5b9c024a 100644 --- a/dom/apps/tests/test_signed_pkg_install.html +++ b/dom/apps/tests/test_signed_pkg_install.html @@ -142,12 +142,53 @@ var steps = [ var request = navigator.mozApps.installPackage(miniManifestURL); request.onerror = function(evt) { ok(false, "Application should have been correctly installed (error: " + - JSON.stringify(evt)); + request.error.name); }; request.onsuccess = function() { info("Application installed"); }; }, + function() { + // Set up the server side to send a different package on the next call. + info("== TEST == Set state to invalid app"); + var url = gSJS + "?" + "nextApp=unsigned"; + var xhr = new XMLHttpRequest(); + xhr.addEventListener("load", function() { + is(xhr.responseText, "OK", "nextApp=unsigned OK"); + PackagedTestHelper.next(); + }); + xhr.addEventListener("error", event => { + ok(false, "XHR error loading " + url + ": " + xhr.status + " - " + + xhr.statusText); + }); + xhr.addEventListener("abort", event => { + ok(false, "XHR abort loading " + url); + }); + xhr.open('GET', url, true); + xhr.send(); + }, + function() { + info("== TEST == Update app from an invalid source"); + info("Updating app: " + gApp.manifest.name); + gApp.ondownloaderror = function() { + is(gApp.downloadError.name, "INVALID_SIGNATURE"); + PackagedTestHelper.next(); + }; + gApp.ondownloadsuccess = function() { + info("App downloaded"); + ok(false, "App should not download success"); + PackagedTestHelper.finish(); + }; + info("App manifest: " + gApp.manifestURL); + + // This update check will return a different mini manifest pointing to + // an invalid package. + var req = gApp.checkForUpdate(); + req.onsuccess = function() { + gApp.download(); + } + req.onerror = PackagedTestHelper.mozAppsError; + }, function() { info("== TEST == Uninstall a signed app"); // Uninstall App