3 <script src=
"../../resources/js-test.js"></script>
8 description("This tests setting and re-serialization of some CSS selectors.");
10 var bogusSelector
= "_foo";
12 function setThenReadSelectorText(selector
)
14 var styleElement
= document
.getElementById("style");
15 var head
= document
.getElementById("head");
17 head
.removeChild(styleElement
);
19 styleElement
= document
.createElement("style");
20 styleElement
.id
= "style";
21 var head
= document
.getElementById("head");
22 head
.appendChild(styleElement
);
24 // First, create a rule with a bogus selector.
25 styleElement
.appendChild(document
.createTextNode(bogusSelector
+ " { }"));
26 // Now, set the desired selector text.
27 styleElement
.sheet
.cssRules
[0].selectorText
= selector
;
28 return styleElement
.sheet
.cssRules
[0].selectorText
;
31 function testSelectorRoundTrip(selector
, expectFailure
)
33 shouldBe("setThenReadSelectorText('" + selector
+ "')", "'" + (expectFailure
? bogusSelector
: selector
) + "'");
36 testSelectorRoundTrip('', true);
37 testSelectorRoundTrip('123', true);
38 testSelectorRoundTrip('-', true);
39 testSelectorRoundTrip('$', true);
40 testSelectorRoundTrip(':', true);
41 testSelectorRoundTrip('.', true);
42 testSelectorRoundTrip('#', true);
43 testSelectorRoundTrip('[]', true);
44 testSelectorRoundTrip('()', true);
48 testSelectorRoundTrip('*');
49 testSelectorRoundTrip('a');
50 testSelectorRoundTrip('#a');
51 testSelectorRoundTrip('.a');
52 testSelectorRoundTrip(':active');
53 testSelectorRoundTrip('[a]');
54 testSelectorRoundTrip('[a="b"]');
55 testSelectorRoundTrip('[a~="b"]');
56 testSelectorRoundTrip('[a|="b"]');
57 testSelectorRoundTrip('[a^="b"]');
58 testSelectorRoundTrip('[a$="b"]');
59 testSelectorRoundTrip('[a*="b"]');
63 testSelectorRoundTrip('*|a');
64 testSelectorRoundTrip('n|a');
65 testSelectorRoundTrip('*|*');
66 testSelectorRoundTrip('n|*');
67 testSelectorRoundTrip('[*|a]');
68 testSelectorRoundTrip('[n|a]');
72 testSelectorRoundTrip('a:active');
73 testSelectorRoundTrip('a b');
74 testSelectorRoundTrip('a + b');
75 testSelectorRoundTrip('a ~ b');
76 testSelectorRoundTrip('a > b');
80 testSelectorRoundTrip(":active");
81 testSelectorRoundTrip(":checked");
82 testSelectorRoundTrip(":disabled");
83 testSelectorRoundTrip(":empty");
84 testSelectorRoundTrip(":enabled");
85 testSelectorRoundTrip(":first-child");
86 testSelectorRoundTrip(":first-of-type");
87 testSelectorRoundTrip(":focus");
88 testSelectorRoundTrip(":hover");
89 testSelectorRoundTrip(":indeterminate");
90 testSelectorRoundTrip(":link");
91 testSelectorRoundTrip(":not(:placeholder-shown)");
92 testSelectorRoundTrip(":placeholder-shown");
93 testSelectorRoundTrip(":root");
94 testSelectorRoundTrip(":target");
95 testSelectorRoundTrip(":visited");
99 testSelectorRoundTrip(":lang(a)");
100 testSelectorRoundTrip(":not(a)");
101 testSelectorRoundTrip(":-webkit-any(a,b,p)");
105 testSelectorRoundTrip("::after");
106 testSelectorRoundTrip("::before");
107 testSelectorRoundTrip("::first-letter");
108 testSelectorRoundTrip("::first-line");
109 testSelectorRoundTrip("::selection");
113 testSelectorRoundTrip(":-webkit-any-link");
114 testSelectorRoundTrip(":-webkit-autofill");
115 testSelectorRoundTrip(":-webkit-drag");
119 shouldBe("setThenReadSelectorText('::-webkit-file-upload-button')", "'*::-webkit-file-upload-button'");
120 shouldBe("setThenReadSelectorText('::-webkit-search-cancel-button')", "'*::-webkit-search-cancel-button'");
121 shouldBe("setThenReadSelectorText('::-webkit-search-decoration')", "'*::-webkit-search-decoration'");
122 shouldBe("setThenReadSelectorText('::-webkit-search-results-button')", "'*::-webkit-search-results-button'");
123 shouldBe("setThenReadSelectorText('::-webkit-search-results-decoration')", "'*::-webkit-search-results-decoration'");
124 shouldBe("setThenReadSelectorText('::-webkit-slider-thumb')", "'*::-webkit-slider-thumb'");
128 testSelectorRoundTrip("a::-webkit-slider-thumb");
129 shouldBe("setThenReadSelectorText('a ::-webkit-slider-thumb')", "'a *::-webkit-slider-thumb'");
130 testSelectorRoundTrip("[a]::-webkit-slider-thumb");
131 shouldBe("setThenReadSelectorText('[a] ::-webkit-slider-thumb')", "'[a] *::-webkit-slider-thumb'");
132 testSelectorRoundTrip(".a::-webkit-slider-thumb");
133 shouldBe("setThenReadSelectorText('.a ::-webkit-slider-thumb')", "'.a *::-webkit-slider-thumb'");
134 testSelectorRoundTrip("#a::-webkit-slider-thumb");
135 shouldBe("setThenReadSelectorText('#a ::-webkit-slider-thumb')", "'#a *::-webkit-slider-thumb'");
136 shouldBe("setThenReadSelectorText('* ::-webkit-slider-thumb')", "'* *::-webkit-slider-thumb'");
140 testSelectorRoundTrip("a[b]::-webkit-slider-thumb");
141 testSelectorRoundTrip("a.b::-webkit-slider-thumb");
142 testSelectorRoundTrip("a#b::-webkit-slider-thumb");
143 testSelectorRoundTrip("a[b].c#d::-webkit-slider-thumb");
147 testSelectorRoundTrip('input:not([type="file"]):focus');
148 testSelectorRoundTrip(':-webkit-any([type="file"])');
149 testSelectorRoundTrip(':-webkit-any(:hover)');
150 testSelectorRoundTrip('input:-webkit-any([type="file"],:hover,:focus):enabled');
151 testSelectorRoundTrip(':-webkit-any(input[type="file"],a:hover,button:focus)');
152 testSelectorRoundTrip(':-webkit-any(.class1.class2.class3)');
153 testSelectorRoundTrip(':-webkit-any(.class1:hover)');
154 testSelectorRoundTrip(':-webkit-any(a.class1.class2.class3:hover)');
158 shouldBe("setThenReadSelectorText('*:active')", "':active'");
159 testSelectorRoundTrip("|a");
163 shouldBe("setThenReadSelectorText('input[type=file]:focus')", "'input[type=\"file\"]:focus'");
167 shouldBe("setThenReadSelectorText('a+b')", "'a + b'");
168 shouldBe("setThenReadSelectorText('a~b')", "'a ~ b'");
169 shouldBe("setThenReadSelectorText('a>b')", "'a > b'");
173 shouldBe("setThenReadSelectorText(':after')", "'::after'");
174 shouldBe("setThenReadSelectorText(':before')", "'::before'");
175 shouldBe("setThenReadSelectorText(':first-letter')", "'::first-letter'");
176 shouldBe("setThenReadSelectorText(':first-line')", "'::first-line'");
177 shouldBe("setThenReadSelectorText(':-webkit-any( a.class1 , #id,[attr] )')","':-webkit-any(a.class1,#id,[attr])'");