Bug 1481002 - Developer tools network panel transferred total should ignore cached data. r=Honza
authorHemakshi Sachdev <sachdev.hemakshi@gmail.com>
Thu, 06 Sep 2018 01:13:00 +0300
changeset 435075 0ed60b04e7eb
parent 435074 3c2793d1514f
child 435076 38ed8871759e
push id107558
push usernbeleuzu@mozilla.com
push dateThu, 06 Sep 2018 20:38:57 +0000
treeherdermozilla-inbound@0ed60b04e7eb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersHonza
bugs1481002
milestone64.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 1481002 - Developer tools network panel transferred total should ignore cached data. r=Honza
devtools/client/netmonitor/src/selectors/requests.js
devtools/client/netmonitor/test/browser.ini
devtools/client/netmonitor/test/browser_net_status-bar-transferred-size.js
devtools/client/netmonitor/test/html_status-codes-test-page.html
--- a/devtools/client/netmonitor/src/selectors/requests.js
+++ b/devtools/client/netmonitor/src/selectors/requests.js
@@ -103,17 +103,18 @@ const getDisplayedRequestsSummary = crea
       return { count: 0, bytes: 0, millis: 0 };
     }
 
     const totalBytes = requests.reduce((totals, item) => {
       if (typeof item.contentSize == "number") {
         totals.contentSize += item.contentSize;
       }
 
-      if (typeof item.transferredSize == "number" && !item.fromCache) {
+      if (typeof item.transferredSize == "number" &&
+        !(item.fromCache || item.status === "304")) {
         totals.transferredSize += item.transferredSize;
       }
 
       return totals;
     }, { contentSize: 0, transferredSize: 0 });
 
     return {
       count: requests.size,
--- a/devtools/client/netmonitor/test/browser.ini
+++ b/devtools/client/netmonitor/test/browser.ini
@@ -179,16 +179,17 @@ skip-if = os == 'win' # bug 1391264
 [browser_net_simple-request-details.js]
 skip-if = true # Bug 1258809
 [browser_net_simple-request.js]
 [browser_net_sort-01.js]
 [browser_net_sort-02.js]
 [browser_net_statistics-01.js]
 skip-if = true # Bug 1373558
 [browser_net_statistics-02.js]
+[browser_net_status-bar-transferred-size.js]
 [browser_net_status-bar.js]
 [browser_net_status-codes.js]
 [browser_net_streaming-response.js]
 [browser_net_telemetry_edit_resend.js]
 [browser_net_telemetry_filters_changed.js]
 [browser_net_telemetry_sidepanel_changed.js]
 [browser_net_telemetry_throttle_changed.js]
 [browser_net_throttle.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/netmonitor/test/browser_net_status-bar-transferred-size.js
@@ -0,0 +1,66 @@
+"use strict";
+
+/**
+ * Test if the value of total data transferred is displayed correctly in the Status Bar
+ * Test for Bug 1481002
+ */
+add_task(async () => {
+  // Clear cache, so we see expected number of cached requests.
+  Services.cache2.clear();
+  // Disable rcwn to make cache behavior deterministic.
+  await pushPref("network.http.rcwn.enabled", false);
+
+  const {
+    getFormattedSize,
+  } = require("devtools/client/netmonitor/src/utils/format-utils");
+
+  const { tab, monitor } = await initNetMonitor(STATUS_CODES_URL, true);
+  info("Starting test... ");
+
+  const { document, store, windowRequire } = monitor.panelWin;
+  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
+  const { getDisplayedRequestsSummary } =
+    windowRequire("devtools/client/netmonitor/src/selectors/index");
+  const { L10N } = windowRequire("devtools/client/netmonitor/src/utils/l10n");
+
+  store.dispatch(Actions.batchEnable(false));
+
+  info("Performing requests...");
+  await performRequestsAndWait();
+
+  let cachedItemsInUI = 0;
+  for (const requestItem of document.querySelectorAll(".request-list-item")) {
+    const requestTransferStatus = requestItem.querySelector(
+      ".requests-list-transferred").textContent;
+    if (requestTransferStatus === "cached") {
+      cachedItemsInUI++;
+    }
+  }
+
+  is(cachedItemsInUI, 1, "Number of cached requests displayed is correct");
+
+  const state = store.getState();
+  const totalRequestsCount = state.requests.requests.size;
+  const requestsSummary = getDisplayedRequestsSummary(state);
+  info(`Current requests: ${requestsSummary.count} of ${totalRequestsCount}.`);
+
+  const valueTransfer =
+    document.querySelector(".requests-list-network-summary-transfer").textContent;
+  info("Current summary transfer: " + valueTransfer);
+  const expectedTransfer = L10N.getFormatStrWithNumbers(
+    "networkMenu.summary.transferred",
+    getFormattedSize(requestsSummary.contentSize),
+    getFormattedSize(requestsSummary.transferredSize));
+
+  is(valueTransfer, expectedTransfer, "The current summary transfer is correct.");
+
+  await teardown(monitor);
+
+  async function performRequestsAndWait() {
+    const wait = waitForNetworkEvents(monitor, 2);
+    await ContentTask.spawn(tab.linkedBrowser, {}, async function() {
+      content.wrappedJSObject.performOneCachedRequest();
+    });
+    await wait;
+  }
+});
--- a/devtools/client/netmonitor/test/html_status-codes-test-page.html
+++ b/devtools/client/netmonitor/test/html_status-codes-test-page.html
@@ -10,17 +10,17 @@
     <meta http-equiv="Expires" content="0" />
     <title>Network Monitor test page</title>
   </head>
 
   <body>
     <p>Status codes test</p>
 
     <script type="text/javascript">
-      /* exported performRequests, performCachedRequests */
+      /* exported performRequests, performCachedRequests, performOneCachedRequest */
       "use strict";
 
       function get(address, callback) {
         const xhr = new XMLHttpRequest();
         xhr.open("GET", address, true);
 
         xhr.onreadystatechange = function() {
           if (this.readyState == this.DONE) {
@@ -49,12 +49,19 @@
       function performCachedRequests() {
         get("sjs_status-codes-test-server.sjs?sts=ok&cached", function() {
           get("sjs_status-codes-test-server.sjs?sts=redirect&cached", function() {
             // Done.
           });
         });
       }
 
+      function performOneCachedRequest() {
+        get("sjs_status-codes-test-server.sjs?sts=ok&cached", function() {
+          get("sjs_status-codes-test-server.sjs?sts=ok&cached", function() {
+            // Done.
+          });
+        });
+      }
     </script>
   </body>
 
 </html>