blob: 541654ad831ef5b6f0a99847852e7f61fa8ba122 [file] [log] [blame]
ojan@chromium.org5858c5d2011-03-23 01:44:38 +00001<!DOCTYPE HTML>
mark.lam@apple.com104d9932013-09-07 22:20:15 +00002<script src="../../resources/js-test-pre.js"></script>
ojan@chromium.org5858c5d2011-03-23 01:44:38 +00003<style>
4:-webkit-any(h1),
5:-webkit-any( #div1, b ),
6:-webkit-any(.foo, #bar),
7:-webkit-any(i,p,:link,span:focus) {
8 background-color: blue;
9}
10
ojan@chromium.org3fd44ea2011-03-29 02:30:37 +000011#test-last-child :-webkit-any(:last-child),
ojan@chromium.org5858c5d2011-03-23 01:44:38 +000012:-webkit-any(:link:focus),
13#container-div :-webkit-any(:link, :not(a)),
14h1:-webkit-any(.h1class, #bar) {
15 background-color: green;
16}
17
18/* Only simple selectors should work. */
19:-webkit-any() {
20 background-color: red;
21}
22
23:-webkit-any(s,:nonexistentpseudo) {
24 background-color: red;
25}
26
27div~q {
28 background-color: blue;
29}
30:-webkit-any(div ~ q) {
31 background-color: red;
32}
33:-webkit-any(div~q) {
34 background-color: red;
35}
36
37q+q {
38 background-color: blue;
39}
40:-webkit-any(q+q) {
41 background-color: red;
42}
43
44q>span {
45 background-color: blue;
46}
47:-webkit-any(q>span) {
48 background-color: red;
49}
50
51div span {
52 background-color: blue;
53}
54:-webkit-any(div span) {
55 background-color: red;
56}
57:-webkit-any( div span ) {
58 background-color: red;
59}
60</style>
61This page tests :-webkit-any. This window needs to be focused for the :focus tests to pass.<br>
62<h1>h1</h1>
63<h1 class="h1class">h1</h1>
64<div id="div1">div</div>
65<div>foo</div>
66<b>b</b>
67<i>i</i>
68<p>p</p>
69<a href="http://webkit.org">a</a>
70<span id="span1">span<span>
71<li class="foo">li</li>
72<u id="bar">u</u>
73<s>s</s>
74<div id="container-div"><input type='text'><a href='http://www.example.com/'></a><div></div><a name='foo'></div>
75<div><span>div span</span></div>
76<q>div~q</q>
77<q>q+q</q>
78<q><span>q>span</span></q>
ojan@chromium.org3fd44ea2011-03-29 02:30:37 +000079<div id="test-last-child"><p>first</p><p>last</p></div>
ojan@chromium.org5858c5d2011-03-23 01:44:38 +000080<pre id="console"></pre>
81
82<script>
rniwa@webkit.org38608af2012-06-19 07:23:13 +000083if (window.testRunner)
84 testRunner.dumpAsText();
ojan@chromium.org5858c5d2011-03-23 01:44:38 +000085
86function assertColor(selectorOrElement, rbgColor)
87{
88 debug("");
89
90 if (typeof selectorOrElement == "string") {
91 debug(selectorOrElement);
92 element = document.querySelector(selectorOrElement);
93 } else {
94 debug("Element: " + element.nodeName);
95 element = selectorOrElement;
96 }
97
98 shouldBe("document.defaultView.getComputedStyle(element, null).getPropertyValue('background-color')", rbgColor);
99}
100
101function assertBlue(selectorOrElement)
102{
103 assertColor(selectorOrElement, "'rgb(0, 0, 255)'")
104}
105
106function assertWhite(selectorOrElement)
107{
108 assertColor(selectorOrElement, "'rgba(0, 0, 0, 0)'")
109}
110
111function assertGreen(selectorOrElement)
112{
113 assertColor(selectorOrElement, "'rgb(0, 128, 0)'")
114}
115
116function focus(selector)
117{
118 var element = document.querySelector(selector);
119 element.tabIndex = -1;
120 element.focus();
121}
122
123assertBlue("h1");
124assertBlue("#div1");
125
126// Ensure the div with ID after the first div does not share a RenderStyle with the first div.
127assertWhite(document.querySelectorAll("div")[1]);
128
129assertBlue("b");
130assertBlue("i");
131assertBlue("p");
132
133assertWhite("#span1");
134focus("#span1");
135assertBlue("span:focus");
136
137assertBlue("a");
138focus("a");
139assertGreen("a:focus");
140
141assertBlue(".foo");
142assertBlue("#bar");
143
144assertGreen("h1.h1class");
145
146debug("");
147shouldBe("document.querySelectorAll('#container-div :-webkit-any([href],input[type],input[name])').length", "2");
148shouldBe("document.querySelectorAll('#container-div :-webkit-any(div,a):-webkit-any([type],[href],[name])').length", "2");
149shouldBe("document.querySelectorAll('#container-div :-webkit-any(:link, :not(a))').length", "3");
150assertGreen("#container-div input");
151assertGreen("#container-div a[href]");
152assertGreen("#container-div div");
153assertWhite("#container-div a[name]");
154
155assertWhite("s");
156assertBlue("div span");
157assertBlue("div ~ q");
158assertBlue("q+q");
159assertBlue("q>span");
ojan@chromium.org3fd44ea2011-03-29 02:30:37 +0000160
161assertBlue("#test-last-child :first-child");
162assertGreen("#test-last-child :last-child");
ojan@chromium.org5858c5d2011-03-23 01:44:38 +0000163</script>