Bug 1408964 - The Network panel should be auto resumed on reload; r=rickychien
MozReview-Commit-ID: L6gTBekWeHz
--- 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,