Bug 1589138 - Make addContentEventListener take an options object for the listener. r=Gijs
authorAndrew McCreight <continuation@gmail.com>
Wed, 16 Oct 2019 17:36:44 +0000
changeset 559244 ca55578623da0eabcacc79af5764ed927d915620
parent 559243 0158a2f1bafc5b4a07905e692ef1938d6b5c0061
child 559245 ea104b51f85e7919614a34e75fea13c188e663d1
push id12175
push userccoroiu@mozilla.com
push dateThu, 17 Oct 2019 19:29:09 +0000
treeherdermozilla-beta@d333b6ef1fd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1589138, 744745, 1058164
milestone71.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 1589138 - Make addContentEventListener take an options object for the listener. r=Gijs All but browser_bug744745.js seem to pass even without the fixes I made, which seems odd. browser_bug1058164.js is a little odd because it passes in {} instead of a boolean for the useCapture argument. I think this ends up calling addEventListener(..., {}, false), which should be the equivalent of addEventListener(..., {}). Differential Revision: https://phabricator.services.mozilla.com/D49453
browser/base/content/test/plugins/browser_bug744745.js
docshell/test/navigation/browser_bug343515.js
dom/base/test/browser_bug1058164.js
testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
toolkit/mozapps/extensions/test/browser/browser_history_navigation.js
--- a/browser/base/content/test/plugins/browser_bug744745.js
+++ b/browser/base/content/test/plugins/browser_bug744745.js
@@ -37,19 +37,17 @@ add_task(async function() {
   gTestBrowser = gBrowser.selectedBrowser;
 
   setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY, "Test Plug-in");
 
   BrowserTestUtils.addContentEventListener(
     gTestBrowser,
     "PluginBindingAttached",
     pluginBindingAttached,
-    true,
-    null,
-    true
+    { capture: true, wantUntrusted: true }
   );
 
   let testRoot = getRootDirectory(gTestPath).replace(
     "chrome://mochitests/content/",
     "http://127.0.0.1:8888/"
   );
   await promiseTabLoadEvent(
     gBrowser.selectedTab,
--- a/docshell/test/navigation/browser_bug343515.js
+++ b/docshell/test/navigation/browser_bug343515.js
@@ -19,17 +19,17 @@ function nShotsListener(aBrowser, aType,
       if (--count == 0) {
         removeFunc();
 
         // aCallback is executed asynchronously, which is handy because load
         // events fire before mIsDocumentLoaded is actually set to true. :(
         executeSoon(aCallback);
       }
     },
-    true
+    { capture: true }
   );
 }
 
 function oneShotListener(aBrowser, aType, aCallback) {
   nShotsListener(aBrowser, aType, aCallback, 1);
 }
 
 function waitForPageshow(aBrowser, callback) {
--- a/dom/base/test/browser_bug1058164.js
+++ b/dom/base/test/browser_bug1058164.js
@@ -55,27 +55,25 @@ function prepareForVisibilityEvents(brow
     let checkFn = e => e.persisted;
 
     rmvHide = BrowserTestUtils.addContentEventListener(
       browser,
       "pagehide",
       () => eventListener("pagehide"),
       {},
       checkFn,
-      false,
-      false
+      /* autoremove = */ false
     );
     rmvShow = BrowserTestUtils.addContentEventListener(
       browser,
       "pageshow",
       () => eventListener("pageshow"),
       {},
       checkFn,
-      false,
-      false
+      /* autoremove = */ false
     );
   });
 }
 
 /**
  * Tests that frame scripts get pageshow / pagehide events when
  * swapping browser frameloaders (which occurs when moving a tab
  * into a different window).
--- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
+++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
@@ -1175,85 +1175,76 @@ var BrowserTestUtils = {
    *
    * @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.
-   * @param {bool} useCapture [optional]
-   *        Whether to use a capturing listener.
+   * @param {object} listenerOptions [optional]
+   *        Options to pass to the event listener.
    * @param {function} checkFn [optional]
    *        Called with the Event object as argument, should return true if the
    *        event is the expected one, or false if it should be ignored and
    *        listening should continue. If not specified, the first event with
    *        the specified name resolves the returned promise. This is called
    *        within the content process and can have no closure environment.
-   * @param {bool} wantsUntrusted [optional]
-   *        Whether to accept untrusted events
    * @param {bool} autoremove [optional]
    *        Whether the listener should be removed when |browser| is removed
    *        from the DOM. Note that, if this flag is true, it won't be possible
    *        to listen for events after a frameloader swap.
    *
    * @returns function
    *        If called, the return value will remove the event listener.
    */
   addContentEventListener(
     browser,
     eventName,
     listener,
-    useCapture = false,
+    listenerOptions = {},
     checkFn,
-    wantsUntrusted = false,
     autoremove = true
   ) {
     let id = gListenerId++;
     let checkFnSource = checkFn
       ? encodeURIComponent(escape(checkFn.toSource()))
       : "";
 
     // To correctly handle frameloader swaps, we load a frame script
     // into all tabs but ignore messages from the ones not related to
     // |browser|.
 
     /* eslint-disable no-eval */
-    function frameScript(
-      id,
-      eventName,
-      useCapture,
-      checkFnSource,
-      wantsUntrusted
-    ) {
+    function frameScript(id, eventName, listenerOptions, checkFnSource) {
       let checkFn;
       if (checkFnSource) {
         checkFn = eval(`(() => (${unescape(checkFnSource)}))()`);
       }
 
       function listener(event) {
         if (checkFn && !checkFn(event)) {
           return;
         }
         sendAsyncMessage("ContentEventListener:Run", id);
       }
       function removeListener(msg) {
         if (msg.data == id) {
           removeMessageListener("ContentEventListener:Remove", removeListener);
-          removeEventListener(eventName, listener, useCapture, wantsUntrusted);
+          removeEventListener(eventName, listener, listenerOptions);
         }
       }
       addMessageListener("ContentEventListener:Remove", removeListener);
-      addEventListener(eventName, listener, useCapture, wantsUntrusted);
+      addEventListener(eventName, listener, listenerOptions);
     }
     /* eslint-enable no-eval */
 
     let frameScriptSource = `data:,(${frameScript.toString()})(${id}, "${eventName}", ${uneval(
-      useCapture
-    )}, "${checkFnSource}", ${wantsUntrusted})`;
+      listenerOptions
+    )}, "${checkFnSource}")`;
 
     let mm = Services.mm;
 
     function runListener(msg) {
       if (msg.data == id && msg.target == browser) {
         listener();
       }
     }
--- a/toolkit/mozapps/extensions/test/browser/browser_history_navigation.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_history_navigation.js
@@ -159,20 +159,19 @@ function wait_for_page_show(browser) {
     let listener = () => {
       removeFunc();
       resolve();
     };
     removeFunc = BrowserTestUtils.addContentEventListener(
       browser,
       "pageshow",
       listener,
-      false,
+      {},
       event => event.target.location == "http://example.com/",
-      false,
-      false
+      /* autoremove = */ false
     );
   });
   return promise;
 }
 
 // Tests simple forward and back navigation and that the right heading and
 // category is selected
 add_task(async function test_navigate_history() {