summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-transitions/CSSTransition-startTime.tentative.html
blob: 4dbe8634192a3e2431aa7c0f542071fec47e2ba7 (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
<!doctype html>
<meta charset=utf-8>
<title>CSSTransition.startTime</title>
<!-- TODO: Add a more specific link for this once it is specified. -->
<link rel="help" href="https://drafts.csswg.org/css-transitions-2/#csstransition">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/helper.js"></script>
<div id="log"></div>
<script>

'use strict';

test(t => {
  const div = addDiv(t, {
    style: 'margin-left: 100px; transition: margin-left 100s linear 100s',
  });
  getComputedStyle(div).marginLeft;
  div.style.marginLeft = '200px';
  const animation = div.getAnimations()[0];

  assert_equals(animation.startTime, null, 'startTime is unresolved');
}, 'The start time of a newly-created transition is unresolved');

promise_test(async t => {
  const div = addDiv(t);

  div.style.left = '0px';
  div.style.top = '0px';
  getComputedStyle(div).transitionProperty;

  div.style.transition = 'all 100s';
  div.style.left = '100px';
  div.style.top = '100px';

  let animations = div.getAnimations();
  assert_equals(animations.length, 2);
  await waitForAllAnimations(animations);

  assert_equals(animations[0].startTime, animations[1].startTime,
    'CSS transitions started together have the same start time');

  await waitForAnimationFrames(1);

  div.style.backgroundColor = 'green';

  animations = div.getAnimations();
  assert_equals(animations.length, 3);
  await waitForAllAnimations(animations);

  assert_less_than(animations[1].startTime, animations[2].startTime,
    'A CSS transition added in a later frame has a later start time');
}, 'The start time of transitions is based on when they are generated');

test(t => {
  const div = addDiv(t, {
    style: 'margin-left: 100px; transition: margin-left 100s linear 100s',
  });
  getComputedStyle(div).marginLeft;
  div.style.marginLeft = '200px';
  const animation = div.getAnimations()[0];

  const timelineTime = animation.timeline.currentTime;
  animation.startTime = timelineTime;

  assert_times_equal(
    animation.startTime,
    timelineTime,
    'Check setting of startTime actually works'
  );
}, 'The start time of a transition can be set');

promise_test(async t => {
  const div = addDiv(t, {
    style: 'margin-left: 100px; transition: margin-left 100s linear 100s',
  });
  getComputedStyle(div).marginLeft;
  div.style.marginLeft = '200px';
  const animation = div.getAnimations()[0];

  await animation.ready;

  const timelineTime = animation.timeline.currentTime;
  const marginLeft = () => parseFloat(getComputedStyle(div).marginLeft);

  animation.startTime = timelineTime - 100 * MS_PER_SEC;
  assert_equals(marginLeft(), 100);

  animation.startTime = timelineTime - 150 * MS_PER_SEC;
  assert_equals(marginLeft(), 150);
}, 'The start time can be set to seek a transition');

promise_test(async t => {
  const div = addDiv(t, {
    style: 'margin-left: 100px; transition: margin-left 100s linear 100s',
  });
  const eventWatcher = new EventWatcher(t, div, [
    'transitionstart',
    'transitionend',
  ]);
  getComputedStyle(div).marginLeft;
  div.style.marginLeft = '200px';
  const animation = div.getAnimations()[0];

  await animation.ready;

  const timelineTime = animation.timeline.currentTime;

  animation.startTime = timelineTime - 100 * MS_PER_SEC;
  await frameTimeout(
    eventWatcher.wait_for('transitionstart'),
    2,
    'transitionstart'
  );

  animation.startTime = timelineTime - 200 * MS_PER_SEC;
  await frameTimeout(
    eventWatcher.wait_for('transitionend'),
    2,
    'transitionend'
  );
}, 'Seeking a transition using start time dispatches transition events');

</script>