2011-02-17 Ilya Tikhonovsky <loislo@chromium.org>
[WebKit-https.git] / LayoutTests / http / tests / inspector / elements-test.js
index 62486179edcd678bae8d260dcfa7ddffa6cb38b5..3e7f7c38e7ef973c8b8eaf23d2930f4e0ce8f3ce 100755 (executable)
@@ -1,9 +1,5 @@
 var initialize_ElementTest = function() {
 
 var initialize_ElementTest = function() {
 
-InspectorTest.pushAllDOM = function(callback)
-{
-    InspectorTest.nodeWithId(/nonstring/, callback);
-}
 
 InspectorTest.nodeWithId = function(idValue, callback)
 {
 
 InspectorTest.nodeWithId = function(idValue, callback)
 {
@@ -37,6 +33,17 @@ InspectorTest.nodeWithId = function(idValue, callback)
     WebInspector.domAgent.getChildNodesAsync(WebInspector.domAgent.document, processChildren.bind(this, true));
 };
 
     WebInspector.domAgent.getChildNodesAsync(WebInspector.domAgent.document, processChildren.bind(this, true));
 };
 
+InspectorTest.expandedNodeWithId = function(idValue)
+{
+    var result;
+    function callback(node)
+    {
+        result = node;
+    }
+    InspectorTest.nodeWithId(idValue, callback);
+    return result;
+}
+
 InspectorTest.selectNodeWithId = function(idValue, callback)
 {
     function mycallback(node)
 InspectorTest.selectNodeWithId = function(idValue, callback)
 {
     function mycallback(node)
@@ -123,26 +130,77 @@ InspectorTest.dumpStyleTreeItem = function(treeItem, prefix, depth)
     }
 };
 
     }
 };
 
-InspectorTest.dumpElementsTree = function()
+InspectorTest.dumpElementsTree = function(rootNode)
 {
 {
+    function beautify(element)
+    {
+        return element.textContent.replace(/\u200b/g, "").replace(/\n/g, "").trim();
+    }
+
+    function print(treeItem, prefix)
+    {
+        if (treeItem.listItemElement) {
+            var expander;
+            if (treeItem.hasChildren) {
+                if (treeItem.expanded)
+                    expander = "- ";
+                else
+                    expander = "+ ";
+            } else
+                expander = "  ";
+
+            InspectorTest.addResult(prefix + expander + beautify(treeItem.listItemElement));
+        }
+        
+
+        if (!treeItem.expanded)
+            return;
+
+        var children = treeItem.children;
+        for (var i = 0; children && i < children.length - 1; ++i)
+            print(children[i], prefix + "    ");
+
+        // Closing tag.
+        if (children && children.length)
+            print(children[children.length - 1], prefix);
+    }
+
     WebInspector.panels.elements.updateModifiedNodes();
     WebInspector.panels.elements.updateModifiedNodes();
-    InspectorTest.addResult(WebInspector.panels.elements.treeOutline.element.textContent.replace(/\u200b/g, "").replace(/\n/g, "").replace(/</g, "\n<"));
+    var treeOutline = WebInspector.panels.elements.treeOutline;
+    print(rootNode ? treeOutline.findTreeElement(rootNode) : treeOutline, "");
 };
 
 };
 
-InspectorTest.dumpLoadedDOM = function()
+InspectorTest.expandElementsTree = function(callback)
 {
 {
-    function expand(treeItem, topLevel)
+    function expand(treeItem)
     {
         var children = treeItem.children;
         for (var i = 0; children && i < children.length; ++i) {
             children[i].expand();
     {
         var children = treeItem.children;
         for (var i = 0; children && i < children.length; ++i) {
             children[i].expand();
-            expand(children[i], false);
+            expand(children[i]);
         }
         }
-        if (topLevel)
-            InspectorTest.dumpElementsTree();
     }
     }
-    WebInspector.panels.elements.updateModifiedNodes();
-    expand(WebInspector.panels.elements.treeOutline, true);
+
+    function mycallback()
+    {
+        WebInspector.panels.elements.updateModifiedNodes();
+        expand(WebInspector.panels.elements.treeOutline);
+        if (callback)
+            callback();
+    }
+    InspectorTest.nodeWithId(/nonstring/, mycallback);
+};
+
+InspectorTest.dumpDOMAgentTree = function()
+{
+    function dump(node, prefix, startIndex)
+    {
+        InspectorTest.addResult(prefix + node.nodeName + "[" + (node.id - startIndex)+ "]");
+        var children = node.children;
+        for (var i = 0; children && i < children.length; ++i)
+            dump(children[i], prefix + "    ", startIndex);
+    }
+    dump(WebInspector.domAgent.document, "", WebInspector.domAgent.document.id - 1);
 };
 
 };
\ No newline at end of file
 };
 
 };
\ No newline at end of file