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

Side by Side Diff: third_party/WebKit/LayoutTests/inspector-protocol/runtime/runtime-callFunctionOn-async.js

Issue 2954093003: [DevTools] Migrate inspector-protocol/runtime tests to new harness (Closed)
Patch Set: fail: Created 3 years, 5 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 unified diff | Download patch
OLDNEW
(Empty)
1 (async function(testRunner) {
2 let {page, session, dp} = await testRunner.startBlank('Tests that Runtime.call FunctionOn works with awaitPromise flag.');
3
4 function dumpResult(result) {
5 if (result.exceptionDetails && result.exceptionDetails.scriptId)
6 result.exceptionDetails.scriptId = 0;
7 if (result.result && result.result.objectId)
8 result.result.objectId = '[ObjectId]';
9 if (result.exceptionDetails) {
10 result.exceptionDetails.exceptionId = 0;
11 result.exceptionDetails.exception.objectId = 0;
12 }
13 testRunner.logObject(result);
14 }
15
16 async function callFunctionOn(objectExpression, functionDeclaration, argumentE xpressions, returnByValue, generatePreview, awaitPromise) {
17 var objectId = (await dp.Runtime.evaluate({ expression: objectExpression })) .result.result.objectId;
18
19 var callArguments = [];
20 for (var argumentExpression of argumentExpressions) {
21 var result = (await dp.Runtime.evaluate({ expression: argumentExpression } )).result.result;
22 if (result.objectId) {
23 callArguments.push({ objectId: result.objectId });
24 } else if (result.value) {
25 callArguments.push({ value: result.value })
26 } else if (result.unserializableValue) {
27 callArguments.push({ unserializableValue: result.unserializableValue });
28 } else if (result.type === 'undefined') {
29 callArguments.push({});
30 } else {
31 testRunner.log('Unexpected argument object:');
32 testRunner.logObject(result);
33 testRunner.completeTest();
34 }
35 }
36
37 return dp.Runtime.callFunctionOn({ objectId, functionDeclaration, arguments: callArguments, returnByValue, generatePreview, awaitPromise });
38 }
39
40 await testRunner.runTestSuite([
41 async function testArguments() {
42 var result = await callFunctionOn(
43 '({a : 1})',
44 'function(arg1, arg2, arg3, arg4) { return \'\' + arg1 + \'|\' + arg2 + \'|\' + arg3 + \'|\' + arg4; }',
45 [ 'undefined', 'NaN', '({a:2})', 'window'],
46 /* returnByValue */ true,
47 /* generatePreview */ false,
48 /* awaitPromise */ false);
49 dumpResult(result.result);
50 },
51
52 async function testSyntaxErrorInFunction() {
53 var result = await callFunctionOn(
54 '({a : 1})',
55 '\n }',
56 [],
57 /* returnByValue */ false,
58 /* generatePreview */ false,
59 /* awaitPromise */ true);
60 dumpResult(result.result);
61 },
62
63 async function testExceptionInFunctionExpression() {
64 var result = await callFunctionOn(
65 '({a : 1})',
66 '(function() { throw new Error() })()',
67 [],
68 /* returnByValue */ false,
69 /* generatePreview */ false,
70 /* awaitPromise */ true);
71 dumpResult(result.result);
72 },
73
74 async function testFunctionReturnNotPromise() {
75 var result = await callFunctionOn(
76 '({a : 1})',
77 '(function() { return 239; })',
78 [],
79 /* returnByValue */ false,
80 /* generatePreview */ false,
81 /* awaitPromise */ true);
82 testRunner.logObject(result.error);
83 },
84
85 async function testFunctionReturnResolvedPromiseReturnByValue() {
86 var result = await callFunctionOn(
87 '({a : 1})',
88 '(function(arg) { return Promise.resolve({a : this.a + arg.a}); })',
89 [ '({a:2})' ],
90 /* returnByValue */ true,
91 /* generatePreview */ false,
92 /* awaitPromise */ true);
93 dumpResult(result.result);
94 },
95
96 async function testFunctionReturnResolvedPromiseWithPreview() {
97 var result = await callFunctionOn(
98 '({a : 1})',
99 '(function(arg) { return Promise.resolve({a : this.a + arg.a}); })',
100 [ '({a:2})' ],
101 /* returnByValue */ false,
102 /* generatePreview */ true,
103 /* awaitPromise */ true);
104 dumpResult(result.result);
105 },
106
107 async function testFunctionReturnRejectedPromise() {
108 var result = await callFunctionOn(
109 '({a : 1})',
110 '(function(arg) { return Promise.reject({a : this.a + arg.a}); })',
111 [ '({a:2})' ],
112 /* returnByValue */ true,
113 /* generatePreview */ false,
114 /* awaitPromise */ true);
115 dumpResult(result.result);
116 }
117 ]);
118 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698