Bug 1070932 - Updates error handling code can fail r=marco

This commit is contained in:
Fabrice Desré 2014-09-26 10:23:21 -07:00
parent 52a7711c5d
commit 38972332f5
3 changed files with 55 additions and 4 deletions

View File

@ -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",

View File

@ -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;

View File

@ -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