1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
<!DOCTYPE html>
<html>
<head>
<title>CSS Selectors Invalidation: sibling</title>
<link rel="help" href="https://drafts.csswg.org/selectors-4/#adjacent-sibling-combinators">
<link rel="help" href="https://drafts.csswg.org/selectors-4/#general-sibling-combinators">
<meta name="assert" content="This tests that the + next-sibling selector is effective">
<meta name="assert" content="This tests that the ~ subsequent-sibling selector is effective">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
* { background-color: inherit; }
body { background-color: rgba(0, 0, 0, 0); }
.t1 .sibling + *,
.t2 .sibling ~ *,
.t3 + .sibling + *,
.t4 + .sibling,
.t5 + *,
.t6 ~ .sibling,
.t7 + * + * .child { background-color: rgb(0, 128, 0); }
</style>
</head>
<body>
<div>
<div id="t1">
<div class="sibling"></div>
<div id="r1"></div>
<div id="u1"></div>
</div>
</div>
<div>
<div id="t2">
<div class="sibling"></div>
<div></div>
<div id="r2"></div>
</div>
</div>
<div>
<div id="t3"></div>
<div class="sibling"></div>
<div id="r3"></div>
</div>
<div>
<div id="t4"></div>
<div id="r4" class="sibling"></div>
<div id="u4" class="sibling"></div>
</div>
<div>
<div id="t5"></div>
<div id="r5"></div>
<div id="u5"></div>
</div>
<div>
<div id="t6"></div>
<div></div>
<div id="r6" class="sibling">
<div id="r6b"></div>
</div>
<div id="u6"></div>
</div>
<div>
<div id="t7">
<div class="child"></div>
</div>
<div></div>
<div>
<div id="r7" class="child"></div>
</div>
<div>
<div id="u7" class="child"></div>
</div>
</div>
<script>
test(function() {
assert_equals(getComputedStyle(r1).backgroundColor, "rgba(0, 0, 0, 0)", "Background color should initially be transparent");
t1.className = "t1";
assert_equals(getComputedStyle(r1).backgroundColor, "rgb(0, 128, 0)", "Background color is green after class change");
assert_equals(getComputedStyle(u1).backgroundColor, "rgba(0, 0, 0, 0)", "Background color remains transparent");
}, "Adjacent with universal selector");
test(function() {
assert_equals(getComputedStyle(r2).backgroundColor, "rgba(0, 0, 0, 0)", "Background color should initially be transparent");
t2.className = "t2";
assert_equals(getComputedStyle(r2).backgroundColor, "rgb(0, 128, 0)", "Background color is green after class change");
}, "Indirect adjacent with universal selector");
test(function() {
assert_equals(getComputedStyle(r3).backgroundColor, "rgba(0, 0, 0, 0)", "Background color should initially be transparent");
t3.className = "t3";
assert_equals(getComputedStyle(r3).backgroundColor, "rgb(0, 128, 0)", "Background color is green after class change");
}, "Indirect adjacent with two adjacent selectors");
test(function() {
assert_equals(getComputedStyle(r4).backgroundColor, "rgba(0, 0, 0, 0)", "Background color should initially be transparent");
t4.className = "t4";
assert_equals(getComputedStyle(r4).backgroundColor, "rgb(0, 128, 0)", "Background color is green after class change");
assert_equals(getComputedStyle(u4).backgroundColor, "rgba(0, 0, 0, 0)", "Background color remains transparent");
}, "Adjacent class");
test(function() {
assert_equals(getComputedStyle(r5).backgroundColor, "rgba(0, 0, 0, 0)", "Background color should initially be transparent");
t5.className = "t5";
assert_equals(getComputedStyle(r5).backgroundColor, "rgb(0, 128, 0)", "Background color is green after class change");
assert_equals(getComputedStyle(u5).backgroundColor, "rgba(0, 0, 0, 0)", "Background color remains transparent");
}, "Adjacent universal");
test(function() {
assert_equals(getComputedStyle(r6).backgroundColor, "rgba(0, 0, 0, 0)", "Background color should initially be transparent");
assert_equals(getComputedStyle(r6b).backgroundColor, "rgba(0, 0, 0, 0)", "Child's background color should initially be transparent");
t6.className = "t6";
assert_equals(getComputedStyle(r6).backgroundColor, "rgb(0, 128, 0)", "Background color is green after class change");
assert_equals(getComputedStyle(r6b).backgroundColor, "rgb(0, 128, 0)", "Child's background color is green after class change");
assert_equals(getComputedStyle(u6).backgroundColor, "rgba(0, 0, 0, 0)", "Background color remains transparent");
}, "Sibling subtree through an indirect adjacent combinator");
test(function() {
assert_equals(getComputedStyle(r7).backgroundColor, "rgba(0, 0, 0, 0)", "Background color should initially be transparent");
t7.className = "t7";
assert_equals(getComputedStyle(r7).backgroundColor, "rgb(0, 128, 0)", "Background color is green after class change");
assert_equals(getComputedStyle(u7).backgroundColor, "rgba(0, 0, 0, 0)", "Background color remains transparent");
}, "Sibling descendant through a universal selector");
</script>
</body>
</html>
|