1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Test that we can get the list of dependent promises from the ObjectClient.
*/
"use strict";
const { PromisesFront } = require("devtools/shared/fronts/promises");
var events = require("sdk/event/core");
add_task(function* () {
let client = yield startTestDebuggerServer("test-promises-dependentpromises");
let chromeActors = yield getChromeActors(client);
yield attachTab(client, chromeActors);
ok(Promise.toString().includes("native code"), "Expect native DOM Promise.");
yield testGetDependentPromises(client, chromeActors, () => {
let p = new Promise(() => {});
p.name = "p";
let q = p.then();
q.name = "q";
let r = p.then(null, () => {});
r.name = "r";
return p;
});
let response = yield listTabs(client);
let targetTab = findTab(response.tabs, "test-promises-dependentpromises");
ok(targetTab, "Found our target tab.");
yield attachTab(client, targetTab);
yield testGetDependentPromises(client, targetTab, () => {
const debuggee =
DebuggerServer.getTestGlobal("test-promises-dependentpromises");
let p = new debuggee.Promise(() => {});
p.name = "p";
let q = p.then();
q.name = "q";
let r = p.then(null, () => {});
r.name = "r";
return p;
});
yield close(client);
});
function* testGetDependentPromises(client, form, makePromises) {
let front = PromisesFront(client, form);
yield front.attach();
yield front.listPromises();
// Get the grip for promise p
let onNewPromise = new Promise(resolve => {
events.on(front, "new-promises", promises => {
for (let p of promises) {
if (p.preview.ownProperties.name &&
p.preview.ownProperties.name.value === "p") {
resolve(p);
}
}
});
});
let promise = makePromises();
let grip = yield onNewPromise;
ok(grip, "Found our promise p.");
let objectClient = new ObjectClient(client, grip);
ok(objectClient, "Got Object Client.");
// Get the dependent promises for promise p and assert that the list of
// dependent promises is correct
yield new Promise(resolve => {
objectClient.getDependentPromises(response => {
let dependentNames = response.promises.map(p =>
p.preview.ownProperties.name.value);
let expectedDependentNames = ["q", "r"];
equal(dependentNames.length, expectedDependentNames.length,
"Got expected number of dependent promises.");
for (let i = 0; i < dependentNames.length; i++) {
equal(dependentNames[i], expectedDependentNames[i],
"Got expected dependent name.");
}
for (let p of response.promises) {
equal(p.type, "object", "Expect type to be Object.");
equal(p.class, "Promise", "Expect class to be Promise.");
equal(typeof p.promiseState.creationTimestamp, "number",
"Expect creation timestamp to be a number.");
ok(!p.promiseState.timeToSettle,
"Expect time to settle to be undefined.");
}
resolve();
});
});
yield front.detach();
// Appease eslint
void promise;
}
|