animate-calcMode-spline-from-to.html (2060B)
1 <!doctype html> 2 <html> 3 <meta charset="utf-8"> 4 <title>Test calcMode spline with from-to animation. You should see a green 100x100 rect and only PASS messages</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("x", "100"); 20 rect.setAttribute("width", "100"); 21 rect.setAttribute("height", "100"); 22 rect.setAttribute("fill", "green"); 23 rect.setAttribute("onclick", "executeTest()"); 24 25 var animate = createSVGElement("animate"); 26 animate.setAttribute("id", "animation"); 27 animate.setAttribute("attributeName", "x"); 28 animate.setAttribute("from", "100"); 29 animate.setAttribute("to", "0"); 30 animate.setAttribute("begin", "0s"); 31 animate.setAttribute("dur", "4s"); 32 animate.setAttribute("keyTimes", "0;1"); 33 animate.setAttribute("keySplines", "0.25 .5 .25 0.85"); 34 animate.setAttribute("calcMode", "spline"); 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.x.animVal.value, 100, epsilon); 42 assert_equals(rect.x.baseVal.value, 100); 43 } 44 45 function sample2() { 46 // Check half-time conditions 47 assert_approx_equals(rect.x.animVal.value, 18.8, epsilon); 48 assert_equals(rect.x.baseVal.value, 100); 49 } 50 51 function sample3() { 52 // Check just before-end conditions 53 assert_approx_equals(rect.x.animVal.value, 0, epsilon); 54 assert_equals(rect.x.baseVal.value, 100); 55 } 56 57 smil_async_test((t) => { 58 const expectedValues = [ 59 // [animationId, time, sampleCallback] 60 ["animation", 0.0, sample1], 61 ["animation", 2.0, sample2], 62 ["animation", 3.999, sample3], 63 ["animation", 4.001, sample1] 64 ]; 65 66 runAnimationTest(t, expectedValues); 67 }); 68 69 window.clickX = 150; 70 71 </script>