Debian Codegraph @

plugins/postcss-cascade-layers/test/wpt/layer-vs-inline-style.html

raw
1 <!DOCTYPE html>
2 <link rel="help" href="https://drafts.csswg.org/css-cascade-5/#cascade-sort">
3 <link rel="author" title="Xiaocheng Hu" href="mailto:[email protected]">
4 <!-- Source : https://github.com/web-platform-tests/wpt/blob/master/css/css-cascade/layer-vs-inline-style.html -->
5
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 <div id="log"></div>
21
22 <script type="module">
23 window.addEventListener('click', () => {
24 window.runTest();
25 });
26
27 window.runTest = async function runTest() {
28 function assert_equals(actual, expected, message) {
29 if (actual != expected) {
30 log.innerHTML = message + ": expected " + expected + ", got " + actual;
31 throw new Error(message + ": expected " + expected + ", got " + actual);
32 }
33 }
34
35 // In all tests, #target should have green background color, same as #reference
36
37 const testCases = [
38 {
39 title: 'Normal inline style > normal layered style',
40 style: '@layer { #target { background-color: red; }}',
41 inlineStyle: 'background-color: green'
42 },
43 {
44 title: 'Normal inline style < important layered style',
45 style: '@layer { #target { background-color: green !important; }}',
46 inlineStyle: 'background-color: red'
47 },
48 {
49 title: 'Important inline style > normal layered style',
50 style: '@layer { #target { background-color: red; }}',
51 inlineStyle: 'background-color: green !important'
52 },
53 {
54 title: 'Important inline style > important layered style',
55 style: '@layer { #target { background-color: red !important; }}',
56 inlineStyle: 'background-color: green !important'
57 },
58 ];
59
60 for (let testCase of testCases) {
61 var documentStyle = document.createElement('style');
62
63 const testCaseStyle = await (fetch(`/test/styles.css`, {
64 method: 'POST',
65 body: testCase['style'],
66 }).then((response) => response.text()));
67
68 documentStyle.appendChild(document.createTextNode(testCaseStyle));
69 document.head.appendChild(documentStyle);
70
71 target.style = testCase['inlineStyle'];
72
73 assert_equals(
74 getComputedStyle(target).backgroundColor,
75 getComputedStyle(reference).backgroundColor,
76 testCase['title']
77 );
78
79 documentStyle.remove();
80 }
81
82 return true;
83 }
84 </script>