| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <meta charset=utf-8> | 2 <meta charset=utf-8> |
| 3 <title>Animation.finish()</title> | 3 <title>Animation.finish()</title> |
| 4 <link rel="help" href="https://w3c.github.io/web-animations/#dom-animation-finis
h"> | 4 <link rel="help" href="https://w3c.github.io/web-animations/#dom-animation-finis
h"> |
| 5 <script src="../../../../resources/testharness.js"></script> | 5 <script src="../../../../../resources/testharness.js"></script> |
| 6 <script src="../../../../resources/testharnessreport.js"></script> | 6 <script src="../../../../../resources/testharnessreport.js"></script> |
| 7 <script src="../testcommon.js"></script> | 7 <script src="../../testcommon.js"></script> |
| 8 <link rel="stylesheet" href="../../../../resources/testharness.css"> | 8 <link rel="stylesheet" href="../../../../../resources/testharness.css"> |
| 9 <body> | 9 <body> |
| 10 <div id="log"></div> | 10 <div id="log"></div> |
| 11 <script> | 11 <script> |
| 12 'use strict'; | 12 'use strict'; |
| 13 | 13 |
| 14 var gKeyFrames = { 'marginLeft': ['100px', '200px'] }; | 14 var gKeyFrames = { 'marginLeft': ['100px', '200px'] }; |
| 15 | 15 |
| 16 test(function(t) { | 16 test(function(t) { |
| 17 var div = createDiv(t); | 17 var div = createDiv(t); |
| 18 var animation = div.animate(gKeyFrames, 100 * MS_PER_SEC); | 18 var animation = div.animate(gKeyFrames, 100 * MS_PER_SEC); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 promise_test(function(t) { | 89 promise_test(function(t) { |
| 90 var div = createDiv(t); | 90 var div = createDiv(t); |
| 91 var animation = div.animate(gKeyFrames, 100 * MS_PER_SEC); | 91 var animation = div.animate(gKeyFrames, 100 * MS_PER_SEC); |
| 92 animation.pause(); | 92 animation.pause(); |
| 93 return animation.ready.then(function() { | 93 return animation.ready.then(function() { |
| 94 animation.finish(); | 94 animation.finish(); |
| 95 | 95 |
| 96 assert_equals(animation.playState, 'finished', | 96 assert_equals(animation.playState, 'finished', |
| 97 'The play state of a paused animation should become ' + | 97 'The play state of a paused animation should become ' + |
| 98 '"finished" after finish() is called'); | 98 '"finished" after finish() is called'); |
| 99 assert_approx_equals(animation.startTime, | 99 assert_times_equal(animation.startTime, |
| 100 animation.timeline.currentTime - 100 * MS_PER_SEC, | 100 animation.timeline.currentTime - 100 * MS_PER_SEC, |
| 101 0.0001, | 101 'The start time of a paused animation should be set ' + |
| 102 'The start time of a paused animation should be set ' + | 102 'after calling finish()'); |
| 103 'after calling finish()'); | |
| 104 }); | 103 }); |
| 105 }, 'Test finish() while paused'); | 104 }, 'Test finish() while paused'); |
| 106 | 105 |
| 107 test(function(t) { | 106 test(function(t) { |
| 108 var div = createDiv(t); | 107 var div = createDiv(t); |
| 109 var animation = div.animate(gKeyFrames, 100 * MS_PER_SEC); | 108 var animation = div.animate(gKeyFrames, 100 * MS_PER_SEC); |
| 110 animation.pause(); | 109 animation.pause(); |
| 111 // Update playbackRate so we can test that the calculated startTime | 110 // Update playbackRate so we can test that the calculated startTime |
| 112 // respects it | 111 // respects it |
| 113 animation.playbackRate = 2; | 112 animation.playbackRate = 2; |
| 114 // While animation is still pause-pending call finish() | 113 // While animation is still pause-pending call finish() |
| 115 animation.finish(); | 114 animation.finish(); |
| 116 | 115 |
| 117 assert_equals(animation.playState, 'finished', | 116 assert_equals(animation.playState, 'finished', |
| 118 'The play state of a pause-pending animation should become ' + | 117 'The play state of a pause-pending animation should become ' + |
| 119 '"finished" after finish() is called'); | 118 '"finished" after finish() is called'); |
| 120 assert_approx_equals(animation.startTime, | 119 assert_times_equal(animation.startTime, |
| 121 animation.timeline.currentTime - 100 * MS_PER_SEC / 2, | 120 animation.timeline.currentTime - 100 * MS_PER_SEC / 2, |
| 122 0.0001, | 121 'The start time of a pause-pending animation should ' + |
| 123 'The start time of a pause-pending animation should ' + | 122 'be set after calling finish()'); |
| 124 'be set after calling finish()'); | |
| 125 }, 'Test finish() while pause-pending with positive playbackRate'); | 123 }, 'Test finish() while pause-pending with positive playbackRate'); |
| 126 | 124 |
| 127 test(function(t) { | 125 test(function(t) { |
| 128 var div = createDiv(t); | 126 var div = createDiv(t); |
| 129 var animation = div.animate(gKeyFrames, 100 * MS_PER_SEC); | 127 var animation = div.animate(gKeyFrames, 100 * MS_PER_SEC); |
| 130 animation.pause(); | 128 animation.pause(); |
| 131 animation.playbackRate = -2; | 129 animation.playbackRate = -2; |
| 132 animation.finish(); | 130 animation.finish(); |
| 133 | 131 |
| 134 assert_equals(animation.playState, 'finished', | 132 assert_equals(animation.playState, 'finished', |
| 135 'The play state of a pause-pending animation should become ' + | 133 'The play state of a pause-pending animation should become ' + |
| 136 '"finished" after finish() is called'); | 134 '"finished" after finish() is called'); |
| 137 assert_equals(animation.startTime, animation.timeline.currentTime, | 135 assert_equals(animation.startTime, animation.timeline.currentTime, |
| 138 'The start time of a pause-pending animation should be ' + | 136 'The start time of a pause-pending animation should be ' + |
| 139 'set after calling finish()'); | 137 'set after calling finish()'); |
| 140 }, 'Test finish() while pause-pending with negative playbackRate'); | 138 }, 'Test finish() while pause-pending with negative playbackRate'); |
| 141 | 139 |
| 142 test(function(t) { | 140 test(function(t) { |
| 143 var div = createDiv(t); | 141 var div = createDiv(t); |
| 144 var animation = div.animate(gKeyFrames, 100 * MS_PER_SEC); | 142 var animation = div.animate(gKeyFrames, 100 * MS_PER_SEC); |
| 145 animation.playbackRate = 0.5; | 143 animation.playbackRate = 0.5; |
| 146 animation.finish(); | 144 animation.finish(); |
| 147 | 145 |
| 148 assert_equals(animation.playState, 'finished', | 146 assert_equals(animation.playState, 'finished', |
| 149 'The play state of a play-pending animation should become ' + | 147 'The play state of a play-pending animation should become ' + |
| 150 '"finished" after finish() is called'); | 148 '"finished" after finish() is called'); |
| 151 assert_approx_equals(animation.startTime, | 149 assert_times_equal(animation.startTime, |
| 152 animation.timeline.currentTime - 100 * MS_PER_SEC / 0.5, | 150 animation.timeline.currentTime - 100 * MS_PER_SEC / 0.5, |
| 153 0.0001, | 151 'The start time of a play-pending animation should ' + |
| 154 'The start time of a play-pending animation should ' + | 152 'be set after calling finish()'); |
| 155 'be set after calling finish()'); | |
| 156 }, 'Test finish() while play-pending'); | 153 }, 'Test finish() while play-pending'); |
| 157 | 154 |
| 158 // FIXME: Add a test for when we are play-pending without an active timeline. | 155 // FIXME: Add a test for when we are play-pending without an active timeline. |
| 159 // - In that case even after calling finish() we should still be pending but | 156 // - In that case even after calling finish() we should still be pending but |
| 160 // the current time should be updated | 157 // the current time should be updated |
| 161 | 158 |
| 162 promise_test(function(t) { | 159 promise_test(function(t) { |
| 163 var div = createDiv(t); | 160 var div = createDiv(t); |
| 164 var animation = div.animate(gKeyFrames, 100 * MS_PER_SEC); | 161 var animation = div.animate(gKeyFrames, 100 * MS_PER_SEC); |
| 165 return animation.ready.then(function() { | 162 return animation.ready.then(function() { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 }); | 196 }); |
| 200 | 197 |
| 201 return animation.ready.then(function() { | 198 return animation.ready.then(function() { |
| 202 animation.finish(); | 199 animation.finish(); |
| 203 }).then(function() { | 200 }).then(function() { |
| 204 assert_true(resolvedFinished, | 201 assert_true(resolvedFinished, |
| 205 'Animation.finished should be resolved soon after ' + | 202 'Animation.finished should be resolved soon after ' + |
| 206 'Animation.finish()'); | 203 'Animation.finish()'); |
| 207 }); | 204 }); |
| 208 }, 'Test finish() resolves finished promise synchronously'); | 205 }, 'Test finish() resolves finished promise synchronously'); |
| 206 |
| 207 promise_test(function(t) { |
| 208 var effect = new KeyframeEffectReadOnly(null, gKeyFrames, 100 * MS_PER_SEC); |
| 209 var animation = new Animation(effect, document.timeline); |
| 210 var resolvedFinished = false; |
| 211 animation.finished.then(function() { |
| 212 resolvedFinished = true; |
| 213 }); |
| 214 |
| 215 return animation.ready.then(function() { |
| 216 animation.finish(); |
| 217 }).then(function() { |
| 218 assert_true(resolvedFinished, |
| 219 'Animation.finished should be resolved soon after ' + |
| 220 'Animation.finish()'); |
| 221 }); |
| 222 }, 'Test finish() resolves finished promise synchronously with an animation ' + |
| 223 'without a target'); |
| 224 |
| 225 promise_test(function(t) { |
| 226 var effect = new KeyframeEffectReadOnly(null, gKeyFrames, 100 * MS_PER_SEC); |
| 227 var animation = new Animation(effect, document.timeline); |
| 228 animation.play(); |
| 229 |
| 230 var resolvedFinished = false; |
| 231 animation.finished.then(function() { |
| 232 resolvedFinished = true; |
| 233 }); |
| 234 |
| 235 return animation.ready.then(function() { |
| 236 animation.currentTime = animation.effect.getComputedTiming().endTime - 1; |
| 237 return waitForAnimationFrames(2); |
| 238 }).then(function() { |
| 239 assert_true(resolvedFinished, |
| 240 'Animation.finished should be resolved soon after ' + |
| 241 'Animation finishes normally'); |
| 242 }); |
| 243 }, 'Test normally finished animation resolves finished promise synchronously ' + |
| 244 'with an animation without a target'); |
| 245 |
| 209 </script> | 246 </script> |
| 210 </body> | 247 </body> |
| OLD | NEW |