summaryrefslogtreecommitdiffstats
path: root/dom/animation/test/css-animations/file_animation-pausing.html
blob: 7176a0c1d6c85d4749d59562348cec5ddafb67b2 (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
<!doctype html>
<meta charset=utf-8>
<script src="../testcommon.js"></script>
<style>
@keyframes anim { 
  0% { margin-left: 0px }
  100% { margin-left: 10000px }
}
</style>
<body>
<script>
'use strict';

function getMarginLeft(cs) {
  return parseFloat(cs.marginLeft);
}

promise_test(function(t) {
  var div = addDiv(t);
  var cs = window.getComputedStyle(div);
  div.style.animation = 'anim 1000s paused';
  var animation = div.getAnimations()[0];
  assert_equals(getMarginLeft(cs), 0,
                'Initial value of margin-left is zero');
  animation.play();

  return animation.ready.then(waitForFrame).then(function() {
    assert_true(getMarginLeft(cs) > 0,
                'Playing value of margin-left is greater than zero');
  });
}, 'play() overrides animation-play-state');

promise_test(function(t) {
  var div = addDiv(t);
  var cs = window.getComputedStyle(div);
  div.style.animation = 'anim 1000s paused';
  var animation = div.getAnimations()[0];
  assert_equals(getMarginLeft(cs), 0,
                'Initial value of margin-left is zero');

  animation.pause();
  div.style.animationPlayState = 'running';

  return animation.ready.then(waitForFrame).then(function() {
    assert_equals(cs.animationPlayState, 'running',
                  'animation-play-state is running');
    assert_equals(getMarginLeft(cs), 0,
                  'Paused value of margin-left is zero');
  });
}, 'pause() overrides animation-play-state');

promise_test(function(t) {
  var div = addDiv(t);
  var cs = window.getComputedStyle(div);
  div.style.animation = 'anim 1000s paused';
  var animation = div.getAnimations()[0];
  assert_equals(getMarginLeft(cs), 0,
                'Initial value of margin-left is zero');
  animation.play();
  var previousAnimVal;

  return animation.ready.then(function() {
    div.style.animationPlayState = 'running';
    cs.animationPlayState; // Trigger style resolution
    return waitForFrame();
  }).then(function() {
    assert_equals(cs.animationPlayState, 'running',
                  'animation-play-state is running');
    div.style.animationPlayState = 'paused';
    return animation.ready;
  }).then(function() {
    assert_equals(cs.animationPlayState, 'paused',
                  'animation-play-state is paused');
    previousAnimVal = getMarginLeft(cs);
    return waitForFrame();
  }).then(function() {
    assert_equals(getMarginLeft(cs), previousAnimVal,
                  'Animated value of margin-left does not change when'
                  + ' paused by style');
  });
}, 'play() is overridden by later setting "animation-play-state: paused"');

promise_test(function(t) {
  var div = addDiv(t);
  var cs = window.getComputedStyle(div);
  div.style.animation = 'anim 1000s';
  var animation = div.getAnimations()[0];
  assert_equals(getMarginLeft(cs), 0,
                'Initial value of margin-left is zero');

  // Set the specified style first. If implementations fail to
  // apply the style changes first, they will ignore the redundant
  // call to play() and fail to correctly override the pause style.
  div.style.animationPlayState = 'paused';
  animation.play();
  var previousAnimVal = getMarginLeft(cs);

  return animation.ready.then(waitForFrame).then(function() {
    assert_equals(cs.animationPlayState, 'paused',
                  'animation-play-state is paused');
    assert_true(getMarginLeft(cs) > previousAnimVal,
                'Playing value of margin-left is increasing');
  });
}, 'play() flushes pending changes to animation-play-state first');

promise_test(function(t) {
  var div = addDiv(t);
  var cs = window.getComputedStyle(div);
  div.style.animation = 'anim 1000s paused';
  var animation = div.getAnimations()[0];
  assert_equals(getMarginLeft(cs), 0,
                'Initial value of margin-left is zero');

  // Unlike the previous test for play(), since calling pause() is sticky,
  // we'll apply it even if the underlying style also says we're paused.
  //
  // We would like to test that implementations flush styles before running
  // pause() but actually there's no style we can currently set that will
  // change the behavior of pause(). That may change in the future
  // (e.g. if we introduce animation-timeline or animation-playback-rate etc.).
  //
  // For now this just serves as a sanity check that we do the same thing
  // even if we set style before calling the API.
  div.style.animationPlayState = 'running';
  animation.pause();
  var previousAnimVal = getMarginLeft(cs);

  return animation.ready.then(waitForFrame).then(function() {
    assert_equals(cs.animationPlayState, 'running',
                  'animation-play-state is running');
    assert_equals(getMarginLeft(cs), previousAnimVal,
                  'Paused value of margin-left does not change');
  });
}, 'pause() applies pending changes to animation-play-state first');
// (Note that we can't actually test for this; see comment above, in test-body.)

promise_test(function(t) {
  var div = addDiv(t, { style: 'animation: anim 1000s' });
  var animation = div.getAnimations()[0];
  var readyPromiseRun = false;

  return animation.ready.then(function() {
    div.style.animationPlayState = 'paused';
    assert_equals(animation.playState, 'pending', 'Animation is pause pending');

    // Set current time
    animation.currentTime = 5 * MS_PER_SEC;
    assert_equals(animation.playState, 'paused',
                  'Animation is paused immediately after setting currentTime');
    assert_equals(animation.startTime, null,
                  'Animation startTime is unresolved immediately after ' +
                  'setting currentTime');
    assert_equals(animation.currentTime, 5 * MS_PER_SEC,
                  'Animation currentTime does not change when forcing a ' +
                  'pause operation to complete');

    // The ready promise should now be resolved. If it's not then test will
    // probably time out before anything else happens that causes it to resolve.
    return animation.ready;
  });
}, 'Setting the current time completes a pending pause');

done();
</script>
</body>