Bug 1436665 - Do not fire events on window, update tests; r=ochameau
☠☠ backed out by 00d4c3be380c ☠ ☠
authorJan Odvarko <odvarko@gmail.com>
Fri, 13 Apr 2018 15:51:03 +0200
changeset 467543 513c72b05382c41171f49f81b0a799a6cfc132ad
parent 467542 4b8fe40857db84a50f456815f36c2a583fc1ccaa
child 467544 09030f59fbeae4360be8c46d7e85ff32e9c00201
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1436665
milestone61.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 1436665 - Do not fire events on window, update tests; r=ochameau MozReview-Commit-ID: K5xd0UmyKb
browser/components/extensions/test/browser/browser_ext_devtools_network.js
devtools/client/netmonitor/initializer.js
devtools/client/netmonitor/src/connector/firefox-connector.js
devtools/client/netmonitor/src/connector/firefox-data-provider.js
devtools/client/netmonitor/test/browser_net_brotli.js
devtools/client/netmonitor/test/browser_net_columns_time.js
devtools/client/netmonitor/test/browser_net_content-type.js
devtools/client/netmonitor/test/browser_net_pane-toggle.js
devtools/client/netmonitor/test/browser_net_pause.js
devtools/client/netmonitor/test/browser_net_security-tab-visibility.js
devtools/client/netmonitor/test/browser_net_simple-request-data.js
devtools/client/netmonitor/test/browser_net_simple-request-details.js
devtools/client/netmonitor/test/head.js
devtools/client/webconsole/test/mochitest/browser_webconsole_network_attach.js
--- a/browser/components/extensions/test/browser/browser_ext_devtools_network.js
+++ b/browser/components/extensions/test/browser/browser_ext_devtools_network.js
@@ -77,17 +77,17 @@ function devtools_page() {
     browser.devtools.network.onRequestFinished.removeListener(requestFinishedListener);
   };
   browser.devtools.network.onRequestFinished.addListener(requestFinishedListener);
 }
 
 function waitForRequestAdded(toolbox) {
   return new Promise(resolve => {
     let netPanel = toolbox.getPanel("netmonitor");
-    netPanel.panelWin.once("NetMonitor:RequestAdded", () => {
+    netPanel.panelWin.api.once("NetMonitor:RequestAdded", () => {
       resolve();
     });
   });
 }
 
 let extData = {
   background,
   manifest: {
--- a/devtools/client/netmonitor/initializer.js
+++ b/devtools/client/netmonitor/initializer.js
@@ -29,16 +29,17 @@ EventEmitter.decorate(window);
  *
  * @param {Object} api Allows reusing existing API object.
  */
 function initialize(api) {
   const app = new NetMonitorApp(api);
 
   // Inject to global window for testing
   window.Netmonitor = app;
+  window.api = api;
   window.store = app.api.store;
   window.connector = app.api.connector;
   window.actions = app.api.actions;
 
   return app;
 }
 
 /**
--- a/devtools/client/netmonitor/src/connector/firefox-connector.js
+++ b/devtools/client/netmonitor/src/connector/firefox-connector.js
@@ -409,17 +409,12 @@ class FirefoxConnector {
 
   /**
    * Fire events for the owner object.
    */
   emit(type, data) {
     if (this.owner) {
       this.owner.emit(type, data);
     }
-
-    // Consumed mainly by tests.
-    if (typeof window != "undefined") {
-      window.emit(type, data);
-    }
   }
 }
 
 module.exports = FirefoxConnector;
--- a/devtools/client/netmonitor/src/connector/firefox-data-provider.js
+++ b/devtools/client/netmonitor/src/connector/firefox-data-provider.js
@@ -622,17 +622,12 @@ class FirefoxDataProvider {
 
   /**
    * Fire events for the owner object.
    */
   emit(type, data) {
     if (this.owner) {
       this.owner.emit(type, data);
     }
-
-    // Consumed mainly by tests.
-    if (typeof window != "undefined") {
-      window.emit(type, data);
-    }
   }
 }
 
 module.exports = FirefoxDataProvider;
--- a/devtools/client/netmonitor/test/browser_net_brotli.js
+++ b/devtools/client/netmonitor/test/browser_net_brotli.js
@@ -43,17 +43,17 @@ add_task(async function() {
       type: "plain",
       fullMimeType: "text/plain",
       transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 60),
       size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 64),
       time: true
     });
 
   wait = waitForDOM(document, ".CodeMirror-code");
-  let onResponseContent = monitor.panelWin.once(EVENTS.RECEIVED_RESPONSE_CONTENT);
+  let onResponseContent = monitor.panelWin.api.once(EVENTS.RECEIVED_RESPONSE_CONTENT);
   store.dispatch(Actions.toggleNetworkDetails());
   EventUtils.sendMouseEvent({ type: "click" },
     document.querySelector("#response-tab"));
   await wait;
   await onResponseContent;
   await testResponse("br");
   await teardown(monitor);
 
--- a/devtools/client/netmonitor/test/browser_net_columns_time.js
+++ b/devtools/client/netmonitor/test/browser_net_columns_time.js
@@ -27,17 +27,17 @@ add_task(async function() {
 
   ["endTime", "responseTime", "duration", "latency"].forEach(async (column) => {
     if (!visibleColumns[column]) {
       await showColumn(monitor, column);
     }
   });
 
   let onNetworkEvents = waitForNetworkEvents(monitor, 1);
-  let onEventTimings = waitFor(monitor.panelWin, EVENTS.RECEIVED_EVENT_TIMINGS);
+  let onEventTimings = waitFor(monitor.panelWin.api, EVENTS.RECEIVED_EVENT_TIMINGS);
   tab.linkedBrowser.reload();
   await Promise.all([onNetworkEvents, onEventTimings]);
 
   // There should be one request in the list.
   let requestItems = document.querySelectorAll(".request-list-item");
   is(requestItems.length, 1, "There must be one visible item");
 
   let item = requestItems[0];
--- a/devtools/client/netmonitor/test/browser_net_content-type.js
+++ b/devtools/client/netmonitor/test/browser_net_content-type.js
@@ -263,30 +263,30 @@ add_task(async function() {
         is(text, new Array(1000).join("Hello gzip!"),
           "The text shown in the source editor is incorrect for the gzip request.");
         break;
       }
     }
   }
 
   async function selectIndexAndWaitForJSONView(index) {
-    let onResponseContent = monitor.panelWin.once(EVENTS.RECEIVED_RESPONSE_CONTENT);
+    let onResponseContent = monitor.panelWin.api.once(EVENTS.RECEIVED_RESPONSE_CONTENT);
     let tabpanel = document.querySelector("#response-panel");
     let waitDOM = waitForDOM(tabpanel, ".treeTable");
     store.dispatch(Actions.selectRequestByIndex(index));
     await waitDOM;
     await onResponseContent;
 
     // Waiting for RECEIVED_RESPONSE_CONTENT isn't enough.
     // DOM may not be fully updated yet and checkVisibility(json) may still fail.
     await waitForTick();
   }
 
   async function selectIndexAndWaitForImageView(index) {
-    let onResponseContent = monitor.panelWin.once(EVENTS.RECEIVED_RESPONSE_CONTENT);
+    let onResponseContent = monitor.panelWin.api.once(EVENTS.RECEIVED_RESPONSE_CONTENT);
     let tabpanel = document.querySelector("#response-panel");
     let waitDOM = waitForDOM(tabpanel, ".response-image");
     store.dispatch(Actions.selectRequestByIndex(index));
     let [imageNode] = await waitDOM;
     await once(imageNode, "load");
     await onResponseContent;
   }
 });
