Index: third_party/WebKit/LayoutTests/inspector-protocol/resources/tracing-test.js |
diff --git a/third_party/WebKit/LayoutTests/inspector-protocol/resources/tracing-test.js b/third_party/WebKit/LayoutTests/inspector-protocol/resources/tracing-test.js |
index 0c545b56164c1f4c2583754af0934c562e8b66d8..8f24f8713fb931c8aa01c57c0a5e93fb98d62214 100644 |
--- a/third_party/WebKit/LayoutTests/inspector-protocol/resources/tracing-test.js |
+++ b/third_party/WebKit/LayoutTests/inspector-protocol/resources/tracing-test.js |
@@ -2,135 +2,117 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-var evalCallbackCallId = 3; |
+(class TracingHelper { |
+ constructor(testRunner, session) { |
+ this._testRunner = testRunner; |
+ this._session = session; |
+ } |
-initialize_tracingHarness = function() |
-{ |
+ startTracing() { |
+ return this.startTracingWithArguments({ "categories": "-*,disabled-by-default-devtools.timeline,devtools.timeline", "type": "", "options": "" }); |
+ } |
-InspectorTest.startTracing = function(callback) |
-{ |
- InspectorTest.startTracingWithArguments({ "categories": "-*,disabled-by-default-devtools.timeline,devtools.timeline", "type": "", "options": "" }, callback); |
-} |
- |
-InspectorTest.startTracingAndSaveAsStream = function(callback) |
-{ |
+ startTracingAndSaveAsStream() { |
var args = { |
- "categories": "-*,disabled-by-default-devtools.timeline,devtools.timeline", |
- "type": "", |
- "options": "", |
- "transferMode": "ReturnAsStream" |
+ "categories": "-*,disabled-by-default-devtools.timeline,devtools.timeline", |
+ "type": "", |
+ "options": "", |
+ "transferMode": "ReturnAsStream" |
}; |
- InspectorTest.startTracingWithArguments(args, callback); |
-} |
- |
-InspectorTest.startTracingWithArguments = function(args, callback) |
-{ |
- InspectorTest.sendCommand("Tracing.start", args, onStart); |
- |
- function onStart(response) |
- { |
- InspectorTest.log("Recording started"); |
- callback(); |
- } |
-} |
- |
-InspectorTest.stopTracing = function(callback) |
-{ |
- InspectorTest.eventHandler["Tracing.tracingComplete"] = tracingComplete; |
- InspectorTest.eventHandler["Tracing.dataCollected"] = dataCollected; |
- InspectorTest.sendCommand("Tracing.end", { }); |
- |
- InspectorTest.devtoolsEvents = []; |
- function dataCollected(reply) |
- { |
- var allEvents = reply.params.value; |
- InspectorTest.devtoolsEvents = InspectorTest.devtoolsEvents.concat(allEvents.filter(function(e) |
- { |
- return /devtools.timeline/.test(e.cat); |
- })); |
- } |
- |
- function tracingComplete(event) |
- { |
- InspectorTest.log("Tracing complete"); |
- InspectorTest.eventHandler["Tracing.tracingComplete"] = null; |
- InspectorTest.eventHandler["Tracing.dataCollected"] = null; |
- callback(InspectorTest.devtoolsEvents); |
- } |
-} |
+ return this.startTracingWithArguments(args); |
+ } |
-InspectorTest.stopTracingAndReturnStream = function(callback) |
-{ |
- InspectorTest.eventHandler["Tracing.tracingComplete"] = tracingComplete; |
- InspectorTest.eventHandler["Tracing.dataCollected"] = dataCollected; |
- InspectorTest.sendCommand("Tracing.end"); |
+ async startTracingWithArguments(args) { |
+ await this._session.protocol.Tracing.start(args); |
+ this._testRunner.log("Recording started"); |
+ } |
- function dataCollected(reply) |
- { |
- InspectorTest.log("FAIL: dataCollected event should not be fired when returning trace as stream."); |
+ async stopTracing() { |
+ var devtoolsEvents = []; |
- } |
+ function dataCollected(reply) { |
+ var allEvents = reply.params.value; |
+ var filteredEvents = allEvents.filter(e => /devtools.timeline/.test(e.cat)); |
+ devtoolsEvents = devtoolsEvents.concat(filteredEvents); |
+ }; |
- function tracingComplete(event) |
- { |
- InspectorTest.log("Tracing complete"); |
- InspectorTest.eventHandler["Tracing.tracingComplete"] = null; |
- InspectorTest.eventHandler["Tracing.dataCollected"] = null; |
- callback(event.params.stream); |
+ this._session.protocol.Tracing.onDataCollected(dataCollected); |
+ this._session.protocol.Tracing.end(); |
+ await this._session.protocol.Tracing.onceTracingComplete(); |
+ this._testRunner.log("Tracing complete"); |
+ this._session.protocol.Tracing.offDataCollected(dataCollected); |
+ this._devtoolsEvents = devtoolsEvents; |
+ return devtoolsEvents; |
+ } |
+ |
+ async stopTracingAndReturnStream() { |
+ function dataCollected() { |
+ this._testRunner.log("FAIL: dataCollected event should not be fired when returning trace as stream."); |
} |
-} |
-InspectorTest.retrieveStream = function(streamHandle, offset, chunkSize, callback) |
-{ |
+ this._session.protocol.Tracing.onDataCollected(dataCollected); |
+ this._session.protocol.Tracing.end(); |
+ var event = await this._session.protocol.Tracing.onceTracingComplete(); |
+ this._testRunner.log("Tracing complete"); |
+ this._session.protocol.Tracing.offDataCollected(dataCollected); |
+ return event.params.stream; |
+ } |
+ |
+ retrieveStream(streamHandle, offset, chunkSize) { |
+ var callback; |
+ var promise = new Promise(f => callback = f); |
var result = ""; |
var had_eof = false; |
var readArguments = { handle: streamHandle }; |
if (typeof chunkSize === "number") |
- readArguments.size = chunkSize; |
+ readArguments.size = chunkSize; |
var firstReadArguments = JSON.parse(JSON.stringify(readArguments)); |
if (typeof offset === "number") |
- firstReadArguments.offset = 0; |
- InspectorTest.sendCommandOrDie("IO.read", firstReadArguments, onChunkRead); |
- // Assure multiple in-lfight reads are fine (also, save on latencies). |
- InspectorTest.sendCommandOrDie("IO.read", readArguments, onChunkRead); |
- |
- function onChunkRead(response) |
- { |
- if (had_eof) |
- return; |
- result += response.data; |
- if (response.eof) { |
- // Ignore stray callbacks from proactive read requests. |
- had_eof = true; |
- callback(result); |
- return; |
- } |
- InspectorTest.sendCommandOrDie("IO.read", readArguments, onChunkRead); |
+ firstReadArguments.offset = 0; |
+ this._session.protocol.IO.read(firstReadArguments).then(message => onChunkRead.call(this, message.result)); |
+ // Assure multiple in-flight reads are fine (also, save on latencies). |
+ this._session.protocol.IO.read(readArguments).then(message => onChunkRead.call(this, message.result)); |
+ return promise; |
+ |
+ function onChunkRead(response) { |
+ if (had_eof) |
+ return; |
+ result += response.data; |
+ if (response.eof) { |
+ // Ignore stray callbacks from proactive read requests. |
+ had_eof = true; |
+ callback(result); |
+ return; |
+ } |
+ this._session.protocol.IO.read(readArguments).then(message => onChunkRead.call(this, message.result)); |
} |
-} |
+ } |
-InspectorTest.findEvents = function(name, ph, condition) |
-{ |
- return InspectorTest.devtoolsEvents.filter(e => e.name === name && e.ph === ph && (!condition || condition(e))); |
-} |
+ findEvents(name, ph, condition) { |
+ return this._devtoolsEvents.filter(e => e.name === name && e.ph === ph && (!condition || condition(e))); |
+ } |
-InspectorTest.findEvent = function(name, ph, condition) |
-{ |
- var events = InspectorTest.findEvents(name, ph, condition); |
+ findEvent(name, ph, condition) { |
+ var events = this.findEvents(name, ph, condition); |
if (events.length) |
- return events[0]; |
- throw new Error("Couldn't find event " + name + " / " + ph + "\n\n in " + JSON.stringify(InspectorTest.devtoolsEvents, null, 2)); |
-} |
- |
-InspectorTest.invokeAsyncWithTracing = function(functionName, callback) |
-{ |
- InspectorTest.startTracing(onStart); |
- |
- function onStart() |
- { |
- InspectorTest.evaluateInPageAsync(functionName + "()").then((data) => InspectorTest.stopTracing((devtoolsEvents) => callback(devtoolsEvents, data))); |
- } |
-} |
- |
-} |
+ return events[0]; |
+ throw new Error("Couldn't find event " + name + " / " + ph + "\n\n in " + JSON.stringify(this.devtoolsEvents, null, 2)); |
+ } |
+ |
+ filterEvents(callback) { |
+ return this._devtoolsEvents.filter(callback); |
+ } |
+ |
+ async invokeAsyncWithTracing(performActions) { |
+ await this.startTracing(); |
+ var data = await this._session.evaluateAsync(`(${performActions.toString()})()`); |
+ await this.stopTracing(); |
+ return data; |
+ } |
+ |
+ formattedEvents() { |
+ var formattedEvents = this._devtoolsEvents.map(e => e.name + (e.args.data ? '(' + e.args.data.type + ')' : '')); |
+ return JSON.stringify(formattedEvents, null, 2); |
+ } |
+}) |