Skip to content

Commit

Permalink
[WPT] Sync css/css-nesting
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=279130

Reviewed by Brent Fulgham and Tim Nguyen.

WPT @ 8c85e2c44e2e4572d6e64327ef4f01b602af3d78

* LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/contextually-invalid-selectors-expected.html:
* LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/nested-declarations-cssom-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/nested-declarations-cssom.html:
* LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/nested-declarations-matching.html:
* LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/w3c-import.log:

Canonical link: https://commits.webkit.org/283164@main
  • Loading branch information
mdubet committed Sep 4, 2024
1 parent 21bdf1a commit dc1c862
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!DOCTYPE html>
<link rel="author" title="Morten Stenshorne" href="[email protected]">
<p>Test passes if there is a filled green square.</p>
<div style="width:100px; height:100px; background:green;"></div>
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ FAIL CSSNestedDeclarations.style assert_equals: expected 2 but got 1
FAIL Nested group rule assert_equals: expected 2 but got 1
FAIL Nested @scope rule assert_equals: expected 2 but got 1
FAIL Inner rule starting with an ident assert_equals: expected 4 but got 2
FAIL Inserting a CSSNestedDeclaration rule into style rule The string did not match the expected pattern.
FAIL Inserting a CSSNestedDeclaration rule into nested group rule The string did not match the expected pattern.
PASS Attempting to insert a CSSNestedDeclaration rule into top-level @media rule
PASS Attempting to insert a CSSNestedDeclaration rule into a stylesheet
PASS Attempting to insert a CSSNestedDeclaration rule, empty block
PASS Attempting to insert a CSSNestedDeclaration rule, all invalid declarations

Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,86 @@
assert_equals(outer.cssRules[2].cssText, `& color:hover { }`);
assert_equals(outer.cssRules[3].cssText, `--y: 2;`);
}, 'Inner rule starting with an ident');

test(() => {
let s = new CSSStyleSheet();
s.replaceSync('.a {}');
assert_equals(s.cssRules.length, 1);
let a_rule = s.cssRules[0];
assert_equals(a_rule.cssRules.length, 0);
a_rule.insertRule(`
width: 100px;
height: 200px;
`);
assert_equals(a_rule.cssRules.length, 1);
assert_true(a_rule.cssRules[0] instanceof CSSNestedDeclarations);
assert_equals(a_rule.cssRules[0].cssText, `width: 100px; height: 200px;`);
}, 'Inserting a CSSNestedDeclaration rule into style rule');

test(() => {
let s = new CSSStyleSheet();
s.replaceSync('.a { @media (width > 100px) {} }');
assert_equals(s.cssRules.length, 1);
assert_equals(s.cssRules[0].cssRules.length, 1);
let media_rule = s.cssRules[0].cssRules[0];
assert_true(media_rule instanceof CSSMediaRule);
assert_equals(media_rule.cssRules.length, 0);
media_rule.insertRule(`
width: 100px;
height: 200px;
`);
assert_equals(media_rule.cssRules.length, 1);
assert_true(media_rule.cssRules[0] instanceof CSSNestedDeclarations);
assert_equals(media_rule.cssRules[0].cssText, `width: 100px; height: 200px;`);
}, 'Inserting a CSSNestedDeclaration rule into nested group rule');

test(() => {
let s = new CSSStyleSheet();
s.replaceSync('@media (width > 100px) {}');
assert_equals(s.cssRules.length, 1);
let media_rule = s.cssRules[0];
assert_true(media_rule instanceof CSSMediaRule);
assert_equals(media_rule.cssRules.length, 0);
assert_throws_dom('SyntaxError', () => {
media_rule.insertRule(`
width: 100px;
height: 200px;
`);
});
}, 'Attempting to insert a CSSNestedDeclaration rule into top-level @media rule');

test(() => {
let sheet = new CSSStyleSheet();
assert_throws_dom('SyntaxError', () => {
sheet.insertRule(`
width: 100px;
height: 200px;
`);
});
}, 'Attempting to insert a CSSNestedDeclaration rule into a stylesheet');

test(() => {
let s = new CSSStyleSheet();
s.replaceSync('.a {}');
assert_equals(s.cssRules.length, 1);
let a_rule = s.cssRules[0];
assert_equals(a_rule.cssRules.length, 0);
assert_throws_dom('SyntaxError', () => {
a_rule.insertRule('');
});
}, 'Attempting to insert a CSSNestedDeclaration rule, empty block');

test(() => {
let s = new CSSStyleSheet();
s.replaceSync('.a {}');
assert_equals(s.cssRules.length, 1);
let a_rule = s.cssRules[0];
assert_equals(a_rule.cssRules.length, 0);
assert_throws_dom('SyntaxError', () => {
a_rule.insertRule(`
xwidth: 100px;
xheight: 200px;
`);
});
}, 'Attempting to insert a CSSNestedDeclaration rule, all invalid declarations');
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@
color: red;
}
.a1 {
& { color: green };
.ignored {}
color: green;
}
}
</style>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ None
------------------------------------------------------------------------
List of files:
/LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/WEB_FEATURES.yml
/LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/block-skipping.css
/LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/block-skipping.html
/LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/conditional-properties-expected.html
/LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/conditional-properties-ref.html
/LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/conditional-properties.html
/LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/conditional-rules-expected.html
/LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/conditional-rules-ref.html
/LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/conditional-rules.html
/LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/contextually-invalid-selectors-expected.html
/LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/contextually-invalid-selectors.html
/LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/cssom.html
/LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/delete-other-rule-crash.html
/LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/has-nesting-expected.html
Expand Down Expand Up @@ -52,6 +56,7 @@ List of files:
/LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/nest-containing-forgiving.html
/LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/nested-declarations-cssom.html
/LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/nested-declarations-matching.html
/LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/nested-rule-cssom-invalidation.html
/LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/nesting-basic-expected.html
/LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/nesting-basic-ref.html
/LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/nesting-basic.html
Expand Down

0 comments on commit dc1c862

Please sign in to comment.