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

Unified Diff: third_party/WebKit/LayoutTests/svg/dom/script-tests/SVGLength-viewport-units.js

Issue 1544543003: Adding support of viewport units to SVG (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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/script-tests/SVGLength-viewport-units.js
diff --git a/third_party/WebKit/LayoutTests/svg/dom/script-tests/SVGLength-viewport-units.js b/third_party/WebKit/LayoutTests/svg/dom/script-tests/SVGLength-viewport-units.js
new file mode 100644
index 0000000000000000000000000000000000000000..98453b3e99f2e6827648e73ffc26e5ccaec01099
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/svg/dom/script-tests/SVGLength-viewport-units.js
@@ -0,0 +1,69 @@
+description("This test checks the Viewport Units for SVGLength");
+
+var svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg");
+document.body.appendChild(svgElement);
+var viewportWidth = window.innerWidth;
+var viewportHeight = window.innerHeight;
+var EPSILON = Math.pow(2, -8);
+
+function viewportWidthPercent()
+{
+ return (viewportWidth / 100);
+}
+
+function viewportHeightPercent()
+{
+ return (viewportHeight / 100);
+}
+
+function viewportMinPercent()
+{
+ return (Math.min(viewportWidth, viewportHeight) / 100);
+}
+
+function viewportMaxPercent()
+{
+ return (Math.max(viewportWidth, viewportHeight) / 100);
+}
+
+debug("");
+debug("Tests the vw unit");
+svgElement.setAttribute("width", "10vw");
+shouldBeCloseEnough("svgElement.width.baseVal.value", "10 * viewportWidthPercent()", EPSILON);
+shouldBe("svgElement.width.baseVal.valueInSpecifiedUnits", "10");
+shouldThrow("svgElement.width.baseVal.valueAsString = '2vw'");
+shouldNotThrow("svgElement.width.baseVal.valueInSpecifiedUnits = '2'");
+shouldBeCloseEnough("svgElement.width.baseVal.value", "2 * viewportWidthPercent()", EPSILON);
+shouldBe("svgElement.width.baseVal.unitType", "SVGLength.SVG_LENGTHTYPE_UNKNOWN");
+
+debug("");
+debug("Tests the vh unit");
+svgElement.setAttribute("width", "10vh");
+shouldBeCloseEnough("svgElement.width.baseVal.value", "10 * viewportHeightPercent()", EPSILON);
+shouldBe("svgElement.width.baseVal.valueInSpecifiedUnits", "10");
+shouldThrow("svgElement.width.baseVal.valueAsString = '2vh'");
+shouldNotThrow("svgElement.width.baseVal.valueInSpecifiedUnits = '2'");
+shouldBeCloseEnough("svgElement.width.baseVal.value", "2 * viewportHeightPercent()", EPSILON);
+shouldBe("svgElement.width.baseVal.unitType", "SVGLength.SVG_LENGTHTYPE_UNKNOWN");
+
+debug("");
+debug("Tests the vmin unit");
+svgElement.setAttribute("width", "10vmin");
+shouldBeCloseEnough("svgElement.width.baseVal.value", "10 * viewportMinPercent()", EPSILON);
+shouldBe("svgElement.width.baseVal.valueInSpecifiedUnits", "10");
+shouldThrow("svgElement.width.baseVal.valueAsString = '2vmin'");
+shouldNotThrow("svgElement.width.baseVal.valueInSpecifiedUnits = '2'");
+shouldBeCloseEnough("svgElement.width.baseVal.value", "2 * viewportMinPercent()", EPSILON);
+shouldBe("svgElement.width.baseVal.unitType", "SVGLength.SVG_LENGTHTYPE_UNKNOWN");
+
+debug("");
+debug("Tests the vmax unit");
+svgElement.setAttribute("width", "10vmax");
+shouldBeCloseEnough("svgElement.width.baseVal.value", "10 * viewportMaxPercent()", EPSILON);
+shouldBe("svgElement.width.baseVal.valueInSpecifiedUnits", "10");
+shouldThrow("svgElement.width.baseVal.valueAsString = '2vmax'");
+shouldNotThrow("svgElement.width.baseVal.valueInSpecifiedUnits = '2'");
+shouldBeCloseEnough("svgElement.width.baseVal.value", "2 * viewportMaxPercent()", EPSILON);
+shouldBe("svgElement.width.baseVal.unitType", "SVGLength.SVG_LENGTHTYPE_UNKNOWN");
+
+successfullyParsed = true;

Powered by Google App Engine
This is Rietveld 408576698