3 <script src=
"../../resources/js-test.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("@namespace n url('test');"));
23 styleElement
.appendChild(document
.createTextNode(rule
));
24 return styleElement
.sheet
.cssRules
[1].cssText
;
27 function testSelectorRoundTrip(selector
)
29 shouldBe("parseThenSerializeRule('" + selector
+ " { }')", "'" + selector
+ " { }'");
32 testSelectorRoundTrip('*');
33 testSelectorRoundTrip('a');
34 testSelectorRoundTrip('#a');
35 testSelectorRoundTrip('.a');
36 testSelectorRoundTrip(':active');
37 testSelectorRoundTrip('[a]');
38 testSelectorRoundTrip('[a="b"]');
39 testSelectorRoundTrip('[a~="b"]');
40 testSelectorRoundTrip('[a|="b"]');
41 testSelectorRoundTrip('[a^="b"]');
42 testSelectorRoundTrip('[a$="b"]');
43 testSelectorRoundTrip('[a*="b"]');
47 testSelectorRoundTrip('*|a');
48 testSelectorRoundTrip('n|a');
49 testSelectorRoundTrip('*|*');
50 testSelectorRoundTrip('n|*');
51 testSelectorRoundTrip('[*|a]');
52 testSelectorRoundTrip('[n|a]');
56 testSelectorRoundTrip('a:active');
57 testSelectorRoundTrip('a b');
58 testSelectorRoundTrip('a + b');
59 testSelectorRoundTrip('a ~ b');
60 testSelectorRoundTrip('a > b');
64 testSelectorRoundTrip(":active");
65 testSelectorRoundTrip(":checked");
66 testSelectorRoundTrip(":disabled");
67 testSelectorRoundTrip(":empty");
68 testSelectorRoundTrip(":enabled");
69 testSelectorRoundTrip(":first-child");
70 testSelectorRoundTrip(":first-of-type");
71 testSelectorRoundTrip(":focus");
72 testSelectorRoundTrip(":hover");
73 testSelectorRoundTrip(":indeterminate");
74 testSelectorRoundTrip(":link");
75 testSelectorRoundTrip(":not(:placeholder-shown)");
76 testSelectorRoundTrip(":placeholder-shown");
77 testSelectorRoundTrip(":root");
78 testSelectorRoundTrip(":target");
79 testSelectorRoundTrip(":visited");
83 testSelectorRoundTrip(":lang(a)");
84 testSelectorRoundTrip(":not(a)");
85 testSelectorRoundTrip(":-webkit-any(a,b,p)");
89 testSelectorRoundTrip("::after");
90 testSelectorRoundTrip("::before");
91 testSelectorRoundTrip("::first-letter");
92 testSelectorRoundTrip("::first-line");
93 testSelectorRoundTrip("::selection");
97 testSelectorRoundTrip(":-webkit-any-link");
98 testSelectorRoundTrip(":-webkit-autofill");
99 testSelectorRoundTrip(":-webkit-drag");
103 shouldBe("parseThenSerializeRule('::-webkit-file-upload-button { }')", "'*::-webkit-file-upload-button { }'");
104 shouldBe("parseThenSerializeRule('::-webkit-search-cancel-button { }')", "'*::-webkit-search-cancel-button { }'");
105 shouldBe("parseThenSerializeRule('::-webkit-search-decoration { }')", "'*::-webkit-search-decoration { }'");
106 shouldBe("parseThenSerializeRule('::-webkit-search-results-button { }')", "'*::-webkit-search-results-button { }'");
107 shouldBe("parseThenSerializeRule('::-webkit-search-results-decoration { }')", "'*::-webkit-search-results-decoration { }'");
108 shouldBe("parseThenSerializeRule('::-webkit-slider-thumb { }')", "'*::-webkit-slider-thumb { }'");
112 testSelectorRoundTrip("a::-webkit-slider-thumb");
113 shouldBe("parseThenSerializeRule('a ::-webkit-slider-thumb { }')", "'a *::-webkit-slider-thumb { }'");
114 testSelectorRoundTrip("[a]::-webkit-slider-thumb");
115 shouldBe("parseThenSerializeRule('[a] ::-webkit-slider-thumb { }')", "'[a] *::-webkit-slider-thumb { }'");
116 testSelectorRoundTrip(".a::-webkit-slider-thumb");
117 shouldBe("parseThenSerializeRule('.a ::-webkit-slider-thumb { }')", "'.a *::-webkit-slider-thumb { }'");
118 testSelectorRoundTrip("#a::-webkit-slider-thumb");
119 shouldBe("parseThenSerializeRule('#a ::-webkit-slider-thumb { }')", "'#a *::-webkit-slider-thumb { }'");
120 shouldBe("parseThenSerializeRule('* ::-webkit-slider-thumb { }')", "'* *::-webkit-slider-thumb { }'");
124 testSelectorRoundTrip("a[b]::-webkit-slider-thumb");
125 testSelectorRoundTrip("a.b::-webkit-slider-thumb");
126 testSelectorRoundTrip("a#b::-webkit-slider-thumb");
127 testSelectorRoundTrip("a[b].c#d::-webkit-slider-thumb");
131 testSelectorRoundTrip('input:not([type="file"]):focus');
132 testSelectorRoundTrip(':-webkit-any([type="file"])');
133 testSelectorRoundTrip(':-webkit-any(:hover)');
134 testSelectorRoundTrip('input:-webkit-any([type="file"],:hover,:focus):enabled');
135 testSelectorRoundTrip(':-webkit-any(input[type="file"],a:hover,button:focus)');
136 testSelectorRoundTrip(':-webkit-any(.class1.class2.class3)');
137 testSelectorRoundTrip(':-webkit-any(.class1:hover)');
138 testSelectorRoundTrip(':-webkit-any(a.class1.class2.class3:hover)');
142 shouldBe("parseThenSerializeRule('*:active { }')", "':active { }'");
143 testSelectorRoundTrip("|a");
147 shouldBe("parseThenSerializeRule('input[type=file]:focus { }')", "'input[type=\"file\"]:focus { }'");
151 shouldBe("parseThenSerializeRule('a+b { }')", "'a + b { }'");
152 shouldBe("parseThenSerializeRule('a~b { }')", "'a ~ b { }'");
153 shouldBe("parseThenSerializeRule('a>b { }')", "'a > b { }'");
157 shouldBe("parseThenSerializeRule(':after { }')", "'::after { }'");
158 shouldBe("parseThenSerializeRule(':before { }')", "'::before { }'");
159 shouldBe("parseThenSerializeRule(':first-letter { }')", "'::first-letter { }'");
160 shouldBe("parseThenSerializeRule(':first-line { }')", "'::first-line { }'");
161 shouldBe("parseThenSerializeRule(':-webkit-any( a.class1 , #id,[attr] ) { }')","':-webkit-any(a.class1,#id,[attr]) { }'");