Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Unified Diff: third_party/WebKit/LayoutTests/svg/dom/SVGLength-calc-in-attr.html

Issue 2097383002: Added support of calc() for SVGLength (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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>

Powered by Google App Engine
This is Rietveld 408576698