test_supports_rules.html 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=649740
  5. -->
  6. <head>
  7. <title>Test for Bug 649740</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. <style id="style">
  11. </style>
  12. </head>
  13. <body>
  14. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=649740">Mozilla Bug 649740</a>
  15. <p id="display1"></p>
  16. <p id="display2"></p>
  17. <pre id="test">
  18. <script type="application/javascript">
  19. /** Test for Bug 649740 **/
  20. function condition(s) {
  21. return s.replace(/^@supports\s*/, '').replace(/ \s*{\s*}\s*$/, '');
  22. }
  23. var styleSheetText =
  24. "@supports(color: green){ }\n" +
  25. "@supports (color: green) { }\n" +
  26. "@supports ((color: green)) { }\n" +
  27. "@supports (color: green) and (color: blue) { }\n" +
  28. "@supports ( Font: 20px serif ! Important) { }";
  29. function runTest() {
  30. var style = document.getElementById("style");
  31. style.textContent = styleSheetText;
  32. var sheet = style.sheet;
  33. is(condition(sheet.cssRules[0].cssText), "(color: green)");
  34. is(condition(sheet.cssRules[1].cssText), "(color: green)");
  35. is(condition(sheet.cssRules[2].cssText), "((color: green))");
  36. is(condition(sheet.cssRules[3].cssText), "(color: green) and (color: blue)");
  37. is(condition(sheet.cssRules[4].cssText), "( Font: 20px serif ! Important)");
  38. var cs1 = getComputedStyle(document.getElementById("display1"), "");
  39. var cs2 = getComputedStyle(document.getElementById("display2"), "");
  40. function check_balanced_condition(condition, expected_match) {
  41. style.textContent = "#display1, #display2 { text-decoration: overline }\n" +
  42. "@supports " + condition + "{\n" +
  43. " #display1 { text-decoration: line-through }\n" +
  44. "}\n" +
  45. "#display2 { text-decoration: underline }\n";
  46. is(cs1.textDecoration,
  47. expected_match ? "line-through" : "overline",
  48. "@supports condition \"" + condition + "\" should " +
  49. (expected_match ? "" : "NOT ") + "match");
  50. is(cs2.textDecoration, "underline",
  51. "@supports condition \"" + condition + "\" should be balanced");
  52. }
  53. check_balanced_condition("not (color: green)", false);
  54. check_balanced_condition("not (colour: green)", true);
  55. check_balanced_condition("not(color: green)", false);
  56. check_balanced_condition("not(colour: green)", false);
  57. check_balanced_condition("not/* */(color: green)", false);
  58. check_balanced_condition("not/* */(colour: green)", false);
  59. check_balanced_condition("not /* */ (color: green)", false);
  60. check_balanced_condition("not /* */ (colour: green)", true);
  61. check_balanced_condition("(color: green) and (color: blue)", true);
  62. check_balanced_condition("(color: green) /* */ /* */ and /* */ /* */ (color: blue)", true);
  63. check_balanced_condition("(color: green) and(color: blue)", false);
  64. check_balanced_condition("(color: green) and/* */(color: blue)", false);
  65. check_balanced_condition("(color: green)and (color: blue)", false);
  66. check_balanced_condition("(color: green) or (color: blue)", true);
  67. check_balanced_condition("(color: green) /* */ /* */ or /* */ /* */ (color: blue)", true);
  68. check_balanced_condition("(color: green) or(color: blue)", false);
  69. check_balanced_condition("(color: green) or/* */(color: blue)", false);
  70. check_balanced_condition("(color: green)or (color: blue)", false);
  71. SimpleTest.finish();
  72. }
  73. SimpleTest.waitForExplicitFinish();
  74. runTest();
  75. </script>
  76. </pre>
  77. </body>
  78. </html>