| 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
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..4282fcd13ab6ef8f95aa74b62f419e5ba1f36ecb
|
| --- /dev/null
|
| +++ b/third_party/WebKit/LayoutTests/inspector-protocol/resources/tracing-test.js
|
| @@ -0,0 +1,116 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +(function initialize_tracingHarness(testRunner, session) {
|
| +
|
| + class TracingHelper {
|
| + startTracing(callback) {
|
| + this.startTracingWithArguments({ "categories": "-*,disabled-by-default-devtools.timeline,devtools.timeline", "type": "", "options": "" }, callback);
|
| + }
|
| +
|
| + startTracingAndSaveAsStream(callback) {
|
| + var args = {
|
| + "categories": "-*,disabled-by-default-devtools.timeline,devtools.timeline",
|
| + "type": "",
|
| + "options": "",
|
| + "transferMode": "ReturnAsStream"
|
| + };
|
| + this.startTracingWithArguments(args, callback);
|
| + }
|
| +
|
| + startTracingWithArguments(args, callback) {
|
| + session.protocol.Tracing.start(args).then(onStart);
|
| + function onStart(response) {
|
| + testRunner.log("Recording started");
|
| + callback();
|
| + }
|
| + }
|
| +
|
| + stopTracing(callback) {
|
| + this.devtoolsEvents = [];
|
| + var dataCollected = reply => {
|
| + var allEvents = reply.params.value;
|
| + this.devtoolsEvents = this.devtoolsEvents.concat(allEvents.filter(function(e) {
|
| + return /devtools.timeline/.test(e.cat);
|
| + }));
|
| + };
|
| +
|
| + var tracingComplete = event => {
|
| + testRunner.log("Tracing complete");
|
| + session.protocol.Tracing.offTracingComplete(tracingComplete);
|
| + session.protocol.Tracing.offDataCollected(dataCollected);
|
| + callback(this.devtoolsEvents);
|
| + };
|
| +
|
| + session.protocol.Tracing.onTracingComplete(tracingComplete);
|
| + session.protocol.Tracing.onDataCollected(dataCollected);
|
| + session.protocol.Tracing.end();
|
| + }
|
| +
|
| + stopTracingAndReturnStream(callback) {
|
| + session.protocol.Tracing.onTracingComplete(tracingComplete);
|
| + session.protocol.Tracing.onDataCollected(dataCollected);
|
| + session.protocol.Tracing.end();
|
| +
|
| + function dataCollected(reply) {
|
| + testRunner.log("FAIL: dataCollected event should not be fired when returning trace as stream.");
|
| + }
|
| +
|
| + function tracingComplete(event) {
|
| + testRunner.log("Tracing complete");
|
| + session.protocol.Tracing.offTracingComplete(tracingComplete);
|
| + session.protocol.Tracing.offDataCollected(dataCollected);
|
| + callback(event.params.stream);
|
| + }
|
| + }
|
| +
|
| + retrieveStream(streamHandle, offset, chunkSize, callback) {
|
| + var result = "";
|
| + var had_eof = false;
|
| +
|
| + var readArguments = { handle: streamHandle };
|
| + if (typeof chunkSize === "number")
|
| + readArguments.size = chunkSize;
|
| + var firstReadArguments = JSON.parse(JSON.stringify(readArguments));
|
| + if (typeof offset === "number")
|
| + firstReadArguments.offset = 0;
|
| + session.protocol.IO.read(firstReadArguments).then(message => onChunkRead(message.result));
|
| + // Assure multiple in-lfight reads are fine (also, save on latencies).
|
| + session.protocol.IO.read(readArguments).then(message => onChunkRead(message.result));
|
| +
|
| + 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;
|
| + }
|
| + session.protocol.IO.read(readArguments).then(message => onChunkRead(message.result));
|
| + }
|
| + }
|
| +
|
| + findEvents(name, ph, condition) {
|
| + return this.devtoolsEvents.filter(e => e.name === name && e.ph === ph && (!condition || condition(e)));
|
| + }
|
| +
|
| + 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(this.devtoolsEvents, null, 2));
|
| + }
|
| +
|
| + invokeAsyncWithTracing(functionName, callback) {
|
| + this.startTracing(async () => {
|
| + var data = await session.evaluateAsync(functionName + "()");
|
| + this.stopTracing(devtoolsEvents => callback(devtoolsEvents, data));
|
| + });
|
| + }
|
| + }
|
| +
|
| + return new TracingHelper();
|
| +})
|
|
|