test_viewport_units.html 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=804970
  5. -->
  6. <head>
  7. <title>Test for dynamic changes to CSS 'vh', 'vw', 'vmin', and 'vmax' units</title>
  8. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  9. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  10. </head>
  11. <body>
  12. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=804970">Mozilla Bug 804970</a>
  13. <iframe id="iframe" src="viewport_units_iframe.html"></iframe>
  14. <pre id="test">
  15. <script type="application/javascript">
  16. /** Test for CSS vh/vw/vmin/vmax units **/
  17. function px_to_num(str)
  18. {
  19. return Number(String(str).match(/^([\d.]+)px$/)[1]);
  20. }
  21. function width(elt)
  22. {
  23. return px_to_num(elt.ownerDocument.defaultView.getComputedStyle(elt, "").width);
  24. }
  25. SimpleTest.waitForExplicitFinish();
  26. function run() {
  27. var iframe = document.getElementById("iframe");
  28. var idoc = iframe.contentDocument;
  29. var vh = idoc.getElementById("vh");
  30. var vw = idoc.getElementById("vw");
  31. var vmin = idoc.getElementById("vmin");
  32. var vmax = idoc.getElementById("vmax");
  33. iframe.style.width = "100px";
  34. iframe.style.height = "250px";
  35. is(width(vh), 250, "vh should be 250px");
  36. is(width(vw), 100, "vw should be 100px");
  37. is(width(vmin), 100, "vmin should be 100px");
  38. is(width(vmax), 250, "vmax should be 250px");
  39. iframe.style.width = "300px";
  40. is(width(vh), 250, "vh should be 250px");
  41. is(width(vw), 300, "vw should be 300px");
  42. is(width(vmin), 250, "vmin should be 250px");
  43. is(width(vmax), 300, "vmax should be 300px");
  44. iframe.style.height = "200px";
  45. is(width(vh), 200, "vh should be 200px");
  46. is(width(vw), 300, "vw should be 300px");
  47. is(width(vmin), 200, "vmin should be 200px");
  48. is(width(vmax), 300, "vmax should be 300px");
  49. SimpleTest.finish();
  50. }
  51. window.addEventListener("load", run, false);
  52. </script>
  53. </pre>
  54. </body>
  55. </html>