test_smilKeyTimesPacedMode.xhtml (3436B)
1 <html xmlns="http://www.w3.org/1999/xhtml"> 2 <head> 3 <title>Tests updated intervals</title> 4 <script src="/tests/SimpleTest/SimpleTest.js"></script> 5 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 6 </head> 7 <body> 8 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=555026">Mozilla Bug 555026</a> 9 <p id="display"></p> 10 <div id="content"> 11 <svg id="svg" xmlns="http://www.w3.org/2000/svg" width="120px" height="120px" 12 onload="this.pauseAnimations()"> 13 <circle r="10" id="circle"/> 14 </svg> 15 </div> 16 <pre id="test"> 17 <script class="testbody" type="text/javascript"> 18 <![CDATA[ 19 /** Test that we ignore keyTimes attr when calcMode="paced" */ 20 21 /* Global Variables */ 22 const SVGNS = "http://www.w3.org/2000/svg"; 23 const ANIM_DUR = "2s"; 24 const HALF_TIME = "1"; 25 const ATTR_NAME = "cx" 26 const KEYTIMES_TO_TEST = [ 27 // potentially-valid values (depending on number of values in animation) 28 "0; 0.2; 1", 29 "0; 0.5", 30 "0; 1", 31 // invalid values: 32 "", "abc", "-0.5", "0; 0.5; 1.01", "5" 33 ]; 34 const gSvg = document.getElementById("svg"); 35 const gCircle = document.getElementById("circle"); 36 37 SimpleTest.waitForExplicitFinish(); 38 39 40 // MAIN FUNCTIONS 41 function main() { 42 ok(gSvg.animationsPaused(), "should be paused by <svg> load handler"); 43 is(gSvg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler"); 44 45 testByAnimation(); 46 testToAnimation(); 47 testValuesAnimation(); 48 SimpleTest.finish(); 49 } 50 51 function testByAnimation() { 52 for (var i = 0; i < KEYTIMES_TO_TEST.length; i++) { 53 setupTest(); 54 var anim = createAnim(); 55 anim.setAttribute("by", "200"); 56 var curKeyTimes = KEYTIMES_TO_TEST[i]; 57 anim.setAttribute("keyTimes", curKeyTimes); 58 59 gSvg.setCurrentTime(HALF_TIME); 60 is(gCircle.cx.animVal.value, 100, 61 "Checking animVal with 'by' and keyTimes='" + curKeyTimes + "'"); 62 63 anim.remove(); // clean up 64 } 65 } 66 67 function testToAnimation() { 68 for (var i = 0; i < KEYTIMES_TO_TEST.length; i++) { 69 setupTest(); 70 var anim = createAnim(); 71 anim.setAttribute("to", "200"); 72 var curKeyTimes = KEYTIMES_TO_TEST[i]; 73 anim.setAttribute("keyTimes", curKeyTimes); 74 75 gSvg.setCurrentTime(HALF_TIME); 76 is(gCircle.cx.animVal.value, 100, 77 "Checking animVal with 'to' and keyTimes='" + curKeyTimes + "'"); 78 79 anim.remove(); // clean up 80 } 81 } 82 83 function testValuesAnimation() { 84 for (var i = 0; i < KEYTIMES_TO_TEST.length; i++) { 85 setupTest(); 86 var anim = createAnim(); 87 anim.setAttribute("values", "100; 110; 200"); 88 var curKeyTimes = KEYTIMES_TO_TEST[i]; 89 anim.setAttribute("keyTimes", curKeyTimes); 90 91 gSvg.setCurrentTime(HALF_TIME); 92 is(gCircle.cx.animVal.value, 150, 93 "Checking animVal with 'values' and keyTimes='" + curKeyTimes + "'"); 94 95 anim.remove(); // clean up 96 } 97 } 98 99 // HELPER FUNCTIONS 100 // Common setup code for each test function: seek to 0, and make sure 101 // the previous test cleaned up its animations. 102 function setupTest() { 103 gSvg.setCurrentTime(0); 104 if (gCircle.firstChild) { 105 ok(false, "Previous test didn't clean up after itself."); 106 } 107 } 108 109 function createAnim() { 110 var anim = document.createElementNS(SVGNS,"animate"); 111 anim.setAttribute("attributeName", ATTR_NAME); 112 anim.setAttribute("dur", ANIM_DUR); 113 anim.setAttribute("begin", "0s"); 114 anim.setAttribute("calcMode", "paced"); 115 return gCircle.appendChild(anim); 116 } 117 118 window.addEventListener("load", main); 119 ]]> 120 </script> 121 </pre> 122 </body> 123 </html>