summaryrefslogtreecommitdiffstats
path: root/dom/console/tests/xpcshell
diff options
context:
space:
mode:
Diffstat (limited to 'dom/console/tests/xpcshell')
-rw-r--r--dom/console/tests/xpcshell/test_basic.js31
-rw-r--r--dom/console/tests/xpcshell/test_formatting.js79
-rw-r--r--dom/console/tests/xpcshell/test_reportForServiceWorkerScope.js44
-rw-r--r--dom/console/tests/xpcshell/xpcshell.ini7
4 files changed, 161 insertions, 0 deletions
diff --git a/dom/console/tests/xpcshell/test_basic.js b/dom/console/tests/xpcshell/test_basic.js
new file mode 100644
index 0000000000..00fb253a4c
--- /dev/null
+++ b/dom/console/tests/xpcshell/test_basic.js
@@ -0,0 +1,31 @@
+/* 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);
+
+ let p = new Promise(resolve => {
+ function consoleListener() {
+ Services.obs.addObserver(this, "console-api-log-event");
+ }
+
+ consoleListener.prototype = {
+ observe(aSubject, aTopic, aData) {
+ 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");
+
+ Services.obs.removeObserver(this, "console-api-log-event");
+ resolve();
+ },
+ };
+
+ new consoleListener();
+ });
+
+ console.log(42);
+ await p;
+});
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;
+});
diff --git a/dom/console/tests/xpcshell/test_reportForServiceWorkerScope.js b/dom/console/tests/xpcshell/test_reportForServiceWorkerScope.js
new file mode 100644
index 0000000000..9a33aca7b7
--- /dev/null
+++ b/dom/console/tests/xpcshell/test_reportForServiceWorkerScope.js
@@ -0,0 +1,44 @@
+/* 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() {
+ let p = new Promise(resolve => {
+ function consoleListener() {
+ Services.obs.addObserver(this, "console-api-log-event");
+ }
+
+ consoleListener.prototype = {
+ observe(aSubject, aTopic, aData) {
+ 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");
+
+ Services.obs.removeObserver(this, "console-api-log-event");
+ 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.ini b/dom/console/tests/xpcshell/xpcshell.ini
new file mode 100644
index 0000000000..5dbc841bd6
--- /dev/null
+++ b/dom/console/tests/xpcshell/xpcshell.ini
@@ -0,0 +1,7 @@
+[DEFAULT]
+head =
+support-files =
+
+[test_basic.js]
+[test_reportForServiceWorkerScope.js]
+[test_formatting.js]