OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <meta charset=utf-8> | 2 <meta charset=utf-8> |
3 <title>Current iteration tests</title> | 3 <title>Current iteration tests</title> |
4 <link rel="help" href="https://w3c.github.io/web-animations/#current-iteration"> | 4 <link rel="help" href="https://w3c.github.io/web-animations/#current-iteration"> |
5 <script src="/resources/testharness.js"></script> | 5 <script src="/resources/testharness.js"></script> |
6 <script src="/resources/testharnessreport.js"></script> | 6 <script src="/resources/testharnessreport.js"></script> |
7 <script src="../../testcommon.js"></script> | 7 <script src="../../testcommon.js"></script> |
8 <body> | 8 <body> |
9 <div id="log"></div> | 9 <div id="log"></div> |
10 <script> | 10 <script> |
11 'use strict'; | 11 'use strict'; |
12 | 12 |
13 function executeTests(tests, description) { | 13 function runTests(tests, description) { |
14 tests.forEach(function(currentTest) { | 14 tests.forEach(function(currentTest) { |
15 var testParams = ''; | 15 var testParams = ''; |
16 for (var attr in currentTest.input) { | 16 for (var attr in currentTest.input) { |
17 testParams += ' ' + attr + ':' + currentTest.input[attr]; | 17 testParams += ' ' + attr + ':' + currentTest.input[attr]; |
18 } | 18 } |
19 test(function(t) { | 19 test(function(t) { |
20 var div = createDiv(t); | 20 var div = createDiv(t); |
21 var anim = div.animate({ opacity: [ 0, 1 ] }, currentTest.input); | 21 var anim = div.animate({ opacity: [ 0, 1 ] }, currentTest.input); |
22 assert_equals(anim.effect.getComputedTiming().currentIteration, | 22 assert_equals(anim.effect.getComputedTiming().currentIteration, |
23 currentTest.before); | 23 currentTest.before); |
24 anim.currentTime = currentTest.input.delay || 0; | 24 anim.currentTime = currentTest.input.delay || 0; |
25 assert_equals(anim.effect.getComputedTiming().currentIteration, | 25 assert_equals(anim.effect.getComputedTiming().currentIteration, |
26 currentTest.active); | 26 currentTest.active); |
27 if (typeof currentTest.after !== 'undefined') { | 27 if (typeof currentTest.after !== 'undefined') { |
28 anim.finish(); | 28 anim.finish(); |
29 assert_equals(anim.effect.getComputedTiming().currentIteration, | 29 assert_equals(anim.effect.getComputedTiming().currentIteration, |
30 currentTest.after); | 30 currentTest.after); |
31 } | 31 } |
32 }, description + testParams); | 32 }, description + ':' + testParams); |
33 }); | 33 }); |
34 } | 34 } |
35 | 35 |
36 async_test(function(t) { | 36 async_test(function(t) { |
37 var div = createDiv(t); | 37 var div = createDiv(t); |
38 var anim = div.animate({ opacity: [ 0, 1 ] }, { delay: 1 }); | 38 var anim = div.animate({ opacity: [ 0, 1 ] }, { delay: 1 }); |
39 assert_equals(anim.effect.getComputedTiming().currentIteration, null); | 39 assert_equals(anim.effect.getComputedTiming().currentIteration, null); |
40 anim.finished.then(t.step_func(function() { | 40 anim.finished.then(t.step_func(function() { |
41 assert_equals(anim.effect.getComputedTiming().currentIteration, null); | 41 assert_equals(anim.effect.getComputedTiming().currentIteration, null); |
42 t.done(); | 42 t.done(); |
43 })); | 43 })); |
44 }, 'Test currentIteration during before and after phase when fill is none'); | 44 }, 'Test currentIteration during before and after phase when fill is none'); |
45 | 45 |
46 var gTests_zero_iterations = [ | 46 |
| 47 // -------------------------------------------------------------------- |
| 48 // |
| 49 // Zero iteration duration tests |
| 50 // |
| 51 // -------------------------------------------------------------------- |
| 52 |
| 53 runTests([ |
47 { | 54 { |
48 input: { iterations: 0, | 55 input: { iterations: 0, |
49 iterationStart: 0, | 56 iterationStart: 0, |
50 duration: 0, | 57 duration: 0, |
51 delay: 1, | 58 delay: 1, |
52 fill: 'both' }, | 59 fill: 'both' }, |
53 before: 0, | 60 before: 0, |
54 active: 0, | 61 active: 0, |
55 after: 0 | 62 after: 0 |
56 }, | 63 }, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 { | 142 { |
136 input: { iterations: 0, | 143 input: { iterations: 0, |
137 iterationStart: 3, | 144 iterationStart: 3, |
138 duration: Infinity, | 145 duration: Infinity, |
139 delay: 1, | 146 delay: 1, |
140 fill: 'both' }, | 147 fill: 'both' }, |
141 before: 3, | 148 before: 3, |
142 active: 3, | 149 active: 3, |
143 after: 3 | 150 after: 3 |
144 } | 151 } |
145 ]; | 152 ], 'Test zero iterations'); |
146 | 153 |
147 var gTests_integer_iterations = [ | 154 |
| 155 // -------------------------------------------------------------------- |
| 156 // |
| 157 // Tests where the iteration count is an integer |
| 158 // |
| 159 // -------------------------------------------------------------------- |
| 160 |
| 161 runTests([ |
148 { | 162 { |
149 input: { iterations: 3, | 163 input: { iterations: 3, |
150 iterationStart: 0, | 164 iterationStart: 0, |
151 duration: 0, | 165 duration: 0, |
152 delay: 1, | 166 delay: 1, |
153 fill: 'both' }, | 167 fill: 'both' }, |
154 before: 0, | 168 before: 0, |
155 active: 2, | 169 active: 2, |
156 after: 2 | 170 after: 2 |
157 }, | 171 }, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 | 247 |
234 { | 248 { |
235 input: { iterations: 3, | 249 input: { iterations: 3, |
236 iterationStart: 3, | 250 iterationStart: 3, |
237 duration: Infinity, | 251 duration: Infinity, |
238 delay: 1, | 252 delay: 1, |
239 fill: 'both' }, | 253 fill: 'both' }, |
240 before: 3, | 254 before: 3, |
241 active: 3 | 255 active: 3 |
242 } | 256 } |
243 ]; | 257 ], 'Test integer iterations'); |
244 | 258 |
245 var gTests_fractional_iterations = [ | 259 |
| 260 // -------------------------------------------------------------------- |
| 261 // |
| 262 // Tests where the iteration count is a fraction |
| 263 // |
| 264 // -------------------------------------------------------------------- |
| 265 |
| 266 runTests([ |
246 { | 267 { |
247 input: { iterations: 3.5, | 268 input: { iterations: 3.5, |
248 iterationStart: 0, | 269 iterationStart: 0, |
249 duration: 0, | 270 duration: 0, |
250 delay: 1, | 271 delay: 1, |
251 fill: 'both' }, | 272 fill: 'both' }, |
252 before: 0, | 273 before: 0, |
253 active: 3, | 274 active: 3, |
254 after: 3 | 275 after: 3 |
255 }, | 276 }, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 | 352 |
332 { | 353 { |
333 input: { iterations: 3.5, | 354 input: { iterations: 3.5, |
334 iterationStart: 3, | 355 iterationStart: 3, |
335 duration: Infinity, | 356 duration: Infinity, |
336 delay: 1, | 357 delay: 1, |
337 fill: 'both' }, | 358 fill: 'both' }, |
338 before: 3, | 359 before: 3, |
339 active: 3 | 360 active: 3 |
340 } | 361 } |
341 ]; | 362 ], 'Test fractional iterations'); |
342 | 363 |
343 var gTests_infinity_iterations = [ | 364 |
| 365 // -------------------------------------------------------------------- |
| 366 // |
| 367 // Tests where the iteration count is Infinity |
| 368 // |
| 369 // -------------------------------------------------------------------- |
| 370 |
| 371 runTests([ |
344 { | 372 { |
345 input: { iterations: Infinity, | 373 input: { iterations: Infinity, |
346 iterationStart: 0, | 374 iterationStart: 0, |
347 duration: 0, | 375 duration: 0, |
348 delay: 1, | 376 delay: 1, |
349 fill: 'both' }, | 377 fill: 'both' }, |
350 before: 0, | 378 before: 0, |
351 active: Infinity, | 379 active: Infinity, |
352 after: Infinity | 380 after: Infinity |
353 }, | 381 }, |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 | 454 |
427 { | 455 { |
428 input: { iterations: Infinity, | 456 input: { iterations: Infinity, |
429 iterationStart: 3, | 457 iterationStart: 3, |
430 duration: Infinity, | 458 duration: Infinity, |
431 delay: 1, | 459 delay: 1, |
432 fill: 'both' }, | 460 fill: 'both' }, |
433 before: 3, | 461 before: 3, |
434 active: 3 | 462 active: 3 |
435 } | 463 } |
436 ]; | 464 ], 'Test infinity iterations'); |
437 | 465 |
438 executeTests(gTests_zero_iterations, "Test zero iterations:"); | 466 |
439 executeTests(gTests_integer_iterations, "Test integer iterations:"); | 467 // -------------------------------------------------------------------- |
440 executeTests(gTests_fractional_iterations, "Test fractional iterations:"); | 468 // |
441 executeTests(gTests_infinity_iterations, "Test infinity iterations:"); | 469 // End delay tests |
| 470 // |
| 471 // -------------------------------------------------------------------- |
| 472 |
| 473 runTests([ |
| 474 { |
| 475 input: { duration: 100, |
| 476 delay: 1, |
| 477 fill: 'both', |
| 478 endDelay: 50 }, |
| 479 before: 0, |
| 480 active: 0, |
| 481 after: 0 |
| 482 }, |
| 483 |
| 484 { |
| 485 input: { duration: 100, |
| 486 delay: 1, |
| 487 fill: 'both', |
| 488 endDelay: -50 }, |
| 489 before: 0, |
| 490 active: 0, |
| 491 after: 0 |
| 492 }, |
| 493 |
| 494 { |
| 495 input: { duration: 100, |
| 496 delay: 1, |
| 497 fill: 'both', |
| 498 endDelay: -100 }, |
| 499 before: 0, |
| 500 active: 0, |
| 501 after: 0 |
| 502 }, |
| 503 |
| 504 { |
| 505 input: { duration: 100, |
| 506 delay: 1, |
| 507 fill: 'both', |
| 508 endDelay: -200 }, |
| 509 before: 0, |
| 510 active: 0, |
| 511 after: 0 |
| 512 }, |
| 513 |
| 514 { |
| 515 input: { iterationStart: 0.5, |
| 516 duration: 100, |
| 517 delay: 1, |
| 518 fill: 'both', |
| 519 endDelay: 50 }, |
| 520 before: 0, |
| 521 active: 0, |
| 522 after: 1 |
| 523 }, |
| 524 |
| 525 { |
| 526 input: { iterationStart: 0.5, |
| 527 duration: 100, |
| 528 delay: 1, |
| 529 fill: 'both', |
| 530 endDelay: -50 }, |
| 531 before: 0, |
| 532 active: 0, |
| 533 after: 0 |
| 534 }, |
| 535 |
| 536 { |
| 537 input: { iterationStart: 0.5, |
| 538 duration: 100, |
| 539 delay: 1, |
| 540 fill: 'both', |
| 541 endDelay: -100 }, |
| 542 before: 0, |
| 543 active: 0, |
| 544 after: 0 |
| 545 }, |
| 546 |
| 547 { |
| 548 input: { iterations: 2, |
| 549 duration: 100, |
| 550 delay: 1, |
| 551 fill: 'both', |
| 552 endDelay: -100 }, |
| 553 before: 0, |
| 554 active: 0, |
| 555 after: 0 |
| 556 }, |
| 557 |
| 558 { |
| 559 input: { iterations: 1, |
| 560 iterationStart: 2, |
| 561 duration: 100, |
| 562 delay: 1, |
| 563 fill: 'both', |
| 564 endDelay: -50 }, |
| 565 before: 2, |
| 566 active: 2, |
| 567 after: 2 |
| 568 }, |
| 569 |
| 570 { |
| 571 input: { iterations: 1, |
| 572 iterationStart: 2, |
| 573 duration: 100, |
| 574 delay: 1, |
| 575 fill: 'both', |
| 576 endDelay: -100 }, |
| 577 before: 2, |
| 578 active: 2, |
| 579 after: 2 |
| 580 }, |
| 581 ], 'Test end delay'); |
442 | 582 |
443 </script> | 583 </script> |
444 </body> | 584 </body> |
OLD | NEW |