OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <meta charset=utf-8> |
| 3 <title>Animation.ready</title> |
| 4 <link rel="help" href="https://w3c.github.io/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 <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({}, 100 * MS_PER_SEC); |
| 17 var originalReadyPromise = animation.ready; |
| 18 var pauseReadyPromise; |
| 19 |
| 20 return animation.ready.then(function() { |
| 21 assert_equals(animation.ready, originalReadyPromise, |
| 22 'Ready promise is the same object when playing completes'); |
| 23 animation.pause(); |
| 24 assert_not_equals(animation.ready, originalReadyPromise, |
| 25 'A new ready promise is created when pausing'); |
| 26 pauseReadyPromise = animation.ready; |
| 27 // Wait for the promise to fulfill since if we abort the pause the ready |
| 28 // promise object is reused. |
| 29 return animation.ready; |
| 30 }).then(function() { |
| 31 animation.play(); |
| 32 assert_not_equals(animation.ready, pauseReadyPromise, |
| 33 'A new ready promise is created when playing'); |
| 34 }); |
| 35 }, 'A new ready promise is created when play()/pause() is called'); |
| 36 |
| 37 promise_test(function(t) { |
| 38 var div = createDiv(t); |
| 39 var animation = div.animate({}, 100 * MS_PER_SEC); |
| 40 |
| 41 return animation.ready.then(function() { |
| 42 var promiseBeforeCallingPlay = animation.ready; |
| 43 animation.play(); |
| 44 assert_equals(animation.ready, promiseBeforeCallingPlay, |
| 45 'Ready promise has same object identity after redundant call' |
| 46 + ' to play()'); |
| 47 }); |
| 48 }, 'Redundant calls to play() do not generate new ready promise objects'); |
| 49 |
| 50 promise_test(function(t) { |
| 51 var div = createDiv(t); |
| 52 var animation = div.animate({}, 100 * MS_PER_SEC); |
| 53 |
| 54 return animation.ready.then(function(resolvedAnimation) { |
| 55 assert_equals(resolvedAnimation, animation, |
| 56 'Object identity of Animation passed to Promise callback' |
| 57 + ' matches the Animation object owning the Promise'); |
| 58 }); |
| 59 }, 'The ready promise is fulfilled with its Animation'); |
| 60 |
| 61 promise_test(function(t) { |
| 62 var div = createDiv(t); |
| 63 var animation = div.animate({}, 100 * MS_PER_SEC); |
| 64 |
| 65 var retPromise = animation.ready.then(function() { |
| 66 assert_unreached('ready promise was fulfilled'); |
| 67 }).catch(function(err) { |
| 68 assert_equals(err.name, 'AbortError', |
| 69 'ready promise is rejected with AbortError'); |
| 70 }); |
| 71 |
| 72 animation.cancel(); |
| 73 |
| 74 return retPromise; |
| 75 }, 'ready promise is rejected when a pause-pending animation is cancelled by' |
| 76 + ' calling cancel()'); |
| 77 |
| 78 promise_test(function(t) { |
| 79 var div = createDiv(t); |
| 80 var animation = div.animate({}, 100 * MS_PER_SEC); |
| 81 return animation.ready.then(function() { |
| 82 animation.pause(); |
| 83 // Set up listeners on pause-pending ready promise |
| 84 var retPromise = animation.ready.then(function() { |
| 85 assert_unreached('ready promise was fulfilled'); |
| 86 }).catch(function(err) { |
| 87 assert_equals(err.name, 'AbortError', |
| 88 'ready promise is rejected with AbortError'); |
| 89 }); |
| 90 animation.cancel(); |
| 91 return retPromise; |
| 92 }); |
| 93 }, 'ready promise is rejected when a pause-pending animation is cancelled by' |
| 94 + ' calling cancel()'); |
| 95 |
| 96 </script> |
| 97 </body> |
OLD | NEW |