Bug 1219556 - Report full body size from NetworkResponseListener. r=jryans, a=jcristau
authorTom Tromey <tom@tromey.com>
Fri, 23 Dec 2016 11:11:37 -0700
changeset 353592 bb809441355b489480f9f4a33be48902aa388b0a
parent 353591 295f6ec43e36c39548f172cb3d3f64c38439aaea
child 353593 6700e062f852de615d12120f8b4067d98ff500d1
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjryans, jcristau
bugs1219556
milestone52.0a2
Bug 1219556 - Report full body size from NetworkResponseListener. r=jryans, a=jcristau MozReview-Commit-ID: ISXVBOtQnQ4
devtools/client/netmonitor/test/browser.ini
devtools/client/netmonitor/test/browser_net_sort-01.js
devtools/client/netmonitor/test/browser_net_status-codes.js
devtools/client/netmonitor/test/browser_net_truncate.js
devtools/client/netmonitor/test/sjs_truncate-test-server.sjs
devtools/shared/webconsole/network-monitor.js
--- a/devtools/client/netmonitor/test/browser.ini
+++ b/devtools/client/netmonitor/test/browser.ini
@@ -38,16 +38,17 @@ support-files =
   html_curl-utils.html
   sjs_content-type-test-server.sjs
   sjs_cors-test-server.sjs
   sjs_https-redirect-test-server.sjs
   sjs_hsts-test-server.sjs
   sjs_simple-test-server.sjs
   sjs_sorting-test-server.sjs
   sjs_status-codes-test-server.sjs
+  sjs_truncate-test-server.sjs
   test-image.png
   service-workers/status-codes.html
   service-workers/status-codes-service-worker.js
   !/devtools/client/framework/test/shared-head.js
 
 [browser_net_aaa_leaktest.js]
 [browser_net_accessibility-01.js]
 [browser_net_accessibility-02.js]
@@ -146,9 +147,10 @@ skip-if = (e10s && debug && os == 'mac')
 [browser_net_statistics-01.js]
 [browser_net_statistics-02.js]
 [browser_net_statistics-03.js]
 [browser_net_status-codes.js]
 [browser_net_streaming-response.js]
 [browser_net_throttle.js]
 [browser_net_timeline_ticks.js]
 [browser_net_timing-division.js]
+[browser_net_truncate.js]
 [browser_net_persistent_logs.js]
--- a/devtools/client/netmonitor/test/browser_net_sort-01.js
+++ b/devtools/client/netmonitor/test/browser_net_sort-01.js
@@ -198,17 +198,17 @@ add_task(function* () {
       });
     verifyRequestItemTarget(RequestsMenu.getItemAtIndex(c),
       "GET", STATUS_CODES_SJS + "?sts=300", {
         status: 303,
         statusText: "See Other",
         type: "plain",
         fullMimeType: "text/plain; charset=utf-8",
         transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 22),
-        size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 0),
+        size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 22),
         time: true
       });
     verifyRequestItemTarget(RequestsMenu.getItemAtIndex(d),
       "GET", STATUS_CODES_SJS + "?sts=400", {
         status: 404,
         statusText: "Not Found",
         type: "plain",
         fullMimeType: "text/plain; charset=utf-8",
--- a/devtools/client/netmonitor/test/browser_net_status-codes.js
+++ b/devtools/client/netmonitor/test/browser_net_status-codes.js
@@ -52,17 +52,17 @@ add_task(function* () {
       // request #2
       method: "GET",
       uri: STATUS_CODES_SJS + "?sts=300",
       details: {
         status: 303,
         statusText: "See Other",
         type: "plain",
         fullMimeType: "text/plain; charset=utf-8",
-        size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 0),
+        size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 22),
         time: true
       }
     },
     {
       // request #3
       method: "GET",
       uri: STATUS_CODES_SJS + "?sts=400",
       details: {
new file mode 100644
--- /dev/null
+++ b/devtools/client/netmonitor/test/browser_net_truncate.js
@@ -0,0 +1,44 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Verifies that truncated response bodies still have the correct reported size.
+ */
+
+function test() {
+  let { L10N } = require("devtools/client/netmonitor/l10n");
+  const { RESPONSE_BODY_LIMIT } = require("devtools/shared/webconsole/network-monitor");
+
+  const URL = EXAMPLE_URL + "sjs_truncate-test-server.sjs?limit=" + RESPONSE_BODY_LIMIT;
+
+  // Another slow test on Linux debug.
+  requestLongerTimeout(2);
+
+  initNetMonitor(URL).then(({ tab, monitor }) => {
+    info("Starting test... ");
+
+    let { NetMonitorView } = monitor.panelWin;
+    let { RequestsMenu } = NetMonitorView;
+
+    RequestsMenu.lazyUpdate = false;
+
+    waitForNetworkEvents(monitor, 1)
+      .then(() => teardown(monitor))
+      .then(finish);
+
+    monitor.panelWin.once(monitor.panelWin.EVENTS.RECEIVED_RESPONSE_CONTENT, () => {
+      let requestItem = RequestsMenu.getItemAtIndex(0);
+
+      verifyRequestItemTarget(RequestsMenu, requestItem, "GET", URL, {
+        type: "plain",
+        fullMimeType: "text/plain; charset=utf-8",
+        transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeMB", 2),
+        size: L10N.getFormatStrWithNumbers("networkMenu.sizeMB", 2),
+      });
+    });
+
+    tab.linkedBrowser.reload();
+  });
+}
new file mode 100644
--- /dev/null
+++ b/devtools/client/netmonitor/test/sjs_truncate-test-server.sjs
@@ -0,0 +1,18 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function handleRequest(request, response) {
+  let params = request.queryString.split("&");
+  let limit = (params.filter((s) => s.includes("limit="))[0] || "").split("=")[1];
+
+  response.setStatusLine(request.httpVersion, 200, "Och Aye");
+
+  response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
+  response.setHeader("Pragma", "no-cache");
+  response.setHeader("Expires", "0");
+  response.setHeader("Content-Type", "text/plain; charset=utf-8", false);
+
+  response.write("x".repeat(2 * parseInt(limit, 10)));
+
+  response.write("Hello world!");
+}
--- a/devtools/shared/webconsole/network-monitor.js
+++ b/devtools/shared/webconsole/network-monitor.js
@@ -32,16 +32,18 @@ const PR_UINT32_MAX = 4294967295;
 // HTTP status codes.
 const HTTP_MOVED_PERMANENTLY = 301;
 const HTTP_FOUND = 302;
 const HTTP_SEE_OTHER = 303;
 const HTTP_TEMPORARY_REDIRECT = 307;
 
 // The maximum number of bytes a NetworkResponseListener can hold: 1 MB
 const RESPONSE_BODY_LIMIT = 1048576;
+// Exported for testing.
+exports.RESPONSE_BODY_LIMIT = RESPONSE_BODY_LIMIT;
 
 /**
  * Check if a given network request should be logged by a network monitor
  * based on the specified filters.
  *
  * @param nsIHttpChannel channel
  *        Request to check.
  * @param filters
@@ -586,17 +588,17 @@ NetworkResponseListener.prototype = {
    *        from the cache.
    */
   _onComplete: function (data) {
     let response = {
       mimeType: "",
       text: data || "",
     };
 
-    response.size = response.text.length;
+    response.size = this.bodySize;
     response.transferredSize = this.transferredSize;
 
     try {
       response.mimeType = this.request.contentType;
     } catch (ex) {
       // Ignore.
     }