svglength-animation-LengthModeHeight.html (1956B)
1 <!doctype html> 2 <html> 3 <meta charset="utf-8"> 4 <title>Test SVGLength animation on LengthModeHeight.</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 rootSVGElement.setAttribute("width", "600"); 18 rootSVGElement.setAttribute("height", "400"); 19 20 // Setup test document 21 var rect = createSVGElement("rect"); 22 rect.setAttribute("id", "rect"); 23 rect.setAttribute("x", "0"); 24 rect.setAttribute("width", "100"); 25 rect.setAttribute("height", "100"); 26 rect.setAttribute("fill", "green"); 27 rect.setAttribute("font-size", "10px"); 28 rect.setAttribute("onclick", "executeTest()"); 29 30 var animate = createSVGElement("animate"); 31 animate.setAttribute("id", "animation"); 32 animate.setAttribute("attributeName", "height"); 33 animate.setAttribute("begin", "0s"); 34 animate.setAttribute("dur", "4s"); 35 animate.setAttribute("from", "100"); 36 animate.setAttribute("to", "50%"); 37 rect.appendChild(animate); 38 rootSVGElement.appendChild(rect); 39 40 // Setup animation test 41 function sample1() { 42 // Check initial/end conditions 43 assert_approx_equals(rect.height.animVal.value, 100, epsilon); 44 assert_equals(rect.height.baseVal.value, 100); 45 } 46 47 function sample2() { 48 assert_approx_equals(rect.height.animVal.value, 150, epsilon); 49 assert_equals(rect.height.baseVal.value, 100); 50 } 51 52 function sample3() { 53 assert_approx_equals(rect.height.animVal.value, 200, epsilon); 54 assert_equals(rect.height.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 </script>