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
|
<!DOCTYPE html>
<meta charset=utf-8>
<title>Play states</title>
<link rel="help" href="https://drafts.csswg.org/web-animations/#play-states">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../testcommon.js"></script>
<body>
<div id="log"></div>
<script>
'use strict';
test(t => {
const animation = new Animation(
new KeyframeEffect(null, {}, 100 * MS_PER_SEC)
);
assert_equals(animation.currentTime, null,
'Current time should be initially unresolved');
assert_equals(animation.playState, 'idle');
}, 'reports \'idle\' for an animation with an unresolved current time'
+ ' and no pending tasks')
test(t => {
const animation = createDiv(t).animate({}, 100 * MS_PER_SEC);
animation.pause();
assert_equals(animation.playState, 'paused');
}, 'reports \'paused\' for an animation with a pending pause task');
test(t => {
const animation = new Animation(
new KeyframeEffect(null, {}, 100 * MS_PER_SEC)
);
animation.currentTime = 0;
assert_equals(animation.startTime, null,
'Start time should still be unresolved after setting current'
+ ' time');
assert_equals(animation.playState, 'paused');
}, 'reports \'paused\' for an animation with a resolved current time and'
+ ' unresolved start time')
test(t => {
const animation = new Animation(
new KeyframeEffect(null, {}, 100 * MS_PER_SEC)
);
animation.startTime = document.timeline.currentTime;
assert_not_equals(animation.currentTime, null,
'Current time should be resolved after setting start time');
assert_equals(animation.playState, 'running');
}, 'reports \'running\' for an animation with a resolved start time and'
+ ' current time');
test(t => {
const animation = new Animation(
new KeyframeEffect(null, {}, 100 * MS_PER_SEC)
);
animation.startTime = document.timeline.currentTime;
animation.currentTime = 100 * MS_PER_SEC;
assert_equals(animation.playState, 'finished');
}, 'reports \'finished\' when playback rate > 0 and'
+ ' current time = target effect end');
test(t => {
const animation = new Animation(
new KeyframeEffect(null, {}, 100 * MS_PER_SEC)
);
animation.startTime = document.timeline.currentTime;
animation.playbackRate = 0;
animation.currentTime = 100 * MS_PER_SEC;
assert_equals(animation.playState, 'running');
}, 'reports \'running\' when playback rate = 0 and'
+ ' current time = target effect end');
test(t => {
const animation = new Animation(
new KeyframeEffect(null, {}, 100 * MS_PER_SEC)
);
animation.startTime = document.timeline.currentTime;
animation.playbackRate = -1;
animation.currentTime = 100 * MS_PER_SEC;
assert_equals(animation.playState, 'running');
}, 'reports \'running\' when playback rate < 0 and'
+ ' current time = target effect end');
test(t => {
const animation = new Animation(
new KeyframeEffect(null, {}, 100 * MS_PER_SEC)
);
animation.startTime = document.timeline.currentTime;
animation.currentTime = 0;
assert_equals(animation.playState, 'running');
}, 'reports \'running\' when playback rate > 0 and'
+ ' current time = 0');
test(t => {
const animation = new Animation(
new KeyframeEffect(null, {}, 100 * MS_PER_SEC)
);
animation.startTime = document.timeline.currentTime;
animation.playbackRate = 0;
animation.currentTime = 0;
assert_equals(animation.playState, 'running');
}, 'reports \'running\' when playback rate = 0 and'
+ ' current time = 0');
test(t => {
const animation = new Animation(
new KeyframeEffect(null, {}, 100 * MS_PER_SEC)
);
animation.startTime = document.timeline.currentTime;
animation.playbackRate = -1;
animation.currentTime = 0;
assert_equals(animation.playState, 'finished');
}, 'reports \'finished\' when playback rate < 0 and'
+ ' current time = 0');
test(t => {
const animation = createDiv(t).animate({}, 0);
assert_equals(animation.startTime, null,
'Sanity check: start time should be unresolved');
assert_equals(animation.playState, 'finished');
}, 'reports \'finished\' when playback rate > 0 and'
+ ' current time = target effect end and there is a pending play task');
test(t => {
const animation = createDiv(t).animate({}, 100 * MS_PER_SEC);
assert_equals(animation.startTime, null,
'Sanity check: start time should be unresolved');
assert_equals(animation.playState, 'running');
}, 'reports \'running\' when playback rate > 0 and'
+ ' current time < target effect end and there is a pending play task');
test(t => {
const animation = createDiv(t).animate({}, 100 * MS_PER_SEC);
assert_equals(animation.playState, 'running');
assert_true(animation.pending);
}, 'reports \'running\' for a play-pending animation');
test(t => {
const animation = createDiv(t).animate({}, 100 * MS_PER_SEC);
animation.pause();
assert_equals(animation.playState, 'paused');
assert_true(animation.pending);
}, 'reports \'paused\' for a pause-pending animation');
test(t => {
const animation = createDiv(t).animate({}, 0);
assert_equals(animation.playState, 'finished');
assert_true(animation.pending);
}, 'reports \'finished\' for a finished-pending animation');
test(t => {
const animation = createDiv(t).animate({}, 100 * MS_PER_SEC);
// Set up the pending playback rate
animation.updatePlaybackRate(-1);
// Call play again so that we seek to the end while remaining play-pending
animation.play();
// For a pending animation, the play state should always report what the
// play state _will_ be once we finish pending.
assert_equals(animation.playState, 'running');
assert_true(animation.pending);
}, 'reports the play state based on the pending playback rate');
</script>
</body>
|