| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <meta charset=utf-8> | 2 <meta charset=utf-8> |
| 3 <title>Animatable.animate tests</title> | 3 <title>Animatable.animate tests</title> |
| 4 <link rel="help" href="http://w3c.github.io/web-animations/#dom-animatable-anima
te"> | 4 <link rel="help" href="https://w3c.github.io/web-animations/#dom-animatable-anim
ate"> |
| 5 <link rel="author" title="Brian Birtles" href="mailto:bbirtles@mozilla.com"> | 5 <script src="../../../../../resources/testharness.js"></script> |
| 6 <script src="../../../../resources/testharness.js"></script> | 6 <script src="../../../../../resources/testharnessreport.js"></script> |
| 7 <script src="../../../../resources/testharnessreport.js"></script> | 7 <script src="../../testcommon.js"></script> |
| 8 <script src="../testcommon.js"></script> | 8 <script src="../../resources/keyframe-utils.js"></script> |
| 9 <body> | 9 <body> |
| 10 <div id="log"></div> | 10 <div id="log"></div> |
| 11 <script> | 11 <script> |
| 12 'use strict'; | 12 'use strict'; |
| 13 | 13 |
| 14 // Tests on Element |
| 15 |
| 14 test(function(t) { | 16 test(function(t) { |
| 15 var div = createDiv(t); | 17 var div = createDiv(t); |
| 16 var anim = div.animate({ opacity: [ 0, 1 ] }, 2000); | 18 var anim = div.animate(null); |
| 17 assert_class_string(anim, 'Animation', 'Returned object is an Animation'); | 19 assert_class_string(anim, 'Animation', 'Returned object is an Animation'); |
| 18 }, 'Element.animate() creates an Animation object'); | 20 }, 'Element.animate() creates an Animation object'); |
| 19 | 21 |
| 20 test(function(t) { | 22 test(function(t) { |
| 21 var div = createDiv(t); | 23 var div = createDiv(t); |
| 22 var anim = div.animate({ opacity: [ 0, 1 ] }, 2000); | 24 var anim = div.animate(null); |
| 23 assert_class_string(anim.effect, 'KeyframeEffect', | 25 assert_class_string(anim.effect, 'KeyframeEffect', |
| 24 'Returned Animation has a KeyframeEffect'); | 26 'Returned Animation has a KeyframeEffect'); |
| 25 }, 'Element.animate() creates an Animation object with a KeyframeEffect'); | 27 }, 'Element.animate() creates an Animation object with a KeyframeEffect'); |
| 26 | 28 |
| 27 // Animatable.animate() passes its |frames| argument to the KeyframeEffect | 29 gPropertyIndexedKeyframesTests.forEach(function(subtest) { |
| 28 // constructor. As a result, detailed tests of the handling of that argument | 30 test(function(t) { |
| 29 // are found in the tests for that constructor. Here we just check that the | 31 var div = createDiv(t); |
| 30 // different types of arguments are correctly passed along. | 32 var anim = div.animate(subtest.input, 2000); |
| 33 assert_frame_lists_equal(anim.effect.getKeyframes(), subtest.output); |
| 34 }, 'Element.animate() accepts ' + subtest.desc); |
| 35 }); |
| 36 |
| 37 gKeyframeSequenceTests.forEach(function(subtest) { |
| 38 test(function(t) { |
| 39 var div = createDiv(t); |
| 40 var anim = div.animate(subtest.input, 2000); |
| 41 assert_frame_lists_equal(anim.effect.getKeyframes(), subtest.output); |
| 42 }, 'Element.animate() accepts ' + subtest.desc); |
| 43 }); |
| 44 |
| 45 gInvalidKeyframesTests.forEach(function(subtest) { |
| 46 test(function(t) { |
| 47 var div = createDiv(t); |
| 48 assert_throws(subtest.expected, function() { |
| 49 div.animate(subtest.input, 2000); |
| 50 }); |
| 51 }, 'Element.animate() does not accept ' + subtest.desc); |
| 52 }); |
| 31 | 53 |
| 32 test(function(t) { | 54 test(function(t) { |
| 33 var div = createDiv(t); | 55 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); | 56 var anim = div.animate({ opacity: [ 0, 1 ] }, 2000); |
| 64 assert_equals(anim.effect.timing.duration, 2000); | 57 assert_equals(anim.effect.timing.duration, 2000); |
| 65 // Also check that unspecified parameters receive their default values | 58 // Also check that unspecified parameters receive their default values |
| 66 assert_equals(anim.effect.timing.fill, 'auto'); | 59 assert_equals(anim.effect.timing.fill, 'auto'); |
| 67 }, 'Element.animate() accepts a double as an options argument'); | 60 }, 'Element.animate() accepts a double as an options argument'); |
| 68 | 61 |
| 69 test(function(t) { | 62 test(function(t) { |
| 70 var div = createDiv(t); | 63 var div = createDiv(t); |
| 71 var anim = div.animate({ opacity: [ 0, 1 ] }, | 64 var anim = div.animate({ opacity: [ 0, 1 ] }, |
| 72 { duration: Infinity, fill: 'forwards' }); | 65 { duration: Infinity, fill: 'forwards' }); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 test(function(t) { | 113 test(function(t) { |
| 121 var div = createDiv(t); | 114 var div = createDiv(t); |
| 122 var anim = div.animate({ opacity: [ 0, 1 ] }, 2000); | 115 var anim = div.animate({ opacity: [ 0, 1 ] }, 2000); |
| 123 assert_equals(anim.playState, 'pending'); | 116 assert_equals(anim.playState, 'pending'); |
| 124 }, 'Element.animate() calls play on the Animation'); | 117 }, 'Element.animate() calls play on the Animation'); |
| 125 | 118 |
| 126 // Tests on CSSPseudoElement | 119 // Tests on CSSPseudoElement |
| 127 | 120 |
| 128 test(function(t) { | 121 test(function(t) { |
| 129 var pseudoTarget = createPseudo(t, 'before'); | 122 var pseudoTarget = createPseudo(t, 'before'); |
| 130 var anim = pseudoTarget.animate({ opacity: [ 0, 1 ] }, 2000); | 123 var anim = pseudoTarget.animate(null); |
| 131 assert_class_string(anim, 'Animation', 'The returned object is an Animation'); | 124 assert_class_string(anim, 'Animation', 'The returned object is an Animation'); |
| 132 }, 'CSSPseudoElement.animate() creates an Animation object'); | 125 }, 'CSSPseudoElement.animate() creates an Animation object'); |
| 133 | 126 |
| 134 test(function(t) { | 127 test(function(t) { |
| 135 var pseudoTarget = createPseudo(t, 'before'); | 128 var pseudoTarget = createPseudo(t, 'before'); |
| 136 var anim = pseudoTarget.animate({ opacity: [ 0, 1 ] }, 2000); | 129 var anim = pseudoTarget.animate(null); |
| 137 assert_equals(anim.effect.target, pseudoTarget, | 130 assert_equals(anim.effect.target, pseudoTarget, |
| 138 'The returned Animation targets to the correct object'); | 131 'The returned Animation targets to the correct object'); |
| 139 }, 'CSSPseudoElement.animate() creates an Animation object targeting ' + | 132 }, 'CSSPseudoElement.animate() creates an Animation object targeting ' + |
| 140 'to the correct CSSPseudoElement object'); | 133 'to the correct CSSPseudoElement object'); |
| 141 </script> | 134 </script> |
| 142 </body> | 135 </body> |
| OLD | NEW |