Title: [145364] trunk/LayoutTests
Revision
145364
Author
[email protected]
Date
2013-03-11 08:31:36 -0700 (Mon, 11 Mar 2013)

Log Message

(tests) make nodesFromRect.js print a list of nodes that were found
https://bugs.webkit.org/show_bug.cgi?id=111793

Patch by Christian Biesinger <[email protected]> on 2013-03-11
Reviewed by Allan Sandfeld Jensen.

* fast/dom/nodesFromRect/resources/nodesFromRect.js:
(nodeToString):
(nodeListToString):
(check):
(nodesFromRectAsString):
Move node prettyprinting code from nodesFromRectAsString to new
functions nodeToString and nodeListToString, and make use of it in
check().
I've also converted the nodeType checks to use the constants on Node
instead of using magic numbers.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (145363 => 145364)


--- trunk/LayoutTests/ChangeLog	2013-03-11 15:26:17 UTC (rev 145363)
+++ trunk/LayoutTests/ChangeLog	2013-03-11 15:31:36 UTC (rev 145364)
@@ -1,3 +1,21 @@
+2013-03-11  Christian Biesinger  <[email protected]>
+
+        (tests) make nodesFromRect.js print a list of nodes that were found
+        https://bugs.webkit.org/show_bug.cgi?id=111793
+
+        Reviewed by Allan Sandfeld Jensen.
+
+        * fast/dom/nodesFromRect/resources/nodesFromRect.js:
+        (nodeToString):
+        (nodeListToString):
+        (check):
+        (nodesFromRectAsString):
+        Move node prettyprinting code from nodesFromRectAsString to new
+        functions nodeToString and nodeListToString, and make use of it in
+        check().
+        I've also converted the nodeType checks to use the constants on Node
+        instead of using magic numbers.
+
 2013-03-11  Kent Tamura  <[email protected]>
 
         Inappropriate validation message for required number/date input elements

Modified: trunk/LayoutTests/fast/dom/nodesFromRect/resources/nodesFromRect.js (145363 => 145364)


--- trunk/LayoutTests/fast/dom/nodesFromRect/resources/nodesFromRect.js	2013-03-11 15:26:17 UTC (rev 145363)
+++ trunk/LayoutTests/fast/dom/nodesFromRect/resources/nodesFromRect.js	2013-03-11 15:31:36 UTC (rev 145364)
@@ -4,6 +4,36 @@
  *     * Allan Sandfeld Jensen <[email protected]>
 **/
 
+function nodeToString(node) {
+    var str = "";
+    if (node.nodeType == Node.ELEMENT_NODE) {
+        str += node.nodeName;
+        if (node.id)
+            str += '#' + node.id;
+        else if (node.class)
+            str += '.' + node.class;
+    } else if (node.nodeType == Node.TEXT_NODE) {
+        str += "'" + node.data + "'";
+    } else if (node.nodeType == Node.DOCUMENT_NODE) {
+        str += "#document";
+    }
+    return str;
+}
+
+function nodeListToString(nodes) {
+    var nodeString = "";
+
+    for (var i = 0; i < nodes.length; i++) {
+        var str = nodeToString(nodes[i]);
+        if (!str)
+            continue;
+        nodeString += str;
+        if (i + 1 < nodes.length)
+            nodeString += ", ";
+    }
+    return nodeString;
+}
+
 function check(x, y, topPadding, rightPadding, bottomPadding, leftPadding, list, doc)
 {
   if (!window.internals)
@@ -21,7 +51,8 @@
               "[" + x + "," + y + "], " +
               "[" + topPadding + "," + rightPadding +
               "," + bottomPadding + "," + leftPadding +
-              "]: '" + list.length + "' vs '" + nodes.length + "'");
+              "]: '" + list.length + "' vs '" + nodes.length +
+              "', found: " + nodeListToString(nodes));
     return;
   }
 
@@ -30,7 +61,8 @@
       testFailed("Unexpected node #" + i + " for rect " +
                 "[" + x + "," + y + "], " +
                 "[" + topPadding + "," + rightPadding +
-                "," + bottomPadding + "," + leftPadding + "]" + " - " + nodes[i]);
+                "," + bottomPadding + "," + leftPadding + "]" +
+                " - " + nodeToString(nodes[i]));
       return;
     }
   }
@@ -113,31 +145,11 @@
 
 function nodesFromRectAsString(doc, x, y, topPadding, rightPadding, bottomPadding, leftPadding)
 {
-    var nodeString = "";
     var nodes = internals.nodesFromRect(doc, x, y, topPadding, rightPadding, bottomPadding, leftPadding, true /* ignoreClipping */, false /* allow shadow content */, true /* allow child-frame content */);
     if (!nodes)
-        return nodeString;
+        return "";
 
-    for (var i = 0; i < nodes.length; i++) {
-        if (nodes[i].nodeType == 1) {
-            nodeString += nodes[i].nodeName;
-            if (nodes[i].id)
-                nodeString += '#' + nodes[i].id;
-            else if (nodes[i].class) {
-                nodeString += '.' + nodes[i].class;
-            }
-        } else if (nodes[i].nodeType == 3) {
-            nodeString += "'" + nodes[i].data + "'";
-        } else if (nodes[i].nodeType == 9) {
-            nodeString += "#document";
-        } else {
-            continue;
-        }
-        if (i + 1 < nodes.length) {
-            nodeString += ", ";
-        }
-    }
-    return nodeString;
+    return nodeListToString(nodes);
 }
 
 function getCenterFor(element)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to