Skip to content

Commit

Permalink
Cover changing content targetting :has-slotted and :has-slotted(...) (#…
Browse files Browse the repository at this point in the history
…48317)

* Cover changing content targetting :has-slotted and :has-slotted(...)

* Diversify DOM interactions

* Lint

* Make test file "tentative"

* Include missing `.shadowRoot`s

* Split out functional :has-slotted() from non-functional :has-slotted

* Correc titles and :has-slotted(div + div) test
  • Loading branch information
Westbrook authored Sep 30, 2024
1 parent 1ff0d85 commit d3ec111
Show file tree
Hide file tree
Showing 26 changed files with 579 additions and 84 deletions.
5 changes: 2 additions & 3 deletions css/css-scoping/has-slotted-001.tentative.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!doctype html>
<meta charset="utf-8">
<title>:has-slotted(*)</title>
<title>:has-slotted</title>
<link rel="help" href="https://github.com/w3c/csswg-drafts/pull/10586">
<link rel="match" href="/css/reference/ref-filled-green-100px-square-only.html">
<p>Test passes if there is a filled green square.</p>
Expand All @@ -13,11 +13,10 @@
height: 100px;
background-color: red;
}
:has-slotted(*) {
:has-slotted {
background-color: green;
}
</style>
<slot></slot>
</template>
<div></div>
</div>
3 changes: 1 addition & 2 deletions css/css-scoping/has-slotted-002.tentative.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!doctype html>
<meta charset="utf-8">
<title>:has-slotted(...) negative test: no children or white space</title>
<title>:has-slotted negative test: no children or white space</title>
<link rel="help" href="https://github.com/w3c/csswg-drafts/pull/10586">
<link rel="match" href="/css/reference/ref-filled-green-100px-square-only.html">
<p>Test passes if there is a filled green square.</p>
Expand All @@ -12,7 +12,6 @@
height: 100px;
background-color: green;
}
:has-slotted(*),
:has-slotted {
background-color: red;
}
Expand Down
21 changes: 11 additions & 10 deletions css/css-scoping/has-slotted-003.tentative.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
<!doctype html>
<meta charset="utf-8">
<title>:has-slotted(...) negative test: no children, but whitespace present</title>
<title>:has-slotted</title>
<link rel="help" href="https://github.com/w3c/csswg-drafts/pull/10586">
<link rel="match" href="/css/reference/ref-filled-green-100px-square-only.html">
<p>Test passes if there is a filled green square.</p>
<div id="host">
<template shadowrootmode="open">
<style>
<style>
slot {
display: block;
width: 100px;
height: 100px;
background-color: green;
display: block;
width: 100px;
height: 100px;
background-color: red;
}
:has-slotted(*) {
background-color: red;
:has-slotted {
background-color: green;
}
</style>
<slot></slot>
</style>
<slot></slot>
</template>
<div></div>
</div>
59 changes: 59 additions & 0 deletions css/css-scoping/has-slotted-changing-001.tentative.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE HTML>
<html>

<head>
<meta charset="utf-8">
<title>Changing content targetting :has-slotted through a single shadow root</title>
<link rel="help" href="https://github.com/w3c/csswg-drafts/pull/10586">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/resources/testdriver-actions.js"></script>
</head>

<body>

<div id="test"><template shadowrootmode="open">
<slot></slot>
<p id="target">This text will be styled.</p>
<style>
p {
color: rgb(0 255 0);
}
slot:not(:has-slotted) + p {
color: rgb(0 0 255);
}
</style>
</template></div>

<script>
const blue = 'rgb(0, 0, 255)';
const green = 'rgb(0, 255, 0)';
test(function () {
const test = document.getElementById('test');
const target = test.shadowRoot.getElementById('target');
let styles = getComputedStyle(target);
assert_equals(styles.getPropertyValue('color'), green);
test.innerHTML = ' ';
styles = getComputedStyle(target);
assert_equals(styles.getPropertyValue('color'), blue);
test.replaceChildren();;
styles = getComputedStyle(target);
assert_equals(styles.getPropertyValue('color'), green);
const div = document.createElement('div');
test.append(div);
styles = getComputedStyle(target);
assert_equals(styles.getPropertyValue('color'), blue);
const node = document.createTextNode(' ');
test.replaceChildren(node);
styles = getComputedStyle(target);
assert_equals(styles.getPropertyValue('color'), blue);
test.innerHTML = '';
styles = getComputedStyle(target);
assert_equals(styles.getPropertyValue('color'), green);
}, name);
</script>
</body>

</html>
60 changes: 60 additions & 0 deletions css/css-scoping/has-slotted-changing-002.tentative.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!DOCTYPE HTML>
<html>

<head>
<meta charset="utf-8">
<title>Changing content targetting :has-slotted through multiple shadow roots</title>
<link rel="help" href="https://github.com/w3c/csswg-drafts/pull/10586">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/resources/testdriver-actions.js"></script>
</head>

<body>

<div id="test"><template shadowrootmode="open"><div id="inner"><template shadowrootmode="open">
<slot></slot>
<p id="target">This text will be styled.</p>
<style>
p {
color: rgb(0 255 0);
}
slot:not(:has-slotted) + p {
color: rgb(0 0 255);
}
</style>
</template><slot></slot></div></template></div>


<script>
const blue = 'rgb(0, 0, 255)';
const green = 'rgb(0, 255, 0)';
test(function () {
const test = document.getElementById('test');
const inner = test.shadowRoot.getElementById('inner');
const target = inner.shadowRoot.getElementById('target');
let styles = getComputedStyle(target);
assert_equals(styles.getPropertyValue('color'), green);
const node = document.createTextNode(' ');
test.replaceChildren(node);
styles = getComputedStyle(target);
assert_equals(styles.getPropertyValue('color'), blue);
node.remove();
styles = getComputedStyle(target);
assert_equals(styles.getPropertyValue('color'), green);
test.innerHTML = '<div></div>';
styles = getComputedStyle(target);
assert_equals(styles.getPropertyValue('color'), blue);
test.appendChild(node);
styles = getComputedStyle(target);
assert_equals(styles.getPropertyValue('color'), blue);
test.textContent = '';
styles = getComputedStyle(target);
assert_equals(styles.getPropertyValue('color'), green);
}, name);
</script>
</body>

</html>
32 changes: 14 additions & 18 deletions css/css-scoping/has-slotted-flattened-001.tentative.html
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
<!doctype html>
<meta charset="utf-8">
<title>:has-slotted(*) flattened through multiple slots</title>
<title>:has-slotted flattened through multiple slots</title>
<link rel="help" href="https://github.com/w3c/csswg-drafts/pull/10586">
<link rel="match" href="/css/reference/ref-filled-green-100px-square-only.html">
<p>Test passes if there is a filled green square.</p>
<div id="ancestor">
<template shadowrootmode="open">
<div id="host">
<template shadowrootmode="open">
<style>
slot {
display: block;
width: 100px;
height: 100px;
background-color: red;
}
:has-slotted(*) {
background-color: green;
}
</style>
<slot></slot>
</template>
<div id="host"><template shadowrootmode="open">
<style>
slot {
display: block;
width: 100px;
height: 100px;
background-color: red;
}
:has-slotted {
background-color: green;
}
</style>
<slot></slot>
</div>
</template><slot></slot></div>
</template>
<div></div>
</div>
3 changes: 1 addition & 2 deletions css/css-scoping/has-slotted-flattened-002.tentative.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!doctype html>
<meta charset="utf-8">
<title>:has-slotted(...) negative test: no children or white space</title>
<title>:has-slotted negative test: no children or white space</title>
<link rel="help" href="https://github.com/w3c/csswg-drafts/pull/10586">
<link rel="match" href="/css/reference/ref-filled-green-100px-square-only.html">
<p>Test passes if there is a filled green square.</p>
Expand All @@ -13,7 +13,6 @@
height: 100px;
background-color: green;
}
:has-slotted(*),
:has-slotted {
background-color: red;
}
Expand Down
34 changes: 16 additions & 18 deletions css/css-scoping/has-slotted-flattened-003.tentative.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
<!doctype html>
<meta charset="utf-8">
<title>:has-slotted(...) flattened through multiple slots, negative test: no children, but whitespace present</title>
<title>:has-slotted flattened through multiple slots</title>
<link rel="help" href="https://github.com/w3c/csswg-drafts/pull/10586">
<link rel="match" href="/css/reference/ref-filled-green-100px-square-only.html">
<p>Test passes if there is a filled green square.</p>
<div id="ancestor">
<template shadowrootmode="open">
<div id="host">
<template shadowrootmode="open">
<style>
slot {
display: block;
width: 100px;
height: 100px;
background-color: green;
}
:has-slotted(*) {
background-color: red;
}
</style>
<slot></slot>
</template>
</div>
<slot></slot>
<div id="host"><template shadowrootmode="open">
<style>
slot {
display: block;
width: 100px;
height: 100px;
background-color: red;
}
:has-slotted {
background-color: green;
}
</style>
<slot></slot>
</template><slot></slot></div>
</template>
<div></div>
</div>
24 changes: 0 additions & 24 deletions css/css-scoping/has-slotted-flattened-007.tentative.html

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!doctype html>
<meta charset="utf-8">
<title>:has-slotted</title>
<title>:has-slotted(*)</title>
<link rel="help" href="https://github.com/w3c/csswg-drafts/pull/10586">
<link rel="match" href="/css/reference/ref-filled-green-100px-square-only.html">
<p>Test passes if there is a filled green square.</p>
Expand All @@ -13,10 +13,11 @@
height: 100px;
background-color: red;
}
:has-slotted {
:has-slotted(*) {
background-color: green;
}
</style>
<slot></slot>
</template>
<div></div>
</div>
20 changes: 20 additions & 0 deletions css/css-scoping/has-slotted-functional-002.tentative.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!doctype html>
<meta charset="utf-8">
<title>:has-slotted(...) negative test: no children or white space</title>
<link rel="help" href="https://github.com/w3c/csswg-drafts/pull/10586">
<link rel="match" href="/css/reference/ref-filled-green-100px-square-only.html">
<p>Test passes if there is a filled green square.</p>
<div id="host"><template shadowrootmode="open">
<style>
slot {
display: block;
width: 100px;
height: 100px;
background-color: green;
}
:has-slotted(*) {
background-color: red;
}
</style>
<slot></slot>
</template></div>
22 changes: 22 additions & 0 deletions css/css-scoping/has-slotted-functional-003.tentative.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!doctype html>
<meta charset="utf-8">
<title>:has-slotted(...) negative test: no children, but whitespace present</title>
<link rel="help" href="https://github.com/w3c/csswg-drafts/pull/10586">
<link rel="match" href="/css/reference/ref-filled-green-100px-square-only.html">
<p>Test passes if there is a filled green square.</p>
<div id="host">
<template shadowrootmode="open">
<style>
slot {
display: block;
width: 100px;
height: 100px;
background-color: green;
}
:has-slotted(*) {
background-color: red;
}
</style>
<slot></slot>
</template>
</div>
Loading

0 comments on commit d3ec111

Please sign in to comment.