--- a/devtools/client/netmonitor/test/browser_net_pane-toggle.js
+++ b/devtools/client/netmonitor/test/browser_net_pane-toggle.js
@@ -23,17 +23,17 @@ add_task(async function() {
 
   ok(!document.querySelector(".sidebar-toggle"),
     "The pane toggle button should not be visible.");
   is(!!document.querySelector(".network-details-panel"), false,
     "The details pane should be hidden when the frontend is opened.");
   is(getSelectedRequest(store.getState()), null,
     "There should be no selected item in the requests menu.");
 
-  let networkEvent = monitor.panelWin.once(EVENTS.NETWORK_EVENT);
+  let networkEvent = monitor.panelWin.api.once(EVENTS.NETWORK_EVENT);
   tab.linkedBrowser.reload();
   await networkEvent;
 
   ok(!document.querySelector(".sidebar-toggle"),
     "The pane toggle button should not be visible after the first request.");
   is(!!document.querySelector(".network-details-panel"), false,
     "The details pane should still be hidden after the first request.");
   is(getSelectedRequest(store.getState()), null,
--- a/devtools/client/netmonitor/test/browser_net_pause.js
+++ b/devtools/client/netmonitor/test/browser_net_pause.js
@@ -19,21 +19,21 @@ add_task(async function() {
   // Make sure we start in a sane state.
   assertRequestCount(store, 0);
 
   // Load one request and assert it shows up in the list.
   await performRequestAndWait(tab, monitor);
   assertRequestCount(store, 1);
 
   let noRequest = true;
-  monitor.panelWin.once(EVENTS.NETWORK_EVENT, () => {
+  monitor.panelWin.api.once(EVENTS.NETWORK_EVENT, () => {
     noRequest = false;
   });
 
-  monitor.panelWin.once(EVENTS.NETWORK_EVENT_UPDATED, () => {
+  monitor.panelWin.api.once(EVENTS.NETWORK_EVENT_UPDATED, () => {
     noRequest = false;
   });
 
   // Click pause, load second request and make sure they don't show up.
   EventUtils.sendMouseEvent({ type: "click" }, pauseButton);
   await performPausedRequest(connector, tab, monitor);
   ok(noRequest, "There should be no activity when paused.");
   assertRequestCount(store, 1);
--- a/devtools/client/netmonitor/test/browser_net_security-tab-visibility.js
+++ b/devtools/client/netmonitor/test/browser_net_security-tab-visibility.js
@@ -36,17 +36,17 @@ add_task(async function() {
   let Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
   let { getSelectedRequest } =
     windowRequire("devtools/client/netmonitor/src/selectors/index");
 
   store.dispatch(Actions.batchEnable(false));
 
   for (let testcase of TEST_DATA) {
     info("Testing Security tab visibility for " + testcase.desc);
-    let onNewItem = monitor.panelWin.once(EVENTS.NETWORK_EVENT);
+    let onNewItem = monitor.panelWin.api.once(EVENTS.NETWORK_EVENT);
     let onComplete = testcase.isBroken ?
                        waitForSecurityBrokenNetworkEvent() :
                        waitForNetworkEvents(monitor, 1);
 
     info("Performing a request to " + testcase.uri);
     await ContentTask.spawn(tab.linkedBrowser, testcase.uri, async function(url) {
       content.wrappedJSObject.performRequests(1, url);
     });
@@ -101,14 +101,14 @@ add_task(async function() {
    */
   function waitForSecurityBrokenNetworkEvent() {
     let awaitedEvents = [
       "UPDATING_EVENT_TIMINGS",
       "RECEIVED_EVENT_TIMINGS",
     ];
 
     let promises = awaitedEvents.map((event) => {
-      return monitor.panelWin.once(EVENTS[event]);
+      return monitor.panelWin.api.once(EVENTS[event]);
     });
 
     return Promise.all(promises);
   }
 });
--- a/devtools/client/netmonitor/test/browser_net_simple-request-data.js
+++ b/devtools/client/netmonitor/test/browser_net_simple-request-data.js
@@ -29,17 +29,17 @@ function test() {
 
     store.dispatch(Actions.batchEnable(false));
 
     let promiseList = [];
     promiseList.push(waitForNetworkEvents(monitor, 1));
 
     function expectEvent(evt, cb) {
       promiseList.push(new Promise((resolve, reject) => {
-        monitor.panelWin.once(evt, _ => {
+        monitor.panelWin.api.once(evt, _ => {
           cb().then(resolve, reject);
         });
       }));
     }
 
     expectEvent(EVENTS.NETWORK_EVENT, async () => {
       is(getSelectedRequest(store.getState()), null,
         "There shouldn't be any selected item in the requests menu.");
@@ -146,17 +146,17 @@ function test() {
         document,
         getDisplayedRequests(store.getState()),
         requestItem,
         "GET",
         SIMPLE_SJS
       );
     });
 
-    monitor.panelWin.once(EVENTS.RECEIVED_REQUEST_POST_DATA, () => {
+    monitor.panelWin.api.once(EVENTS.RECEIVED_REQUEST_POST_DATA, () => {
       ok(false, "Trap listener: this request doesn't have any post data.");
     });
 
     expectEvent(EVENTS.RECEIVED_RESPONSE_HEADERS, async () => {
       await waitUntil(() => {
         let requestItem = getSortedRequests(store.getState()).get(0);
         return requestItem && requestItem.responseHeaders;
       });
--- a/devtools/client/netmonitor/test/browser_net_simple-request-details.js
+++ b/devtools/client/netmonitor/test/browser_net_simple-request-details.js
@@ -156,17 +156,17 @@ add_task(async function() {
       .getAttribute("value"),
       "Cache-Control", "The last request header name was incorrect.");
     is(requestScope.querySelectorAll(".variables-view-variable .value")[8]
       .getAttribute("value"),
       "\"no-cache\"", "The last request header value was incorrect.");
   }
 
   async function testCookiesTab() {
-    let onEvent = monitor.panelWin.once(EVENTS.TAB_UPDATED);
+    let onEvent = monitor.panelWin.api.once(EVENTS.TAB_UPDATED);
     EventUtils.sendMouseEvent({ type: "mousedown" },
       document.querySelectorAll("#details-pane tab")[1]);
     await onEvent;
 
     let tabEl = document.querySelectorAll("#details-pane tab")[1];
     let tabpanel = document.querySelectorAll("#details-pane tabpanel")[1];
 
     is(tabEl.getAttribute("selected"), "true",
@@ -199,17 +199,17 @@ add_task(async function() {
       .hasAttribute("hidden"), false,
       "The request params box should not be hidden.");
     is(tabpanel.querySelector("#request-post-data-textarea-box")
       .hasAttribute("hidden"), true,
       "The request post data textarea box should be hidden.");
   }
 
   async function testResponseTab() {
-    let onEvent = monitor.panelWin.once(EVENTS.TAB_UPDATED);
+    let onEvent = monitor.panelWin.api.once(EVENTS.TAB_UPDATED);
     EventUtils.sendMouseEvent({ type: "mousedown" },
       document.querySelectorAll("#details-pane tab")[3]);
     await onEvent;
 
     let tabEl = document.querySelectorAll("#details-pane tab")[3];
     let tabpanel = document.querySelectorAll("#details-pane tabpanel")[3];
 
     is(tabEl.getAttribute("selected"), "true",
--- a/devtools/client/netmonitor/test/head.js
+++ b/devtools/client/netmonitor/test/head.js
@@ -150,23 +150,23 @@ function toggleCache(target, disabled) {
 function waitForTimelineMarkers(monitor) {
   return new Promise(resolve => {
     let markers = [];
 
     function handleTimelineEvent(marker) {
       info(`Got marker: ${marker.name}`);
       markers.push(marker);
       if (markers.length == 2) {
-        monitor.panelWin.off(EVENTS.TIMELINE_EVENT, handleTimelineEvent);
+        monitor.panelWin.api.off(EVENTS.TIMELINE_EVENT, handleTimelineEvent);
         info("Got two timeline markers, done waiting");
         resolve(markers);
       }
     }
 
-    monitor.panelWin.on(EVENTS.TIMELINE_EVENT, handleTimelineEvent);
+    monitor.panelWin.api.on(EVENTS.TIMELINE_EVENT, handleTimelineEvent);
   });
 }
 
 /**
  * Start monitoring all incoming update events about network requests and wait until
  * a complete info about all requests is received. (We wait for the timings info
  * explicitly, because that's always the last piece of information that is received.)
  *
@@ -207,24 +207,24 @@ function waitForAllRequestsFinished(moni
 
     function maybeResolve() {
       // Have all the requests in the map finished yet?
       if (![...requests.values()].every(finished => finished)) {
         return;
       }
 
       // All requests are done - unsubscribe from events and resolve!
-      window.off(EVENTS.NETWORK_EVENT, onRequest);
-      window.off(EVENTS.PAYLOAD_READY, onTimings);
+      window.api.off(EVENTS.NETWORK_EVENT, onRequest);
+      window.api.off(EVENTS.PAYLOAD_READY, onTimings);
       info("All requests finished");
       resolve();
     }
 
-    window.on(EVENTS.NETWORK_EVENT, onRequest);
-    window.on(EVENTS.PAYLOAD_READY, onTimings);
+    window.api.on(EVENTS.NETWORK_EVENT, onRequest);
+    window.api.on(EVENTS.PAYLOAD_READY, onTimings);
   });
 }
 
 let finishedQueue = {};
 let updatingTypes = [
   "NetMonitor:NetworkEventUpdating:RequestCookies",
   "NetMonitor:NetworkEventUpdating:ResponseCookies",
   "NetMonitor:NetworkEventUpdating:RequestHeaders",
@@ -243,22 +243,22 @@ let updatedTypes = [
   "NetMonitor:NetworkEventUpdated:ResponseContent",
   "NetMonitor:NetworkEventUpdated:SecurityInfo",
   "NetMonitor:NetworkEventUpdated:EventTimings",
 ];
 
 // Start collecting all networkEventUpdate event when panel is opened.
 // removeTab() should be called once all corresponded RECEIVED_* events finished.
 function startNetworkEventUpdateObserver(panelWin) {
-  updatingTypes.forEach((type) => panelWin.on(type, actor => {
+  updatingTypes.forEach((type) => panelWin.api.on(type, actor => {
     let key = actor + "-" + updatedTypes[updatingTypes.indexOf(type)];
     finishedQueue[key] = finishedQueue[key] ? finishedQueue[key] + 1 : 1;
   }));
 
-  updatedTypes.forEach((type) => panelWin.on(type, actor => {
+  updatedTypes.forEach((type) => panelWin.api.on(type, actor => {
     let key = actor + "-" + type;
     finishedQueue[key] = finishedQueue[key] ? finishedQueue[key] - 1 : -1;
   }));
 }
 
 async function waitForAllNetworkUpdateEvents() {
   function checkNetworkEventUpdateState() {
     for (let key in finishedQueue) {
@@ -384,24 +384,24 @@ function waitForNetworkEvents(monitor, g
     function maybeResolve(event, actor, networkInfo) {
       info("> Network event progress: " +
         "NetworkEvent: " + networkEvent + "/" + getRequests + ", " +
         "PayloadReady: " + payloadReady + "/" + getRequests + ", " +
         "got " + event + " for " + actor);
 
       // Wait until networkEvent & payloadReady finish for each request.
       if (networkEvent >= getRequests && payloadReady >= getRequests) {
-        panel.off(EVENTS.NETWORK_EVENT, onNetworkEvent);
-        panel.off(EVENTS.PAYLOAD_READY, onPayloadReady);
+        panel.api.off(EVENTS.NETWORK_EVENT, onNetworkEvent);
+        panel.api.off(EVENTS.PAYLOAD_READY, onPayloadReady);
         executeSoon(resolve);
       }
     }
 
-    panel.on(EVENTS.NETWORK_EVENT, onNetworkEvent);
-    panel.on(EVENTS.PAYLOAD_READY, onPayloadReady);
+    panel.api.on(EVENTS.NETWORK_EVENT, onNetworkEvent);
+    panel.api.on(EVENTS.PAYLOAD_READY, onPayloadReady);
   });
 }
 
 function verifyRequestItemTarget(document, requestList, requestItem, method,
                                  url, data = {}) {
   info("> Verifying: " + method + " " + url + " " + data.toSource());
 
   let visibleIndex = requestList.indexOf(requestItem);
@@ -558,17 +558,17 @@ function verifyRequestItemTarget(documen
       ok(!target.classList.contains("even"), "Item shouldn't have 'even' class.");
       ok(target.classList.contains("odd"), "Item should have 'odd' class.");
     }
   }
 }
 
 /**
  * Helper function for waiting for an event to fire before resolving a promise.
- * Example: waitFor(aMonitor.panelWin, EVENT_NAME);
+ * Example: waitFor(aMonitor.panelWin.api, EVENT_NAME);
  *
  * @param object subject
  *        The event emitter object that is being listened to.
  * @param string eventName
  *        The name of the event to listen to.
  * @return object
  *        Returns a promise that resolves upon firing of the event.
  */
@@ -732,17 +732,17 @@ async function showColumn(monitor, colum
 
 /**
  * Select a request and switch to its response panel.
  *
  * @param {Number} index The request index to be selected
  */
 async function selectIndexAndWaitForSourceEditor(monitor, index) {
   let document = monitor.panelWin.document;
-  let onResponseContent = monitor.panelWin.once(EVENTS.RECEIVED_RESPONSE_CONTENT);
+  let onResponseContent = monitor.panelWin.api.once(EVENTS.RECEIVED_RESPONSE_CONTENT);
   // Select the request first, as it may try to fetch whatever is the current request's
   // responseContent if we select the ResponseTab first.
   EventUtils.sendMouseEvent({ type: "mousedown" },
     document.querySelectorAll(".request-list-item")[index]);
   // We may already be on the ResponseTab, so only select it if needed.
   let editor = document.querySelector("#response-panel .CodeMirror-code");
   if (!editor) {
     let waitDOM = waitForDOM(document, "#response-panel .CodeMirror-code");
--- a/devtools/client/webconsole/test/mochitest/browser_webconsole_network_attach.js
+++ b/devtools/client/webconsole/test/mochitest/browser_webconsole_network_attach.js
@@ -13,17 +13,17 @@ add_task(async function task() {
   await pushPref("devtools.webconsole.filter.netxhr", true);
   await openNewTabAndToolbox(TEST_URI, "netmonitor");
 
   const currentTab = gBrowser.selectedTab;
   let target = TargetFactory.forTab(currentTab);
   let toolbox = gDevTools.getToolbox(target);
 
   let monitor = toolbox.getCurrentPanel();
-  let netReady = monitor.panelWin.once("NetMonitor:PayloadReady");
+  let netReady = monitor.panelWin.api.once("NetMonitor:PayloadReady");
 
   // Fire an XHR POST request.
   await ContentTask.spawn(gBrowser.selectedBrowser, null, function() {
     content.wrappedJSObject.testXhrGet();
   });
 
   info("XHR executed");
 
@@ -64,17 +64,17 @@ async function testNetworkMessage(messag
       "#headers-panel .headers-overview");
     return headersContent;
   });
 
   ok(headersContent, "Headers content is available");
 }
 
 /**
- * Wait until all lazily fetch requests in netmonitor get finsished.
+ * Wait until all lazily fetch requests in netmonitor get finished.
  * Otherwise test will be shutdown too early and cause failure.
  */
 async function waitForLazyRequests(toolbox) {
   let { ui } = toolbox.getCurrentPanel().hud;
   let proxy = ui.jsterm.hud.proxy;
   return waitUntil(() => {
     return !proxy.networkDataProvider.lazyRequestData.size;
   });