Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / inspector / elements / elements-panel-selection-after-delete.html
blob63c041e6384f18ea8bfa79d01ba012b9555715ec
1 <html>
2 <head>
3 <script src="../../http/tests/inspector/inspector-test.js"></script>
4 <script src="../../http/tests/inspector/elements-test.js"></script>
5 <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));
15 function test()
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)
30 if (!node)
31 return "null"
32 var result = "<" + node.nodeName();
33 var attributes = node.attributes();
34 for (var attribute of attributes) {
35 result += " " + attribute.name;
36 if (attribute.value)
37 result += "=\"" + attribute.value + "\"";
39 result += ">";
40 return result;
43 function prepareTestTree(callback)
45 InspectorTest.evaluateInPage("prepareTestTree()", callback);
48 function removeElementAsUser(element, callback)
50 InspectorTest.addSniffer(WebInspector.ElementsTreeOutline.prototype, "_updateModifiedNodes", callback);
51 element.remove();
54 function removeElementExternally(element, callback)
56 var node = element.node();
57 InspectorTest.addSniffer(WebInspector.ElementsTreeOutline.prototype, "_updateChildren", callback);
58 node.removeNode();
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);
73 function step2()
75 InspectorTest.addResult("Selecting node...");
76 selectNode("child2", step3);
79 function step3()
81 dumpSelectedNode();
83 InspectorTest.addResult("Deleting selected node like it was a user action...");
84 var selectedElement = InspectorTest.firstElementsTreeOutline().selectedTreeElement;
85 removeElementAsUser(selectedElement, step4);
88 function step4()
90 dumpSelectedNode();
92 InspectorTest.addResult("Deleting selected node like it was a user action again...");
93 var selectedElement = InspectorTest.firstElementsTreeOutline().selectedTreeElement;
94 removeElementAsUser(selectedElement, step5);
97 function step5()
99 dumpSelectedNode();
101 InspectorTest.addResult("Deleting last child like it was a user action...");
102 var selectedElement = InspectorTest.firstElementsTreeOutline().selectedTreeElement;
103 removeElementAsUser(selectedElement, step6);
106 function step6()
108 dumpSelectedNode();
109 next();
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);
117 prepareTestTree();
119 function step2()
121 InspectorTest.addResult("Selecting node...");
122 selectNode("child2", step3);
125 function step3()
127 dumpSelectedNode();
129 InspectorTest.addResult("Deleting selected node externally...");
130 var selectedElement = InspectorTest.firstElementsTreeOutline().selectedTreeElement;
131 removeElementExternally(selectedElement, step4);
134 function step4()
136 dumpSelectedNode();
138 InspectorTest.addResult("Deleting selected node externally again...");
139 var selectedElement = InspectorTest.firstElementsTreeOutline().selectedTreeElement;
140 removeElementExternally(selectedElement, step5);
143 function step5()
145 dumpSelectedNode();
147 InspectorTest.addResult("Deleting last child externally...");
148 var selectedElement = InspectorTest.firstElementsTreeOutline().selectedTreeElement;
149 removeElementExternally(selectedElement, step6);
152 function step6()
154 dumpSelectedNode();
155 next();
161 </script>
162 </head>
163 <body onload="runTest()">
164 <p>Tests that elements panel correctly updates selection on node removal.</p>
165 <template id="testTree">
166 <div class="left">
167 <div class="child1">
168 </div>
169 <div class="child2">
170 <div class="child5">
171 </div>
172 <div class="child6">
173 </div>
174 <div class="child7">
175 </div>
176 <div class="child8">
177 </div>
178 </div>
179 <div class="child3">
180 </div>
181 </div>
182 </template>
183 <div id="testTreeContainer">
184 </div>
185 </body>
186 </html>