Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(794)

Side by Side Diff: cc/animation/layer_animation_controller_unittest.cc

Issue 13613003: cc: Make animations tick regardless of drawing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Drop extra statemachine function Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/animation/layer_animation_controller.cc ('k') | cc/scheduler/scheduler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/animation/layer_animation_controller.h" 5 #include "cc/animation/layer_animation_controller.h"
6 6
7 #include "cc/animation/animation.h" 7 #include "cc/animation/animation.h"
8 #include "cc/animation/animation_curve.h" 8 #include "cc/animation/animation_curve.h"
9 #include "cc/animation/keyframed_animation_curve.h" 9 #include "cc/animation/keyframed_animation_curve.h"
10 #include "cc/animation/transform_operations.h" 10 #include "cc/animation/transform_operations.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 AddOpacityTransitionToController(controller, 1, 0, 1, false); 63 AddOpacityTransitionToController(controller, 1, 0, 1, false);
64 64
65 controller->PushAnimationUpdatesTo(controller_impl.get()); 65 controller->PushAnimationUpdatesTo(controller_impl.get());
66 66
67 EXPECT_TRUE(controller_impl->GetAnimation(0, Animation::Opacity)); 67 EXPECT_TRUE(controller_impl->GetAnimation(0, Animation::Opacity));
68 EXPECT_EQ(Animation::WaitingForTargetAvailability, 68 EXPECT_EQ(Animation::WaitingForTargetAvailability,
69 controller_impl->GetAnimation(0, Animation::Opacity)->run_state()); 69 controller_impl->GetAnimation(0, Animation::Opacity)->run_state());
70 70
71 AnimationEventsVector events; 71 AnimationEventsVector events;
72 controller_impl->Animate(1.0); 72 controller_impl->Animate(1.0);
73 controller_impl->UpdateState(&events); 73 controller_impl->UpdateState(true, &events);
74 74
75 // Synchronize the start times. 75 // Synchronize the start times.
76 EXPECT_EQ(1u, events.size()); 76 EXPECT_EQ(1u, events.size());
77 controller->OnAnimationStarted(events[0]); 77 controller->OnAnimationStarted(events[0]);
78 EXPECT_EQ(controller->GetAnimation(0, Animation::Opacity)->start_time(), 78 EXPECT_EQ(controller->GetAnimation(0, Animation::Opacity)->start_time(),
79 controller_impl->GetAnimation(0, Animation::Opacity)->start_time()); 79 controller_impl->GetAnimation(0, Animation::Opacity)->start_time());
80 80
81 // Start the animation on the main thread. Should not affect the start time. 81 // Start the animation on the main thread. Should not affect the start time.
82 controller->Animate(1.5); 82 controller->Animate(1.5);
83 controller->UpdateState(NULL); 83 controller->UpdateState(true, NULL);
84 EXPECT_EQ(controller->GetAnimation(0, Animation::Opacity)->start_time(), 84 EXPECT_EQ(controller->GetAnimation(0, Animation::Opacity)->start_time(),
85 controller_impl->GetAnimation(0, Animation::Opacity)->start_time()); 85 controller_impl->GetAnimation(0, Animation::Opacity)->start_time());
86 } 86 }
87 87
88 TEST(LayerAnimationControllerTest, SyncPauseAndResume) { 88 TEST(LayerAnimationControllerTest, SyncPauseAndResume) {
89 FakeLayerAnimationValueObserver dummy_impl; 89 FakeLayerAnimationValueObserver dummy_impl;
90 scoped_refptr<LayerAnimationController> controller_impl( 90 scoped_refptr<LayerAnimationController> controller_impl(
91 LayerAnimationController::Create(0)); 91 LayerAnimationController::Create(0));
92 controller_impl->AddObserver(&dummy_impl); 92 controller_impl->AddObserver(&dummy_impl);
93 FakeLayerAnimationValueObserver dummy; 93 FakeLayerAnimationValueObserver dummy;
94 scoped_refptr<LayerAnimationController> controller( 94 scoped_refptr<LayerAnimationController> controller(
95 LayerAnimationController::Create(0)); 95 LayerAnimationController::Create(0));
96 controller->AddObserver(&dummy); 96 controller->AddObserver(&dummy);
97 97
98 EXPECT_FALSE(controller_impl->GetAnimation(0, Animation::Opacity)); 98 EXPECT_FALSE(controller_impl->GetAnimation(0, Animation::Opacity));
99 99
100 AddOpacityTransitionToController(controller, 1, 0, 1, false); 100 AddOpacityTransitionToController(controller, 1, 0, 1, false);
101 101
102 controller->PushAnimationUpdatesTo(controller_impl.get()); 102 controller->PushAnimationUpdatesTo(controller_impl.get());
103 103
104 EXPECT_TRUE(controller_impl->GetAnimation(0, Animation::Opacity)); 104 EXPECT_TRUE(controller_impl->GetAnimation(0, Animation::Opacity));
105 EXPECT_EQ(Animation::WaitingForTargetAvailability, 105 EXPECT_EQ(Animation::WaitingForTargetAvailability,
106 controller_impl->GetAnimation(0, Animation::Opacity)->run_state()); 106 controller_impl->GetAnimation(0, Animation::Opacity)->run_state());
107 107
108 // Start the animations on each controller. 108 // Start the animations on each controller.
109 AnimationEventsVector events; 109 AnimationEventsVector events;
110 controller_impl->Animate(0.0); 110 controller_impl->Animate(0.0);
111 controller_impl->UpdateState(&events); 111 controller_impl->UpdateState(true, &events);
112 controller->Animate(0.0); 112 controller->Animate(0.0);
113 controller->UpdateState(NULL); 113 controller->UpdateState(true, NULL);
114 EXPECT_EQ(Animation::Running, 114 EXPECT_EQ(Animation::Running,
115 controller_impl->GetAnimation(0, Animation::Opacity)->run_state()); 115 controller_impl->GetAnimation(0, Animation::Opacity)->run_state());
116 EXPECT_EQ(Animation::Running, 116 EXPECT_EQ(Animation::Running,
117 controller->GetAnimation(0, Animation::Opacity)->run_state()); 117 controller->GetAnimation(0, Animation::Opacity)->run_state());
118 118
119 // Pause the main-thread animation. 119 // Pause the main-thread animation.
120 controller->SuspendAnimations(1.0); 120 controller->SuspendAnimations(1.0);
121 EXPECT_EQ(Animation::Paused, 121 EXPECT_EQ(Animation::Paused,
122 controller->GetAnimation(0, Animation::Opacity)->run_state()); 122 controller->GetAnimation(0, Animation::Opacity)->run_state());
123 123
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 LayerAnimationController::Create(0)); 195 LayerAnimationController::Create(0));
196 controller->AddObserver(&dummy); 196 controller->AddObserver(&dummy);
197 197
198 scoped_ptr<Animation> to_add(CreateAnimation( 198 scoped_ptr<Animation> to_add(CreateAnimation(
199 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), 199 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
200 1, 200 1,
201 Animation::Opacity)); 201 Animation::Opacity));
202 202
203 controller->AddAnimation(to_add.Pass()); 203 controller->AddAnimation(to_add.Pass());
204 controller->Animate(0.0); 204 controller->Animate(0.0);
205 controller->UpdateState(events.get()); 205 controller->UpdateState(true, events.get());
206 EXPECT_TRUE(controller->HasActiveAnimation()); 206 EXPECT_TRUE(controller->HasActiveAnimation());
207 EXPECT_EQ(0.f, dummy.opacity()); 207 EXPECT_EQ(0.f, dummy.opacity());
208 // A non-impl-only animation should not generate property updates. 208 // A non-impl-only animation should not generate property updates.
209 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); 209 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get());
210 EXPECT_FALSE(event); 210 EXPECT_FALSE(event);
211 controller->Animate(1.0); 211 controller->Animate(1.0);
212 controller->UpdateState(events.get()); 212 controller->UpdateState(true, events.get());
213 EXPECT_EQ(1.f, dummy.opacity()); 213 EXPECT_EQ(1.f, dummy.opacity());
214 EXPECT_FALSE(controller->HasActiveAnimation()); 214 EXPECT_FALSE(controller->HasActiveAnimation());
215 event = GetMostRecentPropertyUpdateEvent(events.get()); 215 event = GetMostRecentPropertyUpdateEvent(events.get());
216 EXPECT_FALSE(event); 216 EXPECT_FALSE(event);
217 } 217 }
218 218
219 TEST(LayerAnimationControllerTest, TrivialTransitionOnImpl) { 219 TEST(LayerAnimationControllerTest, TrivialTransitionOnImpl) {
220 scoped_ptr<AnimationEventsVector> events( 220 scoped_ptr<AnimationEventsVector> events(
221 make_scoped_ptr(new AnimationEventsVector)); 221 make_scoped_ptr(new AnimationEventsVector));
222 FakeLayerAnimationValueObserver dummy_impl; 222 FakeLayerAnimationValueObserver dummy_impl;
223 scoped_refptr<LayerAnimationController> controller_impl( 223 scoped_refptr<LayerAnimationController> controller_impl(
224 LayerAnimationController::Create(0)); 224 LayerAnimationController::Create(0));
225 controller_impl->AddObserver(&dummy_impl); 225 controller_impl->AddObserver(&dummy_impl);
226 226
227 scoped_ptr<Animation> to_add(CreateAnimation( 227 scoped_ptr<Animation> to_add(CreateAnimation(
228 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), 228 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
229 1, 229 1,
230 Animation::Opacity)); 230 Animation::Opacity));
231 to_add->set_is_impl_only(true); 231 to_add->set_is_impl_only(true);
232 232
233 controller_impl->AddAnimation(to_add.Pass()); 233 controller_impl->AddAnimation(to_add.Pass());
234 controller_impl->Animate(0.0); 234 controller_impl->Animate(0.0);
235 controller_impl->UpdateState(events.get()); 235 controller_impl->UpdateState(true, events.get());
236 EXPECT_TRUE(controller_impl->HasActiveAnimation()); 236 EXPECT_TRUE(controller_impl->HasActiveAnimation());
237 EXPECT_EQ(0.f, dummy_impl.opacity()); 237 EXPECT_EQ(0.f, dummy_impl.opacity());
238 EXPECT_EQ(2u, events->size()); 238 EXPECT_EQ(2u, events->size());
239 const AnimationEvent* start_opacity_event = 239 const AnimationEvent* start_opacity_event =
240 GetMostRecentPropertyUpdateEvent(events.get()); 240 GetMostRecentPropertyUpdateEvent(events.get());
241 EXPECT_EQ(0.f, start_opacity_event->opacity); 241 EXPECT_EQ(0.f, start_opacity_event->opacity);
242 242
243 controller_impl->Animate(1.0); 243 controller_impl->Animate(1.0);
244 controller_impl->UpdateState(events.get()); 244 controller_impl->UpdateState(true, events.get());
245 EXPECT_EQ(1.f, dummy_impl.opacity()); 245 EXPECT_EQ(1.f, dummy_impl.opacity());
246 EXPECT_FALSE(controller_impl->HasActiveAnimation()); 246 EXPECT_FALSE(controller_impl->HasActiveAnimation());
247 EXPECT_EQ(4u, events->size()); 247 EXPECT_EQ(4u, events->size());
248 const AnimationEvent* end_opacity_event = 248 const AnimationEvent* end_opacity_event =
249 GetMostRecentPropertyUpdateEvent(events.get()); 249 GetMostRecentPropertyUpdateEvent(events.get());
250 EXPECT_EQ(1.f, end_opacity_event->opacity); 250 EXPECT_EQ(1.f, end_opacity_event->opacity);
251 } 251 }
252 252
253 TEST(LayerAnimationControllerTest, TrivialTransformOnImpl) { 253 TEST(LayerAnimationControllerTest, TrivialTransformOnImpl) {
254 scoped_ptr<AnimationEventsVector> events( 254 scoped_ptr<AnimationEventsVector> events(
(...skipping 19 matching lines...) Expand all
274 curve->AddKeyframe(TransformKeyframe::Create( 274 curve->AddKeyframe(TransformKeyframe::Create(
275 1, operations, scoped_ptr<cc::TimingFunction>())); 275 1, operations, scoped_ptr<cc::TimingFunction>()));
276 276
277 scoped_ptr<Animation> animation(Animation::Create( 277 scoped_ptr<Animation> animation(Animation::Create(
278 curve.PassAs<AnimationCurve>(), 1, 0, Animation::Transform)); 278 curve.PassAs<AnimationCurve>(), 1, 0, Animation::Transform));
279 animation->set_is_impl_only(true); 279 animation->set_is_impl_only(true);
280 controller_impl->AddAnimation(animation.Pass()); 280 controller_impl->AddAnimation(animation.Pass());
281 281
282 // Run animation. 282 // Run animation.
283 controller_impl->Animate(0.0); 283 controller_impl->Animate(0.0);
284 controller_impl->UpdateState(events.get()); 284 controller_impl->UpdateState(true, events.get());
285 EXPECT_TRUE(controller_impl->HasActiveAnimation()); 285 EXPECT_TRUE(controller_impl->HasActiveAnimation());
286 EXPECT_EQ(gfx::Transform(), dummy_impl.transform()); 286 EXPECT_EQ(gfx::Transform(), dummy_impl.transform());
287 EXPECT_EQ(2u, events->size()); 287 EXPECT_EQ(2u, events->size());
288 const AnimationEvent* start_transform_event = 288 const AnimationEvent* start_transform_event =
289 GetMostRecentPropertyUpdateEvent(events.get()); 289 GetMostRecentPropertyUpdateEvent(events.get());
290 ASSERT_TRUE(start_transform_event); 290 ASSERT_TRUE(start_transform_event);
291 EXPECT_EQ(gfx::Transform(), start_transform_event->transform); 291 EXPECT_EQ(gfx::Transform(), start_transform_event->transform);
292 292
293 gfx::Transform expected_transform; 293 gfx::Transform expected_transform;
294 expected_transform.Translate(delta_x, delta_y); 294 expected_transform.Translate(delta_x, delta_y);
295 295
296 controller_impl->Animate(1.0); 296 controller_impl->Animate(1.0);
297 controller_impl->UpdateState(events.get()); 297 controller_impl->UpdateState(true, events.get());
298 EXPECT_EQ(expected_transform, dummy_impl.transform()); 298 EXPECT_EQ(expected_transform, dummy_impl.transform());
299 EXPECT_FALSE(controller_impl->HasActiveAnimation()); 299 EXPECT_FALSE(controller_impl->HasActiveAnimation());
300 EXPECT_EQ(4u, events->size()); 300 EXPECT_EQ(4u, events->size());
301 const AnimationEvent* end_transform_event = 301 const AnimationEvent* end_transform_event =
302 GetMostRecentPropertyUpdateEvent(events.get()); 302 GetMostRecentPropertyUpdateEvent(events.get());
303 EXPECT_EQ(expected_transform, end_transform_event->transform); 303 EXPECT_EQ(expected_transform, end_transform_event->transform);
304 } 304 }
305 305
306 // Tests animations that are waiting for a synchronized start time do not 306 // Tests animations that are waiting for a synchronized start time do not
307 // finish. 307 // finish.
308 TEST(LayerAnimationControllerTest, 308 TEST(LayerAnimationControllerTest,
309 AnimationsWaitingForStartTimeDoNotFinishIfTheyWaitLongerToStartThanTheirDur ation) { 309 AnimationsWaitingForStartTimeDoNotFinishIfTheyWaitLongerToStartThanTheirDur ation) {
310 scoped_ptr<AnimationEventsVector> events( 310 scoped_ptr<AnimationEventsVector> events(
311 make_scoped_ptr(new AnimationEventsVector)); 311 make_scoped_ptr(new AnimationEventsVector));
312 FakeLayerAnimationValueObserver dummy; 312 FakeLayerAnimationValueObserver dummy;
313 scoped_refptr<LayerAnimationController> controller( 313 scoped_refptr<LayerAnimationController> controller(
314 LayerAnimationController::Create(0)); 314 LayerAnimationController::Create(0));
315 controller->AddObserver(&dummy); 315 controller->AddObserver(&dummy);
316 316
317 scoped_ptr<Animation> to_add(CreateAnimation( 317 scoped_ptr<Animation> to_add(CreateAnimation(
318 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), 318 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
319 1, 319 1,
320 Animation::Opacity)); 320 Animation::Opacity));
321 to_add->set_needs_synchronized_start_time(true); 321 to_add->set_needs_synchronized_start_time(true);
322 322
323 // We should pause at the first keyframe indefinitely waiting for that 323 // We should pause at the first keyframe indefinitely waiting for that
324 // animation to start. 324 // animation to start.
325 controller->AddAnimation(to_add.Pass()); 325 controller->AddAnimation(to_add.Pass());
326 controller->Animate(0.0); 326 controller->Animate(0.0);
327 controller->UpdateState(events.get()); 327 controller->UpdateState(true, events.get());
328 EXPECT_TRUE(controller->HasActiveAnimation()); 328 EXPECT_TRUE(controller->HasActiveAnimation());
329 EXPECT_EQ(0.f, dummy.opacity()); 329 EXPECT_EQ(0.f, dummy.opacity());
330 controller->Animate(1.0); 330 controller->Animate(1.0);
331 controller->UpdateState(events.get()); 331 controller->UpdateState(true, events.get());
332 EXPECT_TRUE(controller->HasActiveAnimation()); 332 EXPECT_TRUE(controller->HasActiveAnimation());
333 EXPECT_EQ(0.f, dummy.opacity()); 333 EXPECT_EQ(0.f, dummy.opacity());
334 controller->Animate(2.0); 334 controller->Animate(2.0);
335 controller->UpdateState(events.get()); 335 controller->UpdateState(true, events.get());
336 EXPECT_TRUE(controller->HasActiveAnimation()); 336 EXPECT_TRUE(controller->HasActiveAnimation());
337 EXPECT_EQ(0.f, dummy.opacity()); 337 EXPECT_EQ(0.f, dummy.opacity());
338 338
339 // Send the synchronized start time. 339 // Send the synchronized start time.
340 controller->OnAnimationStarted(AnimationEvent( 340 controller->OnAnimationStarted(AnimationEvent(
341 AnimationEvent::Started, 0, 1, Animation::Opacity, 2)); 341 AnimationEvent::Started, 0, 1, Animation::Opacity, 2));
342 controller->Animate(5.0); 342 controller->Animate(5.0);
343 controller->UpdateState(events.get()); 343 controller->UpdateState(true, events.get());
344 EXPECT_EQ(1.f, dummy.opacity()); 344 EXPECT_EQ(1.f, dummy.opacity());
345 EXPECT_FALSE(controller->HasActiveAnimation()); 345 EXPECT_FALSE(controller->HasActiveAnimation());
346 } 346 }
347 347
348 // Tests that two queued animations affecting the same property run in sequence. 348 // Tests that two queued animations affecting the same property run in sequence.
349 TEST(LayerAnimationControllerTest, TrivialQueuing) { 349 TEST(LayerAnimationControllerTest, TrivialQueuing) {
350 scoped_ptr<AnimationEventsVector> events( 350 scoped_ptr<AnimationEventsVector> events(
351 make_scoped_ptr(new AnimationEventsVector)); 351 make_scoped_ptr(new AnimationEventsVector));
352 FakeLayerAnimationValueObserver dummy; 352 FakeLayerAnimationValueObserver dummy;
353 scoped_refptr<LayerAnimationController> controller( 353 scoped_refptr<LayerAnimationController> controller(
354 LayerAnimationController::Create(0)); 354 LayerAnimationController::Create(0));
355 controller->AddObserver(&dummy); 355 controller->AddObserver(&dummy);
356 356
357 controller->AddAnimation(CreateAnimation( 357 controller->AddAnimation(CreateAnimation(
358 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), 358 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
359 1, 359 1,
360 Animation::Opacity)); 360 Animation::Opacity));
361 controller->AddAnimation(CreateAnimation( 361 controller->AddAnimation(CreateAnimation(
362 scoped_ptr<AnimationCurve>( 362 scoped_ptr<AnimationCurve>(
363 new FakeFloatTransition(1.0, 1.f, 0.5f)).Pass(), 363 new FakeFloatTransition(1.0, 1.f, 0.5f)).Pass(),
364 2, 364 2,
365 Animation::Opacity)); 365 Animation::Opacity));
366 366
367 controller->Animate(0.0); 367 controller->Animate(0.0);
368 controller->UpdateState(events.get()); 368 controller->UpdateState(true, events.get());
369 EXPECT_TRUE(controller->HasActiveAnimation()); 369 EXPECT_TRUE(controller->HasActiveAnimation());
370 EXPECT_EQ(0.f, dummy.opacity()); 370 EXPECT_EQ(0.f, dummy.opacity());
371 controller->Animate(1.0); 371 controller->Animate(1.0);
372 controller->UpdateState(events.get()); 372 controller->UpdateState(true, events.get());
373 EXPECT_TRUE(controller->HasActiveAnimation()); 373 EXPECT_TRUE(controller->HasActiveAnimation());
374 EXPECT_EQ(1.f, dummy.opacity()); 374 EXPECT_EQ(1.f, dummy.opacity());
375 controller->Animate(2.0); 375 controller->Animate(2.0);
376 controller->UpdateState(events.get()); 376 controller->UpdateState(true, events.get());
377 EXPECT_EQ(0.5f, dummy.opacity()); 377 EXPECT_EQ(0.5f, dummy.opacity());
378 EXPECT_FALSE(controller->HasActiveAnimation()); 378 EXPECT_FALSE(controller->HasActiveAnimation());
379 } 379 }
380 380
381 // Tests interrupting a transition with another transition. 381 // Tests interrupting a transition with another transition.
382 TEST(LayerAnimationControllerTest, Interrupt) { 382 TEST(LayerAnimationControllerTest, Interrupt) {
383 scoped_ptr<AnimationEventsVector> events( 383 scoped_ptr<AnimationEventsVector> events(
384 make_scoped_ptr(new AnimationEventsVector)); 384 make_scoped_ptr(new AnimationEventsVector));
385 FakeLayerAnimationValueObserver dummy; 385 FakeLayerAnimationValueObserver dummy;
386 scoped_refptr<LayerAnimationController> controller( 386 scoped_refptr<LayerAnimationController> controller(
387 LayerAnimationController::Create(0)); 387 LayerAnimationController::Create(0));
388 controller->AddObserver(&dummy); 388 controller->AddObserver(&dummy);
389 controller->AddAnimation(CreateAnimation( 389 controller->AddAnimation(CreateAnimation(
390 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), 390 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
391 1, 391 1,
392 Animation::Opacity)); 392 Animation::Opacity));
393 controller->Animate(0.0); 393 controller->Animate(0.0);
394 controller->UpdateState(events.get()); 394 controller->UpdateState(true, events.get());
395 EXPECT_TRUE(controller->HasActiveAnimation()); 395 EXPECT_TRUE(controller->HasActiveAnimation());
396 EXPECT_EQ(0.f, dummy.opacity()); 396 EXPECT_EQ(0.f, dummy.opacity());
397 397
398 scoped_ptr<Animation> to_add(CreateAnimation( 398 scoped_ptr<Animation> to_add(CreateAnimation(
399 scoped_ptr<AnimationCurve>( 399 scoped_ptr<AnimationCurve>(
400 new FakeFloatTransition(1.0, 1.f, 0.5f)).Pass(), 400 new FakeFloatTransition(1.0, 1.f, 0.5f)).Pass(),
401 2, 401 2,
402 Animation::Opacity)); 402 Animation::Opacity));
403 to_add->SetRunState(Animation::WaitingForNextTick, 0); 403 to_add->SetRunState(Animation::WaitingForNextTick, 0);
404 controller->AddAnimation(to_add.Pass()); 404 controller->AddAnimation(to_add.Pass());
405 405
406 // Since the animation was in the WaitingForNextTick state, it should start 406 // Since the animation was in the WaitingForNextTick state, it should start
407 // right in this call to animate. 407 // right in this call to animate.
408 controller->Animate(0.5); 408 controller->Animate(0.5);
409 controller->UpdateState(events.get()); 409 controller->UpdateState(true, events.get());
410 EXPECT_TRUE(controller->HasActiveAnimation()); 410 EXPECT_TRUE(controller->HasActiveAnimation());
411 EXPECT_EQ(1.f, dummy.opacity()); 411 EXPECT_EQ(1.f, dummy.opacity());
412 controller->Animate(1.5); 412 controller->Animate(1.5);
413 controller->UpdateState(events.get()); 413 controller->UpdateState(true, events.get());
414 EXPECT_EQ(0.5f, dummy.opacity()); 414 EXPECT_EQ(0.5f, dummy.opacity());
415 EXPECT_FALSE(controller->HasActiveAnimation()); 415 EXPECT_FALSE(controller->HasActiveAnimation());
416 } 416 }
417 417
418 // Tests scheduling two animations to run together when only one property is 418 // Tests scheduling two animations to run together when only one property is
419 // free. 419 // free.
420 TEST(LayerAnimationControllerTest, ScheduleTogetherWhenAPropertyIsBlocked) { 420 TEST(LayerAnimationControllerTest, ScheduleTogetherWhenAPropertyIsBlocked) {
421 scoped_ptr<AnimationEventsVector> events( 421 scoped_ptr<AnimationEventsVector> events(
422 make_scoped_ptr(new AnimationEventsVector)); 422 make_scoped_ptr(new AnimationEventsVector));
423 FakeLayerAnimationValueObserver dummy; 423 FakeLayerAnimationValueObserver dummy;
424 scoped_refptr<LayerAnimationController> controller( 424 scoped_refptr<LayerAnimationController> controller(
425 LayerAnimationController::Create(0)); 425 LayerAnimationController::Create(0));
426 controller->AddObserver(&dummy); 426 controller->AddObserver(&dummy);
427 427
428 controller->AddAnimation(CreateAnimation( 428 controller->AddAnimation(CreateAnimation(
429 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), 429 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(),
430 1, 430 1,
431 Animation::Transform)); 431 Animation::Transform));
432 controller->AddAnimation(CreateAnimation( 432 controller->AddAnimation(CreateAnimation(
433 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), 433 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(),
434 2, 434 2,
435 Animation::Transform)); 435 Animation::Transform));
436 controller->AddAnimation(CreateAnimation( 436 controller->AddAnimation(CreateAnimation(
437 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), 437 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
438 2, 438 2,
439 Animation::Opacity)); 439 Animation::Opacity));
440 440
441 controller->Animate(0.0); 441 controller->Animate(0.0);
442 controller->UpdateState(events.get()); 442 controller->UpdateState(true, events.get());
443 EXPECT_EQ(0.f, dummy.opacity()); 443 EXPECT_EQ(0.f, dummy.opacity());
444 EXPECT_TRUE(controller->HasActiveAnimation()); 444 EXPECT_TRUE(controller->HasActiveAnimation());
445 controller->Animate(1.0); 445 controller->Animate(1.0);
446 controller->UpdateState(events.get()); 446 controller->UpdateState(true, events.get());
447 // Should not have started the float transition yet. 447 // Should not have started the float transition yet.
448 EXPECT_TRUE(controller->HasActiveAnimation()); 448 EXPECT_TRUE(controller->HasActiveAnimation());
449 EXPECT_EQ(0.f, dummy.opacity()); 449 EXPECT_EQ(0.f, dummy.opacity());
450 // The float animation should have started at time 1 and should be done. 450 // The float animation should have started at time 1 and should be done.
451 controller->Animate(2.0); 451 controller->Animate(2.0);
452 controller->UpdateState(events.get()); 452 controller->UpdateState(true, events.get());
453 EXPECT_EQ(1.f, dummy.opacity()); 453 EXPECT_EQ(1.f, dummy.opacity());
454 EXPECT_FALSE(controller->HasActiveAnimation()); 454 EXPECT_FALSE(controller->HasActiveAnimation());
455 } 455 }
456 456
457 // Tests scheduling two animations to run together with different lengths and 457 // Tests scheduling two animations to run together with different lengths and
458 // another animation queued to start when the shorter animation finishes (should 458 // another animation queued to start when the shorter animation finishes (should
459 // wait for both to finish). 459 // wait for both to finish).
460 TEST(LayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting) { 460 TEST(LayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting) {
461 scoped_ptr<AnimationEventsVector> events( 461 scoped_ptr<AnimationEventsVector> events(
462 make_scoped_ptr(new AnimationEventsVector)); 462 make_scoped_ptr(new AnimationEventsVector));
(...skipping 11 matching lines...) Expand all
474 1, 474 1,
475 Animation::Opacity)); 475 Animation::Opacity));
476 controller->AddAnimation(CreateAnimation( 476 controller->AddAnimation(CreateAnimation(
477 scoped_ptr<AnimationCurve>( 477 scoped_ptr<AnimationCurve>(
478 new FakeFloatTransition(1.0, 1.f, 0.5f)).Pass(), 478 new FakeFloatTransition(1.0, 1.f, 0.5f)).Pass(),
479 2, 479 2,
480 Animation::Opacity)); 480 Animation::Opacity));
481 481
482 // Animations with id 1 should both start now. 482 // Animations with id 1 should both start now.
483 controller->Animate(0.0); 483 controller->Animate(0.0);
484 controller->UpdateState(events.get()); 484 controller->UpdateState(true, events.get());
485 EXPECT_TRUE(controller->HasActiveAnimation()); 485 EXPECT_TRUE(controller->HasActiveAnimation());
486 EXPECT_EQ(0.f, dummy.opacity()); 486 EXPECT_EQ(0.f, dummy.opacity());
487 // The opacity animation should have finished at time 1, but the group 487 // The opacity animation should have finished at time 1, but the group
488 // of animations with id 1 don't finish until time 2 because of the length 488 // of animations with id 1 don't finish until time 2 because of the length
489 // of the transform animation. 489 // of the transform animation.
490 controller->Animate(2.0); 490 controller->Animate(2.0);
491 controller->UpdateState(events.get()); 491 controller->UpdateState(true, events.get());
492 // Should not have started the float transition yet. 492 // Should not have started the float transition yet.
493 EXPECT_TRUE(controller->HasActiveAnimation()); 493 EXPECT_TRUE(controller->HasActiveAnimation());
494 EXPECT_EQ(1.f, dummy.opacity()); 494 EXPECT_EQ(1.f, dummy.opacity());
495 495
496 // The second opacity animation should start at time 2 and should be done by 496 // The second opacity animation should start at time 2 and should be done by
497 // time 3. 497 // time 3.
498 controller->Animate(3.0); 498 controller->Animate(3.0);
499 controller->UpdateState(events.get()); 499 controller->UpdateState(true, events.get());
500 EXPECT_EQ(0.5f, dummy.opacity()); 500 EXPECT_EQ(0.5f, dummy.opacity());
501 EXPECT_FALSE(controller->HasActiveAnimation()); 501 EXPECT_FALSE(controller->HasActiveAnimation());
502 } 502 }
503 503
504 // Tests scheduling an animation to start in the future. 504 // Tests scheduling an animation to start in the future.
505 TEST(LayerAnimationControllerTest, ScheduleAnimation) { 505 TEST(LayerAnimationControllerTest, ScheduleAnimation) {
506 scoped_ptr<AnimationEventsVector> events( 506 scoped_ptr<AnimationEventsVector> events(
507 make_scoped_ptr(new AnimationEventsVector)); 507 make_scoped_ptr(new AnimationEventsVector));
508 FakeLayerAnimationValueObserver dummy; 508 FakeLayerAnimationValueObserver dummy;
509 scoped_refptr<LayerAnimationController> controller( 509 scoped_refptr<LayerAnimationController> controller(
510 LayerAnimationController::Create(0)); 510 LayerAnimationController::Create(0));
511 controller->AddObserver(&dummy); 511 controller->AddObserver(&dummy);
512 512
513 scoped_ptr<Animation> to_add(CreateAnimation( 513 scoped_ptr<Animation> to_add(CreateAnimation(
514 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), 514 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
515 1, 515 1,
516 Animation::Opacity)); 516 Animation::Opacity));
517 to_add->SetRunState(Animation::WaitingForStartTime, 0); 517 to_add->SetRunState(Animation::WaitingForStartTime, 0);
518 to_add->set_start_time(1.f); 518 to_add->set_start_time(1.f);
519 controller->AddAnimation(to_add.Pass()); 519 controller->AddAnimation(to_add.Pass());
520 520
521 controller->Animate(0.0); 521 controller->Animate(0.0);
522 controller->UpdateState(events.get()); 522 controller->UpdateState(true, events.get());
523 EXPECT_TRUE(controller->HasActiveAnimation()); 523 EXPECT_TRUE(controller->HasActiveAnimation());
524 EXPECT_EQ(0.f, dummy.opacity()); 524 EXPECT_EQ(0.f, dummy.opacity());
525 controller->Animate(1.0); 525 controller->Animate(1.0);
526 controller->UpdateState(events.get()); 526 controller->UpdateState(true, events.get());
527 EXPECT_TRUE(controller->HasActiveAnimation()); 527 EXPECT_TRUE(controller->HasActiveAnimation());
528 EXPECT_EQ(0.f, dummy.opacity()); 528 EXPECT_EQ(0.f, dummy.opacity());
529 controller->Animate(2.0); 529 controller->Animate(2.0);
530 controller->UpdateState(events.get()); 530 controller->UpdateState(true, events.get());
531 EXPECT_EQ(1.f, dummy.opacity()); 531 EXPECT_EQ(1.f, dummy.opacity());
532 EXPECT_FALSE(controller->HasActiveAnimation()); 532 EXPECT_FALSE(controller->HasActiveAnimation());
533 } 533 }
534 534
535 // Tests scheduling an animation to start in the future that's interrupting a 535 // Tests scheduling an animation to start in the future that's interrupting a
536 // running animation. 536 // running animation.
537 TEST(LayerAnimationControllerTest, 537 TEST(LayerAnimationControllerTest,
538 ScheduledAnimationInterruptsRunningAnimation) { 538 ScheduledAnimationInterruptsRunningAnimation) {
539 scoped_ptr<AnimationEventsVector> events( 539 scoped_ptr<AnimationEventsVector> events(
540 make_scoped_ptr(new AnimationEventsVector)); 540 make_scoped_ptr(new AnimationEventsVector));
(...skipping 11 matching lines...) Expand all
552 scoped_ptr<AnimationCurve>( 552 scoped_ptr<AnimationCurve>(
553 new FakeFloatTransition(1.0, 0.5f, 0.f)).Pass(), 553 new FakeFloatTransition(1.0, 0.5f, 0.f)).Pass(),
554 2, 554 2,
555 Animation::Opacity)); 555 Animation::Opacity));
556 to_add->SetRunState(Animation::WaitingForStartTime, 0); 556 to_add->SetRunState(Animation::WaitingForStartTime, 0);
557 to_add->set_start_time(1.f); 557 to_add->set_start_time(1.f);
558 controller->AddAnimation(to_add.Pass()); 558 controller->AddAnimation(to_add.Pass());
559 559
560 // First 2s opacity transition should start immediately. 560 // First 2s opacity transition should start immediately.
561 controller->Animate(0.0); 561 controller->Animate(0.0);
562 controller->UpdateState(events.get()); 562 controller->UpdateState(true, events.get());
563 EXPECT_TRUE(controller->HasActiveAnimation()); 563 EXPECT_TRUE(controller->HasActiveAnimation());
564 EXPECT_EQ(0.f, dummy.opacity()); 564 EXPECT_EQ(0.f, dummy.opacity());
565 controller->Animate(0.5); 565 controller->Animate(0.5);
566 controller->UpdateState(events.get()); 566 controller->UpdateState(true, events.get());
567 EXPECT_TRUE(controller->HasActiveAnimation()); 567 EXPECT_TRUE(controller->HasActiveAnimation());
568 EXPECT_EQ(0.25f, dummy.opacity()); 568 EXPECT_EQ(0.25f, dummy.opacity());
569 controller->Animate(1.0); 569 controller->Animate(1.0);
570 controller->UpdateState(events.get()); 570 controller->UpdateState(true, events.get());
571 EXPECT_TRUE(controller->HasActiveAnimation()); 571 EXPECT_TRUE(controller->HasActiveAnimation());
572 EXPECT_EQ(0.5f, dummy.opacity()); 572 EXPECT_EQ(0.5f, dummy.opacity());
573 controller->Animate(2.0); 573 controller->Animate(2.0);
574 controller->UpdateState(events.get()); 574 controller->UpdateState(true, events.get());
575 EXPECT_EQ(0.f, dummy.opacity()); 575 EXPECT_EQ(0.f, dummy.opacity());
576 EXPECT_FALSE(controller->HasActiveAnimation()); 576 EXPECT_FALSE(controller->HasActiveAnimation());
577 } 577 }
578 578
579 // Tests scheduling an animation to start in the future that interrupts a 579 // Tests scheduling an animation to start in the future that interrupts a
580 // running animation and there is yet another animation queued to start later. 580 // running animation and there is yet another animation queued to start later.
581 TEST(LayerAnimationControllerTest, 581 TEST(LayerAnimationControllerTest,
582 ScheduledAnimationInterruptsRunningAnimationWithAnimInQueue) { 582 ScheduledAnimationInterruptsRunningAnimationWithAnimInQueue) {
583 scoped_ptr<AnimationEventsVector> events( 583 scoped_ptr<AnimationEventsVector> events(
584 make_scoped_ptr(new AnimationEventsVector)); 584 make_scoped_ptr(new AnimationEventsVector));
(...skipping 17 matching lines...) Expand all
602 controller->AddAnimation(to_add.Pass()); 602 controller->AddAnimation(to_add.Pass());
603 603
604 controller->AddAnimation(CreateAnimation( 604 controller->AddAnimation(CreateAnimation(
605 scoped_ptr<AnimationCurve>( 605 scoped_ptr<AnimationCurve>(
606 new FakeFloatTransition(1.0, 0.f, 0.75f)).Pass(), 606 new FakeFloatTransition(1.0, 0.f, 0.75f)).Pass(),
607 3, 607 3,
608 Animation::Opacity)); 608 Animation::Opacity));
609 609
610 // First 2s opacity transition should start immediately. 610 // First 2s opacity transition should start immediately.
611 controller->Animate(0.0); 611 controller->Animate(0.0);
612 controller->UpdateState(events.get()); 612 controller->UpdateState(true, events.get());
613 EXPECT_TRUE(controller->HasActiveAnimation()); 613 EXPECT_TRUE(controller->HasActiveAnimation());
614 EXPECT_EQ(0.f, dummy.opacity()); 614 EXPECT_EQ(0.f, dummy.opacity());
615 controller->Animate(0.5); 615 controller->Animate(0.5);
616 controller->UpdateState(events.get()); 616 controller->UpdateState(true, events.get());
617 EXPECT_TRUE(controller->HasActiveAnimation()); 617 EXPECT_TRUE(controller->HasActiveAnimation());
618 EXPECT_EQ(0.25f, dummy.opacity()); 618 EXPECT_EQ(0.25f, dummy.opacity());
619 EXPECT_TRUE(controller->HasActiveAnimation()); 619 EXPECT_TRUE(controller->HasActiveAnimation());
620 controller->Animate(1.0); 620 controller->Animate(1.0);
621 controller->UpdateState(events.get()); 621 controller->UpdateState(true, events.get());
622 EXPECT_TRUE(controller->HasActiveAnimation()); 622 EXPECT_TRUE(controller->HasActiveAnimation());
623 EXPECT_EQ(0.5f, dummy.opacity()); 623 EXPECT_EQ(0.5f, dummy.opacity());
624 controller->Animate(3.0); 624 controller->Animate(3.0);
625 controller->UpdateState(events.get()); 625 controller->UpdateState(true, events.get());
626 EXPECT_TRUE(controller->HasActiveAnimation()); 626 EXPECT_TRUE(controller->HasActiveAnimation());
627 EXPECT_EQ(0.f, dummy.opacity()); 627 EXPECT_EQ(0.f, dummy.opacity());
628 controller->Animate(4.0); 628 controller->Animate(4.0);
629 controller->UpdateState(events.get()); 629 controller->UpdateState(true, events.get());
630 EXPECT_EQ(0.75f, dummy.opacity()); 630 EXPECT_EQ(0.75f, dummy.opacity());
631 EXPECT_FALSE(controller->HasActiveAnimation()); 631 EXPECT_FALSE(controller->HasActiveAnimation());
632 } 632 }
633 633
634 // Test that a looping animation loops and for the correct number of iterations. 634 // Test that a looping animation loops and for the correct number of iterations.
635 TEST(LayerAnimationControllerTest, TrivialLooping) { 635 TEST(LayerAnimationControllerTest, TrivialLooping) {
636 scoped_ptr<AnimationEventsVector> events( 636 scoped_ptr<AnimationEventsVector> events(
637 make_scoped_ptr(new AnimationEventsVector)); 637 make_scoped_ptr(new AnimationEventsVector));
638 FakeLayerAnimationValueObserver dummy; 638 FakeLayerAnimationValueObserver dummy;
639 scoped_refptr<LayerAnimationController> controller( 639 scoped_refptr<LayerAnimationController> controller(
640 LayerAnimationController::Create(0)); 640 LayerAnimationController::Create(0));
641 controller->AddObserver(&dummy); 641 controller->AddObserver(&dummy);
642 642
643 scoped_ptr<Animation> to_add(CreateAnimation( 643 scoped_ptr<Animation> to_add(CreateAnimation(
644 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), 644 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
645 1, 645 1,
646 Animation::Opacity)); 646 Animation::Opacity));
647 to_add->set_iterations(3); 647 to_add->set_iterations(3);
648 controller->AddAnimation(to_add.Pass()); 648 controller->AddAnimation(to_add.Pass());
649 649
650 controller->Animate(0.0); 650 controller->Animate(0.0);
651 controller->UpdateState(events.get()); 651 controller->UpdateState(true, events.get());
652 EXPECT_TRUE(controller->HasActiveAnimation()); 652 EXPECT_TRUE(controller->HasActiveAnimation());
653 EXPECT_EQ(0.f, dummy.opacity()); 653 EXPECT_EQ(0.f, dummy.opacity());
654 controller->Animate(1.25); 654 controller->Animate(1.25);
655 controller->UpdateState(events.get()); 655 controller->UpdateState(true, events.get());
656 EXPECT_TRUE(controller->HasActiveAnimation()); 656 EXPECT_TRUE(controller->HasActiveAnimation());
657 EXPECT_EQ(0.25f, dummy.opacity()); 657 EXPECT_EQ(0.25f, dummy.opacity());
658 controller->Animate(1.75); 658 controller->Animate(1.75);
659 controller->UpdateState(events.get()); 659 controller->UpdateState(true, events.get());
660 EXPECT_TRUE(controller->HasActiveAnimation()); 660 EXPECT_TRUE(controller->HasActiveAnimation());
661 EXPECT_EQ(0.75f, dummy.opacity()); 661 EXPECT_EQ(0.75f, dummy.opacity());
662 controller->Animate(2.25); 662 controller->Animate(2.25);
663 controller->UpdateState(events.get()); 663 controller->UpdateState(true, events.get());
664 EXPECT_TRUE(controller->HasActiveAnimation()); 664 EXPECT_TRUE(controller->HasActiveAnimation());
665 EXPECT_EQ(0.25f, dummy.opacity()); 665 EXPECT_EQ(0.25f, dummy.opacity());
666 controller->Animate(2.75); 666 controller->Animate(2.75);
667 controller->UpdateState(events.get()); 667 controller->UpdateState(true, events.get());
668 EXPECT_TRUE(controller->HasActiveAnimation()); 668 EXPECT_TRUE(controller->HasActiveAnimation());
669 EXPECT_EQ(0.75f, dummy.opacity()); 669 EXPECT_EQ(0.75f, dummy.opacity());
670 controller->Animate(3.0); 670 controller->Animate(3.0);
671 controller->UpdateState(events.get()); 671 controller->UpdateState(true, events.get());
672 EXPECT_FALSE(controller->HasActiveAnimation()); 672 EXPECT_FALSE(controller->HasActiveAnimation());
673 EXPECT_EQ(1.f, dummy.opacity()); 673 EXPECT_EQ(1.f, dummy.opacity());
674 674
675 // Just be extra sure. 675 // Just be extra sure.
676 controller->Animate(4.0); 676 controller->Animate(4.0);
677 controller->UpdateState(events.get()); 677 controller->UpdateState(true, events.get());
678 EXPECT_EQ(1.f, dummy.opacity()); 678 EXPECT_EQ(1.f, dummy.opacity());
679 } 679 }
680 680
681 // Test that an infinitely looping animation does indeed go until aborted. 681 // Test that an infinitely looping animation does indeed go until aborted.
682 TEST(LayerAnimationControllerTest, InfiniteLooping) { 682 TEST(LayerAnimationControllerTest, InfiniteLooping) {
683 scoped_ptr<AnimationEventsVector> events( 683 scoped_ptr<AnimationEventsVector> events(
684 make_scoped_ptr(new AnimationEventsVector)); 684 make_scoped_ptr(new AnimationEventsVector));
685 FakeLayerAnimationValueObserver dummy; 685 FakeLayerAnimationValueObserver dummy;
686 scoped_refptr<LayerAnimationController> controller( 686 scoped_refptr<LayerAnimationController> controller(
687 LayerAnimationController::Create(0)); 687 LayerAnimationController::Create(0));
688 controller->AddObserver(&dummy); 688 controller->AddObserver(&dummy);
689 689
690 const int id = 1; 690 const int id = 1;
691 scoped_ptr<Animation> to_add(CreateAnimation( 691 scoped_ptr<Animation> to_add(CreateAnimation(
692 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), 692 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
693 id, 693 id,
694 Animation::Opacity)); 694 Animation::Opacity));
695 to_add->set_iterations(-1); 695 to_add->set_iterations(-1);
696 controller->AddAnimation(to_add.Pass()); 696 controller->AddAnimation(to_add.Pass());
697 697
698 controller->Animate(0.0); 698 controller->Animate(0.0);
699 controller->UpdateState(events.get()); 699 controller->UpdateState(true, events.get());
700 EXPECT_TRUE(controller->HasActiveAnimation()); 700 EXPECT_TRUE(controller->HasActiveAnimation());
701 EXPECT_EQ(0.f, dummy.opacity()); 701 EXPECT_EQ(0.f, dummy.opacity());
702 controller->Animate(1.25); 702 controller->Animate(1.25);
703 controller->UpdateState(events.get()); 703 controller->UpdateState(true, events.get());
704 EXPECT_TRUE(controller->HasActiveAnimation()); 704 EXPECT_TRUE(controller->HasActiveAnimation());
705 EXPECT_EQ(0.25f, dummy.opacity()); 705 EXPECT_EQ(0.25f, dummy.opacity());
706 controller->Animate(1.75); 706 controller->Animate(1.75);
707 controller->UpdateState(events.get()); 707 controller->UpdateState(true, events.get());
708 EXPECT_TRUE(controller->HasActiveAnimation()); 708 EXPECT_TRUE(controller->HasActiveAnimation());
709 EXPECT_EQ(0.75f, dummy.opacity()); 709 EXPECT_EQ(0.75f, dummy.opacity());
710 710
711 controller->Animate(1073741824.25); 711 controller->Animate(1073741824.25);
712 controller->UpdateState(events.get()); 712 controller->UpdateState(true, events.get());
713 EXPECT_TRUE(controller->HasActiveAnimation()); 713 EXPECT_TRUE(controller->HasActiveAnimation());
714 EXPECT_EQ(0.25f, dummy.opacity()); 714 EXPECT_EQ(0.25f, dummy.opacity());
715 controller->Animate(1073741824.75); 715 controller->Animate(1073741824.75);
716 controller->UpdateState(events.get()); 716 controller->UpdateState(true, events.get());
717 EXPECT_TRUE(controller->HasActiveAnimation()); 717 EXPECT_TRUE(controller->HasActiveAnimation());
718 EXPECT_EQ(0.75f, dummy.opacity()); 718 EXPECT_EQ(0.75f, dummy.opacity());
719 719
720 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity)); 720 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity));
721 controller->GetAnimation(id, Animation::Opacity)->SetRunState( 721 controller->GetAnimation(id, Animation::Opacity)->SetRunState(
722 Animation::Aborted, 0.75); 722 Animation::Aborted, 0.75);
723 EXPECT_FALSE(controller->HasActiveAnimation()); 723 EXPECT_FALSE(controller->HasActiveAnimation());
724 EXPECT_EQ(0.75f, dummy.opacity()); 724 EXPECT_EQ(0.75f, dummy.opacity());
725 } 725 }
726 726
727 // Test that pausing and resuming work as expected. 727 // Test that pausing and resuming work as expected.
728 TEST(LayerAnimationControllerTest, PauseResume) { 728 TEST(LayerAnimationControllerTest, PauseResume) {
729 scoped_ptr<AnimationEventsVector> events( 729 scoped_ptr<AnimationEventsVector> events(
730 make_scoped_ptr(new AnimationEventsVector)); 730 make_scoped_ptr(new AnimationEventsVector));
731 FakeLayerAnimationValueObserver dummy; 731 FakeLayerAnimationValueObserver dummy;
732 scoped_refptr<LayerAnimationController> controller( 732 scoped_refptr<LayerAnimationController> controller(
733 LayerAnimationController::Create(0)); 733 LayerAnimationController::Create(0));
734 controller->AddObserver(&dummy); 734 controller->AddObserver(&dummy);
735 735
736 const int id = 1; 736 const int id = 1;
737 controller->AddAnimation(CreateAnimation( 737 controller->AddAnimation(CreateAnimation(
738 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), 738 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
739 id, 739 id,
740 Animation::Opacity)); 740 Animation::Opacity));
741 741
742 controller->Animate(0.0); 742 controller->Animate(0.0);
743 controller->UpdateState(events.get()); 743 controller->UpdateState(true, events.get());
744 EXPECT_TRUE(controller->HasActiveAnimation()); 744 EXPECT_TRUE(controller->HasActiveAnimation());
745 EXPECT_EQ(0.f, dummy.opacity()); 745 EXPECT_EQ(0.f, dummy.opacity());
746 controller->Animate(0.5); 746 controller->Animate(0.5);
747 controller->UpdateState(events.get()); 747 controller->UpdateState(true, events.get());
748 EXPECT_TRUE(controller->HasActiveAnimation()); 748 EXPECT_TRUE(controller->HasActiveAnimation());
749 EXPECT_EQ(0.5f, dummy.opacity()); 749 EXPECT_EQ(0.5f, dummy.opacity());
750 750
751 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity)); 751 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity));
752 controller->GetAnimation(id, Animation::Opacity)->SetRunState( 752 controller->GetAnimation(id, Animation::Opacity)->SetRunState(
753 Animation::Paused, 0.5); 753 Animation::Paused, 0.5);
754 754
755 controller->Animate(1024); 755 controller->Animate(1024);
756 controller->UpdateState(events.get()); 756 controller->UpdateState(true, events.get());
757 EXPECT_TRUE(controller->HasActiveAnimation()); 757 EXPECT_TRUE(controller->HasActiveAnimation());
758 EXPECT_EQ(0.5f, dummy.opacity()); 758 EXPECT_EQ(0.5f, dummy.opacity());
759 759
760 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity)); 760 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity));
761 controller->GetAnimation(id, Animation::Opacity)->SetRunState( 761 controller->GetAnimation(id, Animation::Opacity)->SetRunState(
762 Animation::Running, 1024); 762 Animation::Running, 1024);
763 763
764 controller->Animate(1024.25); 764 controller->Animate(1024.25);
765 controller->UpdateState(events.get()); 765 controller->UpdateState(true, events.get());
766 EXPECT_TRUE(controller->HasActiveAnimation()); 766 EXPECT_TRUE(controller->HasActiveAnimation());
767 EXPECT_EQ(0.75f, dummy.opacity()); 767 EXPECT_EQ(0.75f, dummy.opacity());
768 controller->Animate(1024.5); 768 controller->Animate(1024.5);
769 controller->UpdateState(events.get()); 769 controller->UpdateState(true, events.get());
770 EXPECT_FALSE(controller->HasActiveAnimation()); 770 EXPECT_FALSE(controller->HasActiveAnimation());
771 EXPECT_EQ(1.f, dummy.opacity()); 771 EXPECT_EQ(1.f, dummy.opacity());
772 } 772 }
773 773
774 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) { 774 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) {
775 scoped_ptr<AnimationEventsVector> events( 775 scoped_ptr<AnimationEventsVector> events(
776 make_scoped_ptr(new AnimationEventsVector)); 776 make_scoped_ptr(new AnimationEventsVector));
777 FakeLayerAnimationValueObserver dummy; 777 FakeLayerAnimationValueObserver dummy;
778 scoped_refptr<LayerAnimationController> controller( 778 scoped_refptr<LayerAnimationController> controller(
779 LayerAnimationController::Create(0)); 779 LayerAnimationController::Create(0));
780 controller->AddObserver(&dummy); 780 controller->AddObserver(&dummy);
781 781
782 const int id = 1; 782 const int id = 1;
783 controller->AddAnimation(CreateAnimation( 783 controller->AddAnimation(CreateAnimation(
784 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), 784 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(),
785 id, 785 id,
786 Animation::Transform)); 786 Animation::Transform));
787 controller->AddAnimation(CreateAnimation( 787 controller->AddAnimation(CreateAnimation(
788 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(), 788 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(),
789 id, 789 id,
790 Animation::Opacity)); 790 Animation::Opacity));
791 controller->AddAnimation(CreateAnimation( 791 controller->AddAnimation(CreateAnimation(
792 scoped_ptr<AnimationCurve>( 792 scoped_ptr<AnimationCurve>(
793 new FakeFloatTransition(1.0, 1.f, 0.75f)).Pass(), 793 new FakeFloatTransition(1.0, 1.f, 0.75f)).Pass(),
794 2, 794 2,
795 Animation::Opacity)); 795 Animation::Opacity));
796 796
797 controller->Animate(0.0); 797 controller->Animate(0.0);
798 controller->UpdateState(events.get()); 798 controller->UpdateState(true, events.get());
799 EXPECT_TRUE(controller->HasActiveAnimation()); 799 EXPECT_TRUE(controller->HasActiveAnimation());
800 EXPECT_EQ(0.f, dummy.opacity()); 800 EXPECT_EQ(0.f, dummy.opacity());
801 controller->Animate(1.0); 801 controller->Animate(1.0);
802 controller->UpdateState(events.get()); 802 controller->UpdateState(true, events.get());
803 EXPECT_TRUE(controller->HasActiveAnimation()); 803 EXPECT_TRUE(controller->HasActiveAnimation());
804 EXPECT_EQ(0.5f, dummy.opacity()); 804 EXPECT_EQ(0.5f, dummy.opacity());
805 805
806 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity)); 806 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity));
807 controller->GetAnimation(id, Animation::Opacity)->SetRunState( 807 controller->GetAnimation(id, Animation::Opacity)->SetRunState(
808 Animation::Aborted, 1); 808 Animation::Aborted, 1);
809 controller->Animate(1.0); 809 controller->Animate(1.0);
810 controller->UpdateState(events.get()); 810 controller->UpdateState(true, events.get());
811 EXPECT_TRUE(controller->HasActiveAnimation()); 811 EXPECT_TRUE(controller->HasActiveAnimation());
812 EXPECT_EQ(1.f, dummy.opacity()); 812 EXPECT_EQ(1.f, dummy.opacity());
813 controller->Animate(2.0); 813 controller->Animate(2.0);
814 controller->UpdateState(events.get()); 814 controller->UpdateState(true, events.get());
815 EXPECT_TRUE(!controller->HasActiveAnimation()); 815 EXPECT_TRUE(!controller->HasActiveAnimation());
816 EXPECT_EQ(0.75f, dummy.opacity()); 816 EXPECT_EQ(0.75f, dummy.opacity());
817 } 817 }
818 818
819 TEST(LayerAnimationControllerTest, ForceSyncWhenSynchronizedStartTimeNeeded) { 819 TEST(LayerAnimationControllerTest, ForceSyncWhenSynchronizedStartTimeNeeded) {
820 FakeLayerAnimationValueObserver dummy_impl; 820 FakeLayerAnimationValueObserver dummy_impl;
821 scoped_refptr<LayerAnimationController> controller_impl( 821 scoped_refptr<LayerAnimationController> controller_impl(
822 LayerAnimationController::Create(0)); 822 LayerAnimationController::Create(0));
823 controller_impl->AddObserver(&dummy_impl); 823 controller_impl->AddObserver(&dummy_impl);
824 scoped_ptr<AnimationEventsVector> events( 824 scoped_ptr<AnimationEventsVector> events(
825 make_scoped_ptr(new AnimationEventsVector)); 825 make_scoped_ptr(new AnimationEventsVector));
826 FakeLayerAnimationValueObserver dummy; 826 FakeLayerAnimationValueObserver dummy;
827 scoped_refptr<LayerAnimationController> controller( 827 scoped_refptr<LayerAnimationController> controller(
828 LayerAnimationController::Create(0)); 828 LayerAnimationController::Create(0));
829 controller->AddObserver(&dummy); 829 controller->AddObserver(&dummy);
830 830
831 scoped_ptr<Animation> to_add(CreateAnimation( 831 scoped_ptr<Animation> to_add(CreateAnimation(
832 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(), 832 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(),
833 0, 833 0,
834 Animation::Opacity)); 834 Animation::Opacity));
835 to_add->set_needs_synchronized_start_time(true); 835 to_add->set_needs_synchronized_start_time(true);
836 controller->AddAnimation(to_add.Pass()); 836 controller->AddAnimation(to_add.Pass());
837 837
838 controller->Animate(0.0); 838 controller->Animate(0.0);
839 controller->UpdateState(events.get()); 839 controller->UpdateState(true, events.get());
840 EXPECT_TRUE(controller->HasActiveAnimation()); 840 EXPECT_TRUE(controller->HasActiveAnimation());
841 Animation* active_animation = controller->GetAnimation(0, Animation::Opacity); 841 Animation* active_animation = controller->GetAnimation(0, Animation::Opacity);
842 EXPECT_TRUE(active_animation); 842 EXPECT_TRUE(active_animation);
843 EXPECT_TRUE(active_animation->needs_synchronized_start_time()); 843 EXPECT_TRUE(active_animation->needs_synchronized_start_time());
844 844
845 controller->set_force_sync(); 845 controller->set_force_sync();
846 846
847 controller->PushAnimationUpdatesTo(controller_impl.get()); 847 controller->PushAnimationUpdatesTo(controller_impl.get());
848 848
849 active_animation = controller_impl->GetAnimation(0, Animation::Opacity); 849 active_animation = controller_impl->GetAnimation(0, Animation::Opacity);
(...skipping 10 matching lines...) Expand all
860 scoped_refptr<LayerAnimationController> controller( 860 scoped_refptr<LayerAnimationController> controller(
861 LayerAnimationController::Create(0)); 861 LayerAnimationController::Create(0));
862 controller->AddObserver(&dummy); 862 controller->AddObserver(&dummy);
863 863
864 controller->AddAnimation(CreateAnimation( 864 controller->AddAnimation(CreateAnimation(
865 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), 865 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(),
866 1, 866 1,
867 Animation::Transform)); 867 Animation::Transform));
868 868
869 controller->Animate(0.0); 869 controller->Animate(0.0);
870 controller->UpdateState(events.get()); 870 controller->UpdateState(true, events.get());
871 871
872 controller->AddAnimation(CreateAnimation( 872 controller->AddAnimation(CreateAnimation(
873 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), 873 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
874 2, 874 2,
875 Animation::Opacity)); 875 Animation::Opacity));
876 876
877 // Animate but don't UpdateState. 877 // Animate but don't UpdateState.
878 controller->Animate(1.0); 878 controller->Animate(1.0);
879 879
880 controller->Animate(2.0); 880 controller->Animate(2.0);
881 events.reset(new AnimationEventsVector); 881 events.reset(new AnimationEventsVector);
882 controller->UpdateState(events.get()); 882 controller->UpdateState(true, events.get());
883 883
884 // Should have one Started event and one Finished event. 884 // Should have one Started event and one Finished event.
885 EXPECT_EQ(2u, events->size()); 885 EXPECT_EQ(2u, events->size());
886 EXPECT_NE((*events)[0].type, (*events)[1].type); 886 EXPECT_NE((*events)[0].type, (*events)[1].type);
887 887
888 // The float transition should still be at its starting point. 888 // The float transition should still be at its starting point.
889 EXPECT_TRUE(controller->HasActiveAnimation()); 889 EXPECT_TRUE(controller->HasActiveAnimation());
890 EXPECT_EQ(0.f, dummy.opacity()); 890 EXPECT_EQ(0.f, dummy.opacity());
891 891
892 controller->Animate(3.0); 892 controller->Animate(3.0);
893 controller->UpdateState(events.get()); 893 controller->UpdateState(true, events.get());
894 894
895 // The float tranisition should now be done. 895 // The float tranisition should now be done.
896 EXPECT_EQ(1.f, dummy.opacity()); 896 EXPECT_EQ(1.f, dummy.opacity());
897 EXPECT_FALSE(controller->HasActiveAnimation()); 897 EXPECT_FALSE(controller->HasActiveAnimation());
898 } 898 }
899 899
900 } // namespace 900 } // namespace
901 } // namespace cc 901 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/layer_animation_controller.cc ('k') | cc/scheduler/scheduler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698