Bug 1442312 - Wait for addon reload to finish in tests. r=jdescottes
authorJ. Ryan Stinnett <jryans@gmail.com>
Thu, 08 Mar 2018 19:05:32 -0600
changeset 460012 bedc6f6583bf50e57135d20af8b75c5138a655e8
parent 460011 3ca7ee7f010fbb8e85fbe5dc71edfe61fa15c8dd
child 460013 37e3ec770550abec14beb8eb9939da78d578a2bb
push id8824
push userarchaeopteryx@coole-files.de
push dateMon, 12 Mar 2018 14:54:48 +0000
treeherdermozilla-beta@8d9daab95d68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdescottes
bugs1442312
milestone60.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 1442312 - Wait for addon reload to finish in tests. r=jdescottes In about:debugging's browser_addon_reload.js test, we would request a reload without waiting for it to reply. This led to the RDP connection closing before the reply could be sent, triggering later errors. For better test correctness, we now emit an event on reply and the test waits to receive it before proceeding. MozReview-Commit-ID: Jfps7MJ6Pzo
devtools/client/aboutdebugging/components/addons/Target.js
devtools/client/aboutdebugging/initializer.js
devtools/client/aboutdebugging/test/browser_addons_reload.js
--- a/devtools/client/aboutdebugging/components/addons/Target.js
+++ b/devtools/client/aboutdebugging/components/addons/Target.js
@@ -188,27 +188,28 @@ class AddonTarget extends Component {
     }
   }
 
   uninstall() {
     let { target } = this.props;
     uninstallAddon(target.addonID);
   }
 
-  reload() {
+  async reload() {
     let { client, target } = this.props;
-    // This function sometimes returns a partial promise that only
-    // implements then().
-    client.request({
-      to: target.addonActor,
-      type: "reload"
-    }).then(() => {}, error => {
-      throw new Error(
-        "Error reloading addon " + target.addonID + ": " + error);
-    });
+    let { AboutDebugging } = window;
+    try {
+      await client.request({
+        to: target.addonActor,
+        type: "reload"
+      });
+      AboutDebugging.emit("addon-reload");
+    } catch (e) {
+      throw new Error("Error reloading addon " + target.addonID + ": " + e.message);
+    }
   }
 
   render() {
     let { target, debugDisabled } = this.props;
 
     return dom.li(
       { className: "addon-target-container", "data-addon-id": target.addonID },
       dom.div({ className: "target" },
--- a/devtools/client/aboutdebugging/initializer.js
+++ b/devtools/client/aboutdebugging/initializer.js
@@ -19,16 +19,17 @@ loader.lazyRequireGetter(this, "Telemetr
 
 const { require } = BrowserLoader({
   baseURI: "resource://devtools/client/aboutdebugging/",
   window
 });
 
 const { createFactory } = require("devtools/client/shared/vendor/react");
 const { render, unmountComponentAtNode } = require("devtools/client/shared/vendor/react-dom");
+const EventEmitter = require("devtools/shared/event-emitter");
 
 const AboutDebuggingApp = createFactory(require("./components/Aboutdebugging"));
 const { createClient } = require("./modules/connect");
 
 var AboutDebugging = {
   async init() {
     if (!Services.prefs.getBoolPref("devtools.enabled", true)) {
       // If DevTools are disabled, navigate to about:devtools.
@@ -52,15 +53,18 @@ var AboutDebugging = {
 
     if (this.client) {
       this.client.close();
       this.client = null;
     }
   },
 };
 
+// Used to track async requests in tests.  See bug 1444424 for better ideas.
+EventEmitter.decorate(AboutDebugging);
+
 window.addEventListener("DOMContentLoaded", function () {
   AboutDebugging.init();
 }, {once: true});
 
 window.addEventListener("unload", function () {
   AboutDebugging.destroy();
 }, {once: true});
--- a/devtools/client/aboutdebugging/test/browser_addons_reload.js
+++ b/devtools/client/aboutdebugging/test/browser_addons_reload.js
@@ -56,17 +56,18 @@ class TempWebExt {
   }
 
   remove() {
     return this.tmpDir.remove(true);
   }
 }
 
 add_task(function* reloadButtonReloadsAddon() {
-  const { tab, document } = yield openAboutDebugging("addons");
+  const { tab, document, window } = yield openAboutDebugging("addons");
+  const { AboutDebugging } = window;
   yield waitForInitialAddonList(document);
   yield installAddon({
     document,
     path: "addons/unpacked/install.rdf",
     name: ADDON_NAME,
   });
 
   const reloadButton = getReloadButton(document, ADDON_NAME);
@@ -76,29 +77,32 @@ add_task(function* reloadButtonReloadsAd
   const onBootstrapInstallCalled = new Promise(done => {
     Services.obs.addObserver(function listener() {
       Services.obs.removeObserver(listener, ADDON_NAME);
       info("Add-on was re-installed: " + ADDON_NAME);
       done();
     }, ADDON_NAME);
   });
 
+  let reloaded = once(AboutDebugging, "addon-reload");
   reloadButton.click();
+  yield reloaded;
 
   const [reloadedAddon] = yield onInstalled;
   is(reloadedAddon.name, ADDON_NAME,
      "Add-on was reloaded: " + reloadedAddon.name);
 
   yield onBootstrapInstallCalled;
   yield tearDownAddon(reloadedAddon);
   yield closeAboutDebugging(tab);
 });
 
 add_task(function* reloadButtonRefreshesMetadata() {
-  const { tab, document } = yield openAboutDebugging("addons");
+  const { tab, document, window } = yield openAboutDebugging("addons");
+  const { AboutDebugging } = window;
   yield waitForInitialAddonList(document);
 
   const manifestBase = {
     "manifest_version": 2,
     "name": "Temporary web extension",
     "version": "1.0",
     "applications": {
       "gecko": {
@@ -120,17 +124,19 @@ add_task(function* reloadButtonRefreshes
   yield waitUntilAddonContainer("Temporary web extension", document);
 
   const newName = "Temporary web extension (updated)";
   tempExt.writeManifest(Object.assign({}, manifestBase, {name: newName}));
 
   // Wait for the add-on list to be updated with the reloaded name.
   const onReInstall = promiseAddonEvent("onInstalled");
   const reloadButton = getReloadButton(document, manifestBase.name);
+  let reloaded = once(AboutDebugging, "addon-reload");
   reloadButton.click();
+  yield reloaded;
 
   info("Wait until addon onInstalled event is received again");
   const [reloadedAddon] = yield onReInstall;
 
   info("Wait until addon name is updated in about:debugging#addons");
   yield waitUntilAddonContainer(newName, document);
 
   yield tearDownAddon(reloadedAddon);