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