svgenum-animation-10.html (2696B)
1 <!doctype html> 2 <html> 3 <meta charset="utf-8"> 4 <title>Test SVGMarkerUnitsType enumeration animations</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 marker = createSVGElement("marker"); 18 marker.setAttribute("id", "marker"); 19 marker.setAttribute("viewBox", "0 0 10 10"); 20 marker.setAttribute("markerWidth", "2"); 21 marker.setAttribute("markerHeight", "2"); 22 marker.setAttribute("refX", "5"); 23 marker.setAttribute("refY", "5"); 24 marker.setAttribute("markerUnits", "userSpaceOnUse"); 25 26 var markerPath = createSVGElement("path"); 27 markerPath.setAttribute("fill", "blue"); 28 markerPath.setAttribute("d", "M 5 0 L 10 10 L 0 10 Z"); 29 marker.appendChild(markerPath); 30 31 var defsElement = createSVGElement("defs"); 32 defsElement.appendChild(marker); 33 rootSVGElement.appendChild(defsElement); 34 35 var path = createSVGElement("path"); 36 path.setAttribute("id", "path"); 37 path.setAttribute("onclick", "executeTest()"); 38 path.setAttribute("fill", "none"); 39 path.setAttribute("stroke", "green"); 40 path.setAttribute("stroke-width", "10"); 41 path.setAttribute("marker-start", "url(#marker)"); 42 path.setAttribute("marker-end", "url(#marker)"); 43 path.setAttribute("d", "M 130 135 L 180 135 L 180 185"); 44 path.setAttribute("transform", "translate(-130, -120)"); 45 rootSVGElement.appendChild(path); 46 47 var animate1 = createSVGElement("animate"); 48 animate1.setAttribute("id", "animation"); 49 animate1.setAttribute("attributeName", "markerUnits"); 50 animate1.setAttribute("begin", "0s"); 51 animate1.setAttribute("dur", "4s"); 52 animate1.setAttribute("from", "userSpaceOnUse"); 53 animate1.setAttribute("to", "strokeWidth"); 54 animate1.setAttribute("fill", "freeze"); 55 marker.appendChild(animate1); 56 57 // Setup animation test 58 function sample1() { 59 assert_equals(marker.markerUnits.animVal, SVGMarkerElement.SVG_MARKERUNITS_USERSPACEONUSE); 60 assert_equals(marker.markerUnits.baseVal, SVGMarkerElement.SVG_MARKERUNITS_USERSPACEONUSE); 61 } 62 63 function sample2() { 64 assert_equals(marker.markerUnits.animVal, SVGMarkerElement.SVG_MARKERUNITS_STROKEWIDTH); 65 assert_equals(marker.markerUnits.baseVal, SVGMarkerElement.SVG_MARKERUNITS_USERSPACEONUSE); 66 } 67 68 smil_async_test((t) => { 69 const expectedValues = [ 70 // [animationId, time, sampleCallback] 71 ["animation", 0.0, sample1], 72 ["animation", 1.999, sample1], 73 ["animation", 2.001, sample2], 74 ["animation", 3.999, sample2], 75 ["animation", 4.001, sample2] 76 ]; 77 78 runAnimationTest(t, expectedValues); 79 }); 80 81 </script>