OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <meta charset=utf-8> |
| 3 <title>Animation.reverse()</title> |
| 4 <link rel="help" href="https://w3c.github.io/web-animations/#dom-animation-rever
se"> |
| 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({}, {duration: 100 * MS_PER_SEC, |
| 17 iterations: Infinity}); |
| 18 |
| 19 // Wait a frame because if currentTime is still 0 when we call |
| 20 // reverse(), it will throw (per spec). |
| 21 return animation.ready.then(waitForAnimationFrames(1)).then(function() { |
| 22 assert_greater_than_equal(animation.currentTime, 0, |
| 23 'currentTime expected to be greater than 0, one frame after starting'); |
| 24 animation.currentTime = 50 * MS_PER_SEC; |
| 25 var previousPlaybackRate = animation.playbackRate; |
| 26 animation.reverse(); |
| 27 assert_equals(animation.playbackRate, -previousPlaybackRate, |
| 28 'playbackRate should be inverted'); |
| 29 }); |
| 30 }, 'reverse() inverts playbackRate'); |
| 31 |
| 32 promise_test(function(t) { |
| 33 var div = createDiv(t); |
| 34 var animation = div.animate({}, {duration: 100 * MS_PER_SEC, |
| 35 iterations: Infinity}); |
| 36 animation.currentTime = 50 * MS_PER_SEC; |
| 37 animation.pause(); |
| 38 |
| 39 return animation.ready.then(function() { |
| 40 animation.reverse(); |
| 41 return animation.ready; |
| 42 }).then(function() { |
| 43 assert_equals(animation.playState, 'running', |
| 44 'Animation.playState should be "running" after reverse()'); |
| 45 }); |
| 46 }, 'reverse() starts to play when pausing animation'); |
| 47 |
| 48 test(function(t) { |
| 49 var div = createDiv(t); |
| 50 var animation = div.animate({}, 100 * MS_PER_SEC); |
| 51 animation.currentTime = 50 * MS_PER_SEC; |
| 52 animation.reverse(); |
| 53 |
| 54 assert_equals(animation.currentTime, 50 * MS_PER_SEC, |
| 55 'reverse() should not change the currentTime ' + |
| 56 'if the currentTime is in the middle of animation duration'); |
| 57 }, 'reverse() maintains the same currentTime'); |
| 58 |
| 59 test(function(t) { |
| 60 var div = createDiv(t); |
| 61 var animation = div.animate({}, 100 * MS_PER_SEC); |
| 62 animation.currentTime = 200 * MS_PER_SEC; |
| 63 animation.reverse(); |
| 64 |
| 65 assert_equals(animation.currentTime, 100 * MS_PER_SEC, |
| 66 'reverse() should start playing from the animation effect end ' + |
| 67 'if the playbackRate > 0 and the currentTime > effect end'); |
| 68 }, 'reverse() when playbackRate > 0 and currentTime > effect end'); |
| 69 |
| 70 test(function(t) { |
| 71 var div = createDiv(t); |
| 72 var animation = div.animate({}, 100 * MS_PER_SEC); |
| 73 |
| 74 animation.currentTime = -200 * MS_PER_SEC; |
| 75 animation.reverse(); |
| 76 |
| 77 assert_equals(animation.currentTime, 100 * MS_PER_SEC, |
| 78 'reverse() should start playing from the animation effect end ' + |
| 79 'if the playbackRate > 0 and the currentTime < 0'); |
| 80 }, 'reverse() when playbackRate > 0 and currentTime < 0'); |
| 81 |
| 82 test(function(t) { |
| 83 var div = createDiv(t); |
| 84 var animation = div.animate({}, 100 * MS_PER_SEC); |
| 85 animation.playbackRate = -1; |
| 86 animation.currentTime = -200 * MS_PER_SEC; |
| 87 animation.reverse(); |
| 88 |
| 89 assert_equals(animation.currentTime, 0, |
| 90 'reverse() should start playing from the start of animation time ' + |
| 91 'if the playbackRate < 0 and the currentTime < 0'); |
| 92 }, 'reverse() when playbackRate < 0 and currentTime < 0'); |
| 93 |
| 94 test(function(t) { |
| 95 var div = createDiv(t); |
| 96 var animation = div.animate({}, 100 * MS_PER_SEC); |
| 97 animation.playbackRate = -1; |
| 98 animation.currentTime = 200 * MS_PER_SEC; |
| 99 animation.reverse(); |
| 100 |
| 101 assert_equals(animation.currentTime, 0, |
| 102 'reverse() should start playing from the start of animation time ' + |
| 103 'if the playbackRate < 0 and the currentTime > effect end'); |
| 104 }, 'reverse() when playbackRate < 0 and currentTime > effect end'); |
| 105 |
| 106 test(function(t) { |
| 107 var div = createDiv(t); |
| 108 var animation = div.animate({}, {duration: 100 * MS_PER_SEC, |
| 109 iterations: Infinity}); |
| 110 animation.currentTime = -200 * MS_PER_SEC; |
| 111 |
| 112 assert_throws('InvalidStateError', |
| 113 function () { animation.reverse(); }, |
| 114 'reverse() should throw InvalidStateError ' + |
| 115 'if the playbackRate > 0 and the currentTime < 0 ' + |
| 116 'and the target effect is positive infinity'); |
| 117 }, 'reverse() when playbackRate > 0 and currentTime < 0 ' + |
| 118 'and the target effect end is positive infinity'); |
| 119 |
| 120 test(function(t) { |
| 121 var div = createDiv(t); |
| 122 var animation = div.animate({}, {duration: 100 * MS_PER_SEC, |
| 123 iterations: Infinity}); |
| 124 animation.playbackRate = -1; |
| 125 animation.currentTime = -200 * MS_PER_SEC; |
| 126 animation.reverse(); |
| 127 |
| 128 assert_equals(animation.currentTime, 0, |
| 129 'reverse() should start playing from the start of animation time ' + |
| 130 'if the playbackRate < 0 and the currentTime < 0 ' + |
| 131 'and the target effect is positive infinity'); |
| 132 }, 'reverse() when playbackRate < 0 and currentTime < 0 ' + |
| 133 'and the target effect end is positive infinity'); |
| 134 |
| 135 test(function(t) { |
| 136 var div = createDiv(t); |
| 137 var animation = div.animate({}, 100 * MS_PER_SEC); |
| 138 animation.playbackRate = 0; |
| 139 animation.currentTime = 50 * MS_PER_SEC; |
| 140 animation.reverse(); |
| 141 |
| 142 assert_equals(animation.playbackRate, 0, |
| 143 'reverse() should preserve playbackRate if the playbackRate == 0'); |
| 144 assert_equals(animation.currentTime, 50 * MS_PER_SEC, |
| 145 'reverse() should not affect the currentTime if the playbackRate == 0'); |
| 146 t.done(); |
| 147 }, 'reverse() when playbackRate == 0'); |
| 148 |
| 149 </script> |
| 150 </body> |
OLD | NEW |