Skip to content

Commit

Permalink
[@layer] Ensure layer establishment behavior on failed/unmatched imports
Browse files Browse the repository at this point in the history
As per w3c/csswg-drafts#6776:
1. @import with unmatched media query shouldn't establish layer
2. @import that fails to load should still establish layer

This patch adds test cases for it and also fixes our behavior on 1.

Bug: 1095765
Change-Id: Ia7d2c9921b4b93173546cbd78ab243dac3f92420
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3272669
Reviewed-by: Anders Hartvoll Ruud <andruud@chromium.org>
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/main@{#940505}
  • Loading branch information
xiaochengh authored and chromium-wpt-export-bot committed Nov 10, 2021
1 parent 76ecf19 commit e204571
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
13 changes: 13 additions & 0 deletions css/css-cascade/layer-import.html
Expand Up @@ -252,6 +252,18 @@
}
`
},
{
title: 'E1 Named imports establish layer even with network errors',
style: `
@import "nonexist.css" layer(A);
@layer B {
target { color: green; }
}
@layer A {
target { color: red; }
}
`,
},
];

for (let testCase of testCases) {
Expand All @@ -264,6 +276,7 @@

await new Promise(resolve => {
styleElement.onload = resolve;
styleElement.onerror = resolve;
document.head.append(styleElement);
});

Expand Down
18 changes: 17 additions & 1 deletion css/css-cascade/layer-media-query.html
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<title>CSS Cascade Layers: Media queries</title>
<meta name="assert" content="Import functionality of CSS Cascade Layers">
<meta name="assert" content="CSS Cascade Layers nested in Media Queries">
<link rel="author" title="Antti Koivisto" href="mailto:antti@apple.com">
<link rel="help" href="https://www.w3.org/TR/css-cascade-5/#layering">
<script src="/resources/testharness.js"></script>
Expand All @@ -20,6 +20,7 @@
"basic-red.css": `
target { color: red; }
`,
"empty.css": "",
};

// For 300px wide iframe the target should be red and for 500px green.
Expand Down Expand Up @@ -118,6 +119,21 @@
}
`
},
{
title: 'C4 Reordering',
style: `
@import url(empty.css) layer(B) (max-width: 300px);
@import url(empty.css) layer(A) (max-width: 300px);
@import url(empty.css) layer(A) (min-width: 500px);
@import url(empty.css) layer(B) (min-width: 500px);
@layer A {
target { color: red; }
}
@layer B {
target { color: green; }
}
`
},
];

let iframe = document.querySelector("iframe");
Expand Down

0 comments on commit e204571

Please sign in to comment.