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

Side by Side Diff: test/inspector/runtime/await-promise.js

Issue 2390733002: [inspector] Make InspectorTest.sendCommand* private (Closed)
Patch Set: addressed comments Created 4 years, 2 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
« no previous file with comments | « test/inspector/protocol-test.js ('k') | test/inspector/runtime/await-promise-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // Flags: --expose_gc 4 // Flags: --expose_gc
5 5
6 print("Tests that Runtime.awaitPromise works."); 6 print("Tests that Runtime.awaitPromise works.");
7 7
8 InspectorTest.evaluateInPage( 8 InspectorTest.addScript(
9 ` 9 `
10 var resolveCallback; 10 var resolveCallback;
11 var rejectCallback; 11 var rejectCallback;
12 function createPromise() 12 function createPromise()
13 { 13 {
14 return new Promise((resolve, reject) => { resolveCallback = resolve; rejectC allback = reject }); 14 return new Promise((resolve, reject) => { resolveCallback = resolve; rejectC allback = reject });
15 } 15 }
16 16
17 function resolvePromise() 17 function resolvePromise()
18 { 18 {
19 resolveCallback(239); 19 resolveCallback(239);
20 resolveCallback = undefined; 20 resolveCallback = undefined;
21 rejectCallback = undefined; 21 rejectCallback = undefined;
22 } 22 }
23 23
24 function rejectPromise() 24 function rejectPromise()
25 { 25 {
26 rejectCallback(239); 26 rejectCallback(239);
27 resolveCallback = undefined; 27 resolveCallback = undefined;
28 rejectCallback = undefined; 28 rejectCallback = undefined;
29 } 29 }
30 30
31 //# sourceURL=test.js`); 31 //# sourceURL=test.js`);
32 32
33 InspectorTest.sendCommandPromise("Debugger.enable", {}) 33 Protocol.Debugger.enable()
34 .then(() => InspectorTest.sendCommandPromise("Debugger.setAsyncCallStackDept h", { maxDepth: 128 })) 34 .then(() => Protocol.Debugger.setAsyncCallStackDepth({ maxDepth: 128 }))
35 .then(() => testSuite()); 35 .then(() => testSuite());
36
37 function dumpResult(result)
38 {
39 if (result.exceptionDetails) {
40 if (result.exceptionDetails.stackTrace && result.exceptionDetails.stackTrace .parent) {
41 for (var frame of result.exceptionDetails.stackTrace.parent.callFrames) {
42 frame.scriptId = 0;
43 if (!frame.url)
44 frame.url = "(empty)";
45 if (!frame.functionName)
46 frame.functionName = "(anonymous)";
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 36
56 function testSuite() 37 function testSuite()
57 { 38 {
58 InspectorTest.runTestSuite([ 39 InspectorTest.runTestSuite([
59 function testResolvedPromise(next) 40 function testResolvedPromise(next)
60 { 41 {
61 InspectorTest.sendCommandPromise("Runtime.evaluate", { expression: "Promis e.resolve(239)"}) 42 Protocol.Runtime.evaluate({ expression: "Promise.resolve(239)"})
62 .then((result) => InspectorTest.sendCommandPromise("Runtime.awaitPromise ", { promiseObjectId: result.result.result.objectId, returnByValue: false, gener atePreview: true })) 43 .then(result => Protocol.Runtime.awaitPromise({ promiseObjectId: result. result.result.objectId, returnByValue: false, generatePreview: true }))
63 .then((result) => dumpResult(result.result)) 44 .then(result => InspectorTest.logMessage(result))
64 .then(() => next()); 45 .then(() => next());
65 }, 46 },
66 47
67 function testRejectedPromise(next) 48 function testRejectedPromise(next)
68 { 49 {
69 InspectorTest.sendCommandPromise("Runtime.evaluate", { expression: "Promis e.reject({ a : 1 })"}) 50 Protocol.Runtime.evaluate({ expression: "Promise.reject({ a : 1 })"})
70 .then((result) => InspectorTest.sendCommandPromise("Runtime.awaitPromise ", { promiseObjectId: result.result.result.objectId, returnByValue: true, genera tePreview: false })) 51 .then(result => Protocol.Runtime.awaitPromise({ promiseObjectId: result. result.result.objectId, returnByValue: true, generatePreview: false }))
71 .then((result) => dumpResult(result.result)) 52 .then(result => InspectorTest.logMessage(result))
72 .then(() => next()); 53 .then(() => next());
73 }, 54 },
74 55
75 function testRejectedPromiseWithStack(next) 56 function testRejectedPromiseWithStack(next)
76 { 57 {
77 InspectorTest.sendCommandPromise("Runtime.evaluate", { expression: "create Promise()"}) 58 Protocol.Runtime.evaluate({ expression: "createPromise()"})
78 .then((result) => scheduleRejectAndAwaitPromise(result)) 59 .then(result => scheduleRejectAndAwaitPromise(result))
79 .then((result) => dumpResult(result.result)) 60 .then(result => InspectorTest.logMessage(result))
80 .then(() => next()); 61 .then(() => next());
81 62
82 function scheduleRejectAndAwaitPromise(result) 63 function scheduleRejectAndAwaitPromise(result)
83 { 64 {
84 var promise = InspectorTest.sendCommandPromise("Runtime.awaitPromise", { promiseObjectId: result.result.result.objectId }); 65 var promise = Protocol.Runtime.awaitPromise({ promiseObjectId: result.re sult.result.objectId });
85 InspectorTest.sendCommandPromise("Runtime.evaluate", { expression: "reje ctPromise()" }); 66 Protocol.Runtime.evaluate({ expression: "rejectPromise()" });
86 return promise; 67 return promise;
87 } 68 }
88 }, 69 },
89 70
90 function testPendingPromise(next) 71 function testPendingPromise(next)
91 { 72 {
92 InspectorTest.sendCommandPromise("Runtime.evaluate", { expression: "create Promise()"}) 73 Protocol.Runtime.evaluate({ expression: "createPromise()"})
93 .then((result) => scheduleFulfillAndAwaitPromise(result)) 74 .then(result => scheduleFulfillAndAwaitPromise(result))
94 .then((result) => dumpResult(result.result)) 75 .then(result => InspectorTest.logMessage(result))
95 .then(() => next()); 76 .then(() => next());
96 77
97 function scheduleFulfillAndAwaitPromise(result) 78 function scheduleFulfillAndAwaitPromise(result)
98 { 79 {
99 var promise = InspectorTest.sendCommandPromise("Runtime.awaitPromise", { promiseObjectId: result.result.result.objectId }); 80 var promise = Protocol.Runtime.awaitPromise({ promiseObjectId: result.re sult.result.objectId });
100 InspectorTest.sendCommandPromise("Runtime.evaluate", { expression: "reso lvePromise()" }); 81 Protocol.Runtime.evaluate({ expression: "resolvePromise()" });
101 return promise; 82 return promise;
102 } 83 }
103 }, 84 },
104 85
105 function testResolvedWithoutArgsPromise(next) 86 function testResolvedWithoutArgsPromise(next)
106 { 87 {
107 InspectorTest.sendCommandPromise("Runtime.evaluate", { expression: "Promis e.resolve()"}) 88 Protocol.Runtime.evaluate({ expression: "Promise.resolve()"})
108 .then((result) => InspectorTest.sendCommandPromise("Runtime.awaitPromise ", { promiseObjectId: result.result.result.objectId, returnByValue: true, genera tePreview: false })) 89 .then(result => Protocol.Runtime.awaitPromise({ promiseObjectId: result. result.result.objectId, returnByValue: true, generatePreview: false }))
109 .then((result) => dumpResult(result.result)) 90 .then(result => InspectorTest.logMessage(result))
110 .then(() => next()); 91 .then(() => next());
111 }, 92 },
112 93
113 function testGarbageCollectedPromise(next) 94 function testGarbageCollectedPromise(next)
114 { 95 {
115 InspectorTest.sendCommandPromise("Runtime.evaluate", { expression: "new Pr omise(() => undefined)" }) 96 Protocol.Runtime.evaluate({ expression: "new Promise(() => undefined)" })
116 .then((result) => scheduleGCAndawaitPromise(result)) 97 .then(result => scheduleGCAndawaitPromise(result))
117 .then((result) => InspectorTest.logObject(result.error)) 98 .then(result => InspectorTest.logMessage(result))
118 .then(() => next()); 99 .then(() => next());
119 100
120 function scheduleGCAndawaitPromise(result) 101 function scheduleGCAndawaitPromise(result)
121 { 102 {
122 var objectId = result.result.result.objectId; 103 var objectId = result.result.result.objectId;
123 var promise = InspectorTest.sendCommandPromise("Runtime.awaitPromise", { promiseObjectId: objectId }); 104 var promise = Protocol.Runtime.awaitPromise({ promiseObjectId: objectId });
124 gcPromise(objectId); 105 gcPromise(objectId);
125 return promise; 106 return promise;
126 } 107 }
127 108
128 function gcPromise(objectId) 109 function gcPromise(objectId)
129 { 110 {
130 InspectorTest.sendCommandPromise("Runtime.releaseObject", { objectId: ob jectId}) 111 Protocol.Runtime.releaseObject({ objectId: objectId})
131 .then(() => InspectorTest.sendCommandPromise("Runtime.evaluate", { exp ression: "gc()" })); 112 .then(() => Protocol.Runtime.evaluate({ expression: "gc()" }));
132 } 113 }
133 } 114 }
134 ]); 115 ]);
135 } 116 }
OLDNEW
« no previous file with comments | « test/inspector/protocol-test.js ('k') | test/inspector/runtime/await-promise-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698