diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:37 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:37 +0000 |
commit | a90a5cba08fdf6c0ceb95101c275108a152a3aed (patch) | |
tree | 532507288f3defd7f4dcf1af49698bcb76034855 /dom/console/tests | |
parent | Adding debian version 126.0.1-1. (diff) | |
download | firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.tar.xz firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/console/tests')
-rw-r--r-- | dom/console/tests/xpcshell/test_worker.js | 59 | ||||
-rw-r--r-- | dom/console/tests/xpcshell/worker.mjs | 15 | ||||
-rw-r--r-- | dom/console/tests/xpcshell/xpcshell.toml | 6 |
3 files changed, 80 insertions, 0 deletions
diff --git a/dom/console/tests/xpcshell/test_worker.js b/dom/console/tests/xpcshell/test_worker.js new file mode 100644 index 0000000000..7792dfc2da --- /dev/null +++ b/dom/console/tests/xpcshell/test_worker.js @@ -0,0 +1,59 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * Tests for console.createInstance usage in workers. + * + * Also tests that the use of `maxLogLevelPref` logs an error, and log levels + * fallback to the `maxLogLevel` option. + */ + +"use strict"; + +let { TestUtils } = ChromeUtils.importESModule( + "resource://testing-common/TestUtils.sys.mjs" +); + +add_task(async function () { + let endConsoleListening = TestUtils.listenForConsoleMessages(); + let workerCompleteDeferred = Promise.withResolvers(); + + const worker = new ChromeWorker("resource://test/worker.mjs"); + worker.onmessage = workerCompleteDeferred.resolve; + worker.postMessage({}); + + await workerCompleteDeferred.promise; + + let messages = await endConsoleListening(); + + // Should log that we can't use `maxLogLevelPref`, and the warning message. + // The info message should not be logged, as that's lower than the specified + // `maxLogLevel` in the worker. + Assert.equal(messages.length, 2, "Should have received two messages"); + + // First message should be the error that `maxLogLevelPref` cannot be used. + Assert.equal(messages[0].level, "error", "Should be an error message"); + Assert.equal( + messages[0].prefix, + "testPrefix", + "Should have the correct prefix" + ); + Assert.equal( + messages[0].arguments[0], + "Console.maxLogLevelPref is not supported within workers!", + "Should have the correct message text" + ); + + // Second message should be the warning. + Assert.equal(messages[1].level, "warn", "Should be a warning message"); + Assert.equal( + messages[1].prefix, + "testPrefix", + "Should have the correct prefix" + ); + Assert.equal( + messages[1].arguments[0], + "Test Warn", + "Should have the correct message text" + ); +}); diff --git a/dom/console/tests/xpcshell/worker.mjs b/dom/console/tests/xpcshell/worker.mjs new file mode 100644 index 0000000000..4a1ff21b00 --- /dev/null +++ b/dom/console/tests/xpcshell/worker.mjs @@ -0,0 +1,15 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +onmessage = () => { + let logConsole = console.createInstance({ + maxLogLevelPref: "browser.test.logLevel", + maxLogLevel: "Warn", + prefix: "testPrefix", + }); + + logConsole.warn("Test Warn"); + logConsole.info("Test Info"); + + postMessage({}); +}; diff --git a/dom/console/tests/xpcshell/xpcshell.toml b/dom/console/tests/xpcshell/xpcshell.toml index c5cc54d665..621605221d 100644 --- a/dom/console/tests/xpcshell/xpcshell.toml +++ b/dom/console/tests/xpcshell/xpcshell.toml @@ -11,3 +11,9 @@ support-files = "" ["test_formatting.js"] ["test_reportForServiceWorkerScope.js"] + +["test_worker.js"] +skip-if = ["os == 'android'"] # Uses ChromeWorker. +support-files = [ + "worker.mjs", +] |