summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/scroll-animations/css/view-timeline-shorthand.html
blob: 9027eb0b09dc7dd348d2d3a0df94720b0de76150 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<!DOCTYPE html>
<link rel="help" href="https://drafts.csswg.org/scroll-animations-1/#view-timeline-shorthand">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/css/support/computed-testcommon.js"></script>
<script src="/css/support/parsing-testcommon.js"></script>
<script src="/css/support/shorthand-testcommon.js"></script>
<div id="target"></div>
<script>
test_valid_value('view-timeline', '--abcd');
test_valid_value('view-timeline', 'none block', 'none');
test_valid_value('view-timeline', 'none inline');

// view-timeline-name: inline/block/x/y.
test_valid_value('view-timeline', '--inline block', '--inline');
test_valid_value('view-timeline', '--block block', '--block');
test_valid_value('view-timeline', '--y block', '--y');
test_valid_value('view-timeline', '--x block', '--x');

test_valid_value('view-timeline', '--a, --b, --c');
test_valid_value('view-timeline', '--a inline, --b block, --c y', '--a inline, --b, --c y');
test_valid_value('view-timeline', '--auto');
test_valid_value('view-timeline', '--abcd block auto', '--abcd');
test_valid_value('view-timeline', '--abcd block auto auto', '--abcd');
test_valid_value('view-timeline', '--abcd block 1px 2px', '--abcd 1px 2px');
test_valid_value('view-timeline', '--abcd inline 1px 2px', '--abcd inline 1px 2px');
test_valid_value('view-timeline', '--abcd 1px 2px inline', '--abcd inline 1px 2px');
test_valid_value('view-timeline', '--abcd 1px 2px block', '--abcd 1px 2px');
test_valid_value('view-timeline', '--abcd auto auto block', '--abcd');
test_valid_value('view-timeline', '--abcd auto block', '--abcd');
test_valid_value('view-timeline', '--abcd block 1px 1px', '--abcd 1px');

test_invalid_value('view-timeline', '--abc --abc');
test_invalid_value('view-timeline', 'block none');
test_invalid_value('view-timeline', 'none none');
test_invalid_value('view-timeline', 'default');
test_invalid_value('view-timeline', ',');
test_invalid_value('view-timeline', ',,--block,,');
test_invalid_value('view-timeline', 'auto');
test_invalid_value('view-timeline', 'auto auto');
test_invalid_value('view-timeline', '--abc 500kg');
test_invalid_value('view-timeline', '--abc #ff0000');
test_invalid_value('view-timeline', '--abc red red');

test_computed_value('view-timeline', '--abcd');
test_computed_value('view-timeline', 'none block', 'none');
test_computed_value('view-timeline', 'none inline');
test_computed_value('view-timeline', '--inline block', '--inline');
test_computed_value('view-timeline', '--block block', '--block');
test_computed_value('view-timeline', '--y block', '--y');
test_computed_value('view-timeline', '--x block', '--x');
test_computed_value('view-timeline', '--a, --b, --c');
test_computed_value('view-timeline', '--a inline, --b block, --c y', '--a inline, --b, --c y');
test_computed_value('view-timeline', '--abcd block auto', '--abcd');
test_computed_value('view-timeline', '--abcd block auto auto', '--abcd');
test_computed_value('view-timeline', '--abcd block 1px 2px', '--abcd 1px 2px');
test_computed_value('view-timeline', '--abcd inline 1px 2px', '--abcd inline 1px 2px');
test_computed_value('view-timeline', '--abcd 1px 2px inline', '--abcd inline 1px 2px');
test_computed_value('view-timeline', '--abcd 1px 2px block', '--abcd 1px 2px');
test_computed_value('view-timeline', '--abcd auto auto block', '--abcd');
test_computed_value('view-timeline', '--abcd auto block', '--abcd');
test_computed_value('view-timeline', '--abcd block 1px 1px', '--abcd 1px');

test_shorthand_value('view-timeline', '--abc y',
{
  'view-timeline-name': '--abc',
  'view-timeline-axis': 'y',
  'view-timeline-inset': 'auto',
});
test_shorthand_value('view-timeline', '--abc y, --def',
{
  'view-timeline-name': '--abc, --def',
  'view-timeline-axis': 'y, block',
  'view-timeline-inset': 'auto, auto',
});
test_shorthand_value('view-timeline', '--abc, --def',
{
  'view-timeline-name': '--abc, --def',
  'view-timeline-axis': 'block, block',
  'view-timeline-inset': 'auto, auto',
});
test_shorthand_value('view-timeline', '--inline x',
{
  'view-timeline-name': '--inline',
  'view-timeline-axis': 'x',
  'view-timeline-inset': 'auto',
});
test_shorthand_value('view-timeline', '--abc 1px 2px',
{
  'view-timeline-name': '--abc',
  'view-timeline-axis': 'block',
  'view-timeline-inset': '1px 2px',
});
test_shorthand_value('view-timeline', '--abc 1px',
{
  'view-timeline-name': '--abc',
  'view-timeline-axis': 'block',
  'view-timeline-inset': '1px',
});
test_shorthand_value('view-timeline', '--abc 1px inline',
{
  'view-timeline-name': '--abc',
  'view-timeline-axis': 'inline',
  'view-timeline-inset': '1px',
});

function test_shorthand_contraction(shorthand, longhands, expected) {
  let longhands_fmt = Object.entries(longhands).map((e) => `${e[0]}:${e[1]}:${e[2]}`).join(';');
  test((t) => {
    t.add_cleanup(() => {
      for (let shorthand of Object.keys(longhands))
        target.style.removeProperty(shorthand);
    });
    for (let [shorthand, value] of Object.entries(longhands))
      target.style.setProperty(shorthand, value);
    assert_equals(target.style.getPropertyValue(shorthand), expected, 'Declared value');
    assert_equals(getComputedStyle(target).getPropertyValue(shorthand), expected, 'Computed value');
  }, `Shorthand contraction of ${longhands_fmt}`);
}

test_shorthand_contraction('view-timeline', {
  'view-timeline-name': '--abc',
  'view-timeline-axis': 'inline',
  'view-timeline-inset': 'auto',
}, '--abc inline');

test_shorthand_contraction('view-timeline', {
  'view-timeline-name': '--a, --b',
  'view-timeline-axis': 'inline, block',
  'view-timeline-inset': 'auto, auto',
}, '--a inline, --b');

test_shorthand_contraction('view-timeline', {
  'view-timeline-name': '--a, --b',
  'view-timeline-axis': 'inline, block',
  'view-timeline-inset': '1px 2px, 3px 3px',
}, '--a inline 1px 2px, --b 3px');

test_shorthand_contraction('view-timeline', {
  'view-timeline-name': 'none, none',
  'view-timeline-axis': 'block, block',
  'view-timeline-inset': 'auto auto, auto',
}, 'none, none');

// Longhands with different lengths:

test_shorthand_contraction('view-timeline', {
  'view-timeline-name': '--a, --b, --c',
  'view-timeline-axis': 'inline, inline',
  'view-timeline-inset': 'auto, auto',
}, '--a inline, --b inline, --c inline');

test_shorthand_contraction('view-timeline', {
  'view-timeline-name': '--a, --b',
  'view-timeline-axis': 'inline, inline, inline',
  'view-timeline-inset': 'auto, auto, auto',
}, '--a inline, --b inline');

test_shorthand_contraction('view-timeline', {
  'view-timeline-name': '--a, --b',
  'view-timeline-axis': 'inline, inline',
  'view-timeline-inset': 'auto, auto, auto',
}, '--a inline, --b inline');
</script>