OLD | NEW |
(Empty) | |
| 1 description("This test checks the Viewport Units for SVGLength"); |
| 2 |
| 3 var svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg"); |
| 4 document.body.appendChild(svgElement); |
| 5 var viewportWidth = window.innerWidth; |
| 6 var viewportHeight = window.innerHeight; |
| 7 var EPSILON = Math.pow(2, -8); |
| 8 |
| 9 function viewportWidthPercent() |
| 10 { |
| 11 return (viewportWidth / 100); |
| 12 } |
| 13 |
| 14 function viewportHeightPercent() |
| 15 { |
| 16 return (viewportHeight / 100); |
| 17 } |
| 18 |
| 19 function viewportMinPercent() |
| 20 { |
| 21 return (Math.min(viewportWidth, viewportHeight) / 100); |
| 22 } |
| 23 |
| 24 function viewportMaxPercent() |
| 25 { |
| 26 return (Math.max(viewportWidth, viewportHeight) / 100); |
| 27 } |
| 28 |
| 29 debug(""); |
| 30 debug("Tests the vw unit"); |
| 31 svgElement.setAttribute("width", "10vw"); |
| 32 shouldBeCloseEnough("svgElement.width.baseVal.value", "10 * viewportWidthPercent
()", EPSILON); |
| 33 shouldBe("svgElement.width.baseVal.valueInSpecifiedUnits", "10"); |
| 34 shouldThrow("svgElement.width.baseVal.valueAsString = '2vw'"); |
| 35 shouldNotThrow("svgElement.width.baseVal.valueInSpecifiedUnits = '2'"); |
| 36 shouldBeCloseEnough("svgElement.width.baseVal.value", "2 * viewportWidthPercent(
)", EPSILON); |
| 37 shouldBe("svgElement.width.baseVal.unitType", "SVGLength.SVG_LENGTHTYPE_UNKNOWN"
); |
| 38 |
| 39 debug(""); |
| 40 debug("Tests the vh unit"); |
| 41 svgElement.setAttribute("width", "10vh"); |
| 42 shouldBeCloseEnough("svgElement.width.baseVal.value", "10 * viewportHeightPercen
t()", EPSILON); |
| 43 shouldBe("svgElement.width.baseVal.valueInSpecifiedUnits", "10"); |
| 44 shouldThrow("svgElement.width.baseVal.valueAsString = '2vh'"); |
| 45 shouldNotThrow("svgElement.width.baseVal.valueInSpecifiedUnits = '2'"); |
| 46 shouldBeCloseEnough("svgElement.width.baseVal.value", "2 * viewportHeightPercent
()", EPSILON); |
| 47 shouldBe("svgElement.width.baseVal.unitType", "SVGLength.SVG_LENGTHTYPE_UNKNOWN"
); |
| 48 |
| 49 debug(""); |
| 50 debug("Tests the vmin unit"); |
| 51 svgElement.setAttribute("width", "10vmin"); |
| 52 shouldBeCloseEnough("svgElement.width.baseVal.value", "10 * viewportMinPercent()
", EPSILON); |
| 53 shouldBe("svgElement.width.baseVal.valueInSpecifiedUnits", "10"); |
| 54 shouldThrow("svgElement.width.baseVal.valueAsString = '2vmin'"); |
| 55 shouldNotThrow("svgElement.width.baseVal.valueInSpecifiedUnits = '2'"); |
| 56 shouldBeCloseEnough("svgElement.width.baseVal.value", "2 * viewportMinPercent()"
, EPSILON); |
| 57 shouldBe("svgElement.width.baseVal.unitType", "SVGLength.SVG_LENGTHTYPE_UNKNOWN"
); |
| 58 |
| 59 debug(""); |
| 60 debug("Tests the vmax unit"); |
| 61 svgElement.setAttribute("width", "10vmax"); |
| 62 shouldBeCloseEnough("svgElement.width.baseVal.value", "10 * viewportMaxPercent()
", EPSILON); |
| 63 shouldBe("svgElement.width.baseVal.valueInSpecifiedUnits", "10"); |
| 64 shouldThrow("svgElement.width.baseVal.valueAsString = '2vmax'"); |
| 65 shouldNotThrow("svgElement.width.baseVal.valueInSpecifiedUnits = '2'"); |
| 66 shouldBeCloseEnough("svgElement.width.baseVal.value", "2 * viewportMaxPercent()"
, EPSILON); |
| 67 shouldBe("svgElement.width.baseVal.unitType", "SVGLength.SVG_LENGTHTYPE_UNKNOWN"
); |
| 68 |
| 69 successfullyParsed = true; |
OLD | NEW |