Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / inspector / sources / debugger / promise-events.html
blob9578e1f2c916b7554ddee07761b0e6377cdba94d
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 var promise1 = new Promise(
10 function promiseConstructor1(resolve, reject)
12 resolve("Resolved!");
15 var promise2 = new Promise(
16 function promiseConstructor2(resolve, reject)
18 reject("Rejected!");
21 promise2
22 .then(thenCallback1, thenCallback1)
23 .then(thenCallback2);
26 function thenCallback1()
28 return 0;
31 function thenCallback2()
33 if (window.GCController)
34 GCController.collectAll();
35 debugger;
38 function test()
40 var events = [];
41 var minPromiseId;
43 InspectorTest.startDebuggerTest(step1, true);
45 function step1()
47 InspectorTest.DebuggerAgent.enablePromiseTracker(true);
48 InspectorTest.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.PromiseUpdated, promiseUpdated);
49 InspectorTest.runTestFunctionAndWaitUntilPaused(step2);
52 function promiseUpdated(event)
54 var promiseId = event.data.promise.id;
55 minPromiseId = Math.min(minPromiseId, promiseId) || promiseId;
56 events.push(event.data);
59 function step2()
61 outputResults();
62 InspectorTest.DebuggerAgent.disablePromiseTracker();
63 InspectorTest.completeDebuggerTest();
66 function outputResults()
68 var output = [];
69 for (var i = 0; i < events.length; i++) {
70 var eventType = events[i].eventType;
71 var promise = events[i].promise;
72 var outputItem = [
73 eventType + ":",
74 "id: " + (promise.id - minPromiseId)
76 switch (eventType) {
77 case "new":
78 var callFrame = promise.callFrame;
79 if (callFrame) {
80 var url = WebInspector.displayNameForURL(callFrame.url);
81 outputItem.push(callFrame.functionName + " " + url + ":" + callFrame.lineNumber);
83 break;
84 case "update":
85 if (promise.status !== "pending") {
86 outputItem.push("status: " + promise.status)
87 var callFrame = promise.settlementStack && promise.settlementStack[0];
88 if (callFrame) {
89 var url = WebInspector.displayNameForURL(callFrame.url);
90 outputItem.push(callFrame.functionName + " " + url + ":" + callFrame.lineNumber);
92 } else {
93 outputItem.push("parent id: " + (promise.parentId - minPromiseId));
95 break;
97 output.push(outputItem.join("\n "));
99 output.sort();
100 InspectorTest.addResults(output);
104 </script>
105 </head>
107 <body onload="runTest()">
109 Tests promise tracker events in debugger.
110 </p>
111 </body>
112 </html>