blob: ad273198d70c3815bd393e2f2aa9e6bd813e2c58 [file] [log] [blame]
<html>
<head>
<script type="text/javascript" src="../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
<script>
function collectProfiles()
{
console.profile("outer");
console.profile(42);
console.profileEnd("outer");
console.profileEnd(42);
}
function test()
{
InspectorTest.fail = function(message)
{
InspectorTest.log("FAIL: " + message);
InspectorTest.completeTest();
}
InspectorTest.sendCommand("Profiler.enable", {});
InspectorTest.sendCommand("Runtime.evaluate", { expression: "collectProfiles()"}, didCollectProfiles);
var headers = [];
InspectorTest.eventHandler["Profiler.consoleProfileFinished"] = function(messageObject)
{
headers.push({
profile: messageObject["params"]["profile"],
title: messageObject["params"]["title"]
});
}
function didCollectProfiles(messageObject)
{
if (headers.length !== 2)
return InspectorTest.fail("Cannot retrive headers: " + JSON.stringify(messageObject, null, 4));
for (var i = 0; i < headers.length; i++) {
if (headers[i].title === "42") {
checkInnerProfile(headers[i].profile);
return;
}
}
InspectorTest.fail("Cannot find '42' profile header");
}
function checkInnerProfile(profile)
{
InspectorTest.log("SUCCESS: retrieved '42' profile");
var root = profile.head;
if (!findFunctionInProfile(root, "collectProfiles"))
return InspectorTest.fail("collectProfiles function not found in the profile: " + JSON.stringify(profile, null, 4));
InspectorTest.log("SUCCESS: found 'collectProfiles' function in the profile");
InspectorTest.completeTest();
}
function findFunctionInProfile(node, functionName)
{
if (node.functionName === functionName)
return true;
var children = node.children;
for (var i = 0; i < children.length; ++i)
if (findFunctionInProfile(children[i], functionName))
return true;
return false;
}
}
</script>
</head>
<body onload="runTest()">
<p>
Tests that console.profile/profileEnd will record CPU profile when inspector front-end is connected.<br>
</p>
</body>
</html>