| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <meta charset=utf-8> | |
| 3 <title>Animation.onfinish</title> | |
| 4 <link rel="help" href="https://w3c.github.io/web-animations/#dom-animation-onfin
ish"> | |
| 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 async_test(function(t) { | |
| 15 var div = createDiv(t); | |
| 16 var animation = div.animate({}, 100 * MS_PER_SEC); | |
| 17 var finishedTimelineTime; | |
| 18 animation.finished.then(function() { | |
| 19 finishedTimelineTime = animation.timeline.currentTime; | |
| 20 }); | |
| 21 | |
| 22 animation.onfinish = t.step_func_done(function(event) { | |
| 23 assert_equals(event.currentTime, 0, | |
| 24 'event.currentTime should be zero'); | |
| 25 assert_equals(event.timelineTime, finishedTimelineTime, | |
| 26 'event.timelineTime should equal to the animation timeline ' + | |
| 27 'when finished promise is resolved'); | |
| 28 }); | |
| 29 | |
| 30 animation.playbackRate = -1; | |
| 31 }, 'onfinish event is fired when the currentTime < 0 and ' + | |
| 32 'the playbackRate < 0'); | |
| 33 | |
| 34 async_test(function(t) { | |
| 35 var div = createDiv(t); | |
| 36 var animation = div.animate({}, 100 * MS_PER_SEC); | |
| 37 | |
| 38 var finishedTimelineTime; | |
| 39 animation.finished.then(function() { | |
| 40 finishedTimelineTime = animation.timeline.currentTime; | |
| 41 }); | |
| 42 | |
| 43 animation.onfinish = t.step_func_done(function(event) { | |
| 44 assert_equals(event.currentTime, 100 * MS_PER_SEC, | |
| 45 'event.currentTime should be the effect end'); | |
| 46 assert_equals(event.timelineTime, finishedTimelineTime, | |
| 47 'event.timelineTime should equal to the animation timeline ' + | |
| 48 'when finished promise is resolved'); | |
| 49 }); | |
| 50 | |
| 51 animation.currentTime = 100 * MS_PER_SEC; | |
| 52 }, 'onfinish event is fired when the currentTime > 0 and ' + | |
| 53 'the playbackRate > 0'); | |
| 54 | |
| 55 async_test(function(t) { | |
| 56 var div = createDiv(t); | |
| 57 var animation = div.animate({}, 100 * MS_PER_SEC); | |
| 58 | |
| 59 var finishedTimelineTime; | |
| 60 animation.finished.then(function() { | |
| 61 finishedTimelineTime = animation.timeline.currentTime; | |
| 62 }); | |
| 63 | |
| 64 animation.onfinish = t.step_func_done(function(event) { | |
| 65 assert_equals(event.currentTime, 100 * MS_PER_SEC, | |
| 66 'event.currentTime should be the effect end'); | |
| 67 assert_equals(event.timelineTime, finishedTimelineTime, | |
| 68 'event.timelineTime should equal to the animation timeline ' + | |
| 69 'when finished promise is resolved'); | |
| 70 }); | |
| 71 | |
| 72 animation.finish(); | |
| 73 }, 'onfinish event is fired when animation.finish() is called'); | |
| 74 | |
| 75 promise_test(function(t) { | |
| 76 var div = createDiv(t); | |
| 77 var animation = div.animate({}, 100 * MS_PER_SEC); | |
| 78 | |
| 79 animation.onfinish = function(event) { | |
| 80 assert_unreached('onfinish event should not be fired'); | |
| 81 }; | |
| 82 | |
| 83 animation.currentTime = 100 * MS_PER_SEC / 2; | |
| 84 animation.pause(); | |
| 85 | |
| 86 return animation.ready.then(function() { | |
| 87 animation.currentTime = 100 * MS_PER_SEC; | |
| 88 return waitForAnimationFrames(2); | |
| 89 }); | |
| 90 }, 'onfinish event is not fired when paused'); | |
| 91 | |
| 92 promise_test(function(t) { | |
| 93 var div = createDiv(t); | |
| 94 var animation = div.animate({}, 100 * MS_PER_SEC); | |
| 95 animation.onfinish = function(event) { | |
| 96 assert_unreached('onfinish event should not be fired'); | |
| 97 }; | |
| 98 | |
| 99 return animation.ready.then(function() { | |
| 100 animation.playbackRate = 0; | |
| 101 animation.currentTime = 100 * MS_PER_SEC; | |
| 102 return waitForAnimationFrames(2); | |
| 103 }); | |
| 104 }, 'onfinish event is not fired when the playbackRate is zero'); | |
| 105 | |
| 106 promise_test(function(t) { | |
| 107 var div = createDiv(t); | |
| 108 var animation = div.animate({}, 100 * MS_PER_SEC); | |
| 109 animation.onfinish = function(event) { | |
| 110 assert_unreached('onfinish event should not be fired'); | |
| 111 }; | |
| 112 | |
| 113 return animation.ready.then(function() { | |
| 114 animation.currentTime = 100 * MS_PER_SEC; | |
| 115 animation.currentTime = 100 * MS_PER_SEC / 2; | |
| 116 return waitForAnimationFrames(2); | |
| 117 }); | |
| 118 }, 'onfinish event is not fired when the animation falls out ' + | |
| 119 'finished state immediately'); | |
| 120 | |
| 121 </script> | |
| 122 </body> | |
| OLD | NEW |