Bug 1447903: Part 22 - Refactor test_dictionary.js to be less insane. r?aswan draft
authorKris Maglione <maglione.k@gmail.com>
Thu, 22 Mar 2018 14:45:03 -0700
changeset 772401 16666b45db4218fd7b1141eb0981aaa8859270c8
parent 772400 68379bd3931825e2b500fad772b358a6bf96d382
push id103898
push usermaglione.k@gmail.com
push dateMon, 26 Mar 2018 01:36:14 +0000
reviewersaswan
bugs1447903
milestone61.0a1
Bug 1447903: Part 22 - Refactor test_dictionary.js to be less insane. r?aswan MozReview-Commit-ID: Di3jtklRmne
toolkit/mozapps/extensions/internal/AddonTestUtils.jsm
toolkit/mozapps/extensions/test/xpcshell/data/test_dictionary.json
toolkit/mozapps/extensions/test/xpcshell/test_dictionary.js
--- a/toolkit/mozapps/extensions/internal/AddonTestUtils.jsm
+++ b/toolkit/mozapps/extensions/internal/AddonTestUtils.jsm
@@ -1041,17 +1041,25 @@ var AddonTestUtils = {
 
       let zip = ZipReader(xpiFile);
       let entries = zip.findEntries(null);
       while (entries.hasMore()) {
         let entry = entries.getNext();
         let target = dir.clone();
         for (let part of entry.split("/"))
           target.append(part);
-        zip.extract(entry, target);
+        if (!target.parent.exists())
+          target.parent.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
+        try {
+          zip.extract(entry, target);
+        } catch (e) {
+          if (e.result != Cr.NS_ERROR_FILE_DIR_NOT_EMPTY) {
+            throw e;
+          }
+        }
         target.permissions |= FileUtils.PERMS_FILE;
       }
       zip.close();
 
       return dir;
     }
 
     let target = installLocation.clone();
--- a/toolkit/mozapps/extensions/test/xpcshell/data/test_dictionary.json
+++ b/toolkit/mozapps/extensions/test/xpcshell/data/test_dictionary.json
@@ -5,42 +5,42 @@
         {
           "applications": {
             "gecko": {
               "strict_min_version": "1",
               "advisory_max_version": "1"
             }
           },
           "version": "2.0",
-          "update_link": "http://localhost:%PORT%/addons/test_dictionary_3.xpi"
+          "update_link": "http://example.com/addons/test_dictionary_3.xpi"
         }
       ]
     },
     "gh@dictionaries.addons.mozilla.org": {
       "updates": [
         {
           "applications": {
             "gecko": {
               "strict_min_version": "1",
               "advisory_max_version": "1"
             }
           },
           "version": "2.0",
-          "update_link": "http://localhost:%PORT%/addons/test_dictionary_5.xpi"
+          "update_link": "http://example.com/addons/test_dictionary_5.xpi"
         }
       ]
     },
     "ef@dictionaries.addons.mozilla.org": {
       "updates": [
         {
           "applications": {
             "gecko": {
               "strict_min_version": "1",
               "advisory_max_version": "1"
             }
           },
           "version": "2.0",
-          "update_link": "http://localhost:%PORT%/addons/test_dictionary_4.xpi"
+          "update_link": "http://example.com/addons/test_dictionary_4.xpi"
         }
       ]
     }
   }
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_dictionary.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_dictionary.js
@@ -7,34 +7,36 @@ ChromeUtils.import("resource://gre/modul
 
 // Enable loading extensions from the user scopes
 Services.prefs.setIntPref("extensions.enabledScopes",
                           AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_USER);
 
 // The test extension uses an insecure update url.
 Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false);
 
+const ID_DICT = "ab-CD@dictionaries.addons.mozilla.org";
+const XPI_DICT = do_get_addon("test_dictionary");
+
 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
 
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
+
 const userExtDir = gProfD.clone();
 userExtDir.append("extensions2");
 userExtDir.append(gAppInfo.ID);
+
 registerDirectory("XREUSysExt", userExtDir.parent);
 
-ChromeUtils.import("resource://testing-common/httpd.js");
 // Create and configure the HTTP server.
