| 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 var evalCallbackCallId = 3; |
| 6 | 6 |
| 7 initialize_tracingHarness = function() | 7 initialize_tracingHarness = function() |
| 8 { | 8 { |
| 9 | 9 |
| 10 InspectorTest.startTracing = function(callback) | 10 InspectorTest.startTracing = function(callback) |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 } | 119 } |
| 120 throw new Error("Couldn't find event " + name + " / " + ph + "\n\n in " + JS
ON.stringify(InspectorTest.devtoolsEvents, null, 2)); | 120 throw new Error("Couldn't find event " + name + " / " + ph + "\n\n in " + JS
ON.stringify(InspectorTest.devtoolsEvents, null, 2)); |
| 121 } | 121 } |
| 122 | 122 |
| 123 InspectorTest.invokeAsyncWithTracing = function(functionName, callback) | 123 InspectorTest.invokeAsyncWithTracing = function(functionName, callback) |
| 124 { | 124 { |
| 125 InspectorTest.startTracing(onStart); | 125 InspectorTest.startTracing(onStart); |
| 126 | 126 |
| 127 function onStart() | 127 function onStart() |
| 128 { | 128 { |
| 129 InspectorTest.invokePageFunctionAsync(functionName, done); | 129 InspectorTest.evaluateInPageAsync(functionName + "()").then((data) => In
spectorTest.stopTracing((devtoolsEvents) => callback(devtoolsEvents, data))); |
| 130 } | |
| 131 | |
| 132 function done() | |
| 133 { | |
| 134 InspectorTest.stopTracing(callback); | |
| 135 } | 130 } |
| 136 } | 131 } |
| 137 | 132 |
| 138 InspectorTest._lastEvalId = 0; | |
| 139 InspectorTest._pendingEvalRequests = {}; | |
| 140 | |
| 141 InspectorTest.invokePageFunctionAsync = function(functionName, callback) | |
| 142 { | |
| 143 var id = ++InspectorTest._lastEvalId; | |
| 144 InspectorTest._pendingEvalRequests[id] = callback; | |
| 145 var asyncEvalWrapper = function(callId, functionName) | |
| 146 { | |
| 147 function evalCallback(result) | |
| 148 { | |
| 149 evaluateInFrontend("InspectorTest.didInvokePageFunctionAsync(" + cal
lId + ", " + JSON.stringify(result) + ");"); | |
| 150 } | |
| 151 eval(functionName + "(" + evalCallback + ")"); | |
| 152 } | |
| 153 InspectorTest.evaluateInPage("(" + asyncEvalWrapper.toString() + ")(" + id +
", unescape('" + escape(functionName) + "'))", function() { }); | |
| 154 } | 133 } |
| 155 | |
| 156 InspectorTest.didInvokePageFunctionAsync = function(callId, value) | |
| 157 { | |
| 158 var callback = InspectorTest._pendingEvalRequests[callId]; | |
| 159 | |
| 160 if (!callback) { | |
| 161 InspectorTest.addResult("Missing callback for async eval " + callId + ",
perhaps callback invoked twice?"); | |
| 162 return; | |
| 163 } | |
| 164 delete InspectorTest._pendingEvalRequests[callId]; | |
| 165 callback(value); | |
| 166 } | |
| 167 | |
| 168 } | |
| OLD | NEW |