2010-08-09 Ilya Tikhonovsky <loislo@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_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     WebInspector.showPanel("elements");
129     testController.waitUntilDone();
130     // Need test to be async to expand whole the tree first.
131     try {
132         frontend_expandDOMSubtreeAndRun(testController, null, testController.notifyDone.bind(testController, ""));
133     } catch(e) {
134         testController.notifyDone("loadDOM: " + e);
135     }
136 }
137
138 function frontend_getDataTreeElement()
139 {
140     var node = frontend_getDataDOMElement();
141     if (!node)
142         return null;
143     return WebInspector.panels.elements.treeOutline.findTreeElement(node);
144 }
145
146
147 function frontend_getDataDOMElement()
148 {
149     var innerMapping = WebInspector.domAgent._idToDOMNode;
150
151     for (var nodeId in innerMapping) {
152         var node = innerMapping[nodeId];
153         if (node.nodeName === "DIV" && node.getAttribute("id") === "data")
154             return node;
155     }
156     return null;
157 }
158 </script>
159 </head>
160
161 <body onload="onload()">
162 <div id="data">
163 <div id="id1">1</div>
164 <div id="id2">2</div>
165 <div id="id3">3</div>
166 <div id="id4">4</div>
167 <div id="id5">5</div>
168 <div id="id6">6</div>
169 <div id="id7">7</div>
170 <div id="id8">8</div>
171 <div id="id9">9</div>
172 <div id="id10">10</div>
173 </div>
174 <p>
175 Tests that src and href element targets are rewritten properly.
176 </p>
177 <pre id="outputPre">
178 </pre>
179 </body>
180 </html>