Bug 1096971 - Don't propagate an error when the package downloaded was the same we had. r=fabrice
authorAntonio M. Amaya <amac@tid.es>
Mon, 17 Nov 2014 02:01:00 +0100
changeset 217045 71a0e053308c44f9cf8b7f255c71e4d8622f4cc1
parent 217044 3c993904ea4f8b76b0f7558c9857b1f99287885d
child 217046 8e0063fd3c5edb0bd45417b5573d35e402fb49c9
push id52216
push usercbook@mozilla.com
push dateMon, 24 Nov 2014 08:31:32 +0000
treeherdermozilla-inbound@4ad7f3e41256 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfabrice
bugs1096971
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1096971 - Don't propagate an error when the package downloaded was the same we had. r=fabrice
dom/apps/Webapps.jsm
dom/apps/tests/test_packaged_app_update.html
--- a/dom/apps/Webapps.jsm
+++ b/dom/apps/Webapps.jsm
@@ -3258,17 +3258,17 @@ this.DOMApplicationRegistry = {
 
     if (oldPackage) {
       debug("package's etag or hash unchanged; sending 'applied' event");
       // The package's Etag or hash has not changed.
       // We send an "applied" event right away so code awaiting that event
       // can proceed to access the app. We also throw an error to alert
       // the caller that the package wasn't downloaded.
       this._sendAppliedEvent(aOldApp);
-      throw new Error("PACKAGE_UNCHANGED");
+      throw "PACKAGE_UNCHANGED";
     }
 
     let newManifest = yield this._openAndReadPackage(zipFile, aOldApp, aNewApp,
             isLocalFileInstall, aIsUpdate, aManifest, requestChannel, hash);
 
     return [aOldApp.id, newManifest];
 
   }),
@@ -3917,16 +3917,23 @@ this.DOMApplicationRegistry = {
     // We avoid notifying the error to the DOM side if the app download
     // was cancelled via cancelDownload, which already sends its own
     // notification.
     if (aOldApp.isCanceling) {
       delete aOldApp.isCanceling;
       return;
     }
 
+    // If the error that got us here was that the package hasn't changed,
+    // since we already sent a success and an applied, let's not confuse
+    // the clients...
+    if (aError == "PACKAGE_UNCHANGED") {
+      return;
+    }
+
     let download = AppDownloadManager.get(aNewApp.manifestURL);
     aOldApp.downloading = false;
 
     // If there were not enough storage to download the package we
     // won't have a record of the download details, so we just set the
     // installState to 'pending' at first download and to 'installed' when
     // updating.
     aOldApp.installState = download ? download.previousState
--- a/dom/apps/tests/test_packaged_app_update.html
+++ b/dom/apps/tests/test_packaged_app_update.html
@@ -67,32 +67,40 @@ function checkLastAppState(aMiniManifest
     size: 0,
     readyToApplyDownload: aExpectedReady
   };
 
   PackagedTestHelper.checkAppState(PackagedTestHelper.gApp, aExpectedVersion,
                                    expected, true, false, aCb);
 }
 
-function updateApp(aExpectedReady, aPreviousVersion, aNextVersion) {
+function updateApp(aExpectedReady, aPreviousVersion, aNextVersion, aFailOnError) {
   var lApp = PackagedTestHelper.gApp;
 
   var ondownloadappliedhandler =
     checkLastAppState.bind(PackagedTestHelper, miniManifestURL, false, false,
-                           aNextVersion, PackagedTestHelper.next);
+                           aNextVersion,
+                           setTimeout.bind(undefined, PackagedTestHelper.next, 500));
 
   var ondownloadsuccesshandler =
     checkLastAppState.bind(undefined, miniManifestURL,
                            aExpectedReady, false, aPreviousVersion,
                            function() {
       navigator.mozApps.mgmt.applyDownload(lApp);
   });
 
+  var ondownloaderrorhandler = aFailOnError ?
+    function() {
+      ok(false, "We should not get an error but got " +
+         lApp.downloadError.name);
+      PackagedTestHelper.finish();
+    } : null;
+
   checkForUpdate(true, ondownloadsuccesshandler, ondownloadappliedhandler,
-                 null, true);
+                 ondownloaderrorhandler, true);
 
 }
 
 var initialPermissionState = {
   "geolocation": "prompt",
   "audio-capture": "prompt",
   "video-capture": "prompt",
   "test-permission-read": "prompt",
@@ -233,17 +241,17 @@ var steps = [
     info("== TEST == Check for Update after getting a new package");
     checkForUpdate(false);
   },
   function() {
     PackagedTestHelper.setAppVersion(4, PackagedTestHelper.next, true);
   },
   function() {
     info("== TEST == Update packaged app - same package");
-    updateApp(false, 3, 3);
+    updateApp(false, 3, 3, true);
   },
   function() {
     info("== TEST == Check for Update after getting the same package");
     checkForUpdate(false);
   },
   function() {
     PackagedTestHelper.setAppVersion(1, PackagedTestHelper.next);
   },