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
This commit is contained in:
Julian Descottes 2019-11-13 12:29:08 +00:00
Родитель f7f11a5637
Коммит d80bec141d
5 изменённых файлов: 27 добавлений и 16 удалений

Просмотреть файл

@ -51,6 +51,13 @@ const { addDebuggerToGlobal } = ChromeUtils.import(
"resource://gre/modules/jsdebugger.jsm" "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( const systemPrincipal = Cc["@mozilla.org/systemprincipal;1"].createInstance(
Ci.nsIPrincipal Ci.nsIPrincipal
); );
@ -59,17 +66,22 @@ var { loadSubScript, loadSubScriptWithOptions } = Services.scriptloader;
/** /**
* Initializes any test that needs to work with add-ons. * 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. // Create a directory for extensions.
const profileDir = do_get_profile().clone(); const profileDir = do_get_profile().clone();
profileDir.append("extensions"); profileDir.append("extensions");
const internalManager = Cc["@mozilla.org/addons/integration;1"] /* global globalThis */
.getService(Ci.nsIObserver) /* See Bug 1595810 to add globalThis to eslint */
.QueryInterface(Ci.nsITimerCallback); AddonTestUtils.init(globalThis);
AddonTestUtils.overrideCertDB();
AddonTestUtils.appInfo = getAppInfo();
internalManager.observe(null, "addons-startup", null); await AddonTestUtils.promiseStartupManager();
} }
async function createTargetForFakeTab(title) { async function createTargetForFakeTab(title) {

Просмотреть файл

@ -5,13 +5,12 @@
"use strict"; "use strict";
const { AddonManager } = require("resource://gre/modules/AddonManager.jsm"); const { AddonManager } = require("resource://gre/modules/AddonManager.jsm");
startupAddonsManager();
add_task(async function testReloadExitedAddon() { add_task(async function testReloadExitedAddon() {
// Force sync plugin loading to avoid spurious install events from plugins. // Force sync plugin loading to avoid spurious install events from plugins.
Services.prefs.setBoolPref("plugin.load_flash_only", false); Services.prefs.setBoolPref("plugin.load_flash_only", false);
await startupAddonsManager();
DebuggerServer.init(); DebuggerServer.init();
DebuggerServer.registerAllActors(); DebuggerServer.registerAllActors();

Просмотреть файл

@ -6,8 +6,6 @@
const { AddonManager } = require("resource://gre/modules/AddonManager.jsm"); const { AddonManager } = require("resource://gre/modules/AddonManager.jsm");
startupAddonsManager();
function promiseAddonEvent(event) { function promiseAddonEvent(event) {
return new Promise(resolve => { return new Promise(resolve => {
const listener = { const listener = {
@ -49,6 +47,8 @@ function getSupportFile(path) {
} }
add_task(async function testReloadExitedAddon() { add_task(async function testReloadExitedAddon() {
await startupAddonsManager();
DebuggerServer.init(); DebuggerServer.init();
DebuggerServer.registerAllActors(); DebuggerServer.registerAllActors();

Просмотреть файл

@ -4,8 +4,6 @@
"use strict"; "use strict";
startupAddonsManager();
async function connect() { async function connect() {
DebuggerServer.init(); DebuggerServer.init();
DebuggerServer.registerAllActors(); DebuggerServer.registerAllActors();
@ -17,6 +15,12 @@ async function connect() {
return [client, 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() { add_task(async function testSuccessfulInstall() {
const [client, addons] = await connect(); const [client, addons] = await connect();

Просмотреть файл

@ -5,10 +5,6 @@
"use strict"; "use strict";
const { AddonTestUtils } = ChromeUtils.import(
"resource://testing-common/AddonTestUtils.jsm"
);
const { FileUtils } = ChromeUtils.import( const { FileUtils } = ChromeUtils.import(
"resource://gre/modules/FileUtils.jsm" "resource://gre/modules/FileUtils.jsm"
); );