Bug 853388: Make existing tests a little more robust and easier to debug, also callback stack friendly; r=unfocused
authorIrving Reid <irving@mozilla.com>
Sat, 13 Jul 2013 12:36:27 -0400
changeset 139187 1d2ba634c054c1e932d5472155000fcdff095cdc
parent 139186 e80c4863db275c7bf2de9cf47e005f6f41360453
child 139188 7b4f810372b48e184fc07a73c172ee0354875a26
push id1890
push userryanvm@gmail.com
push dateFri, 19 Jul 2013 17:44:21 +0000
treeherderfx-team@20848adc9980 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersunfocused
bugs853388
milestone25.0a1
Bug 853388: Make existing tests a little more robust and easier to debug, also callback stack friendly; r=unfocused
toolkit/mozapps/extensions/AddonLogging.jsm
toolkit/mozapps/extensions/XPIProvider.jsm
toolkit/mozapps/extensions/test/addons/test_bootstrap1_1/bootstrap.js
toolkit/mozapps/extensions/test/addons/test_bootstrap1_2/bootstrap.js
toolkit/mozapps/extensions/test/addons/test_bootstrap1_3/bootstrap.js
toolkit/mozapps/extensions/test/xpcshell/head_addons.js
toolkit/mozapps/extensions/test/xpcshell/test_AddonRepository.js
toolkit/mozapps/extensions/test/xpcshell/test_AddonRepository_cache.js
toolkit/mozapps/extensions/test/xpcshell/test_backgroundupdate.js
toolkit/mozapps/extensions/test/xpcshell/test_badschema.js
toolkit/mozapps/extensions/test/xpcshell/test_blocklistchange.js
toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js
toolkit/mozapps/extensions/test/xpcshell/test_bug324121.js
toolkit/mozapps/extensions/test/xpcshell/test_bug335238.js
toolkit/mozapps/extensions/test/xpcshell/test_bug449027.js
toolkit/mozapps/extensions/test/xpcshell/test_bug470377_3.js
toolkit/mozapps/extensions/test/xpcshell/test_bug470377_3_strictcompat.js
toolkit/mozapps/extensions/test/xpcshell/test_bug470377_4.js
toolkit/mozapps/extensions/test/xpcshell/test_bug521905.js
toolkit/mozapps/extensions/test/xpcshell/test_bug542391.js
toolkit/mozapps/extensions/test/xpcshell/test_bug559800.js
toolkit/mozapps/extensions/test/xpcshell/test_bug563256.js
toolkit/mozapps/extensions/test/xpcshell/test_bug587088.js
toolkit/mozapps/extensions/test/xpcshell/test_bug595573.js
toolkit/mozapps/extensions/test/xpcshell/test_bug596607.js
toolkit/mozapps/extensions/test/xpcshell/test_bug659772.js
toolkit/mozapps/extensions/test/xpcshell/test_bug675371.js
toolkit/mozapps/extensions/test/xpcshell/test_cacheflush.js
toolkit/mozapps/extensions/test/xpcshell/test_checkcompatibility.js
toolkit/mozapps/extensions/test/xpcshell/test_compatoverrides.js
toolkit/mozapps/extensions/test/xpcshell/test_corrupt.js
toolkit/mozapps/extensions/test/xpcshell/test_corrupt_strictcompat.js
toolkit/mozapps/extensions/test/xpcshell/test_dictionary.js
toolkit/mozapps/extensions/test/xpcshell/test_disable.js
toolkit/mozapps/extensions/test/xpcshell/test_distribution.js
toolkit/mozapps/extensions/test/xpcshell/test_dss.js
toolkit/mozapps/extensions/test/xpcshell/test_duplicateplugins.js
toolkit/mozapps/extensions/test/xpcshell/test_filepointer.js
toolkit/mozapps/extensions/test/xpcshell/test_general.js
toolkit/mozapps/extensions/test/xpcshell/test_hotfix.js
toolkit/mozapps/extensions/test/xpcshell/test_install.js
toolkit/mozapps/extensions/test/xpcshell/test_install_strictcompat.js
toolkit/mozapps/extensions/test/xpcshell/test_langpack.js
toolkit/mozapps/extensions/test/xpcshell/test_locked.js
toolkit/mozapps/extensions/test/xpcshell/test_locked2.js
toolkit/mozapps/extensions/test/xpcshell/test_locked_strictcompat.js
toolkit/mozapps/extensions/test/xpcshell/test_migrate4.js
toolkit/mozapps/extensions/test/xpcshell/test_onPropertyChanged_appDisabled.js
toolkit/mozapps/extensions/test/xpcshell/test_plugins.js
toolkit/mozapps/extensions/test/xpcshell/test_registry.js
toolkit/mozapps/extensions/test/xpcshell/test_startup.js
toolkit/mozapps/extensions/test/xpcshell/test_strictcompatibility.js
toolkit/mozapps/extensions/test/xpcshell/test_syncGUID.js
toolkit/mozapps/extensions/test/xpcshell/test_theme.js
toolkit/mozapps/extensions/test/xpcshell/test_uninstall.js
toolkit/mozapps/extensions/test/xpcshell/test_update.js
toolkit/mozapps/extensions/test/xpcshell/test_update_strictcompat.js
toolkit/mozapps/extensions/test/xpcshell/test_updateid.js
toolkit/mozapps/extensions/test/xpcshell/test_upgrade.js
toolkit/mozapps/extensions/test/xpcshell/test_upgrade_strictcompat.js
--- a/toolkit/mozapps/extensions/AddonLogging.jsm
+++ b/toolkit/mozapps/extensions/AddonLogging.jsm
@@ -22,19 +22,25 @@ Components.utils.import("resource://gre/
 this.EXPORTED_SYMBOLS = [ "LogManager" ];
 
 var gDebugLogEnabled = false;
 
 function formatLogMessage(aType, aName, aStr, aException) {
   let message = aType.toUpperCase() + " " + aName + ": " + aStr;
   if (aException) {
     if (typeof aException == "number")
-      return message + ": " + Components.Exception("", aException).name
-    else
-      return message + ": " + aException;
+      return message + ": " + Components.Exception("", aException).name;
+
+    message  = message + ": " + aException;
+    // instanceOf doesn't work here, let's duck type
+    if (aException.fileName)
+      message = message + " (" + aException.fileName + ":" + aException.lineNumber + ")";
+
+    if (aException.message == "too much recursion")
+      dump(message + "\n" + aException.stack + "\n");
   }
   return message;
 }
 
 function getStackDetails(aException) {
   // Defensively wrap all this to ensure that failing to get the message source
   // doesn't stop the message from being logged
   try {
--- a/toolkit/mozapps/extensions/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/XPIProvider.jsm
@@ -2718,17 +2718,17 @@ var XPIProvider = {
      * @param  aOldAddon
      *         The AddonInternal as it appeared the last time the application
      *         ran
      * @return a boolean indicating if flushing caches is required to complete
      *         changing this add-on
      */
     function removeMetadata(aInstallLocation, aOldAddon) {
       // This add-on has disappeared
-      LOG("Add-on " + aOldAddon.id + " removed from " + aInstallLocation.name);
+      LOG("Add-on " + aOldAddon.id + " removed from " + aInstallLocation);
       XPIDatabase.removeAddonMetadata(aOldAddon);
 
       // Remember add-ons that were uninstalled during startup
       if (aOldAddon.visible) {
         AddonManagerPrivate.addStartupChange(AddonManager.STARTUP_CHANGE_UNINSTALLED,
                                              aOldAddon.id);
       }
       else if (AddonManager.getStartupChanges(AddonManager.STARTUP_CHANGE_INSTALLED)
@@ -3042,17 +3042,17 @@ var XPIProvider = {
               changed = updateVisibilityAndCompatibility(installLocation,
                                                          aOldAddon, addonState) ||
                         changed;
             }
             if (aOldAddon.visible && aOldAddon._installLocation.name != KEY_APP_GLOBAL)
               XPIProvider.allAppGlobal = false;
           }
           else {
-            changed = removeMetadata(installLocation, aOldAddon) || changed;
+            changed = removeMetadata(installLocation.name, aOldAddon) || changed;
           }
         }, this);
       }
 
       // All the remaining add-ons in this install location must be new.
 
       // Get the migration data for this install location.
       let locMigrateData = {};
@@ -3949,18 +3949,20 @@ var XPIProvider = {
    *         the params argument
    */
   callBootstrapMethod: function XPI_callBootstrapMethod(aId, aVersion, aType, aFile,
                                                         aMethod, aReason, aExtraParams) {
     // Never call any bootstrap methods in safe mode
     if (Services.appinfo.inSafeMode)
       return;
 
-    if (aMethod == "startup")
+    if (aMethod == "startup") {
+      LOG("Registering manifest for " + aFile.path);
       Components.manager.addBootstrappedManifestLocation(aFile);
+    }
 
     try {
       // Load the scope if it hasn't already been loaded
       if (!(aId in this.bootstrapScopes))
         this.loadBootstrapScope(aId, aFile, aVersion, aType);
 
       // Nothing to call for locales
       if (aType == "locale")
@@ -3990,18 +3992,20 @@ var XPIProvider = {
         this.bootstrapScopes[aId][aMethod](params, aReason);
       }
       catch (e) {
         WARN("Exception running bootstrap method " + aMethod + " on " +
              aId, e);
       }
     }
     finally {
-      if (aMethod == "shutdown")
+      if (aMethod == "shutdown") {
+        LOG("Removing manifest for " + aFile.path);
         Components.manager.removeBootstrappedManifestLocation(aFile);
+      }
     }
   },
 
   /**
    * Updates the appDisabled property for all add-ons.
    */
   updateAllAddonDisabledStates: function XPI_updateAllAddonDisabledStates() {
     let addons = XPIDatabase.getAddons();
@@ -4324,16 +4328,19 @@ function AddonInstall(aInstallLocation, 
   this.icons = {};
   this.existingAddon = aExistingAddon;
   this.error = 0;
   if (aLoadGroup)
     this.window = aLoadGroup.notificationCallbacks
                             .getInterface(Ci.nsIDOMWindow);
   else
     this.window = null;
+
+  this.WARN = WARN;
+  this.LOG = LOG;
 }
 
 AddonInstall.prototype = {
   installLocation: null,
   wrapper: null,
   stream: null,
   crypto: null,
   originalHash: null,
@@ -4411,17 +4418,17 @@ AddonInstall.prototype = {
 
     if (this.hash) {
       let crypto = Cc["@mozilla.org/security/hash;1"].
                    createInstance(Ci.nsICryptoHash);
       try {
         crypto.initWithString(this.hash.algorithm);
       }
       catch (e) {
-        WARN("Unknown hash algorithm " + this.hash.algorithm);
+        WARN("Unknown hash algorithm '" + this.hash.algorithm + "' for addon " + this.sourceURI.spec, e);
         this.state = AddonManager.STATE_DOWNLOAD_FAILED;
         this.error = AddonManager.ERROR_INCORRECT_HASH;
         aCallback(this);
         return;
       }
 
       let fis = Cc["@mozilla.org/network/file-input-stream;1"].
                 createInstance(Ci.nsIFileInputStream);
@@ -4619,25 +4626,31 @@ AddonInstall.prototype = {
     });
   },
 
   /**
    * Removes the temporary file owned by this AddonInstall if there is one.
    */
   removeTemporaryFile: function AI_removeTemporaryFile() {
     // Only proceed if this AddonInstall owns its XPI file
-    if (!this.ownsTempFile)
+    if (!this.ownsTempFile) {
+      this.LOG("removeTemporaryFile: " + this.sourceURI.spec + " does not own temp file");
       return;
+    }
 
     try {
+      this.LOG("removeTemporaryFile: " + this.sourceURI.spec + " removing temp file " +
+          this.file.path);
       this.file.remove(true);
       this.ownsTempFile = false;
     }
     catch (e) {
-      WARN("Failed to remove temporary file " + this.file.path, e);
+      this.WARN("Failed to remove temporary file " + this.file.path + " for addon " +
+          this.sourceURI.spec,
+          e);
     }
   },
 
   /**
    * Updates the sourceURI and releaseNotesURI values on the Addon being
    * installed by this AddonInstall instance.
    */
   updateAddonURIs: function AI_updateAddonURIs() {
@@ -4864,16 +4877,17 @@ AddonInstall.prototype = {
 
   /**
    * Starts downloading the add-on's XPI file.
    */
   startDownload: function AI_startDownload() {
     this.state = AddonManager.STATE_DOWNLOADING;
     if (!AddonManagerPrivate.callInstallListeners("onDownloadStarted",
                                                   this.listeners, this.wrapper)) {
+      LOG("onDownloadStarted listeners cancelled installation of addon " + this.sourceURI.spec);
       this.state = AddonManager.STATE_CANCELLED;
       XPIProvider.removeActiveInstall(this);
       AddonManagerPrivate.callInstallListeners("onDownloadCancelled",
                                                this.listeners, this.wrapper)
       return;
     }
 
     // If a listener changed our state then do not proceed with the download
@@ -4898,17 +4912,17 @@ AddonInstall.prototype = {
       this.file = getTemporaryFile();
       this.ownsTempFile = true;
       this.stream = Cc["@mozilla.org/network/file-output-stream;1"].
                     createInstance(Ci.nsIFileOutputStream);
       this.stream.init(this.file, FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE |
                        FileUtils.MODE_TRUNCATE, FileUtils.PERMS_FILE, 0);
     }
     catch (e) {
-      WARN("Failed to start download", e);
+      WARN("Failed to start download for addon " + this.sourceURI.spec, e);
       this.state = AddonManager.STATE_DOWNLOAD_FAILED;
       this.error = AddonManager.ERROR_FILE_ACCESS;
       XPIProvider.removeActiveInstall(this);
       AddonManagerPrivate.callInstallListeners("onDownloadFailed",
                                                this.listeners, this.wrapper);
       return;
     }
 
@@ -4924,17 +4938,17 @@ AddonInstall.prototype = {
       this.channel.notificationCallbacks = this;
       if (this.channel instanceof Ci.nsIHttpChannelInternal)
         this.channel.forceAllowThirdPartyCookie = true;
       this.channel.asyncOpen(listener, null);
 
       Services.obs.addObserver(this, "network:offline-about-to-go-offline", false);
     }
     catch (e) {
-      WARN("Failed to start download", e);
+      WARN("Failed to start download for addon " + this.sourceURI.spec, e);
       this.state = AddonManager.STATE_DOWNLOAD_FAILED;
       this.error = AddonManager.ERROR_NETWORK_FAILURE;
       XPIProvider.removeActiveInstall(this);
       AddonManagerPrivate.callInstallListeners("onDownloadFailed",
                                                this.listeners, this.wrapper);
     }
   },
 
@@ -4992,17 +5006,17 @@ AddonInstall.prototype = {
   onStartRequest: function AI_onStartRequest(aRequest, aContext) {
     this.crypto = Cc["@mozilla.org/security/hash;1"].
                   createInstance(Ci.nsICryptoHash);
     if (this.hash) {
       try {
         this.crypto.initWithString(this.hash.algorithm);
       }
       catch (e) {
-        WARN("Unknown hash algorithm " + this.hash.algorithm);
+        WARN("Unknown hash algorithm '" + this.hash.algorithm + "' for addon " + this.sourceURI.spec, e);
         this.state = AddonManager.STATE_DOWNLOAD_FAILED;
         this.error = AddonManager.ERROR_INCORRECT_HASH;
         XPIProvider.removeActiveInstall(this);
         AddonManagerPrivate.callInstallListeners("onDownloadFailed",
                                                  this.listeners, this.wrapper);
         aRequest.cancel(Cr.NS_BINDING_ABORTED);
         return;
       }
@@ -5116,18 +5130,23 @@ AddonInstall.prototype = {
     this.state = AddonManager.STATE_DOWNLOAD_FAILED;
     this.error = aReason;
     XPIProvider.removeActiveInstall(this);
     AddonManagerPrivate.callInstallListeners("onDownloadFailed", this.listeners,
                                              this.wrapper);
 
     // If the listener hasn't restarted the download then remove any temporary
     // file
-    if (this.state == AddonManager.STATE_DOWNLOAD_FAILED)
+    if (this.state == AddonManager.STATE_DOWNLOAD_FAILED) {
+      LOG("downloadFailed: removing temp file for " + this.sourceURI.spec);
       this.removeTemporaryFile();
+    }
+    else
+      LOG("downloadFailed: listener changed AddonInstall state for " +
+          this.sourceURI.spec + " to " + this.state);
   },
 
   /**
    * Notify listeners that the download completed.
    */
   downloadCompleted: function AI_downloadCompleted() {
     let self = this;
     XPIDatabase.getVisibleAddonForID(this.addon.id, function downloadCompleted_getVisibleAddonForID(aAddon) {
@@ -5242,17 +5261,17 @@ AddonInstall.prototype = {
           converter.init(stream, "UTF-8", 0, 0x0000);
           converter.writeString(JSON.stringify(this.addon));
         }
         finally {
           converter.close();
           stream.close();
         }
 
-        LOG("Install of " + this.sourceURI.spec + " completed.");
+        LOG("Staged install of " + this.sourceURI.spec + " ready; waiting for restart.");
         this.state = AddonManager.STATE_INSTALLED;
         if (isUpgrade) {
           delete this.existingAddon.pendingUpgrade;
           this.existingAddon.pendingUpgrade = this.addon;
         }
         AddonManagerPrivate.callInstallListeners("onInstallEnded",
                                                  this.listeners, this.wrapper,
                                                  createWrapper(this.addon));
@@ -6841,18 +6860,20 @@ DirectoryInstallLocation.prototype = {
 
       delete this._FileToIDMap[file.path];
       delete this._IDToFileMap[aId];
       return;
     }
 
     let trashDir = this.getTrashDir();
 
-    if (file.leafName != aId)
+    if (file.leafName != aId) {
+      LOG("uninstallAddon: flushing jar cache " + file.path + " for addon " + aId);
       flushJarCache(file);
+    }
 
     let transaction = new SafeInstallOperation();
 
     try {
       transaction.move(file, trashDir);
     }
     finally {
       // It isn't ideal if this cleanup fails, but it is probably better than
--- a/toolkit/mozapps/extensions/test/addons/test_bootstrap1_1/bootstrap.js
+++ b/toolkit/mozapps/extensions/test/addons/test_bootstrap1_1/bootstrap.js
@@ -1,30 +1,32 @@
 Components.utils.import("resource://gre/modules/Services.jsm");
 
+// Test steps chain from pref observers on *_reason,
+// so always set that last
 function install(data, reason) {
   Components.utils.import(data.resourceURI.spec + "version.jsm");
   Services.prefs.setIntPref("bootstraptest.installed_version", VERSION);
-  Services.prefs.setIntPref("bootstraptest.install_reason", reason);
   Services.prefs.setIntPref("bootstraptest.install_oldversion", data.oldVersion);
   Components.utils.unload(data.resourceURI.spec + "version.jsm");
+  Services.prefs.setIntPref("bootstraptest.install_reason", reason);
 }
 
 function startup(data, reason) {
   Components.utils.reportError("bootstrap startup");
   Components.utils.import(data.resourceURI.spec + "version.jsm");
   Services.prefs.setIntPref("bootstraptest.active_version", VERSION);
-  Services.prefs.setIntPref("bootstraptest.startup_reason", reason);
   Services.prefs.setIntPref("bootstraptest.startup_oldversion", data.oldVersion);
   Components.utils.unload(data.resourceURI.spec + "version.jsm");
+  Services.prefs.setIntPref("bootstraptest.startup_reason", reason);
 }
 
 function shutdown(data, reason) {
   Services.prefs.setIntPref("bootstraptest.active_version", 0);
+  Services.prefs.setIntPref("bootstraptest.shutdown_newversion", data.newVersion);
   Services.prefs.setIntPref("bootstraptest.shutdown_reason", reason);
-  Services.prefs.setIntPref("bootstraptest.shutdown_newversion", data.newVersion);
 }
 
 function uninstall(data, reason) {
   Services.prefs.setIntPref("bootstraptest.installed_version", 0);
+  Services.prefs.setIntPref("bootstraptest.uninstall_newversion", data.newVersion);
   Services.prefs.setIntPref("bootstraptest.uninstall_reason", reason);
-  Services.prefs.setIntPref("bootstraptest.uninstall_newversion", data.newVersion);
 }
--- a/toolkit/mozapps/extensions/test/addons/test_bootstrap1_2/bootstrap.js
+++ b/toolkit/mozapps/extensions/test/addons/test_bootstrap1_2/bootstrap.js
@@ -1,29 +1,31 @@
 Components.utils.import("resource://gre/modules/Services.jsm");
 
+// Test steps chain from pref observers on *_reason,
+// so always set that last
 function install(data, reason) {
   Components.utils.import(data.resourceURI.spec + "version.jsm");
   Services.prefs.setIntPref("bootstraptest.installed_version", VERSION);
-  Services.prefs.setIntPref("bootstraptest.install_reason", reason);
   Services.prefs.setIntPref("bootstraptest.install_oldversion", data.oldVersion);
   Components.utils.unload(data.resourceURI.spec + "version.jsm");
+  Services.prefs.setIntPref("bootstraptest.install_reason", reason);
 }
 
 function startup(data, reason) {
   Components.utils.import(data.resourceURI.spec + "version.jsm");
   Services.prefs.setIntPref("bootstraptest.active_version", VERSION);
-  Services.prefs.setIntPref("bootstraptest.startup_reason", reason);
   Services.prefs.setIntPref("bootstraptest.startup_oldversion", data.oldVersion);
   Components.utils.unload(data.resourceURI.spec + "version.jsm");
+  Services.prefs.setIntPref("bootstraptest.startup_reason", reason);
 }
 
 function shutdown(data, reason) {
   Services.prefs.setIntPref("bootstraptest.active_version", 0);
+  Services.prefs.setIntPref("bootstraptest.shutdown_newversion", data.newVersion);
   Services.prefs.setIntPref("bootstraptest.shutdown_reason", reason);
-  Services.prefs.setIntPref("bootstraptest.shutdown_newversion", data.newVersion);
 }
 
 function uninstall(data, reason) {
   Services.prefs.setIntPref("bootstraptest.installed_version", 0);
+  Services.prefs.setIntPref("bootstraptest.uninstall_newversion", data.newVersion);
   Services.prefs.setIntPref("bootstraptest.uninstall_reason", reason);
-  Services.prefs.setIntPref("bootstraptest.uninstall_newversion", data.newVersion);
 }
--- a/toolkit/mozapps/extensions/test/addons/test_bootstrap1_3/bootstrap.js
+++ b/toolkit/mozapps/extensions/test/addons/test_bootstrap1_3/bootstrap.js
@@ -1,29 +1,31 @@
 Components.utils.import("resource://gre/modules/Services.jsm");
 
+// Test steps chain from pref observers on *_reason,
+// so always set that last
 function install(data, reason) {
   Components.utils.import(data.resourceURI.spec + "version.jsm");
   Services.prefs.setIntPref("bootstraptest.installed_version", VERSION);
-  Services.prefs.setIntPref("bootstraptest.install_reason", reason);
   Services.prefs.setIntPref("bootstraptest.install_oldversion", data.oldVersion);
   Components.utils.unload(data.resourceURI.spec + "version.jsm");
+  Services.prefs.setIntPref("bootstraptest.install_reason", reason);
 }
 
 function startup(data, reason) {
   Components.utils.import(data.resourceURI.spec + "version.jsm");
   Services.prefs.setIntPref("bootstraptest.active_version", VERSION);
-  Services.prefs.setIntPref("bootstraptest.startup_reason", reason);
   Services.prefs.setIntPref("bootstraptest.startup_oldversion", data.oldVersion);
   Components.utils.unload(data.resourceURI.spec + "version.jsm");
+  Services.prefs.setIntPref("bootstraptest.startup_reason", reason);
 }
 
 function shutdown(data, reason) {
   Services.prefs.setIntPref("bootstraptest.active_version", 0);
+  Services.prefs.setIntPref("bootstraptest.shutdown_newversion", data.newVersion);
   Services.prefs.setIntPref("bootstraptest.shutdown_reason", reason);
-  Services.prefs.setIntPref("bootstraptest.shutdown_newversion", data.newVersion);
 }
 
 function uninstall(data, reason) {
   Services.prefs.setIntPref("bootstraptest.installed_version", 0);
+  Services.prefs.setIntPref("bootstraptest.uninstall_newversion", data.newVersion);
   Services.prefs.setIntPref("bootstraptest.uninstall_reason", reason);
-  Services.prefs.setIntPref("bootstraptest.uninstall_newversion", data.newVersion);
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/head_addons.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/head_addons.js
@@ -220,22 +220,29 @@ function do_check_addon(aActualAddon, aE
   do_check_neq(aActualAddon, null);
 
   aProperties.forEach(function(aProperty) {
     let actualValue = aActualAddon[aProperty];
     let expectedValue = aExpectedAddon[aProperty];
 
     // Check that all undefined expected properties are null on actual add-on
     if (!(aProperty in aExpectedAddon)) {
-      if (actualValue !== undefined && actualValue !== null)
+      if (actualValue !== undefined && actualValue !== null) {
         do_throw("Unexpected defined/non-null property for add-on " +
-                 aExpectedAddon.id + " (addon[" + aProperty + "] = " + actualValue);
+                 aExpectedAddon.id + " (addon[" + aProperty + "] = " +
+                 actualValue.toSource() + ")");
+      }
 
       return;
     }
+    else if (expectedValue && !actualValue) {
+      do_throw("Missing property for add-on " + aExpectedAddon.id +
+        ": expected addon[" + aProperty + "] = " + expectedValue);
+      return;
+    }
 
     switch (aProperty) {
       case "creator":
         do_check_author(actualValue, expectedValue);
         break;
 
       case "developers":
       case "translators":
@@ -1034,17 +1041,17 @@ function completeAllInstalls(aInstalls, 
     aCallback();
     return;
   }
 
   function installCompleted(aInstall) {
     aInstall.removeListener(listener);
 
     if (--count == 0)
-      aCallback();
+      do_execute_soon(aCallback);
   }
 
   let listener = {
     onDownloadFailed: installCompleted,
     onDownloadCancelled: installCompleted,
     onInstallFailed: installCompleted,
     onInstallCancelled: installCompleted,
     onInstallEnded: installCompleted
@@ -1261,42 +1268,72 @@ function timeout() {
 
   // Attempt to bail out of the test
   do_test_finished();
 }
 
 var timer = AM_Cc["@mozilla.org/timer;1"].createInstance(AM_Ci.nsITimer);
 timer.init(timeout, TIMEOUT_MS, AM_Ci.nsITimer.TYPE_ONE_SHOT);
 
-do_register_cleanup(function() {
+// Make sure that a given path does not exist
+function pathShouldntExist(aPath) {
+  if (aPath.exists()) {
+    do_throw("Test cleanup: path " + aPath.path + " exists when it should not");
+  }
+}
+
+do_register_cleanup(function addon_cleanup() {
   if (timer)
     timer.cancel();
 
   // Check that the temporary directory is empty
   var dirEntries = gTmpD.directoryEntries
                         .QueryInterface(AM_Ci.nsIDirectoryEnumerator);
   var entry;
   while (entry = dirEntries.nextFile) {
     do_throw("Found unexpected file in temporary directory: " + entry.leafName);
   }
   dirEntries.close();
 
   var testDir = gProfD.clone();
   testDir.append("extensions");
   testDir.append("trash");
-  do_check_false(testDir.exists());
+  pathShouldntExist(testDir);
 
   testDir.leafName = "staged";
-  do_check_false(testDir.exists());
+  pathShouldntExist(testDir);
 
   testDir.leafName = "staged-xpis";
-  do_check_false(testDir.exists());
+  pathShouldntExist(testDir);
 
   shutdownManager();
 
   // Clear commonly set prefs.
   try {
     Services.prefs.clearUserPref(PREF_EM_CHECK_UPDATE_SECURITY);
   } catch (e) {}
   try {
     Services.prefs.clearUserPref(PREF_EM_STRICT_COMPATIBILITY);
   } catch (e) {}
 });
+
+// Wrap a function (typically a callback) to catch and report exceptions
+function do_exception_wrap(func) {
+  return function() {
+    try {
+      func.apply(null, arguments);
+    }
+    catch(e) {
+      do_report_unexpected_exception(e);
+    }
+  };
+}
+
+/**
+ * Create a callback function that calls do_execute_soon on an actual callback and arguments
+ */
+function callback_soon(aFunction) {
+  return function(...args) {
+    do_execute_soon(function() {
+      aFunction.apply(null, args);
+    }, aFunction.name ? "delayed callback " + aFunction.name : "delayed callback");
+  }
+}
--- a/toolkit/mozapps/extensions/test/xpcshell/test_AddonRepository.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_AddonRepository.js
@@ -294,18 +294,18 @@ var SEARCH_TEST = {
 // Test that actual results and expected results are equal
 function check_results(aActualAddons, aExpectedAddons, aAddonCount, aInstallNull) {
   do_check_false(AddonRepository.isSearching);
 
   do_check_eq(aActualAddons.length, aAddonCount);
   do_check_addons(aActualAddons, aExpectedAddons, ADDON_PROPERTIES);
 
   // Additional tests
-  aActualAddons.forEach(function(aActualAddon) {
-    // Separately check name so better messages are outputted when failure
+  aActualAddons.forEach(function check_each_addon(aActualAddon) {
+    // Separately check name so better messages are output when test fails
     if (aActualAddon.name == "FAIL")
       do_throw(aActualAddon.id + " - " + aActualAddon.description);
     if (aActualAddon.name != "PASS")
       do_throw(aActualAddon.id + " - " + "invalid add-on name " + aActualAddon.name);
 
     do_check_eq(aActualAddon.install == null, !!aInstallNull || !aActualAddon.sourceURI);
 
     // Check that sourceURI property consistent within actual addon
@@ -359,17 +359,17 @@ function complete_search(aSearch, aSearc
 function run_test() {
   // Setup for test
   do_test_pending();
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
 
   startupManager();
 
   // Install an add-on so can check that it isn't returned in the results
-  installAllFiles([do_get_addon("test_AddonRepository_1")], function() {
+  installAllFiles([do_get_addon("test_AddonRepository_1")], function addon_1_install_callback() {
     restartManager();
 
     gServer = new HttpServer();
 
     // Register other add-on XPI files
     gServer.registerFile(INSTALL_URL2,
                         do_get_addon("test_AddonRepository_2"));
     gServer.registerFile(INSTALL_URL3,
@@ -389,18 +389,24 @@ function run_test() {
     gServer.registerFile(RECOMMENDED_TEST.successfulURL,
                         do_get_file("data/test_AddonRepository.xml"));
     gServer.registerFile(SEARCH_TEST.successfulURL,
                         do_get_file("data/test_AddonRepository.xml"));
 
     gServer.start(PORT);
 
     // Create an active AddonInstall so can check that it isn't returned in the results
-    AddonManager.getInstallForURL(BASE_URL + INSTALL_URL2, function(aInstall) {
-      aInstall.install();
+    AddonManager.getInstallForURL(BASE_URL + INSTALL_URL2, function addon_2_get(aInstall) {
+      try {
+        aInstall.install();
+      }
+      catch(e) {
+        do_print("Failed to install add-on " + aInstall.sourceURI.spec);
+        do_report_unexpected_exception(e);
+      }
 
       // Create a non-active AddonInstall so can check that it is returned in the results
       AddonManager.getInstallForURL(BASE_URL + INSTALL_URL3,
                                     run_test_1, "application/x-xpinstall");
     }, "application/x-xpinstall");
   });
 }
 
@@ -457,134 +463,134 @@ function run_test_1() {
     urlTests:           urlTests.concat(searchURLTests),
     getURL:             function getSearchURL(aTest) {
                           var searchTerms = aTest && aTest.searchTerms ? aTest.searchTerms
                                                                        : "unused terms";
                           return AddonRepository.getSearchURL(searchTerms);
                         }
   }];
 
-  tests.forEach(function(aTest) {
+  tests.forEach(function url_test(aTest) {
     if (aTest.initiallyUndefined) {
       // Preference is not defined by default
       do_check_eq(Services.prefs.getPrefType(aTest.preference),
                   Services.prefs.PREF_INVALID);
       do_check_eq(aTest.getURL(), DEFAULT_URL);
     }
 
     check_urls(aTest.preference, aTest.getURL, aTest.urlTests);
   });
 
-  run_test_2();
+  run_test_getAddonsByID_fails();
 }
 
 // Tests failure of AddonRepository.getAddonsByIDs()
-function run_test_2() {
+function run_test_getAddonsByID_fails() {
   Services.prefs.setCharPref(GET_TEST.preference, GET_TEST.preferenceValue);
   var callback = {
     searchSucceeded: function(aAddonsList, aAddonCount, aTotalResults) {
       do_throw("searchAddons should not have succeeded");
       end_test();
     },
 
     searchFailed: function() {
       do_check_false(AddonRepository.isSearching);
-      run_test_3();
+      run_test_getAddonsByID_succeeds();
     }
   };
 
-  complete_search(function(aCallback) {
+  complete_search(function complete_search_fail_callback(aCallback) {
     AddonRepository.getAddonsByIDs(GET_TEST.failedIDs, aCallback);
   }, callback);
 }
 
 // Tests success of AddonRepository.getAddonsByIDs()
-function run_test_3() {
+function run_test_getAddonsByID_succeeds() {
   var callback = {
     searchSucceeded: function(aAddonsList, aAddonCount, aTotalResults) {
       do_check_eq(aTotalResults, -1);
       check_results(aAddonsList, GET_RESULTS, aAddonCount, true);
-      run_test_4();
+      run_test_retrieveRecommended_fails();
     },
 
     searchFailed: function() {
       do_throw("searchAddons should not have failed");
       end_test();
     }
   };
 
-  complete_search(function(aCallback) {
+  complete_search(function complete_search_succeed_callback(aCallback) {
     AddonRepository.getAddonsByIDs(GET_TEST.successfulIDs, aCallback);
   }, callback);
 }
 
 // Tests failure of AddonRepository.retrieveRecommendedAddons()
-function run_test_4() {
+function run_test_retrieveRecommended_fails() {
   Services.prefs.setCharPref(RECOMMENDED_TEST.preference,
                              RECOMMENDED_TEST.preferenceValue);
   var callback = {
     searchSucceeded: function(aAddonsList, aAddonCount, aTotalResults) {
       do_throw("retrieveRecommendedAddons should not have succeeded");
       end_test();
     },
 
     searchFailed: function() {
       do_check_false(AddonRepository.isSearching);
-      run_test_5();
+      run_test_retrieveRecommended_succeed();
     }
   };
 
-  complete_search(function(aCallback) {
+  complete_search(function retrieveRecommended_failing_callback(aCallback) {
     AddonRepository.retrieveRecommendedAddons(FAILED_MAX_RESULTS, aCallback);
   }, callback);
 }
 
 // Tests success of AddonRepository.retrieveRecommendedAddons()
-function run_test_5() {
+function run_test_retrieveRecommended_succeed() {
   var callback = {
     searchSucceeded: function(aAddonsList, aAddonCount, aTotalResults) {
       do_check_eq(aTotalResults, -1);
       check_results(aAddonsList, SEARCH_RESULTS, aAddonCount);
-      run_test_6();
+      run_test_searchAddons_fails();
     },
 
     searchFailed: function() {
       do_throw("retrieveRecommendedAddons should not have failed");
       end_test();
     }
   };
 
-  complete_search(function(aCallback) {
+  complete_search(function retrieveRecommended_succeed_callback(aCallback) {
     AddonRepository.retrieveRecommendedAddons(MAX_RESULTS, aCallback);
   }, callback);
 }
 
 // Tests failure of AddonRepository.searchAddons()
-function run_test_6() {
+function run_test_searchAddons_fails() {
   Services.prefs.setCharPref(SEARCH_TEST.preference, SEARCH_TEST.preferenceValue);
   var callback = {
     searchSucceeded: function(aAddonsList, aAddonCount, aTotalResults) {
       do_throw("searchAddons should not have succeeded");
       end_test();
     },
 
     searchFailed: function() {
       do_check_false(AddonRepository.isSearching);
-      run_test_7();
+      run_test_searchAddons_succeeds();
     }
   };
 
   complete_search(function(aCallback) {
     var searchTerms = SEARCH_TEST.searchTerms;
     AddonRepository.searchAddons(searchTerms, FAILED_MAX_RESULTS, aCallback);
   }, callback);
 }
 
 // Tests success of AddonRepository.searchAddons()
-function run_test_7() {
+function run_test_searchAddons_succeeds() {
   var callback = {
     searchSucceeded: function(aAddonsList, aAddonCount, aTotalResults) {
       do_check_eq(aTotalResults, TOTAL_RESULTS);
       check_results(aAddonsList, SEARCH_RESULTS, aAddonCount);
       end_test();
     },
 
     searchFailed: function() {
--- a/toolkit/mozapps/extensions/test/xpcshell/test_AddonRepository_cache.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_AddonRepository_cache.js
@@ -409,17 +409,17 @@ const WITH_EXTENSION_CACHE = [{
  *
  * @param  aCallback
  *         Callback to call once the background update is complete
  */
 function trigger_background_update(aCallback) {
   Services.obs.addObserver({
     observe: function(aSubject, aTopic, aData) {
       Services.obs.removeObserver(this, "addons-background-update-complete");
-      aCallback();
+      do_execute_soon(aCallback);
     }
   }, "addons-background-update-complete", false);
 
   gInternalManager.notify(null);
 }
 
 /*
  * Check whether or not the add-ons database exists
@@ -488,17 +488,17 @@ function check_cache(aExpectedToFind, aE
       do_check_eq(immediatelyFound, aExpectedImmediately);
 
       if (expected == null)
         do_check_eq(aAddon, null);
       else
         check_results([aAddon], [expected], true);
 
       if (--pendingAddons == 0)
-        aCallback();
+        do_execute_soon(aCallback);
     });
   }
 
   immediatelyFound = false;
 }
 
 /*
  * Check an initialized cache by checking the cache, then restarting the
@@ -532,32 +532,32 @@ function run_test() {
   // Install XPI add-ons
   installAllFiles(ADDON_FILES, function() {
     restartManager();
 
     gServer = new HttpServer();
     gServer.registerDirectory("/data/", do_get_file("data"));
     gServer.start(PORT);
 
-    run_test_1();
+    do_execute_soon(run_test_1);
   });
 }
 
 function end_test() {
   gServer.stop(do_test_finished);
 }
 
 // Tests AddonRepository.cacheEnabled
 function run_test_1() {
   Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, false);
   do_check_false(AddonRepository.cacheEnabled);
   Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, true);
   do_check_true(AddonRepository.cacheEnabled);
 
-  run_test_2();
+  do_execute_soon(run_test_2);
 }
 
 // Tests that the cache and database begin as empty
 function run_test_2() {
   check_database_exists(false);
   check_cache([false, false, false], false, run_test_3);
 }
 
@@ -679,74 +679,74 @@ function run_test_11() {
 // caching is disabled, even if there are repository properties available
 function run_test_12() {
   check_database_exists(true);
   Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, false);
   Services.prefs.setCharPref(PREF_GETADDONS_BYIDS, GETADDONS_RESULTS);
 
   AddonManager.getAddonsByIDs(ADDON_IDS, function(aAddons) {
     check_results(aAddons, WITHOUT_CACHE);
-    run_test_13();
+    do_execute_soon(run_test_13);
   });
 }
 
 // Tests that a background update with caching disabled deletes the add-ons
 // database, and that XPI add-ons still do not use any of repository properties
 function run_test_13() {
   check_database_exists(true);
   Services.prefs.setCharPref(PREF_GETADDONS_BYIDS_PERF, GETADDONS_EMPTY);
 
   trigger_background_update(function() {
     // Database should have been deleted
     check_database_exists(false);
 
     AddonManager.getAddonsByIDs(ADDON_IDS, function(aAddons) {
       check_results(aAddons, WITHOUT_CACHE);
-      run_test_14();
+      do_execute_soon(run_test_14);
     });
   });
 }
 
 // Tests that the XPI add-ons have the correct properties if caching is
 // enabled but has no information
 function run_test_14() {
   Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, true);
 
   trigger_background_update(function() {
     check_database_exists(true);
 
     AddonManager.getAddonsByIDs(ADDON_IDS, function(aAddons) {
       check_results(aAddons, WITHOUT_CACHE);
-      run_test_15();
+      do_execute_soon(run_test_15);
     });
   });
 }
 
 // Tests that the XPI add-ons correctly use the repository properties when
 // caching is enabled and the repository information is available
 function run_test_15() {
   Services.prefs.setCharPref(PREF_GETADDONS_BYIDS_PERF, GETADDONS_RESULTS);
 
   trigger_background_update(function() {
     AddonManager.getAddonsByIDs(ADDON_IDS, function(aAddons) {
       check_results(aAddons, WITH_CACHE);
-      run_test_16();
+      do_execute_soon(run_test_16);
     });
   });
 }
 
 // Tests that restarting the manager does not change the checked properties
 // on the XPI add-ons (repository properties still exist and are still properly
 // used)
 function run_test_16() {
   restartManager();
 
   AddonManager.getAddonsByIDs(ADDON_IDS, function(aAddons) {
     check_results(aAddons, WITH_CACHE);
-    run_test_17();
+    do_execute_soon(run_test_17);
   });
 }
 
 // Tests that setting a list of types to cache works
 function run_test_17() {
   Services.prefs.setCharPref(PREF_GETADDONS_CACHE_TYPES, "foo,bar,extension,baz");
 
   trigger_background_update(function() {
--- a/toolkit/mozapps/extensions/test/xpcshell/test_backgroundupdate.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_backgroundupdate.js
@@ -35,17 +35,17 @@ function end_test() {
 // called
 function run_test_1() {
   AddonManager.getAddonsByTypes(["extension", "theme", "locale"], function(aAddons) {
     do_check_eq(aAddons.length, 0);
 
     Services.obs.addObserver(function() {
       Services.obs.removeObserver(arguments.callee, "addons-background-update-complete");
 
-      run_test_2();
+      do_execute_soon(run_test_2);
     }, "addons-background-update-complete", false);
 
     AddonManagerPrivate.backgroundUpdateCheck();
   });
 }
 
 // Verify that with two add-ons installed both of which claim to have updates
 // available we get the notification after both updates attempted to start
--- a/toolkit/mozapps/extensions/test/xpcshell/test_badschema.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_badschema.js
@@ -161,31 +161,31 @@ function run_test() {
     a2.userDisabled = true;
     a4.userDisabled = true;
     a7.userDisabled = true;
     t2.userDisabled = false;
     a3.findUpdates({
       onUpdateFinished: function() {
         a4.findUpdates({
           onUpdateFinished: function() {
-            restartManager();
-
-            run_test_1();
+            do_execute_soon(run_test_1);
           }
         }, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
       }
     }, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
   });
 }
 
 function end_test() {
   testserver.stop(do_test_finished);
 }
 
 function run_test_1() {
+  restartManager();
+
   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                "addon2@tests.mozilla.org",
                                "addon3@tests.mozilla.org",
                                "addon4@tests.mozilla.org",
                                "addon5@tests.mozilla.org",
                                "addon6@tests.mozilla.org",
                                "addon7@tests.mozilla.org",
                                "theme1@tests.mozilla.org",
@@ -241,16 +241,22 @@ function run_test_1() {
     do_check_eq(t1.pendingOperations, AddonManager.PENDING_NONE);
 
     do_check_neq(t2, null);
     do_check_true(t2.isActive);
     do_check_false(t2.userDisabled);
     do_check_false(t2.appDisabled);
     do_check_eq(t2.pendingOperations, AddonManager.PENDING_NONE);
 
+    do_execute_soon(run_test_1_modified_db);
+  });
+}
+
+
+function run_test_1_modified_db() {
     // After restarting the database won't be open and so can be replaced with
     // a bad file
     restartManager();
     var dbfile = gProfD.clone();
     dbfile.append("extensions.sqlite");
     var db = Services.storage.openDatabase(dbfile);
     db.schemaVersion = 100;
     db.close();
@@ -317,16 +323,21 @@ function run_test_1() {
       do_check_eq(t1.pendingOperations, AddonManager.PENDING_NONE);
 
       do_check_neq(t2, null);
       do_check_true(t2.isActive);
       do_check_false(t2.userDisabled);
       do_check_false(t2.appDisabled);
       do_check_eq(t2.pendingOperations, AddonManager.PENDING_NONE);
 
+      do_execute_soon(run_test_1_after_rebuild);
+    });
+}
+
+function run_test_1_after_rebuild() {
       restartManager();
 
       AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                    "addon2@tests.mozilla.org",
                                    "addon3@tests.mozilla.org",
                                    "addon4@tests.mozilla.org",
                                    "addon5@tests.mozilla.org",
                                    "addon6@tests.mozilla.org",
@@ -386,11 +397,9 @@ function run_test_1() {
         do_check_neq(t2, null);
         do_check_true(t2.isActive);
         do_check_false(t2.userDisabled);
         do_check_false(t2.appDisabled);
         do_check_eq(t2.pendingOperations, AddonManager.PENDING_NONE);
 
         end_test();
       });
-    });
-  });
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_blocklistchange.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_blocklistchange.js
@@ -558,136 +558,150 @@ function check_addon(aAddon, aExpectedVe
 
 function run_test() {
   // Create and configure the HTTP server.
   testserver = new HttpServer();
   testserver.registerDirectory("/data/", do_get_file("data/blocklistchange"));
   testserver.registerDirectory("/addons/", do_get_file("addons"));
   testserver.start(4444);
 
-  do_test_pending();
+  do_test_pending("test_blocklistchange main");
 
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1");
   writeInstallRDFForExtension(default_theme, profileDir);
   writeInstallRDFForExtension(softblock1_1, profileDir);
   writeInstallRDFForExtension(softblock2_1, profileDir);
   writeInstallRDFForExtension(softblock3_1, profileDir);
   writeInstallRDFForExtension(softblock4_1, profileDir);
   writeInstallRDFForExtension(softblock5_1, profileDir);
   writeInstallRDFForExtension(hardblock_1, profileDir);
   writeInstallRDFForExtension(regexpblock_1, profileDir);
   startupManager();
 
-  AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
+  AddonManager.getAddonsByIDs(ADDON_IDS, do_exception_wrap(function([s1, s2, s3, s4, s5, h, r]) {
     s4.userDisabled = true;
     s5.userDisabled = false;
-    restartManager();
 
-    run_app_update_test();
-  });
-}
-
-function end_test() {
-  testserver.stop(do_test_finished);
+    run_next_test();
+  }));
 }
 
 // Starts with add-ons unblocked and then switches application versions to
 // change add-ons to blocked and back
-function run_app_update_test() {
-  dump(arguments.callee.name + "\n");
-  load_blocklist("app_update.xml", function() {
+add_test(function run_app_update_test() {
+  do_print("Test: " + arguments.callee.name);
+  restartManager();
+  load_blocklist("app_update.xml", function app_update_step_1() {
     restartManager();
 
     AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
 
       check_addon(s1, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
       check_addon(s2, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
       check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
       check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
       check_addon(s5, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
       check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
       check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
       do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "test/1.0");
 
-      restartManager("2");
+      do_execute_soon(app_update_step_2);
+    })
+  });
 
-      AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
+  function app_update_step_2() {
+    restartManager("2");
+
+    AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
 
-        check_addon(s1, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-        check_addon(s2, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-        check_addon(s3, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-        check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-        check_addon(s5, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-        check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
-        check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
-        do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
+      check_addon(s1, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(s2, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(s3, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(s5, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
+      check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
+      do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
 
-        s2.userDisabled = false;
-        s2.userDisabled = true;
-        check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-        s3.userDisabled = false;
-        check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-        restartManager();
+      s2.userDisabled = false;
+      s2.userDisabled = true;
+      check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      s3.userDisabled = false;
+      check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
 
-        restartManager("2.5");
+      do_execute_soon(app_update_step_3);
+    });
+  }
 
-        AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
+  function app_update_step_3() {
+    restartManager();
+
+    restartManager("2.5");
+
+    AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
 
-          check_addon(s1, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-          check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-          check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-          check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-          check_addon(s5, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-          check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
-          check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
-          do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
+      check_addon(s1, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(s5, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
+      check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
+      do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
 
-          restartManager("1");
+      do_execute_soon(app_update_step_4);
+    });
+  }
 
-          AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
+  function app_update_step_4() {
+    restartManager("1");
 
-            check_addon(s1, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
-            check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
-            check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
-            check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
-            check_addon(s5, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
-            check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
-            check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
-            do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
+    AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
 
-            s1.userDisabled = false;
-            s2.userDisabled = false;
-            s5.userDisabled = false;
-            run_app_update_schema_test();
-          });
-        });
-      });
+      check_addon(s1, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
+      check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
+      check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
+      check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
+      check_addon(s5, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
+      check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
+      check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
+      do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
+
+      s1.userDisabled = false;
+      s2.userDisabled = false;
+      s5.userDisabled = false;
+      run_next_test();
     });
-  });
-}
+  }
+});
 
 // Starts with add-ons unblocked and then switches application versions to
 // change add-ons to blocked and back. A DB schema change is faked to force a
 // rebuild when the application version changes
-function run_app_update_schema_test() {
-  dump(arguments.callee.name + "\n");
+add_test(function run_app_update_schema_test() {
+  do_print("Test: " + arguments.callee.name);
   restartManager();
 
   AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
 
     check_addon(s1, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
     check_addon(s2, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
     check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
     check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
     check_addon(s5, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
     check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
     check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
     do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "test/1.0");
 
+    do_execute_soon(update_schema_2);
+  });
+
+  function update_schema_2() {
     shutdownManager();
+
     var dbfile = gProfD.clone();
     dbfile.append("extensions.sqlite");
     var db = Services.storage.openDatabase(dbfile);
     db.schemaVersion = 100;
     db.close();
     gAppInfo.version = "2";
     startupManager(true);
 
@@ -702,107 +716,121 @@ function run_app_update_schema_test() {
       check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
       do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
 
       s2.userDisabled = false;
       s2.userDisabled = true;
       check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
       s3.userDisabled = false;
       check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-      restartManager();
+      do_execute_soon(update_schema_3);
+    });
+  }
+
+  function update_schema_3() {
+    restartManager();
 
-      shutdownManager();
-      var dbfile = gProfD.clone();
-      dbfile.append("extensions.sqlite");
-      var db = Services.storage.openDatabase(dbfile);
-      db.schemaVersion = 100;
-      db.close();
-      gAppInfo.version = "2.5";
-      startupManager(true);
+    shutdownManager();
+    var dbfile = gProfD.clone();
+    dbfile.append("extensions.sqlite");
+    var db = Services.storage.openDatabase(dbfile);
+    db.schemaVersion = 100;
+    db.close();
+    gAppInfo.version = "2.5";
+    startupManager(true);
 
-      AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
+    AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
 
-        check_addon(s1, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-        check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-        check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-        check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-        check_addon(s5, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-        check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
-        check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
-        do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
+      check_addon(s1, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(s5, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
+      check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
+      do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
 
-        shutdownManager();
-        var dbfile = gProfD.clone();
-        dbfile.append("extensions.sqlite");
-        var db = Services.storage.openDatabase(dbfile);
-        db.schemaVersion = 100;
-        db.close();
-        startupManager(false);
+      do_execute_soon(update_schema_4);
+    });
+  }
+
+  function update_schema_4() {
+    shutdownManager();
 
-        AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
+    var dbfile = gProfD.clone();
+    dbfile.append("extensions.sqlite");
+    var db = Services.storage.openDatabase(dbfile);
+    db.schemaVersion = 100;
+    db.close();
+    startupManager(false);
+
+    AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
 
-          check_addon(s1, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-          check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-          check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-          check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-          check_addon(s5, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-          check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
-          check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
-          do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
+      check_addon(s1, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(s5, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
+      check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
+      do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
 
-          shutdownManager();
-          var dbfile = gProfD.clone();
-          dbfile.append("extensions.sqlite");
-          var db = Services.storage.openDatabase(dbfile);
-          db.schemaVersion = 100;
-          db.close();
-          gAppInfo.version = "1";
-          startupManager(true);
+      do_execute_soon(update_schema_5);
+    });
+  }
 
-          AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
+  function update_schema_5() {
+    shutdownManager();
 
-            check_addon(s1, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
-            check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
-            check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
-            check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
-            check_addon(s5, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
-            check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
-            check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
-            do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
+    var dbfile = gProfD.clone();
+    dbfile.append("extensions.sqlite");
+    var db = Services.storage.openDatabase(dbfile);
+    db.schemaVersion = 100;
+    db.close();
+    gAppInfo.version = "1";
+    startupManager(true);
+
+    AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
 
-            s1.userDisabled = false;
-            s2.userDisabled = false;
-            s5.userDisabled = false;
-            run_blocklist_update_test();
-          });
-        });
-      });
+      check_addon(s1, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
+      check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
+      check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
+      check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
+      check_addon(s5, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
+      check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
+      check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
+      do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
+
+      s1.userDisabled = false;
+      s2.userDisabled = false;
+      s5.userDisabled = false;
+      run_next_test();
     });
-  });
-}
+  }
+});
 
 // Starts with add-ons unblocked and then loads new blocklists to change add-ons
 // to blocked and back again.
-function run_blocklist_update_test() {
-  dump(arguments.callee.name + "\n");
-  load_blocklist("blocklist_update1.xml", function() {
+add_test(function run_blocklist_update_test() {
+  do_print("Test: " + arguments.callee.name + "\n");
+  load_blocklist("blocklist_update1.xml", function run_blocklist_update_1() {
     restartManager();
 
     AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
 
       check_addon(s1, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
       check_addon(s2, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
       check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
       check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
       check_addon(s5, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
       check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
       check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
       do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "test/1.0");
 
-      load_blocklist("blocklist_update2.xml", function() {
+      load_blocklist("blocklist_update2.xml", function run_blocklist_update_2() {
         restartManager();
 
         AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
 
           check_addon(s1, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
           check_addon(s2, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
           check_addon(s3, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
           check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
@@ -811,190 +839,205 @@ function run_blocklist_update_test() {
           check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
           do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
 
           s2.userDisabled = false;
           s2.userDisabled = true;
           check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
           s3.userDisabled = false;
           check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-          restartManager();
 
-          load_blocklist("blocklist_update2.xml", function() {
+          do_execute_soon(function restart_and_reload() {
+           restartManager();
+
+           load_blocklist("blocklist_update2.xml", function run_blocklist_update_3() {
             restartManager();
 
             AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
 
               check_addon(s1, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
               check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
               check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
               check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
               check_addon(s5, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
               check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
               check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
               do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
 
-              load_blocklist("blocklist_update1.xml", function() {
+              load_blocklist("blocklist_update1.xml", function run_blocklist_update_4() {
                 restartManager();
 
                 AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
 
                   check_addon(s1, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
                   check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
                   check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
                   check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
                   check_addon(s5, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
                   check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
                   check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
                   do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
 
                   s1.userDisabled = false;
                   s2.userDisabled = false;
                   s5.userDisabled = false;
-                  run_addon_change_test();
+                  run_next_test();
                 });
               });
             });
+           });
           });
         });
       });
     });
   });
-}
+});
 
 // Starts with add-ons unblocked and then new versions are installed outside of
 // the app to change them to blocked and back again.
-function run_addon_change_test() {
-  dump(arguments.callee.name + "\n");
-  load_blocklist("addon_change.xml", function() {
+add_test(function run_addon_change_test() {
+  do_print("Test: " + arguments.callee.name + "\n");
+  load_blocklist("addon_change.xml", function run_addon_change_1() {
     restartManager();
 
     AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
 
       check_addon(s1, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
       check_addon(s2, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
       check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
       check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
       check_addon(s5, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
       check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
       check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
       do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "test/1.0");
 
-      shutdownManager();
-
-      writeInstallRDFForExtension(softblock1_2, profileDir);
-      setExtensionModifiedTime(getFileForAddon(profileDir, softblock1_2.id), Date.now() + 10000);
-      writeInstallRDFForExtension(softblock2_2, profileDir);
-      setExtensionModifiedTime(getFileForAddon(profileDir, softblock2_2.id), Date.now() + 10000);
-      writeInstallRDFForExtension(softblock3_2, profileDir);
-      setExtensionModifiedTime(getFileForAddon(profileDir, softblock3_2.id), Date.now() + 10000);
-      writeInstallRDFForExtension(softblock4_2, profileDir);
-      setExtensionModifiedTime(getFileForAddon(profileDir, softblock4_2.id), Date.now() + 10000);
-      writeInstallRDFForExtension(softblock5_2, profileDir);
-      setExtensionModifiedTime(getFileForAddon(profileDir, softblock5_2.id), Date.now() + 10000);
-      writeInstallRDFForExtension(hardblock_2, profileDir);
-      setExtensionModifiedTime(getFileForAddon(profileDir, hardblock_2.id), Date.now() + 10000);
-      writeInstallRDFForExtension(regexpblock_2, profileDir);
-      setExtensionModifiedTime(getFileForAddon(profileDir, regexpblock_2.id), Date.now() + 10000);
-
-      startupManager(false);
-
-      AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
-
-        check_addon(s1, "2.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-        check_addon(s2, "2.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-        check_addon(s3, "2.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-        check_addon(s4, "2.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-        check_addon(s5, "2.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-        check_addon(h, "2.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
-        check_addon(r, "2.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
-        do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
-
-        s2.userDisabled = false;
-        s2.userDisabled = true;
-        check_addon(s2, "2.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-        s3.userDisabled = false;
-        check_addon(s3, "2.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-        restartManager();
-
-        shutdownManager();
-
-        writeInstallRDFForExtension(softblock1_3, profileDir);
-        setExtensionModifiedTime(getFileForAddon(profileDir, softblock1_3.id), Date.now() + 20000);
-        writeInstallRDFForExtension(softblock2_3, profileDir);
-        setExtensionModifiedTime(getFileForAddon(profileDir, softblock2_3.id), Date.now() + 20000);
-        writeInstallRDFForExtension(softblock3_3, profileDir);
-        setExtensionModifiedTime(getFileForAddon(profileDir, softblock3_3.id), Date.now() + 20000);
-        writeInstallRDFForExtension(softblock4_3, profileDir);
-        setExtensionModifiedTime(getFileForAddon(profileDir, softblock4_3.id), Date.now() + 20000);
-        writeInstallRDFForExtension(softblock5_3, profileDir);
-        setExtensionModifiedTime(getFileForAddon(profileDir, softblock5_3.id), Date.now() + 20000);
-        writeInstallRDFForExtension(hardblock_3, profileDir);
-        setExtensionModifiedTime(getFileForAddon(profileDir, hardblock_3.id), Date.now() + 20000);
-        writeInstallRDFForExtension(regexpblock_3, profileDir);
-        setExtensionModifiedTime(getFileForAddon(profileDir, regexpblock_3.id), Date.now() + 20000);
-
-        startupManager(false);
-
-        AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
-
-          check_addon(s1, "3.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-          check_addon(s2, "3.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-          check_addon(s3, "3.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-          check_addon(s4, "3.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-          check_addon(s5, "3.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-          check_addon(h, "3.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
-          check_addon(r, "3.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
-          do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
-
-          shutdownManager();
-
-          writeInstallRDFForExtension(softblock1_1, profileDir);
-          setExtensionModifiedTime(getFileForAddon(profileDir, softblock1_1.id), Date.now() + 30000);
-          writeInstallRDFForExtension(softblock2_1, profileDir);
-          setExtensionModifiedTime(getFileForAddon(profileDir, softblock2_1.id), Date.now() + 30000);
-          writeInstallRDFForExtension(softblock3_1, profileDir);
-          setExtensionModifiedTime(getFileForAddon(profileDir, softblock3_1.id), Date.now() + 30000);
-          writeInstallRDFForExtension(softblock4_1, profileDir);
-          setExtensionModifiedTime(getFileForAddon(profileDir, softblock4_1.id), Date.now() + 30000);
-          writeInstallRDFForExtension(softblock5_1, profileDir);
-          setExtensionModifiedTime(getFileForAddon(profileDir, softblock5_1.id), Date.now() + 30000);
-          writeInstallRDFForExtension(hardblock_1, profileDir);
-          setExtensionModifiedTime(getFileForAddon(profileDir, hardblock_1.id), Date.now() + 30000);
-          writeInstallRDFForExtension(regexpblock_1, profileDir);
-          setExtensionModifiedTime(getFileForAddon(profileDir, regexpblock_1.id), Date.now() + 30000);
-
-          startupManager(false);
-
-          AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
-
-            check_addon(s1, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
-            check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
-            check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
-            check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
-            check_addon(s5, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
-            check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
-            check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
-            do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
-
-            s1.userDisabled = false;
-            s2.userDisabled = false;
-            s5.userDisabled = false;
-            run_addon_change_2_test();
-          });
-        });
-      });
+      do_execute_soon(run_addon_change_2);
     });
   });
-}
+
+  function run_addon_change_2() {
+    shutdownManager();
+
+    writeInstallRDFForExtension(softblock1_2, profileDir);
+    setExtensionModifiedTime(getFileForAddon(profileDir, softblock1_2.id), Date.now() + 10000);
+    writeInstallRDFForExtension(softblock2_2, profileDir);
+    setExtensionModifiedTime(getFileForAddon(profileDir, softblock2_2.id), Date.now() + 10000);
+    writeInstallRDFForExtension(softblock3_2, profileDir);
+    setExtensionModifiedTime(getFileForAddon(profileDir, softblock3_2.id), Date.now() + 10000);
+    writeInstallRDFForExtension(softblock4_2, profileDir);
+    setExtensionModifiedTime(getFileForAddon(profileDir, softblock4_2.id), Date.now() + 10000);
+    writeInstallRDFForExtension(softblock5_2, profileDir);
+    setExtensionModifiedTime(getFileForAddon(profileDir, softblock5_2.id), Date.now() + 10000);
+    writeInstallRDFForExtension(hardblock_2, profileDir);
+    setExtensionModifiedTime(getFileForAddon(profileDir, hardblock_2.id), Date.now() + 10000);
+    writeInstallRDFForExtension(regexpblock_2, profileDir);
+    setExtensionModifiedTime(getFileForAddon(profileDir, regexpblock_2.id), Date.now() + 10000);
+
+    startupManager(false);
+
+    AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
+
+      check_addon(s1, "2.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(s2, "2.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(s3, "2.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(s4, "2.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(s5, "2.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(h, "2.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
+      check_addon(r, "2.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
+      do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
+
+      s2.userDisabled = false;
+      s2.userDisabled = true;
+      check_addon(s2, "2.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      s3.userDisabled = false;
+      check_addon(s3, "2.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      do_execute_soon(run_addon_change_3);
+    });
+  }
+
+  function run_addon_change_3() {
+    restartManager();
+
+    shutdownManager();
+
+    writeInstallRDFForExtension(softblock1_3, profileDir);
+    setExtensionModifiedTime(getFileForAddon(profileDir, softblock1_3.id), Date.now() + 20000);
+    writeInstallRDFForExtension(softblock2_3, profileDir);
+    setExtensionModifiedTime(getFileForAddon(profileDir, softblock2_3.id), Date.now() + 20000);
+    writeInstallRDFForExtension(softblock3_3, profileDir);
+    setExtensionModifiedTime(getFileForAddon(profileDir, softblock3_3.id), Date.now() + 20000);
+    writeInstallRDFForExtension(softblock4_3, profileDir);
+    setExtensionModifiedTime(getFileForAddon(profileDir, softblock4_3.id), Date.now() + 20000);
+    writeInstallRDFForExtension(softblock5_3, profileDir);
+    setExtensionModifiedTime(getFileForAddon(profileDir, softblock5_3.id), Date.now() + 20000);
+    writeInstallRDFForExtension(hardblock_3, profileDir);
+    setExtensionModifiedTime(getFileForAddon(profileDir, hardblock_3.id), Date.now() + 20000);
+    writeInstallRDFForExtension(regexpblock_3, profileDir);
+    setExtensionModifiedTime(getFileForAddon(profileDir, regexpblock_3.id), Date.now() + 20000);
+
+    startupManager(false);
+
+    AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
+
+      check_addon(s1, "3.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(s2, "3.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(s3, "3.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(s4, "3.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(s5, "3.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+      check_addon(h, "3.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
+      check_addon(r, "3.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
+      do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
+
+      do_execute_soon(run_addon_change_4);
+    });
+  }
+
+  function run_addon_change_4() {
+    shutdownManager();
+
+    writeInstallRDFForExtension(softblock1_1, profileDir);
+    setExtensionModifiedTime(getFileForAddon(profileDir, softblock1_1.id), Date.now() + 30000);
+    writeInstallRDFForExtension(softblock2_1, profileDir);
+    setExtensionModifiedTime(getFileForAddon(profileDir, softblock2_1.id), Date.now() + 30000);
+    writeInstallRDFForExtension(softblock3_1, profileDir);
+    setExtensionModifiedTime(getFileForAddon(profileDir, softblock3_1.id), Date.now() + 30000);
+    writeInstallRDFForExtension(softblock4_1, profileDir);
+    setExtensionModifiedTime(getFileForAddon(profileDir, softblock4_1.id), Date.now() + 30000);
+    writeInstallRDFForExtension(softblock5_1, profileDir);
+    setExtensionModifiedTime(getFileForAddon(profileDir, softblock5_1.id), Date.now() + 30000);
+    writeInstallRDFForExtension(hardblock_1, profileDir);
+    setExtensionModifiedTime(getFileForAddon(profileDir, hardblock_1.id), Date.now() + 30000);
+    writeInstallRDFForExtension(regexpblock_1, profileDir);
+    setExtensionModifiedTime(getFileForAddon(profileDir, regexpblock_1.id), Date.now() + 30000);
+
+    startupManager(false);
+
+    AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
+
+      check_addon(s1, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
+      check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
+      check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
+      check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
+      check_addon(s5, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
+      check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
+      check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
+      do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
+
+      s1.userDisabled = false;
+      s2.userDisabled = false;
+      s5.userDisabled = false;
+      run_next_test();
+    });
+  }
+});
 
 // Starts with add-ons blocked and then new versions are installed outside of
 // the app to change them to unblocked.
-function run_addon_change_2_test() {
-  dump(arguments.callee.name + "\n");
+add_test(function run_addon_change_2_test() {
+  do_print("Test: " + arguments.callee.name + "\n");
   shutdownManager();
 
   getFileForAddon(profileDir, softblock1_1.id).remove(true);
   getFileForAddon(profileDir, softblock2_1.id).remove(true);
   getFileForAddon(profileDir, softblock3_1.id).remove(true);
   getFileForAddon(profileDir, softblock4_1.id).remove(true);
   getFileForAddon(profileDir, softblock5_1.id).remove(true);
   getFileForAddon(profileDir, hardblock_1.id).remove(true);
@@ -1021,16 +1064,20 @@ function run_addon_change_2_test() {
     check_addon(h, "2.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
     check_addon(r, "2.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
 
     s2.userDisabled = false;
     s2.userDisabled = true;
     check_addon(s2, "2.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
     s3.userDisabled = false;
     check_addon(s3, "2.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
+    do_execute_soon(addon_change_2_test_2);
+  });
+
+  function addon_change_2_test_2() {
     restartManager();
 
     shutdownManager();
 
     writeInstallRDFForExtension(softblock1_3, profileDir);
     setExtensionModifiedTime(getFileForAddon(profileDir, softblock1_3.id), Date.now() + 10000);
     writeInstallRDFForExtension(softblock2_3, profileDir);
     setExtensionModifiedTime(getFileForAddon(profileDir, softblock2_3.id), Date.now() + 10000);
@@ -1050,92 +1097,96 @@ function run_addon_change_2_test() {
     AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
 
       check_addon(s1, "3.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
       check_addon(s2, "3.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
       check_addon(s3, "3.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
       check_addon(h, "3.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
       check_addon(r, "3.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
 
-      shutdownManager();
+      do_execute_soon(addon_change_2_test_3);
+    });
+  }
 
-      writeInstallRDFForExtension(softblock1_1, profileDir);
-      setExtensionModifiedTime(getFileForAddon(profileDir, softblock1_1.id), Date.now() + 20000);
-      writeInstallRDFForExtension(softblock2_1, profileDir);
-      setExtensionModifiedTime(getFileForAddon(profileDir, softblock2_1.id), Date.now() + 20000);
-      writeInstallRDFForExtension(softblock3_1, profileDir);
-      setExtensionModifiedTime(getFileForAddon(profileDir, softblock3_1.id), Date.now() + 20000);
-      writeInstallRDFForExtension(softblock4_1, profileDir);
-      setExtensionModifiedTime(getFileForAddon(profileDir, softblock4_1.id), Date.now() + 20000);
-      writeInstallRDFForExtension(softblock5_1, profileDir);
-      setExtensionModifiedTime(getFileForAddon(profileDir, softblock5_1.id), Date.now() + 20000);
-      writeInstallRDFForExtension(hardblock_1, profileDir);
-      setExtensionModifiedTime(getFileForAddon(profileDir, hardblock_1.id), Date.now() + 20000);
-      writeInstallRDFForExtension(regexpblock_1, profileDir);
-      setExtensionModifiedTime(getFileForAddon(profileDir, regexpblock_1.id), Date.now() + 20000);
+  function addon_change_2_test_3() {
+    shutdownManager();
 
-      startupManager(false);
-
-      AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
+    writeInstallRDFForExtension(softblock1_1, profileDir);
+    setExtensionModifiedTime(getFileForAddon(profileDir, softblock1_1.id), Date.now() + 20000);
+    writeInstallRDFForExtension(softblock2_1, profileDir);
+    setExtensionModifiedTime(getFileForAddon(profileDir, softblock2_1.id), Date.now() + 20000);
+    writeInstallRDFForExtension(softblock3_1, profileDir);
+    setExtensionModifiedTime(getFileForAddon(profileDir, softblock3_1.id), Date.now() + 20000);
+    writeInstallRDFForExtension(softblock4_1, profileDir);
+    setExtensionModifiedTime(getFileForAddon(profileDir, softblock4_1.id), Date.now() + 20000);
+    writeInstallRDFForExtension(softblock5_1, profileDir);
+    setExtensionModifiedTime(getFileForAddon(profileDir, softblock5_1.id), Date.now() + 20000);
+    writeInstallRDFForExtension(hardblock_1, profileDir);
+    setExtensionModifiedTime(getFileForAddon(profileDir, hardblock_1.id), Date.now() + 20000);
+    writeInstallRDFForExtension(regexpblock_1, profileDir);
+    setExtensionModifiedTime(getFileForAddon(profileDir, regexpblock_1.id), Date.now() + 20000);
 
-        check_addon(s1, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
-        check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
-        check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
-        check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
-        check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
+    startupManager(false);
 
-        s1.userDisabled = false;
-        s2.userDisabled = false;
-        s4.userDisabled = true;
-        s5.userDisabled = false;
-        run_background_update_test();
-      });
+    AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
+
+      check_addon(s1, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
+      check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
+      check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
+      check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
+      check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
+
+      s1.userDisabled = false;
+      s2.userDisabled = false;
+      s4.userDisabled = true;
+      s5.userDisabled = false;
+      run_next_test();
     });
-  });
-}
+  }
+});
 
 // Add-ons are initially unblocked then attempts to upgrade to blocked versions
 // in the background which should fail
-function run_background_update_test() {
-  dump(arguments.callee.name + "\n");
+add_test(function run_background_update_test() {
+  do_print("Test: " + arguments.callee.name + "\n");
   restartManager();
 
   AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
 
     check_addon(s1, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
     check_addon(s2, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
     check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
     check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
     check_addon(s5, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
     check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
     check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
 
-    background_update(function() {
+    background_update(function background_update_1() {
       restartManager();
 
       AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
 
         check_addon(s1, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
         check_addon(s2, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
         check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
         check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
         check_addon(s5, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
         check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
         check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
 
-        run_background_update_2_test();
+        run_next_test();
       });
     });
   });
-}
+});
 
 // Starts with add-ons blocked and then new versions are detected and installed
 // automatically for unblocked versions.
-function run_background_update_2_test() {
-  dump(arguments.callee.name + "\n");
+add_test(function run_background_update_2_test() {
+  do_print("Test: " + arguments.callee.name + "\n");
   shutdownManager();
 
   getFileForAddon(profileDir, softblock1_1.id).remove(true);
   getFileForAddon(profileDir, softblock2_1.id).remove(true);
   getFileForAddon(profileDir, softblock3_1.id).remove(true);
   getFileForAddon(profileDir, softblock4_1.id).remove(true);
   getFileForAddon(profileDir, softblock5_1.id).remove(true);
   getFileForAddon(profileDir, hardblock_1.id).remove(true);
@@ -1162,45 +1213,49 @@ function run_background_update_2_test() 
     check_addon(h, "3.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
     check_addon(r, "3.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
 
     s2.userDisabled = false;
     s2.userDisabled = true;
     check_addon(s2, "3.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
     s3.userDisabled = false;
     check_addon(s3, "3.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-    restartManager();
 
-    background_update(function() {
+    // make sure we're not in a handler when we restart
+    do_execute_soon(function restart_and_update() {
+     restartManager();
+
+     background_update(function background_update_2_1() {
       restartManager();
 
       AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
 
         check_addon(s1, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
         check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
         check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
         check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
         check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
 
         s1.userDisabled = false;
         s2.userDisabled = false;
         s4.userDisabled = true;
         s5.userDisabled = true;
-        run_manual_update_test();
+        run_next_test();
       });
+     });
     });
   });
-}
+});
 
 // Starts with add-ons blocked and then simulates the user upgrading them to
 // unblocked versions.
-function run_manual_update_test() {
-  dump(arguments.callee.name + "\n");
+add_test(function run_manual_update_test() {
+  do_print("Test: " + arguments.callee.name + "\n");
   restartManager();
-  load_blocklist("manual_update.xml", function() {
+  load_blocklist("manual_update.xml", function manual_update_1() {
     restartManager();
 
     AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
 
       check_addon(s1, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
       check_addon(s2, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
       check_addon(s3, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
       check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
@@ -1208,58 +1263,61 @@ function run_manual_update_test() {
       check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
       check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
 
       s2.userDisabled = false;
       s2.userDisabled = true;
       check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
       s3.userDisabled = false;
       check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
-      restartManager();
 
-      manual_update("2", function() {
+      do_execute_soon(function restart_manual_update() {
+       restartManager();
+
+       manual_update("2", function manual_update_2() {
         restartManager();
 
         AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
 
           check_addon(s1, "2.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
           check_addon(s2, "2.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
           check_addon(s3, "2.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
           check_addon(s4, "2.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
           check_addon(s5, "2.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
           // Can't manually update to a hardblocked add-on
           check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
           check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
 
-          manual_update("3", function() {
+          manual_update("3", function manual_update_3() {
             restartManager();
 
             AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
 
               check_addon(s1, "3.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
               check_addon(s2, "3.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
               check_addon(s3, "3.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
               check_addon(s4, "3.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
               check_addon(s5, "3.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
               check_addon(h, "3.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
               check_addon(r, "3.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
 
-              run_manual_update_2_test();
+              run_next_test();
             });
           });
         });
+       });
       });
     });
   });
-}
+});
 
 // Starts with add-ons blocked and then new versions are installed outside of
 // the app to change them to unblocked.
-function run_manual_update_2_test() {
-  dump(arguments.callee.name + "\n");
+add_test(function run_manual_update_2_test() {
+  do_print("Test: " + arguments.callee.name + "\n");
   shutdownManager();
 
   getFileForAddon(profileDir, softblock1_1.id).remove(true);
   getFileForAddon(profileDir, softblock2_1.id).remove(true);
   getFileForAddon(profileDir, softblock3_1.id).remove(true);
   getFileForAddon(profileDir, softblock4_1.id).remove(true);
   getFileForAddon(profileDir, softblock5_1.id).remove(true);
   getFileForAddon(profileDir, hardblock_1.id).remove(true);
@@ -1288,55 +1346,55 @@ function run_manual_update_2_test() {
 
     s2.userDisabled = false;
     s2.userDisabled = true;
     check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
     s3.userDisabled = false;
     check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
     restartManager();
 
-    manual_update("2", function() {
+    manual_update("2", function manual_update_2_2() {
       restartManager();
 
       AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
 
         check_addon(s1, "2.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
         check_addon(s2, "2.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
         check_addon(s3, "2.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
         // Can't manually update to a hardblocked add-on
         check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
         check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
 
         restartManager();
 
-        manual_update("3", function() {
+        manual_update("3", function manual_update_2_3() {
           restartManager();
 
           AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
 
             check_addon(s1, "3.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
             check_addon(s2, "3.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
             check_addon(s3, "3.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
             check_addon(h, "3.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
             check_addon(r, "3.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
 
             s1.userDisabled = false;
             s2.userDisabled = false;
             s4.userDisabled = true;
-            run_local_install_test();
+            run_next_test();
           });
         });
       });
     });
   });
-}
+});
 
 // Uses the API to install blocked add-ons from the local filesystem
-function run_local_install_test() {
-  dump(arguments.callee.name + "\n");
+add_test(function run_local_install_test() {
+  do_print("Test: " + arguments.callee.name + "\n");
   shutdownManager();
 
   getFileForAddon(profileDir, softblock1_1.id).remove(true);
   getFileForAddon(profileDir, softblock2_1.id).remove(true);
   getFileForAddon(profileDir, softblock3_1.id).remove(true);
   getFileForAddon(profileDir, softblock4_1.id).remove(true);
   getFileForAddon(profileDir, softblock5_1.id).remove(true);
   getFileForAddon(profileDir, hardblock_1.id).remove(true);
@@ -1347,26 +1405,35 @@ function run_local_install_test() {
   installAllFiles([
     do_get_file("addons/blocklist_soft1_1.xpi"),
     do_get_file("addons/blocklist_soft2_1.xpi"),
     do_get_file("addons/blocklist_soft3_1.xpi"),
     do_get_file("addons/blocklist_soft4_1.xpi"),
     do_get_file("addons/blocklist_soft5_1.xpi"),
     do_get_file("addons/blocklist_hard1_1.xpi"),
     do_get_file("addons/blocklist_regexp1_1.xpi")
-  ], function() {
+  ], function local_install_1() {
     AddonManager.getAllInstalls(function(aInstalls) {
       // Should have finished all installs without needing to restart
       do_check_eq(aInstalls.length, 0);
 
       AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
 
         check_addon(s1, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
         check_addon(s2, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
         check_addon(s3, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
         check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
         check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
 
-        end_test();
+        run_next_test();
       });
     });
   });
-}
+});
+
+add_test(function shutdown_httpserver() {
+  testserver.stop(function() {
+    do_test_finished("test_blocklistchange main");
+    // this really means "async test step done"; needs to be called
+    // even when there isn't a next test
+    run_next_test();
+  });
+});
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js
@@ -6,16 +6,18 @@ const APP_STARTUP                     = 
 const APP_SHUTDOWN                    = 2;
 const ADDON_ENABLE                    = 3;
 const ADDON_DISABLE                   = 4;
 const ADDON_INSTALL                   = 5;
 const ADDON_UNINSTALL                 = 6;
 const ADDON_UPGRADE                   = 7;
 const ADDON_DOWNGRADE                 = 8;
 
+const EXTENSIONS_DB                   = "extensions.sqlite";
+
 // This verifies that bootstrappable add-ons can be used without restarts.
 Components.utils.import("resource://gre/modules/Services.jsm");
 
 // Enable loading extensions from the user scopes
 Services.prefs.setIntPref("extensions.enabledScopes",
                           AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_USER);
 
 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
@@ -43,17 +45,18 @@ function resetPrefs() {
   Services.prefs.setIntPref("bootstraptest.shutdown_newversion", -1);
   Services.prefs.setIntPref("bootstraptest.install_oldversion", -1);
   Services.prefs.setIntPref("bootstraptest.uninstall_newversion", -1);
 }
 
 function waitForPref(aPref, aCallback) {
   function prefChanged() {
     Services.prefs.removeObserver(aPref, prefChanged);
-    aCallback();
+    // Always let whoever set the preference keep running
+    do_execute_soon(aCallback);
   }
   Services.prefs.addObserver(aPref, prefChanged, false);
 }
 
 function getActiveVersion() {
   return Services.prefs.getIntPref("bootstraptest.active_version");
 }
 
@@ -142,17 +145,17 @@ function run_test() {
   // Create and configure the HTTP server.
   testserver = new HttpServer();
   testserver.registerDirectory("/addons/", do_get_file("addons"));
   testserver.start(4444);
 
   startupManager();
 
   let file = gProfD.clone();
-  file.append("extensions.sqlite");
+  file.append(EXTENSIONS_DB);
   do_check_false(file.exists());
 
   file.leafName = "extensions.ini";
   do_check_false(file.exists());
 
   do_check_bootstrappedPref(run_test_1);
 }
 
@@ -174,44 +177,44 @@ function run_test_1() {
     do_check_true(install.addon.hasResource("install.rdf"));
     do_check_true(install.addon.hasResource("bootstrap.js"));
     do_check_false(install.addon.hasResource("foo.bar"));
     do_check_eq(install.addon.operationsRequiringRestart &
                 AddonManager.OP_NEEDS_RESTART_INSTALL, 0);
     do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0");
 
     let addon = install.addon;
+
+    waitForPref("bootstraptest.startup_reason", function() {
+      do_check_bootstrappedPref(function() {
+        check_test_1(addon.syncGUID);
+      });
+    });
+
     prepare_test({
       "bootstrap1@tests.mozilla.org": [
         ["onInstalling", false],
         "onInstalled"
       ]
     }, [
       "onInstallStarted",
       "onInstallEnded",
     ], function() {
       do_check_true(addon.hasResource("install.rdf"));
 
       // startup should not have been called yet.
       do_check_eq(getActiveVersion(), -1);
-
-      waitForPref("bootstraptest.active_version", function() {
-        do_check_bootstrappedPref(function() {
-          check_test_1(addon.syncGUID);
-        });
-      });
-
     });
     install.install();
   });
 }
 
 function check_test_1(installSyncGUID) {
   let file = gProfD.clone();
-  file.append("extensions.sqlite");
+  file.append(EXTENSIONS_DB);
   do_check_true(file.exists());
 
   file.leafName = "extensions.ini";
   do_check_false(file.exists());
 
   AddonManager.getAllInstalls(function(installs) {
     // There should be no active installs now since the install completed and
     // doesn't require a restart.
@@ -235,17 +238,17 @@ function check_test_1(installSyncGUID) {
       do_check_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0");
 
       let dir = do_get_addon_root_uri(profileDir, "bootstrap1@tests.mozilla.org");
       do_check_eq(b1.getResourceURI("bootstrap.js").spec, dir + "bootstrap.js");
 
       AddonManager.getAddonsWithOperationsByTypes(null, function(list) {
         do_check_eq(list.length, 0);
 
-        run_test_2();
+        do_execute_soon(run_test_2);
       });
     });
   });
 }
 
 // Tests that disabling doesn't require a restart
 function run_test_2() {
   AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) {
@@ -388,26 +391,26 @@ function run_test_6() {
     ensure_test_completed();
 
     do_check_neq(install, null);
     do_check_eq(install.type, "extension");
     do_check_eq(install.version, "2.0");
     do_check_eq(install.name, "Test Bootstrap 1");
     do_check_eq(install.state, AddonManager.STATE_DOWNLOADED);
 
+    waitForPref("bootstraptest.startup_reason", check_test_6);
     prepare_test({
       "bootstrap1@tests.mozilla.org": [
         ["onInstalling", false],
         "onInstalled"
       ]
     }, [
       "onInstallStarted",
       "onInstallEnded",
     ], function() {
-      waitForPref("bootstraptest.active_version", check_test_6);
     });
     install.install();
   });
 }
 
 function check_test_6() {
   AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) {
     do_check_neq(b1, null);
@@ -509,16 +512,17 @@ function run_test_9() {
 
     do_check_bootstrappedPref(run_test_10);
   });
 }
 
 
 // Tests that installing a downgrade sends the right reason
 function run_test_10() {
+  resetPrefs();
   prepare_test({ }, [
     "onNewInstall"
   ]);
 
   AddonManager.getInstallForFile(do_get_addon("test_bootstrap1_2"), function(install) {
     ensure_test_completed();
 
     do_check_neq(install, null);
@@ -526,26 +530,27 @@ function run_test_10() {
     do_check_eq(install.version, "2.0");
     do_check_eq(install.name, "Test Bootstrap 1");
     do_check_eq(install.state, AddonManager.STATE_DOWNLOADED);
     do_check_true(install.addon.hasResource("install.rdf"));
     do_check_true(install.addon.hasResource("bootstrap.js"));
     do_check_false(install.addon.hasResource("foo.bar"));
     do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "2.0");
 
+    waitForPref("bootstraptest.startup_reason", check_test_10_pt1);
     prepare_test({
       "bootstrap1@tests.mozilla.org": [
         ["onInstalling", false],
         "onInstalled"
       ]
     }, [
       "onInstallStarted",
       "onInstallEnded",
     ], function() {
-      waitForPref("bootstraptest.active_version", check_test_10_pt1);
+      do_print("Waiting for startup of bootstrap1_2");
     });
     install.install();
   });
 }
 
 function check_test_10_pt1() {
   AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) {
     do_check_neq(b1, null);
@@ -570,27 +575,26 @@ function check_test_10_pt1() {
       ensure_test_completed();
 
       do_check_neq(install, null);
       do_check_eq(install.type, "extension");
       do_check_eq(install.version, "1.0");
       do_check_eq(install.name, "Test Bootstrap 1");
       do_check_eq(install.state, AddonManager.STATE_DOWNLOADED);
 
+      waitForPref("bootstraptest.startup_reason", check_test_10_pt2);
       prepare_test({
         "bootstrap1@tests.mozilla.org": [
           ["onInstalling", false],
           "onInstalled"
         ]
       }, [
         "onInstallStarted",
         "onInstallEnded",
-      ], function() {
-      waitForPref("bootstraptest.active_version", check_test_10_pt2);
-    });
+      ], function() { });
       install.install();
     });
   });
 }
 
 function check_test_10_pt2() {
   AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) {
     do_check_neq(b1, null);
@@ -698,17 +702,17 @@ function run_test_13() {
     prepare_test({
       "bootstrap1@tests.mozilla.org": [
         ["onInstalling", false],
         "onInstalled"
       ]
     }, [
       "onInstallStarted",
       "onInstallEnded",
-    ], check_test_13);
+    ], function() {do_execute_soon(check_test_13)});
     install.install();
   });
 }
 
 function check_test_13() {
   AddonManager.getAllInstalls(function(installs) {
     // There should be no active installs now since the install completed and
     // doesn't require a restart.
@@ -733,28 +737,28 @@ function check_test_13() {
         do_check_false(b1.userDisabled);
         do_check_false(b1.isActive);
         do_check_eq(getInstalledVersion(), 3);  // We call install even for disabled add-ons
         do_check_eq(getActiveVersion(), 0);     // Should not have called startup though
         do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "3.0");
 
         do_check_bootstrappedPref(function() {
           b1.uninstall();
-          restartManager();
-
-          run_test_14();
+          do_execute_soon(run_test_14);
         });
       });
     });
   });
 }
 
 // Tests that a bootstrapped extension with an invalid target application entry
 // does not get loaded when detected during startup
 function run_test_14() {
+  restartManager();
+
   shutdownManager();
 
   manuallyInstall(do_get_addon("test_bootstrap1_3"), profileDir,
                   "bootstrap1@tests.mozilla.org");
 
   startupManager(false);
 
   AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) {
@@ -773,17 +777,18 @@ function run_test_14() {
       run_test_15();
     });
   });
 }
 
 // Tests that upgrading a disabled bootstrapped extension still calls uninstall
 // and install but doesn't startup the new version
 function run_test_15() {
-  installAllFiles([do_get_addon("test_bootstrap1_1")], function() {
+  resetPrefs();
+  waitForPref("bootstraptest.startup_reason", function test_15_after_startup() {
     AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) {
       do_check_neq(b1, null);
       do_check_eq(b1.version, "1.0");
       do_check_false(b1.appDisabled);
       do_check_false(b1.userDisabled);
       do_check_true(b1.isActive);
       do_check_eq(getInstalledVersion(), 1);
       do_check_eq(getActiveVersion(), 1);
@@ -806,21 +811,22 @@ function run_test_15() {
         prepare_test({
           "bootstrap1@tests.mozilla.org": [
             ["onInstalling", false],
             "onInstalled"
           ]
         }, [
           "onInstallStarted",
           "onInstallEnded",
-        ], check_test_15);
+        ], function() {do_execute_soon(check_test_15)});
         install.install();
       });
     });
   });
+  installAllFiles([do_get_addon("test_bootstrap1_1")], function test_15_addon_installed() { });
 }
 
 function check_test_15() {
   AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) {
     do_check_neq(b1, null);
     do_check_eq(b1.version, "2.0");
     do_check_false(b1.appDisabled);
     do_check_true(b1.userDisabled);
@@ -845,17 +851,18 @@ function check_test_15() {
         run_test_16();
       });
     });
   });
 }
 
 // Tests that bootstrapped extensions don't get loaded when in safe mode
 function run_test_16() {
-  installAllFiles([do_get_addon("test_bootstrap1_1")], function() {
+  resetPrefs();
+  waitForPref("bootstraptest.startup_reason", function test_16_after_startup() {
     AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) {
       // Should have installed and started
       do_check_eq(getInstalledVersion(), 1);
       do_check_eq(getActiveVersion(), 1);
       do_check_true(b1.isActive);
       do_check_eq(b1.iconURL, "chrome://foo/skin/icon.png");
       do_check_eq(b1.aboutURL, "chrome://foo/content/about.xul");
       do_check_eq(b1.optionsURL, "chrome://foo/content/options.xul");
@@ -889,16 +896,17 @@ function run_test_16() {
         AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) {
           b1.uninstall();
 
           run_test_17();
         });
       });
     });
   });
+  installAllFiles([do_get_addon("test_bootstrap1_1")], function() { });
 }
 
 // Check that a bootstrapped extension in a non-profile location is loaded
 function run_test_17() {
   shutdownManager();
 
   manuallyInstall(do_get_addon("test_bootstrap1_1"), userExtDir,
                   "bootstrap1@tests.mozilla.org");
@@ -917,17 +925,17 @@ function run_test_17() {
     do_check_bootstrappedPref(run_test_18);
   });
 }
 
 // Check that installing a new bootstrapped extension in the profile replaces
 // the existing one
 function run_test_18() {
   resetPrefs();
-  installAllFiles([do_get_addon("test_bootstrap1_2")], function() {
+  waitForPref("bootstraptest.startup_reason", function test_16_after_startup() {
     AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) {
       // Should have installed and started
       do_check_eq(getInstalledVersion(), 2);
       do_check_eq(getActiveVersion(), 2);
       do_check_neq(b1, null);
       do_check_eq(b1.version, "2.0");
       do_check_true(b1.isActive);
 
@@ -939,16 +947,17 @@ function run_test_18() {
       do_check_eq(getShutdownNewVersion(), 2);
       do_check_eq(getUninstallNewVersion(), 2);
       do_check_eq(getInstallOldVersion(), 1);
       do_check_eq(getStartupOldVersion(), 1);
 
       do_check_bootstrappedPref(run_test_19);
     });
   });
+  installAllFiles([do_get_addon("test_bootstrap1_2")], function() { });
 }
 
 // Check that uninstalling the profile version reveals the non-profile one
 function run_test_19() {
   resetPrefs();
   AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) {
     // The revealed add-on gets activated asynchronously
     prepare_test({
@@ -1169,16 +1178,17 @@ function run_test_23() {
 
 function check_test_23() {
   AddonManager.getAllInstalls(function(installs) {
     // There should be no active installs now since the install completed and
     // doesn't require a restart.
     do_check_eq(installs.length, 0);
 
     AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) {
+     do_execute_soon(function test_23_after_startup() {
       do_check_neq(b1, null);
       do_check_eq(b1.version, "1.0");
       do_check_false(b1.appDisabled);
       do_check_false(b1.userDisabled);
       do_check_true(b1.isActive);
       do_check_eq(getInstalledVersion(), 1);
       do_check_eq(getActiveVersion(), 1);
       do_check_eq(getStartupReason(), ADDON_INSTALL);
@@ -1197,69 +1207,74 @@ function check_test_23() {
         restartManager();
         AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) {
           b1.uninstall();
           restartManager();
 
           testserver.stop(run_test_24);
         });
       });
+     });
     });
   });
 }
 
 // Tests that we recover from a broken preference
 function run_test_24() {
   resetPrefs();
-  installAllFiles([do_get_addon("test_bootstrap1_1"), do_get_addon("test_bootstrap2_1")],
-                  function() {
-    waitForPref("bootstraptest2.active_version", function() {
-      do_check_eq(getInstalledVersion(), 1);
-      do_check_eq(getActiveVersion(), 1);
-      do_check_eq(getInstalledVersion2(), 1);
-      do_check_eq(getActiveVersion2(), 1);
+  do_print("starting 24");
+  waitForPref("bootstraptest2.active_version", function test_24_pref() {
+    do_print("test 24 got prefs");
+    do_check_eq(getInstalledVersion(), 1);
+    do_check_eq(getActiveVersion(), 1);
+    do_check_eq(getInstalledVersion2(), 1);
+    do_check_eq(getActiveVersion2(), 1);
 
-      resetPrefs();
+    resetPrefs();
 
-      restartManager();
+    restartManager();
 
-      do_check_eq(getInstalledVersion(), -1);
-      do_check_eq(getActiveVersion(), 1);
-      do_check_eq(getInstalledVersion2(), -1);
-      do_check_eq(getActiveVersion2(), 1);
+    do_check_eq(getInstalledVersion(), -1);
+    do_check_eq(getActiveVersion(), 1);
+    do_check_eq(getInstalledVersion2(), -1);
+    do_check_eq(getActiveVersion2(), 1);
 
-      shutdownManager();
+    shutdownManager();
 
-      do_check_eq(getInstalledVersion(), -1);
-      do_check_eq(getActiveVersion(), 0);
-      do_check_eq(getInstalledVersion2(), -1);
-      do_check_eq(getActiveVersion2(), 0);
+    do_check_eq(getInstalledVersion(), -1);
+    do_check_eq(getActiveVersion(), 0);
+    do_check_eq(getInstalledVersion2(), -1);
+    do_check_eq(getActiveVersion2(), 0);
 
-      // Break the preferece
-      let bootstrappedAddons = JSON.parse(Services.prefs.getCharPref("extensions.bootstrappedAddons"));
-      bootstrappedAddons["bootstrap1@tests.mozilla.org"].descriptor += "foo";
-      Services.prefs.setCharPref("extensions.bootstrappedAddons", JSON.stringify(bootstrappedAddons));
+    // Break the preferece
+    let bootstrappedAddons = JSON.parse(Services.prefs.getCharPref("extensions.bootstrappedAddons"));
+    bootstrappedAddons["bootstrap1@tests.mozilla.org"].descriptor += "foo";
+    Services.prefs.setCharPref("extensions.bootstrappedAddons", JSON.stringify(bootstrappedAddons));
+
+    startupManager(false);
 
-      startupManager(false);
+    do_check_eq(getInstalledVersion(), -1);
+    do_check_eq(getActiveVersion(), 1);
+    do_check_eq(getInstalledVersion2(), -1);
+    do_check_eq(getActiveVersion2(), 1);
 
-      do_check_eq(getInstalledVersion(), -1);
-      do_check_eq(getActiveVersion(), 1);
-      do_check_eq(getInstalledVersion2(), -1);
-      do_check_eq(getActiveVersion2(), 1);
+    run_test_25();
+  });
 
-      run_test_25();
-    });
+  installAllFiles([do_get_addon("test_bootstrap1_1"), do_get_addon("test_bootstrap2_1")],
+                  function test_24_installed() {
+    do_print("test 24 installed");
   });
 }
 
 // Tests that updating from a bootstrappable add-on to a normal add-on calls
 // the uninstall method
 function run_test_25() {
-  installAllFiles([do_get_addon("test_bootstrap1_1")], function() {
-    waitForPref("bootstraptest.active_version", function() {
+  waitForPref("bootstraptest.startup_reason", function test_25_after_pref() {
+      do_print("test 25 pref change detected");
       do_check_eq(getInstalledVersion(), 1);
       do_check_eq(getActiveVersion(), 1);
 
       installAllFiles([do_get_addon("test_bootstrap1_4")], function() {
         // Needs a restart to complete this so the old version stays running
         do_check_eq(getInstalledVersion(), 1);
         do_check_eq(getActiveVersion(), 1);
 
@@ -1281,17 +1296,19 @@ function run_test_25() {
             do_check_eq(b1.version, "4.0");
             do_check_true(b1.isActive);
             do_check_eq(b1.pendingOperations, AddonManager.PENDING_NONE);
 
             do_check_bootstrappedPref(run_test_26);
           });
         });
       });
-    });
+  });
+  installAllFiles([do_get_addon("test_bootstrap1_1")], function test_25_installed() {
+    do_print("test 25 install done");
   });
 }
 
 // Tests that updating from a normal add-on to a bootstrappable add-on calls
 // the install method
 function run_test_26() {
   installAllFiles([do_get_addon("test_bootstrap1_1")], function() {
     // Needs a restart to complete this
@@ -1362,42 +1379,46 @@ function run_test_27() {
           do_check_bootstrappedPref(run_test_28);
         });
       });
     });
   });
 }
 
 // Tests that updating from a normal add-on to a bootstrappable add-on when
-// disabled calls the install method
+// disabled calls the install method but not the startup method
 function run_test_28() {
   installAllFiles([do_get_addon("test_bootstrap1_1")], function() {
+   do_execute_soon(function bootstrap_disabled_downgrade_check() {
     // Doesn't need a restart to complete this
     do_check_eq(getInstalledVersion(), 1);
     do_check_eq(getInstallReason(), ADDON_DOWNGRADE);
     do_check_eq(getInstallOldVersion(), 4);
     do_check_eq(getActiveVersion(), 0);
 
     AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) {
       do_check_neq(b1, null);
       do_check_eq(b1.version, "1.0");
       do_check_false(b1.isActive);
+      do_check_true(b1.userDisabled);
       do_check_eq(b1.pendingOperations, AddonManager.PENDING_NONE);
 
       restartManager();
 
       do_check_eq(getInstalledVersion(), 1);
       do_check_eq(getActiveVersion(), 0);
 
       AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) {
         do_check_neq(b1, null);
+        do_check_true(b1.userDisabled);
         b1.userDisabled = false;
         do_check_eq(b1.version, "1.0");
         do_check_true(b1.isActive);
         do_check_eq(b1.pendingOperations, AddonManager.PENDING_NONE);
         do_check_eq(getInstalledVersion(), 1);
         do_check_eq(getActiveVersion(), 1);
 
         do_check_bootstrappedPref(do_test_finished);
       });
     });
+   });
   });
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug324121.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug324121.js
@@ -134,16 +134,17 @@ function run_test() {
   testserver.registerDirectory("/data/", dataDir);
   testserver.start(4444);
 
   startupManager();
 
   installAllFiles([do_get_addon(a.addon) for each (a in ADDONS)], function() {
     restartManager();
     AddonManager.getAddonByID(ADDONS[0].id, function(addon) {
+      do_check_true(!(!addon));
       addon.userDisabled = true;
       restartManager();
 
       AddonManager.getAddonsByTypes(["extension"], function(installedItems) {
         var items = [];
 
         for (let addon of ADDONS) {
           for (let installedItem of installedItems) {
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug335238.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug335238.js
@@ -161,16 +161,17 @@ function run_test() {
   Services.prefs.setBoolPref(PREF_MATCH_OS_LOCALE, false);
   Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "en-US");
 
   startupManager();
   installAllFiles([do_get_addon(a.addon) for each (a in ADDONS)], function() {
 
     restartManager();
     AddonManager.getAddonByID(ADDONS[1].id, function(addon) {
+      do_check_true(!(!addon));
       addon.userDisabled = true;
       restartManager();
 
       AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], function(installedItems) {
         installedItems.forEach(function(item) {
           updateListener.pendingCount++;
           item.findUpdates(updateListener, AddonManager.UPDATE_WHEN_USER_REQUESTED);
         });
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug449027.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug449027.js
@@ -363,17 +363,17 @@ function check_state(test, lastTest, cal
           if (gNewBlocks.indexOf(PLUGINS[i].name + " " + PLUGINS[i].version) < 0)
             do_throw("Plugin " + (i + 1) + " should have been listed in the blocklist notification for test " + test);
           expected++;
         }
       }
 
       do_check_eq(expected, gNewBlocks.length);
     }
-    callback();
+    do_execute_soon(callback);
   });
 }
 
 function load_blocklist(file) {
   Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:4444/data/" + file);
   var blocklist = Components.classes["@mozilla.org/extensions/blocklist;1"]
                             .getService(Ci.nsITimerCallback);
   blocklist.notify(null);
@@ -405,17 +405,17 @@ function check_test_pt1() {
   dump("Checking pt 1\n");
 
   AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], function(addons) {
     for (var i = 0; i < ADDONS.length; i++) {
       if (!addons[i])
         do_throw("Addon " + (i + 1) + " did not get installed correctly");
     }
 
-    check_state("start", null, run_test_pt2);
+    do_execute_soon(function checkstate1() {check_state("start", null, run_test_pt2);});
   });
 }
 
 /**
  * Load the toolkit based blocks
  */
 function run_test_pt2() {
   dump("Running test pt 2\n");
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug470377_3.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug470377_3.js
@@ -59,17 +59,17 @@ function run_test_1() {
     do_check_true(a2.isActive);
     do_check_neq(a3, null);
     do_check_true(a3.isActive);
     do_check_neq(a4, null);
     do_check_true(a4.isActive);
     do_check_neq(a5, null);
     do_check_true(a5.isActive);
 
-    run_test_2();
+    do_execute_soon(run_test_2);
   });
 }
 
 function run_test_2() {
   AddonManager.checkCompatibility = false;
 
   restartManager();
 
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug470377_3_strictcompat.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug470377_3_strictcompat.js
@@ -58,17 +58,17 @@ function run_test_1() {
     do_check_false(a2.isActive);
     do_check_neq(a3, null);
     do_check_false(a3.isActive);
     do_check_neq(a4, null);
     do_check_true(a4.isActive);
     do_check_neq(a5, null);
     do_check_true(a5.isActive);
 
-    run_test_2();
+    do_execute_soon(run_test_2);
   });
 }
 
 function run_test_2() {
   AddonManager.checkCompatibility = false;
 
   restartManager();
 
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug470377_4.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug470377_4.js
@@ -56,17 +56,17 @@ function run_test_1() {
     do_check_true(a2.isActive);
     do_check_neq(a3, null);
     do_check_true(a3.isActive);
     do_check_neq(a4, null);
     do_check_true(a4.isActive);
     do_check_neq(a5, null);
     do_check_true(a5.isActive);
 
-    run_test_2();
+    do_execute_soon(run_test_2);
   });
 }
 
 function run_test_2() {
   AddonManager.checkCompatibility = true;
 
   restartManager();
 
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug521905.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug521905.js
@@ -24,30 +24,30 @@ function run_test() {
 
   installAllFiles([do_get_addon(ADDON)], function() {
     restartManager();
 
     AddonManager.getAddonByID(ID, function(addon) {
       do_check_neq(addon, null);
       do_check_true(addon.isActive);
 
-      run_test_1();
+      do_execute_soon(run_test_1);
     });
   });
 }
 
 function run_test_1() {
   Services.prefs.setBoolPref("extensions.checkCompatibility.2.0pre", true);
 
   restartManager();
   AddonManager.getAddonByID(ID, function(addon) {
     do_check_neq(addon, null);
     do_check_false(addon.isActive);
 
-    run_test_2();
+    do_execute_soon(run_test_2);
   });
 }
 
 function run_test_2() {
   Services.prefs.setBoolPref("extensions.checkCompatibility.2.0p", false);
 
   restartManager();
   AddonManager.getAddonByID(ID, function(addon) {
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug542391.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug542391.js
@@ -316,28 +316,29 @@ function run_test() {
 
   dest.remove(true);
 
   installAllFiles([do_get_addon("test_bug542391_1"),
                    do_get_addon("test_bug542391_2"),
                    do_get_addon("test_bug542391_3_1"),
                    do_get_addon("test_bug542391_4"),
                    do_get_addon("test_bug542391_5"),
-                   do_get_addon("test_bug542391_6")], function() {
+                   do_get_addon("test_bug542391_6")], function install_and_restart() {
 
     restartManager();
     check_startup_changes("installed", []);
     check_startup_changes("updated", []);
     check_startup_changes("uninstalled", ["addon1@tests.mozilla.org"]);
     check_startup_changes("disabled", []);
     check_startup_changes("enabled", []);
 
     AddonManager.getAddonsByIDs(["bug542391_2@tests.mozilla.org",
                                  "bug542391_4@tests.mozilla.org"],
-                                 function([a2, a4]) {
+                                 function disable_and_restart([a2, a4]) {
+      do_check_true(a2 != null && a4 != null);
       a2.userDisabled = true;
       a4.userDisabled = true;
       restartManager();
       check_startup_changes("installed", []);
       check_startup_changes("updated", []);
       check_startup_changes("uninstalled", []);
       check_startup_changes("disabled", []);
       check_startup_changes("enabled", []);
@@ -364,17 +365,17 @@ function run_test() {
                                      "bug542391_2@tests.mozilla.org",
                                      "bug542391_3@tests.mozilla.org",
                                      "bug542391_4@tests.mozilla.org",
                                      "bug542391_5@tests.mozilla.org",
                                      "bug542391_6@tests.mozilla.org"],
                                      function(addons) {
           check_state_v2(addons);
 
-          run_test_1();
+          do_execute_soon(run_test_1);
         });
       });
     });
   });
 }
 
 function end_test() {
   testserver.stop(do_test_finished);
@@ -403,17 +404,17 @@ function run_test_1() {
                                function(addons) {
     check_state_v3(addons);
 
     do_check_eq(WindowWatcher.arguments.length, 3);
     do_check_true(WindowWatcher.arguments.indexOf("bug542391_1@tests.mozilla.org") >= 0);
     do_check_true(WindowWatcher.arguments.indexOf("bug542391_2@tests.mozilla.org") >= 0);
     do_check_true(WindowWatcher.arguments.indexOf("bug542391_4@tests.mozilla.org") >= 0);
 
-    run_test_2();
+    do_execute_soon(run_test_2);
   });
 }
 
 // Downgrade to version 2 which will remove appDisable from two add-ons and
 // should pass all 4 previously disabled add-ons.
 function run_test_2() {
   WindowWatcher.expected = true;
   restartManager("2");
@@ -434,17 +435,17 @@ function run_test_2() {
     check_state_v2(addons);
 
     do_check_eq(WindowWatcher.arguments.length, 4);
     do_check_true(WindowWatcher.arguments.indexOf("bug542391_1@tests.mozilla.org") >= 0);
     do_check_true(WindowWatcher.arguments.indexOf("bug542391_2@tests.mozilla.org") >= 0);
     do_check_true(WindowWatcher.arguments.indexOf("bug542391_3@tests.mozilla.org") >= 0);
     do_check_true(WindowWatcher.arguments.indexOf("bug542391_4@tests.mozilla.org") >= 0);
 
-    run_test_5();
+    do_execute_soon(run_test_5);
   });
 }
 
 // Upgrade to version 3 which will appDisable two more add-ons. Check that when
 // the upgrade dialog updates an add-on no restart is necessary
 function run_test_5() {
   Services.prefs.setBoolPref(PREF_EM_SHOW_MISMATCH_UI, true);
   gInstallUpdate = true;
@@ -468,17 +469,17 @@ function run_test_5() {
                                function(addons) {
     check_state_v3_2(addons);
 
     do_check_eq(WindowWatcher.arguments.length, 3);
     do_check_true(WindowWatcher.arguments.indexOf("bug542391_1@tests.mozilla.org") >= 0);
     do_check_true(WindowWatcher.arguments.indexOf("bug542391_2@tests.mozilla.org") >= 0);
     do_check_true(WindowWatcher.arguments.indexOf("bug542391_4@tests.mozilla.org") >= 0);
 
-    run_test_6();
+    do_execute_soon(run_test_6);
   });
 }
 
 // Downgrade to version 1 which will appEnable all the add-ons
 function run_test_6() {
   WindowWatcher.expected = true;
   restartManager("1");
   check_startup_changes("installed", []);
@@ -492,15 +493,11 @@ function run_test_6() {
                                "bug542391_2@tests.mozilla.org",
                                "bug542391_3@tests.mozilla.org",
                                "bug542391_4@tests.mozilla.org",
                                "bug542391_5@tests.mozilla.org",
                                "bug542391_6@tests.mozilla.org"],
                                function(addons) {
     check_state_v1_2(addons);
 
-    finish_test();
+    end_test();
   });
 }
-
-function finish_test() {
-  do_test_finished();
-}
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug559800.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug559800.js
@@ -1,15 +1,17 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // This verifies that deleting the database from the profile doesn't break
 // anything
 
+const EXTENSIONS_DB = "extensions.sqlite";
+
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
 
 function run_test() {
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
 
   writeInstallRDFForExtension({
     id: "addon1@tests.mozilla.org",
@@ -37,30 +39,30 @@ function end_test() {
 function run_test_1() {
   AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
     do_check_neq(a1, null);
     do_check_eq(a1.version, "1.0");
 
     shutdownManager();
 
     let db = gProfD.clone();
-    db.append("extensions.sqlite");
+    db.append(EXTENSIONS_DB);
     db.remove(true);
 
-    check_test_1();
+    do_execute_soon(check_test_1);
   });
 }
 
 function check_test_1() {
   startupManager(false);
 
   AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
     do_check_neq(a1, null);
     do_check_eq(a1.version, "1.0");
 
     let db = gProfD.clone();
-    db.append("extensions.sqlite");
+    db.append(EXTENSIONS_DB);
     do_check_true(db.exists());
     do_check_true(db.fileSize > 0);
 
     end_test();
   });
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug563256.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug563256.js
@@ -102,22 +102,22 @@ function run_test_1(d, a) {
   do_check_false(a.appDisabled);
   do_check_false(a.isActive);
   do_check_false(isThemeInAddonsList(profileDir, a.id));
   do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_DISABLE));
   do_check_true(hasFlag(a.permissions, AddonManager.PERM_CAN_ENABLE));
 
   do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "classic/1.0");
 
-  restartManager();
-  run_test_2();
+  do_execute_soon(run_test_2);
 }
 
 // Tests that after the restart themes can be changed as expected
 function run_test_2() {
+  restartManager();
   AddonManager.getAddonsByIDs(["default@tests.mozilla.org",
                                "alternate@tests.mozilla.org"], function([d, a]) {
     do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "classic/1.0");
 
     do_check_neq(d, null);
     do_check_false(d.userDisabled);
     do_check_false(d.appDisabled);
     do_check_true(d.isActive);
@@ -184,22 +184,22 @@ function run_test_2() {
     do_check_false(a.appDisabled);
     do_check_false(a.isActive);
     do_check_false(isThemeInAddonsList(profileDir, a.id));
     do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_DISABLE));
     do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_ENABLE));
 
     do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "classic/1.0");
 
-    restartManager();
-    check_test_2();
+    do_execute_soon(check_test_2);
   });
 }
 
 function check_test_2() {
+  restartManager();
   AddonManager.getAddonsByIDs(["default@tests.mozilla.org",
                                "alternate@tests.mozilla.org"], function([d, a]) {
     do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "alternate/1.0");
 
     do_check_true(d.userDisabled);
     do_check_false(d.appDisabled);
     do_check_false(d.isActive);
     do_check_false(isThemeInAddonsList(profileDir, d.id));
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug587088.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug587088.js
@@ -107,29 +107,29 @@ function run_test_1() {
             fstream.close();
 
             restartManager();
 
             AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
               check_addon(a1, "2.0");
 
               a1.uninstall();
-              restartManager();
-
-              run_test_2();
+              do_execute_soon(run_test_2);
             });
           });
         });
       });
     });
   });
 }
 
 // Test that a failed uninstall gets rolled back
 function run_test_2() {
+  restartManager();
+
   installAllFiles([do_get_addon("test_bug587088_1")], function() {
     restartManager();
 
     AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
       check_addon(a1, "1.0");
 
       // Lock either install.rdf for unpacked add-ons or the xpi for packed add-ons.
       let uri = a1.getResourceURI("install.rdf");
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug595573.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug595573.js
@@ -18,17 +18,17 @@ function run_test() {
 function run_test_1() {
   installAllFiles([do_get_addon("test_bug595573")], function() {
     restartManager();
 
     AddonManager.getAddonByID("{2f69dacd-03df-4150-a9f1-e8a7b2748829}", function(a1) {
       do_check_neq(a1, null);
       do_check_true(isExtensionInAddonsList(profileDir, a1.id));
 
-      run_test_2();
+      do_execute_soon(run_test_2);
     });
   });
 }
 
 function run_test_2() {
   restartManager();
 
   AddonManager.getAddonByID("{2f69dacd-03df-4150-a9f1-e8a7b2748829}", function(a1) {
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug596607.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug596607.js
@@ -72,24 +72,24 @@ function run_test_1() {
 
     do_check_neq(a2, null);
     do_check_true(a2.isActive);
     do_check_false(hasFlag(a2.permissions, AddonManager.PERM_CAN_UNINSTALL));
     do_check_eq(a2.scope, AddonManager.SCOPE_USER);
 
     do_check_eq(a3, null);
 
-    shutdownManager();
-
-    run_test_2();
+    do_execute_soon(run_test_2);
   });
 }
 
 // Tests whether removing the bad entry has any effect
 function run_test_2() {
+  shutdownManager();
+
   MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
                         "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
                         "addon3@tests.mozilla.org", addon3Dir.path);
 
   startupManager(false);
 
   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                "addon2@tests.mozilla.org",
@@ -101,24 +101,24 @@ function run_test_2() {
 
     do_check_neq(a2, null);
     do_check_true(a2.isActive);
     do_check_false(hasFlag(a2.permissions, AddonManager.PERM_CAN_UNINSTALL));
     do_check_eq(a2.scope, AddonManager.SCOPE_USER);
 
     do_check_eq(a3, null);
 
-    shutdownManager();
-
-    run_test_3();
+    do_execute_soon(run_test_3);
   });
 }
 
 // Tests adding the bad entry to an existing profile has any effect
 function run_test_3() {
+  shutdownManager();
+
   MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
                         "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
                         "addon3@tests.mozilla.org", null);
 
   startupManager(false);
 
   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                "addon2@tests.mozilla.org",
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug659772.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug659772.js
@@ -180,36 +180,36 @@ function run_test_1() {
 
         do_check_neq(a4, null);
         do_check_eq(a4.version, "2.0");
         do_check_true(a4.appDisabled);
         do_check_false(a4.userDisabled);
         do_check_false(a4.isActive);
         do_check_false(isExtensionInAddonsList(profileDir, addon4.id));
 
-        // Check that install and uninstall haven't been called on the bootstrapped adddon
+        // Check that install and uninstall haven't been called on the bootstrapped addon
         do_check_false(Services.prefs.prefHasUserValue("bootstraptest.install_reason"));
         do_check_false(Services.prefs.prefHasUserValue("bootstraptest.uninstall_reason"));
 
         a1.uninstall();
         a2.uninstall();
         a3.uninstall();
         a4.uninstall();
-        restartManager();
-
-        shutdownManager();
-
-        run_test_2();
+        do_execute_soon(run_test_2);
       });
     });
   });
 }
 
 // Tests whether a schema migration with app version change works
 function run_test_2() {
+  restartManager();
+
+  shutdownManager();
+
   writeInstallRDFForExtension(addon1, profileDir);
   writeInstallRDFForExtension(addon2, profileDir);
   writeInstallRDFForExtension(addon3, profileDir);
   writeInstallRDFForExtension(addon4, profileDir);
 
   startupManager();
 
   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
@@ -244,17 +244,19 @@ function run_test_2() {
     do_check_false(a4.userDisabled);
     do_check_false(a4.isActive);
     do_check_false(isExtensionInAddonsList(profileDir, addon4.id));
 
     // Prepare the add-on update, and a bootstrapped addon (bug 693714)
     installAllFiles([
       do_get_addon("test_bug659772"),
       do_get_addon("test_bootstrap1_1")
-    ], function() {
+    ], function() { do_execute_soon(prepare_schema_migrate); });
+
+    function prepare_schema_migrate() {
       shutdownManager();
 
       // Make it look like the next time the app is started it has a new DB schema
       let dbfile = gProfD.clone();
       dbfile.append("extensions.sqlite");
       let db = AM_Cc["@mozilla.org/storage/service;1"].
                getService(AM_Ci.mozIStorageService).
                openDatabase(dbfile);
@@ -326,25 +328,25 @@ function run_test_2() {
 
         do_check_neq(a4, null);
         do_check_eq(a4.version, "2.0");
         do_check_false(a4.appDisabled);
         do_check_false(a4.userDisabled);
         do_check_true(a4.isActive);
         do_check_true(isExtensionInAddonsList(profileDir, addon4.id));
 
-        // Check that install and uninstall haven't been called on the bootstrapped adddon
+        // Check that install and uninstall haven't been called on the bootstrapped addon
         do_check_false(Services.prefs.prefHasUserValue("bootstraptest.install_reason"));
         do_check_false(Services.prefs.prefHasUserValue("bootstraptest.uninstall_reason"));
 
         a1.uninstall();
         a2.uninstall();
         a3.uninstall();
         a4.uninstall();
         restartManager();
 
         shutdownManager();
 
         do_test_finished();
       });
-    });
+    };
   });
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug675371.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug675371.js
@@ -19,23 +19,25 @@ function run_test() {
     prepare_test({
       "bug675371@tests.mozilla.org": [
         ["onInstalling", false],
         "onInstalled"
       ]
     }, [
       "onInstallStarted",
       "onInstallEnded",
-    ], check_test);
+    ], function() {
+      do_execute_soon(check_test)
+    });
     install.install();
   });
 }
 
 function check_test() {
-  AddonManager.getAddonByID("bug675371@tests.mozilla.org", function(addon) {
+  AddonManager.getAddonByID("bug675371@tests.mozilla.org", do_exception_wrap(function(addon) {
     do_check_neq(addon, null);
     do_check_true(addon.isActive);
 
     // Tests that chrome.manifest is registered when the addon is installed.
     var target = { active: false };
     Services.scriptloader.loadSubScript("chrome://bug675371/content/test.js", target);
     do_check_true(target.active);
 
@@ -82,10 +84,10 @@ function check_test() {
     try {
       Services.scriptloader.loadSubScript("chrome://bug675371/content/test.js", target);
       do_throw("Chrome file should not have been found");
     } catch (e) {
       do_check_false(target.active);
     }
 
     do_test_finished();
-  });
+  }));
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_cacheflush.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_cacheflush.js
@@ -66,42 +66,43 @@ function run_test_2() {
     gCacheFlushed = false;
 
     AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
       // We should flush the installed XPI when uninstalling
       gExpectedFile = gProfD.clone();
       gExpectedFile.append("extensions");
       gExpectedFile.append("addon1@tests.mozilla.org.xpi");
 
+      do_check_true(a1 != null);
       a1.uninstall();
       do_check_false(gCacheFlushed);
-      restartManager();
-
-      run_test_3();
+      do_execute_soon(run_test_3);
     });
   });
 }
 
 // Tests that the cache is flushed when installing a restartless add-on
 function run_test_3() {
+  restartManager();
+
   AddonManager.getInstallForFile(do_get_addon("test_cacheflush2"), function(aInstall) {
     aInstall.addListener({
       onInstallStarted: function(aInstall) {
         // We should flush the staged XPI when completing the install
         gExpectedFile = gProfD.clone();
         gExpectedFile.append("extensions");
         gExpectedFile.append("staged");
         gExpectedFile.append("addon2@tests.mozilla.org.xpi");
       },
 
       onInstallEnded: function(aInstall) {
         do_check_true(gCacheFlushed);
         gCacheFlushed = false;
 
-        run_test_4();
+        do_execute_soon(run_test_4);
       }
     });
 
     aInstall.install();
   });
 }
 
 // Tests that the cache is flushed when uninstalling a restartless add-on
--- a/toolkit/mozapps/extensions/test/xpcshell/test_checkcompatibility.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_checkcompatibility.js
@@ -57,17 +57,17 @@ var ADDONS = [{
 }];
 
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
 
 var gIsNightly = false;
 
 function run_test() {
-  do_test_pending();
+  do_test_pending("checkcompatibility.js");
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2.2.3", "2");
 
   ADDONS.forEach(function(a) {
     writeInstallRDFForExtension(a, profileDir);
   });
 
   gIsNightly = isNightlyChannel();
 
@@ -125,17 +125,17 @@ function run_test_1() {
   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                "addon2@tests.mozilla.org",
                                "addon3@tests.mozilla.org",
                                "addon4@tests.mozilla.org",
                                "addon5@tests.mozilla.org"],
                                function([a1, a2, a3, a4, a5]) {
     check_state(false, a1, a2, a3, a4, a5);
 
-    run_test_2();
+    do_execute_soon(run_test_2);
   });
 }
 
 // Tests that with compatibility checking disabled we see the incompatible
 // add-ons enabled
 function run_test_2() {
   if (gIsNightly)
     Services.prefs.setBoolPref("extensions.checkCompatibility.nightly", false);
@@ -146,17 +146,17 @@ function run_test_2() {
   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                "addon2@tests.mozilla.org",
                                "addon3@tests.mozilla.org",
                                "addon4@tests.mozilla.org",
                                "addon5@tests.mozilla.org"],
                                function([a1, a2, a3, a4, a5]) {
     check_state(true, a1, a2, a3, a4, a5);
 
-    run_test_3();
+    do_execute_soon(run_test_3);
   });
 }
 
 // Tests that with compatibility checking disabled we see the incompatible
 // add-ons enabled.
 function run_test_3() {
   if (!gIsNightly)
     Services.prefs.setBoolPref("extensions.checkCompatibility.2.1a", false);
@@ -165,17 +165,17 @@ function run_test_3() {
   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                "addon2@tests.mozilla.org",
                                "addon3@tests.mozilla.org",
                                "addon4@tests.mozilla.org",
                                "addon5@tests.mozilla.org"],
                                function([a1, a2, a3, a4, a5]) {
     check_state(true, a1, a2, a3, a4, a5);
 
-    run_test_4();
+    do_execute_soon(run_test_4);
   });
 }
 
 // Tests that with compatibility checking enabled we see the incompatible
 // add-ons disabled.
 function run_test_4() {
   if (gIsNightly)
     Services.prefs.setBoolPref("extensions.checkCompatibility.nightly", true);
@@ -186,11 +186,11 @@ function run_test_4() {
   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                "addon2@tests.mozilla.org",
                                "addon3@tests.mozilla.org",
                                "addon4@tests.mozilla.org",
                                "addon5@tests.mozilla.org"],
                                function([a1, a2, a3, a4, a5]) {
     check_state(false, a1, a2, a3, a4, a5);
 
-    do_test_finished();
+    do_test_finished("checkcompatibility.js");
   });
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_compatoverrides.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_compatoverrides.js
@@ -53,17 +53,17 @@ var addon3 = {
   name: "Test addon 3",
   targetApplications: [{
     id: "xpcshell@tests.mozilla.org",
     minVersion: "1",
     maxVersion: "1"
   }]
 };
 
-// Hosted, matching override, wouldn't be compatible if strict chekcing is enabled
+// Hosted, matching override, wouldn't be compatible if strict checking is enabled
 var addon4 = {
   id: "addon4@tests.mozilla.org",
   version: "1.0",
   name: "Test addon 4",
   targetApplications: [{
     id: "xpcshell@tests.mozilla.org",
     minVersion: "0.1",
     maxVersion: "0.2"
@@ -152,17 +152,17 @@ profileDir.append("extensions");
  *
  * @param  aCallback
  *         Callback to call once the background update is complete
  */
 function trigger_background_update(aCallback) {
   Services.obs.addObserver({
     observe: function(aSubject, aTopic, aData) {
       Services.obs.removeObserver(this, "addons-background-update-complete");
-      aCallback();
+      do_execute_soon(aCallback);
     }
   }, "addons-background-update-complete", false);
 
   gInternalManager.notify(null);
 }
 
 function run_test() {
   do_test_pending();
@@ -256,20 +256,22 @@ function check_compat_status(aCallback) 
     do_check_false(a9.isCompatible);
     do_check_true(a9.appDisabled);
 
     do_check_neq(a10, null);
     do_check_eq(a10.compatibilityOverrides, null);
     do_check_true(a10.isCompatible);
     do_check_false(a10.appDisabled);
 
-    aCallback();
+    do_execute_soon(aCallback);
   });
 }
 
 function run_test_1() {
+  do_print("Run test 1");
   check_compat_status(run_test_2);
 }
 
 function run_test_2() {
+  do_print("Run test 2");
   restartManager();
   check_compat_status(end_test);  
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_corrupt.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_corrupt.js
@@ -162,42 +162,41 @@ function run_test() {
     a2.userDisabled = true;
     a4.userDisabled = true;
     a7.userDisabled = true;
     t2.userDisabled = false;
     a3.findUpdates({
       onUpdateFinished: function() {
         a4.findUpdates({
           onUpdateFinished: function() {
-            restartManager();
-
-            run_test_1();
+            do_execute_soon(run_test_1);
           }
         }, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
       }
     }, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
   });
 }
 
 function end_test() {
   testserver.stop(do_test_finished);
 }
 
 function run_test_1() {
+  restartManager();
+
   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                "addon2@tests.mozilla.org",
                                "addon3@tests.mozilla.org",
                                "addon4@tests.mozilla.org",
                                "addon5@tests.mozilla.org",
                                "addon6@tests.mozilla.org",
                                "addon7@tests.mozilla.org",
                                "theme1@tests.mozilla.org",
-                               "theme2@tests.mozilla.org"], function([a1, a2, a3,
-                                                                      a4, a5, a6,
-                                                                      a7, t1, t2]) {
+                               "theme2@tests.mozilla.org"],
+                               callback_soon(function([a1, a2, a3, a4, a5, a6, a7, t1, t2]) {
     do_check_neq(a1, null);
     do_check_true(a1.isActive);
     do_check_false(a1.userDisabled);
     do_check_false(a1.appDisabled);
     do_check_eq(a1.pendingOperations, AddonManager.PENDING_NONE);
 
     do_check_neq(a2, null);
     do_check_false(a2.isActive);
@@ -261,19 +260,18 @@ function run_test_1() {
     AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                  "addon2@tests.mozilla.org",
                                  "addon3@tests.mozilla.org",
                                  "addon4@tests.mozilla.org",
                                  "addon5@tests.mozilla.org",
                                  "addon6@tests.mozilla.org",
                                  "addon7@tests.mozilla.org",
                                  "theme1@tests.mozilla.org",
-                                 "theme2@tests.mozilla.org"], function([a1, a2, a3,
-                                                                        a4, a5, a6,
-                                                                        a7, t1, t2]) {
+                                 "theme2@tests.mozilla.org"],
+                                 callback_soon(function([a1, a2, a3, a4, a5, a6, a7, t1, t2]) {
       // Should be correctly recovered
       do_check_neq(a1, null);
       do_check_true(a1.isActive);
       do_check_false(a1.userDisabled);
       do_check_false(a1.appDisabled);
       do_check_eq(a1.pendingOperations, AddonManager.PENDING_NONE);
 
       // Should be correctly recovered
@@ -338,19 +336,18 @@ function run_test_1() {
       AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                    "addon2@tests.mozilla.org",
                                    "addon3@tests.mozilla.org",
                                    "addon4@tests.mozilla.org",
                                    "addon5@tests.mozilla.org",
                                    "addon6@tests.mozilla.org",
                                    "addon7@tests.mozilla.org",
                                    "theme1@tests.mozilla.org",
-                                   "theme2@tests.mozilla.org"], function([a1, a2, a3,
-                                                                          a4, a5, a6,
-                                                                          a7, t1, t2]) {
+                                   "theme2@tests.mozilla.org"],
+                                   callback_soon(function([a1, a2, a3, a4, a5, a6, a7, t1, t2]) {
         do_check_neq(a1, null);
         do_check_true(a1.isActive);
         do_check_false(a1.userDisabled);
         do_check_false(a1.appDisabled);
         do_check_eq(a1.pendingOperations, AddonManager.PENDING_NONE);
 
         do_check_neq(a2, null);
         do_check_false(a2.isActive);
@@ -396,12 +393,12 @@ function run_test_1() {
 
         do_check_neq(t2, null);
         do_check_true(t2.isActive);
         do_check_false(t2.userDisabled);
         do_check_false(t2.appDisabled);
         do_check_eq(t2.pendingOperations, AddonManager.PENDING_NONE);
 
         end_test();
-      });
-    });
-  });
+      }));
+    }));
+  }));
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_corrupt_strictcompat.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_corrupt_strictcompat.js
@@ -162,42 +162,41 @@ function run_test() {
     a2.userDisabled = true;
     a4.userDisabled = true;
     a7.userDisabled = true;
     t2.userDisabled = false;
     a3.findUpdates({
       onUpdateFinished: function() {
         a4.findUpdates({
           onUpdateFinished: function() {
-            restartManager();
-
-            run_test_1();
+            do_execute_soon(run_test_1);
           }
         }, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
       }
     }, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
   });
 }
 
 function end_test() {
   testserver.stop(do_test_finished);
 }
 
 function run_test_1() {
+  restartManager();
+
   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                "addon2@tests.mozilla.org",
                                "addon3@tests.mozilla.org",
                                "addon4@tests.mozilla.org",
                                "addon5@tests.mozilla.org",
                                "addon6@tests.mozilla.org",
                                "addon7@tests.mozilla.org",
                                "theme1@tests.mozilla.org",
-                               "theme2@tests.mozilla.org"], function([a1, a2, a3,
-                                                                      a4, a5, a6,
-                                                                      a7, t1, t2]) {
+                               "theme2@tests.mozilla.org"],
+                               callback_soon(function([a1, a2, a3, a4, a5, a6, a7, t1, t2]) {
     do_check_neq(a1, null);
     do_check_true(a1.isActive);
     do_check_false(a1.userDisabled);
     do_check_false(a1.appDisabled);
     do_check_eq(a1.pendingOperations, AddonManager.PENDING_NONE);
 
     do_check_neq(a2, null);
     do_check_false(a2.isActive);
@@ -261,19 +260,18 @@ function run_test_1() {
     AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                  "addon2@tests.mozilla.org",
                                  "addon3@tests.mozilla.org",
                                  "addon4@tests.mozilla.org",
                                  "addon5@tests.mozilla.org",
                                  "addon6@tests.mozilla.org",
                                  "addon7@tests.mozilla.org",
                                  "theme1@tests.mozilla.org",
-                                 "theme2@tests.mozilla.org"], function([a1, a2, a3,
-                                                                        a4, a5, a6,
-                                                                        a7, t1, t2]) {
+                                 "theme2@tests.mozilla.org"],
+                                 callback_soon(function([a1, a2, a3, a4, a5, a6, a7, t1, t2]) {
       // Should be correctly recovered
       do_check_neq(a1, null);
       do_check_true(a1.isActive);
       do_check_false(a1.userDisabled);
       do_check_false(a1.appDisabled);
       do_check_eq(a1.pendingOperations, AddonManager.PENDING_NONE);
 
       // Should be correctly recovered
@@ -336,19 +334,18 @@ function run_test_1() {
       AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                    "addon2@tests.mozilla.org",
                                    "addon3@tests.mozilla.org",
                                    "addon4@tests.mozilla.org",
                                    "addon5@tests.mozilla.org",
                                    "addon6@tests.mozilla.org",
                                    "addon7@tests.mozilla.org",
                                    "theme1@tests.mozilla.org",
-                                   "theme2@tests.mozilla.org"], function([a1, a2, a3,
-                                                                          a4, a5, a6,
-                                                                          a7, t1, t2]) {
+                                   "theme2@tests.mozilla.org"],
+                                   callback_soon(function([a1, a2, a3, a4, a5, a6, a7, t1, t2]) {
         do_check_neq(a1, null);
         do_check_true(a1.isActive);
         do_check_false(a1.userDisabled);
         do_check_false(a1.appDisabled);
         do_check_eq(a1.pendingOperations, AddonManager.PENDING_NONE);
 
         do_check_neq(a2, null);
         do_check_false(a2.isActive);
@@ -394,12 +391,12 @@ function run_test_1() {
 
         do_check_neq(t2, null);
         do_check_true(t2.isActive);
         do_check_false(t2.userDisabled);
         do_check_false(t2.appDisabled);
         do_check_eq(t2.pendingOperations, AddonManager.PENDING_NONE);
 
         end_test();
-      });
-    });
-  });
+      }));
+    }));
+  }));
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_dictionary.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_dictionary.js
@@ -208,17 +208,17 @@ function run_test_2() {
 
     AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(newb1) {
       do_check_neq(newb1, null);
       do_check_eq(newb1.version, "1.0");
       do_check_false(newb1.appDisabled);
       do_check_true(newb1.userDisabled);
       do_check_false(newb1.isActive);
 
-      run_test_3();
+      do_execute_soon(run_test_3);
     });
   });
 }
 
 // Test that restarting doesn't accidentally re-enable
 function run_test_3() {
   shutdownManager();
   do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
@@ -262,17 +262,17 @@ function run_test_4() {
 
     AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(newb1) {
       do_check_neq(newb1, null);
       do_check_eq(newb1.version, "1.0");
       do_check_false(newb1.appDisabled);
       do_check_false(newb1.userDisabled);
       do_check_true(newb1.isActive);
 
-      run_test_5();
+      do_execute_soon(run_test_5);
     });
   });
 }
 
 // Tests that a restart shuts down and restarts the add-on
 function run_test_5() {
   shutdownManager();
   do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
@@ -319,17 +319,17 @@ function check_test_7() {
   AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
     do_check_eq(b1, null);
 
     restartManager();
 
     AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(newb1) {
       do_check_eq(newb1, null);
 
-      run_test_8();
+      do_execute_soon(run_test_8);
     });
   });
 }
 
 // Test that a bootstrapped extension dropped into the profile loads properly
 // on startup and doesn't cause an EM restart
 function run_test_8() {
   shutdownManager();
@@ -355,34 +355,34 @@ function run_test_8() {
     do_check_neq(b1, null);
     do_check_eq(b1.version, "1.0");
     do_check_false(b1.appDisabled);
     do_check_false(b1.userDisabled);
     do_check_true(b1.isActive);
     do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
     do_check_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0");
 
-    run_test_9();
+    do_execute_soon(run_test_9);
   });
 }
 
 // Test that items detected as removed during startup get removed properly
 function run_test_9() {
   shutdownManager();
 
   let dir = profileDir.clone();
   dir.append("ab-CD@dictionaries.addons.mozilla.org");
   dir.remove(true);
   startupManager(false);
 
   AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
     do_check_eq(b1, null);
     do_check_not_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0");
 
-    run_test_12();
+    do_execute_soon(run_test_12);
   });
 }
 
 
 // Tests that bootstrapped extensions are correctly loaded even if the app is
 // upgraded at the same time
 function run_test_12() {
   shutdownManager();
@@ -409,26 +409,28 @@ function run_test_12() {
     do_check_eq(b1.version, "1.0");
     do_check_false(b1.appDisabled);
     do_check_false(b1.userDisabled);
     do_check_true(b1.isActive);
     do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
     do_check_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0");
 
     b1.uninstall();
-    restartManager();
-
-    run_test_16();
+    do_execute_soon(run_test_16);
   });
 }
 
 
 // Tests that bootstrapped extensions don't get loaded when in safe mode
 function run_test_16() {
+  restartManager();
+
   installAllFiles([do_get_addon("test_dictionary")], function() {
+    // spin the event loop to let the addon finish starting
+   do_execute_soon(function check_installed_dictionary() {
     AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
       // Should have installed and started
       do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
 
       shutdownManager();
 
       // Should have stopped
       do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
@@ -446,20 +448,21 @@ function run_test_16() {
         startupManager(false);
 
         // Should have started
         do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
 
         AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
           b1.uninstall();
 
-          run_test_17();
+          do_execute_soon(run_test_17);
         });
       });
     });
