-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
attachedNodes.html
132 lines (113 loc) · 4.17 KB
/
attachedNodes.html
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<!doctype html>
<html>
<head>
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script>
function createDetachedNode()
{
window.__testDetachedNode = document.createElement("div");
window.__testDetachedNode.id = "script-created-node";
return window.__testDetachedNode;
}
function insertDetachedNode()
{
let parentElement = document.getElementById("a");
parentElement.insertBefore(window.__testDetachedNode, parentElement.firstChild);
}
function removePreviouslyDetachedNode()
{
window.__testDetachedNode.remove();
}
function test()
{
let suite = InspectorTest.createAsyncSuite("DOM.attachedNodes");
async function ensureDocumentSubtree() {
let documentNode = await WI.domManager.requestDocument();
const entireSubtreeDepth = -1;
await WI.assumingMainTarget().DOMAgent.requestChildNodes(documentNode.id, entireSubtreeDepth);
}
function logNodes(nodesIterator) {
InspectorTest.log("Dumping nodes:")
for (let node of nodesIterator) {
// Each test adds more content to the DOM tree, but we don't want to clutter test output with those.
if (node.escapedIdSelector === "#end-of-prewritten-test-content")
break;
logNode(node);
}
}
function logNode(node) {
if (node.nodeType() === Node.TEXT_NODE)
InspectorTest.log(" [text node]");
else
InspectorTest.log(" " + node.unescapedSelector);
}
suite.addTestCase({
name: "DOM.attachedNodes.Unfiltered",
description: "Ensure that `attachedNodes` provides a correctly ordered list of all attached DOM nodes.",
async test() {
await ensureDocumentSubtree();
logNodes(WI.domManager.attachedNodes());
}
});
suite.addTestCase({
name: "DOM.attachedNodes.Filtered",
description: "Ensure that `attachedNodes` correctly filters nodes.",
async test() {
await ensureDocumentSubtree();
logNodes(WI.domManager.attachedNodes({filter: (node) => node.nodeNameInCorrectCase() === "div"}));
}
});
suite.addTestCase({
name: "DOM.attachedNodes.DetachedNode",
description: "Ensure that `attachedNodes` provides a correctly ordered list of all attached DOM nodes, and ignored detached nodes that are known to the backend.",
async test() {
await ensureDocumentSubtree();
InspectorTest.log("Creating detached node...");
let detachedNodeRemoteObject = await InspectorTest.evaluateInPage(`createDetachedNode()`);
let detachedNodeId = (await WI.assumingMainTarget().DOMAgent.requestNode(detachedNodeRemoteObject.objectId)).nodeId;
let detachedNode = WI.domManager.nodeForId(detachedNodeId);
InspectorTest.log("Created detached node: " + detachedNode.unescapedSelector);
logNodes(WI.domManager.attachedNodes());
InspectorTest.log("Attaching node to DOM tree...");
await Promise.all([
InspectorTest.evaluateInPage(`insertDetachedNode()`),
WI.domManager.awaitEvent(WI.DOMManager.Event.NodeInserted),
]);
InspectorTest.log("DOM node attached to tree.");
logNodes(WI.domManager.attachedNodes());
InspectorTest.log("Detaching node from DOM tree...");
await Promise.all([
InspectorTest.evaluateInPage(`removePreviouslyDetachedNode()`),
WI.domManager.awaitEvent(WI.DOMManager.Event.NodeRemoved),
]);
InspectorTest.log("DOM node detached from tree.");
logNodes(WI.domManager.attachedNodes());
}
});
suite.runTestCasesAndFinish();
}
</script>
<style>
#a::before {
content: "before";
}
#a::after {
content: "after";
}
</style>
</head>
<body onload="runTest()">
<p id="test-description">Tests for the DOMManager.attachedNodes.</p>
<div id="a">
<div id="a1"></div>
<div id="a2"></div>
<div id="a3"></div>
</div>
<div id="b">
<div id="b1"></div>
<div id="b2"></div>
<div id="b3"></div>
</div>
<div id="end-of-prewritten-test-content"></div>
</body>
</html>