summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/cssom/cssstyledeclaration-registered-custom-properties.html
blob: 5aa4ad2532b6a3e5cd9123cd29ff83464847e352 (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
<!DOCTYPE html>
<title>Computed CSSStyleDeclaration includes registered custom properties</title>
<link rel="help" href="https://drafts.csswg.org/cssom/#dom-window-getcomputedstyle">
<link rel="help" href="https://github.com/w3c/csswg-drafts/issues/1316">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
  @property --non-inherited-length {
    syntax: "<length>";
    inherits: false;
    initial-value: 0px;
  }
  @property --inherited-length {
    syntax: "<length>";
    inherits: true;
    initial-value: 0px;
  }
  @property --universal-with-initial {
    syntax: "*";
    inherits: false;
    initial-value: foo;
  }
  @property --universal-without-initial {
    syntax: "*";
    inherits: false;
  }
  #outer { --non-registered-outer: 1px; }
  #inner { --non-registered-inner: 2px; }
  #sibling { --universal-without-initial: bar; }
</style>
<div id=outer>
  <div id=inner></div>
  <div id=sibling></div>
</div>
<script>
  const assert_present = (props, name) => assert_not_equals(props.indexOf(name), -1);
  const assert_absent = (props, name) => assert_equals(props.indexOf(name), -1);

  test(function() {
    let props = Array.from(getComputedStyle(inner));
    assert_present(props, '--non-inherited-length');
    assert_present(props, '--inherited-length');
    assert_present(props, '--non-registered-outer');
    assert_present(props, '--non-registered-inner');
    assert_present(props, '--universal-with-initial');
    assert_absent(props, '--universal-without-initial');
  }, 'Registered custom properties are included in CSSComputedStyleDeclaration');

  test(function() {
    let props = Array.from(getComputedStyle(sibling));
    assert_present(props, '--non-inherited-length');
    assert_present(props, '--inherited-length');
    assert_present(props, '--non-registered-outer');
    assert_present(props, '--universal-with-initial');
    assert_present(props, '--universal-without-initial');
    assert_absent(props, '--non-registered-inner');
  }, 'Only relevant custom properties are included');
</script>