Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / cc / animation / layer_animation_controller_unittest.cc
bloba6a5363a6a8ec0d4f26712eeb119f5eb78f79a5b
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
3 // found in the LICENSE file.
5 #include "cc/animation/layer_animation_controller.h"
7 #include "cc/animation/animation.h"
8 #include "cc/animation/animation_curve.h"
9 #include "cc/animation/animation_delegate.h"
10 #include "cc/animation/animation_registrar.h"
11 #include "cc/animation/keyframed_animation_curve.h"
12 #include "cc/animation/scroll_offset_animation_curve.h"
13 #include "cc/animation/transform_operations.h"
14 #include "cc/test/animation_test_common.h"
15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "ui/gfx/box_f.h"
18 #include "ui/gfx/transform.h"
20 namespace cc {
21 namespace {
23 // A LayerAnimationController cannot be ticked at 0.0, since an animation
24 // with start time 0.0 is treated as an animation whose start time has
25 // not yet been set.
26 const double kInitialTickTime = 1.0;
28 scoped_ptr<Animation> CreateAnimation(scoped_ptr<AnimationCurve> curve,
29 int id,
30 Animation::TargetProperty property) {
31 return Animation::Create(curve.Pass(), 0, id, property);
34 TEST(LayerAnimationControllerTest, SyncNewAnimation) {
35 FakeLayerAnimationValueObserver dummy_impl;
36 scoped_refptr<LayerAnimationController> controller_impl(
37 LayerAnimationController::Create(0));
38 controller_impl->AddValueObserver(&dummy_impl);
39 FakeLayerAnimationValueObserver dummy;
40 scoped_refptr<LayerAnimationController> controller(
41 LayerAnimationController::Create(0));
42 controller->AddValueObserver(&dummy);
44 EXPECT_FALSE(controller_impl->GetAnimation(Animation::Opacity));
46 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false);
47 int group_id = controller->GetAnimation(Animation::Opacity)->group();
49 controller->PushAnimationUpdatesTo(controller_impl.get());
50 controller_impl->ActivateAnimations();
52 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity));
53 EXPECT_EQ(Animation::WaitingForTargetAvailability,
54 controller_impl->GetAnimation(group_id,
55 Animation::Opacity)->run_state());
58 // If an animation is started on the impl thread before it is ticked on the main
59 // thread, we must be sure to respect the synchronized start time.
60 TEST(LayerAnimationControllerTest, DoNotClobberStartTimes) {
61 FakeLayerAnimationValueObserver dummy_impl;
62 scoped_refptr<LayerAnimationController> controller_impl(
63 LayerAnimationController::Create(0));
64 controller_impl->AddValueObserver(&dummy_impl);
65 FakeLayerAnimationValueObserver dummy;
66 scoped_refptr<LayerAnimationController> controller(
67 LayerAnimationController::Create(0));
68 controller->AddValueObserver(&dummy);
70 EXPECT_FALSE(controller_impl->GetAnimation(Animation::Opacity));
72 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false);
73 int group_id = controller->GetAnimation(Animation::Opacity)->group();
75 controller->PushAnimationUpdatesTo(controller_impl.get());
76 controller_impl->ActivateAnimations();
78 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity));
79 EXPECT_EQ(Animation::WaitingForTargetAvailability,
80 controller_impl->GetAnimation(group_id,
81 Animation::Opacity)->run_state());
83 AnimationEventsVector events;
84 controller_impl->Animate(kInitialTickTime);
85 controller_impl->UpdateState(true, &events);
87 // Synchronize the start times.
88 EXPECT_EQ(1u, events.size());
89 controller->NotifyAnimationStarted(events[0]);
90 EXPECT_EQ(controller->GetAnimation(group_id,
91 Animation::Opacity)->start_time(),
92 controller_impl->GetAnimation(group_id,
93 Animation::Opacity)->start_time());
95 // Start the animation on the main thread. Should not affect the start time.
96 controller->Animate(kInitialTickTime + 0.5);
97 controller->UpdateState(true, NULL);
98 EXPECT_EQ(controller->GetAnimation(group_id,
99 Animation::Opacity)->start_time(),
100 controller_impl->GetAnimation(group_id,
101 Animation::Opacity)->start_time());
104 TEST(LayerAnimationControllerTest, UseSpecifiedStartTimes) {
105 FakeLayerAnimationValueObserver dummy_impl;
106 scoped_refptr<LayerAnimationController> controller_impl(
107 LayerAnimationController::Create(0));
108 controller_impl->AddValueObserver(&dummy_impl);
109 FakeLayerAnimationValueObserver dummy;
110 scoped_refptr<LayerAnimationController> controller(
111 LayerAnimationController::Create(0));
112 controller->AddValueObserver(&dummy);
114 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false);
115 int group_id = controller->GetAnimation(Animation::Opacity)->group();
117 const double start_time = 123;
118 controller->GetAnimation(Animation::Opacity)->set_start_time(start_time);
120 controller->PushAnimationUpdatesTo(controller_impl.get());
121 controller_impl->ActivateAnimations();
123 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity));
124 EXPECT_EQ(Animation::WaitingForTargetAvailability,
125 controller_impl->GetAnimation(group_id,
126 Animation::Opacity)->run_state());
128 AnimationEventsVector events;
129 controller_impl->Animate(kInitialTickTime);
130 controller_impl->UpdateState(true, &events);
132 // Synchronize the start times.
133 EXPECT_EQ(1u, events.size());
134 controller->NotifyAnimationStarted(events[0]);
136 EXPECT_EQ(start_time,
137 controller->GetAnimation(group_id,
138 Animation::Opacity)->start_time());
139 EXPECT_EQ(controller->GetAnimation(group_id,
140 Animation::Opacity)->start_time(),
141 controller_impl->GetAnimation(group_id,
142 Animation::Opacity)->start_time());
144 // Start the animation on the main thread. Should not affect the start time.
145 controller->Animate(kInitialTickTime + 0.5);
146 controller->UpdateState(true, NULL);
147 EXPECT_EQ(start_time,
148 controller->GetAnimation(group_id,
149 Animation::Opacity)->start_time());
150 EXPECT_EQ(controller->GetAnimation(group_id,
151 Animation::Opacity)->start_time(),
152 controller_impl->GetAnimation(group_id,
153 Animation::Opacity)->start_time());
156 // Tests that controllers activate and deactivate as expected.
157 TEST(LayerAnimationControllerTest, Activation) {
158 scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::Create();
159 scoped_ptr<AnimationRegistrar> registrar_impl = AnimationRegistrar::Create();
161 FakeLayerAnimationValueObserver dummy_impl;
162 scoped_refptr<LayerAnimationController> controller_impl(
163 LayerAnimationController::Create(0));
164 controller_impl->AddValueObserver(&dummy_impl);
165 FakeLayerAnimationValueObserver dummy;
166 scoped_refptr<LayerAnimationController> controller(
167 LayerAnimationController::Create(0));
168 controller->AddValueObserver(&dummy);
169 scoped_ptr<AnimationEventsVector> events(
170 make_scoped_ptr(new AnimationEventsVector));
172 controller->SetAnimationRegistrar(registrar.get());
173 controller_impl->SetAnimationRegistrar(registrar_impl.get());
174 EXPECT_EQ(1u, registrar->all_animation_controllers().size());
175 EXPECT_EQ(1u, registrar_impl->all_animation_controllers().size());
177 // Initially, both controllers should be inactive.
178 EXPECT_EQ(0u, registrar->active_animation_controllers().size());
179 EXPECT_EQ(0u, registrar_impl->active_animation_controllers().size());
181 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false);
182 // The main thread controller should now be active.
183 EXPECT_EQ(1u, registrar->active_animation_controllers().size());
185 controller->PushAnimationUpdatesTo(controller_impl.get());
186 controller_impl->ActivateAnimations();
187 // Both controllers should now be active.
188 EXPECT_EQ(1u, registrar->active_animation_controllers().size());
189 EXPECT_EQ(1u, registrar_impl->active_animation_controllers().size());
191 controller_impl->Animate(kInitialTickTime);
192 controller_impl->UpdateState(true, events.get());
193 EXPECT_EQ(1u, events->size());
194 controller->NotifyAnimationStarted((*events)[0]);
196 EXPECT_EQ(1u, registrar->active_animation_controllers().size());
197 EXPECT_EQ(1u, registrar_impl->active_animation_controllers().size());
199 controller->Animate(kInitialTickTime + 0.5);
200 controller->UpdateState(true, NULL);
201 EXPECT_EQ(1u, registrar->active_animation_controllers().size());
203 controller->Animate(kInitialTickTime + 1.0);
204 controller->UpdateState(true, NULL);
205 EXPECT_EQ(Animation::Finished,
206 controller->GetAnimation(Animation::Opacity)->run_state());
207 EXPECT_EQ(1u, registrar->active_animation_controllers().size());
209 events.reset(new AnimationEventsVector);
210 controller_impl->Animate(kInitialTickTime + 1.5);
211 controller_impl->UpdateState(true, events.get());
213 EXPECT_EQ(Animation::WaitingForDeletion,
214 controller_impl->GetAnimation(Animation::Opacity)->run_state());
215 // The impl thread controller should have de-activated.
216 EXPECT_EQ(0u, registrar_impl->active_animation_controllers().size());
218 EXPECT_EQ(1u, events->size());
219 controller->NotifyAnimationFinished((*events)[0]);
220 controller->Animate(kInitialTickTime + 1.5);
221 controller->UpdateState(true, NULL);
223 EXPECT_EQ(Animation::WaitingForDeletion,
224 controller->GetAnimation(Animation::Opacity)->run_state());
225 // The main thread controller should have de-activated.
226 EXPECT_EQ(0u, registrar->active_animation_controllers().size());
228 controller->PushAnimationUpdatesTo(controller_impl.get());
229 controller_impl->ActivateAnimations();
230 EXPECT_FALSE(controller->has_any_animation());
231 EXPECT_FALSE(controller_impl->has_any_animation());
232 EXPECT_EQ(0u, registrar->active_animation_controllers().size());
233 EXPECT_EQ(0u, registrar_impl->active_animation_controllers().size());
235 controller->SetAnimationRegistrar(NULL);
236 controller_impl->SetAnimationRegistrar(NULL);
239 TEST(LayerAnimationControllerTest, SyncPause) {
240 FakeLayerAnimationValueObserver dummy_impl;
241 scoped_refptr<LayerAnimationController> controller_impl(
242 LayerAnimationController::Create(0));
243 controller_impl->AddValueObserver(&dummy_impl);
244 FakeLayerAnimationValueObserver dummy;
245 scoped_refptr<LayerAnimationController> controller(
246 LayerAnimationController::Create(0));
247 controller->AddValueObserver(&dummy);
249 EXPECT_FALSE(controller_impl->GetAnimation(Animation::Opacity));
251 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false);
252 int group_id = controller->GetAnimation(Animation::Opacity)->group();
253 int animation_id = controller->GetAnimation(Animation::Opacity)->id();
255 controller->PushAnimationUpdatesTo(controller_impl.get());
256 controller_impl->ActivateAnimations();
258 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity));
259 EXPECT_EQ(Animation::WaitingForTargetAvailability,
260 controller_impl->GetAnimation(group_id,
261 Animation::Opacity)->run_state());
263 // Start the animations on each controller.
264 AnimationEventsVector events;
265 controller_impl->Animate(kInitialTickTime);
266 controller_impl->UpdateState(true, &events);
267 controller->Animate(kInitialTickTime);
268 controller->UpdateState(true, NULL);
269 EXPECT_EQ(Animation::Running,
270 controller_impl->GetAnimation(group_id,
271 Animation::Opacity)->run_state());
272 EXPECT_EQ(Animation::Running,
273 controller->GetAnimation(group_id,
274 Animation::Opacity)->run_state());
276 // Pause the main-thread animation.
277 controller->PauseAnimation(animation_id, kInitialTickTime + 1.0);
278 EXPECT_EQ(Animation::Paused,
279 controller->GetAnimation(group_id,
280 Animation::Opacity)->run_state());
282 // The pause run state change should make it to the impl thread controller.
283 controller->PushAnimationUpdatesTo(controller_impl.get());
284 controller_impl->ActivateAnimations();
285 EXPECT_EQ(Animation::Paused,
286 controller_impl->GetAnimation(group_id,
287 Animation::Opacity)->run_state());
290 TEST(LayerAnimationControllerTest, DoNotSyncFinishedAnimation) {
291 FakeLayerAnimationValueObserver dummy_impl;
292 scoped_refptr<LayerAnimationController> controller_impl(
293 LayerAnimationController::Create(0));
294 controller_impl->AddValueObserver(&dummy_impl);
295 FakeLayerAnimationValueObserver dummy;
296 scoped_refptr<LayerAnimationController> controller(
297 LayerAnimationController::Create(0));
298 controller->AddValueObserver(&dummy);
300 EXPECT_FALSE(controller_impl->GetAnimation(Animation::Opacity));
302 int animation_id =
303 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false);
304 int group_id = controller->GetAnimation(Animation::Opacity)->group();
306 controller->PushAnimationUpdatesTo(controller_impl.get());
307 controller_impl->ActivateAnimations();
309 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity));
310 EXPECT_EQ(Animation::WaitingForTargetAvailability,
311 controller_impl->GetAnimation(group_id,
312 Animation::Opacity)->run_state());
314 // Notify main thread controller that the animation has started.
315 AnimationEvent animation_started_event(AnimationEvent::Started,
317 group_id,
318 Animation::Opacity,
319 kInitialTickTime);
320 controller->NotifyAnimationStarted(animation_started_event);
322 // Force animation to complete on impl thread.
323 controller_impl->RemoveAnimation(animation_id);
325 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity));
327 controller->PushAnimationUpdatesTo(controller_impl.get());
328 controller_impl->ActivateAnimations();
330 // Even though the main thread has a 'new' animation, it should not be pushed
331 // because the animation has already completed on the impl thread.
332 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity));
335 // Ensure that a finished animation is eventually deleted by both the
336 // main-thread and the impl-thread controllers.
337 TEST(LayerAnimationControllerTest, AnimationsAreDeleted) {
338 FakeLayerAnimationValueObserver dummy;
339 FakeLayerAnimationValueObserver dummy_impl;
340 scoped_ptr<AnimationEventsVector> events(
341 make_scoped_ptr(new AnimationEventsVector));
342 scoped_refptr<LayerAnimationController> controller(
343 LayerAnimationController::Create(0));
344 scoped_refptr<LayerAnimationController> controller_impl(
345 LayerAnimationController::Create(0));
346 controller->AddValueObserver(&dummy);
347 controller_impl->AddValueObserver(&dummy_impl);
349 AddOpacityTransitionToController(controller.get(), 1.0, 0.0f, 1.0f, false);
350 controller->Animate(kInitialTickTime);
351 controller->UpdateState(true, NULL);
352 controller->PushAnimationUpdatesTo(controller_impl.get());
353 controller_impl->ActivateAnimations();
355 controller_impl->Animate(kInitialTickTime + 0.5);
356 controller_impl->UpdateState(true, events.get());
358 // There should be a Started event for the animation.
359 EXPECT_EQ(1u, events->size());
360 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type);
361 controller->NotifyAnimationStarted((*events)[0]);
363 controller->Animate(kInitialTickTime + 1.0);
364 controller->UpdateState(true, NULL);
366 EXPECT_FALSE(dummy.animation_waiting_for_deletion());
367 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion());
369 events.reset(new AnimationEventsVector);
370 controller_impl->Animate(kInitialTickTime + 2.0);
371 controller_impl->UpdateState(true, events.get());
373 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion());
375 // There should be a Finished event for the animation.
376 EXPECT_EQ(1u, events->size());
377 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type);
379 // Neither controller should have deleted the animation yet.
380 EXPECT_TRUE(controller->GetAnimation(Animation::Opacity));
381 EXPECT_TRUE(controller_impl->GetAnimation(Animation::Opacity));
383 controller->NotifyAnimationFinished((*events)[0]);
385 controller->Animate(kInitialTickTime + 3.0);
386 controller->UpdateState(true, NULL);
387 EXPECT_TRUE(dummy.animation_waiting_for_deletion());
389 controller->PushAnimationUpdatesTo(controller_impl.get());
391 // Both controllers should now have deleted the animation. The impl controller
392 // should have deleted the animation even though activation has not occurred,
393 // since the animation was already waiting for deletion when
394 // PushAnimationUpdatesTo was called.
395 EXPECT_FALSE(controller->has_any_animation());
396 EXPECT_FALSE(controller_impl->has_any_animation());
399 // Tests that transitioning opacity from 0 to 1 works as expected.
401 static const AnimationEvent* GetMostRecentPropertyUpdateEvent(
402 const AnimationEventsVector* events) {
403 const AnimationEvent* event = 0;
404 for (size_t i = 0; i < events->size(); ++i)
405 if ((*events)[i].type == AnimationEvent::PropertyUpdate)
406 event = &(*events)[i];
408 return event;
411 TEST(LayerAnimationControllerTest, TrivialTransition) {
412 scoped_ptr<AnimationEventsVector> events(
413 make_scoped_ptr(new AnimationEventsVector));
414 FakeLayerAnimationValueObserver dummy;
415 scoped_refptr<LayerAnimationController> controller(
416 LayerAnimationController::Create(0));
417 controller->AddValueObserver(&dummy);
419 scoped_ptr<Animation> to_add(CreateAnimation(
420 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
422 Animation::Opacity));
424 controller->AddAnimation(to_add.Pass());
425 controller->Animate(kInitialTickTime);
426 controller->UpdateState(true, events.get());
427 EXPECT_TRUE(controller->HasActiveAnimation());
428 EXPECT_EQ(0.f, dummy.opacity());
429 // A non-impl-only animation should not generate property updates.
430 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get());
431 EXPECT_FALSE(event);
432 controller->Animate(kInitialTickTime + 1.0);
433 controller->UpdateState(true, events.get());
434 EXPECT_EQ(1.f, dummy.opacity());
435 EXPECT_FALSE(controller->HasActiveAnimation());
436 event = GetMostRecentPropertyUpdateEvent(events.get());
437 EXPECT_FALSE(event);
440 TEST(LayerAnimationControllerTest, TrivialTransitionOnImpl) {
441 scoped_ptr<AnimationEventsVector> events(
442 make_scoped_ptr(new AnimationEventsVector));
443 FakeLayerAnimationValueObserver dummy_impl;
444 scoped_refptr<LayerAnimationController> controller_impl(
445 LayerAnimationController::Create(0));
446 controller_impl->AddValueObserver(&dummy_impl);
448 scoped_ptr<Animation> to_add(CreateAnimation(
449 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
451 Animation::Opacity));
452 to_add->set_is_impl_only(true);
454 controller_impl->AddAnimation(to_add.Pass());
455 controller_impl->Animate(kInitialTickTime);
456 controller_impl->UpdateState(true, events.get());
457 EXPECT_TRUE(controller_impl->HasActiveAnimation());
458 EXPECT_EQ(0.f, dummy_impl.opacity());
459 EXPECT_EQ(2u, events->size());
460 const AnimationEvent* start_opacity_event =
461 GetMostRecentPropertyUpdateEvent(events.get());
462 EXPECT_EQ(0.f, start_opacity_event->opacity);
464 controller_impl->Animate(kInitialTickTime + 1.0);
465 controller_impl->UpdateState(true, events.get());
466 EXPECT_EQ(1.f, dummy_impl.opacity());
467 EXPECT_FALSE(controller_impl->HasActiveAnimation());
468 EXPECT_EQ(4u, events->size());
469 const AnimationEvent* end_opacity_event =
470 GetMostRecentPropertyUpdateEvent(events.get());
471 EXPECT_EQ(1.f, end_opacity_event->opacity);
474 TEST(LayerAnimationControllerTest, TrivialTransformOnImpl) {
475 scoped_ptr<AnimationEventsVector> events(
476 make_scoped_ptr(new AnimationEventsVector));
477 FakeLayerAnimationValueObserver dummy_impl;
478 scoped_refptr<LayerAnimationController> controller_impl(
479 LayerAnimationController::Create(0));
480 controller_impl->AddValueObserver(&dummy_impl);
482 // Choose different values for x and y to avoid coincidental values in the
483 // observed transforms.
484 const float delta_x = 3;
485 const float delta_y = 4;
487 scoped_ptr<KeyframedTransformAnimationCurve> curve(
488 KeyframedTransformAnimationCurve::Create());
490 // Create simple Transform animation.
491 TransformOperations operations;
492 curve->AddKeyframe(
493 TransformKeyframe::Create(0, operations, scoped_ptr<TimingFunction>()));
494 operations.AppendTranslate(delta_x, delta_y, 0);
495 curve->AddKeyframe(
496 TransformKeyframe::Create(1, operations, scoped_ptr<TimingFunction>()));
498 scoped_ptr<Animation> animation(Animation::Create(
499 curve.PassAs<AnimationCurve>(), 1, 0, Animation::Transform));
500 animation->set_is_impl_only(true);
501 controller_impl->AddAnimation(animation.Pass());
503 // Run animation.
504 controller_impl->Animate(kInitialTickTime);
505 controller_impl->UpdateState(true, events.get());
506 EXPECT_TRUE(controller_impl->HasActiveAnimation());
507 EXPECT_EQ(gfx::Transform(), dummy_impl.transform());
508 EXPECT_EQ(2u, events->size());
509 const AnimationEvent* start_transform_event =
510 GetMostRecentPropertyUpdateEvent(events.get());
511 ASSERT_TRUE(start_transform_event);
512 EXPECT_EQ(gfx::Transform(), start_transform_event->transform);
513 EXPECT_TRUE(start_transform_event->is_impl_only);
515 gfx::Transform expected_transform;
516 expected_transform.Translate(delta_x, delta_y);
518 controller_impl->Animate(kInitialTickTime + 1.0);
519 controller_impl->UpdateState(true, events.get());
520 EXPECT_EQ(expected_transform, dummy_impl.transform());
521 EXPECT_FALSE(controller_impl->HasActiveAnimation());
522 EXPECT_EQ(4u, events->size());
523 const AnimationEvent* end_transform_event =
524 GetMostRecentPropertyUpdateEvent(events.get());
525 EXPECT_EQ(expected_transform, end_transform_event->transform);
526 EXPECT_TRUE(end_transform_event->is_impl_only);
529 TEST(LayerAnimationControllerTest, FilterTransition) {
530 scoped_ptr<AnimationEventsVector> events(
531 make_scoped_ptr(new AnimationEventsVector));
532 FakeLayerAnimationValueObserver dummy;
533 scoped_refptr<LayerAnimationController> controller(
534 LayerAnimationController::Create(0));
535 controller->AddValueObserver(&dummy);
537 scoped_ptr<KeyframedFilterAnimationCurve> curve(
538 KeyframedFilterAnimationCurve::Create());
540 FilterOperations start_filters;
541 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f));
542 curve->AddKeyframe(
543 FilterKeyframe::Create(0, start_filters, scoped_ptr<TimingFunction>()));
544 FilterOperations end_filters;
545 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f));
546 curve->AddKeyframe(
547 FilterKeyframe::Create(1, end_filters, scoped_ptr<TimingFunction>()));
549 scoped_ptr<Animation> animation(Animation::Create(
550 curve.PassAs<AnimationCurve>(), 1, 0, Animation::Filter));
551 controller->AddAnimation(animation.Pass());
553 controller->Animate(kInitialTickTime);
554 controller->UpdateState(true, events.get());
555 EXPECT_TRUE(controller->HasActiveAnimation());
556 EXPECT_EQ(start_filters, dummy.filters());
557 // A non-impl-only animation should not generate property updates.
558 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get());
559 EXPECT_FALSE(event);
561 controller->Animate(kInitialTickTime + 0.5);
562 controller->UpdateState(true, events.get());
563 EXPECT_EQ(1u, dummy.filters().size());
564 EXPECT_EQ(FilterOperation::CreateBrightnessFilter(1.5f),
565 dummy.filters().at(0));
566 event = GetMostRecentPropertyUpdateEvent(events.get());
567 EXPECT_FALSE(event);
569 controller->Animate(kInitialTickTime + 1.0);
570 controller->UpdateState(true, events.get());
571 EXPECT_EQ(end_filters, dummy.filters());
572 EXPECT_FALSE(controller->HasActiveAnimation());
573 event = GetMostRecentPropertyUpdateEvent(events.get());
574 EXPECT_FALSE(event);
577 TEST(LayerAnimationControllerTest, FilterTransitionOnImplOnly) {
578 scoped_ptr<AnimationEventsVector> events(
579 make_scoped_ptr(new AnimationEventsVector));
580 FakeLayerAnimationValueObserver dummy_impl;
581 scoped_refptr<LayerAnimationController> controller_impl(
582 LayerAnimationController::Create(0));
583 controller_impl->AddValueObserver(&dummy_impl);
585 scoped_ptr<KeyframedFilterAnimationCurve> curve(
586 KeyframedFilterAnimationCurve::Create());
588 // Create simple Filter animation.
589 FilterOperations start_filters;
590 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f));
591 curve->AddKeyframe(
592 FilterKeyframe::Create(0, start_filters, scoped_ptr<TimingFunction>()));
593 FilterOperations end_filters;
594 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f));
595 curve->AddKeyframe(
596 FilterKeyframe::Create(1, end_filters, scoped_ptr<TimingFunction>()));
598 scoped_ptr<Animation> animation(Animation::Create(
599 curve.PassAs<AnimationCurve>(), 1, 0, Animation::Filter));
600 animation->set_is_impl_only(true);
601 controller_impl->AddAnimation(animation.Pass());
603 // Run animation.
604 controller_impl->Animate(kInitialTickTime);
605 controller_impl->UpdateState(true, events.get());
606 EXPECT_TRUE(controller_impl->HasActiveAnimation());
607 EXPECT_EQ(start_filters, dummy_impl.filters());
608 EXPECT_EQ(2u, events->size());
609 const AnimationEvent* start_filter_event =
610 GetMostRecentPropertyUpdateEvent(events.get());
611 EXPECT_TRUE(start_filter_event);
612 EXPECT_EQ(start_filters, start_filter_event->filters);
613 EXPECT_TRUE(start_filter_event->is_impl_only);
615 controller_impl->Animate(kInitialTickTime + 1.0);
616 controller_impl->UpdateState(true, events.get());
617 EXPECT_EQ(end_filters, dummy_impl.filters());
618 EXPECT_FALSE(controller_impl->HasActiveAnimation());
619 EXPECT_EQ(4u, events->size());
620 const AnimationEvent* end_filter_event =
621 GetMostRecentPropertyUpdateEvent(events.get());
622 EXPECT_TRUE(end_filter_event);
623 EXPECT_EQ(end_filters, end_filter_event->filters);
624 EXPECT_TRUE(end_filter_event->is_impl_only);
627 TEST(LayerAnimationControllerTest, ScrollOffsetTransition) {
628 FakeLayerAnimationValueObserver dummy_impl;
629 FakeLayerAnimationValueProvider dummy_provider_impl;
630 scoped_refptr<LayerAnimationController> controller_impl(
631 LayerAnimationController::Create(0));
632 controller_impl->AddValueObserver(&dummy_impl);
633 controller_impl->set_value_provider(&dummy_provider_impl);
634 scoped_ptr<AnimationEventsVector> events(
635 make_scoped_ptr(new AnimationEventsVector));
636 FakeLayerAnimationValueObserver dummy;
637 FakeLayerAnimationValueProvider dummy_provider;
638 scoped_refptr<LayerAnimationController> controller(
639 LayerAnimationController::Create(0));
640 controller->AddValueObserver(&dummy);
641 controller->set_value_provider(&dummy_provider);
643 gfx::Vector2dF initial_value(100.f, 300.f);
644 gfx::Vector2dF target_value(300.f, 200.f);
645 scoped_ptr<ScrollOffsetAnimationCurve> curve(
646 ScrollOffsetAnimationCurve::Create(
647 target_value,
648 EaseInOutTimingFunction::Create().Pass()));
650 scoped_ptr<Animation> animation(Animation::Create(
651 curve.PassAs<AnimationCurve>(), 1, 0, Animation::ScrollOffset));
652 animation->set_needs_synchronized_start_time(true);
653 controller->AddAnimation(animation.Pass());
655 dummy_provider_impl.set_scroll_offset(initial_value);
656 controller->PushAnimationUpdatesTo(controller_impl.get());
657 controller_impl->ActivateAnimations();
658 EXPECT_TRUE(controller_impl->GetAnimation(Animation::ScrollOffset));
659 double duration = controller_impl->GetAnimation(
660 Animation::ScrollOffset)->curve()->Duration();
662 EXPECT_EQ(
663 duration,
664 controller->GetAnimation(Animation::ScrollOffset)->curve()->Duration());
666 controller->Animate(kInitialTickTime);
667 controller->UpdateState(true, NULL);
668 EXPECT_TRUE(controller->HasActiveAnimation());
669 EXPECT_EQ(initial_value, dummy.scroll_offset());
671 controller_impl->Animate(kInitialTickTime);
672 controller_impl->UpdateState(true, events.get());
673 EXPECT_TRUE(controller_impl->HasActiveAnimation());
674 EXPECT_EQ(initial_value, dummy_impl.scroll_offset());
675 // Scroll offset animations should not generate property updates.
676 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get());
677 EXPECT_FALSE(event);
679 controller->NotifyAnimationStarted((*events)[0]);
680 controller->Animate(kInitialTickTime + duration/2.0);
681 controller->UpdateState(true, NULL);
682 EXPECT_TRUE(controller->HasActiveAnimation());
683 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), dummy.scroll_offset());
685 controller_impl->Animate(kInitialTickTime + duration/2.0);
686 controller_impl->UpdateState(true, events.get());
687 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f),
688 dummy_impl.scroll_offset());
689 event = GetMostRecentPropertyUpdateEvent(events.get());
690 EXPECT_FALSE(event);
692 controller_impl->Animate(kInitialTickTime + duration);
693 controller_impl->UpdateState(true, events.get());
694 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset());
695 EXPECT_FALSE(controller_impl->HasActiveAnimation());
696 event = GetMostRecentPropertyUpdateEvent(events.get());
697 EXPECT_FALSE(event);
699 controller->Animate(kInitialTickTime + duration);
700 controller->UpdateState(true, NULL);
701 EXPECT_VECTOR2DF_EQ(target_value, dummy.scroll_offset());
702 EXPECT_FALSE(controller->HasActiveAnimation());
705 // Ensure that when the impl controller doesn't have a value provider,
706 // the main-thread controller's value provider is used to obtain the intial
707 // scroll offset.
708 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionNoImplProvider) {
709 FakeLayerAnimationValueObserver dummy_impl;
710 scoped_refptr<LayerAnimationController> controller_impl(
711 LayerAnimationController::Create(0));
712 controller_impl->AddValueObserver(&dummy_impl);
713 scoped_ptr<AnimationEventsVector> events(
714 make_scoped_ptr(new AnimationEventsVector));
715 FakeLayerAnimationValueObserver dummy;
716 FakeLayerAnimationValueProvider dummy_provider;
717 scoped_refptr<LayerAnimationController> controller(
718 LayerAnimationController::Create(0));
719 controller->AddValueObserver(&dummy);
720 controller->set_value_provider(&dummy_provider);
722 gfx::Vector2dF initial_value(500.f, 100.f);
723 gfx::Vector2dF target_value(300.f, 200.f);
724 scoped_ptr<ScrollOffsetAnimationCurve> curve(
725 ScrollOffsetAnimationCurve::Create(
726 target_value,
727 EaseInOutTimingFunction::Create().Pass()));
729 scoped_ptr<Animation> animation(Animation::Create(
730 curve.PassAs<AnimationCurve>(), 1, 0, Animation::ScrollOffset));
731 animation->set_needs_synchronized_start_time(true);
732 controller->AddAnimation(animation.Pass());
734 dummy_provider.set_scroll_offset(initial_value);
735 controller->PushAnimationUpdatesTo(controller_impl.get());
736 controller_impl->ActivateAnimations();
737 EXPECT_TRUE(controller_impl->GetAnimation(Animation::ScrollOffset));
738 double duration = controller_impl->GetAnimation(
739 Animation::ScrollOffset)->curve()->Duration();
741 EXPECT_EQ(
742 duration,
743 controller->GetAnimation(Animation::ScrollOffset)->curve()->Duration());
745 controller->Animate(kInitialTickTime);
746 controller->UpdateState(true, NULL);
747 EXPECT_TRUE(controller->HasActiveAnimation());
748 EXPECT_EQ(initial_value, dummy.scroll_offset());
750 controller_impl->Animate(kInitialTickTime);
751 controller_impl->UpdateState(true, events.get());
752 EXPECT_TRUE(controller_impl->HasActiveAnimation());
753 EXPECT_EQ(initial_value, dummy_impl.scroll_offset());
754 // Scroll offset animations should not generate property updates.
755 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get());
756 EXPECT_FALSE(event);
758 controller->NotifyAnimationStarted((*events)[0]);
759 controller->Animate(kInitialTickTime + duration/2.0);
760 controller->UpdateState(true, NULL);
761 EXPECT_TRUE(controller->HasActiveAnimation());
762 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f), dummy.scroll_offset());
764 controller_impl->Animate(kInitialTickTime + duration/2.0);
765 controller_impl->UpdateState(true, events.get());
766 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f),
767 dummy_impl.scroll_offset());
768 event = GetMostRecentPropertyUpdateEvent(events.get());
769 EXPECT_FALSE(event);
771 controller_impl->Animate(kInitialTickTime + duration);
772 controller_impl->UpdateState(true, events.get());
773 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset());
774 EXPECT_FALSE(controller_impl->HasActiveAnimation());
775 event = GetMostRecentPropertyUpdateEvent(events.get());
776 EXPECT_FALSE(event);
778 controller->Animate(kInitialTickTime + duration);
779 controller->UpdateState(true, NULL);
780 EXPECT_VECTOR2DF_EQ(target_value, dummy.scroll_offset());
781 EXPECT_FALSE(controller->HasActiveAnimation());
784 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionOnImplOnly) {
785 FakeLayerAnimationValueObserver dummy_impl;
786 scoped_refptr<LayerAnimationController> controller_impl(
787 LayerAnimationController::Create(0));
788 controller_impl->AddValueObserver(&dummy_impl);
789 scoped_ptr<AnimationEventsVector> events(
790 make_scoped_ptr(new AnimationEventsVector));
792 gfx::Vector2dF initial_value(100.f, 300.f);
793 gfx::Vector2dF target_value(300.f, 200.f);
794 scoped_ptr<ScrollOffsetAnimationCurve> curve(
795 ScrollOffsetAnimationCurve::Create(
796 target_value,
797 EaseInOutTimingFunction::Create().Pass()));
798 curve->SetInitialValue(initial_value);
799 double duration = curve->Duration();
801 scoped_ptr<Animation> animation(Animation::Create(
802 curve.PassAs<AnimationCurve>(), 1, 0, Animation::ScrollOffset));
803 animation->set_is_impl_only(true);
804 controller_impl->AddAnimation(animation.Pass());
806 controller_impl->Animate(kInitialTickTime);
807 controller_impl->UpdateState(true, events.get());
808 EXPECT_TRUE(controller_impl->HasActiveAnimation());
809 EXPECT_EQ(initial_value, dummy_impl.scroll_offset());
810 // Scroll offset animations should not generate property updates.
811 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get());
812 EXPECT_FALSE(event);
814 controller_impl->Animate(kInitialTickTime + duration/2.0);
815 controller_impl->UpdateState(true, events.get());
816 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f),
817 dummy_impl.scroll_offset());
818 event = GetMostRecentPropertyUpdateEvent(events.get());
819 EXPECT_FALSE(event);
821 controller_impl->Animate(kInitialTickTime + duration);
822 controller_impl->UpdateState(true, events.get());
823 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset());
824 EXPECT_FALSE(controller_impl->HasActiveAnimation());
825 event = GetMostRecentPropertyUpdateEvent(events.get());
826 EXPECT_FALSE(event);
829 class FakeAnimationDelegate : public AnimationDelegate {
830 public:
831 FakeAnimationDelegate()
832 : started_(false),
833 finished_(false) {}
835 virtual void NotifyAnimationStarted(
836 base::TimeTicks monotonic_time,
837 Animation::TargetProperty target_property) OVERRIDE {
838 started_ = true;
841 virtual void NotifyAnimationFinished(
842 base::TimeTicks monotonic_time,
843 Animation::TargetProperty target_property) OVERRIDE {
844 finished_ = true;
847 bool started() { return started_; }
849 bool finished() { return finished_; }
851 private:
852 bool started_;
853 bool finished_;
856 // Tests that impl-only animations lead to start and finished notifications
857 // being sent to the main thread controller's animation delegate.
858 TEST(LayerAnimationControllerTest,
859 NotificationsForImplOnlyAnimationsAreSentToMainThreadDelegate) {
860 FakeLayerAnimationValueObserver dummy_impl;
861 scoped_refptr<LayerAnimationController> controller_impl(
862 LayerAnimationController::Create(0));
863 controller_impl->AddValueObserver(&dummy_impl);
864 scoped_ptr<AnimationEventsVector> events(
865 make_scoped_ptr(new AnimationEventsVector));
866 FakeLayerAnimationValueObserver dummy;
867 scoped_refptr<LayerAnimationController> controller(
868 LayerAnimationController::Create(0));
869 controller->AddValueObserver(&dummy);
870 FakeAnimationDelegate delegate;
871 controller->set_layer_animation_delegate(&delegate);
873 scoped_ptr<Animation> to_add(CreateAnimation(
874 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
876 Animation::Opacity));
877 to_add->set_is_impl_only(true);
878 controller_impl->AddAnimation(to_add.Pass());
880 controller_impl->Animate(kInitialTickTime);
881 controller_impl->UpdateState(true, events.get());
883 // We should receive 2 events (a started notification and a property update).
884 EXPECT_EQ(2u, events->size());
885 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type);
886 EXPECT_TRUE((*events)[0].is_impl_only);
887 EXPECT_EQ(AnimationEvent::PropertyUpdate, (*events)[1].type);
888 EXPECT_TRUE((*events)[1].is_impl_only);
890 // Passing on the start event to the main thread controller should cause the
891 // delegate to get notified.
892 EXPECT_FALSE(delegate.started());
893 controller->NotifyAnimationStarted((*events)[0]);
894 EXPECT_TRUE(delegate.started());
896 events.reset(new AnimationEventsVector);
897 controller_impl->Animate(kInitialTickTime + 1.0);
898 controller_impl->UpdateState(true, events.get());
900 // We should receive 2 events (a finished notification and a property update).
901 EXPECT_EQ(2u, events->size());
902 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type);
903 EXPECT_TRUE((*events)[0].is_impl_only);
904 EXPECT_EQ(AnimationEvent::PropertyUpdate, (*events)[1].type);
905 EXPECT_TRUE((*events)[1].is_impl_only);
907 // Passing on the finished event to the main thread controller should cause
908 // the delegate to get notified.
909 EXPECT_FALSE(delegate.finished());
910 controller->NotifyAnimationFinished((*events)[0]);
911 EXPECT_TRUE(delegate.finished());
914 // Tests animations that are waiting for a synchronized start time do not
915 // finish.
916 TEST(LayerAnimationControllerTest,
917 AnimationsWaitingForStartTimeDoNotFinishIfTheyOutwaitTheirFinish) {
918 scoped_ptr<AnimationEventsVector> events(
919 make_scoped_ptr(new AnimationEventsVector));
920 FakeLayerAnimationValueObserver dummy;
921 scoped_refptr<LayerAnimationController> controller(
922 LayerAnimationController::Create(0));
923 controller->AddValueObserver(&dummy);
925 scoped_ptr<Animation> to_add(CreateAnimation(
926 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
928 Animation::Opacity));
929 to_add->set_needs_synchronized_start_time(true);
931 // We should pause at the first keyframe indefinitely waiting for that
932 // animation to start.
933 controller->AddAnimation(to_add.Pass());
934 controller->Animate(kInitialTickTime);
935 controller->UpdateState(true, events.get());
936 EXPECT_TRUE(controller->HasActiveAnimation());
937 EXPECT_EQ(0.f, dummy.opacity());
938 controller->Animate(kInitialTickTime + 1.0);
939 controller->UpdateState(true, events.get());
940 EXPECT_TRUE(controller->HasActiveAnimation());
941 EXPECT_EQ(0.f, dummy.opacity());
942 controller->Animate(kInitialTickTime + 2.0);
943 controller->UpdateState(true, events.get());
944 EXPECT_TRUE(controller->HasActiveAnimation());
945 EXPECT_EQ(0.f, dummy.opacity());
947 // Send the synchronized start time.
948 controller->NotifyAnimationStarted(AnimationEvent(
949 AnimationEvent::Started, 0, 1, Animation::Opacity, kInitialTickTime + 2));
950 controller->Animate(kInitialTickTime + 5.0);
951 controller->UpdateState(true, events.get());
952 EXPECT_EQ(1.f, dummy.opacity());
953 EXPECT_FALSE(controller->HasActiveAnimation());
956 // Tests that two queued animations affecting the same property run in sequence.
957 TEST(LayerAnimationControllerTest, TrivialQueuing) {
958 scoped_ptr<AnimationEventsVector> events(
959 make_scoped_ptr(new AnimationEventsVector));
960 FakeLayerAnimationValueObserver dummy;
961 scoped_refptr<LayerAnimationController> controller(
962 LayerAnimationController::Create(0));
963 controller->AddValueObserver(&dummy);
965 controller->AddAnimation(CreateAnimation(
966 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
968 Animation::Opacity));
969 controller->AddAnimation(CreateAnimation(
970 scoped_ptr<AnimationCurve>(
971 new FakeFloatTransition(1.0, 1.f, 0.5f)).Pass(),
973 Animation::Opacity));
975 controller->Animate(kInitialTickTime);
976 controller->UpdateState(true, events.get());
977 EXPECT_TRUE(controller->HasActiveAnimation());
978 EXPECT_EQ(0.f, dummy.opacity());
979 controller->Animate(kInitialTickTime + 1.0);
980 controller->UpdateState(true, events.get());
981 EXPECT_TRUE(controller->HasActiveAnimation());
982 EXPECT_EQ(1.f, dummy.opacity());
983 controller->Animate(kInitialTickTime + 2.0);
984 controller->UpdateState(true, events.get());
985 EXPECT_EQ(0.5f, dummy.opacity());
986 EXPECT_FALSE(controller->HasActiveAnimation());
989 // Tests interrupting a transition with another transition.
990 TEST(LayerAnimationControllerTest, Interrupt) {
991 scoped_ptr<AnimationEventsVector> events(
992 make_scoped_ptr(new AnimationEventsVector));
993 FakeLayerAnimationValueObserver dummy;
994 scoped_refptr<LayerAnimationController> controller(
995 LayerAnimationController::Create(0));
996 controller->AddValueObserver(&dummy);
997 controller->AddAnimation(CreateAnimation(
998 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1000 Animation::Opacity));
1001 controller->Animate(kInitialTickTime);
1002 controller->UpdateState(true, events.get());
1003 EXPECT_TRUE(controller->HasActiveAnimation());
1004 EXPECT_EQ(0.f, dummy.opacity());
1006 scoped_ptr<Animation> to_add(CreateAnimation(
1007 scoped_ptr<AnimationCurve>(
1008 new FakeFloatTransition(1.0, 1.f, 0.5f)).Pass(),
1010 Animation::Opacity));
1011 controller->AbortAnimations(Animation::Opacity);
1012 controller->AddAnimation(to_add.Pass());
1014 // Since the previous animation was aborted, the new animation should start
1015 // right in this call to animate.
1016 controller->Animate(kInitialTickTime + 0.5);
1017 controller->UpdateState(true, events.get());
1018 EXPECT_TRUE(controller->HasActiveAnimation());
1019 EXPECT_EQ(1.f, dummy.opacity());
1020 controller->Animate(kInitialTickTime + 1.5);
1021 controller->UpdateState(true, events.get());
1022 EXPECT_EQ(0.5f, dummy.opacity());
1023 EXPECT_FALSE(controller->HasActiveAnimation());
1026 // Tests scheduling two animations to run together when only one property is
1027 // free.
1028 TEST(LayerAnimationControllerTest, ScheduleTogetherWhenAPropertyIsBlocked) {
1029 scoped_ptr<AnimationEventsVector> events(
1030 make_scoped_ptr(new AnimationEventsVector));
1031 FakeLayerAnimationValueObserver dummy;
1032 scoped_refptr<LayerAnimationController> controller(
1033 LayerAnimationController::Create(0));
1034 controller->AddValueObserver(&dummy);
1036 controller->AddAnimation(CreateAnimation(
1037 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(),
1039 Animation::Transform));
1040 controller->AddAnimation(CreateAnimation(
1041 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(),
1043 Animation::Transform));
1044 controller->AddAnimation(CreateAnimation(
1045 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1047 Animation::Opacity));
1049 controller->Animate(kInitialTickTime);
1050 controller->UpdateState(true, events.get());
1051 EXPECT_EQ(0.f, dummy.opacity());
1052 EXPECT_TRUE(controller->HasActiveAnimation());
1053 controller->Animate(kInitialTickTime + 1.0);
1054 controller->UpdateState(true, events.get());
1055 // Should not have started the float transition yet.
1056 EXPECT_TRUE(controller->HasActiveAnimation());
1057 EXPECT_EQ(0.f, dummy.opacity());
1058 // The float animation should have started at time 1 and should be done.
1059 controller->Animate(kInitialTickTime + 2.0);
1060 controller->UpdateState(true, events.get());
1061 EXPECT_EQ(1.f, dummy.opacity());
1062 EXPECT_FALSE(controller->HasActiveAnimation());
1065 // Tests scheduling two animations to run together with different lengths and
1066 // another animation queued to start when the shorter animation finishes (should
1067 // wait for both to finish).
1068 TEST(LayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting) {
1069 scoped_ptr<AnimationEventsVector> events(
1070 make_scoped_ptr(new AnimationEventsVector));
1071 FakeLayerAnimationValueObserver dummy;
1072 scoped_refptr<LayerAnimationController> controller(
1073 LayerAnimationController::Create(0));
1074 controller->AddValueObserver(&dummy);
1076 controller->AddAnimation(CreateAnimation(
1077 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2)).Pass(),
1079 Animation::Transform));
1080 controller->AddAnimation(CreateAnimation(
1081 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1083 Animation::Opacity));
1084 controller->AddAnimation(CreateAnimation(
1085 scoped_ptr<AnimationCurve>(
1086 new FakeFloatTransition(1.0, 1.f, 0.5f)).Pass(),
1088 Animation::Opacity));
1090 // Animations with id 1 should both start now.
1091 controller->Animate(kInitialTickTime);
1092 controller->UpdateState(true, events.get());
1093 EXPECT_TRUE(controller->HasActiveAnimation());
1094 EXPECT_EQ(0.f, dummy.opacity());
1095 // The opacity animation should have finished at time 1, but the group
1096 // of animations with id 1 don't finish until time 2 because of the length
1097 // of the transform animation.
1098 controller->Animate(kInitialTickTime + 2.0);
1099 controller->UpdateState(true, events.get());
1100 // Should not have started the float transition yet.
1101 EXPECT_TRUE(controller->HasActiveAnimation());
1102 EXPECT_EQ(1.f, dummy.opacity());
1104 // The second opacity animation should start at time 2 and should be done by
1105 // time 3.
1106 controller->Animate(kInitialTickTime + 3.0);
1107 controller->UpdateState(true, events.get());
1108 EXPECT_EQ(0.5f, dummy.opacity());
1109 EXPECT_FALSE(controller->HasActiveAnimation());
1112 // Test that a looping animation loops and for the correct number of iterations.
1113 TEST(LayerAnimationControllerTest, TrivialLooping) {
1114 scoped_ptr<AnimationEventsVector> events(
1115 make_scoped_ptr(new AnimationEventsVector));
1116 FakeLayerAnimationValueObserver dummy;
1117 scoped_refptr<LayerAnimationController> controller(
1118 LayerAnimationController::Create(0));
1119 controller->AddValueObserver(&dummy);
1121 scoped_ptr<Animation> to_add(CreateAnimation(
1122 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1124 Animation::Opacity));
1125 to_add->set_iterations(3);
1126 controller->AddAnimation(to_add.Pass());
1128 controller->Animate(kInitialTickTime);
1129 controller->UpdateState(true, events.get());
1130 EXPECT_TRUE(controller->HasActiveAnimation());
1131 EXPECT_EQ(0.f, dummy.opacity());
1132 controller->Animate(kInitialTickTime + 1.25);
1133 controller->UpdateState(true, events.get());
1134 EXPECT_TRUE(controller->HasActiveAnimation());
1135 EXPECT_EQ(0.25f, dummy.opacity());
1136 controller->Animate(kInitialTickTime + 1.75);
1137 controller->UpdateState(true, events.get());
1138 EXPECT_TRUE(controller->HasActiveAnimation());
1139 EXPECT_EQ(0.75f, dummy.opacity());
1140 controller->Animate(kInitialTickTime + 2.25);
1141 controller->UpdateState(true, events.get());
1142 EXPECT_TRUE(controller->HasActiveAnimation());
1143 EXPECT_EQ(0.25f, dummy.opacity());
1144 controller->Animate(kInitialTickTime + 2.75);
1145 controller->UpdateState(true, events.get());
1146 EXPECT_TRUE(controller->HasActiveAnimation());
1147 EXPECT_EQ(0.75f, dummy.opacity());
1148 controller->Animate(kInitialTickTime + 3.0);
1149 controller->UpdateState(true, events.get());
1150 EXPECT_FALSE(controller->HasActiveAnimation());
1151 EXPECT_EQ(1.f, dummy.opacity());
1153 // Just be extra sure.
1154 controller->Animate(kInitialTickTime + 4.0);
1155 controller->UpdateState(true, events.get());
1156 EXPECT_EQ(1.f, dummy.opacity());
1159 // Test that an infinitely looping animation does indeed go until aborted.
1160 TEST(LayerAnimationControllerTest, InfiniteLooping) {
1161 scoped_ptr<AnimationEventsVector> events(
1162 make_scoped_ptr(new AnimationEventsVector));
1163 FakeLayerAnimationValueObserver dummy;
1164 scoped_refptr<LayerAnimationController> controller(
1165 LayerAnimationController::Create(0));
1166 controller->AddValueObserver(&dummy);
1168 const int id = 1;
1169 scoped_ptr<Animation> to_add(CreateAnimation(
1170 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1172 Animation::Opacity));
1173 to_add->set_iterations(-1);
1174 controller->AddAnimation(to_add.Pass());
1176 controller->Animate(kInitialTickTime);
1177 controller->UpdateState(true, events.get());
1178 EXPECT_TRUE(controller->HasActiveAnimation());
1179 EXPECT_EQ(0.f, dummy.opacity());
1180 controller->Animate(kInitialTickTime + 1.25);
1181 controller->UpdateState(true, events.get());
1182 EXPECT_TRUE(controller->HasActiveAnimation());
1183 EXPECT_EQ(0.25f, dummy.opacity());
1184 controller->Animate(kInitialTickTime + 1.75);
1185 controller->UpdateState(true, events.get());
1186 EXPECT_TRUE(controller->HasActiveAnimation());
1187 EXPECT_EQ(0.75f, dummy.opacity());
1189 controller->Animate(kInitialTickTime + 1073741824.25);
1190 controller->UpdateState(true, events.get());
1191 EXPECT_TRUE(controller->HasActiveAnimation());
1192 EXPECT_EQ(0.25f, dummy.opacity());
1193 controller->Animate(kInitialTickTime + 1073741824.75);
1194 controller->UpdateState(true, events.get());
1195 EXPECT_TRUE(controller->HasActiveAnimation());
1196 EXPECT_EQ(0.75f, dummy.opacity());
1198 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity));
1199 controller->GetAnimation(id, Animation::Opacity)->SetRunState(
1200 Animation::Aborted, kInitialTickTime + 0.75);
1201 EXPECT_FALSE(controller->HasActiveAnimation());
1202 EXPECT_EQ(0.75f, dummy.opacity());
1205 // Test that pausing and resuming work as expected.
1206 TEST(LayerAnimationControllerTest, PauseResume) {
1207 scoped_ptr<AnimationEventsVector> events(
1208 make_scoped_ptr(new AnimationEventsVector));
1209 FakeLayerAnimationValueObserver dummy;
1210 scoped_refptr<LayerAnimationController> controller(
1211 LayerAnimationController::Create(0));
1212 controller->AddValueObserver(&dummy);
1214 const int id = 1;
1215 controller->AddAnimation(CreateAnimation(
1216 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1218 Animation::Opacity));
1220 controller->Animate(kInitialTickTime);
1221 controller->UpdateState(true, events.get());
1222 EXPECT_TRUE(controller->HasActiveAnimation());
1223 EXPECT_EQ(0.f, dummy.opacity());
1224 controller->Animate(kInitialTickTime + 0.5);
1225 controller->UpdateState(true, events.get());
1226 EXPECT_TRUE(controller->HasActiveAnimation());
1227 EXPECT_EQ(0.5f, dummy.opacity());
1229 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity));
1230 controller->GetAnimation(id, Animation::Opacity)->SetRunState(
1231 Animation::Paused, kInitialTickTime + 0.5);
1233 controller->Animate(kInitialTickTime + 1024.0);
1234 controller->UpdateState(true, events.get());
1235 EXPECT_TRUE(controller->HasActiveAnimation());
1236 EXPECT_EQ(0.5f, dummy.opacity());
1238 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity));
1239 controller->GetAnimation(id, Animation::Opacity)->SetRunState(
1240 Animation::Running, kInitialTickTime + 1024);
1242 controller->Animate(kInitialTickTime + 1024.25);
1243 controller->UpdateState(true, events.get());
1244 EXPECT_TRUE(controller->HasActiveAnimation());
1245 EXPECT_EQ(0.75f, dummy.opacity());
1246 controller->Animate(kInitialTickTime + 1024.5);
1247 controller->UpdateState(true, events.get());
1248 EXPECT_FALSE(controller->HasActiveAnimation());
1249 EXPECT_EQ(1.f, dummy.opacity());
1252 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) {
1253 scoped_ptr<AnimationEventsVector> events(
1254 make_scoped_ptr(new AnimationEventsVector));
1255 FakeLayerAnimationValueObserver dummy;
1256 scoped_refptr<LayerAnimationController> controller(
1257 LayerAnimationController::Create(0));
1258 controller->AddValueObserver(&dummy);
1260 const int id = 1;
1261 controller->AddAnimation(CreateAnimation(
1262 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(),
1264 Animation::Transform));
1265 controller->AddAnimation(CreateAnimation(
1266 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(),
1268 Animation::Opacity));
1269 controller->AddAnimation(CreateAnimation(
1270 scoped_ptr<AnimationCurve>(
1271 new FakeFloatTransition(1.0, 1.f, 0.75f)).Pass(),
1273 Animation::Opacity));
1275 controller->Animate(kInitialTickTime);
1276 controller->UpdateState(true, events.get());
1277 EXPECT_TRUE(controller->HasActiveAnimation());
1278 EXPECT_EQ(0.f, dummy.opacity());
1279 controller->Animate(kInitialTickTime + 1.0);
1280 controller->UpdateState(true, events.get());
1281 EXPECT_TRUE(controller->HasActiveAnimation());
1282 EXPECT_EQ(0.5f, dummy.opacity());
1284 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity));
1285 controller->GetAnimation(id, Animation::Opacity)->SetRunState(
1286 Animation::Aborted, kInitialTickTime + 1.0);
1287 controller->Animate(kInitialTickTime + 1.0);
1288 controller->UpdateState(true, events.get());
1289 EXPECT_TRUE(controller->HasActiveAnimation());
1290 EXPECT_EQ(1.f, dummy.opacity());
1291 controller->Animate(kInitialTickTime + 2.0);
1292 controller->UpdateState(true, events.get());
1293 EXPECT_TRUE(!controller->HasActiveAnimation());
1294 EXPECT_EQ(0.75f, dummy.opacity());
1297 TEST(LayerAnimationControllerTest, PushUpdatesWhenSynchronizedStartTimeNeeded) {
1298 FakeLayerAnimationValueObserver dummy_impl;
1299 scoped_refptr<LayerAnimationController> controller_impl(
1300 LayerAnimationController::Create(0));
1301 controller_impl->AddValueObserver(&dummy_impl);
1302 scoped_ptr<AnimationEventsVector> events(
1303 make_scoped_ptr(new AnimationEventsVector));
1304 FakeLayerAnimationValueObserver dummy;
1305 scoped_refptr<LayerAnimationController> controller(
1306 LayerAnimationController::Create(0));
1307 controller->AddValueObserver(&dummy);
1309 scoped_ptr<Animation> to_add(CreateAnimation(
1310 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(),
1312 Animation::Opacity));
1313 to_add->set_needs_synchronized_start_time(true);
1314 controller->AddAnimation(to_add.Pass());
1316 controller->Animate(kInitialTickTime);
1317 controller->UpdateState(true, events.get());
1318 EXPECT_TRUE(controller->HasActiveAnimation());
1319 Animation* active_animation = controller->GetAnimation(0, Animation::Opacity);
1320 EXPECT_TRUE(active_animation);
1321 EXPECT_TRUE(active_animation->needs_synchronized_start_time());
1323 controller->PushAnimationUpdatesTo(controller_impl.get());
1324 controller_impl->ActivateAnimations();
1326 active_animation = controller_impl->GetAnimation(0, Animation::Opacity);
1327 EXPECT_TRUE(active_animation);
1328 EXPECT_EQ(Animation::WaitingForTargetAvailability,
1329 active_animation->run_state());
1332 // Tests that skipping a call to UpdateState works as expected.
1333 TEST(LayerAnimationControllerTest, SkipUpdateState) {
1334 scoped_ptr<AnimationEventsVector> events(
1335 make_scoped_ptr(new AnimationEventsVector));
1336 FakeLayerAnimationValueObserver dummy;
1337 scoped_refptr<LayerAnimationController> controller(
1338 LayerAnimationController::Create(0));
1339 controller->AddValueObserver(&dummy);
1341 controller->AddAnimation(CreateAnimation(
1342 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(),
1344 Animation::Transform));
1346 controller->Animate(kInitialTickTime);
1347 controller->UpdateState(true, events.get());
1349 controller->AddAnimation(CreateAnimation(
1350 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1352 Animation::Opacity));
1354 // Animate but don't UpdateState.
1355 controller->Animate(kInitialTickTime + 1.0);
1357 controller->Animate(kInitialTickTime + 2.0);
1358 events.reset(new AnimationEventsVector);
1359 controller->UpdateState(true, events.get());
1361 // Should have one Started event and one Finished event.
1362 EXPECT_EQ(2u, events->size());
1363 EXPECT_NE((*events)[0].type, (*events)[1].type);
1365 // The float transition should still be at its starting point.
1366 EXPECT_TRUE(controller->HasActiveAnimation());
1367 EXPECT_EQ(0.f, dummy.opacity());
1369 controller->Animate(kInitialTickTime + 3.0);
1370 controller->UpdateState(true, events.get());
1372 // The float tranisition should now be done.
1373 EXPECT_EQ(1.f, dummy.opacity());
1374 EXPECT_FALSE(controller->HasActiveAnimation());
1377 // Tests that an animation controller with only a pending observer gets ticked
1378 // but doesn't progress animations past the Starting state.
1379 TEST(LayerAnimationControllerTest, InactiveObserverGetsTicked) {
1380 scoped_ptr<AnimationEventsVector> events(
1381 make_scoped_ptr(new AnimationEventsVector));
1382 FakeLayerAnimationValueObserver dummy;
1383 FakeInactiveLayerAnimationValueObserver pending_dummy;
1384 scoped_refptr<LayerAnimationController> controller(
1385 LayerAnimationController::Create(0));
1387 const int id = 1;
1388 controller->AddAnimation(CreateAnimation(scoped_ptr<AnimationCurve>(
1389 new FakeFloatTransition(1.0, 0.5f, 1.f)).Pass(),
1391 Animation::Opacity));
1393 // Without an observer, the animation shouldn't progress to the Starting
1394 // state.
1395 controller->Animate(kInitialTickTime);
1396 controller->UpdateState(true, events.get());
1397 EXPECT_EQ(0u, events->size());
1398 EXPECT_EQ(Animation::WaitingForTargetAvailability,
1399 controller->GetAnimation(id, Animation::Opacity)->run_state());
1401 controller->AddValueObserver(&pending_dummy);
1403 // With only a pending observer, the animation should progress to the
1404 // Starting state and get ticked at its starting point, but should not
1405 // progress to Running.
1406 controller->Animate(kInitialTickTime + 1.0);
1407 controller->UpdateState(true, events.get());
1408 EXPECT_EQ(0u, events->size());
1409 EXPECT_EQ(Animation::Starting,
1410 controller->GetAnimation(id, Animation::Opacity)->run_state());
1411 EXPECT_EQ(0.5f, pending_dummy.opacity());
1413 // Even when already in the Starting state, the animation should stay
1414 // there, and shouldn't be ticked past its starting point.
1415 controller->Animate(kInitialTickTime + 2.0);
1416 controller->UpdateState(true, events.get());
1417 EXPECT_EQ(0u, events->size());
1418 EXPECT_EQ(Animation::Starting,
1419 controller->GetAnimation(id, Animation::Opacity)->run_state());
1420 EXPECT_EQ(0.5f, pending_dummy.opacity());
1422 controller->AddValueObserver(&dummy);
1424 // Now that an active observer has been added, the animation should still
1425 // initially tick at its starting point, but should now progress to Running.
1426 controller->Animate(kInitialTickTime + 3.0);
1427 controller->UpdateState(true, events.get());
1428 EXPECT_EQ(1u, events->size());
1429 EXPECT_EQ(Animation::Running,
1430 controller->GetAnimation(id, Animation::Opacity)->run_state());
1431 EXPECT_EQ(0.5f, pending_dummy.opacity());
1432 EXPECT_EQ(0.5f, dummy.opacity());
1434 // The animation should now tick past its starting point.
1435 controller->Animate(kInitialTickTime + 3.5);
1436 EXPECT_NE(0.5f, pending_dummy.opacity());
1437 EXPECT_NE(0.5f, dummy.opacity());
1440 TEST(LayerAnimationControllerTest, TransformAnimationBounds) {
1441 scoped_refptr<LayerAnimationController> controller_impl(
1442 LayerAnimationController::Create(0));
1444 scoped_ptr<KeyframedTransformAnimationCurve> curve1(
1445 KeyframedTransformAnimationCurve::Create());
1447 TransformOperations operations1;
1448 curve1->AddKeyframe(TransformKeyframe::Create(
1449 0.0, operations1, scoped_ptr<TimingFunction>()));
1450 operations1.AppendTranslate(10.0, 15.0, 0.0);
1451 curve1->AddKeyframe(TransformKeyframe::Create(
1452 1.0, operations1, scoped_ptr<TimingFunction>()));
1454 scoped_ptr<Animation> animation(Animation::Create(
1455 curve1.PassAs<AnimationCurve>(), 1, 1, Animation::Transform));
1456 controller_impl->AddAnimation(animation.Pass());
1458 scoped_ptr<KeyframedTransformAnimationCurve> curve2(
1459 KeyframedTransformAnimationCurve::Create());
1461 TransformOperations operations2;
1462 curve2->AddKeyframe(TransformKeyframe::Create(
1463 0.0, operations2, scoped_ptr<TimingFunction>()));
1464 operations2.AppendScale(2.0, 3.0, 4.0);
1465 curve2->AddKeyframe(TransformKeyframe::Create(
1466 1.0, operations2, scoped_ptr<TimingFunction>()));
1468 animation = Animation::Create(
1469 curve2.PassAs<AnimationCurve>(), 2, 2, Animation::Transform);
1470 controller_impl->AddAnimation(animation.Pass());
1472 gfx::BoxF box(1.f, 2.f, -1.f, 3.f, 4.f, 5.f);
1473 gfx::BoxF bounds;
1475 EXPECT_TRUE(controller_impl->TransformAnimationBoundsForBox(box, &bounds));
1476 EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 13.f, 19.f, 20.f).ToString(),
1477 bounds.ToString());
1479 controller_impl->GetAnimation(1, Animation::Transform)
1480 ->SetRunState(Animation::Finished, 0.0);
1482 // Only the unfinished animation should affect the animated bounds.
1483 EXPECT_TRUE(controller_impl->TransformAnimationBoundsForBox(box, &bounds));
1484 EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 7.f, 16.f, 20.f).ToString(),
1485 bounds.ToString());
1487 controller_impl->GetAnimation(2, Animation::Transform)
1488 ->SetRunState(Animation::Finished, 0.0);
1490 // There are no longer any running animations.
1491 EXPECT_FALSE(controller_impl->HasTransformAnimationThatInflatesBounds());
1493 // Add an animation whose bounds we don't yet support computing.
1494 scoped_ptr<KeyframedTransformAnimationCurve> curve3(
1495 KeyframedTransformAnimationCurve::Create());
1496 TransformOperations operations3;
1497 gfx::Transform transform3;
1498 transform3.Scale3d(1.0, 2.0, 3.0);
1499 curve3->AddKeyframe(TransformKeyframe::Create(
1500 0.0, operations3, scoped_ptr<TimingFunction>()));
1501 operations3.AppendMatrix(transform3);
1502 curve3->AddKeyframe(TransformKeyframe::Create(
1503 1.0, operations3, scoped_ptr<TimingFunction>()));
1504 animation = Animation::Create(
1505 curve3.PassAs<AnimationCurve>(), 3, 3, Animation::Transform);
1506 controller_impl->AddAnimation(animation.Pass());
1507 EXPECT_FALSE(controller_impl->TransformAnimationBoundsForBox(box, &bounds));
1510 // Tests that AbortAnimations aborts all animations targeting the specified
1511 // property.
1512 TEST(LayerAnimationControllerTest, AbortAnimations) {
1513 FakeLayerAnimationValueObserver dummy;
1514 scoped_refptr<LayerAnimationController> controller(
1515 LayerAnimationController::Create(0));
1516 controller->AddValueObserver(&dummy);
1518 // Start with several animations, and allow some of them to reach the finished
1519 // state.
1520 controller->AddAnimation(CreateAnimation(
1521 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)).Pass(),
1523 Animation::Transform));
1524 controller->AddAnimation(CreateAnimation(
1525 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1527 Animation::Opacity));
1528 controller->AddAnimation(CreateAnimation(
1529 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)).Pass(),
1531 Animation::Transform));
1532 controller->AddAnimation(CreateAnimation(
1533 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2.0)).Pass(),
1535 Animation::Transform));
1536 controller->AddAnimation(CreateAnimation(
1537 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1539 Animation::Opacity));
1541 controller->Animate(kInitialTickTime);
1542 controller->UpdateState(true, NULL);
1543 controller->Animate(kInitialTickTime + 1.0);
1544 controller->UpdateState(true, NULL);
1546 EXPECT_EQ(Animation::Finished,
1547 controller->GetAnimation(1, Animation::Transform)->run_state());
1548 EXPECT_EQ(Animation::Finished,
1549 controller->GetAnimation(2, Animation::Opacity)->run_state());
1550 EXPECT_EQ(Animation::Running,
1551 controller->GetAnimation(3, Animation::Transform)->run_state());
1552 EXPECT_EQ(Animation::WaitingForTargetAvailability,
1553 controller->GetAnimation(4, Animation::Transform)->run_state());
1554 EXPECT_EQ(Animation::Running,
1555 controller->GetAnimation(5, Animation::Opacity)->run_state());
1557 controller->AbortAnimations(Animation::Transform);
1559 // Only un-finished Transform animations should have been aborted.
1560 EXPECT_EQ(Animation::Finished,
1561 controller->GetAnimation(1, Animation::Transform)->run_state());
1562 EXPECT_EQ(Animation::Finished,
1563 controller->GetAnimation(2, Animation::Opacity)->run_state());
1564 EXPECT_EQ(Animation::Aborted,
1565 controller->GetAnimation(3, Animation::Transform)->run_state());
1566 EXPECT_EQ(Animation::Aborted,
1567 controller->GetAnimation(4, Animation::Transform)->run_state());
1568 EXPECT_EQ(Animation::Running,
1569 controller->GetAnimation(5, Animation::Opacity)->run_state());
1572 // An animation aborted on the main thread should get deleted on both threads.
1573 TEST(LayerAnimationControllerTest, MainThreadAbortedAnimationGetsDeleted) {
1574 FakeLayerAnimationValueObserver dummy_impl;
1575 scoped_refptr<LayerAnimationController> controller_impl(
1576 LayerAnimationController::Create(0));
1577 controller_impl->AddValueObserver(&dummy_impl);
1578 FakeLayerAnimationValueObserver dummy;
1579 scoped_refptr<LayerAnimationController> controller(
1580 LayerAnimationController::Create(0));
1581 controller->AddValueObserver(&dummy);
1583 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false);
1584 int group_id = controller->GetAnimation(Animation::Opacity)->group();
1586 controller->PushAnimationUpdatesTo(controller_impl.get());
1587 controller_impl->ActivateAnimations();
1588 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity));
1590 controller->AbortAnimations(Animation::Opacity);
1591 EXPECT_EQ(Animation::Aborted,
1592 controller->GetAnimation(Animation::Opacity)->run_state());
1593 EXPECT_FALSE(dummy.animation_waiting_for_deletion());
1594 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion());
1596 controller->Animate(kInitialTickTime);
1597 controller->UpdateState(true, NULL);
1598 EXPECT_TRUE(dummy.animation_waiting_for_deletion());
1599 EXPECT_EQ(Animation::WaitingForDeletion,
1600 controller->GetAnimation(Animation::Opacity)->run_state());
1602 controller->PushAnimationUpdatesTo(controller_impl.get());
1603 controller_impl->ActivateAnimations();
1604 EXPECT_FALSE(controller->GetAnimation(group_id, Animation::Opacity));
1605 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity));
1608 // An animation aborted on the impl thread should get deleted on both threads.
1609 TEST(LayerAnimationControllerTest, ImplThreadAbortedAnimationGetsDeleted) {
1610 FakeLayerAnimationValueObserver dummy_impl;
1611 scoped_refptr<LayerAnimationController> controller_impl(
1612 LayerAnimationController::Create(0));
1613 controller_impl->AddValueObserver(&dummy_impl);
1614 FakeLayerAnimationValueObserver dummy;
1615 scoped_refptr<LayerAnimationController> controller(
1616 LayerAnimationController::Create(0));
1617 controller->AddValueObserver(&dummy);
1619 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false);
1620 int group_id = controller->GetAnimation(Animation::Opacity)->group();
1622 controller->PushAnimationUpdatesTo(controller_impl.get());
1623 controller_impl->ActivateAnimations();
1624 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity));
1626 controller_impl->AbortAnimations(Animation::Opacity);
1627 EXPECT_EQ(Animation::Aborted,
1628 controller_impl->GetAnimation(Animation::Opacity)->run_state());
1629 EXPECT_FALSE(dummy.animation_waiting_for_deletion());
1630 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion());
1632 AnimationEventsVector events;
1633 controller_impl->Animate(kInitialTickTime);
1634 controller_impl->UpdateState(true, &events);
1635 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion());
1636 EXPECT_EQ(1u, events.size());
1637 EXPECT_EQ(AnimationEvent::Aborted, events[0].type);
1638 EXPECT_EQ(Animation::WaitingForDeletion,
1639 controller_impl->GetAnimation(Animation::Opacity)->run_state());
1641 controller->NotifyAnimationAborted(events[0]);
1642 EXPECT_EQ(Animation::Aborted,
1643 controller->GetAnimation(Animation::Opacity)->run_state());
1645 controller->Animate(kInitialTickTime + 0.5);
1646 controller->UpdateState(true, NULL);
1647 EXPECT_TRUE(dummy.animation_waiting_for_deletion());
1648 EXPECT_EQ(Animation::WaitingForDeletion,
1649 controller->GetAnimation(Animation::Opacity)->run_state());
1651 controller->PushAnimationUpdatesTo(controller_impl.get());
1652 controller_impl->ActivateAnimations();
1653 EXPECT_FALSE(controller->GetAnimation(group_id, Animation::Opacity));
1654 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity));
1657 // Ensure that we only generate Finished events for animations in a group
1658 // once all animations in that group are finished.
1659 TEST(LayerAnimationControllerTest, FinishedEventsForGroup) {
1660 scoped_ptr<AnimationEventsVector> events(
1661 make_scoped_ptr(new AnimationEventsVector));
1662 FakeLayerAnimationValueObserver dummy_impl;
1663 scoped_refptr<LayerAnimationController> controller_impl(
1664 LayerAnimationController::Create(0));
1665 controller_impl->AddValueObserver(&dummy_impl);
1667 // Add two animations with the same group id but different durations.
1668 controller_impl->AddAnimation(CreateAnimation(
1669 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2.0)).Pass(),
1671 Animation::Transform));
1672 controller_impl->AddAnimation(CreateAnimation(
1673 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1675 Animation::Opacity));
1677 controller_impl->Animate(kInitialTickTime);
1678 controller_impl->UpdateState(true, events.get());
1680 // Both animations should have started.
1681 EXPECT_EQ(2u, events->size());
1682 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type);
1683 EXPECT_EQ(AnimationEvent::Started, (*events)[1].type);
1685 events.reset(new AnimationEventsVector);
1686 controller_impl->Animate(kInitialTickTime + 1.0);
1687 controller_impl->UpdateState(true, events.get());
1689 // The opacity animation should be finished, but should not have generated
1690 // a Finished event yet.
1691 EXPECT_EQ(0u, events->size());
1692 EXPECT_EQ(Animation::Finished,
1693 controller_impl->GetAnimation(1, Animation::Opacity)->run_state());
1694 EXPECT_EQ(Animation::Running,
1695 controller_impl->GetAnimation(1,
1696 Animation::Transform)->run_state());
1698 controller_impl->Animate(kInitialTickTime + 2.0);
1699 controller_impl->UpdateState(true, events.get());
1701 // Both animations should have generated Finished events.
1702 EXPECT_EQ(2u, events->size());
1703 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type);
1704 EXPECT_EQ(AnimationEvent::Finished, (*events)[1].type);
1707 // Ensure that when a group has a mix of aborted and finished animations,
1708 // we generate a Finished event for the finished animation and an Aborted
1709 // event for the aborted animation.
1710 TEST(LayerAnimationControllerTest, FinishedAndAbortedEventsForGroup) {
1711 scoped_ptr<AnimationEventsVector> events(
1712 make_scoped_ptr(new AnimationEventsVector));
1713 FakeLayerAnimationValueObserver dummy_impl;
1714 scoped_refptr<LayerAnimationController> controller_impl(
1715 LayerAnimationController::Create(0));
1716 controller_impl->AddValueObserver(&dummy_impl);
1718 // Add two animations with the same group id.
1719 controller_impl->AddAnimation(CreateAnimation(
1720 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)).Pass(),
1722 Animation::Transform));
1723 controller_impl->AddAnimation(CreateAnimation(
1724 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1726 Animation::Opacity));
1728 controller_impl->Animate(kInitialTickTime);
1729 controller_impl->UpdateState(true, events.get());
1731 // Both animations should have started.
1732 EXPECT_EQ(2u, events->size());
1733 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type);
1734 EXPECT_EQ(AnimationEvent::Started, (*events)[1].type);
1736 controller_impl->AbortAnimations(Animation::Opacity);
1738 events.reset(new AnimationEventsVector);
1739 controller_impl->Animate(kInitialTickTime + 1.0);
1740 controller_impl->UpdateState(true, events.get());
1742 // We should have exactly 2 events: a Finished event for the tranform
1743 // animation, and an Aborted event for the opacity animation.
1744 EXPECT_EQ(2u, events->size());
1745 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type);
1746 EXPECT_EQ(Animation::Transform, (*events)[0].target_property);
1747 EXPECT_EQ(AnimationEvent::Aborted, (*events)[1].type);
1748 EXPECT_EQ(Animation::Opacity, (*events)[1].target_property);
1751 TEST(LayerAnimationControllerTest, HasAnimationThatAffectsScale) {
1752 scoped_refptr<LayerAnimationController> controller_impl(
1753 LayerAnimationController::Create(0));
1755 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale());
1757 controller_impl->AddAnimation(CreateAnimation(
1758 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1760 Animation::Opacity));
1762 // Opacity animations don't affect scale.
1763 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale());
1765 scoped_ptr<KeyframedTransformAnimationCurve> curve1(
1766 KeyframedTransformAnimationCurve::Create());
1768 TransformOperations operations1;
1769 curve1->AddKeyframe(TransformKeyframe::Create(
1770 0.0, operations1, scoped_ptr<TimingFunction>()));
1771 operations1.AppendTranslate(10.0, 15.0, 0.0);
1772 curve1->AddKeyframe(TransformKeyframe::Create(
1773 1.0, operations1, scoped_ptr<TimingFunction>()));
1775 scoped_ptr<Animation> animation(Animation::Create(
1776 curve1.PassAs<AnimationCurve>(), 2, 2, Animation::Transform));
1777 controller_impl->AddAnimation(animation.Pass());
1779 // Translations don't affect scale.
1780 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale());
1782 scoped_ptr<KeyframedTransformAnimationCurve> curve2(
1783 KeyframedTransformAnimationCurve::Create());
1785 TransformOperations operations2;
1786 curve2->AddKeyframe(TransformKeyframe::Create(
1787 0.0, operations2, scoped_ptr<TimingFunction>()));
1788 operations2.AppendScale(2.0, 3.0, 4.0);
1789 curve2->AddKeyframe(TransformKeyframe::Create(
1790 1.0, operations2, scoped_ptr<TimingFunction>()));
1792 animation = Animation::Create(
1793 curve2.PassAs<AnimationCurve>(), 3, 3, Animation::Transform);
1794 controller_impl->AddAnimation(animation.Pass());
1796 EXPECT_TRUE(controller_impl->HasAnimationThatAffectsScale());
1798 controller_impl->GetAnimation(3, Animation::Transform)
1799 ->SetRunState(Animation::Finished, 0.0);
1801 // Only unfinished animations should be considered by
1802 // HasAnimationThatAffectsScale.
1803 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale());
1806 TEST(LayerAnimationControllerTest, HasOnlyTranslationTransforms) {
1807 scoped_refptr<LayerAnimationController> controller_impl(
1808 LayerAnimationController::Create(0));
1810 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms());
1812 controller_impl->AddAnimation(CreateAnimation(
1813 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1815 Animation::Opacity));
1817 // Opacity animations aren't non-translation transforms.
1818 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms());
1820 scoped_ptr<KeyframedTransformAnimationCurve> curve1(
1821 KeyframedTransformAnimationCurve::Create());
1823 TransformOperations operations1;
1824 curve1->AddKeyframe(TransformKeyframe::Create(
1825 0.0, operations1, scoped_ptr<TimingFunction>()));
1826 operations1.AppendTranslate(10.0, 15.0, 0.0);
1827 curve1->AddKeyframe(TransformKeyframe::Create(
1828 1.0, operations1, scoped_ptr<TimingFunction>()));
1830 scoped_ptr<Animation> animation(Animation::Create(
1831 curve1.PassAs<AnimationCurve>(), 2, 2, Animation::Transform));
1832 controller_impl->AddAnimation(animation.Pass());
1834 // The only transform animation we've added is a translation.
1835 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms());
1837 scoped_ptr<KeyframedTransformAnimationCurve> curve2(
1838 KeyframedTransformAnimationCurve::Create());
1840 TransformOperations operations2;
1841 curve2->AddKeyframe(TransformKeyframe::Create(
1842 0.0, operations2, scoped_ptr<TimingFunction>()));
1843 operations2.AppendScale(2.0, 3.0, 4.0);
1844 curve2->AddKeyframe(TransformKeyframe::Create(
1845 1.0, operations2, scoped_ptr<TimingFunction>()));
1847 animation = Animation::Create(
1848 curve2.PassAs<AnimationCurve>(), 3, 3, Animation::Transform);
1849 controller_impl->AddAnimation(animation.Pass());
1851 // A scale animation is not a translation.
1852 EXPECT_FALSE(controller_impl->HasOnlyTranslationTransforms());
1854 controller_impl->GetAnimation(3, Animation::Transform)
1855 ->SetRunState(Animation::Finished, 0.0);
1857 // Only unfinished animations should be considered by
1858 // HasOnlyTranslationTransforms.
1859 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms());
1862 TEST(LayerAnimationControllerTest, MaximumScale) {
1863 scoped_refptr<LayerAnimationController> controller_impl(
1864 LayerAnimationController::Create(0));
1866 float max_scale = 0.f;
1867 EXPECT_TRUE(controller_impl->MaximumScale(&max_scale));
1868 EXPECT_EQ(0.f, max_scale);
1870 scoped_ptr<KeyframedTransformAnimationCurve> curve1(
1871 KeyframedTransformAnimationCurve::Create());
1873 TransformOperations operations1;
1874 curve1->AddKeyframe(TransformKeyframe::Create(
1875 0.0, operations1, scoped_ptr<TimingFunction>()));
1876 operations1.AppendScale(2.0, 3.0, 4.0);
1877 curve1->AddKeyframe(TransformKeyframe::Create(
1878 1.0, operations1, scoped_ptr<TimingFunction>()));
1880 scoped_ptr<Animation> animation(Animation::Create(
1881 curve1.PassAs<AnimationCurve>(), 1, 1, Animation::Transform));
1882 controller_impl->AddAnimation(animation.Pass());
1884 EXPECT_TRUE(controller_impl->MaximumScale(&max_scale));
1885 EXPECT_EQ(4.f, max_scale);
1887 scoped_ptr<KeyframedTransformAnimationCurve> curve2(
1888 KeyframedTransformAnimationCurve::Create());
1890 TransformOperations operations2;
1891 curve2->AddKeyframe(TransformKeyframe::Create(
1892 0.0, operations2, scoped_ptr<TimingFunction>()));
1893 operations2.AppendScale(6.0, 5.0, 4.0);
1894 curve2->AddKeyframe(TransformKeyframe::Create(
1895 1.0, operations2, scoped_ptr<TimingFunction>()));
1897 animation = Animation::Create(
1898 curve2.PassAs<AnimationCurve>(), 2, 2, Animation::Transform);
1899 controller_impl->AddAnimation(animation.Pass());
1901 EXPECT_TRUE(controller_impl->MaximumScale(&max_scale));
1902 EXPECT_EQ(6.f, max_scale);
1904 scoped_ptr<KeyframedTransformAnimationCurve> curve3(
1905 KeyframedTransformAnimationCurve::Create());
1907 TransformOperations operations3;
1908 curve3->AddKeyframe(TransformKeyframe::Create(
1909 0.0, operations3, scoped_ptr<TimingFunction>()));
1910 operations3.AppendPerspective(6.0);
1911 curve3->AddKeyframe(TransformKeyframe::Create(
1912 1.0, operations3, scoped_ptr<TimingFunction>()));
1914 animation = Animation::Create(
1915 curve3.PassAs<AnimationCurve>(), 3, 3, Animation::Transform);
1916 controller_impl->AddAnimation(animation.Pass());
1918 EXPECT_FALSE(controller_impl->MaximumScale(&max_scale));
1920 controller_impl->GetAnimation(3, Animation::Transform)
1921 ->SetRunState(Animation::Finished, 0.0);
1922 controller_impl->GetAnimation(2, Animation::Transform)
1923 ->SetRunState(Animation::Finished, 0.0);
1925 // Only unfinished animations should be considered by
1926 // MaximumScale.
1927 EXPECT_TRUE(controller_impl->MaximumScale(&max_scale));
1928 EXPECT_EQ(4.f, max_scale);
1931 TEST(LayerAnimationControllerTest, NewlyPushedAnimationWaitsForActivation) {
1932 scoped_ptr<AnimationEventsVector> events(
1933 make_scoped_ptr(new AnimationEventsVector));
1934 FakeLayerAnimationValueObserver dummy_impl;
1935 FakeInactiveLayerAnimationValueObserver pending_dummy_impl;
1936 scoped_refptr<LayerAnimationController> controller_impl(
1937 LayerAnimationController::Create(0));
1938 controller_impl->AddValueObserver(&dummy_impl);
1939 controller_impl->AddValueObserver(&pending_dummy_impl);
1940 FakeLayerAnimationValueObserver dummy;
1941 scoped_refptr<LayerAnimationController> controller(
1942 LayerAnimationController::Create(0));
1943 controller->AddValueObserver(&dummy);
1945 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, false);
1946 int group_id = controller->GetAnimation(Animation::Opacity)->group();
1948 controller->PushAnimationUpdatesTo(controller_impl.get());
1950 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity));
1951 EXPECT_EQ(
1952 Animation::WaitingForTargetAvailability,
1953 controller_impl->GetAnimation(group_id, Animation::Opacity)->run_state());
1954 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)
1955 ->affects_pending_observers());
1956 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity)
1957 ->affects_active_observers());
1959 controller_impl->Animate(kInitialTickTime);
1960 controller_impl->UpdateState(true, events.get());
1962 // Since the animation hasn't been activated, it should still be Starting
1963 // rather than Running.
1964 EXPECT_EQ(
1965 Animation::Starting,
1966 controller_impl->GetAnimation(group_id, Animation::Opacity)->run_state());
1968 // Since the animation hasn't been activated, only the pending observer
1969 // should have been ticked.
1970 EXPECT_EQ(0.5f, pending_dummy_impl.opacity());
1971 EXPECT_EQ(0.f, dummy_impl.opacity());
1973 controller_impl->ActivateAnimations();
1974 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)
1975 ->affects_pending_observers());
1976 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)
1977 ->affects_active_observers());
1979 controller_impl->Animate(kInitialTickTime + 1.0);
1980 controller_impl->UpdateState(true, events.get());
1982 // Since the animation has been activated, it should have reached the
1983 // Running state and the active observer should start to get ticked.
1984 EXPECT_EQ(
1985 Animation::Running,
1986 controller_impl->GetAnimation(group_id, Animation::Opacity)->run_state());
1987 EXPECT_EQ(0.5f, pending_dummy_impl.opacity());
1988 EXPECT_EQ(0.5f, dummy_impl.opacity());
1991 TEST(LayerAnimationControllerTest, ActivationBetweenAnimateAndUpdateState) {
1992 scoped_ptr<AnimationEventsVector> events(
1993 make_scoped_ptr(new AnimationEventsVector));
1994 FakeLayerAnimationValueObserver dummy_impl;
1995 FakeInactiveLayerAnimationValueObserver pending_dummy_impl;
1996 scoped_refptr<LayerAnimationController> controller_impl(
1997 LayerAnimationController::Create(0));
1998 controller_impl->AddValueObserver(&dummy_impl);
1999 controller_impl->AddValueObserver(&pending_dummy_impl);
2000 FakeLayerAnimationValueObserver dummy;
2001 scoped_refptr<LayerAnimationController> controller(
2002 LayerAnimationController::Create(0));
2003 controller->AddValueObserver(&dummy);
2005 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, true);
2006 int group_id = controller->GetAnimation(Animation::Opacity)->group();
2008 controller->PushAnimationUpdatesTo(controller_impl.get());
2010 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity));
2011 EXPECT_EQ(
2012 Animation::WaitingForTargetAvailability,
2013 controller_impl->GetAnimation(group_id, Animation::Opacity)->run_state());
2014 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)
2015 ->affects_pending_observers());
2016 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity)
2017 ->affects_active_observers());
2019 controller_impl->Animate(kInitialTickTime);
2021 // Since the animation hasn't been activated, only the pending observer
2022 // should have been ticked.
2023 EXPECT_EQ(0.5f, pending_dummy_impl.opacity());
2024 EXPECT_EQ(0.f, dummy_impl.opacity());
2026 controller_impl->ActivateAnimations();
2027 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)
2028 ->affects_pending_observers());
2029 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)
2030 ->affects_active_observers());
2032 controller_impl->UpdateState(true, events.get());
2034 // Since the animation has been activated, it should have reached the
2035 // Running state.
2036 EXPECT_EQ(
2037 Animation::Running,
2038 controller_impl->GetAnimation(group_id, Animation::Opacity)->run_state());
2040 controller_impl->Animate(kInitialTickTime + 0.5);
2042 // Both observers should have been ticked.
2043 EXPECT_EQ(0.75f, pending_dummy_impl.opacity());
2044 EXPECT_EQ(0.75f, dummy_impl.opacity());
2047 TEST(LayerAnimationControllerTest, PushedDeletedAnimationWaitsForActivation) {
2048 scoped_ptr<AnimationEventsVector> events(
2049 make_scoped_ptr(new AnimationEventsVector));
2050 FakeLayerAnimationValueObserver dummy_impl;
2051 FakeInactiveLayerAnimationValueObserver pending_dummy_impl;
2052 scoped_refptr<LayerAnimationController> controller_impl(
2053 LayerAnimationController::Create(0));
2054 controller_impl->AddValueObserver(&dummy_impl);
2055 controller_impl->AddValueObserver(&pending_dummy_impl);
2056 FakeLayerAnimationValueObserver dummy;
2057 scoped_refptr<LayerAnimationController> controller(
2058 LayerAnimationController::Create(0));
2059 controller->AddValueObserver(&dummy);
2061 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, true);
2062 int group_id = controller->GetAnimation(Animation::Opacity)->group();
2064 controller->PushAnimationUpdatesTo(controller_impl.get());
2065 controller_impl->ActivateAnimations();
2066 controller_impl->Animate(kInitialTickTime);
2067 controller_impl->UpdateState(true, events.get());
2068 EXPECT_EQ(
2069 Animation::Running,
2070 controller_impl->GetAnimation(group_id, Animation::Opacity)->run_state());
2071 EXPECT_EQ(0.5f, pending_dummy_impl.opacity());
2072 EXPECT_EQ(0.5f, dummy_impl.opacity());
2074 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)
2075 ->affects_pending_observers());
2076 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)
2077 ->affects_active_observers());
2079 // Delete the animation on the main-thread controller.
2080 controller->RemoveAnimation(
2081 controller->GetAnimation(Animation::Opacity)->id());
2082 controller->PushAnimationUpdatesTo(controller_impl.get());
2084 // The animation should no longer affect pending observers.
2085 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity)
2086 ->affects_pending_observers());
2087 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)
2088 ->affects_active_observers());
2090 controller_impl->Animate(kInitialTickTime + 0.5);
2091 controller_impl->UpdateState(true, events.get());
2093 // Only the active observer should have been ticked.
2094 EXPECT_EQ(0.5f, pending_dummy_impl.opacity());
2095 EXPECT_EQ(0.75f, dummy_impl.opacity());
2097 controller_impl->ActivateAnimations();
2099 // Activation should cause the animation to be deleted.
2100 EXPECT_FALSE(controller_impl->has_any_animation());
2103 // Tests that an animation that affects only active observers won't block
2104 // an animation that affects only pending observers from starting.
2105 TEST(LayerAnimationControllerTest, StartAnimationsAffectingDifferentObservers) {
2106 scoped_ptr<AnimationEventsVector> events(
2107 make_scoped_ptr(new AnimationEventsVector));
2108 FakeLayerAnimationValueObserver dummy_impl;
2109 FakeInactiveLayerAnimationValueObserver pending_dummy_impl;
2110 scoped_refptr<LayerAnimationController> controller_impl(
2111 LayerAnimationController::Create(0));
2112 controller_impl->AddValueObserver(&dummy_impl);
2113 controller_impl->AddValueObserver(&pending_dummy_impl);
2114 FakeLayerAnimationValueObserver dummy;
2115 scoped_refptr<LayerAnimationController> controller(
2116 LayerAnimationController::Create(0));
2117 controller->AddValueObserver(&dummy);
2119 AddOpacityTransitionToController(controller.get(), 1, 0.f, 1.f, true);
2120 int first_animation_group_id =
2121 controller->GetAnimation(Animation::Opacity)->group();
2123 controller->PushAnimationUpdatesTo(controller_impl.get());
2124 controller_impl->ActivateAnimations();
2125 controller_impl->Animate(kInitialTickTime);
2126 controller_impl->UpdateState(true, events.get());
2128 // Remove the first animation from the main-thread controller, and add a
2129 // new animation affecting the same property.
2130 controller->RemoveAnimation(
2131 controller->GetAnimation(Animation::Opacity)->id());
2132 AddOpacityTransitionToController(controller.get(), 1, 1.f, 0.5f, true);
2133 int second_animation_group_id =
2134 controller->GetAnimation(Animation::Opacity)->group();
2135 controller->PushAnimationUpdatesTo(controller_impl.get());
2137 // The original animation should only affect active observers, and the new
2138 // animation should only affect pending observers.
2139 EXPECT_FALSE(controller_impl->GetAnimation(first_animation_group_id,
2140 Animation::Opacity)
2141 ->affects_pending_observers());
2142 EXPECT_TRUE(controller_impl->GetAnimation(first_animation_group_id,
2143 Animation::Opacity)
2144 ->affects_active_observers());
2145 EXPECT_TRUE(controller_impl->GetAnimation(second_animation_group_id,
2146 Animation::Opacity)
2147 ->affects_pending_observers());
2148 EXPECT_FALSE(controller_impl->GetAnimation(second_animation_group_id,
2149 Animation::Opacity)
2150 ->affects_active_observers());
2152 controller_impl->Animate(kInitialTickTime + 0.5);
2153 controller_impl->UpdateState(true, events.get());
2155 // The original animation should still be running, and the new animation
2156 // should be starting.
2157 EXPECT_EQ(Animation::Running,
2158 controller_impl->GetAnimation(first_animation_group_id,
2159 Animation::Opacity)->run_state());
2160 EXPECT_EQ(Animation::Starting,
2161 controller_impl->GetAnimation(second_animation_group_id,
2162 Animation::Opacity)->run_state());
2164 // The active observer should have been ticked by the original animation,
2165 // and the pending observer should have been ticked by the new animation.
2166 EXPECT_EQ(1.f, pending_dummy_impl.opacity());
2167 EXPECT_EQ(0.5f, dummy_impl.opacity());
2169 controller_impl->ActivateAnimations();
2171 // The original animation should have been deleted, and the new animation
2172 // should now affect both observers.
2173 EXPECT_FALSE(controller_impl->GetAnimation(first_animation_group_id,
2174 Animation::Opacity));
2175 EXPECT_TRUE(controller_impl->GetAnimation(second_animation_group_id,
2176 Animation::Opacity)
2177 ->affects_pending_observers());
2178 EXPECT_TRUE(controller_impl->GetAnimation(second_animation_group_id,
2179 Animation::Opacity)
2180 ->affects_active_observers());
2182 controller_impl->Animate(kInitialTickTime + 1.0);
2183 controller_impl->UpdateState(true, events.get());
2185 // The new animation should be running, and the active observer should have
2186 // been ticked at the new animation's starting point.
2187 EXPECT_EQ(Animation::Running,
2188 controller_impl->GetAnimation(second_animation_group_id,
2189 Animation::Opacity)->run_state());
2190 EXPECT_EQ(1.f, pending_dummy_impl.opacity());
2191 EXPECT_EQ(1.f, dummy_impl.opacity());
2194 } // namespace
2195 } // namespace cc