dom/smil/test/test_smilTimingZeroIntervals.xhtml

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 <html xmlns="http://www.w3.org/1999/xhtml">
michael@0 2 <head>
michael@0 3 <title>Test for SMIL timing with zero-duration intervals</title>
michael@0 4 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 5 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 6 </head>
michael@0 7 <body>
michael@0 8 <p id="display"></p>
michael@0 9 <div id="content" style="display: none">
michael@0 10 <svg id="svg" xmlns="http://www.w3.org/2000/svg" width="120px" height="120px"
michael@0 11 onload="this.pauseAnimations()">
michael@0 12 <circle cx="-100" cy="20" r="15" fill="blue" id="circle"/>
michael@0 13 </svg>
michael@0 14 </div>
michael@0 15 <pre id="test">
michael@0 16 <script class="testbody" type="text/javascript">
michael@0 17 <![CDATA[
michael@0 18 /** Test for SMIL timing with zero-duration intervals **/
michael@0 19
michael@0 20 /* Global Variables */
michael@0 21 const svgns="http://www.w3.org/2000/svg";
michael@0 22 var svg = document.getElementById("svg");
michael@0 23 var circle = document.getElementById('circle');
michael@0 24
michael@0 25 SimpleTest.waitForExplicitFinish();
michael@0 26
michael@0 27 function createAnim() {
michael@0 28 var anim = document.createElementNS(svgns,'animate');
michael@0 29 anim.setAttribute('attributeName','cx');
michael@0 30 anim.setAttribute('from','0');
michael@0 31 anim.setAttribute('to','100');
michael@0 32 anim.setAttribute('dur','10s');
michael@0 33 anim.setAttribute('begin','indefinite');
michael@0 34 return circle.appendChild(anim);
michael@0 35 }
michael@0 36
michael@0 37 function removeAnim(anim) {
michael@0 38 anim.parentNode.removeChild(anim);
michael@0 39 }
michael@0 40
michael@0 41 function main() {
michael@0 42 ok(svg.animationsPaused(), "should be paused by <svg> load handler");
michael@0 43 is(svg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler");
michael@0 44
michael@0 45 var tests =
michael@0 46 [ testZeroDurationIntervalsA,
michael@0 47 testZeroDurationIntervalsB,
michael@0 48 testZeroDurationIntervalsC,
michael@0 49 testZeroDurationIntervalsD,
michael@0 50 testZeroDurationIntervalsE,
michael@0 51 testZeroDurationIntervalsF,
michael@0 52 testZeroDurationIntervalsG,
michael@0 53 testZeroDurationIntervalsH,
michael@0 54 testZeroDurationIntervalsI,
michael@0 55 testZeroDurationIntervalsJ,
michael@0 56 testZeroDurationIntervalsK,
michael@0 57 testZeroDurationIntervalsL,
michael@0 58 testZeroDurationIntervalsM,
michael@0 59 testZeroDurationIntervalsN,
michael@0 60 testZeroDurationIntervalsO
michael@0 61 ];
michael@0 62 for (var i = 0; i < tests.length; i++) {
michael@0 63 var anim = createAnim();
michael@0 64 svg.setCurrentTime(0);
michael@0 65 tests[i](anim);
michael@0 66 removeAnim(anim);
michael@0 67 }
michael@0 68 SimpleTest.finish();
michael@0 69 }
michael@0 70
michael@0 71 function checkSample(time, expectedValue) {
michael@0 72 svg.setCurrentTime(time);
michael@0 73 is(circle.cx.animVal.value, expectedValue);
michael@0 74 }
michael@0 75
michael@0 76 function testZeroDurationIntervalsA(anim) {
michael@0 77 // The zero-duration interval should play, followed by a second interval
michael@0 78 // starting at the same point. There is no end for the interval
michael@0 79 // at 4s so it should not play.
michael@0 80 anim.setAttribute('begin', '1s ;4s');
michael@0 81 anim.setAttribute('end', '1s; 2s');
michael@0 82 anim.setAttribute('dur', '2s ');
michael@0 83 anim.setAttribute('fill', 'freeze');
michael@0 84 checkSample(0,-100);
michael@0 85 checkSample(1,0);
michael@0 86 checkSample(1.1,5);
michael@0 87 checkSample(2,50);
michael@0 88 checkSample(3,50);
michael@0 89 checkSample(4,50);
michael@0 90 checkSample(5,50);
michael@0 91 checkSample(6,50);
michael@0 92 }
michael@0 93
michael@0 94 function testZeroDurationIntervalsB(anim) {
michael@0 95 // This interval should however actually restart as there is a valid end-point
michael@0 96 anim.setAttribute('begin', '1s ;4s');
michael@0 97 anim.setAttribute('end', '1.1s; indefinite');
michael@0 98 anim.setAttribute('dur', '2s ');
michael@0 99 anim.setAttribute('fill', 'freeze');
michael@0 100 checkSample(0,-100);
michael@0 101 checkSample(1,0);
michael@0 102 checkSample(1.1,5);
michael@0 103 checkSample(2,5);
michael@0 104 checkSample(4,0);
michael@0 105 checkSample(5,50);
michael@0 106 }
michael@0 107
michael@0 108 function testZeroDurationIntervalsC(anim) {
michael@0 109 // -0.5s has already been used as the endpoint of one interval so don't use it
michael@0 110 // a second time
michael@0 111 anim.setAttribute('begin', '-2s; -0.5s');
michael@0 112 anim.setAttribute('end', '-0.5s; 1s');
michael@0 113 anim.setAttribute('dur', '2s');
michael@0 114 anim.setAttribute('fill', 'freeze');
michael@0 115 checkSample(0,25);
michael@0 116 checkSample(1.5,75);
michael@0 117 }
michael@0 118
michael@0 119 function testZeroDurationIntervalsD(anim) {
michael@0 120 // Two end points that could make a zero-length interval
michael@0 121 anim.setAttribute('begin', '-2s; -0.5s');
michael@0 122 anim.setAttribute('end', '-0.5s; -0.5s; 1s');
michael@0 123 anim.setAttribute('dur', '2s');
michael@0 124 anim.setAttribute('fill', 'freeze');
michael@0 125 checkSample(0,25);
michael@0 126 checkSample(1.5,75);
michael@0 127 }
michael@0 128
michael@0 129 function testZeroDurationIntervalsE(anim) {
michael@0 130 // Should give us 1s-1s, 1s-5s
michael@0 131 anim.setAttribute('begin', '1s');
michael@0 132 anim.setAttribute('end', '1s; 5s');
michael@0 133 anim.setAttribute('fill', 'freeze');
michael@0 134 is(anim.getStartTime(),1);
michael@0 135 checkSample(0,-100);
michael@0 136 checkSample(1,0);
michael@0 137 checkSample(6,40);
michael@0 138 }
michael@0 139
michael@0 140 function testZeroDurationIntervalsF(anim) {
michael@0 141 // Should give us 1s-1s
michael@0 142 anim.setAttribute('begin', '1s');
michael@0 143 anim.setAttribute('end', '1s');
michael@0 144 anim.setAttribute('fill', 'freeze');
michael@0 145 is(anim.getStartTime(),1);
michael@0 146 checkSample(0,-100);
michael@0 147 checkSample(1,0);
michael@0 148 checkSample(2,0);
michael@0 149 try {
michael@0 150 anim.getStartTime();
michael@0 151 ok(false, "Failed to throw exception when there's no current interval.");
michael@0 152 } catch (e) { }
michael@0 153 }
michael@0 154
michael@0 155 function testZeroDurationIntervalsG(anim) {
michael@0 156 // Test a non-zero interval after a zero interval
michael@0 157 // Should give us 1-2s, 3-3s, 3-4s
michael@0 158 anim.setAttribute('begin', '1s; 3s');
michael@0 159 anim.setAttribute('end', '3s; 5s');
michael@0 160 anim.setAttribute('dur', '1s');
michael@0 161 anim.setAttribute('fill', 'freeze');
michael@0 162 checkSample(0,-100);
michael@0 163 checkSample(1,0);
michael@0 164 checkSample(2,100);
michael@0 165 checkSample(3,0);
michael@0 166 checkSample(5,100);
michael@0 167 }
michael@0 168
michael@0 169 function testZeroDurationIntervalsH(anim) {
michael@0 170 // Test multiple non-adjacent zero-intervals
michael@0 171 // Should give us 1-1s, 1-2s, 3-3s, 3-4s
michael@0 172 anim.setAttribute('begin', '1s; 3s');
michael@0 173 anim.setAttribute('end', '1s; 3s; 5s');
michael@0 174 anim.setAttribute('dur', '1s');
michael@0 175 anim.setAttribute('fill', 'freeze');
michael@0 176 checkSample(0,-100);
michael@0 177 checkSample(1,0);
michael@0 178 checkSample(2,100);
michael@0 179 checkSample(3,0);
michael@0 180 checkSample(5,100);
michael@0 181 }
michael@0 182
michael@0 183 function testZeroDurationIntervalsI(anim) {
michael@0 184 // Test skipping values that are the same
michael@0 185 // Should give us 1-1s, 1-2s
michael@0 186 anim.setAttribute('begin', '1s; 1s');
michael@0 187 anim.setAttribute('end', '1s; 1s; 2s');
michael@0 188 anim.setAttribute('fill', 'freeze');
michael@0 189 is(anim.getStartTime(),1);
michael@0 190 checkSample(0,-100);
michael@0 191 checkSample(1,0);
michael@0 192 checkSample(2,10);
michael@0 193 checkSample(3,10);
michael@0 194 }
michael@0 195
michael@0 196 function testZeroDurationIntervalsJ(anim) {
michael@0 197 // Should give us 0-0.5s, 1-1s, 1-3s
michael@0 198 anim.setAttribute('begin', '0s; 1s; 1s');
michael@0 199 anim.setAttribute('end', '1s; 3s');
michael@0 200 anim.setAttribute('dur', '0.5s');
michael@0 201 anim.setAttribute('fill', 'freeze');
michael@0 202 is(anim.getStartTime(),0);
michael@0 203 checkSample(0,0);
michael@0 204 checkSample(0.6,100);
michael@0 205 checkSample(1,0);
michael@0 206 checkSample(2,100);
michael@0 207 }
michael@0 208
michael@0 209 function testZeroDurationIntervalsK(anim) {
michael@0 210 // Should give us -0.5-1s
michael@0 211 anim.setAttribute('begin', '-0.5s');
michael@0 212 anim.setAttribute('end', '-0.5s; 1s');
michael@0 213 anim.setAttribute('fill', 'freeze');
michael@0 214 is(anim.getStartTime(),-0.5);
michael@0 215 checkSample(0,5);
michael@0 216 checkSample(1,15);
michael@0 217 checkSample(2,15);
michael@0 218 }
michael@0 219
michael@0 220 function testZeroDurationIntervalsL(anim) {
michael@0 221 // Test that multiple end values are ignored
michael@0 222 // Should give us 1-1s, 1-3s
michael@0 223 anim.setAttribute('begin', '1s');
michael@0 224 anim.setAttribute('end', '1s; 1s; 1s; 3s');
michael@0 225 anim.setAttribute('fill', 'freeze');
michael@0 226 is(anim.getStartTime(),1);
michael@0 227 checkSample(0,-100);
michael@0 228 checkSample(1,0);
michael@0 229 checkSample(2,10);
michael@0 230 checkSample(4,20);
michael@0 231 }
michael@0 232
michael@0 233 function testZeroDurationIntervalsM(anim) {
michael@0 234 // Test 0-duration interval at start
michael@0 235 anim.setAttribute('begin', '0s');
michael@0 236 anim.setAttribute('end', '0s');
michael@0 237 anim.setAttribute('fill', 'freeze');
michael@0 238 try {
michael@0 239 anim.getStartTime();
michael@0 240 ok(false, "Failed to throw exception when there's no current interval.");
michael@0 241 } catch (e) { }
michael@0 242 checkSample(0,0);
michael@0 243 checkSample(1,0);
michael@0 244 }
michael@0 245
michael@0 246 function testZeroDurationIntervalsN(anim) {
michael@0 247 // Test 0-active-duration interval at start (different code path to above)
michael@0 248 anim.setAttribute('begin', '0s');
michael@0 249 anim.setAttribute('repeatDur', '0s');
michael@0 250 anim.setAttribute('fill', 'freeze');
michael@0 251 try {
michael@0 252 anim.getStartTime();
michael@0 253 ok(false, "Failed to throw exception when there's no current interval.");
michael@0 254 } catch (e) { }
michael@0 255 checkSample(0,0);
michael@0 256 checkSample(1,0);
michael@0 257 }
michael@0 258
michael@0 259 function testZeroDurationIntervalsO(anim) {
michael@0 260 // Make a zero-duration interval by constraining the active duration
michael@0 261 // We should not loop infinitely but should look for the next begin time after
michael@0 262 // that (in this case that is 2s, which would otherwise have been skipped
michael@0 263 // because restart=whenNotActive)
michael@0 264 // Should give us 1-1s, 2-2s
michael@0 265 anim.setAttribute('begin', '1s; 2s');
michael@0 266 anim.setAttribute('repeatDur', '0s');
michael@0 267 anim.setAttribute('restart', 'whenNotActive');
michael@0 268 anim.setAttribute('fill', 'freeze');
michael@0 269 is(anim.getStartTime(),1);
michael@0 270 checkSample(0,-100);
michael@0 271 checkSample(1,0);
michael@0 272 checkSample(1.5,0);
michael@0 273 checkSample(3,0);
michael@0 274 try {
michael@0 275 anim.getStartTime();
michael@0 276 ok(false, "Failed to throw exception when there's no current interval.");
michael@0 277 } catch (e) { }
michael@0 278 }
michael@0 279
michael@0 280 window.addEventListener("load", main, false);
michael@0 281 ]]>
michael@0 282 </script>
michael@0 283 </pre>
michael@0 284 </body>
michael@0 285 </html>

mercurial