svglengthlist-animation-3.html (2558B)
1 <!doctype html> 2 <html> 3 <meta charset="utf-8"> 4 <meta name="timeout" content="long"> 5 <title>Test 'to' animation of SVGLengthList with different count of items.</title> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script src="/resources/SVGAnimationTestCase-testharness.js"></script> 9 10 <svg> 11 </svg> 12 13 <script> 14 var rootSVGElement = document.querySelector("svg"); 15 var epsilon = 1.0; 16 17 // Setup test document 18 var text = createSVGElement("text"); 19 text.setAttribute("id", "text"); 20 text.textContent = "ABCD"; 21 text.setAttribute("x", "50"); 22 text.setAttribute("y", "50"); 23 text.setAttribute("onclick", "executeTest()"); 24 rootSVGElement.appendChild(text); 25 26 var animate = createSVGElement("animate"); 27 animate.setAttribute("id", "animation"); 28 animate.setAttribute("attributeName", "x"); 29 animate.setAttribute("begin", "0s"); 30 animate.setAttribute("dur", "4s"); 31 animate.setAttribute("from", "50"); 32 animate.setAttribute("to", "70 80 90 110"); 33 text.appendChild(animate); 34 35 // Setup animation test 36 function sample1() { 37 assert_equals(text.x.animVal.numberOfItems, 1); 38 assert_approx_equals(text.x.animVal.getItem(0).value, 50, epsilon); 39 40 assert_equals(text.x.baseVal.numberOfItems, 1); 41 assert_equals(text.x.baseVal.getItem(0).value, 50); 42 } 43 44 function sample2() { 45 assert_equals(text.x.animVal.numberOfItems, 4); 46 assert_approx_equals(text.x.animVal.getItem(0).value, 70, epsilon); 47 assert_approx_equals(text.x.animVal.getItem(1).value, 80, epsilon); 48 assert_approx_equals(text.x.animVal.getItem(2).value, 90, epsilon); 49 assert_approx_equals(text.x.animVal.getItem(3).value, 110, epsilon); 50 51 assert_equals(text.x.baseVal.numberOfItems, 1); 52 assert_equals(text.x.baseVal.getItem(0).value, 50); 53 } 54 55 function sample3() { 56 assert_equals(text.x.animVal.numberOfItems, 4); 57 assert_approx_equals(text.x.animVal.getItem(0).value, 70, epsilon); 58 assert_approx_equals(text.x.animVal.getItem(1).value, 80, epsilon); 59 assert_approx_equals(text.x.animVal.getItem(2).value, 90, epsilon); 60 assert_approx_equals(text.x.animVal.getItem(3).value, 110, epsilon); 61 62 assert_equals(text.x.baseVal.numberOfItems, 1); 63 assert_equals(text.x.baseVal.getItem(0).value, 50); 64 } 65 66 smil_async_test((t) => { 67 const expectedValues = [ 68 // [animationId, time, sampleCallback] 69 ["animation", 0.0, sample1], 70 ["animation", 2.0, sample2], 71 ["animation", 3.999, sample3], 72 ["animation", 4.001, sample1] 73 ]; 74 75 runAnimationTest(t, expectedValues); 76 }); 77 78 </script>