diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /dom/console/tests/xpcshell/test_formatting.js | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/console/tests/xpcshell/test_formatting.js')
-rw-r--r-- | dom/console/tests/xpcshell/test_formatting.js | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/dom/console/tests/xpcshell/test_formatting.js b/dom/console/tests/xpcshell/test_formatting.js new file mode 100644 index 0000000000..b84e7a1a98 --- /dev/null +++ b/dom/console/tests/xpcshell/test_formatting.js @@ -0,0 +1,79 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); + +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() { + Services.obs.addObserver(this, "console-api-log-event"); + } + + consoleListener.prototype = { + observe(aSubject, aTopic, aData) { + 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) { + Services.obs.removeObserver(this, "console-api-log-event"); + resolve(); + } + }, + }; + + new consoleListener(); + }); + + tests.forEach(test => { + console.log(...test[0]); + }); + + await p; +}); |