test_worker.js (1802B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 /** 5 * Tests for console.createInstance usage in workers. 6 * 7 * Also tests that the use of `maxLogLevelPref` logs an error, and log levels 8 * fallback to the `maxLogLevel` option. 9 */ 10 11 "use strict"; 12 13 let { TestUtils } = ChromeUtils.importESModule( 14 "resource://testing-common/TestUtils.sys.mjs" 15 ); 16 17 add_task(async function () { 18 let endConsoleListening = TestUtils.listenForConsoleMessages(); 19 let workerCompleteDeferred = Promise.withResolvers(); 20 21 const worker = new ChromeWorker("resource://test/worker.mjs"); 22 worker.onmessage = workerCompleteDeferred.resolve; 23 worker.postMessage({}); 24 25 await workerCompleteDeferred.promise; 26 27 let messages = await endConsoleListening(); 28 29 // Should log that we can't use `maxLogLevelPref`, and the warning message. 30 // The info message should not be logged, as that's lower than the specified 31 // `maxLogLevel` in the worker. 32 Assert.equal(messages.length, 2, "Should have received two messages"); 33 34 // First message should be the error that `maxLogLevelPref` cannot be used. 35 Assert.equal(messages[0].level, "error", "Should be an error message"); 36 Assert.equal( 37 messages[0].prefix, 38 "testPrefix", 39 "Should have the correct prefix" 40 ); 41 Assert.equal( 42 messages[0].arguments[0], 43 "Console.maxLogLevelPref is not supported within workers!", 44 "Should have the correct message text" 45 ); 46 47 // Second message should be the warning. 48 Assert.equal(messages[1].level, "warn", "Should be a warning message"); 49 Assert.equal( 50 messages[1].prefix, 51 "testPrefix", 52 "Should have the correct prefix" 53 ); 54 Assert.equal( 55 messages[1].arguments[0], 56 "Test Warn", 57 "Should have the correct message text" 58 ); 59 });