+   });
   });
 }
 
 // Check that a bootstrapped extension in a non-profile location is loaded
 function run_test_17() {
   shutdownManager();
 
   let dir = userExtDir.clone();
@@ -529,17 +532,18 @@ function run_test_23() {
           ["onInstalling", false],
           "onInstalled"
         ]
       }, [
         "onInstallStarted",
         "onInstallEnded",
       ], function() {
         do_check_true(addon.hasResource("install.rdf"));
-        check_test_23();
+        // spin to let the addon startup finish
+        do_execute_soon(check_test_23);
       });
     });
     install.install();
   }, "application/x-xpinstall");
 }
 
 function check_test_23() {
   AddonManager.getAllInstalls(function(installs) {
@@ -561,66 +565,66 @@ function check_test_23() {
       let dir = do_get_addon_root_uri(profileDir, "ab-CD@dictionaries.addons.mozilla.org");
 
       AddonManager.getAddonsWithOperationsByTypes(null, function(list) {
         do_check_eq(list.length, 0);
 
         restartManager();
         AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
           b1.uninstall();
-          restartManager();
-
-          run_test_25();
+          do_execute_soon(run_test_25);
         });
       });
     });
   });
 }
 
 // Tests that updating from a bootstrappable add-on to a normal add-on calls
 // the uninstall method
 function run_test_25() {
-  installAllFiles([do_get_addon("test_dictionary")], function() {
-    HunspellEngine.listener = function(aEvent) {
-      HunspellEngine.listener = null;
-      do_check_eq(aEvent, "addDirectory");
+  restartManager();
+
+  HunspellEngine.listener = function(aEvent) {
+    HunspellEngine.listener = null;
+    do_check_eq(aEvent, "addDirectory");
+    do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
+
+    installAllFiles([do_get_addon("test_dictionary_2")], function test_25_installed2() {
+      // Needs a restart to complete this so the old version stays running
       do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
-  
-      installAllFiles([do_get_addon("test_dictionary_2")], function() {
-        // Needs a restart to complete this so the old version stays running
-        do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
-  
+
+      AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
+        do_check_neq(b1, null);
+        do_check_eq(b1.version, "1.0");
+        do_check_true(b1.isActive);
+        do_check_true(hasFlag(b1.pendingOperations, AddonManager.PENDING_UPGRADE));
+
+        restartManager();
+
+        do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
+
         AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
           do_check_neq(b1, null);
-          do_check_eq(b1.version, "1.0");
+          do_check_eq(b1.version, "2.0");
           do_check_true(b1.isActive);
-          do_check_true(hasFlag(b1.pendingOperations, AddonManager.PENDING_UPGRADE));
-  
-          restartManager();
-  
-          do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
-  
-          AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
-            do_check_neq(b1, null);
-            do_check_eq(b1.version, "2.0");
-            do_check_true(b1.isActive);
-            do_check_eq(b1.pendingOperations, AddonManager.PENDING_NONE);
-  
-            run_test_26();
-          });
+          do_check_eq(b1.pendingOperations, AddonManager.PENDING_NONE);
+
+          do_execute_soon(run_test_26);
         });
       });
-    };
-  });
+    });
+  };
+
+  installAllFiles([do_get_addon("test_dictionary")], function test_25_installed() { });
 }
 
 // Tests that updating from a normal add-on to a bootstrappable add-on calls
 // the install method
 function run_test_26() {
-  installAllFiles([do_get_addon("test_dictionary")], function() {
+  installAllFiles([do_get_addon("test_dictionary")], function test_26_install() {
     // Needs a restart to complete this
     do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
 
     AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
       do_check_neq(b1, null);
       do_check_eq(b1.version, "2.0");
       do_check_true(b1.isActive);
       do_check_true(hasFlag(b1.pendingOperations, AddonManager.PENDING_UPGRADE));
@@ -632,25 +636,25 @@ function run_test_26() {
       AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
         do_check_neq(b1, null);
         do_check_eq(b1.version, "1.0");
         do_check_true(b1.isActive);
         do_check_eq(b1.pendingOperations, AddonManager.PENDING_NONE);
 
         HunspellEngine.deactivate();
         b1.uninstall();
-        restartManager();
-        run_test_27();
+        do_execute_soon(run_test_27);
       });
     });
   });
 }
 
 // Tests that an update check from a normal add-on to a bootstrappable add-on works
 function run_test_27() {
+  restartManager();
   writeInstallRDFForExtension({
     id: "ab-CD@dictionaries.addons.mozilla.org",
     version: "1.0",
     updateURL: "http://localhost:4444/data/test_dictionary.rdf",
     targetApplications: [{
       id: "xpcshell@tests.mozilla.org",
       minVersion: "1",
       maxVersion: "1"
@@ -678,24 +682,24 @@ function check_test_27(install) {
   do_check_eq(install.existingAddon.pendingUpgrade.install, install);
 
   restartManager();
   AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
     do_check_neq(b1, null);
     do_check_eq(b1.version, "2.0");
     do_check_eq(b1.type, "dictionary");
     b1.uninstall();
-    restartManager();
-
-    run_test_28();
+    do_execute_soon(run_test_28);
   });
 }
 
 // Tests that an update check from a bootstrappable add-on to a normal add-on works
 function run_test_28() {
+  restartManager();
+
   writeInstallRDFForExtension({
     id: "ef@dictionaries.addons.mozilla.org",
     version: "1.0",
     type: "64",
     updateURL: "http://localhost:4444/data/test_dictionary.rdf",
     targetApplications: [{
       id: "xpcshell@tests.mozilla.org",
       minVersion: "1",
@@ -724,24 +728,24 @@ function check_test_28(install) {
   do_check_eq(install.existingAddon.pendingUpgrade.install, install);
 
   restartManager();
   AddonManager.getAddonByID("ef@dictionaries.addons.mozilla.org", function(b2) {
     do_check_neq(b2, null);
     do_check_eq(b2.version, "2.0");
     do_check_eq(b2.type, "extension");
     b2.uninstall();
-    restartManager();
-
-    run_test_29();
+    do_execute_soon(run_test_29);
   });
 }
 
 // Tests that an update check from a bootstrappable add-on to a bootstrappable add-on works
 function run_test_29() {
+  restartManager();
+
   writeInstallRDFForExtension({
     id: "gh@dictionaries.addons.mozilla.org",
     version: "1.0",
     type: "64",
     updateURL: "http://localhost:4444/data/test_dictionary.rdf",
     targetApplications: [{
       id: "xpcshell@tests.mozilla.org",
       minVersion: "1",
--- a/toolkit/mozapps/extensions/test/xpcshell/test_disable.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_disable.js
@@ -148,17 +148,17 @@ function run_test_2() {
         do_check_in_crash_annotation(addon1.id, addon1.version);
 
         run_test_3();
       });
     });
   });
 }
 
-// Disabling then enabling withut restart should fire onOperationCancelled.
+// Disabling then enabling without restart should fire onOperationCancelled.
 function run_test_3() {
   prepare_test({
     "addon1@tests.mozilla.org": [
       "onDisabling"
     ]
   });
 
   AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
--- a/toolkit/mozapps/extensions/test/xpcshell/test_distribution.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_distribution.js
@@ -86,17 +86,17 @@ function run_test_1() {
 
   AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
     do_check_neq(a1, null);
     do_check_eq(a1.version, "1.0");
     do_check_true(a1.isActive);
     do_check_eq(a1.scope, AddonManager.SCOPE_PROFILE);
     do_check_false(a1.foreignInstall);
 
-    run_test_2();
+    do_execute_soon(run_test_2);
   });
 }
 
 // Tests that starting with a newer version in the distribution dir doesn't
 // install it yet
 function run_test_2() {
   setOldModificationTime();
 
@@ -105,32 +105,32 @@ function run_test_2() {
   restartManager();
 
   AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
     do_check_neq(a1, null);
     do_check_eq(a1.version, "1.0");
     do_check_true(a1.isActive);
     do_check_eq(a1.scope, AddonManager.SCOPE_PROFILE);
 
-    run_test_3();
+    do_execute_soon(run_test_3);
   });
 }
 
 // Test that an app upgrade installs the newer version
 function run_test_3() {
   restartManager("2");
 
   AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
     do_check_neq(a1, null);
     do_check_eq(a1.version, "2.0");
     do_check_true(a1.isActive);
     do_check_eq(a1.scope, AddonManager.SCOPE_PROFILE);
     do_check_false(a1.foreignInstall);
 
-    run_test_4();
+    do_execute_soon(run_test_4);
   });
 }
 
 // Test that an app upgrade doesn't downgrade the extension
 function run_test_4() {
   setOldModificationTime();
 
   writeInstallRDFForExtension(addon1_1, distroDir);
@@ -138,44 +138,44 @@ function run_test_4() {
   restartManager("3");
 
   AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
     do_check_neq(a1, null);
     do_check_eq(a1.version, "2.0");
     do_check_true(a1.isActive);
     do_check_eq(a1.scope, AddonManager.SCOPE_PROFILE);
 
-    run_test_5();
+    do_execute_soon(run_test_5);
   });
 }
 
 // Tests that after uninstalling a restart doesn't re-install the extension
 function run_test_5() {
   AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
     a1.uninstall();
 
     restartManager();
 
     AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
       do_check_eq(a1, null);
 
-      run_test_6();
+      do_execute_soon(run_test_6);
     });
   });
 }
 
 // Tests that upgrading the application still doesn't re-install the uninstalled
 // extension
 function run_test_6() {
   restartManager("4");
 
   AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
     do_check_eq(a1, null);
 
-    run_test_7();
+    do_execute_soon(run_test_7);
   });
 }
 
 // Tests that a pending install of a newer version of a distributed add-on
 // at app change still gets applied
 function run_test_7() {
   Services.prefs.clearUserPref("extensions.installedDistroAddon.addon1@tests.mozilla.org");
 
@@ -184,48 +184,48 @@ function run_test_7() {
 
     AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
       do_check_neq(a1, null);
       do_check_eq(a1.version, "2.0");
       do_check_true(a1.isActive);
       do_check_eq(a1.scope, AddonManager.SCOPE_PROFILE);
 
       a1.uninstall();
-      restartManager();
-
-      run_test_8();
+      do_execute_soon(run_test_8);
     });
   });
 }
 
 // Tests that a pending install of a older version of a distributed add-on
 // at app change gets replaced by the distributed version
 function run_test_8() {
+  restartManager();
+
   writeInstallRDFForExtension(addon1_3, distroDir);
 
   installAllFiles([do_get_addon("test_distribution1_2")], function() {
     restartManager(3);
 
     AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
       do_check_neq(a1, null);
       do_check_eq(a1.version, "3.0");
       do_check_true(a1.isActive);
       do_check_eq(a1.scope, AddonManager.SCOPE_PROFILE);
 
       a1.uninstall();
-      restartManager();
-
-      run_test_9();
+      do_execute_soon(run_test_9);
     });
   });
 }
 
 // Tests that bootstrapped add-ons distributed start up correctly, also that
 // add-ons with multiple directories get copied fully
 function run_test_9() {
+  restartManager();
+
   // Copy the test add-on to the distro dir
   let addon = do_get_file("data/test_distribution2_2");
   addon.copyTo(distroDir, "addon2@tests.mozilla.org");
 
   restartManager("5");
 
   AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
     do_check_neq(a2, null);
--- a/toolkit/mozapps/extensions/test/xpcshell/test_dss.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_dss.js
@@ -99,17 +99,17 @@ function run_test() {
     do_check_true(t2.userDisabled);
     do_check_false(t2.appDisabled);
     do_check_false(t2.isActive);
     do_check_eq(t2.screenshots, null);
     do_check_true(isThemeInAddonsList(profileDir, t2.id));
     do_check_false(hasFlag(t2.permissions, AddonManager.PERM_CAN_DISABLE));
     do_check_true(hasFlag(t2.permissions, AddonManager.PERM_CAN_ENABLE));
 
-    run_test_1();
+    do_execute_soon(run_test_1);
   });
 }
 
 function end_test() {
   do_test_finished();
 }
 
 // Checks enabling one theme disables the others
