Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.

Commit 8a0bc01

Browse files
Web Inspector: Audit: tests should support async operations
https://bugs.webkit.org/show_bug.cgi?id=192171 <rdar://problem/46423562> Reviewed by Joseph Pecoraro. Source/JavaScriptCore: Add `awaitPromise` command for executing a callback when a Promise gets settled. Drive-by: allow `wasThrown` to be optional, instead of expecting it to always have a value. * inspector/protocol/Runtime.json: * inspector/InjectedScriptSource.js: (InjectedScript.prototype.awaitPromise): Added. * inspector/InjectedScript.h: * inspector/InjectedScript.cpp: (Inspector::InjectedScript::evaluate): (Inspector::InjectedScript::awaitPromise): Added. (Inspector::InjectedScript::callFunctionOn): (Inspector::InjectedScript::evaluateOnCallFrame): * inspector/InjectedScriptBase.h: * inspector/InjectedScriptBase.cpp: (Inspector::InjectedScriptBase::makeEvalCall): (Inspector::InjectedScriptBase::makeAsyncCall): Added. (Inspector::InjcetedScriptBase::checkCallResult): Added. (Inspector::InjcetedScriptBase::checkAsyncCallResult): Added. * inspector/agents/InspectorRuntimeAgent.h: * inspector/agents/InspectorRuntimeAgent.cpp: (Inspector::InspectorRuntimeAgent::evaluate): (Inspector::InspectorRuntimeAgent::awaitPromise): (Inspector::InspectorRuntimeAgent::callFunctionOn): * inspector/agents/InspectorDebuggerAgent.cpp: (Inspector::InspectorDebuggerAgent::evaluateOnCallFrame): Source/WebCore: * page/Settings.yaml: * dom/ScriptExecutionContext.cpp: (ScriptExecutionContext::reportUnhandledPromiseRejection): Add setting for muting the "Unhandled Promise Rejection" console message. Source/WebInspectorUI: * UserInterface/Controllers/RuntimeManager.js: (WI.RuntimeManager.supportsAwaitPromise): Added. * UserInterface/Models/AuditTestCase.js: (WI.AuditTestCase.prototype.async run.async parseResponse.checkResultProperty.addErrorForValueType): Deleted. (WI.AuditTestCase.prototype.async run.async parseResponse.checkResultProperty): Deleted. (WI.AuditTestCase.prototype.async run.async parseResponse.async resultArrayForEach): Deleted. (WI.AuditTestCase.prototype.async run.async parseResponse): Added. (WI.AuditTestCase.prototype.async run): (WI.AuditTestCase.prototype.async run.checkResultProperty.addErrorForValueType): Deleted. (WI.AuditTestCase.prototype.async run.checkResultProperty): Deleted. (WI.AuditTestCase.prototype.async run.async resultArrayForEach): Deleted. * UserInterface/Models/AuditTestCaseResult.js: (WI.AuditTestCaseResult.async fromPayload): (WI.AuditTestCaseResult.prototype.toJSON): * UserInterface/Views/AuditTestCaseContentView.js: (WI.AuditTestCaseContentView.prototype.layout): LayoutTests: * inspector/audit/resources/audit-utilities.js: (TestPage.registerInitializer.InspectorTest.Audit.addFunctionlessTest): (TestPage.registerInitializer.InspectorTest.Audit.addStringTest): (TestPage.registerInitializer.InspectorTest.Audit.addObjectTest): (TestPage.registerInitializer.InspectorTest.Audit.addPromiseTest): Added. * inspector/audit/basic-expected.txt: * inspector/audit/basic.html: * inspector/model/auditTestCaseResult-expected.txt: * inspector/model/auditTestCaseResult.html: * inspector/model/auditTestGroupResult-expected.txt: * inspector/model/auditTestGroupResult.html: * inspector/runtime/awaitPromise-expected.txt: Added. * inspector/runtime/awaitPromise.html: Added. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@238850 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent f44f6d7 commit 8a0bc01

28 files changed

+613
-59
lines changed

