Title: [148973] trunk/LayoutTests
Revision
148973
Author
[email protected]
Date
2013-04-23 10:50:01 -0700 (Tue, 23 Apr 2013)

Log Message

checkLayout() should error out if no data-expected* attributes were found
https://bugs.webkit.org/show_bug.cgi?id=114900

Reviewed by Ojan Vafai.

If checkLayout() doesn't find any attributes checking the node's layout then error out
instead of assuming the test has passed. This will ensure data-* attributes containing
typos don't register as a pass.

* fast/check-layout-error-no-attributes-expected.txt: Added.
* fast/check-layout-error-no-attributes.html: Added.
* resources/check-layout.js:
(.):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (148972 => 148973)


--- trunk/LayoutTests/ChangeLog	2013-04-23 17:08:57 UTC (rev 148972)
+++ trunk/LayoutTests/ChangeLog	2013-04-23 17:50:01 UTC (rev 148973)
@@ -1,3 +1,19 @@
+2013-04-23  Robert Hogan  <[email protected]>
+
+        checkLayout() should error out if no data-expected* attributes were found
+        https://bugs.webkit.org/show_bug.cgi?id=114900
+
+        Reviewed by Ojan Vafai.
+
+        If checkLayout() doesn't find any attributes checking the node's layout then error out
+        instead of assuming the test has passed. This will ensure data-* attributes containing
+        typos don't register as a pass.
+
+        * fast/check-layout-error-no-attributes-expected.txt: Added.
+        * fast/check-layout-error-no-attributes.html: Added.
+        * resources/check-layout.js:
+        (.):
+
 2013-04-23  Lamarque V. Souza  <[email protected]>
 
         WebSocket: Return type of send() should be void if hybi-10 protocol is chosen

Added: trunk/LayoutTests/fast/check-layout-error-no-attributes-expected.txt (0 => 148973)


--- trunk/LayoutTests/fast/check-layout-error-no-attributes-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/check-layout-error-no-attributes-expected.txt	2013-04-23 17:50:01 UTC (rev 148973)
@@ -0,0 +1 @@
+FAIL: No valid data-* attributes found in selector list : span > span

Added: trunk/LayoutTests/fast/check-layout-error-no-attributes.html (0 => 148973)


--- trunk/LayoutTests/fast/check-layout-error-no-attributes.html	                        (rev 0)
+++ trunk/LayoutTests/fast/check-layout-error-no-attributes.html	2013-04-23 17:50:01 UTC (rev 148973)
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+<body>
+    <script src=""
+    <p> webkit.org/b/114900: checkLayout() should error out if the layout wasn't checked. </p>
+    <span style="background-color: green;">xxx <span style="background-color:blue;" data-total-invalid-attribute=0>yyy</span></span>
+    <script>
+        checkLayout('span > span');
+    </script>
+</body>
+</html>

Modified: trunk/LayoutTests/resources/check-layout.js (148972 => 148973)


--- trunk/LayoutTests/resources/check-layout.js	2013-04-23 17:08:57 UTC (rev 148972)
+++ trunk/LayoutTests/resources/check-layout.js	2013-04-23 17:50:01 UTC (rev 148973)
@@ -18,84 +18,93 @@
 
 function checkSubtreeExpectedValues(parent, failures)
 {
-    checkExpectedValues(parent, failures);
+    var checkedLayout = checkExpectedValues(parent, failures);
     Array.prototype.forEach.call(parent.childNodes, function(node) {
-        checkSubtreeExpectedValues(node, failures);
+        checkedLayout |= checkSubtreeExpectedValues(node, failures);
     });
+    return checkedLayout;
 }
 
