Bug 1458466 - Implement Console.timeLog(optional DOMString label = "default") - fixed an intermittent failure, r=me

This commit is contained in:
Andrea Marchesini 2018-05-15 18:11:44 +02:00
Родитель 28a86c9503
Коммит 625539c9d7
1 изменённых файлов: 46 добавлений и 19 удалений

Просмотреть файл

@ -11,34 +11,58 @@
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
function consoleListener(cb) { function ConsoleListener() {
return new Promise(resolve => { SpecialPowers.addObserver(this, "console-api-log-event");
let observer = {
observe: function listener(aSubject, aTopic, aData) {
var obj = aSubject.wrappedJSObject;
if (obj.arguments[0] == 'test' && cb(obj)) {
SpecialPowers.removeObserver(observer, "console-api-log-event");
resolve();
}
}
};
SpecialPowers.addObserver(observer, "console-api-log-event");
});
} }
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();
// Timer creation: // Timer creation:
async function runTest() { async function runTest() {
var cl = consoleListener(function(obj) { let cl = listener.waitFor(obj => {
return ("timer" in obj) && return ("timer" in obj) &&
("name" in obj.timer) && ("name" in obj.timer) &&
obj.timer.name == 'test'; obj.timer.name == 'test';
}); });
console.time('test'); console.time('test');
await cl; await cl;
ok(true, "Console.time received!"); ok(true, "Console.time received!");
// Timer check: // Timer check:
cl = consoleListener(obj => { cl = listener.waitFor(obj => {
return ("timer" in obj) && return ("timer" in obj) &&
("name" in obj.timer) && ("name" in obj.timer) &&
obj.timer.name == 'test' && obj.timer.name == 'test' &&
@ -54,7 +78,7 @@ async function runTest() {
ok(true, "Console.timeLog received!"); ok(true, "Console.timeLog received!");
// Time deleted: // Time deleted:
cl = consoleListener(obj => { cl = listener.waitFor(obj => {
return ("timer" in obj) && return ("timer" in obj) &&
("name" in obj.timer) && ("name" in obj.timer) &&
obj.timer.name == 'test' && obj.timer.name == 'test' &&
@ -66,7 +90,7 @@ async function runTest() {
ok(true, "Console.timeEnd received!"); ok(true, "Console.timeEnd received!");
// Here an error: // Here an error:
cl = consoleListener(obj => { cl = listener.waitFor(obj => {
return ("timer" in obj) && return ("timer" in obj) &&
("name" in obj.timer) && ("name" in obj.timer) &&
obj.timer.name == 'test' && obj.timer.name == 'test' &&
@ -74,10 +98,13 @@ async function runTest() {
}); });
console.timeLog('test'); console.timeLog('test');
await cl; await cl;
ok(true, "Console.timeLog with error received!"); ok(true, "Console.time with error received!");
} }
runTest().then(SimpleTest.finish); runTest().then(() => {
listener.shutdown();
SimpleTest.finish();
});
</script> </script>
</body> </body>