OLD | NEW |
---|---|
(Empty) | |
1 (async function(testRunner) { | |
2 let {page, session, dp} = await testRunner.startBlank('Tests that console.prof ile/profileEnd will record CPU profile when inspector front-end is connected.'); | |
3 | |
4 function fail(message) { | |
5 testRunner.log('FAIL: ' + message); | |
6 testRunner.completeTest(); | |
7 } | |
8 | |
9 function findFunctionInProfile(nodes, functionName) { | |
10 return nodes.some(n => n.callFrame.functionName === functionName); | |
11 } | |
12 | |
13 var headers = []; | |
14 dp.Profiler.onConsoleProfileFinished(messageObject => { | |
15 headers.push({profile: messageObject['params']['profile'], title: messageObj ect['params']['title']}); | |
16 }); | |
17 | |
18 dp.Profiler.enable(); | |
19 await session.evaluate(` | |
20 (function collectProfiles() { | |
21 console.profile('outer'); | |
22 console.profile(42); | |
23 console.profileEnd('outer'); | |
24 console.profileEnd(42); | |
25 })(); | |
26 `); | |
27 | |
28 if (headers.length !== 2) | |
29 return fail('Cannot retrive headers: ' + JSON.stringify(messageObject, null, 4)); | |
30 | |
31 for (var i = 0; i < headers.length; i++) { | |
alph
2017/06/22 01:30:54
for-of
dgozman
2017/06/22 17:14:32
Done.
| |
32 if (headers[i].title === '42') { | |
33 testRunner.log('SUCCESS: retrieved "42" profile'); | |
34 if (!findFunctionInProfile(headers[i].profile.nodes, 'collectProfiles')) | |
35 return fail('collectProfiles function not found in the profile: ' + JSON .stringify(headers[i].profile, null, 4)); | |
36 testRunner.log('SUCCESS: found "collectProfiles" function in the profile') ; | |
37 testRunner.completeTest(); | |
38 return; | |
39 } | |
40 } | |
41 | |
42 fail('Cannot find "42" profile header'); | |
43 }) | |
OLD | NEW |