Chromium Code Reviews| 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..4282fcd13ab6ef8f95aa74b62f419e5ba1f36ecb 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,115 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -var evalCallbackCallId = 3; |
| +(function initialize_tracingHarness(testRunner, session) { |
| -initialize_tracingHarness = function() |
| -{ |
| - |
| -InspectorTest.startTracing = function(callback) |
| -{ |
| - InspectorTest.startTracingWithArguments({ "categories": "-*,disabled-by-default-devtools.timeline,devtools.timeline", "type": "", "options": "" }, callback); |
| -} |
| + class TracingHelper { |
| + 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.
|
| + this.startTracingWithArguments({ "categories": "-*,disabled-by-default-devtools.timeline,devtools.timeline", "type": "", "options": "" }, callback); |
| + } |
| -InspectorTest.startTracingAndSaveAsStream = function(callback) |
| -{ |
| - var args = { |
| + startTracingAndSaveAsStream(callback) { |
| + var args = { |
| "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); |
| + }; |
| + this.startTracingWithArguments(args, callback); |
| + } |
| - function onStart(response) |
| - { |
| - InspectorTest.log("Recording started"); |
| + startTracingWithArguments(args, callback) { |
| + session.protocol.Tracing.start(args).then(onStart); |
| + function onStart(response) { |
| + testRunner.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) |
| - { |
| + stopTracing(callback) { |
| + this.devtoolsEvents = []; |
| + var dataCollected = reply => { |
| var allEvents = reply.params.value; |
| - InspectorTest.devtoolsEvents = InspectorTest.devtoolsEvents.concat(allEvents.filter(function(e) |
| - { |
| - return /devtools.timeline/.test(e.cat); |
| + 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(); |
| } |
| - function tracingComplete(event) |
| - { |
| - InspectorTest.log("Tracing complete"); |
| - InspectorTest.eventHandler["Tracing.tracingComplete"] = null; |
| - InspectorTest.eventHandler["Tracing.dataCollected"] = null; |
| - callback(InspectorTest.devtoolsEvents); |
| - } |
| -} |
| - |
| -InspectorTest.stopTracingAndReturnStream = function(callback) |
| -{ |
| - InspectorTest.eventHandler["Tracing.tracingComplete"] = tracingComplete; |
| - InspectorTest.eventHandler["Tracing.dataCollected"] = dataCollected; |
| - InspectorTest.sendCommand("Tracing.end"); |
| - |
| - function dataCollected(reply) |
| - { |
| - InspectorTest.log("FAIL: dataCollected event should not be fired when returning trace as stream."); |
| + 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) |
| - { |
| - InspectorTest.log("Tracing complete"); |
| - InspectorTest.eventHandler["Tracing.tracingComplete"] = null; |
| - InspectorTest.eventHandler["Tracing.dataCollected"] = null; |
| + function tracingComplete(event) { |
| + testRunner.log("Tracing complete"); |
| + session.protocol.Tracing.offTracingComplete(tracingComplete); |
| + session.protocol.Tracing.offDataCollected(dataCollected); |
| callback(event.params.stream); |
| + } |
| } |
| -} |
| -InspectorTest.retrieveStream = function(streamHandle, offset, chunkSize, callback) |
| -{ |
| - var result = ""; |
| - var had_eof = false; |
| + retrieveStream(streamHandle, offset, chunkSize, callback) { |
| + var result = ""; |
| + var had_eof = false; |
| - var readArguments = { handle: streamHandle }; |
| - if (typeof chunkSize === "number") |
| + var readArguments = { handle: streamHandle }; |
| + if (typeof chunkSize === "number") |
| readArguments.size = chunkSize; |
| - var firstReadArguments = JSON.parse(JSON.stringify(readArguments)); |
| - if (typeof offset === "number") |
| + 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); |
| + session.protocol.IO.read(firstReadArguments).then(message => onChunkRead(message.result)); |
| + // 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.
|
| + session.protocol.IO.read(readArguments).then(message => onChunkRead(message.result)); |
| - function onChunkRead(response) |
| - { |
| + function onChunkRead(response) { |
| if (had_eof) |
| - return; |
| + return; |
| result += response.data; |
| if (response.eof) { |
| - // Ignore stray callbacks from proactive read requests. |
| - had_eof = true; |
| - callback(result); |
| - return; |
| + // Ignore stray callbacks from proactive read requests. |
| + had_eof = true; |
| + callback(result); |
| + return; |
| } |
| - InspectorTest.sendCommandOrDie("IO.read", readArguments, onChunkRead); |
| + session.protocol.IO.read(readArguments).then(message => onChunkRead(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); |
| - if (events.length) |
| + 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); |
| + throw new Error("Couldn't find event " + name + " / " + ph + "\n\n in " + JSON.stringify(this.devtoolsEvents, null, 2)); |
| + } |
| - function onStart() |
| - { |
| - InspectorTest.evaluateInPageAsync(functionName + "()").then((data) => InspectorTest.stopTracing((devtoolsEvents) => callback(devtoolsEvents, data))); |
| + invokeAsyncWithTracing(functionName, callback) { |
| + this.startTracing(async () => { |
| + var data = await session.evaluateAsync(functionName + "()"); |
| + this.stopTracing(devtoolsEvents => callback(devtoolsEvents, data)); |
| + }); |
| } |
| -} |
| + } |
| -} |
| + return new TracingHelper(); |
| +}) |