2018-05-22 12:34:41 +03:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<title>Test for count/countReset in console</title>
|
2019-04-16 06:53:28 +03:00
|
|
|
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
2022-05-03 20:21:59 +03:00
|
|
|
<script src="head.js"></script>
|
2018-05-22 12:34:41 +03:00
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<script type="application/javascript">
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
|
|
|
function ConsoleListener() {
|
2022-05-03 20:21:59 +03:00
|
|
|
addConsoleStorageListener(this);
|
2018-05-22 12:34:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ConsoleListener.prototype = {
|
2022-05-03 20:21:59 +03:00
|
|
|
observe(aSubject) {
|
2018-05-22 12:34:41 +03:00
|
|
|
let obj = aSubject.wrappedJSObject;
|
2018-12-20 01:38:44 +03:00
|
|
|
if (obj.arguments[0] != "test") {
|
2018-05-22 12:34:41 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this._cb) {
|
|
|
|
ok(false, "Callback not set!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this._cb(obj)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._cb = null;
|
|
|
|
this._resolve();
|
|
|
|
},
|
|
|
|
|
|
|
|
shutdown() {
|
2022-05-03 20:21:59 +03:00
|
|
|
removeConsoleStorageListener(this);
|
2018-05-22 12:34:41 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
waitFor(cb) {
|
|
|
|
return new Promise(resolve => {
|
2020-05-31 06:41:03 +03:00
|
|
|
this._cb = SpecialPowers.wrapCallback(cb);
|
2018-05-22 12:34:41 +03:00
|
|
|
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!");
|
|
|
|
}
|
|
|
|
|
2020-05-31 06:41:03 +03:00
|
|
|
runTest().then(() => {
|
|
|
|
listener.shutdown();
|
|
|
|
SimpleTest.finish();
|
|
|
|
});
|
2018-05-22 12:34:41 +03:00
|
|
|
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|