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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
|
<!DOCTYPE html>
<meta charset="utf-8">
<title>:has pseudo class behavior with various relative arguments</title>
<link rel="author" title="Byungwoo Lee" href="mailto:blee@igalia.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="https://drafts.csswg.org/selectors/#relational">
<main id=main>
<div id=d01>
<div id=d02 class="x">
<div id=d03 class="a"></div>
<div id=d04></div>
<div id=d05 class="b"></div>
</div>
<div id=d06 class="x">
<div id=d07 class="x">
<div id=d08 class="a"></div>
</div>
</div>
<div id=d09 class="x">
<div id=d10 class="a">
<div id=d11 class="b"></div>
</div>
</div>
<div id=d12 class="x">
<div id=d13 class="a">
<div id=d14>
<div id=d15 class="b"></div>
</div>
</div>
<div id=d16 class="b"></div>
</div>
</div>
<div id=d17>
<div id=d18 class="x"></div>
<div id=d19 class="x"></div>
<div id=d20 class="a"></div>
<div id=d21 class="x"></div>
<div id=d22 class="a">
<div id=d23 class="b"></div>
</div>
<div id=d24 class="x"></div>
<div id=d25 class="a">
<div id=d26>
<div id=d27 class="b"></div>
</div>
</div>
<div id=d28 class="x"></div>
<div id=d29 class="a"></div>
<div id=d30 class="b">
<div id=d31 class="c"></div>
</div>
<div id=d32 class="x"></div>
<div id=d33 class="a"></div>
<div id=d34 class="b">
<div id=d35>
<div id=d36 class="c"></div>
</div>
</div>
<div id=d37 class="x"></div>
<div id=d38 class="a"></div>
<div id=d39 class="b"></div>
<div id=d40 class="x"></div>
<div id=d41 class="a"></div>
<div id=d42></div>
<div id=d43 class="b">
<div id=d44 class="x">
<div id=d45 class="c"></div>
</div>
</div>
<div id=d46 class="x"></div>
<div id=d47 class="a">
</div>
</div>
<div>
<div id=d48 class="x">
<div id=d49 class="x">
<div id=d50 class="x d">
<div id=d51 class="x d">
<div id=d52 class="x">
<div id=d53 class="x e">
<div id=d54 class="f"></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div id=d55 class="x"></div>
<div id=d56 class="x d"></div>
<div id=d57 class="x d"></div>
<div id=d58 class="x"></div>
<div id=d59 class="x e"></div>
<div id=d60 class="f"></div>
</div>
<div>
<div id=d61 class="x"></div>
<div id=d62 class="x y"></div>
<div id=d63 class="x y">
<div id=d64 class="y g">
<div id=d65 class="y">
<div id=d66 class="y h">
<div id=d67 class="i"></div>
</div>
</div>
</div>
</div>
<div id=d68 class="x y">
<div id=d69 class="x"></div>
<div id=d70 class="x"></div>
<div id=d71 class="x y">
<div id=d72 class="y g">
<div id=d73 class="y">
<div id=d74 class="y h">
<div id=d75 class="i"></div>
</div>
</div>
</div>
</div>
<div id=d76 class="x"></div>
<div id=d77 class="j"><div id=d78><div id=d79></div></div></div>
</div>
<div id=d80 class="j"></div>
</div>
</main>
<script>
function formatElements(elements) {
return elements.map(e => e.id).sort().join();
}
// Test that |selector| returns the given elements in #main.
function test_selector_all(selector, expected) {
test(function() {
let actual = Array.from(main.querySelectorAll(selector));
assert_equals(formatElements(actual), formatElements(expected));
}, `${selector} matches expected elements`);
}
test_selector_all('.x:has(:scope .a)', [d02, d06, d07, d09, d12]);
test_selector_all('.x:has(:scope .a > .b)', [d09]);
test_selector_all('.x:has(:scope .a .b)', [d09, d12]);
test_selector_all('.x:has(:scope .a + .b)', [d12]);
test_selector_all('.x:has(:scope .a ~ .b)', [d02, d12]);
test_selector_all(':has(.x:scope .a)', [d02, d06, d07, d09, d12]);
test_selector_all(':has(.x:scope .a > .b)', [d09]);
test_selector_all(':has(.x:scope .a .b)', [d09, d12]);
test_selector_all(':has(.x:scope .a + .b)', [d12]);
test_selector_all(':has(.x:scope .a ~ .b)', [d02, d12]);
test_selector_all(':has(:scope.x .a)', [d02, d06, d07, d09, d12]);
test_selector_all(':has(:scope.x .a > .b)', [d09]);
test_selector_all(':has(:scope.x .a .b)', [d09, d12]);
test_selector_all(':has(:scope.x .a + .b)', [d12]);
test_selector_all(':has(:scope.x .a ~ .b)', [d02, d12]);
test_selector_all('.x:has(:scope > .a)', [d02, d07, d09, d12]);
test_selector_all('.x:has(:scope > .a > .b)', [d09]);
test_selector_all('.x:has(:scope > .a .b)', [d09, d12]);
test_selector_all('.x:has(:scope > .a + .b)', [d12]);
test_selector_all('.x:has(:scope > .a ~ .b)', [d02, d12]);
test_selector_all(':has(.x:scope > .a)', [d02, d07, d09, d12]);
test_selector_all(':has(.x:scope > .a > .b)', [d09]);
test_selector_all(':has(.x:scope > .a .b)', [d09, d12]);
test_selector_all(':has(.x:scope > .a + .b)', [d12]);
test_selector_all(':has(.x:scope > .a ~ .b)', [d02, d12]);
test_selector_all(':has(:scope.x > .a)', [d02, d07, d09, d12]);
test_selector_all(':has(:scope.x > .a > .b)', [d09]);
test_selector_all(':has(:scope.x > .a .b)', [d09, d12]);
test_selector_all(':has(:scope.x > .a + .b)', [d12]);
test_selector_all(':has(:scope.x > .a ~ .b)', [d02, d12]);
test_selector_all('.x:has(:scope + .a)', [d19, d21, d24, d28, d32, d37, d40, d46]);
test_selector_all('.x:has(:scope + .a > .b)', [d21]);
test_selector_all('.x:has(:scope + .a .b)', [d21, d24]);
test_selector_all('.x:has(:scope + .a + .b)', [d28, d32, d37]);
test_selector_all('.x:has(:scope + .a ~ .b)', [d19, d21, d24, d28, d32, d37, d40]);
test_selector_all(':has(.x:scope + .a)', [d19, d21, d24, d28, d32, d37, d40, d46]);
test_selector_all(':has(.x:scope + .a > .b)', [d21]);
test_selector_all(':has(.x:scope + .a .b)', [d21, d24]);
test_selector_all(':has(.x:scope + .a + .b)', [d28, d32, d37]);
test_selector_all(':has(.x:scope + .a ~ .b)', [d19, d21, d24, d28, d32, d37, d40]);
test_selector_all(':has(:scope.x + .a)', [d19, d21, d24, d28, d32, d37, d40, d46]);
test_selector_all(':has(:scope.x + .a > .b)', [d21]);
test_selector_all(':has(:scope.x + .a .b)', [d21, d24]);
test_selector_all(':has(:scope.x + .a + .b)', [d28, d32, d37]);
test_selector_all(':has(:scope.x + .a ~ .b)', [d19, d21, d24, d28, d32, d37, d40]);
test_selector_all('.x:has(:scope ~ .a)', [d18, d19, d21, d24, d28, d32, d37, d40, d46]);
test_selector_all('.x:has(:scope ~ .a > .b)', [d18, d19, d21]);
test_selector_all('.x:has(:scope ~ .a .b)', [d18, d19, d21, d24]);
test_selector_all('.x:has(:scope ~ .a + .b)', [d18, d19, d21, d24, d28, d32, d37]);
test_selector_all('.x:has(:scope ~ .a + .b > .c)', [d18, d19, d21, d24, d28]);
test_selector_all('.x:has(:scope ~ .a + .b .c)', [d18, d19, d21, d24, d28, d32]);
test_selector_all(':has(.x:scope ~ .a)', [d18, d19, d21, d24, d28, d32, d37, d40, d46]);
test_selector_all(':has(.x:scope ~ .a > .b)', [d18, d19, d21]);
test_selector_all(':has(.x:scope ~ .a .b)', [d18, d19, d21, d24]);
test_selector_all(':has(.x:scope ~ .a + .b)', [d18, d19, d21, d24, d28, d32, d37]);
test_selector_all(':has(.x:scope ~ .a + .b > .c)', [d18, d19, d21, d24, d28]);
test_selector_all(':has(.x:scope ~ .a + .b .c)', [d18, d19, d21, d24, d28, d32]);
test_selector_all(':has(:scope.x ~ .a)', [d18, d19, d21, d24, d28, d32, d37, d40, d46]);
test_selector_all(':has(:scope.x ~ .a > .b)', [d18, d19, d21]);
test_selector_all(':has(:scope.x ~ .a .b)', [d18, d19, d21, d24]);
test_selector_all(':has(:scope.x ~ .a + .b)', [d18, d19, d21, d24, d28, d32, d37]);
test_selector_all(':has(:scope.x ~ .a + .b > .c)', [d18, d19, d21, d24, d28]);
test_selector_all(':has(:scope.x ~ .a + .b .c)', [d18, d19, d21, d24, d28, d32]);
test_selector_all('.x:has(.d .e)', [d48, d49, d50]);
test_selector_all('.x:has(.d .e) .f', [d54]);
test_selector_all('.x:has(:scope .d .e)', [d48, d49, d50]);
test_selector_all('.x:has(:scope .d .e) .f', [d54]);
test_selector_all('.x:has(:scope > .d)', [d49, d50]);
test_selector_all('.x:has(:scope > .d) .f', [d54]);
test_selector_all('.x:has(:scope ~ .d ~ .e)', [d48, d55, d56]);
test_selector_all('.x:has(:scope ~ .d ~ .e) ~ .f', [d60]);
test_selector_all('.x:has(:scope + .d ~ .e)', [d55, d56]);
test_selector_all('.x:has(:scope + .d ~ .e) ~ .f', [d60]);
test_selector_all(':has(.x:scope .d .e)', [d48, d49, d50]);
test_selector_all(':has(.x:scope .d .e) .f', [d54]);
test_selector_all(':has(.x:scope > .d)', [d49, d50]);
test_selector_all(':has(.x:scope > .d) .f', [d54]);
test_selector_all(':has(.x:scope ~ .d ~ .e)', [d48, d55, d56]);
test_selector_all(':has(.x:scope ~ .d ~ .e) ~ .f', [d60]);
test_selector_all(':has(.x:scope + .d ~ .e)', [d55, d56]);
test_selector_all(':has(.x:scope + .d ~ .e) ~ .f', [d60]);
test_selector_all(':has(:scope.x .d .e)', [d48, d49, d50]);
test_selector_all(':has(:scope.x .d .e) .f', [d54]);
test_selector_all(':has(:scope.x > .d)', [d49, d50]);
test_selector_all(':has(:scope.x > .d) .f', [d54]);
test_selector_all(':has(:scope.x ~ .d ~ .e)', [d48, d55, d56]);
test_selector_all(':has(:scope.x ~ .d ~ .e) ~ .f', [d60]);
test_selector_all(':has(:scope.x + .d ~ .e)', [d55, d56]);
test_selector_all(':has(:scope.x + .d ~ .e) ~ .f', [d60]);
test_selector_all('.y:has(:scope > .g .h)', [d63, d71])
test_selector_all('.y:has(:scope .g .h)', [d63, d68, d71])
test_selector_all('.y:has(:scope > .g .h) .i', [d67, d75])
test_selector_all('.y:has(:scope .g .h) .i', [d67, d75])
test_selector_all('.x:has(:scope + .y:has(:scope > .g .h) .i)', [d62, d70])
test_selector_all('.x:has(:scope + .y:has(:scope .g .h) .i)', [d62, d63, d70])
test_selector_all('.x:has(:scope + .y:has(:scope > .g .h) .i) ~ .j', [d77, d80])
test_selector_all('.x:has(:scope + .y:has(:scope .g .h) .i) ~ .j', [d77, d80])
test_selector_all('.x:has(:scope ~ .y:has(:scope > .g .h) .i)', [d61, d62, d69, d70])
test_selector_all('.x:has(:scope ~ .y:has(:scope .g .h) .i)', [d61, d62, d63, d69, d70])
test_selector_all(':has(.y:scope > .g .h)', [d63, d71])
test_selector_all(':has(.y:scope .g .h)', [d63, d68, d71])
test_selector_all(':has(.y:scope > .g .h) .i', [d67, d75])
test_selector_all(':has(.y:scope .g .h) .i', [d67, d75])
test_selector_all(':has(.x:scope + :has(.y:scope > .g .h) .i)', [d62, d70])
test_selector_all(':has(.x:scope + :has(.y:scope .g .h) .i)', [d62, d63, d70])
test_selector_all(':has(.x:scope + :has(.y:scope > .g .h) .i) ~ .j', [d77, d80])
test_selector_all(':has(.x:scope + :has(.y:scope .g .h) .i) ~ .j', [d77, d80])
test_selector_all(':has(.x:scope ~ :has(.y:scope > .g .h) .i)', [d61, d62, d69, d70])
test_selector_all(':has(.x:scope ~ :has(.y:scope .g .h) .i)', [d61, d62, d63, d69, d70])
test_selector_all(':has(:scope.y > .g .h)', [d63, d71])
test_selector_all(':has(:scope.y .g .h)', [d63, d68, d71])
test_selector_all(':has(:scope.y > .g .h) .i', [d67, d75])
test_selector_all(':has(:scope.y .g .h) .i', [d67, d75])
test_selector_all(':has(:scope.x + :has(:scope.y > .g .h) .i)', [d62, d70])
test_selector_all(':has(:scope.x + :has(:scope.y .g .h) .i)', [d62, d63, d70])
test_selector_all(':has(:scope.x + :has(:scope.y > .g .h) .i) ~ .j', [d77, d80])
test_selector_all(':has(:scope.x + :has(:scope.y .g .h) .i) ~ .j', [d77, d80])
test_selector_all(':has(:scope.x ~ :has(:scope.y > .g .h) .i)', [d61, d62, d69, d70])
test_selector_all(':has(:scope.x ~ :has(:scope.y .g .h) .i)', [d61, d62, d63, d69, d70])
test_selector_all('.x:has(.d :scope .e)', [d51, d52])
test_selector_all(':has(.d .x:scope .e)', [d51, d52])
test_selector_all(':has(.d :scope.x .e)', [d51, d52])
test_selector_all('.x:has(.d ~ :scope ~ .e)', [d57, d58])
test_selector_all(':has(.d ~ .x:scope ~ .e)', [d57, d58])
test_selector_all(':has(.d ~ :scope.x ~ .e)', [d57, d58])
test_selector_all(':has(:scope .d :scope)', [])
test_selector_all(':has(:scope ~ .d ~ :scope)', [])
</script>
|