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
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Check evaluating and expanding promises in the console.
const TEST_URI =
"data:text/html;charset=utf8,<!DOCTYPE html>" +
"<h1>Object Inspector on deeply nested promises</h1>";
add_task(async function testExpandNestedPromise() {
const hud = await openNewTabAndConsole(TEST_URI);
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
let nestedPromise = Promise.resolve({});
for (let i = 5; i > 0; --i) {
nestedPromise[i] = i;
Object.setPrototypeOf(nestedPromise, null);
nestedPromise = Promise.resolve(nestedPromise);
}
nestedPromise[0] = 0;
content.wrappedJSObject.console.log("oi-test", nestedPromise);
});
const node = await waitFor(() => findConsoleAPIMessage(hud, "oi-test"));
const oi = node.querySelector(".tree");
const [promiseNode] = getObjectInspectorNodes(oi);
expandObjectInspectorNode(promiseNode);
await waitFor(() => getObjectInspectorNodes(oi).length > 1);
checkChildren(promiseNode, [`0`, `<state>`, `<value>`, `<prototype>`]);
const valueNode = findObjectInspectorNode(oi, "<value>");
expandObjectInspectorNode(valueNode);
await waitFor(() => !!getObjectInspectorChildrenNodes(valueNode).length);
checkChildren(valueNode, [`1`, `<state>`, `<value>`]);
});
add_task(async function testExpandCyclicPromise() {
const hud = await openNewTabAndConsole(TEST_URI);
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
let resolve;
const cyclicPromise = new Promise(r => {
resolve = r;
});
Object.setPrototypeOf(cyclicPromise, null);
cyclicPromise.foo = "foo";
const otherPromise = Promise.reject(cyclicPromise);
otherPromise.catch(() => {});
Object.setPrototypeOf(otherPromise, null);
otherPromise.bar = "bar";
resolve(otherPromise);
content.wrappedJSObject.console.log("oi-test", cyclicPromise);
});
const node = await waitFor(() => findConsoleAPIMessage(hud, "oi-test"));
const oi = node.querySelector(".tree");
const [promiseNode] = getObjectInspectorNodes(oi);
expandObjectInspectorNode(promiseNode);
await waitFor(() => getObjectInspectorNodes(oi).length > 1);
checkChildren(promiseNode, [`foo`, `<state>`, `<value>`]);
const valueNode = findObjectInspectorNode(oi, "<value>");
expandObjectInspectorNode(valueNode);
await waitFor(() => !!getObjectInspectorChildrenNodes(valueNode).length);
checkChildren(valueNode, [`bar`, `<state>`, `<reason>`]);
const reasonNode = findObjectInspectorNode(oi, "<reason>");
expandObjectInspectorNode(reasonNode);
await waitFor(() => !!getObjectInspectorChildrenNodes(reasonNode).length);
checkChildren(reasonNode, [`foo`, `<state>`, `<value>`]);
});
function checkChildren(node, expectedChildren) {
const children = getObjectInspectorChildrenNodes(node);
is(
children.length,
expectedChildren.length,
"There is the expected number of children"
);
children.forEach((child, index) => {
is(
child.querySelector(".object-label").textContent,
expectedChildren[index],
`Found correct child at index ${index}`
);
});
}
|