1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/smil/test/test_smilSetCurrentTime.xhtml Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,75 @@ 1.4 +<html xmlns="http://www.w3.org/1999/xhtml"> 1.5 +<head> 1.6 + <title>Test for setCurrentTime Behavior </title> 1.7 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.8 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.9 +</head> 1.10 +<body> 1.11 +<p id="display"></p> 1.12 +<div id="content" style="display: none"> 1.13 +<svg id="svg" xmlns="http://www.w3.org/2000/svg" 1.14 + onload="this.pauseAnimations()" /> 1.15 +</div> 1.16 +<pre id="test"> 1.17 +<script class="testbody" type="text/javascript"> 1.18 +<![CDATA[ 1.19 +/** Test for basic setCurrentTime / getCurrentTime Behavior **/ 1.20 + 1.21 +/* Global Variables & Constants */ 1.22 +const PRECISION_LEVEL = 0.0000001; // Allow small level of floating-point error 1.23 +const gTimes = [0, 1.5, 0.2, 0.99, -400.5, 10000000, -1]; 1.24 +const gWaitTime = 20; 1.25 +var gSvg = document.getElementById("svg"); 1.26 + 1.27 +SimpleTest.waitForExplicitFinish(); 1.28 + 1.29 +function main() { 1.30 + ok(gSvg.animationsPaused(), "should be paused by <svg> load handler"); 1.31 + is(gSvg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler"); 1.32 + 1.33 + // Test that seeking takes effect immediately 1.34 + for (var i = 0; i < gTimes.length; i++) { 1.35 + gSvg.setCurrentTime(gTimes[i]); 1.36 + // We adopt the SVGT1.2 behavior of clamping negative times to 0 1.37 + assertFloatsEqual(gSvg.getCurrentTime(), Math.max(gTimes[i], 0.0)); 1.38 + } 1.39 + 1.40 + // Test that seeking isn't messed up by timeouts 1.41 + // (using tail recursion to set up the chain of timeout function calls) 1.42 + var func = function() { 1.43 + checkTimesAfterIndex(0); 1.44 + } 1.45 + setTimeout(func, gWaitTime); 1.46 +} 1.47 + 1.48 +/* This method seeks to the time at gTimes[index], 1.49 + * and then sets up a timeout to... 1.50 + * - verify that the seek worked 1.51 + * - make a recursive call for the next index. 1.52 + */ 1.53 +function checkTimesAfterIndex(index) { 1.54 + if (index == gTimes.length) { 1.55 + // base case -- we're done! 1.56 + SimpleTest.finish(); 1.57 + return; 1.58 + } 1.59 + 1.60 + gSvg.setCurrentTime(gTimes[index]); 1.61 + var func = function() { 1.62 + assertFloatsEqual(gSvg.getCurrentTime(), Math.max(gTimes[index], 0.0)); 1.63 + checkTimesAfterIndex(index + 1); 1.64 + } 1.65 + setTimeout(func, gWaitTime); 1.66 +} 1.67 + 1.68 +function assertFloatsEqual(aVal, aExpected) { 1.69 + ok(Math.abs(aVal - aExpected) <= PRECISION_LEVEL, 1.70 + "getCurrentTime returned " + aVal + " after seeking to " + aExpected) 1.71 +} 1.72 + 1.73 +window.addEventListener("load", main, false); 1.74 +]]> 1.75 +</script> 1.76 +</pre> 1.77 +</body> 1.78 +</html>