Bug 957123 - Fix the use of File.prototype.close() by a few AddonManager tests. r=Unfocused
☠☠ backed out by cff6ebdce225 ☠ ☠
authorDavid Rajchenbach-Teller <dteller@mozilla.com>
Fri, 07 Feb 2014 10:52:45 -0500
changeset 184777 3d460520c085280acf3e0ac927a8d807430c7cbd
parent 184776 9beffa3991770db5c7264ca6eecd34ebbf545b9d
child 184778 039dcbcaec4e2779eae71f2904c4a4cc4b5a5a0d
push id3503
push userraliiev@mozilla.com
push dateMon, 28 Apr 2014 18:51:11 +0000
treeherdermozilla-beta@c95ac01e332e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersUnfocused
bugs957123
milestone30.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 957123 - Fix the use of File.prototype.close() by a few AddonManager tests. r=Unfocused
toolkit/mozapps/extensions/test/xpcshell/head_addons.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
--- a/toolkit/mozapps/extensions/test/xpcshell/head_addons.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/head_addons.js
@@ -18,16 +18,21 @@ const PREF_GETADDONS_BYIDS_PERFORMANCE  
 // Forcibly end the test if it runs longer than 15 minutes
 const TIMEOUT_MS = 900000;
 
 Components.utils.import("resource://gre/modules/AddonRepository.jsm");
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 Components.utils.import("resource://gre/modules/FileUtils.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
 Components.utils.import("resource://gre/modules/NetUtil.jsm");
+Components.utils.import("resource://gre/modules/Promise.jsm");
+Components.utils.import("resource://gre/modules/Task.jsm");
+Components.utils.import("resource://gre/modules/osfile.jsm");
+
+Services.prefs.setBoolPref("toolkit.osfile.log", true);
 
 // We need some internal bits of AddonManager
 let AMscope = Components.utils.import("resource://gre/modules/AddonManager.jsm");
 let AddonManager = AMscope.AddonManager;
 let AddonManagerInternal = AMscope.AddonManagerInternal;
 // Mock out AddonManager's reference to the AsyncShutdown module so we can shut
 // down AddonManager from the test
 let MockAsyncShutdown = {
@@ -439,16 +444,17 @@ function shutdownManager() {
   gAppInfo.annotations = {};
 
   // Force the XPIProvider provider to reload to better
   // simulate real-world usage.
   let XPIscope = Components.utils.import("resource://gre/modules/XPIProvider.jsm");
   // This would be cleaner if I could get it as the rejection reason from
   // the AddonManagerInternal.shutdown() promise
   gXPISaveError = XPIscope.XPIProvider._shutdownError;
+  do_print("gXPISaveError set to: " + gXPISaveError);
   AddonManagerPrivate.unregisterProvider(XPIscope.XPIProvider);
   Components.utils.unload("resource://gre/modules/XPIProvider.jsm");
 }
 
 function loadAddonsList() {
   function readDirectories(aSection) {
     var dirs = [];
     var keys = parser.getKeys(aSection);
@@ -686,27 +692,48 @@ function writeInstallRDFForExtension(aDa
 
 /**
  * Sets the last modified time of the extension, usually to trigger an update
  * of its metadata. If the extension is unpacked, this function assumes that
  * the extension contains only the install.rdf file.
  *
  * @param aExt   a file pointing to either the packed extension or its unpacked directory.
  * @param aTime  the time to which we set the lastModifiedTime of the extension
+ *
+ * @deprecated Please use promiseSetExtensionModifiedTime instead
  */
 function setExtensionModifiedTime(aExt, aTime) {
   aExt.lastModifiedTime = aTime;
   if (aExt.isDirectory()) {
     let entries = aExt.directoryEntries
                       .QueryInterface(AM_Ci.nsIDirectoryEnumerator);
     while (entries.hasMoreElements())
       setExtensionModifiedTime(entries.nextFile, aTime);
     entries.close();
   }
 }
+function promiseSetExtensionModifiedTime(aPath, aTime) {
+  return Task.spawn(function* () {
+    yield OS.File.setDates(aPath, aTime, aTime);
+    let entries, iterator;
+    try {
+      let iterator = new OS.File.DirectoryIterator(aPath);
+      entries = yield iterator.nextBatch();
+    } catch (ex if ex instanceof OS.File.Error) {
+      return;
+    } finally {
+      if (iterator) {
+        iterator.close();
+      }
+    }
+    for (let entry of entries) {
+      yield promiseSetExtensionModifiedTime(entry.path, aTime);
+    }
+  });
+}
 
 /**
  * Manually installs an XPI file into an install location by either copying the
  * XPI there or extracting it depending on whether unpacking is being tested
  * or not.
  *
  * @param aXPIFile
  *        The XPI file to install.
@@ -1077,32 +1104,43 @@ function completeAllInstalls(aInstalls, 
  *          The callback to call when all installs have finished
  * @param   aIgnoreIncompatible
  *          Optional parameter to ignore add-ons that are incompatible in
  *          aome way with the application
  */
 function installAllFiles(aFiles, aCallback, aIgnoreIncompatible) {
   let count = aFiles.length;
   let installs = [];
-
+  function callback() {
+    if (aCallback) {
+      aCallback();
+    }
+  }
   aFiles.forEach(function(aFile) {
     AddonManager.getInstallForFile(aFile, function(aInstall) {
       if (!aInstall)
         do_throw("No AddonInstall created for " + aFile.path);
       do_check_eq(aInstall.state, AddonManager.STATE_DOWNLOADED);
 
       if (!aIgnoreIncompatible || !aInstall.addon.appDisabled)
         installs.push(aInstall);
 
       if (--count == 0)
-        completeAllInstalls(installs, aCallback);
+        completeAllInstalls(installs, callback);
     });
   });
 }
 
+function promiseInstallAllFiles(aFiles, aIgnoreIncompatible) {
+  let deferred = Promise.defer();
+  installAllFiles(aFiles, deferred.resolve, aIgnoreIncompatible);
+  return deferred.promise;
+
+}
+
 if ("nsIWindowsRegKey" in AM_Ci) {
   var MockRegistry = {
     LOCAL_MACHINE: {},
     CURRENT_USER: {},
     CLASSES_ROOT: {},
 
     getRoot: function(aRoot) {
       switch (aRoot) {
@@ -1468,8 +1506,22 @@ function saveJSON(aData, aFile) {
  */
 function callback_soon(aFunction) {
   return function(...args) {
     do_execute_soon(function() {
       aFunction.apply(null, args);
     }, aFunction.name ? "delayed callback " + aFunction.name : "delayed callback");
   }
 }
+
+/**
+ * A promise-based variant of AddonManager.getAddonsByIDs.
+ *
+ * @param {array} list As the first argument of AddonManager.getAddonsByIDs
+ * @return {promise}
+ * @resolve {array} The list of add-ons sent by AddonManaget.getAddonsByIDs to
+ * its callback.
+ */
+function promiseAddonsByIDs(list) {
+  let deferred = Promise.defer();
+  AddonManager.getAddonsByIDs(list, deferred.resolve);
+  return deferred.promise;
+}
--- a/toolkit/mozapps/extensions/test/xpcshell/test_locked.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_locked.js
@@ -129,18 +129,17 @@ var theme2 = {
     minVersion: "2",
     maxVersion: "2"
   }]
 };
 
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
 
-function run_test() {
-  do_test_pending();
+add_task(function* init() {
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2", "2");
 
   writeInstallRDFForExtension(addon1, profileDir);
   writeInstallRDFForExtension(addon2, profileDir);
   writeInstallRDFForExtension(addon3, profileDir);
   writeInstallRDFForExtension(addon4, profileDir);
   writeInstallRDFForExtension(addon5, profileDir);
   writeInstallRDFForExtension(addon6, profileDir);
@@ -149,383 +148,382 @@ function run_test() {
   writeInstallRDFForExtension(theme2, profileDir);
 
   // Startup the profile and setup the initial state
   startupManager();
 
   // New profile so new add-ons are ignored
   check_startup_changes(AddonManager.STARTUP_CHANGE_INSTALLED, []);
 
-  AddonManager.getAddonsByIDs(["addon2@tests.mozilla.org",
+  let [a2, a3, a4, a7, t2] =
+    yield promiseAddonsByIDs(["addon2@tests.mozilla.org",
                                "addon3@tests.mozilla.org",
                                "addon4@tests.mozilla.org",
                                "addon7@tests.mozilla.org",
-                               "theme2@tests.mozilla.org"], function([a2, a3, a4,
-                                                                      a7, t2]) {
-    // Set up the initial state
-    a2.userDisabled = true;
-    a4.userDisabled = true;
-    a7.userDisabled = true;
-    t2.userDisabled = false;
-    a3.findUpdates({
-      onUpdateFinished: function() {
-        a4.findUpdates({
-          onUpdateFinished: function() {
-            // Let the updates finish before restarting the manager
-            do_execute_soon(run_test_1);
-          }
-        }, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
-      }
-    }, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
-  });
-}
+                               "theme2@tests.mozilla.org"]);
+  let deferredUpdateFinished = Promise.defer();
+  // Set up the initial state
+  a2.userDisabled = true;
+  a4.userDisabled = true;
+  a7.userDisabled = true;
+  t2.userDisabled = false;
+  a3.findUpdates({
+    onUpdateFinished: function() {
+      a4.findUpdates({
+        onUpdateFinished: function() {
+          // Let the updates finish before restarting the manager
+          deferredUpdateFinished.resolve();
+        }
+      }, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
+    }
+  }, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
+
+  yield deferredUpdateFinished.promise;
+});
+
+
+add_task(function* run_test_1() {
+  restartManager();
+  let [a1, a2, a3, a4, a5, a6, a7, t1, t2] =
+    yield promiseAddonsByIDs(["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"]);
+
+  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);
+  do_check_false(a2.isActive);
+  do_check_true(a2.userDisabled);
+  do_check_false(a2.appDisabled);
+  do_check_eq(a2.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_false(isExtensionInAddonsList(profileDir, a2.id));
+
+  do_check_neq(a3, null);
+  do_check_true(a3.isActive);
+  do_check_false(a3.userDisabled);
+  do_check_false(a3.appDisabled);
+  do_check_eq(a3.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_true(isExtensionInAddonsList(profileDir, a3.id));
+
+  do_check_neq(a4, null);
+  do_check_false(a4.isActive);
+  do_check_true(a4.userDisabled);
+  do_check_false(a4.appDisabled);
+  do_check_eq(a4.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_false(isExtensionInAddonsList(profileDir, a4.id));
+
+  do_check_neq(a5, null);
+  do_check_true(a5.isActive);
+  do_check_false(a5.userDisabled);
+  do_check_false(a5.appDisabled);
+  do_check_eq(a5.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_true(isExtensionInAddonsList(profileDir, a5.id));
+
+  do_check_neq(a6, null);
+  do_check_true(a6.isActive);
+  do_check_false(a6.userDisabled);
+  do_check_false(a6.appDisabled);
+  do_check_eq(a6.pendingOperations, AddonManager.PENDING_NONE);
+
+  do_check_neq(a7, null);
+  do_check_false(a7.isActive);
+  do_check_true(a7.userDisabled);
+  do_check_false(a7.appDisabled);
+  do_check_eq(a7.pendingOperations, AddonManager.PENDING_NONE);
+
+  do_check_neq(t1, null);
+  do_check_false(t1.isActive);
+  do_check_true(t1.userDisabled);
+  do_check_false(t1.appDisabled);
+  do_check_eq(t1.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_false(isThemeInAddonsList(profileDir, t1.id));
+
+  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));
 
-function end_test() {
-  testserver.stop(do_test_finished);
-}
+  // Open another handle on the JSON DB with as much Unix and Windows locking
+  // as we can to simulate some other process interfering with it
+  shutdownManager();
+  do_print("Locking " + gExtensionsJSON.path);
+  let options = {
+    winShare: 0
+  };
+  if (OS.Constants.libc.O_EXLOCK)
+    options.unixFlags = OS.Constants.libc.O_EXLOCK;
+
+  let file = yield OS.File.open(gExtensionsJSON.path, {read:true, write:true, existing:true}, options);
+
+  let filePermissions = gExtensionsJSON.permissions;
+  if (!OS.Constants.Win) {
+    gExtensionsJSON.permissions = 0;
+  }
+  startupManager(false);
+
+  // Shouldn't have seen any startup changes
+  check_startup_changes(AddonManager.STARTUP_CHANGE_INSTALLED, []);
+
+  // Accessing the add-ons should open and recover the database
+  [a1, a2, a3, a4, a5, a6, a7, t1, t2] =
+    yield promiseAddonsByIDs(["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"]);
+
+   // 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));
+
+   // Should be correctly recovered
+   do_check_neq(a2, null);
+   do_check_false(a2.isActive);
+   do_check_true(a2.userDisabled);
+   do_check_false(a2.appDisabled);
+   do_check_eq(a2.pendingOperations, AddonManager.PENDING_NONE);
+   do_check_false(isExtensionInAddonsList(profileDir, a2.id));
 
-function run_test_1() {
-  restartManager();
-  AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
+   // The compatibility update won't be recovered but it should still be
+   // active for this session
+   do_check_neq(a3, null);
+   do_check_true(a3.isActive);
+   do_check_false(a3.userDisabled);
+   do_check_false(a3.appDisabled);
+   do_check_eq(a3.pendingOperations, AddonManager.PENDING_NONE);
+   do_check_true(isExtensionInAddonsList(profileDir, a3.id));
+
+   // The compatibility update won't be recovered and with strict
+   // compatibility it would not have been able to tell that it was
+   // previously userDisabled. However, without strict compat, it wasn't
+   // appDisabled, so it knows it must have been userDisabled.
+   do_check_neq(a4, null);
+   do_check_false(a4.isActive);
+   do_check_true(a4.userDisabled);
+   do_check_false(a4.appDisabled);
+   do_check_eq(a4.pendingOperations, AddonManager.PENDING_NONE);
+   do_check_false(isExtensionInAddonsList(profileDir, a4.id));
+
+   do_check_neq(a5, null);
+   do_check_true(a5.isActive);
+   do_check_false(a5.userDisabled);
+   do_check_false(a5.appDisabled);
+   do_check_eq(a5.pendingOperations, AddonManager.PENDING_NONE);
+   do_check_true(isExtensionInAddonsList(profileDir, a5.id));
+
+   do_check_neq(a6, null);
+   do_check_true(a6.isActive);
+   do_check_false(a6.userDisabled);
+   do_check_false(a6.appDisabled);
+   do_check_eq(a6.pendingOperations, AddonManager.PENDING_NONE);
+
+   do_check_neq(a7, null);
+   do_check_false(a7.isActive);
+   do_check_true(a7.userDisabled);
+   do_check_false(a7.appDisabled);
+   do_check_eq(a7.pendingOperations, AddonManager.PENDING_NONE);
+
+   // Should be correctly recovered
+   do_check_neq(t1, null);
+   do_check_false(t1.isActive);
+   do_check_true(t1.userDisabled);
+   do_check_false(t1.appDisabled);
+   do_check_eq(t1.pendingOperations, AddonManager.PENDING_NONE);
+   do_check_false(isThemeInAddonsList(profileDir, t1.id));
+
+   // Should be correctly recovered
+   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));
+
+   // Restarting will actually apply changes to extensions.ini which will
+   // then be put into the in-memory database when we next fail to load the
+   // real thing
+   restartManager();
+
+   // Shouldn't have seen any startup changes
+   check_startup_changes(AddonManager.STARTUP_CHANGE_INSTALLED, []);
+
+   [a1, a2, a3, a4, a5, a6, a7, t1, t2] =
+     yield promiseAddonsByIDs(["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"],
-                               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);
-    do_check_false(a2.isActive);
-    do_check_true(a2.userDisabled);
-    do_check_false(a2.appDisabled);
-    do_check_eq(a2.pendingOperations, AddonManager.PENDING_NONE);
-    do_check_false(isExtensionInAddonsList(profileDir, a2.id));
-
-    do_check_neq(a3, null);
-    do_check_true(a3.isActive);
-    do_check_false(a3.userDisabled);
-    do_check_false(a3.appDisabled);
-    do_check_eq(a3.pendingOperations, AddonManager.PENDING_NONE);
-    do_check_true(isExtensionInAddonsList(profileDir, a3.id));
+                               "theme2@tests.mozilla.org"]);
 
-    do_check_neq(a4, null);
-    do_check_false(a4.isActive);
-    do_check_true(a4.userDisabled);
-    do_check_false(a4.appDisabled);
-    do_check_eq(a4.pendingOperations, AddonManager.PENDING_NONE);
-    do_check_false(isExtensionInAddonsList(profileDir, a4.id));
-
-    do_check_neq(a5, null);
-    do_check_true(a5.isActive);
-    do_check_false(a5.userDisabled);
-    do_check_false(a5.appDisabled);
-    do_check_eq(a5.pendingOperations, AddonManager.PENDING_NONE);
-    do_check_true(isExtensionInAddonsList(profileDir, a5.id));
-
-    do_check_neq(a6, null);
-    do_check_true(a6.isActive);
-    do_check_false(a6.userDisabled);
-    do_check_false(a6.appDisabled);
-    do_check_eq(a6.pendingOperations, AddonManager.PENDING_NONE);
-
-    do_check_neq(a7, null);
-    do_check_false(a7.isActive);
-    do_check_true(a7.userDisabled);
-    do_check_false(a7.appDisabled);
-    do_check_eq(a7.pendingOperations, AddonManager.PENDING_NONE);
-
-    do_check_neq(t1, null);
-    do_check_false(t1.isActive);
-    do_check_true(t1.userDisabled);
-    do_check_false(t1.appDisabled);
-    do_check_eq(t1.pendingOperations, AddonManager.PENDING_NONE);
-    do_check_false(isThemeInAddonsList(profileDir, t1.id));
+   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(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));
-
-    // Open another handle on the JSON DB with as much Unix and Windows locking
-    // as we can to simulate some other process interfering with it
-    shutdownManager();
-    do_print("Locking " + gExtensionsJSON.path);
-    let options = {
-      winShare: 0
-    };
-    if (OS.Constants.libc.O_EXLOCK)
-      options.unixFlags = OS.Constants.libc.O_EXLOCK;
-
-    OS.File.open(gExtensionsJSON.path, {read:true, write:true, existing:true}, options).then(
-      file => {
-        filePermissions = gExtensionsJSON.permissions;
-        if (!OS.Constants.Win) {
-          gExtensionsJSON.permissions = 0;
-        }
-        startupManager(false);
-
-        // Shouldn't have seen any startup changes
-        check_startup_changes(AddonManager.STARTUP_CHANGE_INSTALLED, []);
+   do_check_neq(a2, null);
+   do_check_false(a2.isActive);
+   do_check_true(a2.userDisabled);
+   do_check_false(a2.appDisabled);
+   do_check_eq(a2.pendingOperations, AddonManager.PENDING_NONE);
+   do_check_false(isExtensionInAddonsList(profileDir, a2.id));
 
-        // Accessing the add-ons should open and recover the database
-        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"],
-                                     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));
+   do_check_neq(a3, null);
+   do_check_true(a3.isActive);
+   do_check_false(a3.userDisabled);
+   do_check_false(a3.appDisabled);
+   do_check_eq(a3.pendingOperations, AddonManager.PENDING_NONE);
+   do_check_true(isExtensionInAddonsList(profileDir, a3.id));
 
-          // Should be correctly recovered
-          do_check_neq(a2, null);
-          do_check_false(a2.isActive);
-          do_check_true(a2.userDisabled);
-          do_check_false(a2.appDisabled);
-          do_check_eq(a2.pendingOperations, AddonManager.PENDING_NONE);
-          do_check_false(isExtensionInAddonsList(profileDir, a2.id));
-
-          // The compatibility update won't be recovered but it should still be
-          // active for this session
-          do_check_neq(a3, null);
-          do_check_true(a3.isActive);
-          do_check_false(a3.userDisabled);
-          do_check_false(a3.appDisabled);
-          do_check_eq(a3.pendingOperations, AddonManager.PENDING_NONE);
-          do_check_true(isExtensionInAddonsList(profileDir, a3.id));
+   do_check_neq(a4, null);
+   do_check_false(a4.isActive);
+   do_check_true(a4.userDisabled);
+   do_check_false(a4.appDisabled);
+   do_check_eq(a4.pendingOperations, AddonManager.PENDING_NONE);
+   do_check_false(isExtensionInAddonsList(profileDir, a4.id));
 
-          // The compatibility update won't be recovered and with strict
-          // compatibility it would not have been able to tell that it was
-          // previously userDisabled. However, without strict compat, it wasn't
-          // appDisabled, so it knows it must have been userDisabled.
-          do_check_neq(a4, null);
-          do_check_false(a4.isActive);
-          do_check_true(a4.userDisabled);
-          do_check_false(a4.appDisabled);
-          do_check_eq(a4.pendingOperations, AddonManager.PENDING_NONE);
-          do_check_false(isExtensionInAddonsList(profileDir, a4.id));
-
-          do_check_neq(a5, null);
-          do_check_true(a5.isActive);
-          do_check_false(a5.userDisabled);
-          do_check_false(a5.appDisabled);
-          do_check_eq(a5.pendingOperations, AddonManager.PENDING_NONE);
-          do_check_true(isExtensionInAddonsList(profileDir, a5.id));
-
-          do_check_neq(a6, null);
-          do_check_true(a6.isActive);
-          do_check_false(a6.userDisabled);
-          do_check_false(a6.appDisabled);
-          do_check_eq(a6.pendingOperations, AddonManager.PENDING_NONE);
+   do_check_neq(a5, null);
+   do_check_true(a5.isActive);
+   do_check_false(a5.userDisabled);
+   do_check_false(a5.appDisabled);
+   do_check_eq(a5.pendingOperations, AddonManager.PENDING_NONE);
+   do_check_true(isExtensionInAddonsList(profileDir, a5.id));
 
-          do_check_neq(a7, null);
-          do_check_false(a7.isActive);
-          do_check_true(a7.userDisabled);
-          do_check_false(a7.appDisabled);
-          do_check_eq(a7.pendingOperations, AddonManager.PENDING_NONE);
-
-          // Should be correctly recovered
-          do_check_neq(t1, null);
-          do_check_false(t1.isActive);
-          do_check_true(t1.userDisabled);
-          do_check_false(t1.appDisabled);
-          do_check_eq(t1.pendingOperations, AddonManager.PENDING_NONE);
-          do_check_false(isThemeInAddonsList(profileDir, t1.id));
+   do_check_neq(a6, null);
+   do_check_true(a6.isActive);
+   do_check_false(a6.userDisabled);
+   do_check_false(a6.appDisabled);
+   do_check_eq(a6.pendingOperations, AddonManager.PENDING_NONE);
 
-          // Should be correctly recovered
-          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));
-
-          // Restarting will actually apply changes to extensions.ini which will
-          // then be put into the in-memory database when we next fail to load the
-          // real thing
-          restartManager();
-
-          // Shouldn't have seen any startup changes
-          check_startup_changes(AddonManager.STARTUP_CHANGE_INSTALLED, []);
+   do_check_neq(a7, null);
+   do_check_false(a7.isActive);
+   do_check_true(a7.userDisabled);
+   do_check_false(a7.appDisabled);
+   do_check_eq(a7.pendingOperations, AddonManager.PENDING_NONE);
 
-          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"],
-                                       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);
-            do_check_false(a2.isActive);
-            do_check_true(a2.userDisabled);
-            do_check_false(a2.appDisabled);
-            do_check_eq(a2.pendingOperations, AddonManager.PENDING_NONE);
-            do_check_false(isExtensionInAddonsList(profileDir, a2.id));
-
-            do_check_neq(a3, null);
-            do_check_true(a3.isActive);
-            do_check_false(a3.userDisabled);
-            do_check_false(a3.appDisabled);
-            do_check_eq(a3.pendingOperations, AddonManager.PENDING_NONE);
-            do_check_true(isExtensionInAddonsList(profileDir, a3.id));
-
-            do_check_neq(a4, null);
-            do_check_false(a4.isActive);
-            do_check_true(a4.userDisabled);
-            do_check_false(a4.appDisabled);
-            do_check_eq(a4.pendingOperations, AddonManager.PENDING_NONE);
-            do_check_false(isExtensionInAddonsList(profileDir, a4.id));
+   do_check_neq(t1, null);
+   do_check_false(t1.isActive);
+   do_check_true(t1.userDisabled);
+   do_check_false(t1.appDisabled);
+   do_check_eq(t1.pendingOperations, AddonManager.PENDING_NONE);
+   do_check_false(isThemeInAddonsList(profileDir, t1.id));
 
-            do_check_neq(a5, null);
-            do_check_true(a5.isActive);
-            do_check_false(a5.userDisabled);
-            do_check_false(a5.appDisabled);
-            do_check_eq(a5.pendingOperations, AddonManager.PENDING_NONE);
-            do_check_true(isExtensionInAddonsList(profileDir, a5.id));
-
-            do_check_neq(a6, null);
-            do_check_true(a6.isActive);
-            do_check_false(a6.userDisabled);
-            do_check_false(a6.appDisabled);
-            do_check_eq(a6.pendingOperations, AddonManager.PENDING_NONE);
-
-            do_check_neq(a7, null);
-            do_check_false(a7.isActive);
-            do_check_true(a7.userDisabled);
-            do_check_false(a7.appDisabled);
-            do_check_eq(a7.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_check_true(isThemeInAddonsList(profileDir, t2.id));
 
-            do_check_neq(t1, null);
-            do_check_false(t1.isActive);
-            do_check_true(t1.userDisabled);
-            do_check_false(t1.appDisabled);
-            do_check_eq(t1.pendingOperations, AddonManager.PENDING_NONE);
-            do_check_false(isThemeInAddonsList(profileDir, t1.id));
-
-            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));
-
-            // After allowing access to the original DB things should go back to as
-            // they were previously
-            shutdownManager();
-            do_print("Unlocking " + gExtensionsJSON.path);
-            file.close();
-            gExtensionsJSON.permissions = filePermissions;
-            startupManager();
+   // After allowing access to the original DB things should go back to as
+   // they were previously
+   shutdownManager();
+   do_print("Unlocking " + gExtensionsJSON.path);
+   yield file.close();
+   gExtensionsJSON.permissions = filePermissions;
+   startupManager();
 
 
-            // Shouldn't have seen any startup changes
-            check_startup_changes(AddonManager.STARTUP_CHANGE_INSTALLED, []);
+   // Shouldn't have seen any startup changes
+   check_startup_changes(AddonManager.STARTUP_CHANGE_INSTALLED, []);
 
-            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"],
-                                         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));
+   [a1, a2, a3, a4, a5, a6, a7, t1, t2] =
+     yield promiseAddonsByIDs(["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"]);
 
-              do_check_neq(a2, null);
-              do_check_false(a2.isActive);
-              do_check_true(a2.userDisabled);
-              do_check_false(a2.appDisabled);
-              do_check_eq(a2.pendingOperations, AddonManager.PENDING_NONE);
-              do_check_false(isExtensionInAddonsList(profileDir, a2.id));
+   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(a3, null);
-              do_check_true(a3.isActive);
-              do_check_false(a3.userDisabled);
-              do_check_false(a3.appDisabled);
-              do_check_eq(a3.pendingOperations, AddonManager.PENDING_NONE);
-              do_check_true(isExtensionInAddonsList(profileDir, a3.id));
+   do_check_neq(a2, null);
+   do_check_false(a2.isActive);
+   do_check_true(a2.userDisabled);
+   do_check_false(a2.appDisabled);
+   do_check_eq(a2.pendingOperations, AddonManager.PENDING_NONE);
+   do_check_false(isExtensionInAddonsList(profileDir, a2.id));
 
-              do_check_neq(a4, null);
-              do_check_false(a4.isActive);
-              do_check_true(a4.userDisabled);
-              do_check_false(a4.appDisabled);
-              do_check_eq(a4.pendingOperations, AddonManager.PENDING_NONE);
-              do_check_false(isExtensionInAddonsList(profileDir, a4.id));
+   do_check_neq(a3, null);
+   do_check_true(a3.isActive);
+   do_check_false(a3.userDisabled);
+   do_check_false(a3.appDisabled);
+   do_check_eq(a3.pendingOperations, AddonManager.PENDING_NONE);
+   do_check_true(isExtensionInAddonsList(profileDir, a3.id));
 
-              do_check_neq(a5, null);
-              do_check_true(a5.isActive);
-              do_check_false(a5.userDisabled);
-              do_check_false(a5.appDisabled);
-              do_check_eq(a5.pendingOperations, AddonManager.PENDING_NONE);
-              do_check_true(isExtensionInAddonsList(profileDir, a5.id));
+   do_check_neq(a4, null);
+   do_check_false(a4.isActive);
+   do_check_true(a4.userDisabled);
+   do_check_false(a4.appDisabled);
+   do_check_eq(a4.pendingOperations, AddonManager.PENDING_NONE);
+   do_check_false(isExtensionInAddonsList(profileDir, a4.id));
 
-              do_check_neq(a6, null);
-              do_check_true(a6.isActive);
-              do_check_false(a6.userDisabled);
-              do_check_false(a6.appDisabled);
-              do_check_eq(a6.pendingOperations, AddonManager.PENDING_NONE);
+   do_check_neq(a5, null);
+   do_check_true(a5.isActive);
+   do_check_false(a5.userDisabled);
+   do_check_false(a5.appDisabled);
+   do_check_eq(a5.pendingOperations, AddonManager.PENDING_NONE);
+   do_check_true(isExtensionInAddonsList(profileDir, a5.id));
 
-              do_check_neq(a7, null);
-              do_check_false(a7.isActive);
-              do_check_true(a7.userDisabled);
-              do_check_false(a7.appDisabled);
-              do_check_eq(a7.pendingOperations, AddonManager.PENDING_NONE);
+   do_check_neq(a6, null);
+   do_check_true(a6.isActive);
+   do_check_false(a6.userDisabled);
+   do_check_false(a6.appDisabled);
+   do_check_eq(a6.pendingOperations, AddonManager.PENDING_NONE);
 
-              do_check_neq(t1, null);
-              do_check_false(t1.isActive);
-              do_check_true(t1.userDisabled);
-              do_check_false(t1.appDisabled);
-              do_check_eq(t1.pendingOperations, AddonManager.PENDING_NONE);
-              do_check_false(isThemeInAddonsList(profileDir, t1.id));
+   do_check_neq(a7, null);
+   do_check_false(a7.isActive);
+   do_check_true(a7.userDisabled);
+   do_check_false(a7.appDisabled);
+   do_check_eq(a7.pendingOperations, AddonManager.PENDING_NONE);
+
+   do_check_neq(t1, null);
+   do_check_false(t1.isActive);
+   do_check_true(t1.userDisabled);
+   do_check_false(t1.appDisabled);
+   do_check_eq(t1.pendingOperations, AddonManager.PENDING_NONE);
+   do_check_false(isThemeInAddonsList(profileDir, t1.id));
 
-              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));
+   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();
-            }));
-          }));
-        }));
-      },
-      do_report_unexpected_exception
-    );
-  }));
+
+function run_test() {
+ run_next_test();
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_locked2.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_locked2.js
@@ -66,230 +66,227 @@ var addon5 = {
     minVersion: "2",
     maxVersion: "2"
   }]
 };
 
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
 