+function checkAttribute(output, node, attribute)
+{
+    var result = node.getAttribute && node.getAttribute(attribute);
+    output.checked |= !!result;
+    return result;
+}
+
 function checkExpectedValues(node, failures)
 {
-    var expectedWidth = node.getAttribute && node.getAttribute("data-expected-width");
+    var output = { checked: false };
+    var expectedWidth = checkAttribute(output, node, "data-expected-width");
     if (expectedWidth) {
         if (node.offsetWidth != parseInt(expectedWidth))
             failures.push("Expected " + expectedWidth + " for width, but got " + node.offsetWidth + ". ");
     }
 
-    var expectedHeight = node.getAttribute && node.getAttribute("data-expected-height");
+    var expectedHeight = checkAttribute(output, node, "data-expected-height");
     if (expectedHeight) {
         if (node.offsetHeight != parseInt(expectedHeight))
             failures.push("Expected " + expectedHeight + " for height, but got " + node.offsetHeight + ". ");
     }
 
-    var expectedOffset = node.getAttribute && node.getAttribute("data-offset-x");
+    var expectedOffset = checkAttribute(output, node, "data-offset-x");
     if (expectedOffset) {
         if (node.offsetLeft != parseInt(expectedOffset))
             failures.push("Expected " + expectedOffset + " for offsetLeft, but got " + node.offsetLeft + ". ");
     }
 
-    var expectedOffset = node.getAttribute && node.getAttribute("data-offset-y");
+    var expectedOffset = checkAttribute(output, node, "data-offset-y");
     if (expectedOffset) {
         if (node.offsetTop != parseInt(expectedOffset))
             failures.push("Expected " + expectedOffset + " for offsetTop, but got " + node.offsetTop + ". ");
     }
 
-    var expectedWidth = node.getAttribute && node.getAttribute("data-expected-client-width");
+    var expectedWidth = checkAttribute(output, node, "data-expected-client-width");
     if (expectedWidth) {
         if (node.clientWidth != parseInt(expectedWidth))
             failures.push("Expected " + expectedWidth + " for clientWidth, but got " + node.clientWidth + ". ");
     }
 
-    var expectedHeight = node.getAttribute && node.getAttribute("data-expected-client-height");
+    var expectedHeight = checkAttribute(output, node, "data-expected-client-height");
     if (expectedHeight) {
         if (node.clientHeight != parseInt(expectedHeight))
             failures.push("Expected " + expectedHeight + " for clientHeight, but got " + node.clientHeight + ". ");
     }
 
-    var expectedWidth = node.getAttribute && node.getAttribute("data-expected-scroll-width");
+    var expectedWidth = checkAttribute(output, node, "data-expected-scroll-width");
     if (expectedWidth) {
         if (node.scrollWidth != parseInt(expectedWidth))
             failures.push("Expected " + expectedWidth + " for scrollWidth, but got " + node.scrollWidth + ". ");
     }
 
-    var expectedHeight = node.getAttribute && node.getAttribute("data-expected-scroll-height");
+    var expectedHeight = checkAttribute(output, node, "data-expected-scroll-height");
     if (expectedHeight) {
         if (node.scrollHeight != parseInt(expectedHeight))
             failures.push("Expected " + expectedHeight + " for scrollHeight, but got " + node.scrollHeight + ". ");
     }
 
-    var expectedOffset = node.getAttribute && node.getAttribute("data-total-x");
+    var expectedOffset = checkAttribute(output, node, "data-total-x");
     if (expectedOffset) {
         var totalLeft = node.clientLeft + node.offsetLeft;
         if (totalLeft != parseInt(expectedOffset))
             failures.push("Expected " + expectedOffset + " for clientLeft+offsetLeft, but got " + totalLeft + ", clientLeft: " + node.clientLeft + ", offsetLeft: " + node.offsetLeft + ". ");
     }
 
-    var expectedOffset = node.getAttribute && node.getAttribute("data-total-y");
+    var expectedOffset = checkAttribute(output, node, "data-total-y");
     if (expectedOffset) {
         var totalTop = node.clientTop + node.offsetTop;
         if (totalTop != parseInt(expectedOffset))
             failures.push("Expected " + expectedOffset + " for clientTop+offsetTop, but got " + totalTop + ", clientTop: " + node.clientTop + ", + offsetTop: " + node.offsetTop + ". ");
     }
 
-    var expectedDisplay = node.getAttribute && node.getAttribute("data-expected-display");
+    var expectedDisplay = checkAttribute(output, node, "data-expected-display");
     if (expectedDisplay) {
         var actualDisplay = getComputedStyle(node).display;
         if (actualDisplay != expectedDisplay)
             failures.push("Expected " + expectedDisplay + " for display, but got " + actualDisplay + ". ");
     }
 
-    var expectedPaddingTop = node.getAttribute && node.getAttribute("data-expected-padding-top");
+    var expectedPaddingTop = checkAttribute(output, node, "data-expected-padding-top");
     if (expectedPaddingTop) {
         var actualPaddingTop = getComputedStyle(node).paddingTop;
         // Trim the unit "px" from the output.
@@ -104,7 +113,7 @@
             failures.push("Expected " + expectedPaddingTop + " for padding-top, but got " + actualPaddingTop + ". ");
     }
 
-    var expectedPaddingBottom = node.getAttribute && node.getAttribute("data-expected-padding-bottom");
+    var expectedPaddingBottom = checkAttribute(output, node, "data-expected-padding-bottom");
     if (expectedPaddingBottom) {
         var actualPaddingBottom = getComputedStyle(node).paddingBottom;
         // Trim the unit "px" from the output.
@@ -113,7 +122,7 @@
             failures.push("Expected " + expectedPaddingBottom + " for padding-bottom, but got " + actualPaddingBottom + ". ");
     }
 
-    var expectedPaddingLeft = node.getAttribute && node.getAttribute("data-expected-padding-left");
+    var expectedPaddingLeft = checkAttribute(output, node, "data-expected-padding-left");
     if (expectedPaddingLeft) {
         var actualPaddingLeft = getComputedStyle(node).paddingLeft;
         // Trim the unit "px" from the output.
@@ -122,7 +131,7 @@
             failures.push("Expected " + expectedPaddingLeft + " for padding-left, but got " + actualPaddingLeft + ". ");
     }
 
-    var expectedPaddingRight = node.getAttribute && node.getAttribute("data-expected-padding-right");
+    var expectedPaddingRight = checkAttribute(output, node, "data-expected-padding-right");
     if (expectedPaddingRight) {
         var actualPaddingRight = getComputedStyle(node).paddingRight;
         // Trim the unit "px" from the output.
@@ -131,7 +140,7 @@
             failures.push("Expected " + expectedPaddingRight + " for padding-right, but got " + actualPaddingRight + ". ");
     }
 
-    var expectedMarginTop = node.getAttribute && node.getAttribute("data-expected-margin-top");
+    var expectedMarginTop = checkAttribute(output, node, "data-expected-margin-top");
     if (expectedMarginTop) {
         var actualMarginTop = getComputedStyle(node).marginTop;
         // Trim the unit "px" from the output.
@@ -140,7 +149,7 @@
             failures.push("Expected " + expectedMarginTop + " for margin-top, but got " + actualMarginTop + ". ");
     }
 
-    var expectedMarginBottom = node.getAttribute && node.getAttribute("data-expected-margin-bottom");
+    var expectedMarginBottom = checkAttribute(output, node, "data-expected-margin-bottom");
     if (expectedMarginBottom) {
         var actualMarginBottom = getComputedStyle(node).marginBottom;
         // Trim the unit "px" from the output.
@@ -149,7 +158,7 @@
             failures.push("Expected " + expectedMarginBottom + " for margin-bottom, but got " + actualMarginBottom + ". ");
     }
 
-    var expectedMarginLeft = node.getAttribute && node.getAttribute("data-expected-margin-left");
+    var expectedMarginLeft = checkAttribute(output, node, "data-expected-margin-left");
     if (expectedMarginLeft) {
         var actualMarginLeft = getComputedStyle(node).marginLeft;
         // Trim the unit "px" from the output.
@@ -158,7 +167,7 @@
             failures.push("Expected " + expectedMarginLeft + " for margin-left, but got " + actualMarginLeft + ". ");
     }
 
-    var expectedMarginRight = node.getAttribute && node.getAttribute("data-expected-margin-right");
+    var expectedMarginRight = checkAttribute(output, node, "data-expected-margin-right");
     if (expectedMarginRight) {
         var actualMarginRight = getComputedStyle(node).marginRight;
         // Trim the unit "px" from the output.
@@ -166,6 +175,8 @@
         if (actualMarginRight != expectedMarginRight)
             failures.push("Expected " + expectedMarginRight + " for margin-right, but got " + actualMarginRight + ". ");
     }
+
+    return output.checked;
 }
 
 window.checkLayout = function(selectorList)
@@ -177,10 +188,11 @@
     var nodes = document.querySelectorAll(selectorList);
     nodes = Array.prototype.slice.call(nodes);
     nodes.reverse();
+    var checkedLayout = false;
     Array.prototype.forEach.call(nodes, function(node) {
         var failures = [];
-        checkExpectedValues(node.parentNode, failures);
-        checkSubtreeExpectedValues(node, failures);
+        checkedLayout |= checkExpectedValues(node.parentNode, failures);
+        checkedLayout |= checkSubtreeExpectedValues(node, failures);
 
         var container = node.parentNode.className == 'container' ? node.parentNode : node;
 
@@ -190,6 +202,12 @@
         pre.appendChild(document.createTextNode(failures.length ? "FAIL:\n" + failures.join('\n') + '\n\n' + container.outerHTML : "PASS"));
         insertAfter(pre, container);
     });
+
+    if (!checkedLayout) {
+        document.body.innerHTML = "FAIL: No valid data-* attributes found in selector list : " + selectorList;
+        return;
+    }
+
     var pre = document.querySelector('.FAIL');
     if (pre)
         setTimeout(function() { pre.previousSibling.scrollIntoView(); }, 0);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to