OLD | NEW |
| (Empty) |
1 <html> | |
2 <head> | |
3 <script type="text/javascript" src="../../http/tests/inspector-protocol/resource
s/inspector-protocol-test.js"></script> | |
4 <script> | |
5 | |
6 var resolveCallback; | |
7 var rejectCallback; | |
8 function createPromise() | |
9 { | |
10 return new Promise((resolve, reject) => { resolveCallback = resolve; rejectC
allback = reject }); | |
11 } | |
12 | |
13 function resolvePromise() | |
14 { | |
15 resolveCallback(239); | |
16 resolveCallback = undefined; | |
17 rejectCallback = undefined; | |
18 } | |
19 | |
20 function rejectPromise() | |
21 { | |
22 rejectCallback(239); | |
23 resolveCallback = undefined; | |
24 rejectCallback = undefined; | |
25 } | |
26 | |
27 function runGC() | |
28 { | |
29 if (window.gc) | |
30 window.gc(); | |
31 } | |
32 | |
33 testRunner.setDumpConsoleMessages(false); | |
34 function test() | |
35 { | |
36 InspectorTest.sendCommandPromise("Debugger.enable", {}) | |
37 .then(() => InspectorTest.sendCommandPromise("Debugger.setAsyncCallStack
Depth", { maxDepth: 128 })) | |
38 .then(() => testSuite()); | |
39 | |
40 function dumpResult(result) | |
41 { | |
42 if (result.exceptionDetails) { | |
43 if (result.exceptionDetails.stackTrace && result.exceptionDetails.st
ackTrace.parent) { | |
44 for (var frame of result.exceptionDetails.stackTrace.parent.call
Frames) { | |
45 frame.scriptId = 0; | |
46 frame.url = ""; | |
47 } | |
48 } | |
49 result.exceptionDetails.exceptionId = 0; | |
50 if (result.exceptionDetails.exception) | |
51 result.exceptionDetails.exception.objectId = 0; | |
52 } | |
53 InspectorTest.logObject(result); | |
54 } | |
55 | |
56 function testSuite() | |
57 { | |
58 InspectorTest.runTestSuite([ | |
59 function testResolvedPromise(next) | |
60 { | |
61 InspectorTest.sendCommandPromise("Runtime.evaluate", { expressio
n: "Promise.resolve(239)"}) | |
62 .then((result) => InspectorTest.sendCommandPromise("Runtime.
awaitPromise", { promiseObjectId: result.result.result.objectId, returnByValue:
false, generatePreview: true })) | |
63 .then((result) => dumpResult(result.result)) | |
64 .then(() => next()); | |
65 }, | |
66 | |
67 function testRejectedPromise(next) | |
68 { | |
69 InspectorTest.sendCommandPromise("Runtime.evaluate", { expressio
n: "Promise.reject({ a : 1 })"}) | |
70 .then((result) => InspectorTest.sendCommandPromise("Runtime.
awaitPromise", { promiseObjectId: result.result.result.objectId, returnByValue:
true, generatePreview: false })) | |
71 .then((result) => dumpResult(result.result)) | |
72 .then(() => next()); | |
73 }, | |
74 | |
75 function testRejectedPromiseWithStack(next) | |
76 { | |
77 InspectorTest.sendCommandPromise("Runtime.evaluate", { expressio
n: "createPromise()"}) | |
78 .then((result) => scheduleRejectAndAwaitPromise(result)) | |
79 .then((result) => dumpResult(result.result)) | |
80 .then(() => next()); | |
81 | |
82 function scheduleRejectAndAwaitPromise(result) | |
83 { | |
84 var promise = InspectorTest.sendCommandPromise("Runtime.awai
tPromise", { promiseObjectId: result.result.result.objectId }); | |
85 InspectorTest.sendCommandPromise("Runtime.evaluate", { expre
ssion: "rejectPromise()" }); | |
86 return promise; | |
87 } | |
88 }, | |
89 | |
90 function testPendingPromise(next) | |
91 { | |
92 InspectorTest.sendCommandPromise("Runtime.evaluate", { expressio
n: "createPromise()"}) | |
93 .then((result) => scheduleFulfillAndAwaitPromise(result)) | |
94 .then((result) => dumpResult(result.result)) | |
95 .then(() => next()); | |
96 | |
97 function scheduleFulfillAndAwaitPromise(result) | |
98 { | |
99 var promise = InspectorTest.sendCommandPromise("Runtime.awai
tPromise", { promiseObjectId: result.result.result.objectId }); | |
100 InspectorTest.sendCommandPromise("Runtime.evaluate", { expre
ssion: "resolvePromise()" }); | |
101 return promise; | |
102 } | |
103 }, | |
104 | |
105 function testResolvedWithoutArgsPromise(next) | |
106 { | |
107 InspectorTest.sendCommandPromise("Runtime.evaluate", { expressio
n: "Promise.resolve()"}) | |
108 .then((result) => InspectorTest.sendCommandPromise("Runtime.
awaitPromise", { promiseObjectId: result.result.result.objectId, returnByValue:
true, generatePreview: false })) | |
109 .then((result) => dumpResult(result.result)) | |
110 .then(() => next()); | |
111 }, | |
112 | |
113 function testGarbageCollectedPromise(next) | |
114 { | |
115 InspectorTest.sendCommandPromise("Runtime.evaluate", { expressio
n: "new Promise(() => undefined)" }) | |
116 .then((result) => scheduleGCAndawaitPromise(result)) | |
117 .then((result) => InspectorTest.logObject(result.error)) | |
118 .then(() => next()); | |
119 | |
120 function scheduleGCAndawaitPromise(result) | |
121 { | |
122 var objectId = result.result.result.objectId; | |
123 var promise = InspectorTest.sendCommandPromise("Runtime.awai
tPromise", { promiseObjectId: objectId }); | |
124 gcPromise(objectId); | |
125 return promise; | |
126 } | |
127 | |
128 function gcPromise(objectId) | |
129 { | |
130 InspectorTest.sendCommandPromise("Runtime.releaseObject", {
objectId: objectId}) | |
131 .then(() => InspectorTest.sendCommandPromise("Runtime.ev
aluate", { expression: "runGC()" })); | |
132 } | |
133 } | |
134 ]); | |
135 } | |
136 } | |
137 </script> | |
138 </head> | |
139 <body onLoad="runTest();"> | |
140 Tests that Runtime.awaitPromise works. | |
141 </body> | |
142 </html> | |
143 | |
OLD | NEW |