Bug 1512985: Await result of bootstrap method before returning. r=aswan
authorKris Maglione <maglione.k@gmail.com>
Fri, 04 Jan 2019 12:40:30 +0900
changeset 509635 1979ad1abb92120daf45e949079b1a818b17b285
parent 509602 167735f407393b851817d77915c5d0be05523f23
child 509636 81804f8f55d0b7971a16e7da807799f8de04d01b
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1512985
milestone66.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 1512985: Await result of bootstrap method before returning. r=aswan
toolkit/mozapps/extensions/internal/XPIProvider.jsm
toolkit/mozapps/extensions/test/xpcshell/test_dependencies.js
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -1631,17 +1631,17 @@ class BootstrapScope {
       if (!method) {
         logger.warn(`Add-on ${addon.id} is missing bootstrap method ${aMethod}`);
       } else {
         logger.debug(`Calling bootstrap method ${aMethod} on ${addon.id} version ${addon.version}`);
 
         this._beforeCallBootstrapMethod(aMethod, params, aReason);
 
         try {
-          result = method.call(scope, params, aReason);
+          result = await method.call(scope, params, aReason);
         } catch (e) {
           logger.warn(`Exception running bootstrap method ${aMethod} on ${addon.id}`, e);
         }
       }
       return result;
     } finally {
       // Extensions are automatically initialized in the correct order at startup.
       if (aMethod == "startup" && aReason != BOOTSTRAP_REASONS.APP_STARTUP) {
--- a/toolkit/mozapps/extensions/test/xpcshell/test_dependencies.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_dependencies.js
@@ -27,16 +27,29 @@ const ADDONS = [
     dependencies: ["experiments.addon2"],
   },
 ];
 
 let addonFiles = [];
 
 let events = [];
 
+function promiseAddonStartup(id) {
+  return new Promise(resolve => {
+    const onBootstrapMethod = (event, {method, params}) => {
+      if (method == "startup" && params.id == id) {
+        AddonTestUtils.off("bootstrap-method", onBootstrapMethod);
+        resolve();
+      }
+    };
+
+    AddonTestUtils.on("bootstrap-method", onBootstrapMethod);
+  });
+}
+
 add_task(async function setup() {
   await promiseStartupManager();
 
   const onBootstrapMethod = (event, {method, params}) => {
     if (method == "startup" || method == "shutdown") {
       events.push([method, params.id]);
     }
   };
@@ -68,27 +81,33 @@ add_task(async function() {
   events.length = 0;
 
   await promiseInstallFile(addonFiles[0]);
   deepEqual(events, [], "Should have no events");
 
   await promiseInstallFile(addonFiles[1]);
   deepEqual(events, [], "Should have no events");
 
-  await promiseInstallFile(addonFiles[2]);
+  await Promise.all([
+    promiseInstallFile(addonFiles[2]),
+    promiseAddonStartup(ADDONS[0].id),
+  ]);
 
   deepEqual(events, [
     ["startup", ADDONS[2].id],
     ["startup", ADDONS[1].id],
     ["startup", ADDONS[0].id],
   ]);
 
   events.length = 0;
 
-  await promiseInstallFile(addonFiles[2]);
+  await Promise.all([
+    promiseInstallFile(addonFiles[2]),
+    promiseAddonStartup(ADDONS[0].id),
+  ]);
 
   deepEqual(events, [
     ["shutdown", ADDONS[0].id],
     ["shutdown", ADDONS[1].id],
     ["shutdown", ADDONS[2].id],
 
     ["startup", ADDONS[2].id],
     ["startup", ADDONS[1].id],