@@ -131,17 +131,17 @@ function run_test_1() {
     ensure_test_completed();
     do_check_false(hasFlag(t2.permissions, AddonManager.PERM_CAN_DISABLE));
     do_check_false(hasFlag(t2.permissions, AddonManager.PERM_CAN_ENABLE));
 
     do_check_true(t1.userDisabled);
     do_check_false(hasFlag(t1.permissions, AddonManager.PERM_CAN_DISABLE));
     do_check_true(hasFlag(t1.permissions, AddonManager.PERM_CAN_ENABLE));
 
-    check_test_1();
+    do_execute_soon(check_test_1);
   });
 }
 
 function check_test_1() {
   restartManager();
   do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "theme2/1.0");
 
   AddonManager.getAddonsByIDs(["theme1@tests.mozilla.org",
@@ -158,17 +158,17 @@ function check_test_1() {
     do_check_false(t2.userDisabled);
     do_check_false(t2.appDisabled);
     do_check_true(t2.isActive);
     do_check_true(isThemeInAddonsList(profileDir, t2.id));
     do_check_false(hasFlag(t2.permissions, AddonManager.PERM_CAN_DISABLE));
     do_check_false(hasFlag(t2.permissions, AddonManager.PERM_CAN_ENABLE));
     do_check_false(gLWThemeChanged);
 
-    run_test_2();
+    do_execute_soon(run_test_2);
   });
 }
 
 // Removing the active theme should fall back to the default (not ideal in this
 // case since we don't have the default theme installed)
 function run_test_2() {
   var dest = profileDir.clone();
   dest.append(do_get_expected_addon_name("theme2@tests.mozilla.org"));
@@ -186,17 +186,17 @@ function run_test_2() {
     do_check_true(isThemeInAddonsList(profileDir, t1.id));
     do_check_false(hasFlag(t1.permissions, AddonManager.PERM_CAN_DISABLE));
     do_check_true(hasFlag(t1.permissions, AddonManager.PERM_CAN_ENABLE));
 
     do_check_eq(t2, null);
     do_check_false(isThemeInAddonsList(profileDir, "theme2@tests.mozilla.org"));
     do_check_false(gLWThemeChanged);
 
-    run_test_3();
+    do_execute_soon(run_test_3);
   });
 }
 
 // Installing a lightweight theme should happen instantly and disable the default theme
 function run_test_3() {
   writeInstallRDFForExtension({
     id: "theme2@tests.mozilla.org",
     version: "1.0",
@@ -275,17 +275,17 @@ function run_test_3() {
           do_check_true(a.userDisabled);
         }
       });
       do_check_true(seen);
 
       do_check_true(gLWThemeChanged);
       gLWThemeChanged = false;
 
-      run_test_4();
+      do_execute_soon(run_test_4);
     });
   });
 }
 
 // Installing a second lightweight theme should disable the first with no restart
 function run_test_4() {
   prepare_test({
     "1@personas.mozilla.org": [
@@ -345,17 +345,17 @@ function run_test_4() {
           do_check_true(a.userDisabled);
         }
       });
       do_check_true(seen);
 
       do_check_true(gLWThemeChanged);
       gLWThemeChanged = false;
 
-      run_test_5();
+      do_execute_soon(run_test_5);
     });
   });
 }
 
 // Switching to a custom theme should disable the lightweight theme and require
 // a restart. Cancelling that should also be possible.
 function run_test_5() {
   prepare_test({
@@ -407,17 +407,17 @@ function run_test_5() {
     do_check_false(t2.userDisabled);
     do_check_false(hasFlag(AddonManager.PENDING_ENABLE, t2.pendingOperations));
     do_check_false(p2.isActive);
     do_check_true(p2.userDisabled);
     do_check_false(hasFlag(AddonManager.PENDING_DISABLE, p2.pendingOperations));
     do_check_true(hasFlag(AddonManager.PERM_CAN_ENABLE, p2.permissions));
     do_check_true(gLWThemeChanged);
 
-    check_test_5();
+    do_execute_soon(check_test_5);
   });
 }
 
 function check_test_5() {
   restartManager();
 
   AddonManager.getAddonsByIDs(["2@personas.mozilla.org",
                                "theme2@tests.mozilla.org"], function([p2, t2]) {
@@ -426,17 +426,17 @@ function check_test_5() {
     do_check_false(hasFlag(AddonManager.PENDING_ENABLE, t2.pendingOperations));
     do_check_false(p2.isActive);
     do_check_true(p2.userDisabled);
     do_check_false(hasFlag(AddonManager.PENDING_DISABLE, p2.pendingOperations));
 
     do_check_true(gLWThemeChanged);
     gLWThemeChanged = false;
 
-    run_test_6();
+    do_execute_soon(run_test_6);
   });
 }
 
 // Switching from a custom theme to a lightweight theme should require a restart
 function run_test_6() {
   prepare_test({
     "2@personas.mozilla.org": [
       "onEnabling",
@@ -484,17 +484,17 @@ function run_test_6() {
     do_check_false(p2.isActive);
     do_check_false(p2.userDisabled);
     do_check_true(hasFlag(AddonManager.PENDING_ENABLE, p2.pendingOperations));
     do_check_false(t2.isActive);
     do_check_true(t2.userDisabled);
     do_check_false(hasFlag(AddonManager.PENDING_DISABLE, t2.pendingOperations));
     do_check_false(gLWThemeChanged);
 
-    check_test_6();
+    do_execute_soon(check_test_6);
   });
 }
 
 function check_test_6() {
   restartManager();
 
   AddonManager.getAddonsByIDs(["2@personas.mozilla.org",
                                "theme2@tests.mozilla.org"], function([p2, t2]) {
@@ -503,17 +503,17 @@ function check_test_6() {
     do_check_false(hasFlag(AddonManager.PENDING_ENABLE, p2.pendingOperations));
     do_check_false(t2.isActive);
     do_check_true(t2.userDisabled);
     do_check_false(hasFlag(AddonManager.PENDING_DISABLE, t2.pendingOperations));
 
     do_check_true(gLWThemeChanged);
     gLWThemeChanged = false;
 
-    run_test_7();
+    do_execute_soon(run_test_7);
   });
 }
 
 // Uninstalling a lightweight theme should not require a restart
 function run_test_7() {
   prepare_test({
     "1@personas.mozilla.org": [
       ["onUninstalling", false],
@@ -523,17 +523,17 @@ function run_test_7() {
 
   AddonManager.getAddonByID("1@personas.mozilla.org", function(p1) {
     p1.uninstall();
 
     ensure_test_completed();
     do_check_eq(LightweightThemeManager.usedThemes.length, 1);
     do_check_false(gLWThemeChanged);
 
-    run_test_8();
+    do_execute_soon(run_test_8);
   });
 }
 
 // Uninstalling a lightweight theme in use should not require a restart and it
 // should reactivate the default theme
 // Also, uninstalling a lightweight theme in use should send a
 // "lightweight-theme-styling-update" notification through the observer service
 function run_test_8() {
@@ -552,17 +552,17 @@ function run_test_8() {
     p2.uninstall();
 
     ensure_test_completed();
     do_check_eq(LightweightThemeManager.usedThemes.length, 0);
 
     do_check_true(gLWThemeChanged);
     gLWThemeChanged = false;
 
-    run_test_9();
+    do_execute_soon(run_test_9);
   });
 }
 
 // Uninstalling a theme not in use should not require a restart
 function run_test_9() {
   AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) {
     prepare_test({
       "theme1@tests.mozilla.org": [
@@ -574,17 +574,17 @@ function run_test_9() {
     t1.uninstall();
 
     ensure_test_completed();
 
     AddonManager.getAddonByID("theme1@tests.mozilla.org", function(newt1) {
       do_check_eq(newt1, null);
       do_check_false(gLWThemeChanged);
 
-      run_test_10();
+      do_execute_soon(run_test_10);
     });
   });
 }
 
 // Uninstalling a custom theme in use should require a restart
 function run_test_10() {
   AddonManager.getAddonByID("theme2@tests.mozilla.org", function(oldt2) {
     prepare_test({
@@ -626,17 +626,17 @@ function run_test_10() {
 
       t2.uninstall();
 
       ensure_test_completed();
       do_check_false(gLWThemeChanged);
 
       restartManager();
 
-      run_test_11();
+      do_execute_soon(run_test_11);
     });
   });
 }
 
 // Installing a custom theme not in use should not require a restart
 function run_test_11() {
   prepare_test({ }, [
     "onNewInstall"
@@ -668,17 +668,17 @@ function check_test_11() {
   restartManager();
   AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) {
     do_check_neq(t1, null);
     var previewSpec = do_get_addon_root_uri(profileDir, "theme1@tests.mozilla.org") + "preview.png";
     do_check_eq(t1.screenshots.length, 1);
     do_check_eq(t1.screenshots[0], previewSpec);
     do_check_false(gLWThemeChanged);
 
-    run_test_12();
+    do_execute_soon(run_test_12);
   });
 }
 
 // Updating a custom theme not in use should not require a restart
 function run_test_12() {
   prepare_test({ }, [
     "onNewInstall"
   ]);
@@ -705,17 +705,17 @@ function run_test_12() {
   });
 }
 
 function check_test_12() {
   AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) {
     do_check_neq(t1, null);
     do_check_false(gLWThemeChanged);
 
-    run_test_13();
+    do_execute_soon(run_test_13);
   });
 }
 
 // Updating a custom theme in use should require a restart
 function run_test_13() {
   AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) {
     prepare_test({
       "theme1@tests.mozilla.org": [
@@ -763,17 +763,17 @@ function check_test_13() {
 
   AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) {
     do_check_neq(t1, null);
     do_check_true(t1.isActive);
     do_check_false(gLWThemeChanged);
     t1.uninstall();
     restartManager();
 
-    run_test_14();
+    do_execute_soon(run_test_14);
   });
 }
 
 // Switching from a lightweight theme to the default theme should not require
 // a restart
 function run_test_14() {
   LightweightThemeManager.currentTheme = {
     id: "1",
--- a/toolkit/mozapps/extensions/test/xpcshell/test_duplicateplugins.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_duplicateplugins.js
@@ -151,17 +151,17 @@ function run_test_1() {
 // Test that disabling a coalesced plugin disables all its tags
 function run_test_2() {
   AddonManager.getAddonByID(gPluginIDs[0], function(p) {
     do_check_false(p.userDisabled);
     p.userDisabled = true;
     do_check_true(PLUGINS[0].disabled);
     do_check_true(PLUGINS[1].disabled);
 
-    run_test_3();
+    do_execute_soon(run_test_3);
   });
 }
 
 // Test that IDs persist across restart
 function run_test_3() {
   restartManager();
 
   AddonManager.getAddonByID(gPluginIDs[0], function(p) {
--- a/toolkit/mozapps/extensions/test/xpcshell/test_filepointer.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_filepointer.js
@@ -172,41 +172,41 @@ function check_test_2() {
     do_check_eq(uri.spec, rootUri + "install.rdf");
 
     let source = sourceDir.clone();
     source.append(addon1.id);
     do_check_true(source.exists());
 
     a1.uninstall();
 
-    restartManager();
-
-    run_test_3();
+    do_execute_soon(run_test_3);
   });
 }
 
 // Tests that uninstalling doesn't clobber the original sources
 function run_test_3() {
+  restartManager();
+
   writePointer(addon1.id);
 
   restartManager();
 
   AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
     do_check_neq(a1, null);
     do_check_eq(a1.version, "1.0");
 
     a1.uninstall();
 
     restartManager();
 
     let source = sourceDir.clone();
     source.append(addon1.id);
     do_check_true(source.exists());
 
-    run_test_4();
+    do_execute_soon(run_test_4);
   });
 }
 
 // Tests that misnaming a pointer doesn't clobber the sources
 function run_test_4() {
   writePointer("addon2@tests.mozilla.org", addon1.id);
 
   restartManager();
@@ -219,17 +219,17 @@ function run_test_4() {
     let source = sourceDir.clone();
     source.append(addon1.id);
     do_check_true(source.exists());
 
     let pointer = profileDir.clone();
     pointer.append("addon2@tests.mozilla.org");
     do_check_false(pointer.exists());
 
-    run_test_5();
+    do_execute_soon(run_test_5);
   });
 }
 
 // Tests that changing the ID of an existing add-on doesn't clobber the sources
 function run_test_5() {
   var dest = writeInstallRDFForExtension(addon1, sourceDir);
   // Make sure the modification time changes enough to be detected.
   setExtensionModifiedTime(dest, dest.lastModifiedTime - 5000);
@@ -253,17 +253,17 @@ function run_test_5() {
       let source = sourceDir.clone();
       source.append(addon1.id);
       do_check_true(source.exists());
 
       let pointer = profileDir.clone();
       pointer.append(addon1.id);
       do_check_false(pointer.exists());
 
-      run_test_6();
+      do_execute_soon(run_test_6);
     });
   });
 }
 
 // Removing the pointer file should uninstall the add-on
 function run_test_6() {
   var dest = writeInstallRDFForExtension(addon1, sourceDir);
   // Make sure the modification time changes enough to be detected in run_test_8.
@@ -280,17 +280,17 @@ function run_test_6() {
     pointer.append(addon1.id);
     pointer.remove(false);
 
     restartManager();
 
     AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
       do_check_eq(a1, null);
 
-      run_test_7();
+      do_execute_soon(run_test_7);
     });
   });
 }
 
 // Removing the pointer file and replacing it with a directory should work
 function run_test_7() {
   writePointer(addon1.id);
 
@@ -311,17 +311,17 @@ function run_test_7() {
     AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
       do_check_neq(a1, null);
       do_check_eq(a1.version, "2.0");
 
       a1.uninstall();
 
       restartManager();
 
-      run_test_8();
+      do_execute_soon(run_test_8);
     });
   });
 }
 
 // Changes to the source files should be detected
 function run_test_8() {
   writePointer(addon1.id);
 
@@ -338,17 +338,17 @@ function run_test_8() {
     AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
       do_check_neq(a1, null);
       do_check_eq(a1.version, "2.0");
 
       a1.uninstall();
 
       restartManager();
 
-      run_test_9();
+      do_execute_soon(run_test_9);
     });
   });
 }
 
 // Removing the add-on the pointer file points at should uninstall the add-on
 function run_test_9() {
   var dest = writeInstallRDFForExtension(addon1, sourceDir);
   writePointer(addon1.id);
@@ -365,17 +365,17 @@ function run_test_9() {
 
     AddonManager.getAddonByID(addon1.id, function(a1) {
       do_check_eq(a1, null);
 
       let pointer = profileDir.clone();
       pointer.append(addon1.id);
       do_check_false(pointer.exists());
 
-      run_test_10();
+      do_execute_soon(run_test_10);
     });
   });
 }
 
 // Tests that installing a new add-on by pointer with a relative path works
 function run_test_10() {
   writeInstallRDFForExtension(addon1, sourceDir);
   writeRelativePointer(addon1.id);
--- a/toolkit/mozapps/extensions/test/xpcshell/test_general.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_general.js
@@ -26,30 +26,30 @@ function run_test_1() {
   restartManager();
 
   AddonManager.getAddonsByTypes(null, function(addons) {
     do_check_eq(gCount, addons.length);
 
     AddonManager.getAddonsWithOperationsByTypes(null, function(pendingAddons) {
       do_check_eq(0, pendingAddons.length);
 
-      run_test_2();
+      do_execute_soon(run_test_2);
     });
   });
 }
 
 function run_test_2() {
   shutdownManager();
 
   startupManager(false);
 
   AddonManager.getAddonsByTypes(null, function(addons) {
     do_check_eq(gCount, addons.length);
 
-    run_test_3();
+    do_execute_soon(run_test_3);
   });
 }
 
 function run_test_3() {
   restartManager();
 
   AddonManager.getAddonsByTypes(null, function(addons) {
     do_check_eq(gCount, addons.length);
--- a/toolkit/mozapps/extensions/test/xpcshell/test_hotfix.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_hotfix.js
@@ -57,45 +57,44 @@ function run_test_1() {
 function check_test_1() {
   restartManager();
 
   AddonManager.getAddonByID("hotfix@tests.mozilla.org", function(aAddon) {
     do_check_neq(aAddon, null);
     do_check_eq(aAddon.version, "1.0");
 
     aAddon.uninstall();
-    restartManager();
-
-    run_test_2();
+    do_execute_soon(run_test_2);
   });
 }
 
 // Don't install an already used hotfix
 function run_test_2() {
+  restartManager();
+
   AddonManager.addInstallListener({
     onNewInstall: function() {
       do_throw("Should not have seen a new install created");
     }
   });
 
   function observer() {
     Services.obs.removeObserver(arguments.callee, "addons-background-update-complete");
-
-    restartManager();
-    run_test_3();
+    do_execute_soon(run_test_3);
   }
 
   Services.obs.addObserver(observer, "addons-background-update-complete", false);
 
   // Fake a timer event
   gInternalManager.notify(null);
 }
 
 // Install a newer hotfix
 function run_test_3() {
+  restartManager();
   Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:4444/data/test_hotfix_2.rdf");
 
   prepare_test({
     "hotfix@tests.mozilla.org": [
       "onInstalling"
     ]
   }, [
     "onNewInstall",
@@ -112,70 +111,70 @@ function run_test_3() {
 function check_test_3() {
   restartManager();
 
   AddonManager.getAddonByID("hotfix@tests.mozilla.org", function(aAddon) {
     do_check_neq(aAddon, null);
     do_check_eq(aAddon.version, "2.0");
 
     aAddon.uninstall();
-    restartManager();
-
-    run_test_4();
+    do_execute_soon(run_test_4);
   });
 }
 
 // Don't install an incompatible hotfix
 function run_test_4() {
+  restartManager();
+
   Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:4444/data/test_hotfix_3.rdf");
 
   AddonManager.addInstallListener({
     onNewInstall: function() {
       do_throw("Should not have seen a new install created");
     }
   });
 
   function observer() {
     Services.obs.removeObserver(arguments.callee, "addons-background-update-complete");
-
-    restartManager();
-    run_test_5();
+    do_execute_soon(run_test_5);
   }
 
   Services.obs.addObserver(observer, "addons-background-update-complete", false);
 
   // Fake a timer event
   gInternalManager.notify(null);
 }
 
 // Don't install an older hotfix
 function run_test_5() {
+  restartManager();
+
   Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:4444/data/test_hotfix_1.rdf");
 
   AddonManager.addInstallListener({
     onNewInstall: function() {
       do_throw("Should not have seen a new install created");
     }
   });
 
   function observer() {
     Services.obs.removeObserver(arguments.callee, "addons-background-update-complete");
-
-    restartManager();
-    run_test_6();
+    do_execute_soon(run_test_6);
   }
 
   Services.obs.addObserver(observer, "addons-background-update-complete", false);
 
   // Fake a timer event
   gInternalManager.notify(null);
 }
 
 // Don't re-download an already pending install
 function run_test_6() {
+  restartManager();
+
   Services.prefs.setCharPref("extensions.hotfix.lastVersion", "0");
   Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:4444/data/test_hotfix_1.rdf");
 
   prepare_test({
     "hotfix@tests.mozilla.org": [
       "onInstalling"
     ]
   }, [
@@ -198,30 +197,30 @@ function check_test_6() {
   });
 
   function observer() {
     Services.obs.removeObserver(arguments.callee, "addons-background-update-complete");
     restartManager();
 
     AddonManager.getAddonByID("hotfix@tests.mozilla.org", function(aAddon) {
       aAddon.uninstall();
-
-      restartManager();
-      run_test_7();
+      do_execute_soon(run_test_7);
     });
   }
 
   Services.obs.addObserver(observer, "addons-background-update-complete", false);
 
   // Fake a timer event
   gInternalManager.notify(null);
 }
 
 // Start downloading again if something cancels the install
 function run_test_7() {
+  restartManager();
+
   Services.prefs.setCharPref("extensions.hotfix.lastVersion", "0");
 
   prepare_test({
     "hotfix@tests.mozilla.org": [
       "onInstalling"
     ]
   }, [
     "onNewInstall",
@@ -265,24 +264,24 @@ function check_test_7(aInstall) {
 function finish_test_7() {
   restartManager();
 
   AddonManager.getAddonByID("hotfix@tests.mozilla.org", function(aAddon) {
     do_check_neq(aAddon, null);
     do_check_eq(aAddon.version, "1.0");
 
     aAddon.uninstall();
-    restartManager();
-
-    run_test_8();
+    do_execute_soon(run_test_8);
   });
 }
 
 // Cancel a pending install when a newer version is already available
 function run_test_8() {
+  restartManager();
+
   Services.prefs.setCharPref("extensions.hotfix.lastVersion", "0");
   Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:4444/data/test_hotfix_1.rdf");
 
   prepare_test({
     "hotfix@tests.mozilla.org": [
       "onInstalling"
     ]
   }, [
--- a/toolkit/mozapps/extensions/test/xpcshell/test_install.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_install.js
@@ -1084,56 +1084,61 @@ function run_test_16() {
   AddonManager.getInstallForURL(url, function(aInstall) {
     aInstall.addListener({
       onInstallStarted: function() {
         do_check_false(aInstall.addon.userDisabled);
         aInstall.addon.userDisabled = true;
       },
 
       onInstallEnded: function() {
+       do_execute_soon(function install2_1_ended() {
         restartManager();
 
         AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
           do_check_true(a2.userDisabled);
           do_check_false(a2.isActive);
 
           let url = "http://localhost:4444/addons/test_install2_2.xpi";
           AddonManager.getInstallForURL(url, function(aInstall) {
             aInstall.addListener({
               onInstallEnded: function() {
+               do_execute_soon(function install2_2_ended() {
                 do_check_true(aInstall.addon.userDisabled);
 
                 restartManager();
 
                 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
                   do_check_true(a2.userDisabled);
                   do_check_false(a2.isActive);
 
                   a2.uninstall();
-                  restartManager();
-
-                  run_test_17();
+                  do_execute_soon(run_test_17);
                 });
+               });
               }
             });
             aInstall.install();
           }, "application/x-xpinstall");
         });
+       });
       }
     });
     aInstall.install();
   }, "application/x-xpinstall");
 }
 
 // Verify that changing the userDisabled value before onInstallEnded works
 function run_test_17() {
+  restartManager();
+
   let url = "http://localhost:4444/addons/test_install2_1.xpi";
   AddonManager.getInstallForURL(url, function(aInstall) {
     aInstall.addListener({
       onInstallEnded: function() {
+       do_execute_soon(function install2_1_ended2() {
         do_check_false(aInstall.addon.userDisabled);
 
         restartManager();
 
         AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
           do_check_false(a2.userDisabled);
           do_check_true(a2.isActive);
 
@@ -1141,171 +1146,184 @@ function run_test_17() {
           AddonManager.getInstallForURL(url, function(aInstall) {
             aInstall.addListener({
               onInstallStarted: function() {
                 do_check_false(aInstall.addon.userDisabled);
                 aInstall.addon.userDisabled = true;
               },
 
               onInstallEnded: function() {
+               do_execute_soon(function install2_2_ended2() {
                 restartManager();
 
                 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
                   do_check_true(a2.userDisabled);
                   do_check_false(a2.isActive);
 
                   a2.uninstall();
-                  restartManager();
-
-                  run_test_18();
+                  do_execute_soon(run_test_18);
                 });
+               });
               }
             });
             aInstall.install();
           }, "application/x-xpinstall");
         });
+       });
       }
     });
     aInstall.install();
   }, "application/x-xpinstall");
 }
 
 // Verify that changing the userDisabled value before onInstallEnded works
 function run_test_18() {
+  restartManager();
+
   let url = "http://localhost:4444/addons/test_install2_1.xpi";
   AddonManager.getInstallForURL(url, function(aInstall) {
     aInstall.addListener({
       onInstallStarted: function() {
         do_check_false(aInstall.addon.userDisabled);
         aInstall.addon.userDisabled = true;
       },
 
       onInstallEnded: function() {
+       do_execute_soon(function install_2_1_ended3() {
         restartManager();
 
         AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
           do_check_true(a2.userDisabled);
           do_check_false(a2.isActive);
 
           let url = "http://localhost:4444/addons/test_install2_2.xpi";
           AddonManager.getInstallForURL(url, function(aInstall) {
             aInstall.addListener({
               onInstallStarted: function() {
                 do_check_true(aInstall.addon.userDisabled);
                 aInstall.addon.userDisabled = false;
               },
 
               onInstallEnded: function() {
+               do_execute_soon(function install_2_2_ended3() {
                 restartManager();
 
                 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
                   do_check_false(a2.userDisabled);
                   do_check_true(a2.isActive);
 
                   a2.uninstall();
-                  restartManager();
-
-                  run_test_18_1();
+                  do_execute_soon(run_test_18_1);
                 });
+               });
               }
             });
             aInstall.install();
           }, "application/x-xpinstall");
         });
+       });
       }
     });
     aInstall.install();
   }, "application/x-xpinstall");
 }
 
 
 // Checks that metadata is not stored if the pref is set to false
 function run_test_18_1() {
+  restartManager();
+
   Services.prefs.setBoolPref("extensions.getAddons.cache.enabled", true);
   Services.prefs.setCharPref("extensions.getAddons.get.url",
                              "http://localhost:4444/data/test_install.xml");
 
   Services.prefs.setBoolPref("extensions.addon2@tests.mozilla.org.getAddons.cache.enabled", false);
 
   let url = "http://localhost:4444/addons/test_install2_1.xpi";
   AddonManager.getInstallForURL(url, function(aInstall) {
     aInstall.addListener({
       onInstallEnded: function(aInstall, aAddon) {
+       do_execute_soon(function test18_1_install_ended() {
         do_check_neq(aAddon.fullDescription, "Repository description");
 
         restartManager();
 
         AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
           do_check_neq(a2.fullDescription, "Repository description");
 
           a2.uninstall();
-          restartManager();
-
-          Services.prefs.setBoolPref("extensions.addon2@tests.mozilla.org.getAddons.cache.enabled", true);
-          run_test_19();
+          do_execute_soon(run_test_19);
         });
+       });
       }
     });
     aInstall.install();
   }, "application/x-xpinstall");
 }
 
 // Checks that metadata is downloaded for new installs and is visible before and
 // after restart
 function run_test_19() {
+  restartManager();
+  Services.prefs.setBoolPref("extensions.addon2@tests.mozilla.org.getAddons.cache.enabled", true);
+
   let url = "http://localhost:4444/addons/test_install2_1.xpi";
   AddonManager.getInstallForURL(url, function(aInstall) {
     aInstall.addListener({
       onInstallEnded: function(aInstall, aAddon) {
+       do_execute_soon(function test19_install_ended() {
         do_check_eq(aAddon.fullDescription, "Repository description");
 
         restartManager();
 
         AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
           do_check_eq(a2.fullDescription, "Repository description");
 
           a2.uninstall();
-          restartManager();
-
-          run_test_20();
+          do_execute_soon(run_test_20);
         });
+       });
       }
     });
     aInstall.install();
   }, "application/x-xpinstall");
 }
 
 // Do the same again to make sure it works when the data is already in the cache
 function run_test_20() {
+  restartManager();
+
   let url = "http://localhost:4444/addons/test_install2_1.xpi";
   AddonManager.getInstallForURL(url, function(aInstall) {
     aInstall.addListener({
       onInstallEnded: function(aInstall, aAddon) {
+       do_execute_soon(function test20_install_ended() {
         do_check_eq(aAddon.fullDescription, "Repository description");
 
         restartManager();
 
         AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
           do_check_eq(a2.fullDescription, "Repository description");
 
           a2.uninstall();
-          restartManager();
-
-          Services.prefs.setBoolPref("extensions.getAddons.cache.enabled", false);
-          run_test_21();
+          do_execute_soon(run_test_21);
         });
+       });
       }
     });
     aInstall.install();
   }, "application/x-xpinstall");
 }
 
 // Verify that installing an add-on that is already pending install cancels the
 // first install
 function run_test_21() {
+  restartManager();
+  Services.prefs.setBoolPref("extensions.getAddons.cache.enabled", false);
+
   installAllFiles([do_get_addon("test_install2_1")], function() {
     AddonManager.getAllInstalls(function(aInstalls) {
       do_check_eq(aInstalls.length, 1);
 
       prepare_test({
         "addon2@tests.mozilla.org": [
           "onOperationCancelled",
           "onInstalling"
--- a/toolkit/mozapps/extensions/test/xpcshell/test_install_strictcompat.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_install_strictcompat.js
@@ -183,28 +183,28 @@ function check_test_1() {
           do_check_false(a1.hasResource("foo.bar"));
 
           let uri = do_get_addon_root_uri(profileDir, "addon1@tests.mozilla.org");
           do_check_eq(a1.getResourceURI("install.rdf").spec, uri + "install.rdf");
           do_check_eq(a1.iconURL, uri + "icon.png");
           do_check_eq(a1.icon64URL, uri + "icon64.png");
 
           a1.uninstall();
-          restartManager();
-          do_check_not_in_crash_annotation(a1.id, a1.version);
-
-          run_test_2();
+          do_execute_soon(function(){run_test_2(a1)});
         });
       });
     });
   });
 }
 
 // Tests that an install from a url downloads.
