test_rule_serialization.html 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=
  5. -->
  6. <head>
  7. <title>Test for Bug </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 type="text/css" id="style"></style>
  11. </head>
  12. <body>
  13. <pre id="test">
  14. <script type="application/javascript">
  15. var rules = [
  16. { rule: "@-moz-document url(http://www.example.com/) {}" },
  17. { rule: "@-moz-document url('http://www.example.com/') {}" },
  18. { rule: '@-moz-document url("http://www.example.com/") {}' },
  19. { rule: "@-moz-document url-prefix('http://www.example.com/') {}" },
  20. { rule: '@-moz-document url-prefix("http://www.example.com/") {}' },
  21. { rule: "@-moz-document domain('example.com') {}" },
  22. { rule: '@-moz-document domain("example.com") {}' },
  23. { rule: "@-moz-document regexp('http://www.w3.org/TR/\\d{4}/[^/]*-CSS2-\\d{8}/') {}" },
  24. { rule: '@-moz-document regexp("http://www.w3.org/TR/\\d{4}/[^/]*-CSS2-\\d{8}/") {}' },
  25. ];
  26. var style = document.getElementById("style");
  27. var style_text = document.createTextNode("");
  28. style.appendChild(style_text);
  29. for (var i in rules) {
  30. var obj = rules[i];
  31. var rule = obj.rule;
  32. style_text.data = rule;
  33. is(style.sheet.cssRules.length, 1, "should have one rule");
  34. var ser1 = style.sheet.cssRules[0].cssText;
  35. if ("is_canonical" in obj) {
  36. is(ser1, rule, "rule '" + rule + "' should serialize to itself");
  37. }
  38. style_text.data = ser1;
  39. is(style.sheet.cssRules.length, 1, "should have one rule");
  40. var ser2 = style.sheet.cssRules[0].cssText;
  41. is(ser2, ser1,
  42. "parse+serialize for rule '" + rule + "' should be idempotent");
  43. }
  44. </script>
  45. </pre>
  46. </body>
  47. </html>