summaryrefslogtreecommitdiffstats
path: root/dom/console/tests/test_count.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/console/tests/test_count.html
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/console/tests/test_count.html')
-rw-r--r--dom/console/tests/test_count.html117
1 files changed, 117 insertions, 0 deletions
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 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>Test for count/countReset in console</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script src="head.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+ <script type="application/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+function ConsoleListener() {
+ addConsoleStorageListener(this);
+}
+
+ConsoleListener.prototype = {
+ observe(aSubject) {
+ let obj = aSubject.wrappedJSObject;
+ if (obj.arguments[0] != "test") {
+ return;
+ }
+
+ if (!this._cb) {
+ ok(false, "Callback not set!");
+ return;
+ }
+
+ if (!this._cb(obj)) {
+ return;
+ }
+
+ this._cb = null;
+ this._resolve();
+ },
+
+ shutdown() {
+ removeConsoleStorageListener(this);
+ },
+
+ waitFor(cb) {
+ return new Promise(resolve => {
+ this._cb = SpecialPowers.wrapCallback(cb);
+ this._resolve = resolve;
+ });
+ },
+};
+
+let listener = new ConsoleListener();
+
+async function runTest() {
+ // First count.
+ let cl = listener.waitFor(obj => {
+ return ("counter" in obj) &&
+ ("label" in obj.counter) &&
+ obj.counter.label == "test" &&
+ obj.counter.count == 1;
+ });
+ console.count("test");
+ await cl;
+ ok(true, "Console.count == 1 received!");
+
+ // Second count.
+ cl = listener.waitFor(obj => {
+ return ("counter" in obj) &&
+ ("label" in obj.counter) &&
+ obj.counter.label == "test" &&
+ obj.counter.count == 2;
+ });
+ console.count("test");
+ await cl;
+ ok(true, "Console.count == 2 received!");
+
+ // Counter reset.
+ cl = listener.waitFor(obj => {
+ return ("counter" in obj) &&
+ ("label" in obj.counter) &&
+ obj.counter.label == "test" &&
+ obj.counter.count == 0;
+ });
+ console.countReset("test");
+ await cl;
+ ok(true, "Console.countReset == 0 received!");
+
+ // Counter reset with error.
+ cl = listener.waitFor(obj => {
+ return ("counter" in obj) &&
+ ("label" in obj.counter) &&
+ obj.counter.label == "test" &&
+ obj.counter.error == "counterDoesntExist";
+ });
+ console.countReset("test");
+ await cl;
+ ok(true, "Console.countReset with error received!");
+
+ // First again!
+ cl = listener.waitFor(obj => {
+ return ("counter" in obj) &&
+ ("label" in obj.counter) &&
+ obj.counter.label == "test" &&
+ obj.counter.count == 1;
+ });
+ console.count("test");
+ await cl;
+ ok(true, "Console.count == 1 received!");
+}
+
+runTest().then(() => {
+ listener.shutdown();
+ SimpleTest.finish();
+});
+
+ </script>
+</body>
+</html>