OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 InspectorTest.log("Test that profiler is able to record a profile. Also it tests
that profiler returns an error when it unable to find the profile."); | 5 let {session, contextGroup, Protocol} = InspectorTest.start("Test that profiler
is able to record a profile. Also it tests that profiler returns an error when i
t unable to find the profile."); |
6 | 6 |
7 Protocol.Profiler.enable(); | 7 Protocol.Profiler.enable(); |
8 Protocol.Profiler.start().then(didStartFrontendProfile); | 8 Protocol.Profiler.start().then(didStartFrontendProfile); |
9 function didStartFrontendProfile(messageObject) | 9 function didStartFrontendProfile(messageObject) |
10 { | 10 { |
11 if (!InspectorTest.expectedSuccess("startFrontendProfile", messageObject)) | 11 if (!expectedSuccess("startFrontendProfile", messageObject)) |
12 return; | 12 return; |
13 Protocol.Runtime.evaluate({expression: "console.profile('Profile 1');"}).then(
didStartConsoleProfile); | 13 Protocol.Runtime.evaluate({expression: "console.profile('Profile 1');"}).then(
didStartConsoleProfile); |
14 } | 14 } |
15 | 15 |
16 function didStartConsoleProfile(messageObject) | 16 function didStartConsoleProfile(messageObject) |
17 { | 17 { |
18 if (!InspectorTest.expectedSuccess("startConsoleProfile", messageObject)) | 18 if (!expectedSuccess("startConsoleProfile", messageObject)) |
19 return; | 19 return; |
20 Protocol.Runtime.evaluate({expression: "console.profileEnd('Profile 1');"}).th
en(didStopConsoleProfile); | 20 Protocol.Runtime.evaluate({expression: "console.profileEnd('Profile 1');"}).th
en(didStopConsoleProfile); |
21 } | 21 } |
22 | 22 |
23 function didStopConsoleProfile(messageObject) | 23 function didStopConsoleProfile(messageObject) |
24 { | 24 { |
25 if (!InspectorTest.expectedSuccess("stopConsoleProfile", messageObject)) | 25 if (!expectedSuccess("stopConsoleProfile", messageObject)) |
26 return; | 26 return; |
27 Protocol.Profiler.stop().then(didStopFrontendProfile); | 27 Protocol.Profiler.stop().then(didStopFrontendProfile); |
28 } | 28 } |
29 | 29 |
30 function didStopFrontendProfile(messageObject) | 30 function didStopFrontendProfile(messageObject) |
31 { | 31 { |
32 if (!InspectorTest.expectedSuccess("stoppedFrontendProfile", messageObject)) | 32 if (!expectedSuccess("stoppedFrontendProfile", messageObject)) |
33 return; | 33 return; |
34 Protocol.Profiler.start().then(didStartFrontendProfile2); | 34 Protocol.Profiler.start().then(didStartFrontendProfile2); |
35 } | 35 } |
36 | 36 |
37 function didStartFrontendProfile2(messageObject) | 37 function didStartFrontendProfile2(messageObject) |
38 { | 38 { |
39 if (!InspectorTest.expectedSuccess("startFrontendProfileSecondTime", messageOb
ject)) | 39 if (!expectedSuccess("startFrontendProfileSecondTime", messageObject)) |
40 return; | 40 return; |
41 Protocol.Profiler.stop().then(didStopFrontendProfile2); | 41 Protocol.Profiler.stop().then(didStopFrontendProfile2); |
42 } | 42 } |
43 | 43 |
44 function didStopFrontendProfile2(messageObject) | 44 function didStopFrontendProfile2(messageObject) |
45 { | 45 { |
46 InspectorTest.expectedSuccess("stopFrontendProfileSecondTime", messageObject) | 46 expectedSuccess("stopFrontendProfileSecondTime", messageObject) |
47 InspectorTest.completeTest(); | 47 InspectorTest.completeTest(); |
48 } | 48 } |
| 49 |
| 50 function checkExpectation(fail, name, messageObject) |
| 51 { |
| 52 if (fail === !!messageObject.error) { |
| 53 InspectorTest.log("PASS: " + name); |
| 54 return true; |
| 55 } |
| 56 |
| 57 InspectorTest.log("FAIL: " + name + ": " + JSON.stringify(messageObject)); |
| 58 InspectorTest.completeTest(); |
| 59 return false; |
| 60 } |
| 61 var expectedSuccess = checkExpectation.bind(null, false); |
| 62 var expectedError = checkExpectation.bind(null, true); |
OLD | NEW |