svgangle-animation-deg-to-grad.html (3075B)
1 <!doctype html> 2 <html> 3 <meta charset="utf-8"> 4 <title>Tests SVGAngle animation from deg to grad.</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 defs = createSVGElement("defs"); 18 19 var marker = createSVGElement("marker"); 20 marker.setAttribute("id", "marker"); 21 marker.setAttribute("viewBox", "0 0 10 10"); 22 marker.setAttribute("markerWidth", "4"); 23 marker.setAttribute("markerHeight", "3"); 24 marker.setAttribute("markerUnits", "strokeWidth"); 25 marker.setAttribute("refX", "1"); 26 marker.setAttribute("refY", "5"); 27 marker.setAttribute("orient", "0deg"); 28 defs.appendChild(marker); 29 30 var polyline = createSVGElement("polyline"); 31 polyline.setAttribute("id", "polyline"); 32 polyline.setAttribute("points", "0,0 10,5 0,10 1,5"); 33 polyline.setAttribute("fill", "green"); 34 marker.appendChild(polyline); 35 36 var path = createSVGElement("path"); 37 path.setAttribute("id", "path"); 38 path.setAttribute("d", "M45,50 L55,50"); 39 path.setAttribute("stroke-width","10"); 40 path.setAttribute("stroke", "green"); 41 path.setAttribute("marker-end", "url(#marker)"); 42 path.setAttribute("onclick", "executeTest()"); 43 44 var animate = createSVGElement("animate"); 45 animate.setAttribute("id", "animation"); 46 animate.setAttribute("attributeName", "orient"); 47 animate.setAttribute("begin", "0s"); 48 animate.setAttribute("dur", "4s"); 49 animate.setAttribute("from", "0deg"); 50 animate.setAttribute("to", "200grad"); 51 marker.appendChild(animate); 52 rootSVGElement.appendChild(defs); 53 rootSVGElement.appendChild(path); 54 55 // Setup animation test 56 function sample1() { 57 // Check initial/end conditions 58 assert_approx_equals(marker.orientAngle.animVal.value, 0, epsilon); 59 assert_equals(marker.orientAngle.baseVal.value, 0); 60 61 assert_equals(marker.orientType.animVal, SVGMarkerElement.SVG_MARKER_ORIENT_ANGLE); 62 assert_equals(marker.orientType.baseVal, SVGMarkerElement.SVG_MARKER_ORIENT_ANGLE); 63 } 64 65 function sample2() { 66 assert_approx_equals(marker.orientAngle.animVal.value, 90, epsilon); 67 assert_equals(marker.orientAngle.baseVal.value, 0); 68 69 assert_equals(marker.orientType.animVal, SVGMarkerElement.SVG_MARKER_ORIENT_ANGLE); 70 assert_equals(marker.orientType.baseVal, SVGMarkerElement.SVG_MARKER_ORIENT_ANGLE); 71 } 72 73 function sample3() { 74 assert_approx_equals(marker.orientAngle.animVal.value, 180, epsilon); 75 assert_equals(marker.orientAngle.baseVal.value, 0); 76 77 assert_equals(marker.orientType.animVal, SVGMarkerElement.SVG_MARKER_ORIENT_ANGLE); 78 assert_equals(marker.orientType.baseVal, SVGMarkerElement.SVG_MARKER_ORIENT_ANGLE); 79 } 80 81 smil_async_test((t) => { 82 const expectedValues = [ 83 // [animationId, time, sampleCallback] 84 ["animation", 0.0, sample1], 85 ["animation", 2.0, sample2], 86 ["animation", 3.999, sample3], 87 ["animation", 4.001, sample1] 88 ]; 89 90 runAnimationTest(t, expectedValues); 91 }); 92 93 </script>