test_keyframes_rules.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=577974
  5. -->
  6. <head>
  7. <title>Test for Bug 577974</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. @keyframes bounce {
  12. from {
  13. margin-left: 0
  14. }
  15. /*
  16. * These rules should get dropped due to syntax errors. The script
  17. * below tests that the 25% rule following them is at cssRules[1].
  18. */
  19. from, { margin-left: 0 }
  20. from , { margin-left: 0 }
  21. , from { margin-left: 0 }
  22. ,from { margin-left: 0 }
  23. from from { margin-left: 0 }
  24. from, 1 { margin-left: 0 }
  25. 1 { margin-left: 0 }
  26. 1, from { margin-left: 0 }
  27. from, 1.0 { margin-left: 0 }
  28. 1.0 { margin-left: 0 }
  29. 1.0, from { margin-left: 0 }
  30. 25% {
  31. margin-left: 25px;
  32. }
  33. 75%, 85% {
  34. margin-left: 90px;
  35. }
  36. 100% {
  37. margin-left: 100px;
  38. }
  39. }
  40. </style>
  41. </head>
  42. <body>
  43. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=577974">Mozilla Bug 577974</a>
  44. <p id="display"></p>
  45. <div id="content" style="display: none">
  46. </div>
  47. <pre id="test">
  48. <script type="application/javascript">
  49. /** Test for Bug 577974 **/
  50. var sheet = document.getElementById("style").sheet;
  51. var bounce = sheet.cssRules[0];
  52. is(bounce.type, CSSRule.KEYFRAMES_RULE, "bounce.type");
  53. is(bounce.type, 7, "bounce.type");
  54. is(bounce.name, "bounce", "bounce.name");
  55. bounce.name = "bouncier";
  56. is(bounce.name, "bouncier", "setting bounce.name");
  57. is(bounce.cssRules[0].type, CSSRule.KEYFRAME_RULE, "keyframe rule type");
  58. is(bounce.cssRules[0].type, 8, "keyframe rule type");
  59. is(bounce.cssRules[0].keyText, "0%", "keyframe rule keyText");
  60. is(bounce.cssRules[1].keyText, "25%", "keyframe rule keyText");
  61. is(bounce.cssRules[2].keyText, "75%, 85%", "keyframe rule keyText");
  62. is(bounce.cssRules[3].keyText, "100%", "keyframe rule keyText");
  63. is(bounce.cssRules[0].style.marginLeft, "0px", "keyframe rule style");
  64. is(bounce.cssRules[1].style.marginLeft, "25px", "keyframe rule style");
  65. is(bounce.cssRules[0].cssText, "0% { margin-left: 0px; }");
  66. is(bounce.cssText, "@keyframes bouncier {\n" +
  67. "0% { margin-left: 0px; }\n" +
  68. "25% { margin-left: 25px; }\n" +
  69. "75%, 85% { margin-left: 90px; }\n" +
  70. "100% { margin-left: 100px; }\n" +
  71. "}");
  72. bounce.cssRules[1].keyText = "from, 1"; // syntax error
  73. bounce.cssRules[1].keyText = "from, x"; // syntax error
  74. bounce.cssRules[1].keyText = "from,"; // syntax error
  75. bounce.cssRules[1].keyText = "from x"; // syntax error
  76. bounce.cssRules[1].keyText = "x"; // syntax error
  77. is(bounce.cssRules[1].keyText, "25%", "keyframe rule keyText parsing");
  78. bounce.cssRules[1].keyText = "from, 10%";
  79. is(bounce.cssRules[1].keyText, "0%, 10%", "keyframe rule keyText parsing");
  80. bounce.cssRules[1].keyText = "from, 0%";
  81. is(bounce.cssRules[1].keyText, "0%, 0%", "keyframe rule keyText parsing");
  82. bounce.cssRules[1].keyText = "from, from, from";
  83. is(bounce.cssRules[1].keyText, "0%, 0%, 0%", "keyframe rule keyText parsing");
  84. is(bounce.findRule("75%"), null, "findRule should match all keys");
  85. is(bounce.findRule("85%, 75%"), null,
  86. "findRule should match all keys in order");
  87. is(bounce.findRule("75%,85%"), bounce.cssRules[2],
  88. "findRule should match all keys in order, parsed");
  89. is(bounce.findRule("to"), bounce.cssRules[3],
  90. "findRule should match keys as parsed");
  91. is(bounce.findRule("100%"), bounce.cssRules[3],
  92. "findRule should match keys as parsed");
  93. is(bounce.findRule("100%, 100%"), null,
  94. "findRule should match key list");
  95. is(bounce.findRule("100%,"), null,
  96. "findRule should fail when given bad selector");
  97. is(bounce.findRule(",100%"), null,
  98. "findRule should fail when given bad selector");
  99. is(bounce.cssRules.length, 4, "length of css rules");
  100. bounce.deleteRule("85%");
  101. is(bounce.cssRules.length, 4, "deleteRule should match all keys");
  102. bounce.deleteRule("85%, 75%");
  103. is(bounce.cssRules.length, 4, "deleteRule should match key list");
  104. bounce.deleteRule("75% ,85%");
  105. is(bounce.cssRules.length, 3, "deleteRule should match keys in order, parsed");
  106. bounce.deleteRule("0%");
  107. is(bounce.cssRules.length, 2, "deleteRule should match keys in order, parsed");
  108. bounce.appendRule("from { color: blue }");
  109. is(bounce.cssRules.length, 3, "appendRule should append");
  110. is(bounce.cssRules[2].keyText, "0%", "appendRule should append");
  111. bounce.appendRule("from { color: blue }");
  112. is(bounce.cssRules.length, 4, "appendRule should append");
  113. is(bounce.cssRules[3].keyText, "0%", "appendRule should append");
  114. bounce.appendRule("from { color: blue } to { color: green }");
  115. is(bounce.cssRules.length, 4, "appendRule should ignore garbage at end");
  116. </script>
  117. </pre>
  118. </body>
  119. </html>