Bug 1543751 Part 4 - Add test for uncaught worker errors.
authorBrian Hackett <bhackett1024@gmail.com>
Mon, 15 Apr 2019 13:58:51 -1000
changeset 469757 f236858f5add
parent 469756 e38792ce2185
child 469758 bbca68b2af26
push id35881
push usercbrindusan@mozilla.com
push dateWed, 17 Apr 2019 09:38:58 +0000
treeherdermozilla-central@bbca68b2af26 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1543751
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 1543751 Part 4 - Add test for uncaught worker errors.
devtools/client/webconsole/test/fixtures/stubs/pageError.js
devtools/client/webconsole/test/mochitest/browser.ini
devtools/client/webconsole/test/mochitest/browser_webconsole_primitive_stacktrace.js
devtools/client/webconsole/test/mochitest/browser_webconsole_worker_error.js
devtools/client/webconsole/test/mochitest/head.js
devtools/client/webconsole/test/mochitest/test-error-worker.html
devtools/client/webconsole/test/mochitest/test-error-worker.js
devtools/client/webconsole/test/mochitest/test-error-worker2.js
--- a/devtools/client/webconsole/test/fixtures/stubs/pageError.js
+++ b/devtools/client/webconsole/test/fixtures/stubs/pageError.js
@@ -200,17 +200,17 @@ stubPreparedMessages.set(`throw ""`, new
   "source": "javascript",
   "timeStamp": 1517942398629,
   "type": "log",
   "helperType": null,
   "level": "error",
   "category": "content javascript",
   "messageText": "uncaught exception: ",
   "parameters": null,
-  "repeatId": "{\"frame\":null,\"groupId\":null,\"indent\":0,\"level\":\"error\",\"messageText\":\"uncaught exception: \",\"parameters\":null,\"source\":\"javascript\",\"type\":\"log\",\"userProvidedStyles\":null,\"private\":false,\"stacktrace\":[{\"filename\":\"http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html\",\"sourceId\":\"server1.conn0.child1/source24\",\"lineNumber\":1,\"columnNumber\":1,\"functionName\":null},{\"filename\":\"resource://testing-common/content-task.js line 59 > eval\",\"sourceId\":null,\"lineNumber\":7,\"columnNumber\":31,\"functionName\":null},{\"filename\":\"resource://testing-common/content-task.js\",\"sourceId\":null,\"lineNumber\":60,\"columnNumber\":29,\"functionName\":null}]}",
+  "repeatId": "{\"frame\":{\"source\":\"http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html\",\"sourceId\":null,\"line\":1,\"column\":1},\"groupId\":null,\"indent\":0,\"level\":\"error\",\"messageText\":\"uncaught exception: \",\"parameters\":null,\"source\":\"javascript\",\"type\":\"log\",\"userProvidedStyles\":null,\"private\":false,\"stacktrace\":[{\"filename\":\"http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html\",\"sourceId\":\"server1.conn0.child1/source24\",\"lineNumber\":1,\"columnNumber\":1,\"functionName\":null},{\"filename\":\"resource://testing-common/content-task.js line 59 > eval\",\"sourceId\":null,\"lineNumber\":7,\"columnNumber\":31,\"functionName\":null},{\"filename\":\"resource://testing-common/content-task.js\",\"sourceId\":null,\"lineNumber\":60,\"columnNumber\":29,\"functionName\":null}]}",
   "stacktrace": [
     {
       "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
       "sourceId": "server1.conn0.child1/source24",
       "lineNumber": 1,
       "columnNumber": 1,
       "functionName": null
     },
@@ -224,17 +224,22 @@ stubPreparedMessages.set(`throw ""`, new
     {
       "filename": "resource://testing-common/content-task.js",
       "sourceId": null,
       "lineNumber": 60,
       "columnNumber": 29,
       "functionName": null
     }
   ],
-  "frame": null,
+  "frame": {
+    "source": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
+    "sourceId": null,
+    "line": 1,
+    "column": 1
+  },
   "groupId": null,
   "errorMessageName": "JSMSG_UNCAUGHT_EXCEPTION",
   "userProvidedStyles": null,
   "notes": null,
   "indent": 0,
   "prefix": "",
   "private": false,
   "chromeContext": false
@@ -247,17 +252,17 @@ stubPreparedMessages.set(`throw "tomato"
   "source": "javascript",
   "timeStamp": 1517942398637,
   "type": "log",
   "helperType": null,
   "level": "error",
   "category": "content javascript",
   "messageText": "uncaught exception: tomato",
   "parameters": null,
-  "repeatId": "{\"frame\":null,\"groupId\":null,\"indent\":0,\"level\":\"error\",\"messageText\":\"uncaught exception: tomato\",\"parameters\":null,\"source\":\"javascript\",\"type\":\"log\",\"userProvidedStyles\":null,\"private\":false,\"stacktrace\":[{\"filename\":\"http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html\",\"sourceId\":\"server1.conn0.child1/source24\",\"lineNumber\":1,\"columnNumber\":1,\"functionName\":null},{\"filename\":\"resource://testing-common/content-task.js line 59 > eval\",\"sourceId\":null,\"lineNumber\":7,\"columnNumber\":31,\"functionName\":null},{\"filename\":\"resource://testing-common/content-task.js\",\"sourceId\":null,\"lineNumber\":60,\"columnNumber\":29,\"functionName\":null}]}",
+  "repeatId": "{\"frame\":{\"source\":\"http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html\",\"sourceId\":null,\"line\":1,\"column\":1},\"groupId\":null,\"indent\":0,\"level\":\"error\",\"messageText\":\"uncaught exception: tomato\",\"parameters\":null,\"source\":\"javascript\",\"type\":\"log\",\"userProvidedStyles\":null,\"private\":false,\"stacktrace\":[{\"filename\":\"http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html\",\"sourceId\":\"server1.conn0.child1/source24\",\"lineNumber\":1,\"columnNumber\":1,\"functionName\":null},{\"filename\":\"resource://testing-common/content-task.js line 59 > eval\",\"sourceId\":null,\"lineNumber\":7,\"columnNumber\":31,\"functionName\":null},{\"filename\":\"resource://testing-common/content-task.js\",\"sourceId\":null,\"lineNumber\":60,\"columnNumber\":29,\"functionName\":null}]}",
   "stacktrace": [
     {
       "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
       "sourceId": "server1.conn0.child1/source24",
       "lineNumber": 1,
       "columnNumber": 1,
       "functionName": null
     },
@@ -271,17 +276,22 @@ stubPreparedMessages.set(`throw "tomato"
     {
       "filename": "resource://testing-common/content-task.js",
       "sourceId": null,
       "lineNumber": 60,
       "columnNumber": 29,
       "functionName": null
     }
   ],
-  "frame": null,
+  "frame": {
+    "source": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
+    "sourceId": null,
+    "line": 1,
+    "column": 1
+  },
   "groupId": null,
   "errorMessageName": "JSMSG_UNCAUGHT_EXCEPTION",
   "userProvidedStyles": null,
   "notes": null,
   "indent": 0,
   "prefix": "",
   "private": false,
   "chromeContext": false
@@ -454,21 +464,21 @@ stubPackets.set(`TypeError longString me
   "type": "pageError",
   "from": "server1.conn0.child1/consoleActor2"
 });
 
 stubPackets.set(`throw ""`, {
   "pageError": {
     "errorMessage": "uncaught exception: ",
     "errorMessageName": "JSMSG_UNCAUGHT_EXCEPTION",
-    "sourceName": "",
+    "sourceName": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "sourceId": null,
     "lineText": "",
-    "lineNumber": 0,
-    "columnNumber": 0,
+    "lineNumber": 1,
+    "columnNumber": 1,
     "category": "content javascript",
     "innerWindowID": 6442450949,
     "timeStamp": 1517942398629,
     "warning": false,
     "error": false,
     "exception": false,
     "strict": false,
     "info": false,
@@ -502,21 +512,21 @@ stubPackets.set(`throw ""`, {
   "type": "pageError",
   "from": "server1.conn0.child1/consoleActor2"
 });
 
 stubPackets.set(`throw "tomato"`, {
   "pageError": {
     "errorMessage": "uncaught exception: tomato",
     "errorMessageName": "JSMSG_UNCAUGHT_EXCEPTION",
-    "sourceName": "",
+    "sourceName": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
     "sourceId": null,
     "lineText": "",
-    "lineNumber": 0,
-    "columnNumber": 0,
+    "lineNumber": 1,
+    "columnNumber": 1,
     "category": "content javascript",
     "innerWindowID": 6442450949,
     "timeStamp": 1517942398637,
     "warning": false,
     "error": false,
     "exception": false,
     "strict": false,
     "info": false,
--- a/devtools/client/webconsole/test/mochitest/browser.ini
+++ b/devtools/client/webconsole/test/mochitest/browser.ini
@@ -40,16 +40,19 @@ support-files =
   test-console.html
   test-cu-reporterror.js
   test-data.json
   test-data.json^headers^
   test-duplicate-error.html
   test-dynamic-import.html
   test-dynamic-import.js
   test-error.html
+  test-error-worker.html
+  test-error-worker.js
+  test-error-worker2.js
   test-eval-in-stackframe.html
   test-eval-sources.html
   test-external-script-errors.html
   test-external-script-errors.js
   test-iframe-insecure-form-action.html
   test-iframe1.html
   test-iframe2.html
   test-iframe3.html
@@ -402,8 +405,9 @@ skip-if = verify
 tags = trackingprotection
 [browser_webconsole_view_source.js]
 [browser_webconsole_visibility_messages.js]
 [browser_webconsole_warn_about_replaced_api.js]
 [browser_webconsole_warning_group_content_blocking.js]
 [browser_webconsole_warning_groups_outside_console_group.js]
 [browser_webconsole_warning_groups.js]
 [browser_webconsole_websocket.js]
+[browser_webconsole_worker_error.js]
--- a/devtools/client/webconsole/test/mochitest/browser_webconsole_primitive_stacktrace.js
+++ b/devtools/client/webconsole/test/mochitest/browser_webconsole_primitive_stacktrace.js
@@ -10,24 +10,11 @@
 
 const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
                  "test/mochitest/" +
                  "test-primitive-stacktrace.html";
 
 add_task(async function() {
   const hud = await openNewTabAndConsole(TEST_URI);
 
-  await checkMessage("hello", 14, 3);
-  await checkMessage("1,2,3", 20, 1);
-
-  async function checkMessage(text, line, numFrames) {
-    const msgNode = await waitFor(() => findMessage(hud, text));
-    ok(!msgNode.classList.contains("open"), `Error logged not expanded`);
-
-    const button = msgNode.querySelector(".collapse-button");
-    button.click();
-
-    const framesNode = await waitFor(() => msgNode.querySelector(".frames"));
-    const frameNodes = framesNode.querySelectorAll(".frame");
-    ok(frameNodes.length == numFrames);
-    ok(frameNodes[0].querySelector(".line").textContent == "" + line);
-  }
+  await checkMessageStack(hud, "hello", [14, 10, 7]);
+  await checkMessageStack(hud, "1,2,3", [20]);
 });
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/test/mochitest/browser_webconsole_worker_error.js
@@ -0,0 +1,21 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Tests that throwing uncaught errors and primitive values in workers shows a
+// stack in the console.
+
+"use strict";
+
+const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
+                 "test/mochitest/test-error-worker.html";
+
+add_task(async function() {
+  const hud = await openNewTabAndConsole(TEST_URI);
+
+  await checkMessageStack(hud, "hello", [11, 3]);
+  await checkMessageStack(hud, "there", [14, 3]);
+  await checkMessageStack(hud, "dom", [16, 3]);
+  await checkMessageStack(hud, "worker2", [6, 3]);
+});
--- a/devtools/client/webconsole/test/mochitest/head.js
+++ b/devtools/client/webconsole/test/mochitest/head.js
@@ -1315,8 +1315,33 @@ function checkConsoleOutputForWarningGro
 
       expectedMessage = expectedMessage.replace("| ", "");
     }
 
     ok(message.textContent.trim().includes(expectedMessage.trim()), `Message includes ` +
       `the expected "${expectedMessage}" content - "${message.textContent.trim()}"`);
   });
 }
+
+/**
+ * Check that there is a message with the specified text that has the specified
+ * stack information.
+ * @param {WebConsole} hud
+ * @param {string} text
+ *        message substring to look for
+ * @param {Array<number>} frameLines
+ *        line numbers of the frames expected in the stack
+ */
+async function checkMessageStack(hud, text, frameLines) {
+  const msgNode = await waitFor(() => findMessage(hud, text));
+  ok(!msgNode.classList.contains("open"), `Error logged not expanded`);
+
+  const button = msgNode.querySelector(".collapse-button");
+  button.click();
+
+  const framesNode = await waitFor(() => msgNode.querySelector(".frames"));
+  const frameNodes = framesNode.querySelectorAll(".frame");
+  ok(frameNodes.length == frameLines.length, `Found ${frameLines.length} frames`);
+  for (let i = 0; i < frameLines.length; i++) {
+    ok(frameNodes[i].querySelector(".line").textContent == "" + frameLines[i],
+       `Found line ${frameLines[i]} for frame #${i}`);
+  }
+}
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/test/mochitest/test-error-worker.html
@@ -0,0 +1,7 @@
+<script>
+"use strict";
+var w = new Worker("test-error-worker.js");
+w.postMessage(1);
+w.postMessage(2);
+w.postMessage(3);
+</script>
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/test/mochitest/test-error-worker.js
@@ -0,0 +1,18 @@
+"use strict";
+
+self.addEventListener("message", ({ data }) => foo(data));
+
+var w = new Worker("test-error-worker2.js");
+w.postMessage({});
+
+function foo(data) {
+  switch (data) {
+    case 1:
+      throw new Error("hello");
+    case 2:
+      /* eslint-disable */
+      throw "there";
+    case 3:
+      throw new DOMException("dom");
+  }
+}
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/test/mochitest/test-error-worker2.js
@@ -0,0 +1,7 @@
+"use strict";
+
+self.addEventListener("message", ({ data }) => foo(data));
+
+function foo(data) {
+  throw new Error("worker2");
+}