Backed out 2 changesets (bug 1365021) for xpcshell failures in toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_OS.js on a CLOSED TREE
authorNoemi Erli <nerli@mozilla.com>
Wed, 28 Mar 2018 07:18:37 +0300
changeset 773641 60d3e9b4aea9a036b02b1c7cb547930fc94c33a7
parent 773640 64eaee27492a1a37905780f7cac1bbe83a305021
child 773642 dea16926510733a02d98073d3a64bf7279462b99
push id104266
push userbmo:hsivonen@hsivonen.fi
push dateWed, 28 Mar 2018 07:33:03 +0000
bugs1365021
milestone61.0a1
backs outcf2f8604cb5ee52c143c91f56d465a8486ff8f1b
2aa1a76c7dfb765f1434d8a774f83debc69ee305
Backed out 2 changesets (bug 1365021) for xpcshell failures in toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_OS.js on a CLOSED TREE Backed out changeset cf2f8604cb5e Backed out changeset 2aa1a76c7dfb (bug 1365021)
toolkit/mozapps/extensions/test/addons/test_bootstrap1_3/bootstrap.js
toolkit/mozapps/extensions/test/addons/test_bootstrap1_3/install.rdf
toolkit/mozapps/extensions/test/addons/test_bootstrap1_3/version.jsm
toolkit/mozapps/extensions/test/addons/test_bootstrap1_4/install.rdf
toolkit/mozapps/extensions/test/addons/test_bootstrap2_1/bootstrap.js
toolkit/mozapps/extensions/test/addons/test_bootstrap2_1/install.rdf
toolkit/mozapps/extensions/test/xpcshell/data/test_AddonRepository_getAddonsByIDs.json
toolkit/mozapps/extensions/test/xpcshell/data/test_backgroundupdate.json
toolkit/mozapps/extensions/test/xpcshell/data/test_delay_updates_complete.json
toolkit/mozapps/extensions/test/xpcshell/data/test_delay_updates_complete_legacy.json
toolkit/mozapps/extensions/test/xpcshell/data/test_delay_updates_defer.json
toolkit/mozapps/extensions/test/xpcshell/data/test_delay_updates_defer_legacy.json
toolkit/mozapps/extensions/test/xpcshell/data/test_delay_updates_ignore.json
toolkit/mozapps/extensions/test/xpcshell/data/test_delay_updates_ignore_legacy.json
toolkit/mozapps/extensions/test/xpcshell/data/test_updatecompatmode_ignore.json
toolkit/mozapps/extensions/test/xpcshell/data/test_updatecompatmode_normal.json
toolkit/mozapps/extensions/test/xpcshell/data/test_updatecompatmode_strict.json
toolkit/mozapps/extensions/test/xpcshell/head_addons.js
toolkit/mozapps/extensions/test/xpcshell/test_AddonRepository.js
toolkit/mozapps/extensions/test/xpcshell/test_ProductAddonChecker.js
toolkit/mozapps/extensions/test/xpcshell/test_asyncBlocklistLoad.js
toolkit/mozapps/extensions/test/xpcshell/test_backgroundupdate.js
toolkit/mozapps/extensions/test/xpcshell/test_bad_json.js
toolkit/mozapps/extensions/test/xpcshell/test_badschema.js
toolkit/mozapps/extensions/test/xpcshell/test_blocklist_metadata_filters.js
toolkit/mozapps/extensions/test/xpcshell/test_blocklist_prefs.js
toolkit/mozapps/extensions/test/xpcshell/test_blocklist_regexp.js
toolkit/mozapps/extensions/test/xpcshell/test_blocklistchange.js
toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js
toolkit/mozapps/extensions/test/xpcshell/test_bug384052.js
toolkit/mozapps/extensions/test/xpcshell/test_bug393285.js
toolkit/mozapps/extensions/test/xpcshell/test_bug406118.js
toolkit/mozapps/extensions/test/xpcshell/test_bug430120.js
toolkit/mozapps/extensions/test/xpcshell/test_bug455906.js
toolkit/mozapps/extensions/test/xpcshell/test_bug587088.js
toolkit/mozapps/extensions/test/xpcshell/test_bug596607.js
toolkit/mozapps/extensions/test/xpcshell/test_bug619730.js
toolkit/mozapps/extensions/test/xpcshell/test_bug620837.js
toolkit/mozapps/extensions/test/xpcshell/test_bug655254.js
toolkit/mozapps/extensions/test/xpcshell/test_cacheflush.js
toolkit/mozapps/extensions/test/xpcshell/test_childprocess.js
toolkit/mozapps/extensions/test/xpcshell/test_corrupt.js
toolkit/mozapps/extensions/test/xpcshell/test_delay_update.js
toolkit/mozapps/extensions/test/xpcshell/test_delay_update_webextension.js
toolkit/mozapps/extensions/test/xpcshell/test_filepointer.js
toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_Device.js
toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_DriverNew.js
toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_Equal_DriverNew.js
toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_Equal_DriverOld.js
toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_Equal_OK.js
toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_GTE_DriverOld.js
toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_GTE_OK.js
toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_No_Comparison.js
toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_OK.js
toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_OS.js
toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_OSVersion_match.js
toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_OSVersion_mismatch_DriverVersion.js
toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_OSVersion_mismatch_OSVersion.js
toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_Vendor.js
toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_Version.js
toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_prefs.js
toolkit/mozapps/extensions/test/xpcshell/test_isDebuggable.js
toolkit/mozapps/extensions/test/xpcshell/test_manifest.js
toolkit/mozapps/extensions/test/xpcshell/test_migrate_state_prefs.js
toolkit/mozapps/extensions/test/xpcshell/test_permissions.js
toolkit/mozapps/extensions/test/xpcshell/test_pluginBlocklistCtp.js
toolkit/mozapps/extensions/test/xpcshell/test_pluginchange.js
toolkit/mozapps/extensions/test/xpcshell/test_plugins.js
toolkit/mozapps/extensions/test/xpcshell/test_proxies.js
toolkit/mozapps/extensions/test/xpcshell/test_registry.js
toolkit/mozapps/extensions/test/xpcshell/test_signed_inject.js
toolkit/mozapps/extensions/test/xpcshell/test_signed_install.js
toolkit/mozapps/extensions/test/xpcshell/test_switch_os.js
toolkit/mozapps/extensions/test/xpcshell/test_system_reset.js
toolkit/mozapps/extensions/test/xpcshell/test_updateCancel.js
toolkit/mozapps/extensions/test/xpcshell/test_update_compatmode.js
toolkit/mozapps/extensions/test/xpcshell/test_update_ignorecompat.js
toolkit/mozapps/extensions/test/xpcshell/test_update_webextensions.js
toolkit/mozapps/extensions/test/xpcshell/test_upgrade.js
toolkit/mozapps/extensions/test/xpcshell/test_webextension.js
toolkit/mozapps/extensions/test/xpcshell/test_webextension_icons.js
toolkit/mozapps/extensions/test/xpcshell/test_webextension_install.js
toolkit/mozapps/extensions/test/xpcshell/test_webextension_theme.js
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/addons/test_bootstrap1_3/bootstrap.js
@@ -0,0 +1,1 @@
+ChromeUtils.import("resource://xpcshell-data/BootstrapMonitor.jsm").monitor(this);
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/addons/test_bootstrap1_3/install.rdf
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+
+<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+     xmlns:em="http://www.mozilla.org/2004/em-rdf#">
+
+  <Description about="urn:mozilla:install-manifest">
+    <em:id>bootstrap1@tests.mozilla.org</em:id>
+    <em:version>3.0</em:version>
+    <em:bootstrap>true</em:bootstrap>
+
+    <!-- Front End MetaData -->
+    <em:name>Test Bootstrap 1</em:name>
+    <em:description>Test Description</em:description>
+
+    <em:targetApplication>
+      <Description>
+        <em:id>undefined</em:id>
+        <em:minVersion>1</em:minVersion>
+        <em:maxVersion>1</em:maxVersion>
+      </Description>
+    </em:targetApplication>
+
+  </Description>
+</RDF>
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/addons/test_bootstrap1_3/version.jsm
@@ -0,0 +1,3 @@
+var EXPORTED_SYMBOLS = ["VERSION"];
+
+var VERSION = 3;
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/addons/test_bootstrap1_4/install.rdf
@@ -0,0 +1,23 @@
+<?xml version="1.0"?>
+
+<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+     xmlns:em="http://www.mozilla.org/2004/em-rdf#">
+
+  <Description about="urn:mozilla:install-manifest">
+    <em:id>bootstrap1@tests.mozilla.org</em:id>
+    <em:version>4.0</em:version>
+
+    <!-- Front End MetaData -->
+    <em:name>Test Bootstrap 1</em:name>
+    <em:description>Test Description</em:description>
+
+    <em:targetApplication>
+      <Description>
+        <em:id>xpcshell@tests.mozilla.org</em:id>
+        <em:minVersion>1</em:minVersion>
+        <em:maxVersion>1</em:maxVersion>
+      </Description>
+    </em:targetApplication>
+
+  </Description>
+</RDF>
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/addons/test_bootstrap2_1/bootstrap.js
@@ -0,0 +1,1 @@
+ChromeUtils.import("resource://xpcshell-data/BootstrapMonitor.jsm").monitor(this);
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/addons/test_bootstrap2_1/install.rdf
@@ -0,0 +1,29 @@
+<?xml version="1.0"?>
+
+<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+     xmlns:em="http://www.mozilla.org/2004/em-rdf#">
+
+  <Description about="urn:mozilla:install-manifest">
+    <em:id>bootstrap2@tests.mozilla.org</em:id>
+    <em:version>1.0</em:version>
+    <em:bootstrap>true</em:bootstrap>
+    <em:multiprocessCompatible>true</em:multiprocessCompatible>
+
+    <!-- Front End MetaData -->
+    <em:name>Test Bootstrap 2</em:name>
+    <em:description>Test Description</em:description>
+
+    <em:iconURL>chrome://foo/skin/icon.png</em:iconURL>
+    <em:aboutURL>chrome://foo/content/about.xul</em:aboutURL>
+    <em:optionsURL>chrome://foo/content/options.xul</em:optionsURL>
+
+    <em:targetApplication>
+      <Description>
+        <em:id>xpcshell@tests.mozilla.org</em:id>
+        <em:minVersion>1</em:minVersion>
+        <em:maxVersion>1</em:maxVersion>
+      </Description>
+    </em:targetApplication>
+
+  </Description>
+</RDF>
--- a/toolkit/mozapps/extensions/test/xpcshell/data/test_AddonRepository_getAddonsByIDs.json
+++ b/toolkit/mozapps/extensions/test/xpcshell/data/test_AddonRepository_getAddonsByIDs.json
@@ -9,71 +9,71 @@
             "name": "PASS",
             "type": "extension",
             "guid": "test1@tests.mozilla.org",
             "current_version": {
                 "version": "1.1",
                 "files": [
                     {
                         "platform": "all",
-                        "url": "http://example.com/addons/test_AddonRepository_2.xpi",
+                        "url": "http://localhost:%PORT%/addons/test_AddonRepository_2.xpi",
                         "size": 5555
                     }
                 ]
             },
             "authors": [
                 {
                     "name": "Test Creator 1",
-                    "url": "http://example.com/creator1.html"
+                    "url": "http://localhost:%PORT%/creator1.html"
                 },
                 {
                     "name": "Test Developer 1",
-                    "url": "http://example.com/developer1.html"
+                    "url": "http://localhost:%PORT%/developer1.html"
                 }
             ],
             "summary": "Test Summary 1",
             "description": "Test Description 1",
             "icons": {
-              "32": "http://example.com/icon1.png"
+              "32": "http://localhost:%PORT%/icon1.png"
             },
             "previews": [
                 {
                     "caption": "Caption 1 - 1",
                     "image_size": [400, 300],
-                    "image_url": "http://example.com/full1-1.png",
+                    "image_url": "http://localhost:%PORT%/full1-1.png",
                     "thumbnail_size": [200, 150],
-                    "thumbnail_url": "http://example.com/thumbnail1-1.png"
+                    "thumbnail_url": "http://localhost:%PORT%/thumbnail1-1.png"
                 },
                 {
                     "caption": "Caption 2 - 1",
-                    "image_url": "http://example.com/full2-1.png",
-                    "thumbnail_url": "http://example.com/thumbnail2-1.png"
+                    "image_url": "http://localhost:%PORT%/full2-1.png",
+                    "thumbnail_url": "http://localhost:%PORT%/thumbnail2-1.png"
                 }
             ],
             "ratings": {
                 "count": 1234,
                 "text_count": 1111,
                 "average": 4
             },
-            "ratings_url": "http://example.com/review1.html",
-            "support_url": "http://example.com/support1.html",
-            "contributions_url": "http://example.com/contribution1.html",
+            "ratings_url": "http://localhost:%PORT%/review1.html",
+            "support_url": "http://localhost:%PORT%/support1.html",
+            "contributions_url": "http://localhost:%PORT%/contribution1.html",
             "weekly_downloads": 3333,
             "last_updated": "2010-02-01T14:04:05Z"
         },
         {
             "name": "FAIL",
             "type": "extension",
             "guid": "notRequested@tests.mozilla.org",
             "current_version": {
                 "version": "1.3",
                 "files": [
                     {
                         "platform": "all",
-                        "url": "http://example.com/test3.xpi"
+                        "url": "http://localhost:%PORT%/test3.xpi"
                     }
                 ]
             },
             "authors": [
                 {
                     "name": "Test Creator 3"
                 }
             ],
@@ -83,20 +83,20 @@
             "name": "PASS",
             "type": "theme",
             "guid": "test_AddonRepository_1@tests.mozilla.org",
             "current_version": {
                 "version": "1.4",
                 "files": [
                     {
                         "platform": "UNKNOWN1",
-                        "url": "http://example.com/test4.xpi"
+                        "url": "http://localhost:%PORT%/test4.xpi"
                     },
                     {
                         "platform": "UNKNOWN2",
-                        "url": "http://example.com/test4.xpi"
+                        "url": "http://localhost:%PORT%/test4.xpi"
                     }
                 ]
             }
         }
     ]
 }
 
--- a/toolkit/mozapps/extensions/test/xpcshell/data/test_backgroundupdate.json
+++ b/toolkit/mozapps/extensions/test/xpcshell/data/test_backgroundupdate.json
@@ -5,42 +5,42 @@
         {
           "applications": {
             "gecko": {
               "strict_min_version": "1",
               "advisory_max_version": "1"
             }
           },
           "version": "2",
-          "update_link": "http://example.com/broken.xpi"
+          "update_link": "http://localhost:%PORT%/broken.xpi"
         }
       ]
     },
     "addon3@tests.mozilla.org": {
       "updates": [
         {
           "applications": {
             "gecko": {
               "strict_min_version": "1",
               "advisory_max_version": "1"
             }
           },
           "version": "2",
-          "update_link": "http://example.com/broken.xpi"
+          "update_link": "http://localhost:%PORT%/broken.xpi"
         }
       ]
     },
     "addon1@tests.mozilla.org": {
       "updates": [
         {
           "applications": {
             "gecko": {
               "strict_min_version": "1",
               "advisory_max_version": "1"
             }
           },
           "version": "2",
-          "update_link": "http://example.com/broken.xpi"
+          "update_link": "http://localhost:%PORT%/broken.xpi"
         }
       ]
     }
   }
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/data/test_delay_updates_complete.json
+++ b/toolkit/mozapps/extensions/test/xpcshell/data/test_delay_updates_complete.json
@@ -1,11 +1,11 @@
 {
   "addons": {
     "test_delay_update_complete_webext@tests.mozilla.org": {
       "updates": [
         { "version": "2.0",
-          "update_link": "http://example.com/addons/test_delay_update_complete_webextension_v2.xpi"
+          "update_link": "http://localhost:%PORT%/addons/test_delay_update_complete_webextension_v2.xpi"
         }
       ]
     }
   }
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/data/test_delay_updates_complete_legacy.json
+++ b/toolkit/mozapps/extensions/test/xpcshell/data/test_delay_updates_complete_legacy.json
@@ -5,14 +5,14 @@
         {
           "applications": {
             "gecko": {
               "strict_min_version": "1",
               "advisory_max_version": "1"
             }
           },
           "version": "2.0",
-          "update_link": "http://example.com/addons/test_delay_update_complete_v2.xpi"
+          "update_link": "http://localhost:%PORT%/addons/test_delay_update_complete_v2.xpi"
         }
       ]
     }
   }
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/data/test_delay_updates_defer.json
+++ b/toolkit/mozapps/extensions/test/xpcshell/data/test_delay_updates_defer.json
@@ -1,11 +1,11 @@
 {
   "addons": {
     "test_delay_update_defer_webext@tests.mozilla.org": {
       "updates": [
         { "version": "2.0",
-          "update_link": "http://example.com/addons/test_delay_update_defer_webextension_v2.xpi"
+          "update_link": "http://localhost:%PORT%/addons/test_delay_update_defer_webextension_v2.xpi"
         }
       ]
     }
   }
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/data/test_delay_updates_defer_legacy.json
+++ b/toolkit/mozapps/extensions/test/xpcshell/data/test_delay_updates_defer_legacy.json
@@ -5,14 +5,14 @@
         {
           "applications": {
             "gecko": {
               "strict_min_version": "1",
               "advisory_max_version": "1"
             }
           },
           "version": "2.0",
-          "update_link": "http://example.com/addons/test_delay_update_defer_v2.xpi"
+          "update_link": "http://localhost:%PORT%/addons/test_delay_update_defer_v2.xpi"
         }
       ]
     }
   }
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/data/test_delay_updates_ignore.json
+++ b/toolkit/mozapps/extensions/test/xpcshell/data/test_delay_updates_ignore.json
@@ -1,11 +1,11 @@
 {
   "addons": {
     "test_delay_update_ignore_webext@tests.mozilla.org": {
       "updates": [
         { "version": "2.0",
-          "update_link": "http://example.com/addons/test_delay_update_ignore_webextension_v2.xpi"
+          "update_link": "http://localhost:%PORT%/addons/test_delay_update_ignore_webextension_v2.xpi"
         }
       ]
     }
   }
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/data/test_delay_updates_ignore_legacy.json
+++ b/toolkit/mozapps/extensions/test/xpcshell/data/test_delay_updates_ignore_legacy.json
@@ -5,14 +5,14 @@
         {
           "applications": {
             "gecko": {
               "strict_min_version": "1",
               "advisory_max_version": "1"
             }
           },
           "version": "2.0",
-          "update_link": "http://example.com/addons/test_delay_update_ignore_v2.xpi"
+          "update_link": "http://localhost:%PORT%/addons/test_delay_update_ignore_v2.xpi"
         }
       ]
     }
   }
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/data/test_updatecompatmode_ignore.json
+++ b/toolkit/mozapps/extensions/test/xpcshell/data/test_updatecompatmode_ignore.json
@@ -5,14 +5,14 @@
         {
           "applications": {
             "gecko": {
               "strict_min_version": "1",
               "advisory_max_version": "2"
             }
           },
           "version": "2.0",
-          "update_link": "https://example.com/addons/test1.xpi"
+          "update_link": "https://localhost:%PORT%/addons/test1.xpi"
         }
       ]
     }
   }
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/data/test_updatecompatmode_normal.json
+++ b/toolkit/mozapps/extensions/test/xpcshell/data/test_updatecompatmode_normal.json
@@ -5,14 +5,14 @@
         {
           "applications": {
             "gecko": {
               "strict_min_version": "1",
               "advisory_max_version": "2"
             }
           },
           "version": "2.0",
-          "update_link": "https://example.com/addons/test1.xpi"
+          "update_link": "https://localhost:%PORT%/addons/test1.xpi"
         }
       ]
     }
   }
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/data/test_updatecompatmode_strict.json
+++ b/toolkit/mozapps/extensions/test/xpcshell/data/test_updatecompatmode_strict.json
@@ -5,14 +5,14 @@
         {
           "applications": {
             "gecko": {
               "strict_min_version": "1",
               "advisory_max_version": "2"
             }
           },
           "version": "2.0",
-          "update_link": "https://example.com/addons/test1.xpi"
+          "update_link": "https://localhost:%PORT%/addons/test1.xpi"
         }
       ]
     }
   }
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/head_addons.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/head_addons.js
@@ -1,20 +1,27 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 /* eslint no-unused-vars: ["error", {vars: "local", args: "none"}] */
 
+var AM_Cc = Cc;
+var AM_Ci = Ci;
+var AM_Cu = Cu;
+
+AM_Cu.importGlobalProperties(["TextEncoder"]);
+
 if (!_TEST_FILE[0].includes("toolkit/mozapps/extensions/test/xpcshell/")) {
   ok(false, ("head_addons.js may not be loaded by tests outside of " +
              "the add-on manager component."));
 }
 
-Cu.importGlobalProperties(["TextEncoder"]);
+const CERTDB_CONTRACTID = "@mozilla.org/security/x509certdb;1";
+const CERTDB_CID = Components.ID("{fb0bbc5c-452e-4783-b32c-80124693d871}");
 
 const PREF_EM_CHECK_UPDATE_SECURITY   = "extensions.checkUpdateSecurity";
 const PREF_EM_STRICT_COMPATIBILITY    = "extensions.strictCompatibility";
 const PREF_EM_MIN_COMPAT_APP_VERSION      = "extensions.minCompatibleAppVersion";
 const PREF_EM_MIN_COMPAT_PLATFORM_VERSION = "extensions.minCompatiblePlatformVersion";
 const PREF_GETADDONS_BYIDS               = "extensions.getAddons.get.url";
 const PREF_COMPAT_OVERRIDES              = "extensions.getAddons.compatOverides.url";
 const PREF_XPI_SIGNATURES_REQUIRED    = "xpinstall.signatures.required";
@@ -31,23 +38,24 @@ const TIMEOUT_MS = 900000;
 // modification times exactly. As long as we are closer than this then it
 // still passes.
 const MAX_TIME_DIFFERENCE = 3000;
 
 // Time to reset file modified time relative to Date.now() so we can test that
 // times are modified (10 hours old).
 const MAKE_FILE_OLD_DIFFERENCE = 10 * 3600 * 1000;
 
+ChromeUtils.import("resource://gre/modules/addons/AddonRepository.jsm");
 ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
+ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 ChromeUtils.import("resource://gre/modules/FileUtils.jsm");
-ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
-ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
-ChromeUtils.import("resource://gre/modules/addons/AddonRepository.jsm");
-ChromeUtils.import("resource://gre/modules/osfile.jsm");
+ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
+const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm", {});
+ChromeUtils.import("resource://gre/modules/AsyncShutdown.jsm");
 
 ChromeUtils.import("resource://testing-common/AddonTestUtils.jsm");
 
 ChromeUtils.defineModuleGetter(this, "Extension",
                                "resource://gre/modules/Extension.jsm");
 ChromeUtils.defineModuleGetter(this, "ExtensionTestUtils",
                                "resource://testing-common/ExtensionXPCShellUtils.jsm");
 ChromeUtils.defineModuleGetter(this, "ExtensionTestCommon",
@@ -63,17 +71,16 @@ ChromeUtils.defineModuleGetter(this, "Mo
 
 XPCOMUtils.defineLazyServiceGetter(this, "aomStartup",
                                    "@mozilla.org/addons/addon-manager-startup;1",
                                    "amIAddonManagerStartup");
 
 const {
   awaitPromise,
   createAppInfo,
-  createHttpServer,
   createInstallRDF,
   createTempWebExtensionFile,
   createUpdateRDF,
   getFileForAddon,
   manuallyUninstall,
   overrideBuiltIns,
   promiseAddonEvent,
   promiseCompleteAllInstalls,
@@ -113,17 +120,17 @@ Object.defineProperty(this, "gAppInfo", 
 Object.defineProperty(this, "gAddonStartup", {
   get() {
     return AddonTestUtils.addonStartup.clone();
   },
 });
 
 Object.defineProperty(this, "gInternalManager", {
   get() {
-    return AddonTestUtils.addonIntegrationService.QueryInterface(Ci.nsITimerCallback);
+    return AddonTestUtils.addonIntegrationService.QueryInterface(AM_Ci.nsITimerCallback);
   },
 });
 
 Object.defineProperty(this, "gProfD", {
   get() {
     return AddonTestUtils.profileDir.clone();
   },
 });
@@ -160,31 +167,31 @@ const promiseAddonByID = AddonManager.ge
 const promiseAddonsByIDs = AddonManager.getAddonsByIDs;
 const promiseAddonsWithOperationsByTypes = AddonManager.getAddonsWithOperationsByTypes;
 
 var gPort = null;
 var gUrlToFileMap = {};
 
 // Map resource://xpcshell-data/ to the data directory
 var resHandler = Services.io.getProtocolHandler("resource")
-                         .QueryInterface(Ci.nsISubstitutingProtocolHandler);
+                         .QueryInterface(AM_Ci.nsISubstitutingProtocolHandler);
 // Allow non-existent files because of bug 1207735
 var dataURI = NetUtil.newURI(do_get_file("data", true));
 resHandler.setSubstitution("xpcshell-data", dataURI);
 
 function isManifestRegistered(file) {
   let manifests = Components.manager.getManifestLocations();
   for (let i = 0; i < manifests.length; i++) {
-    let manifest = manifests.queryElementAt(i, Ci.nsIURI);
+    let manifest = manifests.queryElementAt(i, AM_Ci.nsIURI);
 
     // manifest is the url to the manifest file either in an XPI or a directory.
     // We want the location of the XPI or directory itself.
-    if (manifest instanceof Ci.nsIJARURI) {
-      manifest = manifest.JARFile.QueryInterface(Ci.nsIFileURL).file;
-    } else if (manifest instanceof Ci.nsIFileURL) {
+    if (manifest instanceof AM_Ci.nsIJARURI) {
+      manifest = manifest.JARFile.QueryInterface(AM_Ci.nsIFileURL).file;
+    } else if (manifest instanceof AM_Ci.nsIFileURL) {
       manifest = manifest.file.parent;
     } else {
       continue;
     }
 
     if (manifest.equals(file))
       return true;
   }
@@ -469,21 +476,21 @@ function do_get_addon_hash(aName, aAlgor
   let file = do_get_addon(aName);
   return do_get_file_hash(file);
 }
 
 function do_get_file_hash(aFile, aAlgorithm) {
   if (!aAlgorithm)
     aAlgorithm = "sha1";
 
-  let crypto = Cc["@mozilla.org/security/hash;1"].
-               createInstance(Ci.nsICryptoHash);
+  let crypto = AM_Cc["@mozilla.org/security/hash;1"].
+               createInstance(AM_Ci.nsICryptoHash);
   crypto.initWithString(aAlgorithm);
-  let fis = Cc["@mozilla.org/network/file-input-stream;1"].
-            createInstance(Ci.nsIFileInputStream);
+  let fis = AM_Cc["@mozilla.org/network/file-input-stream;1"].
+            createInstance(AM_Ci.nsIFileInputStream);
   fis.init(aFile, -1, -1, false);
   crypto.updateFromStream(fis, aFile.fileSize);
 
   // return the two-digit hexadecimal code for a byte
   let toHexString = charCode => ("0" + charCode.toString(16)).slice(-2);
 
   let binary = crypto.finish(false);
   let hash = Array.from(binary, c => toHexString(c.charCodeAt(0)));
@@ -596,17 +603,17 @@ function do_check_addon(aActualAddon, aE
           do_check_compatibilityoverride(actualValue[i], expectedValue[i]);
         break;
 
       case "icons":
         do_check_icons(actualValue, expectedValue);
         break;
 
       default:
-        if (actualValue !== expectedValue)
+        if (remove_port(actualValue) !== remove_port(expectedValue))
           do_throw("Failed for " + aProperty + " for add-on " + aExpectedAddon.id +
                    " (" + actualValue + " === " + expectedValue + ")");
     }
   });
 }
 
 /**
  * Check that the actual author is the same as the expected author.
@@ -656,17 +663,17 @@ function do_check_compatibilityoverride(
   Assert.equal(aActual.maxVersion, aExpected.maxVersion);
   Assert.equal(aActual.appID, aExpected.appID);
   Assert.equal(aActual.appMinVersion, aExpected.appMinVersion);
   Assert.equal(aActual.appMaxVersion, aExpected.appMaxVersion);
 }
 
 function do_check_icons(aActual, aExpected) {
   for (var size in aExpected) {
-    Assert.equal(aActual[size], aExpected[size]);
+    Assert.equal(remove_port(aActual[size]), remove_port(aExpected[size]));
   }
 }
 
 function startupManager(aAppChanged) {
   promiseStartupManager(aAppChanged);
 }
 
 /**
@@ -766,17 +773,17 @@ function writeInstallRDFToXPI(aData, aDi
   };
   if (typeof aExtraFile === "object")
     Object.assign(files, aExtraFile);
   else
   if (aExtraFile)
     files[aExtraFile] = "";
 
   if (!aDir.exists())
-    aDir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
+    aDir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
 
   var file = aDir.clone();
   file.append(`${aId}.xpi`);
 
   AddonTestUtils.writeFilesToZip(file.path, files);
 
   return file;
 }
@@ -1186,74 +1193,185 @@ function copyBlocklistToProfile(blocklis
 function timeout() {
   timer = null;
   do_throw("Test ran longer than " + TIMEOUT_MS + "ms");
 
   // Attempt to bail out of the test
   do_test_finished();
 }
 
-var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
-timer.init(timeout, TIMEOUT_MS, Ci.nsITimer.TYPE_ONE_SHOT);
+var timer = AM_Cc["@mozilla.org/timer;1"].createInstance(AM_Ci.nsITimer);
+timer.init(timeout, TIMEOUT_MS, AM_Ci.nsITimer.TYPE_ONE_SHOT);
 
 // Make sure that a given path does not exist
 function pathShouldntExist(file) {
   if (file.exists()) {
     do_throw(`Test cleanup: path ${file.path} exists when it should not`);
   }
 }
 
 registerCleanupFunction(function addon_cleanup() {
   if (timer)
     timer.cancel();
 });
 
+/**
+ * Creates a new HttpServer for testing, and begins listening on the
+ * specified port. Automatically shuts down the server when the test
+ * unit ends.
+ *
+ * @param port
+ *        The port to listen on. If omitted, listen on a random
+ *        port. The latter is the preferred behavior.
+ *
+ * @return HttpServer
+ */
+function createHttpServer(port = -1) {
+  let server = new HttpServer();
+  server.start(port);
+
+  registerCleanupFunction(() => {
+    return new Promise(resolve => {
+      server.stop(resolve);
+    });
+  });
+
+  return server;
+}
+
+/**
+ * Handler function that responds with the interpolated
+ * static file associated to the URL specified by request.path.
+ * This replaces the %PORT% entries in the file with the actual
+ * value of the running server's port (stored in gPort).
+ */
+function interpolateAndServeFile(request, response) {
+  try {
+    let file = gUrlToFileMap[request.path];
+    var data = "";
+    var fstream = Cc["@mozilla.org/network/file-input-stream;1"].
+    createInstance(Ci.nsIFileInputStream);
+    var cstream = Cc["@mozilla.org/intl/converter-input-stream;1"].
+    createInstance(Ci.nsIConverterInputStream);
+    fstream.init(file, -1, 0, 0);
+    cstream.init(fstream, "UTF-8", 0, 0);
+
+    let str = {};
+    let read = 0;
+    do {
+      // read as much as we can and put it in str.value
+      read = cstream.readString(0xffffffff, str);
+      data += str.value;
+    } while (read != 0);
+    data = data.replace(/%PORT%/g, gPort);
+
+    response.write(data);
+  } catch (e) {
+    do_throw(`Exception while serving interpolated file: ${e}\n${e.stack}`);
+  } finally {
+    cstream.close(); // this closes fstream as well
+  }
+}
+
+/**
+ * Sets up a path handler for the given URL and saves the
+ * corresponding file in the global url -> file map.
+ *
+ * @param  url
+ *         the actual URL
+ * @param  file
+ *         nsIFile representing a static file
+ */
+function mapUrlToFile(url, file, server) {
+  server.registerPathHandler(url, interpolateAndServeFile);
+  gUrlToFileMap[url] = file;
+}
+
+function mapFile(path, server) {
+  mapUrlToFile(path, do_get_file(path), server);
+}
+
+/**
+ * Take out the port number in an URL
+ *
+ * @param url
+ *        String that represents an URL with a port number in it
+ */
+function remove_port(url) {
+  if (typeof url === "string")
+    return url.replace(/:\d+/, "");
+  return url;
+}
 // Wrap a function (typically a callback) to catch and report exceptions
 function do_exception_wrap(func) {
   return function() {
     try {
       func.apply(null, arguments);
     } catch (e) {
       do_report_unexpected_exception(e);
     }
   };
 }
 
 /**
  * Change the schema version of the JSON extensions database
  */
-async function changeXPIDBVersion(aNewVersion) {
-  let json = await loadJSON(gExtensionsJSON.path);
-  json.schemaVersion = aNewVersion;
-  await saveJSON(json, gExtensionsJSON.path);
+function changeXPIDBVersion(aNewVersion, aMutator = undefined) {
+  let jData = loadJSON(gExtensionsJSON);
+  jData.schemaVersion = aNewVersion;
+  if (aMutator)
+    aMutator(jData);
+  saveJSON(jData, gExtensionsJSON);
 }
 
 /**
  * Load a file into a string
  */
-async function loadFile(aFile) {
-  let buffer = await OS.File.read(aFile);
-  return new TextDecoder().decode(buffer);
+function loadFile(aFile) {
+  let data = "";
+  let fstream = Cc["@mozilla.org/network/file-input-stream;1"].
+          createInstance(Ci.nsIFileInputStream);
+  let cstream = Cc["@mozilla.org/intl/converter-input-stream;1"].
+          createInstance(Ci.nsIConverterInputStream);
+  fstream.init(aFile, -1, 0, 0);
+  cstream.init(fstream, "UTF-8", 0, 0);
+  let str = {};
+  let read = 0;
+  do {
+    read = cstream.readString(0xffffffff, str); // read as much as we can and put it in str.value
+    data += str.value;
+  } while (read != 0);
+  cstream.close();
+  return data;
 }
 
 /**
  * Raw load of a JSON file
  */
-async function loadJSON(aFile) {
-  let data = await loadFile(aFile);
-  info("Loaded JSON file " + aFile);
-  return JSON.parse(data);
+function loadJSON(aFile) {
+  let data = loadFile(aFile);
+  info("Loaded JSON file " + aFile.path);
+  return (JSON.parse(data));
 }
 
 /**
  * Raw save of a JSON blob to file
  */
-async function saveJSON(aData, aFile) {
-  info("Starting to save JSON file " + aFile);
-  await OS.File.writeAtomic(aFile, new TextEncoder().encode(JSON.stringify(aData, null, 2)));
+function saveJSON(aData, aFile) {
+  info("Starting to save JSON file " + aFile.path);
+  let stream = FileUtils.openSafeFileOutputStream(aFile);
+  let converter = AM_Cc["@mozilla.org/intl/converter-output-stream;1"].
+    createInstance(AM_Ci.nsIConverterOutputStream);
+  converter.init(stream, "UTF-8");
+  // XXX pretty print the JSON while debugging
+  converter.writeString(JSON.stringify(aData, null, 2));
+  converter.flush();
+  // nsConverterOutputStream doesn't finish() safe output streams on close()
+  FileUtils.closeSafeFileOutputStream(stream);
+  converter.close();
   info("Done saving JSON file " + aFile.path);
 }
 
 /**
  * Create a callback function that calls do_execute_soon on an actual callback and arguments
  */
 function callback_soon(aFunction) {
   return function(...args) {
@@ -1431,17 +1549,17 @@ async function checkInstalledSystemAddon
 
       // Verify the add-ons file is in the right place
       let file = expectedDir.clone();
       file.append(id + ".xpi");
       Assert.ok(file.exists());
       Assert.ok(file.isFile());
 
       let uri = addon.getResourceURI(null);
-      Assert.ok(uri instanceof Ci.nsIFileURL);
+      Assert.ok(uri instanceof AM_Ci.nsIFileURL);
       Assert.equal(uri.file.path, file.path);
 
       if (isUpgrade) {
         Assert.equal(addon.signedState, AddonManager.SIGNEDSTATE_SYSTEM);
       }
 
       // Verify the add-on actually started
       BootstrapMonitor.checkAddonStarted(id, version);
--- a/toolkit/mozapps/extensions/test/xpcshell/test_AddonRepository.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_AddonRepository.js
@@ -1,23 +1,23 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // Tests AddonRepository.jsm
 
 ChromeUtils.import("resource://gre/modules/addons/AddonRepository.jsm");
 
-var gServer = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+var gServer = AddonTestUtils.createHttpServer();
 
 const PREF_GETADDONS_BROWSEADDONS        = "extensions.getAddons.browseAddons";
 const PREF_GETADDONS_BROWSESEARCHRESULTS = "extensions.getAddons.search.browseURL";
 
 const PORT          = gServer.identity.primaryPort;
-const BASE_URL      = "http://example.com";
+const BASE_URL      = "http://localhost:" + PORT;
 const DEFAULT_URL   = "about:blank";
 
 const ADDONS = [
   {
     id: "test_AddonRepository_1@tests.mozilla.org",
     version: "1.1",
     bootstrap: true,
 
@@ -166,22 +166,24 @@ add_task(async function setup() {
 
   let xpis = ADDONS.map(addon => createTempXPIFile(addon));
 
   // Register other add-on XPI files
   gServer.registerFile(INSTALL_URL2, xpis[1]);
   gServer.registerFile(INSTALL_URL3, xpis[2]);
 
   // Register files used to test search failure
-  gServer.registerFile(GET_TEST.failedURL,
-                       do_get_file("data/test_AddonRepository_fail.json"));
+  mapUrlToFile(GET_TEST.failedURL,
+               do_get_file("data/test_AddonRepository_fail.json"),
+               gServer);
 
   // Register files used to test search success
-  gServer.registerFile(GET_TEST.successfulURL,
-                       do_get_file("data/test_AddonRepository_getAddonsByIDs.json"));
+  mapUrlToFile(GET_TEST.successfulURL,
+               do_get_file("data/test_AddonRepository_getAddonsByIDs.json"),
+               gServer);
 
   await promiseStartupManager();
 
   // Install an add-on so can check that it isn't returned in the results
   await promiseInstallFile(xpis[0]);
   await promiseRestartManager();
 
   // Create an active AddonInstall so can check that it isn't returned in the results
--- a/toolkit/mozapps/extensions/test/xpcshell/test_ProductAddonChecker.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_ProductAddonChecker.js
@@ -1,15 +1,15 @@
 "use strict";
 
 ChromeUtils.import("resource://gre/modules/addons/ProductAddonChecker.jsm");
 ChromeUtils.import("resource://testing-common/httpd.js");
 ChromeUtils.import("resource://gre/modules/osfile.jsm");
 
-const LocalFile = new Components.Constructor("@mozilla.org/file/local;1", Ci.nsIFile, "initWithPath");
+const LocalFile = new Components.Constructor("@mozilla.org/file/local;1", AM_Ci.nsIFile, "initWithPath");
 
 var testserver = new HttpServer();
 testserver.registerDirectory("/data/", do_get_file("data/productaddons"));
 testserver.start();
 var root = testserver.identity.primaryScheme + "://" +
            testserver.identity.primaryHost + ":" +
            testserver.identity.primaryPort + "/data/";
 
@@ -33,23 +33,23 @@ function compareBinaryData(arr1, arr2) {
 
 /**
  * Reads a file's data and returns it
  *
  * @param file The file to read the data from
  * @return array of bytes for the data in the file.
 */
 function getBinaryFileData(file) {
-  let fileStream = Cc["@mozilla.org/network/file-input-stream;1"].
-                   createInstance(Ci.nsIFileInputStream);
+  let fileStream = AM_Cc["@mozilla.org/network/file-input-stream;1"].
+                   createInstance(AM_Ci.nsIFileInputStream);
   // Open as RD_ONLY with default permissions.
   fileStream.init(file, FileUtils.MODE_RDONLY, FileUtils.PERMS_FILE, 0);
 
-  let stream = Cc["@mozilla.org/binaryinputstream;1"].
-               createInstance(Ci.nsIBinaryInputStream);
+  let stream = AM_Cc["@mozilla.org/binaryinputstream;1"].
+               createInstance(AM_Ci.nsIBinaryInputStream);
   stream.setInputStream(fileStream);
   let bytes = stream.readByteArray(stream.available());
   fileStream.close();
   return bytes;
 }
 
 /**
  * Compares binary data of 2 files and returns true if they are the same
--- a/toolkit/mozapps/extensions/test/xpcshell/test_asyncBlocklistLoad.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_asyncBlocklistLoad.js
@@ -1,14 +1,14 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 add_task(async function() {
-  let blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
+  let blocklist = AM_Cc["@mozilla.org/extensions/blocklist;1"].
                   getService().wrappedJSObject;
   let scope = ChromeUtils.import("resource://gre/modules/osfile.jsm", {});
 
   // sync -> async. Check that async code doesn't try to read the file
   // once it's already been read synchronously.
   let read = scope.OS.File.read;
   let triedToRead = false;
   scope.OS.File.read = () => triedToRead = true;
--- a/toolkit/mozapps/extensions/test/xpcshell/test_backgroundupdate.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_backgroundupdate.js
@@ -2,34 +2,39 @@
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // This verifies that background updates & notifications work as expected
 
 // The test extension uses an insecure update url.
 Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false);
 
-var testserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+ChromeUtils.import("resource://testing-common/httpd.js");
+var testserver = new HttpServer();
+testserver.start(-1);
+gPort = testserver.identity.primaryPort;
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
 
+// register static files with server and interpolate port numbers in them
+mapFile("/data/test_backgroundupdate.json", testserver);
+
 function run_test() {
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
 
   testserver.registerDirectory("/addons/", do_get_file("addons"));
-  testserver.registerDirectory("/data/", do_get_file("data"));
 
   startupManager();
 
   do_test_pending();
   run_test_1();
 }
 
 function end_test() {
-  do_test_finished();
+  testserver.stop(do_test_finished);
 }
 
 // Verify that with no add-ons installed the background update notifications get
 // called
 function run_test_1() {
   AddonManager.getAddonsByTypes(["extension", "theme", "locale"], function(aAddons) {
     Assert.equal(aAddons.length, 0);
 
@@ -45,30 +50,30 @@ function run_test_1() {
 }
 
 // Verify that with two add-ons installed both of which claim to have updates
 // available we get the notification after both updates attempted to start
 function run_test_2() {
   writeInstallRDFForExtension({
     id: "addon1@tests.mozilla.org",
     version: "1.0",
-    updateURL: "http://example.com/data/test_backgroundupdate.json",
+    updateURL: "http://localhost:" + gPort + "/data/test_backgroundupdate.json",
     bootstrap: true,
     targetApplications: [{
       id: "xpcshell@tests.mozilla.org",
       minVersion: "1",
       maxVersion: "1"
     }],
     name: "Test Addon 1",
   }, profileDir);
 
   writeInstallRDFForExtension({
     id: "addon2@tests.mozilla.org",
     version: "1.0",
-    updateURL: "http://example.com/data/test_backgroundupdate.json",
+    updateURL: "http://localhost:" + gPort + "/data/test_backgroundupdate.json",
     bootstrap: true,
     targetApplications: [{
       id: "xpcshell@tests.mozilla.org",
       minVersion: "1",
       maxVersion: "1"
     }],
     name: "Test Addon 2",
   }, profileDir);
@@ -85,17 +90,17 @@ function run_test_2() {
     name: "Test Addon 3",
   }, profileDir);
 
   // Disable rcwn to make cache behavior deterministic.
   Services.prefs.setBoolPref("network.http.rcwn.enabled", false);
 
   // Background update uses a different pref, if set
   Services.prefs.setCharPref("extensions.update.background.url",
-                             "http://example.com/data/test_backgroundupdate.json");
+                             "http://localhost:" + gPort + "/data/test_backgroundupdate.json");
 
   restartManager();
 
   let installCount = 0;
   let completeCount = 0;
   let sawCompleteNotification = false;
 
   Services.obs.addObserver(function observer() {
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bad_json.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bad_json.js
@@ -15,41 +15,41 @@ var addon1 = {
     minVersion: "1",
     maxVersion: "1"
   }]
 };
 
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
 
-async function run_test() {
+function run_test() {
   do_test_pending("Bad JSON");
 
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
 
   // This addon will be auto-installed at startup
   writeInstallRDFForExtension(addon1, profileDir);
 
   startupManager();
 
   shutdownManager();
 
   // First startup/shutdown finished
   // Replace the JSON store with something bogus
-  await saveJSON({not: "what we expect to find"}, gExtensionsJSON.path);
+  saveJSON({not: "what we expect to find"}, gExtensionsJSON);
 
   startupManager(false);
   // Retrieve an addon to force the database to rebuild
   AddonManager.getAddonsByIDs([addon1.id], callback_soon(after_db_rebuild));
 }
 
-async function after_db_rebuild([a1]) {
+function after_db_rebuild([a1]) {
   Assert.equal(a1.id, addon1.id);
 
   shutdownManager();
 
   // Make sure our JSON database has schemaVersion and our installed extension
-  let data = await loadJSON(gExtensionsJSON.path);
+  let data = loadJSON(gExtensionsJSON);
   Assert.ok("schemaVersion" in data);
   Assert.equal(data.addons[0].id, addon1.id);
 
   do_test_finished("Bad JSON");
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_badschema.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_badschema.js
@@ -1,19 +1,20 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // Checks that we rebuild something sensible from a database with a bad schema
 
-var testserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+var testserver = AddonTestUtils.createHttpServer();
+gPort = testserver.identity.primaryPort;
 
 // register files with server
 testserver.registerDirectory("/addons/", do_get_file("addons"));
-testserver.registerDirectory("/data/", do_get_file("data"));
+mapFile("/data/test_corrupt.json", testserver);
 
 // The test extension uses an insecure update url.
 Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false);
 Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false);
 
 const ADDONS = {
   "addon1@tests.mozilla.org": {
     "install.rdf": {
@@ -63,17 +64,17 @@ const ADDONS = {
   },
 
   "addon3@tests.mozilla.org": {
     "install.rdf": {
       id: "addon3@tests.mozilla.org",
       version: "1.0",
       name: "Test 3",
       bootstrap: true,
-      updateURL: "http://example.com/data/test_corrupt.json",
+      updateURL: "http://localhost:" + gPort + "/data/test_corrupt.json",
       targetApplications: [{
         id: "xpcshell@tests.mozilla.org",
         minVersion: "1",
         maxVersion: "1"
       }]
     },
     findUpdates: true,
     desiredValues: {
@@ -87,17 +88,17 @@ const ADDONS = {
   },
 
   "addon4@tests.mozilla.org": {
     "install.rdf": {
       id: "addon4@tests.mozilla.org",
       version: "1.0",
       name: "Test 4",
       bootstrap: true,
-      updateURL: "http://example.com/data/test_corrupt.json",
+      updateURL: "http://localhost:" + gPort + "/data/test_corrupt.json",
       targetApplications: [{
         id: "xpcshell@tests.mozilla.org",
         minVersion: "1",
         maxVersion: "1"
       }]
     },
     initialState: {
       userDisabled: true,
@@ -277,17 +278,17 @@ add_task(async function test_after_resta
   }
 
   await promiseShutdownManager();
 });
 
 add_task(async function test_after_schema_version_change() {
   // After restarting the database won't be open so we can alter
   // the schema
-  await changeXPIDBVersion(100);
+  changeXPIDBVersion(100);
 
   await promiseStartupManager(false);
 
   info("Test add-on state after schema version change");
   let addons = await getAddons(IDS);
   for (let [id, addon] of Object.entries(ADDONS)) {
     checkAddon(id, addons.get(id),
                Object.assign({}, addon.desiredValues, addon.afterCorruption));
--- a/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_metadata_filters.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_metadata_filters.js
@@ -2,21 +2,24 @@
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // Tests blocking of extensions by ID, name, creator, homepageURL, updateURL
 // and RegExps for each. See bug 897735.
 
 const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul";
 
+ChromeUtils.import("resource://testing-common/httpd.js");
 ChromeUtils.import("resource://testing-common/MockRegistrar.jsm");
-var testserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+var testserver = new HttpServer();
+testserver.start(-1);
 gPort = testserver.identity.primaryPort;
 
-testserver.registerDirectory("/data/", do_get_file("data"));
+// register static files with server and interpolate port numbers in them
+mapFile("/data/test_blocklist_metadata_filters_1.xml", testserver);
 
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
 
 // Don't need the full interface, attempts to call other methods will just
 // throw which is just fine
 var WindowWatcher = {
   openWindow(parent, url, name, features, args) {
@@ -57,17 +60,17 @@ function load_blocklist(aFile, aCallback
                              gPort + "/data/" + aFile);
   var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
                   getService(Ci.nsITimerCallback);
   blocklist.notify(null);
 }
 
 
 function end_test() {
-  do_test_finished();
+  testserver.stop(do_test_finished);
 }
 
 function run_test() {
   do_test_pending();
 
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1");
 
   // Should get blocked by name
--- a/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_prefs.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_prefs.js
@@ -2,21 +2,24 @@
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // Tests resetting of preferences in blocklist entry when an add-on is blocked.
 // See bug 802434.
 
 const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul";
 
+ChromeUtils.import("resource://testing-common/httpd.js");
 ChromeUtils.import("resource://testing-common/MockRegistrar.jsm");
-var testserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+var testserver = new HttpServer();
+testserver.start(-1);
 gPort = testserver.identity.primaryPort;
 
-testserver.registerDirectory("/data/", do_get_file("data"));
+// register static files with server and interpolate port numbers in them
+mapFile("/data/test_blocklist_prefs_1.xml", testserver);
 
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
 
 // A window watcher to handle the blocklist UI.
 // Don't need the full interface, attempts to call other methods will just
 // throw which is just fine
 var WindowWatcher = {
@@ -57,17 +60,17 @@ function load_blocklist(aFile, aCallback
   Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" +
                              gPort + "/data/" + aFile);
   var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
                   getService(Ci.nsITimerCallback);
   blocklist.notify(null);
 }
 
 function end_test() {
-  do_test_finished();
+  testserver.stop(do_test_finished);
 }
 
 function run_test() {
   do_test_pending();
 
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1");
 
   // Add 2 extensions
--- a/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_regexp.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_regexp.js
@@ -3,21 +3,24 @@
  */
 
 // Checks that blocklist entries using RegExp work as expected. This only covers
 // behavior specific to RegExp entries - general behavior is already tested
 // in test_blocklistchange.js.
 
 const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul";
 
+ChromeUtils.import("resource://testing-common/httpd.js");
 ChromeUtils.import("resource://testing-common/MockRegistrar.jsm");
-var testserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+var testserver = new HttpServer();
+testserver.start(-1);
 gPort = testserver.identity.primaryPort;
 
-testserver.registerDirectory("/data/", do_get_file("data"));
+// register static files with server and interpolate port numbers in them
+mapFile("/data/test_blocklist_regexp_1.xml", testserver);
 
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
 
 // Don't need the full interface, attempts to call other methods will just
 // throw which is just fine
 var WindowWatcher = {
   openWindow(parent, url, name, features, args) {
@@ -61,17 +64,17 @@ function load_blocklist(aFile, aCallback
                   getService(Ci.nsITimerCallback);
   ok(Services.prefs.getBoolPref("services.blocklist.update_enabled"),
                                 "Kinto update should be enabled");
   blocklist.notify(null);
 }
 
 
 function end_test() {
-  do_test_finished();
+  testserver.stop(do_test_finished);
 }
 
 
 function run_test() {
   do_test_pending();
 
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1");
 
--- a/toolkit/mozapps/extensions/test/xpcshell/test_blocklistchange.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_blocklistchange.js
@@ -27,16 +27,17 @@ const URI_EXTENSION_BLOCKLIST_DIALOG = "
 
 ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
 ChromeUtils.import("resource://testing-common/MockRegistrar.jsm");
 
 // Allow insecure updates
 Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false);
 
 var testserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+gPort = testserver.identity.primaryPort;
 
 testserver.registerDirectory("/data/", do_get_file("data"));
 
 const ADDONS = {
   "blocklist_hard1_1": {
     id: "hardblock@tests.mozilla.org",
     version: "1.0",
     name: "Hardblocked add-on",
@@ -624,17 +625,17 @@ function Pbackground_update() {
 }
 
 // Manually updates the test add-ons to the given version
 function Pmanual_update(aVersion) {
   let Pinstalls = [];
   for (let name of ["soft1", "soft2", "soft3", "soft4", "hard1", "regexp1"]) {
     Pinstalls.push(
       AddonManager.getInstallForURL(
-        `http://example.com/addons/blocklist_${name}_${aVersion}.xpi`,
+        `http://localhost:${gPort}/addons/blocklist_${name}_${aVersion}.xpi`,
         null, "application/x-xpinstall"));
   }
 
   return Promise.all(Pinstalls).then(installs => {
     let completePromises = [];
     for (let install of installs) {
       completePromises.push(new Promise(resolve => {
         install.addListener({
@@ -797,17 +798,17 @@ add_task(async function run_app_update_s
   check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
 });
 
 add_task(async function update_schema_2() {
   await promiseShutdownManager();
 
-  await changeXPIDBVersion(100);
+  changeXPIDBVersion(100);
   gAppInfo.version = "2";
   startupManager(true);
 
   let [s1, s2, s3, s4, h, r] = await promiseAddonsByIDs(ADDON_IDS);
 
   check_addon(s1, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   check_addon(s2, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   check_addon(s3, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
@@ -821,50 +822,50 @@ add_task(async function update_schema_2(
   s3.userDisabled = false;
   check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
 });
 
 add_task(async function update_schema_3() {
   await promiseRestartManager();
 
   await promiseShutdownManager();
-  await changeXPIDBVersion(100);
+  changeXPIDBVersion(100);
   gAppInfo.version = "2.5";
   startupManager(true);
 
   let [s1, s2, s3, s4, h, r] = await promiseAddonsByIDs(ADDON_IDS);
 
   check_addon(s1, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
   check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
 });
 
 add_task(async function update_schema_4() {
   await promiseShutdownManager();
 
-  await changeXPIDBVersion(100);
+  changeXPIDBVersion(100);
   startupManager(false);
 
   let [s1, s2, s3, s4, h, r] = await promiseAddonsByIDs(ADDON_IDS);
 
   check_addon(s1, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
   check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
 });
 
 add_task(async function update_schema_5() {
   await promiseShutdownManager();
 
-  await changeXPIDBVersion(100);
+  changeXPIDBVersion(100);
   gAppInfo.version = "1";
   startupManager(true);
 
   let [s1, s2, s3, s4, h, r] = await promiseAddonsByIDs(ADDON_IDS);
 
   check_addon(s1, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js
@@ -27,106 +27,22 @@ createAppInfo("xpcshell@tests.mozilla.or
 
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
 const userExtDir = gProfD.clone();
 userExtDir.append("extensions2");
 userExtDir.append(gAppInfo.ID);
 registerDirectory("XREUSysExt", userExtDir.parent);
 
-
-const BOOTSTRAP = `
-  ChromeUtils.import("resource://xpcshell-data/BootstrapMonitor.jsm").monitor(this);
-`;
-
-const ADDONS = {
-  test_bootstrap1_1: {
-    "install.rdf": {
-      id: "bootstrap1@tests.mozilla.org",
-      version: "1.0",
-      bootstrap: "true",
-      multiprocessCompatible: "true",
-
-      name: "Test Bootstrap 1",
-      description: "Test Description",
-
-      iconURL: "chrome://foo/skin/icon.png",
-      aboutURL: "chrome://foo/content/about.xul",
-      optionsURL: "chrome://foo/content/options.xul",
-
-      targetApplications: [{
-        id: "xpcshell@tests.mozilla.org",
-        minVersion: "1",
-        maxVersion: "1"}],
-    },
-    "bootstrap.js": BOOTSTRAP,
-  },
-  test_bootstrap1_2: {
-    "install.rdf": {
-      id: "bootstrap1@tests.mozilla.org",
-      version: "2.0",
-      bootstrap: "true",
-
-      name: "Test Bootstrap 1",
-      description: "Test Description",
+ChromeUtils.import("resource://testing-common/httpd.js");
+var testserver = new HttpServer();
+testserver.start(undefined);
+gPort = testserver.identity.primaryPort;
 
-      targetApplications: [{
-        id: "xpcshell@tests.mozilla.org",
-        minVersion: "1",
-        maxVersion: "1"}],
-    },
-    "bootstrap.js": BOOTSTRAP,
-  },
-  test_bootstrap1_3: {
-    "install.rdf": {
-      id: "bootstrap1@tests.mozilla.org",
-      version: "3.0",
-      bootstrap: "true",
-
-      name: "Test Bootstrap 1",
-      description: "Test Description",
-
-      targetApplications: [{
-        id: "undefined",
-        minVersion: "1",
-        maxVersion: "1"}],
-    },
-    "bootstrap.js": BOOTSTRAP,
-  },
-  test_bootstrap2_1: {
-    "install.rdf": {
-      id: "bootstrap2@tests.mozilla.org",
-      version: "1.0",
-      bootstrap: "true",
-      multiprocessCompatible: "true",
-
-      name: "Test Bootstrap 2",
-      description: "Test Description",
-
-      iconURL: "chrome://foo/skin/icon.png",
-      aboutURL: "chrome://foo/content/about.xul",
-      optionsURL: "chrome://foo/content/options.xul",
-
-      targetApplications: [{
-        id: "xpcshell@tests.mozilla.org",
-        minVersion: "1",
-        maxVersion: "1"}],
-    },
-    "bootstrap.js": BOOTSTRAP,
-  },
-};
-
-var testserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
-
-const XPIS = {};
-for (let [name, addon] of Object.entries(ADDONS)) {
-  XPIS[name] = AddonTestUtils.createTempXPIFile(addon);
-  testserver.registerFile(`/addons/${name}.xpi`, XPIS[name]);
-}
-
+testserver.registerDirectory("/addons/", do_get_file("addons"));
 
 function getStartupReason() {
   let info = BootstrapMonitor.started.get(ID1);
   return info ? info.reason : undefined;
 }
 
 function getShutdownReason() {
   let info = BootstrapMonitor.stopped.get(ID1);
@@ -158,1096 +74,1337 @@ function getInstallOldVersion() {
   return info ? info.data.oldVersion : undefined;
 }
 
 function getUninstallNewVersion() {
   let info = BootstrapMonitor.uninstalled.get(ID1);
   return info ? info.data.newVersion : undefined;
 }
 
-async function checkBootstrappedPref() {
-  let XPIScope = ChromeUtils.import("resource://gre/modules/addons/XPIProvider.jsm", {});
+function do_check_bootstrappedPref(aCallback) {
+  let XPIScope = AM_Cu.import("resource://gre/modules/addons/XPIProvider.jsm", {});
 
-  let data = new Map();
+  let data = {};
   for (let entry of XPIScope.XPIStates.bootstrappedAddons()) {
-    data.set(entry.id, entry);
+    data[entry.id] = entry;
   }
 
-  let addons = await AddonManager.getAddonsByTypes(["extension"]);
-  for (let addon of addons) {
-    if (!addon.id.endsWith("@tests.mozilla.org"))
-      continue;
-    if (!addon.isActive)
-      continue;
-    if (addon.operationsRequiringRestart != AddonManager.OP_NEEDS_RESTART_NONE)
-      continue;
+  AddonManager.getAddonsByTypes(["extension"], function(aAddons) {
+    for (let addon of aAddons) {
+      if (!addon.id.endsWith("@tests.mozilla.org"))
+        continue;
+      if (!addon.isActive)
+        continue;
+      if (addon.operationsRequiringRestart != AddonManager.OP_NEEDS_RESTART_NONE)
+        continue;
+
+      Assert.ok(addon.id in data);
+      let addonData = data[addon.id];
+      delete data[addon.id];
+
+      Assert.equal(addonData.version, addon.version);
+      Assert.equal(addonData.type, addon.type);
+      let file = addon.getResourceURI().QueryInterface(Ci.nsIFileURL).file;
+      Assert.equal(addonData.path, file.path);
+    }
+    Assert.equal(Object.keys(data).length, 0);
+
+    executeSoon(aCallback);
+  });
+}
+
+
+function run_test() {
+  do_test_pending();
+
+  startupManager();
+
+  Assert.ok(!gExtensionsJSON.exists());
+
+  Assert.ok(!gAddonStartup.exists());
+
+  run_test_1();
+}
+
+// Tests that installing doesn't require a restart
+function run_test_1() {
+  prepare_test({ }, [
+    "onNewInstall"
+  ]);
+
+  AddonManager.getInstallForFile(do_get_addon("test_bootstrap1_1"), function(install) {
+    ensure_test_completed();
+
+    Assert.notEqual(install, null);
+    Assert.equal(install.type, "extension");
+    Assert.equal(install.version, "1.0");
+    Assert.equal(install.name, "Test Bootstrap 1");
+    Assert.equal(install.state, AddonManager.STATE_DOWNLOADED);
+    Assert.notEqual(install.addon.syncGUID, null);
+    Assert.ok(install.addon.hasResource("install.rdf"));
+    Assert.ok(install.addon.hasResource("bootstrap.js"));
+    Assert.ok(!install.addon.hasResource("foo.bar"));
+    Assert.equal(install.addon.operationsRequiringRestart &
+                 AddonManager.OP_NEEDS_RESTART_INSTALL, 0);
+    do_check_not_in_crash_annotation(ID1, "1.0");
+
+    let addon = install.addon;
+
+    BootstrapMonitor.promiseAddonStartup(ID1).then(function() {
+      do_check_bootstrappedPref(function() {
+        check_test_1(addon.syncGUID);
+      });
+    });
+
+    prepare_test({
+      [ID1]: [
+        ["onInstalling", false],
+        "onInstalled"
+      ]
+    }, [
+      "onInstallStarted",
+      "onInstallEnded",
+    ], function() {
+      Assert.ok(addon.hasResource("install.rdf"));
+
+      // startup should not have been called yet.
+      BootstrapMonitor.checkAddonNotStarted(ID1);
+    });
+    install.install();
+  });
+}
+
+function check_test_1(installSyncGUID) {
+  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);
+
+    AddonManager.getAddonByID(ID1, function(b1) {
+      Assert.notEqual(b1, null);
+      Assert.equal(b1.version, "1.0");
+      Assert.notEqual(b1.syncGUID, null);
+      Assert.equal(b1.syncGUID, installSyncGUID);
+      Assert.ok(!b1.appDisabled);
+      Assert.ok(!b1.userDisabled);
+      Assert.ok(b1.isActive);
+      Assert.ok(!b1.isSystem);
+      BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+      BootstrapMonitor.checkAddonStarted(ID1, "1.0");
+      Assert.equal(getStartupReason(), ADDON_INSTALL);
+      Assert.equal(getStartupOldVersion(), undefined);
+      Assert.ok(b1.hasResource("install.rdf"));
+      Assert.ok(b1.hasResource("bootstrap.js"));
+      Assert.ok(!b1.hasResource("foo.bar"));
+      do_check_in_crash_annotation(ID1, "1.0");
+
+      let dir = do_get_addon_root_uri(profileDir, ID1);
+      Assert.equal(b1.getResourceURI("bootstrap.js").spec, dir + "bootstrap.js");
+
+      AddonManager.getAddonsWithOperationsByTypes(null, function(list) {
+        Assert.equal(list.length, 0);
+
+        executeSoon(run_test_2);
+      });
+    });
+  });
+}
+
+// Tests that disabling doesn't require a restart
+function run_test_2() {
+  AddonManager.getAddonByID(ID1, function(b1) {
+    prepare_test({
+      [ID1]: [
+        ["onDisabling", false],
+        "onDisabled"
+      ]
+    });
+
+    Assert.equal(b1.operationsRequiringRestart &
+                 AddonManager.OP_NEEDS_RESTART_DISABLE, 0);
+    b1.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);
+    BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+    BootstrapMonitor.checkAddonNotStarted(ID1);
+    Assert.equal(getShutdownReason(), ADDON_DISABLE);
+    Assert.equal(getShutdownNewVersion(), undefined);
+    do_check_not_in_crash_annotation(ID1, "1.0");
+
+    AddonManager.getAddonByID(ID1, function(newb1) {
+      Assert.notEqual(newb1, null);
+      Assert.equal(newb1.version, "1.0");
+      Assert.ok(!newb1.appDisabled);
+      Assert.ok(newb1.userDisabled);
+      Assert.ok(!newb1.isActive);
+
+      do_check_bootstrappedPref(run_test_3);
+    });
+  });
+}
+
+// Test that restarting doesn't accidentally re-enable
+function run_test_3() {
+  shutdownManager();
+  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+  BootstrapMonitor.checkAddonNotStarted(ID1);
+  Assert.equal(getShutdownReason(), ADDON_DISABLE);
+  Assert.equal(getShutdownNewVersion(), undefined);
+  startupManager(false);
+  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+  BootstrapMonitor.checkAddonNotStarted(ID1);
+  Assert.equal(getShutdownReason(), ADDON_DISABLE);
+  Assert.equal(getShutdownNewVersion(), undefined);
+  do_check_not_in_crash_annotation(ID1, "1.0");
+
+  Assert.ok(gAddonStartup.exists());
+
+  AddonManager.getAddonByID(ID1, function(b1) {
+    Assert.notEqual(b1, null);
+    Assert.equal(b1.version, "1.0");
+    Assert.ok(!b1.appDisabled);
+    Assert.ok(b1.userDisabled);
+    Assert.ok(!b1.isActive);
+
+    do_check_bootstrappedPref(run_test_4);
+  });
+}
 
-    ok(data.has(addon.id));
-    let addonData = data.get(addon.id);
-    data.delete(addon.id);
+// Tests that enabling doesn't require a restart
+function run_test_4() {
+  AddonManager.getAddonByID(ID1, function(b1) {
+    prepare_test({
+      [ID1]: [
+        ["onEnabling", false],
+        "onEnabled"
+      ]
+    });
+
+    Assert.equal(b1.operationsRequiringRestart &
+                 AddonManager.OP_NEEDS_RESTART_ENABLE, 0);
+    b1.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(!b1.isSystem);
+    BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+    BootstrapMonitor.checkAddonStarted(ID1, "1.0");
+    Assert.equal(getStartupReason(), ADDON_ENABLE);
+    Assert.equal(getStartupOldVersion(), undefined);
+    do_check_in_crash_annotation(ID1, "1.0");
+
+    AddonManager.getAddonByID(ID1, function(newb1) {
+      Assert.notEqual(newb1, null);
+      Assert.equal(newb1.version, "1.0");
+      Assert.ok(!newb1.appDisabled);
+      Assert.ok(!newb1.userDisabled);
+      Assert.ok(newb1.isActive);
+
+      do_check_bootstrappedPref(run_test_5);
+    });
+  });
+}
+
+// Tests that a restart shuts down and restarts the add-on
+function run_test_5() {
+  shutdownManager();
+  // By the time we've shut down, the database must have been written
+  Assert.ok(gExtensionsJSON.exists());
+
+  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+  BootstrapMonitor.checkAddonNotStarted(ID1);
+  Assert.equal(getShutdownReason(), APP_SHUTDOWN);
+  Assert.equal(getShutdownNewVersion(), undefined);
+  do_check_not_in_crash_annotation(ID1, "1.0");
+  startupManager(false);
+  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+  BootstrapMonitor.checkAddonStarted(ID1, "1.0");
+  Assert.equal(getStartupReason(), APP_STARTUP);
+  Assert.equal(getStartupOldVersion(), undefined);
+  do_check_in_crash_annotation(ID1, "1.0");
+
+  AddonManager.getAddonByID(ID1, 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(!b1.isSystem);
+    Assert.ok(!isExtensionInAddonsList(profileDir, b1.id));
+
+    do_check_bootstrappedPref(run_test_6);
+  });
+}
+
+// Tests that installing an upgrade doesn't require a restart
+function run_test_6() {
+  prepare_test({ }, [
+    "onNewInstall"
+  ]);
+
+  AddonManager.getInstallForFile(do_get_addon("test_bootstrap1_2"), function(install) {
+    ensure_test_completed();
+
+    Assert.notEqual(install, null);
+    Assert.equal(install.type, "extension");
+    Assert.equal(install.version, "2.0");
+    Assert.equal(install.name, "Test Bootstrap 1");
+    Assert.equal(install.state, AddonManager.STATE_DOWNLOADED);
+
+    BootstrapMonitor.promiseAddonStartup(ID1).then(check_test_6);
+    prepare_test({
+      [ID1]: [
+        ["onInstalling", false],
+        "onInstalled"
+      ]
+    }, [
+      "onInstallStarted",
+      "onInstallEnded",
+    ], function() {
+    });
+    install.install();
+  });
+}
 
-    equal(addonData.version, addon.version);
-    equal(addonData.type, addon.type);
-    let file = addon.getResourceURI().QueryInterface(Ci.nsIFileURL).file;
-    equal(addonData.path, file.path);
-  }
-  equal(data.size, 0);
+function check_test_6() {
+  AddonManager.getAddonByID(ID1, function(b1) {
+    Assert.notEqual(b1, null);
+    Assert.equal(b1.version, "2.0");
+    Assert.ok(!b1.appDisabled);
+    Assert.ok(!b1.userDisabled);
+    Assert.ok(b1.isActive);
+    Assert.ok(!b1.isSystem);
+    BootstrapMonitor.checkAddonInstalled(ID1, "2.0");
+    BootstrapMonitor.checkAddonStarted(ID1, "2.0");
+    Assert.equal(getStartupReason(), ADDON_UPGRADE);
+    Assert.equal(getInstallOldVersion(), 1);
+    Assert.equal(getStartupOldVersion(), 1);
+    Assert.equal(getShutdownReason(), ADDON_UPGRADE);
+    Assert.equal(getShutdownNewVersion(), 2);
+    Assert.equal(getUninstallNewVersion(), 2);
+    do_check_not_in_crash_annotation(ID1, "1.0");
+    do_check_in_crash_annotation(ID1, "2.0");
+
+    do_check_bootstrappedPref(run_test_7);
+  });
+}
+
+// Tests that uninstalling doesn't require a restart
+function run_test_7() {
+  AddonManager.getAddonByID(ID1, function(b1) {
+    prepare_test({
+      [ID1]: [
+        ["onUninstalling", false],
+        "onUninstalled"
+      ]
+    });
+
+    Assert.equal(b1.operationsRequiringRestart &
+                 AddonManager.OP_NEEDS_RESTART_UNINSTALL, 0);
+    b1.uninstall();
+
+    do_check_bootstrappedPref(check_test_7);
+  });
+}
+
+function check_test_7() {
+  ensure_test_completed();
+  BootstrapMonitor.checkAddonNotInstalled(ID1);
+  BootstrapMonitor.checkAddonNotStarted(ID1);
+  Assert.equal(getShutdownReason(), ADDON_UNINSTALL);
+  Assert.equal(getShutdownNewVersion(), undefined);
+  do_check_not_in_crash_annotation(ID1, "2.0");
+
+  AddonManager.getAddonByID(ID1, callback_soon(function(b1) {
+    Assert.equal(b1, null);
+
+    restartManager();
+
+    AddonManager.getAddonByID(ID1, function(newb1) {
+      Assert.equal(newb1, null);
+
+      do_check_bootstrappedPref(run_test_8);
+    });
+  }));
+}
+
+// Test that a bootstrapped extension dropped into the profile loads properly
+// on startup and doesn't cause an EM restart
+function run_test_8() {
+  shutdownManager();
+
+  manuallyInstall(do_get_addon("test_bootstrap1_1"), profileDir,
+                  ID1);
+
+  startupManager(false);
+
+  AddonManager.getAddonByID(ID1, 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(!b1.isSystem);
+    BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+    BootstrapMonitor.checkAddonStarted(ID1, "1.0");
+    Assert.equal(getStartupReason(), ADDON_INSTALL);
+    Assert.equal(getStartupOldVersion(), undefined);
+    do_check_in_crash_annotation(ID1, "1.0");
+
+    do_check_bootstrappedPref(run_test_9);
+  });
+}
+
+// Test that items detected as removed during startup get removed properly
+function run_test_9() {
+  shutdownManager();
+
+  manuallyUninstall(profileDir, ID1);
+  BootstrapMonitor.clear(ID1);
+
+  startupManager(false);
+
+  AddonManager.getAddonByID(ID1, function(b1) {
+    Assert.equal(b1, null);
+    do_check_not_in_crash_annotation(ID1, "1.0");
+
+    do_check_bootstrappedPref(run_test_10);
+  });
 }
 
 
-add_task(async function run_test() {
-  promiseStartupManager();
+// Tests that installing a downgrade sends the right reason
+function run_test_10() {
+  prepare_test({ }, [
+    "onNewInstall"
+  ]);
+
+  AddonManager.getInstallForFile(do_get_addon("test_bootstrap1_2"), function(install) {
+    ensure_test_completed();
+
+    Assert.notEqual(install, null);
+    Assert.equal(install.type, "extension");
+    Assert.equal(install.version, "2.0");
+    Assert.equal(install.name, "Test Bootstrap 1");
+    Assert.equal(install.state, AddonManager.STATE_DOWNLOADED);
+    Assert.ok(install.addon.hasResource("install.rdf"));
+    Assert.ok(install.addon.hasResource("bootstrap.js"));
+    Assert.ok(!install.addon.hasResource("foo.bar"));
+    do_check_not_in_crash_annotation(ID1, "2.0");
+
+    BootstrapMonitor.promiseAddonStartup(ID1).then(check_test_10_pt1);
+    prepare_test({
+      [ID1]: [
+        ["onInstalling", false],
+        "onInstalled"
+      ]
+    }, [
+      "onInstallStarted",
+      "onInstallEnded",
+    ], function() {
+      info("Waiting for startup of bootstrap1_2");
+    });
+    install.install();
+  });
+}
+
+function check_test_10_pt1() {
+  AddonManager.getAddonByID(ID1, function(b1) {
+    Assert.notEqual(b1, null);
+    Assert.equal(b1.version, "2.0");
+    Assert.ok(!b1.appDisabled);
+    Assert.ok(!b1.userDisabled);
+    Assert.ok(b1.isActive);
+    Assert.ok(!b1.isSystem);
+    BootstrapMonitor.checkAddonInstalled(ID1, "2.0");
+    BootstrapMonitor.checkAddonStarted(ID1, "2.0");
+    Assert.equal(getStartupReason(), ADDON_INSTALL);
+    Assert.equal(getStartupOldVersion(), undefined);
+    Assert.ok(b1.hasResource("install.rdf"));
+    Assert.ok(b1.hasResource("bootstrap.js"));
+    Assert.ok(!b1.hasResource("foo.bar"));
+    do_check_in_crash_annotation(ID1, "2.0");
+
+    prepare_test({ }, [
+      "onNewInstall"
+    ]);
+
+    AddonManager.getInstallForFile(do_get_addon("test_bootstrap1_1"), function(install) {
+      ensure_test_completed();
+
+      Assert.notEqual(install, null);
+      Assert.equal(install.type, "extension");
+      Assert.equal(install.version, "1.0");
+      Assert.equal(install.name, "Test Bootstrap 1");
+      Assert.equal(install.state, AddonManager.STATE_DOWNLOADED);
+
+      BootstrapMonitor.promiseAddonStartup(ID1).then(check_test_10_pt2);
+      prepare_test({
+        [ID1]: [
+          ["onInstalling", false],
+          "onInstalled"
+        ]
+      }, [
+        "onInstallStarted",
+        "onInstallEnded",
+      ], function() { });
+      install.install();
+    });
+  });
+}
 
-  ok(!gExtensionsJSON.exists());
-  ok(!gAddonStartup.exists());
-});
+function check_test_10_pt2() {
+  AddonManager.getAddonByID(ID1, 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(!b1.isSystem);
+    BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+    BootstrapMonitor.checkAddonStarted(ID1, "1.0");
+    Assert.equal(getStartupReason(), ADDON_DOWNGRADE);
+    Assert.equal(getInstallOldVersion(), 2);
+    Assert.equal(getStartupOldVersion(), 2);
+    Assert.equal(getShutdownReason(), ADDON_DOWNGRADE);
+    Assert.equal(getShutdownNewVersion(), 1);
+    Assert.equal(getUninstallNewVersion(), 1);
+    do_check_in_crash_annotation(ID1, "1.0");
+    do_check_not_in_crash_annotation(ID1, "2.0");
+
+    do_check_bootstrappedPref(run_test_11);
+  });
+}
+
+// Tests that uninstalling a disabled add-on still calls the uninstall method
+function run_test_11() {
+  AddonManager.getAddonByID(ID1, function(b1) {
+    prepare_test({
+      [ID1]: [
+        ["onDisabling", false],
+        "onDisabled",
+        ["onUninstalling", false],
+        "onUninstalled"
+      ]
+    });
+
+    b1.userDisabled = true;
+
+    BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+    BootstrapMonitor.checkAddonNotStarted(ID1);
+    Assert.equal(getShutdownReason(), ADDON_DISABLE);
+    Assert.equal(getShutdownNewVersion(), undefined);
+    do_check_not_in_crash_annotation(ID1, "1.0");
+
+    b1.uninstall();
 
-// Tests that installing doesn't require a restart
-add_task(async function test_1() {
-  prepare_test({}, [
+    check_test_11();
+  });
+}
+
+function check_test_11() {
+  ensure_test_completed();
+  BootstrapMonitor.checkAddonNotInstalled(ID1);
+  BootstrapMonitor.checkAddonNotStarted(ID1);
+  do_check_not_in_crash_annotation(ID1, "1.0");
+
+  do_check_bootstrappedPref(run_test_12);
+}
+
+// Tests that bootstrapped extensions are correctly loaded even if the app is
+// upgraded at the same time
+function run_test_12() {
+  shutdownManager();
+
+  manuallyInstall(do_get_addon("test_bootstrap1_1"), profileDir,
+                  ID1);
+
+  startupManager(true);
+
+  AddonManager.getAddonByID(ID1, 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(!b1.isSystem);
+    BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+    BootstrapMonitor.checkAddonStarted(ID1, "1.0");
+    Assert.equal(getStartupReason(), ADDON_INSTALL);
+    Assert.equal(getStartupOldVersion(), undefined);
+    do_check_in_crash_annotation(ID1, "1.0");
+
+    b1.uninstall();
+    executeSoon(test_12_restart);
+  });
+}
+
+function test_12_restart() {
+  restartManager();
+  do_check_bootstrappedPref(run_test_13);
+}
+
+
+// Tests that installing a bootstrapped extension with an invalid application
+// entry doesn't call it's startup method
+function run_test_13() {
+  prepare_test({ }, [
     "onNewInstall"
   ]);
 
-  let install = await AddonManager.getInstallForFile(XPIS.test_bootstrap1_1);
-  ensure_test_completed();
+  AddonManager.getInstallForFile(do_get_addon("test_bootstrap1_3"), function(install) {
+    ensure_test_completed();
+
+    Assert.notEqual(install, null);
+    Assert.equal(install.type, "extension");
+    Assert.equal(install.version, "3.0");
+    Assert.equal(install.name, "Test Bootstrap 1");
+    Assert.equal(install.state, AddonManager.STATE_DOWNLOADED);
+    do_check_not_in_crash_annotation(ID1, "3.0");
+
+    prepare_test({
+      [ID1]: [
+        ["onInstalling", false],
+        "onInstalled"
+      ]
+    }, [
+      "onInstallStarted",
+      "onInstallEnded",
+    ], callback_soon(check_test_13));
+    install.install();
+  });
+}
+
+function check_test_13() {
+  AddonManager.getAllInstalls(function(installs) {
+    // There should be no active installs now since the install completed and
+    // doesn't require a restart.
+    Assert.equal(installs.length, 0);
+
+    AddonManager.getAddonByID(ID1, function(b1) {
+      Assert.notEqual(b1, null);
+      Assert.equal(b1.version, "3.0");
+      Assert.ok(b1.appDisabled);
+      Assert.ok(!b1.userDisabled);
+      Assert.ok(!b1.isActive);
+      BootstrapMonitor.checkAddonInstalled(ID1, "3.0"); // We call install even for disabled add-ons
+      BootstrapMonitor.checkAddonNotStarted(ID1); // Should not have called startup though
+      do_check_not_in_crash_annotation(ID1, "3.0");
+
+      executeSoon(test_13_restart);
+    });
+  });
+}
+
+function test_13_restart() {
+  restartManager();
+
+  AddonManager.getAddonByID(ID1, function(b1) {
+    Assert.notEqual(b1, null);
+    Assert.equal(b1.version, "3.0");
+    Assert.ok(b1.appDisabled);
+    Assert.ok(!b1.userDisabled);
+    Assert.ok(!b1.isActive);
+    BootstrapMonitor.checkAddonInstalled(ID1, "3.0"); // We call install even for disabled add-ons
+    BootstrapMonitor.checkAddonNotStarted(ID1); // Should not have called startup though
+    do_check_not_in_crash_annotation(ID1, "3.0");
+
+    do_check_bootstrappedPref(function() {
+      b1.uninstall();
+      executeSoon(run_test_14);
+    });
+  });
+}
+
+// Tests that a bootstrapped extension with an invalid target application entry
+// does not get loaded when detected during startup
+function run_test_14() {
+  restartManager();
+
+  shutdownManager();
+
+  manuallyInstall(do_get_addon("test_bootstrap1_3"), profileDir,
+                  ID1);
+
+  startupManager(false);
+
+  AddonManager.getAddonByID(ID1, function(b1) {
+    Assert.notEqual(b1, null);
+    Assert.equal(b1.version, "3.0");
+    Assert.ok(b1.appDisabled);
+    Assert.ok(!b1.userDisabled);
+    Assert.ok(!b1.isActive);
+    BootstrapMonitor.checkAddonInstalled(ID1, "3.0"); // We call install even for disabled add-ons
+    BootstrapMonitor.checkAddonNotStarted(ID1); // Should not have called startup though
+    do_check_not_in_crash_annotation(ID1, "3.0");
+
+    do_check_bootstrappedPref(function() {
+      b1.uninstall();
+
+      run_test_15();
+    });
+  });
+}
+
+// Tests that upgrading a disabled bootstrapped extension still calls uninstall
+// and install but doesn't startup the new version
+function run_test_15() {
+  BootstrapMonitor.promiseAddonStartup(ID1).then(function test_15_after_startup() {
+    AddonManager.getAddonByID(ID1, 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(!b1.isSystem);
+      BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+      BootstrapMonitor.checkAddonStarted(ID1, "1.0");
+
+      b1.userDisabled = true;
+      Assert.ok(!b1.isActive);
+      BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+      BootstrapMonitor.checkAddonNotStarted(ID1);
+
+      prepare_test({ }, [
+        "onNewInstall"
+      ]);
+
+      AddonManager.getInstallForFile(do_get_addon("test_bootstrap1_2"), function(install) {
+        ensure_test_completed();
+
+        Assert.notEqual(install, null);
+        Assert.ok(install.addon.userDisabled);
+
+        prepare_test({
+          [ID1]: [
+            ["onInstalling", false],
+            "onInstalled"
+          ]
+        }, [
+          "onInstallStarted",
+          "onInstallEnded",
+        ], callback_soon(check_test_15));
+        install.install();
+      });
+    });
+  });
+  installAllFiles([do_get_addon("test_bootstrap1_1")], function test_15_addon_installed() { });
+}
+
+function check_test_15() {
+  AddonManager.getAddonByID(ID1, function(b1) {
+    Assert.notEqual(b1, null);
+    Assert.equal(b1.version, "2.0");
+    Assert.ok(!b1.appDisabled);
+    Assert.ok(b1.userDisabled);
+    Assert.ok(!b1.isActive);
+    BootstrapMonitor.checkAddonInstalled(ID1, "2.0");
+    BootstrapMonitor.checkAddonNotStarted(ID1);
+
+    do_check_bootstrappedPref(function() {
+      restartManager();
+
+      AddonManager.getAddonByID(ID1, callback_soon(function(b1_2) {
+        Assert.notEqual(b1_2, null);
+        Assert.equal(b1_2.version, "2.0");
+        Assert.ok(!b1_2.appDisabled);
+        Assert.ok(b1_2.userDisabled);
+        Assert.ok(!b1_2.isActive);
+        BootstrapMonitor.checkAddonInstalled(ID1, "2.0");
+        BootstrapMonitor.checkAddonNotStarted(ID1);
+
+        b1_2.uninstall();
+
+        run_test_16();
+      }));
+    });
+  });
+}
+
+// Tests that bootstrapped extensions don't get loaded when in safe mode
+function run_test_16() {
+  BootstrapMonitor.promiseAddonStartup(ID1).then(function test_16_after_startup() {
+    AddonManager.getAddonByID(ID1, callback_soon(function(b1) {
+      // Should have installed and started
+      BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+      BootstrapMonitor.checkAddonStarted(ID1, "1.0");
+      Assert.ok(b1.isActive);
+      Assert.ok(!b1.isSystem);
+      Assert.equal(b1.iconURL, "chrome://foo/skin/icon.png");
+      Assert.equal(b1.aboutURL, "chrome://foo/content/about.xul");
+      Assert.equal(b1.optionsURL, "chrome://foo/content/options.xul");
+
+      shutdownManager();
+
+      // Should have stopped
+      BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+      BootstrapMonitor.checkAddonNotStarted(ID1);
+
+      gAppInfo.inSafeMode = true;
+      startupManager(false);
+
+      AddonManager.getAddonByID(ID1, callback_soon(function(b1_2) {
+        // Should still be stopped
+        BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+        BootstrapMonitor.checkAddonNotStarted(ID1);
+        Assert.ok(!b1_2.isActive);
+        Assert.equal(b1_2.iconURL, null);
+        Assert.equal(b1_2.aboutURL, null);
+        Assert.equal(b1_2.optionsURL, null);
+
+        shutdownManager();
+        gAppInfo.inSafeMode = false;
+        startupManager(false);
+
+        // Should have started
+        BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+        BootstrapMonitor.checkAddonStarted(ID1, "1.0");
+
+        AddonManager.getAddonByID(ID1, function(b1_3) {
+          b1_3.uninstall();
+
+          executeSoon(run_test_17);
+        });
+      }));
+    }));
+  });
+  installAllFiles([do_get_addon("test_bootstrap1_1")], function() { });
+}
+
+// Check that a bootstrapped extension in a non-profile location is loaded
+function run_test_17() {
+  shutdownManager();
+
+  manuallyInstall(do_get_addon("test_bootstrap1_1"), userExtDir,
+                  ID1);
+
+  startupManager();
+
+  AddonManager.getAddonByID(ID1, function(b1) {
+    // Should have installed and started
+    BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+    BootstrapMonitor.checkAddonStarted(ID1, "1.0");
+    Assert.notEqual(b1, null);
+    Assert.equal(b1.version, "1.0");
+    Assert.ok(b1.isActive);
+    Assert.ok(!b1.isSystem);
 
-  notEqual(install, null);
-  equal(install.type, "extension");
-  equal(install.version, "1.0");
-  equal(install.name, "Test Bootstrap 1");
-  equal(install.state, AddonManager.STATE_DOWNLOADED);
-  notEqual(install.addon.syncGUID, null);
-  ok(install.addon.hasResource("install.rdf"));
-  ok(install.addon.hasResource("bootstrap.js"));
-  ok(!install.addon.hasResource("foo.bar"));
-  equal(install.addon.operationsRequiringRestart &
-               AddonManager.OP_NEEDS_RESTART_INSTALL, 0);
-  do_check_not_in_crash_annotation(ID1, "1.0");
+    do_check_bootstrappedPref(run_test_18);
+  });
+}
+
+// Check that installing a new bootstrapped extension in the profile replaces
+// the existing one
+function run_test_18() {
+  BootstrapMonitor.promiseAddonStartup(ID1).then(function test_18_after_startup() {
+    AddonManager.getAddonByID(ID1, function(b1) {
+      // Should have installed and started
+      BootstrapMonitor.checkAddonInstalled(ID1, "2.0");
+      BootstrapMonitor.checkAddonStarted(ID1, "2.0");
+      Assert.notEqual(b1, null);
+      Assert.equal(b1.version, "2.0");
+      Assert.ok(b1.isActive);
+      Assert.ok(!b1.isSystem);
+
+      Assert.equal(getShutdownReason(), ADDON_UPGRADE);
+      Assert.equal(getUninstallReason(), ADDON_UPGRADE);
+      Assert.equal(getInstallReason(), ADDON_UPGRADE);
+      Assert.equal(getStartupReason(), ADDON_UPGRADE);
+
+      Assert.equal(getShutdownNewVersion(), 2);
+      Assert.equal(getUninstallNewVersion(), 2);
+      Assert.equal(getInstallOldVersion(), 1);
+      Assert.equal(getStartupOldVersion(), 1);
+
+      do_check_bootstrappedPref(run_test_19);
+    });
+  });
+  installAllFiles([do_get_addon("test_bootstrap1_2")], function() { });
+}
+
+// Check that uninstalling the profile version reveals the non-profile one
+function run_test_19() {
+  AddonManager.getAddonByID(ID1, function(b1) {
+    // The revealed add-on gets activated asynchronously
+    prepare_test({
+      [ID1]: [
+        ["onUninstalling", false],
+        "onUninstalled",
+        ["onInstalling", false],
+        "onInstalled"
+      ]
+    }, [], check_test_19);
+
+    b1.uninstall();
+  });
+}
+
+function check_test_19() {
+  AddonManager.getAddonByID(ID1, function(b1) {
+    // Should have reverted to the older version
+    BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+    BootstrapMonitor.checkAddonStarted(ID1, "1.0");
+    Assert.notEqual(b1, null);
+    Assert.equal(b1.version, "1.0");
+    Assert.ok(b1.isActive);
+    Assert.ok(!b1.isSystem);
+
+    Assert.equal(getShutdownReason(), ADDON_DOWNGRADE);
+    Assert.equal(getUninstallReason(), ADDON_DOWNGRADE);
+    Assert.equal(getInstallReason(), ADDON_DOWNGRADE);
+    Assert.equal(getStartupReason(), ADDON_DOWNGRADE);
+
+    Assert.equal(getShutdownNewVersion(), undefined);
+    Assert.equal(getUninstallNewVersion(), undefined);
+    Assert.equal(getInstallOldVersion(), undefined);
+    Assert.equal(getStartupOldVersion(), undefined);
+
+    do_check_bootstrappedPref(run_test_20);
+  });
+}
+
+// Check that a new profile extension detected at startup replaces the non-profile
+// one
+function run_test_20() {
+  shutdownManager();
+
+  manuallyInstall(do_get_addon("test_bootstrap1_2"), profileDir,
+                  ID1);
+
+  startupManager();
+
+  AddonManager.getAddonByID(ID1, function(b1) {
+    // Should have installed and started
+    BootstrapMonitor.checkAddonInstalled(ID1, "2.0");
+    BootstrapMonitor.checkAddonStarted(ID1, "2.0");
+    Assert.notEqual(b1, null);
+    Assert.equal(b1.version, "2.0");
+    Assert.ok(b1.isActive);
+    Assert.ok(!b1.isSystem);
+
+    Assert.equal(getShutdownReason(), APP_SHUTDOWN);
+    Assert.equal(getUninstallReason(), ADDON_UPGRADE);
+    Assert.equal(getInstallReason(), ADDON_UPGRADE);
+    Assert.equal(getStartupReason(), APP_STARTUP);
+
+    Assert.equal(getShutdownNewVersion(), undefined);
+    Assert.equal(getUninstallNewVersion(), 2);
+    Assert.equal(getInstallOldVersion(), 1);
+    Assert.equal(getStartupOldVersion(), undefined);
+
+    executeSoon(run_test_21);
+  });
+}
+
+// Check that a detected removal reveals the non-profile one
+function run_test_21() {
+  shutdownManager();
+
+  Assert.equal(getShutdownReason(), APP_SHUTDOWN);
+  Assert.equal(getShutdownNewVersion(), undefined);
+
+  manuallyUninstall(profileDir, ID1);
+  BootstrapMonitor.clear(ID1);
+
+  startupManager();
 
-  let addon = install.addon;
+  AddonManager.getAddonByID(ID1, function(b1) {
+    // Should have installed and started
+    BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+    BootstrapMonitor.checkAddonStarted(ID1, "1.0");
+    Assert.notEqual(b1, null);
+    Assert.equal(b1.version, "1.0");
+    Assert.ok(b1.isActive);
+    Assert.ok(!b1.isSystem);
+
+    // This won't be set as the bootstrap script was gone so we couldn't
+    // uninstall it properly
+    Assert.equal(getUninstallReason(), undefined);
+    Assert.equal(getUninstallNewVersion(), undefined);
+
+    Assert.equal(getInstallReason(), ADDON_DOWNGRADE);
+    Assert.equal(getInstallOldVersion(), 2);
+
+    Assert.equal(getStartupReason(), APP_STARTUP);
+    Assert.equal(getStartupOldVersion(), undefined);
+
+    do_check_bootstrappedPref(function() {
+      shutdownManager();
+
+      manuallyUninstall(userExtDir, ID1);
+      BootstrapMonitor.clear(ID1);
+
+      startupManager(false);
+      run_test_22();
+    });
+  });
+}
+
+// Check that an upgrade from the filesystem is detected and applied correctly
+function run_test_22() {
+  shutdownManager();
+
+  let file = manuallyInstall(do_get_addon("test_bootstrap1_1"), profileDir,
+                             ID1);
+  if (file.isDirectory())
+    file.append("install.rdf");
+
+  // Make it look old so changes are detected
+  setExtensionModifiedTime(file, file.lastModifiedTime - 5000);
+
+  startupManager();
+
+  AddonManager.getAddonByID(ID1, callback_soon(function(b1) {
+    // Should have installed and started
+    BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+    BootstrapMonitor.checkAddonStarted(ID1, "1.0");
+    Assert.notEqual(b1, null);
+    Assert.equal(b1.version, "1.0");
+    Assert.ok(b1.isActive);
+    Assert.ok(!b1.isSystem);
+
+    shutdownManager();
+
+    Assert.equal(getShutdownReason(), APP_SHUTDOWN);
+    Assert.equal(getShutdownNewVersion(), undefined);
 
-  await Promise.all([
-    BootstrapMonitor.promiseAddonStartup(ID1),
-    new Promise(resolve => {
+    manuallyUninstall(profileDir, ID1);
+    BootstrapMonitor.clear(ID1);
+    manuallyInstall(do_get_addon("test_bootstrap1_2"), profileDir,
+                    ID1);
+
+    startupManager();
+
+    AddonManager.getAddonByID(ID1, function(b1_2) {
+      // Should have installed and started
+      BootstrapMonitor.checkAddonInstalled(ID1, "2.0");
+      BootstrapMonitor.checkAddonStarted(ID1, "2.0");
+      Assert.notEqual(b1_2, null);
+      Assert.equal(b1_2.version, "2.0");
+      Assert.ok(b1_2.isActive);
+      Assert.ok(!b1_2.isSystem);
+
+      // This won't be set as the bootstrap script was gone so we couldn't
+      // uninstall it properly
+      Assert.equal(getUninstallReason(), undefined);
+      Assert.equal(getUninstallNewVersion(), undefined);
+
+      Assert.equal(getInstallReason(), ADDON_UPGRADE);
+      Assert.equal(getInstallOldVersion(), 1);
+      Assert.equal(getStartupReason(), APP_STARTUP);
+      Assert.equal(getStartupOldVersion(), undefined);
+
+      do_check_bootstrappedPref(function() {
+        b1_2.uninstall();
+
+        run_test_23();
+      });
+    });
+  }));
+}
+
+
+// Tests that installing from a URL doesn't require a restart
+function run_test_23() {
+  prepare_test({ }, [
+    "onNewInstall"
+  ]);
+
+  let url = "http://localhost:" + gPort + "/addons/test_bootstrap1_1.xpi";
+  AddonManager.getInstallForURL(url, function(install) {
+    ensure_test_completed();
+
+    Assert.notEqual(install, null);
+
+    prepare_test({ }, [
+      "onDownloadStarted",
+      "onDownloadEnded"
+    ], function() {
+      Assert.equal(install.type, "extension");
+      Assert.equal(install.version, "1.0");
+      Assert.equal(install.name, "Test Bootstrap 1");
+      Assert.equal(install.state, AddonManager.STATE_DOWNLOADED);
+      Assert.ok(install.addon.hasResource("install.rdf"));
+      Assert.ok(install.addon.hasResource("bootstrap.js"));
+      Assert.ok(!install.addon.hasResource("foo.bar"));
+      Assert.equal(install.addon.operationsRequiringRestart &
+                   AddonManager.OP_NEEDS_RESTART_INSTALL, 0);
+      do_check_not_in_crash_annotation(ID1, "1.0");
+
+      let addon = install.addon;
       prepare_test({
         [ID1]: [
           ["onInstalling", false],
           "onInstalled"
         ]
       }, [
         "onInstallStarted",
         "onInstallEnded",
       ], function() {
-        ok(addon.hasResource("install.rdf"));
-
-        // startup should not have been called yet.
-        BootstrapMonitor.checkAddonNotStarted(ID1);
-        resolve();
+        Assert.ok(addon.hasResource("install.rdf"));
+        do_check_bootstrappedPref(check_test_23);
       });
-      install.install();
-    }),
-  ]);
-
-  await checkBootstrappedPref();
-  let installSyncGUID = addon.syncGUID;
-
-  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);
-
-  let b1 = await AddonManager.getAddonByID(ID1);
-  notEqual(b1, null);
-  equal(b1.version, "1.0");
-  notEqual(b1.syncGUID, null);
-  equal(b1.syncGUID, installSyncGUID);
-  ok(!b1.appDisabled);
-  ok(!b1.userDisabled);
-  ok(b1.isActive);
-  ok(!b1.isSystem);
-  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
-  BootstrapMonitor.checkAddonStarted(ID1, "1.0");
-  equal(getStartupReason(), ADDON_INSTALL);
-  equal(getStartupOldVersion(), undefined);
-  ok(b1.hasResource("install.rdf"));
-  ok(b1.hasResource("bootstrap.js"));
-  ok(!b1.hasResource("foo.bar"));
-  do_check_in_crash_annotation(ID1, "1.0");
-
-  let dir = do_get_addon_root_uri(profileDir, ID1);
-  equal(b1.getResourceURI("bootstrap.js").spec, dir + "bootstrap.js");
-
-  let list = await AddonManager.getAddonsWithOperationsByTypes(null);
-  equal(list.length, 0);
-});
-
-// Tests that disabling doesn't require a restart
-add_task(async function test_2() {
-  let b1 = await AddonManager.getAddonByID(ID1);
-  prepare_test({
-    [ID1]: [
-      ["onDisabling", false],
-      "onDisabled"
-    ]
-  });
-
-  equal(b1.operationsRequiringRestart &
-        AddonManager.OP_NEEDS_RESTART_DISABLE, 0);
-  b1.userDisabled = true;
-  ensure_test_completed();
-
-  notEqual(b1, null);
-  equal(b1.version, "1.0");
-  ok(!b1.appDisabled);
-  ok(b1.userDisabled);
-  ok(!b1.isActive);
-  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
-  BootstrapMonitor.checkAddonNotStarted(ID1);
-  equal(getShutdownReason(), ADDON_DISABLE);
-  equal(getShutdownNewVersion(), undefined);
-  do_check_not_in_crash_annotation(ID1, "1.0");
-
-  let newb1 = await AddonManager.getAddonByID(ID1);
-  notEqual(newb1, null);
-  equal(newb1.version, "1.0");
-  ok(!newb1.appDisabled);
-  ok(newb1.userDisabled);
-  ok(!newb1.isActive);
-
-  await checkBootstrappedPref();
-});
-
-// Test that restarting doesn't accidentally re-enable
-add_task(async function test_3() {
-  await promiseShutdownManager();
-
-  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
-  BootstrapMonitor.checkAddonNotStarted(ID1);
-  equal(getShutdownReason(), ADDON_DISABLE);
-  equal(getShutdownNewVersion(), undefined);
-
-  await promiseStartupManager(false);
-
-  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
-  BootstrapMonitor.checkAddonNotStarted(ID1);
-  equal(getShutdownReason(), ADDON_DISABLE);
-  equal(getShutdownNewVersion(), undefined);
-  do_check_not_in_crash_annotation(ID1, "1.0");
-
-  ok(gAddonStartup.exists());
-
-  let b1 = await AddonManager.getAddonByID(ID1);
-  notEqual(b1, null);
-  equal(b1.version, "1.0");
-  ok(!b1.appDisabled);
-  ok(b1.userDisabled);
-  ok(!b1.isActive);
-
-  await checkBootstrappedPref();
-});
-
-// Tests that enabling doesn't require a restart
-add_task(async function test_4() {
-  let b1 = await AddonManager.getAddonByID(ID1);
-  prepare_test({
-    [ID1]: [
-      ["onEnabling", false],
-      "onEnabled"
-    ]
-  });
-
-  equal(b1.operationsRequiringRestart &
-               AddonManager.OP_NEEDS_RESTART_ENABLE, 0);
-  b1.userDisabled = false;
-  ensure_test_completed();
-
-  notEqual(b1, null);
-  equal(b1.version, "1.0");
-  ok(!b1.appDisabled);
-  ok(!b1.userDisabled);
-  ok(b1.isActive);
-  ok(!b1.isSystem);
-  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
-  BootstrapMonitor.checkAddonStarted(ID1, "1.0");
-  equal(getStartupReason(), ADDON_ENABLE);
-  equal(getStartupOldVersion(), undefined);
-  do_check_in_crash_annotation(ID1, "1.0");
-
-  let newb1 = await AddonManager.getAddonByID(ID1);
-  notEqual(newb1, null);
-  equal(newb1.version, "1.0");
-  ok(!newb1.appDisabled);
-  ok(!newb1.userDisabled);
-  ok(newb1.isActive);
-
-  await checkBootstrappedPref();
-});
-
-// Tests that a restart shuts down and restarts the add-on
-add_task(async function test_5() {
-  await promiseShutdownManager();
-  // By the time we've shut down, the database must have been written
-  ok(gExtensionsJSON.exists());
-
-  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
-  BootstrapMonitor.checkAddonNotStarted(ID1);
-  equal(getShutdownReason(), APP_SHUTDOWN);
-  equal(getShutdownNewVersion(), undefined);
-  do_check_not_in_crash_annotation(ID1, "1.0");
-  await promiseStartupManager(false);
-  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
-  BootstrapMonitor.checkAddonStarted(ID1, "1.0");
-  equal(getStartupReason(), APP_STARTUP);
-  equal(getStartupOldVersion(), undefined);
-  do_check_in_crash_annotation(ID1, "1.0");
-
-  let b1 = await AddonManager.getAddonByID(ID1);
-  notEqual(b1, null);
-  equal(b1.version, "1.0");
-  ok(!b1.appDisabled);
-  ok(!b1.userDisabled);
-  ok(b1.isActive);
-  ok(!b1.isSystem);
-  ok(!isExtensionInAddonsList(profileDir, b1.id));
-
-  await checkBootstrappedPref();
-});
-
-// Tests that installing an upgrade doesn't require a restart
-add_task(async function test_6() {
-  prepare_test({}, [
-    "onNewInstall"
-  ]);
-
-  let install = await AddonManager.getInstallForFile(XPIS.test_bootstrap1_2);
-  ensure_test_completed();
-
-  notEqual(install, null);
-  equal(install.type, "extension");
-  equal(install.version, "2.0");
-  equal(install.name, "Test Bootstrap 1");
-  equal(install.state, AddonManager.STATE_DOWNLOADED);
-
-  await Promise.all([
-    BootstrapMonitor.promiseAddonStartup(ID1),
-    new Promise(resolve => {
-      prepare_test({
-        [ID1]: [
-          ["onInstalling", false],
-          "onInstalled"
-        ]
-      }, [
-        "onInstallStarted",
-        "onInstallEnded",
-      ], resolve);
-      install.install();
-    }),
-  ]);
-
-  let b1 = await AddonManager.getAddonByID(ID1);
-  notEqual(b1, null);
-  equal(b1.version, "2.0");
-  ok(!b1.appDisabled);
-  ok(!b1.userDisabled);
-  ok(b1.isActive);
-  ok(!b1.isSystem);
-  BootstrapMonitor.checkAddonInstalled(ID1, "2.0");
-  BootstrapMonitor.checkAddonStarted(ID1, "2.0");
-  equal(getStartupReason(), ADDON_UPGRADE);
-  equal(getInstallOldVersion(), 1);
-  equal(getStartupOldVersion(), 1);
-  equal(getShutdownReason(), ADDON_UPGRADE);
-  equal(getShutdownNewVersion(), 2);
-  equal(getUninstallNewVersion(), 2);
-  do_check_not_in_crash_annotation(ID1, "1.0");
-  do_check_in_crash_annotation(ID1, "2.0");
-
-  await checkBootstrappedPref();
-});
-
-// Tests that uninstalling doesn't require a restart
-add_task(async function test_7() {
-  let b1 = await AddonManager.getAddonByID(ID1);
-  prepare_test({
-    [ID1]: [
-      ["onUninstalling", false],
-      "onUninstalled"
-    ]
-  });
-
-  equal(b1.operationsRequiringRestart &
-        AddonManager.OP_NEEDS_RESTART_UNINSTALL, 0);
-  b1.uninstall();
-
-  await checkBootstrappedPref();
-
-  ensure_test_completed();
-  BootstrapMonitor.checkAddonNotInstalled(ID1);
-  BootstrapMonitor.checkAddonNotStarted(ID1);
-  equal(getShutdownReason(), ADDON_UNINSTALL);
-  equal(getShutdownNewVersion(), undefined);
-  do_check_not_in_crash_annotation(ID1, "2.0");
-
-  b1 = await AddonManager.getAddonByID(ID1);
-  equal(b1, null);
-
-  await promiseRestartManager();
-
-  let newb1 = await AddonManager.getAddonByID(ID1);
-  equal(newb1, null);
-
-  await checkBootstrappedPref();
-});
-
-// Test that a bootstrapped extension dropped into the profile loads properly
-// on startup and doesn't cause an EM restart
-add_task(async function test_8() {
-  await promiseShutdownManager();
-
-  manuallyInstall(XPIS.test_bootstrap1_1, profileDir,
-                  ID1);
-
-  await promiseStartupManager(false);
-
-  let b1 = await AddonManager.getAddonByID(ID1);
-  notEqual(b1, null);
-  equal(b1.version, "1.0");
-  ok(!b1.appDisabled);
-  ok(!b1.userDisabled);
-  ok(b1.isActive);
-  ok(!b1.isSystem);
-  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
-  BootstrapMonitor.checkAddonStarted(ID1, "1.0");
-  equal(getStartupReason(), ADDON_INSTALL);
-  equal(getStartupOldVersion(), undefined);
-  do_check_in_crash_annotation(ID1, "1.0");
-
-  await checkBootstrappedPref();
-});
-
-// Test that items detected as removed during startup get removed properly
-add_task(async function test_9() {
-  await promiseShutdownManager();
-
-  manuallyUninstall(profileDir, ID1);
-  BootstrapMonitor.clear(ID1);
-
-  await promiseStartupManager(false);
-
-  let b1 = await AddonManager.getAddonByID(ID1);
-  equal(b1, null);
-  do_check_not_in_crash_annotation(ID1, "1.0");
-
-  await checkBootstrappedPref();
-});
-
-
-// Tests that installing a downgrade sends the right reason
-add_task(async function test_10() {
-  prepare_test({}, [
-    "onNewInstall"
-  ]);
-
-  let install = await AddonManager.getInstallForFile(XPIS.test_bootstrap1_2);
-  ensure_test_completed();
-
-  notEqual(install, null);
-  equal(install.type, "extension");
-  equal(install.version, "2.0");
-  equal(install.name, "Test Bootstrap 1");
-  equal(install.state, AddonManager.STATE_DOWNLOADED);
-  ok(install.addon.hasResource("install.rdf"));
-  ok(install.addon.hasResource("bootstrap.js"));
-  ok(!install.addon.hasResource("foo.bar"));
-  do_check_not_in_crash_annotation(ID1, "2.0");
-
-  await Promise.all([
-    BootstrapMonitor.promiseAddonStartup(ID1),
-    new Promise(resolve => {
-      prepare_test({
-        [ID1]: [
-          ["onInstalling", false],
-          "onInstalled"
-        ]
-      }, [
-        "onInstallStarted",
-        "onInstallEnded",
-      ], resolve);
-      install.install();
-    }),
-  ]);
-
-
-  let b1 = await AddonManager.getAddonByID(ID1);
-  notEqual(b1, null);
-  equal(b1.version, "2.0");
-  ok(!b1.appDisabled);
-  ok(!b1.userDisabled);
-  ok(b1.isActive);
-  ok(!b1.isSystem);
-  BootstrapMonitor.checkAddonInstalled(ID1, "2.0");
-  BootstrapMonitor.checkAddonStarted(ID1, "2.0");
-  equal(getStartupReason(), ADDON_INSTALL);
-  equal(getStartupOldVersion(), undefined);
-  ok(b1.hasResource("install.rdf"));
-  ok(b1.hasResource("bootstrap.js"));
-  ok(!b1.hasResource("foo.bar"));
-  do_check_in_crash_annotation(ID1, "2.0");
-
-  prepare_test({}, [
-    "onNewInstall"
-  ]);
-
-  install = await AddonManager.getInstallForFile(XPIS.test_bootstrap1_1);
-  ensure_test_completed();
-
-  notEqual(install, null);
-  equal(install.type, "extension");
-  equal(install.version, "1.0");
-  equal(install.name, "Test Bootstrap 1");
-  equal(install.state, AddonManager.STATE_DOWNLOADED);
-
-  await Promise.all([
-    BootstrapMonitor.promiseAddonStartup(ID1),
-    new Promise(resolve => {
-      prepare_test({
-        [ID1]: [
-          ["onInstalling", false],
-          "onInstalled"
-        ]
-      }, [
-        "onInstallStarted",
-        "onInstallEnded",
-      ], resolve);
-      install.install();
-    }),
-  ]);
-
-  b1 = await AddonManager.getAddonByID(ID1);
-  notEqual(b1, null);
-  equal(b1.version, "1.0");
-  ok(!b1.appDisabled);
-  ok(!b1.userDisabled);
-  ok(b1.isActive);
-  ok(!b1.isSystem);
-  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
-  BootstrapMonitor.checkAddonStarted(ID1, "1.0");
-  equal(getStartupReason(), ADDON_DOWNGRADE);
-  equal(getInstallOldVersion(), 2);
-  equal(getStartupOldVersion(), 2);
-  equal(getShutdownReason(), ADDON_DOWNGRADE);
-  equal(getShutdownNewVersion(), 1);
-  equal(getUninstallNewVersion(), 1);
-  do_check_in_crash_annotation(ID1, "1.0");
-  do_check_not_in_crash_annotation(ID1, "2.0");
-
-  await checkBootstrappedPref();
-});
-
-// Tests that uninstalling a disabled add-on still calls the uninstall method
-add_task(async function test_11() {
-  let b1 = await AddonManager.getAddonByID(ID1);
-  prepare_test({
-    [ID1]: [
-      ["onDisabling", false],
-      "onDisabled",
-      ["onUninstalling", false],
-      "onUninstalled"
-    ]
-  });
-
-  b1.userDisabled = true;
-
-  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
-  BootstrapMonitor.checkAddonNotStarted(ID1);
-  equal(getShutdownReason(), ADDON_DISABLE);
-  equal(getShutdownNewVersion(), undefined);
-  do_check_not_in_crash_annotation(ID1, "1.0");
-
-  b1.uninstall();
-
-  ensure_test_completed();
-  BootstrapMonitor.checkAddonNotInstalled(ID1);
-  BootstrapMonitor.checkAddonNotStarted(ID1);
-  do_check_not_in_crash_annotation(ID1, "1.0");
-
-  await checkBootstrappedPref();
-});
-
-// Tests that bootstrapped extensions are correctly loaded even if the app is
-// upgraded at the same time
-add_task(async function test_12() {
-  await promiseShutdownManager();
-
-  manuallyInstall(XPIS.test_bootstrap1_1, profileDir,
-                  ID1);
-
-  await promiseStartupManager(true);
-
-  let b1 = await AddonManager.getAddonByID(ID1);
-  notEqual(b1, null);
-  equal(b1.version, "1.0");
-  ok(!b1.appDisabled);
-  ok(!b1.userDisabled);
-  ok(b1.isActive);
-  ok(!b1.isSystem);
-  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
-  BootstrapMonitor.checkAddonStarted(ID1, "1.0");
-  equal(getStartupReason(), ADDON_INSTALL);
-  equal(getStartupOldVersion(), undefined);
-  do_check_in_crash_annotation(ID1, "1.0");
-
-  b1.uninstall();
-
-  await promiseRestartManager();
-  await checkBootstrappedPref();
-});
-
-
-// Tests that installing a bootstrapped extension with an invalid application
-// entry doesn't call it's startup method
-add_task(async function test_13() {
-  prepare_test({}, [
-    "onNewInstall"
-  ]);
-
-  let install = await AddonManager.getInstallForFile(XPIS.test_bootstrap1_3);
-  ensure_test_completed();
-
-  notEqual(install, null);
-  equal(install.type, "extension");
-  equal(install.version, "3.0");
-  equal(install.name, "Test Bootstrap 1");
-  equal(install.state, AddonManager.STATE_DOWNLOADED);
-  do_check_not_in_crash_annotation(ID1, "3.0");
-
-  await new Promise(resolve => {
-    prepare_test({
-      [ID1]: [
-        ["onInstalling", false],
-        "onInstalled"
-      ]
-    }, [
-      "onInstallStarted",
-      "onInstallEnded",
-    ], resolve);
-    install.install();
-  });
-
-  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);
-
-  let b1 = await AddonManager.getAddonByID(ID1);
-  notEqual(b1, null);
-  equal(b1.version, "3.0");
-  ok(b1.appDisabled);
-  ok(!b1.userDisabled);
-  ok(!b1.isActive);
-  BootstrapMonitor.checkAddonInstalled(ID1, "3.0"); // We call install even for disabled add-ons
-  BootstrapMonitor.checkAddonNotStarted(ID1); // Should not have called startup though
-  do_check_not_in_crash_annotation(ID1, "3.0");
-
-  await promiseRestartManager();
-
-  b1 = await AddonManager.getAddonByID(ID1);
-  notEqual(b1, null);
-  equal(b1.version, "3.0");
-  ok(b1.appDisabled);
-  ok(!b1.userDisabled);
-  ok(!b1.isActive);
-  BootstrapMonitor.checkAddonInstalled(ID1, "3.0"); // We call install even for disabled add-ons
-  BootstrapMonitor.checkAddonNotStarted(ID1); // Should not have called startup though
-  do_check_not_in_crash_annotation(ID1, "3.0");
-
-  await checkBootstrappedPref();
-  b1.uninstall();
-});
-
-// Tests that a bootstrapped extension with an invalid target application entry
-// does not get loaded when detected during startup
-add_task(async function test_14() {
-  await promiseRestartManager();
-
-  await promiseShutdownManager();
-
-  manuallyInstall(XPIS.test_bootstrap1_3, profileDir,
-                  ID1);
-
-  await promiseStartupManager(false);
-
-  let b1 = await AddonManager.getAddonByID(ID1);
-  notEqual(b1, null);
-  equal(b1.version, "3.0");
-  ok(b1.appDisabled);
-  ok(!b1.userDisabled);
-  ok(!b1.isActive);
-  BootstrapMonitor.checkAddonInstalled(ID1, "3.0"); // We call install even for disabled add-ons
-  BootstrapMonitor.checkAddonNotStarted(ID1); // Should not have called startup though
-  do_check_not_in_crash_annotation(ID1, "3.0");
-
-  await checkBootstrappedPref();
-  b1.uninstall();
-});
-
-// Tests that upgrading a disabled bootstrapped extension still calls uninstall
-// and install but doesn't startup the new version
-add_task(async function test_15() {
-  await Promise.all([
-    BootstrapMonitor.promiseAddonStartup(ID1),
-    promiseInstallFile(XPIS.test_bootstrap1_1),
-  ]);
-
-  let b1 = await AddonManager.getAddonByID(ID1);
-  notEqual(b1, null);
-  equal(b1.version, "1.0");
-  ok(!b1.appDisabled);
-  ok(!b1.userDisabled);
-  ok(b1.isActive);
-  ok(!b1.isSystem);
-  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
-  BootstrapMonitor.checkAddonStarted(ID1, "1.0");
-
-  b1.userDisabled = true;
-  ok(!b1.isActive);
-  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
-  BootstrapMonitor.checkAddonNotStarted(ID1);
-
-  prepare_test({}, [
-    "onNewInstall"
-  ]);
-
-  let install = await AddonManager.getInstallForFile(XPIS.test_bootstrap1_2);
-  ensure_test_completed();
-
-  notEqual(install, null);
-  ok(install.addon.userDisabled);
-
-  await new Promise(resolve => {
-    prepare_test({
-      [ID1]: [
-        ["onInstalling", false],
-        "onInstalled"
-      ]
-    }, [
-      "onInstallStarted",
-      "onInstallEnded",
-    ], resolve);
-    install.install();
-  });
-
-  b1 = await AddonManager.getAddonByID(ID1);
-  notEqual(b1, null);
-  equal(b1.version, "2.0");
-  ok(!b1.appDisabled);
-  ok(b1.userDisabled);
-  ok(!b1.isActive);
-  BootstrapMonitor.checkAddonInstalled(ID1, "2.0");
-  BootstrapMonitor.checkAddonNotStarted(ID1);
-
-  await checkBootstrappedPref();
-  await promiseRestartManager();
-
-  let b1_2 = await AddonManager.getAddonByID(ID1);
-  notEqual(b1_2, null);
-  equal(b1_2.version, "2.0");
-  ok(!b1_2.appDisabled);
-  ok(b1_2.userDisabled);
-  ok(!b1_2.isActive);
-  BootstrapMonitor.checkAddonInstalled(ID1, "2.0");
-  BootstrapMonitor.checkAddonNotStarted(ID1);
-
-  b1_2.uninstall();
-});
-
-// Tests that bootstrapped extensions don't get loaded when in safe mode
-add_task(async function test_16() {
-  await Promise.all([
-    BootstrapMonitor.promiseAddonStartup(ID1),
-    promiseInstallFile(XPIS.test_bootstrap1_1),
-  ]);
-
-  let b1 = await AddonManager.getAddonByID(ID1);
-  // Should have installed and started
-  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
-  BootstrapMonitor.checkAddonStarted(ID1, "1.0");
-  ok(b1.isActive);
-  ok(!b1.isSystem);
-  equal(b1.iconURL, "chrome://foo/skin/icon.png");
-  equal(b1.aboutURL, "chrome://foo/content/about.xul");
-  equal(b1.optionsURL, "chrome://foo/content/options.xul");
-
-  await promiseShutdownManager();
-
-  // Should have stopped
-  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
-  BootstrapMonitor.checkAddonNotStarted(ID1);
-
-  gAppInfo.inSafeMode = true;
-  await promiseStartupManager(false);
-
-  let b1_2 = await AddonManager.getAddonByID(ID1);
-  // Should still be stopped
-  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
-  BootstrapMonitor.checkAddonNotStarted(ID1);
-  ok(!b1_2.isActive);
-  equal(b1_2.iconURL, null);
-  equal(b1_2.aboutURL, null);
-  equal(b1_2.optionsURL, null);
-
-  await promiseShutdownManager();
-  gAppInfo.inSafeMode = false;
-  await promiseStartupManager(false);
-
-  // Should have started
-  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
-  BootstrapMonitor.checkAddonStarted(ID1, "1.0");
-
-  let b1_3 = await AddonManager.getAddonByID(ID1);
-  b1_3.uninstall();
-});
-
-// Check that a bootstrapped extension in a non-profile location is loaded
-add_task(async function test_17() {
-  await promiseShutdownManager();
-
-  manuallyInstall(XPIS.test_bootstrap1_1, userExtDir,
-                  ID1);
-
-  await promiseStartupManager();
-
-  let b1 = await AddonManager.getAddonByID(ID1);
-  // Should have installed and started
-  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
-  BootstrapMonitor.checkAddonStarted(ID1, "1.0");
-  notEqual(b1, null);
-  equal(b1.version, "1.0");
-  ok(b1.isActive);
-  ok(!b1.isSystem);
-
-  await checkBootstrappedPref();
-});
-
-// Check that installing a new bootstrapped extension in the profile replaces
-// the existing one
-add_task(async function test_18() {
-  await Promise.all([
-    BootstrapMonitor.promiseAddonStartup(ID1),
-    promiseInstallFile(XPIS.test_bootstrap1_2),
-  ]);
-
-  let b1 = await AddonManager.getAddonByID(ID1);
-  // Should have installed and started
-  BootstrapMonitor.checkAddonInstalled(ID1, "2.0");
-  BootstrapMonitor.checkAddonStarted(ID1, "2.0");
-  notEqual(b1, null);
-  equal(b1.version, "2.0");
-  ok(b1.isActive);
-  ok(!b1.isSystem);
-
-  equal(getShutdownReason(), ADDON_UPGRADE);
-  equal(getUninstallReason(), ADDON_UPGRADE);
-  equal(getInstallReason(), ADDON_UPGRADE);
-  equal(getStartupReason(), ADDON_UPGRADE);
-
-  equal(getShutdownNewVersion(), 2);
-  equal(getUninstallNewVersion(), 2);
-  equal(getInstallOldVersion(), 1);
-  equal(getStartupOldVersion(), 1);
-
-  await checkBootstrappedPref();
-});
-
-// Check that uninstalling the profile version reveals the non-profile one
-add_task(async function test_19() {
-  let b1 = await AddonManager.getAddonByID(ID1);
-  // The revealed add-on gets activated asynchronously
-  await new Promise(resolve => {
-    prepare_test({
-      [ID1]: [
-        ["onUninstalling", false],
-        "onUninstalled",
-        ["onInstalling", false],
-        "onInstalled"
-      ]
-    }, [], resolve);
-
-    b1.uninstall();
-  });
-
-  b1 = await AddonManager.getAddonByID(ID1);
-  // Should have reverted to the older version
-  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
-  BootstrapMonitor.checkAddonStarted(ID1, "1.0");
-  notEqual(b1, null);
-  equal(b1.version, "1.0");
-  ok(b1.isActive);
-  ok(!b1.isSystem);
-
-  equal(getShutdownReason(), ADDON_DOWNGRADE);
-  equal(getUninstallReason(), ADDON_DOWNGRADE);
-  equal(getInstallReason(), ADDON_DOWNGRADE);
-  equal(getStartupReason(), ADDON_DOWNGRADE);
-
-  equal(getShutdownNewVersion(), undefined);
-  equal(getUninstallNewVersion(), undefined);
-  equal(getInstallOldVersion(), undefined);
-  equal(getStartupOldVersion(), undefined);
-
-  await checkBootstrappedPref();
-});
-
-// Check that a new profile extension detected at startup replaces the non-profile
-// one
-add_task(async function test_20() {
-  await promiseShutdownManager();
-
-  manuallyInstall(XPIS.test_bootstrap1_2, profileDir,
-                  ID1);
-
-  await promiseStartupManager();
-
-  let b1 = await AddonManager.getAddonByID(ID1);
-  // Should have installed and started
-  BootstrapMonitor.checkAddonInstalled(ID1, "2.0");
-  BootstrapMonitor.checkAddonStarted(ID1, "2.0");
-  notEqual(b1, null);
-  equal(b1.version, "2.0");
-  ok(b1.isActive);
-  ok(!b1.isSystem);
-
-  equal(getShutdownReason(), APP_SHUTDOWN);
-  equal(getUninstallReason(), ADDON_UPGRADE);
-  equal(getInstallReason(), ADDON_UPGRADE);
-  equal(getStartupReason(), APP_STARTUP);
-
-  equal(getShutdownNewVersion(), undefined);
-  equal(getUninstallNewVersion(), 2);
-  equal(getInstallOldVersion(), 1);
-  equal(getStartupOldVersion(), undefined);
-});
-
-// Check that a detected removal reveals the non-profile one
-add_task(async function test_21() {
-  await promiseShutdownManager();
-
-  equal(getShutdownReason(), APP_SHUTDOWN);
-  equal(getShutdownNewVersion(), undefined);
-
-  manuallyUninstall(profileDir, ID1);
-  BootstrapMonitor.clear(ID1);
-
-  await promiseStartupManager();
-
-  let b1 = await AddonManager.getAddonByID(ID1);
-  // Should have installed and started
-  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
-  BootstrapMonitor.checkAddonStarted(ID1, "1.0");
-  notEqual(b1, null);
-  equal(b1.version, "1.0");
-  ok(b1.isActive);
-  ok(!b1.isSystem);
-
-  // This won't be set as the bootstrap script was gone so we couldn't
-  // uninstall it properly
-  equal(getUninstallReason(), undefined);
-  equal(getUninstallNewVersion(), undefined);
-
-  equal(getInstallReason(), ADDON_DOWNGRADE);
-  equal(getInstallOldVersion(), 2);
-
-  equal(getStartupReason(), APP_STARTUP);
-  equal(getStartupOldVersion(), undefined);
-
-  await checkBootstrappedPref();
-  await promiseShutdownManager();
-
-  manuallyUninstall(userExtDir, ID1);
-  BootstrapMonitor.clear(ID1);
-
-  await promiseStartupManager(false);
-});
-
-// Check that an upgrade from the filesystem is detected and applied correctly
-add_task(async function test_22() {
-  await promiseShutdownManager();
-
-  let file = manuallyInstall(XPIS.test_bootstrap1_1, profileDir,
-                             ID1);
-  if (file.isDirectory())
-    file.append("install.rdf");
-
-  // Make it look old so changes are detected
-  setExtensionModifiedTime(file, file.lastModifiedTime - 5000);
-
-  await promiseStartupManager();
-
-  let b1 = await AddonManager.getAddonByID(ID1);
-  // Should have installed and started
-  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
-  BootstrapMonitor.checkAddonStarted(ID1, "1.0");
-  notEqual(b1, null);
-  equal(b1.version, "1.0");
-  ok(b1.isActive);
-  ok(!b1.isSystem);
-
-  await promiseShutdownManager();
-
-  equal(getShutdownReason(), APP_SHUTDOWN);
-  equal(getShutdownNewVersion(), undefined);
-
-  manuallyUninstall(profileDir, ID1);
-  BootstrapMonitor.clear(ID1);
-  manuallyInstall(XPIS.test_bootstrap1_2, profileDir,
-                  ID1);
-
-  await promiseStartupManager();
-
-  let b1_2 = await AddonManager.getAddonByID(ID1);
-  // Should have installed and started
-  BootstrapMonitor.checkAddonInstalled(ID1, "2.0");
-  BootstrapMonitor.checkAddonStarted(ID1, "2.0");
-  notEqual(b1_2, null);
-  equal(b1_2.version, "2.0");
-  ok(b1_2.isActive);
-  ok(!b1_2.isSystem);
-
-  // This won't be set as the bootstrap script was gone so we couldn't
-  // uninstall it properly
-  equal(getUninstallReason(), undefined);
-  equal(getUninstallNewVersion(), undefined);
-
-  equal(getInstallReason(), ADDON_UPGRADE);
-  equal(getInstallOldVersion(), 1);
-  equal(getStartupReason(), APP_STARTUP);
-  equal(getStartupOldVersion(), undefined);
-
-  await checkBootstrappedPref();
-  b1_2.uninstall();
-});
-
-
-// Tests that installing from a URL doesn't require a restart
-add_task(async function test_23() {
-  prepare_test({}, [
-    "onNewInstall"
-  ]);
-
-  let url = "http://example.com/addons/test_bootstrap1_1.xpi";
-  let install = await AddonManager.getInstallForURL(url, null, "application/x-xpinstall");
-
-  ensure_test_completed();
-
-  notEqual(install, null);
-
-  await new Promise(resolve => {
-    prepare_test({}, [
-      "onDownloadStarted",
-      "onDownloadEnded"
-    ], function() {
-      equal(install.type, "extension");
-      equal(install.version, "1.0");
-      equal(install.name, "Test Bootstrap 1");
-      equal(install.state, AddonManager.STATE_DOWNLOADED);
-      ok(install.addon.hasResource("install.rdf"));
-      ok(install.addon.hasResource("bootstrap.js"));
-      ok(!install.addon.hasResource("foo.bar"));
-      equal(install.addon.operationsRequiringRestart &
-                   AddonManager.OP_NEEDS_RESTART_INSTALL, 0);
-      do_check_not_in_crash_annotation(ID1, "1.0");
-
-      prepare_test({
-        [ID1]: [
-          ["onInstalling", false],
-          "onInstalled"
-        ]
-      }, [
-        "onInstallStarted",
-        "onInstallEnded",
-      ], resolve);
     });
     install.install();
-  });
-
-  ok(install.addon.hasResource("install.rdf"));
-  await checkBootstrappedPref();
+  }, "application/x-xpinstall");
+}
 
-  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);
-
-  let b1 = await AddonManager.getAddonByID(ID1);
+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);
 
-  notEqual(b1, null);
-  equal(b1.version, "1.0");
-  ok(!b1.appDisabled);
-  ok(!b1.userDisabled);
-  ok(b1.isActive);
-  ok(!b1.isSystem);
-  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
-  BootstrapMonitor.checkAddonStarted(ID1, "1.0");
-  equal(getStartupReason(), ADDON_INSTALL);
-  equal(getStartupOldVersion(), undefined);
-  ok(b1.hasResource("install.rdf"));
-  ok(b1.hasResource("bootstrap.js"));
-  ok(!b1.hasResource("foo.bar"));
-  do_check_in_crash_annotation(ID1, "1.0");
+    AddonManager.getAddonByID(ID1, function(b1) {
+     executeSoon(function test_23_after_startup() {
+      Assert.notEqual(b1, null);
+      Assert.equal(b1.version, "1.0");
+      Assert.ok(!b1.appDisabled);
+      Assert.ok(!b1.userDisabled);
+      Assert.ok(b1.isActive);
+      Assert.ok(!b1.isSystem);
+      BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+      BootstrapMonitor.checkAddonStarted(ID1, "1.0");
+      Assert.equal(getStartupReason(), ADDON_INSTALL);
+      Assert.equal(getStartupOldVersion(), undefined);
+      Assert.ok(b1.hasResource("install.rdf"));
+      Assert.ok(b1.hasResource("bootstrap.js"));
+      Assert.ok(!b1.hasResource("foo.bar"));
+      do_check_in_crash_annotation(ID1, "1.0");
 
-  let dir = do_get_addon_root_uri(profileDir, ID1);
-  equal(b1.getResourceURI("bootstrap.js").spec, dir + "bootstrap.js");
+      let dir = do_get_addon_root_uri(profileDir, ID1);
+      Assert.equal(b1.getResourceURI("bootstrap.js").spec, dir + "bootstrap.js");
 
-  let list = await AddonManager.getAddonsWithOperationsByTypes(null);
-  equal(list.length, 0);
+      AddonManager.getAddonsWithOperationsByTypes(null, callback_soon(function(list) {
+        Assert.equal(list.length, 0);
 
-  await promiseRestartManager();
+        restartManager();
+        AddonManager.getAddonByID(ID1, callback_soon(function(b1_2) {
+          b1_2.uninstall();
+          restartManager();
 
-  let b1_2 = await AddonManager.getAddonByID(ID1);
-  b1_2.uninstall();
-});
+          testserver.stop(run_test_24);
+        }));
+      }));
+     });
+    });
+  });
+}
 
 // Tests that we recover from a broken preference
-add_task(async function test_24() {
+function run_test_24() {
   info("starting 24");
 
-  await Promise.all([
-    BootstrapMonitor.promiseAddonStartup(ID2),
-    promiseInstallAllFiles([XPIS.test_bootstrap1_1, XPIS.test_bootstrap2_1]),
-  ]);
+  Promise.all([BootstrapMonitor.promiseAddonStartup(ID2),
+              promiseInstallAllFiles([do_get_addon("test_bootstrap1_1"), do_get_addon("test_bootstrap2_1")])])
+         .then(async function test_24_pref() {
+    info("test 24 got prefs");
+    BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+    BootstrapMonitor.checkAddonStarted(ID1, "1.0");
+    BootstrapMonitor.checkAddonInstalled(ID2, "1.0");
+    BootstrapMonitor.checkAddonStarted(ID2, "1.0");
+
+    restartManager();
+
+    BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+    BootstrapMonitor.checkAddonStarted(ID1, "1.0");
+    BootstrapMonitor.checkAddonInstalled(ID2, "1.0");
+    BootstrapMonitor.checkAddonStarted(ID2, "1.0");
+
+    shutdownManager();
+
+    BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+    BootstrapMonitor.checkAddonNotStarted(ID1);
+    BootstrapMonitor.checkAddonInstalled(ID2, "1.0");
+    BootstrapMonitor.checkAddonNotStarted(ID2);
+
+    // Break the JSON.
+    let data = aomStartup.readStartupData();
+    data["app-profile"].addons[ID1].path += "foo";
+
+    await OS.File.writeAtomic(gAddonStartup.path,
+                              new TextEncoder().encode(JSON.stringify(data)),
+                              {compression: "lz4"});
+
+    startupManager(false);
+
+    BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+    BootstrapMonitor.checkAddonStarted(ID1, "1.0");
+    BootstrapMonitor.checkAddonInstalled(ID2, "1.0");
+    BootstrapMonitor.checkAddonStarted(ID2, "1.0");
+
+    run_test_25();
+  });
+}
+
+// Tests that updating from a bootstrappable add-on to a normal add-on calls
+// the uninstall method
+function run_test_25() {
+  BootstrapMonitor.promiseAddonStartup(ID1).then(function test_25_after_pref() {
+      info("test 25 pref change detected");
+      BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+      BootstrapMonitor.checkAddonStarted(ID1, "1.0");
 
-  info("test 24 got prefs");
-  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
-  BootstrapMonitor.checkAddonStarted(ID1, "1.0");
-  BootstrapMonitor.checkAddonInstalled(ID2, "1.0");
-  BootstrapMonitor.checkAddonStarted(ID2, "1.0");
+      installAllFiles([do_get_addon("test_bootstrap1_4")], function() {
+        // Needs a restart to complete this so the old version stays running
+        BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+        BootstrapMonitor.checkAddonStarted(ID1, "1.0");
+
+        AddonManager.getAddonByID(ID1, callback_soon(function(b1) {
+          Assert.notEqual(b1, null);
+          Assert.equal(b1.version, "1.0");
+          Assert.ok(b1.isActive);
+          Assert.ok(!b1.isSystem);
+          Assert.ok(hasFlag(b1.pendingOperations, AddonManager.PENDING_UPGRADE));
+
+          restartManager();
+
+          BootstrapMonitor.checkAddonNotInstalled(ID1);
+          Assert.equal(getUninstallReason(), ADDON_UPGRADE);
+          Assert.equal(getUninstallNewVersion(), 4);
+          BootstrapMonitor.checkAddonNotStarted(ID1);
+
+          AddonManager.getAddonByID(ID1, function(b1_2) {
+            Assert.notEqual(b1_2, null);
+            Assert.equal(b1_2.version, "4.0");
+            Assert.ok(b1_2.isActive);
+            Assert.ok(!b1_2.isSystem);
+            Assert.equal(b1_2.pendingOperations, AddonManager.PENDING_NONE);
 
-  await promiseRestartManager();
+            do_check_bootstrappedPref(run_test_26);
+          });
+        }));
+      });
+  });
+  installAllFiles([do_get_addon("test_bootstrap1_1")], function test_25_installed() {
+    info("test 25 install done");
+  });
+}
 
-  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
-  BootstrapMonitor.checkAddonStarted(ID1, "1.0");
-  BootstrapMonitor.checkAddonInstalled(ID2, "1.0");
-  BootstrapMonitor.checkAddonStarted(ID2, "1.0");
+// Tests that updating from a normal add-on to a bootstrappable add-on calls
+// the install method
+function run_test_26() {
+  installAllFiles([do_get_addon("test_bootstrap1_1")], function() {
+    // Needs a restart to complete this
+    BootstrapMonitor.checkAddonNotInstalled(ID1);
+    BootstrapMonitor.checkAddonNotStarted(ID1);
 
-  await promiseShutdownManager();
+    AddonManager.getAddonByID(ID1, callback_soon(function(b1) {
+      Assert.notEqual(b1, null);
+      Assert.equal(b1.version, "4.0");
+      Assert.ok(b1.isActive);
+      Assert.ok(!b1.isSystem);
+      Assert.ok(hasFlag(b1.pendingOperations, AddonManager.PENDING_UPGRADE));
+
+      restartManager();
 
-  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
-  BootstrapMonitor.checkAddonNotStarted(ID1);
-  BootstrapMonitor.checkAddonInstalled(ID2, "1.0");
-  BootstrapMonitor.checkAddonNotStarted(ID2);
+      BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+      Assert.equal(getInstallReason(), ADDON_DOWNGRADE);
+      Assert.equal(getInstallOldVersion(), 4);
+      BootstrapMonitor.checkAddonStarted(ID1, "1.0");
+
+      AddonManager.getAddonByID(ID1, function(b1_2) {
+        Assert.notEqual(b1_2, null);
+        Assert.equal(b1_2.version, "1.0");
+        Assert.ok(b1_2.isActive);
+        Assert.ok(!b1_2.isSystem);
+        Assert.equal(b1_2.pendingOperations, AddonManager.PENDING_NONE);
+
+        do_check_bootstrappedPref(run_test_27);
+      });
+    }));
+  });
+}
 
-  // Break the JSON.
-  let data = aomStartup.readStartupData();
-  data["app-profile"].addons[ID1].path += "foo";
+// Tests that updating from a bootstrappable add-on to a normal add-on while
+// disabled calls the uninstall method
+function run_test_27() {
+  AddonManager.getAddonByID(ID1, function(b1) {
+    Assert.notEqual(b1, null);
+    b1.userDisabled = true;
+    Assert.equal(b1.version, "1.0");
+    Assert.ok(!b1.isActive);
+    Assert.equal(b1.pendingOperations, AddonManager.PENDING_NONE);
+    BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+    BootstrapMonitor.checkAddonNotStarted(ID1);
+
+    BootstrapMonitor.restartfulIds.add(ID1);
+
+    installAllFiles([do_get_addon("test_bootstrap1_4")], function() {
+      // Updating disabled things happens immediately
+      BootstrapMonitor.checkAddonNotInstalled(ID1);
+      Assert.equal(getUninstallReason(), ADDON_UPGRADE);
+      Assert.equal(getUninstallNewVersion(), 4);
+      BootstrapMonitor.checkAddonNotStarted(ID1);
+
+      AddonManager.getAddonByID(ID1, callback_soon(function(b1_2) {
+        Assert.notEqual(b1_2, null);
+        Assert.equal(b1_2.version, "4.0");
+        Assert.ok(!b1_2.isActive);
+        Assert.equal(b1_2.pendingOperations, AddonManager.PENDING_NONE);
+
+        restartManager();
+
+        BootstrapMonitor.checkAddonNotInstalled(ID1);
+        BootstrapMonitor.checkAddonNotStarted(ID1);
 
-  await OS.File.writeAtomic(gAddonStartup.path,
-                            new TextEncoder().encode(JSON.stringify(data)),
-                            {compression: "lz4"});
+        AddonManager.getAddonByID(ID1, function(b1_3) {
+          Assert.notEqual(b1_3, null);
+          Assert.equal(b1_3.version, "4.0");
+          Assert.ok(!b1_3.isActive);
+          Assert.equal(b1_3.pendingOperations, AddonManager.PENDING_NONE);
 
-  await promiseStartupManager(false);
+          do_check_bootstrappedPref(run_test_28);
+        });
+      }));
+    });
+  });
+}
+
+// Tests that updating from a normal add-on to a bootstrappable add-on when
+// disabled calls the install method but not the startup method
+function run_test_28() {
+  installAllFiles([do_get_addon("test_bootstrap1_1")], function() {
+   executeSoon(function bootstrap_disabled_downgrade_check() {
+    // Doesn't need a restart to complete this
+    BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+    Assert.equal(getInstallReason(), ADDON_DOWNGRADE);
+    Assert.equal(getInstallOldVersion(), 4);
+    BootstrapMonitor.checkAddonNotStarted(ID1);
 
-  BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
-  BootstrapMonitor.checkAddonStarted(ID1, "1.0");
-  BootstrapMonitor.checkAddonInstalled(ID2, "1.0");
-  BootstrapMonitor.checkAddonStarted(ID2, "1.0");
-});
+    AddonManager.getAddonByID(ID1, callback_soon(function(b1) {
+      Assert.notEqual(b1, null);
+      Assert.equal(b1.version, "1.0");
+      Assert.ok(!b1.isActive);
+      Assert.ok(b1.userDisabled);
+      Assert.equal(b1.pendingOperations, AddonManager.PENDING_NONE);
+
+      restartManager();
+
+      BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+      BootstrapMonitor.checkAddonNotStarted(ID1);
+
+      AddonManager.getAddonByID(ID1, function(b1_2) {
+        Assert.notEqual(b1_2, null);
+        Assert.ok(b1_2.userDisabled);
+        b1_2.userDisabled = false;
+        Assert.equal(b1_2.version, "1.0");
+        Assert.ok(b1_2.isActive);
+        Assert.ok(!b1_2.isSystem);
+        Assert.equal(b1_2.pendingOperations, AddonManager.PENDING_NONE);
+        BootstrapMonitor.checkAddonInstalled(ID1, "1.0");
+        BootstrapMonitor.checkAddonStarted(ID1, "1.0");
+
+        do_check_bootstrappedPref(do_test_finished);
+      });
+    }));
+   });
+  });
+}
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug384052.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug384052.js
@@ -1,32 +1,36 @@
 const CLASS_ID = Components.ID("{12345678-1234-1234-1234-123456789abc}");
 const CONTRACT_ID = "@mozilla.org/test-parameter-source;1";
 
-var testserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+// Get and create the HTTP server.
+ChromeUtils.import("resource://testing-common/httpd.js");
+var testserver = new HttpServer();
+testserver.start(-1);
+gPort = testserver.identity.primaryPort;
 
-var gTestURL = "http://example.com/update.json?itemID=%ITEM_ID%&custom1=%CUSTOM1%&custom2=%CUSTOM2%";
+var gTestURL = "http://127.0.0.1:" + gPort + "/update.json?itemID=%ITEM_ID%&custom1=%CUSTOM1%&custom2=%CUSTOM2%";
 var gExpectedQuery = "itemID=test@mozilla.org&custom1=custom_parameter_1&custom2=custom_parameter_2";
 var gSeenExpectedURL = false;
 
-var gComponentRegistrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
-var gCategoryManager = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
+var gComponentRegistrar = Components.manager.QueryInterface(AM_Ci.nsIComponentRegistrar);
+var gCategoryManager = AM_Cc["@mozilla.org/categorymanager;1"].getService(AM_Ci.nsICategoryManager);
 
 // Factory for our parameter handler
 var paramHandlerFactory = {
   QueryInterface(iid) {
-    if (iid.equals(Ci.nsIFactory) || iid.equals(Ci.nsISupports))
+    if (iid.equals(AM_Ci.nsIFactory) || iid.equals(AM_Ci.nsISupports))
       return this;
 
     throw Cr.NS_ERROR_NO_INTERFACE;
   },
 
   createInstance(outer, iid) {
-    var bag = Cc["@mozilla.org/hash-property-bag;1"].
-              createInstance(Ci.nsIWritablePropertyBag);
+    var bag = AM_Cc["@mozilla.org/hash-property-bag;1"].
+              createInstance(AM_Ci.nsIWritablePropertyBag);
     bag.setProperty("CUSTOM1", "custom_parameter_1");
     bag.setProperty("CUSTOM2", "custom_parameter_2");
     return bag.QueryInterface(iid);
   }
 };
 
 function initTest() {
   do_test_pending();
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug393285.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug393285.js
@@ -1,20 +1,23 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
 const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul";
 
+ChromeUtils.import("resource://testing-common/httpd.js");
 ChromeUtils.import("resource://testing-common/MockRegistrar.jsm");
-var testserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+var testserver = new HttpServer();
+testserver.start(-1);
 gPort = testserver.identity.primaryPort;
 
-testserver.registerDirectory("/data/", do_get_file("data"));
+// register static files with server and interpolate port numbers in them
+mapFile("/data/test_bug393285.xml", testserver);
 
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
 
 var addonIDs = ["test_bug393285_1@tests.mozilla.org",
                 "test_bug393285_2@tests.mozilla.org",
                 "test_bug393285_3a@tests.mozilla.org",
                 "test_bug393285_3b@tests.mozilla.org",
@@ -71,17 +74,17 @@ function load_blocklist(aFile, aCallback
                              gPort + "/data/" + aFile);
   var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
                   getService(Ci.nsITimerCallback);
   blocklist.notify(null);
 }
 
 
 function end_test() {
-  do_test_finished();
+  testserver.stop(do_test_finished);
 }
 
 function run_test() {
   do_test_pending();
 
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
 
   writeInstallRDFForExtension({
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug406118.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug406118.js
@@ -5,21 +5,24 @@
 
 var addonIDs = ["test_bug393285_1@tests.mozilla.org",
                 "test_bug393285_2@tests.mozilla.org",
                 "test_bug393285_3a@tests.mozilla.org",
                 "test_bug393285_4@tests.mozilla.org"];
 
 const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul";
 
+ChromeUtils.import("resource://testing-common/httpd.js");
 ChromeUtils.import("resource://testing-common/MockRegistrar.jsm");
-var testserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+var testserver = new HttpServer();
+testserver.start(-1);
 gPort = testserver.identity.primaryPort;
 
-testserver.registerDirectory("/data/", do_get_file("data"));
+// register static files with server and interpolate port numbers in them
+mapFile("/data/test_bug393285.xml", testserver);
 
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
 
 // A window watcher to deal with the blocklist UI dialog.
 var WindowWatcher = {
   openWindow(parent, url, name, features, args) {
     // Should be called to list the newly blocklisted items
@@ -59,17 +62,17 @@ function load_blocklist(aFile, aCallback
                              gPort + "/data/" + aFile);
   var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
                   getService(Ci.nsITimerCallback);
   blocklist.notify(null);
 }
 
 
 function end_test() {
-  do_test_finished();
+  testserver.stop(do_test_finished);
 }
 
 function run_test() {
   do_test_pending();
 
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
 
   writeInstallRDFForExtension({
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug430120.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug430120.js
@@ -67,17 +67,17 @@ function pathHandler(metadata, response)
   }
   Assert.equal(metadata.queryString,
                "xpcshell@tests.mozilla.org&1&XPCShell&1&" +
                gAppInfo.appBuildID + "&" +
                "XPCShell_" + ABI + "&locale&updatechannel&" +
                gOSVersion + "&1.9&distribution&distribution-version");
   gBlocklist.observe(null, "quit-application", "");
   gBlocklist.observe(null, "xpcom-shutdown", "");
-  do_test_finished();
+  testserver.stop(do_test_finished);
 }
 
 function run_test() {
   var osVersion;
   try {
     osVersion = Services.sysinfo.getProperty("name") + " " + Services.sysinfo.getProperty("version");
     if (osVersion) {
       try {
@@ -86,41 +86,43 @@ function run_test() {
       }
       gOSVersion = encodeURIComponent(osVersion);
     }
   } catch (e) {
   }
 
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
 
-  testserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+  testserver = new HttpServer();
   testserver.registerPathHandler("/1", failHandler);
   testserver.registerPathHandler("/2", pathHandler);
+  testserver.start(-1);
+  gPort = testserver.identity.primaryPort;
 
   // Initialise the blocklist service
   gBlocklist = Services.blocklist.QueryInterface(Ci.nsIObserver);
   gBlocklist.observe(null, "profile-after-change", "");
 
   Assert.ok(timerService.hasTimer(BLOCKLIST_TIMER));
 
   do_test_pending();
 
   // This should have no effect as the blocklist is disabled
-  Services.prefs.setCharPref(PREF_BLOCKLIST_URL, "http://example.com/1");
+  Services.prefs.setCharPref(PREF_BLOCKLIST_URL, "http://localhost:" + gPort + "/1");
   Services.prefs.setBoolPref(PREF_BLOCKLIST_ENABLED, false);
   timerService.fireTimer(BLOCKLIST_TIMER);
 
   // Some values have to be on the default branch to work
   var defaults = Services.prefs.QueryInterface(Ci.nsIPrefService)
                        .getDefaultBranch(null);
   defaults.setCharPref(PREF_APP_UPDATE_CHANNEL, "updatechannel");
   defaults.setCharPref(PREF_APP_DISTRIBUTION, "distribution");
   defaults.setCharPref(PREF_APP_DISTRIBUTION_VERSION, "distribution-version");
   Services.locale.setRequestedLocales(["locale"]);
 
   // This should correctly escape everything
-  Services.prefs.setCharPref(PREF_BLOCKLIST_URL, "http://example.com/2?" +
+  Services.prefs.setCharPref(PREF_BLOCKLIST_URL, "http://localhost:" + gPort + "/2?" +
                      "%APP_ID%&%APP_VERSION%&%PRODUCT%&%VERSION%&%BUILD_ID%&" +
                      "%BUILD_TARGET%&%LOCALE%&%CHANNEL%&" +
                      "%OS_VERSION%&%PLATFORM_VERSION%&%DISTRIBUTION%&%DISTRIBUTION_VERSION%");
   Services.prefs.setBoolPref(PREF_BLOCKLIST_ENABLED, true);
   timerService.fireTimer(BLOCKLIST_TIMER);
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug455906.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug455906.js
@@ -1,26 +1,33 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
 const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul";
 
 ChromeUtils.import("resource://gre/modules/ExtensionUtils.jsm");
+ChromeUtils.import("resource://testing-common/httpd.js");
 ChromeUtils.import("resource://testing-common/MockRegistrar.jsm");
-var gTestserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+var gTestserver = new HttpServer();
+gTestserver.start(-1);
+gPort = gTestserver.identity.primaryPort;
 
 const {promiseObserved} = ExtensionUtils;
 
-gTestserver.registerDirectory("/data/", do_get_file("data"));
+// register static files with server and interpolate port numbers in them
+mapFile("/data/bug455906_warn.xml", gTestserver);
+mapFile("/data/bug455906_start.xml", gTestserver);
+mapFile("/data/bug455906_block.xml", gTestserver);
+mapFile("/data/bug455906_empty.xml", gTestserver);
 
 // Workaround for Bug 658720 - URL formatter can leak during xpcshell tests
 const PREF_BLOCKLIST_ITEM_URL = "extensions.blocklist.itemURL";
-Services.prefs.setCharPref(PREF_BLOCKLIST_ITEM_URL, "http://example.com/blocklist/%blockID%");
+Services.prefs.setCharPref(PREF_BLOCKLIST_ITEM_URL, "http://localhost:" + gPort + "/blocklist/%blockID%");
 
 var ADDONS = [{
   // Tests how the blocklist affects a disabled add-on
   id: "test_bug455906_1@tests.mozilla.org",
   name: "Bug 455906 Addon Test 1",
   version: "5",
   appVersion: "3"
 }, {
@@ -183,17 +190,17 @@ function create_addon(addon) {
   stream.init(target,
               FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | FileUtils.MODE_TRUNCATE,
               FileUtils.PERMS_FILE, 0);
   stream.write(installrdf, installrdf.length);
   stream.close();
 }
 
 function load_blocklist(file) {
-  Services.prefs.setCharPref("extensions.blocklist.url", "http://example.com/data/" + file);
+  Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" + gPort + "/data/" + file);
   var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
                   getService(Ci.nsITimerCallback);
   blocklist.notify(null);
 }
 
 function check_addon_state(addon) {
   return addon.userDisabled + "," + addon.softDisabled + "," + addon.appDisabled;
 }
@@ -496,10 +503,10 @@ function check_test_pt4() {
     Assert.equal(check_plugin_state(PLUGINS[3]), "true,false");
     Assert.equal(check_plugin_state(PLUGINS[4]), "false,false");
 
     finish();
   });
 }
 
 function finish() {
-  do_test_finished();
+  gTestserver.stop(do_test_finished);
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug587088.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug587088.js
@@ -5,17 +5,17 @@
 // Tests that trying to upgrade or uninstall an extension that has a file locked
 // will roll back the upgrade or uninstall and retry at the next restart
 
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
 
 function run_test() {
   // This is only an issue on windows.
-  if (!("nsIWindowsRegKey" in Ci))
+  if (!("nsIWindowsRegKey" in AM_Ci))
     return;
 
   do_test_pending();
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
 
   startupManager();
   run_test_1();
 }
@@ -79,19 +79,19 @@ function run_test_1() {
     AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
       check_addon(a1, "1.0");
 
       // Lock either install.rdf for unpacked add-ons or the xpi for packed add-ons.
       let uri = a1.getResourceURI("install.rdf");
       if (uri.schemeIs("jar"))
         uri = a1.getResourceURI();
 
-      let fstream = Cc["@mozilla.org/network/file-input-stream;1"].
-                    createInstance(Ci.nsIFileInputStream);
-      fstream.init(uri.QueryInterface(Ci.nsIFileURL).file, -1, 0, 0);
+      let fstream = AM_Cc["@mozilla.org/network/file-input-stream;1"].
+                    createInstance(AM_Ci.nsIFileInputStream);
+      fstream.init(uri.QueryInterface(AM_Ci.nsIFileURL).file, -1, 0, 0);
 
       installAllFiles([do_get_addon("test_bug587088_2")], function() {
 
         check_addon_upgrading(a1);
 
         restartManager();
 
         AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(a1_2) {
@@ -129,19 +129,19 @@ function run_test_2() {
     AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(async function(a1) {
       check_addon(a1, "1.0");
 
       // Lock either install.rdf for unpacked add-ons or the xpi for packed add-ons.
       let uri = a1.getResourceURI("install.rdf");
       if (uri.schemeIs("jar"))
         uri = a1.getResourceURI();
 
-      let fstream = Cc["@mozilla.org/network/file-input-stream;1"].
-                    createInstance(Ci.nsIFileInputStream);
-      fstream.init(uri.QueryInterface(Ci.nsIFileURL).file, -1, 0, 0);
+      let fstream = AM_Cc["@mozilla.org/network/file-input-stream;1"].
+                    createInstance(AM_Ci.nsIFileInputStream);
+      fstream.init(uri.QueryInterface(AM_Ci.nsIFileURL).file, -1, 0, 0);
 
       a1.uninstall();
 
       check_addon_uninstalling(a1);
 
       await promiseRestartManager();
 
       AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(async function(a1_2) {
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug596607.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug596607.js
@@ -39,38 +39,38 @@ const addon1Dir = writeInstallRDFForExte
 const addon2Dir = writeInstallRDFForExtension(addon2, gProfD, "addon2");
 const addon3Dir = gProfD.clone();
 addon3Dir.append("addon3@tests.mozilla.org");
 
 let registry;
 
 function run_test() {
   // This test only works where there is a registry.
-  if (!("nsIWindowsRegKey" in Ci))
+  if (!("nsIWindowsRegKey" in AM_Ci))
     return;
 
   registry = new MockRegistry();
   registerCleanupFunction(() => {
     registry.shutdown();
   });
 
   do_test_pending();
 
   run_test_1();
 }
 
 // Tests whether starting a fresh profile with a bad entry works
 function run_test_1() {
-  registry.setValue(Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
+  registry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
                     "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
                     "addon1@tests.mozilla.org", addon1Dir.path);
-  registry.setValue(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
+  registry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
                     "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
                     "addon2@tests.mozilla.org", addon2Dir.path);
-  registry.setValue(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
+  registry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
                     "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
                     "addon3@tests.mozilla.org", addon3Dir.path);
 
   startupManager();
 
   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                "addon2@tests.mozilla.org",
                                "addon3@tests.mozilla.org"], function([a1, a2, a3]) {
@@ -89,17 +89,17 @@ function run_test_1() {
     executeSoon(run_test_2);
   });
 }
 
 // Tests whether removing the bad entry has any effect
 function run_test_2() {
   shutdownManager();
 
-  registry.setValue(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
+  registry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
                     "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
                     "addon3@tests.mozilla.org", addon3Dir.path);
 
   startupManager(false);
 
   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                "addon2@tests.mozilla.org",
                                "addon3@tests.mozilla.org"], function([a1, a2, a3]) {
@@ -118,17 +118,17 @@ function run_test_2() {
     executeSoon(run_test_3);
   });
 }
 
 // Tests adding the bad entry to an existing profile has any effect
 function run_test_3() {
   shutdownManager();
 
-  registry.setValue(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
+  registry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
                     "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
                     "addon3@tests.mozilla.org", null);
 
   startupManager(false);
 
   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                "addon2@tests.mozilla.org",
                                "addon3@tests.mozilla.org"], function([a1, a2, a3]) {
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug619730.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug619730.js
@@ -1,54 +1,60 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
-var gTestserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
-gTestserver.registerDirectory("/data/", do_get_file("data"));
+// Tests whether
+ChromeUtils.import("resource://testing-common/httpd.js");
+
+var gTestserver = new HttpServer();
+gTestserver.start(-1);
+gPort = gTestserver.identity.primaryPort;
+mapFile("/data/test_bug619730.xml", gTestserver);
 
 function load_blocklist(file, aCallback) {
   Services.obs.addObserver(function observer() {
     Services.obs.removeObserver(observer, "blocklist-updated");
 
     executeSoon(aCallback);
   }, "blocklist-updated");
 
-  Services.prefs.setCharPref("extensions.blocklist.url", "http://example.com/data/" + file);
+  Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" +
+                             gPort + "/data/" + file);
   var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
                   getService(Ci.nsITimerCallback);
   blocklist.notify(null);
 }
 
 var gSawGFX = false;
 var gSawTest = false;
 
 // Performs the initial setup
 function run_test() {
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "3", "8");
   startupManager();
 
   do_test_pending();
 
   Services.obs.addObserver(function(aSubject, aTopic, aData) {
-    Assert.ok(aSubject instanceof Ci.nsIDOMElement);
+    Assert.ok(aSubject instanceof AM_Ci.nsIDOMElement);
     Assert.equal(aSubject.getAttribute("testattr"), "GFX");
     Assert.equal(aSubject.childNodes.length, 2);
     gSawGFX = true;
   }, "blocklist-data-gfxItems");
 
   Services.obs.addObserver(function(aSubject, aTopic, aData) {
-    Assert.ok(aSubject instanceof Ci.nsIDOMElement);
+    Assert.ok(aSubject instanceof AM_Ci.nsIDOMElement);
     Assert.equal(aSubject.getAttribute("testattr"), "FOO");
     Assert.equal(aSubject.childNodes.length, 3);
     gSawTest = true;
   }, "blocklist-data-testItems");
 
   Services.obs.addObserver(function(aSubject, aTopic, aData) {
     Assert.ok(gSawGFX);
     Assert.ok(gSawTest);
   }, "blocklist-data-fooItems");
 
   // Need to wait for the blocklist to load; Bad Things happen if the test harness
   // shuts down AddonManager before the blocklist service is done telling it about
   // changes
-  load_blocklist("test_bug619730.xml", () => do_test_finished());
+  load_blocklist("test_bug619730.xml", () => gTestserver.stop(do_test_finished));
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug620837.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug620837.js
@@ -10,18 +10,18 @@ const PREF_BLOCKLIST_PINGCOUNTVERSION = 
 
 const SECONDS_IN_DAY = 60 * 60 * 24;
 
 var gExpectedQueryString = null;
 var gNextTest = null;
 var gTestserver = null;
 
 function notify_blocklist() {
-  var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
-                  getService(Ci.nsITimerCallback);
+  var blocklist = AM_Cc["@mozilla.org/extensions/blocklist;1"].
+                  getService(AM_Ci.nsITimerCallback);
   blocklist.notify(null);
 }
 
 function pathHandler(metadata, response) {
   Assert.equal(metadata.queryString, gExpectedQueryString);
   gNextTest();
 }
 
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug655254.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug655254.js
@@ -8,42 +8,45 @@
 // The test extension uses an insecure update url.
 Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false);
 // Enable loading extensions from the user and system scopes
 Services.prefs.setIntPref("extensions.enabledScopes",
                           AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_USER);
 
 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2", "1.9.2");
 
-var testserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
-testserver.registerDirectory("/data/", do_get_file("data"));
+ChromeUtils.import("resource://testing-common/httpd.js");
+var testserver = new HttpServer();
+testserver.start(-1);
+gPort = testserver.identity.primaryPort;
+mapFile("/data/test_bug655254.json", testserver);
 
 var userDir = gProfD.clone();
 userDir.append("extensions2");
 userDir.append(gAppInfo.ID);
 
 var dirProvider = {
   getFile(aProp, aPersistent) {
     aPersistent.value = false;
     if (aProp == "XREUSysExt")
       return userDir.parent;
     return null;
   },
 
-  QueryInterface: XPCOMUtils.generateQI([Ci.nsIDirectoryServiceProvider,
-                                         Ci.nsISupports])
+  QueryInterface: XPCOMUtils.generateQI([AM_Ci.nsIDirectoryServiceProvider,
+                                         AM_Ci.nsISupports])
 };
 Services.dirsvc.registerProvider(dirProvider);
 
 var addon1 = {
   id: "addon1@tests.mozilla.org",
   version: "1.0",
   name: "Test 1",
   bootstrap: true,
-  updateURL: "http://example.com/data/test_bug655254.json",
+  updateURL: "http://localhost:" + gPort + "/data/test_bug655254.json",
   targetApplications: [{
     id: "xpcshell@tests.mozilla.org",
     minVersion: "1",
     maxVersion: "1"
   }]
 };
 
 const ADDONS = [
@@ -78,17 +81,17 @@ const XPIS = ADDONS.map(addon => AddonTe
 
 // Set up the profile
 function run_test() {
   do_test_pending();
   run_test_1();
 }
 
 function end_test() {
-  do_test_finished();
+  testserver.stop(do_test_finished);
 }
 
 async function run_test_1() {
   var time = Date.now();
   var dir = writeInstallRDFForExtension(addon1, userDir);
   setExtensionModifiedTime(dir, time);
 
   manuallyInstall(XPIS[0], userDir, "addon2@tests.mozilla.org");
--- a/toolkit/mozapps/extensions/test/xpcshell/test_cacheflush.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_cacheflush.js
@@ -11,17 +11,17 @@ var CacheFlushObserver = {
   observe(aSubject, aTopic, aData) {
     if (aTopic != "flush-cache-entry")
       return;
     // Ignore flushes triggered by the fake cert DB
     if (aData == "cert-override")
       return;
 
     ok(gExpectedFile != null);
-    ok(aSubject instanceof Ci.nsIFile);
+    ok(aSubject instanceof AM_Ci.nsIFile);
     equal(aSubject.path, gExpectedFile.path);
     gCacheFlushCount++;
   }
 };
 
 const ADDONS = [
   {
     id: "addon2@tests.mozilla.org",
--- a/toolkit/mozapps/extensions/test/xpcshell/test_childprocess.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_childprocess.js
@@ -4,17 +4,17 @@
 
 // This verifies that the AddonManager refuses to load in child processes.
 
 function run_test() {
   // Already loaded the module by head_addons.js. Need to unload this again, so
   // that overriding the app-info and re-importing the module works.
   Cu.unload("resource://gre/modules/AddonManager.jsm");
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
-  gAppInfo.processType = Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT;
+  gAppInfo.processType = AM_Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT;
   try {
     ChromeUtils.import("resource://gre/modules/AddonManager.jsm");
     do_throw("AddonManager should have refused to load");
   } catch (ex) {
     info(ex.message);
     Assert.ok(!!ex.message);
   }
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_corrupt.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_corrupt.js
@@ -246,17 +246,17 @@ add_task(async function test_after_resta
   await promiseShutdownManager();
 });
 
 add_task(async function test_after_corruption() {
   // Shutdown and replace the database with a corrupt file (a directory
   // serves this purpose). On startup the add-ons manager won't rebuild
   // because there is a file there still.
   gExtensionsJSON.remove(true);
-  gExtensionsJSON.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
+  gExtensionsJSON.create(AM_Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
 
   await promiseStartupManager(false);
 
   await new Promise(resolve => {
     Services.obs.addObserver(function listener() {
       Services.obs.removeObserver(listener, "xpi-database-loaded");
       resolve();
     }, "xpi-database-loaded");
--- a/toolkit/mozapps/extensions/test/xpcshell/test_delay_update.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_delay_update.js
@@ -2,43 +2,47 @@
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // This verifies that delaying an update works
 
 // The test extension uses an insecure update url.
 Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false);
 
+ChromeUtils.import("resource://testing-common/httpd.js");
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
 
 const IGNORE_ID = "test_delay_update_ignore@tests.mozilla.org";
 const COMPLETE_ID = "test_delay_update_complete@tests.mozilla.org";
 const DEFER_ID = "test_delay_update_defer@tests.mozilla.org";
 
 const TEST_IGNORE_PREF = "delaytest.ignore";
 
 // Note that we would normally use BootstrapMonitor but it currently requires
 // the objects in `data` to be serializable, and we need a real reference to the
 // `instanceID` symbol to test.
 
 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "42");
 
 // Create and configure the HTTP server.
-var testserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
-testserver.registerDirectory("/data/", do_get_file("data"));
+let testserver = createHttpServer();
+gPort = testserver.identity.primaryPort;
+mapFile("/data/test_delay_updates_complete_legacy.json", testserver);
+mapFile("/data/test_delay_updates_ignore_legacy.json", testserver);
+mapFile("/data/test_delay_updates_defer_legacy.json", testserver);
 testserver.registerDirectory("/addons/", do_get_file("addons"));
 
 function createIgnoreAddon() {
   writeInstallRDFToDir({
     id: IGNORE_ID,
     version: "1.0",
     bootstrap: true,
     unpack: true,
-    updateURL: `http://example.com/data/test_delay_updates_ignore_legacy.json`,
+    updateURL: `http://localhost:${gPort}/data/test_delay_updates_ignore_legacy.json`,
     targetApplications: [{
       id: "xpcshell@tests.mozilla.org",
       minVersion: "1",
       maxVersion: "1"
     }],
     name: "Test Delay Update Ignore",
   }, profileDir, IGNORE_ID, "bootstrap.js");
 
@@ -49,17 +53,17 @@ function createIgnoreAddon() {
 }
 
 function createCompleteAddon() {
   writeInstallRDFToDir({
     id: COMPLETE_ID,
     version: "1.0",
     bootstrap: true,
     unpack: true,
-    updateURL: `http://example.com/data/test_delay_updates_complete_legacy.json`,
+    updateURL: `http://localhost:${gPort}/data/test_delay_updates_complete_legacy.json`,
     targetApplications: [{
       id: "xpcshell@tests.mozilla.org",
       minVersion: "1",
       maxVersion: "1"
     }],
     name: "Test Delay Update Complete",
   }, profileDir, COMPLETE_ID, "bootstrap.js");
 
@@ -70,17 +74,17 @@ function createCompleteAddon() {
 }
 
 function createDeferAddon() {
   writeInstallRDFToDir({
     id: DEFER_ID,
     version: "1.0",
     bootstrap: true,
     unpack: true,
-    updateURL: `http://example.com/data/test_delay_updates_defer_legacy.json`,
+    updateURL: `http://localhost:${gPort}/data/test_delay_updates_defer_legacy.json`,
     targetApplications: [{
       id: "xpcshell@tests.mozilla.org",
       minVersion: "1",
       maxVersion: "1"
     }],
     name: "Test Delay Update Defer",
   }, profileDir, DEFER_ID, "bootstrap.js");
 
--- a/toolkit/mozapps/extensions/test/xpcshell/test_delay_update_webextension.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_delay_update_webextension.js
@@ -28,34 +28,38 @@ const stageDir = profileDir.clone();
 stageDir.append("staged");
 
 const IGNORE_ID = "test_delay_update_ignore_webext@tests.mozilla.org";
 const COMPLETE_ID = "test_delay_update_complete_webext@tests.mozilla.org";
 const DEFER_ID = "test_delay_update_defer_webext@tests.mozilla.org";
 const NOUPDATE_ID = "test_no_update_webext@tests.mozilla.org";
 
 // Create and configure the HTTP server.
-var testserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
-testserver.registerDirectory("/data/", do_get_file("data"));
+let testserver = createHttpServer();
+gPort = testserver.identity.primaryPort;
+mapFile("/data/test_delay_updates_complete.json", testserver);
+mapFile("/data/test_delay_updates_ignore.json", testserver);
+mapFile("/data/test_delay_updates_defer.json", testserver);
+mapFile("/data/test_no_update.json", testserver);
 testserver.registerDirectory("/addons/", do_get_file("addons"));
 
 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "42", "42");
 
 // add-on registers upgrade listener, and ignores update.
 add_task(async function delay_updates_ignore() {
   startupManager();
 
   let extension = ExtensionTestUtils.loadExtension({
     useAddonManager: "permanent",
     manifest: {
       "version": "1.0",
       "applications": {
         "gecko": {
           "id": IGNORE_ID,
-          "update_url": `http://example.com/data/test_delay_updates_ignore.json`,
+          "update_url": `http://localhost:${gPort}/data/test_delay_updates_ignore.json`,
         },
       },
     },
     background() {
       browser.runtime.onUpdateAvailable.addListener(details => {
         if (details) {
           if (details.version) {
             // This should be the version of the pending update.
@@ -124,17 +128,17 @@ add_task(async function delay_updates_co
 
   let extension = ExtensionTestUtils.loadExtension({
     useAddonManager: "permanent",
     manifest: {
       "version": "1.0",
       "applications": {
         "gecko": {
           "id": COMPLETE_ID,
-          "update_url": `http://example.com/data/test_delay_updates_complete.json`,
+          "update_url": `http://localhost:${gPort}/data/test_delay_updates_complete.json`,
         },
       },
     },
     background() {
       browser.runtime.onUpdateAvailable.addListener(details => {
         browser.test.notifyPass("reload");
         browser.runtime.reload();
       });
@@ -187,17 +191,17 @@ add_task(async function delay_updates_de
 
   let extension = ExtensionTestUtils.loadExtension({
     useAddonManager: "permanent",
     manifest: {
       "version": "1.0",
       "applications": {
         "gecko": {
           "id": DEFER_ID,
-          "update_url": `http://example.com/data/test_delay_updates_defer.json`,
+          "update_url": `http://localhost:${gPort}/data/test_delay_updates_defer.json`,
         },
       },
     },
     background() {
       browser.runtime.onUpdateAvailable.addListener(details => {
         // Upgrade will only proceed when "allow" message received.
         browser.test.onMessage.addListener(msg => {
           if (msg == "allow") {
@@ -283,17 +287,17 @@ add_task(async function runtime_reload()
 
   let extension = ExtensionTestUtils.loadExtension({
     useAddonManager: "permanent",
     manifest: {
       "version": "1.0",
       "applications": {
         "gecko": {
           "id": NOUPDATE_ID,
-          "update_url": `http://example.com/data/test_no_update.json`,
+          "update_url": `http://localhost:${gPort}/data/test_no_update.json`,
         },
       },
     },
     background() {
       browser.test.onMessage.addListener(msg => {
         if (msg == "reload") {
           browser.runtime.reload();
         } else {
--- a/toolkit/mozapps/extensions/test/xpcshell/test_filepointer.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_filepointer.js
@@ -38,17 +38,17 @@ var addon2 = {
     id: "xpcshell@tests.mozilla.org",
     minVersion: "1",
     maxVersion: "1"
   }]
 };
 
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
-profileDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755);
+profileDir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0o755);
 
 const sourceDir = gProfD.clone();
 sourceDir.append("source");
 
 var testserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
 testserver.registerDirectory("/data/", do_get_file("data"));
 testserver.registerDirectory("/addons/", do_get_file("addons"));
 gPort = testserver.identity.primaryPort;
@@ -84,17 +84,17 @@ add_task(async function test_new_pointer
   await promiseWriteInstallRDFForExtension(addon1, sourceDir);
   await promiseWritePointer(addon1.id);
   await promiseStartupManager();
 
   let addon = await AddonManager.getAddonByID(addon1.id);
   notEqual(addon, null);
   equal(addon.version, "1.0");
 
-  let file = addon.getResourceURI().QueryInterface(Ci.nsIFileURL).file;
+  let file = addon.getResourceURI().QueryInterface(AM_Ci.nsIFileURL).file;
   equal(file.parent.path, sourceDir.path);
 
   let rootUri = do_get_addon_root_uri(sourceDir, addon1.id);
   let uri = addon.getResourceURI("/");
   equal(uri.spec, rootUri);
   uri = addon.getResourceURI("install.rdf");
   equal(uri.spec, rootUri + "install.rdf");
 
@@ -146,17 +146,17 @@ add_task(async function test_addon_over_
   });
 
   await promiseRestartManager();
 
   let addon = await AddonManager.getAddonByID(addon1.id);
   notEqual(addon, null);
   equal(addon.version, "2.0");
 
-  let file = addon.getResourceURI().QueryInterface(Ci.nsIFileURL).file;
+  let file = addon.getResourceURI().QueryInterface(AM_Ci.nsIFileURL).file;
   equal(file.parent.path, profileDir.path);
 
   let rootUri = do_get_addon_root_uri(profileDir, addon1.id);
   let uri = addon.getResourceURI("/");
   equal(uri.spec, rootUri);
   uri = addon.getResourceURI("install.rdf");
   equal(uri.spec, rootUri + "install.rdf");
 
@@ -333,17 +333,17 @@ add_task(async function test_remove_poin
 add_task(async function test_new_relative_pointer() {
   writeInstallRDFForExtension(addon1, sourceDir);
   await promiseWriteRelativePointer(addon1.id);
   await promiseRestartManager();
 
   let addon = await AddonManager.getAddonByID(addon1.id);
   equal(addon.version, "1.0");
 
-  let file = addon.getResourceURI().QueryInterface(Ci.nsIFileURL).file;
+  let file = addon.getResourceURI().QueryInterface(AM_Ci.nsIFileURL).file;
   equal(file.parent.path, sourceDir.path);
 
   let rootUri = do_get_addon_root_uri(sourceDir, addon1.id);
   let uri = addon.getResourceURI("/");
   equal(uri.spec, rootUri);
   uri = addon.getResourceURI("install.rdf");
   equal(uri.spec, rootUri + "install.rdf");
 
--- a/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_Device.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_Device.js
@@ -2,19 +2,22 @@
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // This should eventually be moved to head_addons.js
 // Test whether a machine which differs only on device ID, but otherwise
 // exactly matches the blacklist entry, is not blocked.
 // Uses test_gfxBlacklist.xml
 
-var gTestserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+ChromeUtils.import("resource://testing-common/httpd.js");
+
+var gTestserver = new HttpServer();
+gTestserver.start(-1);
 gPort = gTestserver.identity.primaryPort;
-gTestserver.registerDirectory("/data/", do_get_file("data"));
+mapFile("/data/test_gfxBlacklist.xml", gTestserver);
 
 function load_blocklist(file) {
   Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" +
                              gPort + "/data/" + file);
   var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
                   getService(Ci.nsITimerCallback);
   blocklist.notify(null);
 }
@@ -66,17 +69,17 @@ function run_test() {
     Assert.equal(status, Ci.nsIGfxInfo.FEATURE_STATUS_OK);
 
     status = gfxInfo.getFeatureStatus(Ci.nsIGfxInfo.FEATURE_DIRECT3D_9_LAYERS);
     Assert.equal(status, Ci.nsIGfxInfo.FEATURE_STATUS_OK);
 
     status = gfxInfo.getFeatureStatus(Ci.nsIGfxInfo.FEATURE_CANVAS2D_ACCELERATION);
     Assert.equal(status, Ci.nsIGfxInfo.FEATURE_STATUS_OK);
 
-    do_test_finished();
+    gTestserver.stop(do_test_finished);
   }
 
   Services.obs.addObserver(function(aSubject, aTopic, aData) {
     // If we wait until after we go through the event loop, gfxInfo is sure to
     // have processed the gfxItems event.
     executeSoon(checkBlacklist);
   }, "blocklist-data-gfxItems");
 
--- a/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_DriverNew.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_DriverNew.js
@@ -2,19 +2,22 @@
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // This should eventually be moved to head_addons.js
 // Test whether a new-enough driver bypasses the blacklist, even if the rest of
 // the attributes match the blacklist entry.
 // Uses test_gfxBlacklist.xml
 
-var gTestserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+ChromeUtils.import("resource://testing-common/httpd.js");
+
+var gTestserver = new HttpServer();
+gTestserver.start(-1);
 gPort = gTestserver.identity.primaryPort;
-gTestserver.registerDirectory("/data/", do_get_file("data"));
+mapFile("/data/test_gfxBlacklist.xml", gTestserver);
 
 function load_blocklist(file) {
   Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" +
                              gPort + "/data/" + file);
   var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
                   getService(Ci.nsITimerCallback);
   blocklist.notify(null);
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_Equal_DriverNew.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_Equal_DriverNew.js
@@ -2,19 +2,22 @@
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // This should eventually be moved to head_addons.js
 // Test whether a machine which is newer than the equal
 // blacklist entry is allowed.
 // Uses test_gfxBlacklist.xml
 
-var gTestserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+ChromeUtils.import("resource://testing-common/httpd.js");
+
+var gTestserver = new HttpServer();
+gTestserver.start(-1);
 gPort = gTestserver.identity.primaryPort;
-gTestserver.registerDirectory("/data/", do_get_file("data"));
+mapFile("/data/test_gfxBlacklist.xml", gTestserver);
 
 function load_blocklist(file) {
   Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" +
                              gPort + "/data/" + file);
   var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
                   getService(Ci.nsITimerCallback);
   blocklist.notify(null);
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_Equal_DriverOld.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_Equal_DriverOld.js
@@ -2,20 +2,22 @@
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // This should eventually be moved to head_addons.js
 // Test whether a machine which is older than the equal
 // blacklist entry is correctly allowed.
 // Uses test_gfxBlacklist.xml
 
-var gTestserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+ChromeUtils.import("resource://testing-common/httpd.js");
 
+var gTestserver = new HttpServer();
+gTestserver.start(-1);
 gPort = gTestserver.identity.primaryPort;
-gTestserver.registerDirectory("/data/", do_get_file("data"));
+mapFile("/data/test_gfxBlacklist.xml", gTestserver);
 
 function load_blocklist(file) {
   Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" +
                              gPort + "/data/" + file);
   var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
                   getService(Ci.nsITimerCallback);
   blocklist.notify(null);
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_Equal_OK.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_Equal_OK.js
@@ -2,19 +2,22 @@
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // This should eventually be moved to head_addons.js
 // Test whether a machine which exactly matches the equal
 // blacklist entry is successfully blocked.
 // Uses test_gfxBlacklist.xml
 
-var gTestserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+ChromeUtils.import("resource://testing-common/httpd.js");
+
+var gTestserver = new HttpServer();
+gTestserver.start(-1);
 gPort = gTestserver.identity.primaryPort;
-gTestserver.registerDirectory("/data/", do_get_file("data"));
+mapFile("/data/test_gfxBlacklist.xml", gTestserver);
 
 function load_blocklist(file) {
   Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" +
                              gPort + "/data/" + file);
   var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
                   getService(Ci.nsITimerCallback);
   blocklist.notify(null);
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_GTE_DriverOld.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_GTE_DriverOld.js
@@ -2,19 +2,22 @@
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // This should eventually be moved to head_addons.js
 // Test whether a machine which is lower than the greater-than-or-equal
 // blacklist entry is allowed.
 // Uses test_gfxBlacklist.xml
 
-var gTestserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+ChromeUtils.import("resource://testing-common/httpd.js");
+
+var gTestserver = new HttpServer();
+gTestserver.start(-1);
 gPort = gTestserver.identity.primaryPort;
-gTestserver.registerDirectory("/data/", do_get_file("data"));
+mapFile("/data/test_gfxBlacklist.xml", gTestserver);
 
 function load_blocklist(file) {
   Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" +
                              gPort + "/data/" + file);
   var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
                   getService(Ci.nsITimerCallback);
   blocklist.notify(null);
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_GTE_OK.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_GTE_OK.js
@@ -2,19 +2,22 @@
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // This should eventually be moved to head_addons.js
 // Test whether a machine which exactly matches the greater-than-or-equal
 // blacklist entry is successfully blocked.
 // Uses test_gfxBlacklist.xml
 
-var gTestserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+ChromeUtils.import("resource://testing-common/httpd.js");
+
+var gTestserver = new HttpServer();
+gTestserver.start(-1);
 gPort = gTestserver.identity.primaryPort;
-gTestserver.registerDirectory("/data/", do_get_file("data"));
+mapFile("/data/test_gfxBlacklist.xml", gTestserver);
 
 function load_blocklist(file) {
   Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" +
                              gPort + "/data/" + file);
   var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
                   getService(Ci.nsITimerCallback);
   blocklist.notify(null);
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_No_Comparison.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_No_Comparison.js
@@ -2,19 +2,22 @@
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // This should eventually be moved to head_addons.js
 // Test whether a machine which exactly matches the blacklist entry is
 // successfully blocked.
 // Uses test_gfxBlacklist.xml
 
-var gTestserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+ChromeUtils.import("resource://testing-common/httpd.js");
+
+var gTestserver = new HttpServer();
+gTestserver.start(-1);
 gPort = gTestserver.identity.primaryPort;
-gTestserver.registerDirectory("/data/", do_get_file("data"));
+mapFile("/data/test_gfxBlacklist.xml", gTestserver);
 
 function load_blocklist(file) {
   Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" +
                              gPort + "/data/" + file);
   var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
                   getService(Ci.nsITimerCallback);
   blocklist.notify(null);
 }
@@ -59,17 +62,17 @@ function run_test() {
     if (driverVersion) {
       var status = gfxInfo.getFeatureStatus(Ci.nsIGfxInfo.FEATURE_DIRECT2D);
       Assert.equal(status, Ci.nsIGfxInfo.FEATURE_BLOCKED_DEVICE);
 
       // Make sure unrelated features aren't affected
       status = gfxInfo.getFeatureStatus(Ci.nsIGfxInfo.FEATURE_DIRECT3D_9_LAYERS);
       Assert.equal(status, Ci.nsIGfxInfo.FEATURE_STATUS_OK);
     }
-    do_test_finished();
+    gTestserver.stop(do_test_finished);
   }
 
   Services.obs.addObserver(function(aSubject, aTopic, aData) {
     // If we wait until after we go through the event loop, gfxInfo is sure to
     // have processed the gfxItems event.
     executeSoon(checkBlacklist);
   }, "blocklist-data-gfxItems");
 
--- a/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_OK.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_OK.js
@@ -2,19 +2,22 @@
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // This should eventually be moved to head_addons.js
 // Test whether a machine which exactly matches the blacklist entry is
 // successfully blocked.
 // Uses test_gfxBlacklist.xml
 
-var gTestserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+ChromeUtils.import("resource://testing-common/httpd.js");
+
+var gTestserver = new HttpServer();
+gTestserver.start(-1);
 gPort = gTestserver.identity.primaryPort;
-gTestserver.registerDirectory("/data/", do_get_file("data"));
+mapFile("/data/test_gfxBlacklist.xml", gTestserver);
 
 function load_blocklist(file) {
   Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" +
                              gPort + "/data/" + file);
   var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
                   getService(Ci.nsITimerCallback);
   blocklist.notify(null);
 }
@@ -64,17 +67,17 @@ function run_test() {
   function checkBlacklist() {
     var status = gfxInfo.getFeatureStatus(Ci.nsIGfxInfo.FEATURE_DIRECT2D);
     Assert.equal(status, Ci.nsIGfxInfo.FEATURE_BLOCKED_DRIVER_VERSION);
 
     // Make sure unrelated features aren't affected
     status = gfxInfo.getFeatureStatus(Ci.nsIGfxInfo.FEATURE_DIRECT3D_9_LAYERS);
     Assert.equal(status, Ci.nsIGfxInfo.FEATURE_STATUS_OK);
 
-    do_test_finished();
+    gTestserver.stop(do_test_finished);
   }
 
   Services.obs.addObserver(function(aSubject, aTopic, aData) {
     // If we wait until after we go through the event loop, gfxInfo is sure to
     // have processed the gfxItems event.
     executeSoon(checkBlacklist);
   }, "blocklist-data-gfxItems");
 
--- a/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_OS.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_OS.js
@@ -2,19 +2,22 @@
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // This should eventually be moved to head_addons.js
 // Test whether a machine which differs only on OS version, but otherwise
 // exactly matches the blacklist entry, is not blocked.
 // Uses test_gfxBlacklist.xml
 
-var gTestserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+ChromeUtils.import("resource://testing-common/httpd.js");
+
+var gTestserver = new HttpServer();
+gTestserver.start(-1);
 gPort = gTestserver.identity.primaryPort;
-gTestserver.registerDirectory("/data/", do_get_file("data"));
+mapFile("/data/test_gfxBlacklist.xml", gTestserver);
 
 function load_blocklist(file) {
   Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" +
                              gPort + "/data/" + file);
   var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
                   getService(Ci.nsITimerCallback);
   blocklist.notify(null);
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_OSVersion_match.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_OSVersion_match.js
@@ -1,19 +1,22 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // This should eventually be moved to head_addons.js
 // Test whether new OS versions are matched properly.
 // Uses test_gfxBlacklist_OS.xml
 
-var gTestserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+ChromeUtils.import("resource://testing-common/httpd.js");
+
+var gTestserver = new HttpServer();
+gTestserver.start(-1);
 gPort = gTestserver.identity.primaryPort;
-gTestserver.registerDirectory("/data/", do_get_file("data"));
+mapFile("/data/test_gfxBlacklist_OSVersion.xml", gTestserver);
 
 function load_blocklist(file) {
   Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" +
                              gPort + "/data/" + file);
   var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
                   getService(Ci.nsITimerCallback);
   blocklist.notify(null);
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_OSVersion_mismatch_DriverVersion.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_OSVersion_mismatch_DriverVersion.js
@@ -2,19 +2,22 @@
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // This should eventually be moved to head_addons.js
 // Test whether blocklists specifying new OSeswcorrectly don't block if driver
 // versions are appropriately up-to-date.
 // Uses test_gfxBlacklist_OS.xml
 
-var gTestserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+ChromeUtils.import("resource://testing-common/httpd.js");
+
+var gTestserver = new HttpServer();
+gTestserver.start(-1);
 gPort = gTestserver.identity.primaryPort;
-gTestserver.registerDirectory("/data/", do_get_file("data"));
+mapFile("/data/test_gfxBlacklist_OSVersion.xml", gTestserver);
 
 function load_blocklist(file) {
   Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" +
                              gPort + "/data/" + file);
   var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
                   getService(Ci.nsITimerCallback);
   blocklist.notify(null);
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_OSVersion_mismatch_OSVersion.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_OSVersion_mismatch_OSVersion.js
@@ -2,19 +2,22 @@
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // This should eventually be moved to head_addons.js
 // Test whether old OS versions are not matched when the blacklist contains
 // only new OS versions.
 // Uses test_gfxBlacklist_OS.xml
 
-var gTestserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+ChromeUtils.import("resource://testing-common/httpd.js");
+
+var gTestserver = new HttpServer();
+gTestserver.start(-1);
 gPort = gTestserver.identity.primaryPort;
-gTestserver.registerDirectory("/data/", do_get_file("data"));
+mapFile("/data/test_gfxBlacklist_OSVersion.xml", gTestserver);
 
 function load_blocklist(file) {
   Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" +
                              gPort + "/data/" + file);
   var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
                   getService(Ci.nsITimerCallback);
   blocklist.notify(null);
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_Vendor.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_Vendor.js
@@ -2,19 +2,22 @@
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // This should eventually be moved to head_addons.js
 // Test whether a machine which differs only on vendor, but otherwise
 // exactly matches the blacklist entry, is not blocked.
 // Uses test_gfxBlacklist.xml
 
-var gTestserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+ChromeUtils.import("resource://testing-common/httpd.js");
+
+var gTestserver = new HttpServer();
+gTestserver.start(-1);
 gPort = gTestserver.identity.primaryPort;
-gTestserver.registerDirectory("/data/", do_get_file("data"));
+mapFile("/data/test_gfxBlacklist.xml", gTestserver);
 
 function load_blocklist(file) {
   Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" +
                              gPort + "/data/" + file);
   var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
                   getService(Ci.nsITimerCallback);
   blocklist.notify(null);
 }
@@ -63,17 +66,17 @@ function run_test() {
 
   function checkBlacklist() {
     var status = gfxInfo.getFeatureStatus(Ci.nsIGfxInfo.FEATURE_DIRECT2D);
     Assert.equal(status, Ci.nsIGfxInfo.FEATURE_STATUS_OK);
 
     status = gfxInfo.getFeatureStatus(Ci.nsIGfxInfo.FEATURE_DIRECT3D_9_LAYERS);
     Assert.equal(status, Ci.nsIGfxInfo.FEATURE_STATUS_OK);
 
-    do_test_finished();
+    gTestserver.stop(do_test_finished);
   }
 
   Services.obs.addObserver(function(aSubject, aTopic, aData) {
     // If we wait until after we go through the event loop, gfxInfo is sure to
     // have processed the gfxItems event.
     executeSoon(checkBlacklist);
   }, "blocklist-data-gfxItems");
 
--- a/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_Version.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_Version.js
@@ -1,19 +1,22 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // Test whether a machine which exactly matches the blacklist entry is
 // successfully blocked.
 // Uses test_gfxBlacklist_AllOS.xml
 
-var gTestserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+ChromeUtils.import("resource://testing-common/httpd.js");
+
+var gTestserver = new HttpServer();
+gTestserver.start(-1);
 gPort = gTestserver.identity.primaryPort;
-gTestserver.registerDirectory("/data/", do_get_file("data"));
+mapFile("/data/test_gfxBlacklist_AllOS.xml", gTestserver);
 
 function load_blocklist(file) {
   Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" +
                              gPort + "/data/" + file);
   var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
                   getService(Ci.nsITimerCallback);
   blocklist.notify(null);
 }
@@ -119,17 +122,17 @@ function run_test() {
     Assert.equal(status, Ci.nsIGfxInfo.FEATURE_STATUS_OK);
 
     status = gfxInfo.getFeatureStatus(Ci.nsIGfxInfo.FEATURE_DIRECT3D_11_ANGLE, failureId);
     Assert.equal(status, Ci.nsIGfxInfo.FEATURE_STATUS_OK);
 
     status = gfxInfo.getFeatureStatus(Ci.nsIGfxInfo.FEATURE_DX_INTEROP2, failureId);
     Assert.equal(status, Ci.nsIGfxInfo.FEATURE_STATUS_OK);
 
-    do_test_finished();
+    gTestserver.stop(do_test_finished);
   }
 
   Services.obs.addObserver(function(aSubject, aTopic, aData) {
     // If we wait until after we go through the event loop, gfxInfo is sure to
     // have processed the gfxItems event.
     executeSoon(checkBlacklist);
   }, "blocklist-data-gfxItems");
 
--- a/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_prefs.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_prefs.js
@@ -1,19 +1,23 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // Test whether the blacklist succesfully adds and removes the prefs that store
 // its decisions when the remote blacklist is changed.
 // Uses test_gfxBlacklist.xml and test_gfxBlacklist2.xml
 
-var gTestserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+ChromeUtils.import("resource://testing-common/httpd.js");
+
+var gTestserver = new HttpServer();
+gTestserver.start(-1);
 gPort = gTestserver.identity.primaryPort;
-gTestserver.registerDirectory("/data/", do_get_file("data"));
+mapFile("/data/test_gfxBlacklist.xml", gTestserver);
+mapFile("/data/test_gfxBlacklist2.xml", gTestserver);
 
 function load_blocklist(file) {
   Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" +
                              gPort + "/data/" + file);
   var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
                   getService(Ci.nsITimerCallback);
   blocklist.notify(null);
 }
@@ -102,14 +106,14 @@ function run_test() {
     var exists = false;
     try {
       Services.prefs.getIntPref("gfx.blacklist.direct2d");
       exists = true;
     } catch (e) {}
 
     Assert.ok(!exists);
 
-    do_test_finished();
+    gTestserver.stop(do_test_finished);
   }
 
   Services.obs.addObserver(blacklistAdded, "blocklist-data-gfxItems");
   load_blocklist("test_gfxBlacklist.xml");
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_isDebuggable.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_isDebuggable.js
@@ -1,37 +1,30 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
-var ID = "bootstrap2@tests.mozilla.org";
-
-const ADDON = {
-  id: ID,
-  version: "1.0",
-  bootstrap: "true",
-  multiprocessCompatible: "true",
-
-  name: "Test Bootstrap 2",
-  description: "Test Description",
+var ADDONS = [
+  "test_bootstrap2_1", // restartless addon
+];
 
-  iconURL: "chrome://foo/skin/icon.png",
-  aboutURL: "chrome://foo/content/about.xul",
-  optionsURL: "chrome://foo/content/options.xul",
+var IDS = [
+  "bootstrap2@tests.mozilla.org",
+];
 
-  targetApplications: [{
-    id: "xpcshell@tests.mozilla.org",
-    minVersion: "1",
-    maxVersion: "1"}],
-};
+function run_test() {
+  do_test_pending();
 
-add_task(async function() {
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2", "2");
 
-  await promiseStartupManager();
+  startupManager();
   AddonManager.checkCompatibility = false;
 
-  await promiseInstallXPI(ADDON);
+  installAllFiles(ADDONS.map(do_get_addon), function() {
+    restartManager();
 
-  let addon = await AddonManager.getAddonByID(ID);
-  Assert.equal(addon.isDebuggable, true);
-});
+    AddonManager.getAddonsByIDs(IDS, function([a1]) {
+      Assert.equal(a1.isDebuggable, true);
+      do_test_finished();
+    });
+  }, true);
+}
--- a/toolkit/mozapps/extensions/test/xpcshell/test_manifest.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_manifest.js
@@ -54,17 +54,17 @@ const ADDONS = [
       developers: ["Test Developer 1", "Test Developer 2"],
       translators: ["Test Translator 1", "Test Translator 2"],
       contributors: ["Test Contributor 1", "Test Contributor 2"],
       isActive: true,
       userDisabled: false,
       appDisabled: false,
       isCompatible: true,
       providesUpdatesSecurely: true,
-      blocklistState: Ci.nsIBlocklistService.STATE_NOT_BLOCKED,
+      blocklistState: AM_Ci.nsIBlocklistService.STATE_NOT_BLOCKED,
     },
   },
 
   {
     "install.rdf": {
       id: "addon2@tests.mozilla.org",
       version: "1.0",
       bootstrap: true,
--- a/toolkit/mozapps/extensions/test/xpcshell/test_migrate_state_prefs.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_migrate_state_prefs.js
@@ -1,15 +1,15 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 "use strict";
 
 /* globals Preferences */
-ChromeUtils.import("resource://gre/modules/Preferences.jsm");
+AM_Cu.import("resource://gre/modules/Preferences.jsm");
 
 function getXS() {
   let XPI = ChromeUtils.import("resource://gre/modules/addons/XPIProvider.jsm", {});
   return XPI.XPIStates;
 }
 
 function installExtension(id, data) {
   return AddonTestUtils.promiseWriteFilesToExtension(
--- a/toolkit/mozapps/extensions/test/xpcshell/test_permissions.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_permissions.js
@@ -16,17 +16,17 @@ function newPrincipal(uri) {
 function run_test() {
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2", "2");
 
   Services.prefs.setCharPref("xpinstall.whitelist.add", "https://test1.com,https://test2.com");
   Services.prefs.setCharPref("xpinstall.whitelist.add.36", "https://test3.com,https://www.test4.com");
   Services.prefs.setCharPref("xpinstall.whitelist.add.test5", "https://test5.com");
 
   Services.perms.add(NetUtil.newURI("https://www.test9.com"), "install",
-                     Ci.nsIPermissionManager.ALLOW_ACTION);
+                     AM_Ci.nsIPermissionManager.ALLOW_ACTION);
 
   startupManager();
 
   Assert.ok(!AddonManager.isInstallAllowed(XPI_MIMETYPE,
                                            newPrincipal("http://test1.com")));
   Assert.ok(AddonManager.isInstallAllowed(XPI_MIMETYPE,
                                           newPrincipal("https://test1.com")));
   Assert.ok(AddonManager.isInstallAllowed(XPI_MIMETYPE,
--- a/toolkit/mozapps/extensions/test/xpcshell/test_pluginBlocklistCtp.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_pluginBlocklistCtp.js
@@ -1,20 +1,24 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 const nsIBLS = Ci.nsIBlocklistService;
+ChromeUtils.import("resource://testing-common/httpd.js");
 
 var gNotifier = null;
 var gNextTest = null;
 var gPluginHost = null;
 
-var gTestserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
-gTestserver.registerDirectory("/data/", do_get_file("data"));
+var gServer = new HttpServer();
+gServer.start(-1);
+gPort = gServer.identity.primaryPort;
+mapFile("/data/test_pluginBlocklistCtp.xml", gServer);
+mapFile("/data/test_pluginBlocklistCtpUndo.xml", gServer);
 
 var PLUGINS = [{
   // severity=0, vulnerabilitystatus=0 -> outdated
   name: "test_plugin_0",
   version: "5",
   disabled: false,
   blocklisted: false
 },
@@ -86,42 +90,42 @@ function get_test_plugin() {
 // At this time, the blocklist does not have an entry for the test plugin,
 // so it shouldn't be click-to-play.
 function test_is_not_clicktoplay() {
   var plugin = get_test_plugin();
   var blocklistState = Services.blocklist.getPluginBlocklistState(plugin, "1", "1.9");
   Assert.notEqual(blocklistState, Ci.nsIBlocklistService.STATE_VULNERABLE_UPDATE_AVAILABLE);
   Assert.notEqual(blocklistState, Ci.nsIBlocklistService.STATE_VULNERABLE_NO_UPDATE);
 
-  Services.prefs.setCharPref("extensions.blocklist.url", "http://example.com/data/test_pluginBlocklistCtpUndo.xml");
+  Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" + gPort + "/data/test_pluginBlocklistCtpUndo.xml");
   gNextTest = test_is_clicktoplay;
   gNotifier.notify(null);
 }
 
 // Here, we've updated the blocklist to have a block for the test plugin,
 // so it should be click-to-play.
 function test_is_clicktoplay() {
   var plugin = get_test_plugin();
   var blocklistState = Services.blocklist.getPluginBlocklistState(plugin, "1", "1.9");
   Assert.equal(blocklistState, Ci.nsIBlocklistService.STATE_VULNERABLE_NO_UPDATE);
 
-  Services.prefs.setCharPref("extensions.blocklist.url", "http://example.com/data/test_pluginBlocklistCtp.xml");
+  Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" + gPort + "/data/test_pluginBlocklistCtp.xml");
   gNextTest = test_is_not_clicktoplay2;
   gNotifier.notify(null);
 }
 
 // But now we've removed that entry from the blocklist (really we've gone back
 // to the old one), so the plugin shouldn't be click-to-play any more.
 function test_is_not_clicktoplay2() {
   var plugin = get_test_plugin();
   var blocklistState = Services.blocklist.getPluginBlocklistState(plugin, "1", "1.9");
   Assert.notEqual(blocklistState, Ci.nsIBlocklistService.STATE_VULNERABLE_UPDATE_AVAILABLE);
   Assert.notEqual(blocklistState, Ci.nsIBlocklistService.STATE_VULNERABLE_NO_UPDATE);
 
-  Services.prefs.setCharPref("extensions.blocklist.url", "http://example.com/data/test_pluginBlocklistCtpUndo.xml");
+  Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" + gPort + "/data/test_pluginBlocklistCtpUndo.xml");
   gNextTest = test_disable_blocklist;
   gNotifier.notify(null);
 }
 
 // Test that disabling the blocklist when a plugin is ctp-blocklisted will
 // result in the plugin not being click-to-play.
 function test_disable_blocklist() {
   var plugin = get_test_plugin();
@@ -138,29 +142,29 @@ function test_disable_blocklist() {
   // and setting that plugin's enabled state to click-to-play
   Services.prefs.setBoolPref("plugins.click_to_play", true);
   let previousEnabledState = plugin.enabledState;
   plugin.enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
   Assert.equal(gPluginHost.getStateForType("application/x-test"), Ci.nsIPluginTag.STATE_CLICKTOPLAY);
   // clean up plugin state
   plugin.enabledState = previousEnabledState;
 
-  do_test_finished();
+  gServer.stop(do_test_finished);
 }
 
 // Observe "blocklist-updated" so we know when to advance to the next test
 function observer() {
   if (gNextTest)
     executeSoon(gNextTest);
 }
 
 function run_test() {
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
 
-  Services.prefs.setCharPref("extensions.blocklist.url", "http://example.com/data/test_pluginBlocklistCtp.xml");
+  Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" + gPort + "/data/test_pluginBlocklistCtp.xml");
   Services.prefs.setBoolPref("plugin.load_flash_only", false);
   startupManager();
 
   gPluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
   gNotifier = Cc["@mozilla.org/extensions/blocklist;1"].getService(Ci.nsITimerCallback);
   Services.obs.addObserver(observer, "blocklist-updated");
 
   registerCleanupFunction(function() {
--- a/toolkit/mozapps/extensions/test/xpcshell/test_pluginchange.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_pluginchange.js
@@ -40,17 +40,17 @@ const PLUGINS = [
 
 const gPluginHost = {
   // nsIPluginHost
   getPluginTags(count) {
     count.value = PLUGINS.length;
     return PLUGINS;
   },
 
-  QueryInterface: XPCOMUtils.generateQI([Ci.nsIPluginHost])
+  QueryInterface: XPCOMUtils.generateQI([AM_Ci.nsIPluginHost])
 };
 
 MockRegistrar.register("@mozilla.org/plugin/host;1", gPluginHost);
 
 // This verifies that when the list of plugins changes the add-ons manager
 // correctly updates
 function run_test() {
   do_test_pending();
--- a/toolkit/mozapps/extensions/test/xpcshell/test_plugins.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_plugins.js
@@ -3,17 +3,17 @@
  */
 
 var TEST_PLUGIN_DESCRIPTION = "Flash plug-in for testing purposes.";
 
 // This verifies that plugins exist and can be enabled and disabled.
 var gID = null;
 
 function setTestPluginState(state) {
-  let tags = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost)
+  let tags = AM_Cc["@mozilla.org/plugin/host;1"].getService(AM_Ci.nsIPluginHost)
     .getPluginTags();
   for (let tag of tags) {
     info("Checking tag: " + tag.description);
     if (tag.description == TEST_PLUGIN_DESCRIPTION) {
       tag.enabledState = state;
       return;
     }
   }
@@ -21,30 +21,30 @@ function setTestPluginState(state) {
 }
 
 function run_test() {
   do_test_pending();
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
   Services.prefs.setBoolPref("plugins.click_to_play", true);
   Services.prefs.setBoolPref("plugin.load_flash_only", false);
 
-  setTestPluginState(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
+  setTestPluginState(AM_Ci.nsIPluginTag.STATE_CLICKTOPLAY);
 
   startupManager();
   AddonManager.addAddonListener(AddonListener);
   AddonManager.addInstallListener(InstallListener);
 
   run_test_1();
 }
 
 // Finds the test plugin library
 function get_test_plugin() {
-  var pluginEnum = Services.dirsvc.get("APluginsDL", Ci.nsISimpleEnumerator);
+  var pluginEnum = Services.dirsvc.get("APluginsDL", AM_Ci.nsISimpleEnumerator);
   while (pluginEnum.hasMoreElements()) {
-    let dir = pluginEnum.getNext().QueryInterface(Ci.nsIFile);
+    let dir = pluginEnum.getNext().QueryInterface(AM_Ci.nsIFile);
     let plugin = dir.clone();
     // OSX plugin
     plugin.append("npswftest.plugin");
     if (plugin.exists()) {
       plugin.normalize();
       return plugin;
     }
     plugin = dir.clone();
@@ -65,30 +65,30 @@ function get_test_plugin() {
   return null;
 }
 
 function getFileSize(aFile) {
   if (!aFile.isDirectory())
     return aFile.fileSize;
 
   let size = 0;
-  let entries = aFile.directoryEntries.QueryInterface(Ci.nsIDirectoryEnumerator);
+  let entries = aFile.directoryEntries.QueryInterface(AM_Ci.nsIDirectoryEnumerator);
   let entry;
   while ((entry = entries.nextFile))
     size += getFileSize(entry);
   entries.close();
   return size;
 }
 
 function getPluginLastModifiedTime(aPluginFile) {
   // On OS X we use the bundle contents last modified time as using
   // the package directories modified date may be outdated.
   // See bug 313700.
   try {
-    let localFileMac = aPluginFile.QueryInterface(Ci.nsILocalFileMac);
+    let localFileMac = aPluginFile.QueryInterface(AM_Ci.nsILocalFileMac);
     if (localFileMac) {
       return localFileMac.bundleContentsLastModifiedTime;
     }
   } catch (e) {
   }
 
   return aPluginFile.lastModifiedTime;
 }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_proxies.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_proxies.js
@@ -37,27 +37,27 @@ var METADATA = {
     maxVersion: "2"
   }]
 };
 
 const gHaveSymlinks = AppConstants.platform != "win";
 
 
 function createSymlink(aSource, aDest) {
-  if (aSource instanceof Ci.nsIFile)
+  if (aSource instanceof AM_Ci.nsIFile)
     aSource = aSource.path;
-  if (aDest instanceof Ci.nsIFile)
+  if (aDest instanceof AM_Ci.nsIFile)
     aDest = aDest.path;
 
   return OS.File.unixSymLink(aSource, aDest);
 }
 
 function promiseWriteFile(aFile, aData) {
   if (!aFile.parent.exists())
-    aFile.parent.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755);
+    aFile.parent.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0o755);
 
   return OS.File.writeAtomic(aFile.path, new TextEncoder().encode(aData));
 }
 
 function checkAddonsExist() {
   for (let addon of ADDONS) {
     let file = addon.directory.clone();
     file.append("install.rdf");
@@ -178,17 +178,17 @@ async function run_symlink_tests() {
   METADATA.name = METADATA.id;
   METADATA.unpack = "true";
 
   let tempDirectory = gTmpD.clone();
   tempDirectory.append(METADATA.id);
 
   let tempFile = tempDirectory.clone();
   tempFile.append("test.txt");
-  tempFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0o644);
+  tempFile.create(AM_Ci.nsIFile.NORMAL_FILE_TYPE, 0o644);
 
   let addonDirectory = profileDir.clone();
   addonDirectory.append(METADATA.id);
 
   writeInstallRDFToDir(METADATA, profileDir);
 
   let symlink = addonDirectory.clone();
   symlink.append(tempDirectory.leafName);
--- a/toolkit/mozapps/extensions/test/xpcshell/test_registry.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_registry.js
@@ -36,35 +36,35 @@ var addon2 = {
 
 const addon1Dir = writeInstallRDFForExtension(addon1, gProfD, "addon1");
 const addon2Dir = writeInstallRDFForExtension(addon2, gProfD, "addon2");
 
 let registry;
 
 function run_test() {
   // This test only works where there is a registry.
-  if (!("nsIWindowsRegKey" in Ci))
+  if (!("nsIWindowsRegKey" in AM_Ci))
     return;
 
   registry = new MockRegistry();
   registerCleanupFunction(() => {
     registry.shutdown();
   });
 
   do_test_pending();
 
   run_test_1();
 }
 
 // Tests whether basic registry install works
 function run_test_1() {
-  registry.setValue(Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
+  registry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
                    "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
                     "addon1@tests.mozilla.org", addon1Dir.path);
-  registry.setValue(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
+  registry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
                     "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
                     "addon2@tests.mozilla.org", addon2Dir.path);
 
   startupManager();
 
   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                "addon2@tests.mozilla.org"], function([a1, a2]) {
     Assert.notEqual(a1, null);
@@ -78,40 +78,40 @@ function run_test_1() {
     Assert.equal(a2.scope, AddonManager.SCOPE_USER);
 
     executeSoon(run_test_2);
   });
 }
 
 // Tests whether uninstalling from the registry works
 function run_test_2() {
-  registry.setValue(Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
+  registry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
                     "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
                     "addon1@tests.mozilla.org", null);
-  registry.setValue(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
+  registry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
                     "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
                     "addon2@tests.mozilla.org", null);
 
   restartManager();
 
   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                "addon2@tests.mozilla.org"], function([a1, a2]) {
     Assert.equal(a1, null);
     Assert.equal(a2, null);
 
     executeSoon(run_test_3);
   });
 }
 
 // Checks that the ID in the registry must match that in the install manifest
 function run_test_3() {
-  registry.setValue(Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
+  registry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
                     "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
                     "addon1@tests.mozilla.org", addon2Dir.path);
-  registry.setValue(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
+  registry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
                     "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
                     "addon2@tests.mozilla.org", addon1Dir.path);
 
   restartManager();
 
   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                "addon2@tests.mozilla.org"], function([a1, a2]) {
     Assert.equal(a1, null);
@@ -121,34 +121,34 @@ function run_test_3() {
   });
 }
 
 // Tests whether an extension's ID can change without its directory changing
 function run_test_4() {
   // Restarting with bad items in the registry should not force an EM restart
   restartManager();
 
-  registry.setValue(Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
+  registry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
                     "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
                     "addon1@tests.mozilla.org", null);
-  registry.setValue(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
+  registry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
                     "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
                     "addon2@tests.mozilla.org", null);
 
   restartManager();
 
-  registry.setValue(Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
+  registry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
                     "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
                     "addon1@tests.mozilla.org", addon1Dir.path);
   restartManager();
 
-  registry.setValue(Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
+  registry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
                     "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
                     "addon1@tests.mozilla.org", null);
-  registry.setValue(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
+  registry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
                     "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
                     "addon2@tests.mozilla.org", addon1Dir.path);
   writeInstallRDFForExtension(addon2, gProfD, "addon1");
 
   restartManager();
 
   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                "addon2@tests.mozilla.org"], function([a1, a2]) {
--- a/toolkit/mozapps/extensions/test/xpcshell/test_signed_inject.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_signed_inject.js
@@ -28,18 +28,18 @@ function breakAddon(file) {
     let f = file.clone();
     f.append("test.txt");
     f.remove(true);
 
     f = file.clone();
     f.append("install.rdf");
     f.lastModifiedTime = Date.now();
   } else {
-    var zipW = Cc["@mozilla.org/zipwriter;1"].
-               createInstance(Ci.nsIZipWriter);
+    var zipW = AM_Cc["@mozilla.org/zipwriter;1"].
+               createInstance(AM_Ci.nsIZipWriter);
     zipW.open(file, FileUtils.MODE_RDWR | FileUtils.MODE_APPEND);
     zipW.removeEntry("test.txt", false);
     zipW.close();
   }
 }
 
 function resetPrefs() {
   Services.prefs.setIntPref("bootstraptest.active_version", -1);
--- a/toolkit/mozapps/extensions/test/xpcshell/test_signed_install.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_signed_install.js
@@ -12,68 +12,68 @@ const ADDONS = {
     signed: "signed_bootstrap_2.xpi",
     sha256Signed: "signed_bootstrap_sha256_1.xpi",
     privileged: "privileged_bootstrap_2.xpi",
   },
 };
 const WORKING = "signed_bootstrap_1.xpi";
 const ID = "test@tests.mozilla.org";
 
-var gServer = createHttpServer({port: 4444});
+var gServer = createHttpServer(4444);
 
 // Creates an add-on with a broken signature by changing an existing file
 function createBrokenAddonModify(file) {
   let brokenFile = gTmpD.clone();
   brokenFile.append("broken.xpi");
   file.copyTo(brokenFile.parent, brokenFile.leafName);
 
-  var stream = Cc["@mozilla.org/io/string-input-stream;1"].
-               createInstance(Ci.nsIStringInputStream);
+  var stream = AM_Cc["@mozilla.org/io/string-input-stream;1"].
+               createInstance(AM_Ci.nsIStringInputStream);
   stream.setData("FOOBAR", -1);
-  var zipW = Cc["@mozilla.org/zipwriter;1"].
-             createInstance(Ci.nsIZipWriter);
+  var zipW = AM_Cc["@mozilla.org/zipwriter;1"].
+             createInstance(AM_Ci.nsIZipWriter);
   zipW.open(brokenFile, FileUtils.MODE_RDWR | FileUtils.MODE_APPEND);
   zipW.removeEntry("test.txt", false);
-  zipW.addEntryStream("test.txt", 0, Ci.nsIZipWriter.COMPRESSION_NONE,
+  zipW.addEntryStream("test.txt", 0, AM_Ci.nsIZipWriter.COMPRESSION_NONE,
                       stream, false);
   zipW.close();
 
   return brokenFile;
 }
 
 // Creates an add-on with a broken signature by adding a new file
 function createBrokenAddonAdd(file) {
   let brokenFile = gTmpD.clone();
   brokenFile.append("broken.xpi");
   file.copyTo(brokenFile.parent, brokenFile.leafName);
 
-  var stream = Cc["@mozilla.org/io/string-input-stream;1"].
-               createInstance(Ci.nsIStringInputStream);
+  var stream = AM_Cc["@mozilla.org/io/string-input-stream;1"].
+               createInstance(AM_Ci.nsIStringInputStream);
   stream.setData("FOOBAR", -1);
-  var zipW = Cc["@mozilla.org/zipwriter;1"].
-             createInstance(Ci.nsIZipWriter);
+  var zipW = AM_Cc["@mozilla.org/zipwriter;1"].
+             createInstance(AM_Ci.nsIZipWriter);
   zipW.open(brokenFile, FileUtils.MODE_RDWR | FileUtils.MODE_APPEND);
-  zipW.addEntryStream("test2.txt", 0, Ci.nsIZipWriter.COMPRESSION_NONE,
+  zipW.addEntryStream("test2.txt", 0, AM_Ci.nsIZipWriter.COMPRESSION_NONE,
                       stream, false);
   zipW.close();
 
   return brokenFile;
 }
 
 // Creates an add-on with a broken signature by removing an existing file
 function createBrokenAddonRemove(file) {
   let brokenFile = gTmpD.clone();
   brokenFile.append("broken.xpi");
   file.copyTo(brokenFile.parent, brokenFile.leafName);
 
-  var stream = Cc["@mozilla.org/io/string-input-stream;1"].
-               createInstance(Ci.nsIStringInputStream);
+  var stream = AM_Cc["@mozilla.org/io/string-input-stream;1"].
+               createInstance(AM_Ci.nsIStringInputStream);
   stream.setData("FOOBAR", -1);
-  var zipW = Cc["@mozilla.org/zipwriter;1"].
-             createInstance(Ci.nsIZipWriter);
+  var zipW = AM_Cc["@mozilla.org/zipwriter;1"].
+             createInstance(AM_Ci.nsIZipWriter);
   zipW.open(brokenFile, FileUtils.MODE_RDWR | FileUtils.MODE_APPEND);
   zipW.removeEntry("test.txt", false);
   zipW.close();
 
   return brokenFile;
 }
 
 function createInstall(url) {
--- a/toolkit/mozapps/extensions/test/xpcshell/test_switch_os.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_switch_os.js
@@ -24,26 +24,26 @@ add_task(async function() {
   BootstrapMonitor.checkAddonStarted(ID);
   Assert.ok(!addon.userDisabled);
   Assert.ok(addon.isActive);
 
   await promiseShutdownManager();
 
   BootstrapMonitor.checkAddonNotStarted(ID);
 
-  let jData = await loadJSON(gExtensionsJSON.path);
+  let jData = loadJSON(gExtensionsJSON);
 
   for (let addonInstance of jData.addons) {
     if (addonInstance.id == ID) {
       // Set to something that would be an invalid descriptor for this platform
       addonInstance.descriptor = AppConstants.platform == "win" ? "/foo/bar" : "C:\\foo\\bar";
     }
   }
 
-  await saveJSON(jData, gExtensionsJSON.path);
+  saveJSON(jData, gExtensionsJSON);
 
   startupManager();
 
   addon = await promiseAddonByID(ID);
   Assert.notEqual(addon, null);
 
   BootstrapMonitor.checkAddonStarted(ID);
   Assert.ok(!addon.userDisabled);
--- a/toolkit/mozapps/extensions/test/xpcshell/test_system_reset.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_system_reset.js
@@ -19,18 +19,18 @@ do_get_file("data/system_addons/system1_
 do_get_file("data/system_addons/system3_1.xpi").copyTo(dir, "system3@tests.mozilla.org.xpi");
 
 const distroDir = FileUtils.getDir("ProfD", ["sysfeatures", "app0"], true);
 registerDirectory("XREAppFeat", distroDir);
 
 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "0");
 
 function makeUUID() {
-  let uuidGen = Cc["@mozilla.org/uuid-generator;1"].
-                getService(Ci.nsIUUIDGenerator);
+  let uuidGen = AM_Cc["@mozilla.org/uuid-generator;1"].
+                getService(AM_Ci.nsIUUIDGenerator);
   return uuidGen.generateUUID().toString();
 }
 
 async function check_installed(conditions) {
   for (let i = 0; i < conditions.length; i++) {
     let condition = conditions[i];
     let id = "system" + (i + 1) + "@tests.mozilla.org";
     let addon = await promiseAddonByID(id);
@@ -60,17 +60,17 @@ async function check_installed(condition
 
       // Verify the add-ons file is in the right place
       let file = expectedDir.clone();
       file.append(id + ".xpi");
       Assert.ok(file.exists());
       Assert.ok(file.isFile());
 
       let uri = addon.getResourceURI(null);
-      Assert.ok(uri instanceof Ci.nsIFileURL);
+      Assert.ok(uri instanceof AM_Ci.nsIFileURL);
       Assert.equal(uri.file.path, file.path);
 
       if (isUpgrade) {
         Assert.equal(addon.signedState, AddonManager.SIGNEDSTATE_SYSTEM);
       }
 
       // Verify the add-on actually started
       BootstrapMonitor.checkAddonStarted(id, version);
--- a/toolkit/mozapps/extensions/test/xpcshell/test_updateCancel.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_updateCancel.js
@@ -1,15 +1,15 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // Test cancelling add-on update checks while in progress (bug 925389)
 
-ChromeUtils.import("resource://gre/modules/PromiseUtils.jsm");
+ChromeUtils.import("resource://gre/modules/Promise.jsm");
 
 // The test extension uses an insecure update url.
 Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false);
 Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false);
 
 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
 
 // Set up an HTTP server to respond to update requests
@@ -24,32 +24,32 @@ profileDir.append("extensions");
 //  - ensure we get cancel notification
 // complete HTTP response
 //  - ensure no callbacks after cancel
 //  - ensure update is gone
 
 // Create an addon update listener containing a promise
 // that resolves when the update is cancelled
 function makeCancelListener() {
-  let updated = PromiseUtils.defer();
+  let updated = Promise.defer();
   return {
     onUpdateAvailable(addon, install) {
       updated.reject("Should not have seen onUpdateAvailable notification");
     },
 
     onUpdateFinished(aAddon, aError) {
       info("onUpdateCheckFinished: " + aAddon.id + " " + aError);
       updated.resolve(aError);
     },
     promise: updated.promise
   };
 }
 
 // Set up the HTTP server so that we can control when it responds
-var httpReceived = PromiseUtils.defer();
+var httpReceived = Promise.defer();
 function dataHandler(aRequest, aResponse) {
   aResponse.processAsync();
   httpReceived.resolve([aRequest, aResponse]);
 }
 var testserver = new HttpServer();
 testserver.registerDirectory("/addons/", do_get_file("addons"));
 testserver.registerPathHandler("/data/test_update.json", dataHandler);
 testserver.start(-1);
@@ -86,31 +86,31 @@ add_task(async function cancel_during_ch
 
   let updateResult = await listener.promise;
   Assert.equal(AddonManager.UPDATE_STATUS_CANCELLED, updateResult);
 
   // Now complete the HTTP request
   let file = do_get_cwd();
   file.append("data");
   file.append("test_update.json");
-  let data = new TextDecoder().decode(await OS.File.read(file.path));
+  let data = loadFile(file);
   response.write(data);
   response.finish();
 
   // trying to cancel again should return false, i.e. nothing to cancel
   Assert.ok(!a1.cancelUpdate());
 
   await true;
 });
 
 // Test that update check is cancelled if the XPI provider shuts down while
 // the update check is in progress
 add_task(async function shutdown_during_check() {
   // Reset our HTTP listener
-  httpReceived = PromiseUtils.defer();
+  httpReceived = Promise.defer();
 
   let a1 = await promiseAddonByID("addon1@tests.mozilla.org");
   Assert.notEqual(a1, null);
 
   let listener = makeCancelListener();
   a1.findUpdates(listener, AddonManager.UPDATE_WHEN_USER_REQUESTED);
 
   // Wait for the http request to arrive
@@ -120,14 +120,14 @@ add_task(async function shutdown_during_
 
   let updateResult = await listener.promise;
   Assert.equal(AddonManager.UPDATE_STATUS_CANCELLED, updateResult);
 
   // Now complete the HTTP request
   let file = do_get_cwd();
   file.append("data");
   file.append("test_update.json");
-  let data = await loadFile(file.path);
+  let data = loadFile(file);
   response.write(data);
   response.finish();
 
-  await testserver.stop();
+  await testserver.stop(Promise.defer().resolve);
 });
--- a/toolkit/mozapps/extensions/test/xpcshell/test_update_compatmode.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_update_compatmode.js
@@ -4,86 +4,91 @@
 
 // This verifies that add-on update check correctly fills in the
 // %COMPATIBILITY_MODE% token in the update URL.
 
 
 // The test extension uses an insecure update url.
 Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false);
 
-var testserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
-testserver.registerDirectory("/data/", do_get_file("data"));
+ChromeUtils.import("resource://testing-common/httpd.js");
+var testserver = new HttpServer();
+testserver.start(-1);
+gPort = testserver.identity.primaryPort;
+mapFile("/data/test_updatecompatmode_ignore.json", testserver);
+mapFile("/data/test_updatecompatmode_normal.json", testserver);
+mapFile("/data/test_updatecompatmode_strict.json", testserver);
 testserver.registerDirectory("/addons/", do_get_file("addons"));
 
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
 
 function run_test() {
   do_test_pending();
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
 
   writeInstallRDFForExtension({
     id: "compatmode-normal@tests.mozilla.org",
     version: "1.0",
     bootstrap: true,
-    updateURL: "http://example.com/data/test_updatecompatmode_%COMPATIBILITY_MODE%.json",
+    updateURL: "http://localhost:" + gPort + "/data/test_updatecompatmode_%COMPATIBILITY_MODE%.json",
     targetApplications: [{
       id: "xpcshell@tests.mozilla.org",
       minVersion: "1",
       maxVersion: "1"
     }],
     name: "Test Addon - normal"
   }, profileDir);
 
   writeInstallRDFForExtension({
     id: "compatmode-strict@tests.mozilla.org",
     version: "1.0",
     bootstrap: true,
-    updateURL: "http://example.com/data/test_updatecompatmode_%COMPATIBILITY_MODE%.json",
+    updateURL: "http://localhost:" + gPort + "/data/test_updatecompatmode_%COMPATIBILITY_MODE%.json",
     targetApplications: [{
       id: "xpcshell@tests.mozilla.org",
       minVersion: "1",
       maxVersion: "1"
     }],
     name: "Test Addon - strict"
   }, profileDir);
 
   writeInstallRDFForExtension({
     id: "compatmode-strict-optin@tests.mozilla.org",
     version: "1.0",
     bootstrap: true,
-    updateURL: "http://example.com/data/test_updatecompatmode_%COMPATIBILITY_MODE%.json",
+    updateURL: "http://localhost:" + gPort + "/data/test_updatecompatmode_%COMPATIBILITY_MODE%.json",
     targetApplications: [{
       id: "xpcshell@tests.mozilla.org",
       minVersion: "1",
       maxVersion: "1"
     }],
     name: "Test Addon - strict opt-in",
     strictCompatibility: true
   }, profileDir);
 
   writeInstallRDFForExtension({
     id: "compatmode-ignore@tests.mozilla.org",
     version: "1.0",
     bootstrap: true,
-    updateURL: "http://example.com/data/test_updatecompatmode_%COMPATIBILITY_MODE%.json",
+    updateURL: "http://localhost:" + gPort + "/data/test_updatecompatmode_%COMPATIBILITY_MODE%.json",
     targetApplications: [{
       id: "xpcshell@tests.mozilla.org",
       minVersion: "1",
       maxVersion: "1"
     }],
     name: "Test Addon - ignore",
   }, profileDir);
 
   startupManager();
   run_test_1();
 }
 
 function end_test() {
-  do_test_finished();
+  testserver.stop(do_test_finished);
 }
 
 
 // Strict compatibility checking disabled.
 function run_test_1() {
   info("Testing with strict compatibility checking disabled");
   Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false);
   AddonManager.getAddonByID("compatmode-normal@tests.mozilla.org", function(addon) {
--- a/toolkit/mozapps/extensions/test/xpcshell/test_update_ignorecompat.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_update_ignorecompat.js
@@ -6,36 +6,39 @@
 // check is disabled.
 
 const PREF_GETADDONS_CACHE_ENABLED = "extensions.getAddons.cache.enabled";
 
 // The test extension uses an insecure update url.
 Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false);
 Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false);
 
-var testserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
-testserver.registerDirectory("/data/", do_get_file("data"));
-testserver.registerDirectory("/data/", do_get_file("data"));
+var testserver = createHttpServer();
+gPort = testserver.identity.primaryPort;
+mapFile("/data/test_update.json", testserver);
+mapFile("/data/test_update_addons.json", testserver);
+mapFile("/data/test_update_compat.json", testserver);
+testserver.registerDirectory("/addons/", do_get_file("addons"));
 
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
 
 
 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1");
 
 const updateFile = "test_update.json";
 const appId = "toolkit@mozilla.org";
 
 // Test that the update check correctly observes the
 // extensions.strictCompatibility pref and compatibility overrides.
 add_test(function() {
   writeInstallRDFForExtension({
     id: "addon9@tests.mozilla.org",
     version: "1.0",
-    updateURL: "http://example.com/data/" + updateFile,
+    updateURL: "http://localhost:" + gPort + "/data/" + updateFile,
     targetApplications: [{
       id: appId,
       minVersion: "0.1",
       maxVersion: "0.2"
     }],
     name: "Test Addon 9",
   }, profileDir);
 
@@ -48,31 +51,31 @@ add_test(function() {
       Assert.equal(aInstall.version, "4.0");
     },
     onDownloadFailed(aInstall) {
       run_next_test();
     }
   });
 
   Services.prefs.setCharPref(PREF_GETADDONS_BYIDS,
-                             `http://example.com/data/test_update_addons.json`);
+                             `http://localhost:${gPort}/data/test_update_addons.json`);
   Services.prefs.setCharPref(PREF_COMPAT_OVERRIDES,
-                             `http://example.com/data/test_update_compat.json`);
+                             `http://localhost:${gPort}/data/test_update_compat.json`);
   Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, true);
 
   AddonManagerInternal.backgroundUpdateCheck();
 });
 
 // Test that the update check correctly observes when an addon opts-in to
 // strict compatibility checking.
 add_test(function() {
   writeInstallRDFForExtension({
     id: "addon11@tests.mozilla.org",
     version: "1.0",
-    updateURL: "http://example.com/data/" + updateFile,
+    updateURL: "http://localhost:" + gPort + "/data/" + updateFile,
     targetApplications: [{
       id: appId,
       minVersion: "0.1",
       maxVersion: "0.2"
     }],
     name: "Test Addon 11",
   }, profileDir);
 
--- a/toolkit/mozapps/extensions/test/xpcshell/test_update_webextensions.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_update_webextensions.js
@@ -3,24 +3,24 @@
 const TOOLKIT_ID = "toolkit@mozilla.org";
 
 // We don't have an easy way to serve update manifests from a secure URL.
 Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false);
 
 var testserver = createHttpServer();
 gPort = testserver.identity.primaryPort;
 
-const uuidGenerator = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
+const uuidGenerator = AM_Cc["@mozilla.org/uuid-generator;1"].getService(AM_Ci.nsIUUIDGenerator);
 
 const extensionsDir = gProfD.clone();
 extensionsDir.append("extensions");
 
 const addonsDir = gTmpD.clone();
 addonsDir.append("addons");
-addonsDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755);
+addonsDir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0o755);
 
 registerCleanupFunction(() => addonsDir.remove(true));
 
 testserver.registerDirectory("/addons/", addonsDir);
 
 
 let gUpdateManifests = {};
 
--- a/toolkit/mozapps/extensions/test/xpcshell/test_upgrade.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_upgrade.js
@@ -10,17 +10,17 @@ Services.prefs.setBoolPref(PREF_EM_STRIC
 // Enable loading extensions from the application scope
 Services.prefs.setIntPref("extensions.enabledScopes",
                           AddonManager.SCOPE_PROFILE +
                           AddonManager.SCOPE_APPLICATION);
 
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
 
-const globalDir = Services.dirsvc.get("XREAddonAppDir", Ci.nsIFile);
+const globalDir = Services.dirsvc.get("XREAddonAppDir", AM_Ci.nsIFile);
 globalDir.append("extensions");
 
 var gGlobalExisted = globalDir.exists();
 var gInstallTime = Date.now();
 
 function run_test() {
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
 
--- a/toolkit/mozapps/extensions/test/xpcshell/test_webextension.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_webextension.js
@@ -20,18 +20,18 @@ add_task(async function() {
   await Promise.all([
     promiseInstallAllFiles([do_get_addon("webextension_1")], true),
     promiseWebExtensionStartup()
   ]);
 
   equal(GlobalManager.extensionMap.size, 1);
   ok(GlobalManager.extensionMap.has(ID));
 
-  let chromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"].
-                  getService(Ci.nsIChromeRegistry);
+  let chromeReg = AM_Cc["@mozilla.org/chrome/chrome-registry;1"].
+                  getService(AM_Ci.nsIChromeRegistry);
   try {
     chromeReg.convertChromeURL(NetUtil.newURI("chrome://webex/content/webex.xul"));
     do_throw("Chrome manifest should not have been registered");
   } catch (e) {
     // Expected the chrome url to not be registered
   }
 
   let addon = await promiseAddonByID(ID);
--- a/toolkit/mozapps/extensions/test/xpcshell/test_webextension_icons.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_webextension_icons.js
@@ -1,17 +1,17 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 const ID = "webextension1@tests.mozilla.org";
 
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
-profileDir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
+profileDir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
 
 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "42");
 startupManager();
 
 async function testSimpleIconsetParsing(manifest) {
   await promiseWriteWebManifestForExtension(manifest, profileDir);
 
   await Promise.all([
--- a/toolkit/mozapps/extensions/test/xpcshell/test_webextension_install.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_webextension_install.js
@@ -2,17 +2,17 @@
 ChromeUtils.import("resource://gre/modules/addons/AddonSettings.jsm");
 
 let profileDir;
 add_task(async function setup() {
   profileDir = gProfD.clone();
   profileDir.append("extensions");
 
   if (!profileDir.exists())
-    profileDir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
+    profileDir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
 
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
   startupManager();
 });
 
 const IMPLICIT_ID_XPI = "data/webext-implicit-id.xpi";
 const IMPLICIT_ID_ID = "webext_implicit_id@tests.mozilla.org";
 
--- a/toolkit/mozapps/extensions/test/xpcshell/test_webextension_theme.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_webextension_theme.js
@@ -3,17 +3,17 @@
 /**
  * This file contains test for 'theme' type WebExtension addons. Tests focus mostly
  * on interoperability between the different theme formats (XUL and LWT) and
  * Addon Manager integration.
  *
  * Coverage may overlap with other tests in this folder.
  */
 
-const {LightweightThemeManager} = ChromeUtils.import("resource://gre/modules/LightweightThemeManager.jsm", {});
+const {LightweightThemeManager} = AM_Cu.import("resource://gre/modules/LightweightThemeManager.jsm", {});
 const THEME_IDS = [
   "theme3@tests.mozilla.org",
   "theme2@personas.mozilla.org",
   "default@tests.mozilla.org"
 ];
 const DEFAULT_THEME = THEME_IDS[2];
 
 const profileDir = gProfD.clone();