Bug 1392411 Part 3 - Add test for capturing websocket stacks in net monitor, r=ochameau.
☠☠ backed out by a67530e635b1 ☠ ☠
authorBrian Hackett <bhackett1024@gmail.com>
Fri, 19 Apr 2019 07:50:02 -1000
changeset 474192 1c23ba0f835f1a097ba5249bbef8e5c79308ae29
parent 474191 fce11a50c0589bb63a61abc716ea05ca1c53f12f
child 474193 c37ca68a24e5a38192a1ef8ccf01c406ccc511ce
push id36026
push usermalexandru@mozilla.com
push dateFri, 17 May 2019 09:30:40 +0000
treeherdermozilla-central@839cdad764d7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1392411
milestone68.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 1392411 Part 3 - Add test for capturing websocket stacks in net monitor, r=ochameau. Differential Revision: https://phabricator.services.mozilla.com/D28231
devtools/client/netmonitor/test/browser.ini
devtools/client/netmonitor/test/browser_net_websocket_stacks.js
devtools/client/netmonitor/test/html_websocket-test-page.html
devtools/client/netmonitor/test/js_websocket-worker-test.js
--- a/devtools/client/netmonitor/test/browser.ini
+++ b/devtools/client/netmonitor/test/browser.ini
@@ -40,18 +40,20 @@ support-files =
   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
   html_open-request-in-tab.html
   html_worker-test-page.html
+  html_websocket-test-page.html
   js_worker-test.js
   js_worker-test2.js
+  js_websocket-worker-test.js
   sjs_content-type-test-server.sjs
   sjs_cors-test-server.sjs
   sjs_https-redirect-test-server.sjs
   sjs_hsts-test-server.sjs
   sjs_json-test-server.sjs
   sjs_method-test-server.sjs
   sjs_set-cookie-same-site.sjs
   sjs_simple-test-server.sjs
@@ -219,9 +221,10 @@ skip-if = true # Bug 1373558
 [browser_net_timeline_ticks.js]
 skip-if = true # TODO: fix the test
 [browser_net_timing-division.js]
 [browser_net_tracking-resources.js]
 [browser_net_truncate-post-data.js]
 [browser_net_truncate.js]
 [browser_net_view-source-debugger.js]
 [browser_net_waterfall-click.js]
+[browser_net_websocket_stacks.js]
 [browser_net_worker_stacks.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/netmonitor/test/browser_net_websocket_stacks.js
@@ -0,0 +1,75 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// Test that we get stack traces for the network requests made when creating
+// web sockets on the main or worker threads.
+
+const TOP_FILE_NAME = "html_websocket-test-page.html";
+const TOP_URL = EXAMPLE_URL + TOP_FILE_NAME;
+const WORKER_FILE_NAME = "js_websocket-worker-test.js";
+
+const EXPECTED_REQUESTS = [
+  {
+    method: "GET",
+    url: TOP_URL,
+    causeType: "document",
+    causeUri: null,
+    stack: true,
+  },
+  {
+    method: "GET",
+    url: "http://localhost:8080/",
+    causeType: "websocket",
+    causeUri: TOP_URL,
+    stack: [
+      { fn: "openSocket", file: TOP_FILE_NAME, line: 6 },
+      { file: TOP_FILE_NAME, line: 3 },
+    ],
+  },
+  {
+    method: "GET",
+    url: EXAMPLE_URL + WORKER_FILE_NAME,
+    causeType: "script",
+    causeUri: TOP_URL,
+    stack: [ { file: TOP_FILE_NAME, line: 9 } ],
+  },
+  {
+    method: "GET",
+    url: "https://localhost:8081/",
+    causeType: "websocket",
+    causeUri: TOP_URL,
+    stack: [
+      { fn: "openWorkerSocket", file: WORKER_FILE_NAME, line: 5 },
+      { file: WORKER_FILE_NAME, line: 2 },
+    ],
+  },
+];
+
+add_task(async function() {
+  // Load a different URL first to instantiate the network monitor before we
+  // load the page we're really interested in.
+  const { tab, monitor } = await initNetMonitor(SIMPLE_URL);
+
+  const { store, windowRequire, connector } = monitor.panelWin;
+  const {
+    getSortedRequests,
+  } = windowRequire("devtools/client/netmonitor/src/selectors/index");
+
+  BrowserTestUtils.loadURI(tab.linkedBrowser, TOP_URL);
+
+  await waitForNetworkEvents(monitor, EXPECTED_REQUESTS.length);
+
+  is(store.getState().requests.requests.size, EXPECTED_REQUESTS.length,
+    "All the page events should be recorded.");
+
+  // Wait for stack traces from all requests.
+  const requests = getSortedRequests(store.getState());
+  await Promise.all(requests.map(requestItem =>
+    connector.requestData(requestItem.id, "stackTrace")));
+
+  validateRequests(EXPECTED_REQUESTS, monitor);
+
+  await teardown(monitor);
+});
new file mode 100644
--- /dev/null
+++ b/devtools/client/netmonitor/test/html_websocket-test-page.html
@@ -0,0 +1,10 @@
+<script>
+"use strict";
+openSocket();
+
+function openSocket() {
+  this.ws = new WebSocket("ws://localhost:8080/");
+}
+
+this.w = new Worker("js_websocket-worker-test.js");
+</script>
new file mode 100644
--- /dev/null
+++ b/devtools/client/netmonitor/test/js_websocket-worker-test.js
@@ -0,0 +1,6 @@
+"use strict";
+openWorkerSocket();
+
+function openWorkerSocket() {
+  this.ws = new WebSocket("wss://localhost:8081");
+}