-var testserver = new HttpServer();
-testserver.start(-1);
-gPort = testserver.identity.primaryPort;
+var testserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
 
 // register files with server
 testserver.registerDirectory("/addons/", do_get_file("addons"));
-mapFile("/data/test_dictionary.json", testserver);
+testserver.registerDirectory("/data/", do_get_file("data"));
 
 /**
  * This object is both a factory and an mozISpellCheckingEngine implementation (so, it
  * is de-facto a service). It's also an interface requestor that gives out
  * itself when asked for mozISpellCheckingEngine.
  */
 var HunspellEngine = {
   dictionaryDirs: [],
@@ -100,549 +102,442 @@ var HunspellEngine = {
     return this.dictionaryDirs.some(function(dir) {
       var dic = dir.clone();
       dic.append(name);
       return dic.exists();
     });
   }
 };
 
-function run_test() {
-  do_test_pending();
+add_task(async function setup() {
+  // Dictionaries are only supported unpacked.
+  AddonTestUtils.testUnpacked = true;
 
-  startupManager();
-
-  run_test_1();
-}
+  await promiseStartupManager();
+});
 
 // Tests that installing doesn't require a restart
-function run_test_1() {
+add_task(async function test_1() {
   prepare_test({ }, [
     "onNewInstall"
   ]);
 
   HunspellEngine.activate();
 
-  AddonManager.getInstallForFile(do_get_addon("test_dictionary"), function(install) {
-    ensure_test_completed();
+  let install = await AddonManager.getInstallForFile(
+    do_get_addon("test_dictionary"));
+  ensure_test_completed();
 
-    Assert.notEqual(install, null);
-    Assert.equal(install.type, "dictionary");
-    Assert.equal(install.version, "1.0");
-    Assert.equal(install.name, "Test Dictionary");
-    Assert.equal(install.state, AddonManager.STATE_DOWNLOADED);
-    Assert.ok(install.addon.hasResource("install.rdf"));
-    Assert.ok(!install.addon.hasResource("bootstrap.js"));
-    Assert.equal(install.addon.operationsRequiringRestart &
-                 AddonManager.OP_NEEDS_RESTART_INSTALL, 0);
-    do_check_not_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0");
+  notEqual(install, null);
+  equal(install.type, "dictionary");
+  equal(install.version, "1.0");
+  equal(install.name, "Test Dictionary");
+  equal(install.state, AddonManager.STATE_DOWNLOADED);
+  ok(install.addon.hasResource("install.rdf"));
+  ok(!install.addon.hasResource("bootstrap.js"));
+  equal(install.addon.operationsRequiringRestart &
+               AddonManager.OP_NEEDS_RESTART_INSTALL, 0);
+  do_check_not_in_crash_annotation(ID_DICT, "1.0");
 
+  await new Promise(resolve => {
     let addon = install.addon;
     prepare_test({
-      "ab-CD@dictionaries.addons.mozilla.org": [
+      [ID_DICT]: [
         ["onInstalling", false],
         "onInstalled"
       ]
     }, [
       "onInstallStarted",
       "onInstallEnded",
     ], function() {
-      Assert.ok(addon.hasResource("install.rdf"));
+      ok(addon.hasResource("install.rdf"));
       HunspellEngine.listener = function(aEvent) {
         HunspellEngine.listener = null;
-        Assert.equal(aEvent, "addDirectory");
-        executeSoon(check_test_1);
+        equal(aEvent, "addDirectory");
+        resolve();
       };
     });
     install.install();
   });
-}
 
-function check_test_1() {
-  AddonManager.getAllInstalls(function(installs) {
-    // There should be no active installs now since the install completed and
-    // doesn't require a restart.
-    Assert.equal(installs.length, 0);
+  let installs = await AddonManager.getAllInstalls();
+  // There should be no active installs now since the install completed and
+  // doesn't require a restart.
+  equal(installs.length, 0);
 
-    AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
-      Assert.notEqual(b1, null);
-      Assert.equal(b1.version, "1.0");
-      Assert.ok(!b1.appDisabled);
-      Assert.ok(!b1.userDisabled);
-      Assert.ok(b1.isActive);
-      Assert.ok(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
-      Assert.ok(b1.hasResource("install.rdf"));
-      Assert.ok(!b1.hasResource("bootstrap.js"));
-      do_check_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0");
+  let addon = await AddonManager.getAddonByID(ID_DICT);
+  notEqual(addon, null);
+  equal(addon.version, "1.0");
+  ok(!addon.appDisabled);
+  ok(!addon.userDisabled);
+  ok(addon.isActive);
+  ok(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
+  ok(addon.hasResource("install.rdf"));
+  ok(!addon.hasResource("bootstrap.js"));
+  do_check_in_crash_annotation(ID_DICT, "1.0");
 
-      let chromeReg = AM_Cc["@mozilla.org/chrome/chrome-registry;1"].
-                      getService(AM_Ci.nsIChromeRegistry);
-      try {
-        chromeReg.convertChromeURL(NetUtil.newURI("chrome://dict/content/dict.xul"));
-        do_throw("Chrome manifest should not have been registered");
-      } catch (e) {
-        // Expected the chrome url to not be registered
-      }
+  let chromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"].
+                  getService(Ci.nsIChromeRegistry);
+  try {
+    chromeReg.convertChromeURL(NetUtil.newURI("chrome://dict/content/dict.xul"));
+    do_throw("Chrome manifest should not have been registered");
+  } catch (e) {
+    // Expected the chrome url to not be registered
+  }
 
-      AddonManager.getAddonsWithOperationsByTypes(null, function(list) {
-        Assert.equal(list.length, 0);
-
-        run_test_2();
-      });
-    });
-  });
-}
+  let list = await AddonManager.getAddonsWithOperationsByTypes(null);
+  equal(list.length, 0);
+});
 
 // Tests that disabling doesn't require a restart
-function run_test_2() {
-  AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
-    prepare_test({
-      "ab-CD@dictionaries.addons.mozilla.org": [
-        ["onDisabling", false],
-        "onDisabled"
-      ]
-    });
+add_task(async function test_2() {
+  let addon = await AddonManager.getAddonByID(ID_DICT);
+  prepare_test({
+    [ID_DICT]: [
+      ["onDisabling", false],
+      "onDisabled"
+    ]
+  });
 
-    Assert.equal(b1.operationsRequiringRestart &
-                 AddonManager.OP_NEEDS_RESTART_DISABLE, 0);
-    b1.userDisabled = true;
-    ensure_test_completed();
+  equal(addon.operationsRequiringRestart &
+               AddonManager.OP_NEEDS_RESTART_DISABLE, 0);
+  addon.userDisabled = true;
+  ensure_test_completed();
 
-    Assert.notEqual(b1, null);
-    Assert.equal(b1.version, "1.0");
-    Assert.ok(!b1.appDisabled);
-    Assert.ok(b1.userDisabled);
-    Assert.ok(!b1.isActive);
-    Assert.ok(!HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
-    do_check_not_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0");
+  notEqual(addon, null);
+  equal(addon.version, "1.0");
+  ok(!addon.appDisabled);
+  ok(addon.userDisabled);
+  ok(!addon.isActive);
+  ok(!HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
+  do_check_not_in_crash_annotation(ID_DICT, "1.0");
 
-    AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(newb1) {
-      Assert.notEqual(newb1, null);
-      Assert.equal(newb1.version, "1.0");
-      Assert.ok(!newb1.appDisabled);
-      Assert.ok(newb1.userDisabled);
-      Assert.ok(!newb1.isActive);
-
-      executeSoon(run_test_3);
-    });
-  });
-}
+  addon = await AddonManager.getAddonByID(ID_DICT);
+  notEqual(addon, null);
+  equal(addon.version, "1.0");
+  ok(!addon.appDisabled);
+  ok(addon.userDisabled);
+  ok(!addon.isActive);
+});
 
 // Test that restarting doesn't accidentally re-enable
-function run_test_3() {
-  shutdownManager();
-  Assert.ok(!HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
-  startupManager(false);
-  Assert.ok(!HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
-  do_check_not_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0");
+add_task(async function test_3() {
+  await promiseShutdownManager();
+  ok(!HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
+  await promiseStartupManager(false);
+
+  ok(!HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
+  do_check_not_in_crash_annotation(ID_DICT, "1.0");
 
-  AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
-    Assert.notEqual(b1, null);
-    Assert.equal(b1.version, "1.0");
-    Assert.ok(!b1.appDisabled);
-    Assert.ok(b1.userDisabled);
-    Assert.ok(!b1.isActive);
-
-    run_test_4();
-  });
-}
+  let addon = await AddonManager.getAddonByID(ID_DICT);
+  notEqual(addon, null);
+  equal(addon.version, "1.0");
+  ok(!addon.appDisabled);
+  ok(addon.userDisabled);
+  ok(!addon.isActive);
+});
 
 // Tests that enabling doesn't require a restart
-function run_test_4() {
-  AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
-    prepare_test({
-      "ab-CD@dictionaries.addons.mozilla.org": [
-        ["onEnabling", false],
-        "onEnabled"
-      ]
-    });
+add_task(async function test_4() {
+  let addon = await AddonManager.getAddonByID(ID_DICT);
+  prepare_test({
+    [ID_DICT]: [
+      ["onEnabling", false],
+      "onEnabled"
+    ]
+  });
 
-    Assert.equal(b1.operationsRequiringRestart &
-                 AddonManager.OP_NEEDS_RESTART_ENABLE, 0);
-    b1.userDisabled = false;
-    ensure_test_completed();
+  equal(addon.operationsRequiringRestart &
+               AddonManager.OP_NEEDS_RESTART_ENABLE, 0);
+  addon.userDisabled = false;
+  ensure_test_completed();
 
-    Assert.notEqual(b1, null);
-    Assert.equal(b1.version, "1.0");
-    Assert.ok(!b1.appDisabled);
-    Assert.ok(!b1.userDisabled);
-    Assert.ok(b1.isActive);
-    Assert.ok(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
-    do_check_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0");
+  notEqual(addon, null);
+  equal(addon.version, "1.0");
+  ok(!addon.appDisabled);
+  ok(!addon.userDisabled);
+  ok(addon.isActive);
+  ok(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
+  do_check_in_crash_annotation(ID_DICT, "1.0");
 
-    AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(newb1) {
-      Assert.notEqual(newb1, null);
-      Assert.equal(newb1.version, "1.0");
-      Assert.ok(!newb1.appDisabled);
-      Assert.ok(!newb1.userDisabled);
-      Assert.ok(newb1.isActive);
-
-      executeSoon(run_test_5);
-    });
-  });
-}
+  addon = await AddonManager.getAddonByID(ID_DICT);
+  notEqual(addon, null);
+  equal(addon.version, "1.0");
+  ok(!addon.appDisabled);
+  ok(!addon.userDisabled);
+  ok(addon.isActive);
+});
 
 // Tests that a restart shuts down and restarts the add-on
-function run_test_5() {
-  shutdownManager();
-  Assert.ok(!HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
-  do_check_not_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0");
-  startupManager(false);
-  Assert.ok(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
-  do_check_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0");
+add_task(async function test_5() {
+  await promiseShutdownManager();
+
+  ok(!HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
+  do_check_not_in_crash_annotation(ID_DICT, "1.0");
+
+  await promiseStartupManager(false);
 
-  AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
-    Assert.notEqual(b1, null);
-    Assert.equal(b1.version, "1.0");
-    Assert.ok(!b1.appDisabled);
-    Assert.ok(!b1.userDisabled);
-    Assert.ok(b1.isActive);
-    Assert.ok(!isExtensionInAddonsList(profileDir, b1.id));
+  ok(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
+  do_check_in_crash_annotation(ID_DICT, "1.0");
 
-    run_test_7();
-  });
-}
+  let addon = await AddonManager.getAddonByID(ID_DICT);
+  notEqual(addon, null);
+  equal(addon.version, "1.0");
+  ok(!addon.appDisabled);
+  ok(!addon.userDisabled);
+  ok(addon.isActive);
+  ok(!isExtensionInAddonsList(profileDir, addon.id));
+});
 
 // Tests that uninstalling doesn't require a restart
-function run_test_7() {
-  AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
-    prepare_test({
-      "ab-CD@dictionaries.addons.mozilla.org": [
-        ["onUninstalling", false],
-        "onUninstalled"
-      ]
-    });
+add_task(async function test_7() {
+  let addon = await AddonManager.getAddonByID(ID_DICT);
+  prepare_test({
+    [ID_DICT]: [
+      ["onUninstalling", false],
+      "onUninstalled"
+    ]
+  });
 
-    Assert.equal(b1.operationsRequiringRestart &
-                 AddonManager.OP_NEEDS_RESTART_UNINSTALL, 0);
-    b1.uninstall();
-
-    check_test_7();
-  });
-}
+  equal(addon.operationsRequiringRestart &
+               AddonManager.OP_NEEDS_RESTART_UNINSTALL, 0);
+  addon.uninstall();
 
-function check_test_7() {
   ensure_test_completed();
-  Assert.ok(!HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
-  do_check_not_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0");
 
-  AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org",
-   callback_soon(function(b1) {
-    Assert.equal(b1, null);
+  ok(!HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
+  do_check_not_in_crash_annotation(ID_DICT, "1.0");
 
-    restartManager();
-
-    AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(newb1) {
-      Assert.equal(newb1, null);
+  addon = await AddonManager.getAddonByID(ID_DICT);
+  equal(addon, null);
 
-      executeSoon(run_test_8);
-    });
-  }));
-}
+  await promiseRestartManager();
+
+  addon = await AddonManager.getAddonByID(ID_DICT);
+  equal(addon, null);
+});
 
 // 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();
+add_task(async function test_8() {
+  await promiseShutdownManager();
+  await AddonTestUtils.manuallyInstall(XPI_DICT);
+  await promiseStartupManager(false);
 
-  let dir = profileDir.clone();
-  dir.append("ab-CD@dictionaries.addons.mozilla.org");
-  dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0o755);
-  let zip = AM_Cc["@mozilla.org/libjar/zip-reader;1"].
-            createInstance(AM_Ci.nsIZipReader);
-  zip.open(do_get_addon("test_dictionary"));
-  dir.append("install.rdf");
-  zip.extract("install.rdf", dir);
-  dir.permissions |= FileUtils.PERMS_FILE;
-  dir = dir.parent;
-  dir.append("dictionaries");
-  dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0o755);
-  dir.append("ab-CD.dic");
-  zip.extract("dictionaries/ab-CD.dic", dir);
-  dir.permissions |= FileUtils.PERMS_FILE;
-  zip.close();
-
-  startupManager(false);
-
-  AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
-    Assert.notEqual(b1, null);
-    Assert.equal(b1.version, "1.0");
-    Assert.ok(!b1.appDisabled);
-    Assert.ok(!b1.userDisabled);
-    Assert.ok(b1.isActive);
-    Assert.ok(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
-    do_check_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0");
-
-    executeSoon(run_test_9);
-  });
-}
+  let addon = await AddonManager.getAddonByID(ID_DICT);
+  notEqual(addon, null);
+  equal(addon.version, "1.0");
+  ok(!addon.appDisabled);
+  ok(!addon.userDisabled);
+  ok(addon.isActive);
+  ok(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
+  do_check_in_crash_annotation(ID_DICT, "1.0");
+});
 
 // 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);
