2011-01-26 Martin Robinson <mrobinson@igalia.com>
[WebKit-https.git] / LayoutTests / inspector / elements-panel-limited-children.html
1 <html>
2 <head>
3 <script src="../http/tests/inspector/inspector-test.js"></script>
4 <script src="elements-tests.js"></script>
5 <script>
6
7 function doit()
8 {
9     function preOutput(result)
10     {
11         var output = document.getElementById("outputPre");
12         output.textContent += result.replace(/\u200b/g, "").replace(/\n/g, "").replace(/</g, "\n<");
13     }
14
15     function nodeDumpAfterCallback(dump)
16     {
17         preOutput(dump);
18         notifyDone();
19     }
20
21     function showAllCallback(result)
22     {
23         if (result) {
24             preOutput(result);
25             notifyDone();
26         }
27         evaluateInWebInspector("frontend_dumpNode", nodeDumpAfterCallback);
28     }
29
30     function nodeDumpBeforeCallback(dump)
31     {
32         preOutput(dump);
33         evaluateInWebInspector("frontend_showAll", showAllCallback);
34     }
35
36     function nodeExpandedCallback(result)
37     {
38         if (result) {
39             preOutput(result);
40             notifyDone();
41         }
42         var dataElement = document.getElementById("data");
43         dataElement.appendChild(document.createElement("a"));
44         dataElement.removeChild(document.getElementById("id2"));
45         var aElement = document.createElement("a");
46         dataElement.insertBefore(aElement, document.getElementById("id1"));
47         dataElement.appendChild(aElement);
48         dataElement.insertBefore(aElement, document.getElementById("id1"));
49         evaluateInWebInspector("frontend_dumpNode", nodeDumpBeforeCallback);
50     }
51
52     function domLoadedCallback(result)
53     {
54         if (result) {
55             preOutput(result);
56             notifyDone();
57         }
58         evaluateInWebInspector("frontend_revealAndExpandDataNodeInElementsPanel", nodeExpandedCallback);
59     }
60
61     evaluateInWebInspector("frontend_loadDOM", domLoadedCallback);
62 }
63
64 // Frontend functions.
65
66 function frontend_showAll(testController)
67 {
68     try {
69         var dataDivTreeElement = frontend_getDataTreeElement();
70         if (!dataDivTreeElement) {
71             testController.notifyDone("show_All: No data div tree element found");
72             return;
73         }
74         window.__oldUpdateChildren = WebInspector.ElementsTreeElement.prototype._updateChildren;
75         window.__newUpdateChildren = function() {
76             window.__oldUpdateChildren.apply(this, arguments);
77             WebInspector.ElementsTreeElement.prototype._updateChildren = window.__oldUpdateChildren;
78             testController.notifyDone("");
79         }
80         WebInspector.ElementsTreeElement.prototype._updateChildren = window.__newUpdateChildren;
81
82         WebInspector.ElementsTreeElement.prototype.handleLoadAllChildren.call(dataDivTreeElement);
83         testController.waitUntilDone();
84     } catch(e) {
85         testController.notifyDone("showAll: " + e);
86     }
87 }
88
89 function frontend_dumpNode(testController)
90 {
91     testController.waitUntilDone();
92     function dumpFunction()
93     {
94         var dataDivTreeElement = frontend_getDataTreeElement();
95         if (!dataDivTreeElement) {
96             testController.notifyDone("dumpNode: No data div tree element found");
97             return;
98         }
99
100         var liContent = dataDivTreeElement.listItemElement ? dataDivTreeElement.listItemElement.textContent : "{EMPTY}";
101         var childrenContent = dataDivTreeElement.childrenListElement ? dataDivTreeElement.childrenListElement.textContent : "{EMPTY}";
102         testController.notifyDone(liContent + "/" + childrenContent);
103     }
104     // Ensure all asynchronous updates to the Elements tree outline are processed before dumping.
105     setTimeout(dumpFunction, 0);
106 }
107
108 function frontend_revealAndExpandDataNodeInElementsPanel(testController)
109 {
110     var dataDivTreeElement = frontend_getDataTreeElement();
111     if (!dataDivTreeElement) {
112         testController.notifyDone("No data div tree element found");
113         return;
114     }
115
116     try {
117         dataDivTreeElement._expandedChildrenLimit = 5;
118         dataDivTreeElement.reveal();
119         dataDivTreeElement.expand();
120         testController.notifyDone("");
121     } catch(e) {
122         testController.notifyDone("expandNode: " + e);
123     }
124 }
125
126 function frontend_loadDOM(testController)
127 {
128     testController.waitUntilDone();
129     // Need test to be async to expand whole the tree first.
130     try {
131         frontend_expandDOMSubtreeAndRun(testController, null, testController.notifyDone.bind(testController, ""));
132     } catch(e) {
133         testController.notifyDone("loadDOM: " + e);
134     }
135 }
136
137 function frontend_getDataTreeElement()
138 {
139     var node = frontend_getDataDOMElement();
140     if (!node)
141         return null;
142     return WebInspector.panels.elements.treeOutline.findTreeElement(node);
143 }
144
145
146 function frontend_getDataDOMElement()
147 {
148     var innerMapping = WebInspector.domAgent._idToDOMNode;
149
150     for (var nodeId in innerMapping) {
151         var node = innerMapping[nodeId];
152         if (node.nodeName === "DIV" && node.getAttribute("id") === "data")
153             return node;
154     }
155     return null;
156 }
157 </script>
158 </head>
159
160 <body onload="onload()">
161 <div id="data">
162 <div id="id1">1</div>
163 <div id="id2">2</div>
164 <div id="id3">3</div>
165 <div id="id4">4</div>
166 <div id="id5">5</div>
167 <div id="id6">6</div>
168 <div id="id7">7</div>
169 <div id="id8">8</div>
170 <div id="id9">9</div>
171 <div id="id10">10</div>
172 </div>
173 <p>
174 Tests that src and href element targets are rewritten properly.
175 </p>
176 <pre id="outputPre">
177 </pre>
178 </body>
179 </html>