OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 var evalCallbackCallId = 3; | |
6 | |
7 initialize_tracingHarness = function() | |
8 { | |
9 | |
10 InspectorTest.startTracing = function(callback) | |
11 { | |
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", | |
19 "type": "", | |
20 "options": "", | |
21 "transferMode": "ReturnAsStream" | |
22 }; | |
23 InspectorTest.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 } | |
52 | |
53 function tracingComplete(event) | |
54 { | |
55 InspectorTest.log("Tracing complete"); | |
56 InspectorTest.eventHandler["Tracing.tracingComplete"] = null; | |
57 InspectorTest.eventHandler["Tracing.dataCollected"] = null; | |
58 callback(InspectorTest.devtoolsEvents); | |
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 } | |
73 | |
74 function tracingComplete(event) | |
75 { | |
76 InspectorTest.log("Tracing complete"); | |
77 InspectorTest.eventHandler["Tracing.tracingComplete"] = null; | |
78 InspectorTest.eventHandler["Tracing.dataCollected"] = null; | |
79 callback(event.params.stream); | |
80 } | |
81 } | |
82 | |
83 InspectorTest.retrieveStream = function(streamHandle, offset, chunkSize, callbac
k) | |
84 { | |
85 var result = ""; | |
86 var had_eof = false; | |
87 | |
88 var readArguments = { handle: streamHandle }; | |
89 if (typeof chunkSize === "number") | |
90 readArguments.size = chunkSize; | |
91 var firstReadArguments = JSON.parse(JSON.stringify(readArguments)); | |
92 if (typeof offset === "number") | |
93 firstReadArguments.offset = 0; | |
94 InspectorTest.sendCommandOrDie("IO.read", firstReadArguments, onChunkRead); | |
95 // Assure multiple in-lfight reads are fine (also, save on latencies). | |
96 InspectorTest.sendCommandOrDie("IO.read", readArguments, onChunkRead); | |
97 | |
98 function onChunkRead(response) | |
99 { | |
100 if (had_eof) | |
101 return; | |
102 result += response.data; | |
103 if (response.eof) { | |
104 // Ignore stray callbacks from proactive read requests. | |
105 had_eof = true; | |
106 callback(result); | |
107 return; | |
108 } | |
109 InspectorTest.sendCommandOrDie("IO.read", readArguments, onChunkRead); | |
110 } | |
111 } | |
112 | |
113 InspectorTest.findEvents = function(name, ph, condition) | |
114 { | |
115 return InspectorTest.devtoolsEvents.filter(e => e.name === name && e.ph ===
ph && (!condition || condition(e))); | |
116 } | |
117 | |
118 InspectorTest.findEvent = function(name, ph, condition) | |
119 { | |
120 var events = InspectorTest.findEvents(name, ph, condition); | |
121 if (events.length) | |
122 return events[0]; | |
123 throw new Error("Couldn't find event " + name + " / " + ph + "\n\n in " + JS
ON.stringify(InspectorTest.devtoolsEvents, null, 2)); | |
124 } | |
125 | |
126 InspectorTest.invokeAsyncWithTracing = function(functionName, callback) | |
127 { | |
128 InspectorTest.startTracing(onStart); | |
129 | |
130 function onStart() | |
131 { | |
132 InspectorTest.evaluateInPageAsync(functionName + "()").then((data) => In
spectorTest.stopTracing((devtoolsEvents) => callback(devtoolsEvents, data))); | |
133 } | |
134 } | |
135 | |
136 } | |
OLD | NEW |