animVal-basics.html (1910B)
1 <!doctype html> 2 <html> 3 <meta charset="utf-8"> 4 <title>Trivial animVal testcase, to see wheter we support it at all. Should result in a 200x200 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("width", "200"); 20 rect.setAttribute("height", "200"); 21 rect.setAttribute("fill", "green"); 22 rect.setAttribute("onclick", "executeTest()"); 23 24 var animate = createSVGElement("animate"); 25 animate.setAttribute("id", "animation"); 26 animate.setAttribute("attributeName", "width"); 27 animate.setAttribute("from", "200"); 28 animate.setAttribute("to", "100"); 29 animate.setAttribute("begin", "0s"); 30 animate.setAttribute("dur", "4s"); 31 rect.appendChild(animate); 32 rootSVGElement.appendChild(rect); 33 34 // Setup animation test 35 function sample1() { 36 // Check initial/end conditions 37 assert_approx_equals(rect.width.animVal.value, 200, epsilon); 38 assert_equals(rect.width.baseVal.value, 200); 39 } 40 41 function sample2() { 42 // Check half-time conditions 43 assert_approx_equals(rect.width.animVal.value, 150, epsilon); 44 assert_equals(rect.width.baseVal.value, 200); 45 } 46 47 function sample3() { 48 // Check just before-end conditions 49 assert_approx_equals(rect.width.animVal.value, 100, epsilon); 50 assert_equals(rect.width.baseVal.value, 200); 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>