Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / inspector-protocol / cpu-profiler / console-profile.html
blobaf156936f8bc2b23f03d56011ed74d72b08669b8
1 <html>
2 <head>
3 <script type="text/javascript" src="../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
4 <script>
5 function collectProfiles()
7 console.profile("outer");
8 console.profile("inner");
9 console.profileEnd("outer");
10 console.profileEnd("inner");
13 function test()
15 InspectorTest.fail = function(message)
17 InspectorTest.log("FAIL: " + message);
18 InspectorTest.completeTest();
21 InspectorTest.sendCommand("Profiler.enable", {});
22 InspectorTest.sendCommand("Runtime.evaluate", { expression: "collectProfiles()"}, didCollectProfiles);
24 var headers = [];
25 InspectorTest.eventHandler["Profiler.consoleProfileFinished"] = function(messageObject)
27 headers.push({
28 profile: messageObject["params"]["profile"],
29 title: messageObject["params"]["title"]
30 });
33 function didCollectProfiles(messageObject)
35 if (headers.length !== 2)
36 return InspectorTest.fail("Cannot retrive headers: " + JSON.stringify(messageObject, null, 4));
37 for (var i = 0; i < headers.length; i++) {
38 if (headers[i].title === "inner") {
39 checkInnerProfile(headers[i].profile);
40 return;
43 InspectorTest.fail("Cannot find 'inner' profile header");
46 function checkInnerProfile(profile)
48 InspectorTest.log("SUCCESS: retrieved 'inner' profile");
49 var root = profile.head;
50 if (!findFunctionInProfile(root, "collectProfiles"))
51 return InspectorTest.fail("collectProfiles function not found in the profile: " + JSON.stringify(profile, null, 4));
52 InspectorTest.log("SUCCESS: found 'collectProfiles' function in the profile");
53 InspectorTest.completeTest();
56 function findFunctionInProfile(node, functionName)
58 if (node.functionName === functionName)
59 return true;
60 var children = node.children;
61 for (var i = 0; i < children.length; ++i)
62 if (findFunctionInProfile(children[i], functionName))
63 return true;
64 return false;
67 </script>
68 </head>
69 <body onload="runTest()">
70 <p>
71 Tests that console.profile/profileEnd will record CPU profile when inspector front-end is connected.<br>
72 </p>
73 </body>
74 </html>