| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <meta charset=utf-8> | |
| 3 <title>Animatable.animate tests</title> | |
| 4 <link rel="help" href="http://w3c.github.io/web-animations/#dom-animatable-anima
te"> | |
| 5 <link rel="author" title="Brian Birtles" href="mailto:bbirtles@mozilla.com"> | |
| 6 <script src="../../../../resources/testharness.js"></script> | |
| 7 <script src="../../../../resources/testharnessreport.js"></script> | |
| 8 <script src="../testcommon.js"></script> | |
| 9 <body> | |
| 10 <div id="log"></div> | |
| 11 <script> | |
| 12 'use strict'; | |
| 13 | |
| 14 test(function(t) { | |
| 15 var div = createDiv(t); | |
| 16 var anim = div.animate({ opacity: [ 0, 1 ] }, 2000); | |
| 17 assert_class_string(anim, 'Animation', 'Returned object is an Animation'); | |
| 18 }, 'Element.animate() creates an Animation object'); | |
| 19 | |
| 20 test(function(t) { | |
| 21 var div = createDiv(t); | |
| 22 var anim = div.animate({ opacity: [ 0, 1 ] }, 2000); | |
| 23 assert_class_string(anim.effect, 'KeyframeEffect', | |
| 24 'Returned Animation has a KeyframeEffect'); | |
| 25 }, 'Element.animate() creates an Animation object with a KeyframeEffect'); | |
| 26 | |
| 27 // Animatable.animate() passes its |frames| argument to the KeyframeEffect | |
| 28 // constructor. As a result, detailed tests of the handling of that argument | |
| 29 // are found in the tests for that constructor. Here we just check that the | |
| 30 // different types of arguments are correctly passed along. | |
| 31 | |
| 32 test(function(t) { | |
| 33 var div = createDiv(t); | |
| 34 var anim = div.animate({ opacity: [ 0, 1 ] }, 2000); | |
| 35 assert_equals(anim.effect.getFrames().length, 2); | |
| 36 assert_equals(anim.effect.getFrames()[0].opacity, '0'); | |
| 37 assert_equals(anim.effect.getFrames()[1].opacity, '1'); | |
| 38 }, 'Element.animate() accepts a property-indexed keyframe specification'); | |
| 39 | |
| 40 test(function(t) { | |
| 41 var div = createDiv(t); | |
| 42 var anim = div.animate([ { opacity: 0 }, { opacity: 1 } ], 2000); | |
| 43 assert_equals(anim.effect.getFrames().length, 2); | |
| 44 assert_equals(anim.effect.getFrames()[0].opacity, '0'); | |
| 45 assert_equals(anim.effect.getFrames()[1].opacity, '1'); | |
| 46 }, 'Element.animate() accepts a frame-indexed keyframe specification'); | |
| 47 | |
| 48 test(function(t) { | |
| 49 var div = createDiv(t); | |
| 50 var anim = div.animate({ opacity: 0 }, 2000); | |
| 51 assert_equals(anim.effect.getFrames().length, 1); | |
| 52 assert_equals(anim.effect.getFrames()[0].opacity, '0'); | |
| 53 }, 'Element.animate() accepts a single-valued keyframe specification'); | |
| 54 | |
| 55 // As with the |frames| argument, Animatable.animate() passes its |options| | |
| 56 // argument to the KeyframeEffect constructor as well. As a result, detailed | |
| 57 // tests of the handling of that argument are found in the tests for that | |
| 58 // constructor. Here we just check that the different types of arguments are | |
| 59 // correctly passed along. | |
| 60 | |
| 61 test(function(t) { | |
| 62 var div = createDiv(t); | |
| 63 var anim = div.animate({ opacity: [ 0, 1 ] }, 2000); | |
| 64 assert_equals(anim.effect.timing.duration, 2000); | |
| 65 // Also check that unspecified parameters receive their default values | |
| 66 assert_equals(anim.effect.timing.fill, 'auto'); | |
| 67 }, 'Element.animate() accepts a double as an options argument'); | |
| 68 | |
| 69 test(function(t) { | |
| 70 var div = createDiv(t); | |
| 71 var anim = div.animate({ opacity: [ 0, 1 ] }, | |
| 72 { duration: Infinity, fill: 'forwards' }); | |
| 73 assert_equals(anim.effect.timing.duration, Infinity); | |
| 74 assert_equals(anim.effect.timing.fill, 'forwards'); | |
| 75 // Also check that unspecified parameters receive their default values | |
| 76 assert_equals(anim.effect.timing.direction, 'normal'); | |
| 77 }, 'Element.animate() accepts a KeyframeAnimationOptions argument'); | |
| 78 | |
| 79 test(function(t) { | |
| 80 var div = createDiv(t); | |
| 81 var anim = div.animate({ opacity: [ 0, 1 ] }); | |
| 82 assert_equals(anim.effect.timing.duration, 'auto'); | |
| 83 }, 'Element.animate() accepts an absent options argument'); | |
| 84 | |
| 85 test(function(t) { | |
| 86 var div = createDiv(t); | |
| 87 var anim = div.animate({ opacity: [ 0, 1 ] }, 2000); | |
| 88 assert_equals(anim.id, ''); | |
| 89 }, 'Element.animate() correctly sets the id attribute when no id is specified'); | |
| 90 | |
| 91 test(function(t) { | |
| 92 var div = createDiv(t); | |
| 93 var anim = div.animate({ opacity: [ 0, 1 ] }, { id: 'test' }); | |
| 94 assert_equals(anim.id, 'test'); | |
| 95 }, 'Element.animate() correctly sets the id attribute'); | |
| 96 | |
| 97 test(function(t) { | |
| 98 var div = createDiv(t); | |
| 99 var anim = div.animate({ opacity: [ 0, 1 ] }, 2000); | |
| 100 assert_equals(anim.timeline, document.timeline); | |
| 101 }, 'Element.animate() correctly sets the Animation\'s timeline'); | |
| 102 | |
| 103 async_test(function(t) { | |
| 104 var iframe = document.createElement('iframe'); | |
| 105 iframe.width = 10; | |
| 106 iframe.height = 10; | |
| 107 | |
| 108 iframe.addEventListener('load', t.step_func(function() { | |
| 109 var div = createDiv(t, iframe.contentDocument); | |
| 110 var anim = div.animate({ opacity: [ 0, 1 ] }, 2000); | |
| 111 assert_equals(anim.timeline, iframe.contentDocument.timeline); | |
| 112 iframe.remove(); | |
| 113 t.done(); | |
| 114 })); | |
| 115 | |
| 116 document.body.appendChild(iframe); | |
| 117 }, 'Element.animate() correctly sets the Animation\'s timeline when ' + | |
| 118 'triggered on an element in a different document'); | |
| 119 | |
| 120 test(function(t) { | |
| 121 var div = createDiv(t); | |
| 122 var anim = div.animate({ opacity: [ 0, 1 ] }, 2000); | |
| 123 assert_equals(anim.playState, 'pending'); | |
| 124 }, 'Element.animate() calls play on the Animation'); | |
| 125 | |
| 126 // Tests on CSSPseudoElement | |
| 127 | |
| 128 test(function(t) { | |
| 129 var pseudoTarget = createPseudo(t, 'before'); | |
| 130 var anim = pseudoTarget.animate({ opacity: [ 0, 1 ] }, 2000); | |
| 131 assert_class_string(anim, 'Animation', 'The returned object is an Animation'); | |
| 132 }, 'CSSPseudoElement.animate() creates an Animation object'); | |
| 133 | |
| 134 test(function(t) { | |
| 135 var pseudoTarget = createPseudo(t, 'before'); | |
| 136 var anim = pseudoTarget.animate({ opacity: [ 0, 1 ] }, 2000); | |
| 137 assert_equals(anim.effect.target, pseudoTarget, | |
| 138 'The returned Animation targets to the correct object'); | |
| 139 }, 'CSSPseudoElement.animate() creates an Animation object targeting ' + | |
| 140 'to the correct CSSPseudoElement object'); | |
| 141 </script> | |
| 142 </body> | |
| OLD | NEW |