Debian Codegraph @

closure-library/closure/goog/fx/animationqueue_test.js

raw
1 // Copyright 2011 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 goog.provide('goog.fx.AnimationQueueTest');
16 goog.setTestOnly('goog.fx.AnimationQueueTest');
17
18 goog.require('goog.events');
19 goog.require('goog.fx.Animation');
20 goog.require('goog.fx.AnimationParallelQueue');
21 goog.require('goog.fx.AnimationSerialQueue');
22 goog.require('goog.fx.Transition');
23 goog.require('goog.fx.anim');
24 goog.require('goog.testing.MockClock');
25 goog.require('goog.testing.jsunit');
26
27 var clock;
28
29 function setUpPage() {
30 clock = new goog.testing.MockClock(true);
31 goog.fx.anim.setAnimationWindow(null);
32 }
33
34 function tearDownPage() {
35 clock.dispose();
36 }
37
38 function testParallelEvents() {
39 var anim = new goog.fx.AnimationParallelQueue();
40 anim.add(new goog.fx.Animation([0], [100], 200));
41 anim.add(new goog.fx.Animation([0], [100], 400));
42 anim.add(new goog.fx.Animation([0], [100], 600));
43
44 assertTrue(anim.queue[0].isStopped());
45 assertTrue(anim.queue[1].isStopped());
46 assertTrue(anim.queue[2].isStopped());
47 assertTrue(anim.isStopped());
48
49 var playEvents = 0, beginEvents = 0, resumeEvents = 0, pauseEvents = 0;
50 var endEvents = 0, stopEvents = 0, finishEvents = 0;
51
52 goog.events.listen(
53 anim, goog.fx.Transition.EventType.PLAY, function() { ++playEvents; });
54 goog.events.listen(
55 anim, goog.fx.Transition.EventType.BEGIN, function() { ++beginEvents; });
56 goog.events.listen(anim, goog.fx.Transition.EventType.RESUME, function() {
57 ++resumeEvents;
58 });
59 goog.events.listen(
60 anim, goog.fx.Transition.EventType.PAUSE, function() { ++pauseEvents; });
61 goog.events.listen(
62 anim, goog.fx.Transition.EventType.END, function() { ++endEvents; });
63 goog.events.listen(
64 anim, goog.fx.Transition.EventType.STOP, function() { ++stopEvents; });
65 goog.events.listen(anim, goog.fx.Transition.EventType.FINISH, function() {
66 ++finishEvents;
67 });
68
69 // PLAY, BEGIN
70 anim.play();
71 // No queue events.
72 clock.tick(100);
73 // PAUSE
74 anim.pause();
75 // No queue events
76 clock.tick(200);
77 // PLAY, RESUME
78 anim.play();
79 // No queue events.
80 clock.tick(400);
81 // END, STOP
82 anim.stop();
83 // PLAY, BEGIN
84 anim.play();
85 // No queue events.
86 clock.tick(400);
87 // END, FINISH
88 clock.tick(200);
89
90 // Make sure the event counts are right.
91 assertEquals(3, playEvents);
92 assertEquals(2, beginEvents);
93 assertEquals(1, resumeEvents);
94 assertEquals(1, pauseEvents);
95 assertEquals(2, endEvents);
96 assertEquals(1, stopEvents);
97 assertEquals(1, finishEvents);
98 }
99
100 function testSerialEvents() {
101 var anim = new goog.fx.AnimationSerialQueue();
102 anim.add(new goog.fx.Animation([0], [100], 100));
103 anim.add(new goog.fx.Animation([0], [100], 200));
104 anim.add(new goog.fx.Animation([0], [100], 300));
105
106 assertTrue(anim.queue[0].isStopped());
107 assertTrue(anim.queue[1].isStopped());
108 assertTrue(anim.queue[2].isStopped());
109 assertTrue(anim.isStopped());
110
111 var playEvents = 0, beginEvents = 0, resumeEvents = 0, pauseEvents = 0;
112 var endEvents = 0, stopEvents = 0, finishEvents = 0;
113
114 goog.events.listen(
115 anim, goog.fx.Transition.EventType.PLAY, function() { ++playEvents; });
116 goog.events.listen(
117 anim, goog.fx.Transition.EventType.BEGIN, function() { ++beginEvents; });
118 goog.events.listen(anim, goog.fx.Transition.EventType.RESUME, function() {
119 ++resumeEvents;
120 });
121 goog.events.listen(
122 anim, goog.fx.Transition.EventType.PAUSE, function() { ++pauseEvents; });
123 goog.events.listen(
124 anim, goog.fx.Transition.EventType.END, function() { ++endEvents; });
125 goog.events.listen(
126 anim, goog.fx.Transition.EventType.STOP, function() { ++stopEvents; });
127 goog.events.listen(anim, goog.fx.Transition.EventType.FINISH, function() {
128 ++finishEvents;
129 });
130
131 // PLAY, BEGIN
132 anim.play();
133 // No queue events.
134 clock.tick(100);
135 // PAUSE
136 anim.pause();
137 // No queue events
138 clock.tick(200);
139 // PLAY, RESUME
140 anim.play();
141 // No queue events.
142 clock.tick(400);
143 // END, STOP
144 anim.stop();
145 // PLAY, BEGIN
146 anim.play(true);
147 // No queue events.
148 clock.tick(400);
149 // END, FINISH
150 clock.tick(200);
151
152 // Make sure the event counts are right.
153 assertEquals(3, playEvents);
154 assertEquals(2, beginEvents);
155 assertEquals(1, resumeEvents);
156 assertEquals(1, pauseEvents);
157 assertEquals(2, endEvents);
158 assertEquals(1, stopEvents);
159 assertEquals(1, finishEvents);
160 }
161
162 function testParallelPause() {
163 var anim = new goog.fx.AnimationParallelQueue();
164 anim.add(new goog.fx.Animation([0], [100], 100));
165 anim.add(new goog.fx.Animation([0], [100], 200));
166 anim.add(new goog.fx.Animation([0], [100], 300));
167
168 assertTrue(anim.queue[0].isStopped());
169 assertTrue(anim.queue[1].isStopped());
170 assertTrue(anim.queue[2].isStopped());
171 assertTrue(anim.isStopped());
172
173 anim.play();
174
175 assertTrue(anim.queue[0].isPlaying());
176 assertTrue(anim.queue[1].isPlaying());
177 assertTrue(anim.queue[2].isPlaying());
178 assertTrue(anim.isPlaying());
179
180 clock.tick(100);
181
182 assertTrue(anim.queue[0].isStopped());
183 assertTrue(anim.queue[1].isPlaying());
184 assertTrue(anim.queue[2].isPlaying());
185 assertTrue(anim.isPlaying());
186
187 anim.pause();
188
189 assertTrue(anim.queue[0].isStopped());
190 assertTrue(anim.queue[1].isPaused());
191 assertTrue(anim.queue[2].isPaused());
192 assertTrue(anim.isPaused());
193
194 clock.tick(200);
195
196 assertTrue(anim.queue[0].isStopped());
197 assertTrue(anim.queue[1].isPaused());
198 assertTrue(anim.queue[2].isPaused());
199 assertTrue(anim.isPaused());
200
201 anim.play();
202
203 assertTrue(anim.queue[0].isStopped());
204 assertTrue(anim.queue[1].isPlaying());
205 assertTrue(anim.queue[2].isPlaying());
206 assertTrue(anim.isPlaying());
207
208 clock.tick(100);
209
210 assertTrue(anim.queue[0].isStopped());
211 assertTrue(anim.queue[1].isStopped());
212 assertTrue(anim.queue[2].isPlaying());
213 assertTrue(anim.isPlaying());
214
215 anim.pause();
216
217 assertTrue(anim.queue[0].isStopped());
218 assertTrue(anim.queue[1].isStopped());
219 assertTrue(anim.queue[2].isPaused());
220 assertTrue(anim.isPaused());
221
222 clock.tick(200);
223
224 assertTrue(anim.queue[0].isStopped());
225 assertTrue(anim.queue[1].isStopped());
226 assertTrue(anim.queue[2].isPaused());
227 assertTrue(anim.isPaused());
228
229 anim.play();
230
231 assertTrue(anim.queue[0].isStopped());
232 assertTrue(anim.queue[1].isStopped());
233 assertTrue(anim.queue[2].isPlaying());
234 assertTrue(anim.isPlaying());
235
236 clock.tick(100);
237
238 assertTrue(anim.queue[0].isStopped());
239 assertTrue(anim.queue[1].isStopped());
240 assertTrue(anim.queue[2].isStopped());
241 assertTrue(anim.isStopped());
242 }
243
244 function testSerialPause() {
245 var anim = new goog.fx.AnimationSerialQueue();
246 anim.add(new goog.fx.Animation([0], [100], 100));
247 anim.add(new goog.fx.Animation([0], [100], 200));
248 anim.add(new goog.fx.Animation([0], [100], 300));
249
250 assertTrue(anim.queue[0].isStopped());
251 assertTrue(anim.queue[1].isStopped());
252 assertTrue(anim.queue[2].isStopped());
253 assertTrue(anim.isStopped());
254
255 anim.play();
256
257 assertTrue(anim.queue[0].isPlaying());
258 assertTrue(anim.queue[1].isStopped());
259 assertTrue(anim.queue[2].isStopped());
260 assertTrue(anim.isPlaying());
261
262 clock.tick(100);
263
264 assertTrue(anim.queue[0].isStopped());
265 assertTrue(anim.queue[1].isPlaying());
266 assertTrue(anim.queue[2].isStopped());
267 assertTrue(anim.isPlaying());
268
269 anim.pause();
270
271 assertTrue(anim.queue[0].isStopped());
272 assertTrue(anim.queue[1].isPaused());
273 assertTrue(anim.queue[2].isStopped());
274 assertTrue(anim.isPaused());
275
276 clock.tick(400);
277
278 assertTrue(anim.queue[0].isStopped());
279 assertTrue(anim.queue[1].isPaused());
280 assertTrue(anim.queue[2].isStopped());
281 assertTrue(anim.isPaused());
282
283 anim.play();
284
285 assertTrue(anim.queue[0].isStopped());
286 assertTrue(anim.queue[1].isPlaying());
287 assertTrue(anim.queue[2].isStopped());
288 assertTrue(anim.isPlaying());
289
290 clock.tick(200);
291
292 assertTrue(anim.queue[0].isStopped());
293 assertTrue(anim.queue[1].isStopped());
294 assertTrue(anim.queue[2].isPlaying());
295 assertTrue(anim.isPlaying());
296
297 anim.pause();
298
299 assertTrue(anim.queue[0].isStopped());
300 assertTrue(anim.queue[1].isStopped());
301 assertTrue(anim.queue[2].isPaused());
302 assertTrue(anim.isPaused());
303
304 clock.tick(300);
305
306 assertTrue(anim.queue[0].isStopped());
307 assertTrue(anim.queue[1].isStopped());
308 assertTrue(anim.queue[2].isPaused());
309 assertTrue(anim.isPaused());
310
311 anim.play();
312
313 clock.tick(300);
314
315 assertTrue(anim.queue[0].isStopped());
316 assertTrue(anim.queue[1].isStopped());
317 assertTrue(anim.queue[2].isStopped());
318 assertTrue(anim.isStopped());
319 }