2010-05-03 Abhishek Arya <inferno@chromium.org>
[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_expandNode", nodeExpandedCallback);
59     }
60
61     evaluateInWebInspector("frontend_loadDOM", domLoadedCallback);
62 }
63
64
65 // Frontend functions.
66
67 function frontend_showAll(testController)
68 {
69     try {
70         var dataDivTreeElement = frontend_getDataTreeElement();
71         if (!dataDivTreeElement) {
72             testController.notifyDone("show_All: No data div tree element found");
73             return;
74         }
75         window.__oldUpdateChildren = WebInspector.ElementsTreeElement.prototype._updateChildren;
76         window.__newUpdateChildren = function() {
77             window.__oldUpdateChildren.apply(this, arguments);
78             WebInspector.ElementsTreeElement.prototype._updateChildren = window.__oldUpdateChildren;
79             testController.notifyDone("");
80         }
81         WebInspector.ElementsTreeElement.prototype._updateChildren = window.__newUpdateChildren;
82
83         WebInspector.ElementsTreeElement.prototype.handleLoadAllChildren.call(dataDivTreeElement);
84         testController.waitUntilDone();
85     } catch(e) {
86         testController.notifyDone("showAll: " + e);
87     }
88 }
89
90 function frontend_dumpNode(testController)
91 {
92     testController.waitUntilDone();
93     function dumpFunction()
94     {
95         var dataDivTreeElement = frontend_getDataTreeElement();
96         if (!dataDivTreeElement) {
97             testController.notifyDone("dumpNode: No data div tree element found");
98             return;
99         }
100
101         var liContent = dataDivTreeElement.listItemElement ? dataDivTreeElement.listItemElement.textContent : "{EMPTY}";
102         var childrenContent = dataDivTreeElement.childrenListElement ? dataDivTreeElement.childrenListElement.textContent : "{EMPTY}";
103         testController.notifyDone(liContent + "/" + childrenContent);
104     }
105     // Ensure all asynchronous updates to the Elements tree outline are processed before dumping.
106     setTimeout(dumpFunction, 0);
107 }
108
109 function frontend_expandNode(testController)
110 {
111     var dataDivTreeElement = frontend_getDataTreeElement();
112     if (!dataDivTreeElement) {
113         testController.notifyDone("No data div tree element found");
114         return;
115     }
116
117     try {
118         dataDivTreeElement._expandedChildrenLimit = 5;
119         dataDivTreeElement.reveal();
120         dataDivTreeElement.expand();
121         testController.notifyDone("");
122     } catch(e) {
123         testController.notifyDone("expandNode: " + e);
124     }
125 }
126
127 function frontend_loadDOM(testController)
128 {
129     testController.waitUntilDone();
130     // Need test to be async to expand whole the tree first.
131     try {
132         frontend_expandDOMSubtree(WebInspector.domAgent.document);
133         testController.runAfterPendingDispatches(function() {
134             testController.notifyDone("");
135         });
136     } catch(e) {
137         testController.notifyDone("loadDOM: " + e);
138     }
139 }
140
141 function frontend_getDataTreeElement()
142 {
143     var node = frontend_getDataDOMElement();
144     if (!node)
145         return null;
146     return WebInspector.panels.elements.treeOutline.createTreeElementFor(node);
147 }
148
149
150 function frontend_getDataDOMElement()
151 {
152     var innerMapping = WebInspector.domAgent._idToDOMNode;
153
154     for (var nodeId in innerMapping) {
155         var node = innerMapping[nodeId];
156         if (node.nodeName === "DIV" || node.getAttribute("id") === "data")
157             return node;
158     }
159     return null;
160 }
161 </script>
162 </head>
163
164 <body onload="onload()">
165 <div id="data">
166 <div id="id1">1</div>
167 <div id="id2">2</div>
168 <div id="id3">3</div>
169 <div id="id4">4</div>
170 <div id="id5">5</div>
171 <div id="id6">6</div>
172 <div id="id7">7</div>
173 <div id="id8">8</div>
174 <div id="id9">9</div>
175 <div id="id10">10</div>
176 </div>
177 <p>
178 Tests that src and href element targets are rewritten properly.
179 </p>
180 <pre id="outputPre">
181 </pre>
182 </body>
183 </html>