| 1 |
<!DOCTYPE html> |
| 2 |
<title>Resolving @counter-style name conflicts with cascade layers</title> |
| 3 |
<link rel="help" href="https://drafts.csswg.org/css-cascade-5/#layering"> |
| 4 |
<link rel="author" href="mailto:[email protected]"> |
| 5 |
<!-- Source : https://github.com/web-platform-tests/wpt/blob/master/css/css-cascade/layer-counter-style-override.html --> |
| 6 |
<style> |
| 7 |
#target, |
| 8 |
#reference { |
| 9 |
font-family: monospace; |
| 10 |
width: min-content; |
| 11 |
} |
| 12 |
|
| 13 |
#reference::before { |
| 14 |
content: '0000'; |
| 15 |
} |
| 16 |
|
| 17 |
@counter-style three { |
| 18 |
system: cyclic; |
| 19 |
symbols: '000'; |
| 20 |
} |
| 21 |
|
| 22 |
@counter-style four { |
| 23 |
system: cyclic; |
| 24 |
symbols: '0000'; |
| 25 |
} |
| 26 |
</style> |
| 27 |
|
| 28 |
<ul> |
| 29 |
<li id="target"></li> |
| 30 |
<li id="reference"></li> |
| 31 |
</ul> |
| 32 |
|
| 33 |
<div id="log"></div> |
| 34 |
|
| 35 |
<script type="module"> |
| 36 |
window.addEventListener('click', () => { |
| 37 |
window.runTest(); |
| 38 |
}); |
| 39 |
|
| 40 |
window.runTest = async function runTest() { |
| 41 |
function assert_equals(actual, expected, message) { |
| 42 |
if (actual != expected) { |
| 43 |
log.innerHTML = message + ": expected " + expected + ", got " + actual; |
| 44 |
throw new Error(message + ": expected " + expected + ", got " + actual); |
| 45 |
} |
| 46 |
} |
| 47 |
// In all tests, #target::before should have 4 characters, same as #reference. |
| 48 |
|
| 49 |
const testCases = [ |
| 50 |
{ |
| 51 |
title: '@counter-style unlayered overrides layered', |
| 52 |
style: ` |
| 53 |
#target::before { |
| 54 |
content: counter(dont-care, custom-counter-style); |
| 55 |
} |
| 56 |
|
| 57 |
@counter-style custom-counter-style { |
| 58 |
system: extends four; |
| 59 |
} |
| 60 |
|
| 61 |
@layer { |
| 62 |
@counter-style custom-counter-style { |
| 63 |
system: extends three; |
| 64 |
} |
| 65 |
} |
| 66 |
` |
| 67 |
}, |
| 68 |
|
| 69 |
{ |
| 70 |
title: '@counter-style override between layers', |
| 71 |
style: ` |
| 72 |
@layer base, override; |
| 73 |
|
| 74 |
#target::before { |
| 75 |
content: counter(dont-care, custom-counter-style); |
| 76 |
} |
| 77 |
|
| 78 |
@layer override { |
| 79 |
@counter-style custom-counter-style { |
| 80 |
system: extends four; |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
@layer base { |
| 85 |
@counter-style custom-counter-style { |
| 86 |
system: extends three; |
| 87 |
} |
| 88 |
} |
| 89 |
` |
| 90 |
}, |
| 91 |
|
| 92 |
{ |
| 93 |
title: '@counter-style override update with appended sheet 1', |
| 94 |
style: ` |
| 95 |
@layer base, override; |
| 96 |
|
| 97 |
#target::before { |
| 98 |
content: counter(dont-care, custom-counter-style); |
| 99 |
} |
| 100 |
|
| 101 |
@layer override { |
| 102 |
@counter-style custom-counter-style { |
| 103 |
system: extends four; |
| 104 |
} |
| 105 |
} |
| 106 |
`, |
| 107 |
append: ` |
| 108 |
@layer base { |
| 109 |
@counter-style custom-counter-style { |
| 110 |
system: extends three; |
| 111 |
} |
| 112 |
} |
| 113 |
` |
| 114 |
}, |
| 115 |
|
| 116 |
{ |
| 117 |
title: '@counter-style override update with appended sheet 2', |
| 118 |
style: ` |
| 119 |
@layer base, override; |
| 120 |
|
| 121 |
#target::before { |
| 122 |
content: counter(dont-care, custom-counter-style); |
| 123 |
} |
| 124 |
|
| 125 |
@layer base { |
| 126 |
@counter-style custom-counter-style { |
| 127 |
system: extends three; |
| 128 |
} |
| 129 |
} |
| 130 |
`, |
| 131 |
append: ` |
| 132 |
@layer override { |
| 133 |
@counter-style custom-counter-style { |
| 134 |
system: extends four; |
| 135 |
} |
| 136 |
} |
| 137 |
` |
| 138 |
}, |
| 139 |
]; |
| 140 |
|
| 141 |
for (let testCase of testCases) { |
| 142 |
var documentStyle = document.createElement('style'); |
| 143 |
var appendedStyle = document.createElement('style'); |
| 144 |
|
| 145 |
const testCaseStyle = await (fetch(`/test/styles.css`, { |
| 146 |
method: 'POST', |
| 147 |
body: testCase['style'], |
| 148 |
}).then((response) => response.text())); |
| 149 |
|
| 150 |
const testCaseAppend = await (fetch(`/test/styles.css`, { |
| 151 |
method: 'POST', |
| 152 |
body: testCase['style'] + "\n" + (testCase['append'] ?? ''), |
| 153 |
}).then((response) => response.text())); |
| 154 |
|
| 155 |
documentStyle.appendChild(document.createTextNode(testCaseStyle)); |
| 156 |
document.head.appendChild(documentStyle); |
| 157 |
|
| 158 |
if (testCase['append']) { |
| 159 |
appendedStyle.appendChild(document.createTextNode(testCaseAppend)); |
| 160 |
document.head.appendChild(appendedStyle); |
| 161 |
} |
| 162 |
|
| 163 |
assert_equals( |
| 164 |
getComputedStyle(target).width, |
| 165 |
getComputedStyle(reference).width, |
| 166 |
testCase.title + ': width' |
| 167 |
); |
| 168 |
|
| 169 |
appendedStyle.remove(); |
| 170 |
documentStyle.remove(); |
| 171 |
} |
| 172 |
|
| 173 |
return true; |
| 174 |
} |
| 175 |
</script> |