2018-05-15 14:00:49 +03:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<title>Test for timeStart/timeLog/timeEnd in console</title>
|
|
|
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<script type="application/javascript">
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
2018-05-23 17:06:31 +03:00
|
|
|
var reduceTimePrecisionPrevPrefValue = SpecialPowers.getBoolPref("privacy.reduceTimerPrecision");
|
|
|
|
SpecialPowers.setBoolPref("privacy.reduceTimerPrecision", false);
|
|
|
|
|
2018-05-15 19:11:44 +03:00
|
|
|
function ConsoleListener() {
|
|
|
|
SpecialPowers.addObserver(this, "console-api-log-event");
|
2018-05-15 14:00:49 +03:00
|
|
|
}
|
|
|
|
|
2018-05-15 19:11:44 +03:00
|
|
|
ConsoleListener.prototype = {
|
|
|
|
observe(aSubject, aTopic, aData) {
|
|
|
|
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() {
|
|
|
|
SpecialPowers.removeObserver(this, "console-api-log-event");
|
|
|
|
},
|
|
|
|
|
|
|
|
waitFor(cb) {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
this._cb = cb;
|
|
|
|
this._resolve = resolve;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
let listener = new ConsoleListener();
|
|
|
|
|
2018-05-15 14:00:49 +03:00
|
|
|
// Timer creation:
|
|
|
|
async function runTest() {
|
2018-05-15 19:11:44 +03:00
|
|
|
let cl = listener.waitFor(obj => {
|
2018-05-15 14:00:49 +03:00
|
|
|
return ("timer" in obj) &&
|
|
|
|
("name" in obj.timer) &&
|
|
|
|
obj.timer.name == 'test';
|
|
|
|
});
|
2018-05-15 19:11:44 +03:00
|
|
|
|
2018-05-15 14:00:49 +03:00
|
|
|
console.time('test');
|
|
|
|
await cl;
|
|
|
|
ok(true, "Console.time received!");
|
|
|
|
|
|
|
|
// Timer check:
|
2018-05-15 19:11:44 +03:00
|
|
|
cl = listener.waitFor(obj => {
|
2018-05-15 14:00:49 +03:00
|
|
|
return ("timer" in obj) &&
|
|
|
|
("name" in obj.timer) &&
|
|
|
|
obj.timer.name == 'test' &&
|
|
|
|
("duration" in obj.timer) &&
|
|
|
|
obj.timer.duration > 0 &&
|
|
|
|
obj.arguments[1] == 1 &&
|
|
|
|
obj.arguments[2] == 2 &&
|
|
|
|
obj.arguments[3] == 3 &&
|
|
|
|
obj.arguments[4] == 4;
|
|
|
|
});
|
|
|
|
console.timeLog('test', 1, 2, 3, 4);
|
|
|
|
await cl;
|
|
|
|
ok(true, "Console.timeLog received!");
|
|
|
|
|
|
|
|
// Time deleted:
|
2018-05-15 19:11:44 +03:00
|
|
|
cl = listener.waitFor(obj => {
|
2018-05-15 14:00:49 +03:00
|
|
|
return ("timer" in obj) &&
|
|
|
|
("name" in obj.timer) &&
|
|
|
|
obj.timer.name == 'test' &&
|
|
|
|
("duration" in obj.timer) &&
|
|
|
|
obj.timer.duration > 0;
|
|
|
|
});
|
|
|
|
console.timeEnd('test');
|
|
|
|
await cl;
|
|
|
|
ok(true, "Console.timeEnd received!");
|
|
|
|
|
|
|
|
// Here an error:
|
2018-05-15 19:11:44 +03:00
|
|
|
cl = listener.waitFor(obj => {
|
2018-05-15 14:00:49 +03:00
|
|
|
return ("timer" in obj) &&
|
|
|
|
("name" in obj.timer) &&
|
|
|
|
obj.timer.name == 'test' &&
|
|
|
|
("error" in obj.timer);
|
|
|
|
});
|
|
|
|
console.timeLog('test');
|
|
|
|
await cl;
|
2018-05-15 19:11:44 +03:00
|
|
|
ok(true, "Console.time with error received!");
|
2018-05-15 14:00:49 +03:00
|
|
|
}
|
|
|
|
|
2018-05-15 19:11:44 +03:00
|
|
|
runTest().then(() => {
|
|
|
|
listener.shutdown();
|
2018-05-23 17:06:31 +03:00
|
|
|
|
|
|
|
SpecialPowers.setBoolPref("privacy.reduceTimerPrecision", reduceTimePrecisionPrevPrefValue);
|
2018-05-15 19:11:44 +03:00
|
|
|
SimpleTest.finish();
|
|
|
|
});
|
2018-05-15 14:00:49 +03:00
|
|
|
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|