Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Unified Diff: third_party/WebKit/LayoutTests/http/tests/inspector-protocol/resources/protocol-test.html

Issue 1417173002: Devtools Animations: Pause button based on groups not global (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/inspector-protocol/animation/animation-pause.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
{
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/inspector-protocol/animation/animation-pause.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698