Bug 1392411 Part 3 - Add test for capturing websocket stacks in net monitor, r=ochameau.
authorBrian Hackett <bhackett1024@gmail.com>
Sun, 19 May 2019 12:45:19 -1000
changeset 536355 c4af6879f495591ca82b946a4fc1717e0322847d
parent 536354 3e0d5c61f31e3fd31726f5b4769e734a8e933008
child 536356 72731b10931017b247d79f754145726e52672b71
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [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.
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() {
+  new WebSocket("ws://localhost:8080/");
+}
+
+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() {
+  new WebSocket("wss://localhost:8081");
+}