| OLD | NEW |
| (Empty) |
| 1 <!-- | |
| 2 Copyright 2014 Google Inc. All Rights Reserved. | |
| 3 | |
| 4 Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 you may not use this file except in compliance with the License. | |
| 6 You may obtain a copy of the License at | |
| 7 | |
| 8 http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | |
| 10 Unless required by applicable law or agreed to in writing, software | |
| 11 distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 See the License for the specific language governing permissions and | |
| 14 limitations under the License. | |
| 15 --> | |
| 16 | |
| 17 <!DOCTYPE html><meta charset="UTF-8"> | |
| 18 <script src="../bootstrap.js"></script> | |
| 19 <script> | |
| 20 'use strict'; | |
| 21 | |
| 22 function createPlayer() { | |
| 23 return document.timeline.play(new Animation(null, null, 200)); | |
| 24 } | |
| 25 | |
| 26 function assertFinishEvents(description, player, expectedEvents) { | |
| 27 var i = 0; | |
| 28 | |
| 29 expectedEvents.forEach(function (expectedEvent, expectedIndex) { | |
| 30 var asyncTestHandle = async_test(description + ', t=' + expectedEvent.timeli
neTime); | |
| 31 // Testharness quirk: async_test won't time out if step is never called. | |
| 32 at(expectedEvent.timelineTime, function() {asyncTestHandle.step(function() {
});}); | |
| 33 player.addEventListener('finish', function(event) { | |
| 34 if (i === expectedIndex) { | |
| 35 asyncTestHandle.step(function() { | |
| 36 assert_equals(event.currentTime, expectedEvent.currentTime, 'event.cur
rentTime'); | |
| 37 assert_equals(event.timelineTime, expectedEvent.timelineTime, 'event.t
imelineTime'); | |
| 38 assert_equals(event.target, player, 'event.target'); | |
| 39 assert_approx_equals(document.timeline.currentTime, expectedEvent.time
lineTime, 50, 'timeline.currentTime'); | |
| 40 }); | |
| 41 asyncTestHandle.done(); | |
| 42 } | |
| 43 }); | |
| 44 }); | |
| 45 | |
| 46 player.addEventListener('finish', function(event) { | |
| 47 if (i >= expectedEvents.length) { | |
| 48 test(function() {assert_true(false);}, 'More than ' + expectedEvents.lengt
h + ' events fired for test "' + description + '"'); | |
| 49 } | |
| 50 i++; | |
| 51 }); | |
| 52 } | |
| 53 | |
| 54 var player; | |
| 55 | |
| 56 player = createPlayer(); | |
| 57 assertFinishEvents('Players should fire finished events when they complete', pla
yer, [ | |
| 58 {timelineTime: 200, currentTime: 200}, | |
| 59 ]); | |
| 60 | |
| 61 player = createPlayer(); | |
| 62 player.source = null; | |
| 63 assertFinishEvents('A player with no source should report finished on the next s
ample', player, [ | |
| 64 {timelineTime: 0, currentTime: 0}, | |
| 65 ]); | |
| 66 | |
| 67 player = createPlayer(); | |
| 68 player.currentTime = 200; | |
| 69 assertFinishEvents('Jumping to the end of a player\'s animation should fire the
finish event', player, [ | |
| 70 {timelineTime: 0, currentTime: 200}, | |
| 71 ]); | |
| 72 | |
| 73 player = createPlayer(); | |
| 74 player.currentTime = 200; | |
| 75 player.currentTime = 1; | |
| 76 player.currentTime = 200; | |
| 77 assertFinishEvents('Jumping to the end of a player\'s animation twice should fir
e the finish event once', player, [ | |
| 78 {timelineTime: 0, currentTime: 200}, | |
| 79 ]); | |
| 80 | |
| 81 var jumpingPlayer = createPlayer(); | |
| 82 jumpingPlayer.currentTime = 200; | |
| 83 at(100, function() {jumpingPlayer.currentTime = 100;}); | |
| 84 at(200, function() {jumpingPlayer.currentTime = 200;}); | |
| 85 assertFinishEvents('Jumping to the end of a player\'s animation twice on differe
nt frames should fire the finish event twice', jumpingPlayer, [ | |
| 86 {timelineTime: 0, currentTime: 200}, | |
| 87 {timelineTime: 200, currentTime: 200}, | |
| 88 ]); | |
| 89 | |
| 90 var reversedPlayer = createPlayer(); | |
| 91 reversedPlayer.currentTime = 100; | |
| 92 reversedPlayer.reverse(); | |
| 93 assertFinishEvents('Reversed players should fire finish events when they reach t
he start of their animation', reversedPlayer, [ | |
| 94 {timelineTime: 100, currentTime: 0}, | |
| 95 ]); | |
| 96 | |
| 97 // Force the test harness to sample periodically. | |
| 98 for (var t = 0; t < 500; t += 100) { | |
| 99 at(t, function() {}); | |
| 100 } | |
| 101 </script> | |
| OLD | NEW |