3 <script src="../js/resources/js-test-pre.js"></script>
8 description("This tests parsing and re-serialization of some CSS selectors.");
10 function parseThenSerializeRule(rule)
12 var styleElement = document.getElementById("style");
13 var head = document.getElementById("head");
15 head.removeChild(styleElement);
17 styleElement = document.createElement("style");
18 styleElement.id = "style";
19 var head = document.getElementById("head");
20 head.appendChild(styleElement);
22 styleElement.appendChild(document.createTextNode(rule));
23 return styleElement.sheet.cssRules[0].cssText;
26 function testSelectorRoundTrip(selector)
28 shouldBe("parseThenSerializeRule('" + selector + " { }')", "'" + selector + " { }'");
31 testSelectorRoundTrip('*');
32 testSelectorRoundTrip('a');
33 testSelectorRoundTrip('#a');
34 testSelectorRoundTrip('.a');
35 testSelectorRoundTrip(':active');
36 testSelectorRoundTrip('[a]');
37 testSelectorRoundTrip('[a="b"]');
38 testSelectorRoundTrip('[a~="b"]');
39 testSelectorRoundTrip('[a|="b"]');
40 testSelectorRoundTrip('[a^="b"]');
41 testSelectorRoundTrip('[a$="b"]');
42 testSelectorRoundTrip('[a*="b"]');
46 testSelectorRoundTrip('*|a');
47 testSelectorRoundTrip('n|a');
48 testSelectorRoundTrip('*|*');
49 testSelectorRoundTrip('n|*');
50 testSelectorRoundTrip('[*|a]');
51 testSelectorRoundTrip('[n|a]');
55 testSelectorRoundTrip('a:active');
56 testSelectorRoundTrip('a b');
57 testSelectorRoundTrip('a + b');
58 testSelectorRoundTrip('a ~ b');
59 testSelectorRoundTrip('a > b');
63 testSelectorRoundTrip(":active");
64 testSelectorRoundTrip(":checked");
65 testSelectorRoundTrip(":disabled");
66 testSelectorRoundTrip(":empty");
67 testSelectorRoundTrip(":enabled");
68 testSelectorRoundTrip(":first-child");
69 testSelectorRoundTrip(":first-of-type");
70 testSelectorRoundTrip(":focus");
71 testSelectorRoundTrip(":hover");
72 testSelectorRoundTrip(":indeterminate");
73 testSelectorRoundTrip(":link");
74 testSelectorRoundTrip(":root");
75 testSelectorRoundTrip(":target");
76 testSelectorRoundTrip(":visited");
80 testSelectorRoundTrip(":lang(a)");
81 testSelectorRoundTrip(":not(a)");
82 testSelectorRoundTrip(":-webkit-any(a,b,p)");
86 testSelectorRoundTrip("::after");
87 testSelectorRoundTrip("::before");
88 testSelectorRoundTrip("::first-letter");
89 testSelectorRoundTrip("::first-line");
90 testSelectorRoundTrip("::selection");
94 testSelectorRoundTrip(":-webkit-any-link");
95 testSelectorRoundTrip(":-webkit-autofill");
96 testSelectorRoundTrip(":-webkit-drag");
100 testSelectorRoundTrip("::-webkit-file-upload-button");
101 testSelectorRoundTrip("::-webkit-search-cancel-button");
102 testSelectorRoundTrip("::-webkit-search-decoration");
103 testSelectorRoundTrip("::-webkit-search-results-button");
104 testSelectorRoundTrip("::-webkit-search-results-decoration");
105 testSelectorRoundTrip("::-webkit-slider-thumb");
109 testSelectorRoundTrip('input:not([type="file"]):focus');
110 testSelectorRoundTrip(':-webkit-any([type="file"])');
111 testSelectorRoundTrip(':-webkit-any(:hover)');
112 testSelectorRoundTrip('input:-webkit-any([type="file"],:hover,:focus):enabled');
113 testSelectorRoundTrip(':-webkit-any(input[type="file"],a:hover,button:focus)');
114 testSelectorRoundTrip(':-webkit-any(.class1.class2.class3)');
115 testSelectorRoundTrip(':-webkit-any(.class1:hover)');
116 testSelectorRoundTrip(':-webkit-any(a.class1.class2.class3:hover)');
120 shouldBe("parseThenSerializeRule('*:active { }')", "':active { }'");
121 shouldBe("parseThenSerializeRule('|a { }')", "'a { }'");
125 shouldBe("parseThenSerializeRule('input[type=file]:focus { }')", "'input[type=\"file\"]:focus { }'");
129 shouldBe("parseThenSerializeRule('a+b { }')", "'a + b { }'");
130 shouldBe("parseThenSerializeRule('a~b { }')", "'a ~ b { }'");
131 shouldBe("parseThenSerializeRule('a>b { }')", "'a > b { }'");
135 shouldBe("parseThenSerializeRule(':after { }')", "'::after { }'");
136 shouldBe("parseThenSerializeRule(':before { }')", "'::before { }'");
137 shouldBe("parseThenSerializeRule(':first-letter { }')", "'::first-letter { }'");
138 shouldBe("parseThenSerializeRule(':first-line { }')", "'::first-line { }'");
139 shouldBe("parseThenSerializeRule(':-webkit-any( a.class1 , #id,[attr] ) { }')","':-webkit-any(a.class1,#id,[attr]) { }'");
144 <script src="../js/resources/js-test-post.js"></script>