Replace hasAttribute with the check for actual value

This change replaces the use of hasAttribute() by a
better and correct approach, to check if the actual
value is greater than or equal to zero. This patch also
includes a Ref Test which demonstrates the setting of attribute
within a 'use' tag to test the changed code path.

BUG=235256
R=pdr@chromium.org

Review URL: https://chromiumcodereview.appspot.com/17287012

git-svn-id: svn://svn.chromium.org/blink/trunk@152911 bbb929c8-8fbe-4397-9dbb-9b2b20218538
diff --git a/LayoutTests/svg/animations/use-set-attribute-width-height-expected.html b/LayoutTests/svg/animations/use-set-attribute-width-height-expected.html
new file mode 100644
index 0000000..d898d92
--- /dev/null
+++ b/LayoutTests/svg/animations/use-set-attribute-width-height-expected.html
@@ -0,0 +1,8 @@
+<!-- Test for crbug.com/235256: this test passes if only 
+the green rect is shown on the top left side -->
+<html>
+<body>
+<svg width="10cm" height="3cm" viewBox="0 0 100 30">
+  <rect x="1" y="1" width="8" height="8" fill="green"/>
+</svg>
+</body>
diff --git a/LayoutTests/svg/animations/use-set-attribute-width-height.html b/LayoutTests/svg/animations/use-set-attribute-width-height.html
new file mode 100644
index 0000000..d395024
--- /dev/null
+++ b/LayoutTests/svg/animations/use-set-attribute-width-height.html
@@ -0,0 +1,22 @@
+<!-- Test for crbug.com/235256: this test passes if only 
+the top left green rect is shown.
+Modified from the original example here, 
+http://www.w3.org/TR/SVG/images/struct/Use02.svg -->
+<html>
+<body>
+<svg width="10cm" height="3cm" viewBox="0 0 100 30">
+  <defs>
+    <symbol id="MySymbol">
+      <desc>MySymbol - four rectangles in a grid</desc>
+      <rect x="1" y="1" width="8" height="8" fill="green"/>
+      <rect x="11" y="1" width="8" height="8" fill="red"/>
+      <rect x="1" y="11" width="8" height="8" fill="red"/>
+      <rect x="11" y="11" width="8" height="8"  fill="red"/>
+    </symbol>
+  </defs>
+  <use x="0" y="0" xlink:href="#MySymbol" >
+    <set attributeName="width" to="10" begin="0s" fill="freeze" />
+    <set attributeName="height" to="10" begin="0s" fill="freeze" />
+  </use>
+</svg>
+</body>
diff --git a/Source/core/rendering/svg/RenderSVGViewportContainer.cpp b/Source/core/rendering/svg/RenderSVGViewportContainer.cpp
index 00e428e..cb2f28e 100644
--- a/Source/core/rendering/svg/RenderSVGViewportContainer.cpp
+++ b/Source/core/rendering/svg/RenderSVGViewportContainer.cpp
@@ -96,14 +96,14 @@
         // values will override the corresponding attributes on the 'svg' in the generated tree.
 
         SVGLengthContext lengthContext(element);
-        if (useElement->hasAttribute(SVGNames::widthAttr))
+        if (useElement->width().value(lengthContext) > 0)
             m_viewport.setWidth(useElement->width().value(lengthContext));
         else if (isSymbolElement && svg->hasAttribute(SVGNames::widthAttr)) {
             SVGLength containerWidth(LengthModeWidth, "100%");
             m_viewport.setWidth(containerWidth.value(lengthContext));
         }
 
-        if (useElement->hasAttribute(SVGNames::heightAttr))
+        if (useElement->height().value(lengthContext) > 0)
             m_viewport.setHeight(useElement->height().value(lengthContext));
         else if (isSymbolElement && svg->hasAttribute(SVGNames::heightAttr)) {
             SVGLength containerHeight(LengthModeHeight, "100%");