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

Side by Side Diff: third_party/WebKit/LayoutTests/inspector-protocol/resources/tracing-test.js

Issue 2953663003: [DevTools] Migrate inspector-protocol/{timeline,worker} tests to new harness (Closed)
Patch Set: Created 3 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium 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 var evalCallbackCallId = 3; 5 (function initialize_tracingHarness(testRunner, session) {
6 6
7 initialize_tracingHarness = function() 7 class TracingHelper {
8 { 8 startTracing(callback) {
caseq 2017/06/22 19:32:41 nit: if you're rewriting this beyond any recogniti
dgozman 2017/06/22 21:48:55 Done.
9 this.startTracingWithArguments({ "categories": "-*,disabled-by-default-dev tools.timeline,devtools.timeline", "type": "", "options": "" }, callback);
10 }
9 11
10 InspectorTest.startTracing = function(callback) 12 startTracingAndSaveAsStream(callback) {
11 { 13 var args = {
12 InspectorTest.startTracingWithArguments({ "categories": "-*,disabled-by-defa ult-devtools.timeline,devtools.timeline", "type": "", "options": "" }, callback) ;
13 }
14
15 InspectorTest.startTracingAndSaveAsStream = function(callback)
16 {
17 var args = {
18 "categories": "-*,disabled-by-default-devtools.timeline,devtools.timelin e", 14 "categories": "-*,disabled-by-default-devtools.timeline,devtools.timelin e",
19 "type": "", 15 "type": "",
20 "options": "", 16 "options": "",
21 "transferMode": "ReturnAsStream" 17 "transferMode": "ReturnAsStream"
22 }; 18 };
23 InspectorTest.startTracingWithArguments(args, callback); 19 this.startTracingWithArguments(args, callback);
24 }
25
26 InspectorTest.startTracingWithArguments = function(args, callback)
27 {
28 InspectorTest.sendCommand("Tracing.start", args, onStart);
29
30 function onStart(response)
31 {
32 InspectorTest.log("Recording started");
33 callback();
34 }
35 }
36
37 InspectorTest.stopTracing = function(callback)
38 {
39 InspectorTest.eventHandler["Tracing.tracingComplete"] = tracingComplete;
40 InspectorTest.eventHandler["Tracing.dataCollected"] = dataCollected;
41 InspectorTest.sendCommand("Tracing.end", { });
42
43 InspectorTest.devtoolsEvents = [];
44 function dataCollected(reply)
45 {
46 var allEvents = reply.params.value;
47 InspectorTest.devtoolsEvents = InspectorTest.devtoolsEvents.concat(allEv ents.filter(function(e)
48 {
49 return /devtools.timeline/.test(e.cat);
50 }));
51 } 20 }
52 21
53 function tracingComplete(event) 22 startTracingWithArguments(args, callback) {
54 { 23 session.protocol.Tracing.start(args).then(onStart);
55 InspectorTest.log("Tracing complete"); 24 function onStart(response) {
56 InspectorTest.eventHandler["Tracing.tracingComplete"] = null; 25 testRunner.log("Recording started");
57 InspectorTest.eventHandler["Tracing.dataCollected"] = null; 26 callback();
58 callback(InspectorTest.devtoolsEvents); 27 }
59 }
60 }
61
62 InspectorTest.stopTracingAndReturnStream = function(callback)
63 {
64 InspectorTest.eventHandler["Tracing.tracingComplete"] = tracingComplete;
65 InspectorTest.eventHandler["Tracing.dataCollected"] = dataCollected;
66 InspectorTest.sendCommand("Tracing.end");
67
68 function dataCollected(reply)
69 {
70 InspectorTest.log("FAIL: dataCollected event should not be fired when re turning trace as stream.");
71
72 } 28 }
73 29
74 function tracingComplete(event) 30 stopTracing(callback) {
75 { 31 this.devtoolsEvents = [];
76 InspectorTest.log("Tracing complete"); 32 var dataCollected = reply => {
77 InspectorTest.eventHandler["Tracing.tracingComplete"] = null; 33 var allEvents = reply.params.value;
78 InspectorTest.eventHandler["Tracing.dataCollected"] = null; 34 this.devtoolsEvents = this.devtoolsEvents.concat(allEvents.filter(functi on(e) {
35 return /devtools.timeline/.test(e.cat);
36 }));
37 };
38
39 var tracingComplete = event => {
40 testRunner.log("Tracing complete");
41 session.protocol.Tracing.offTracingComplete(tracingComplete);
42 session.protocol.Tracing.offDataCollected(dataCollected);
43 callback(this.devtoolsEvents);
44 };
45
46 session.protocol.Tracing.onTracingComplete(tracingComplete);
47 session.protocol.Tracing.onDataCollected(dataCollected);
48 session.protocol.Tracing.end();
49 }
50
51 stopTracingAndReturnStream(callback) {
52 session.protocol.Tracing.onTracingComplete(tracingComplete);
53 session.protocol.Tracing.onDataCollected(dataCollected);
54 session.protocol.Tracing.end();
55
56 function dataCollected(reply) {
57 testRunner.log("FAIL: dataCollected event should not be fired when retur ning trace as stream.");
58 }
59
60 function tracingComplete(event) {
61 testRunner.log("Tracing complete");
62 session.protocol.Tracing.offTracingComplete(tracingComplete);
63 session.protocol.Tracing.offDataCollected(dataCollected);
79 callback(event.params.stream); 64 callback(event.params.stream);
65 }
80 } 66 }
81 }
82 67
83 InspectorTest.retrieveStream = function(streamHandle, offset, chunkSize, callbac k) 68 retrieveStream(streamHandle, offset, chunkSize, callback) {
84 { 69 var result = "";
85 var result = ""; 70 var had_eof = false;
86 var had_eof = false;
87 71
88 var readArguments = { handle: streamHandle }; 72 var readArguments = { handle: streamHandle };
89 if (typeof chunkSize === "number") 73 if (typeof chunkSize === "number")
90 readArguments.size = chunkSize; 74 readArguments.size = chunkSize;
91 var firstReadArguments = JSON.parse(JSON.stringify(readArguments)); 75 var firstReadArguments = JSON.parse(JSON.stringify(readArguments));
92 if (typeof offset === "number") 76 if (typeof offset === "number")
93 firstReadArguments.offset = 0; 77 firstReadArguments.offset = 0;
94 InspectorTest.sendCommandOrDie("IO.read", firstReadArguments, onChunkRead); 78 session.protocol.IO.read(firstReadArguments).then(message => onChunkRead(m essage.result));
95 // Assure multiple in-lfight reads are fine (also, save on latencies). 79 // Assure multiple in-lfight reads are fine (also, save on latencies).
caseq 2017/06/22 19:32:41 mind fixing my typo while you're here? ;-)
dgozman 2017/06/22 21:48:55 Done.
96 InspectorTest.sendCommandOrDie("IO.read", readArguments, onChunkRead); 80 session.protocol.IO.read(readArguments).then(message => onChunkRead(messag e.result));
97 81
98 function onChunkRead(response) 82 function onChunkRead(response) {
99 {
100 if (had_eof) 83 if (had_eof)
101 return; 84 return;
102 result += response.data; 85 result += response.data;
103 if (response.eof) { 86 if (response.eof) {
104 // Ignore stray callbacks from proactive read requests. 87 // Ignore stray callbacks from proactive read requests.
105 had_eof = true; 88 had_eof = true;
106 callback(result); 89 callback(result);
107 return; 90 return;
108 } 91 }
109 InspectorTest.sendCommandOrDie("IO.read", readArguments, onChunkRead); 92 session.protocol.IO.read(readArguments).then(message => onChunkRead(mess age.result));
93 }
110 } 94 }
111 }
112 95
113 InspectorTest.findEvents = function(name, ph, condition) 96 findEvents(name, ph, condition) {
114 { 97 return this.devtoolsEvents.filter(e => e.name === name && e.ph === ph && ( !condition || condition(e)));
115 return InspectorTest.devtoolsEvents.filter(e => e.name === name && e.ph === ph && (!condition || condition(e))); 98 }
116 }
117 99
118 InspectorTest.findEvent = function(name, ph, condition) 100 findEvent(name, ph, condition) {
119 { 101 var events = this.findEvents(name, ph, condition);
120 var events = InspectorTest.findEvents(name, ph, condition); 102 if (events.length)
121 if (events.length)
122 return events[0]; 103 return events[0];
123 throw new Error("Couldn't find event " + name + " / " + ph + "\n\n in " + JS ON.stringify(InspectorTest.devtoolsEvents, null, 2)); 104 throw new Error("Couldn't find event " + name + " / " + ph + "\n\n in " + JSON.stringify(this.devtoolsEvents, null, 2));
124 } 105 }
125 106
126 InspectorTest.invokeAsyncWithTracing = function(functionName, callback) 107 invokeAsyncWithTracing(functionName, callback) {
127 { 108 this.startTracing(async () => {
128 InspectorTest.startTracing(onStart); 109 var data = await session.evaluateAsync(functionName + "()");
110 this.stopTracing(devtoolsEvents => callback(devtoolsEvents, data));
111 });
112 }
113 }
129 114
130 function onStart() 115 return new TracingHelper();
131 { 116 })
132 InspectorTest.evaluateInPageAsync(functionName + "()").then((data) => In spectorTest.stopTracing((devtoolsEvents) => callback(devtoolsEvents, data)));
133 }
134 }
135
136 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698