+add_task(async function test_9() {
+  await promiseShutdownManager();
+  await AddonTestUtils.manuallyUninstall(profileDir, ID_DICT);
+  await promiseStartupManager(false);
 
-  AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
-    Assert.equal(b1, null);
-    do_check_not_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0");
-
-    executeSoon(run_test_12);
-  });
-}
+  let addon = await AddonManager.getAddonByID(ID_DICT);
+  equal(addon, null);
+  do_check_not_in_crash_annotation(ID_DICT, "1.0");
+});
 
 
 // Tests that bootstrapped extensions are correctly loaded even if the app is
 // upgraded at the same time
-function run_test_12() {
-  shutdownManager();
+add_task(async function test_12() {
+  await promiseShutdownManager();
+  await AddonTestUtils.manuallyInstall(XPI_DICT);
+  await promiseStartupManager(true);
 
-  let dir = profileDir.clone();
-  dir.append("ab-CD@dictionaries.addons.mozilla.org");
-  dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0o755);
-  let zip = AM_Cc["@mozilla.org/libjar/zip-reader;1"].
-            createInstance(AM_Ci.nsIZipReader);
-  zip.open(do_get_addon("test_dictionary"));
-  dir.append("install.rdf");
-  zip.extract("install.rdf", dir);
-  dir = dir.parent;
-  dir.append("dictionaries");
-  dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0o755);
-  dir.append("ab-CD.dic");
-  zip.extract("dictionaries/ab-CD.dic", dir);
-  zip.close();
+  let addon = await AddonManager.getAddonByID(ID_DICT);
+  notEqual(addon, null);
+  equal(addon.version, "1.0");
+  ok(!addon.appDisabled);
+  ok(!addon.userDisabled);
+  ok(addon.isActive);
+  ok(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
+  do_check_in_crash_annotation(ID_DICT, "1.0");
 
-  startupManager(true);
-
-  AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
-    Assert.notEqual(b1, null);
-    Assert.equal(b1.version, "1.0");
-    Assert.ok(!b1.appDisabled);
-    Assert.ok(!b1.userDisabled);
-    Assert.ok(b1.isActive);
-    Assert.ok(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
-    do_check_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0");
-
-    b1.uninstall();
-    executeSoon(run_test_16);
-  });
-}
+  addon.uninstall();
+});
 
 
 // Tests that bootstrapped extensions don't get loaded when in safe mode
