Bug 499770 - um.activeUpdate is null in onStopRequest for some edgecases. r=dtownsend
authorRobert Strong <robert.bugzilla@gmail.com>
Tue, 23 Jun 2009 12:17:46 -0700
changeset 29492 7a8502b70fdf44bfeb943f4372da1fc1ea77a9ec
parent 29491 07fb0b9396fa1105ab9cea2fe52f3217789fe057
child 29493 7c62ba676b2c777923ae1b85806ac8b0c3dd72de
push id7665
push userrstrong@mozilla.com
push dateTue, 23 Jun 2009 19:18:08 +0000
treeherdermozilla-central@7a8502b70fdf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdtownsend
bugs499770
milestone1.9.2a1pre
Bug 499770 - um.activeUpdate is null in onStopRequest for some edgecases. r=dtownsend
toolkit/mozapps/update/src/nsUpdateService.js.in
toolkit/mozapps/update/test/unit/head_update.js
toolkit/mozapps/update/test/unit/tail_update.js
toolkit/mozapps/update/test/unit/test_bug497578.js
--- a/toolkit/mozapps/update/src/nsUpdateService.js.in
+++ b/toolkit/mozapps/update/src/nsUpdateService.js.in
@@ -2753,17 +2753,18 @@ Downloader.prototype = {
     this._patch.state = state;
     var um = Cc["@mozilla.org/updates/update-manager;1"].
              getService(Ci.nsIUpdateManager);
     if (deleteActiveUpdate) {
       this._update.installDate = (new Date()).getTime();
       um.activeUpdate = null;
     }
     else {
-      um.activeUpdate.state = state;
+      if (um.activeUpdate)
+        um.activeUpdate.state = state;
     }
     um.saveUpdates();
 
     var listenerCount = this._listeners.length;
     for (var i = 0; i < listenerCount; ++i)
       this._listeners[i].onStopRequest(request, context, status);
 
     this._request = null;
--- a/toolkit/mozapps/update/test/unit/head_update.js
+++ b/toolkit/mozapps/update/test/unit/head_update.js
@@ -107,16 +107,24 @@ function getPrefBranch() {
 
 /**
  * Nulls out the most commonly used global vars used by tests as appropriate.
  * This was moved here from the tail file due to check-interactive executing
  * the tail file prior to _execute_test(); (bug 384339). It hasn't been moved
  * back since it is easier to comment out the call to cleanUp when needed.
  */
 function cleanUp() {
+  // Always call app update's observe method passing xpcom-shutdown to test that
+  // the shutdown of app update runs without throwing or leaking. The observer
+  // method is used directly instead of calling notifyObservers so components
+  // outside of the scope of this test don't assert and thereby cause app update
+  // tests to fail.
+  if (gAUS)
+    gAUS.observe(null, "xpcom-shutdown", "");
+
   removeUpdateDirsAndFiles();
   gDirSvc.unregisterProvider(gDirProvider);
 
   if (gXHR) {
     gXHRCallback     = null;
 
     gXHR.responseXML = null;
     // null out the event handlers to prevent a mFreeCount leak of 1
@@ -154,17 +162,18 @@ function setDefaultPrefs() {
 /**
  * Initializes nsIApplicationUpdateService and the most commonly used global
  * vars used by tests.
  */
 function startAUS() {
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1.0", "2.0");
   setDefaultPrefs();
   gAUS = AUS_Cc["@mozilla.org/updates/update-service;1"].
-         getService(AUS_Ci.nsIApplicationUpdateService);
+         getService(AUS_Ci.nsIApplicationUpdateService).
+         QueryInterface(AUS_Ci.nsIObserver);
   var os = AUS_Cc["@mozilla.org/observer-service;1"].
            getService(AUS_Ci.nsIObserverService);
   os.notifyObservers(null, "profile-after-change", null);
   os.notifyObservers(null, "final-ui-startup", null);
 }
 
 /* Initializes nsIUpdateChecker */
 function startUpdateChecker() {
--- a/toolkit/mozapps/update/test/unit/tail_update.js
+++ b/toolkit/mozapps/update/test/unit/tail_update.js
@@ -31,10 +31,11 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK *****
  */
 
-// Not used since check-interactive executes this prior to _execute_test();
-// being executed.
+// Initially moved to head_update since check-interactive was executing this
+// prior to _execute_test(); being executed (bug 384339). It hasn't been moved
+// back since it is easier to comment out the call to cleanUp when needed.
--- a/toolkit/mozapps/update/test/unit/test_bug497578.js
+++ b/toolkit/mozapps/update/test/unit/test_bug497578.js
@@ -71,20 +71,16 @@ function run_test() {
 
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1.0", "2.0");
   setDefaultPrefs();
   do_timeout(0, "run_test_pt1()");
 }
 
 function end_test() {
   do_test_finished();
-  // Call the app update service's observe method with xpcom-shutdown to force
-  // updating the active-update.xml and updates.xml files so they don't contain
-  // updates.
-  gAUS.observe(null, "xpcom-shutdown", "");
   cleanUp();
 }
 
 function run_test_pt1() {
   writeUpdatesToXMLFile(getLocalUpdatesXMLString(""), false);
   var url = URL_HOST + DIR_DATA + "/partial.mar";
   var patches = getLocalPatchString("partial", url, null, null, null, null,
                                     STATE_FAILED) +