svgnumber-animation-4.html (2283B)
1 <!doctype html> 2 <html> 3 <meta charset="utf-8"> 4 <title>Test for SVGNumber animation on SVG DOM properties.</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 gradient = createSVGElement("linearGradient"); 18 gradient.setAttribute("id", "gradient"); 19 20 var stop1 = createSVGElement("stop"); 21 stop1.setAttribute("offset", "0"); 22 stop1.setAttribute("stop-color", "green"); 23 gradient.appendChild(stop1); 24 25 var stop2 = createSVGElement("stop"); 26 stop2.setAttribute("offset", "1"); 27 stop2.setAttribute("stop-color", "red"); 28 gradient.appendChild(stop2); 29 30 var defsElement = createSVGElement("defs"); 31 defsElement.appendChild(gradient); 32 rootSVGElement.appendChild(defsElement); 33 34 var rect = createSVGElement("rect"); 35 rect.setAttribute("id", "rect"); 36 rect.setAttribute("x", "0"); 37 rect.setAttribute("width", "100"); 38 rect.setAttribute("height", "100"); 39 rect.setAttribute("fill", "url(#gradient)"); 40 rect.setAttribute("onclick", "executeTest()"); 41 42 var animate = createSVGElement("animate"); 43 animate.setAttribute("id", "animation"); 44 animate.setAttribute("attributeType", "XML"); 45 animate.setAttribute("attributeName", "offset"); 46 animate.setAttribute("begin", "0s"); 47 animate.setAttribute("dur", "4s"); 48 animate.setAttribute("from", "0"); 49 animate.setAttribute("to", "1"); 50 animate.setAttribute("fill", "freeze"); 51 stop1.appendChild(animate); 52 53 rootSVGElement.appendChild(rect); 54 55 // Setup animation test 56 function sample1() { 57 assert_approx_equals(stop1.offset.animVal, 0, epsilon); 58 assert_equals(stop1.offset.baseVal, 0); 59 } 60 61 function sample2() { 62 assert_approx_equals(stop1.offset.animVal, 0.5, epsilon); 63 assert_equals(stop1.offset.baseVal, 0); 64 } 65 66 function sample3() { 67 assert_approx_equals(stop1.offset.animVal, 1, epsilon); 68 assert_equals(stop1.offset.baseVal, 0); 69 } 70 71 smil_async_test((t) => { 72 const expectedValues = [ 73 // [animationId, time, sampleCallback] 74 ["animation", 0.0, sample1], 75 ["animation", 2.0, sample2], 76 ["animation", 4.0, sample3] 77 ]; 78 79 runAnimationTest(t, expectedValues); 80 }); 81 82 </script>