summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/scroll-animations/view-timelines/view-timeline-inset.html
blob: 357d8558f94eeb8342942ecb17a3e1a1bf86fa1d (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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<!DOCTYPE html>
<html id="top">
<meta charset="utf-8">
<title>View timeline delay</title>
<link rel="help" href="https://drafts.csswg.org/scroll-animations-1/#viewtimeline-interface">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/web-animations/testcommon.js"></script>
<script src="/scroll-animations/scroll-timelines/testcommon.js"></script>
<script src="/scroll-animations/view-timelines/testcommon.js"></script>
<style>
    #container {
    border:  10px solid lightgray;
    overflow-x: scroll;
    height:  200px;
    width: 200px;
  }
  #content {
    display:  flex;
    flex-flow:  row nowrap;
    justify-content:  flex-start;
    width:  1800px;
    margin: 0;
  }
  .spacer {
    width:  800px;
    display:  inline-block;
  }
  #target {
    background-color:  green;
    height:  100px;
    width:  100px;
    display:  inline-block;
    font-size:  16px;
  }
  #target.big-font {
    font-size:  20px;
  }
  #container.scroll-padded {
    scroll-padding-inline: 10px 20px;
  }
</style>
</style>
<body>
  <div id="container">
    <div id="content">
      <div class="spacer"></div>
      <div id="target"></div>
      <div class="spacer"></div>
    </div>
  </div>
</body>
<script type="text/javascript">

  function verifyTimelineOffsets(anim, start, end)  {
    const timeline = anim.timeline;
    assert_px_equals(timeline.startOffset, start, 'startOffset');
    assert_px_equals(timeline.endOffset, end, 'endOffset');
  };

  promise_test(async t => {
    // These tests are all based on the cover range, which has bounds
    // [600, 900] if there are no insets.
    // startOffset = target_pos - viewport_size + end_side_inset
    //             = 600 + end_side_inset
    // endOffset = target_pos + target_size - start_side_inset
    //           = 900 - start_side_inset
    await runTimelineInsetTest(t, {
      inset: [ CSS.px(0), CSS.px(0) ],
      startOffset: 600,
      endOffset: 900
    }).then(anim => verifyTimelineOffsets(anim, 600, 900));
    await runTimelineInsetTest(t, {
      inset: [ CSS.px(10), CSS.px(20) ],
      startOffset: 620,
      endOffset: 890
    }).then(anim => verifyTimelineOffsets(anim, 620, 890));
    await runTimelineInsetTest(t, {
      inset: [ CSS.px(10) ],
      startOffset: 610,
      endOffset: 890
    }).then(anim => verifyTimelineOffsets(anim, 610, 890));
  }, 'View timeline with px based inset.');

  promise_test(async t => {
    // These tests are all based on the cover range, which has bounds
    // [600, 900].
    // Percentages are relative to the viewport size, which is 200 for this
    // test.
    await runTimelineInsetTest(t, {
      inset: [ CSS.percent(0), CSS.percent(0) ],
      startOffset: 600,
      endOffset: 900
    }).then(anim => verifyTimelineOffsets(anim, 600, 900));
    await runTimelineInsetTest(t, {
      inset: [ CSS.percent(10), CSS.percent(20) ],
      startOffset: 640,
      endOffset: 880
    }).then(anim => verifyTimelineOffsets(anim, 640, 880));
    await runTimelineInsetTest(t, {
      inset: [ CSS.percent(10) ],
      startOffset: 620,
      endOffset: 880
    }).then(anim => verifyTimelineOffsets(anim, 620, 880));
  }, 'View timeline with percent based inset.');

  promise_test(async t => {
    t.add_cleanup(() => {
      container.classList.remove('scroll-padded');
    });
    const anim = await runTimelineInsetTest(t, {
      inset: [ "auto", "auto" ],
      startOffset: 600,
      endOffset: 900
    });
    verifyTimelineOffsets(anim, 600, 900);
    container.classList.add('scroll-padded');
    await runTimelineBoundsTest(t, {
      anim: anim,
      startOffset: 620,
      endOffset: 890,
    }, 'Adjust for scroll-padding')
        .then(anim => verifyTimelineOffsets(anim, 620, 890));
  }, 'view timeline with inset auto.');

promise_test(async t => {
  t.add_cleanup(() => {
    target.classList.remove('big-font');
  });
  const anim = await runTimelineInsetTest(t, {
    inset: [ CSS.em(1), CSS.em(2) ],
    startOffset: 632,
    endOffset: 884
  });
  verifyTimelineOffsets(anim, 632, 884);
  target.classList.add('big-font');
  await runTimelineBoundsTest(t, {
    anim: anim,
    startOffset: 640,
    endOffset: 880,
  }, 'Adjust for font size increase')
      .then(anim => verifyTimelineOffsets(anim, 640, 880));
}, 'view timeline with font relative inset.');

promise_test(async t => {
  const vw = window.innerWidth;
  const vh = window.innerHeight;
  const vmin = Math.min(vw, vh);
  await runTimelineInsetTest(t, {
    inset: [ CSS.vw(10), CSS.vw(20) ],
    startOffset: 600 + 0.2 * vw,
    endOffset: 900 - 0.1 * vw
  });
  await runTimelineInsetTest(t, {
    inset: [ CSS.vmin(10), CSS.vmin(20) ],
    startOffset: 600 + 0.2 * vmin,
    endOffset: 900 - 0.1 * vmin
  });
}, 'view timeline with viewport relative insets.');

promise_test(async t => {
  await runTimelineInsetTest(t, {
    inset: "10px",
    startOffset: 610,
    endOffset: 890
  });
  await runTimelineInsetTest(t, {
    inset: "10px 20px",
    startOffset: 620,
    endOffset: 890
  });
  await runTimelineInsetTest(t, {
    inset: "10%",
    startOffset: 620,
    endOffset: 880
  });
  await runTimelineInsetTest(t, {
    inset: "10% 20%",
    startOffset: 640,
    endOffset: 880
  });
  await runTimelineInsetTest(t, {
    inset: "auto",
    startOffset: 600,
    endOffset: 900
  });
  await runTimelineInsetTest(t, {
    inset: "1em 2em",
    startOffset: 632,
    endOffset: 884
  });
  assert_throws_js(TypeError, () => {
    new ViewTimeline({
      subject: target,
      inset: "go fish"
    });
  });

  assert_throws_js(TypeError, () => {
    new ViewTimeline({
      subject: target,
      inset: "1 2"
    });
  });

}, 'view timeline inset as string');

promise_test(async t => {
  assert_throws_js(TypeError, () => {
    new ViewTimeline({
      subject: target,
      inset: [ CSS.rad(1) ]
    });
  });

  assert_throws_js(TypeError, () => {
    new ViewTimeline({
      subject: target,
      inset: [ CSS.px(10), CSS.px(10), CSS.px(10) ]
    });
  });


}, 'view timeline with invalid inset');

</script>