Bug 1408964 - The Network panel should be auto resumed on reload; r=rickychien
authorJan Odvarko <odvarko@gmail.com>
Fri, 03 Nov 2017 11:41:33 +0100
changeset 443265 628b2f8e23b7aaa468e078138b51033ede6d97a2
parent 443264 c08ecbfbb50902b34bdfec572f5582d48fa4e829
child 443266 3b8671ab0719717be8e0f3d71b7254d45a0e17b9
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrickychien
bugs1408964
milestone58.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 1408964 - The Network panel should be auto resumed on reload; r=rickychien MozReview-Commit-ID: L6gTBekWeHz
devtools/client/netmonitor/src/connector/firefox-connector.js
devtools/client/netmonitor/test/browser_net_pause.js
--- a/devtools/client/netmonitor/src/connector/firefox-connector.js
+++ b/devtools/client/netmonitor/src/connector/firefox-connector.js
@@ -38,16 +38,23 @@ class FirefoxConnector {
 
     this.dataProvider = new FirefoxDataProvider({
       webConsoleClient: this.webConsoleClient,
       actions: this.actions,
     });
 
     this.addListeners();
 
+    // Listener for `will-navigate` event is (un)registered outside
+    // of the `addListeners` and `removeListeners` methods since
+    // these are used to pause/resume the connector.
+    // Paused network panel should be automatically resumed when page
+    // reload, so `will-navigate` listener needs to be there all the time.
+    this.tabTarget.on("will-navigate", this.willNavigate);
+
     // Don't start up waiting for timeline markers if the server isn't
     // recent enough to emit the markers we're interested in.
     if (this.tabTarget.getTrait("documentLoadingMarkers")) {
       this.timelineFront = new TimelineFront(this.tabTarget.client, this.tabTarget.form);
       this.timelineFront.on("doc-loading", this.onDocLoadingMarker);
       await this.timelineFront.start({ withDocLoadingEvents: true });
     }
 
@@ -61,54 +68,60 @@ class FirefoxConnector {
     // recent enough to emit the markers we were interested in.
     if (this.tabTarget.getTrait("documentLoadingMarkers") && this.timelineFront) {
       this.timelineFront.off("doc-loading", this.onDocLoadingMarker);
       await this.timelineFront.destroy();
     }
 
     this.removeListeners();
 
+    this.tabTarget.off("will-navigate");
+
     this.tabTarget = null;
     this.webConsoleClient = null;
     this.timelineFront = null;
     this.dataProvider = null;
   }
 
   pause() {
     this.removeListeners();
   }
 
   resume() {
     this.addListeners();
   }
 
   addListeners() {
-    this.tabTarget.on("will-navigate", this.willNavigate);
     this.tabTarget.on("close", this.disconnect);
     this.webConsoleClient.on("networkEvent",
       this.dataProvider.onNetworkEvent);
     this.webConsoleClient.on("networkEventUpdate",
       this.dataProvider.onNetworkEventUpdate);
   }
 
   removeListeners() {
-    this.tabTarget.off("will-navigate");
     this.tabTarget.off("close");
     this.webConsoleClient.off("networkEvent");
     this.webConsoleClient.off("networkEventUpdate");
   }
 
   willNavigate() {
     if (!Services.prefs.getBoolPref("devtools.netmonitor.persistlog")) {
       this.actions.batchReset();
       this.actions.clearRequests();
     } else {
       // If the log is persistent, just clear all accumulated timing markers.
       this.actions.clearTimingMarkers();
     }
+
+    // Resume is done automatically on page reload/navigation.
+    let state = this.getState();
+    if (!state.requests.recording) {
+      this.actions.toggleRecording();
+    }
   }
 
   /**
    * Display any network events already in the cache.
    */
   displayCachedEvents() {
     for (let networkInfo of this.webConsoleClient.getNetworkEvents()) {
       // First add the request to the timeline.
--- a/devtools/client/netmonitor/test/browser_net_pause.js
+++ b/devtools/client/netmonitor/test/browser_net_pause.js
@@ -39,16 +39,23 @@ add_task(function* () {
   assertRequestCount(store, 1);
 
   // Click pause again to resume monitoring. Load a third request
   // and make sure they will show up.
   EventUtils.sendMouseEvent({ type: "click" }, pauseButton);
   yield performRequestAndWait(tab, monitor);
   assertRequestCount(store, 2);
 
+  // Click pause, reload the page and check that there are
+  // some requests. Page reload should auto-resume.
+  EventUtils.sendMouseEvent({ type: "click" }, pauseButton);
+  tab.linkedBrowser.reload();
+  yield waitForNetworkEvents(monitor, 1);
+  assertRequestCount(store, 1);
+
   return teardown(monitor);
 });
 
 /**
  * Asserts the number of requests in the network monitor.
  */
 function assertRequestCount(store, count) {
   is(store.getState().requests.requests.size, count,