From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- dom/console/tests/chrome.toml | 11 ++ dom/console/tests/console.sys.mjs | 45 ++++++++ dom/console/tests/file_empty.html | 1 + dom/console/tests/head.js | 24 +++++ dom/console/tests/mochitest.toml | 23 ++++ dom/console/tests/test_bug659625.html | 107 +++++++++++++++++++ dom/console/tests/test_bug978522.html | 32 ++++++ dom/console/tests/test_bug979109.html | 32 ++++++ dom/console/tests/test_bug989665.html | 21 ++++ dom/console/tests/test_console.xhtml | 35 ++++++ dom/console/tests/test_consoleEmptyStack.html | 26 +++++ dom/console/tests/test_console_binding.html | 40 +++++++ dom/console/tests/test_console_proto.html | 17 +++ dom/console/tests/test_count.html | 117 +++++++++++++++++++++ dom/console/tests/test_jsm.xhtml | 103 ++++++++++++++++++ dom/console/tests/test_timer.html | 112 ++++++++++++++++++++ dom/console/tests/xpcshell/head.js | 22 ++++ dom/console/tests/xpcshell/test_basic.js | 29 +++++ .../tests/xpcshell/test_console_shouldLog.js | 35 ++++++ .../xpcshell/test_failing_console_listener.js | 35 ++++++ dom/console/tests/xpcshell/test_formatting.js | 77 ++++++++++++++ .../xpcshell/test_reportForServiceWorkerScope.js | 42 ++++++++ dom/console/tests/xpcshell/xpcshell.toml | 13 +++ 23 files changed, 999 insertions(+) create mode 100644 dom/console/tests/chrome.toml create mode 100644 dom/console/tests/console.sys.mjs create mode 100644 dom/console/tests/file_empty.html create mode 100644 dom/console/tests/head.js create mode 100644 dom/console/tests/mochitest.toml create mode 100644 dom/console/tests/test_bug659625.html create mode 100644 dom/console/tests/test_bug978522.html create mode 100644 dom/console/tests/test_bug979109.html create mode 100644 dom/console/tests/test_bug989665.html create mode 100644 dom/console/tests/test_console.xhtml create mode 100644 dom/console/tests/test_consoleEmptyStack.html create mode 100644 dom/console/tests/test_console_binding.html create mode 100644 dom/console/tests/test_console_proto.html create mode 100644 dom/console/tests/test_count.html create mode 100644 dom/console/tests/test_jsm.xhtml create mode 100644 dom/console/tests/test_timer.html create mode 100644 dom/console/tests/xpcshell/head.js create mode 100644 dom/console/tests/xpcshell/test_basic.js create mode 100644 dom/console/tests/xpcshell/test_console_shouldLog.js create mode 100644 dom/console/tests/xpcshell/test_failing_console_listener.js create mode 100644 dom/console/tests/xpcshell/test_formatting.js create mode 100644 dom/console/tests/xpcshell/test_reportForServiceWorkerScope.js create mode 100644 dom/console/tests/xpcshell/xpcshell.toml (limited to 'dom/console/tests') diff --git a/dom/console/tests/chrome.toml b/dom/console/tests/chrome.toml new file mode 100644 index 0000000000..5927dbb9cb --- /dev/null +++ b/dom/console/tests/chrome.toml @@ -0,0 +1,11 @@ +[DEFAULT] +skip-if = ["os == 'android'"] +support-files = [ + "file_empty.html", + "console.sys.mjs", + "head.js", +] + +["test_console.xhtml"] + +["test_jsm.xhtml"] diff --git a/dom/console/tests/console.sys.mjs b/dom/console/tests/console.sys.mjs new file mode 100644 index 0000000000..d239d58a5d --- /dev/null +++ b/dom/console/tests/console.sys.mjs @@ -0,0 +1,45 @@ +/** + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ +export var ConsoleTest = { + go(dumpFunction) { + console.log("Hello world!"); + console.createInstance().log("Hello world!"); + + let c = console.createInstance({ + consoleID: "wow", + innerID: "CUSTOM INNER", + dump: dumpFunction, + prefix: "_PREFIX_", + }); + + c.log("Hello world!"); + c.trace("Hello world!"); + + console + .createInstance({ innerID: "LEVEL", maxLogLevel: "Off" }) + .log("Invisible!"); + console + .createInstance({ innerID: "LEVEL", maxLogLevel: "All" }) + .log("Hello world!"); + console + .createInstance({ + innerID: "LEVEL", + maxLogLevelPref: "pref.test.console", + }) + .log("Hello world!"); + + this.c2 = console.createInstance({ + innerID: "NO PREF", + maxLogLevel: "Warn", + maxLogLevelPref: "pref.test.console.notset", + }); + this.c2.log("Invisible!"); + this.c2.warn("Hello world!"); + }, + + go2() { + this.c2.log("Hello world!"); + }, +}; diff --git a/dom/console/tests/file_empty.html b/dom/console/tests/file_empty.html new file mode 100644 index 0000000000..495c23ec8a --- /dev/null +++ b/dom/console/tests/file_empty.html @@ -0,0 +1 @@ + diff --git a/dom/console/tests/head.js b/dom/console/tests/head.js new file mode 100644 index 0000000000..3e9c72cfb9 --- /dev/null +++ b/dom/console/tests/head.js @@ -0,0 +1,24 @@ +/** + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +const ConsoleAPIStorage = SpecialPowers.Cc[ + "@mozilla.org/consoleAPI-storage;1" +].getService(SpecialPowers.Ci.nsIConsoleAPIStorage); + +// This is intended to just be a drop-in replacement for an old observer +// notification. +function addConsoleStorageListener(listener) { + listener.__handler = (message, id) => { + listener.observe(message, id); + }; + ConsoleAPIStorage.addLogEventListener( + listener.__handler, + SpecialPowers.wrap(document).nodePrincipal + ); +} + +function removeConsoleStorageListener(listener) { + ConsoleAPIStorage.removeLogEventListener(listener.__handler); +} diff --git a/dom/console/tests/mochitest.toml b/dom/console/tests/mochitest.toml new file mode 100644 index 0000000000..4768f9521e --- /dev/null +++ b/dom/console/tests/mochitest.toml @@ -0,0 +1,23 @@ +[DEFAULT] +support-files = [ + "file_empty.html", + "head.js", +] + +["test_bug659625.html"] + +["test_bug978522.html"] + +["test_bug979109.html"] + +["test_bug989665.html"] + +["test_consoleEmptyStack.html"] + +["test_console_binding.html"] + +["test_console_proto.html"] + +["test_count.html"] + +["test_timer.html"] diff --git a/dom/console/tests/test_bug659625.html b/dom/console/tests/test_bug659625.html new file mode 100644 index 0000000000..1cf93d9bfd --- /dev/null +++ b/dom/console/tests/test_bug659625.html @@ -0,0 +1,107 @@ + + + + + + Test for Bug 659625 + + + + +Mozilla Bug 659625 + + + diff --git a/dom/console/tests/test_bug978522.html b/dom/console/tests/test_bug978522.html new file mode 100644 index 0000000000..b0cc4e76b9 --- /dev/null +++ b/dom/console/tests/test_bug978522.html @@ -0,0 +1,32 @@ + + + + + + Test for Bug 978522 - basic support + + + + +Mozilla Bug 978522 + + + diff --git a/dom/console/tests/test_bug979109.html b/dom/console/tests/test_bug979109.html new file mode 100644 index 0000000000..231808e260 --- /dev/null +++ b/dom/console/tests/test_bug979109.html @@ -0,0 +1,32 @@ + + + + + + Test for Bug 979109 + + + + +Mozilla Bug 979109 + + + diff --git a/dom/console/tests/test_bug989665.html b/dom/console/tests/test_bug989665.html new file mode 100644 index 0000000000..484656a06b --- /dev/null +++ b/dom/console/tests/test_bug989665.html @@ -0,0 +1,21 @@ + + + + + + Test for Bug 989665 + + + + +Mozilla Bug 989665 + + + diff --git a/dom/console/tests/test_console.xhtml b/dom/console/tests/test_console.xhtml new file mode 100644 index 0000000000..cbeb9469e7 --- /dev/null +++ b/dom/console/tests/test_console.xhtml @@ -0,0 +1,35 @@ + + + + + + diff --git a/dom/console/tests/test_consoleEmptyStack.html b/dom/console/tests/test_consoleEmptyStack.html new file mode 100644 index 0000000000..ec77d0ac6f --- /dev/null +++ b/dom/console/tests/test_consoleEmptyStack.html @@ -0,0 +1,26 @@ + + + + + Test for empty stack in console + + + + + + + + diff --git a/dom/console/tests/test_console_binding.html b/dom/console/tests/test_console_binding.html new file mode 100644 index 0000000000..0ec1926400 --- /dev/null +++ b/dom/console/tests/test_console_binding.html @@ -0,0 +1,40 @@ + + + + + Test Console binding + + + + + + + + diff --git a/dom/console/tests/test_console_proto.html b/dom/console/tests/test_console_proto.html new file mode 100644 index 0000000000..3e9461bade --- /dev/null +++ b/dom/console/tests/test_console_proto.html @@ -0,0 +1,17 @@ + + + + + Test for console.__proto__ + + + + + + + diff --git a/dom/console/tests/test_count.html b/dom/console/tests/test_count.html new file mode 100644 index 0000000000..5591768150 --- /dev/null +++ b/dom/console/tests/test_count.html @@ -0,0 +1,117 @@ + + + + + Test for count/countReset in console + + + + + + + + diff --git a/dom/console/tests/test_jsm.xhtml b/dom/console/tests/test_jsm.xhtml new file mode 100644 index 0000000000..0257956393 --- /dev/null +++ b/dom/console/tests/test_jsm.xhtml @@ -0,0 +1,103 @@ + + + + + + + + + diff --git a/dom/console/tests/test_timer.html b/dom/console/tests/test_timer.html new file mode 100644 index 0000000000..fa3ca7baec --- /dev/null +++ b/dom/console/tests/test_timer.html @@ -0,0 +1,112 @@ + + + + + Test for timeStart/timeLog/timeEnd in console + + + + + + + + diff --git a/dom/console/tests/xpcshell/head.js b/dom/console/tests/xpcshell/head.js new file mode 100644 index 0000000000..446eb9ba9e --- /dev/null +++ b/dom/console/tests/xpcshell/head.js @@ -0,0 +1,22 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +const ConsoleAPIStorage = Cc["@mozilla.org/consoleAPI-storage;1"].getService( + Ci.nsIConsoleAPIStorage +); + +// This is intended to just be a drop-in replacement for an old observer +// notification. +function addConsoleStorageListener(listener) { + listener.__handler = (message, id) => { + listener.observe(message, id); + }; + ConsoleAPIStorage.addLogEventListener( + listener.__handler, + Cc["@mozilla.org/systemprincipal;1"].createInstance(Ci.nsIPrincipal) + ); +} + +function removeConsoleStorageListener(listener) { + ConsoleAPIStorage.removeLogEventListener(listener.__handler); +} diff --git a/dom/console/tests/xpcshell/test_basic.js b/dom/console/tests/xpcshell/test_basic.js new file mode 100644 index 0000000000..5736912979 --- /dev/null +++ b/dom/console/tests/xpcshell/test_basic.js @@ -0,0 +1,29 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +add_task(async function () { + Assert.ok("console" in this); + + let p = new Promise(resolve => { + function consoleListener() { + addConsoleStorageListener(this); + } + + consoleListener.prototype = { + observe(aSubject) { + let obj = aSubject.wrappedJSObject; + Assert.ok(obj.arguments[0] === 42, "Message received!"); + Assert.ok(obj.ID === "jsm", "The ID is JSM"); + Assert.ok(obj.innerID.endsWith("test_basic.js"), "The innerID matches"); + + removeConsoleStorageListener(this); + resolve(); + }, + }; + + new consoleListener(); + }); + + console.log(42); + await p; +}); diff --git a/dom/console/tests/xpcshell/test_console_shouldLog.js b/dom/console/tests/xpcshell/test_console_shouldLog.js new file mode 100644 index 0000000000..9e78c474db --- /dev/null +++ b/dom/console/tests/xpcshell/test_console_shouldLog.js @@ -0,0 +1,35 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +add_task(async function test_shouldLog_maxLogLevel() { + let ci = console.createInstance({ maxLogLevel: "Warn" }); + + Assert.ok( + ci.shouldLog("Error"), + "Should return true for logging a higher level" + ); + Assert.ok( + ci.shouldLog("Warn"), + "Should return true for logging the same level" + ); + Assert.ok( + !ci.shouldLog("Debug"), + "Should return false for logging a lower level;" + ); +}); + +add_task(async function test_shouldLog_maxLogLevelPref() { + Services.prefs.setStringPref("test.log", "Warn"); + let ci = console.createInstance({ maxLogLevelPref: "test.log" }); + + Assert.ok( + !ci.shouldLog("Debug"), + "Should return false for logging a lower level;" + ); + + Services.prefs.setStringPref("test.log", "Debug"); + Assert.ok( + ci.shouldLog("Debug"), + "Should return true for logging a lower level after pref update" + ); +}); diff --git a/dom/console/tests/xpcshell/test_failing_console_listener.js b/dom/console/tests/xpcshell/test_failing_console_listener.js new file mode 100644 index 0000000000..bb1b7cd46c --- /dev/null +++ b/dom/console/tests/xpcshell/test_failing_console_listener.js @@ -0,0 +1,35 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +add_task(async function () { + Assert.ok("console" in this); + + // Add a first listener that synchronously throws. + const removeListener1 = addConsoleListener(() => { + throw new Error("Fail"); + }); + + // Add a second listener updating a flag we can observe from the test. + let secondListenerCalled = false; + const removeListener2 = addConsoleListener( + () => (secondListenerCalled = true) + ); + + console.log(42); + Assert.ok(secondListenerCalled, "Second listener was called"); + + // Cleanup listeners. + removeListener1(); + removeListener2(); +}); + +function addConsoleListener(callback) { + const principal = Cc["@mozilla.org/systemprincipal;1"].createInstance( + Ci.nsIPrincipal + ); + ConsoleAPIStorage.addLogEventListener(callback, principal); + + return () => { + ConsoleAPIStorage.removeLogEventListener(callback, principal); + }; +} diff --git a/dom/console/tests/xpcshell/test_formatting.js b/dom/console/tests/xpcshell/test_formatting.js new file mode 100644 index 0000000000..89d5a1947e --- /dev/null +++ b/dom/console/tests/xpcshell/test_formatting.js @@ -0,0 +1,77 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +add_task(async function () { + Assert.ok("console" in this); + + const tests = [ + // Plain value. + [[42], ["42"]], + + // Integers. + [["%d", 42], ["42"]], + [["%i", 42], ["42"]], + [["c%iao", 42], ["c42ao"]], + + // Floats. + [["%2.4f", 42], ["42.0000"]], + [["%2.2f", 42], ["42.00"]], + [["%1.2f", 42], ["42.00"]], + [["a%3.2fb", 42], ["a42.00b"]], + [["%f", NaN], ["NaN"]], + + // Strings + [["%s", 42], ["42"]], + + // Empty values. + [ + ["", 42], + ["", "42"], + ], + [ + ["", 42], + ["", "42"], + ], + ]; + + let p = new Promise(resolve => { + let t = 0; + + function consoleListener() { + addConsoleStorageListener(this); + } + + consoleListener.prototype = { + observe(aSubject) { + let test = tests[t++]; + + let obj = aSubject.wrappedJSObject; + Assert.equal( + obj.arguments.length, + test[1].length, + "Same number of arguments" + ); + for (let i = 0; i < test[1].length; ++i) { + Assert.equal( + "" + obj.arguments[i], + test[1][i], + "Message received: " + test[1][i] + ); + } + + if (t === tests.length) { + removeConsoleStorageListener(this); + resolve(); + } + }, + }; + + new consoleListener(); + }); + + tests.forEach(test => { + console.log(...test[0]); + }); + + await p; +}); diff --git a/dom/console/tests/xpcshell/test_reportForServiceWorkerScope.js b/dom/console/tests/xpcshell/test_reportForServiceWorkerScope.js new file mode 100644 index 0000000000..f96519183c --- /dev/null +++ b/dom/console/tests/xpcshell/test_reportForServiceWorkerScope.js @@ -0,0 +1,42 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +add_task(async function () { + let p = new Promise(resolve => { + function consoleListener() { + addConsoleStorageListener(this); + } + + consoleListener.prototype = { + observe(aSubject) { + let obj = aSubject.wrappedJSObject; + Assert.ok(obj.arguments[0] === "Hello world!", "Message received!"); + Assert.ok(obj.ID === "scope", "The ID is the scope"); + Assert.ok( + obj.innerID === "ServiceWorker", + "The innerID is ServiceWorker" + ); + Assert.ok(obj.filename === "filename", "The filename matches"); + Assert.ok(obj.lineNumber === 42, "The lineNumber matches"); + Assert.ok(obj.columnNumber === 24, "The columnNumber matches"); + Assert.ok(obj.level === "error", "The level is correct"); + + removeConsoleStorageListener(this); + resolve(); + }, + }; + + new consoleListener(); + }); + + let ci = console.createInstance(); + ci.reportForServiceWorkerScope( + "scope", + "Hello world!", + "filename", + 42, + 24, + "error" + ); + await p; +}); diff --git a/dom/console/tests/xpcshell/xpcshell.toml b/dom/console/tests/xpcshell/xpcshell.toml new file mode 100644 index 0000000000..c5cc54d665 --- /dev/null +++ b/dom/console/tests/xpcshell/xpcshell.toml @@ -0,0 +1,13 @@ +[DEFAULT] +head = "head.js" +support-files = "" + +["test_basic.js"] + +["test_console_shouldLog.js"] + +["test_failing_console_listener.js"] + +["test_formatting.js"] + +["test_reportForServiceWorkerScope.js"] -- cgit v1.2.3