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
|
<!doctype html>
<meta charset="utf-8">
<title>CSS Container Queries Test: style query container for Shadow DOM</title>
<link rel="help" href="https://drafts.csswg.org/css-conditional-5/#query-container">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/cq-testcommon.js"></script>
<div id="ancestor-across-root">
<div style="--foo: bar">
<template shadowrootmode="open">
<style>
@container style(--foo: bar) {
#t1 { color: green; }
}
</style>
<div id="t1"></div>
</template>
</div>
</div>
<div id="ancestor-slotting">
<div style="--foo: bar">
<template shadowrootmode="open">
<div style="--foo: baz">
<slot></slot>
</div>
</template>
<style>
@container style(--foo: baz) {
#t2 { color: green; }
}
</style>
<div id="t2"></div>
</div>
</div>
<div id="ancestor-slotted">
<div style="--foo: baz">
<template shadowrootmode="open">
<style>
@container style(--foo: bar) {
::slotted(#t3) { color: green; }
}
</style>
<slot style="--foo: bar"></slot>
</template>
<div id="t3"></div>
</div>
</div>
<div id="ancestor-host" style="--foo: bar">
<div id="t4">
<template shadowrootmode="open">
<style>
@container style(--foo: bar) {
:host(#t4) { color: green; }
}
</style>
</template>
</div>
</div>
<div id="ancestor-part">
<div style="--foo: bar">
<template shadowrootmode="open">
<div style="--foo: baz">
<span id="t5" part="part"></span>
</div>
</template>
<style>
@container style(--foo: baz) {
#ancestor-part > div::part(part) { color: green; }
}
</style>
</div>
</div>
<div id="ancestor-slotted-before">
<div>
<template shadowrootmode="open">
<style>
@container style(--foo: baz) {
::slotted(#t6)::before {
content: "X";
color: green;
}
}
</style>
<slot style="--foo: bar"></slot>
</template>
<div id="t6" style="--foo: baz"></div>
</div>
</div>
<div id="ancestor-host-before">
<div id="t7" style="--foo: bar">
<template shadowrootmode="open">
<style>
@container style(--foo: bar) {
:host(#t7)::before {
content: "X";
color: green;
}
}
</style>
</template>
</div>
</div>
<div id="ancestor-part-before">
<style>
@container style(--foo: quz) {
#ancestor-part-before > div::part(part)::before {
content: "X";
color: green;
}
}
</style>
<div style="--foo: bar">
<template shadowrootmode="open">
<div style="--foo: baz">
<span id="t8" part="part" style="--foo: quz"></span>
</div>
</template>
</div>
</div>
<div id="ancestor-inner-part">
<style>
@container style(--foo: quz) {
#ancestor-inner-part > div::part(inner-part) { color: green; }
}
</style>
<div style="--foo: bar">
<template shadowrootmode="open">
<div exportparts="inner-part" style="--foo: baz">
<template shadowrootmode="open">
<div style="--foo: quz">
<span id="t9" part="inner-part"></span>
</div>
</template>
</div>
</template>
</div>
</div>
<div id="ancestor-slot-fallback">
<div><template shadowrootmode="open">
<style>
@container style(--foo: bar) {
#t10 { color: green; }
}
</style>
<div>
<slot style="--foo: bar"><span id="t10"></span></slot>
</div>
</template></div>
</div>
<div id="container-for-part">
<div>
<template shadowrootmode="open">
<div style="--foo: bar">
<span id="t11" part="part"></span>
</div>
</template>
<style>
@container style(--foo: bar) {
#container-for-part > div::part(part) { color: green; }
}
</style>
</div>
</div>
<div id="inner-scope-host-part" style="--foo: bar">
<div>
<template shadowrootmode="open">
<style>
@container style(--foo: baz) {
:host::part(part) { color: green; }
}
</style>
<div style="--foo: baz">
<span id="t12" part="part"></span>
</div>
</template>
</div>
</div>
<script>
setup(() => {
assert_implements_style_container_queries();
});
const green = "rgb(0, 128, 0)";
test(() => {
const t1 = document.querySelector("#ancestor-across-root > div").shadowRoot.querySelector("#t1");
assert_equals(getComputedStyle(t1).color, green);
}, "Match container in outer tree");
test(() => {
const t2 = document.querySelector("#t2");
assert_equals(getComputedStyle(t2).color, green);
}, "Match container in the shadow tree for a host child in the host child's tree scope");
test(() => {
const t3 = document.querySelector("#t3");
assert_equals(getComputedStyle(t3).color, green);
}, "Match <slot> as a container for ::slotted element");
test(() => {
const t4 = document.querySelector("#t4");
assert_equals(getComputedStyle(t4).color, green);
}, "Match container in outer tree for :host");
test(() => {
const t5 = document.querySelector("#ancestor-part > div").shadowRoot.querySelector("#t5");
assert_equals(getComputedStyle(t5).color, green);
}, "Match ::part's parent in the shadow tree as the container for ::part");
test(() => {
const t6 = document.querySelector("#t6");
assert_equals(getComputedStyle(t6, "::before").color, green);
}, "Match ::slotted as a container for its ::before");
test(() => {
const t7 = document.querySelector("#t7");
assert_equals(getComputedStyle(t7, "::before").color, green);
}, "Match container in outer tree for :host::before");
test(() => {
const t8 = document.querySelector("#ancestor-part-before > div").shadowRoot.querySelector("#t8");
assert_equals(getComputedStyle(t8, "::before").color, green);
}, "Match the ::part as a container for ::before on ::part elements");
test(() => {
const outerhost = document.querySelector("#ancestor-inner-part > div");
const innerhost = outerhost.shadowRoot.querySelector("div");
const t9 = innerhost.shadowRoot.querySelector("#t9");
assert_equals(getComputedStyle(t9).color, green);
}, "Match container for ::part selector in inner shadow tree for exportparts");
test(() => {
const t10 = document.querySelector("#ancestor-slot-fallback > div").shadowRoot.querySelector("#t10");
assert_equals(getComputedStyle(t10).color, green);
}, "Match container for slot light tree child fallback");
test(() => {
const t11 = document.querySelector("#container-for-part > div").shadowRoot.querySelector("#t11");
assert_equals(getComputedStyle(t11).color, green);
}, "Should match parent container inside shadow tree for ::part()");
test(() => {
const t12 = document.querySelector("#inner-scope-host-part > div").shadowRoot.querySelector("#t12");
assert_equals(getComputedStyle(t12).color, green);
}, "A :host::part rule matching a container in the shadow tree");
</script>
|