-function run_test() {
-  do_test_pending();
+add_task(function() {
+
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2", "2");
 
   writeInstallRDFForExtension(addon1, profileDir);
   writeInstallRDFForExtension(addon2, profileDir);
   writeInstallRDFForExtension(addon3, profileDir);
   writeInstallRDFForExtension(addon4, profileDir);
   writeInstallRDFForExtension(addon5, profileDir);
 
   // Make it look like add-on 5 was installed some time in the past so the update is
   // detected
-  setExtensionModifiedTime(getFileForAddon(profileDir, addon5.id), Date.now() - (60000));
+  let path = getFileForAddon(profileDir, addon5.id).path;
+  yield promiseSetExtensionModifiedTime(path, Date.now() - (60000));
 
   // Startup the profile and setup the initial state
   startupManager();
 
   check_startup_changes(AddonManager.STARTUP_CHANGE_INSTALLED, []);
   check_startup_changes(AddonManager.STARTUP_CHANGE_UNINSTALLED, []);
 
-  AddonManager.getAddonByID("addon2@tests.mozilla.org", callback_soon(function(a2) {
-    a2.userDisabled = true;
+  let a1, a2, a3, a4, a5, a6;
 
-    restartManager();
+  [a2] = yield promiseAddonsByIDs(["addon2@tests.mozilla.org"]);
+  a2.userDisabled = true;
+
+  restartManager();
 
-    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]) {
-      a2.userDisabled = false;
-      a3.userDisabled = true;
-      a4.uninstall();
+  [a1, a2, a3, a4, a5] =
+    yield promiseAddonsByIDs(["addon1@tests.mozilla.org",
+                              "addon2@tests.mozilla.org",
+                              "addon3@tests.mozilla.org",
+                              "addon4@tests.mozilla.org",
+                              "addon5@tests.mozilla.org"]);
+
+  a2.userDisabled = false;
+  a3.userDisabled = true;
+  a4.uninstall();
 
-      installAllFiles([do_get_addon("test_locked2_5"),
-                       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));
+  yield promiseInstallAllFiles([do_get_addon("test_locked2_5"),
+                                do_get_addon("test_locked2_6")]);
+  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);
-        do_check_false(a2.isActive);
-        do_check_false(a2.userDisabled);
-        do_check_false(a2.appDisabled);
-        do_check_eq(a2.pendingOperations, AddonManager.PENDING_ENABLE);
-        do_check_false(isExtensionInAddonsList(profileDir, a2.id));
+  do_check_neq(a2, null);
+  do_check_false(a2.isActive);
+  do_check_false(a2.userDisabled);
+  do_check_false(a2.appDisabled);
+  do_check_eq(a2.pendingOperations, AddonManager.PENDING_ENABLE);
+  do_check_false(isExtensionInAddonsList(profileDir, a2.id));
 
-        do_check_neq(a3, null);
-        do_check_true(a3.isActive);
-        do_check_true(a3.userDisabled);
-        do_check_false(a3.appDisabled);
-        do_check_eq(a3.pendingOperations, AddonManager.PENDING_DISABLE);
-        do_check_true(isExtensionInAddonsList(profileDir, a3.id));
-
-        do_check_neq(a4, null);
-        do_check_true(a4.isActive);
-        do_check_false(a4.userDisabled);
-        do_check_false(a4.appDisabled);
-        do_check_eq(a4.pendingOperations, AddonManager.PENDING_UNINSTALL);
-        do_check_true(isExtensionInAddonsList(profileDir, a4.id));
+  do_check_neq(a3, null);
+  do_check_true(a3.isActive);
+  do_check_true(a3.userDisabled);
+  do_check_false(a3.appDisabled);
+  do_check_eq(a3.pendingOperations, AddonManager.PENDING_DISABLE);
+  do_check_true(isExtensionInAddonsList(profileDir, a3.id));
 
-        do_check_neq(a5, null);
-        do_check_eq(a5.version, "1.0");
-        do_check_true(a5.isActive);
-        do_check_false(a5.userDisabled);
-        do_check_false(a5.appDisabled);
-        do_check_eq(a5.pendingOperations, AddonManager.PENDING_UPGRADE);
-        do_check_true(isExtensionInAddonsList(profileDir, a5.id));
+  do_check_neq(a4, null);
+  do_check_true(a4.isActive);
+  do_check_false(a4.userDisabled);
+  do_check_false(a4.appDisabled);
+  do_check_eq(a4.pendingOperations, AddonManager.PENDING_UNINSTALL);
+  do_check_true(isExtensionInAddonsList(profileDir, a4.id));
 
-        // Open another handle on the JSON DB with as much Unix and Windows locking
-        // as we can to simulate some other process interfering with it
-        shutdownManager();
-        do_print("Locking " + gExtensionsJSON.path);
-        let options = {
-          winShare: 0
-        };
-        if (OS.Constants.libc.O_EXLOCK)
-          options.unixFlags = OS.Constants.libc.O_EXLOCK;
+  do_check_neq(a5, null);
+  do_check_eq(a5.version, "1.0");
+  do_check_true(a5.isActive);
+  do_check_false(a5.userDisabled);
+  do_check_false(a5.appDisabled);
+  do_check_eq(a5.pendingOperations, AddonManager.PENDING_UPGRADE);
+  do_check_true(isExtensionInAddonsList(profileDir, a5.id));
+
+  // Open another handle on the JSON DB with as much Unix and Windows locking
+  // as we can to simulate some other process interfering with it
+  shutdownManager();
+  do_print("Locking " + gExtensionsJSON.path);
+  let options = {
+    winShare: 0
+  };
+  if (OS.Constants.libc.O_EXLOCK)
+    options.unixFlags = OS.Constants.libc.O_EXLOCK;
 
-        OS.File.open(gExtensionsJSON.path, {read:true, write:true, existing:true}, options).then(
-          file => {
-            filePermissions = gExtensionsJSON.permissions;
-            if (!OS.Constants.Win) {
-              gExtensionsJSON.permissions = 0;
-            }
-            startupManager(false);
+  let file = yield OS.File.open(gExtensionsJSON.path, {read:true, write:true, existing:true}, options);
 
-            check_startup_changes(AddonManager.STARTUP_CHANGE_INSTALLED, []);
-            check_startup_changes(AddonManager.STARTUP_CHANGE_UNINSTALLED, []);
+  let filePermissions = gExtensionsJSON.permissions;
+  if (!OS.Constants.Win) {
+    gExtensionsJSON.permissions = 0;
+  }
+  startupManager(false);
+
+  check_startup_changes(AddonManager.STARTUP_CHANGE_INSTALLED, []);
+  check_startup_changes(AddonManager.STARTUP_CHANGE_UNINSTALLED, []);
 
-            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"],
-                                        callback_soon(function([a1, a2, a3, a4, a5, a6]) {
-              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));
+  [a1, a2, a3, a4, a5, a6] =
+    yield promiseAddonsByIDs(["addon1@tests.mozilla.org",
+                              "addon2@tests.mozilla.org",
+                              "addon3@tests.mozilla.org",
+                              "addon4@tests.mozilla.org",
+                              "addon5@tests.mozilla.org",
+                              "addon6@tests.mozilla.org"]);
 
-              do_check_neq(a2, null);
-              do_check_true(a2.isActive);
-              do_check_false(a2.userDisabled);
-              do_check_false(a2.appDisabled);
-              do_check_eq(a2.pendingOperations, AddonManager.PENDING_NONE);
-              do_check_true(isExtensionInAddonsList(profileDir, a2.id));
+  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(a3, null);
-              do_check_false(a3.isActive);
-              do_check_true(a3.userDisabled);
-              do_check_false(a3.appDisabled);
-              do_check_eq(a3.pendingOperations, AddonManager.PENDING_NONE);
-              do_check_false(isExtensionInAddonsList(profileDir, a3.id));
-
-              do_check_eq(a4, null);
+  do_check_neq(a2, null);
+  do_check_true(a2.isActive);
+  do_check_false(a2.userDisabled);
+  do_check_false(a2.appDisabled);
+  do_check_eq(a2.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_true(isExtensionInAddonsList(profileDir, a2.id));
 
-              do_check_neq(a5, null);
-              do_check_eq(a5.version, "2.0");
-              do_check_true(a5.isActive);
-              do_check_false(a5.userDisabled);
-              do_check_false(a5.appDisabled);
-              do_check_eq(a5.pendingOperations, AddonManager.PENDING_NONE);
-              do_check_true(isExtensionInAddonsList(profileDir, a5.id));
+  do_check_neq(a3, null);
+  do_check_false(a3.isActive);
+  do_check_true(a3.userDisabled);
+  do_check_false(a3.appDisabled);
+  do_check_eq(a3.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_false(isExtensionInAddonsList(profileDir, a3.id));
 
-              do_check_neq(a6, null);
-              do_check_true(a6.isActive);
-              do_check_false(a6.userDisabled);
-              do_check_false(a6.appDisabled);
-              do_check_eq(a6.pendingOperations, AddonManager.PENDING_NONE);
-              do_check_true(isExtensionInAddonsList(profileDir, a6.id));
+  do_check_eq(a4, null);
 
-              // After allowing access to the original DB things should still be
-              // back how they were before the lock
-              shutdownManager();
-              file.close();
-              gExtensionsJSON.permissions = filePermissions;
-              startupManager();
+  do_check_neq(a5, null);
+  do_check_eq(a5.version, "2.0");
+  do_check_true(a5.isActive);
+  do_check_false(a5.userDisabled);
+  do_check_false(a5.appDisabled);
+  do_check_eq(a5.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_true(isExtensionInAddonsList(profileDir, a5.id));
 
-              // On Unix, we can save the DB even when the original file wasn't
-              // readable, so our changes were saved. On Windows,
-              // these things happened when we had no access to the database so
-              // they are seen as external changes when we get the database back
-              if (gXPISaveError) {
-                do_print("Previous XPI save failed");
-                check_startup_changes(AddonManager.STARTUP_CHANGE_INSTALLED,
-                    ["addon6@tests.mozilla.org"]);
-                check_startup_changes(AddonManager.STARTUP_CHANGE_UNINSTALLED,
-                    ["addon4@tests.mozilla.org"]);
-              }
-              else {
-                do_print("Previous XPI save succeeded");
-                check_startup_changes(AddonManager.STARTUP_CHANGE_INSTALLED, []);
-                check_startup_changes(AddonManager.STARTUP_CHANGE_UNINSTALLED, []);
-              }
+  do_check_neq(a6, null);
+  do_check_true(a6.isActive);
+  do_check_false(a6.userDisabled);
+  do_check_false(a6.appDisabled);
+  do_check_eq(a6.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_true(isExtensionInAddonsList(profileDir, a6.id));
+
+  // After allowing access to the original DB things should still be
+  // back how they were before the lock
+  shutdownManager();
+  yield file.close();
+  gExtensionsJSON.permissions = filePermissions;
+  startupManager();
 
-              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"],
-                                          function([a1, a2, a3, a4, a5, a6]) {
-                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));
+  // On Unix, we can save the DB even when the original file wasn't
+  // readable, so our changes were saved. On Windows,
+  // these things happened when we had no access to the database so
+  // they are seen as external changes when we get the database back
+  if (gXPISaveError) {
+    do_print("Previous XPI save failed");
+    check_startup_changes(AddonManager.STARTUP_CHANGE_INSTALLED,
+        ["addon6@tests.mozilla.org"]);
+    check_startup_changes(AddonManager.STARTUP_CHANGE_UNINSTALLED,
+        ["addon4@tests.mozilla.org"]);
+  }
+  else {
+    do_print("Previous XPI save succeeded");
+    check_startup_changes(AddonManager.STARTUP_CHANGE_INSTALLED, []);
+    check_startup_changes(AddonManager.STARTUP_CHANGE_UNINSTALLED, []);
+  }
 
-                do_check_neq(a2, null);
-                do_check_true(a2.isActive);
-                do_check_false(a2.userDisabled);
-                do_check_false(a2.appDisabled);
-                do_check_eq(a2.pendingOperations, AddonManager.PENDING_NONE);
-                do_check_true(isExtensionInAddonsList(profileDir, a2.id));
+  [a1, a2, a3, a4, a5, a6] =
+    yield promiseAddonsByIDs(["addon1@tests.mozilla.org",
+                              "addon2@tests.mozilla.org",
+                              "addon3@tests.mozilla.org",
+                              "addon4@tests.mozilla.org",
+                              "addon5@tests.mozilla.org",
+                              "addon6@tests.mozilla.org"]);
+
+  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(a3, null);
-                do_check_false(a3.isActive);
-                do_check_true(a3.userDisabled);
-                do_check_false(a3.appDisabled);
-                do_check_eq(a3.pendingOperations, AddonManager.PENDING_NONE);
-                do_check_false(isExtensionInAddonsList(profileDir, a3.id));
+  do_check_neq(a2, null);
+  do_check_true(a2.isActive);
+  do_check_false(a2.userDisabled);
+  do_check_false(a2.appDisabled);
+  do_check_eq(a2.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_true(isExtensionInAddonsList(profileDir, a2.id));
 
-                do_check_eq(a4, null);
+  do_check_neq(a3, null);
+  do_check_false(a3.isActive);
+  do_check_true(a3.userDisabled);
+  do_check_false(a3.appDisabled);
+  do_check_eq(a3.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_false(isExtensionInAddonsList(profileDir, a3.id));
 
-                do_check_neq(a5, null);
-                do_check_eq(a5.version, "2.0");
-                do_check_true(a5.isActive);
-                do_check_false(a5.userDisabled);
-                do_check_false(a5.appDisabled);
-                do_check_eq(a5.pendingOperations, AddonManager.PENDING_NONE);
-                do_check_true(isExtensionInAddonsList(profileDir, a5.id));
+  do_check_eq(a4, null);
 
-                do_check_neq(a6, null);
-                do_check_true(a6.isActive);
-                do_check_false(a6.userDisabled);
-                do_check_false(a6.appDisabled);
-                do_check_eq(a6.pendingOperations, AddonManager.PENDING_NONE);
-                do_check_true(isExtensionInAddonsList(profileDir, a6.id));
+  do_check_neq(a5, null);
+  do_check_eq(a5.version, "2.0");
+  do_check_true(a5.isActive);
+  do_check_false(a5.userDisabled);
+  do_check_false(a5.appDisabled);
+  do_check_eq(a5.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_true(isExtensionInAddonsList(profileDir, a5.id));
 
-                end_test();
-              });
-            }));
-          },
-          do_report_unexpected_exception
-          );
-      });
-    });
-  }));
+  do_check_neq(a6, null);
+  do_check_true(a6.isActive);
+  do_check_false(a6.userDisabled);
+  do_check_false(a6.appDisabled);
+  do_check_eq(a6.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_true(isExtensionInAddonsList(profileDir, a6.id));
+});
+
+function run_test() {
+  run_next_test();
 }
 
