OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <meta charset=utf-8> |
| 3 <title>Animation.pause()</title> |
| 4 <link rel="help" href="https://w3c.github.io/web-animations/#dom-animation-pause
"> |
| 5 <script src="../../../../resources/testharness.js"></script> |
| 6 <script src="../../../../resources/testharnessreport.js"></script> |
| 7 <script src="../testcommon.js"></script> |
| 8 <link rel="stylesheet" href="../../../../resources/testharness.css"> |
| 9 <body> |
| 10 <div id="log"></div> |
| 11 <script> |
| 12 "use strict"; |
| 13 |
| 14 promise_test(function(t) { |
| 15 var div = createDiv(t); |
| 16 var animation = div.animate({}, 1000 * MS_PER_SEC); |
| 17 var previousCurrentTime = animation.currentTime; |
| 18 |
| 19 return animation.ready.then(waitForAnimationFrames(1)).then(function() { |
| 20 assert_true(animation.currentTime >= previousCurrentTime, |
| 21 'currentTime is initially increasing'); |
| 22 animation.pause(); |
| 23 return animation.ready; |
| 24 }).then(function() { |
| 25 previousCurrentTime = animation.currentTime; |
| 26 return waitForAnimationFrames(1); |
| 27 }).then(function() { |
| 28 assert_equals(animation.currentTime, previousCurrentTime, |
| 29 'currentTime does not increase after calling pause()'); |
| 30 }); |
| 31 }, 'pause() a running animation'); |
| 32 |
| 33 promise_test(function(t) { |
| 34 var div = createDiv(t); |
| 35 var animation = div.animate({}, 1000 * MS_PER_SEC); |
| 36 |
| 37 // Go to idle state then pause |
| 38 animation.cancel(); |
| 39 animation.pause(); |
| 40 |
| 41 assert_equals(animation.currentTime, 0, 'currentTime is set to 0'); |
| 42 assert_equals(animation.startTime, null, 'startTime is not set'); |
| 43 assert_equals(animation.playState, 'pending', 'initially pause-pending'); |
| 44 |
| 45 // Check it still resolves as expected |
| 46 return animation.ready.then(function() { |
| 47 assert_equals(animation.playState, 'paused', |
| 48 'resolves to paused state asynchronously'); |
| 49 assert_equals(animation.currentTime, 0, |
| 50 'keeps the initially set currentTime'); |
| 51 }); |
| 52 }, 'pause() from idle'); |
| 53 |
| 54 promise_test(function(t) { |
| 55 var div = createDiv(t); |
| 56 var animation = div.animate({}, 1000 * MS_PER_SEC); |
| 57 animation.cancel(); |
| 58 animation.playbackRate = -1; |
| 59 animation.pause(); |
| 60 |
| 61 assert_equals(animation.currentTime, 1000 * MS_PER_SEC, |
| 62 'currentTime is set to the effect end'); |
| 63 |
| 64 return animation.ready.then(function() { |
| 65 assert_equals(animation.currentTime, 1000 * MS_PER_SEC, |
| 66 'keeps the initially set currentTime'); |
| 67 }); |
| 68 }, 'pause() from idle with a negative playbackRate'); |
| 69 |
| 70 test(function(t) { |
| 71 var div = createDiv(t); |
| 72 var animation = div.animate({}, {duration: 1000 * MS_PER_SEC, |
| 73 iterations: Infinity}); |
| 74 animation.cancel(); |
| 75 animation.playbackRate = -1; |
| 76 |
| 77 assert_throws('InvalidStateError', |
| 78 function () { animation.pause(); }, |
| 79 'Expect InvalidStateError exception on calling pause() ' + |
| 80 'from idle with a negative playbackRate and ' + |
| 81 'infinite-duration animation'); |
| 82 }, 'pause() from idle with a negative playbackRate and endless effect'); |
| 83 |
| 84 promise_test(function(t) { |
| 85 var div = createDiv(t); |
| 86 var animation = div.animate({}, 1000 * MS_PER_SEC); |
| 87 return animation.ready |
| 88 .then(function(animation) { |
| 89 animation.finish(); |
| 90 animation.pause(); |
| 91 return animation.ready; |
| 92 }).then(function(animation) { |
| 93 assert_equals(animation.currentTime, 1000 * MS_PER_SEC, |
| 94 'currentTime after pausing finished animation'); |
| 95 }); |
| 96 }, 'pause() on a finished animation'); |
| 97 |
| 98 </script> |
| 99 </body> |
OLD | NEW |