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

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

Issue 2942573003: [DevTools] New harness for inspector-protocol layout tests (Closed)
Patch Set: Protocol -> dp 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
(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 (function initialize_tracingHarness(testRunner, session) {
6
7 class TracingHelper {
8 startTracing(callback) {
9 this.startTracingWithArguments({ "categories": "-*,disabled-by-default-dev tools.timeline,devtools.timeline", "type": "", "options": "" }, callback);
10 }
11
12 startTracingAndSaveAsStream(callback) {
13 var args = {
14 "categories": "-*,disabled-by-default-devtools.timeline,devtools.timelin e",
15 "type": "",
16 "options": "",
17 "transferMode": "ReturnAsStream"
18 };
19 this.startTracingWithArguments(args, callback);
20 }
21
22 startTracingWithArguments(args, callback) {
23 session.protocol.Tracing.start(args).then(onStart);
24 function onStart(response) {
25 testRunner.log("Recording started");
26 callback();
27 }
28 }
29
30 stopTracing(callback) {
31 this.devtoolsEvents = [];
32 var dataCollected = reply => {
33 var allEvents = reply.params.value;
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);
64 callback(event.params.stream);
65 }
66 }
67
68 retrieveStream(streamHandle, offset, chunkSize, callback) {
69 var result = "";
70 var had_eof = false;
71
72 var readArguments = { handle: streamHandle };
73 if (typeof chunkSize === "number")
74 readArguments.size = chunkSize;
75 var firstReadArguments = JSON.parse(JSON.stringify(readArguments));
76 if (typeof offset === "number")
77 firstReadArguments.offset = 0;
78 session.protocol.IO.read(firstReadArguments).then(message => onChunkRead(m essage.result));
79 // Assure multiple in-lfight reads are fine (also, save on latencies).
80 session.protocol.IO.read(readArguments).then(message => onChunkRead(messag e.result));
81
82 function onChunkRead(response) {
83 if (had_eof)
84 return;
85 result += response.data;
86 if (response.eof) {
87 // Ignore stray callbacks from proactive read requests.
88 had_eof = true;
89 callback(result);
90 return;
91 }
92 session.protocol.IO.read(readArguments).then(message => onChunkRead(mess age.result));
93 }
94 }
95
96 findEvents(name, ph, condition) {
97 return this.devtoolsEvents.filter(e => e.name === name && e.ph === ph && ( !condition || condition(e)));
98 }
99
100 findEvent(name, ph, condition) {
101 var events = this.findEvents(name, ph, condition);
102 if (events.length)
103 return events[0];
104 throw new Error("Couldn't find event " + name + " / " + ph + "\n\n in " + JSON.stringify(this.devtoolsEvents, null, 2));
105 }
106
107 invokeAsyncWithTracing(functionName, callback) {
108 this.startTracing(async () => {
109 var data = await session.evaluateAsync(functionName + "()");
110 this.stopTracing(devtoolsEvents => callback(devtoolsEvents, data));
111 });
112 }
113 }
114
115 return new TracingHelper();
116 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698