PageRenderTime 73ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/third_party/blink/web_tests/external/wpt/css/cssom/selectorSerialize.html

https://github.com/chromium/chromium
HTML | 121 lines | 105 code | 16 blank | 0 comment | 0 complexity | 9df6469030bf4ed1f31d9f8a1d8da47e MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, Apache-2.0, BSD-3-Clause
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>CSSOM Test: test serialized selector which is only one simple selector in the sequence of simple selectors</title>
  5. <link rel="author" title="T.Nishitani" href="mailto:lequinharay@gmail.com">
  6. <link rel="reviewer" title="L. David Baron" href="https://dbaron.org/">
  7. <link rel="help" href="https://drafts.csswg.org/cssom-1/#serializing-selectors">
  8. <meta name="flags" content="dom">
  9. <meta charset="utf-8">
  10. <script src="/resources/testharness.js"></script>
  11. <script src="/resources/testharnessreport.js"></script>
  12. <style id="teststyles">
  13. </style>
  14. </head>
  15. <body>
  16. <div id="log"></div>
  17. <script>
  18. function assert_selector_serializes_to(source, expected_result) {
  19. var style_element = document.getElementById("teststyles");
  20. style_element.firstChild.data = source + "{ font-size: 1em; }";
  21. var sheet = style_element.sheet;
  22. assert_equals(sheet.cssRules[sheet.cssRules.length - 1].selectorText, expected_result);
  23. }
  24. function run_tests_on_anplusb_selector(source) {
  25. assert_selector_serializes_to(source + '( even )', source + '(2n)');
  26. assert_selector_serializes_to(source + '( odd )', source + '(2n+1)');
  27. assert_selector_serializes_to(source + '( +10 )', source + '(10)');
  28. assert_selector_serializes_to(source + '( -10 )', source + '(-10)');
  29. assert_selector_serializes_to(source + '( +4n )', source + '(4n)');
  30. assert_selector_serializes_to(source + '( -3n )', source + '(-3n)');
  31. assert_selector_serializes_to(source + '( 1n + 5 )', source + '(n+5)');
  32. assert_selector_serializes_to(source + '( -1n + 5 )', source + '(-n+5)');
  33. assert_selector_serializes_to(source + '( -1n - 5 )', source + '(-n-5)');
  34. }
  35. test(function() {
  36. assert_selector_serializes_to(":nth-child( 3n - 0)", ":nth-child(3n)");
  37. assert_selector_serializes_to(":nth-child( 1n - 0)", ":nth-child(n)");
  38. }, ":nth-child serialization produces canonical form");
  39. /* for universal selecter with default namespace */
  40. test(function(){
  41. /* this is single universal selector */
  42. assert_selector_serializes_to('*', '*');
  43. assert_selector_serializes_to(' * ', '*');
  44. }, 'single universal selector shows \'*\' when serialized.')
  45. test(function(){
  46. assert_selector_serializes_to('div', 'div');
  47. assert_selector_serializes_to(' div ', 'div');
  48. }, 'single type (simple) selector in the sequence of simple selectors that is not a universal selector')
  49. test(function(){
  50. assert_selector_serializes_to('.class', '.class');
  51. assert_selector_serializes_to(' .class ', '.class');
  52. }, 'single class (simple) selector in the sequence of simple selectors that is not a universal selector')
  53. test(function(){
  54. assert_selector_serializes_to('#id', '#id');
  55. assert_selector_serializes_to(' #id ', '#id');
  56. }, 'single id (simple) selector in the sequence of simple selectors that is not a universal selector')
  57. test(function(){
  58. assert_selector_serializes_to(':hover', ':hover');
  59. assert_selector_serializes_to(' :hover ', ':hover');
  60. }, 'single pseudo (simple) selector which does not accept arguments in the sequence of simple selectors that is not a universal selector')
  61. test(function(){
  62. assert_selector_serializes_to(':lang(ja)', ':lang(ja)');
  63. assert_selector_serializes_to(':lang( ja )', ':lang(ja)');
  64. assert_selector_serializes_to(':lang( j\\ a )', ':lang(j\\ a)');
  65. }, 'single pseudo (simple) selector "lang" which accepts arguments in the sequence of simple selectors that is not a universal selector')
  66. test(function(){
  67. run_tests_on_anplusb_selector(':nth-child');
  68. }, 'single pseudo (simple) selector "nth-child" which accepts arguments in the sequence of simple selectors that is not a universal selector')
  69. test(function(){
  70. run_tests_on_anplusb_selector(':nth-last-child');
  71. }, 'single pseudo (simple) selector "nth-last-child" which accepts arguments in the sequence of simple selectors that is not a universal selector')
  72. test(function(){
  73. run_tests_on_anplusb_selector(':nth-of-type');
  74. }, 'single pseudo (simple) selector "nth-of-child" which accepts arguments in the sequence of simple selectors that is not a universal selector')
  75. test(function(){
  76. run_tests_on_anplusb_selector(':nth-last-of-type');
  77. }, 'single pseudo (simple) selector ":nth-last-of-type" which accepts arguments in the sequence of simple selectors that is not a universal selector')
  78. test(function(){
  79. assert_selector_serializes_to(' :not( abc ) ', ':not(abc)');
  80. assert_selector_serializes_to(' :not( .head ) ', ':not(.head)');
  81. assert_selector_serializes_to(' :not( #head ) ', ':not(#head)');
  82. assert_selector_serializes_to(' :not( :hover ) ', ':not(:hover)');
  83. }, 'single pseudo (simple) selector ":not" which accepts arguments in the sequence of simple selectors that is not a universal selector')
  84. var escaped_ns_rule = "@namespace ns\\:odd url(ns);";
  85. test(function() {
  86. assert_selector_serializes_to("[ns\\:foo]", "[ns\\:foo]");
  87. }, "escaped character in attribute name");
  88. test(function() {
  89. assert_selector_serializes_to("[\\30zonk]", "[\\30 zonk]");
  90. }, "escaped character as code point in attribute name");
  91. test(function() {
  92. assert_selector_serializes_to("[\\@]", "[\\@]");
  93. }, "escaped character (@) in attribute name");
  94. test(function() {
  95. assert_selector_serializes_to("[*|ns\\:foo]", "[*|ns\\:foo]");
  96. }, "escaped character in attribute name with any namespace");
  97. test(function() {
  98. assert_selector_serializes_to(escaped_ns_rule + "[ns\\:odd|foo]", "[ns\\:odd|foo]");
  99. }, "escaped character in attribute prefix");
  100. test(function() {
  101. assert_selector_serializes_to(escaped_ns_rule + "[ns\\:odd|odd\\:name]", "[ns\\:odd|odd\\:name]");
  102. }, "escaped character in both attribute prefix and name");
  103. </script>
  104. </body>
  105. </html>