Skip to content

Commit

Permalink
Bug 1578623 add test for syntax errors and uncaught exceptions in wor…
Browse files Browse the repository at this point in the history
…klet scripts r=bhackett

Depends on D44611

Differential Revision: https://phabricator.services.mozilla.com/D44612

--HG--
rename : devtools/client/webconsole/test/browser/browser_webconsole_worker_error.js => devtools/client/webconsole/test/browser/browser_webconsole_worklet_error.js
extra : moz-landing-system : lando
  • Loading branch information
karlt committed Sep 9, 2019
1 parent 5ad63ce commit 337fbc6
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ devtools/server/tests/unit/babel_and_browserify_script_with_source_map.js
devtools/server/tests/unit/setBreakpoint*
devtools/server/tests/unit/sourcemapped.js

# Testing syntax error
devtools/client/webconsole/test/browser/test-syntaxerror-worklet.js

# devtools specific format test file
devtools/server/tests/unit/xpcshell_debugging_script.js

Expand Down
5 changes: 4 additions & 1 deletion devtools/client/webconsole/test/browser/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ module.exports = {
// Extend from the shared list of defined globals for mochitests.
"extends": "../../../../.eslintrc.mochitests.js",
"overrides": [{
"files": ["test-dynamic-import.js"],
"files": [
"test-dynamic-import.js",
"test-error-worklet.js",
],
"parserOptions": {
"sourceType": "module",
},
Expand Down
4 changes: 4 additions & 0 deletions devtools/client/webconsole/test/browser/browser.ini
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ support-files =
test-error-worker.html
test-error-worker.js
test-error-worker2.js
test-error-worklet.html
test-error-worklet.js
test-eval-error.html
test-eval-in-stackframe.html
test-eval-sources.html
Expand Down Expand Up @@ -140,6 +142,7 @@ support-files =
test-subresource-security-error.html
test-subresource-security-error.js
test-subresource-security-error.js^headers^
test-syntaxerror-worklet.js
test-time-methods.html
test-trackingprotection-securityerrors.html
test-warning-groups.html
Expand Down Expand Up @@ -502,3 +505,4 @@ skip-if = (os == "win" && bits == 32) && !debug # Bug 1560261
[browser_webconsole_websocket.js]
[browser_webconsole_worker_error.js]
[browser_webconsole_worker_evaluate.js]
[browser_webconsole_worklet_error.js]
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */

// Tests that syntax errors in worklet scripts show in the console and that
// throwing uncaught errors and primitive values in worklets shows a stack.

"use strict";

const TEST_URI =
"https://example.com/browser/devtools/client/webconsole/" +
"test/browser/test-error-worklet.html";

add_task(async function() {
await SpecialPowers.pushPrefEnv({
set: [["dom.audioworklet.enabled", true], ["dom.worklet.enabled", true]],
});

const hud = await openNewTabAndConsole(TEST_URI);

await waitFor(() =>
findMessage(hud, "SyntaxError: duplicate formal argument")
);
ok(true, "Received expected SyntaxError");

await checkMessageStack(hud, "addModule", [18, 21]);
await checkMessageStack(hud, "process", [7, 12]);
});
24 changes: 24 additions & 0 deletions devtools/client/webconsole/test/browser/test-error-worklet.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Worklet error generator</title>
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
</head>
<script>
"use strict";
const context = new AudioContext();

context.audioWorklet.addModule("test-syntaxerror-worklet.js").catch(
() => context.audioWorklet.addModule("test-error-worklet.js")
).then(() => {
const workletNode = new AudioWorkletNode(context, "error");
const oscillator = new OscillatorNode(context);
oscillator.connect(workletNode);
oscillator.start();
});

</script>
</html>
21 changes: 21 additions & 0 deletions devtools/client/webconsole/test/browser/test-error-worklet.js
Original file line number Diff line number Diff line change
@@ -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/ */

function throw_process() {
throw "process"; // eslint-disable-line no-throw-literal
}

class ErrorProcessor extends AudioWorkletProcessor {
process() {
throw_process();
}
}
registerProcessor("error", ErrorProcessor);

function throw_error() {
throw new Error("addModule");
}

throw_error();
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* -*- 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/ */

function f(a, a) {}

0 comments on commit 337fbc6

Please sign in to comment.