Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / inspector / sources / debugger-async / async-operation-events.html
blob648e21b83a0312d45db3110ab71412a58294326a
1 <html>
2 <head>
3 <script src="../../../http/tests/inspector/inspector-test.js"></script>
4 <script src="../../../http/tests/inspector/debugger-test.js"></script>
5 <script>
7 function testFunction()
9 debugger;
10 setTimeout(callback1, 0);
13 function callback1()
15 setTimeout(callback2, 0);
16 Promise.resolve(42)
17 .then(function() {});
20 function callback2()
22 setTimeout(callback3, 0);
23 // Pressing RESUME here, thus the following async promise events should not be reported to the front-end.
24 Promise.resolve(43)
25 .then(function() {})
26 .then(function() {});
29 function callback3()
31 Promise.resolve(44)
32 .then(function() {})
33 .then(
34 function()
36 setTimeout(callback4, 0);
41 function callback4()
43 debugger;
46 function runIntervals()
48 setInterval(function f1() {}, 50);
49 setInterval(function f2() {}, 60);
50 setInterval(function f3() {}, 70);
53 function test()
55 var maxAsyncCallStackDepth = 4;
56 InspectorTest.startDebuggerTest(step1, true);
58 function step1()
60 InspectorTest.runTestFunctionAndWaitUntilPaused(step2);
63 function step2()
65 InspectorTest.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.AsyncOperationStarted, onAsyncOperationStarted);
66 InspectorTest.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.AsyncOperationCompleted, onAsyncOperationCompleted);
67 InspectorTest.DebuggerAgent.setAsyncCallStackDepth(maxAsyncCallStackDepth, step3);
70 function step3()
72 var actions = [
73 "StepOver", "StepOver", "StepOver", "Print", // @ callback1
74 "StepOver", "StepOver", "StepOver", "StepOver", "StepOver", "Print", // @ callback2
75 "StepOver", "StepOver", "Resume",
76 "Resume",
78 InspectorTest.waitUntilPausedAndPerformSteppingActions(actions, step4);
81 var asyncOperations = {};
82 var setIntervalEventCount = 3;
83 var noAsyncOperationsCallback = null;
85 function onAsyncOperationStarted(event)
87 var operation = event.data;
88 var description = asyncOperationDescription(operation);
89 asyncOperations[operation.id] = description;
90 InspectorTest.addResult("==> AsyncOperationStarted: " + description);
92 if (description.indexOf("runIntervals") !== -1) {
93 if (!--setIntervalEventCount)
94 InspectorTest.completeDebuggerTest();
98 function onAsyncOperationCompleted(event)
100 var operationId = event.data;
101 InspectorTest.addResult("==> AsyncOperationCompleted: " + asyncOperations[operationId]);
102 delete asyncOperations[operationId];
103 maybeRunNoAsyncOperationsCallback();
106 function asyncOperationDescription(operation)
108 var link = "";
109 var callFrame = operation.stackTrace && operation.stackTrace[0];
110 if (callFrame) {
111 var url = WebInspector.displayNameForURL(callFrame.url);
112 link = " " + callFrame.functionName + " @ " + url + ":" + callFrame.lineNumber;
114 return ("[" + operation.description + "]" + link);
117 function maybeRunNoAsyncOperationsCallback()
119 if (!noAsyncOperationsCallback)
120 return;
121 for (var id in asyncOperations)
122 return;
123 var callback = noAsyncOperationsCallback;
124 noAsyncOperationsCallback = null;
125 callback();
128 function step4()
130 noAsyncOperationsCallback = step5;
131 maybeRunNoAsyncOperationsCallback();
134 function step5()
136 InspectorTest.addResult("Scheduling few setInterval's...");
137 InspectorTest.evaluateInPage("runIntervals()", step6);
140 function step6()
142 InspectorTest.addResult("All setInterval's were scheduled.");
143 InspectorTest.addResult("Requesting all pending AsyncOperation events from backend...");
144 InspectorTest.DebuggerAgent.flushAsyncOperationEvents();
149 </script>
150 </head>
152 <body onload="runTest()">
154 Tests debugger AsyncOperation events while in a debugger stepping session.
155 </p>
156 </body>
157 </html>