| Index: LayoutTests/inspector-protocol/cpu-profiler/console-profile.html
 | 
| diff --git a/LayoutTests/inspector-protocol/cpu-profiler/console-profile.html b/LayoutTests/inspector-protocol/cpu-profiler/console-profile.html
 | 
| new file mode 100644
 | 
| index 0000000000000000000000000000000000000000..e5ff5cb2b697a9cbfd3b24dc2c0bfe05173fa8f9
 | 
| --- /dev/null
 | 
| +++ b/LayoutTests/inspector-protocol/cpu-profiler/console-profile.html
 | 
| @@ -0,0 +1,77 @@
 | 
| +<html>
 | 
| +<head>
 | 
| +<script type="text/javascript" src="../../http/tests/inspector-protocol/resources/protocol-test.js"></script>
 | 
| +<script>
 | 
| +function collectProfiles()
 | 
| +{
 | 
| +    console.profile("outer");
 | 
| +    console.profile("inner");
 | 
| +    console.profileEnd("outer");
 | 
| +    console.profileEnd("inner");
 | 
| +}
 | 
| +
 | 
| +function test()
 | 
| +{
 | 
| +    InspectorTest.fail = function(message)
 | 
| +    {
 | 
| +        InspectorTest.log("FAIL: " + message);
 | 
| +        InspectorTest.completeTest();
 | 
| +    }
 | 
| +
 | 
| +    InspectorTest.sendCommand("Profiler.enable", {});
 | 
| +    InspectorTest.sendCommand("Runtime.evaluate", { expression: "collectProfiles()"}, didCollectProfiles);
 | 
| +
 | 
| +    InspectorTest.eventHandler["Profiler.addProfileHeader"] = function(messageObject)
 | 
| +    {
 | 
| +        InspectorTest.log("FAIL: unexpected header = " + JSON.stringify(messageObject, null, 4));
 | 
| +    }
 | 
| +
 | 
| +    function didCollectProfiles(messageObject)
 | 
| +    {
 | 
| +        InspectorTest.sendCommand("Profiler.getProfileHeaders", {}, didReceiveProfileHeaders);
 | 
| +    }
 | 
| +
 | 
| +    function didReceiveProfileHeaders(messageObject)
 | 
| +    {
 | 
| +        var headers = messageObject["result"]["headers"];
 | 
| +        if (!headers || 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 === "inner") {
 | 
| +                InspectorTest.sendCommand("Profiler.getCPUProfile", { uid: headers[i].uid }, didGetProfile);
 | 
| +                return;
 | 
| +            }
 | 
| +        }
 | 
| +        InspectorTest.fail("Cannot find 'inner' profile header");
 | 
| +    }
 | 
| +
 | 
| +    function didGetProfile(messageObject)
 | 
| +    {
 | 
| +        InspectorTest.log("SUCCESS: retrieved 'inner' profile");
 | 
| +        var root = messageObject.result.profile.head;
 | 
| +        if (!findFunctionInProfile(root, "collectProfiles"))
 | 
| +            return InspectorTest.fail("collectProfiles function not found in the profile: " + JSON.stringify(messageObject, null, 4));
 | 
| +        InspectorTest.log("SUCCESS: found 'collectProfiles' function in the profile");
 | 
| +        InspectorTest.sendCommand("Profiler.clearProfiles", {});
 | 
| +        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>
 | 
| 
 |