additive-from-to-width-animation.html (2152B)
1 <!doctype html> 2 <html> 3 <meta charset="utf-8"> 4 <title>This tests multiple additive='sum' animations running at the same time</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 xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> 10 11 <!-- an1: Change width from 10 to 50 in 4s --> 12 <!-- an2: Change width from 10 to 25 + additive=sum. This results in a change from 20 to 75 --> 13 <!-- an3: Change width from 0 to 25 + additve=sum. This results in a final change from 20 to 100 --> 14 <rect width="10" height="100" fill="green"> 15 <animate id="an1" attributeType="XML" attributeName="width" fill="freeze" from="10" to="50" begin="0s" dur="4s"/> 16 <animate id="an2" attributeType="XML" attributeName="width" additive="sum" fill="freeze" from="10" to="25" begin="0s" dur="4s"/> 17 <animate id="an3" attributeType="XML" attributeName="width" additive="sum" fill="freeze" from="0" to="25" begin="0s" dur="4s"/> 18 </rect> 19 20 </svg> 21 22 <script> 23 var rootSVGElement = document.querySelector("svg"); 24 var epsilon = 1.0; 25 26 // Setup animation test 27 function sample1() { 28 assert_approx_equals(rect.width.animVal.value, 20, epsilon); 29 assert_equals(rect.width.baseVal.value, 10); 30 } 31 32 function sample2() { 33 assert_approx_equals(rect.width.animVal.value, 60, epsilon); 34 assert_equals(rect.width.baseVal.value, 10); 35 } 36 37 function sample3() { 38 assert_approx_equals(rect.width.animVal.value, 100, epsilon); 39 assert_equals(rect.width.baseVal.value, 10); 40 } 41 42 smil_async_test((t) => { 43 rect = rootSVGElement.ownerDocument.getElementsByTagName("rect")[0]; 44 45 // All animations in the test file use the same duration, so it's not needed to list all sample points individually for an5/an6/an7/an8. 46 const expectedValues = [ 47 // [animationId, time, sampleCallback] 48 ["an1", 0.0, sample1], 49 ["an1", 2.0, sample2], 50 ["an1", 4.0, sample3], 51 ["an1", 60.0, sample3] 52 ]; 53 54 runAnimationTest(t, expectedValues); 55 }); 56 57 window.animationStartsImmediately = true; 58 59 </script>