Index: third_party/WebKit/LayoutTests/inspector-protocol/cpu-profiler/console-profile.js |
diff --git a/third_party/WebKit/LayoutTests/inspector-protocol/cpu-profiler/console-profile.js b/third_party/WebKit/LayoutTests/inspector-protocol/cpu-profiler/console-profile.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..80bca50d33c1efb2a692ce24ae007a4f0ec8e252 |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/inspector-protocol/cpu-profiler/console-profile.js |
@@ -0,0 +1,43 @@ |
+(async function(testRunner) { |
+ let {page, session, dp} = await testRunner.startBlank('Tests that console.profile/profileEnd will record CPU profile when inspector front-end is connected.'); |
+ |
+ function fail(message) { |
+ testRunner.log('FAIL: ' + message); |
+ testRunner.completeTest(); |
+ } |
+ |
+ function findFunctionInProfile(nodes, functionName) { |
+ return nodes.some(n => n.callFrame.functionName === functionName); |
+ } |
+ |
+ var headers = []; |
+ dp.Profiler.onConsoleProfileFinished(messageObject => { |
+ headers.push({profile: messageObject['params']['profile'], title: messageObject['params']['title']}); |
+ }); |
+ |
+ dp.Profiler.enable(); |
+ await session.evaluate(` |
+ (function collectProfiles() { |
+ console.profile('outer'); |
+ console.profile(42); |
+ console.profileEnd('outer'); |
+ console.profileEnd(42); |
+ })(); |
+ `); |
+ |
+ if (headers.length !== 2) |
+ return fail('Cannot retrive headers: ' + JSON.stringify(messageObject, null, 4)); |
+ |
+ for (var i = 0; i < headers.length; i++) { |
+ if (headers[i].title === '42') { |
+ testRunner.log('SUCCESS: retrieved "42" profile'); |
+ if (!findFunctionInProfile(headers[i].profile.nodes, 'collectProfiles')) |
+ return fail('collectProfiles function not found in the profile: ' + JSON.stringify(headers[i].profile, null, 4)); |
+ testRunner.log('SUCCESS: found "collectProfiles" function in the profile'); |
+ testRunner.completeTest(); |
+ return; |
+ } |
+ } |
+ |
+ fail('Cannot find "42" profile header'); |
+}) |