From ad31645d259608922eeb62ec68bf051e994c36b0 Mon Sep 17 00:00:00 2001 From: Andrew Swan Date: Mon, 30 Jul 2018 17:03:27 -0700 Subject: [PATCH] Bug 1451513 Part 3: Make loading the mochitest extension more robust r=kmag A couple of changes to ensure that the mochitest harness doesn't try to start executing changes before the mochitest extension is loaded: 1. Fix the marionette driver to wait for an installed extension to be started before returning from Addon:install 2. Wait for extension API onStartup() handlers to finish before considering a webextension started. MozReview-Commit-ID: 8YEdNn6s5qh --HG-- extra : rebase_source : 67e9abadcda82d55ac73c33367ec65cdbf7b823d --- testing/marionette/addon.js | 35 +++------------------ toolkit/components/extensions/Extension.jsm | 6 ++-- 2 files changed, 9 insertions(+), 32 deletions(-) diff --git a/testing/marionette/addon.js b/testing/marionette/addon.js index 290c448ebdc6..b465fd371099 100644 --- a/testing/marionette/addon.js +++ b/testing/marionette/addon.js @@ -23,37 +23,12 @@ const ERRORS = { async function installAddon(file) { let install = await AddonManager.getInstallForFile(file); - return new Promise(resolve => { - if (install.error) { - throw new UnknownError(ERRORS[install.error]); - } + if (install.error) { + throw new UnknownError(ERRORS[install.error]); + } - let addonId = install.addon.id; - - let success = install => { - if (install.addon.id === addonId) { - install.removeListener(listener); - resolve(install.addon); - } - }; - - let fail = install => { - if (install.addon.id === addonId) { - install.removeListener(listener); - throw new UnknownError(ERRORS[install.error]); - } - }; - - let listener = { - onDownloadCancelled: fail, - onDownloadFailed: fail, - onInstallCancelled: fail, - onInstallFailed: fail, - onInstallEnded: success, - }; - - install.addListener(listener); - install.install(); + return install.install().catch(err => { + throw new UnknownError(ERRORS[install.error]); }); } diff --git a/toolkit/components/extensions/Extension.jsm b/toolkit/components/extensions/Extension.jsm index 3bf798da45cb..3b0cdf850094 100644 --- a/toolkit/components/extensions/Extension.jsm +++ b/toolkit/components/extensions/Extension.jsm @@ -1778,9 +1778,11 @@ class Extension extends ExtensionData { // and it is used to run code that needs to be executed before // any of the "startup" listeners. this.emit("startup", this); - Management.emit("startup", this); - await this.runManifest(this.manifest); + await Promise.all([ + Management.emit("startup", this), + this.runManifest(this.manifest), + ]); Management.emit("ready", this); this.emit("ready");