-function run_test_2() {
+function run_test_2(aAddon) {
+  restartManager();
+  do_check_not_in_crash_annotation(aAddon.id, aAddon.version);
+
   let url = "http://localhost:4444/addons/test_install2_1.xpi";
   AddonManager.getInstallForURL(url, function(install) {
     do_check_neq(install, null);
     do_check_eq(install.linkedInstalls, null);
     do_check_eq(install.version, "1.0");
     do_check_eq(install.name, "Test 2");
     do_check_eq(install.state, AddonManager.STATE_AVAILABLE);
     do_check_eq(install.iconURL, null);
@@ -388,27 +388,27 @@ function check_test_5(install) {
           do_check_eq(a2.sourceURI.spec,
                       "http://localhost:4444/addons/test_install2_2.xpi");
 
           do_check_eq(a2.installDate.getTime(), gInstallDate);
           // Update date should be later (or the same if this test is too fast)
           do_check_true(a2.installDate <= a2.updateDate);
 
           a2.uninstall();
-          restartManager();
-
-          run_test_6();
+          do_execute_soon(run_test_6);
         });
       });
     });
   });
 }
 
 // Tests that an install that requires a compatibility update works
 function run_test_6() {
+  restartManager();
+
   prepare_test({ }, [
     "onNewInstall"
   ]);
 
   let url = "http://localhost:4444/addons/test_install3.xpi";
   AddonManager.getInstallForURL(url, function(install) {
     ensure_test_completed();
 
@@ -467,25 +467,25 @@ function check_test_7() {
         do_check_eq(a3.type, "extension");
         do_check_eq(a3.version, "1.0");
         do_check_eq(a3.name, "Real Test 4");
         do_check_true(a3.isActive);
         do_check_false(a3.appDisabled);
         do_check_true(isExtensionInAddonsList(profileDir, a3.id));
         do_check_true(do_get_addon("test_install3").exists());
         a3.uninstall();
-        restartManager();
-
-        run_test_8();
+        do_execute_soon(run_test_8);
       });
     });
   });
 }
 
 function run_test_8() {
+  restartManager();
+
   AddonManager.addInstallListener(InstallListener);
   AddonManager.addAddonListener(AddonListener);
 
   prepare_test({ }, [
     "onNewInstall"
   ]);
 
   AddonManager.getInstallForFile(do_get_addon("test_install3"), function(install) {
@@ -511,24 +511,24 @@ function check_test_8() {
     do_check_eq(a3.type, "extension");
     do_check_eq(a3.version, "1.0");
     do_check_eq(a3.name, "Real Test 4");
     do_check_true(a3.isActive);
     do_check_false(a3.appDisabled);
     do_check_true(isExtensionInAddonsList(profileDir, a3.id));
     do_check_true(do_get_addon("test_install3").exists());
     a3.uninstall();
-    restartManager();
-
-    run_test_9();
+    do_execute_soon(run_test_9);
   });
 }
 
 // Test that after cancelling a download it is removed from the active installs
 function run_test_9() {
+  restartManager();
+
   prepare_test({ }, [
     "onNewInstall"
   ]);
 
   let url = "http://localhost:4444/addons/test_install3.xpi";
   AddonManager.getInstallForURL(url, function(install) {
     ensure_test_completed();
 
@@ -756,24 +756,24 @@ function check_test_11() {
     do_check_neq(a6, null);
     do_check_neq(a7, null);
 
     a4.uninstall();
     a5.uninstall();
     a6.uninstall();
     a7.uninstall();
 
-    restartManager();
-
-    run_test_12();
+    do_execute_soon(run_test_12);
   });
 }
 
 // Same as test 11 but for a remote XPI
 function run_test_12() {
+  restartManager();
+
   prepare_test({ }, [
     "onNewInstall",
   ]);
 
   let url = "http://localhost:4444/addons/test_install4.xpi";
   AddonManager.getInstallForURL(url, function(install) {
     gInstall = install;
 
@@ -882,26 +882,26 @@ function check_test_12() {
     do_check_neq(a6, null);
     do_check_neq(a7, null);
 
     a4.uninstall();
     a5.uninstall();
     a6.uninstall();
     a7.uninstall();
 
-    restartManager();
-
-    run_test_13();
+    do_execute_soon(run_test_13);
   });
 }
 
 
 // Tests that cancelling an upgrade leaves the original add-on's pendingOperations
 // correct
 function run_test_13() {
+  restartManager();
+
   installAllFiles([do_get_addon("test_install2_1")], function() {
     restartManager();
 
     prepare_test({ }, [
       "onNewInstall"
     ]);
 
     let url = "http://localhost:4444/addons/test_install2_2.xpi";
@@ -970,25 +970,25 @@ function check_test_13(install) {
     restartManager();
 
     // Check that the upgrade did not complete
     AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
       do_check_eq(a2.version, "2.0");
 
       a2.uninstall();
 
-      restartManager();
-
-      run_test_14();
+      do_execute_soon(run_test_14);
     });
   });
 }
 
 // Check that cancelling the install from onDownloadStarted actually cancels it
 function run_test_14() {
+  restartManager();
+
   prepare_test({ }, [
     "onNewInstall"
   ]);
 
   let url = "http://localhost:4444/addons/test_install2_1.xpi";
   AddonManager.getInstallForURL(url, function(install) {
     ensure_test_completed();
 
@@ -1076,56 +1076,61 @@ function run_test_16() {
   AddonManager.getInstallForURL(url, function(aInstall) {
     aInstall.addListener({
       onInstallStarted: function() {
         do_check_false(aInstall.addon.userDisabled);
         aInstall.addon.userDisabled = true;
       },
 
       onInstallEnded: function() {
+       do_execute_soon(function test16_install1() {
         restartManager();
 
         AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
           do_check_true(a2.userDisabled);
           do_check_false(a2.isActive);
 
           let url = "http://localhost:4444/addons/test_install2_2.xpi";
           AddonManager.getInstallForURL(url, function(aInstall) {
             aInstall.addListener({
               onInstallEnded: function() {
+               do_execute_soon(function test16_install2() {
                 do_check_true(aInstall.addon.userDisabled);
 
                 restartManager();
 
                 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
                   do_check_true(a2.userDisabled);
                   do_check_false(a2.isActive);
 
                   a2.uninstall();
-                  restartManager();
-
-                  run_test_17();
+                  do_execute_soon(run_test_17);
                 });
+               });
               }
             });
             aInstall.install();
           }, "application/x-xpinstall");
         });
+       });
       }
     });
     aInstall.install();
   }, "application/x-xpinstall");
 }
 
 // Verify that changing the userDisabled value before onInstallEnded works
 function run_test_17() {
+  restartManager();
+
   let url = "http://localhost:4444/addons/test_install2_1.xpi";
   AddonManager.getInstallForURL(url, function(aInstall) {
     aInstall.addListener({
       onInstallEnded: function() {
+       do_execute_soon(function test17_install1() {
         do_check_false(aInstall.addon.userDisabled);
 
         restartManager();
 
         AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
           do_check_false(a2.userDisabled);
           do_check_true(a2.isActive);
 
@@ -1133,171 +1138,184 @@ function run_test_17() {
           AddonManager.getInstallForURL(url, function(aInstall) {
             aInstall.addListener({
               onInstallStarted: function() {
                 do_check_false(aInstall.addon.userDisabled);
                 aInstall.addon.userDisabled = true;
               },
 
               onInstallEnded: function() {
+               do_execute_soon(function test17_install1() {
                 restartManager();
 
                 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
                   do_check_true(a2.userDisabled);
                   do_check_false(a2.isActive);
 
                   a2.uninstall();
-                  restartManager();
-
-                  run_test_18();
+                  do_execute_soon(run_test_18);
                 });
+               });
               }
             });
             aInstall.install();
           }, "application/x-xpinstall");
         });
+       });
       }
     });
     aInstall.install();
   }, "application/x-xpinstall");
 }
 
 // Verify that changing the userDisabled value before onInstallEnded works
 function run_test_18() {
+  restartManager();
+
   let url = "http://localhost:4444/addons/test_install2_1.xpi";
   AddonManager.getInstallForURL(url, function(aInstall) {
     aInstall.addListener({
       onInstallStarted: function() {
         do_check_false(aInstall.addon.userDisabled);
         aInstall.addon.userDisabled = true;
       },
 
       onInstallEnded: function() {
+       do_execute_soon(function test18_install1() {
         restartManager();
 
         AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
           do_check_true(a2.userDisabled);
           do_check_false(a2.isActive);
 
           let url = "http://localhost:4444/addons/test_install2_2.xpi";
           AddonManager.getInstallForURL(url, function(aInstall) {
             aInstall.addListener({
               onInstallStarted: function() {
                 do_check_true(aInstall.addon.userDisabled);
                 aInstall.addon.userDisabled = false;
               },
 
               onInstallEnded: function() {
+               do_execute_soon(function test18_install2() {
                 restartManager();
 
                 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
                   do_check_false(a2.userDisabled);
                   do_check_true(a2.isActive);
 
                   a2.uninstall();
-                  restartManager();
-
-                  run_test_18_1();
+                  do_execute_soon(run_test_18_1);
                 });
+               });
               }
             });
             aInstall.install();
           }, "application/x-xpinstall");
         });
+       });
       }
     });
     aInstall.install();
   }, "application/x-xpinstall");
 }
 
 
 // Checks that metadata is not stored if the pref is set to false
 function run_test_18_1() {
+  restartManager();
+
   Services.prefs.setBoolPref("extensions.getAddons.cache.enabled", true);
   Services.prefs.setCharPref("extensions.getAddons.get.url",
                              "http://localhost:4444/data/test_install.xml");
 
   Services.prefs.setBoolPref("extensions.addon2@tests.mozilla.org.getAddons.cache.enabled", false);
 
   let url = "http://localhost:4444/addons/test_install2_1.xpi";
   AddonManager.getInstallForURL(url, function(aInstall) {
     aInstall.addListener({
       onInstallEnded: function(aInstall, aAddon) {
+       do_execute_soon(function test18_install() {
         do_check_neq(aAddon.fullDescription, "Repository description");
 
         restartManager();
 
         AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
           do_check_neq(a2.fullDescription, "Repository description");
 
           a2.uninstall();
-          restartManager();
-
-          Services.prefs.setBoolPref("extensions.addon2@tests.mozilla.org.getAddons.cache.enabled", true);
-          run_test_19();
+          do_execute_soon(run_test_19);
         });
+       });
       }
     });
     aInstall.install();
   }, "application/x-xpinstall");
 }
 
 // Checks that metadata is downloaded for new installs and is visible before and
 // after restart
 function run_test_19() {
+  restartManager();
+  Services.prefs.setBoolPref("extensions.addon2@tests.mozilla.org.getAddons.cache.enabled", true);
+
   let url = "http://localhost:4444/addons/test_install2_1.xpi";
   AddonManager.getInstallForURL(url, function(aInstall) {
     aInstall.addListener({
       onInstallEnded: function(aInstall, aAddon) {
+       do_execute_soon(function test19_install() {
         do_check_eq(aAddon.fullDescription, "Repository description");
 
         restartManager();
 
         AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
           do_check_eq(a2.fullDescription, "Repository description");
 
           a2.uninstall();
-          restartManager();
-
-          run_test_20();
+          do_execute_soon(run_test_20);
         });
+       });
       }
     });
     aInstall.install();
   }, "application/x-xpinstall");
 }
 
 // Do the same again to make sure it works when the data is already in the cache
 function run_test_20() {
+  restartManager();
+
   let url = "http://localhost:4444/addons/test_install2_1.xpi";
   AddonManager.getInstallForURL(url, function(aInstall) {
     aInstall.addListener({
       onInstallEnded: function(aInstall, aAddon) {
+       do_execute_soon(function test20_install() {
         do_check_eq(aAddon.fullDescription, "Repository description");
 
         restartManager();
 
         AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
           do_check_eq(a2.fullDescription, "Repository description");
 
           a2.uninstall();
-          restartManager();
-
-          Services.prefs.setBoolPref("extensions.getAddons.cache.enabled", false);
-          run_test_21();
+          do_execute_soon(run_test_21);
         });
+       });
       }
     });
     aInstall.install();
   }, "application/x-xpinstall");
 }
 
 // Verify that installing an add-on that is already pending install cancels the
 // first install
 function run_test_21() {
+  restartManager();
+  Services.prefs.setBoolPref("extensions.getAddons.cache.enabled", false);
+
   installAllFiles([do_get_addon("test_install2_1")], function() {
     AddonManager.getAllInstalls(function(aInstalls) {
       do_check_eq(aInstalls.length, 1);
 
       prepare_test({
         "addon2@tests.mozilla.org": [
           "onOperationCancelled",
           "onInstalling"
--- a/toolkit/mozapps/extensions/test/xpcshell/test_langpack.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_langpack.js
@@ -72,17 +72,18 @@ function run_test_1() {
         ["onInstalling", false],
         "onInstalled"
       ]
     }, [
       "onInstallStarted",
       "onInstallEnded",
     ], function() {
       do_check_true(addon.hasResource("install.rdf"));
-      check_test_1();
+      // spin to let the startup complete
+      do_execute_soon(check_test_1);
     });
     install.install();
   });
 }
 
 function check_test_1() {
   AddonManager.getAllInstalls(function(installs) {
     // There should be no active installs now since the install completed and
--- a/toolkit/mozapps/extensions/test/xpcshell/test_locked.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_locked.js
@@ -165,42 +165,41 @@ function run_test() {
     a2.userDisabled = true;
     a4.userDisabled = true;
     a7.userDisabled = true;
     t2.userDisabled = false;
     a3.findUpdates({
       onUpdateFinished: function() {
         a4.findUpdates({
           onUpdateFinished: function() {
-            restartManager();
-
-            run_test_1();
+            // Let the updates finish before restarting the manager
+            do_execute_soon(run_test_1);
           }
         }, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
       }
     }, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
   });
 }
 
 function end_test() {
   testserver.stop(do_test_finished);
 }
 
 function run_test_1() {
+  restartManager();
   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                "addon2@tests.mozilla.org",
                                "addon3@tests.mozilla.org",
                                "addon4@tests.mozilla.org",
                                "addon5@tests.mozilla.org",
                                "addon6@tests.mozilla.org",
                                "addon7@tests.mozilla.org",
                                "theme1@tests.mozilla.org",
-                               "theme2@tests.mozilla.org"], function([a1, a2, a3,
-                                                                      a4, a5, a6,
-                                                                      a7, t1, t2]) {
+                               "theme2@tests.mozilla.org"],
+                               callback_soon(function([a1, a2, a3, a4, a5, a6, a7, t1, t2]) {
     do_check_neq(a1, null);
     do_check_true(a1.isActive);
     do_check_false(a1.userDisabled);
     do_check_false(a1.appDisabled);
     do_check_eq(a1.pendingOperations, AddonManager.PENDING_NONE);
     do_check_true(isExtensionInAddonsList(profileDir, a1.id));
 
     do_check_neq(a2, null);
@@ -277,19 +276,18 @@ function run_test_1() {
     AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                  "addon2@tests.mozilla.org",
                                  "addon3@tests.mozilla.org",
                                  "addon4@tests.mozilla.org",
                                  "addon5@tests.mozilla.org",
                                  "addon6@tests.mozilla.org",
                                  "addon7@tests.mozilla.org",
                                  "theme1@tests.mozilla.org",
-                                 "theme2@tests.mozilla.org"], function([a1, a2, a3,
-                                                                        a4, a5, a6,
-                                                                        a7, t1, t2]) {
+                                 "theme2@tests.mozilla.org"],
+                                 callback_soon(function get_after_lock([a1, a2, a3, a4, a5, a6, a7, t1, t2]) {
       // Should be correctly recovered
       do_check_neq(a1, null);
       do_check_true(a1.isActive);
       do_check_false(a1.userDisabled);
       do_check_false(a1.appDisabled);
       do_check_eq(a1.pendingOperations, AddonManager.PENDING_NONE);
       do_check_true(isExtensionInAddonsList(profileDir, a1.id));
 
@@ -367,19 +365,18 @@ function run_test_1() {
       AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                    "addon2@tests.mozilla.org",
                                    "addon3@tests.mozilla.org",
                                    "addon4@tests.mozilla.org",
                                    "addon5@tests.mozilla.org",
                                    "addon6@tests.mozilla.org",
                                    "addon7@tests.mozilla.org",
                                    "theme1@tests.mozilla.org",
-                                   "theme2@tests.mozilla.org"], function([a1, a2, a3,
-                                                                          a4, a5, a6,
-                                                                          a7, t1, t2]) {
+                                   "theme2@tests.mozilla.org"],
+                                   callback_soon(function([a1, a2, a3, a4, a5, a6, a7, t1, t2]) {
         do_check_neq(a1, null);
         do_check_true(a1.isActive);
         do_check_false(a1.userDisabled);
         do_check_false(a1.appDisabled);
         do_check_eq(a1.pendingOperations, AddonManager.PENDING_NONE);
         do_check_true(isExtensionInAddonsList(profileDir, a1.id));
 
         do_check_neq(a2, null);
@@ -448,19 +445,18 @@ function run_test_1() {
         AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                      "addon2@tests.mozilla.org",
                                      "addon3@tests.mozilla.org",
                                      "addon4@tests.mozilla.org",
                                      "addon5@tests.mozilla.org",
                                      "addon6@tests.mozilla.org",
                                      "addon7@tests.mozilla.org",
                                      "theme1@tests.mozilla.org",
-                                     "theme2@tests.mozilla.org"], function([a1, a2, a3,
-                                                                            a4, a5, a6,
-                                                                            a7, t1, t2]) {
+                                     "theme2@tests.mozilla.org"],
+                                     callback_soon(function([a1, a2, a3, a4, a5, a6, a7, t1, t2]) {
           do_check_neq(a1, null);
           do_check_true(a1.isActive);
           do_check_false(a1.userDisabled);
           do_check_false(a1.appDisabled);
           do_check_eq(a1.pendingOperations, AddonManager.PENDING_NONE);
           do_check_true(isExtensionInAddonsList(profileDir, a1.id));
 
           do_check_neq(a2, null);
@@ -513,13 +509,13 @@ function run_test_1() {
           do_check_neq(t2, null);
           do_check_true(t2.isActive);
           do_check_false(t2.userDisabled);
           do_check_false(t2.appDisabled);
           do_check_eq(t2.pendingOperations, AddonManager.PENDING_NONE);
           do_check_true(isThemeInAddonsList(profileDir, t2.id));
 
           end_test();
-        });
-      });
-    });
-  });
+        }));
+      }));
+    }));
+  }));
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_locked2.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_locked2.js
@@ -100,17 +100,17 @@ function run_test() {
                                  "addon4@tests.mozilla.org",
                                  "addon5@tests.mozilla.org"],
                                 function([a1, a2, a3, a4, a5]) {
       a2.userDisabled = false;
       a3.userDisabled = true;
       a4.uninstall();
 
       installAllFiles([do_get_addon("test_locked2_5"),
-                       do_get_addon("test_locked2_6")], function() {
+                       do_get_addon("test_locked2_6")], function locked_installed() {
         do_check_neq(a1, null);
         do_check_true(a1.isActive);
         do_check_false(a1.userDisabled);
         do_check_false(a1.appDisabled);
         do_check_eq(a1.pendingOperations, AddonManager.PENDING_NONE);
         do_check_true(isExtensionInAddonsList(profileDir, a1.id));
 
         do_check_neq(a2, null);
--- a/toolkit/mozapps/extensions/test/xpcshell/test_locked_strictcompat.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_locked_strictcompat.js
@@ -165,42 +165,41 @@ function run_test() {
     a2.userDisabled = true;
     a4.userDisabled = true;
     a7.userDisabled = true;
     t2.userDisabled = false;
     a3.findUpdates({
       onUpdateFinished: function() {
         a4.findUpdates({
           onUpdateFinished: function() {
-            restartManager();
-
-            run_test_1();
+            do_execute_soon(run_test_1);
           }
         }, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
       }
     }, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
   });
 }
 
 function end_test() {
   testserver.stop(do_test_finished);
 }
 
 function run_test_1() {
+  restartManager();
+
   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                "addon2@tests.mozilla.org",
                                "addon3@tests.mozilla.org",
                                "addon4@tests.mozilla.org",
                                "addon5@tests.mozilla.org",
                                "addon6@tests.mozilla.org",
                                "addon7@tests.mozilla.org",
                                "theme1@tests.mozilla.org",
-                               "theme2@tests.mozilla.org"], function([a1, a2, a3,
-                                                                      a4, a5, a6,
-                                                                      a7, t1, t2]) {
+                               "theme2@tests.mozilla.org"],
+                               callback_soon(function([a1, a2, a3, a4, a5, a6, a7, t1, t2]) {
     do_check_neq(a1, null);
     do_check_true(a1.isActive);
     do_check_false(a1.userDisabled);
     do_check_false(a1.appDisabled);
     do_check_eq(a1.pendingOperations, AddonManager.PENDING_NONE);
     do_check_true(isExtensionInAddonsList(profileDir, a1.id));
 
     do_check_neq(a2, null);
@@ -277,19 +276,18 @@ function run_test_1() {
     AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                  "addon2@tests.mozilla.org",
                                  "addon3@tests.mozilla.org",
                                  "addon4@tests.mozilla.org",
                                  "addon5@tests.mozilla.org",
                                  "addon6@tests.mozilla.org",
                                  "addon7@tests.mozilla.org",
                                  "theme1@tests.mozilla.org",
-                                 "theme2@tests.mozilla.org"], function([a1, a2, a3,
-                                                                        a4, a5, a6,
-                                                                        a7, t1, t2]) {
+                                 "theme2@tests.mozilla.org"],
+                                 callback_soon(function([a1, a2, a3, a4, a5, a6, a7, t1, t2]) {
       // Should be correctly recovered
       do_check_neq(a1, null);
       do_check_true(a1.isActive);
       do_check_false(a1.userDisabled);
       do_check_false(a1.appDisabled);
       do_check_eq(a1.pendingOperations, AddonManager.PENDING_NONE);
       do_check_true(isExtensionInAddonsList(profileDir, a1.id));
 
@@ -365,19 +363,18 @@ function run_test_1() {
       AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                    "addon2@tests.mozilla.org",
                                    "addon3@tests.mozilla.org",
                                    "addon4@tests.mozilla.org",
                                    "addon5@tests.mozilla.org",
                                    "addon6@tests.mozilla.org",
                                    "addon7@tests.mozilla.org",
                                    "theme1@tests.mozilla.org",
-                                   "theme2@tests.mozilla.org"], function([a1, a2, a3,
-                                                                          a4, a5, a6,
-                                                                          a7, t1, t2]) {
+                                   "theme2@tests.mozilla.org"],
+                                   callback_soon(function([a1, a2, a3, a4, a5, a6, a7, t1, t2]) {
         do_check_neq(a1, null);
         do_check_true(a1.isActive);
         do_check_false(a1.userDisabled);
         do_check_false(a1.appDisabled);
         do_check_eq(a1.pendingOperations, AddonManager.PENDING_NONE);
         do_check_true(isExtensionInAddonsList(profileDir, a1.id));
 
         do_check_neq(a2, null);
@@ -446,19 +443,18 @@ function run_test_1() {
         AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                      "addon2@tests.mozilla.org",
                                      "addon3@tests.mozilla.org",
                                      "addon4@tests.mozilla.org",
                                      "addon5@tests.mozilla.org",
                                      "addon6@tests.mozilla.org",
                                      "addon7@tests.mozilla.org",
                                      "theme1@tests.mozilla.org",
-                                     "theme2@tests.mozilla.org"], function([a1, a2, a3,
-                                                                            a4, a5, a6,
-                                                                            a7, t1, t2]) {
+                                     "theme2@tests.mozilla.org"],
+                                     callback_soon(function([a1, a2, a3, a4, a5, a6, a7, t1, t2]) {
           do_check_neq(a1, null);
           do_check_true(a1.isActive);
           do_check_false(a1.userDisabled);
           do_check_false(a1.appDisabled);
           do_check_eq(a1.pendingOperations, AddonManager.PENDING_NONE);
           do_check_true(isExtensionInAddonsList(profileDir, a1.id));
 
           do_check_neq(a2, null);
@@ -511,13 +507,13 @@ function run_test_1() {
           do_check_neq(t2, null);
           do_check_true(t2.isActive);
           do_check_false(t2.userDisabled);
           do_check_false(t2.appDisabled);
           do_check_eq(t2.pendingOperations, AddonManager.PENDING_NONE);
           do_check_true(isThemeInAddonsList(profileDir, t2.id));
 
           end_test();
-        });
-      });
-    });
-  });
+        }));
+      }));
+    }));
+  }));
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_migrate4.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_migrate4.js
@@ -151,31 +151,31 @@ function prepare_profile() {
                                            "addon5@tests.mozilla.org",
                                            "addon6@tests.mozilla.org"],
                                            function([a1, a2, a3, a4, a5, a6]) {
                 a3.userDisabled = true;
                 a4.userDisabled = false;
   
                 a5.findUpdates({
                   onUpdateFinished: function() {
-                    shutdownManager();
-  
-                    perform_migration();
+                    do_execute_soon(perform_migration);
                   }
                 }, AddonManager.UPDATE_WHEN_USER_REQUESTED);
               });
             });
           }, "application/x-xpinstall");
         }
       }, AddonManager.UPDATE_WHEN_USER_REQUESTED);
     });
   });
 }
 
 function perform_migration() {
+  shutdownManager();
+  
   // Turn on disabling for all scopes
   Services.prefs.setIntPref("extensions.autoDisableScopes", 15);
 
   let dbfile = gProfD.clone();
   dbfile.append("extensions.sqlite");
   let db = AM_Cc["@mozilla.org/storage/service;1"].
            getService(AM_Ci.mozIStorageService).
            openDatabase(dbfile);
--- a/toolkit/mozapps/extensions/test/xpcshell/test_onPropertyChanged_appDisabled.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_onPropertyChanged_appDisabled.js
@@ -21,22 +21,22 @@ function run_test() {
 
   startupManager();
 
   AddonManager.strictCompatibility = false;
 
   AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
     do_check_neq(aAddon, null);
     aAddon.userDisabled = true;
-    restartManager();
-    run_test_1();
+    do_execute_soon(run_test_1);
   });
 }
 
 function run_test_1() {
+  restartManager();
   AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
     do_check_neq(aAddon, null);
     do_check_true(aAddon.userDisabled);
     do_check_false(aAddon.isActive);
     do_check_false(aAddon.appDisabled);
 
     prepare_test({
       "addon1@tests.mozilla.org": [
--- a/toolkit/mozapps/extensions/test/xpcshell/test_plugins.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_plugins.js
@@ -154,17 +154,17 @@ function run_test_3(p) {
 
   AddonManager.getAddonByID(gID, function(p) {
     do_check_neq(p, null);
     do_check_false(p.userDisabled);
     do_check_false(p.appDisabled);
     do_check_true(p.isActive);
     do_check_eq(p.name, "Test Plug-in");
 
-    run_test_4();
+    do_execute_soon(run_test_4);
   });
 }
 
 // Verify that after a restart the test plugin has the same ID
 function run_test_4() {
   restartManager();
 
   AddonManager.getAddonByID(gID, function(p) {
--- a/toolkit/mozapps/extensions/test/xpcshell/test_registry.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_registry.js
@@ -63,17 +63,17 @@ function run_test_1() {
     do_check_false(hasFlag(a1.permissions, AddonManager.PERM_CAN_UNINSTALL));
     do_check_eq(a1.scope, AddonManager.SCOPE_SYSTEM);
 
     do_check_neq(a2, null);
     do_check_true(a2.isActive);
     do_check_false(hasFlag(a2.permissions, AddonManager.PERM_CAN_UNINSTALL));
     do_check_eq(a2.scope, AddonManager.SCOPE_USER);
 
-    run_test_2();
+    do_execute_soon(run_test_2);
   });
 }
 
 // Tests whether uninstalling from the registry works
 function run_test_2() {
   MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
                         "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
                         "addon1@tests.mozilla.org", null);
@@ -83,17 +83,17 @@ function run_test_2() {
 
   restartManager();
 
   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                "addon2@tests.mozilla.org"], function([a1, a2]) {
     do_check_eq(a1, null);
     do_check_eq(a2, null);
 
-    run_test_3();
+    do_execute_soon(run_test_3);
   });
 }
 
 // Checks that the ID in the registry must match that in the install manifest
 function run_test_3() {
   MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
                         "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
                         "addon1@tests.mozilla.org", addon2Dir.path);
@@ -103,25 +103,25 @@ function run_test_3() {
 
   restartManager();
 
   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                "addon2@tests.mozilla.org"], function([a1, a2]) {
     do_check_eq(a1, null);
     do_check_eq(a2, null);
 
-    // Restarting with bad items in the registry should not force an EM restart
-    restartManager();
-
-    run_test_4();
+    do_execute_soon(run_test_4);
   });
 }
 
 // Tests whether an extension's ID can change without its directory changing
 function run_test_4() {
+  // Restarting with bad items in the registry should not force an EM restart
+  restartManager();
+
   MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
                         "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
                         "addon1@tests.mozilla.org", null);
   MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
                         "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
                         "addon2@tests.mozilla.org", null);
 
   restartManager();
