Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(530)

Side by Side Diff: test/inspector/cpu-profiler/enable-disable.js

Issue 2891213002: [inspector] Refactor protocol-test.js (Closed)
Patch Set: comments addressed Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 profiling can only be started when Profiler was ena bled and that Profiler.disable command will stop recording all profiles."); 5 let {session, contextGroup, Protocol} = InspectorTest.start("Test that profiling can only be started when Profiler was enabled and that Profiler.disable command will stop recording all profiles.");
6 6
7 Protocol.Profiler.start().then(didFailToStartWhenDisabled); 7 Protocol.Profiler.start().then(didFailToStartWhenDisabled);
8 disallowConsoleProfiles(); 8 disallowConsoleProfiles();
9 9
10 function disallowConsoleProfiles() 10 function disallowConsoleProfiles()
11 { 11 {
12 Protocol.Profiler.onConsoleProfileStarted(function(messageObject) 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 Protocol.Profiler.onConsoleProfileFinished(function(messageObject) 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 Protocol.Profiler.onConsoleProfileStarted(function(messageObject) 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 Protocol.Profiler.onConsoleProfileFinished(function(messageObject) 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 (!expectedError("didFailToStartWhenDisabled", messageObject))
35 return; 35 return;
36 allowConsoleProfiles(); 36 allowConsoleProfiles();
37 Protocol.Profiler.enable(); 37 Protocol.Profiler.enable();
38 Protocol.Profiler.start().then(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 (!expectedSuccess("didStartFrontendProfile", messageObject))
43 return; 43 return;
44 Protocol.Runtime.evaluate({expression: "console.profile('p1');"}).then(didStar tConsoleProfile); 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 (!expectedSuccess("didStartConsoleProfile", messageObject))
50 return; 50 return;
51 Protocol.Profiler.disable().then(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 (!expectedSuccess("didDisableProfiler", messageObject))
57 return; 57 return;
58 Protocol.Profiler.enable(); 58 Protocol.Profiler.enable();
59 Protocol.Profiler.stop().then(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 (!expectedError("no front-end initiated profiles found", messageObject))
65 return; 65 return;
66 disallowConsoleProfiles(); 66 disallowConsoleProfiles();
67 Protocol.Runtime.evaluate({expression: "console.profileEnd();"}).then(didStopC onsoleProfile); 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 (!expectedSuccess("didStopConsoleProfile", messageObject))
73 return; 73 return;
74 InspectorTest.completeTest(); 74 InspectorTest.completeTest();
75 } 75 }
76
77 function checkExpectation(fail, name, messageObject)
78 {
79 if (fail === !!messageObject.error) {
80 InspectorTest.log("PASS: " + name);
81 return true;
82 }
83
84 InspectorTest.log("FAIL: " + name + ": " + JSON.stringify(messageObject));
85 InspectorTest.completeTest();
86 return false;
87 }
88 var expectedSuccess = checkExpectation.bind(null, false);
89 var expectedError = checkExpectation.bind(null, true);
OLDNEW
« no previous file with comments | « test/inspector/cpu-profiler/coverage.js ('k') | test/inspector/cpu-profiler/enable-disable-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698