OLD | NEW |
(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 var evalCallbackCallId = 3; |
| 6 |
| 7 initialize_tracingHarness = function() |
| 8 { |
| 9 |
| 10 InspectorTest.startTracing = function(callback) |
| 11 { |
| 12 InspectorTest.sendCommand("Tracing.start", { "categories": "-*,disabled-by-d
efault-devtools.timeline", "type": "", "options": "" }, onStart); |
| 13 |
| 14 function onStart(response) |
| 15 { |
| 16 InspectorTest.log("Recording started"); |
| 17 callback(); |
| 18 } |
| 19 } |
| 20 |
| 21 InspectorTest.stopTracing = function(callback) |
| 22 { |
| 23 InspectorTest.eventHandler["Tracing.tracingComplete"] = tracingComplete; |
| 24 InspectorTest.eventHandler["Tracing.dataCollected"] = dataCollected; |
| 25 InspectorTest.sendCommand("Tracing.end", { }, onStop); |
| 26 |
| 27 InspectorTest.devtoolsEvents = []; |
| 28 function dataCollected(reply) |
| 29 { |
| 30 var allEvents = reply.params.value; |
| 31 InspectorTest.devtoolsEvents = InspectorTest.devtoolsEvents.concat(allEv
ents.filter(function(e) |
| 32 { |
| 33 return e.cat === "disabled-by-default-devtools.timeline"; |
| 34 })); |
| 35 } |
| 36 |
| 37 function tracingComplete(event) |
| 38 { |
| 39 InspectorTest.log("Tracing complete"); |
| 40 InspectorTest.eventHandler["Tracing.tracingComplete"] = null; |
| 41 InspectorTest.eventHandler["Tracing.dataCollected"] = null; |
| 42 callback(InspectorTest.devtoolsEvents); |
| 43 } |
| 44 |
| 45 function onStop(response) |
| 46 { |
| 47 InspectorTest.log("Recording stopped"); |
| 48 } |
| 49 } |
| 50 |
| 51 InspectorTest.findEvent = function(name, ph, condition) |
| 52 { |
| 53 for (var i = 0; i < InspectorTest.devtoolsEvents.length; i++) { |
| 54 var e = InspectorTest.devtoolsEvents[i]; |
| 55 if (e.name === name && e.ph === ph && (!condition || condition(e))) |
| 56 return e; |
| 57 } |
| 58 throw new Error("Couldn't find event " + name + " / " + ph + "\n\n in " + JS
ON.stringify(InspectorTest.devtoolsEvents, null, 2)); |
| 59 } |
| 60 |
| 61 InspectorTest.invokeAsyncWithTracing = function(functionName, callback) |
| 62 { |
| 63 InspectorTest.startTracing(onStart); |
| 64 |
| 65 function onStart() |
| 66 { |
| 67 InspectorTest.invokePageFunctionAsync(functionName, done); |
| 68 } |
| 69 |
| 70 function done() |
| 71 { |
| 72 InspectorTest.stopTracing(callback); |
| 73 } |
| 74 } |
| 75 |
| 76 InspectorTest._lastEvalId = 0; |
| 77 InspectorTest._pendingEvalRequests = {}; |
| 78 |
| 79 InspectorTest.invokePageFunctionAsync = function(functionName, callback) |
| 80 { |
| 81 var id = ++InspectorTest._lastEvalId; |
| 82 InspectorTest._pendingEvalRequests[id] = callback; |
| 83 var asyncEvalWrapper = function(callId, functionName) |
| 84 { |
| 85 function evalCallback(result) |
| 86 { |
| 87 evaluateInFrontend("InspectorTest.didInvokePageFunctionAsync(" + cal
lId + ", " + JSON.stringify(result) + ");"); |
| 88 } |
| 89 eval(functionName + "(" + evalCallback + ")"); |
| 90 } |
| 91 InspectorTest.evaluateInPage("(" + asyncEvalWrapper.toString() + ")(" + id +
", unescape('" + escape(functionName) + "'))", function() { }); |
| 92 } |
| 93 |
| 94 InspectorTest.didInvokePageFunctionAsync = function(callId, value) |
| 95 { |
| 96 var callback = InspectorTest._pendingEvalRequests[callId]; |
| 97 |
| 98 if (!callback) { |
| 99 InspectorTest.addResult("Missing callback for async eval " + callId + ",
perhaps callback invoked twice?"); |
| 100 return; |
| 101 } |
| 102 delete InspectorTest._pendingEvalRequests[callId]; |
| 103 callback(value); |
| 104 } |
| 105 |
| 106 } |
| 107 |
OLD | NEW |