--- a/toolkit/mozapps/extensions/test/xpcshell/test_startup.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_startup.js
@@ -110,17 +110,17 @@ userDir.append(gAppInfo.ID);
 registerDirectory("XREUSysExt", userDir.parent);
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
 
 var gCachePurged = false;
 
 // Set up the profile
 function run_test() {
-  do_test_pending();
+  do_test_pending("test_startup main");
 
   let obs = AM_Cc["@mozilla.org/observer-service;1"].
     getService(AM_Ci.nsIObserverService);
   obs.addObserver({
     observe: function(aSubject, aTopic, aData) {
       gCachePurged = true;
     }
   }, "startupcache-invalidate", false);
@@ -152,22 +152,22 @@ function run_test() {
     do_check_not_in_crash_annotation(addon1.id, addon1.version);
     do_check_eq(a2, null);
     do_check_not_in_crash_annotation(addon2.id, addon2.version);
     do_check_eq(a3, null);
     do_check_not_in_crash_annotation(addon3.id, addon3.version);
     do_check_eq(a4, null);
     do_check_eq(a5, null);
 
-    run_test_1();
+    do_execute_soon(run_test_1);
   });
 }
 
 function end_test() {
-  do_test_finished();
+  do_test_finished("test_startup main");
 }
 
 // Try to install all the items into the profile
 function run_test_1() {
   writeInstallRDFForExtension(addon1, profileDir);
   var dest = writeInstallRDFForExtension(addon2, profileDir);
   // Attempt to make this look like it was added some time in the past so
   // the change in run_test_2 makes the last modified time change.
@@ -270,17 +270,17 @@ function run_test_1() {
     do_check_false(isExtensionInAddonsList(profileDir, "addon7@tests.mozilla.org"));
     dest = profileDir.clone();
     dest.append(do_get_expected_addon_name("addon7@tests.mozilla.org"));
     do_check_false(dest.exists());
 
     AddonManager.getAddonsByTypes(["extension"], function(extensionAddons) {
       do_check_eq(extensionAddons.length, 3);
 
-      run_test_2();
+      do_execute_soon(run_test_2);
     });
   });
 }
 
 // Test that modified items are detected and items in other install locations
 // are ignored
 function run_test_2() {
   addon1.version = "1.1";
@@ -343,17 +343,17 @@ function run_test_2() {
     do_check_not_in_crash_annotation(addon3.id, addon3.version);
 
     do_check_eq(a4, null);
     do_check_false(isExtensionInAddonsList(profileDir, "addon4@tests.mozilla.org"));
 
     do_check_eq(a5, null);
     do_check_false(isExtensionInAddonsList(profileDir, "addon5@tests.mozilla.org"));
 
-    run_test_3();
+    do_execute_soon(run_test_3);
   });
 }
 
 // Check that removing items from the profile reveals their hidden versions.
 function run_test_3() {
   var dest = profileDir.clone();
   dest.append(do_get_expected_addon_name("addon1@tests.mozilla.org"));
   dest.remove(true);
@@ -408,17 +408,17 @@ function run_test_3() {
 
     do_check_eq(a5, null);
     do_check_false(isExtensionInAddonsList(profileDir, "addon5@tests.mozilla.org"));
 
     dest = profileDir.clone();
     dest.append(do_get_expected_addon_name("addon4@tests.mozilla.org"));
     do_check_false(dest.exists());
 
-    run_test_4();
+    do_execute_soon(run_test_4);
   });
 }
 
 // Test that disabling an install location works
 function run_test_4() {
   Services.prefs.setIntPref("extensions.enabledScopes", AddonManager.SCOPE_SYSTEM);
 
   gCachePurged = false;
@@ -447,17 +447,17 @@ function run_test_4() {
     do_check_false(isExtensionInAddonsList(profileDir, a2.id));
     do_check_false(isExtensionInAddonsList(userDir, a2.id));
     do_check_true(isExtensionInAddonsList(globalDir, a2.id));
     do_check_false(hasFlag(a2.permissions, AddonManager.PERM_CAN_UNINSTALL));
     do_check_false(hasFlag(a2.permissions, AddonManager.PERM_CAN_UPGRADE));
     do_check_in_crash_annotation(addon2.id, a2.version);
     do_check_eq(a2.scope, AddonManager.SCOPE_SYSTEM);
 
-    run_test_5();
+    do_execute_soon(run_test_5);
   });
 }
 
 // Switching disabled locations works
 function run_test_5() {
   Services.prefs.setIntPref("extensions.enabledScopes", AddonManager.SCOPE_USER);
 
   gCachePurged = false;
@@ -492,17 +492,17 @@ function run_test_5() {
     do_check_false(isExtensionInAddonsList(profileDir, a2.id));
     do_check_true(isExtensionInAddonsList(userDir, a2.id));
     do_check_false(isExtensionInAddonsList(globalDir, a2.id));
     do_check_false(hasFlag(a2.permissions, AddonManager.PERM_CAN_UNINSTALL));
     do_check_false(hasFlag(a2.permissions, AddonManager.PERM_CAN_UPGRADE));
     do_check_in_crash_annotation(addon2.id, a2.version);
     do_check_eq(a2.scope, AddonManager.SCOPE_USER);
 
-    run_test_6();
+    do_execute_soon(run_test_6);
   });
 }
 
 // Resetting the pref makes everything visible again
 function run_test_6() {
   Services.prefs.clearUserPref("extensions.enabledScopes");
 
   gCachePurged = false;
@@ -537,17 +537,17 @@ function run_test_6() {
     do_check_false(isExtensionInAddonsList(profileDir, a2.id));
     do_check_true(isExtensionInAddonsList(userDir, a2.id));
     do_check_false(isExtensionInAddonsList(globalDir, a2.id));
     do_check_false(hasFlag(a2.permissions, AddonManager.PERM_CAN_UNINSTALL));
     do_check_false(hasFlag(a2.permissions, AddonManager.PERM_CAN_UPGRADE));
     do_check_in_crash_annotation(addon2.id, a2.version);
     do_check_eq(a2.scope, AddonManager.SCOPE_USER);
 
-    run_test_7();
+    do_execute_soon(run_test_7);
   });
 }
 
 // Check that items in the profile hide the others again.
 function run_test_7() {
   addon1.version = "1.2";
   writeInstallRDFForExtension(addon1, profileDir);
   var dest = userDir.clone();
@@ -596,17 +596,17 @@ function run_test_7() {
     do_check_false(isExtensionInAddonsList(profileDir, "addon3@tests.mozilla.org"));
 
     do_check_eq(a4, null);
     do_check_false(isExtensionInAddonsList(profileDir, "addon4@tests.mozilla.org"));
 
     do_check_eq(a5, null);
     do_check_false(isExtensionInAddonsList(profileDir, "addon5@tests.mozilla.org"));
 
-    run_test_8();
+    do_execute_soon(run_test_8);
   });
 }
 
 // Disabling all locations still leaves the profile working
 function run_test_8() {
   Services.prefs.setIntPref("extensions.enabledScopes", 0);
 
   gCachePurged = false;
@@ -635,17 +635,17 @@ function run_test_8() {
     do_check_in_crash_annotation(addon1.id, a1.version);
     do_check_eq(a1.scope, AddonManager.SCOPE_PROFILE);
 
     do_check_eq(a2, null);
     do_check_false(isExtensionInAddonsList(profileDir, "addon2@tests.mozilla.org"));
     do_check_false(isExtensionInAddonsList(userDir, "addon2@tests.mozilla.org"));
     do_check_false(isExtensionInAddonsList(globalDir, "addon2@tests.mozilla.org"));
 
-    run_test_9();
+    do_execute_soon(run_test_9);
   });
 }
 
 // More hiding and revealing
 function run_test_9() {
   Services.prefs.clearUserPref("extensions.enabledScopes", 0);
 
   var dest = userDir.clone();
@@ -696,17 +696,17 @@ function run_test_9() {
     do_check_false(isExtensionInAddonsList(profileDir, "addon3@tests.mozilla.org"));
 
     do_check_eq(a4, null);
     do_check_false(isExtensionInAddonsList(profileDir, "addon4@tests.mozilla.org"));
 
     do_check_eq(a5, null);
     do_check_false(isExtensionInAddonsList(profileDir, "addon5@tests.mozilla.org"));
 
-    run_test_10();
+    do_execute_soon(run_test_10);
   });
 }
 
 // Checks that a removal from one location and an addition in another location
 // for the same item is handled
 function run_test_10() {
   var dest = profileDir.clone();
   dest.append(do_get_expected_addon_name("addon1@tests.mozilla.org"));
@@ -753,17 +753,17 @@ function run_test_10() {
     do_check_false(isExtensionInAddonsList(profileDir, "addon3@tests.mozilla.org"));
 
     do_check_eq(a4, null);
     do_check_false(isExtensionInAddonsList(profileDir, "addon4@tests.mozilla.org"));
 
     do_check_eq(a5, null);
     do_check_false(isExtensionInAddonsList(profileDir, "addon5@tests.mozilla.org"));
 
-    run_test_11();
+    do_execute_soon(run_test_11);
   });
 }
 
 // This should remove any remaining items
 function run_test_11() {
   var dest = userDir.clone();
   dest.append(do_get_expected_addon_name("addon1@tests.mozilla.org"));
   dest.remove(true);
@@ -806,17 +806,17 @@ function run_test_11() {
     do_check_false(isExtensionInAddonsList(globalDir, "addon1@tests.mozilla.org"));
     do_check_false(isExtensionInAddonsList(globalDir, "addon2@tests.mozilla.org"));
     do_check_false(isExtensionInAddonsList(globalDir, "addon3@tests.mozilla.org"));
     do_check_false(isExtensionInAddonsList(globalDir, "addon4@tests.mozilla.org"));
     do_check_false(isExtensionInAddonsList(globalDir, "addon5@tests.mozilla.org"));
     do_check_not_in_crash_annotation(addon1.id, addon1.version);
     do_check_not_in_crash_annotation(addon2.id, addon2.version);
 
-    run_test_12();
+    do_execute_soon(run_test_12);
   });
 }
 
 // Test that auto-disabling for specific scopes works
 function run_test_12() {
   Services.prefs.setIntPref("extensions.autoDisableScopes", AddonManager.SCOPE_USER);
 
   writeInstallRDFForExtension(addon1, profileDir);
--- a/toolkit/mozapps/extensions/test/xpcshell/test_strictcompatibility.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_strictcompatibility.js
@@ -141,17 +141,17 @@ function do_check_compat_status(aStrict,
     do_check_eq(a6.appDisabled, !aAddonCompat[5]);
     do_check_false(a6.strictCompatibility);
 
     do_check_neq(a7, null);
     do_check_eq(a7.isCompatible, aAddonCompat[6]);
     do_check_eq(a7.appDisabled, !aAddonCompat[6]);
     do_check_false(a7.strictCompatibility);
 
-    aCallback();
+    do_execute_soon(aCallback);
   });
 }
 
 
 function run_test() {
   do_test_pending();
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
   
@@ -195,9 +195,9 @@ function run_test_4() {
   do_check_compat_status(true, [true, false, false, false, false, false, false], run_test_5);
 }
 
 function run_test_5() {
   do_print("Test 5");
   Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false);
   Services.prefs.setCharPref(PREF_EM_MIN_COMPAT_APP_VERSION, "0.4");
   do_check_compat_status(false, [true, true, false, false, false, false, true], do_test_finished);
-}
\ No newline at end of file
+}
--- a/toolkit/mozapps/extensions/test/xpcshell/test_syncGUID.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_syncGUID.js
@@ -21,16 +21,19 @@ function run_test() {
 
   run_next_test();
 }
 
 add_test(function test_getter_and_setter() {
   // Our test add-on requires a restart.
   let listener = {
     onInstallEnded: function onInstallEnded() {
+     AddonManager.removeInstallListener(listener);
+     // never restart directly inside an onInstallEnded handler!
+     do_execute_soon(function getter_setter_install_ended() {
       restartManager();
 
       AddonManager.getAddonByID(addonId, function(addon) {
 
         do_check_neq(addon, null);
         do_check_neq(addon.syncGUID, null);
         do_check_true(addon.syncGUID.length >= 9);
 
@@ -41,20 +44,19 @@ add_test(function test_getter_and_setter
         do_check_eq(newGUID, addon.syncGUID);
 
         // Verify change made it to DB.
         AddonManager.getAddonByID(addonId, function(newAddon) {
           do_check_neq(newAddon, null);
           do_check_eq(newGUID, newAddon.syncGUID);
         });
 
-        AddonManager.removeInstallListener(listener);
-
         run_next_test();
       });
+     });
     }
   };
 
   AddonManager.addInstallListener(listener);
 
   AddonManager.getInstallForFile(do_get_addon("test_install1"),
                                  function(install) {
     install.install();
@@ -75,17 +77,18 @@ add_test(function test_error_on_duplicat
 
   let installCount = 0;
 
   let listener = {
     onInstallEnded: function onInstallEnded() {
       installCount++;
 
       if (installCount == installNames.length) {
-        AddonManager.removeInstallListener(listener);
+       AddonManager.removeInstallListener(listener);
+       do_execute_soon(function duplicate_syncguid_install_ended() {
         restartManager();
 
         AddonManager.getAddonsByIDs(installIDs, function(addons) {
           let initialGUID = addons[1].syncGUID;
 
           try {
             addons[1].syncGUID = addons[0].syncGUID;
             do_throw("Should not get here.");
@@ -96,16 +99,17 @@ add_test(function test_error_on_duplicat
             restartManager();
 
             AddonManager.getAddonByID(installIDs[1], function(addon) {
               do_check_eq(initialGUID, addon.syncGUID);
               run_next_test();
             });
           }
         });
+       });
       }
     }
   };
 
   AddonManager.addInstallListener(listener);
   let getInstallCB = function(install) { install.install(); };
 
   for each (let name in installNames) {
--- a/toolkit/mozapps/extensions/test/xpcshell/test_theme.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_theme.js
@@ -116,17 +116,17 @@ function run_test() {
     do_check_false(t2.skinnable);
     do_check_true(t2.foreignInstall);
     do_check_eq(t2.screenshots, null);
     do_check_false(isThemeInAddonsList(profileDir, t2.id));
     do_check_false(hasFlag(t2.permissions, AddonManager.PERM_CAN_DISABLE));
     do_check_true(hasFlag(t2.permissions, AddonManager.PERM_CAN_ENABLE));
     do_check_eq(t2.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_ENABLE);
 
-    run_test_1();
+    do_execute_soon(run_test_1);
   });
 }
 
 function end_test() {
   do_test_finished();
 }
 
 // Checks enabling one theme disables the others
@@ -146,17 +146,17 @@ function run_test_1() {
     ensure_test_completed();
     do_check_false(hasFlag(t2.permissions, AddonManager.PERM_CAN_DISABLE));
     do_check_false(hasFlag(t2.permissions, AddonManager.PERM_CAN_ENABLE));
 
     do_check_true(t1.userDisabled);
     do_check_false(hasFlag(t1.permissions, AddonManager.PERM_CAN_DISABLE));
     do_check_true(hasFlag(t1.permissions, AddonManager.PERM_CAN_ENABLE));
 
-    check_test_1();
+    do_execute_soon(check_test_1);
   });
 }
 
 function check_test_1() {
   restartManager();
   do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "theme2/1.0");
 
   AddonManager.getAddonsByIDs(["theme1@tests.mozilla.org",
@@ -176,17 +176,17 @@ function check_test_1() {
     do_check_true(t2.isActive);
     do_check_true(isThemeInAddonsList(profileDir, t2.id));
     do_check_false(hasFlag(t2.permissions, AddonManager.PERM_CAN_DISABLE));
     do_check_false(hasFlag(t2.permissions, AddonManager.PERM_CAN_ENABLE));
     do_check_eq(t2.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_UNINSTALL |
                                                AddonManager.OP_NEEDS_RESTART_DISABLE);
     do_check_false(gLWThemeChanged);
 
-    run_test_2();
+    do_execute_soon(run_test_2);
   });
 }
 
 // Removing the active theme should fall back to the default (not ideal in this
 // case since we don't have the default theme installed)
 function run_test_2() {
   var dest = profileDir.clone();
   dest.append(do_get_expected_addon_name("theme2@tests.mozilla.org"));
@@ -204,17 +204,17 @@ function run_test_2() {
     do_check_false(isThemeInAddonsList(profileDir, t1.id));
     do_check_false(hasFlag(t1.permissions, AddonManager.PERM_CAN_DISABLE));
     do_check_true(hasFlag(t1.permissions, AddonManager.PERM_CAN_ENABLE));
 
     do_check_eq(t2, null);
     do_check_false(isThemeInAddonsList(profileDir, "theme2@tests.mozilla.org"));
     do_check_false(gLWThemeChanged);
 
-    run_test_3();
+    do_execute_soon(run_test_3);
   });
 }
 
 // Installing a lightweight theme should happen instantly and disable the default theme
 function run_test_3() {
   writeInstallRDFForExtension({
     id: "theme2@tests.mozilla.org",
     version: "1.0",
@@ -301,17 +301,17 @@ function run_test_3() {
           do_check_true(a.userDisabled);
         }
       });
       do_check_true(seen);
 
       do_check_true(gLWThemeChanged);
       gLWThemeChanged = false;
 
-      run_test_4();
+      do_execute_soon(run_test_4);
     });
   });
 }
 
 // Installing a second lightweight theme should disable the first with no restart
 function run_test_4() {
   prepare_test({
     "1@personas.mozilla.org": [
@@ -379,17 +379,17 @@ function run_test_4() {
           do_check_true(a.userDisabled);
         }
       });
       do_check_true(seen);
 
       do_check_true(gLWThemeChanged);
       gLWThemeChanged = false;
 
-      run_test_5();
+      do_execute_soon(run_test_5);
     });
   });
 }
 
 // Switching to a custom theme should disable the lightweight theme and require
 // a restart. Cancelling that should also be possible.
 function run_test_5() {
   prepare_test({
@@ -437,17 +437,17 @@ function run_test_5() {
     do_check_false(t2.userDisabled);
     do_check_true(hasFlag(AddonManager.PENDING_ENABLE, t2.pendingOperations));
     do_check_true(p2.isActive);
     do_check_true(p2.userDisabled);
     do_check_true(hasFlag(AddonManager.PENDING_DISABLE, p2.pendingOperations));
     do_check_true(hasFlag(AddonManager.PERM_CAN_ENABLE, p2.permissions));
     do_check_false(gLWThemeChanged);
 
-    check_test_5();
+    do_execute_soon(check_test_5);
   });
 }
 
 function check_test_5() {
   restartManager();
 
   AddonManager.getAddonsByIDs(["2@personas.mozilla.org",
                                "theme2@tests.mozilla.org"], function([p2, t2]) {
@@ -456,17 +456,17 @@ function check_test_5() {
     do_check_false(hasFlag(AddonManager.PENDING_ENABLE, t2.pendingOperations));
     do_check_false(p2.isActive);
     do_check_true(p2.userDisabled);
     do_check_false(hasFlag(AddonManager.PENDING_DISABLE, p2.pendingOperations));
 
     do_check_true(gLWThemeChanged);
     gLWThemeChanged = false;
 
-    run_test_6();
+    do_execute_soon(run_test_6);
   });
 }
 
 // Switching from a custom theme to a lightweight theme should require a restart
 function run_test_6() {
   prepare_test({
     "2@personas.mozilla.org": [
       "onEnabling",
@@ -511,17 +511,17 @@ function run_test_6() {
     do_check_false(p2.isActive);
     do_check_false(p2.userDisabled);
     do_check_true(hasFlag(AddonManager.PENDING_ENABLE, p2.pendingOperations));
     do_check_true(t2.isActive);
     do_check_true(t2.userDisabled);
     do_check_true(hasFlag(AddonManager.PENDING_DISABLE, t2.pendingOperations));
     do_check_false(gLWThemeChanged);
 
-    check_test_6();
+    do_execute_soon(check_test_6);
   });
 }
 
 function check_test_6() {
   restartManager();
 
   AddonManager.getAddonsByIDs(["2@personas.mozilla.org",
                                "theme2@tests.mozilla.org"], function([p2, t2]) {
@@ -530,17 +530,17 @@ function check_test_6() {
     do_check_false(hasFlag(AddonManager.PENDING_ENABLE, p2.pendingOperations));
     do_check_false(t2.isActive);
     do_check_true(t2.userDisabled);
     do_check_false(hasFlag(AddonManager.PENDING_DISABLE, t2.pendingOperations));
 
     do_check_true(gLWThemeChanged);
     gLWThemeChanged = false;
 
-    run_test_7();
+    do_execute_soon(run_test_7);
   });
 }
 
 // Uninstalling a lightweight theme should not require a restart
 function run_test_7() {
   prepare_test({
     "1@personas.mozilla.org": [
       ["onUninstalling", false],
@@ -550,17 +550,17 @@ function run_test_7() {
 
   AddonManager.getAddonByID("1@personas.mozilla.org", function(p1) {
     p1.uninstall();
 
     ensure_test_completed();
     do_check_eq(LightweightThemeManager.usedThemes.length, 1);
     do_check_false(gLWThemeChanged);
 
-    run_test_8();
+    do_execute_soon(run_test_8);
   });
 }
 
 // Uninstalling a lightweight theme in use should not require a restart and it
 // should reactivate the default theme
 // Also, uninstalling a lightweight theme in use should send a
 // "lightweight-theme-styling-update" notification through the observer service
 function run_test_8() {
@@ -579,17 +579,17 @@ function run_test_8() {
     p2.uninstall();
 
     ensure_test_completed();
     do_check_eq(LightweightThemeManager.usedThemes.length, 0);
 
     do_check_true(gLWThemeChanged);
     gLWThemeChanged = false;
 
-    run_test_9();
+    do_execute_soon(run_test_9);
   });
 }
 
 // Uninstalling a theme not in use should not require a restart
 function run_test_9() {
   AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) {
     prepare_test({
       "theme1@tests.mozilla.org": [
@@ -601,17 +601,17 @@ function run_test_9() {
     t1.uninstall();
 
     ensure_test_completed();
 
     AddonManager.getAddonByID("theme1@tests.mozilla.org", function(newt1) {
       do_check_eq(newt1, null);
       do_check_false(gLWThemeChanged);
 
-      run_test_10();
+      do_execute_soon(run_test_10);
     });
   });
 }
 
 // Uninstalling a custom theme in use should require a restart
 function run_test_10() {
   AddonManager.getAddonByID("theme2@tests.mozilla.org", function(oldt2) {
     prepare_test({
@@ -647,25 +647,25 @@ function run_test_10() {
         ]
       });
 
       t2.uninstall();
 
       ensure_test_completed();
       do_check_false(gLWThemeChanged);
 
-      restartManager();
-
-      run_test_11();
+      do_execute_soon(run_test_11);
     });
   });
 }
 
 // Installing a custom theme not in use should not require a restart
 function run_test_11() {
+  restartManager();
+
   prepare_test({ }, [
     "onNewInstall"
   ]);
 
   AddonManager.getInstallForFile(do_get_addon("test_theme"), function(install) {
     ensure_test_completed();
 
     do_check_neq(install, null);
@@ -693,17 +693,17 @@ function check_test_11() {
   AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) {
     do_check_neq(t1, null);
     var previewSpec = do_get_addon_root_uri(profileDir, "theme1@tests.mozilla.org") + "preview.png";
     do_check_eq(t1.screenshots.length, 1);
     do_check_eq(t1.screenshots[0], previewSpec);
     do_check_true(t1.skinnable);
     do_check_false(gLWThemeChanged);
 
-    run_test_12();
+    do_execute_soon(run_test_12);
   });
 }
 
 // Updating a custom theme not in use should not require a restart
 function run_test_12() {
   prepare_test({ }, [
     "onNewInstall"
   ]);
@@ -731,17 +731,17 @@ function run_test_12() {
   });
 }
 
 function check_test_12() {
   AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) {
     do_check_neq(t1, null);
     do_check_false(gLWThemeChanged);
 
-    run_test_13();
+    do_execute_soon(run_test_13);
   });
 }
 
 // Updating a custom theme in use should require a restart
 function run_test_13() {
   AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) {
     prepare_test({
       "theme1@tests.mozilla.org": [
@@ -788,17 +788,17 @@ function check_test_13() {
 
   AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) {
     do_check_neq(t1, null);
     do_check_true(t1.isActive);
     do_check_false(gLWThemeChanged);
     t1.uninstall();
     restartManager();
 
-    run_test_14();
+    do_execute_soon(run_test_14);
   });
 }
 
 // Switching from a lightweight theme to the default theme should not require
 // a restart
 function run_test_14() {
   LightweightThemeManager.currentTheme = {
     id: "1",
@@ -832,17 +832,17 @@ function run_test_14() {
     ensure_test_completed();
 
     do_check_false(d.userDisabled);
     do_check_true(d.isActive);
 
     do_check_true(gLWThemeChanged);
     gLWThemeChanged = false;
 
-    run_test_15();
+    do_execute_soon(run_test_15);
   });
 }
 
 // Upgrading the application with a custom theme in use should not disable it
 function run_test_15() {
   restartManager();
 
   installAllFiles([do_get_addon("test_theme")], function() {
@@ -870,17 +870,17 @@ function run_test_15() {
           do_check_true(d.userDisabled);
           do_check_false(d.appDisabled);
           do_check_false(d.isActive);
 
           do_check_false(t1.userDisabled);
           do_check_false(t1.appDisabled);
           do_check_true(t1.isActive);
 
-          run_test_16();
+          do_execute_soon(run_test_16);
         });
       });
     });
   });
 }
 
 // Upgrading the application with a custom theme in use should disable it if it
 // is no longer compatible
@@ -893,17 +893,17 @@ function run_test_16() {
     do_check_false(d.userDisabled);
     do_check_false(d.appDisabled);
     do_check_true(d.isActive);
 
     do_check_true(t1.userDisabled);
     do_check_true(t1.appDisabled);
     do_check_false(t1.isActive);
 
-    run_test_17();
+    do_execute_soon(run_test_17);
   });
 }
 
 // Verifies that if the selected theme pref is changed by a different version
 // of the application that we correctly reset it when it points to an
 // incompatible theme
 function run_test_17() {
   restartManager("2");
@@ -919,17 +919,17 @@ function run_test_17() {
     do_check_false(d.userDisabled);
     do_check_false(d.appDisabled);
     do_check_true(d.isActive);
 
     do_check_true(t1.userDisabled);
     do_check_true(t1.appDisabled);
     do_check_false(t1.isActive);
 
-    run_test_18();
+    do_execute_soon(run_test_18);
   });
 }
 
 // Disabling the active theme should switch back to the default theme
 function run_test_18() {
   restartManager(2);
 
   AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) {
@@ -973,17 +973,17 @@ function run_test_18() {
         do_check_false(d.userDisabled);
         do_check_false(d.appDisabled);
         do_check_true(d.isActive);
 
         do_check_true(t1.userDisabled);
         do_check_false(t1.appDisabled);
         do_check_false(t1.isActive);
 
-        run_test_19();
+        do_execute_soon(run_test_19);
       });
     });
   });
 }
 
 // Disabling the active persona should switch back to the default theme
 function run_test_19() {
   AddonManager.getAddonsByIDs(["default@tests.mozilla.org",
@@ -1014,17 +1014,17 @@ function run_test_19() {
     do_check_false(d.userDisabled);
     do_check_false(d.appDisabled);
     do_check_true(d.isActive);
 
     do_check_true(p1.userDisabled);
     do_check_false(p1.appDisabled);
     do_check_false(p1.isActive);
 
-    run_test_20();
+    do_execute_soon(run_test_20);
   });
 }
 
 // Tests that you cannot disable the default theme
 function run_test_20() {
   AddonManager.getAddonByID("default@tests.mozilla.org", function(d) {
     do_check_false(d.userDisabled);
     do_check_false(d.appDisabled);
@@ -1032,17 +1032,17 @@ function run_test_20() {
 
     try {
       d.userDisabled = true;
       do_throw("Disabling the default theme should throw an exception");
     }
     catch (e) {
     }
 
-    run_test_21();
+    do_execute_soon(run_test_21);
   });
 }
 
 // Tests that cached copies of a lightweight theme have the right permissions
 // and pendingOperations during the onEnabling event
 function run_test_21() {
   AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) {
     // Switch to a custom theme so we can test pendingOperations properly.
--- a/toolkit/mozapps/extensions/test/xpcshell/test_uninstall.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_uninstall.js
@@ -65,41 +65,41 @@ function run_test_1() {
     do_check_in_crash_annotation(addon1.id, addon1.version);
 
     ensure_test_completed();
 
     AddonManager.getAddonsWithOperationsByTypes(null, function(list) {
       do_check_eq(list.length, 1);
       do_check_eq(list[0].id, "addon1@tests.mozilla.org");
 
-      check_test_1();
+      do_execute_soon(check_test_1);
     });
   });
 }
 
 function check_test_1() {
   restartManager();
 
   AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
     do_check_eq(a1, null);
     do_check_false(isExtensionInAddonsList(profileDir, "addon1@tests.mozilla.org"));
     do_check_not_in_crash_annotation(addon1.id, addon1.version);
 
     var dest = profileDir.clone();
     dest.append(do_get_expected_addon_name("addon1@tests.mozilla.org"));
     do_check_false(dest.exists());
     writeInstallRDFForExtension(addon1, profileDir);
-    restartManager();
-
-    run_test_2();
+    do_execute_soon(run_test_2);
   });
 }
 
 // Cancelling the uninstall should send onOperationCancelled
 function run_test_2() {
+  restartManager();
+
   prepare_test({
     "addon1@tests.mozilla.org": [
       "onUninstalling"
     ]
   });
 
   AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
     do_check_neq(a1, null);
@@ -117,17 +117,17 @@ function run_test_2() {
         "onOperationCancelled"
       ]
     });
     a1.cancelUninstall();
     do_check_eq(a1.pendingOperations, 0);
 
     ensure_test_completed();
 
