Skip to content

Commit f609e25

Browse files
[css-mixins] Test that @layer is dropped inside mixins
Blink already drops @layer inside mixins per the CSSWG resolution [0], but existing tests only checked the mixin stayed valid, not that @layer was dropped. Add test cases asserting @layer is dropped at every depth inside a mixin, each keeping a sibling "color: green" rule to confirm only the @layer, not its container, was removed. [0] w3c/csswg-drafts#12417 Bug: 440050694 Change-Id: I08c354d23e25f33ba0b843292bb931009570319d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8114962 Commit-Queue: Stephanie Zhang <stephanie.zhang@microsoft.com> Reviewed-by: Kevin Babbitt <kbabbitt@microsoft.com> Cr-Commit-Position: refs/heads/main@{#1664819}
1 parent 4fa69bf commit f609e25

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

css/css-mixins/mixins/mixin-parsing.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,31 @@
4242
test_valid_child('@mixin --m() { @result { @starting-style {} } }', '@starting-style');
4343
test_valid_child('@mixin --m() { @result { @scope (.foo) {} } }', '@scope');
4444
test_valid_child('@mixin --m() { @result { @scope {} } }', '@scope (implicit)');
45+
46+
// @layer is invalid inside mixins, so it must be dropped at any depth. The
47+
// green sibling rule must survive, proving only the @layer was dropped and
48+
// not its enclosing container.
49+
function test_layer_dropped(css, description) {
50+
test(() => {
51+
let sheet = new CSSStyleSheet();
52+
sheet.replaceSync(css);
53+
assert_equals(sheet.cssRules.length, 1, 'mixin is present');
54+
let mixin_text = sheet.cssRules[0].cssText;
55+
assert_true(mixin_text.includes('color: green'), `sibling rule retained: ${mixin_text}`);
56+
assert_false(/@layer/i.test(mixin_text), `@layer dropped: ${mixin_text}`);
57+
}, `@layer is dropped within ${description}`);
58+
}
59+
60+
test_layer_dropped('@mixin --m() { @result { @layer bar; div { color: green } } }', '@result (statement)');
61+
test_layer_dropped('@mixin --m() { @result { @layer bar {} div { color: green } } }', '@result (block)');
62+
test_layer_dropped('@mixin --m() { @result { div { @layer bar; color: green } } }', 'a nested style rule');
63+
test_layer_dropped('@mixin --m() { @result { @media (width) { @layer bar; div { color: green } } } }', '@media');
64+
test_layer_dropped('@mixin --m() { @result { @supports (width: 0) { @layer bar; div { color: green } } } }', '@supports');
65+
test_layer_dropped('@mixin --m() { @result { @container (width) { @layer bar; div { color: green } } } }', '@container');
66+
test_layer_dropped('@mixin --m() { @result { @scope (.foo) { @layer bar; div { color: green } } } }', '@scope');
67+
test_layer_dropped('@mixin --m() { @media (width) { @layer bar; @result { div { color: green } } } }', 'a body-level @media');
68+
test_layer_dropped('@mixin --m() { @supports (width: 0) { @layer bar; @result { div { color: green } } } }', 'a body-level @supports');
69+
test_layer_dropped('@mixin --m() { @container (width) { @layer bar; @result { div { color: green } } } }', 'a body-level @container');
4570
</script>
4671

4772
</body>

0 commit comments

Comments
 (0)