-function run_test_16() {
-  restartManager();
+add_task(async function test_16() {
+  await promiseRestartManager();
+  await promiseInstallFile(do_get_addon("test_dictionary"));
+
+  // spin the event loop to let the addon finish starting
+  await new Promise(executeSoon);
 
-  installAllFiles([do_get_addon("test_dictionary")], function() {
-    // spin the event loop to let the addon finish starting
-   executeSoon(function check_installed_dictionary() {
-    AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org",
-     callback_soon(function(b1) {
-      // Should have installed and started
-      Assert.ok(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
+  let addon = await AddonManager.getAddonByID(ID_DICT);
+  // Should have installed and started
+  ok(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
 
-      shutdownManager();
+  await promiseShutdownManager();
 
-      // Should have stopped
-      Assert.ok(!HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
-
-      gAppInfo.inSafeMode = true;
-      startupManager(false);
+  // Should have stopped
+  ok(!HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
 
-      AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org",
-       callback_soon(function(b1_2) {
-        // Should still be stopped
-        Assert.ok(!HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
-        Assert.ok(!b1_2.isActive);
+  gAppInfo.inSafeMode = true;
+  await promiseStartupManager(false);
 
-        shutdownManager();
-        gAppInfo.inSafeMode = false;
-        startupManager(false);
+  addon = await AddonManager.getAddonByID(ID_DICT);
+  // Should still be stopped
+  ok(!HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
+  ok(!addon.isActive);
 
-        // Should have started
-        Assert.ok(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
-
-        AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1_3) {
-          b1_3.uninstall();
+  await promiseShutdownManager();
+  gAppInfo.inSafeMode = false;
+  await promiseStartupManager(false);
 
-          executeSoon(run_test_17);
-        });
-      }));
-    }));
-   });
-  });
-}
+  // Should have started
+  ok(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
+
+  addon = await AddonManager.getAddonByID(ID_DICT);
+  addon.uninstall();
+});
 
 // Check that a bootstrapped extension in a non-profile location is loaded
-function run_test_17() {
-  shutdownManager();
-
-  let dir = userExtDir.clone();
-  dir.append("ab-CD@dictionaries.addons.mozilla.org");
-  dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0o755);
-  let zip = AM_Cc["@mozilla.org/libjar/zip-reader;1"].
-            createInstance(AM_Ci.nsIZipReader);
-  zip.open(do_get_addon("test_dictionary"));
-  dir.append("install.rdf");
-  zip.extract("install.rdf", dir);
-  dir.permissions |= FileUtils.PERMS_FILE;
-  dir = dir.parent;
-  dir.append("dictionaries");
-  dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0o755);
-  dir.append("ab-CD.dic");
-  zip.extract("dictionaries/ab-CD.dic", dir);
-  dir.permissions |= FileUtils.PERMS_FILE;
-  zip.close();
+add_task(async function test_17() {
+  await promiseShutdownManager();
+  await AddonTestUtils.manuallyInstall(XPI_DICT, userExtDir);
+  await promiseStartupManager();
 
-  startupManager();
-
-  AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org",
-   callback_soon(function(b1) {
-    // Should have installed and started
-    Assert.ok(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
-    Assert.notEqual(b1, null);
-    Assert.equal(b1.version, "1.0");
-    Assert.ok(b1.isActive);
+  let addon = await AddonManager.getAddonByID(ID_DICT);
+  // Should have installed and started
+  ok(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
+  notEqual(addon, null);
+  equal(addon.version, "1.0");
+  ok(addon.isActive);
 
-    // From run_test_21
-    dir = userExtDir.clone();
-    dir.append("ab-CD@dictionaries.addons.mozilla.org");
-    dir.remove(true);
-
-    restartManager();
-
-    run_test_23();
-  }));
-}
+  await AddonTestUtils.manuallyUninstall(userExtDir, ID_DICT);
+  await promiseRestartManager();
+});
 
 // Tests that installing from a URL doesn't require a restart
-function run_test_23() {
+add_task(async function test_23() {
   prepare_test({ }, [
     "onNewInstall"
   ]);
 
-  let url = "http://localhost:" + gPort + "/addons/test_dictionary.xpi";
-  AddonManager.getInstallForURL(url, function(install) {
-    ensure_test_completed();
+  let url = "http://example.com/addons/test_dictionary.xpi";
+  let install = await AddonManager.getInstallForURL(url, null,
+                                                    "application/x-xpinstall");
+  ensure_test_completed();
 
-    Assert.notEqual(install, null);
+  notEqual(install, null);
 
+  await new Promise(resolve => {
     prepare_test({ }, [
       "onDownloadStarted",
       "onDownloadEnded"
     ], function() {
-      Assert.equal(install.type, "dictionary");
-      Assert.equal(install.version, "1.0");
-      Assert.equal(install.name, "Test Dictionary");
-      Assert.equal(install.state, AddonManager.STATE_DOWNLOADED);
-      Assert.ok(install.addon.hasResource("install.rdf"));
-      Assert.ok(!install.addon.hasResource("bootstrap.js"));
-      Assert.equal(install.addon.operationsRequiringRestart &
+      equal(install.type, "dictionary");
+      equal(install.version, "1.0");
+      equal(install.name, "Test Dictionary");
+      equal(install.state, AddonManager.STATE_DOWNLOADED);
+      ok(install.addon.hasResource("install.rdf"));
+      ok(!install.addon.hasResource("bootstrap.js"));
+      equal(install.addon.operationsRequiringRestart &
                    AddonManager.OP_NEEDS_RESTART_INSTALL, 0);
-      do_check_not_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0");
+      do_check_not_in_crash_annotation(ID_DICT, "1.0");
 
       let addon = install.addon;
       prepare_test({
-        "ab-CD@dictionaries.addons.mozilla.org": [
+        [ID_DICT]: [
           ["onInstalling", false],
           "onInstalled"
         ]
       }, [
         "onInstallStarted",
         "onInstallEnded",
       ], function() {
-        Assert.ok(addon.hasResource("install.rdf"));
+        ok(addon.hasResource("install.rdf"));
         // spin to let the addon startup finish
-        executeSoon(check_test_23);
+        resolve();
       });
     });
     install.install();
-  }, "application/x-xpinstall");
-}
+  });
 
-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.
-    Assert.equal(installs.length, 0);
+  let installs = await AddonManager.getAllInstalls();
+  // There should be no active installs now since the install completed and
+  // doesn't require a restart.
+  equal(installs.length, 0);
 
-    AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
-      Assert.notEqual(b1, null);
-      Assert.equal(b1.version, "1.0");
-      Assert.ok(!b1.appDisabled);
-      Assert.ok(!b1.userDisabled);
-      Assert.ok(b1.isActive);
-      Assert.ok(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
-      Assert.ok(b1.hasResource("install.rdf"));
-      Assert.ok(!b1.hasResource("bootstrap.js"));
-      do_check_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0");
+  let addon = await AddonManager.getAddonByID(ID_DICT);
+  notEqual(addon, null);
+  equal(addon.version, "1.0");
+  ok(!addon.appDisabled);
+  ok(!addon.userDisabled);
+  ok(addon.isActive);
+  ok(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
+  ok(addon.hasResource("install.rdf"));
+  ok(!addon.hasResource("bootstrap.js"));
+  do_check_in_crash_annotation(ID_DICT, "1.0");
 
-      AddonManager.getAddonsWithOperationsByTypes(null, callback_soon(function(list) {
-        Assert.equal(list.length, 0);
+  let list = await AddonManager.getAddonsWithOperationsByTypes(null);
+  equal(list.length, 0);
 
-        restartManager();
-        AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1_2) {
-          b1_2.uninstall();
-          executeSoon(run_test_29);
-        });
-      }));
-    });
-  });
-}
+  await promiseRestartManager();
+
+  addon = await AddonManager.getAddonByID(ID_DICT);
+  addon.uninstall();
+});
 
 // Tests that an update check from a bootstrappable add-on to a bootstrappable add-on works
