1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/smil/test/test_smilGetStartTime.xhtml Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,103 @@ 1.4 +<html xmlns="http://www.w3.org/1999/xhtml"> 1.5 +<head> 1.6 + <title>Test for getStartTime 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" width="120px" height="120px" 1.14 + onload="this.pauseAnimations()"> 1.15 + <circle cx="20" cy="20" r="15" fill="blue"> 1.16 + <animate attributeName="cx" attributeType="XML" 1.17 + from="20" to="100" begin="indefinite" dur="1s" id="anim"/> 1.18 + </circle> 1.19 +</svg> 1.20 +</div> 1.21 +<pre id="test"> 1.22 +<script class="testbody" type="text/javascript"> 1.23 +<![CDATA[ 1.24 +/** Test for getStartTime Behavior **/ 1.25 + 1.26 +SimpleTest.waitForExplicitFinish(); 1.27 + 1.28 +function main() { 1.29 + var svg = document.getElementById("svg"); 1.30 + ok(svg.animationsPaused(), "should be paused by <svg> load handler"); 1.31 + is(svg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler"); 1.32 + 1.33 + var anim = document.getElementById("anim"); 1.34 + // indefinite 1.35 + var exceptionCaught = false; 1.36 + try { 1.37 + anim.getStartTime(); 1.38 + } catch(e) { 1.39 + exceptionCaught = true; 1.40 + is(e.name, "InvalidStateError", 1.41 + "Unexpected exception from getStartTime."); 1.42 + is(e.code, DOMException.INVALID_STATE_ERR, 1.43 + "Unexpected exception code from getStartTime."); 1.44 + } 1.45 + ok(exceptionCaught, "No exception thrown for indefinite start time."); 1.46 + 1.47 + // 1s 1.48 + anim.setAttribute("begin", "1s"); 1.49 + is(anim.getStartTime(), 1, "Unexpected start time with begin=1s"); 1.50 + 1.51 + // We have to be careful here when choosing a negative time that we choose 1.52 + // a time that will create an interval that reaches past t=0 as SMIL has 1.53 + // special rules for throwing away intervals that end before t=0 1.54 + anim.setAttribute("begin", "-0.5s"); 1.55 + is(anim.getStartTime(), -0.5, "Unexpected start time with begin=-0.5s"); 1.56 + 1.57 + // Once the animation has begun, the begin time is fixed so we need to end the 1.58 + // element (or advance the timeline) to override the previous start time 1.59 + anim.endElement(); 1.60 + 1.61 + // However, now we have an end instance, and the SMIL model dictates that if 1.62 + // we have end instances and no end event conditions and all end instances are 1.63 + // before our next begin, there's no valid interval. To overcome this we add 1.64 + // an indefinite end. 1.65 + anim.setAttribute("end", "indefinite"); 1.66 + 1.67 + // Now test over the lifetime of the animation when there are multiple 1.68 + // intervals 1.69 + anim.setAttribute("begin", "1s; 3s"); 1.70 + is(anim.getStartTime(), 1, "Unexpected start time before first interval"); 1.71 + 1.72 + svg.setCurrentTime(1); 1.73 + is(anim.getStartTime(), 1, 1.74 + "Unexpected start time at start of first interval"); 1.75 + 1.76 + svg.setCurrentTime(1.5); 1.77 + is(anim.getStartTime(), 1, "Unexpected start time during first interval"); 1.78 + 1.79 + svg.setCurrentTime(2); 1.80 + is(anim.getStartTime(), 3, "Unexpected start time after first interval"); 1.81 + 1.82 + svg.setCurrentTime(3); 1.83 + is(anim.getStartTime(), 3, "Unexpected start time during second interval"); 1.84 + 1.85 + svg.setCurrentTime(4); 1.86 + exceptionCaught = false; 1.87 + try { 1.88 + anim.getStartTime(); 1.89 + } catch(e) { 1.90 + exceptionCaught = true; 1.91 + is(e.name, "InvalidStateError", 1.92 + "Unexpected exception from getStartTime."); 1.93 + is(e.code, DOMException.INVALID_STATE_ERR, 1.94 + "Unexpected exception code from getStartTime."); 1.95 + } 1.96 + ok(exceptionCaught, "No exception thrown for in postactive state."); 1.97 + 1.98 + SimpleTest.finish(); 1.99 +} 1.100 + 1.101 +window.addEventListener("load", main, false); 1.102 +]]> 1.103 +</script> 1.104 +</pre> 1.105 +</body> 1.106 +</html>