OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <script src="../../resources/testharness.js"></script> |
| 3 <script src="../../resources/testharnessreport.js"></script> |
| 4 <svg width="1" height="1" visibility="hidden"> |
| 5 </svg> |
| 6 <script> |
| 7 var svgElement = document.querySelector("svg"); |
| 8 var viewportWidth = window.innerWidth; |
| 9 var viewportHeight = window.innerHeight; |
| 10 var EPSILON = Math.pow(2, -8); |
| 11 |
| 12 function viewportWidthPercent() |
| 13 { |
| 14 return (viewportWidth / 100); |
| 15 } |
| 16 |
| 17 function viewportHeightPercent() |
| 18 { |
| 19 return (viewportHeight / 100); |
| 20 } |
| 21 |
| 22 function viewportMinPercent() |
| 23 { |
| 24 return (Math.min(viewportWidth, viewportHeight) / 100); |
| 25 } |
| 26 |
| 27 function viewportMaxPercent() |
| 28 { |
| 29 return (Math.max(viewportWidth, viewportHeight) / 100); |
| 30 } |
| 31 |
| 32 test(function() { |
| 33 svgElement.setAttribute("width", "10vw"); |
| 34 assert_approx_equals(svgElement.width.baseVal.value, 10 * viewportWidthPerce
nt(), EPSILON); |
| 35 assert_equals(svgElement.width.baseVal.valueInSpecifiedUnits, 10); |
| 36 assert_throws(null, function() {svgElement.width.baseVal.valueAsString = '2v
w'}); |
| 37 svgElement.width.baseVal.valueInSpecifiedUnits = 2; |
| 38 assert_approx_equals(svgElement.width.baseVal.value, 2 * viewportWidthPercen
t(), EPSILON); |
| 39 assert_equals(svgElement.width.baseVal.unitType, SVGLength.SVG_LENGTHTYPE_UN
KNOWN); |
| 40 }, "Tests vw unit"); |
| 41 |
| 42 test(function() { |
| 43 svgElement.setAttribute("width", "10vh"); |
| 44 assert_approx_equals(svgElement.width.baseVal.value, 10 * viewportHeightPerc
ent(), EPSILON); |
| 45 assert_equals(svgElement.width.baseVal.valueInSpecifiedUnits, 10); |
| 46 assert_throws(null, function() {svgElement.width.baseVal.valueAsString = '2v
h'}); |
| 47 svgElement.width.baseVal.valueInSpecifiedUnits = 2; |
| 48 assert_approx_equals(svgElement.width.baseVal.value, 2 * viewportHeightPerce
nt(), EPSILON); |
| 49 assert_equals(svgElement.width.baseVal.unitType, SVGLength.SVG_LENGTHTYPE_UN
KNOWN); |
| 50 }, "Tests vh unit"); |
| 51 |
| 52 test(function() { |
| 53 svgElement.setAttribute("width", "10vmin"); |
| 54 assert_approx_equals(svgElement.width.baseVal.value, 10 * viewportMinPercent
(), EPSILON); |
| 55 assert_equals(svgElement.width.baseVal.valueInSpecifiedUnits, 10); |
| 56 assert_throws(null, function() {svgElement.width.baseVal.valueAsString = '2v
min'}); |
| 57 svgElement.width.baseVal.valueInSpecifiedUnits = 2; |
| 58 assert_approx_equals(svgElement.width.baseVal.value, 2 * viewportMinPercent(
), EPSILON); |
| 59 assert_equals(svgElement.width.baseVal.unitType, SVGLength.SVG_LENGTHTYPE_UN
KNOWN); |
| 60 }, "Tests vmin unit"); |
| 61 |
| 62 test(function() { |
| 63 svgElement.setAttribute("width", "10vmax"); |
| 64 assert_approx_equals(svgElement.width.baseVal.value, 10 * viewportMaxPercent
(), EPSILON); |
| 65 assert_equals(svgElement.width.baseVal.valueInSpecifiedUnits, 10); |
| 66 assert_throws(null, function() {svgElement.width.baseVal.valueAsString = '2v
max'}); |
| 67 svgElement.width.baseVal.valueInSpecifiedUnits = 2; |
| 68 assert_approx_equals(svgElement.width.baseVal.value, 2 * viewportMaxPercent(
), EPSILON); |
| 69 assert_equals(svgElement.width.baseVal.unitType, SVGLength.SVG_LENGTHTYPE_UN
KNOWN); |
| 70 }, "Tests vmax unit"); |
| 71 |
| 72 </script> |
OLD | NEW |