svglength-animation-px-to-number.html (1794B)
1 <!doctype html> 2 <html> 3 <meta charset="utf-8"> 4 <title>Test SVGLength animation from px to number.</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", "0"); 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", "width"); 28 animate.setAttribute("begin", "0s"); 29 animate.setAttribute("dur", "4s"); 30 animate.setAttribute("from", "100px"); 31 animate.setAttribute("to", "200"); 32 rect.appendChild(animate); 33 rootSVGElement.appendChild(rect); 34 35 // Setup animation test 36 function sample1() { 37 // Check initial/end conditions 38 assert_approx_equals(rect.width.animVal.value, 100, epsilon); 39 assert_equals(rect.width.baseVal.value, 100); 40 } 41 42 function sample2() { 43 assert_approx_equals(rect.width.animVal.value, 150, epsilon); 44 assert_equals(rect.width.baseVal.value, 100); 45 } 46 47 function sample3() { 48 assert_approx_equals(rect.width.animVal.value, 200, epsilon); 49 assert_equals(rect.width.baseVal.value, 100); 50 } 51 52 smil_async_test((t) => { 53 const expectedValues = [ 54 // [animationId, time, sampleCallback] 55 ["animation", 0.0, sample1], 56 ["animation", 2.0, sample2], 57 ["animation", 3.999, sample3], 58 ["animation", 4.001, sample1] 59 ]; 60 61 runAnimationTest(t, expectedValues); 62 }); 63 64 </script>