LayoutTests/ChangeLog

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
2018-12-04 Devin Rousso <[email protected]>
2+
3+
Web Inspector: Audit: tests should support async operations
4+
https://bugs.webkit.org/show_bug.cgi?id=192171
5+
<rdar://problem/46423562>
6+
7+
Reviewed by Joseph Pecoraro.
8+
9+
* inspector/audit/resources/audit-utilities.js:
10+
(TestPage.registerInitializer.InspectorTest.Audit.addFunctionlessTest):
11+
(TestPage.registerInitializer.InspectorTest.Audit.addStringTest):
12+
(TestPage.registerInitializer.InspectorTest.Audit.addObjectTest):
13+
(TestPage.registerInitializer.InspectorTest.Audit.addPromiseTest): Added.
14+
* inspector/audit/basic-expected.txt:
15+
* inspector/audit/basic.html:
16+
17+
* inspector/model/auditTestCaseResult-expected.txt:
18+
* inspector/model/auditTestCaseResult.html:
19+
* inspector/model/auditTestGroupResult-expected.txt:
20+
* inspector/model/auditTestGroupResult.html:
21+
22+
* inspector/runtime/awaitPromise-expected.txt: Added.
23+
* inspector/runtime/awaitPromise.html: Added.
24+
125
2018-12-03 Carlos Garcia Campos <[email protected]>
226

327
[GTK] Bump freetype, fontconfig, harfbuzz, cairo and icu in jhbuild

LayoutTests/inspector/audit/basic-expected.txt

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,51 @@ PASS: Result should be "error".
5050
Testing value `{"level":"unsupported"}`...
5151
PASS: Result should be "unsupported".
5252

53+
-- Running test case: Audit.Basic.Promise.Boolean.True
54+
Testing value `new Promise((resolve, reject) => resolve(true))`...
55+
PASS: Result should be "pass".
56+
57+
-- Running test case: Audit.Basic.Promise.String.Pass
58+
Testing value `new Promise((resolve, reject) => resolve("pass"))`...
59+
PASS: Result should be "pass".
60+
61+
-- Running test case: Audit.Basic.Promise.Object.Pass
62+
Testing value `new Promise((resolve, reject) => resolve({level: "pass"}))`...
63+
PASS: Result should be "pass".
64+
65+
-- Running test case: Audit.Basic.Async.Boolean.True
66+
Testing value `true`...
67+
PASS: Result should be "pass".
68+
69+
-- Running test case: Audit.Basic.Async.String.Pass
70+
Testing value `"pass"`...
71+
PASS: Result should be "pass".
72+
73+
-- Running test case: Audit.Basic.Async.Object.Pass
74+
Testing value `{"level":"pass"}`...
75+
PASS: Result should be "pass".
76+
77+
-- Running test case: Audit.Basic.Timeout.Pass
78+
Testing value `new Promise((resolve, reject) => setTimeout(resolve, 0, "pass"))`...
79+
PASS: Result should be "pass".
80+
5381
-- Running test case: Audit.Basic.Error.Undefined
54-
Testing...
82+
Testing value `undefined`...
5583
PASS: Result should be "error".
5684
errors:
57-
- TypeError: eval(undefined) is not a function. (In 'eval(undefined)()', 'eval(undefined)' is undefined)
85+
- Return value is not an object, string, or boolean
5886

5987
-- Running test case: Audit.Basic.Error.Null
60-
Testing...
88+
Testing value `null`...
6189
PASS: Result should be "error".
6290
errors:
63-
- TypeError: eval(null) is not a function. (In 'eval(null)()', 'eval(null)' is null)
91+
- Return value is not an object, string, or boolean
6492

6593
-- Running test case: Audit.Basic.Error.Number
66-
Testing...
94+
Testing value `42`...
6795
PASS: Result should be "error".
6896
errors:
69-
- TypeError: eval(42) is not a function. (In 'eval(42)()', 'eval(42)' is 42)
97+
- Return value is not an object, string, or boolean
7098

7199
-- Running test case: Audit.Basic.Error.String
72100
Testing value `"foo"`...
@@ -81,8 +109,20 @@ PASS: Result should be "error".
81109
- Missing result level
82110

83111
-- Running test case: Audit.Basic.Error.Variable
84-
Testing...
112+
Testing value `INVALID`...
85113
PASS: Result should be "error".
86114
errors:
87115
- ReferenceError: Can't find variable: INVALID
88116

