animate-keySplines.html (2251B)
1 <!doctype html> 2 <html> 3 <meta charset="utf-8"> 4 <title>Testing correct parsing of keySplines.</title> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="/resources/SVGAnimationTestCase-testharness.js"></script> 8 9 <svg> 10 </svg> 11 12 <script> 13 var rootSVGElement = document.querySelector("svg"); 14 var epsilon = 1.0; 15 16 // Setup test document 17 var rect = createSVGElement("rect"); 18 rect.setAttribute("id", "rect"); 19 rect.setAttribute("fill", "green"); 20 rect.setAttribute("x", "0"); 21 rect.setAttribute("y", "0"); 22 rect.setAttribute("width", "100"); 23 rect.setAttribute("height", "100"); 24 rect.setAttribute("onclick", "executeTest()"); 25 26 var animate = createSVGElement("animate"); 27 animate.setAttribute("id", "animation"); 28 animate.setAttribute("attributeName", "height"); 29 animate.setAttribute("calcMode", "spline"); 30 animate.setAttribute("keyTimes", " 0 ; 0.3333333 ; 0.666666; 1 "); 31 animate.setAttribute("keySplines", " 0 ,0 1 , 1 ; 0 0 , 1 , 1 ; .75 , 0 , 0 , .75 ; "); 32 animate.setAttribute("values", "200;167;111;0"); 33 animate.setAttribute("begin", "0s"); 34 animate.setAttribute("dur", "9s"); 35 rect.appendChild(animate); 36 rootSVGElement.appendChild(rect); 37 38 // Setup animation test 39 function sample1() { 40 // Check initial/end conditions 41 assert_approx_equals(rect.height.animVal.value, 167, epsilon); 42 assert_equals(rect.height.baseVal.value, 100); 43 } 44 45 function sample2() { 46 // Check half-time conditions 47 assert_approx_equals(rect.height.animVal.value, 111, epsilon); 48 assert_equals(rect.height.baseVal.value, 100); 49 } 50 51 function sample3() { 52 // Check just before-end conditions 53 assert_approx_equals(rect.height.animVal.value, 0, epsilon); 54 assert_equals(rect.height.baseVal.value, 100); 55 } 56 57 function sample4() { 58 // Check end conditions 59 assert_approx_equals(rect.height.animVal.value, 100, epsilon); 60 assert_equals(rect.height.baseVal.value, 100); 61 } 62 63 smil_async_test((t) => { 64 const expectedValues = [ 65 // [animationId, time, sampleCallback] 66 ["animation", 3.0, sample1], 67 ["animation", 6.0, sample2], 68 ["animation", 8.999, sample3], 69 ["animation", 9.001, sample4] 70 ]; 71 72 runAnimationTest(t, expectedValues); 73 }); 74 75 </script>