-    check_test_2();
+    do_execute_soon(check_test_2);
   });
 }
 
 function check_test_2() {
   restartManager();
 
   AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
     do_check_neq(a1, null);
@@ -175,23 +175,24 @@ function check_test_3() {
       "addon1@tests.mozilla.org": [
         "onOperationCancelled"
       ]
     });
     a1.cancelUninstall();
     ensure_test_completed();
     do_check_true(hasFlag(AddonManager.PENDING_DISABLE, a1.pendingOperations));
 
-    restartManager();
-    run_test_4();
+    do_execute_soon(run_test_4);
   });
 }
 
 // Test that uninstalling an inactive item should happen without a restart
 function run_test_4() {
+  restartManager();
+
   AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
     do_check_neq(a1, null);
     do_check_false(a1.isActive);
     do_check_true(a1.userDisabled);
     do_check_false(isExtensionInAddonsList(profileDir, a1.id));
 
     prepare_test({
       "addon1@tests.mozilla.org": [
--- a/toolkit/mozapps/extensions/test/xpcshell/test_update.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_update.js
@@ -227,26 +227,26 @@ function check_test_2() {
       do_check_true(isExtensionInAddonsList(profileDir, a1.id));
       do_check_eq(a1.applyBackgroundUpdates, AddonManager.AUTOUPDATE_DISABLE);
       do_check_eq(a1.releaseNotesURI.spec, "http://example.com/updateInfo.xhtml");
       do_check_true(a1.foreignInstall);
       do_check_neq(a1.syncGUID, null);
       do_check_eq(originalSyncGUID, a1.syncGUID);
 
       a1.uninstall();
-      restartManager();
-
-      run_test_3();
+      do_execute_soon(run_test_3);
     });
   });
 }
 
 
 // Check that an update check finds compatibility updates and applies them
 function run_test_3() {
+  restartManager();
+
   AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
     do_check_neq(a2, null);
     do_check_true(a2.isActive);
     do_check_true(a2.isCompatible);
     do_check_false(a2.appDisabled);
     do_check_true(a2.isCompatibleWith("0"));
 
     a2.findUpdates({
@@ -257,24 +257,24 @@ function run_test_3() {
       },
 
       onUpdateAvailable: function(addon, install) {
         do_throw("Should not have seen an available update");
       },
 
       onNoUpdateAvailable: function(addon) {
         do_check_eq(addon, a2);
-        restartManager();
-        check_test_3();
+        do_execute_soon(check_test_3);
       }
     }, AddonManager.UPDATE_WHEN_USER_REQUESTED);
   });
 }
 
 function check_test_3() {
+  restartManager();
   AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
     do_check_neq(a2, null);
     do_check_true(a2.isActive);
     do_check_true(a2.isCompatible);
     do_check_false(a2.appDisabled);
     a2.uninstall();
 
     run_test_4();
@@ -338,39 +338,39 @@ function run_test_5() {
       },
 
       onUpdateAvailable: function(addon, install) {
         do_throw("Should not have seen an available update");
       },
 
       onNoUpdateAvailable: function(addon) {
         do_check_true(this.sawUpdate);
-        restartManager();
-        check_test_5();
+        do_execute_soon(check_test_5);
       }
     }, AddonManager.UPDATE_WHEN_USER_REQUESTED, "3.0");
   });
 }
 
 function check_test_5() {
+  restartManager();
   AddonManager.getAddonByID("addon3@tests.mozilla.org", function(a3) {
     do_check_neq(a3, null);
     do_check_false(a3.isActive);
     do_check_false(a3.isCompatible);
     do_check_true(a3.appDisabled);
 
     a3.uninstall();
-    restartManager();
-
-    run_test_6();
+    do_execute_soon(run_test_6);
   });
 }
 
 // Test that background update checks work
 function run_test_6() {
+  restartManager();
+
   writeInstallRDFForExtension({
     id: "addon1@tests.mozilla.org",
     version: "1.0",
     updateURL: "http://localhost:4444/data/test_update.rdf",
     targetApplications: [{
       id: "xpcshell@tests.mozilla.org",
       minVersion: "1",
       maxVersion: "1"
@@ -762,17 +762,17 @@ function run_test_8() {
 
       let updateListener = {
         onUpdateAvailable: function(addon, update) {
           // Dummy so the update checker knows we care about new versions
         },
 
         onUpdateFinished: function(addon, error) {
           if (--count == 0)
-            run_next_test();
+            do_execute_soon(run_next_test);
         }
       };
 
       a1.findUpdates(updateListener, AddonManager.UPDATE_WHEN_USER_REQUESTED);
       a2.findUpdates(compatListener, AddonManager.UPDATE_WHEN_ADDON_INSTALLED);
       a3.findUpdates(updateListener, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
       a4.findUpdates(updateListener, AddonManager.UPDATE_WHEN_NEW_APP_DETECTED, "2");
       a5.findUpdates(compatListener, AddonManager.UPDATE_WHEN_NEW_APP_INSTALLED);
@@ -838,27 +838,27 @@ function run_test_11() {
 function run_test_12() {
   restartManager();
 
   AddonManager.getAddonByID("addon4@tests.mozilla.org", function(a4) {
     do_check_true(a4.isActive);
     do_check_true(a4.isCompatible);
 
     a4.uninstall();
-    restartManager();
-
-    run_test_13();
+    do_execute_soon(run_test_13);
   });
 }
 
 // Tests that a compatibility update is passed to the listener when there is
 // compatibility info for the current version of the app but not for the
 // version of the app that the caller requested an update check for, when
 // strict compatibility checking is disabled.
 function run_test_13() {
+  restartManager();
+
   // Not initially compatible but the update check will make it compatible
   writeInstallRDFForExtension({
     id: "addon7@tests.mozilla.org",
     version: "1.0",
     updateURL: "http://localhost:4444/data/test_update.rdf",
     targetApplications: [{
       id: "xpcshell@tests.mozilla.org",
       minVersion: "0",
@@ -882,40 +882,40 @@ function run_test_13() {
       },
 
       onUpdateAvailable: function(addon, install) {
         do_throw("Should not have seen an available update");
       },
 
       onUpdateFinished: function(addon) {
         do_check_true(addon.isCompatible);
-        restartManager();
-        check_test_13();
+        do_execute_soon(check_test_13);
       }
     }, AddonManager.UPDATE_WHEN_NEW_APP_DETECTED, "3.0");
   });
 }
 
 function check_test_13() {
+  restartManager();
   AddonManager.getAddonByID("addon7@tests.mozilla.org", function(a7) {
     do_check_neq(a7, null);
     do_check_true(a7.isActive);
     do_check_true(a7.isCompatible);
     do_check_false(a7.appDisabled);
 
     a7.uninstall();
-    restartManager();
-
-    run_test_14();
+    do_execute_soon(run_test_14);
   });
 }
 
 // Test that background update checks doesn't update an add-on that isn't
 // allowed to update automatically.
 function run_test_14() {
+  restartManager();
+
   // Have an add-on there that will be updated so we see some events from it
   writeInstallRDFForExtension({
     id: "addon1@tests.mozilla.org",
     version: "1.0",
     updateURL: "http://localhost:4444/data/test_update.rdf",
     targetApplications: [{
       id: "xpcshell@tests.mozilla.org",
       minVersion: "1",
@@ -966,56 +966,56 @@ function run_test_14() {
       },
 
       onInstallStarted: function(aInstall) {
         do_check_eq(aInstall.existingAddon.id, "addon1@tests.mozilla.org");
       },
 
       onInstallEnded: function(aInstall) {
         do_check_eq(aInstall.existingAddon.id, "addon1@tests.mozilla.org");
-        check_test_14(aInstall);
+        do_check_eq(aInstall.existingAddon.pendingUpgrade.install, aInstall);
+
+        do_execute_soon(check_test_14);
       },
 
       onInstallFailed: function(aInstall) {
         do_throw("Should not have seen onInstallFailed event");
       },
 
       onInstallCancelled: function(aInstall) {
         do_throw("Should not have seen onInstallCancelled event");
       },
     });
 
     // Fake a timer event
     gInternalManager.notify(null);
   });
 }
 
-function check_test_14(install) {
-  do_check_eq(install.existingAddon.pendingUpgrade.install, install);
-
+function check_test_14() {
   restartManager();
   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                "addon8@tests.mozilla.org"], function([a1, a8]) {
     do_check_neq(a1, null);
     do_check_eq(a1.version, "2.0");
     a1.uninstall();
 
     do_check_neq(a8, null);
     do_check_eq(a8.version, "1.0");
     a8.uninstall();
 
-    restartManager();
-
-    run_test_15();
+    do_execute_soon(run_test_15);
   });
 }
 
 // Test that background update checks doesn't update an add-on that is
 // pending uninstall
 function run_test_15() {
+  restartManager();
+
   // Have an add-on there that will be updated so we see some events from it
   writeInstallRDFForExtension({
     id: "addon1@tests.mozilla.org",
     version: "1.0",
     updateURL: "http://localhost:4444/data/test_update.rdf",
     targetApplications: [{
       id: "xpcshell@tests.mozilla.org",
       minVersion: "1",
@@ -1067,91 +1067,95 @@ function run_test_15() {
       },
 
       onInstallStarted: function(aInstall) {
         do_check_eq(aInstall.existingAddon.id, "addon1@tests.mozilla.org");
       },
 
       onInstallEnded: function(aInstall) {
         do_check_eq(aInstall.existingAddon.id, "addon1@tests.mozilla.org");
-        check_test_15(aInstall);
+        do_execute_soon(check_test_15);
       },
 
       onInstallFailed: function(aInstall) {
         do_throw("Should not have seen onInstallFailed event");
       },
 
       onInstallCancelled: function(aInstall) {
         do_throw("Should not have seen onInstallCancelled event");
       },
     });
 
     // Fake a timer event
     gInternalManager.notify(null);
   });
 }
 
-function check_test_15(aInstall) {
+function check_test_15() {
   restartManager();
   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                "addon8@tests.mozilla.org"], function([a1, a8]) {
     do_check_neq(a1, null);
     do_check_eq(a1.version, "2.0");
     a1.uninstall();
 
     do_check_eq(a8, null);
 
-    restartManager();
-
-    run_test_16();
+    do_execute_soon(run_test_16);
   });
 }
 
 function run_test_16() {
   restartManager();
 
+  restartManager();
+
   let url = "http://localhost:4444/addons/test_install2_1.xpi";
   AddonManager.getInstallForURL(url, function(aInstall) {
     aInstall.addListener({
       onInstallEnded: function() {
+       do_execute_soon(function install_2_1_ended() {
         restartManager();
 
         AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a1) {
           do_check_neq(a1.syncGUID, null);
           let oldGUID = a1.syncGUID;
 
           let url = "http://localhost:4444/addons/test_install2_2.xpi";
           AddonManager.getInstallForURL(url, function(aInstall) {
             aInstall.addListener({
               onInstallEnded: function() {
+               do_execute_soon(function install_2_2_ended() {
                 restartManager();
 
                 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
                   do_check_neq(a2.syncGUID, null);
                   do_check_eq(oldGUID, a2.syncGUID);
 
                   a2.uninstall();
-                  restartManager();
-
-                  run_test_17();
+                  do_execute_soon(run_test_17);
                 });
+               });
               }
             });
             aInstall.install();
           }, "application/x-xpinstall");
         });
+       });
       }
     });
     aInstall.install();
   }, "application/x-xpinstall");
 }
 
 // Test that the update check correctly observes the
 // extensions.strictCompatibility pref and compatibility overrides.
 function run_test_17() {
+  restartManager();
+
   writeInstallRDFForExtension({
     id: "addon9@tests.mozilla.org",
     version: "1.0",
     updateURL: "http://localhost:4444/data/test_update.rdf",
     targetApplications: [{
       id: "xpcshell@tests.mozilla.org",
       minVersion: "0.1",
       maxVersion: "0.2"
@@ -1164,32 +1168,32 @@ function run_test_17() {
     onNewInstall: function(aInstall) {
       if (aInstall.existingAddon.id != "addon9@tests.mozilla.org")
         do_throw("Saw unexpected onNewInstall for " + aInstall.existingAddon.id);
       do_check_eq(aInstall.version, "3.0");
     },
     onDownloadFailed: function(aInstall) {
       AddonManager.getAddonByID("addon9@tests.mozilla.org", function(a9) {
         a9.uninstall();
-        restartManager();
         do_execute_soon(run_test_18);
       });
     }
   });
 
   Services.prefs.setCharPref(PREF_GETADDONS_BYIDS_PERFORMANCE,
                              "http://localhost:4444/data/test_update.xml");
   Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, true);
   // Fake a timer event
   gInternalManager.notify(null);
 }
 
 // Tests that compatibility updates are applied to addons when the updated
 // compatibility data wouldn't match with strict compatibility enabled.
 function run_test_18() {
+  restartManager();
   writeInstallRDFForExtension({
     id: "addon10@tests.mozilla.org",
     version: "1.0",
     updateURL: "http://localhost:4444/data/test_update.rdf",
     targetApplications: [{
       id: "xpcshell@tests.mozilla.org",
       minVersion: "0.1",
       maxVersion: "0.2"
@@ -1207,26 +1211,26 @@ function run_test_18() {
       },
 
       onUpdateAvailable: function() {
         do_throw("Should not have seen an available update");
       },
 
       onUpdateFinished: function() {
         a10.uninstall();
-        restartManager();
-        run_test_19();
+        do_execute_soon(run_test_19);
       }
     }, AddonManager.UPDATE_WHEN_USER_REQUESTED);
   });
 }
 
 // Test that the update check correctly observes when an addon opts-in to
 // strict compatibility checking.
 function run_test_19() {
+  restartManager();
   writeInstallRDFForExtension({
     id: "addon11@tests.mozilla.org",
     version: "1.0",
     updateURL: "http://localhost:4444/data/test_update.rdf",
     targetApplications: [{
       id: "xpcshell@tests.mozilla.org",
       minVersion: "0.1",
       maxVersion: "0.2"
@@ -1244,26 +1248,26 @@ function run_test_19() {
       },
 
       onUpdateAvailable: function() {
         do_throw("Should not have seen an available update");
       },
 
       onUpdateFinished: function() {
         a11.uninstall();
-        restartManager();
-        run_test_20();
+        do_execute_soon(run_test_20);
       }
    }, AddonManager.UPDATE_WHEN_USER_REQUESTED);
   });
 }
 
 // Test that the update succeeds when the update.rdf URN contains a type prefix
 // different from the add-on type
 function run_test_20() {
+  restartManager();
   writeInstallRDFForExtension({
     id: "addon12@tests.mozilla.org",
     version: "1.0",
     updateURL: "http://localhost:4444/data/test_update.rdf",
     targetApplications: [{
       id: "xpcshell@tests.mozilla.org",
       minVersion: "1",
       maxVersion: "1"
--- a/toolkit/mozapps/extensions/test/xpcshell/test_update_strictcompat.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_update_strictcompat.js
@@ -221,26 +221,26 @@ function check_test_2() {
     AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
       do_check_neq(a1, null);
       do_check_eq(a1.version, "2.0");
       do_check_true(isExtensionInAddonsList(profileDir, a1.id));
       do_check_eq(a1.applyBackgroundUpdates, AddonManager.AUTOUPDATE_DISABLE);
       do_check_eq(a1.releaseNotesURI.spec, "http://example.com/updateInfo.xhtml");
 
       a1.uninstall();
-      restartManager();
-
-      run_test_3();
+      do_execute_soon(run_test_3);
     });
   });
 }
 
 
 // Check that an update check finds compatibility updates and applies them
 function run_test_3() {
+  restartManager();
+
   AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
     do_check_neq(a2, null);
     do_check_false(a2.isActive);
     do_check_false(a2.isCompatible);
     do_check_true(a2.appDisabled);
     do_check_true(a2.isCompatibleWith("0"));
 
     a2.findUpdates({
@@ -251,24 +251,24 @@ function run_test_3() {
       },
 
       onUpdateAvailable: function(addon, install) {
         do_throw("Should not have seen an available update");
       },
 
       onNoUpdateAvailable: function(addon) {
         do_check_eq(addon, a2);
-        restartManager();
-        check_test_3();
+        do_execute_soon(check_test_3);
       }
     }, AddonManager.UPDATE_WHEN_USER_REQUESTED);
   });
 }
 
 function check_test_3() {
+  restartManager();
   AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
     do_check_neq(a2, null);
     do_check_true(a2.isActive);
     do_check_true(a2.isCompatible);
     do_check_false(a2.appDisabled);
     a2.uninstall();
 
     run_test_4();
@@ -332,39 +332,39 @@ function run_test_5() {
       },
 
       onUpdateAvailable: function(addon, install) {
         do_throw("Should not have seen an available update");
       },
 
       onNoUpdateAvailable: function(addon) {
         do_check_true(this.sawUpdate);
-        restartManager();
-        check_test_5();
+        do_execute_soon(check_test_5);
       }
     }, AddonManager.UPDATE_WHEN_USER_REQUESTED, "3.0");
   });
 }
 
 function check_test_5() {
+  restartManager();
   AddonManager.getAddonByID("addon3@tests.mozilla.org", function(a3) {
     do_check_neq(a3, null);
     do_check_false(a3.isActive);
     do_check_false(a3.isCompatible);
     do_check_true(a3.appDisabled);
 
     a3.uninstall();
-    restartManager();
-
-    run_test_6();
+    do_execute_soon(run_test_6);
   });
 }
 
 // Test that background update checks work
 function run_test_6() {
+  restartManager();
+
   writeInstallRDFForExtension({
     id: "addon1@tests.mozilla.org",
     version: "1.0",
     updateURL: "http://localhost:4444/data/test_update.rdf",
     targetApplications: [{
       id: "xpcshell@tests.mozilla.org",
       minVersion: "1",
       maxVersion: "1"
@@ -402,24 +402,24 @@ function check_test_6(install) {
   do_check_eq(install.existingAddon.pendingUpgrade.install, install);
 
   restartManager();
   AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
     do_check_neq(a1, null);
     do_check_eq(a1.version, "2.0");
     do_check_eq(a1.releaseNotesURI.spec, "http://example.com/updateInfo.xhtml");
     a1.uninstall();
-    restartManager();
-
-    run_test_7();
+    do_execute_soon(run_test_7);
   });
 }
 
 // Test that background update checks work for lightweight themes
 function run_test_7() {
+  restartManager();
+
   LightweightThemeManager.currentTheme = {
     id: "1",
     version: "1",
     name: "Test LW Theme",
     description: "A test theme",
     author: "Mozilla",
     homepageURL: "http://localhost:4444/data/index.html",
     headerURL: "http://localhost:4444/data/header.png",
@@ -669,28 +669,28 @@ function run_test_8() {
 
         restartManager();
         run_test_9();
       }
 
       let compatListener = {
         onUpdateFinished: function(addon, error) {
           if (--count == 0)
-            run_next_test();
+            do_execute_soon(run_next_test);
         }
       };
 
       let updateListener = {
         onUpdateAvailable: function(addon, update) {
           // Dummy so the update checker knows we care about new versions
         },
 
         onUpdateFinished: function(addon, error) {
           if (--count == 0)
-            run_next_test();
+            do_execute_soon(run_next_test);
         }
       };
 
       a1.findUpdates(updateListener, AddonManager.UPDATE_WHEN_USER_REQUESTED);
       a2.findUpdates(compatListener, AddonManager.UPDATE_WHEN_ADDON_INSTALLED);
       a3.findUpdates(updateListener, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
       a4.findUpdates(updateListener, AddonManager.UPDATE_WHEN_NEW_APP_DETECTED, "2");
       a5.findUpdates(compatListener, AddonManager.UPDATE_WHEN_NEW_APP_INSTALLED);
@@ -756,26 +756,26 @@ function run_test_11() {
 function run_test_12() {
   restartManager();
 
   AddonManager.getAddonByID("addon4@tests.mozilla.org", function(a4) {
     do_check_false(a4.isActive);
     do_check_false(a4.isCompatible);
 
     a4.uninstall();
-    restartManager();
-
-    run_test_13();
+    do_execute_soon(run_test_13);
   });
 }
 
 // Tests that no compatibility update is passed to the listener when there is
 // compatibility info for the current version of the app but not for the
 // version of the app that the caller requested an update check for.
 function run_test_13() {
+  restartManager();
+
   // Not initially compatible but the update check will make it compatible
   writeInstallRDFForExtension({
     id: "addon7@tests.mozilla.org",
     version: "1.0",
     updateURL: "http://localhost:4444/data/test_update.rdf",
     targetApplications: [{
       id: "xpcshell@tests.mozilla.org",
       minVersion: "0",
@@ -799,40 +799,40 @@ function run_test_13() {
       },
 
       onUpdateAvailable: function(addon, install) {
         do_throw("Should not have seen an available update");
       },
 
       onUpdateFinished: function(addon) {
         do_check_true(addon.isCompatible);
-        restartManager();
-        check_test_13();
+        do_execute_soon(check_test_13);
       }
     }, AddonManager.UPDATE_WHEN_NEW_APP_DETECTED, "3.0");
   });
 }
 
 function check_test_13() {
+  restartManager();
   AddonManager.getAddonByID("addon7@tests.mozilla.org", function(a7) {
     do_check_neq(a7, null);
     do_check_true(a7.isActive);
     do_check_true(a7.isCompatible);
     do_check_false(a7.appDisabled);
 
     a7.uninstall();
-    restartManager();
-
-    run_test_14();
+    do_execute_soon(run_test_14);
   });
 }
 
 // Test that background update checks doesn't update an add-on that isn't
 // allowed to update automatically.
 function run_test_14() {
+  restartManager();
+
   // Have an add-on there that will be updated so we see some events from it
   writeInstallRDFForExtension({
     id: "addon1@tests.mozilla.org",
     version: "1.0",
     updateURL: "http://localhost:4444/data/test_update.rdf",
     targetApplications: [{
       id: "xpcshell@tests.mozilla.org",
       minVersion: "1",
@@ -883,56 +883,55 @@ function run_test_14() {
       },
 
       onInstallStarted: function(aInstall) {
         do_check_eq(aInstall.existingAddon.id, "addon1@tests.mozilla.org");
       },
 
       onInstallEnded: function(aInstall) {
         do_check_eq(aInstall.existingAddon.id, "addon1@tests.mozilla.org");
-        check_test_14(aInstall);
+        do_check_eq(aInstall.existingAddon.pendingUpgrade.install, aInstall);
+        do_execute_soon(check_test_14);
       },
 
       onInstallFailed: function(aInstall) {
         do_throw("Should not have seen onInstallFailed event");
       },
 
       onInstallCancelled: function(aInstall) {
         do_throw("Should not have seen onInstallCancelled event");
       },
     });
 
     // Fake a timer event
     gInternalManager.notify(null);
   });
 }
 
-function check_test_14(install) {
-  do_check_eq(install.existingAddon.pendingUpgrade.install, install);
-
+function check_test_14() {
   restartManager();
   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                "addon8@tests.mozilla.org"], function([a1, a8]) {
     do_check_neq(a1, null);
     do_check_eq(a1.version, "2.0");
     a1.uninstall();
 
     do_check_neq(a8, null);
     do_check_eq(a8.version, "1.0");
     a8.uninstall();
 
-    restartManager();
-
-    run_test_15();
+    do_execute_soon(run_test_15);
   });
 }
 
 // Test that background update checks doesn't update an add-on that is
 // pending uninstall
 function run_test_15() {
+  restartManager();
+
   // Have an add-on there that will be updated so we see some events from it
   writeInstallRDFForExtension({
     id: "addon1@tests.mozilla.org",
     version: "1.0",
     updateURL: "http://localhost:4444/data/test_update.rdf",
     targetApplications: [{
       id: "xpcshell@tests.mozilla.org",
       minVersion: "1",
@@ -984,52 +983,52 @@ function run_test_15() {
       },
 
       onInstallStarted: function(aInstall) {
         do_check_eq(aInstall.existingAddon.id, "addon1@tests.mozilla.org");
       },
 
       onInstallEnded: function(aInstall) {
         do_check_eq(aInstall.existingAddon.id, "addon1@tests.mozilla.org");
-        check_test_15(aInstall);
+        do_execute_soon(check_test_15);
       },
 
       onInstallFailed: function(aInstall) {
         do_throw("Should not have seen onInstallFailed event");
       },
 
       onInstallCancelled: function(aInstall) {
         do_throw("Should not have seen onInstallCancelled event");
       },
     });
 
     // Fake a timer event
     gInternalManager.notify(null);
   });
 }
 
-function check_test_15(aInstall) {
+function check_test_15() {
   restartManager();
   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                "addon8@tests.mozilla.org"], function([a1, a8]) {
     do_check_neq(a1, null);
     do_check_eq(a1.version, "2.0");
     a1.uninstall();
 
     do_check_eq(a8, null);
 
-    restartManager();
-
-    run_test_16();
+    do_execute_soon(run_test_16);
   });
 }
 
 // Test that the update check correctly observes the
 // extensions.strictCompatibility pref and compatibility overrides.
 function run_test_16() {
+  restartManager();
+
   writeInstallRDFForExtension({
     id: "addon9@tests.mozilla.org",
     version: "1.0",
     updateURL: "http://localhost:4444/data/test_update.rdf",
     targetApplications: [{
       id: "xpcshell@tests.mozilla.org",
       minVersion: "0.1",
       maxVersion: "0.2"
--- a/toolkit/mozapps/extensions/test/xpcshell/test_updateid.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_updateid.js
@@ -44,17 +44,20 @@ function run_test() {
 
 function end_test() {
   testserver.stop(do_test_finished);
 }
 
 function installUpdate(aInstall, aCallback) {
   aInstall.addListener({
     onInstallEnded: function(aInstall) {
-      aCallback(aInstall);
+      // give the startup time to run
+      do_execute_soon(function() {
+        aCallback(aInstall);
+      });
     }
   });
 
   aInstall.install();
 }
 
 // Verify that an update to an add-on with a new ID uninstalls the old add-on
 function run_test_1() {
@@ -108,26 +111,26 @@ function check_test_1(install) {
       do_check_neq(a2, null);
       do_check_neq(a2.syncGUID, null);
 
       // The Sync GUID should change when the ID changes
       do_check_neq(a1SyncGUID, a2.syncGUID);
 
       a2.uninstall();
 
-      restartManager();
-      shutdownManager();
-
-      run_test_2();
+      do_execute_soon(run_test_2);
     });
   });
 }
 
 // Test that when the new add-on already exists we just upgrade that
 function run_test_2() {
+  restartManager();
+  shutdownManager();
+
   writeInstallRDFForExtension({
     id: "addon1@tests.mozilla.org",
     version: "1.0",
     updateURL: "http://localhost:4444/data/test_updateid.rdf",
     targetApplications: [{
       id: "xpcshell@tests.mozilla.org",
       minVersion: "1",
       maxVersion: "1"
@@ -174,26 +177,26 @@ function check_test_2(install) {
                                  "addon2@tests.mozilla.org"], function([a1, a2]) {
       // Should have uninstalled the old and installed the new
       do_check_neq(a1, null);
       do_check_neq(a2, null);
 
       a1.uninstall();
       a2.uninstall();
 
-      restartManager();
-      shutdownManager();
-
-      run_test_3();
+      do_execute_soon(run_test_3);
     });
   });
 }
 
 // Test that we rollback correctly when removing the old add-on fails
 function run_test_3() {
+  restartManager();
+  shutdownManager();
+
   // This test only works on Windows
   if (!("nsIWindowsRegKey" in AM_Ci)) {
     run_test_4();
     return;
   }
 
   writeInstallRDFForExtension({
     id: "addon1@tests.mozilla.org",
@@ -256,27 +259,27 @@ function check_test_3(install) {
       AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                    "addon2@tests.mozilla.org"], function([a1, a2]) {
         // Should have installed the new add-on
         do_check_eq(a1, null);
         do_check_neq(a2, null);
 
         a2.uninstall();
 
-        restartManager();
-        shutdownManager();
-
-        run_test_4();
+        do_execute_soon(run_test_4);
       });
     });
   });
 }
 
 // Tests that upgrading to a bootstrapped add-on works but requires a restart
 function run_test_4() {
+  restartManager();
+  shutdownManager();
+
   writeInstallRDFForExtension({
     id: "addon2@tests.mozilla.org",
     version: "2.0",
     updateURL: "http://localhost:4444/data/test_updateid.rdf",
     targetApplications: [{
       id: "xpcshell@tests.mozilla.org",
       minVersion: "1",
       maxVersion: "1"
@@ -320,17 +323,17 @@ function check_test_4() {
                                  "addon3@tests.mozilla.org"], function([a2, a3]) {
       // Should have updated
       do_check_eq(a2, null);
       do_check_neq(a3, null);
 
       do_check_eq(getInstalledVersion(), 3);
       do_check_eq(getActiveVersion(), 3);
 
-      run_test_5();
+      do_execute_soon(run_test_5);
     });
   });
 }
 
 // Tests that upgrading to another bootstrapped add-on works without a restart
 function run_test_5() {
   AddonManager.getAddonByID("addon3@tests.mozilla.org", function(a3) {
     do_check_neq(a3, null);
--- a/toolkit/mozapps/extensions/test/xpcshell/test_upgrade.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_upgrade.js
@@ -114,17 +114,17 @@ function run_test_1() {
 
     do_check_neq(a3, null);
     do_check_false(isExtensionInAddonsList(profileDir, a3.id));
 
     do_check_neq(a4, null);
     do_check_true(isExtensionInAddonsList(globalDir, a4.id));
     do_check_eq(a4.version, "1.0");
 
-    run_test_2();
+    do_execute_soon(run_test_2);
   });
 }
 
 // Test that upgrading the application doesn't disable now incompatible add-ons
 function run_test_2() {
   // Upgrade the extension
   var dest = writeInstallRDFForExtension({
     id: "addon4@tests.mozilla.org",
@@ -153,17 +153,17 @@ function run_test_2() {
 
     do_check_neq(a3, null);
     do_check_true(isExtensionInAddonsList(profileDir, a3.id));
 
     do_check_neq(a4, null);
     do_check_true(isExtensionInAddonsList(globalDir, a4.id));
     do_check_eq(a4.version, "2.0");
 
-    run_test_3();
+    do_execute_soon(run_test_3);
   });
 }
 
 // Test that nothing changes when only the build ID changes.
 function run_test_3() {
   // Upgrade the extension
   var dest = writeInstallRDFForExtension({
     id: "addon4@tests.mozilla.org",
--- a/toolkit/mozapps/extensions/test/xpcshell/test_upgrade_strictcompat.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_upgrade_strictcompat.js
@@ -117,17 +117,17 @@ function run_test_1() {
 
     do_check_neq(a3, null);
     do_check_false(isExtensionInAddonsList(profileDir, a3.id));
 
     do_check_neq(a4, null);
     do_check_true(isExtensionInAddonsList(globalDir, a4.id));
     do_check_eq(a4.version, "1.0");
 
-    run_test_2();
+    do_execute_soon(run_test_2);
   });
 }
 
 // Test that upgrading the application disables now incompatible add-ons
 function run_test_2() {
   // Upgrade the extension
   var dest = writeInstallRDFForExtension({
     id: "addon4@tests.mozilla.org",
@@ -156,17 +156,17 @@ function run_test_2() {
 
     do_check_neq(a3, null);
     do_check_true(isExtensionInAddonsList(profileDir, a3.id));
 
     do_check_neq(a4, null);
     do_check_true(isExtensionInAddonsList(globalDir, a4.id));
     do_check_eq(a4.version, "2.0");
 
-    run_test_3();
+    do_execute_soon(run_test_3);
   });
 }
 
 // Test that nothing changes when only the build ID changes.
 function run_test_3() {
   // Upgrade the extension
   var dest = writeInstallRDFForExtension({
     id: "addon4@tests.mozilla.org",