117+
-- Running test case: Audit.Basic.Error.Promise.Resolved
118+
Testing value `new Promise((resolve, reject) => setTimeout(resolve, 0))`...
119+
PASS: Result should be "error".
120+
errors:
121+
- Return value is not an object, string, or boolean
122+
123+
-- Running test case: Audit.Basic.Error.Promise.Rejected
124+
Testing value `new Promise((resolve, reject) => setTimeout(reject, 0, "rejected"))`...
125+
PASS: Result should be "error".
126+
errors:
127+
- rejected
128+

LayoutTests/inspector/audit/basic.html

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
55
<script src="resources/audit-utilities.js"></script>
66
<script>
7+
if (window.internals)
8+
window.internals.settings.setUnhandledPromiseRejectionToConsoleEnabled(false);
9+
710
function test()
811
{
912
let suite = InspectorTest.Audit.createSuite("Audit.Basic");
@@ -23,12 +26,24 @@
2326
InspectorTest.Audit.addObjectTest("Audit.Basic.Object.Error", {level: WI.AuditTestCaseResult.Level.Error}, WI.AuditTestCaseResult.Level.Error);
2427
InspectorTest.Audit.addObjectTest("Audit.Basic.Object.Unsupported", {level: WI.AuditTestCaseResult.Level.Unsupported}, WI.AuditTestCaseResult.Level.Unsupported);
2528

26-
InspectorTest.Audit.addTest("Audit.Basic.Error.Undefined", undefined, WI.AuditTestCaseResult.Level.Error);
27-
InspectorTest.Audit.addTest("Audit.Basic.Error.Null", null, WI.AuditTestCaseResult.Level.Error);
28-
InspectorTest.Audit.addTest("Audit.Basic.Error.Number", 42, WI.AuditTestCaseResult.Level.Error);
29+
InspectorTest.Audit.addPromiseTest("Audit.Basic.Promise.Boolean.True", `resolve(true)`, WI.AuditTestCaseResult.Level.Pass);
30+
InspectorTest.Audit.addPromiseTest("Audit.Basic.Promise.String.Pass", `resolve("${WI.AuditTestCaseResult.Level.Pass}")`, WI.AuditTestCaseResult.Level.Pass);
31+
InspectorTest.Audit.addPromiseTest("Audit.Basic.Promise.Object.Pass", `resolve({level: "${WI.AuditTestCaseResult.Level.Pass}"})`, WI.AuditTestCaseResult.Level.Pass);
32+
33+
InspectorTest.Audit.addFunctionlessTest("Audit.Basic.Async.Boolean.True", true, WI.AuditTestCaseResult.Level.Pass, {async: true});
34+
InspectorTest.Audit.addStringTest("Audit.Basic.Async.String.Pass", WI.AuditTestCaseResult.Level.Pass, WI.AuditTestCaseResult.Level.Pass, {async: true});
35+
InspectorTest.Audit.addObjectTest("Audit.Basic.Async.Object.Pass", {level: WI.AuditTestCaseResult.Level.Pass}, WI.AuditTestCaseResult.Level.Pass, {async: true});
36+
37+
InspectorTest.Audit.addPromiseTest("Audit.Basic.Timeout.Pass", `setTimeout(resolve, 0, "${WI.AuditTestCaseResult.Level.Pass}")`, WI.AuditTestCaseResult.Level.Pass);
38+
39+
InspectorTest.Audit.addFunctionlessTest("Audit.Basic.Error.Undefined", undefined, WI.AuditTestCaseResult.Level.Error);
40+
InspectorTest.Audit.addFunctionlessTest("Audit.Basic.Error.Null", null, WI.AuditTestCaseResult.Level.Error);
41+
InspectorTest.Audit.addFunctionlessTest("Audit.Basic.Error.Number", 42, WI.AuditTestCaseResult.Level.Error);
2942
InspectorTest.Audit.addStringTest("Audit.Basic.Error.String", "foo", WI.AuditTestCaseResult.Level.Error);
3043
InspectorTest.Audit.addObjectTest("Audit.Basic.Error.Object", {}, WI.AuditTestCaseResult.Level.Error);
31-
InspectorTest.Audit.addTest("Audit.Basic.Error.Variable", "INVALID", WI.AuditTestCaseResult.Level.Error);
44+
InspectorTest.Audit.addFunctionlessTest("Audit.Basic.Error.Variable", "INVALID", WI.AuditTestCaseResult.Level.Error);
45+
InspectorTest.Audit.addPromiseTest("Audit.Basic.Error.Promise.Resolved", `setTimeout(resolve, 0)`, WI.AuditTestCaseResult.Level.Error);
46+
InspectorTest.Audit.addPromiseTest("Audit.Basic.Error.Promise.Rejected", `setTimeout(reject, 0, "rejected")`, WI.AuditTestCaseResult.Level.Error);
3247

3348
suite.runTestCasesAndFinish();
3449
}

