animate-insert-begin.html (1592B)
1 <!doctype html> 2 <html> 3 <meta charset="utf-8"> 4 <title>Test behavior of dynamically inserting animate with begin attribute</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("y", "45"); 21 rect.setAttribute("width", "10"); 22 rect.setAttribute("height", "10"); 23 rect.setAttribute("fill", "green"); 24 25 var animate = createSVGElement("animate"); 26 animate.setAttribute("id", "animation"); 27 animate.setAttribute("attributeName", "x"); 28 animate.setAttribute("begin", "0"); 29 animate.setAttribute("from", "0"); 30 animate.setAttribute("to", "90"); 31 animate.setAttribute("dur", "3s"); 32 animate.setAttribute("fill", "freeze"); 33 rect.appendChild(animate); 34 rootSVGElement.appendChild(rect); 35 36 // Setup animation test 37 function sample1() { 38 assert_approx_equals(rect.x.animVal.value, 0, epsilon); 39 assert_equals(rect.x.baseVal.value, 0); 40 } 41 42 function sample2() { 43 assert_approx_equals(rect.x.animVal.value, 90, epsilon); 44 assert_equals(rect.x.baseVal.value, 0); 45 } 46 47 smil_async_test((t) => { 48 const expectedValues = [ 49 // [animationId, time, sampleCallback] 50 ["animation", 0.0, sample1], 51 ["animation", 3.0, sample2], 52 ]; 53 54 runAnimationTest(t, expectedValues); 55 }); 56 57 window.animationStartsImmediately = true; 58 59 </script>