Bug 1356957 - combine double updateRequest call while receive event in _onNetworkEventUpdate;r=rickychien draft
authorFred Lin <gasolin@mozilla.com>
Thu, 20 Apr 2017 16:48:40 +0800
changeset 566230 4aabf9992146ac08b5715e211495476fc95d386d
parent 566180 cf036d3536c74fd2ecb748a57114c115688ba013
child 625258 f8ab68488a7e901ccfab16aa3de44022e82a6fb1
push id55155
push userbmo:gasolin@mozilla.com
push dateFri, 21 Apr 2017 07:26:33 +0000
reviewersrickychien
bugs1356957
milestone55.0a1
Bug 1356957 - combine double updateRequest call while receive event in _onNetworkEventUpdate;r=rickychien MozReview-Commit-ID: 7cyDQT6Rz6O
devtools/client/netmonitor/src/netmonitor-controller.js
devtools/client/netmonitor/test/browser_net_simple-request-data.js
--- a/devtools/client/netmonitor/src/netmonitor-controller.js
+++ b/devtools/client/netmonitor/src/netmonitor-controller.js
@@ -299,18 +299,16 @@ function NetworkEventsHandler() {
   this._onNetworkEvent = this._onNetworkEvent.bind(this);
   this._onNetworkEventUpdate = this._onNetworkEventUpdate.bind(this);
   this._onDocLoadingMarker = this._onDocLoadingMarker.bind(this);
   this._onRequestHeaders = this._onRequestHeaders.bind(this);
   this._onRequestCookies = this._onRequestCookies.bind(this);
   this._onRequestPostData = this._onRequestPostData.bind(this);
   this._onResponseHeaders = this._onResponseHeaders.bind(this);
   this._onResponseCookies = this._onResponseCookies.bind(this);
-  this._onSecurityInfo = this._onSecurityInfo.bind(this);
-  this._onEventTimings = this._onEventTimings.bind(this);
 }
 
 NetworkEventsHandler.prototype = {
   get client() {
     return NetMonitorController._target.client;
   },
 
   get webConsoleClient() {
@@ -583,22 +581,22 @@ NetworkEventsHandler.prototype = {
         window.emit(EVENTS.UPDATING_REQUEST_COOKIES, actor);
         break;
       case "requestPostData":
         this.webConsoleClient.getRequestPostData(actor,
           this._onRequestPostData);
         window.emit(EVENTS.UPDATING_REQUEST_POST_DATA, actor);
         break;
       case "securityInfo":
-        this.updateRequest(actor, {
-          securityState: networkInfo.securityInfo,
-        }).then(() => {
-          this.webConsoleClient.getSecurityInfo(actor, this._onSecurityInfo);
-          window.emit(EVENTS.UPDATING_SECURITY_INFO, actor);
-        });
+        this.webConsoleClient.getSecurityInfo(actor,
+          this._onSecurityInfo.bind(this, {
+            securityState: networkInfo.securityInfo,
+          })
+        );
+        window.emit(EVENTS.UPDATING_SECURITY_INFO, actor);
         break;
       case "responseHeaders":
         this.webConsoleClient.getResponseHeaders(actor,
           this._onResponseHeaders);
         window.emit(EVENTS.UPDATING_RESPONSE_HEADERS, actor);
         break;
       case "responseCookies":
         this.webConsoleClient.getResponseCookies(actor,
@@ -622,22 +620,22 @@ NetworkEventsHandler.prototype = {
           this._onResponseContent.bind(this, {
             contentSize: networkInfo.response.bodySize,
             transferredSize: networkInfo.response.transferredSize,
             mimeType: networkInfo.response.content.mimeType
           }));
         window.emit(EVENTS.UPDATING_RESPONSE_CONTENT, actor);
         break;
       case "eventTimings":
-        this.updateRequest(actor, {
-          totalTime: networkInfo.totalTime
-        }).then(() => {
-          this.webConsoleClient.getEventTimings(actor, this._onEventTimings);
-          window.emit(EVENTS.UPDATING_EVENT_TIMINGS, actor);
-        });
+        this.webConsoleClient.getEventTimings(actor,
+          this._onEventTimings.bind(this, {
+            totalTime: networkInfo.totalTime
+          })
+        );
+        window.emit(EVENTS.UPDATING_EVENT_TIMINGS, actor);
         break;
     }
   },
 
   /**
    * Handles additional information received for a "requestHeaders" packet.
    *
    * @param object response
@@ -677,23 +675,26 @@ NetworkEventsHandler.prototype = {
     }).then(() => {
       window.emit(EVENTS.RECEIVED_REQUEST_POST_DATA, response.from);
     });
   },
 
   /**
    * Handles additional information received for a "securityInfo" packet.
    *
+   * @param object data
+   *        The message received from the server event.
    * @param object response
    *        The message received from the server.
    */
-  _onSecurityInfo: function (response) {
-    this.updateRequest(response.from, {
+  _onSecurityInfo: function (data, response) {
+    let payload = Object.assign({
       securityInfo: response.securityInfo
-    }).then(() => {
+    }, data);
+    this.updateRequest(response.from, payload).then(() => {
       window.emit(EVENTS.RECEIVED_SECURITY_INFO, response.from);
     });
   },
 
   /**
    * Handles additional information received for a "responseHeaders" packet.
    *
    * @param object response
@@ -734,21 +735,22 @@ NetworkEventsHandler.prototype = {
     this.updateRequest(response.from, payload).then(() => {
       window.emit(EVENTS.RECEIVED_RESPONSE_CONTENT, response.from);
     });
   },
 
   /**
    * Handles additional information received for a "eventTimings" packet.
    *
+   * @param object data
+   *        The message received from the server event.
    * @param object response
    *        The message received from the server.
    */
-  _onEventTimings: function (response) {
-    this.updateRequest(response.from, {
-      eventTimings: response
-    }).then(() => {
+  _onEventTimings: function (data, response) {
+    let payload = Object.assign({ eventTimings: response }, data);
+    this.updateRequest(response.from, payload).then(() => {
       window.emit(EVENTS.RECEIVED_EVENT_TIMINGS, response.from);
     });
   }
 };
 
 exports.NetMonitorController = NetMonitorController;
--- a/devtools/client/netmonitor/test/browser_net_simple-request-data.js
+++ b/devtools/client/netmonitor/test/browser_net_simple-request-data.js
@@ -228,39 +228,24 @@ function test() {
           type: "plain",
           fullMimeType: "text/plain; charset=utf-8",
           transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 12),
           size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 12),
         }
       );
     });
 
-    monitor.panelWin.once(EVENTS.UPDATING_EVENT_TIMINGS, () => {
+    monitor.panelWin.once(EVENTS.RECEIVED_EVENT_TIMINGS, () => {
       let requestItem = getSortedRequests(gStore.getState()).get(0);
 
       is(typeof requestItem.totalTime, "number",
         "The attached totalTime is incorrect.");
       ok(requestItem.totalTime >= 0,
         "The attached totalTime should be positive.");
 
-      verifyRequestItemTarget(
-        document,
-        getDisplayedRequests(gStore.getState()),
-        requestItem,
-        "GET",
-        SIMPLE_SJS,
-        {
-          time: true
-        }
-      );
-    });
-
-    monitor.panelWin.once(EVENTS.RECEIVED_EVENT_TIMINGS, () => {
-      let requestItem = getSortedRequests(gStore.getState()).get(0);
-
       ok(requestItem.eventTimings,
         "There should be a eventTimings data available.");
       is(typeof requestItem.eventTimings.timings.blocked, "number",
         "The eventTimings data has an incorrect |timings.blocked| property.");
       is(typeof requestItem.eventTimings.timings.dns, "number",
         "The eventTimings data has an incorrect |timings.dns| property.");
       is(typeof requestItem.eventTimings.timings.connect, "number",
         "The eventTimings data has an incorrect |timings.connect| property.");