3 <script src=
"../../http/tests/inspector/inspector-test.js"></script>
4 <script src=
"../../http/tests/inspector/elements-test.js"></script>
7 function prepareTestTree()
9 var template
= document
.querySelector("#testTree");
10 var testTreeContainer
= document
.querySelector("#testTreeContainer");
11 testTreeContainer
.textContent
= "";
12 testTreeContainer
.appendChild(document
.importNode(template
.content
, true));
17 function selectNode(className
, callback
)
19 var selector
= "#testTreeContainer ." + className
;
20 InspectorTest
.querySelector(selector
, gotNode
);
22 function gotNode(node
)
24 InspectorTest
.selectNode(node
).then(callback
);
28 function nodeToString(node
)
32 var result
= "<" + node
.nodeName();
33 var attributes
= node
.attributes();
34 for (var attribute
of attributes
) {
35 result
+= " " + attribute
.name
;
37 result
+= "=\"" + attribute
.value
+ "\"";
43 function prepareTestTree(callback
)
45 InspectorTest
.evaluateInPage("prepareTestTree()", callback
);
48 function removeElementAsUser(element
, callback
)
50 InspectorTest
.addSniffer(WebInspector
.ElementsTreeOutline
.prototype, "_updateModifiedNodes", callback
);
54 function removeElementExternally(element
, callback
)
56 var node
= element
.node();
57 InspectorTest
.addSniffer(WebInspector
.ElementsTreeOutline
.prototype, "_updateChildren", callback
);
61 function dumpSelectedNode()
63 var selectedElement
= InspectorTest
.firstElementsTreeOutline().selectedTreeElement
;
64 var selectedNode
= selectedElement
? selectedElement
.node() : null;
65 InspectorTest
.addResult("The following node is now selected: " + nodeToString(selectedNode
));
68 InspectorTest
.runTestSuite([
69 function testUserDelete(next
)
71 prepareTestTree(step2
);
75 InspectorTest
.addResult("Selecting node...");
76 selectNode("child2", step3
);
83 InspectorTest
.addResult("Deleting selected node like it was a user action...");
84 var selectedElement
= InspectorTest
.firstElementsTreeOutline().selectedTreeElement
;
85 removeElementAsUser(selectedElement
, step4
);
92 InspectorTest
.addResult("Deleting selected node like it was a user action again...");
93 var selectedElement
= InspectorTest
.firstElementsTreeOutline().selectedTreeElement
;
94 removeElementAsUser(selectedElement
, step5
);
101 InspectorTest
.addResult("Deleting last child like it was a user action...");
102 var selectedElement
= InspectorTest
.firstElementsTreeOutline().selectedTreeElement
;
103 removeElementAsUser(selectedElement
, step6
);
113 function testExternalDelete(next
)
115 // We should wait for container node to be updated since it is already populated.
116 InspectorTest
.addSniffer(WebInspector
.ElementsTreeOutline
.prototype, "_updateModifiedNodes", step2
);
121 InspectorTest
.addResult("Selecting node...");
122 selectNode("child2", step3
);
129 InspectorTest
.addResult("Deleting selected node externally...");
130 var selectedElement
= InspectorTest
.firstElementsTreeOutline().selectedTreeElement
;
131 removeElementExternally(selectedElement
, step4
);
138 InspectorTest
.addResult("Deleting selected node externally again...");
139 var selectedElement
= InspectorTest
.firstElementsTreeOutline().selectedTreeElement
;
140 removeElementExternally(selectedElement
, step5
);
147 InspectorTest
.addResult("Deleting last child externally...");
148 var selectedElement
= InspectorTest
.firstElementsTreeOutline().selectedTreeElement
;
149 removeElementExternally(selectedElement
, step6
);
163 <body onload=
"runTest()">
164 <p>Tests that elements panel correctly updates selection on node removal.
</p>
165 <template id=
"testTree">
183 <div id=
"testTreeContainer">