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"
);
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) {

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

@ -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();

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

@ -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();

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

@ -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();

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

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