Bug 1656388 - Send the waiting time to the UI r=nchevobbe
authorHubert Boma Manilla <hmanilla@mozilla.com>
Fri, 31 Jul 2020 13:03:53 +0000
changeset 542906 64ab62dc196dc5a4d04673e90ae2a4d47f70b1cb
parent 542905 f46ad63286fa3b93bb5dd41e3b5579326df5d0b0
child 542907 88b60065bd1e6e19f38e1d5a2e1430a645f2d8ff
push id123104
push userhmanilla@mozilla.com
push dateFri, 31 Jul 2020 16:51:17 +0000
treeherderautoland@64ab62dc196d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnchevobbe
bugs1656388
milestone81.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 1656388 - Send the waiting time to the UI r=nchevobbe Differential Revision: https://phabricator.services.mozilla.com/D85501
devtools/client/netmonitor/test/browser.ini
devtools/client/netmonitor/test/browser_net_column_slow-request-indicator.js
devtools/client/netmonitor/test/head.js
devtools/client/netmonitor/test/html_slow-requests-test-page.html
devtools/client/webconsole/test/node/fixtures/stubs/networkEvent.js
devtools/shared/resources/legacy-listeners/network-events.js
--- a/devtools/client/netmonitor/test/browser.ini
+++ b/devtools/client/netmonitor/test/browser.ini
@@ -34,16 +34,17 @@ support-files =
   html_post-data-test-page.html
   html_post-array-data-test-page.html
   html_post-json-test-page.html
   html_post-raw-test-page.html
   html_header-test-page.html
   html_post-raw-with-headers-test-page.html
   html_simple-test-page.html
   html_single-get-page.html
+  html_slow-requests-test-page.html
   html_send-beacon.html
   html_sorting-test-page.html
   html_statistics-test-page.html
   html_status-codes-test-page.html
   html_tracking-protection.html
   html_api-calls-test-page.html
   html_copy-as-curl.html
   html_curl-utils.html
