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

Side by Side Diff: third_party/WebKit/LayoutTests/inspector-protocol/runtime/runtime-await-promise.html

Issue 2185233002: [DevTools] Added Runtime.awaitPromise protocol method (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: alligned output Created 4 years, 4 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 <html>
2 <head>
3 <script type="text/javascript" src="../../http/tests/inspector-protocol/inspecto r-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 function test()
34 {
35 InspectorTest.sendCommandPromise("Debugger.enable", {})
36 .then(() => InspectorTest.sendCommandPromise("Debugger.setAsyncCallStack Depth", { maxDepth: 128 }))
37 .then(() => testSuite());
38
39 function testSuite()
40 {
41 InspectorTest.runTestSuite([
42 function testResolvedPromise(next)
43 {
44 InspectorTest.sendCommandPromise("Runtime.evaluate", { expressio n: "Promise.resolve(239)"})
45 .then((result) => InspectorTest.sendCommandPromise("Runtime. awaitPromise", { promiseObjectId: result.result.result.objectId, returnByValue: false, generatePreview: true }))
46 .then((result) => InspectorTest.logObject(result.result))
47 .then(() => next());
48 },
49
50 function testRejectedPromise(next)
51 {
52 InspectorTest.sendCommandPromise("Runtime.evaluate", { expressio n: "Promise.reject({ a : 1 })"})
53 .then((result) => InspectorTest.sendCommandPromise("Runtime. awaitPromise", { promiseObjectId: result.result.result.objectId, returnByValue: true, generatePreview: false }))
54 .then((result) => InspectorTest.logObject(result.result))
55 .then(() => next());
56 },
57
58 function testRejectedPromiseWithStack(next)
59 {
60 InspectorTest.sendCommandPromise("Runtime.evaluate", { expressio n: "createPromise()"})
61 .then((result) => scheduleRejectAndAwaitPromise(result))
62 .then((result) => dumpResult(result.result))
63 .then(() => next());
64
65 function scheduleRejectAndAwaitPromise(result)
66 {
67 var promise = InspectorTest.sendCommandPromise("Runtime.awai tPromise", { promiseObjectId: result.result.result.objectId });
68 InspectorTest.sendCommandPromise("Runtime.evaluate", { expre ssion: "rejectPromise()" });
69 return promise;
70 }
71
72 function dumpResult(result)
73 {
74 for (var frame of result.exceptionDetails.stackTrace.parent. callFrames) {
75 frame.scriptId = 0;
76 frame.url = "";
77 }
78 InspectorTest.logObject(result);
79 }
80 },
81
82 function testPendingPromise(next)
83 {
84 InspectorTest.sendCommandPromise("Runtime.evaluate", { expressio n: "createPromise()"})
85 .then((result) => scheduleFulfillAndAwaitPromise(result))
86 .then((result) => InspectorTest.logObject(result.result))
87 .then(() => next());
88
89 function scheduleFulfillAndAwaitPromise(result)
90 {
91 var promise = InspectorTest.sendCommandPromise("Runtime.awai tPromise", { promiseObjectId: result.result.result.objectId });
92 InspectorTest.sendCommandPromise("Runtime.evaluate", { expre ssion: "resolvePromise()" });
93 return promise;
94 }
95 },
96
97 function testResolvedWithoutArgsPromise(next)
98 {
99 InspectorTest.sendCommandPromise("Runtime.evaluate", { expressio n: "Promise.resolve()"})
100 .then((result) => InspectorTest.sendCommandPromise("Runtime. awaitPromise", { promiseObjectId: result.result.result.objectId, returnByValue: true, generatePreview: false }))
101 .then((result) => InspectorTest.logObject(result.result))
102 .then(() => next());
103 },
104
105 function testGarbageCollectedPromise(next)
106 {
107 InspectorTest.sendCommandPromise("Runtime.evaluate", { expressio n: "new Promise(() => undefined)" })
108 .then((result) => scheduleGCAndawaitPromise(result))
109 .then((result) => InspectorTest.logObject(result.error))
110 .then(() => next());
111
112 function scheduleGCAndawaitPromise(result)
113 {
114 var objectId = result.result.result.objectId;
115 var promise = InspectorTest.sendCommandPromise("Runtime.awai tPromise", { promiseObjectId: objectId });
116 gcPromise(objectId);
117 return promise;
118 }
119
120 function gcPromise(objectId)
121 {
122 InspectorTest.sendCommandPromise("Runtime.releaseObject", { objectId: objectId})
123 .then(() => InspectorTest.sendCommandPromise("Runtime.ev aluate", { expression: "runGC()" }));
124 }
125 }
126 ]);
127 }
128 }
129 </script>
130 </head>
131 <body onLoad="runTest();">
132 Tests that Runtime.awaitPromise works.
133 </body>
134 </html>
135
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698