blob: 05f44ca9c03e3beae3b3cea4d8cde1d8ed90d592 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script>
function test()
{
let suite = InspectorTest.createAsyncSuite("console.time and console.timeEnd");
suite.addTestCase({
name: "DefaultLabel",
description: "Test that default label works as expected.",
test(resolve, reject) {
let seen = 0;
const expected = 3;
WI.consoleManager.addEventListener(WI.ConsoleManager.Event.MessageAdded, handler);
function handler(event) {
let message = event.data.message;
InspectorTest.expectThat(message.type === WI.ConsoleMessage.MessageType.Timing, "Should receive a Timing type message.");
InspectorTest.expectThat(message.messageText.includes("default"), "Message should contain the 'default' label name somewhere.");
if (++seen === expected) {
WI.consoleManager.removeEventListener(WI.ConsoleManager.Event.MessageAdded, handler);
resolve();
}
}
InspectorTest.evaluateInPage("console.time()");
InspectorTest.evaluateInPage("console.timeEnd()");
InspectorTest.evaluateInPage("console.time(undefined)");
InspectorTest.evaluateInPage("console.timeEnd('default')");
InspectorTest.evaluateInPage("console.time('default')");
InspectorTest.evaluateInPage("console.timeEnd(undefined)");
}
});
suite.addTestCase({
name: "UserLabels",
description: "Test that user labels works as expected.",
test(resolve, reject) {
WI.consoleManager.awaitEvent(WI.ConsoleManager.Event.MessageAdded)
.then((event) => {
let message = event.data.message;
InspectorTest.expectThat(message.type === WI.ConsoleMessage.MessageType.Timing, "Should receive a Timing type message.");
InspectorTest.expectThat(message.messageText.includes("my-label"), "Message should contain the 'my-label' label name somewhere.");
})
.then(resolve, reject);
InspectorTest.evaluateInPage("console.time('my-label')");
InspectorTest.evaluateInPage("console.timeEnd('my-label')");
}
});
suite.addTestCase({
name: "MultipleTimers",
description: "Test that multiple timers running at the same time work as expected.",
test(resolve, reject) {
let seen = 0;
const expected = 2;
WI.consoleManager.addEventListener(WI.ConsoleManager.Event.MessageAdded, handler);
function handler(event) {
let message = event.data.message;
let expectedLabel = seen === 0 ? "my-label-2" : "my-label-1";
InspectorTest.expectThat(message.type === WI.ConsoleMessage.MessageType.Timing, "Should receive a Timing type message.");
InspectorTest.expectThat(message.messageText.includes(expectedLabel), "Message should contain the '" + expectedLabel + "' label name somewhere.");
if (++seen === expected) {
WI.consoleManager.removeEventListener(WI.ConsoleManager.Event.MessageAdded, handler);
resolve();
}
}
InspectorTest.evaluateInPage("console.time('my-label-1')");
InspectorTest.evaluateInPage("console.time('my-label-2')");
InspectorTest.evaluateInPage("console.timeEnd('my-label-2')");
InspectorTest.evaluateInPage("console.timeEnd('my-label-1')");
}
});
suite.addTestCase({
name: "WarnWhenExisting",
description: "Test for a warning when trying to start an already started timer.",
test(resolve, reject) {
WI.consoleManager.addEventListener(WI.ConsoleManager.Event.MessageAdded, handler);
function handler(event) {
let message = event.data.message;
if (message.level === WI.ConsoleMessage.MessageLevel.Warning) {
InspectorTest.expectThat(message.type === WI.ConsoleMessage.MessageType.Timing, "Should receive a Timing type message.");
InspectorTest.pass("Should receive a Warning level message");
InspectorTest.expectThat(message.messageText.includes("default"), "Message should contain the 'default' label name somewhere.");
return;
}
if (message.type === WI.ConsoleMessage.MessageType.Timing) {
WI.consoleManager.removeEventListener(WI.ConsoleManager.Event.MessageAdded, handler);
resolve();
}
}
InspectorTest.evaluateInPage("console.time()");
InspectorTest.evaluateInPage("console.time()"); // Warning
InspectorTest.evaluateInPage("console.timeEnd()");
}
});
suite.addTestCase({
name: "WarnWhenNotExisting",
description: "Test for a warning when trying to start an already started timer.",
test(resolve, reject) {
WI.consoleManager.awaitEvent(WI.ConsoleManager.Event.MessageAdded)
.then((event) => {
let message = event.data.message;
InspectorTest.expectThat(message.type === WI.ConsoleMessage.MessageType.Timing, "Should receive a Timing type message.");
InspectorTest.expectThat(message.level === WI.ConsoleMessage.MessageLevel.Warning, "Should receive a Warning level message.");
InspectorTest.expectThat(message.messageText.includes("default"), "Message should contain the 'default' label name somewhere.");
})
.then(resolve, reject);
InspectorTest.evaluateInPage("console.timeEnd()");
}
});
suite.runTestCasesAndFinish();
}
</script>
</head>
<body onload="runTest()">
<p>Tests for the console.time and console.timeEnd APIs.</p>
</body>
</html>