Bug 1588193 - Register the ContentEventListener actor for every browsing context, r=mconley
☠☠ backed out by 5eaefee2f30d ☠ ☠
authorKashav Madan <kmadan@mozilla.com>
Tue, 05 Nov 2019 21:52:23 +0000
changeset 500736 b10ec4058ec3aee7c9cde560a6afeeaca7bce2c9
parent 500735 c90bab12f4cb6fc5baaa43d3f3e14c681b9cd390
child 500737 074bb8a6fd6851f9ebfc68e7505d6e30b4342bdb
push id99802
push userkmadan@mozilla.com
push dateTue, 05 Nov 2019 23:23:46 +0000
treeherderautoland@0bbb1f92bb47 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs1588193
milestone72.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 1588193 - Register the ContentEventListener actor for every browsing context, r=mconley Various BrowserTestUtils.waitForContentEvent call sites expect to see an event on a browser element that was open before the call was made. For this reason, each of the browsers need to also have a ContentEventListener actor. Differential Revision: https://phabricator.services.mozilla.com/D51440
browser/base/content/test/performance/browser_startup_content.js
testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
testing/mochitest/BrowserTestUtils/ContentEventListenerChild.jsm
--- a/browser/base/content/test/performance/browser_startup_content.js
+++ b/browser/base/content/test/performance/browser_startup_content.js
@@ -93,16 +93,17 @@ const intermittently_loaded_whitelist = 
     "resource://specialpowers/WrapPrivileged.jsm",
 
     // Webcompat about:config front-end. This is presently nightly-only and
     // part of a system add-on which may not load early enough for the test.
     "resource://webcompat/AboutCompat.jsm",
 
     // Test related
     "resource://testing-common/BrowserTestUtilsChild.jsm",
+    "resource://testing-common/ContentEventListenerChild.jsm",
   ]),
   frameScripts: new Set([]),
   processScripts: new Set([
     // Webcompat about:config front-end. This is presently nightly-only and
     // part of a system add-on which may not load early enough for the test.
     "resource://webcompat/aboutPageProcessScript.js",
   ]),
 };
--- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
+++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
@@ -72,56 +72,52 @@ registrar.registerFactory(OUR_PROCESSSEL
 // For now, we'll allow tests to use CPOWs in this module for
 // some cases.
 Cu.permitCPOWsInScope(this);
 
 const kAboutPageRegistrationContentScript =
   "chrome://mochikit/content/tests/BrowserTestUtils/content-about-page-utils.js";
 
 /**
- * Create and register BrowserTestUtils Window Actor.
+ * Create and register the BrowserTestUtils and ContentEventListener window
+ * actors.
  */
-function registerActor() {
-  let actorOptions = {
+function registerActors() {
+  ChromeUtils.registerWindowActor("BrowserTestUtils", {
     parent: {
       moduleURI: "resource://testing-common/BrowserTestUtilsParent.jsm",
     },
     child: {
       moduleURI: "resource://testing-common/BrowserTestUtilsChild.jsm",
       events: {
         DOMContentLoaded: { capture: true },
         load: { capture: true },
       },
     },
     allFrames: true,
     includeChrome: true,
-  };
-  ChromeUtils.registerWindowActor("BrowserTestUtils", actorOptions);
-}
+  });
 
-function registerContentEventListenerActor() {
-  let actorOptions = {
+  ChromeUtils.registerWindowActor("ContentEventListener", {
     parent: {
       moduleURI: "resource://testing-common/ContentEventListenerParent.jsm",
     },
-
     child: {
       moduleURI: "resource://testing-common/ContentEventListenerChild.jsm",
       events: {
         // We need to see the creation of all new windows, in case they have
-        // a browsing context we are interesting in.
+        // a browsing context we are interested in.
         DOMWindowCreated: { capture: true },
       },
     },
     allFrames: true,
-  };
-  ChromeUtils.registerWindowActor("ContentEventListener", actorOptions);
+  });
 }
 
-registerActor();
+registerActors();
 
 var BrowserTestUtils = {
   /**
    * Loads a page in a new tab, executes a Task and closes the tab.
    *
    * @param options
    *        An object  or string.
    *        If this is a string it is the url to open and will be opened in the
@@ -522,18 +518,16 @@ var BrowserTestUtils = {
   },
 
   _webProgressListeners: new Set(),
 
   _contentEventListenerSharedState: new Map(),
 
   _contentEventListeners: new Map(),
 
-  _contentEventListenerActorRegistered: false,
-
   /**
    * Waits for the web progress listener associated with this tab to fire a
    * STATE_STOP for the toplevel document.
    *
    * @param {xul:browser} browser
    *        A xul:browser.
    * @param {String} expectedURI (optional)
    *        A specific URL to check the channel load against
@@ -1233,20 +1227,16 @@ var BrowserTestUtils = {
   },
 
   /**
    * Adds a content event listener on the given browser
    * element. Similar to waitForContentEvent, but the listener will
    * fire until it is removed. A callable object is returned that,
    * when called, removes the event listener. Note that this function
    * works even if the browser's frameloader is swapped.
-   * Note: This will only listen for events that either have the browsing
-   * context of the browser element at the time of the call, or that are fired
-   * on windows that were created after any call to the function since the start
-   * of the test. This could be improved if needed.
    *
    * @param {xul:browser} browser
    *        The browser element to listen for events in.
    * @param {string} eventName
    *        Name of the event to listen to.
    * @param {function} listener
    *        Function to call in parent process when event fires.
    *        Not passed any arguments.
@@ -1281,45 +1271,16 @@ var BrowserTestUtils = {
     });
 
     Services.ppmm.sharedData.set(
       "BrowserTestUtils:ContentEventListener",
       eventListenerState
     );
     Services.ppmm.sharedData.flush();
 
-    if (!this._contentEventListenerActorRegistered) {
-      this._contentEventListenerActorRegistered = true;
-      registerContentEventListenerActor();
-
-      // We hadn't registered the actor yet, so any existing window
-      // for browser's BC will not have been created yet. Explicitly
-      // make sure the actors are created and ready to go now. This
-      // happens after the updating of sharedData so that the actors
-      // don't have to get created and do nothing, and then later have
-      // to be updated.
-      // Note: As mentioned in the comment at the start of this function,
-      // this will miss any windows that existed at the time that the function
-      // was initially called during this test, but that did not have the
-      // browser's browsing context.
-      let contextsToVisit = [browser.browsingContext];
-      while (contextsToVisit.length) {
-        let currentContext = contextsToVisit.pop();
-        let global = currentContext.currentWindowGlobal;
-        if (!global) {
-          continue;
-        }
-        let actor = browser.browsingContext.currentWindowGlobal.getActor(
-          "ContentEventListener"
-        );
-        actor.sendAsyncMessage("ContentEventListener:LateCreate");
-        contextsToVisit.push(...currentContext.getChildren());
-      }
-    }
-
     let unregisterFunction = function() {
       if (!eventListenerState.has(id)) {
         return;
       }
       eventListenerState.delete(id);
       contentEventListeners.delete(id);
       Services.ppmm.sharedData.set(
         "BrowserTestUtils:ContentEventListener",
--- a/testing/mochitest/BrowserTestUtils/ContentEventListenerChild.jsm
+++ b/testing/mochitest/BrowserTestUtils/ContentEventListenerChild.jsm
@@ -20,23 +20,16 @@ class ContentEventListenerChild extends 
     this._shutdown = true;
     Services.cpmm.sharedData.removeEventListener("change", this);
     this._updateContentEventListeners(/* clearListeners = */ true);
     if (this._contentEvents.size != 0) {
       throw new Error(`Didn't expect content events after willDestroy`);
     }
   }
 
-  receiveMessage(msg) {
-    if (msg.name != "ContentEventListener:LateCreate") {
-      return;
-    }
-    this._updateContentEventListeners();
-  }
-
   handleEvent(event) {
     switch (event.type) {
       case "DOMWindowCreated": {
         this._updateContentEventListeners();
         break;
       }
 
       case "change": {