LayoutTests/inspector/audit/resources/audit-utilities.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,22 @@ TestPage.registerInitializer(() => {
6969
});
7070
};
7171

72-
InspectorTest.Audit.addFunctionlessTest = function(name, test, level) {
73-
InspectorTest.Audit.addTest(name, `function() { return ${test} }`, level, {
72+
InspectorTest.Audit.addFunctionlessTest = function(name, test, level, options = {}) {
73+
InspectorTest.Audit.addTest(name, (options.async ? "async " : "") + `function() { return ${test} }`, level, {
7474
beforeStart: ` value \`${test}\``,
7575
});
7676
};
7777

78-
InspectorTest.Audit.addStringTest = function(name, test, level) {
79-
InspectorTest.Audit.addFunctionlessTest(name, `"${test}"`, level);
78+
InspectorTest.Audit.addStringTest = function(name, test, level, options = {}) {
79+
InspectorTest.Audit.addFunctionlessTest(name, `"${test}"`, level, options);
8080
};
8181

82-
InspectorTest.Audit.addObjectTest = function(name, test, level) {
83-
InspectorTest.Audit.addFunctionlessTest(name, JSON.stringify(test), level);
82+
InspectorTest.Audit.addObjectTest = function(name, test, level, options = {}) {
83+
InspectorTest.Audit.addFunctionlessTest(name, JSON.stringify(test), level, options);
84+
};
85+
86+
InspectorTest.Audit.addPromiseTest = function(name, test, level, options = {}) {
87+
InspectorTest.Audit.addFunctionlessTest(name, `new Promise((resolve, reject) => ${test})`, level, options);
8488
};
8589

8690
InspectorTest.Audit.addDOMSelectorTest = function(name, test, level) {

LayoutTests/inspector/model/auditTestCaseResult-expected.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ null
5555
},
5656
"metadata": {
5757
"startTimestamp": "0001-01-01T00:00:00.000Z",
58-
"endTimestamp": "0002-01-01T00:00:00.000Z",
58+
"asyncTimestamp": "0002-01-01T00:00:00.000Z",
59+
"endTimestamp": "0003-01-01T00:00:00.000Z",
5960
"url": "validWithValidSubOptionals test result url"
6061
}
6162
}

LayoutTests/inspector/model/auditTestCaseResult.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
},
7272
metadata: {
7373
startTimestamp: null,
74+
asyncTimestamp: null,
7475
endTimestamp: null,
7576
url: null,
7677
},
@@ -90,7 +91,8 @@
9091
},
9192
metadata: {
9293
startTimestamp: "1",
93-
endTimestamp: "2",
94+
asyncTimestamp: "2",
95+
endTimestamp: "3",
9496
url: "validWithValidSubOptionals test result url",
9597
},
9698
},

LayoutTests/inspector/model/auditTestGroupResult-expected.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ null
7070
},
7171
"metadata": {
7272
"startTimestamp": "0001-01-01T00:00:00.000Z",
73-
"endTimestamp": "0002-01-01T00:00:00.000Z",
73+
"asyncTimestamp": "0002-01-01T00:00:00.000Z",
74+
"endTimestamp": "0003-01-01T00:00:00.000Z",
7475
"url": "validWithValidOptionals test result url"
7576
}
7677
}
@@ -106,7 +107,8 @@ null
106107
},
107108
"metadata": {
108109
"startTimestamp": "0001-01-01T00:00:00.000Z",
109-
"endTimestamp": "0002-01-01T00:00:00.000Z",
110+
"asyncTimestamp": "0002-01-01T00:00:00.000Z",
111+
"endTimestamp": "0003-01-01T00:00:00.000Z",
110112
"url": "validNested nested test result url"
111113
}
112114
}
@@ -129,8 +131,9 @@ null
129131
]
130132
},
131133
"metadata": {
132-
"startTimestamp": "0003-01-01T00:00:00.000Z",
133-
"endTimestamp": "0004-01-01T00:00:00.000Z",
134+
"startTimestamp": "0004-01-01T00:00:00.000Z",
135+
"asyncTimestamp": "0005-01-01T00:00:00.000Z",
136+
"endTimestamp": "0006-01-01T00:00:00.000Z",
134137
"url": "validNested test result url"
135138
}
136139
}