-function run_test_29() {
-  restartManager();
+add_task(async function test_29() {
+  await promiseRestartManager();
 
-  writeInstallRDFForExtension({
+  await promiseWriteInstallRDFForExtension({
     id: "gh@dictionaries.addons.mozilla.org",
     version: "1.0",
     type: "64",
-    updateURL: "http://localhost:" + gPort + "/data/test_dictionary.json",
+    updateURL: "http://example.com/data/test_dictionary.json",
     targetApplications: [{
       id: "xpcshell@tests.mozilla.org",
       minVersion: "1",
       maxVersion: "1"
     }],
     name: "Test Dictionary gh",
   }, profileDir);
-  restartManager();
+
+  await promiseRestartManager();
 
-  prepare_test({
-    "gh@dictionaries.addons.mozilla.org": [
-      ["onInstalling", false /* = no restart */],
-      ["onInstalled", false]
-    ]
-  }, [
-    "onNewInstall",
-    "onDownloadStarted",
-    "onDownloadEnded",
-    "onInstallStarted",
-    "onInstallEnded"
-  ], check_test_29);
+  await new Promise(resolve => {
+    prepare_test({
+      "gh@dictionaries.addons.mozilla.org": [
+        ["onInstalling", false /* = no restart */],
+        ["onInstalled", false]
+      ]
+    }, [
+      "onNewInstall",
+      "onDownloadStarted",
+      "onDownloadEnded",
+      "onInstallStarted",
+      "onInstallEnded"
+    ], resolve);
 
-  AddonManagerPrivate.backgroundUpdateCheck();
-}
+    AddonManagerPrivate.backgroundUpdateCheck();
+  });
 
-function check_test_29(install) {
-  AddonManager.getAddonByID("gh@dictionaries.addons.mozilla.org", function(b2) {
-    Assert.notEqual(b2, null);
-    Assert.equal(b2.version, "2.0");
-    Assert.equal(b2.type, "dictionary");
+  let addon = await AddonManager.getAddonByID("gh@dictionaries.addons.mozilla.org");
+  notEqual(addon, null);
+  equal(addon.version, "2.0");
+  equal(addon.type, "dictionary");
 
+  await new Promise(resolve => {
     prepare_test({
       "gh@dictionaries.addons.mozilla.org": [
         ["onUninstalling", false],
         ["onUninstalled", false],
       ]
     }, [
-    ], callback_soon(finish_test_29));
+    ], resolve);
 
-    b2.uninstall();
+    addon.uninstall();
   });
-}
-
-function finish_test_29() {
-  testserver.stop(do_test_finished);
-}
+});