Bug 1543156 - Wait for the addon manager to start in DevTools addons xpcshell tests r=ochameau
☠☠ backed out by 0a3045be7a72 ☠ ☠
authorJulian Descottes <jdescottes@mozilla.com>
Wed, 13 Nov 2019 09:33:49 +0000
changeset 501723 4d4982e04e4d1dd63b18b8b35bba555ec62c4e38
parent 501722 8001d4ae9b003037412c78d73da61c3ca62277fd
child 501724 351b6e9f017b4587adaaf4de0d2b209338f1a4a6
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1543156
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1543156 - Wait for the addon manager to start in DevTools addons xpcshell tests r=ochameau Differential Revision: https://phabricator.services.mozilla.com/D52535
devtools/server/tests/unit/head_dbg.js
devtools/server/tests/unit/test_addon_events.js
devtools/server/tests/unit/test_addon_reload.js
devtools/server/tests/unit/test_addons_actor.js
--- a/devtools/server/tests/unit/head_dbg.js
+++ b/devtools/server/tests/unit/head_dbg.js
@@ -46,35 +46,47 @@ const { DebuggerClient } = require("devt
 const ObjectFront = require("devtools/shared/fronts/object");
 const { LongStringFront } = require("devtools/shared/fronts/string");
 const { TargetFactory } = require("devtools/client/framework/target");
 
 const { addDebuggerToGlobal } = ChromeUtils.import(
   "resource://gre/modules/jsdebugger.jsm"
 );
 
+const { AddonTestUtils } = ChromeUtils.import(
+  "resource://testing-common/AddonTestUtils.jsm"
+);
+const { getAppInfo } = ChromeUtils.import(
+  "resource://testing-common/AppInfo.jsm"
+);
+
 const systemPrincipal = Cc["@mozilla.org/systemprincipal;1"].createInstance(
   Ci.nsIPrincipal
 );
 
 var { loadSubScript, loadSubScriptWithOptions } = Services.scriptloader;
 
 /**
  * Initializes any test that needs to work with add-ons.
+ *
+ * Should be called once per test script that needs to use AddonTestUtils (and
+ * not once per test task!).
  */
-function startupAddonsManager() {
+async function startupAddonsManager() {
   // Create a directory for extensions.
   const profileDir = do_get_profile().clone();
   profileDir.append("extensions");
 
-  const internalManager = Cc["@mozilla.org/addons/integration;1"]
-    .getService(Ci.nsIObserver)
-    .QueryInterface(Ci.nsITimerCallback);
+  /* global globalThis */
+  /* See Bug 1595810 to add globalThis to eslint */
+  AddonTestUtils.init(globalThis);
+  AddonTestUtils.overrideCertDB();
+  AddonTestUtils.appInfo = getAppInfo();
 
-  internalManager.observe(null, "addons-startup", null);
+  await AddonTestUtils.promiseStartupManager();
 }
 
 async function createTargetForFakeTab(title) {
   const client = await startTestDebuggerServer(title);
 
   const tabs = await listTabs(client);
   return findTab(tabs, title);
 }
--- a/devtools/server/tests/unit/test_addon_events.js
+++ b/devtools/server/tests/unit/test_addon_events.js
@@ -1,22 +1,21 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 /* eslint-disable no-shadow */
 
 "use strict";
 
 const { AddonManager } = require("resource://gre/modules/AddonManager.jsm");
-
-startupAddonsManager();
-
 add_task(async function testReloadExitedAddon() {
   // Force sync plugin loading to avoid spurious install events from plugins.
   Services.prefs.setBoolPref("plugin.load_flash_only", false);
 
+  await startupAddonsManager();
+
   DebuggerServer.init();
   DebuggerServer.registerAllActors();
 
   const client = new DebuggerClient(DebuggerServer.connectPipe());
   await client.connect();
 
   // Retrieve the current list of addons to be notified of the next list update.
   // We will also call listAddons every time we receive the event "addonListChanged" for
--- a/devtools/server/tests/unit/test_addon_reload.js
+++ b/devtools/server/tests/unit/test_addon_reload.js
@@ -1,18 +1,16 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 /* eslint-disable no-shadow */
 
 "use strict";
 
 const { AddonManager } = require("resource://gre/modules/AddonManager.jsm");
 
-startupAddonsManager();
-
 function promiseAddonEvent(event) {
   return new Promise(resolve => {
     const listener = {
       [event]: function(...args) {
         AddonManager.removeAddonListener(listener);
         resolve(args);
       },
     };
@@ -44,16 +42,18 @@ async function reloadAddon(addonFront) {
 }
 
 function getSupportFile(path) {
   const allowMissing = false;
   return do_get_file(path, allowMissing);
 }
 
 add_task(async function testReloadExitedAddon() {
+  await startupAddonsManager();
+
   DebuggerServer.init();
   DebuggerServer.registerAllActors();
 
   const client = new DebuggerClient(DebuggerServer.connectPipe());
   await client.connect();
 
   // Install our main add-on to trigger reloads on.
   const addonFile = getSupportFile("addons/web-extension");
--- a/devtools/server/tests/unit/test_addons_actor.js
+++ b/devtools/server/tests/unit/test_addons_actor.js
@@ -1,27 +1,31 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 /* eslint-disable no-shadow */
 
 "use strict";
 
-startupAddonsManager();
-
 async function connect() {
   DebuggerServer.init();
   DebuggerServer.registerAllActors();
 
   const client = new DebuggerClient(DebuggerServer.connectPipe());
   await client.connect();
 
   const addons = await client.mainRoot.getFront("addons");
   return [client, addons];
 }
 
+// The AddonsManager test helper can only be called once per test script.
+// This `setup` task will run first.
+add_task(async function setup() {
+  await startupAddonsManager();
+});
+
 add_task(async function testSuccessfulInstall() {
   const [client, addons] = await connect();
 
   const allowMissing = false;
   const usePlatformSeparator = true;
   const addonPath = getFilePath(
     "addons/web-extension",
     allowMissing,