Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / inspector / sources / debugger / promise-tracker.html
blob6cf10a7e50271e882585ba4005216eafdd0f8a40
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 var promise;
8 function testFunction()
10 promise = new Promise(function promiseConstructor(resolve, reject) {
11 resolve("Resolved!");
12 });
13 promise
14 .then(thenCallback, errorCallback)
15 .then(thenCallback2, errorCallback);
18 function thenCallback() { }
20 function thenCallback2()
22 debugger;
25 function errorCallback() { }
27 var test = function ()
29 InspectorTest.startDebuggerTest(step1);
31 var minPromiseId;
32 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebInspector.DebuggerModel.Events.PromiseUpdated, onPromiseUpdated, this);
33 function onPromiseUpdated(event)
35 var target = /** @type {!WebInspector.Target} */ (event.target.target());
36 var eventType = /** @type {string} */ (event.data.eventType);
37 var promise = /** @type {!DebuggerAgent.PromiseDetails} */ (event.data.promise);
39 if (typeof minPromiseId === "undefined")
40 minPromiseId = promise.id;
42 var parentId = promise.parentId ? promise.parentId - minPromiseId : undefined;
43 var promiseInfo = [];
44 promiseInfo.push("Promise (" + eventType + "):");
45 if (eventType !== "gc") {
46 promiseInfo.push("id: " + (promise.id - minPromiseId));
47 promiseInfo.push("status: " + promise.status);
48 if (parentId)
49 promiseInfo.push("parent id: " + parentId);
50 var callFrame = promise.callFrame;
51 if (callFrame) {
52 var url = WebInspector.displayNameForURL(callFrame.url);
53 promiseInfo.push(callFrame.functionName + " " + url + ":" + callFrame.lineNumber);
55 if (promise.creationTime)
56 promiseInfo.push("creationTime: " + (promise.creationTime > 0));
57 if (promise.settlementTime)
58 promiseInfo.push("settlementTime: " + (promise.settlementTime > 0));
60 InspectorTest.addResult(promiseInfo.join("\n "));
63 function step1()
65 InspectorTest.DebuggerAgent.enablePromiseTracker();
66 InspectorTest.runTestFunctionAndWaitUntilPaused(step2);
69 function step2()
71 InspectorTest.DebuggerAgent.getPromiseById(minPromiseId, "console", didGetPromiseById);
74 function didGetPromiseById(error, response)
76 if (error) {
77 InspectorTest.addResult("Failed to get promise by id: " + error);
78 InspectorTest.DebuggerAgent.disablePromiseTracker();
79 InspectorTest.completeDebuggerTest();
80 return;
82 InspectorTest.addResult("Got promise by id: " + !error);
83 InspectorTest.addResult("Resolved object class: " + response.className);
84 InspectorTest.RuntimeAgent.getProperties(response.objectId, didGetProperties);
87 function didGetProperties(error, properties, internalProperties)
89 InspectorTest.assertTrue("Received internal properties of the first promise: " + (internalProperties && internalProperties.length > 0));
91 var status, value;
92 for (var i = 0; i < internalProperties.length; i++) {
93 var property = internalProperties[i];
94 if (property.name === "[[PromiseStatus]]")
95 status = property.value.value;
96 if (property.name === "[[PromiseValue]]")
97 value = property.value.value;
100 InspectorTest.addResult("Promise:\n status: " + status + "\n value: " + value);
102 InspectorTest.DebuggerAgent.disablePromiseTracker();
103 InspectorTest.completeDebuggerTest();
107 </script>
108 </head>
110 <body onload="runTest()">
112 Tests promise tracker in debugger.
113 </p>
114 </body>
115 </html>