| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 var evalCallbackCallId = 3; | 5 (function initialize_tracingHarness(session) |
| 6 | |
| 7 initialize_tracingHarness = function() | |
| 8 { | 6 { |
| 9 | 7 |
| 10 InspectorTest.startTracing = function(callback) | 8 InspectorTest.startTracing = function(callback) |
| 11 { | 9 { |
| 12 InspectorTest.startTracingWithArguments({ "categories": "-*,disabled-by-defa
ult-devtools.timeline,devtools.timeline", "type": "", "options": "" }, callback)
; | 10 InspectorTest.startTracingWithArguments({ "categories": "-*,disabled-by-defa
ult-devtools.timeline,devtools.timeline", "type": "", "options": "" }, callback)
; |
| 13 } | 11 } |
| 14 | 12 |
| 15 InspectorTest.startTracingAndSaveAsStream = function(callback) | 13 InspectorTest.startTracingAndSaveAsStream = function(callback) |
| 16 { | 14 { |
| 17 var args = { | 15 var args = { |
| 18 "categories": "-*,disabled-by-default-devtools.timeline,devtools.timelin
e", | 16 "categories": "-*,disabled-by-default-devtools.timeline,devtools.timelin
e", |
| 19 "type": "", | 17 "type": "", |
| 20 "options": "", | 18 "options": "", |
| 21 "transferMode": "ReturnAsStream" | 19 "transferMode": "ReturnAsStream" |
| 22 }; | 20 }; |
| 23 InspectorTest.startTracingWithArguments(args, callback); | 21 InspectorTest.startTracingWithArguments(args, callback); |
| 24 } | 22 } |
| 25 | 23 |
| 26 InspectorTest.startTracingWithArguments = function(args, callback) | 24 InspectorTest.startTracingWithArguments = function(args, callback) |
| 27 { | 25 { |
| 28 InspectorTest.sendCommand("Tracing.start", args, onStart); | 26 session.Protocol.Tracing.start(args).then(onStart); |
| 29 | 27 |
| 30 function onStart(response) | 28 function onStart(response) |
| 31 { | 29 { |
| 32 InspectorTest.log("Recording started"); | 30 InspectorTest.log("Recording started"); |
| 33 callback(); | 31 callback(); |
| 34 } | 32 } |
| 35 } | 33 } |
| 36 | 34 |
| 37 InspectorTest.stopTracing = function(callback) | 35 InspectorTest.stopTracing = function(callback) |
| 38 { | 36 { |
| 39 InspectorTest.eventHandler["Tracing.tracingComplete"] = tracingComplete; | 37 session.Protocol.Tracing.onTracingComplete(tracingComplete); |
| 40 InspectorTest.eventHandler["Tracing.dataCollected"] = dataCollected; | 38 session.Protocol.Tracing.onDataCollected(dataCollected); |
| 41 InspectorTest.sendCommand("Tracing.end", { }); | 39 session.Protocol.Tracing.end(); |
| 42 | 40 |
| 43 InspectorTest.devtoolsEvents = []; | 41 InspectorTest.devtoolsEvents = []; |
| 44 function dataCollected(reply) | 42 function dataCollected(reply) |
| 45 { | 43 { |
| 46 var allEvents = reply.params.value; | 44 var allEvents = reply.params.value; |
| 47 InspectorTest.devtoolsEvents = InspectorTest.devtoolsEvents.concat(allEv
ents.filter(function(e) | 45 InspectorTest.devtoolsEvents = InspectorTest.devtoolsEvents.concat(allEv
ents.filter(function(e) |
| 48 { | 46 { |
| 49 return /devtools.timeline/.test(e.cat); | 47 return /devtools.timeline/.test(e.cat); |
| 50 })); | 48 })); |
| 51 } | 49 } |
| 52 | 50 |
| 53 function tracingComplete(event) | 51 function tracingComplete(event) |
| 54 { | 52 { |
| 55 InspectorTest.log("Tracing complete"); | 53 InspectorTest.log("Tracing complete"); |
| 56 InspectorTest.eventHandler["Tracing.tracingComplete"] = null; | 54 session.Protocol.Tracing.offTracingComplete(tracingComplete); |
| 57 InspectorTest.eventHandler["Tracing.dataCollected"] = null; | 55 session.Protocol.Tracing.offDataCollected(dataCollected); |
| 58 callback(InspectorTest.devtoolsEvents); | 56 callback(InspectorTest.devtoolsEvents); |
| 59 } | 57 } |
| 60 } | 58 } |
| 61 | 59 |
| 62 InspectorTest.stopTracingAndReturnStream = function(callback) | 60 InspectorTest.stopTracingAndReturnStream = function(callback) |
| 63 { | 61 { |
| 64 InspectorTest.eventHandler["Tracing.tracingComplete"] = tracingComplete; | 62 session.Protocol.Tracing.onTracingComplete(tracingComplete); |
| 65 InspectorTest.eventHandler["Tracing.dataCollected"] = dataCollected; | 63 session.Protocol.Tracing.onDataCollected(dataCollected); |
| 66 InspectorTest.sendCommand("Tracing.end"); | 64 session.Protocol.Tracing.end(); |
| 67 | 65 |
| 68 function dataCollected(reply) | 66 function dataCollected(reply) |
| 69 { | 67 { |
| 70 InspectorTest.log("FAIL: dataCollected event should not be fired when re
turning trace as stream."); | 68 InspectorTest.log("FAIL: dataCollected event should not be fired when re
turning trace as stream."); |
| 71 | 69 |
| 72 } | 70 } |
| 73 | 71 |
| 74 function tracingComplete(event) | 72 function tracingComplete(event) |
| 75 { | 73 { |
| 76 InspectorTest.log("Tracing complete"); | 74 InspectorTest.log("Tracing complete"); |
| 77 InspectorTest.eventHandler["Tracing.tracingComplete"] = null; | 75 session.Protocol.Tracing.offTracingComplete(tracingComplete); |
| 78 InspectorTest.eventHandler["Tracing.dataCollected"] = null; | 76 session.Protocol.Tracing.offDataCollected(dataCollected); |
| 79 callback(event.params.stream); | 77 callback(event.params.stream); |
| 80 } | 78 } |
| 81 } | 79 } |
| 82 | 80 |
| 83 InspectorTest.retrieveStream = function(streamHandle, offset, chunkSize, callbac
k) | 81 InspectorTest.retrieveStream = function(streamHandle, offset, chunkSize, callbac
k) |
| 84 { | 82 { |
| 85 var result = ""; | 83 var result = ""; |
| 86 var had_eof = false; | 84 var had_eof = false; |
| 87 | 85 |
| 88 var readArguments = { handle: streamHandle }; | 86 var readArguments = { handle: streamHandle }; |
| 89 if (typeof chunkSize === "number") | 87 if (typeof chunkSize === "number") |
| 90 readArguments.size = chunkSize; | 88 readArguments.size = chunkSize; |
| 91 var firstReadArguments = JSON.parse(JSON.stringify(readArguments)); | 89 var firstReadArguments = JSON.parse(JSON.stringify(readArguments)); |
| 92 if (typeof offset === "number") | 90 if (typeof offset === "number") |
| 93 firstReadArguments.offset = 0; | 91 firstReadArguments.offset = 0; |
| 94 InspectorTest.sendCommandOrDie("IO.read", firstReadArguments, onChunkRead); | 92 session.Protocol.IO.read(firstReadArguments).then(message => onChunkRead(mes
sage.result)); |
| 95 // Assure multiple in-lfight reads are fine (also, save on latencies). | 93 // Assure multiple in-lfight reads are fine (also, save on latencies). |
| 96 InspectorTest.sendCommandOrDie("IO.read", readArguments, onChunkRead); | 94 session.Protocol.IO.read(readArguments).then(message => onChunkRead(message.
result)); |
| 97 | 95 |
| 98 function onChunkRead(response) | 96 function onChunkRead(response) |
| 99 { | 97 { |
| 100 if (had_eof) | 98 if (had_eof) |
| 101 return; | 99 return; |
| 102 result += response.data; | 100 result += response.data; |
| 103 if (response.eof) { | 101 if (response.eof) { |
| 104 // Ignore stray callbacks from proactive read requests. | 102 // Ignore stray callbacks from proactive read requests. |
| 105 had_eof = true; | 103 had_eof = true; |
| 106 callback(result); | 104 callback(result); |
| 107 return; | 105 return; |
| 108 } | 106 } |
| 109 InspectorTest.sendCommandOrDie("IO.read", readArguments, onChunkRead); | 107 session.Protocol.IO.read(readArguments).then(message => onChunkRead(mess
age.result)); |
| 110 } | 108 } |
| 111 } | 109 } |
| 112 | 110 |
| 113 InspectorTest.findEvents = function(name, ph, condition) | 111 InspectorTest.findEvents = function(name, ph, condition) |
| 114 { | 112 { |
| 115 return InspectorTest.devtoolsEvents.filter(e => e.name === name && e.ph ===
ph && (!condition || condition(e))); | 113 return InspectorTest.devtoolsEvents.filter(e => e.name === name && e.ph ===
ph && (!condition || condition(e))); |
| 116 } | 114 } |
| 117 | 115 |
| 118 InspectorTest.findEvent = function(name, ph, condition) | 116 InspectorTest.findEvent = function(name, ph, condition) |
| 119 { | 117 { |
| 120 var events = InspectorTest.findEvents(name, ph, condition); | 118 var events = InspectorTest.findEvents(name, ph, condition); |
| 121 if (events.length) | 119 if (events.length) |
| 122 return events[0]; | 120 return events[0]; |
| 123 throw new Error("Couldn't find event " + name + " / " + ph + "\n\n in " + JS
ON.stringify(InspectorTest.devtoolsEvents, null, 2)); | 121 throw new Error("Couldn't find event " + name + " / " + ph + "\n\n in " + JS
ON.stringify(InspectorTest.devtoolsEvents, null, 2)); |
| 124 } | 122 } |
| 125 | 123 |
| 126 InspectorTest.invokeAsyncWithTracing = function(functionName, callback) | 124 InspectorTest.invokeAsyncWithTracing = function(functionName, callback) |
| 127 { | 125 { |
| 128 InspectorTest.startTracing(onStart); | 126 InspectorTest.startTracing(onStart); |
| 129 | 127 |
| 130 function onStart() | 128 function onStart() |
| 131 { | 129 { |
| 132 InspectorTest.evaluateInPageAsync(functionName + "()").then((data) => In
spectorTest.stopTracing((devtoolsEvents) => callback(devtoolsEvents, data))); | 130 session.evaluateAsync(functionName + "()").then((data) => InspectorTest.
stopTracing((devtoolsEvents) => callback(devtoolsEvents, data))); |
| 133 } | 131 } |
| 134 } | 132 } |
| 135 | 133 |
| 136 } | 134 }) |
| OLD | NEW |