ready.html (2694B)
1 <!DOCTYPE html> 2 <meta charset=utf-8> 3 <title>Animation.ready</title> 4 <link rel="help" href="https://drafts.csswg.org/web-animations/#dom-animation-ready"> 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 promise_test(t => { 14 const div = createDiv(t); 15 const animation = div.animate(null, 100 * MS_PER_SEC); 16 const originalReadyPromise = animation.ready; 17 let pauseReadyPromise; 18 19 return animation.ready.then(() => { 20 assert_equals(animation.ready, originalReadyPromise, 21 'Ready promise is the same object when playing completes'); 22 animation.pause(); 23 assert_not_equals(animation.ready, originalReadyPromise, 24 'A new ready promise is created when pausing'); 25 pauseReadyPromise = animation.ready; 26 // Wait for the promise to fulfill since if we abort the pause the ready 27 // promise object is reused. 28 return animation.ready; 29 }).then(() => { 30 animation.play(); 31 assert_not_equals(animation.ready, pauseReadyPromise, 32 'A new ready promise is created when playing'); 33 }); 34 }, 'A new ready promise is created when play()/pause() is called'); 35 36 promise_test(t => { 37 const div = createDiv(t); 38 const animation = div.animate(null, 100 * MS_PER_SEC); 39 40 return animation.ready.then(() => { 41 const promiseBeforeCallingPlay = animation.ready; 42 animation.play(); 43 assert_equals(animation.ready, promiseBeforeCallingPlay, 44 'Ready promise has same object identity after redundant call' 45 + ' to play()'); 46 }); 47 }, 'Redundant calls to play() do not generate new ready promise objects'); 48 49 promise_test(t => { 50 const div = createDiv(t); 51 const animation = div.animate(null, 100 * MS_PER_SEC); 52 53 return animation.ready.then(resolvedAnimation => { 54 assert_equals(resolvedAnimation, animation, 55 'Object identity of Animation passed to Promise callback' 56 + ' matches the Animation object owning the Promise'); 57 }); 58 }, 'The ready promise is fulfilled with its Animation'); 59 60 promise_test(async t => { 61 const animation = createDiv(t).animate(null, 100 * MS_PER_SEC); 62 63 // Ensure the ready promise is created 64 const ready = animation.ready; 65 66 window.addEventListener( 67 'unhandledrejection', 68 t.unreached_func('Should not get an unhandled rejection') 69 ); 70 71 animation.cancel(); 72 73 // Wait a moment to allow a chance for the event to be dispatched. 74 await waitForAnimationFrames(2); 75 }, 'The ready promise does not report an unhandledrejection when rejected'); 76 77 </script> 78 </body>