-function end_test() {
-  do_execute_soon(do_test_finished);
-}
--- a/toolkit/mozapps/extensions/test/xpcshell/test_locked_strictcompat.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_locked_strictcompat.js
@@ -129,18 +129,17 @@ var theme2 = {
     minVersion: "2",
     maxVersion: "2"
   }]
 };
 
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
 
-function run_test() {
-  do_test_pending();
+add_task(function* init() {
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2", "2");
 
   writeInstallRDFForExtension(addon1, profileDir);
   writeInstallRDFForExtension(addon2, profileDir);
   writeInstallRDFForExtension(addon3, profileDir);
   writeInstallRDFForExtension(addon4, profileDir);
   writeInstallRDFForExtension(addon5, profileDir);
   writeInstallRDFForExtension(addon6, profileDir);
@@ -149,402 +148,404 @@ function run_test() {
   writeInstallRDFForExtension(theme2, profileDir);
 
   // Startup the profile and setup the initial state
   startupManager();
 
   // New profile so new add-ons are ignored
   check_startup_changes(AddonManager.STARTUP_CHANGE_INSTALLED, []);
 
-  AddonManager.getAddonsByIDs(["addon2@tests.mozilla.org",
-                               "addon3@tests.mozilla.org",
-                               "addon4@tests.mozilla.org",
-                               "addon7@tests.mozilla.org",
-                               "theme2@tests.mozilla.org"], function([a2, a3, a4,
-                                                                      a7, t2]) {
-    // Set up the initial state
-    a2.userDisabled = true;
-    a4.userDisabled = true;
-    a7.userDisabled = true;
-    t2.userDisabled = false;
-    a3.findUpdates({
-      onUpdateFinished: function() {
-        a4.findUpdates({
-          onUpdateFinished: function() {
-            do_execute_soon(run_test_1);
-          }
-        }, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
-      }
-    }, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
-  });
-}
+  let a1, a2, a3, a4, a5, a6, a7, t1, t2;
+
+  [a2, a3, a4, a7, t2] =
+    yield promiseAddonsByIDs(["addon2@tests.mozilla.org",
+                              "addon3@tests.mozilla.org",
+                              "addon4@tests.mozilla.org",
+                              "addon7@tests.mozilla.org",
+                              "theme2@tests.mozilla.org"]);
+
+  // Set up the initial state
+  let deferredUpdateFinished = Promise.defer();
+
+  a2.userDisabled = true;
+  a4.userDisabled = true;
+  a7.userDisabled = true;
+  t2.userDisabled = false;
+  a3.findUpdates({
+    onUpdateFinished: function() {
+      a4.findUpdates({
+        onUpdateFinished: function() {
+          deferredUpdateFinished.resolve();
+        }
+      }, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
+    }
+  }, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
+  yield deferredUpdateFinished.promise;
+});
+
+add_task(function* run_test_1() {
+  let a1, a2, a3, a4, a5, a6, a7, t1, t2;
+
+  restartManager();
+  [a1, a2, a3, a4, a5, a6, a7, t1, t2] =
+    yield promiseAddonsByIDs(["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"]);
+
+  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);
+  do_check_false(a2.isActive);
+  do_check_true(a2.userDisabled);
+  do_check_false(a2.appDisabled);
+  do_check_eq(a2.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_false(isExtensionInAddonsList(profileDir, a2.id));
+
+  do_check_neq(a3, null);
+  do_check_true(a3.isActive);
+  do_check_false(a3.userDisabled);
+  do_check_false(a3.appDisabled);
+  do_check_eq(a3.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_true(isExtensionInAddonsList(profileDir, a3.id));
+
+  do_check_neq(a4, null);
+  do_check_false(a4.isActive);
+  do_check_true(a4.userDisabled);
+  do_check_false(a4.appDisabled);
+  do_check_eq(a4.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_false(isExtensionInAddonsList(profileDir, a4.id));
+
+  do_check_neq(a5, null);
+  do_check_false(a5.isActive);
+  do_check_false(a5.userDisabled);
+  do_check_true(a5.appDisabled);
+  do_check_eq(a5.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_false(isExtensionInAddonsList(profileDir, a5.id));
+
+  do_check_neq(a6, null);
+  do_check_true(a6.isActive);
+  do_check_false(a6.userDisabled);
+  do_check_false(a6.appDisabled);
+  do_check_eq(a6.pendingOperations, AddonManager.PENDING_NONE);
+
+  do_check_neq(a7, null);
+  do_check_false(a7.isActive);
+  do_check_true(a7.userDisabled);
+  do_check_false(a7.appDisabled);
+  do_check_eq(a7.pendingOperations, AddonManager.PENDING_NONE);
+
+  do_check_neq(t1, null);
+  do_check_false(t1.isActive);
+  do_check_true(t1.userDisabled);
+  do_check_false(t1.appDisabled);
+  do_check_eq(t1.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_false(isThemeInAddonsList(profileDir, t1.id));
+
+  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));
 
-function end_test() {
-  testserver.stop(do_test_finished);
-}
+  // Open another handle on the JSON DB with as much Unix and Windows locking
+  // as we can to simulate some other process interfering with it
+  shutdownManager();
+  do_print("Locking " + gExtensionsJSON.path);
+  let options = {
+    winShare: 0
+  };
+  if (OS.Constants.libc.O_EXLOCK)
+    options.unixFlags = OS.Constants.libc.O_EXLOCK;
+
+  let file = yield OS.File.open(gExtensionsJSON.path, {read:true, write:true, existing:true}, options);
+
+  let filePermissions = gExtensionsJSON.permissions;
+  if (!OS.Constants.Win) {
+    gExtensionsJSON.permissions = 0;
+  }
+  startupManager(false);
+
+  // Shouldn't have seen any startup changes
+  check_startup_changes(AddonManager.STARTUP_CHANGE_INSTALLED, []);
+
+  // Accessing the add-ons should open and recover the database
+  [a1, a2, a3, a4, a5, a6, a7, t1, t2] =
+    yield promiseAddonsByIDs(["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"]);
+
+  // 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));
+
+  // Should be correctly recovered
+  do_check_neq(a2, null);
+  do_check_false(a2.isActive);
+  do_check_true(a2.userDisabled);
+  do_check_false(a2.appDisabled);
+  do_check_eq(a2.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_false(isExtensionInAddonsList(profileDir, a2.id));
 
-function run_test_1() {
+  // The compatibility update won't be recovered but it should still be
+  // active for this session
+  do_check_neq(a3, null);
+  do_check_true(a3.isActive);
+  do_check_false(a3.userDisabled);
+  do_check_true(a3.appDisabled);
+  do_check_eq(a3.pendingOperations, AddonManager.PENDING_DISABLE);
+  do_check_true(isExtensionInAddonsList(profileDir, a3.id));
+
+  // The compatibility update won't be recovered and it will not have been
+  // able to tell that it was previously userDisabled
+  do_check_neq(a4, null);
+  do_check_false(a4.isActive);
+  do_check_false(a4.userDisabled);
+  do_check_true(a4.appDisabled);
+  do_check_eq(a4.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_false(isExtensionInAddonsList(profileDir, a4.id));
+
+  do_check_neq(a5, null);
+  do_check_false(a5.isActive);
+  do_check_false(a5.userDisabled);
+  do_check_true(a5.appDisabled);
+  do_check_eq(a5.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_false(isExtensionInAddonsList(profileDir, a5.id));
+
+  do_check_neq(a6, null);
+  do_check_true(a6.isActive);
+  do_check_false(a6.userDisabled);
+  do_check_false(a6.appDisabled);
+  do_check_eq(a6.pendingOperations, AddonManager.PENDING_NONE);
+
+  do_check_neq(a7, null);
+  do_check_false(a7.isActive);
+  do_check_true(a7.userDisabled);
+  do_check_false(a7.appDisabled);
+  do_check_eq(a7.pendingOperations, AddonManager.PENDING_NONE);
+
+  // Should be correctly recovered
+  do_check_neq(t1, null);
+  do_check_false(t1.isActive);
+  do_check_true(t1.userDisabled);
+  do_check_false(t1.appDisabled);
+  do_check_eq(t1.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_false(isThemeInAddonsList(profileDir, t1.id));
+
+  // Should be correctly recovered
+  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));
+
+  // Restarting will actually apply changes to extensions.ini which will
+  // then be put into the in-memory database when we next fail to load the
+  // real thing
   restartManager();
 
-  AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
+  // Shouldn't have seen any startup changes
+  check_startup_changes(AddonManager.STARTUP_CHANGE_INSTALLED, []);
+
+  [a1, a2, a3, a4, a5, a6, a7, t1, t2] =
+    yield promiseAddonsByIDs(["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"],
-                               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));
+                               "theme2@tests.mozilla.org"]);
+
+  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);
+  do_check_false(a2.isActive);
+  do_check_true(a2.userDisabled);
+  do_check_false(a2.appDisabled);
+  do_check_eq(a2.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_false(isExtensionInAddonsList(profileDir, a2.id));
+
+  do_check_neq(a3, null);
+  do_check_false(a3.isActive);
+  do_check_false(a3.userDisabled);
+  do_check_true(a3.appDisabled);
+  do_check_eq(a3.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_false(isExtensionInAddonsList(profileDir, a3.id));
+
+  do_check_neq(a4, null);
+  do_check_false(a4.isActive);
+  do_check_false(a4.userDisabled);
+  do_check_true(a4.appDisabled);
+  do_check_eq(a4.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_false(isExtensionInAddonsList(profileDir, a4.id));
+
+  do_check_neq(a5, null);
+  do_check_false(a5.isActive);
+  do_check_false(a5.userDisabled);
+  do_check_true(a5.appDisabled);
+  do_check_eq(a5.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_false(isExtensionInAddonsList(profileDir, a5.id));
+
+  do_check_neq(a6, null);
+  do_check_true(a6.isActive);
+  do_check_false(a6.userDisabled);
+  do_check_false(a6.appDisabled);
+  do_check_eq(a6.pendingOperations, AddonManager.PENDING_NONE);
+
+  do_check_neq(a7, null);
+  do_check_false(a7.isActive);
+  do_check_true(a7.userDisabled);
+  do_check_false(a7.appDisabled);
+  do_check_eq(a7.pendingOperations, AddonManager.PENDING_NONE);
+
+  do_check_neq(t1, null);
+  do_check_false(t1.isActive);
+  do_check_true(t1.userDisabled);
+  do_check_false(t1.appDisabled);
+  do_check_eq(t1.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_false(isThemeInAddonsList(profileDir, t1.id));
+
+  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));
 
-    do_check_neq(a2, null);
-    do_check_false(a2.isActive);
-    do_check_true(a2.userDisabled);
-    do_check_false(a2.appDisabled);
-    do_check_eq(a2.pendingOperations, AddonManager.PENDING_NONE);
-    do_check_false(isExtensionInAddonsList(profileDir, a2.id));
+  // After allowing access to the original DB things should go back to as
+  // back how they were before the lock
+  shutdownManager();
+  do_print("Unlocking " + gExtensionsJSON.path);
+  yield file.close();
+  gExtensionsJSON.permissions = filePermissions;
+  startupManager(false);
+
+  // Shouldn't have seen any startup changes
+  check_startup_changes(AddonManager.STARTUP_CHANGE_INSTALLED, []);
+
+  [a1, a2, a3, a4, a5, a6, a7, t1, t2] =
+    yield promiseAddonsByIDs(["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"]);
+
+  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(a3, null);
+  do_check_neq(a2, null);
+  do_check_false(a2.isActive);
+  do_check_true(a2.userDisabled);
+  do_check_false(a2.appDisabled);
+  do_check_eq(a2.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_false(isExtensionInAddonsList(profileDir, a2.id));
+
+  do_check_neq(a3, null);
+  do_check_false(a3.userDisabled);
+  // On Unix, we may be able to save our changes over the locked DB so we
+  // remember that this extension was changed to disabled. On Windows we
+  // couldn't replace the old DB so we read the older version of the DB
+  // where the extension is enabled
+  if (gXPISaveError) {
+    do_print("XPI save failed");
     do_check_true(a3.isActive);
-    do_check_false(a3.userDisabled);
     do_check_false(a3.appDisabled);
-    do_check_eq(a3.pendingOperations, AddonManager.PENDING_NONE);
     do_check_true(isExtensionInAddonsList(profileDir, a3.id));
+  }
+  else {
+    do_print("XPI save succeeded");
+    do_check_false(a3.isActive);
+    do_check_true(a3.appDisabled);
+    do_check_false(isExtensionInAddonsList(profileDir, a3.id));
+  }
+  do_check_eq(a3.pendingOperations, AddonManager.PENDING_NONE);
 
-    do_check_neq(a4, null);
-    do_check_false(a4.isActive);
+  do_check_neq(a4, null);
+  do_check_false(a4.isActive);
+  // The reverse of the platform difference for a3 - Unix should
+  // stay the same as the last iteration because the save succeeded,
+  // Windows should still say userDisabled
+  if (OS.Constants.Win) {
     do_check_true(a4.userDisabled);
     do_check_false(a4.appDisabled);
-    do_check_eq(a4.pendingOperations, AddonManager.PENDING_NONE);
-    do_check_false(isExtensionInAddonsList(profileDir, a4.id));
-
-    do_check_neq(a5, null);
-    do_check_false(a5.isActive);
-    do_check_false(a5.userDisabled);
-    do_check_true(a5.appDisabled);
-    do_check_eq(a5.pendingOperations, AddonManager.PENDING_NONE);
-    do_check_false(isExtensionInAddonsList(profileDir, a5.id));
-
-    do_check_neq(a6, null);
-    do_check_true(a6.isActive);
-    do_check_false(a6.userDisabled);
-    do_check_false(a6.appDisabled);
-    do_check_eq(a6.pendingOperations, AddonManager.PENDING_NONE);
-
-    do_check_neq(a7, null);
-    do_check_false(a7.isActive);
-    do_check_true(a7.userDisabled);
-    do_check_false(a7.appDisabled);
-    do_check_eq(a7.pendingOperations, AddonManager.PENDING_NONE);
-
-    do_check_neq(t1, null);
-    do_check_false(t1.isActive);
-    do_check_true(t1.userDisabled);
-    do_check_false(t1.appDisabled);
-    do_check_eq(t1.pendingOperations, AddonManager.PENDING_NONE);
-    do_check_false(isThemeInAddonsList(profileDir, t1.id));
-
-    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));
-
-    // Open another handle on the JSON DB with as much Unix and Windows locking
-    // as we can to simulate some other process interfering with it
-    shutdownManager();
-    do_print("Locking " + gExtensionsJSON.path);
-    let options = {
-      winShare: 0
-    };
-    if (OS.Constants.libc.O_EXLOCK)
-      options.unixFlags = OS.Constants.libc.O_EXLOCK;
-
-    OS.File.open(gExtensionsJSON.path, {read:true, write:true, existing:true}, options).then(
-      file => {
-        filePermissions = gExtensionsJSON.permissions;
-        if (!OS.Constants.Win) {
-          gExtensionsJSON.permissions = 0;
-        }
-        startupManager(false);
-
-        // Shouldn't have seen any startup changes
-        check_startup_changes(AddonManager.STARTUP_CHANGE_INSTALLED, []);
-
-        // Accessing the add-ons should open and recover the database
-        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"],
-                                     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));
+  }
+  else {
+    do_check_false(a4.userDisabled);
+    do_check_true(a4.appDisabled);
+  }
+  do_check_false(isExtensionInAddonsList(profileDir, a4.id));
+  do_check_eq(a4.pendingOperations, AddonManager.PENDING_NONE);
 
-          // Should be correctly recovered
-          do_check_neq(a2, null);
-          do_check_false(a2.isActive);
-          do_check_true(a2.userDisabled);
-          do_check_false(a2.appDisabled);
-          do_check_eq(a2.pendingOperations, AddonManager.PENDING_NONE);
-          do_check_false(isExtensionInAddonsList(profileDir, a2.id));
-
-          // The compatibility update won't be recovered but it should still be
-          // active for this session
-          do_check_neq(a3, null);
-          do_check_true(a3.isActive);
-          do_check_false(a3.userDisabled);
-          do_check_true(a3.appDisabled);
-          do_check_eq(a3.pendingOperations, AddonManager.PENDING_DISABLE);
-          do_check_true(isExtensionInAddonsList(profileDir, a3.id));
-
-          // The compatibility update won't be recovered and it will not have been
-          // able to tell that it was previously userDisabled
-          do_check_neq(a4, null);
-          do_check_false(a4.isActive);
-          do_check_false(a4.userDisabled);
-          do_check_true(a4.appDisabled);
-          do_check_eq(a4.pendingOperations, AddonManager.PENDING_NONE);
-          do_check_false(isExtensionInAddonsList(profileDir, a4.id));
-
-          do_check_neq(a5, null);
-          do_check_false(a5.isActive);
-          do_check_false(a5.userDisabled);
-          do_check_true(a5.appDisabled);
-          do_check_eq(a5.pendingOperations, AddonManager.PENDING_NONE);
-          do_check_false(isExtensionInAddonsList(profileDir, a5.id));
-
-          do_check_neq(a6, null);
-          do_check_true(a6.isActive);
-          do_check_false(a6.userDisabled);
-          do_check_false(a6.appDisabled);
-          do_check_eq(a6.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_neq(a5, null);
+  do_check_false(a5.isActive);
+  do_check_false(a5.userDisabled);
+  do_check_true(a5.appDisabled);
+  do_check_eq(a5.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_false(isExtensionInAddonsList(profileDir, a5.id));
 
-          do_check_neq(a7, null);
-          do_check_false(a7.isActive);
-          do_check_true(a7.userDisabled);
-          do_check_false(a7.appDisabled);
-          do_check_eq(a7.pendingOperations, AddonManager.PENDING_NONE);
-
-          // Should be correctly recovered
-          do_check_neq(t1, null);
-          do_check_false(t1.isActive);
-          do_check_true(t1.userDisabled);
-          do_check_false(t1.appDisabled);
-          do_check_eq(t1.pendingOperations, AddonManager.PENDING_NONE);
-          do_check_false(isThemeInAddonsList(profileDir, t1.id));
-
-          // Should be correctly recovered
-          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));
-
-          // Restarting will actually apply changes to extensions.ini which will
-          // then be put into the in-memory database when we next fail to load the
-          // real thing
-          restartManager();
-
-          // Shouldn't have seen any startup changes
-          check_startup_changes(AddonManager.STARTUP_CHANGE_INSTALLED, []);
-
-          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"],
-                                       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(a6, null);
+  do_check_true(a6.isActive);
+  do_check_false(a6.userDisabled);
+  do_check_false(a6.appDisabled);
+  do_check_eq(a6.pendingOperations, AddonManager.PENDING_NONE);
 
-            do_check_neq(a2, null);
-            do_check_false(a2.isActive);
-            do_check_true(a2.userDisabled);
-            do_check_false(a2.appDisabled);
-            do_check_eq(a2.pendingOperations, AddonManager.PENDING_NONE);
-            do_check_false(isExtensionInAddonsList(profileDir, a2.id));
-
-            do_check_neq(a3, null);
-            do_check_false(a3.isActive);
-            do_check_false(a3.userDisabled);
-            do_check_true(a3.appDisabled);
-            do_check_eq(a3.pendingOperations, AddonManager.PENDING_NONE);
-            do_check_false(isExtensionInAddonsList(profileDir, a3.id));
-
-            do_check_neq(a4, null);
-            do_check_false(a4.isActive);
-            do_check_false(a4.userDisabled);
-            do_check_true(a4.appDisabled);
-            do_check_eq(a4.pendingOperations, AddonManager.PENDING_NONE);
-            do_check_false(isExtensionInAddonsList(profileDir, a4.id));
-
-            do_check_neq(a5, null);
-            do_check_false(a5.isActive);
-            do_check_false(a5.userDisabled);
-            do_check_true(a5.appDisabled);
-            do_check_eq(a5.pendingOperations, AddonManager.PENDING_NONE);
-            do_check_false(isExtensionInAddonsList(profileDir, a5.id));
-
-            do_check_neq(a6, null);
-            do_check_true(a6.isActive);
-            do_check_false(a6.userDisabled);
-            do_check_false(a6.appDisabled);
-            do_check_eq(a6.pendingOperations, AddonManager.PENDING_NONE);
-
-            do_check_neq(a7, null);
-            do_check_false(a7.isActive);
-            do_check_true(a7.userDisabled);
-            do_check_false(a7.appDisabled);
-            do_check_eq(a7.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_neq(a7, null);
+  do_check_false(a7.isActive);
+  do_check_true(a7.userDisabled);
+  do_check_false(a7.appDisabled);
+  do_check_eq(a7.pendingOperations, AddonManager.PENDING_NONE);
 
-            do_check_neq(t1, null);
-            do_check_false(t1.isActive);
-            do_check_true(t1.userDisabled);
-            do_check_false(t1.appDisabled);
-            do_check_eq(t1.pendingOperations, AddonManager.PENDING_NONE);
-            do_check_false(isThemeInAddonsList(profileDir, t1.id));
-
-            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));
-
-            // After allowing access to the original DB things should go back to as
-            // back how they were before the lock
-            shutdownManager();
-            do_print("Unlocking " + gExtensionsJSON.path);
-            file.close();
-            gExtensionsJSON.permissions = filePermissions;
-            startupManager(false);
-
-            // Shouldn't have seen any startup changes
-            check_startup_changes(AddonManager.STARTUP_CHANGE_INSTALLED, []);
-
-            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"],
-                                         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(t1, null);
+  do_check_false(t1.isActive);
+  do_check_true(t1.userDisabled);
+  do_check_false(t1.appDisabled);
+  do_check_eq(t1.pendingOperations, AddonManager.PENDING_NONE);
+  do_check_false(isThemeInAddonsList(profileDir, t1.id));
 
-              do_check_neq(a2, null);
-              do_check_false(a2.isActive);
-              do_check_true(a2.userDisabled);
-              do_check_false(a2.appDisabled);
-              do_check_eq(a2.pendingOperations, AddonManager.PENDING_NONE);
-              do_check_false(isExtensionInAddonsList(profileDir, a2.id));
-
-              do_check_neq(a3, null);
-              do_check_false(a3.userDisabled);
-              // On Unix, we may be able to save our changes over the locked DB so we
-              // remember that this extension was changed to disabled. On Windows we
-              // couldn't replace the old DB so we read the older version of the DB
-              // where the extension is enabled
-              if (gXPISaveError) {
-                do_print("XPI save failed");
-                do_check_true(a3.isActive);
-                do_check_false(a3.appDisabled);
-                do_check_true(isExtensionInAddonsList(profileDir, a3.id));
-              }
-              else {
-                do_print("XPI save succeeded");
-                do_check_false(a3.isActive);
-                do_check_true(a3.appDisabled);
-                do_check_false(isExtensionInAddonsList(profileDir, a3.id));
-              }
-              do_check_eq(a3.pendingOperations, AddonManager.PENDING_NONE);
-
-              do_check_neq(a4, null);
-              do_check_false(a4.isActive);
-              // The reverse of the platform difference for a3 - Unix should
-              // stay the same as the last iteration because the save succeeded,
-              // Windows should still say userDisabled
-              if (OS.Constants.Win) {
-                do_check_true(a4.userDisabled);
-                do_check_false(a4.appDisabled);
-              }
-              else {
-                do_check_false(a4.userDisabled);
-                do_check_true(a4.appDisabled);
-              }
-              do_check_false(isExtensionInAddonsList(profileDir, a4.id));
-              do_check_eq(a4.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_check_true(isThemeInAddonsList(profileDir, t2.id));
+});
 
-              do_check_neq(a5, null);
-              do_check_false(a5.isActive);
-              do_check_false(a5.userDisabled);
-              do_check_true(a5.appDisabled);
-              do_check_eq(a5.pendingOperations, AddonManager.PENDING_NONE);
-              do_check_false(isExtensionInAddonsList(profileDir, a5.id));
-
-              do_check_neq(a6, null);
-              do_check_true(a6.isActive);
-              do_check_false(a6.userDisabled);
-              do_check_false(a6.appDisabled);
-              do_check_eq(a6.pendingOperations, AddonManager.PENDING_NONE);
-
-              do_check_neq(a7, null);
-              do_check_false(a7.isActive);
-              do_check_true(a7.userDisabled);
-              do_check_false(a7.appDisabled);
-              do_check_eq(a7.pendingOperations, AddonManager.PENDING_NONE);
+function run_test() {
+  run_next_test();
+}
 
-              do_check_neq(t1, null);
-              do_check_false(t1.isActive);
-              do_check_true(t1.userDisabled);
-              do_check_false(t1.appDisabled);
-              do_check_eq(t1.pendingOperations, AddonManager.PENDING_NONE);
-              do_check_false(isThemeInAddonsList(profileDir, t1.id));
-
-              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();
-            }));
-          }));
-        }));
-      },
-      do_report_unexpected_exception
-    );
-  }));
-}