svgenum-animation-1.html (2464B)
1 <!doctype html> 2 <html> 3 <meta charset="utf-8"> 4 <title>Test SVGUnitTypes 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 defs = createSVGElement("defs"); 18 rootSVGElement.appendChild(defs); 19 20 var pattern = createSVGElement("pattern"); 21 pattern.setAttribute("id", "pattern"); 22 pattern.setAttribute("patternUnits", "userSpaceOnUse"); 23 pattern.setAttribute("patternContentUnits", "userSpaceOnUse"); 24 pattern.setAttribute("width", "50"); 25 pattern.setAttribute("height", "50"); 26 defs.appendChild(pattern); 27 28 var patternChild = createSVGElement("rect"); 29 patternChild.setAttribute("width", "1"); 30 patternChild.setAttribute("height", "1"); 31 patternChild.setAttribute("fill", "green"); 32 pattern.appendChild(patternChild); 33 34 var rect = createSVGElement("rect"); 35 rect.setAttribute("id", "rect"); 36 rect.setAttribute("width", "100"); 37 rect.setAttribute("height", "100"); 38 rect.setAttribute("fill", "url(#pattern)"); 39 rect.setAttribute("onclick", "executeTest()"); 40 rootSVGElement.appendChild(rect); 41 42 var animate = createSVGElement("animate"); 43 animate.setAttribute("id", "animation"); 44 animate.setAttribute("attributeName", "patternContentUnits"); 45 animate.setAttribute("begin", "0s"); 46 animate.setAttribute("dur", "4s"); 47 animate.setAttribute("from", "userSpaceOnUse"); 48 animate.setAttribute("to", "objectBoundingBox"); 49 animate.setAttribute("fill", "freeze"); 50 pattern.appendChild(animate); 51 52 // Setup animation test 53 function sample1() { 54 assert_equals(pattern.patternContentUnits.animVal, SVGUnitTypes.SVG_UNIT_TYPE_USERSPACEONUSE); 55 assert_equals(pattern.patternContentUnits.baseVal, SVGUnitTypes.SVG_UNIT_TYPE_USERSPACEONUSE); 56 } 57 58 function sample2() { 59 assert_equals(pattern.patternContentUnits.animVal, SVGUnitTypes.SVG_UNIT_TYPE_OBJECTBOUNDINGBOX); 60 assert_equals(pattern.patternContentUnits.baseVal, SVGUnitTypes.SVG_UNIT_TYPE_USERSPACEONUSE); 61 } 62 63 smil_async_test((t) => { 64 const expectedValues = [ 65 // [animationId, time, sampleCallback] 66 ["animation", 0.0, sample1], 67 ["animation", 1.999, sample1], 68 ["animation", 2.001, sample2], 69 ["animation", 3.999, sample2], 70 ["animation", 4.001, sample2] 71 ]; 72 73 runAnimationTest(t, expectedValues); 74 }); 75 76 </script>