Debian Codegraph @

plugins/postcss-cascade-layers/test/wpt/layer-keyframes-override.html

raw
1 <!DOCTYPE html>
2 <title>Resolving @keyframe 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-keyframes-override.html -->
6 <style>
7 #target,
8 #reference {
9 width: 100px;
10 height: 100px;
11 }
12
13 #reference {
14 background-color: green;
15 }
16 </style>
17
18 <div id="target"></div>
19 <div id="reference"></div>
20
21 <div id="log"></div>
22
23 <script type="module">
24 window.addEventListener('click', () => {
25 window.runTest();
26 });
27
28 window.runTest = async function runTest() {
29 function assert_equals(actual, expected, message) {
30 if (actual != expected) {
31 log.innerHTML = message + ": expected " + expected + ", got " + actual;
32 throw new Error(message + ": expected " + expected + ", got " + actual);
33 }
34 }
35
36 // In all tests, background color of #target should be green, same as #reference
37
38 const testCases = [
39 {
40 title: '@keyframes unlayered overrides layered',
41 style: `
42 #target {
43 animation: anim 1s paused;
44 }
45
46 @keyframes anim {
47 from { background-color: green; }
48 }
49
50 @layer {
51 @keyframes anim {
52 from { background-color: red; }
53 }
54 }
55 `
56 },
57
58 {
59 title: '@keyframes override between layers',
60 style: `
61 @layer base, override;
62
63 #target {
64 animation: anim 1s paused;
65 }
66
67 @layer override {
68 @keyframes anim {
69 from { background-color: green; }
70 }
71 }
72
73 @layer base {
74 @keyframes anim {
75 from { background-color: red; }
76 }
77 }
78 `
79 },
80
81 {
82 title: '@keyframes override update with appended sheet 1',
83 style: `
84 @layer base, override;
85
86 #target {
87 animation: anim 1s paused;
88 }
89
90 @layer override {
91 @keyframes anim {
92 from { background-color: green; }
93 }
94 }
95 `,
96 append: `
97 @layer base {
98 @keyframes anim {
99 from { background-color: red; }
100 }
101 }
102 `
103 },
104
105 {
106 title: '@keyframes override update with appended sheet 2',
107 style: `
108 @layer base, override;
109
110 #target {
111 animation: anim 1s paused;
112 }
113
114 @layer base {
115 @keyframes anim {
116 from { background-color: red; }
117 }
118 }
119 `,
120 append: `
121 @layer override {
122 @keyframes anim {
123 from { background-color: green; }
124 }
125 }
126 `
127 },
128 ];
129
130 for (let testCase of testCases) {
131 var documentStyle = document.createElement('style');
132
133 const testCaseStyle = await (fetch(`/test/styles.css`, {
134 method: 'POST',
135 body: testCase['style'],
136 }).then((response) => response.text()));
137
138 documentStyle.appendChild(document.createTextNode(testCaseStyle));
139 document.head.appendChild(documentStyle);
140
141 var appendedStyle;
142 if (testCase['append']) {
143 document.body.offsetLeft; // Force style update
144 appendedStyle = document.createElement('style');
145
146 const testCaseAppend= await (fetch(`/test/styles.css`, {
147 method: 'POST',
148 body: testCase['style'] + "\n" + testCase['append'],
149 }).then((response) => response.text()));
150
151 appendedStyle.appendChild(document.createTextNode(testCaseAppend));
152 document.head.appendChild(appendedStyle);
153 }
154
155 assert_equals(
156 getComputedStyle(target).backgroundColor,
157 getComputedStyle(reference).backgroundColor,
158 testCase.title + ': background color'
159 );
160
161 if (appendedStyle) {
162 appendedStyle.remove();
163 }
164
165 documentStyle.remove();
166 }
167
168 return true;
169 }
170 </script>