onremove.html (1867B)
1 <!DOCTYPE html> 2 <meta charset=utf-8> 3 <title>Animation.onremove</title> 4 <link rel="help" href="https://drafts.csswg.org/web-animations/#dom-animation-onremove"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="../../testcommon.js"></script> 8 <body> 9 <div id="log"></div> 10 <script> 11 'use strict'; 12 13 async_test(t => { 14 const div = createDiv(t); 15 const animA = div.animate({ opacity: 1 }, { duration: 1, fill: 'forwards' }); 16 const animB = div.animate({ opacity: 1 }, { duration: 1, fill: 'forwards' }); 17 18 let finishedTimelineTime = null; 19 animB.onfinish = event => { 20 finishedTimelineTime = event.timelineTime; 21 }; 22 23 animA.onremove = t.step_func_done(event => { 24 assert_equals(animA.replaceState, 'removed'); 25 assert_equals(event.currentTime, 1); 26 assert_true(finishedTimelineTime != null, 'finished event fired'); 27 assert_equals(event.timelineTime, finishedTimelineTime, 28 'timeline time is set'); 29 }); 30 31 }, 'onremove event is fired when replaced animation is removed.'); 32 33 promise_test(async t => { 34 const div = createDiv(t); 35 const animA = div.animate({ opacity: 1 }, { duration: 1, fill: 'forwards' }); 36 const animB = div.animate({ opacity: 1 }, { duration: 1, fill: 'forwards' }); 37 const animC = div.animate({ opacity: 1 }, { duration: 1, fill: 'forwards' }); 38 const animD = div.animate({ opacity: 1 }, { duration: 1, fill: 'forwards' }); 39 40 const removed = []; 41 42 animA.onremove = () => { removed.push('A'); }; 43 animB.onremove = () => { removed.push('B'); }; 44 animC.onremove = () => { removed.push('C'); }; 45 46 animD.onremove = event => { 47 assert_unreached('onremove event should not be fired'); 48 }; 49 50 await waitForAnimationFrames(2); 51 52 assert_equals(removed.join(''), 'ABC'); 53 54 }, 'onremove events are fired in the correct order'); 55 56 </script> 57 </body>