| <!doctype html> |
| <meta charset="utf-8"> |
| <title>CSS Container Queries Test: query container for Shadow DOM</title> |
| <link rel="help" href="https://drafts.csswg.org/css-contain-3/#query-container"> |
| <script src="/resources/testharness.js"></script> |
| <script src="/resources/testharnessreport.js"></script> |
| <script src="support/cq-testcommon.js"></script> |
| <style> |
| #inclusive-ancestor-across-root, |
| #inclusive-ancestor-skip-slotting, |
| #inclusive-ancestor-slotted, |
| #inclusive-ancestor-host, |
| #inclusive-ancestor-part, |
| #inclusive-ancestor-slotted-before, |
| #inclusive-ancestor-host-before, |
| #inclusive-ancestor-part-before, |
| #inclusive-ancestor-inner-part, |
| #inclusive-ancestor-slot-fallback { |
| width: 400px; |
| container-type: inline-size; |
| } |
| </style> |
| |
| <div id="inclusive-ancestor-across-root"> |
| <div> |
| <template shadowroot="open"> |
| <style> |
| @container (width = 400px) { |
| #t1 { color: green; } |
| } |
| </style> |
| <div id="t1"></div> |
| </template> |
| </div> |
| </div> |
| |
| <div id="inclusive-ancestor-skip-slotting"> |
| <div> |
| <template shadowroot="open"> |
| <style> |
| div { |
| width: 200px; |
| container-type: inline-size; |
| } |
| </style> |
| <div> |
| <slot></slot> |
| </div> |
| </template> |
| <style> |
| @container (width = 400px) { |
| #t2 { color: green; } |
| } |
| </style> |
| <div id="t2"></div> |
| </div> |
| </div> |
| |
| <div id="inclusive-ancestor-slotted"> |
| <div> |
| <template shadowroot="open"> |
| <style> |
| slot { |
| display: block; |
| width: 200px; |
| container-type: inline-size; |
| } |
| @container (width = 200px) { |
| ::slotted(#t3) { color: green; } |
| } |
| </style> |
| <slot></slot> |
| </template> |
| <div id="t3"></div> |
| </div> |
| </div> |
| |
| <div id="inclusive-ancestor-host"> |
| <div id="t4"> |
| <template shadowroot="open"> |
| <style> |
| @container (width = 400px) { |
| :host(#t4) { color: green; } |
| } |
| </style> |
| </template> |
| </div> |
| </div> |
| |
| <div id="inclusive-ancestor-part"> |
| <div> |
| <template shadowroot="open"> |
| <style> |
| div { |
| width: 200px; |
| container-type: inline-size; |
| } |
| </style> |
| <div> |
| <span id="t5" part="part"></span> |
| </div> |
| </template> |
| <style> |
| @container (width = 400px) { |
| #inclusive-ancestor-part > div::part(part) { color: green; } |
| } |
| </style> |
| </div> |
| </div> |
| |
| <div id="inclusive-ancestor-slotted-before"> |
| <div> |
| <template shadowroot="open"> |
| <style> |
| slot { |
| display: block; |
| width: 200px; |
| container-type: inline-size; |
| } |
| @container (width = 200px) { |
| ::slotted(#t6)::before { |
| content: "X"; |
| color: green; |
| } |
| } |
| </style> |
| <slot></slot> |
| </template> |
| <style> |
| #t6 { |
| width: 400px; |
| container-type: inline-size; |
| } |
| </style> |
| <div id="t6"></div> |
| </div> |
| </div> |
| |
| <div id="inclusive-ancestor-host-before"> |
| <div id="t7"> |
| <template shadowroot="open"> |
| <style> |
| :host { |
| width: 200px; |
| container-type: inline-size; |
| } |
| @container (width = 200px) { |
| :host(#t7)::before { |
| content: "X"; |
| color: green; |
| } |
| } |
| </style> |
| </template> |
| </div> |
| </div> |
| |
| <div id="inclusive-ancestor-part-before"> |
| <style> |
| @container (width = 400px) { |
| #inclusive-ancestor-part-before > div::part(part)::before { |
| content: "X"; |
| color: green; |
| } |
| } |
| </style> |
| <div> |
| <template shadowroot="open"> |
| <style> |
| div { |
| width: 200px; |
| container-type: inline-size; |
| } |
| </style> |
| <div> |
| <span id="t8" part="part"></span> |
| </div> |
| </template> |
| </div> |
| </div> |
| |
| <div id="inclusive-ancestor-inner-part"> |
| <style> |
| @container (width = 400px) { |
| #inclusive-ancestor-inner-part > div::part(inner-part) { color: green; } |
| } |
| </style> |
| <div> |
| <template shadowroot="open"> |
| <style> |
| div { |
| width: 200px; |
| container-type: inline-size; |
| } |
| </style> |
| <div exportparts="inner-part"> |
| <template shadowroot="open"> |
| <style> |
| div { |
| width: 200px; |
| container-type: inline-size; |
| } |
| </style> |
| <div> |
| <span id="t9" part="inner-part"></span> |
| </div> |
| </template> |
| </div> |
| </template> |
| </div> |
| </div> |
| |
| <div id="inclusive-ancestor-slot-fallback"> |
| <div><template shadowroot="open"> |
| <style> |
| div { |
| width: 200px; |
| container-type: inline-size; |
| } |
| @container (width = 200px) { |
| #t10 { color: green; } |
| } |
| </style> |
| <div> |
| <slot><span id="t10"></span></slot> |
| </div> |
| </template></div> |
| </div> |
| |
| <script> |
| setup(() => { |
| assert_implements_container_queries(); |
| |
| // Fallback for browsers not supporting declarative Shadow DOM |
| (function attachShadowRoots(root) { |
| root.querySelectorAll("template[shadowroot]").forEach(template => { |
| const mode = template.getAttribute("shadowroot"); |
| const shadowRoot = template.parentNode.attachShadow({ mode }); |
| shadowRoot.appendChild(template.content); |
| template.remove(); |
| attachShadowRoots(shadowRoot); |
| }); |
| })(document); |
| }); |
| |
| const green = "rgb(0, 128, 0)"; |
| |
| test(() => { |
| const t1 = document.querySelector("#inclusive-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 same tree, not walking flat tree ancestors"); |
| |
| test(() => { |
| const t3 = document.querySelector("#t3"); |
| assert_equals(getComputedStyle(t3).color, green); |
| }, "Match container in ::slotted selector's originating element tree"); |
| |
| test(() => { |
| const t4 = document.querySelector("#t4"); |
| assert_equals(getComputedStyle(t4).color, green); |
| }, "Match container in outer tree for :host"); |
| |
| test(() => { |
| const t5 = document.querySelector("#inclusive-ancestor-part > div").shadowRoot.querySelector("#t5"); |
| assert_equals(getComputedStyle(t5).color, green); |
| }, "Match container in ::part selector's originating element tree"); |
| |
| test(() => { |
| const t6 = document.querySelector("#t6"); |
| assert_equals(getComputedStyle(t6, "::before").color, green); |
| }, "Match container for ::before in ::slotted selector's originating element tree"); |
| |
| 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("#inclusive-ancestor-part-before > div").shadowRoot.querySelector("#t8"); |
| assert_equals(getComputedStyle(t8, "::before").color, green); |
| }, "Match container for ::before in ::part selector's originating element tree"); |
| |
| test(() => { |
| const outerhost = document.querySelector("#inclusive-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's originating element tree for exportparts"); |
| |
| test(() => { |
| const t10 = document.querySelector("#inclusive-ancestor-slot-fallback > div").shadowRoot.querySelector("#t10"); |
| assert_equals(getComputedStyle(t10).color, green); |
| }, "Match container for slot light tree child fallback"); |
| </script> |