Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/http/tests/inspector-protocol/resources/protocol-test.html |
| diff --git a/third_party/WebKit/LayoutTests/http/tests/inspector-protocol/resources/protocol-test.html b/third_party/WebKit/LayoutTests/http/tests/inspector-protocol/resources/protocol-test.html |
| index ef865807e9f4c2871efbf885bb525a0628762965..b7f826a03c0e2251f7d0223a0524dcb5817305bf 100644 |
| --- a/third_party/WebKit/LayoutTests/http/tests/inspector-protocol/resources/protocol-test.html |
| +++ b/third_party/WebKit/LayoutTests/http/tests/inspector-protocol/resources/protocol-test.html |
| @@ -249,7 +249,7 @@ InspectorTest.evaluateInPage = function(string, callback) |
| if (message.error) |
| InspectorTest.log("Error while executing '" + string + "': " + message.error.message); |
| else if (callback) |
| - callback(); |
| + callback(message.result.result.value); |
| }); |
| }; |
| @@ -288,6 +288,80 @@ InspectorTest.importScript = function(scriptName) |
| window.eval(xhr.responseText + "\n//@ sourceURL=" + scriptName); |
| } |
| +InspectorTest.safeWrap = function(func, onexception) |
| +{ |
| + function result() |
| + { |
| + if (!func) |
| + return; |
| + var wrapThis = this; |
| + try { |
| + return func.apply(wrapThis, arguments); |
| + } catch(e) { |
| + InspectorTest.log("Exception while running: " + func + "\n" + (e.stack || e)); |
| + if (onexception) |
| + InspectorTest.safeWrap(onexception)(); |
| + else |
| + InspectorTest.completeTest(); |
| + } |
| + } |
| + return result; |
| +} |
| + |
| +var lastPromiseEvalId = 0; |
| +var pendingPromiseEvalRequests = {}; |
| + |
| +/** |
| + * The given function should take two callback paraters before the arguments: |
| + * * resolve - called when successful (with optional result) |
| + * * reject - called when there was a failure (with optional error) |
| + */ |
| +InspectorTest.invokePageFunctionPromise = function(functionName, parameters) |
| +{ |
| + return new Promise(function(resolve, reject) { |
| + var id = ++lastPromiseEvalId; |
| + pendingPromiseEvalRequests[id] = { resolve: InspectorTest.safeWrap(resolve), reject: InspectorTest.safeWrap(reject) }; |
| + |
| + var jsonParameters = []; |
| + for (var i = 0; i < parameters.length; ++i) |
| + jsonParameters.push(JSON.stringify(parameters[i])); |
| + var asyncEvalWrapper = function(callId, functionName, argumentsArray) |
| + { |
| + function evalCallbackResolve(result) |
| + { |
| + testRunner.evaluateInWebInspector(2, "InspectorTest.didInvokePageFunctionPromise(" + callId + ", " + JSON.stringify(result) + ", true);"); |
|
samli
2015/10/26 21:30:23
2 was evalCallbackCallId in inspector-test.js, but
pfeldman
2015/10/26 21:35:48
I don't think this number matters at all.
|
| + } |
| + |
| + function evalCallbackReject(result) |
| + { |
| + testRunner.evaluateInWebInspector(2, "InspectorTest.didInvokePageFunctionPromise(" + callId + ", " + JSON.stringify(result) + ", false);"); |
| + } |
| + |
| + var args = [evalCallbackResolve, evalCallbackReject].concat(argumentsArray.map(JSON.stringify)); |
| + var functionCall = functionName + ".call(null, " + args.join(", ") + ")"; |
| + try { |
| + eval(functionCall); |
| + } catch(e) { |
| + InspectorTest.log("Error: " + e); |
| + evalCallbackReject(e); |
| + } |
| + } |
| + var pageRequest = "(" + asyncEvalWrapper.toString() + ")(" + id + ", unescape('" + escape(functionName) + "'), [" + jsonParameters.join(", ") + "])"; |
| + InspectorTest.evaluateInPage(pageRequest); |
| + }); |
| +} |
| + |
| +InspectorTest.didInvokePageFunctionPromise = function(callId, value, didResolve) |
| +{ |
| + var callbacks = pendingPromiseEvalRequests[callId]; |
| + if (!callbacks) { |
| + InspectorTest.log("Missing callback for async eval " + callId + ", perhaps callback invoked twice?"); |
| + return; |
| + } |
| + var callback = didResolve ? callbacks.resolve : callbacks.reject; |
| + delete pendingPromiseEvalRequests[callId]; |
| + callback(value); |
| +} |
| InspectorTest.eventHandler["Inspector.evaluateForTestInFrontend"] = function(message) |
| { |