| 1 |
<!DOCTYPE html> |
| 2 |
<html lang="en"> |
| 3 |
<head> |
| 4 |
<meta charset="UTF-8"> |
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 6 |
<link rel="help" href="https://drafts.csswg.org/css-color-adjust/#color-scheme-effect"> |
| 7 |
<link rel="help" href="https://github.com/w3c/csswg-drafts/issues/7561"> |
| 8 |
<title>light-dark() color-scheme propagation</title> |
| 9 |
</head> |
| 10 |
<body> |
| 11 |
<style> |
| 12 |
.box { |
| 13 |
width: 100px; |
| 14 |
height: 100px; |
| 15 |
margin: 8px; |
| 16 |
} |
| 17 |
</style> |
| 18 |
<div class="box" id="system"></div> |
| 19 |
<div id="parent"> |
| 20 |
<div id="child">Text should be green</div> |
| 21 |
</div> |
| 22 |
|
| 23 |
<div id="log"></div> |
| 24 |
<script type="module"> |
| 25 |
window.addEventListener('click', () => { |
| 26 |
window.runTest(); |
| 27 |
}); |
| 28 |
|
| 29 |
window.runTest = async function runTest() { |
| 30 |
const system_is_dark = matchMedia("(prefers-color-scheme: dark)").matches; |
| 31 |
const elements = ["child"].map(document.getElementById.bind(document)); |
| 32 |
|
| 33 |
function assert_equals(actual, expected, message) { |
| 34 |
if (actual != expected) { |
| 35 |
log.innerHTML = message + ": expected " + expected + ", got " + actual; |
| 36 |
throw new Error(message + ": expected " + expected + ", got " + actual); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
var testCases = [ |
| 41 |
{ |
| 42 |
title: 'Light Dark CurrentColor - A', |
| 43 |
style: ` |
| 44 |
:root { |
| 45 |
color-scheme: light dark; |
| 46 |
} |
| 47 |
|
| 48 |
#parent { color: green; } |
| 49 |
#child { |
| 50 |
color-scheme: dark; |
| 51 |
color: light-dark(red, currentColor); |
| 52 |
} |
| 53 |
`, |
| 54 |
expected_light: 'rgb(0, 128, 0)', |
| 55 |
expected_dark: 'rgb(0, 128, 0)', |
| 56 |
} |
| 57 |
]; |
| 58 |
|
| 59 |
for (let testCase of testCases) { |
| 60 |
for (let params of ['', '?native=true']) { |
| 61 |
const styleElement = document.createElement('style'); |
| 62 |
|
| 63 |
const testCaseStyle = await (fetch(`/test/styles.css${params}`, { |
| 64 |
method: 'POST', |
| 65 |
body: testCase['style'], |
| 66 |
}).then((response) => response.text())); |
| 67 |
|
| 68 |
styleElement.textContent = testCaseStyle; |
| 69 |
document.head.append(styleElement); |
| 70 |
|
| 71 |
for (let element of elements) { |
| 72 |
let should_be_dark = element.id == "dark" || (element.id == "system" && system_is_dark && !testCase.root_supports_only_light); |
| 73 |
let actual_value = getComputedStyle(element).color; |
| 74 |
let expected_value = should_be_dark ? testCase.expected_dark : testCase.expected_light; |
| 75 |
|
| 76 |
assert_equals( |
| 77 |
actual_value, |
| 78 |
expected_value, |
| 79 |
`${testCase.title} (${element.id}, ${system_is_dark ? 'is dark' : 'is not dark'})` |
| 80 |
); |
| 81 |
} |
| 82 |
|
| 83 |
styleElement.remove(); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
return true; |
| 88 |
} |
| 89 |
</script> |
| 90 |
</body> |
| 91 |
</html> |