From ae692f9401f75249424ca7edb295acc40fa7a8dd Mon Sep 17 00:00:00 2001 From: Julian Descottes Date: Wed, 13 Nov 2019 09:33:49 +0000 Subject: [PATCH] Bug 1543156 - Wait for the addon manager to start in DevTools addons xpcshell tests r=ochameau Differential Revision: https://phabricator.services.mozilla.com/D52535 --HG-- extra : moz-landing-system : lando --- devtools/server/tests/unit/head_dbg.js | 22 ++++++++++++++----- .../server/tests/unit/test_addon_events.js | 5 ++--- .../server/tests/unit/test_addon_reload.js | 4 ++-- .../server/tests/unit/test_addons_actor.js | 8 +++++-- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/devtools/server/tests/unit/head_dbg.js b/devtools/server/tests/unit/head_dbg.js index c0b38ba87522..d1a43b387213 100644 --- a/devtools/server/tests/unit/head_dbg.js +++ b/devtools/server/tests/unit/head_dbg.js @@ -51,6 +51,13 @@ 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 ); @@ -59,17 +66,22 @@ 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) { diff --git a/devtools/server/tests/unit/test_addon_events.js b/devtools/server/tests/unit/test_addon_events.js index c87dd1766024..102add582104 100644 --- a/devtools/server/tests/unit/test_addon_events.js +++ b/devtools/server/tests/unit/test_addon_events.js @@ -5,13 +5,12 @@ "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(); diff --git a/devtools/server/tests/unit/test_addon_reload.js b/devtools/server/tests/unit/test_addon_reload.js index b7307f78aa3a..8f3ad1d4fb55 100644 --- a/devtools/server/tests/unit/test_addon_reload.js +++ b/devtools/server/tests/unit/test_addon_reload.js @@ -6,8 +6,6 @@ const { AddonManager } = require("resource://gre/modules/AddonManager.jsm"); -startupAddonsManager(); - function promiseAddonEvent(event) { return new Promise(resolve => { const listener = { @@ -49,6 +47,8 @@ function getSupportFile(path) { } add_task(async function testReloadExitedAddon() { + await startupAddonsManager(); + DebuggerServer.init(); DebuggerServer.registerAllActors(); diff --git a/devtools/server/tests/unit/test_addons_actor.js b/devtools/server/tests/unit/test_addons_actor.js index 0f6fd854de27..a8bb13b05b94 100644 --- a/devtools/server/tests/unit/test_addons_actor.js +++ b/devtools/server/tests/unit/test_addons_actor.js @@ -4,8 +4,6 @@ "use strict"; -startupAddonsManager(); - async function connect() { DebuggerServer.init(); DebuggerServer.registerAllActors(); @@ -17,6 +15,12 @@ async function connect() { 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();