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
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
// Check that the inspect() jsterm helper function works.
"use strict";
const TEST_URI =
"data:text/html;charset=utf8,<!DOCTYPE html><p>test inspect() command";
add_task(async function () {
const hud = await openNewTabAndConsole(TEST_URI);
info("Test `inspect(window)`");
// Add a global value so we can check it later.
await executeAndWaitForResultMessage(
hud,
"testProp = 'testValue'",
"testValue"
);
const { node: inspectWindowNode } = await executeAndWaitForResultMessage(
hud,
"inspect(window)",
"Window"
);
const objectInspectors = [...inspectWindowNode.querySelectorAll(".tree")];
is(
objectInspectors.length,
1,
"There is the expected number of object inspectors"
);
const [windowOi] = objectInspectors;
let windowOiNodes = windowOi.querySelectorAll(".node");
// The tree can be collapsed since the properties are fetched asynchronously.
if (windowOiNodes.length === 1) {
// If this is the case, we wait for the properties to be fetched and displayed.
await waitForNodeMutation(windowOi, {
childList: true,
});
windowOiNodes = windowOi.querySelectorAll(".node");
}
const propertiesNodes = [...windowOi.querySelectorAll(".object-label")];
const testPropertyLabelNode = propertiesNodes.find(
el => el.textContent === "testProp"
);
ok(
testPropertyLabelNode,
"The testProp property label is displayed as expected"
);
const testPropertyValueNode = testPropertyLabelNode
.closest(".node")
.querySelector(".objectBox");
is(
testPropertyValueNode.textContent,
'"testValue"',
"The testProp property value is displayed as expected"
);
/* Check that a primitive value can be inspected, too */
info("Test `inspect(1)`");
execute(hud, "inspect(1)");
const inspectPrimitiveNode = await waitFor(() =>
findInspectResultMessage(hud.ui.outputNode, 2)
);
is(
parseInt(inspectPrimitiveNode.textContent, 10),
1,
"The primitive is displayed as expected"
);
});
function findInspectResultMessage(node, index) {
return node.querySelectorAll(".message.result")[index];
}
|