@@ -104,16 +105,17 @@ skip-if = (verify && !debug && (os == 'l
 [browser_net_charts-02.js]
 [browser_net_charts-03.js]
 [browser_net_charts-04.js]
 [browser_net_charts-05.js]
 [browser_net_charts-06.js]
 [browser_net_charts-07.js]
 [browser_net_clear.js]
 [browser_net_column_headers_tooltips.js]
+[browser_net_column_slow-request-indicator.js]
 [browser_net_column-resize-fit.js]
 [browser_net_columns_last_column.js]
 [browser_net_columns_pref.js]
 [browser_net_columns_reset.js]
 [browser_net_columns_showhide.js]
 [browser_net_columns_time.js]
 [browser_net_complex-params.js]
 skip-if = (verify && !debug && (os == 'win'))
new file mode 100644
--- /dev/null
+++ b/devtools/client/netmonitor/test/browser_net_column_slow-request-indicator.js
@@ -0,0 +1,69 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Tests that the slow request indicator is visible for slow requests.
+ */
+
+add_task(async function() {
+  // The script sjs_slow-script-server.sjs takes about 2s which is
+  // definately above the slow threshold set here.
+  const SLOW_THRESHOLD = 450;
+
+  Services.prefs.setIntPref("devtools.netmonitor.audits.slow", SLOW_THRESHOLD);
+
+  const { monitor, tab } = await initNetMonitor(SLOW_REQUESTS_URL, {
+    requestCount: 2,
+  });
+  info("Starting test... ");
+
+  const { document, store, windowRequire } = monitor.panelWin;
+  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
+  store.dispatch(Actions.batchEnable(false));
+
+  const wait = waitForNetworkEvents(monitor, 2);
+  tab.linkedBrowser.reload();
+  await wait;
+
+  const requestList = document.querySelectorAll(
+    ".network-monitor .request-list-item"
+  );
+
+  info("Checking the html document request");
+  is(
+    requestList[0].querySelector(".requests-list-file div:first-child")
+      .textContent,
+    "html_slow-requests-test-page.html",
+    "The html document is the first request"
+  );
+  is(
+    !!requestList[0].querySelector(".requests-list-slow-button"),
+    false,
+    "The request is not slow"
+  );
+
+  info("Checking the slow script request");
+  is(
+    requestList[1].querySelector(".requests-list-file div:first-child")
+      .textContent,
+    "sjs_slow-script-server.sjs",
+    "The slow test script is the second request"
+  );
+  is(
+    !!requestList[1].querySelector(".requests-list-slow-button"),
+    true,
+    "The request is slow"
+  );
+
+  is(
+    requestList[1]
+      .querySelector(".requests-list-slow-button")
+      .title.includes(`The recommended limit is ${SLOW_THRESHOLD} ms.`),
+    true,
+    "The tooltip text is correct"
+  );
+
+  return teardown(monitor);
+});
--- a/devtools/client/netmonitor/test/head.js
+++ b/devtools/client/netmonitor/test/head.js
@@ -96,16 +96,17 @@ const STATISTICS_URL = EXAMPLE_URL + "ht
 const CURL_URL = EXAMPLE_URL + "html_copy-as-curl.html";
 const CURL_UTILS_URL = EXAMPLE_URL + "html_curl-utils.html";
 const SEND_BEACON_URL = EXAMPLE_URL + "html_send-beacon.html";
 const CORS_URL = EXAMPLE_URL + "html_cors-test-page.html";
 const PAUSE_URL = EXAMPLE_URL + "html_pause-test-page.html";
 const OPEN_REQUEST_IN_TAB_URL = EXAMPLE_URL + "html_open-request-in-tab.html";
 const CSP_URL = EXAMPLE_URL + "html_csp-test-page.html";
 const CSP_RESEND_URL = EXAMPLE_URL + "html_csp-resend-test-page.html";
+const SLOW_REQUESTS_URL = EXAMPLE_URL + "html_slow-requests-test-page.html";
 
 const SIMPLE_SJS = EXAMPLE_URL + "sjs_simple-test-server.sjs";
 const SIMPLE_UNSORTED_COOKIES_SJS =
   EXAMPLE_URL + "sjs_simple-unsorted-cookies-test-server.sjs";
 const CONTENT_TYPE_SJS = EXAMPLE_URL + "sjs_content-type-test-server.sjs";
 const WS_CONTENT_TYPE_SJS = WS_HTTP_URL + "sjs_content-type-test-server.sjs";
 const WS_WS_CONTENT_TYPE_SJS = WS_URL + "sjs_content-type-test-server.sjs";
 const HTTPS_CONTENT_TYPE_SJS =
new file mode 100644
--- /dev/null
+++ b/devtools/client/netmonitor/test/html_slow-requests-test-page.html
@@ -0,0 +1,15 @@
+<!-- Any copyright is dedicated to the Public Domain.
+     http://creativecommons.org/publicdomain/zero/1.0/ -->
+
+     <!doctype HTML>
+     <html>
+       <head>
+         <meta charset="utf-8"/>
+         <title>Slow Network Requests Test Page</title>
+       </head>
+       <body>
+         <h1>Slow Network Requests Test Page</h1>
+         <script type="text/javascript"
+           src="http://example.com/browser/devtools/client/netmonitor/test/sjs_slow-script-server.sjs"></script>
+       </body>
+     </html>
\ No newline at end of file
--- a/devtools/client/webconsole/test/node/fixtures/stubs/networkEvent.js
+++ b/devtools/client/webconsole/test/node/fixtures/stubs/networkEvent.js
@@ -50,16 +50,17 @@ rawPackets.set(`GET request`, {
     "status": "404",
     "statusText": "Not Found",
     "headersSize": 160,
     "remoteAddress": "127.0.0.1",
     "remotePort": 8888,
     "content": {
       "mimeType": "text/html; charset=utf-8"
     },
+    "waitingTime": 1,
     "bodySize": 418,
     "transferredSize": 578
   },
   "timings": {},
   "private": false,
   "isThirdPartyTrackingResource": false,
   "referrerPolicy": "no-referrer-when-downgrade",
   "channelId": 265845590720515,
@@ -107,16 +108,17 @@ rawPackets.set(`GET request update`, {
     "status": "404",
     "statusText": "Not Found",
     "headersSize": 160,
     "remoteAddress": "127.0.0.1",
     "remotePort": 8888,
     "content": {
       "mimeType": "text/html; charset=utf-8"
     },
+    "waitingTime": 1,
     "bodySize": 418,
     "transferredSize": 578
   },
   "timings": {},
   "private": false,
   "isThirdPartyTrackingResource": false,
   "referrerPolicy": "no-referrer-when-downgrade",
   "channelId": 202499118071811,
@@ -167,16 +169,17 @@ rawPackets.set(`XHR GET request`, {
     "status": "404",
     "statusText": "Not Found",
     "headersSize": 160,
     "remoteAddress": "127.0.0.1",
     "remotePort": 8888,
     "content": {
       "mimeType": "text/html; charset=utf-8"
     },
+    "waitingTime": 2,
     "bodySize": 418,
     "transferredSize": 578
   },
   "timings": {},
   "private": false,
   "isThirdPartyTrackingResource": false,
   "referrerPolicy": "no-referrer-when-downgrade",
   "channelId": 202499118071812,
@@ -223,16 +226,17 @@ rawPackets.set(`XHR GET request update`,
     "status": "404",
     "statusText": "Not Found",
     "headersSize": 160,
     "remoteAddress": "127.0.0.1",
     "remotePort": 8888,
     "content": {
       "mimeType": "text/html; charset=utf-8"
     },
+    "waitingTime": 2,
     "bodySize": 418,
     "transferredSize": 578
   },
   "timings": {},
   "private": false,
   "isThirdPartyTrackingResource": false,
   "referrerPolicy": "no-referrer-when-downgrade",
   "updates": [
@@ -282,16 +286,17 @@ rawPackets.set(`XHR POST request`, {
     "status": "404",
     "statusText": "Not Found",
     "headersSize": 160,
     "remoteAddress": "127.0.0.1",
     "remotePort": 8888,
     "content": {
       "mimeType": "text/html; charset=utf-8"
     },
+    "waitingTime": 2,
     "bodySize": 418,
     "transferredSize": 578
   },
   "timings": {},
   "private": false,
   "isThirdPartyTrackingResource": false,
   "referrerPolicy": "no-referrer-when-downgrade",
   "channelId": 265845590720517,
@@ -338,16 +343,17 @@ rawPackets.set(`XHR POST request update`
     "status": "404",
     "statusText": "Not Found",
     "headersSize": 160,
     "remoteAddress": "127.0.0.1",
     "remotePort": 8888,
     "content": {
       "mimeType": "text/html; charset=utf-8"
     },
+    "waitingTime": 2,
     "bodySize": 418,
     "transferredSize": 578
   },
   "timings": {},
   "private": false,
   "isThirdPartyTrackingResource": false,
   "referrerPolicy": "no-referrer-when-downgrade",
   "updates": [
--- a/devtools/shared/resources/legacy-listeners/network-events.js
+++ b/devtools/shared/resources/legacy-listeners/network-events.js
@@ -90,16 +90,17 @@ module.exports = async function({
         resource.response.statusText = packet.response.statusText;
         resource.response.headersSize = packet.response.headersSize;
         resource.response.remoteAddress = packet.response.remoteAddress;
         resource.response.remotePort = packet.response.remotePort;
         resource.discardResponseBody = packet.response.discardResponseBody;
         resource.response.content = {
           mimeType: packet.response.mimeType,
         };
+        resource.response.waitingTime = packet.response.waitingTime;
         break;
       case "responseContent":
         resource.response.content = {
           mimeType: packet.mimeType,
         };
         resource.response.bodySize = packet.contentSize;
         resource.response.transferredSize = packet.transferredSize;
         resource.discardResponseBody = packet.discardResponseBody;