test_variables.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <!DOCTYPE type>
  2. <title>Assorted CSS variable tests</title>
  3. <script src="/MochiKit/MochiKit.js"></script>
  4. <script src="/tests/SimpleTest/SimpleTest.js"></script>
  5. <link rel="stylesheet" href="/tests/SimpleTest/test.css" type="text/css">
  6. <style id="test1">
  7. </style>
  8. <style id="test2">
  9. </style>
  10. <style id="test3">
  11. </style>
  12. <style id="test4">
  13. </style>
  14. <div id="t4"></div>
  15. <style id="test5">
  16. </style>
  17. <div id="t5"></div>
  18. <style id="test6">
  19. </style>
  20. <style id="test7">
  21. </style>
  22. <script>
  23. var tests = [
  24. function() {
  25. // https://bugzilla.mozilla.org/show_bug.cgi?id=773296#c121
  26. var test1 = document.getElementById("test1");
  27. test1.textContent = "p { --a:123!important; }";
  28. var declaration = test1.sheet.cssRules[0].style;
  29. declaration.cssText;
  30. declaration.setProperty("color", "black");
  31. is(declaration.getPropertyValue("--a"), "123");
  32. },
  33. function() {
  34. // https://bugzilla.mozilla.org/show_bug.cgi?id=773296#c121
  35. var test2 = document.getElementById("test2");
  36. test2.textContent = "p { --a: a !important; }";
  37. var declaration = test2.sheet.cssRules[0].style;
  38. is(declaration.getPropertyPriority("--a"), "important");
  39. },
  40. function() {
  41. // https://bugzilla.mozilla.org/show_bug.cgi?id=955913
  42. var test3 = document.getElementById("test3");
  43. test3.textContent = "p { border-left-style: inset; padding: 1px; --decoration: line-through; }";
  44. var declaration = test3.sheet.cssRules[0].style;
  45. is(declaration[declaration.length - 1], "--decoration");
  46. },
  47. function() {
  48. // https://bugzilla.mozilla.org/show_bug.cgi?id=959973
  49. var test4 = document.getElementById("test4");
  50. test4.textContent = "#t4 { background-image: var(--a); }";
  51. var element = document.getElementById("t4");
  52. var path = window.location.pathname;
  53. var currentDir = path.substring(0, path.lastIndexOf('/'));
  54. var imageURL = "http://mochi.test:8888" + currentDir + "/image.png";
  55. is(window.getComputedStyle(element).getPropertyValue("background-image"), "url(\"" + imageURL +"\")");
  56. },
  57. function() {
  58. // https://bugzilla.mozilla.org/show_bug.cgi?id=1043713
  59. var test5 = document.getElementById("test5");
  60. test5.textContent = "#t5 { --SomeVariableName: a; }";
  61. var declaration = test5.sheet.cssRules[0].style;
  62. is(declaration.item(0), "--SomeVariableName", "custom property name returned by item() on style declaration");
  63. is(declaration[0], "--SomeVariableName", "custom property name returned by indexed getter on style declaration");
  64. var element = document.getElementById("t5");
  65. var cs = window.getComputedStyle(element);
  66. is(cs.item(cs.length - 1), "--SomeVariableName", "custom property name returned by item() on computed style");
  67. is(cs[cs.length - 1], "--SomeVariableName", "custom property name returned by indexed getter on style declaration");
  68. },
  69. function() {
  70. // https://bugzilla.mozilla.org/show_bug.cgi?id=969756
  71. var test6 = document.getElementById("test6");
  72. test6.textContent = "p { font: var(--var6) hangul mongolian; font-size-adjust: none; }";
  73. var declaration = test6.sheet.cssRules[0].style;
  74. test6.style.color = "white";
  75. is(declaration.getPropertyValue("-x-system-font"), " var(--var6) hangul mongolian");
  76. },
  77. function() {
  78. // https://bugzilla.mozilla.org/show_bug.cgi?id=1154356
  79. var test7 = document.getElementById("test7");
  80. test7.textContent = "p { --weird\\;name: green; }";
  81. is(test7.sheet.cssRules[0].style.cssText, "--weird\\;name: green;");
  82. test7.textContent = "p { --0: green; }";
  83. is(test7.sheet.cssRules[0].style.cssText, "--0: green;");
  84. },
  85. ];
  86. function prepareTest() {
  87. // Load an external style sheet for test 4.
  88. var e = document.createElement("link");
  89. e.addEventListener("load", runTest);
  90. e.setAttribute("rel", "stylesheet");
  91. e.setAttribute("href", "support/external-variable-url.css");
  92. document.head.appendChild(e);
  93. }
  94. function runTest() {
  95. tests.forEach(function(fn) { fn(); });
  96. SimpleTest.finish();
  97. }
  98. SimpleTest.waitForExplicitFinish();
  99. SpecialPowers.pushPrefEnv({ set: [["layout.css.variables.enabled", true ]] },
  100. prepareTest);
  101. </script>