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

Unified Diff: LayoutTests/inspector/debugger/async-callstack-promises.html

Issue 131823003: DevTools: Implement async call stacks for Promises. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 11 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: LayoutTests/inspector/debugger/async-callstack-promises.html
diff --git a/LayoutTests/inspector/debugger/async-callstack-promises.html b/LayoutTests/inspector/debugger/async-callstack-promises.html
new file mode 100644
index 0000000000000000000000000000000000000000..63199394c6b780acb7e7a0e1b5a8626187603eed
--- /dev/null
+++ b/LayoutTests/inspector/debugger/async-callstack-promises.html
@@ -0,0 +1,143 @@
+<html>
+<head>
+<script src="../../http/tests/inspector/inspector-test.js"></script>
+<script src="../../http/tests/inspector/debugger-test.js"></script>
+<script>
+
+function timeoutPromise(value, ms)
+{
+ return new Promise(function promiseCallback(resolve, reject) {
+ function resolvePromise()
+ {
+ resolve(value);
+ }
+ function rejectPromise()
+ {
+ reject(value);
+ }
+ if (value instanceof Error)
+ setTimeout(rejectPromise, ms || 0);
+ else
+ setTimeout(resolvePromise, ms || 0);
+ });
+}
+
+function settledPromise(value)
yhirano 2014/01/15 13:28:55 Let's use Promise.resolve and Promise.reject.
aandrey 2014/01/15 14:49:53 Added a separate test. The idea was to call those
+{
+ function resolveCallback(resolve, reject)
+ {
+ resolve(value);
+ }
+ function rejectCallback(resolve, reject)
+ {
+ reject(value);
+ }
+ if (value instanceof Error)
+ return new Promise(rejectCallback);
+ else
+ return new Promise(resolveCallback);
+}
+
+function testFunction()
+{
+ setTimeout(testFunctionTimeout, 0);
+}
+
+function testFunctionTimeout()
+{
+ var functions = [doTestPromiseConstructor, doTestSettledPromises, doTestChainedPromises, doTestPromiseAll, doTestThrowFromChain];
+ for (var i = 0; i < functions.length; ++i)
+ functions[i]();
+}
+
+function thenCallback(value)
+{
+ debugger;
+}
+
+function errorCallback(error)
+{
+ debugger;
+}
+
+function doTestPromiseConstructor()
+{
+ new Promise(function promiseCallback(resolve, reject) {
+ resolve(1);
+ debugger;
+ });
+}
+
+function doTestSettledPromises()
+{
+ settledPromise("resolved").then(thenCallback, errorCallback);
+ settledPromise(Error("rejected")).then(thenCallback, errorCallback);
+}
+
+function doTestChainedPromises()
+{
+ timeoutPromise(1).then(function chained1() {
+ debugger;
+ return timeoutPromise(2);
+ }).then(function chained2() {
+ debugger;
+ return 3;
+ }).then(function chained3() {
+ debugger;
+ return settledPromise(4);
+ }).then(function chained4() {
+ debugger;
+ return timeoutPromise(5);
+ }).then(thenCallback, errorCallback);
+}
+
+function doTestPromiseAll()
+{
+ Promise.all([11, 22, 33, 44, 55].map(timeoutPromise))
+ .then(thenCallback, errorCallback);
+}
+
+function doTestThrowFromChain()
+{
+ timeoutPromise(1).then(function chained1() {
+ return timeoutPromise(2);
+ }).then(function chained2() {
+ return settledPromise(3);
+ }).then(function chained3() {
+ throw Error("thrown from chained3");
+ }).then(function chained4() {
+ return timeoutPromise(5);
+ }).catch(function catchCallback() {
+ debugger;
+ });
+
+ timeoutPromise(1).then(function chained1() {
+ return timeoutPromise(2);
+ }).then(function chained2() {
+ return timeoutPromise(3);
+ }).then(function chained3() {
+ return timeoutPromise(Error(4));
+ }).then(function chained4() {
+ return timeoutPromise(5);
+ }).catch(function catchCallback() {
+ debugger;
+ });
+}
+
+var test = function()
+{
+ var totalDebuggerStatements = 11;
+ var maxAsyncCallStackDepth = 4;
+ InspectorTest.runAsyncCallStacksTest(totalDebuggerStatements, maxAsyncCallStackDepth);
+}
+
+</script>
+</head>
+
+<body onload="runTest()">
+<p>
+Tests asynchronous call stacks for Promises.
+</p>
+
+</body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698