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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/inspector-protocol/runtime/runtime-await-promise.html
diff --git a/third_party/WebKit/LayoutTests/inspector-protocol/runtime/runtime-await-promise.html b/third_party/WebKit/LayoutTests/inspector-protocol/runtime/runtime-await-promise.html
new file mode 100644
index 0000000000000000000000000000000000000000..53c25920fa566548e5572589425b42f17333d489
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/inspector-protocol/runtime/runtime-await-promise.html
@@ -0,0 +1,135 @@
+<html>
+<head>
+<script type="text/javascript" src="../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
+<script>
+
+var resolveCallback;
+var rejectCallback;
+function createPromise()
+{
+ return new Promise((resolve, reject) => { resolveCallback = resolve; rejectCallback = reject });
+}
+
+function resolvePromise()
+{
+ resolveCallback(239);
+ resolveCallback = undefined;
+ rejectCallback = undefined;
+}
+
+function rejectPromise()
+{
+ rejectCallback(239);
+ resolveCallback = undefined;
+ rejectCallback = undefined;
+}
+
+function runGC()
+{
+ if (window.gc)
+ window.gc();
+}
+
+function test()
+{
+ InspectorTest.sendCommandPromise("Debugger.enable", {})
+ .then(() => InspectorTest.sendCommandPromise("Debugger.setAsyncCallStackDepth", { maxDepth: 128 }))
+ .then(() => testSuite());
+
+ function testSuite()
+ {
+ InspectorTest.runTestSuite([
+ function testResolvedPromise(next)
+ {
+ InspectorTest.sendCommandPromise("Runtime.evaluate", { expression: "Promise.resolve(239)"})
+ .then((result) => InspectorTest.sendCommandPromise("Runtime.awaitPromise", { promiseObjectId: result.result.result.objectId, returnByValue: false, generatePreview: true }))
+ .then((result) => InspectorTest.logObject(result.result))
+ .then(() => next());
+ },
+
+ function testRejectedPromise(next)
+ {
+ InspectorTest.sendCommandPromise("Runtime.evaluate", { expression: "Promise.reject({ a : 1 })"})
+ .then((result) => InspectorTest.sendCommandPromise("Runtime.awaitPromise", { promiseObjectId: result.result.result.objectId, returnByValue: true, generatePreview: false }))
+ .then((result) => InspectorTest.logObject(result.result))
+ .then(() => next());
+ },
+
+ function testRejectedPromiseWithStack(next)
+ {
+ InspectorTest.sendCommandPromise("Runtime.evaluate", { expression: "createPromise()"})
+ .then((result) => scheduleRejectAndAwaitPromise(result))
+ .then((result) => dumpResult(result.result))
+ .then(() => next());
+
+ function scheduleRejectAndAwaitPromise(result)
+ {
+ var promise = InspectorTest.sendCommandPromise("Runtime.awaitPromise", { promiseObjectId: result.result.result.objectId });
+ InspectorTest.sendCommandPromise("Runtime.evaluate", { expression: "rejectPromise()" });
+ return promise;
+ }
+
+ function dumpResult(result)
+ {
+ for (var frame of result.exceptionDetails.stackTrace.parent.callFrames) {
+ frame.scriptId = 0;
+ frame.url = "";
+ }
+ InspectorTest.logObject(result);
+ }
+ },
+
+ function testPendingPromise(next)
+ {
+ InspectorTest.sendCommandPromise("Runtime.evaluate", { expression: "createPromise()"})
+ .then((result) => scheduleFulfillAndAwaitPromise(result))
+ .then((result) => InspectorTest.logObject(result.result))
+ .then(() => next());
+
+ function scheduleFulfillAndAwaitPromise(result)
+ {
+ var promise = InspectorTest.sendCommandPromise("Runtime.awaitPromise", { promiseObjectId: result.result.result.objectId });
+ InspectorTest.sendCommandPromise("Runtime.evaluate", { expression: "resolvePromise()" });
+ return promise;
+ }
+ },
+
+ function testResolvedWithoutArgsPromise(next)
+ {
+ InspectorTest.sendCommandPromise("Runtime.evaluate", { expression: "Promise.resolve()"})
+ .then((result) => InspectorTest.sendCommandPromise("Runtime.awaitPromise", { promiseObjectId: result.result.result.objectId, returnByValue: true, generatePreview: false }))
+ .then((result) => InspectorTest.logObject(result.result))
+ .then(() => next());
+ },
+
+ function testGarbageCollectedPromise(next)
+ {
+ InspectorTest.sendCommandPromise("Runtime.evaluate", { expression: "new Promise(() => undefined)" })
+ .then((result) => scheduleGCAndawaitPromise(result))
+ .then((result) => InspectorTest.logObject(result.error))
+ .then(() => next());
+
+ function scheduleGCAndawaitPromise(result)
+ {
+ var objectId = result.result.result.objectId;
+ var promise = InspectorTest.sendCommandPromise("Runtime.awaitPromise", { promiseObjectId: objectId });
+ gcPromise(objectId);
+ return promise;
+ }
+
+ function gcPromise(objectId)
+ {
+ InspectorTest.sendCommandPromise("Runtime.releaseObject", { objectId: objectId})
+ .then(() => InspectorTest.sendCommandPromise("Runtime.evaluate", { expression: "runGC()" }));
+ }
+ }
+ ]);
+ }
+}
+</script>
+</head>
+<body onLoad="runTest();">
+Tests that Runtime.awaitPromise works.
+</body>
+</html>
+

Powered by Google App Engine
This is Rietveld 408576698