OLD | NEW |
(Empty) | |
| 1 suite('group-player', function() { |
| 2 setup(function() { |
| 3 document.timeline._players = []; |
| 4 webAnimationsMinifill.timeline._players = []; |
| 5 this.elements = []; |
| 6 |
| 7 var animationMargin = function(target) { |
| 8 return new Animation( |
| 9 target, |
| 10 [ |
| 11 {marginLeft: '0px'}, |
| 12 {marginLeft: '100px'} |
| 13 ], |
| 14 500); |
| 15 }; |
| 16 var animationColor = function(target) { |
| 17 return new Animation( |
| 18 target, |
| 19 [ |
| 20 {backgroundColor: 'black'}, |
| 21 {backgroundColor: 'white'} |
| 22 ], |
| 23 500); |
| 24 }; |
| 25 var sequenceEmpty = function() { |
| 26 return new AnimationSequence(); |
| 27 }; |
| 28 var groupEmpty = function() { |
| 29 return new AnimationGroup(); |
| 30 }; |
| 31 var sequenceWithEffects = function(target) { |
| 32 return new AnimationSequence( |
| 33 [ |
| 34 animationMargin(target), |
| 35 animationColor(target) |
| 36 ]); |
| 37 }; |
| 38 var groupWithEffects = function(target) { |
| 39 return new AnimationGroup( |
| 40 [ |
| 41 animationMargin(target), |
| 42 animationColor(target) |
| 43 ]); |
| 44 }; |
| 45 |
| 46 var seqEmpty_source = sequenceEmpty(); |
| 47 |
| 48 var seqSimple_target = document.createElement('div'); |
| 49 var seqSimple_source = sequenceWithEffects(seqSimple_target); |
| 50 |
| 51 var seqWithSeq_target = document.createElement('div'); |
| 52 this.elements.push(seqWithSeq_target); |
| 53 var seqWithSeq_source = new AnimationSequence( |
| 54 [ |
| 55 animationMargin(seqWithSeq_target), |
| 56 animationColor(seqWithSeq_target), |
| 57 sequenceWithEffects(seqWithSeq_target) |
| 58 ]); |
| 59 |
| 60 var seqWithGroup_target = document.createElement('div'); |
| 61 this.elements.push(seqWithGroup_target); |
| 62 var seqWithGroup_source = new AnimationSequence( |
| 63 [ |
| 64 animationMargin(seqWithGroup_target), |
| 65 animationColor(seqWithGroup_target), |
| 66 groupWithEffects(seqWithGroup_target) |
| 67 ]); |
| 68 |
| 69 var seqWithEmptyGroup_source = new AnimationSequence([groupEmpty()]); |
| 70 var seqWithEmptySeq_source = new AnimationSequence([sequenceEmpty()]); |
| 71 |
| 72 var groupEmpty_source = groupEmpty(); |
| 73 |
| 74 var groupSimple_target = document.createElement('div'); |
| 75 var groupSimple_source = groupWithEffects(groupSimple_target); |
| 76 |
| 77 var groupWithSeq_target = document.createElement('div'); |
| 78 this.elements.push(groupWithSeq_target); |
| 79 var groupWithSeq_source = new AnimationGroup( |
| 80 [ |
| 81 animationMargin(groupWithSeq_target), |
| 82 animationColor(groupWithSeq_target), |
| 83 sequenceWithEffects(groupWithSeq_target) |
| 84 ]); |
| 85 |
| 86 var groupWithGroup_target = document.createElement('div'); |
| 87 this.elements.push(groupWithGroup_target); |
| 88 var groupWithGroup_source = new AnimationGroup( |
| 89 [ |
| 90 animationMargin(groupWithGroup_target), |
| 91 animationColor(groupWithGroup_target), |
| 92 groupWithEffects(groupWithGroup_target) |
| 93 ]); |
| 94 |
| 95 var groupWithEmptyGroup_source = new AnimationGroup([groupEmpty()]); |
| 96 var groupWithEmptySeq_source = new AnimationGroup([sequenceEmpty()]); |
| 97 |
| 98 this.seqEmpty_source = seqEmpty_source; |
| 99 this.seqSimple_source = seqSimple_source; |
| 100 this.seqWithSeq_source = seqWithSeq_source; |
| 101 this.seqWithGroup_source = seqWithGroup_source; |
| 102 this.seqWithEmptyGroup_source = seqWithEmptyGroup_source; |
| 103 this.seqWithEmptySeq_source = seqWithEmptySeq_source; |
| 104 |
| 105 this.groupEmpty_source = groupEmpty_source; |
| 106 this.groupSimple_source = groupSimple_source; |
| 107 this.groupWithSeq_source = groupWithSeq_source; |
| 108 this.groupWithGroup_source = groupWithGroup_source; |
| 109 this.groupWithEmptyGroup_source = groupWithEmptyGroup_source; |
| 110 this.groupWithEmptySeq_source = groupWithEmptySeq_source; |
| 111 |
| 112 this.staticAnimation = function(target, value, duration) { |
| 113 var animation = new Animation(target, [{marginLeft: value}, {marginLeft: v
alue}], duration); |
| 114 animation.testValue = value; |
| 115 return animation; |
| 116 }; |
| 117 // The following animation structure looks like: |
| 118 // 44444 |
| 119 // 11 |
| 120 // 33 |
| 121 // 2 |
| 122 // 0 |
| 123 this.complexTarget = document.createElement('div'); |
| 124 this.elements.push(this.complexTarget); |
| 125 this.complexSource = new AnimationGroup([ |
| 126 this.staticAnimation(this.complexTarget, '4px', 5), |
| 127 new AnimationSequence([ |
| 128 this.staticAnimation(this.complexTarget, '1px', 2), |
| 129 new AnimationGroup([ |
| 130 this.staticAnimation(this.complexTarget, '3px', 2), |
| 131 this.staticAnimation(this.complexTarget, '2px', 1), |
| 132 ]), |
| 133 ]), |
| 134 this.staticAnimation(this.complexTarget, '0px', 1), |
| 135 ]); |
| 136 |
| 137 this.target = document.createElement('div'); |
| 138 this.elements.push(this.target); |
| 139 |
| 140 for (var i = 0; i < this.elements.length; i++) |
| 141 document.documentElement.appendChild(this.elements[i]); |
| 142 }); |
| 143 |
| 144 teardown(function() { |
| 145 for (var i = 0; i < this.elements.length; i++) { |
| 146 if (this.elements[i].parent) |
| 147 this.elements[i].parent.removeChild(this.elements[i]); |
| 148 } |
| 149 }); |
| 150 |
| 151 function simpleAnimationGroup() { |
| 152 return new AnimationGroup([new Animation(document.body, [], 2000), new Anima
tion(document.body, [], 1000), new Animation(document.body, [], 3000)]); |
| 153 } |
| 154 |
| 155 function simpleAnimationSequence() { |
| 156 return new AnimationSequence([new Animation(document.body, [], 2000), new An
imation(document.body, [], 1000), new Animation(document.body, [], 3000)]); |
| 157 } |
| 158 |
| 159 // FIXME: Remove _startOffset. |
| 160 // playerState is [startTime, currentTime, _startOffset?, offset?] |
| 161 // innerPlayerStates is a nested array tree of playerStates e.g. [[0, 0], [[1,
-1], [2, -2]]] |
| 162 function checkTimes(player, playerState, innerPlayerStates, description) { |
| 163 description = description ? (description + ' ') : ''; |
| 164 _checkTimes(player, playerState, 0, description + 'top player'); |
| 165 _checkTimes(player, innerPlayerStates, 0, description + 'inner player'); |
| 166 } |
| 167 |
| 168 function _checkTimes(player, timingList, index, trace) { |
| 169 assert.isDefined(player, trace + ' exists'); |
| 170 if (timingList.length == 0) { |
| 171 assert.equal(player._childPlayers.length, index, trace + ' no remaining pl
ayers'); |
| 172 return; |
| 173 } |
| 174 if (timingList[0] === null || typeof timingList[0] == 'number') { |
| 175 assert.equal(player.startTime, timingList[0], trace + ' startTime'); |
| 176 assert.equal(player.currentTime, timingList[1], trace + ' currentTime'); |
| 177 } else { |
| 178 _checkTimes(player._childPlayers[index], timingList[0], 0, trace + ' ' + i
ndex); |
| 179 _checkTimes(player, timingList.slice(1), index + 1, trace); |
| 180 } |
| 181 } |
| 182 |
| 183 test('playing an animationGroup works as expected', function() { |
| 184 tick(90); |
| 185 var p = document.timeline.play(simpleAnimationGroup()); |
| 186 checkTimes(p, [null, 0], []); |
| 187 tick(100); |
| 188 checkTimes(p, [100, 0], [[100, 0], [100, 0], [100, 0]]); |
| 189 tick(300); |
| 190 checkTimes(p, [100, 200], [[100, 200], [100, 200], [100, 200]]); |
| 191 tick(1200); |
| 192 checkTimes(p, [100, 1100], [[100, 1100], [100, 1000], [100, 1100]]); |
| 193 tick(2200); |
| 194 checkTimes(p, [100, 2100], [[100, 2000], [100, 1000], [100, 2100]]); |
| 195 tick(3200); |
| 196 checkTimes(p, [100, 3000], [[100, 2000], [100, 1000], [100, 3000]]); |
| 197 }); |
| 198 |
| 199 test('can seek an animationGroup', function() { |
| 200 tick(90); |
| 201 var p = document.timeline.play(simpleAnimationGroup()); |
| 202 tick(100); |
| 203 checkTimes(p, [100, 0], [[100, 0], [100, 0], [100, 0]]); |
| 204 p.currentTime = 200; |
| 205 checkTimes(p, [-100, 200], [[-100, 200], [-100, 200], [-100, 200]]); |
| 206 p.currentTime = 1100; |
| 207 checkTimes(p, [-1000, 1100], [[-1000, 1100], [-1000, 1100], [-1000, 1100]]); |
| 208 p.currentTime = 2100; |
| 209 checkTimes(p, [-2000, 2100], [[-2000, 2100], [-2000, 2100], [-2000, 2100]]); |
| 210 p.currentTime = 3100; |
| 211 checkTimes(p, [-3000, 3100], [[-3000, 3100], [-3000, 3100], [-3000, 3100]]); |
| 212 }); |
| 213 |
| 214 test('can startTime seek an animationGroup', function() { |
| 215 tick(90); |
| 216 var p = document.timeline.play(simpleAnimationGroup()); |
| 217 tick(100); |
| 218 checkTimes(p, [100, 0], [[100, 0], [100, 0], [100, 0]]); |
| 219 p.startTime = -100; |
| 220 checkTimes(p, [-100, 200], [[-100, 200], [-100, 200], [-100, 200]]); |
| 221 p.startTime = -1000; |
| 222 checkTimes(p, [-1000, 1100], [[-1000, 1100], [-1000, 1000], [-1000, 1100]]); |
| 223 p.startTime = -2000; |
| 224 checkTimes(p, [-2000, 2100], [[-2000, 2000], [-2000, 1000], [-2000, 2100]]); |
| 225 p.startTime = -3000; |
| 226 checkTimes(p, [-3000, 3000], [[-3000, 2000], [-3000, 1000], [-3000, 3000]]); |
| 227 }); |
| 228 |
| 229 test('playing an animationSequence works as expected', function() { |
| 230 tick(100); |
| 231 var p = document.timeline.play(simpleAnimationSequence()); |
| 232 tick(110); |
| 233 checkTimes(p, [110, 0], [[110, 0], [2110, -2000], [3110, -3000]]); |
| 234 tick(210); |
| 235 checkTimes(p, [110, 100], [[110, 100], [2110, -1900], [3110, -2900]]); |
| 236 tick(2210); |
| 237 checkTimes(p, [110, 2100], [[110, 2000], [2110, 100], [3110, -900]]); |
| 238 tick(3210); |
| 239 checkTimes(p, [110, 3100], [[110, 2000], [2110, 1000], [3110, 100]]); |
| 240 tick(6210); |
| 241 checkTimes(p, [110, 6000], [[110, 2000], [2110, 1000], [3110, 3000]]); |
| 242 }); |
| 243 |
| 244 test('can seek an animationSequence', function() { |
| 245 tick(100); |
| 246 var p = document.timeline.play(simpleAnimationSequence()); |
| 247 tick(110); |
| 248 checkTimes(p, [110, 0], [[110, 0], [2110, -2000], [3110, -3000]]); |
| 249 p.currentTime = 100; |
| 250 checkTimes(p, [10, 100], [[10, 100], [2010, -1900], [3010, -2900]]); |
| 251 p.currentTime = 2100; |
| 252 checkTimes(p, [-1990, 2100], [[-1990, 2100], [10, 100], [1010, -900]]); |
| 253 p.currentTime = 3100; |
| 254 checkTimes(p, [-2990, 3100], [[-2990, 3100], [-990, 1100], [10, 100]]); |
| 255 p.currentTime = 6100; |
| 256 checkTimes(p, [-5990, 6100], [[-5990, 6100], [-3990, 4100], [-2990, 3100]]); |
| 257 }); |
| 258 |
| 259 test('can startTime seek an animationSequence', function() { |
| 260 tick(100); |
| 261 var p = document.timeline.play(simpleAnimationSequence()); |
| 262 tick(110); |
| 263 checkTimes(p, [110, 0], [[110, 0], [2110, -2000], [3110, -3000]]); |
| 264 p.startTime = 10; |
| 265 checkTimes(p, [10, 100], [[10, 100], [2010, -1900], [3010, -2900]]); |
| 266 p.startTime = -1990; |
| 267 checkTimes(p, [-1990, 2100], [[-1990, 2000], [10, 100], [1010, -900]]); |
| 268 p.startTime = -2990; |
| 269 checkTimes(p, [-2990, 3100], [[-2990, 2000], [-990, 1000], [10, 100]]); |
| 270 p.startTime = -5990; |
| 271 checkTimes(p, [-5990, 6000], [[-5990, 2000], [-3990, 1000], [-2990, 3000]]); |
| 272 }); |
| 273 |
| 274 test('complex animation tree timing while playing', function() { |
| 275 tick(90); |
| 276 var player = document.timeline.play(this.complexSource); |
| 277 tick(100); |
| 278 checkTimes(player, [100, 0], [ |
| 279 [100, 0], [ // 4 |
| 280 [100, 0], [ // 1 |
| 281 [102, -2], // 3 |
| 282 [102, -2]]], // 2 |
| 283 [100, 0], // 0 |
| 284 ], 't = 100'); |
| 285 tick(101); |
| 286 checkTimes(player, [100, 1], [ |
| 287 [100, 1], [ // 4 |
| 288 [100, 1], [ // 1 |
| 289 [102, -1], // 3 |
| 290 [102, -1]]], // 2 |
| 291 [100, 1], // 0 |
| 292 ], 't = 101'); |
| 293 tick(102); |
| 294 checkTimes(player, [100, 2], [ |
| 295 [100, 2], [ // 4 |
| 296 [100, 2], [ // 1 |
| 297 [102, 0], // 3 |
| 298 [102, 0]]], // 2 |
| 299 [100, 1], // 0 |
| 300 ], 't = 102'); |
| 301 }); |
| 302 |
| 303 test('effects apply in the correct order', function() { |
| 304 tick(0); |
| 305 var player = document.timeline.play(this.complexSource); |
| 306 player.currentTime = 0; |
| 307 assert.equal(getComputedStyle(this.complexTarget).marginLeft, '0px'); |
| 308 player.currentTime = 1; |
| 309 checkTimes(player, [-1, 1], [[-1, 1, 0], [[-1, 1, 0], [[1, -1, 0], [1, -1, 0
]]], [-1, 1, 0]]); |
| 310 assert.equal(getComputedStyle(this.complexTarget).marginLeft, '1px'); |
| 311 player.currentTime = 2; |
| 312 // TODO: When we seek we don't limit. Is this OK? |
| 313 checkTimes(player, [-2, 2], [[-2, 2, 0], [[-2, 2, 0], [[0, 0, 0], [0, 0, 0]]
], [-2, 2, 0]]); |
| 314 assert.equal(getComputedStyle(this.complexTarget).marginLeft, '2px'); |
| 315 player.currentTime = 3; |
| 316 assert.equal(getComputedStyle(this.complexTarget).marginLeft, '3px'); |
| 317 player.currentTime = 4; |
| 318 assert.equal(getComputedStyle(this.complexTarget).marginLeft, '4px'); |
| 319 player.currentTime = 5; |
| 320 assert.equal(getComputedStyle(this.complexTarget).marginLeft, '0px'); |
| 321 }); |
| 322 |
| 323 test('cancelling group players', function() { |
| 324 tick(0); |
| 325 var player = document.timeline.play(this.complexSource); |
| 326 tick(1); |
| 327 tick(4); |
| 328 assert.equal(getComputedStyle(this.complexTarget).marginLeft, '3px'); |
| 329 player.cancel(); |
| 330 assert.equal(player.currentTime, null); |
| 331 assert.equal(getComputedStyle(this.complexTarget).marginLeft, '0px'); |
| 332 }); |
| 333 |
| 334 test('redundant animation node wrapping', function() { |
| 335 tick(100); |
| 336 var animation = new AnimationSequence([ |
| 337 this.staticAnimation(this.target, '0px', 1), |
| 338 new AnimationGroup([ |
| 339 new AnimationSequence([ |
| 340 this.staticAnimation(this.target, '1px', 1), |
| 341 this.staticAnimation(this.target, '2px', 1), |
| 342 ]), |
| 343 ]), |
| 344 ]); |
| 345 var player = document.timeline.play(animation); |
| 346 assert.equal(getComputedStyle(this.target).marginLeft, '0px'); |
| 347 checkTimes(player, [100, 0], [ |
| 348 [100, 0, 0, 0], [[ // 0 |
| 349 [101, -1, 0, 1], // 1 |
| 350 [102, -2, 1, 2]]] // 2 |
| 351 ], 't = 100'); |
| 352 tick(101); |
| 353 assert.equal(getComputedStyle(this.target).marginLeft, '1px'); |
| 354 checkTimes(player, [100, 1], [ |
| 355 [100, 1, 0, 0], [[ // 0 |
| 356 [101, 0, 0, 1], // 1 |
| 357 [102, -1, 1, 2]]] // 2 |
| 358 ], 't = 101'); |
| 359 tick(102); |
| 360 assert.equal(getComputedStyle(this.target).marginLeft, '2px'); |
| 361 assert.equal(document.timeline.currentTime, 102); |
| 362 checkTimes(player, [100, 2], [ // FIXME: Implement limiting on group players |
| 363 [100, 1, 0, 0], [[ // 0 |
| 364 [101, 1, 0, 1], // 1 |
| 365 [102, 0, 1, 2]]] // 2 |
| 366 ], 't = 102'); |
| 367 tick(103); |
| 368 assert.equal(getComputedStyle(this.target).marginLeft, '0px'); |
| 369 checkTimes(player, [100, 3], [ // FIXME: Implement limiting on group players |
| 370 [100, 1, 0, 0], [[ // 0 |
| 371 [101, 1, 0, 1], // 1 |
| 372 [102, 1, 1, 2]]] // 2 |
| 373 ], 't = 103'); |
| 374 if (this.target.parent) |
| 375 this.target.parent.removeChild(target); |
| 376 }); |
| 377 |
| 378 test('delays on groups work correctly', function() { |
| 379 // 444 |
| 380 // 1 |
| 381 // 0 |
| 382 // 33 |
| 383 // 2 |
| 384 var animation = new AnimationGroup([ |
| 385 new AnimationGroup([ |
| 386 this.staticAnimation(this.target, '4px', {duration: 3, delay: 1}), |
| 387 this.staticAnimation(this.target, '1px', {duration: 1, delay: 0}), |
| 388 ], {delay: 1}), |
| 389 new AnimationSequence([ |
| 390 this.staticAnimation(this.target, '0px', {duration: 1, delay: 0}), |
| 391 this.staticAnimation(this.target, '3px', {duration: 2, delay: 1}), |
| 392 this.staticAnimation(this.target, '2px', {duration: 1, delay: -2}), |
| 393 ]), |
| 394 ]); |
| 395 var player = document.timeline.play(animation); |
| 396 tick(100); |
| 397 checkTimes(player, [100, 0], [ |
| 398 [ |
| 399 [101, -1], |
| 400 [101, -1], |
| 401 ], [ |
| 402 [100, 0], |
| 403 [101, -1], |
| 404 [104, -4], |
| 405 ] |
| 406 ]); |
| 407 assert.equal(getComputedStyle(this.target).marginLeft, '0px'); |
| 408 tick(101); |
| 409 assert.equal(getComputedStyle(this.target).marginLeft, '1px'); |
| 410 tick(102); |
| 411 assert.equal(getComputedStyle(this.target).marginLeft, '2px'); |
| 412 tick(103); |
| 413 assert.equal(getComputedStyle(this.target).marginLeft, '3px'); |
| 414 tick(104); |
| 415 assert.equal(getComputedStyle(this.target).marginLeft, '4px'); |
| 416 tick(105); |
| 417 assert.equal(getComputedStyle(this.target).marginLeft, '0px'); |
| 418 }); |
| 419 |
| 420 test('end delays on groups work correctly', function() { |
| 421 // 11 |
| 422 // 4 |
| 423 // 0 |
| 424 // 33 |
| 425 // 2 |
| 426 var animation = new AnimationSequence([ |
| 427 new AnimationSequence([ |
| 428 this.staticAnimation(this.target, '1px', {duration: 2, endDelay: 2}), |
| 429 this.staticAnimation(this.target, '4px', {duration: 1, endDelay: 1}), |
| 430 ], {endDelay: -6}), |
| 431 new AnimationSequence([ |
| 432 this.staticAnimation(this.target, '0px', {duration: 1, endDelay: 1}), |
| 433 this.staticAnimation(this.target, '3px', {duration: 2, endDelay: -2}), |
| 434 this.staticAnimation(this.target, '2px', {duration: 1, endDelay: 2}), |
| 435 ]), |
| 436 ]); |
| 437 var player = document.timeline.play(animation); |
| 438 tick(100); |
| 439 checkTimes(player, [100, 0], [ |
| 440 [ |
| 441 [100, 0], |
| 442 [104, -4], |
| 443 ], [ |
| 444 [100, 0], |
| 445 [102, -2], |
| 446 [102, -2], |
| 447 ] |
| 448 ]); |
| 449 assert.equal(getComputedStyle(this.target).marginLeft, '0px'); |
| 450 tick(101); |
| 451 assert.equal(getComputedStyle(this.target).marginLeft, '1px'); |
| 452 tick(102); |
| 453 assert.equal(getComputedStyle(this.target).marginLeft, '2px'); |
| 454 tick(103); |
| 455 assert.equal(getComputedStyle(this.target).marginLeft, '3px'); |
| 456 tick(104); |
| 457 // FIXME: Group child player limiting bounds should match the parent player'
s limiting bounds. |
| 458 // assert.equal(getComputedStyle(this.target).marginLeft, '4px'); |
| 459 // tick(105); |
| 460 // assert.equal(getComputedStyle(this.target).marginLeft, '0px'); |
| 461 }); |
| 462 |
| 463 // FIXME: This test can be removed when this suite is finished. |
| 464 test('sources are working for basic operations', function() { |
| 465 var players = []; |
| 466 players.push(document.timeline.play(this.seqEmpty_source)); |
| 467 players.push(document.timeline.play(this.seqSimple_source)); |
| 468 players.push(document.timeline.play(this.seqWithSeq_source)); |
| 469 players.push(document.timeline.play(this.seqWithGroup_source)); |
| 470 players.push(document.timeline.play(this.seqWithEmptyGroup_source)); |
| 471 players.push(document.timeline.play(this.seqWithEmptySeq_source)); |
| 472 |
| 473 players.push(document.timeline.play(this.groupEmpty_source)); |
| 474 players.push(document.timeline.play(this.groupSimple_source)); |
| 475 players.push(document.timeline.play(this.groupWithSeq_source)); |
| 476 players.push(document.timeline.play(this.groupWithGroup_source)); |
| 477 players.push(document.timeline.play(this.groupWithEmptyGroup_source)); |
| 478 players.push(document.timeline.play(this.groupWithEmptySeq_source)); |
| 479 |
| 480 var length = players.length; |
| 481 |
| 482 tick(50); |
| 483 for (var i = 0; i < length; i++) |
| 484 players[i].pause(); |
| 485 |
| 486 tick(100); |
| 487 for (var i = 0; i < length; i++) |
| 488 players[i].play(); |
| 489 |
| 490 tick(200); |
| 491 for (var i = 0; i < length; i++) |
| 492 players[i].currentTime += 1; |
| 493 |
| 494 tick(300); |
| 495 for (var i = 0; i < length; i++) |
| 496 players[i].startTime += 1; |
| 497 |
| 498 tick(350); |
| 499 for (var i = 0; i < length; i++) |
| 500 players[i].reverse(); |
| 501 |
| 502 tick(400); |
| 503 for (var i = 0; i < length; i++) |
| 504 players[i].finish(); |
| 505 |
| 506 tick(500); |
| 507 tick(600); |
| 508 for (var i = 0; i < length; i++) |
| 509 players[i].cancel(); |
| 510 |
| 511 for (var i = 0; i < length; i++) |
| 512 players[i].play(); |
| 513 }); |
| 514 |
| 515 test('pausing works as expected with an empty AnimationSequence', function() { |
| 516 var player = document.timeline.play(this.seqEmpty_source); |
| 517 tick(0); |
| 518 assert.equal(player.startTime, 0); |
| 519 assert.equal(player.currentTime, 0); |
| 520 |
| 521 player.pause(); |
| 522 assert.equal(player.startTime, null); |
| 523 assert.equal(player.currentTime, 0); |
| 524 }); |
| 525 |
| 526 test('pausing works as expected with a simple AnimationSequence', function() { |
| 527 var player = document.timeline.play(this.seqSimple_source); |
| 528 tick(0); |
| 529 checkTimes(player, [0, 0], [[0, 0], [500, -500]], 't = 0'); |
| 530 |
| 531 tick(200); |
| 532 checkTimes(player, [0, 200], [[0, 200], [500, -300]], 't = 200'); |
| 533 |
| 534 player.pause(); |
| 535 checkTimes(player, [null, null], [[null, null], [null, null]], 't = 200'); |
| 536 |
| 537 tick(300); |
| 538 checkTimes(player, [null, 200], [[null, 200], [null, -300]], 't = 300'); |
| 539 |
| 540 player.play(); |
| 541 checkTimes(player, [null, 200], [[null, 200], [null, -300]], 't = 300'); |
| 542 |
| 543 tick(301); |
| 544 checkTimes(player, [101, 200], [[101, 200], [601, -300]], 't = 301'); |
| 545 |
| 546 tick(700); |
| 547 checkTimes(player, [101, 599], [[101, 500], [601, 99]], 't = 700'); |
| 548 }); |
| 549 |
| 550 test('pausing works as expected with an AnimationSequence inside an AnimationS
equence', function() { |
| 551 var player = document.timeline.play(this.seqWithSeq_source); |
| 552 tick(0); |
| 553 checkTimes( |
| 554 player, |
| 555 [0, 0], [ |
| 556 [0, 0], |
| 557 [500, -500], [ |
| 558 [1000, -1000], |
| 559 [1500, -1500]]], |
| 560 't = 0'); |
| 561 |
| 562 tick(200); |
| 563 checkTimes( |
| 564 player, |
| 565 [0, 200], [ |
| 566 [0, 200], |
| 567 [500, -300], [ |
| 568 [1000, -800], |
| 569 [1500, -1300]]], |
| 570 't = 200'); |
| 571 |
| 572 player.pause(); |
| 573 checkTimes( |
| 574 player, |
| 575 [null, null], [ |
| 576 [null, null], |
| 577 [null, null], [ |
| 578 [null, null], |
| 579 [null, null]]], |
| 580 't = 200'); |
| 581 |
| 582 tick(300); |
| 583 checkTimes( |
| 584 player, |
| 585 [null, 200], [ |
| 586 [null, 200], |
| 587 [null, -300], [ |
| 588 [null, -800], |
| 589 [null, -1300]]], |
| 590 't = 300'); |
| 591 |
| 592 player.play(); |
| 593 tick(310); |
| 594 checkTimes( |
| 595 player, |
| 596 [110, 200], [ |
| 597 [110, 200], |
| 598 [610, -300], [ |
| 599 [1110, -800], |
| 600 [1610, -1300]]], |
| 601 't = 310'); |
| 602 |
| 603 tick(1300); |
| 604 checkTimes( |
| 605 player, |
| 606 [110, 1190], [ |
| 607 [110, 500], |
| 608 [610, 500], [ |
| 609 [1110, 190], |
| 610 [1610, -310]]], |
| 611 't = 1300'); |
| 612 |
| 613 player.pause(); |
| 614 checkTimes( |
| 615 player, |
| 616 [null, null], [ |
| 617 [null, 500], |
| 618 [null, 500], [ |
| 619 [null, null], |
| 620 [null, null]]], |
| 621 't = 1300'); |
| 622 |
| 623 tick(1400); |
| 624 checkTimes( |
| 625 player, |
| 626 [null, 1190], [ |
| 627 [null, 500], |
| 628 [null, 500], [ |
| 629 [null, 190], |
| 630 [null, -310]]], |
| 631 't = 1400'); |
| 632 |
| 633 player.play(); |
| 634 checkTimes( |
| 635 player, |
| 636 [null, 1190], [ |
| 637 [null, 500], |
| 638 [null, 500], [ |
| 639 [null, 190], |
| 640 [null, -310]]], |
| 641 't = 1400'); |
| 642 |
| 643 tick(1410); |
| 644 checkTimes( |
| 645 player, |
| 646 [220, 1190], [ |
| 647 [220, 500], |
| 648 [720, 500], [ |
| 649 [1220, 190], |
| 650 [1720, -310]]], |
| 651 't = 1410'); |
| 652 |
| 653 tick(1600); |
| 654 checkTimes( |
| 655 player, |
| 656 [220, 1380], [ |
| 657 [220, 500], |
| 658 [720, 500], [ |
| 659 [1220, 380], |
| 660 [1720, -120]]], |
| 661 't = 1600'); |
| 662 |
| 663 player.pause(); |
| 664 checkTimes( |
| 665 player, |
| 666 [null, null], [ |
| 667 [null, 500], |
| 668 [null, 500], [ |
| 669 [null, null], |
| 670 [null, null]]], |
| 671 't = 1600'); |
| 672 |
| 673 tick(1700); |
| 674 checkTimes( |
| 675 player, |
| 676 [null, 1380], [ |
| 677 [null, 500], |
| 678 [null, 500], [ |
| 679 [null, 380], |
| 680 [null, -120]]], |
| 681 't = 1700'); |
| 682 |
| 683 player.play(); |
| 684 tick(1710); |
| 685 checkTimes( |
| 686 player, |
| 687 [330, 1380], [ |
| 688 [330, 500], |
| 689 [830, 500], [ |
| 690 [1330, 380], |
| 691 [1830, -120]]], |
| 692 't = 1710'); |
| 693 |
| 694 tick(2400); |
| 695 checkTimes( |
| 696 player, |
| 697 [330, 2000], [ |
| 698 [330, 500], |
| 699 [830, 500], [ |
| 700 [1330, 500], |
| 701 [1830, 500]]], |
| 702 't = 2400'); |
| 703 }); |
| 704 |
| 705 test('pausing works as expected with an AnimationGroup inside an AnimationSequ
ence', function() { |
| 706 var player = document.timeline.play(this.seqWithGroup_source); |
| 707 tick(0); |
| 708 checkTimes( |
| 709 player, |
| 710 [0, 0], [ |
| 711 [0, 0], |
| 712 [500, -500], [ |
| 713 [1000, -1000], |
| 714 [1000, -1000]]], |
| 715 't = 0'); |
| 716 |
| 717 tick(200); |
| 718 checkTimes( |
| 719 player, |
| 720 [0, 200], [ |
| 721 [0, 200], |
| 722 [500, -300], [ |
| 723 [1000, -800], |
| 724 [1000, -800]]], |
| 725 't = 200'); |
| 726 |
| 727 player.pause(); |
| 728 checkTimes( |
| 729 player, |
| 730 [null, null], [ |
| 731 [null, null], |
| 732 [null, null], [ |
| 733 [null, null], |
| 734 [null, null]]], |
| 735 't = 200'); |
| 736 |
| 737 tick(300); |
| 738 checkTimes( |
| 739 player, |
| 740 [null, 200], [ |
| 741 [null, 200], |
| 742 [null, -300], [ |
| 743 [null, -800], |
| 744 [null, -800]]], |
| 745 't = 300'); |
| 746 |
| 747 player.play(); |
| 748 tick(310); |
| 749 checkTimes( |
| 750 player, |
| 751 [110, 200], [ |
| 752 [110, 200], |
| 753 [610, -300], [ |
| 754 [1110, -800], |
| 755 [1110, -800]]], |
| 756 't = 310'); |
| 757 |
| 758 tick(1310); |
| 759 checkTimes( |
| 760 player, |
| 761 [110, 1200], [ |
| 762 [110, 500], |
| 763 [610, 500], [ |
| 764 [1110, 200], |
| 765 [1110, 200]]], |
| 766 't = 1310'); |
| 767 |
| 768 player.pause(); |
| 769 checkTimes( |
| 770 player, |
| 771 [null, null], [ |
| 772 [null, 500], |
| 773 [null, 500], [ |
| 774 [null, null], |
| 775 [null, null]]], |
| 776 't = 1310'); |
| 777 |
| 778 tick(1400); |
| 779 checkTimes( |
| 780 player, |
| 781 [null, 1200], [ |
| 782 [null, 500], |
| 783 [null, 500], [ |
| 784 [null, 200], |
| 785 [null, 200]]], |
| 786 't = 1410'); |
| 787 |
| 788 player.play(); |
| 789 tick(1410); |
| 790 checkTimes( |
| 791 player, |
| 792 [210, 1200], [ |
| 793 [210, 500], |
| 794 [710, 500], [ |
| 795 [1210, 200], |
| 796 [1210, 200]]], |
| 797 't = 1410'); |
| 798 |
| 799 tick(1610); |
| 800 checkTimes( |
| 801 player, |
| 802 [210, 1400], [ |
| 803 [210, 500], |
| 804 [710, 500], [ |
| 805 [1210, 400], |
| 806 [1210, 400]]], |
| 807 't = 1610'); |
| 808 |
| 809 player.pause(); |
| 810 tick(1810); |
| 811 checkTimes( |
| 812 player, |
| 813 [null, 1400], [ |
| 814 [null, 500], |
| 815 [null, 500], [ |
| 816 [null, 400], |
| 817 [null, 400]]], |
| 818 't = 1810'); |
| 819 |
| 820 player.play(); |
| 821 tick(1820); |
| 822 checkTimes( |
| 823 player, |
| 824 [420, 1400], [ |
| 825 [420, 500], |
| 826 [920, 500], [ |
| 827 [1420, 400], |
| 828 [1420, 400]]], |
| 829 't = 1820'); |
| 830 |
| 831 tick(2020); |
| 832 checkTimes( |
| 833 player, |
| 834 [420, 1500], [ |
| 835 [420, 500], |
| 836 [920, 500], [ |
| 837 [1420, 500], |
| 838 [1420, 500]]], |
| 839 't = 2020'); |
| 840 |
| 841 player.pause(); |
| 842 checkTimes( |
| 843 player, |
| 844 [null, 1500], [ |
| 845 [null, 500], |
| 846 [null, 500], [ |
| 847 [null, 500], |
| 848 [null, 500]]], |
| 849 't = 2020'); |
| 850 }); |
| 851 |
| 852 test('pausing works as expected with an empty AnimationSequence inside an Anim
ationSequence', function() { |
| 853 var player = document.timeline.play(this.seqWithEmptySeq_source); |
| 854 tick(0); |
| 855 checkTimes( |
| 856 player, |
| 857 [0, 0], [0, 0], |
| 858 't = 0'); |
| 859 |
| 860 player.pause(); |
| 861 checkTimes( |
| 862 player, |
| 863 [null, 0], [null, 0], |
| 864 't = 0 after pause'); |
| 865 }); |
| 866 |
| 867 test('pausing works as expected with an empty AnimationGroup inside an Animati
onSequence', function() { |
| 868 var player = document.timeline.play(this.seqWithEmptyGroup_source); |
| 869 tick(0); |
| 870 checkTimes( |
| 871 player, |
| 872 [0, 0], [0, 0], |
| 873 't = 0'); |
| 874 |
| 875 player.pause(); |
| 876 checkTimes( |
| 877 player, |
| 878 [null, 0], [null, 0], |
| 879 't = 0 after pause'); |
| 880 }); |
| 881 |
| 882 test('playState works for groups', function() { |
| 883 var target = document.createElement('div'); |
| 884 document.body.appendChild(target); |
| 885 var anim = new AnimationSequence([new Animation(target, [], 100), new Animat
ion(target, [], 100)]); |
| 886 var p = document.timeline.play(anim); |
| 887 assert.equal(p.playState, 'pending'); |
| 888 tick(1); |
| 889 assert.equal(p.playState, 'running'); |
| 890 assert.equal(p._childPlayers[0]._player.playState, 'running'); |
| 891 assert.equal(p._childPlayers[1]._player.playState, 'running'); |
| 892 tick(101); |
| 893 assert.equal(p.playState, 'running'); |
| 894 assert.equal(p._childPlayers[0]._player.playState, 'finished'); |
| 895 assert.equal(p._childPlayers[1]._player.playState, 'running'); |
| 896 p.pause(); |
| 897 assert.equal(p.playState, 'pending'); |
| 898 assert.equal(p._childPlayers[0]._player.playState, 'paused'); |
| 899 assert.equal(p._childPlayers[1]._player.playState, 'pending'); |
| 900 tick(102); |
| 901 assert.equal(p.playState, 'paused'); |
| 902 assert.equal(p._childPlayers[0]._player.playState, 'paused'); |
| 903 assert.equal(p._childPlayers[1]._player.playState, 'paused'); |
| 904 p.play(); |
| 905 assert.equal(p.playState, 'pending'); |
| 906 assert.equal(p._childPlayers[0]._player.playState, 'pending'); |
| 907 assert.equal(p._childPlayers[1]._player.playState, 'pending'); |
| 908 tick(103); |
| 909 assert.equal(p.playState, 'running'); |
| 910 assert.equal(p._childPlayers[0]._player.playState, 'finished'); |
| 911 assert.equal(p._childPlayers[1]._player.playState, 'running'); |
| 912 tick(204); |
| 913 assert.equal(p.playState, 'finished'); |
| 914 assert.equal(p._childPlayers[0]._player.playState, 'finished'); |
| 915 assert.equal(p._childPlayers[1]._player.playState, 'finished'); |
| 916 }); |
| 917 }); |
OLD | NEW |