3 <script src=
"../../../http/tests/inspector/inspector-test.js"></script>
4 <script src=
"../../../http/tests/inspector/debugger-test.js"></script>
8 function testFunction()
10 promise
= new Promise(function promiseConstructor(resolve
, reject
) {
14 .then(thenCallback
, errorCallback
)
15 .then(thenCallback2
, errorCallback
);
18 function thenCallback() { }
20 function thenCallback2()
25 function errorCallback() { }
27 var test = function ()
29 InspectorTest
.startDebuggerTest(step1
);
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;
44 promiseInfo
.push("Promise (" + eventType
+ "):");
45 if (eventType
!== "gc") {
46 promiseInfo
.push("id: " + (promise
.id
- minPromiseId
));
47 promiseInfo
.push("status: " + promise
.status
);
49 promiseInfo
.push("parent id: " + parentId
);
50 var callFrame
= promise
.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 "));
65 InspectorTest
.DebuggerAgent
.enablePromiseTracker();
66 InspectorTest
.runTestFunctionAndWaitUntilPaused(step2
);
71 InspectorTest
.DebuggerAgent
.getPromiseById(minPromiseId
, "console", didGetPromiseById
);
74 function didGetPromiseById(error
, response
)
77 InspectorTest
.addResult("Failed to get promise by id: " + error
);
78 InspectorTest
.DebuggerAgent
.disablePromiseTracker();
79 InspectorTest
.completeDebuggerTest();
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));
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();
110 <body onload=
"runTest()">
112 Tests promise tracker in debugger.