forked from Floorp-Projects/Floorp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1891789 - Allow console.createInstance to work properly in worker…
…s. r=peterv Also raise an error on the console if 'maxLogLevelPref' is used when it shouldn't be. Differential Revision: https://phabricator.services.mozilla.com/D208000
- Loading branch information
Showing
7 changed files
with
103 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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({}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters