summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-cascade/layer-cssom-order-reverse-at-property.html
blob: dfa6bbfcfbdf727e622c1e0c9a3c026bc2cf98e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<!DOCTYPE html>
<title>CSS Cascade Layers: @property rule invalidation on layer order changes</title>
<link rel="help" href="https://drafts.csswg.org/css-cascade-5/#layering">
<link rel="author" href="mailto:xiaochengh@chromium.org">
<link rel="stylesheet" href="/fonts/ahem.css">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
#reference {
  color: green;
  --foo: green;
}
</style>

<div id=target>Lorem ipsum</div>
<div id=reference>Lorem ipsum</div>

<script>
const testCases = [
  {
    title: 'Insert layer invalidates @property',
    sheets: [
      '',
      `
        @layer first {
          @property --foo {
            syntax: '<color>';
            inherits: false;
            initial-value: green;
          }
        }
        @layer second {
          @property --foo {
            syntax: '<color>';
            inherits: false;
            initial-value: red;
          }
        }
      `,
    ],
    update: function(sheets) {
      sheets[0].insertRule('@layer second {}', 0);
    },
    property: '--foo',
  },
  {
    title: 'Delete layer invalidates @property',
    sheets: [
      '@layer second {}',
      `
        @layer first {
          @property --foo {
            syntax: '<color>';
            inherits: false;
            initial-value: red;
          }
        }
        @layer second {
          @property --foo {
            syntax: '<color>';
            inherits: false;
            initial-value: green;
          }
        }
      `,
    ],
    update: function(sheets) {
      sheets[0].deleteRule(0);
    },
    property: '--foo',
  },
];

for (let testCase of testCases) {
  test(testObj => {
    const styleElements = testCase.sheets.map(sheet => {
      const element = document.createElement('style');
      element.appendChild(document.createTextNode(sheet));
      document.head.appendChild(element);
      return element;
    });
    testObj.add_cleanup(() => {
      for (let element of styleElements)
        element.remove();
    });

    const sheets = styleElements.map(element => element.sheet);
    testCase.update(sheets);
    const actual = getComputedStyle(target).getPropertyValue(testCase.property);
    const expected = getComputedStyle(reference).getPropertyValue(testCase.property);
    assert_equals(actual, expected);
  }, testCase.title);
}
</script>