| Index: third_party/WebKit/LayoutTests/inspector-protocol/runtime/runtime-callFunctionOn-async.html
|
| diff --git a/third_party/WebKit/LayoutTests/inspector-protocol/runtime/runtime-callFunctionOn-async.html b/third_party/WebKit/LayoutTests/inspector-protocol/runtime/runtime-callFunctionOn-async.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f70887e837085dbf13a451b16cc53914648ebfb5
|
| --- /dev/null
|
| +++ b/third_party/WebKit/LayoutTests/inspector-protocol/runtime/runtime-callFunctionOn-async.html
|
| @@ -0,0 +1,148 @@
|
| +<html>
|
| +<head>
|
| +<script type="text/javascript" src="../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
|
| +<script>
|
| +
|
| +function createPromiseAndScheduleResolve()
|
| +{
|
| + var resolveCallback;
|
| + var promise = new Promise((resolve) => resolveCallback = resolve);
|
| + setTimeout(resolveCallback.bind(null, { a : 239 }), 0);
|
| + return promise;
|
| +}
|
| +
|
| +function test()
|
| +{
|
| + InspectorTest.runTestSuite([
|
| + function testArguments(next)
|
| + {
|
| + callFunctionOn(
|
| + "({a : 1})",
|
| + "function(arg1, arg2, arg3, arg4) { return \"\" + arg1 + \"|\" + arg2 + \"|\" + arg3 + \"|\" + arg4; }",
|
| + [ "undefined", "NaN", "({a:2})", "window"],
|
| + /* returnByValue */ true,
|
| + /* generatePreview */ false,
|
| + /* awaitPromise */ false)
|
| + .then((result) => dumpResult(result.result))
|
| + .then(() => next());
|
| + },
|
| +
|
| + function testSyntaxErrorInFunction(next)
|
| + {
|
| + callFunctionOn(
|
| + "({a : 1})",
|
| + "\n }",
|
| + [],
|
| + /* returnByValue */ false,
|
| + /* generatePreview */ false,
|
| + /* awaitPromise */ true)
|
| + .then((result) => dumpResult(result.result))
|
| + .then(() => next());
|
| + },
|
| +
|
| + function testExceptionInFunctionExpression(next)
|
| + {
|
| + callFunctionOn(
|
| + "({a : 1})",
|
| + "(function() { throw new Error() })()",
|
| + [],
|
| + /* returnByValue */ false,
|
| + /* generatePreview */ false,
|
| + /* awaitPromise */ true)
|
| + .then((result) => dumpResult(result.result))
|
| + .then(() => next());
|
| + },
|
| +
|
| + function testFunctionReturnNotPromise(next)
|
| + {
|
| + callFunctionOn(
|
| + "({a : 1})",
|
| + "(function() { return 239; })",
|
| + [],
|
| + /* returnByValue */ false,
|
| + /* generatePreview */ false,
|
| + /* awaitPromise */ true)
|
| + .then((result) => InspectorTest.logObject(result.error))
|
| + .then(() => next());
|
| + },
|
| +
|
| + function testFunctionReturnResolvedPromiseReturnByValue(next)
|
| + {
|
| + callFunctionOn(
|
| + "({a : 1})",
|
| + "(function(arg) { return Promise.resolve({a : this.a + arg.a}); })",
|
| + [ "({a:2})" ],
|
| + /* returnByValue */ true,
|
| + /* generatePreview */ false,
|
| + /* awaitPromise */ true)
|
| + .then((result) => dumpResult(result.result))
|
| + .then(() => next());
|
| + },
|
| +
|
| + function testFunctionReturnResolvedPromiseWithPreview(next)
|
| + {
|
| + callFunctionOn(
|
| + "({a : 1})",
|
| + "(function(arg) { return Promise.resolve({a : this.a + arg.a}); })",
|
| + [ "({a:2})" ],
|
| + /* returnByValue */ false,
|
| + /* generatePreview */ true,
|
| + /* awaitPromise */ true)
|
| + .then((result) => dumpResult(result.result))
|
| + .then(() => next());
|
| + },
|
| +
|
| + function testFunctionReturnRejectedPromise(next)
|
| + {
|
| + callFunctionOn(
|
| + "({a : 1})",
|
| + "(function(arg) { return Promise.reject({a : this.a + arg.a}); })",
|
| + [ "({a:2})" ],
|
| + /* returnByValue */ true,
|
| + /* generatePreview */ false,
|
| + /* awaitPromise */ true)
|
| + .then((result) => dumpResult(result.result))
|
| + .then(() => next());
|
| + }
|
| + ]);
|
| +
|
| + function callFunctionOn(objectExpression, functionDeclaration, argumentExpressions, returnByValue, generatePreview, awaitPromise)
|
| + {
|
| + var objectId;
|
| + var callArguments = [];
|
| + var promise = InspectorTest.sendCommandPromise("Runtime.evaluate", { expression: objectExpression })
|
| + .then((result) => objectId = result.result.result.objectId)
|
| + for (let argumentExpression of argumentExpressions) {
|
| + promise = promise
|
| + .then(() => InspectorTest.sendCommandPromise("Runtime.evaluate", { expression: argumentExpression }))
|
| + .then((result) => addArgument(result.result.result));
|
| + }
|
| + return promise.then(() => InspectorTest.sendCommandPromise("Runtime.callFunctionOn", { objectId: objectId, functionDeclaration: functionDeclaration, arguments: callArguments, returnByValue: returnByValue, generatePreview: generatePreview, awaitPromise: awaitPromise }));
|
| +
|
| + function addArgument(result)
|
| + {
|
| + if (result.objectId)
|
| + callArguments.push({ objectId: result.objectId, type: result.type });
|
| + else if (result.value)
|
| + callArguments.push({ value: result.value, type: result.type })
|
| + else
|
| + callArguments.push({ type: result.type });
|
| + }
|
| + }
|
| +
|
| + function dumpResult(result)
|
| + {
|
| + if (result.exceptionDetails && result.exceptionDetails.scriptId)
|
| + result.exceptionDetails.scriptId = 0;
|
| + if (result.result && result.result.objectId)
|
| + result.result.objectId = "[ObjectId]";
|
| + InspectorTest.logObject(result);
|
| + }
|
| +}
|
| +</script>
|
| +</head>
|
| +<body onLoad="runTest();">
|
| +Tests that Runtime.callFunctionOn works with awaitPromise flag.
|
| +</body>
|
| +</html>
|
| +
|
|
|