test_smilSetCurrentTime.xhtml (2322B)
1 <html xmlns="http://www.w3.org/1999/xhtml"> 2 <head> 3 <title>Test for setCurrentTime Behavior </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 <p id="display"></p> 9 <div id="content" style="display: none"> 10 <svg id="svg" xmlns="http://www.w3.org/2000/svg" 11 onload="this.pauseAnimations()" /> 12 </div> 13 <pre id="test"> 14 <script class="testbody" type="text/javascript"> 15 <![CDATA[ 16 /** Test for basic setCurrentTime / getCurrentTime Behavior */ 17 18 /* Global Variables & Constants */ 19 const PRECISION_LEVEL = 0.0000001; // Allow small level of floating-point error 20 const gTimes = [0, 1.5, 0.2, 0.99, -400.5, 10000000, -1]; 21 const gWaitTime = 20; 22 var gSvg = document.getElementById("svg"); 23 24 SimpleTest.waitForExplicitFinish(); 25 SimpleTest.requestFlakyTimeout("untriaged"); 26 27 function main() { 28 ok(gSvg.animationsPaused(), "should be paused by <svg> load handler"); 29 is(gSvg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler"); 30 31 // Test that seeking takes effect immediately 32 for (var i = 0; i < gTimes.length; i++) { 33 gSvg.setCurrentTime(gTimes[i]); 34 // We adopt the SVGT1.2 behavior of clamping negative times to 0 35 assertFloatsEqual(gSvg.getCurrentTime(), Math.max(gTimes[i], 0.0)); 36 } 37 38 // Test that seeking isn't messed up by timeouts 39 // (using tail recursion to set up the chain of timeout function calls) 40 var func = function() { 41 checkTimesAfterIndex(0); 42 } 43 setTimeout(func, gWaitTime); 44 } 45 46 /* This method seeks to the time at gTimes[index], 47 * and then sets up a timeout to... 48 * - verify that the seek worked 49 * - make a recursive call for the next index. 50 */ 51 function checkTimesAfterIndex(index) { 52 if (index == gTimes.length) { 53 // base case -- we're done! 54 SimpleTest.finish(); 55 return; 56 } 57 58 gSvg.setCurrentTime(gTimes[index]); 59 var func = function() { 60 assertFloatsEqual(gSvg.getCurrentTime(), Math.max(gTimes[index], 0.0)); 61 checkTimesAfterIndex(index + 1); 62 } 63 setTimeout(func, gWaitTime); 64 } 65 66 function assertFloatsEqual(aVal, aExpected) { 67 ok(Math.abs(aVal - aExpected) <= PRECISION_LEVEL, 68 "getCurrentTime returned " + aVal + " after seeking to " + aExpected) 69 } 70 71 window.addEventListener("load", main); 72 ]]> 73 </script> 74 </pre> 75 </body> 76 </html>