Chromium Code Reviews| 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"); |
|
fs
2016/01/04 19:40:05
Drop 'the'. Could we fold this into the html file
|
| + |
| +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; |