processing-a-keyframes-argument-002.html (3723B)
1 <!DOCTYPE html> 2 <meta charset=utf-8> 3 <title>Processing a keyframes argument (easing)</title> 4 <link rel="help" href="https://drafts.csswg.org/web-animations/#processing-a-keyframes-argument"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="../../testcommon.js"></script> 8 <script src="../../resources/easing-tests.js"></script> 9 <body> 10 <div id="log"></div> 11 <div id="target"></div> 12 <script> 13 'use strict'; 14 15 test(() => { 16 for (const [easing, expected] of gEasingParsingTests) { 17 const effect = new KeyframeEffect(target, { 18 left: ['10px', '20px'], 19 easing: easing 20 }); 21 assert_equals(effect.getKeyframes()[0].easing, expected, 22 `resulting easing for '${easing}'`); 23 } 24 }, 'easing values are parsed correctly when set on a property-indexed' 25 + ' keyframe'); 26 27 test(() => { 28 for (const [easing, expected] of gEasingParsingTests) { 29 const effect = new KeyframeEffect(target, [ 30 { offset: 0, left: '10px', easing: easing }, 31 { offset: 1, left: '20px' } 32 ]); 33 assert_equals(effect.getKeyframes()[0].easing, expected, 34 `resulting easing for '${easing}'`); 35 } 36 }, 'easing values are parsed correctly when using a keyframe sequence'); 37 38 test(() => { 39 for (const invalidEasing of gInvalidEasings) { 40 assert_throws_js(TypeError, () => { 41 new KeyframeEffect(target, { easing: invalidEasing }); 42 }, `TypeError is thrown for easing '${invalidEasing}'`); 43 } 44 }, 'Invalid easing values are correctly rejected when set on a property-' 45 + 'indexed keyframe'); 46 47 test(() => { 48 for (const invalidEasing of gInvalidEasings) { 49 assert_throws_js(TypeError, () => { 50 new KeyframeEffect(target, [{ easing: invalidEasing }]); 51 }, `TypeError is thrown for easing '${invalidEasing}'`); 52 } 53 }, 'Invalid easing values are correctly rejected when using a keyframe' 54 + ' sequence'); 55 56 test(() => { 57 let readToEnd = false; 58 const keyframe_obj = { 59 *[Symbol.iterator]() { 60 yield { left: '100px', easing: '' }; 61 yield { left: '200px' }; 62 readToEnd = true; 63 }, 64 }; 65 assert_throws_js( 66 TypeError, 67 () => { 68 new KeyframeEffect(null, keyframe_obj); 69 }, 70 'TypeError is thrown for an invalid easing' 71 ); 72 assert_true( 73 readToEnd, 74 'Read all the keyframe properties before reporting invalid easing' 75 ); 76 }, 'Invalid easing values are correctly rejected after doing all the' 77 + ' iterating'); 78 79 test(() => { 80 let propAccessCount = 0; 81 const keyframe = {}; 82 const addProp = prop => { 83 Object.defineProperty(keyframe, prop, { 84 get: () => { propAccessCount++; }, 85 enumerable: true 86 }); 87 } 88 addProp('height'); 89 addProp('width'); 90 keyframe.easing = 'easy-peasy'; 91 92 assert_throws_js(TypeError, () => { 93 new KeyframeEffect(target, keyframe); 94 }); 95 assert_equals(propAccessCount, 2, 96 'All properties were read before throwing the easing error'); 97 }, 'Errors from invalid easings on a property-indexed keyframe are thrown after reading all properties'); 98 99 test(() => { 100 let propAccessCount = 0; 101 102 const addProp = (keyframe, prop) => { 103 Object.defineProperty(keyframe, prop, { 104 get: () => { propAccessCount++; }, 105 enumerable: true 106 }); 107 } 108 109 const kf1 = {}; 110 addProp(kf1, 'height'); 111 addProp(kf1, 'width'); 112 kf1.easing = 'easy-peasy'; 113 114 const kf2 = {}; 115 addProp(kf2, 'height'); 116 addProp(kf2, 'width'); 117 118 assert_throws_js(TypeError, () => { 119 new KeyframeEffect(target, [ kf1, kf2 ]); 120 }); 121 assert_equals(propAccessCount, 4, 122 'All properties were read before throwing the easing error'); 123 }, 'Errors from invalid easings on a keyframe sequence are thrown after reading all properties'); 124 125 </script>