1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/smil/test/test_smilTimingZeroIntervals.xhtml Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,285 @@ 1.4 +<html xmlns="http://www.w3.org/1999/xhtml"> 1.5 +<head> 1.6 + <title>Test for SMIL timing with zero-duration intervals</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="-100" cy="20" r="15" fill="blue" id="circle"/> 1.16 +</svg> 1.17 +</div> 1.18 +<pre id="test"> 1.19 +<script class="testbody" type="text/javascript"> 1.20 +<![CDATA[ 1.21 +/** Test for SMIL timing with zero-duration intervals **/ 1.22 + 1.23 +/* Global Variables */ 1.24 +const svgns="http://www.w3.org/2000/svg"; 1.25 +var svg = document.getElementById("svg"); 1.26 +var circle = document.getElementById('circle'); 1.27 + 1.28 +SimpleTest.waitForExplicitFinish(); 1.29 + 1.30 +function createAnim() { 1.31 + var anim = document.createElementNS(svgns,'animate'); 1.32 + anim.setAttribute('attributeName','cx'); 1.33 + anim.setAttribute('from','0'); 1.34 + anim.setAttribute('to','100'); 1.35 + anim.setAttribute('dur','10s'); 1.36 + anim.setAttribute('begin','indefinite'); 1.37 + return circle.appendChild(anim); 1.38 +} 1.39 + 1.40 +function removeAnim(anim) { 1.41 + anim.parentNode.removeChild(anim); 1.42 +} 1.43 + 1.44 +function main() { 1.45 + ok(svg.animationsPaused(), "should be paused by <svg> load handler"); 1.46 + is(svg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler"); 1.47 + 1.48 + var tests = 1.49 + [ testZeroDurationIntervalsA, 1.50 + testZeroDurationIntervalsB, 1.51 + testZeroDurationIntervalsC, 1.52 + testZeroDurationIntervalsD, 1.53 + testZeroDurationIntervalsE, 1.54 + testZeroDurationIntervalsF, 1.55 + testZeroDurationIntervalsG, 1.56 + testZeroDurationIntervalsH, 1.57 + testZeroDurationIntervalsI, 1.58 + testZeroDurationIntervalsJ, 1.59 + testZeroDurationIntervalsK, 1.60 + testZeroDurationIntervalsL, 1.61 + testZeroDurationIntervalsM, 1.62 + testZeroDurationIntervalsN, 1.63 + testZeroDurationIntervalsO 1.64 + ]; 1.65 + for (var i = 0; i < tests.length; i++) { 1.66 + var anim = createAnim(); 1.67 + svg.setCurrentTime(0); 1.68 + tests[i](anim); 1.69 + removeAnim(anim); 1.70 + } 1.71 + SimpleTest.finish(); 1.72 +} 1.73 + 1.74 +function checkSample(time, expectedValue) { 1.75 + svg.setCurrentTime(time); 1.76 + is(circle.cx.animVal.value, expectedValue); 1.77 +} 1.78 + 1.79 +function testZeroDurationIntervalsA(anim) { 1.80 + // The zero-duration interval should play, followed by a second interval 1.81 + // starting at the same point. There is no end for the interval 1.82 + // at 4s so it should not play. 1.83 + anim.setAttribute('begin', '1s ;4s'); 1.84 + anim.setAttribute('end', '1s; 2s'); 1.85 + anim.setAttribute('dur', '2s '); 1.86 + anim.setAttribute('fill', 'freeze'); 1.87 + checkSample(0,-100); 1.88 + checkSample(1,0); 1.89 + checkSample(1.1,5); 1.90 + checkSample(2,50); 1.91 + checkSample(3,50); 1.92 + checkSample(4,50); 1.93 + checkSample(5,50); 1.94 + checkSample(6,50); 1.95 +} 1.96 + 1.97 +function testZeroDurationIntervalsB(anim) { 1.98 + // This interval should however actually restart as there is a valid end-point 1.99 + anim.setAttribute('begin', '1s ;4s'); 1.100 + anim.setAttribute('end', '1.1s; indefinite'); 1.101 + anim.setAttribute('dur', '2s '); 1.102 + anim.setAttribute('fill', 'freeze'); 1.103 + checkSample(0,-100); 1.104 + checkSample(1,0); 1.105 + checkSample(1.1,5); 1.106 + checkSample(2,5); 1.107 + checkSample(4,0); 1.108 + checkSample(5,50); 1.109 +} 1.110 + 1.111 +function testZeroDurationIntervalsC(anim) { 1.112 + // -0.5s has already been used as the endpoint of one interval so don't use it 1.113 + // a second time 1.114 + anim.setAttribute('begin', '-2s; -0.5s'); 1.115 + anim.setAttribute('end', '-0.5s; 1s'); 1.116 + anim.setAttribute('dur', '2s'); 1.117 + anim.setAttribute('fill', 'freeze'); 1.118 + checkSample(0,25); 1.119 + checkSample(1.5,75); 1.120 +} 1.121 + 1.122 +function testZeroDurationIntervalsD(anim) { 1.123 + // Two end points that could make a zero-length interval 1.124 + anim.setAttribute('begin', '-2s; -0.5s'); 1.125 + anim.setAttribute('end', '-0.5s; -0.5s; 1s'); 1.126 + anim.setAttribute('dur', '2s'); 1.127 + anim.setAttribute('fill', 'freeze'); 1.128 + checkSample(0,25); 1.129 + checkSample(1.5,75); 1.130 +} 1.131 + 1.132 +function testZeroDurationIntervalsE(anim) { 1.133 + // Should give us 1s-1s, 1s-5s 1.134 + anim.setAttribute('begin', '1s'); 1.135 + anim.setAttribute('end', '1s; 5s'); 1.136 + anim.setAttribute('fill', 'freeze'); 1.137 + is(anim.getStartTime(),1); 1.138 + checkSample(0,-100); 1.139 + checkSample(1,0); 1.140 + checkSample(6,40); 1.141 +} 1.142 + 1.143 +function testZeroDurationIntervalsF(anim) { 1.144 + // Should give us 1s-1s 1.145 + anim.setAttribute('begin', '1s'); 1.146 + anim.setAttribute('end', '1s'); 1.147 + anim.setAttribute('fill', 'freeze'); 1.148 + is(anim.getStartTime(),1); 1.149 + checkSample(0,-100); 1.150 + checkSample(1,0); 1.151 + checkSample(2,0); 1.152 + try { 1.153 + anim.getStartTime(); 1.154 + ok(false, "Failed to throw exception when there's no current interval."); 1.155 + } catch (e) { } 1.156 +} 1.157 + 1.158 +function testZeroDurationIntervalsG(anim) { 1.159 + // Test a non-zero interval after a zero interval 1.160 + // Should give us 1-2s, 3-3s, 3-4s 1.161 + anim.setAttribute('begin', '1s; 3s'); 1.162 + anim.setAttribute('end', '3s; 5s'); 1.163 + anim.setAttribute('dur', '1s'); 1.164 + anim.setAttribute('fill', 'freeze'); 1.165 + checkSample(0,-100); 1.166 + checkSample(1,0); 1.167 + checkSample(2,100); 1.168 + checkSample(3,0); 1.169 + checkSample(5,100); 1.170 +} 1.171 + 1.172 +function testZeroDurationIntervalsH(anim) { 1.173 + // Test multiple non-adjacent zero-intervals 1.174 + // Should give us 1-1s, 1-2s, 3-3s, 3-4s 1.175 + anim.setAttribute('begin', '1s; 3s'); 1.176 + anim.setAttribute('end', '1s; 3s; 5s'); 1.177 + anim.setAttribute('dur', '1s'); 1.178 + anim.setAttribute('fill', 'freeze'); 1.179 + checkSample(0,-100); 1.180 + checkSample(1,0); 1.181 + checkSample(2,100); 1.182 + checkSample(3,0); 1.183 + checkSample(5,100); 1.184 +} 1.185 + 1.186 +function testZeroDurationIntervalsI(anim) { 1.187 + // Test skipping values that are the same 1.188 + // Should give us 1-1s, 1-2s 1.189 + anim.setAttribute('begin', '1s; 1s'); 1.190 + anim.setAttribute('end', '1s; 1s; 2s'); 1.191 + anim.setAttribute('fill', 'freeze'); 1.192 + is(anim.getStartTime(),1); 1.193 + checkSample(0,-100); 1.194 + checkSample(1,0); 1.195 + checkSample(2,10); 1.196 + checkSample(3,10); 1.197 +} 1.198 + 1.199 +function testZeroDurationIntervalsJ(anim) { 1.200 + // Should give us 0-0.5s, 1-1s, 1-3s 1.201 + anim.setAttribute('begin', '0s; 1s; 1s'); 1.202 + anim.setAttribute('end', '1s; 3s'); 1.203 + anim.setAttribute('dur', '0.5s'); 1.204 + anim.setAttribute('fill', 'freeze'); 1.205 + is(anim.getStartTime(),0); 1.206 + checkSample(0,0); 1.207 + checkSample(0.6,100); 1.208 + checkSample(1,0); 1.209 + checkSample(2,100); 1.210 +} 1.211 + 1.212 +function testZeroDurationIntervalsK(anim) { 1.213 + // Should give us -0.5-1s 1.214 + anim.setAttribute('begin', '-0.5s'); 1.215 + anim.setAttribute('end', '-0.5s; 1s'); 1.216 + anim.setAttribute('fill', 'freeze'); 1.217 + is(anim.getStartTime(),-0.5); 1.218 + checkSample(0,5); 1.219 + checkSample(1,15); 1.220 + checkSample(2,15); 1.221 +} 1.222 + 1.223 +function testZeroDurationIntervalsL(anim) { 1.224 + // Test that multiple end values are ignored 1.225 + // Should give us 1-1s, 1-3s 1.226 + anim.setAttribute('begin', '1s'); 1.227 + anim.setAttribute('end', '1s; 1s; 1s; 3s'); 1.228 + anim.setAttribute('fill', 'freeze'); 1.229 + is(anim.getStartTime(),1); 1.230 + checkSample(0,-100); 1.231 + checkSample(1,0); 1.232 + checkSample(2,10); 1.233 + checkSample(4,20); 1.234 +} 1.235 + 1.236 +function testZeroDurationIntervalsM(anim) { 1.237 + // Test 0-duration interval at start 1.238 + anim.setAttribute('begin', '0s'); 1.239 + anim.setAttribute('end', '0s'); 1.240 + anim.setAttribute('fill', 'freeze'); 1.241 + try { 1.242 + anim.getStartTime(); 1.243 + ok(false, "Failed to throw exception when there's no current interval."); 1.244 + } catch (e) { } 1.245 + checkSample(0,0); 1.246 + checkSample(1,0); 1.247 +} 1.248 + 1.249 +function testZeroDurationIntervalsN(anim) { 1.250 + // Test 0-active-duration interval at start (different code path to above) 1.251 + anim.setAttribute('begin', '0s'); 1.252 + anim.setAttribute('repeatDur', '0s'); 1.253 + anim.setAttribute('fill', 'freeze'); 1.254 + try { 1.255 + anim.getStartTime(); 1.256 + ok(false, "Failed to throw exception when there's no current interval."); 1.257 + } catch (e) { } 1.258 + checkSample(0,0); 1.259 + checkSample(1,0); 1.260 +} 1.261 + 1.262 +function testZeroDurationIntervalsO(anim) { 1.263 + // Make a zero-duration interval by constraining the active duration 1.264 + // We should not loop infinitely but should look for the next begin time after 1.265 + // that (in this case that is 2s, which would otherwise have been skipped 1.266 + // because restart=whenNotActive) 1.267 + // Should give us 1-1s, 2-2s 1.268 + anim.setAttribute('begin', '1s; 2s'); 1.269 + anim.setAttribute('repeatDur', '0s'); 1.270 + anim.setAttribute('restart', 'whenNotActive'); 1.271 + anim.setAttribute('fill', 'freeze'); 1.272 + is(anim.getStartTime(),1); 1.273 + checkSample(0,-100); 1.274 + checkSample(1,0); 1.275 + checkSample(1.5,0); 1.276 + checkSample(3,0); 1.277 + try { 1.278 + anim.getStartTime(); 1.279 + ok(false, "Failed to throw exception when there's no current interval."); 1.280 + } catch (e) { } 1.281 +} 1.282 + 1.283 +window.addEventListener("load", main, false); 1.284 +]]> 1.285 +</script> 1.286 +</pre> 1.287 +</body> 1.288 +</html>