svgrect-animation-1.html (3091B)
1 <!doctype html> 2 <html> 3 <title>Test from-to SVGRect animation.</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="/resources/SVGAnimationTestCase-testharness.js"></script> 7 8 <svg> 9 </svg> 10 11 <script> 12 var rootSVGElement = document.querySelector("svg"); 13 var epsilon = 1.0; 14 15 // Setup test document 16 var rect = createSVGElement("rect"); 17 rect.setAttribute("width", "100"); 18 rect.setAttribute("height", "100"); 19 rect.setAttribute("fill", "green"); 20 rect.setAttribute("onclick", "executeTest()"); 21 rootSVGElement.appendChild(rect); 22 23 rootSVGElement.setAttribute("id", "svg"); 24 rootSVGElement.setAttribute("viewBox", "0 0 100 100"); 25 26 var animate = createSVGElement("animate"); 27 animate.setAttribute("id", "animation"); 28 animate.setAttribute("attributeName", "viewBox"); 29 animate.setAttribute("begin", "0s"); 30 animate.setAttribute("dur", "4s"); 31 animate.setAttribute("from", "0 0 100 100"); 32 animate.setAttribute("to", "50 50 50 50"); 33 rootSVGElement.appendChild(animate); 34 35 // Setup animation test 36 function sample1() { 37 // Check initial/end conditions 38 assert_approx_equals(rootSVGElement.viewBox.animVal.x, 0, epsilon); 39 assert_approx_equals(rootSVGElement.viewBox.animVal.y, 0, epsilon); 40 assert_approx_equals(rootSVGElement.viewBox.animVal.width, 100, epsilon); 41 assert_approx_equals(rootSVGElement.viewBox.animVal.height, 100, epsilon); 42 43 assert_equals(rootSVGElement.viewBox.baseVal.x, 0); 44 assert_equals(rootSVGElement.viewBox.baseVal.y, 0); 45 assert_equals(rootSVGElement.viewBox.baseVal.width, 100); 46 assert_equals(rootSVGElement.viewBox.baseVal.height, 100); 47 } 48 49 function sample2() { 50 assert_approx_equals(rootSVGElement.viewBox.animVal.x, 25, epsilon); 51 assert_approx_equals(rootSVGElement.viewBox.animVal.y, 25, epsilon); 52 assert_approx_equals(rootSVGElement.viewBox.animVal.width, 75, epsilon); 53 assert_approx_equals(rootSVGElement.viewBox.animVal.height, 75, epsilon); 54 55 assert_equals(rootSVGElement.viewBox.baseVal.x, 0); 56 assert_equals(rootSVGElement.viewBox.baseVal.y, 0); 57 assert_equals(rootSVGElement.viewBox.baseVal.width, 100); 58 assert_equals(rootSVGElement.viewBox.baseVal.height, 100); 59 } 60 61 function sample3() { 62 assert_approx_equals(rootSVGElement.viewBox.animVal.x, 50, epsilon); 63 assert_approx_equals(rootSVGElement.viewBox.animVal.y, 50, epsilon); 64 assert_approx_equals(rootSVGElement.viewBox.animVal.width, 50, epsilon); 65 assert_approx_equals(rootSVGElement.viewBox.animVal.height, 50, epsilon); 66 67 assert_equals(rootSVGElement.viewBox.baseVal.x, 0); 68 assert_equals(rootSVGElement.viewBox.baseVal.y, 0); 69 assert_equals(rootSVGElement.viewBox.baseVal.width, 100); 70 assert_equals(rootSVGElement.viewBox.baseVal.height, 100); 71 } 72 73 smil_async_test((t) => { 74 const expectedValues = [ 75 // [animationId, time, sampleCallback] 76 ["animation", 0.0, sample1], 77 ["animation", 2.0, sample2], 78 ["animation", 3.999, sample3], 79 ["animation", 4.001, sample1] 80 ]; 81 82 runAnimationTest(t, expectedValues); 83 }); 84 85 </script>