| OLD | NEW |
| 1 <html> | 1 <html> |
| 2 <head> | 2 <head> |
| 3 <script type="text/javascript" src="../../http/tests/inspector-protocol/inspecto
r-protocol-test.js"></script> | 3 <script type="text/javascript" src="../../http/tests/inspector-protocol/inspecto
r-protocol-test.js"></script> |
| 4 <script> | 4 <script> |
| 5 function collectProfiles() | 5 function collectProfiles() |
| 6 { | 6 { |
| 7 console.profile("outer"); | 7 console.profile("outer"); |
| 8 console.profile("inner"); | 8 console.profile(42); |
| 9 console.profileEnd("outer"); | 9 console.profileEnd("outer"); |
| 10 console.profileEnd("inner"); | 10 console.profileEnd(42); |
| 11 } | 11 } |
| 12 | 12 |
| 13 function test() | 13 function test() |
| 14 { | 14 { |
| 15 InspectorTest.fail = function(message) | 15 InspectorTest.fail = function(message) |
| 16 { | 16 { |
| 17 InspectorTest.log("FAIL: " + message); | 17 InspectorTest.log("FAIL: " + message); |
| 18 InspectorTest.completeTest(); | 18 InspectorTest.completeTest(); |
| 19 } | 19 } |
| 20 | 20 |
| 21 InspectorTest.sendCommand("Profiler.enable", {}); | 21 InspectorTest.sendCommand("Profiler.enable", {}); |
| 22 InspectorTest.sendCommand("Runtime.evaluate", { expression: "collectProfiles
()"}, didCollectProfiles); | 22 InspectorTest.sendCommand("Runtime.evaluate", { expression: "collectProfiles
()"}, didCollectProfiles); |
| 23 | 23 |
| 24 var headers = []; | 24 var headers = []; |
| 25 InspectorTest.eventHandler["Profiler.consoleProfileFinished"] = function(mes
sageObject) | 25 InspectorTest.eventHandler["Profiler.consoleProfileFinished"] = function(mes
sageObject) |
| 26 { | 26 { |
| 27 headers.push({ | 27 headers.push({ |
| 28 profile: messageObject["params"]["profile"], | 28 profile: messageObject["params"]["profile"], |
| 29 title: messageObject["params"]["title"] | 29 title: messageObject["params"]["title"] |
| 30 }); | 30 }); |
| 31 } | 31 } |
| 32 | 32 |
| 33 function didCollectProfiles(messageObject) | 33 function didCollectProfiles(messageObject) |
| 34 { | 34 { |
| 35 if (headers.length !== 2) | 35 if (headers.length !== 2) |
| 36 return InspectorTest.fail("Cannot retrive headers: " + JSON.stringif
y(messageObject, null, 4)); | 36 return InspectorTest.fail("Cannot retrive headers: " + JSON.stringif
y(messageObject, null, 4)); |
| 37 for (var i = 0; i < headers.length; i++) { | 37 for (var i = 0; i < headers.length; i++) { |
| 38 if (headers[i].title === "inner") { | 38 if (headers[i].title === "42") { |
| 39 checkInnerProfile(headers[i].profile); | 39 checkInnerProfile(headers[i].profile); |
| 40 return; | 40 return; |
| 41 } | 41 } |
| 42 } | 42 } |
| 43 InspectorTest.fail("Cannot find 'inner' profile header"); | 43 InspectorTest.fail("Cannot find '42' profile header"); |
| 44 } | 44 } |
| 45 | 45 |
| 46 function checkInnerProfile(profile) | 46 function checkInnerProfile(profile) |
| 47 { | 47 { |
| 48 InspectorTest.log("SUCCESS: retrieved 'inner' profile"); | 48 InspectorTest.log("SUCCESS: retrieved '42' profile"); |
| 49 var root = profile.head; | 49 var root = profile.head; |
| 50 if (!findFunctionInProfile(root, "collectProfiles")) | 50 if (!findFunctionInProfile(root, "collectProfiles")) |
| 51 return InspectorTest.fail("collectProfiles function not found in the
profile: " + JSON.stringify(profile, null, 4)); | 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 prof
ile"); | 52 InspectorTest.log("SUCCESS: found 'collectProfiles' function in the prof
ile"); |
| 53 InspectorTest.completeTest(); | 53 InspectorTest.completeTest(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 function findFunctionInProfile(node, functionName) | 56 function findFunctionInProfile(node, functionName) |
| 57 { | 57 { |
| 58 if (node.functionName === functionName) | 58 if (node.functionName === functionName) |
| 59 return true; | 59 return true; |
| 60 var children = node.children; | 60 var children = node.children; |
| 61 for (var i = 0; i < children.length; ++i) | 61 for (var i = 0; i < children.length; ++i) |
| 62 if (findFunctionInProfile(children[i], functionName)) | 62 if (findFunctionInProfile(children[i], functionName)) |
| 63 return true; | 63 return true; |
| 64 return false; | 64 return false; |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 </script> | 67 </script> |
| 68 </head> | 68 </head> |
| 69 <body onload="runTest()"> | 69 <body onload="runTest()"> |
| 70 <p> | 70 <p> |
| 71 Tests that console.profile/profileEnd will record CPU profile when inspector fro
nt-end is connected.<br> | 71 Tests that console.profile/profileEnd will record CPU profile when inspector fro
nt-end is connected.<br> |
| 72 </p> | 72 </p> |
| 73 </body> | 73 </body> |
| 74 </html> | 74 </html> |
| OLD | NEW |