LayoutTests/inspector/model/auditTestGroupResult.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@
107107
},
108108
metadata: {
109109
startTimestamp: "1",
110-
endTimestamp: "2",
110+
asyncTimestamp: "2",
111+
endTimestamp: "3",
111112
url: "validWithValidOptionals test result url",
112113
},
113114
},
@@ -138,7 +139,8 @@
138139
},
139140
metadata: {
140141
startTimestamp: "1",
141-
endTimestamp: "2",
142+
asyncTimestamp: "2",
143+
endTimestamp: "3",
142144
url: "validNested nested test result url",
143145
},
144146
},
@@ -155,8 +157,9 @@
155157
errors: ["validNested test result error"],
156158
},
157159
metadata: {
158-
startTimestamp: "3",
159-
endTimestamp: "4",
160+
startTimestamp: "4",
161+
asyncTimestamp: "5",
162+
endTimestamp: "6",
160163
url: "validNested test result url",
161164
},
162165
},
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
Tests functionality of Runtime.awaitPromise.
2+
3+
4+
== Running test suite: Runtime.awaitPromise
5+
-- Running test case: Runtime.awaitPromise.Resolve.Undefined
6+
PASS: The resolved value should be undefined
7+
8+
-- Running test case: Runtime.awaitPromise.Resolve.Null
9+
PASS: The resolved value should be null
10+
11+
-- Running test case: Runtime.awaitPromise.Resolve.Boolean
12+
PASS: The resolved value should be true
13+
14+
-- Running test case: Runtime.awaitPromise.Resolve.Number
15+
PASS: The resolved value should be 42
16+
17+
-- Running test case: Runtime.awaitPromise.Resolve.String
18+
PASS: The resolved value should be "foo"
19+
20+
-- Running test case: Runtime.awaitPromise.Resolve.Array
21+
PASS: The resolved value should be [0,1]
22+
23+
-- Running test case: Runtime.awaitPromise.Resolve.Object
24+
PASS: The resolved value should be {"a":1,"b":2}
25+
26+
-- Running test case: Runtime.awaitPromise.Resolve.Chain
27+
PASS: The resolved value should be 3.
28+
29+
-- Running test case: Runtime.awaitPromise.Reject.Undefined
30+
PASS: The rejected value should be undefined
31+
32+
-- Running test case: Runtime.awaitPromise.Reject.Null
33+
PASS: The rejected value should be null
34+
35+
-- Running test case: Runtime.awaitPromise.Reject.Boolean
36+
PASS: The rejected value should be true
37+
38+
-- Running test case: Runtime.awaitPromise.Reject.Number
39+
PASS: The rejected value should be 42
40+
41+
-- Running test case: Runtime.awaitPromise.Reject.String
42+
PASS: The rejected value should be "foo"
43+
44+
-- Running test case: Runtime.awaitPromise.Reject.Array
45+
PASS: The rejected value should be [0,1]
46+
47+
-- Running test case: Runtime.awaitPromise.Reject.Object
48+
PASS: The rejected value should be {"a":1,"b":2}
49+
50+
-- Running test case: Runtime.awaitPromise.Reject.Chain
51+
PASS: The rejected value should be 3.
52+
53+
-- Running test case: Runtime.awaitPromise.Error.NonPromiseObjectId
54+
PASS: Should produce an error.
55+
Error: Error: Object with given id is not a Promise
56+
57+
-- Running test case: Runtime.awaitPromise.Error.InvalidPromiseObjectId
58+
PASS: Should produce an error.
59+
Error: Could not find InjectedScript for promiseObjectId
60+

0 commit comments

Comments
 (0)