summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/xpcshell/test_logpoint-03.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /devtools/server/tests/xpcshell/test_logpoint-03.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/server/tests/xpcshell/test_logpoint-03.js')
-rw-r--r--devtools/server/tests/xpcshell/test_logpoint-03.js82
1 files changed, 82 insertions, 0 deletions
diff --git a/devtools/server/tests/xpcshell/test_logpoint-03.js b/devtools/server/tests/xpcshell/test_logpoint-03.js
new file mode 100644
index 0000000000..b5d4440889
--- /dev/null
+++ b/devtools/server/tests/xpcshell/test_logpoint-03.js
@@ -0,0 +1,82 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Check that logpoints generate console errors if the logpoint statement is invalid.
+ */
+
+const Resources = require("resource://devtools/server/actors/resources/index.js");
+
+add_task(
+ threadFrontTest(async ({ threadActor, threadFront, debuggee, client }) => {
+ let lastMessage, lastExpression;
+ const targetActor = threadActor._parent;
+ // Only Workers are evaluating through the WebConsoleActor.
+ // Tabs will be evaluating directly via the frame object.
+ targetActor._consoleActor = {
+ evaluateJS(expression) {
+ lastExpression = expression;
+ },
+ };
+
+ // And then listen for resource RDP event.
+ // Bug 1646677: But we should probably migrate this test to ResourceCommand so that
+ // we don't have to hack the server side via Resource.watchResources call.
+ targetActor.on("resource-available-form", resources => {
+ if (resources[0].resourceType == Resources.TYPES.CONSOLE_MESSAGE) {
+ lastMessage = resources[0].message;
+ }
+ });
+
+ // But both tabs and processes will be going through the ConsoleMessages module
+ // We force watching for console message first,
+ await Resources.watchResources(targetActor, [
+ Resources.TYPES.CONSOLE_MESSAGE,
+ ]);
+
+ const packet = await executeOnNextTickAndWaitForPause(
+ () => evalCode(debuggee),
+ threadFront
+ );
+
+ const source = await getSourceById(threadFront, packet.frame.where.actor);
+
+ // Set a logpoint which should throw an error message.
+ await threadFront.setBreakpoint(
+ {
+ sourceUrl: source.url,
+ line: 3,
+ },
+ { logValue: "c" }
+ );
+
+ // Execute the rest of the code.
+ await threadFront.resume();
+
+ // NOTE: logpoints evaluated in a worker have a lastExpression
+ if (lastMessage) {
+ Assert.equal(lastMessage.level, "logPointError");
+ Assert.equal(lastMessage.arguments[0], "c is not defined");
+ Assert.ok(/\d+\.\d+/.test(lastMessage.timeStamp));
+ } else {
+ Assert.equal(lastExpression.text, "console.log(...[c])");
+ Assert.equal(lastExpression.lineNumber, 3);
+ }
+ })
+);
+
+function evalCode(debuggee) {
+ /* eslint-disable */
+ Cu.evalInSandbox(
+ "debugger;\n" + // 1
+ "var a = 'three';\n" + // 2
+ "var b = 2;\n", // 3
+ debuggee,
+ "1.8",
+ "test.js",
+ 1
+ );
+ /* eslint-enable */
+}