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 print("Test that profiling can only be started when Profiler was enabled and tha
t Profiler.disable command will stop recording all profiles."); | 5 print("Test that profiling can only be started when Profiler was enabled and tha
t Profiler.disable command will stop recording all profiles."); |
6 | 6 |
7 InspectorTest.sendCommand("Profiler.start", {}, didFailToStartWhenDisabled); | 7 Protocol.Profiler.start().then(didFailToStartWhenDisabled); |
8 disallowConsoleProfiles(); | 8 disallowConsoleProfiles(); |
9 | 9 |
10 function disallowConsoleProfiles() | 10 function disallowConsoleProfiles() |
11 { | 11 { |
12 InspectorTest.eventHandler["Profiler.consoleProfileStarted"] = function(messag
eObject) | 12 Protocol.Profiler.onConsoleProfileStarted(function(messageObject) |
13 { | 13 { |
14 InspectorTest.log("FAIL: console profile started " + JSON.stringify(messageO
bject, null, 4)); | 14 InspectorTest.log("FAIL: console profile started " + JSON.stringify(messageO
bject, null, 4)); |
15 } | 15 }); |
16 InspectorTest.eventHandler["Profiler.consoleProfileFinished"] = function(messa
geObject) | 16 Protocol.Profiler.onConsoleProfileFinished(function(messageObject) |
17 { | 17 { |
18 InspectorTest.log("FAIL: unexpected profile received " + JSON.stringify(mess
ageObject, null, 4)); | 18 InspectorTest.log("FAIL: unexpected profile received " + JSON.stringify(mess
ageObject, null, 4)); |
19 } | 19 }); |
20 } | 20 } |
21 function allowConsoleProfiles() | 21 function allowConsoleProfiles() |
22 { | 22 { |
23 InspectorTest.eventHandler["Profiler.consoleProfileStarted"] = function(messag
eObject) | 23 Protocol.Profiler.onConsoleProfileStarted(function(messageObject) |
24 { | 24 { |
25 InspectorTest.log("PASS: console initiated profile started"); | 25 InspectorTest.log("PASS: console initiated profile started"); |
26 } | 26 }); |
27 InspectorTest.eventHandler["Profiler.consoleProfileFinished"] = function(messa
geObject) | 27 Protocol.Profiler.onConsoleProfileFinished(function(messageObject) |
28 { | 28 { |
29 InspectorTest.log("PASS: console initiated profile received"); | 29 InspectorTest.log("PASS: console initiated profile received"); |
30 } | 30 }); |
31 } | 31 } |
32 function didFailToStartWhenDisabled(messageObject) | 32 function didFailToStartWhenDisabled(messageObject) |
33 { | 33 { |
34 if (!InspectorTest.expectedError("didFailToStartWhenDisabled", messageObject)) | 34 if (!InspectorTest.expectedError("didFailToStartWhenDisabled", messageObject)) |
35 return; | 35 return; |
36 allowConsoleProfiles(); | 36 allowConsoleProfiles(); |
37 InspectorTest.sendCommand("Profiler.enable", {}); | 37 Protocol.Profiler.enable(); |
38 InspectorTest.sendCommand("Profiler.start", {}, didStartFrontendProfile); | 38 Protocol.Profiler.start().then(didStartFrontendProfile); |
39 } | 39 } |
40 function didStartFrontendProfile(messageObject) | 40 function didStartFrontendProfile(messageObject) |
41 { | 41 { |
42 if (!InspectorTest.expectedSuccess("didStartFrontendProfile", messageObject)) | 42 if (!InspectorTest.expectedSuccess("didStartFrontendProfile", messageObject)) |
43 return; | 43 return; |
44 InspectorTest.sendCommand("Runtime.evaluate", {expression: "console.profile('p
1');"}, didStartConsoleProfile); | 44 Protocol.Runtime.evaluate({expression: "console.profile('p1');"}).then(didStar
tConsoleProfile); |
45 } | 45 } |
46 | 46 |
47 function didStartConsoleProfile(messageObject) | 47 function didStartConsoleProfile(messageObject) |
48 { | 48 { |
49 if (!InspectorTest.expectedSuccess("didStartConsoleProfile", messageObject)) | 49 if (!InspectorTest.expectedSuccess("didStartConsoleProfile", messageObject)) |
50 return; | 50 return; |
51 InspectorTest.sendCommand("Profiler.disable", {}, didDisableProfiler); | 51 Protocol.Profiler.disable().then(didDisableProfiler); |
52 } | 52 } |
53 | 53 |
54 function didDisableProfiler(messageObject) | 54 function didDisableProfiler(messageObject) |
55 { | 55 { |
56 if (!InspectorTest.expectedSuccess("didDisableProfiler", messageObject)) | 56 if (!InspectorTest.expectedSuccess("didDisableProfiler", messageObject)) |
57 return; | 57 return; |
58 InspectorTest.sendCommand("Profiler.enable", {}); | 58 Protocol.Profiler.enable(); |
59 InspectorTest.sendCommand("Profiler.stop", {}, didStopFrontendProfile); | 59 Protocol.Profiler.stop().then(didStopFrontendProfile); |
60 } | 60 } |
61 | 61 |
62 function didStopFrontendProfile(messageObject) | 62 function didStopFrontendProfile(messageObject) |
63 { | 63 { |
64 if (!InspectorTest.expectedError("no front-end initiated profiles found", mess
ageObject)) | 64 if (!InspectorTest.expectedError("no front-end initiated profiles found", mess
ageObject)) |
65 return; | 65 return; |
66 disallowConsoleProfiles(); | 66 disallowConsoleProfiles(); |
67 InspectorTest.sendCommand("Runtime.evaluate", {expression: "console.profileEnd
();"}, didStopConsoleProfile); | 67 Protocol.Runtime.evaluate({expression: "console.profileEnd();"}).then(didStopC
onsoleProfile); |
68 } | 68 } |
69 | 69 |
70 function didStopConsoleProfile(messageObject) | 70 function didStopConsoleProfile(messageObject) |
71 { | 71 { |
72 if (!InspectorTest.expectedSuccess("didStopConsoleProfile", messageObject)) | 72 if (!InspectorTest.expectedSuccess("didStopConsoleProfile", messageObject)) |
73 return; | 73 return; |
74 InspectorTest.completeTest(); | 74 InspectorTest.completeTest(); |
75 } | 75 } |
OLD | NEW |