summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-properties-values-api/registered-properties-inheritance.html
blob: 7c8c2656c683c199bf0e3dba2dfc5bef224034b5 (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
95
96
<!DOCTYPE HTML>
<link rel="help" href="https://drafts.css-houdini.org/css-properties-values-api/#dom-propertydescriptor-inherits" />
<link rel="help" href="https://drafts.css-houdini.org/css-properties-values-api/#register-a-custom-property" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
#outer {
    --inherited-length-1: 10px;
    --inherited-length-2: var(--non-inherited-length-1);
    --inherited-length-3: 30px;
    --non-inherited-length-1: 22px;
    --non-inherited-length-3: calc(var(--non-inherited-length-2) * 10);
}

#inner {
    --inherited-length-3: 15px;
    --non-inherited-length-1: 40px;
    --non-inherited-length-2: 90px;
}
</style>
<div id=outer><div id=inner></div></div>
<script>
test(function() {
    CSS.registerProperty({name: '--inherited-length-1', syntax: '<length>', initialValue: '1px', inherits: true});
    CSS.registerProperty({name: '--inherited-length-2', syntax: '<length>', initialValue: '2px', inherits: true});
    CSS.registerProperty({name: '--inherited-length-3', syntax: '<length>', initialValue: '3px', inherits: true});
    CSS.registerProperty({name: '--non-inherited-length-1', syntax: '<length>', initialValue: '4px', inherits: false});
    CSS.registerProperty({name: '--non-inherited-length-2', syntax: '<length>', initialValue: '5px', inherits: false});
    CSS.registerProperty({name: '--non-inherited-length-3', syntax: '<length>', initialValue: '6px', inherits: false});

    outerComputedStyle = getComputedStyle(outer);
    assert_equals(outerComputedStyle.getPropertyValue('--inherited-length-1'), '10px');
    assert_equals(outerComputedStyle.getPropertyValue('--inherited-length-2'), '22px');
    assert_equals(outerComputedStyle.getPropertyValue('--inherited-length-3'), '30px');
    assert_equals(outerComputedStyle.getPropertyValue('--non-inherited-length-1'), '22px');
    assert_equals(outerComputedStyle.getPropertyValue('--non-inherited-length-2'), '5px');
    assert_equals(outerComputedStyle.getPropertyValue('--non-inherited-length-3'), '50px');

    innerComputedStyle = getComputedStyle(inner);
    assert_equals(innerComputedStyle.getPropertyValue('--inherited-length-1'), '10px');
    assert_equals(innerComputedStyle.getPropertyValue('--inherited-length-2'), '22px');
    assert_equals(innerComputedStyle.getPropertyValue('--inherited-length-3'), '15px');
    assert_equals(innerComputedStyle.getPropertyValue('--non-inherited-length-1'), '40px');
    assert_equals(innerComputedStyle.getPropertyValue('--non-inherited-length-2'), '90px');
    assert_equals(innerComputedStyle.getPropertyValue('--non-inherited-length-3'), '6px');
}, "Registered properties are correctly inherited (or not) depending on the inherits flag.");

test(function(){
    CSS.registerProperty({name: '--initial-length-1', syntax: '<length>', initialValue: '0px', inherits: false});
    outer.style = '--initial-length-1: notalength';
    inner.style = '--initial-length-1: inherit';
    assert_equals(getComputedStyle(inner).getPropertyValue('--initial-length-1'), '0px');
}, "Explicitly inheriting from a parent with an invalid value results in initial value.");

test(function(){
    CSS.registerProperty({name: '--initial-length-2', syntax: '<length>', initialValue: '0px', inherits: false});
    inner.style = '--initial-length-2: inherit';
    assert_equals(getComputedStyle(inner).getPropertyValue('--initial-length-2'), '0px');
}, "Explicitly inheriting from a parent with no value results in initial value.");

test(function(){
    CSS.registerProperty({name: '--initial-length-3', syntax: '<length>', initialValue: '0px', inherits: false});
    outer.style = '--initial-length-3: 100px';
    inner.style = '--initial-length-3: inherit';
    assert_equals(getComputedStyle(inner).getPropertyValue('--initial-length-3'), '100px');
}, "Explicitly inheriting from a parent with a value results in that value.");

test(function(){
    CSS.registerProperty({name: '--inherited-length-4', syntax: '<length>', initialValue: '0px', inherits: true});
    outer.style = '--inherited-length-4: 42px';
    inner.style = '--inherited-length-4: var(--undefined)';
    assert_equals(getComputedStyle(inner).getPropertyValue('--inherited-length-4'), '42px');
}, "Reference to undefined variable results in inherited value");

test(function(){
    CSS.registerProperty({name: '--inherited-length-5', syntax: '<length>', initialValue: '0px', inherits: true});
    outer.style = '--inherited-length-5: 42px';
    inner.style = '--incompatible: nolength; --inherited-length-5: var(--incompatible)';
    assert_equals(getComputedStyle(inner).getPropertyValue('--inherited-length-5'), '42px');
}, "Reference to syntax-incompatible variable results in inherited value");

test(function(){
    CSS.registerProperty({name: '--inherited-em', syntax: '<length>', initialValue: '0px', inherits: true});
    outer.style = 'font-size: 11px; --inherited-em: 10em;';
    inner.style = 'font-size: 22px; --unregistered:var(--inherited-em);';
    assert_equals(getComputedStyle(inner).getPropertyValue('--unregistered'), '110px');
}, "Font-relative units are absolutized before before inheritance");

test(function(){
    CSS.registerProperty({name: '--calc-length', syntax: '<length>', initialValue: '0px', inherits: true});
    outer.style = '--calc-length: calc(10px + 10px);';
    inner.style = '--unregistered:var(--calc-length);';
    assert_equals(getComputedStyle(inner).getPropertyValue('--unregistered'), '20px');
}, "Calc expressions are resolved before inheritance");

</script>