Bug 1328532 - Refactor updateRequest to fetch full text r=jsnajdr
☠☠ backed out by fb9fc60ae669 ☠ ☠
authorRicky Chien <rchien@mozilla.com>
Wed, 04 Jan 2017 15:34:20 +0800
changeset 456640 a762568b0299d8029d7cb33c7309077350126c27
parent 456639 4903a05dfaecb5f43577c15941bf31c4fd6cb1e5
child 456641 b27f68f4dbd6d16e9e45547e5ddbd8e3dd369137
push id40575
push userjwwang@mozilla.com
push dateFri, 06 Jan 2017 02:27:46 +0000
reviewersjsnajdr
bugs1328532
milestone53.0a1
Bug 1328532 - Refactor updateRequest to fetch full text r=jsnajdr MozReview-Commit-ID: mqLIWLs0xM
devtools/client/netmonitor/netmonitor-controller.js
devtools/client/netmonitor/requests-menu-view.js
devtools/client/netmonitor/test/browser_net_icon-preview.js
devtools/client/netmonitor/test/browser_net_streaming-response.js
--- a/devtools/client/netmonitor/netmonitor-controller.js
+++ b/devtools/client/netmonitor/netmonitor-controller.js
@@ -706,16 +706,22 @@ NetworkEventsHandler.prototype = {
    *        The long string grip containing the corresponding actor.
    *        If you pass in a plain string (by accident or because you're lazy),
    *        then a promise of the same string is simply returned.
    * @return object Promise
    *         A promise that is resolved when the full string contents
    *         are available, or rejected if something goes wrong.
    */
   getString: function (stringGrip) {
+    // FIXME: this.webConsoleClient will be undefined in mochitest,
+    // so we return string instantly to skip undefined error
+    if (typeof stringGrip === "string") {
+      return stringGrip;
+    }
+
     return this.webConsoleClient.getString(stringGrip);
   }
 };
 
 /**
  * Convenient way of emitting events from the panel window.
  */
 EventEmitter.decorate(window);
--- a/devtools/client/netmonitor/requests-menu-view.js
+++ b/devtools/client/netmonitor/requests-menu-view.js
@@ -203,56 +203,54 @@ RequestsMenuView.prototype = {
   updateRequest: Task.async(function* (id, data) {
     const action = Actions.updateRequest(id, data, true);
     yield this.store.dispatch(action);
 
     let { responseContent, requestPostData } = action.data;
 
     if (responseContent && responseContent.content) {
       let request = getRequestById(this.store.getState(), action.id);
-      let { text, encoding } = responseContent.content;
       if (request) {
         let { mimeType } = request;
+        let { text, encoding } = responseContent.content;
+        let response = yield gNetwork.getString(text);
+        let payload = {};
 
-        // Fetch response data if the response is an image (to display thumbnail)
         if (mimeType.includes("image/")) {
-          let responseBody = yield gNetwork.getString(text);
-          const dataUri = formDataURI(mimeType, encoding, responseBody);
-          yield this.store.dispatch(Actions.updateRequest(
-            action.id,
-            { responseContentDataUri: dataUri },
-            true
-          ));
+          payload.responseContentDataUri = formDataURI(mimeType, encoding, response);
+        }
+
+        if (mimeType.includes("text/")) {
+          responseContent.content.text = response;
+          payload.responseContent = responseContent;
+        }
+
+        yield this.store.dispatch(Actions.updateRequest(action.id, payload, true));
+
+        if (mimeType.includes("image/")) {
           window.emit(EVENTS.RESPONSE_IMAGE_THUMBNAIL_DISPLAYED);
-        // Fetch response text only if the response is html, but not all text/*
-        } else if (mimeType.includes("text/html") && typeof text !== "string") {
-          let responseBody = yield gNetwork.getString(text);
-          responseContent.content.text = responseBody;
-          responseContent = Object.assign({}, responseContent);
-          yield this.store.dispatch(Actions.updateRequest(
-            action.id,
-            { responseContent },
-            true
-          ));
         }
       }
     }
 
     // Search the POST data upload stream for request headers and add
     // them as a separate property, different from the classic headers.
     if (requestPostData && requestPostData.postData) {
       let { text } = requestPostData.postData;
       let postData = yield gNetwork.getString(text);
       const headers = CurlUtils.getHeadersFromMultipartText(postData);
       const headersSize = headers.reduce((acc, { name, value }) => {
         return acc + name.length + value.length + 2;
       }, 0);
-      yield this.store.dispatch(Actions.updateRequest(action.id, {
-        requestHeadersFromUploadStream: { headers, headersSize }
-      }, true));
+      let payload = {};
+      requestPostData.postData.text = postData;
+      payload.requestPostData = Object.assign({}, requestPostData);
+      payload.requestHeadersFromUploadStream = { headers, headersSize };
+
+      yield this.store.dispatch(Actions.updateRequest(action.id, payload, true));
     }
   }),
 
   /**
    * Disable batched updates. Used by tests.
    */
   set lazyUpdate(value) {
     this.store.dispatch(Actions.batchEnable(value));
--- a/devtools/client/netmonitor/test/browser_net_icon-preview.js
+++ b/devtools/client/netmonitor/test/browser_net_icon-preview.js
@@ -12,16 +12,18 @@ add_task(function* () {
 
   let { tab, monitor } = yield initNetMonitor(CONTENT_TYPE_WITHOUT_CACHE_URL);
   info("Starting test... ");
 
   let { $, $all, EVENTS, ACTIVITY_TYPE, NetMonitorView, NetMonitorController,
         gStore } = monitor.panelWin;
   let { RequestsMenu } = NetMonitorView;
 
+  RequestsMenu.lazyUpdate = false;
+
   let wait = waitForEvents();
   yield performRequests();
   yield wait;
 
   info("Checking the image thumbnail when all items are shown.");
   checkImageThumbnail();
 
   gStore.dispatch(Actions.sortBy("size"));
--- a/devtools/client/netmonitor/test/browser_net_streaming-response.js
+++ b/devtools/client/netmonitor/test/browser_net_streaming-response.js
@@ -46,19 +46,19 @@ add_task(function* () {
     document.querySelectorAll("#details-pane tab")[3]);
 
   yield panelWin.once(panelWin.EVENTS.RESPONSE_BODY_DISPLAYED);
   let editor = yield NetMonitorView.editor("#response-content-textarea");
 
   // the hls-m3u8 part
   testEditorContent(editor, REQUESTS[0]);
 
+  wait = panelWin.once(panelWin.EVENTS.RESPONSE_BODY_DISPLAYED);
   RequestsMenu.selectedIndex = 1;
-  yield panelWin.once(panelWin.EVENTS.TAB_UPDATED);
-  yield panelWin.once(panelWin.EVENTS.RESPONSE_BODY_DISPLAYED);
+  yield wait;
 
   // the mpeg-dash part
   testEditorContent(editor, REQUESTS[1]);
 
   return teardown(monitor);
 
   function testEditorContent(e, [ fmt, textRe, mode ]) {
     ok(e.getText().match(textRe),