Index: third_party/WebKit/LayoutTests/svg/dom/SVGLength-calc-in-attr.html |
diff --git a/third_party/WebKit/LayoutTests/svg/dom/SVGLength-calc-in-attr.html b/third_party/WebKit/LayoutTests/svg/dom/SVGLength-calc-in-attr.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0f4a448c2c6290b3dbad2e2974d7366e7e2704e6 |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/svg/dom/SVGLength-calc-in-attr.html |
@@ -0,0 +1,52 @@ |
+<!DOCTYPE html> |
+<script src="../../resources/testharness.js"></script> |
+<script src="../../resources/testharnessreport.js"></script> |
+<svg width="500" height="500" visibility="hidden"> |
+ <rect width="1" height="1"/> |
+</svg> |
+<script> |
+var rectElement = document.querySelector("rect"); |
fs
2016/06/29 09:28:17
Doesn't need to be global.
Shanmuga Pandi
2016/07/15 12:18:22
Acknowledged.
|
+var svgWidth = 500; |
+var EPSILON = Math.pow(2, -8); |
+var cssPixelsPerInch = 96; |
+var cssPixelsPerCentimeter = cssPixelsPerInch / 2.54; //2.54 cm/in |
+var cssPixelsPerMillimeter = cssPixelsPerCentimeter / 10; |
+var cssPixelsPerPoint = cssPixelsPerInch / 72; |
+var cssPixelsPerPica = cssPixelsPerInch / 6; |
+var expected; |
+var rect; |
fs
2016/06/29 09:28:17
Neither do these two.
Shanmuga Pandi
2016/07/15 12:18:22
Acknowledged.
|
+ |
+function svgViewportWidthPercent() |
+{ |
fs
2016/06/29 09:28:17
Move to previous line.
Alternatively just open-co
|
+ return (svgWidth / 100); |
fs
2016/06/29 09:28:17
Drop parenthesis.
|
+} |
+ |
+test(function() { |
+ rectElement.setAttribute("width", "calc(10 + 10)"); |
+ expected = 20; |
+ rect = rectElement.getBoundingClientRect(); |
+ assert_approx_equals(rect.width, expected, EPSILON); |
fs
2016/06/29 09:28:17
For some reduction in boilerplate, I think a struc
|
+ |
+ rectElement.setAttribute("width", "calc(10mm + 10)"); |
+ expected = (10 * cssPixelsPerMillimeter) + 10; |
+ rect = rectElement.getBoundingClientRect(); |
+ assert_approx_equals(rect.width, expected, EPSILON); |
+ |
+ rectElement.setAttribute("width", "calc(10% + 10)"); |
+ expected = (10 * svgViewportWidthPercent()) + 10; |
+ rect = rectElement.getBoundingClientRect(); |
+ assert_approx_equals(rect.width, expected, EPSILON); |
+ |
+ rectElement.setAttribute("width", "calc(1cm + 2in + 1cm + 2)"); |
+ expected = (2 * cssPixelsPerInch) + (2 * cssPixelsPerCentimeter) + 2; |
+ rect = rectElement.getBoundingClientRect(); |
+ assert_approx_equals(rect.width, expected, EPSILON); |
+ |
+ rectElement.setAttribute("width", "calc(10% + 10 + 2% + 10pc)"); |
+ expected = (12 * svgViewportWidthPercent()) + 10 + (10 * cssPixelsPerPica); |
+ rect = rectElement.getBoundingClientRect(); |
+ assert_approx_equals(rect.width, expected, EPSILON); |
+ |
fs
2016/06/29 09:28:17
Drop blank line.
|
+}, "Tests calc() in svgLength"); |
+ |
+</script> |