Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <meta charset=utf-8> | |
| 3 <title>Tests for the finish event</title> | |
| 4 <link rel="help" href="https://w3c.github.io/web-animations/#the-animation-inter face"> | |
|
alancutter (OOO until 2018)
2016/07/12 05:25:15
This is too non-specific, how about https://w3c.gi
sashab
2016/07/12 05:45:00
Done
sashab
2016/07/12 05:45:00
Done
| |
| 5 <script src="../resources/testharness.js"></script> | |
| 6 <script src="../resources/testharnessreport.js"></script> | |
| 7 <script src="../imported/wpt/web-animations/testcommon.js"></script> | |
| 8 <body> | |
| 9 <script> | |
| 10 'use strict'; | |
| 11 var keyframes = [ | |
| 12 {left: '10px', opacity: '1', offset: 0}, | |
| 13 {left: '100px', opacity: '0', offset: 1} | |
| 14 ]; | |
|
alancutter (OOO until 2018)
2016/07/12 05:25:15
No need for actual keyframes, you can just use nul
sashab
2016/07/12 05:45:00
Done :)
| |
| 15 | |
| 16 function validateFinishEvent(t, event, animation) { | |
| 17 t.step(function() { | |
| 18 assert_equals(event.target, animation, 'Animation should be target'); | |
| 19 assert_equals(event.currentTime, animation.currentTime, 'Event currentTime s hould be animation currentTime'); | |
| 20 assert_equals(event.timelineTime, document.timeline.currentTime, 'Event time lineTime should be document timeline currentTime'); | |
| 21 }); | |
| 22 } | |
| 23 | |
| 24 async_test(function(t) { | |
| 25 var div = createDiv(t); | |
| 26 var animation = div.animate(keyframes, 70.0); | |
| 27 animation.onfinish = function(event) { | |
|
alancutter (OOO until 2018)
2016/07/12 05:25:15
The WPTs prefer using the finished promise.
| |
| 28 t.unreached_func("Seeking to finish should not queue onfinish event"); | |
| 29 }; | |
| 30 animation.finish(); | |
| 31 animation.currentTime = 0; | |
| 32 animation.pause(); | |
| 33 t.done(); | |
| 34 }, "animation.onfinish() doesn't runs when the animation seeks to finish"); | |
| 35 | |
| 36 async_test(function(t) { | |
| 37 var div = createDiv(t); | |
| 38 var animation = div.animate(keyframes, 70.0); | |
| 39 animation.onfinish = function (event) { | |
| 40 t.unreached_func("Seeking past finish should not queue onfinish event"); | |
| 41 }; | |
| 42 animation.currentTime = 80.0; | |
| 43 animation.currentTime = 0; | |
| 44 animation.pause(); | |
| 45 t.done(); | |
| 46 }, "animation.onfinish() doesn't runs when the animation seeks past finish"); | |
|
alancutter (OOO until 2018)
2016/07/12 05:25:15
s/doesn't runs/doesn't run/
sashab
2016/07/12 05:45:00
Done
| |
| 47 | |
| 48 async_test(function(t) { | |
| 49 var div = createDiv(t); | |
| 50 var animation = div.animate(keyframes, 90.0); | |
| 51 animation.onfinish = function(event) { | |
| 52 validateFinishEvent(t, event, animation); | |
| 53 t.done(); | |
| 54 }; | |
| 55 animation.finish(); | |
| 56 }, "animation.onfinish() runs when the animation completes with .finish()"); | |
| 57 | |
| 58 async_test(function(t) { | |
| 59 var div = createDiv(t); | |
| 60 var animation = div.animate(keyframes, 100); | |
| 61 animation.onfinish = function(event) { | |
| 62 validateFinishEvent(t, event, animation); | |
| 63 t.done(); | |
| 64 }; | |
| 65 }, "animation.onfinish() runs when the animation completes"); | |
| 66 | |
| 67 async_test(function(t) { | |
| 68 var animation1 = createDiv(t).animate(keyframes, 0.05); | |
| 69 var firstRun1 = true; | |
| 70 animation1.onfinish = function(event) { | |
| 71 validateFinishEvent(t, event, animation1); | |
| 72 t.done(); | |
| 73 | |
| 74 if (firstRun1) { | |
| 75 firstRun1 = false; | |
| 76 animation1.currentTime = 0; | |
| 77 return; | |
| 78 } | |
| 79 | |
| 80 var animation2 = createDiv(t).animate(keyframes, 0.05); | |
| 81 var firstRun2 = true; | |
| 82 animation2.onfinish = function(event) { | |
| 83 validateFinishEvent(t, event, animation2); | |
| 84 t.done(); | |
| 85 | |
| 86 if (firstRun2) { | |
| 87 firstRun2 = false; | |
| 88 animation2.play(); | |
| 89 return; | |
| 90 } | |
| 91 | |
| 92 var animation3 = createDiv(t).animate(keyframes, 0.05); | |
|
alancutter (OOO until 2018)
2016/07/12 05:25:15
Two levels of chaining should be sufficient.
sashab
2016/07/12 05:45:00
Done
| |
| 93 var firstRun3 = true; | |
| 94 animation3.onfinish = function(event) { | |
| 95 validateFinishEvent(t, event, animation3); | |
| 96 t.done(); | |
| 97 | |
| 98 if (firstRun3) { | |
| 99 firstRun3 = false; | |
| 100 animation3.reverse(); | |
| 101 return; | |
| 102 } | |
| 103 | |
| 104 t.done(); | |
|
alancutter (OOO until 2018)
2016/07/12 05:25:15
It doesn't seem correct to call t.done() multiple
sashab
2016/07/12 05:44:59
Done
| |
| 105 } | |
| 106 } | |
| 107 } | |
| 108 }, "animation.onfinish() calls can be chained"); | |
| 109 </script> | |
| OLD | NEW |