Bug 1070932 - Updates error handling code can fail. r=marco, a=bajaj
authorFabrice Desré <fabrice@mozilla.com>
Fri, 26 Sep 2014 10:23:21 -0700
changeset 217898 9a17dc3fa1c8b4e67e2350dd11b933e42929ac42
parent 217897 38ad67d1f18585c222056fcec621d1f41a54807a
child 217899 d13ed3d845fe83557fcd5aca2d7624135f81540f
push id6977
push userryanvm@gmail.com
push dateTue, 30 Sep 2014 13:32:22 +0000
treeherdermozilla-aurora@9a17dc3fa1c8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarco, bajaj
bugs1070932
milestone34.0a2
Bug 1070932 - Updates error handling code can fail. r=marco, a=bajaj
dom/apps/Webapps.jsm
dom/apps/tests/signed_app.sjs
dom/apps/tests/test_signed_pkg_install.html
--- a/dom/apps/Webapps.jsm
+++ b/dom/apps/Webapps.jsm
@@ -3702,17 +3702,17 @@ this.DOMApplicationRegistry = {
     if (aOldApp.staged) {
       delete aOldApp.staged;
     }
 
     this._saveApps().then(() => {
       this.broadcastMessage("Webapps:UpdateState", {
         app: aOldApp,
         error: aError,
-        id: aNewApp.id
+        id: aId
       });
       this.broadcastMessage("Webapps:FireEvent", {
         eventType: "downloaderror",
         manifestURL:  aNewApp.manifestURL
       });
     });
     AppDownloadManager.remove(aNewApp.manifestURL);
   },
--- a/dom/apps/tests/signed_app.sjs
+++ b/dom/apps/tests/signed_app.sjs
@@ -15,40 +15,50 @@ var gBasePath = "tests/dom/apps/tests/";
 var gMiniManifestTemplate = "signed_app_template.webapp";
 var gAppName = "Simple App";
 var gDevName = "David Clarke";
 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";
   var app = ("app" in query) ? query.app : "valid";
   var prevVersion = getState("version");
 
   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);
   var packageSize = readSize(packagePath);
 
   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;
 
   response.setHeader("Content-Type",
                      "application/x-web-app-manifest+json", false);
   var manifest = makeResource(template, version, packagePath, packageSize,
                               gAppName, gDevName, gDevUrl);
   response.write(manifest);
--- a/dom/apps/tests/test_signed_pkg_install.html
+++ b/dom/apps/tests/test_signed_pkg_install.html
@@ -137,23 +137,64 @@ var steps = [
         PackagedTestHelper.checkAppState(gApp, 1, expected,
                                          true, false, PackagedTestHelper.next);
       };
     };
     info("Installing app: " + miniManifestURL);
     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
     checkUninstallApp(gApp);
   },
   function() {
     info("== TEST == Install a corrupted package");
     //Scenario: Corrupted package
     var miniManifestURL = gSJS + "?" + "app=corrupt&" + "version=1";