Currently duration is simply returned or changed without checking whether the stream...
[chromium-blink-merge.git] / cc / animation / layer_animation_controller_unittest.cc
blobf7918cd2bf32a00c19d65faec27329284138544f
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());
51 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity));
52 EXPECT_EQ(Animation::WaitingForTargetAvailability,
53 controller_impl->GetAnimation(group_id,
54 Animation::Opacity)->run_state());
57 // If an animation is started on the impl thread before it is ticked on the main
58 // thread, we must be sure to respect the synchronized start time.
59 TEST(LayerAnimationControllerTest, DoNotClobberStartTimes) {
60 FakeLayerAnimationValueObserver dummy_impl;
61 scoped_refptr<LayerAnimationController> controller_impl(
62 LayerAnimationController::Create(0));
63 controller_impl->AddValueObserver(&dummy_impl);
64 FakeLayerAnimationValueObserver dummy;
65 scoped_refptr<LayerAnimationController> controller(
66 LayerAnimationController::Create(0));
67 controller->AddValueObserver(&dummy);
69 EXPECT_FALSE(controller_impl->GetAnimation(Animation::Opacity));
71 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false);
72 int group_id = controller->GetAnimation(Animation::Opacity)->group();
74 controller->PushAnimationUpdatesTo(controller_impl.get());
76 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity));
77 EXPECT_EQ(Animation::WaitingForTargetAvailability,
78 controller_impl->GetAnimation(group_id,
79 Animation::Opacity)->run_state());
81 AnimationEventsVector events;
82 controller_impl->Animate(kInitialTickTime);
83 controller_impl->UpdateState(true, &events);
85 // Synchronize the start times.
86 EXPECT_EQ(1u, events.size());
87 controller->NotifyAnimationStarted(events[0], 0.0);
88 EXPECT_EQ(controller->GetAnimation(group_id,
89 Animation::Opacity)->start_time(),
90 controller_impl->GetAnimation(group_id,
91 Animation::Opacity)->start_time());
93 // Start the animation on the main thread. Should not affect the start time.
94 controller->Animate(kInitialTickTime + 0.5);
95 controller->UpdateState(true, NULL);
96 EXPECT_EQ(controller->GetAnimation(group_id,
97 Animation::Opacity)->start_time(),
98 controller_impl->GetAnimation(group_id,
99 Animation::Opacity)->start_time());
102 // Tests that controllers activate and deactivate as expected.
103 TEST(LayerAnimationControllerTest, Activation) {
104 scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::Create();
105 scoped_ptr<AnimationRegistrar> registrar_impl = AnimationRegistrar::Create();
107 FakeLayerAnimationValueObserver dummy_impl;
108 scoped_refptr<LayerAnimationController> controller_impl(
109 LayerAnimationController::Create(0));
110 controller_impl->AddValueObserver(&dummy_impl);
111 FakeLayerAnimationValueObserver dummy;
112 scoped_refptr<LayerAnimationController> controller(
113 LayerAnimationController::Create(0));
114 controller->AddValueObserver(&dummy);
115 scoped_ptr<AnimationEventsVector> events(
116 make_scoped_ptr(new AnimationEventsVector));
118 controller->SetAnimationRegistrar(registrar.get());
119 controller_impl->SetAnimationRegistrar(registrar_impl.get());
120 EXPECT_EQ(1u, registrar->all_animation_controllers().size());
121 EXPECT_EQ(1u, registrar_impl->all_animation_controllers().size());
123 // Initially, both controllers should be inactive.
124 EXPECT_EQ(0u, registrar->active_animation_controllers().size());
125 EXPECT_EQ(0u, registrar_impl->active_animation_controllers().size());
127 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false);
128 // The main thread controller should now be active.
129 EXPECT_EQ(1u, registrar->active_animation_controllers().size());
131 controller->PushAnimationUpdatesTo(controller_impl.get());
132 // Both controllers should now be active.
133 EXPECT_EQ(1u, registrar->active_animation_controllers().size());
134 EXPECT_EQ(1u, registrar_impl->active_animation_controllers().size());
136 controller_impl->Animate(kInitialTickTime);
137 controller_impl->UpdateState(true, events.get());
138 EXPECT_EQ(1u, events->size());
139 controller->NotifyAnimationStarted((*events)[0], 0.0);
141 EXPECT_EQ(1u, registrar->active_animation_controllers().size());
142 EXPECT_EQ(1u, registrar_impl->active_animation_controllers().size());
144 controller->Animate(kInitialTickTime + 0.5);
145 controller->UpdateState(true, NULL);
146 EXPECT_EQ(1u, registrar->active_animation_controllers().size());
148 controller->Animate(kInitialTickTime + 1.0);
149 controller->UpdateState(true, NULL);
150 EXPECT_EQ(Animation::Finished,
151 controller->GetAnimation(Animation::Opacity)->run_state());
152 EXPECT_EQ(1u, registrar->active_animation_controllers().size());
154 events.reset(new AnimationEventsVector);
155 controller_impl->Animate(kInitialTickTime + 1.5);
156 controller_impl->UpdateState(true, events.get());
158 EXPECT_EQ(Animation::WaitingForDeletion,
159 controller_impl->GetAnimation(Animation::Opacity)->run_state());
160 // The impl thread controller should have de-activated.
161 EXPECT_EQ(0u, registrar_impl->active_animation_controllers().size());
163 EXPECT_EQ(1u, events->size());
164 controller->NotifyAnimationFinished((*events)[0], 0.0);
165 controller->Animate(kInitialTickTime + 1.5);
166 controller->UpdateState(true, NULL);
168 EXPECT_EQ(Animation::WaitingForDeletion,
169 controller->GetAnimation(Animation::Opacity)->run_state());
170 // The main thread controller should have de-activated.
171 EXPECT_EQ(0u, registrar->active_animation_controllers().size());
173 controller->PushAnimationUpdatesTo(controller_impl.get());
174 EXPECT_FALSE(controller->has_any_animation());
175 EXPECT_FALSE(controller_impl->has_any_animation());
176 EXPECT_EQ(0u, registrar->active_animation_controllers().size());
177 EXPECT_EQ(0u, registrar_impl->active_animation_controllers().size());
179 controller->SetAnimationRegistrar(NULL);
180 controller_impl->SetAnimationRegistrar(NULL);
183 TEST(LayerAnimationControllerTest, SyncPause) {
184 FakeLayerAnimationValueObserver dummy_impl;
185 scoped_refptr<LayerAnimationController> controller_impl(
186 LayerAnimationController::Create(0));
187 controller_impl->AddValueObserver(&dummy_impl);
188 FakeLayerAnimationValueObserver dummy;
189 scoped_refptr<LayerAnimationController> controller(
190 LayerAnimationController::Create(0));
191 controller->AddValueObserver(&dummy);
193 EXPECT_FALSE(controller_impl->GetAnimation(Animation::Opacity));
195 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false);
196 int group_id = controller->GetAnimation(Animation::Opacity)->group();
197 int animation_id = controller->GetAnimation(Animation::Opacity)->id();
199 controller->PushAnimationUpdatesTo(controller_impl.get());
201 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity));
202 EXPECT_EQ(Animation::WaitingForTargetAvailability,
203 controller_impl->GetAnimation(group_id,
204 Animation::Opacity)->run_state());
206 // Start the animations on each controller.
207 AnimationEventsVector events;
208 controller_impl->Animate(kInitialTickTime);
209 controller_impl->UpdateState(true, &events);
210 controller->Animate(kInitialTickTime);
211 controller->UpdateState(true, NULL);
212 EXPECT_EQ(Animation::Running,
213 controller_impl->GetAnimation(group_id,
214 Animation::Opacity)->run_state());
215 EXPECT_EQ(Animation::Running,
216 controller->GetAnimation(group_id,
217 Animation::Opacity)->run_state());
219 // Pause the main-thread animation.
220 controller->PauseAnimation(animation_id, kInitialTickTime + 1.0);
221 EXPECT_EQ(Animation::Paused,
222 controller->GetAnimation(group_id,
223 Animation::Opacity)->run_state());
225 // The pause run state change should make it to the impl thread controller.
226 controller->PushAnimationUpdatesTo(controller_impl.get());
227 EXPECT_EQ(Animation::Paused,
228 controller_impl->GetAnimation(group_id,
229 Animation::Opacity)->run_state());
232 TEST(LayerAnimationControllerTest, DoNotSyncFinishedAnimation) {
233 FakeLayerAnimationValueObserver dummy_impl;
234 scoped_refptr<LayerAnimationController> controller_impl(
235 LayerAnimationController::Create(0));
236 controller_impl->AddValueObserver(&dummy_impl);
237 FakeLayerAnimationValueObserver dummy;
238 scoped_refptr<LayerAnimationController> controller(
239 LayerAnimationController::Create(0));
240 controller->AddValueObserver(&dummy);
242 EXPECT_FALSE(controller_impl->GetAnimation(Animation::Opacity));
244 int animation_id =
245 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false);
246 int group_id = controller->GetAnimation(Animation::Opacity)->group();
248 controller->PushAnimationUpdatesTo(controller_impl.get());
250 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity));
251 EXPECT_EQ(Animation::WaitingForTargetAvailability,
252 controller_impl->GetAnimation(group_id,
253 Animation::Opacity)->run_state());
255 // Notify main thread controller that the animation has started.
256 AnimationEvent animation_started_event(AnimationEvent::Started,
258 group_id,
259 Animation::Opacity,
260 kInitialTickTime);
261 controller->NotifyAnimationStarted(animation_started_event, 0.0);
263 // Force animation to complete on impl thread.
264 controller_impl->RemoveAnimation(animation_id);
266 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity));
268 controller->PushAnimationUpdatesTo(controller_impl.get());
270 // Even though the main thread has a 'new' animation, it should not be pushed
271 // because the animation has already completed on the impl thread.
272 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity));
275 // Ensure that a finished animation is eventually deleted by both the
276 // main-thread and the impl-thread controllers.
277 TEST(LayerAnimationControllerTest, AnimationsAreDeleted) {
278 FakeLayerAnimationValueObserver dummy;
279 FakeLayerAnimationValueObserver dummy_impl;
280 scoped_ptr<AnimationEventsVector> events(
281 make_scoped_ptr(new AnimationEventsVector));
282 scoped_refptr<LayerAnimationController> controller(
283 LayerAnimationController::Create(0));
284 scoped_refptr<LayerAnimationController> controller_impl(
285 LayerAnimationController::Create(0));
286 controller->AddValueObserver(&dummy);
287 controller_impl->AddValueObserver(&dummy_impl);
289 AddOpacityTransitionToController(controller.get(), 1.0, 0.0f, 1.0f, false);
290 controller->Animate(kInitialTickTime);
291 controller->UpdateState(true, NULL);
292 controller->PushAnimationUpdatesTo(controller_impl.get());
294 controller_impl->Animate(kInitialTickTime + 0.5);
295 controller_impl->UpdateState(true, events.get());
297 // There should be a Started event for the animation.
298 EXPECT_EQ(1u, events->size());
299 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type);
300 controller->NotifyAnimationStarted((*events)[0], 0.0);
302 controller->Animate(kInitialTickTime + 1.0);
303 controller->UpdateState(true, NULL);
305 EXPECT_FALSE(dummy.animation_waiting_for_deletion());
306 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion());
308 events.reset(new AnimationEventsVector);
309 controller_impl->Animate(kInitialTickTime + 2.0);
310 controller_impl->UpdateState(true, events.get());
312 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion());
314 // There should be a Finished event for the animation.
315 EXPECT_EQ(1u, events->size());
316 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type);
318 // Neither controller should have deleted the animation yet.
319 EXPECT_TRUE(controller->GetAnimation(Animation::Opacity));
320 EXPECT_TRUE(controller_impl->GetAnimation(Animation::Opacity));
322 controller->NotifyAnimationFinished((*events)[0], 0.0);
324 controller->Animate(kInitialTickTime + 3.0);
325 controller->UpdateState(true, NULL);
326 EXPECT_TRUE(dummy.animation_waiting_for_deletion());
328 controller->PushAnimationUpdatesTo(controller_impl.get());
330 // Both controllers should now have deleted the animation.
331 EXPECT_FALSE(controller->has_any_animation());
332 EXPECT_FALSE(controller_impl->has_any_animation());
335 // Tests that transitioning opacity from 0 to 1 works as expected.
337 static const AnimationEvent* GetMostRecentPropertyUpdateEvent(
338 const AnimationEventsVector* events) {
339 const AnimationEvent* event = 0;
340 for (size_t i = 0; i < events->size(); ++i)
341 if ((*events)[i].type == AnimationEvent::PropertyUpdate)
342 event = &(*events)[i];
344 return event;
347 TEST(LayerAnimationControllerTest, TrivialTransition) {
348 scoped_ptr<AnimationEventsVector> events(
349 make_scoped_ptr(new AnimationEventsVector));
350 FakeLayerAnimationValueObserver dummy;
351 scoped_refptr<LayerAnimationController> controller(
352 LayerAnimationController::Create(0));
353 controller->AddValueObserver(&dummy);
355 scoped_ptr<Animation> to_add(CreateAnimation(
356 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
358 Animation::Opacity));
360 controller->AddAnimation(to_add.Pass());
361 controller->Animate(kInitialTickTime);
362 controller->UpdateState(true, events.get());
363 EXPECT_TRUE(controller->HasActiveAnimation());
364 EXPECT_EQ(0.f, dummy.opacity());
365 // A non-impl-only animation should not generate property updates.
366 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get());
367 EXPECT_FALSE(event);
368 controller->Animate(kInitialTickTime + 1.0);
369 controller->UpdateState(true, events.get());
370 EXPECT_EQ(1.f, dummy.opacity());
371 EXPECT_FALSE(controller->HasActiveAnimation());
372 event = GetMostRecentPropertyUpdateEvent(events.get());
373 EXPECT_FALSE(event);
376 TEST(LayerAnimationControllerTest, TrivialTransitionOnImpl) {
377 scoped_ptr<AnimationEventsVector> events(
378 make_scoped_ptr(new AnimationEventsVector));
379 FakeLayerAnimationValueObserver dummy_impl;
380 scoped_refptr<LayerAnimationController> controller_impl(
381 LayerAnimationController::Create(0));
382 controller_impl->AddValueObserver(&dummy_impl);
384 scoped_ptr<Animation> to_add(CreateAnimation(
385 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
387 Animation::Opacity));
388 to_add->set_is_impl_only(true);
390 controller_impl->AddAnimation(to_add.Pass());
391 controller_impl->Animate(kInitialTickTime);
392 controller_impl->UpdateState(true, events.get());
393 EXPECT_TRUE(controller_impl->HasActiveAnimation());
394 EXPECT_EQ(0.f, dummy_impl.opacity());
395 EXPECT_EQ(2u, events->size());
396 const AnimationEvent* start_opacity_event =
397 GetMostRecentPropertyUpdateEvent(events.get());
398 EXPECT_EQ(0.f, start_opacity_event->opacity);
400 controller_impl->Animate(kInitialTickTime + 1.0);
401 controller_impl->UpdateState(true, events.get());
402 EXPECT_EQ(1.f, dummy_impl.opacity());
403 EXPECT_FALSE(controller_impl->HasActiveAnimation());
404 EXPECT_EQ(4u, events->size());
405 const AnimationEvent* end_opacity_event =
406 GetMostRecentPropertyUpdateEvent(events.get());
407 EXPECT_EQ(1.f, end_opacity_event->opacity);
410 TEST(LayerAnimationControllerTest, TrivialTransformOnImpl) {
411 scoped_ptr<AnimationEventsVector> events(
412 make_scoped_ptr(new AnimationEventsVector));
413 FakeLayerAnimationValueObserver dummy_impl;
414 scoped_refptr<LayerAnimationController> controller_impl(
415 LayerAnimationController::Create(0));
416 controller_impl->AddValueObserver(&dummy_impl);
418 // Choose different values for x and y to avoid coincidental values in the
419 // observed transforms.
420 const float delta_x = 3;
421 const float delta_y = 4;
423 scoped_ptr<KeyframedTransformAnimationCurve> curve(
424 KeyframedTransformAnimationCurve::Create());
426 // Create simple Transform animation.
427 TransformOperations operations;
428 curve->AddKeyframe(
429 TransformKeyframe::Create(0, operations, scoped_ptr<TimingFunction>()));
430 operations.AppendTranslate(delta_x, delta_y, 0);
431 curve->AddKeyframe(
432 TransformKeyframe::Create(1, operations, scoped_ptr<TimingFunction>()));
434 scoped_ptr<Animation> animation(Animation::Create(
435 curve.PassAs<AnimationCurve>(), 1, 0, Animation::Transform));
436 animation->set_is_impl_only(true);
437 controller_impl->AddAnimation(animation.Pass());
439 // Run animation.
440 controller_impl->Animate(kInitialTickTime);
441 controller_impl->UpdateState(true, events.get());
442 EXPECT_TRUE(controller_impl->HasActiveAnimation());
443 EXPECT_EQ(gfx::Transform(), dummy_impl.transform());
444 EXPECT_EQ(2u, events->size());
445 const AnimationEvent* start_transform_event =
446 GetMostRecentPropertyUpdateEvent(events.get());
447 ASSERT_TRUE(start_transform_event);
448 EXPECT_EQ(gfx::Transform(), start_transform_event->transform);
449 EXPECT_TRUE(start_transform_event->is_impl_only);
451 gfx::Transform expected_transform;
452 expected_transform.Translate(delta_x, delta_y);
454 controller_impl->Animate(kInitialTickTime + 1.0);
455 controller_impl->UpdateState(true, events.get());
456 EXPECT_EQ(expected_transform, dummy_impl.transform());
457 EXPECT_FALSE(controller_impl->HasActiveAnimation());
458 EXPECT_EQ(4u, events->size());
459 const AnimationEvent* end_transform_event =
460 GetMostRecentPropertyUpdateEvent(events.get());
461 EXPECT_EQ(expected_transform, end_transform_event->transform);
462 EXPECT_TRUE(end_transform_event->is_impl_only);
465 TEST(LayerAnimationControllerTest, FilterTransition) {
466 scoped_ptr<AnimationEventsVector> events(
467 make_scoped_ptr(new AnimationEventsVector));
468 FakeLayerAnimationValueObserver dummy;
469 scoped_refptr<LayerAnimationController> controller(
470 LayerAnimationController::Create(0));
471 controller->AddValueObserver(&dummy);
473 scoped_ptr<KeyframedFilterAnimationCurve> curve(
474 KeyframedFilterAnimationCurve::Create());
476 FilterOperations start_filters;
477 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f));
478 curve->AddKeyframe(
479 FilterKeyframe::Create(0, start_filters, scoped_ptr<TimingFunction>()));
480 FilterOperations end_filters;
481 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f));
482 curve->AddKeyframe(
483 FilterKeyframe::Create(1, end_filters, scoped_ptr<TimingFunction>()));
485 scoped_ptr<Animation> animation(Animation::Create(
486 curve.PassAs<AnimationCurve>(), 1, 0, Animation::Filter));
487 controller->AddAnimation(animation.Pass());
489 controller->Animate(kInitialTickTime);
490 controller->UpdateState(true, events.get());
491 EXPECT_TRUE(controller->HasActiveAnimation());
492 EXPECT_EQ(start_filters, dummy.filters());
493 // A non-impl-only animation should not generate property updates.
494 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get());
495 EXPECT_FALSE(event);
497 controller->Animate(kInitialTickTime + 0.5);
498 controller->UpdateState(true, events.get());
499 EXPECT_EQ(1u, dummy.filters().size());
500 EXPECT_EQ(FilterOperation::CreateBrightnessFilter(1.5f),
501 dummy.filters().at(0));
502 event = GetMostRecentPropertyUpdateEvent(events.get());
503 EXPECT_FALSE(event);
505 controller->Animate(kInitialTickTime + 1.0);
506 controller->UpdateState(true, events.get());
507 EXPECT_EQ(end_filters, dummy.filters());
508 EXPECT_FALSE(controller->HasActiveAnimation());
509 event = GetMostRecentPropertyUpdateEvent(events.get());
510 EXPECT_FALSE(event);
513 TEST(LayerAnimationControllerTest, FilterTransitionOnImplOnly) {
514 scoped_ptr<AnimationEventsVector> events(
515 make_scoped_ptr(new AnimationEventsVector));
516 FakeLayerAnimationValueObserver dummy_impl;
517 scoped_refptr<LayerAnimationController> controller_impl(
518 LayerAnimationController::Create(0));
519 controller_impl->AddValueObserver(&dummy_impl);
521 scoped_ptr<KeyframedFilterAnimationCurve> curve(
522 KeyframedFilterAnimationCurve::Create());
524 // Create simple Filter animation.
525 FilterOperations start_filters;
526 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f));
527 curve->AddKeyframe(
528 FilterKeyframe::Create(0, start_filters, scoped_ptr<TimingFunction>()));
529 FilterOperations end_filters;
530 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f));
531 curve->AddKeyframe(
532 FilterKeyframe::Create(1, end_filters, scoped_ptr<TimingFunction>()));
534 scoped_ptr<Animation> animation(Animation::Create(
535 curve.PassAs<AnimationCurve>(), 1, 0, Animation::Filter));
536 animation->set_is_impl_only(true);
537 controller_impl->AddAnimation(animation.Pass());
539 // Run animation.
540 controller_impl->Animate(kInitialTickTime);
541 controller_impl->UpdateState(true, events.get());
542 EXPECT_TRUE(controller_impl->HasActiveAnimation());
543 EXPECT_EQ(start_filters, dummy_impl.filters());
544 EXPECT_EQ(2u, events->size());
545 const AnimationEvent* start_filter_event =
546 GetMostRecentPropertyUpdateEvent(events.get());
547 EXPECT_TRUE(start_filter_event);
548 EXPECT_EQ(start_filters, start_filter_event->filters);
549 EXPECT_TRUE(start_filter_event->is_impl_only);
551 controller_impl->Animate(kInitialTickTime + 1.0);
552 controller_impl->UpdateState(true, events.get());
553 EXPECT_EQ(end_filters, dummy_impl.filters());
554 EXPECT_FALSE(controller_impl->HasActiveAnimation());
555 EXPECT_EQ(4u, events->size());
556 const AnimationEvent* end_filter_event =
557 GetMostRecentPropertyUpdateEvent(events.get());
558 EXPECT_TRUE(end_filter_event);
559 EXPECT_EQ(end_filters, end_filter_event->filters);
560 EXPECT_TRUE(end_filter_event->is_impl_only);
563 TEST(LayerAnimationControllerTest, ScrollOffsetTransition) {
564 FakeLayerAnimationValueObserver dummy_impl;
565 FakeLayerAnimationValueProvider dummy_provider_impl;
566 scoped_refptr<LayerAnimationController> controller_impl(
567 LayerAnimationController::Create(0));
568 controller_impl->AddValueObserver(&dummy_impl);
569 controller_impl->set_value_provider(&dummy_provider_impl);
570 scoped_ptr<AnimationEventsVector> events(
571 make_scoped_ptr(new AnimationEventsVector));
572 FakeLayerAnimationValueObserver dummy;
573 FakeLayerAnimationValueProvider dummy_provider;
574 scoped_refptr<LayerAnimationController> controller(
575 LayerAnimationController::Create(0));
576 controller->AddValueObserver(&dummy);
577 controller->set_value_provider(&dummy_provider);
579 gfx::Vector2dF initial_value(100.f, 300.f);
580 gfx::Vector2dF target_value(300.f, 200.f);
581 scoped_ptr<ScrollOffsetAnimationCurve> curve(
582 ScrollOffsetAnimationCurve::Create(
583 target_value,
584 EaseInOutTimingFunction::Create().Pass()));
586 scoped_ptr<Animation> animation(Animation::Create(
587 curve.PassAs<AnimationCurve>(), 1, 0, Animation::ScrollOffset));
588 animation->set_needs_synchronized_start_time(true);
589 controller->AddAnimation(animation.Pass());
591 dummy_provider_impl.set_scroll_offset(initial_value);
592 controller->PushAnimationUpdatesTo(controller_impl.get());
593 EXPECT_TRUE(controller_impl->GetAnimation(Animation::ScrollOffset));
594 double duration = controller_impl->GetAnimation(
595 Animation::ScrollOffset)->curve()->Duration();
597 EXPECT_EQ(
598 duration,
599 controller->GetAnimation(Animation::ScrollOffset)->curve()->Duration());
601 controller->Animate(kInitialTickTime);
602 controller->UpdateState(true, NULL);
603 EXPECT_TRUE(controller->HasActiveAnimation());
604 EXPECT_EQ(initial_value, dummy.scroll_offset());
606 controller_impl->Animate(kInitialTickTime);
607 controller_impl->UpdateState(true, events.get());
608 EXPECT_TRUE(controller_impl->HasActiveAnimation());
609 EXPECT_EQ(initial_value, dummy_impl.scroll_offset());
610 // Scroll offset animations should not generate property updates.
611 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get());
612 EXPECT_FALSE(event);
614 controller->NotifyAnimationStarted((*events)[0], 0.0);
615 controller->Animate(kInitialTickTime + duration/2.0);
616 controller->UpdateState(true, NULL);
617 EXPECT_TRUE(controller->HasActiveAnimation());
618 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), dummy.scroll_offset());
620 controller_impl->Animate(kInitialTickTime + duration/2.0);
621 controller_impl->UpdateState(true, events.get());
622 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f),
623 dummy_impl.scroll_offset());
624 event = GetMostRecentPropertyUpdateEvent(events.get());
625 EXPECT_FALSE(event);
627 controller_impl->Animate(kInitialTickTime + duration);
628 controller_impl->UpdateState(true, events.get());
629 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset());
630 EXPECT_FALSE(controller_impl->HasActiveAnimation());
631 event = GetMostRecentPropertyUpdateEvent(events.get());
632 EXPECT_FALSE(event);
634 controller->Animate(kInitialTickTime + duration);
635 controller->UpdateState(true, NULL);
636 EXPECT_VECTOR2DF_EQ(target_value, dummy.scroll_offset());
637 EXPECT_FALSE(controller->HasActiveAnimation());
640 // Ensure that when the impl controller doesn't have a value provider,
641 // the main-thread controller's value provider is used to obtain the intial
642 // scroll offset.
643 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionNoImplProvider) {
644 FakeLayerAnimationValueObserver dummy_impl;
645 scoped_refptr<LayerAnimationController> controller_impl(
646 LayerAnimationController::Create(0));
647 controller_impl->AddValueObserver(&dummy_impl);
648 scoped_ptr<AnimationEventsVector> events(
649 make_scoped_ptr(new AnimationEventsVector));
650 FakeLayerAnimationValueObserver dummy;
651 FakeLayerAnimationValueProvider dummy_provider;
652 scoped_refptr<LayerAnimationController> controller(
653 LayerAnimationController::Create(0));
654 controller->AddValueObserver(&dummy);
655 controller->set_value_provider(&dummy_provider);
657 gfx::Vector2dF initial_value(500.f, 100.f);
658 gfx::Vector2dF target_value(300.f, 200.f);
659 scoped_ptr<ScrollOffsetAnimationCurve> curve(
660 ScrollOffsetAnimationCurve::Create(
661 target_value,
662 EaseInOutTimingFunction::Create().Pass()));
664 scoped_ptr<Animation> animation(Animation::Create(
665 curve.PassAs<AnimationCurve>(), 1, 0, Animation::ScrollOffset));
666 animation->set_needs_synchronized_start_time(true);
667 controller->AddAnimation(animation.Pass());
669 dummy_provider.set_scroll_offset(initial_value);
670 controller->PushAnimationUpdatesTo(controller_impl.get());
671 EXPECT_TRUE(controller_impl->GetAnimation(Animation::ScrollOffset));
672 double duration = controller_impl->GetAnimation(
673 Animation::ScrollOffset)->curve()->Duration();
675 EXPECT_EQ(
676 duration,
677 controller->GetAnimation(Animation::ScrollOffset)->curve()->Duration());
679 controller->Animate(kInitialTickTime);
680 controller->UpdateState(true, NULL);
681 EXPECT_TRUE(controller->HasActiveAnimation());
682 EXPECT_EQ(initial_value, dummy.scroll_offset());
684 controller_impl->Animate(kInitialTickTime);
685 controller_impl->UpdateState(true, events.get());
686 EXPECT_TRUE(controller_impl->HasActiveAnimation());
687 EXPECT_EQ(initial_value, dummy_impl.scroll_offset());
688 // Scroll offset animations should not generate property updates.
689 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get());
690 EXPECT_FALSE(event);
692 controller->NotifyAnimationStarted((*events)[0], 0.0);
693 controller->Animate(kInitialTickTime + duration/2.0);
694 controller->UpdateState(true, NULL);
695 EXPECT_TRUE(controller->HasActiveAnimation());
696 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f), dummy.scroll_offset());
698 controller_impl->Animate(kInitialTickTime + duration/2.0);
699 controller_impl->UpdateState(true, events.get());
700 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f),
701 dummy_impl.scroll_offset());
702 event = GetMostRecentPropertyUpdateEvent(events.get());
703 EXPECT_FALSE(event);
705 controller_impl->Animate(kInitialTickTime + duration);
706 controller_impl->UpdateState(true, events.get());
707 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset());
708 EXPECT_FALSE(controller_impl->HasActiveAnimation());
709 event = GetMostRecentPropertyUpdateEvent(events.get());
710 EXPECT_FALSE(event);
712 controller->Animate(kInitialTickTime + duration);
713 controller->UpdateState(true, NULL);
714 EXPECT_VECTOR2DF_EQ(target_value, dummy.scroll_offset());
715 EXPECT_FALSE(controller->HasActiveAnimation());
718 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionOnImplOnly) {
719 FakeLayerAnimationValueObserver dummy_impl;
720 scoped_refptr<LayerAnimationController> controller_impl(
721 LayerAnimationController::Create(0));
722 controller_impl->AddValueObserver(&dummy_impl);
723 scoped_ptr<AnimationEventsVector> events(
724 make_scoped_ptr(new AnimationEventsVector));
726 gfx::Vector2dF initial_value(100.f, 300.f);
727 gfx::Vector2dF target_value(300.f, 200.f);
728 scoped_ptr<ScrollOffsetAnimationCurve> curve(
729 ScrollOffsetAnimationCurve::Create(
730 target_value,
731 EaseInOutTimingFunction::Create().Pass()));
732 curve->SetInitialValue(initial_value);
733 double duration = curve->Duration();
735 scoped_ptr<Animation> animation(Animation::Create(
736 curve.PassAs<AnimationCurve>(), 1, 0, Animation::ScrollOffset));
737 animation->set_is_impl_only(true);
738 controller_impl->AddAnimation(animation.Pass());
740 controller_impl->Animate(kInitialTickTime);
741 controller_impl->UpdateState(true, events.get());
742 EXPECT_TRUE(controller_impl->HasActiveAnimation());
743 EXPECT_EQ(initial_value, dummy_impl.scroll_offset());
744 // Scroll offset animations should not generate property updates.
745 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get());
746 EXPECT_FALSE(event);
748 controller_impl->Animate(kInitialTickTime + duration/2.0);
749 controller_impl->UpdateState(true, events.get());
750 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f),
751 dummy_impl.scroll_offset());
752 event = GetMostRecentPropertyUpdateEvent(events.get());
753 EXPECT_FALSE(event);
755 controller_impl->Animate(kInitialTickTime + duration);
756 controller_impl->UpdateState(true, events.get());
757 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset());
758 EXPECT_FALSE(controller_impl->HasActiveAnimation());
759 event = GetMostRecentPropertyUpdateEvent(events.get());
760 EXPECT_FALSE(event);
763 class FakeAnimationDelegate : public AnimationDelegate {
764 public:
765 FakeAnimationDelegate()
766 : started_(false),
767 finished_(false) {}
769 virtual void NotifyAnimationStarted(
770 double wall_clock_time,
771 base::TimeTicks monotonic_time,
772 Animation::TargetProperty target_property) OVERRIDE {
773 started_ = true;
776 virtual void NotifyAnimationFinished(
777 double wall_clock_time,
778 base::TimeTicks monotonic_time,
779 Animation::TargetProperty target_property) OVERRIDE {
780 finished_ = true;
783 bool started() { return started_; }
785 bool finished() { return finished_; }
787 private:
788 bool started_;
789 bool finished_;
792 // Tests that impl-only animations lead to start and finished notifications
793 // being sent to the main thread controller's animation delegate.
794 TEST(LayerAnimationControllerTest,
795 NotificationsForImplOnlyAnimationsAreSentToMainThreadDelegate) {
796 FakeLayerAnimationValueObserver dummy_impl;
797 scoped_refptr<LayerAnimationController> controller_impl(
798 LayerAnimationController::Create(0));
799 controller_impl->AddValueObserver(&dummy_impl);
800 scoped_ptr<AnimationEventsVector> events(
801 make_scoped_ptr(new AnimationEventsVector));
802 FakeLayerAnimationValueObserver dummy;
803 scoped_refptr<LayerAnimationController> controller(
804 LayerAnimationController::Create(0));
805 controller->AddValueObserver(&dummy);
806 FakeAnimationDelegate delegate;
807 controller->set_layer_animation_delegate(&delegate);
809 scoped_ptr<Animation> to_add(CreateAnimation(
810 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
812 Animation::Opacity));
813 to_add->set_is_impl_only(true);
814 controller_impl->AddAnimation(to_add.Pass());
816 controller_impl->Animate(kInitialTickTime);
817 controller_impl->UpdateState(true, events.get());
819 // We should receive 2 events (a started notification and a property update).
820 EXPECT_EQ(2u, events->size());
821 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type);
822 EXPECT_TRUE((*events)[0].is_impl_only);
823 EXPECT_EQ(AnimationEvent::PropertyUpdate, (*events)[1].type);
824 EXPECT_TRUE((*events)[1].is_impl_only);
826 // Passing on the start event to the main thread controller should cause the
827 // delegate to get notified.
828 EXPECT_FALSE(delegate.started());
829 controller->NotifyAnimationStarted((*events)[0], 0.0);
830 EXPECT_TRUE(delegate.started());
832 events.reset(new AnimationEventsVector);
833 controller_impl->Animate(kInitialTickTime + 1.0);
834 controller_impl->UpdateState(true, events.get());
836 // We should receive 2 events (a finished notification and a property update).
837 EXPECT_EQ(2u, events->size());
838 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type);
839 EXPECT_TRUE((*events)[0].is_impl_only);
840 EXPECT_EQ(AnimationEvent::PropertyUpdate, (*events)[1].type);
841 EXPECT_TRUE((*events)[1].is_impl_only);
843 // Passing on the finished event to the main thread controller should cause
844 // the delegate to get notified.
845 EXPECT_FALSE(delegate.finished());
846 controller->NotifyAnimationFinished((*events)[0], 0.0);
847 EXPECT_TRUE(delegate.finished());
850 // Tests animations that are waiting for a synchronized start time do not
851 // finish.
852 TEST(LayerAnimationControllerTest,
853 AnimationsWaitingForStartTimeDoNotFinishIfTheyOutwaitTheirFinish) {
854 scoped_ptr<AnimationEventsVector> events(
855 make_scoped_ptr(new AnimationEventsVector));
856 FakeLayerAnimationValueObserver dummy;
857 scoped_refptr<LayerAnimationController> controller(
858 LayerAnimationController::Create(0));
859 controller->AddValueObserver(&dummy);
861 scoped_ptr<Animation> to_add(CreateAnimation(
862 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
864 Animation::Opacity));
865 to_add->set_needs_synchronized_start_time(true);
867 // We should pause at the first keyframe indefinitely waiting for that
868 // animation to start.
869 controller->AddAnimation(to_add.Pass());
870 controller->Animate(kInitialTickTime);
871 controller->UpdateState(true, events.get());
872 EXPECT_TRUE(controller->HasActiveAnimation());
873 EXPECT_EQ(0.f, dummy.opacity());
874 controller->Animate(kInitialTickTime + 1.0);
875 controller->UpdateState(true, events.get());
876 EXPECT_TRUE(controller->HasActiveAnimation());
877 EXPECT_EQ(0.f, dummy.opacity());
878 controller->Animate(kInitialTickTime + 2.0);
879 controller->UpdateState(true, events.get());
880 EXPECT_TRUE(controller->HasActiveAnimation());
881 EXPECT_EQ(0.f, dummy.opacity());
883 // Send the synchronized start time.
884 controller->NotifyAnimationStarted(AnimationEvent(AnimationEvent::Started,
887 Animation::Opacity,
888 kInitialTickTime + 2),
889 0.0);
890 controller->Animate(kInitialTickTime + 5.0);
891 controller->UpdateState(true, events.get());
892 EXPECT_EQ(1.f, dummy.opacity());
893 EXPECT_FALSE(controller->HasActiveAnimation());
896 // Tests that two queued animations affecting the same property run in sequence.
897 TEST(LayerAnimationControllerTest, TrivialQueuing) {
898 scoped_ptr<AnimationEventsVector> events(
899 make_scoped_ptr(new AnimationEventsVector));
900 FakeLayerAnimationValueObserver dummy;
901 scoped_refptr<LayerAnimationController> controller(
902 LayerAnimationController::Create(0));
903 controller->AddValueObserver(&dummy);
905 controller->AddAnimation(CreateAnimation(
906 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
908 Animation::Opacity));
909 controller->AddAnimation(CreateAnimation(
910 scoped_ptr<AnimationCurve>(
911 new FakeFloatTransition(1.0, 1.f, 0.5f)).Pass(),
913 Animation::Opacity));
915 controller->Animate(kInitialTickTime);
916 controller->UpdateState(true, events.get());
917 EXPECT_TRUE(controller->HasActiveAnimation());
918 EXPECT_EQ(0.f, dummy.opacity());
919 controller->Animate(kInitialTickTime + 1.0);
920 controller->UpdateState(true, events.get());
921 EXPECT_TRUE(controller->HasActiveAnimation());
922 EXPECT_EQ(1.f, dummy.opacity());
923 controller->Animate(kInitialTickTime + 2.0);
924 controller->UpdateState(true, events.get());
925 EXPECT_EQ(0.5f, dummy.opacity());
926 EXPECT_FALSE(controller->HasActiveAnimation());
929 // Tests interrupting a transition with another transition.
930 TEST(LayerAnimationControllerTest, Interrupt) {
931 scoped_ptr<AnimationEventsVector> events(
932 make_scoped_ptr(new AnimationEventsVector));
933 FakeLayerAnimationValueObserver dummy;
934 scoped_refptr<LayerAnimationController> controller(
935 LayerAnimationController::Create(0));
936 controller->AddValueObserver(&dummy);
937 controller->AddAnimation(CreateAnimation(
938 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
940 Animation::Opacity));
941 controller->Animate(kInitialTickTime);
942 controller->UpdateState(true, events.get());
943 EXPECT_TRUE(controller->HasActiveAnimation());
944 EXPECT_EQ(0.f, dummy.opacity());
946 scoped_ptr<Animation> to_add(CreateAnimation(
947 scoped_ptr<AnimationCurve>(
948 new FakeFloatTransition(1.0, 1.f, 0.5f)).Pass(),
950 Animation::Opacity));
951 controller->AbortAnimations(Animation::Opacity);
952 controller->AddAnimation(to_add.Pass());
954 // Since the previous animation was aborted, the new animation should start
955 // right in this call to animate.
956 controller->Animate(kInitialTickTime + 0.5);
957 controller->UpdateState(true, events.get());
958 EXPECT_TRUE(controller->HasActiveAnimation());
959 EXPECT_EQ(1.f, dummy.opacity());
960 controller->Animate(kInitialTickTime + 1.5);
961 controller->UpdateState(true, events.get());
962 EXPECT_EQ(0.5f, dummy.opacity());
963 EXPECT_FALSE(controller->HasActiveAnimation());
966 // Tests scheduling two animations to run together when only one property is
967 // free.
968 TEST(LayerAnimationControllerTest, ScheduleTogetherWhenAPropertyIsBlocked) {
969 scoped_ptr<AnimationEventsVector> events(
970 make_scoped_ptr(new AnimationEventsVector));
971 FakeLayerAnimationValueObserver dummy;
972 scoped_refptr<LayerAnimationController> controller(
973 LayerAnimationController::Create(0));
974 controller->AddValueObserver(&dummy);
976 controller->AddAnimation(CreateAnimation(
977 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(),
979 Animation::Transform));
980 controller->AddAnimation(CreateAnimation(
981 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(),
983 Animation::Transform));
984 controller->AddAnimation(CreateAnimation(
985 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
987 Animation::Opacity));
989 controller->Animate(kInitialTickTime);
990 controller->UpdateState(true, events.get());
991 EXPECT_EQ(0.f, dummy.opacity());
992 EXPECT_TRUE(controller->HasActiveAnimation());
993 controller->Animate(kInitialTickTime + 1.0);
994 controller->UpdateState(true, events.get());
995 // Should not have started the float transition yet.
996 EXPECT_TRUE(controller->HasActiveAnimation());
997 EXPECT_EQ(0.f, dummy.opacity());
998 // The float animation should have started at time 1 and should be done.
999 controller->Animate(kInitialTickTime + 2.0);
1000 controller->UpdateState(true, events.get());
1001 EXPECT_EQ(1.f, dummy.opacity());
1002 EXPECT_FALSE(controller->HasActiveAnimation());
1005 // Tests scheduling two animations to run together with different lengths and
1006 // another animation queued to start when the shorter animation finishes (should
1007 // wait for both to finish).
1008 TEST(LayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting) {
1009 scoped_ptr<AnimationEventsVector> events(
1010 make_scoped_ptr(new AnimationEventsVector));
1011 FakeLayerAnimationValueObserver dummy;
1012 scoped_refptr<LayerAnimationController> controller(
1013 LayerAnimationController::Create(0));
1014 controller->AddValueObserver(&dummy);
1016 controller->AddAnimation(CreateAnimation(
1017 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2)).Pass(),
1019 Animation::Transform));
1020 controller->AddAnimation(CreateAnimation(
1021 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1023 Animation::Opacity));
1024 controller->AddAnimation(CreateAnimation(
1025 scoped_ptr<AnimationCurve>(
1026 new FakeFloatTransition(1.0, 1.f, 0.5f)).Pass(),
1028 Animation::Opacity));
1030 // Animations with id 1 should both start now.
1031 controller->Animate(kInitialTickTime);
1032 controller->UpdateState(true, events.get());
1033 EXPECT_TRUE(controller->HasActiveAnimation());
1034 EXPECT_EQ(0.f, dummy.opacity());
1035 // The opacity animation should have finished at time 1, but the group
1036 // of animations with id 1 don't finish until time 2 because of the length
1037 // of the transform animation.
1038 controller->Animate(kInitialTickTime + 2.0);
1039 controller->UpdateState(true, events.get());
1040 // Should not have started the float transition yet.
1041 EXPECT_TRUE(controller->HasActiveAnimation());
1042 EXPECT_EQ(1.f, dummy.opacity());
1044 // The second opacity animation should start at time 2 and should be done by
1045 // time 3.
1046 controller->Animate(kInitialTickTime + 3.0);
1047 controller->UpdateState(true, events.get());
1048 EXPECT_EQ(0.5f, dummy.opacity());
1049 EXPECT_FALSE(controller->HasActiveAnimation());
1052 // Test that a looping animation loops and for the correct number of iterations.
1053 TEST(LayerAnimationControllerTest, TrivialLooping) {
1054 scoped_ptr<AnimationEventsVector> events(
1055 make_scoped_ptr(new AnimationEventsVector));
1056 FakeLayerAnimationValueObserver dummy;
1057 scoped_refptr<LayerAnimationController> controller(
1058 LayerAnimationController::Create(0));
1059 controller->AddValueObserver(&dummy);
1061 scoped_ptr<Animation> to_add(CreateAnimation(
1062 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1064 Animation::Opacity));
1065 to_add->set_iterations(3);
1066 controller->AddAnimation(to_add.Pass());
1068 controller->Animate(kInitialTickTime);
1069 controller->UpdateState(true, events.get());
1070 EXPECT_TRUE(controller->HasActiveAnimation());
1071 EXPECT_EQ(0.f, dummy.opacity());
1072 controller->Animate(kInitialTickTime + 1.25);
1073 controller->UpdateState(true, events.get());
1074 EXPECT_TRUE(controller->HasActiveAnimation());
1075 EXPECT_EQ(0.25f, dummy.opacity());
1076 controller->Animate(kInitialTickTime + 1.75);
1077 controller->UpdateState(true, events.get());
1078 EXPECT_TRUE(controller->HasActiveAnimation());
1079 EXPECT_EQ(0.75f, dummy.opacity());
1080 controller->Animate(kInitialTickTime + 2.25);
1081 controller->UpdateState(true, events.get());
1082 EXPECT_TRUE(controller->HasActiveAnimation());
1083 EXPECT_EQ(0.25f, dummy.opacity());
1084 controller->Animate(kInitialTickTime + 2.75);
1085 controller->UpdateState(true, events.get());
1086 EXPECT_TRUE(controller->HasActiveAnimation());
1087 EXPECT_EQ(0.75f, dummy.opacity());
1088 controller->Animate(kInitialTickTime + 3.0);
1089 controller->UpdateState(true, events.get());
1090 EXPECT_FALSE(controller->HasActiveAnimation());
1091 EXPECT_EQ(1.f, dummy.opacity());
1093 // Just be extra sure.
1094 controller->Animate(kInitialTickTime + 4.0);
1095 controller->UpdateState(true, events.get());
1096 EXPECT_EQ(1.f, dummy.opacity());
1099 // Test that an infinitely looping animation does indeed go until aborted.
1100 TEST(LayerAnimationControllerTest, InfiniteLooping) {
1101 scoped_ptr<AnimationEventsVector> events(
1102 make_scoped_ptr(new AnimationEventsVector));
1103 FakeLayerAnimationValueObserver dummy;
1104 scoped_refptr<LayerAnimationController> controller(
1105 LayerAnimationController::Create(0));
1106 controller->AddValueObserver(&dummy);
1108 const int id = 1;
1109 scoped_ptr<Animation> to_add(CreateAnimation(
1110 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1112 Animation::Opacity));
1113 to_add->set_iterations(-1);
1114 controller->AddAnimation(to_add.Pass());
1116 controller->Animate(kInitialTickTime);
1117 controller->UpdateState(true, events.get());
1118 EXPECT_TRUE(controller->HasActiveAnimation());
1119 EXPECT_EQ(0.f, dummy.opacity());
1120 controller->Animate(kInitialTickTime + 1.25);
1121 controller->UpdateState(true, events.get());
1122 EXPECT_TRUE(controller->HasActiveAnimation());
1123 EXPECT_EQ(0.25f, dummy.opacity());
1124 controller->Animate(kInitialTickTime + 1.75);
1125 controller->UpdateState(true, events.get());
1126 EXPECT_TRUE(controller->HasActiveAnimation());
1127 EXPECT_EQ(0.75f, dummy.opacity());
1129 controller->Animate(kInitialTickTime + 1073741824.25);
1130 controller->UpdateState(true, events.get());
1131 EXPECT_TRUE(controller->HasActiveAnimation());
1132 EXPECT_EQ(0.25f, dummy.opacity());
1133 controller->Animate(kInitialTickTime + 1073741824.75);
1134 controller->UpdateState(true, events.get());
1135 EXPECT_TRUE(controller->HasActiveAnimation());
1136 EXPECT_EQ(0.75f, dummy.opacity());
1138 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity));
1139 controller->GetAnimation(id, Animation::Opacity)->SetRunState(
1140 Animation::Aborted, kInitialTickTime + 0.75);
1141 EXPECT_FALSE(controller->HasActiveAnimation());
1142 EXPECT_EQ(0.75f, dummy.opacity());
1145 // Test that pausing and resuming work as expected.
1146 TEST(LayerAnimationControllerTest, PauseResume) {
1147 scoped_ptr<AnimationEventsVector> events(
1148 make_scoped_ptr(new AnimationEventsVector));
1149 FakeLayerAnimationValueObserver dummy;
1150 scoped_refptr<LayerAnimationController> controller(
1151 LayerAnimationController::Create(0));
1152 controller->AddValueObserver(&dummy);
1154 const int id = 1;
1155 controller->AddAnimation(CreateAnimation(
1156 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1158 Animation::Opacity));
1160 controller->Animate(kInitialTickTime);
1161 controller->UpdateState(true, events.get());
1162 EXPECT_TRUE(controller->HasActiveAnimation());
1163 EXPECT_EQ(0.f, dummy.opacity());
1164 controller->Animate(kInitialTickTime + 0.5);
1165 controller->UpdateState(true, events.get());
1166 EXPECT_TRUE(controller->HasActiveAnimation());
1167 EXPECT_EQ(0.5f, dummy.opacity());
1169 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity));
1170 controller->GetAnimation(id, Animation::Opacity)->SetRunState(
1171 Animation::Paused, kInitialTickTime + 0.5);
1173 controller->Animate(kInitialTickTime + 1024.0);
1174 controller->UpdateState(true, events.get());
1175 EXPECT_TRUE(controller->HasActiveAnimation());
1176 EXPECT_EQ(0.5f, dummy.opacity());
1178 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity));
1179 controller->GetAnimation(id, Animation::Opacity)->SetRunState(
1180 Animation::Running, kInitialTickTime + 1024);
1182 controller->Animate(kInitialTickTime + 1024.25);
1183 controller->UpdateState(true, events.get());
1184 EXPECT_TRUE(controller->HasActiveAnimation());
1185 EXPECT_EQ(0.75f, dummy.opacity());
1186 controller->Animate(kInitialTickTime + 1024.5);
1187 controller->UpdateState(true, events.get());
1188 EXPECT_FALSE(controller->HasActiveAnimation());
1189 EXPECT_EQ(1.f, dummy.opacity());
1192 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) {
1193 scoped_ptr<AnimationEventsVector> events(
1194 make_scoped_ptr(new AnimationEventsVector));
1195 FakeLayerAnimationValueObserver dummy;
1196 scoped_refptr<LayerAnimationController> controller(
1197 LayerAnimationController::Create(0));
1198 controller->AddValueObserver(&dummy);
1200 const int id = 1;
1201 controller->AddAnimation(CreateAnimation(
1202 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(),
1204 Animation::Transform));
1205 controller->AddAnimation(CreateAnimation(
1206 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(),
1208 Animation::Opacity));
1209 controller->AddAnimation(CreateAnimation(
1210 scoped_ptr<AnimationCurve>(
1211 new FakeFloatTransition(1.0, 1.f, 0.75f)).Pass(),
1213 Animation::Opacity));
1215 controller->Animate(kInitialTickTime);
1216 controller->UpdateState(true, events.get());
1217 EXPECT_TRUE(controller->HasActiveAnimation());
1218 EXPECT_EQ(0.f, dummy.opacity());
1219 controller->Animate(kInitialTickTime + 1.0);
1220 controller->UpdateState(true, events.get());
1221 EXPECT_TRUE(controller->HasActiveAnimation());
1222 EXPECT_EQ(0.5f, dummy.opacity());
1224 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity));
1225 controller->GetAnimation(id, Animation::Opacity)->SetRunState(
1226 Animation::Aborted, kInitialTickTime + 1.0);
1227 controller->Animate(kInitialTickTime + 1.0);
1228 controller->UpdateState(true, events.get());
1229 EXPECT_TRUE(controller->HasActiveAnimation());
1230 EXPECT_EQ(1.f, dummy.opacity());
1231 controller->Animate(kInitialTickTime + 2.0);
1232 controller->UpdateState(true, events.get());
1233 EXPECT_TRUE(!controller->HasActiveAnimation());
1234 EXPECT_EQ(0.75f, dummy.opacity());
1237 TEST(LayerAnimationControllerTest, PushUpdatesWhenSynchronizedStartTimeNeeded) {
1238 FakeLayerAnimationValueObserver dummy_impl;
1239 scoped_refptr<LayerAnimationController> controller_impl(
1240 LayerAnimationController::Create(0));
1241 controller_impl->AddValueObserver(&dummy_impl);
1242 scoped_ptr<AnimationEventsVector> events(
1243 make_scoped_ptr(new AnimationEventsVector));
1244 FakeLayerAnimationValueObserver dummy;
1245 scoped_refptr<LayerAnimationController> controller(
1246 LayerAnimationController::Create(0));
1247 controller->AddValueObserver(&dummy);
1249 scoped_ptr<Animation> to_add(CreateAnimation(
1250 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(),
1252 Animation::Opacity));
1253 to_add->set_needs_synchronized_start_time(true);
1254 controller->AddAnimation(to_add.Pass());
1256 controller->Animate(kInitialTickTime);
1257 controller->UpdateState(true, events.get());
1258 EXPECT_TRUE(controller->HasActiveAnimation());
1259 Animation* active_animation = controller->GetAnimation(0, Animation::Opacity);
1260 EXPECT_TRUE(active_animation);
1261 EXPECT_TRUE(active_animation->needs_synchronized_start_time());
1263 controller->PushAnimationUpdatesTo(controller_impl.get());
1265 active_animation = controller_impl->GetAnimation(0, Animation::Opacity);
1266 EXPECT_TRUE(active_animation);
1267 EXPECT_EQ(Animation::WaitingForTargetAvailability,
1268 active_animation->run_state());
1271 // Tests that skipping a call to UpdateState works as expected.
1272 TEST(LayerAnimationControllerTest, SkipUpdateState) {
1273 scoped_ptr<AnimationEventsVector> events(
1274 make_scoped_ptr(new AnimationEventsVector));
1275 FakeLayerAnimationValueObserver dummy;
1276 scoped_refptr<LayerAnimationController> controller(
1277 LayerAnimationController::Create(0));
1278 controller->AddValueObserver(&dummy);
1280 controller->AddAnimation(CreateAnimation(
1281 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(),
1283 Animation::Transform));
1285 controller->Animate(kInitialTickTime);
1286 controller->UpdateState(true, events.get());
1288 controller->AddAnimation(CreateAnimation(
1289 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1291 Animation::Opacity));
1293 // Animate but don't UpdateState.
1294 controller->Animate(kInitialTickTime + 1.0);
1296 controller->Animate(kInitialTickTime + 2.0);
1297 events.reset(new AnimationEventsVector);
1298 controller->UpdateState(true, events.get());
1300 // Should have one Started event and one Finished event.
1301 EXPECT_EQ(2u, events->size());
1302 EXPECT_NE((*events)[0].type, (*events)[1].type);
1304 // The float transition should still be at its starting point.
1305 EXPECT_TRUE(controller->HasActiveAnimation());
1306 EXPECT_EQ(0.f, dummy.opacity());
1308 controller->Animate(kInitialTickTime + 3.0);
1309 controller->UpdateState(true, events.get());
1311 // The float tranisition should now be done.
1312 EXPECT_EQ(1.f, dummy.opacity());
1313 EXPECT_FALSE(controller->HasActiveAnimation());
1316 // Tests that an animation controller with only an inactive observer gets ticked
1317 // but doesn't progress animations past the Starting state.
1318 TEST(LayerAnimationControllerTest, InactiveObserverGetsTicked) {
1319 scoped_ptr<AnimationEventsVector> events(
1320 make_scoped_ptr(new AnimationEventsVector));
1321 FakeLayerAnimationValueObserver dummy;
1322 FakeInactiveLayerAnimationValueObserver inactive_dummy;
1323 scoped_refptr<LayerAnimationController> controller(
1324 LayerAnimationController::Create(0));
1326 const int id = 1;
1327 controller->AddAnimation(CreateAnimation(scoped_ptr<AnimationCurve>(
1328 new FakeFloatTransition(1.0, 0.5f, 1.f)).Pass(),
1330 Animation::Opacity));
1332 // Without an observer, the animation shouldn't progress to the Starting
1333 // state.
1334 controller->Animate(kInitialTickTime);
1335 controller->UpdateState(true, events.get());
1336 EXPECT_EQ(0u, events->size());
1337 EXPECT_EQ(Animation::WaitingForTargetAvailability,
1338 controller->GetAnimation(id, Animation::Opacity)->run_state());
1340 controller->AddValueObserver(&inactive_dummy);
1342 // With only an inactive observer, the animation should progress to the
1343 // Starting state and get ticked at its starting point, but should not
1344 // progress to Running.
1345 controller->Animate(kInitialTickTime + 1.0);
1346 controller->UpdateState(true, events.get());
1347 EXPECT_EQ(0u, events->size());
1348 EXPECT_EQ(Animation::Starting,
1349 controller->GetAnimation(id, Animation::Opacity)->run_state());
1350 EXPECT_EQ(0.5f, inactive_dummy.opacity());
1352 // Even when already in the Starting state, the animation should stay
1353 // there, and shouldn't be ticked past its starting point.
1354 controller->Animate(kInitialTickTime + 2.0);
1355 controller->UpdateState(true, events.get());
1356 EXPECT_EQ(0u, events->size());
1357 EXPECT_EQ(Animation::Starting,
1358 controller->GetAnimation(id, Animation::Opacity)->run_state());
1359 EXPECT_EQ(0.5f, inactive_dummy.opacity());
1361 controller->AddValueObserver(&dummy);
1363 // Now that an active observer has been added, the animation should still
1364 // initially tick at its starting point, but should now progress to Running.
1365 controller->Animate(kInitialTickTime + 3.0);
1366 controller->UpdateState(true, events.get());
1367 EXPECT_EQ(1u, events->size());
1368 EXPECT_EQ(Animation::Running,
1369 controller->GetAnimation(id, Animation::Opacity)->run_state());
1370 EXPECT_EQ(0.5f, inactive_dummy.opacity());
1371 EXPECT_EQ(0.5f, dummy.opacity());
1373 // The animation should now tick past its starting point.
1374 controller->Animate(kInitialTickTime + 3.5);
1375 EXPECT_NE(0.5f, inactive_dummy.opacity());
1376 EXPECT_NE(0.5f, dummy.opacity());
1379 TEST(LayerAnimationControllerTest, AnimatedBounds) {
1380 scoped_refptr<LayerAnimationController> controller_impl(
1381 LayerAnimationController::Create(0));
1383 scoped_ptr<KeyframedTransformAnimationCurve> curve1(
1384 KeyframedTransformAnimationCurve::Create());
1386 TransformOperations operations1;
1387 curve1->AddKeyframe(TransformKeyframe::Create(
1388 0.0, operations1, scoped_ptr<TimingFunction>()));
1389 operations1.AppendTranslate(10.0, 15.0, 0.0);
1390 curve1->AddKeyframe(TransformKeyframe::Create(
1391 1.0, operations1, scoped_ptr<TimingFunction>()));
1393 scoped_ptr<Animation> animation(Animation::Create(
1394 curve1.PassAs<AnimationCurve>(), 1, 1, Animation::Transform));
1395 controller_impl->AddAnimation(animation.Pass());
1397 scoped_ptr<KeyframedTransformAnimationCurve> curve2(
1398 KeyframedTransformAnimationCurve::Create());
1400 TransformOperations operations2;
1401 curve2->AddKeyframe(TransformKeyframe::Create(
1402 0.0, operations2, scoped_ptr<TimingFunction>()));
1403 operations2.AppendScale(2.0, 3.0, 4.0);
1404 curve2->AddKeyframe(TransformKeyframe::Create(
1405 1.0, operations2, scoped_ptr<TimingFunction>()));
1407 animation = Animation::Create(
1408 curve2.PassAs<AnimationCurve>(), 2, 2, Animation::Transform);
1409 controller_impl->AddAnimation(animation.Pass());
1411 gfx::BoxF box(1.f, 2.f, -1.f, 3.f, 4.f, 5.f);
1412 gfx::BoxF bounds;
1414 EXPECT_TRUE(controller_impl->AnimatedBoundsForBox(box, &bounds));
1415 EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 13.f, 19.f, 20.f).ToString(),
1416 bounds.ToString());
1418 controller_impl->GetAnimation(1, Animation::Transform)
1419 ->SetRunState(Animation::Finished, 0.0);
1421 // Only the unfinished animation should affect the animated bounds.
1422 EXPECT_TRUE(controller_impl->AnimatedBoundsForBox(box, &bounds));
1423 EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 7.f, 16.f, 20.f).ToString(),
1424 bounds.ToString());
1426 controller_impl->GetAnimation(2, Animation::Transform)
1427 ->SetRunState(Animation::Finished, 0.0);
1429 // There are no longer any running animations.
1430 EXPECT_TRUE(controller_impl->AnimatedBoundsForBox(box, &bounds));
1431 EXPECT_EQ(gfx::BoxF().ToString(), bounds.ToString());
1433 // Add an animation whose bounds we don't yet support computing.
1434 scoped_ptr<KeyframedTransformAnimationCurve> curve3(
1435 KeyframedTransformAnimationCurve::Create());
1436 TransformOperations operations3;
1437 gfx::Transform transform3;
1438 transform3.Scale3d(1.0, 2.0, 3.0);
1439 curve3->AddKeyframe(TransformKeyframe::Create(
1440 0.0, operations3, scoped_ptr<TimingFunction>()));
1441 operations3.AppendMatrix(transform3);
1442 curve3->AddKeyframe(TransformKeyframe::Create(
1443 1.0, operations3, scoped_ptr<TimingFunction>()));
1444 animation = Animation::Create(
1445 curve3.PassAs<AnimationCurve>(), 3, 3, Animation::Transform);
1446 controller_impl->AddAnimation(animation.Pass());
1447 EXPECT_FALSE(controller_impl->AnimatedBoundsForBox(box, &bounds));
1450 // Tests that AbortAnimations aborts all animations targeting the specified
1451 // property.
1452 TEST(LayerAnimationControllerTest, AbortAnimations) {
1453 FakeLayerAnimationValueObserver dummy;
1454 scoped_refptr<LayerAnimationController> controller(
1455 LayerAnimationController::Create(0));
1456 controller->AddValueObserver(&dummy);
1458 // Start with several animations, and allow some of them to reach the finished
1459 // state.
1460 controller->AddAnimation(CreateAnimation(
1461 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)).Pass(),
1463 Animation::Transform));
1464 controller->AddAnimation(CreateAnimation(
1465 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1467 Animation::Opacity));
1468 controller->AddAnimation(CreateAnimation(
1469 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)).Pass(),
1471 Animation::Transform));
1472 controller->AddAnimation(CreateAnimation(
1473 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2.0)).Pass(),
1475 Animation::Transform));
1476 controller->AddAnimation(CreateAnimation(
1477 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1479 Animation::Opacity));
1481 controller->Animate(kInitialTickTime);
1482 controller->UpdateState(true, NULL);
1483 controller->Animate(kInitialTickTime + 1.0);
1484 controller->UpdateState(true, NULL);
1486 EXPECT_EQ(Animation::Finished,
1487 controller->GetAnimation(1, Animation::Transform)->run_state());
1488 EXPECT_EQ(Animation::Finished,
1489 controller->GetAnimation(2, Animation::Opacity)->run_state());
1490 EXPECT_EQ(Animation::Running,
1491 controller->GetAnimation(3, Animation::Transform)->run_state());
1492 EXPECT_EQ(Animation::WaitingForTargetAvailability,
1493 controller->GetAnimation(4, Animation::Transform)->run_state());
1494 EXPECT_EQ(Animation::Running,
1495 controller->GetAnimation(5, Animation::Opacity)->run_state());
1497 controller->AbortAnimations(Animation::Transform);
1499 // Only un-finished Transform animations should have been aborted.
1500 EXPECT_EQ(Animation::Finished,
1501 controller->GetAnimation(1, Animation::Transform)->run_state());
1502 EXPECT_EQ(Animation::Finished,
1503 controller->GetAnimation(2, Animation::Opacity)->run_state());
1504 EXPECT_EQ(Animation::Aborted,
1505 controller->GetAnimation(3, Animation::Transform)->run_state());
1506 EXPECT_EQ(Animation::Aborted,
1507 controller->GetAnimation(4, Animation::Transform)->run_state());
1508 EXPECT_EQ(Animation::Running,
1509 controller->GetAnimation(5, Animation::Opacity)->run_state());
1512 // An animation aborted on the main thread should get deleted on both threads.
1513 TEST(LayerAnimationControllerTest, MainThreadAbortedAnimationGetsDeleted) {
1514 FakeLayerAnimationValueObserver dummy_impl;
1515 scoped_refptr<LayerAnimationController> controller_impl(
1516 LayerAnimationController::Create(0));
1517 controller_impl->AddValueObserver(&dummy_impl);
1518 FakeLayerAnimationValueObserver dummy;
1519 scoped_refptr<LayerAnimationController> controller(
1520 LayerAnimationController::Create(0));
1521 controller->AddValueObserver(&dummy);
1523 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false);
1524 int group_id = controller->GetAnimation(Animation::Opacity)->group();
1526 controller->PushAnimationUpdatesTo(controller_impl.get());
1527 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity));
1529 controller->AbortAnimations(Animation::Opacity);
1530 EXPECT_EQ(Animation::Aborted,
1531 controller->GetAnimation(Animation::Opacity)->run_state());
1532 EXPECT_FALSE(dummy.animation_waiting_for_deletion());
1533 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion());
1535 controller->Animate(kInitialTickTime);
1536 controller->UpdateState(true, NULL);
1537 EXPECT_TRUE(dummy.animation_waiting_for_deletion());
1538 EXPECT_EQ(Animation::WaitingForDeletion,
1539 controller->GetAnimation(Animation::Opacity)->run_state());
1541 controller->PushAnimationUpdatesTo(controller_impl.get());
1542 EXPECT_FALSE(controller->GetAnimation(group_id, Animation::Opacity));
1543 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity));
1546 // An animation aborted on the impl thread should get deleted on both threads.
1547 TEST(LayerAnimationControllerTest, ImplThreadAbortedAnimationGetsDeleted) {
1548 FakeLayerAnimationValueObserver dummy_impl;
1549 scoped_refptr<LayerAnimationController> controller_impl(
1550 LayerAnimationController::Create(0));
1551 controller_impl->AddValueObserver(&dummy_impl);
1552 FakeLayerAnimationValueObserver dummy;
1553 scoped_refptr<LayerAnimationController> controller(
1554 LayerAnimationController::Create(0));
1555 controller->AddValueObserver(&dummy);
1557 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false);
1558 int group_id = controller->GetAnimation(Animation::Opacity)->group();
1560 controller->PushAnimationUpdatesTo(controller_impl.get());
1561 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity));
1563 controller_impl->AbortAnimations(Animation::Opacity);
1564 EXPECT_EQ(Animation::Aborted,
1565 controller_impl->GetAnimation(Animation::Opacity)->run_state());
1566 EXPECT_FALSE(dummy.animation_waiting_for_deletion());
1567 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion());
1569 AnimationEventsVector events;
1570 controller_impl->Animate(kInitialTickTime);
1571 controller_impl->UpdateState(true, &events);
1572 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion());
1573 EXPECT_EQ(1u, events.size());
1574 EXPECT_EQ(AnimationEvent::Aborted, events[0].type);
1575 EXPECT_EQ(Animation::WaitingForDeletion,
1576 controller_impl->GetAnimation(Animation::Opacity)->run_state());
1578 controller->NotifyAnimationAborted(events[0]);
1579 EXPECT_EQ(Animation::Aborted,
1580 controller->GetAnimation(Animation::Opacity)->run_state());
1582 controller->Animate(kInitialTickTime + 0.5);
1583 controller->UpdateState(true, NULL);
1584 EXPECT_TRUE(dummy.animation_waiting_for_deletion());
1585 EXPECT_EQ(Animation::WaitingForDeletion,
1586 controller->GetAnimation(Animation::Opacity)->run_state());
1588 controller->PushAnimationUpdatesTo(controller_impl.get());
1589 EXPECT_FALSE(controller->GetAnimation(group_id, Animation::Opacity));
1590 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity));
1593 // Ensure that we only generate Finished events for animations in a group
1594 // once all animations in that group are finished.
1595 TEST(LayerAnimationControllerTest, FinishedEventsForGroup) {
1596 scoped_ptr<AnimationEventsVector> events(
1597 make_scoped_ptr(new AnimationEventsVector));
1598 FakeLayerAnimationValueObserver dummy_impl;
1599 scoped_refptr<LayerAnimationController> controller_impl(
1600 LayerAnimationController::Create(0));
1601 controller_impl->AddValueObserver(&dummy_impl);
1603 // Add two animations with the same group id but different durations.
1604 controller_impl->AddAnimation(CreateAnimation(
1605 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2.0)).Pass(),
1607 Animation::Transform));
1608 controller_impl->AddAnimation(CreateAnimation(
1609 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1611 Animation::Opacity));
1613 controller_impl->Animate(kInitialTickTime);
1614 controller_impl->UpdateState(true, events.get());
1616 // Both animations should have started.
1617 EXPECT_EQ(2u, events->size());
1618 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type);
1619 EXPECT_EQ(AnimationEvent::Started, (*events)[1].type);
1621 events.reset(new AnimationEventsVector);
1622 controller_impl->Animate(kInitialTickTime + 1.0);
1623 controller_impl->UpdateState(true, events.get());
1625 // The opacity animation should be finished, but should not have generated
1626 // a Finished event yet.
1627 EXPECT_EQ(0u, events->size());
1628 EXPECT_EQ(Animation::Finished,
1629 controller_impl->GetAnimation(1, Animation::Opacity)->run_state());
1630 EXPECT_EQ(Animation::Running,
1631 controller_impl->GetAnimation(1,
1632 Animation::Transform)->run_state());
1634 controller_impl->Animate(kInitialTickTime + 2.0);
1635 controller_impl->UpdateState(true, events.get());
1637 // Both animations should have generated Finished events.
1638 EXPECT_EQ(2u, events->size());
1639 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type);
1640 EXPECT_EQ(AnimationEvent::Finished, (*events)[1].type);
1643 // Ensure that when a group has a mix of aborted and finished animations,
1644 // we generate a Finished event for the finished animation and an Aborted
1645 // event for the aborted animation.
1646 TEST(LayerAnimationControllerTest, FinishedAndAbortedEventsForGroup) {
1647 scoped_ptr<AnimationEventsVector> events(
1648 make_scoped_ptr(new AnimationEventsVector));
1649 FakeLayerAnimationValueObserver dummy_impl;
1650 scoped_refptr<LayerAnimationController> controller_impl(
1651 LayerAnimationController::Create(0));
1652 controller_impl->AddValueObserver(&dummy_impl);
1654 // Add two animations with the same group id.
1655 controller_impl->AddAnimation(CreateAnimation(
1656 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)).Pass(),
1658 Animation::Transform));
1659 controller_impl->AddAnimation(CreateAnimation(
1660 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1662 Animation::Opacity));
1664 controller_impl->Animate(kInitialTickTime);
1665 controller_impl->UpdateState(true, events.get());
1667 // Both animations should have started.
1668 EXPECT_EQ(2u, events->size());
1669 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type);
1670 EXPECT_EQ(AnimationEvent::Started, (*events)[1].type);
1672 controller_impl->AbortAnimations(Animation::Opacity);
1674 events.reset(new AnimationEventsVector);
1675 controller_impl->Animate(kInitialTickTime + 1.0);
1676 controller_impl->UpdateState(true, events.get());
1678 // We should have exactly 2 events: a Finished event for the tranform
1679 // animation, and an Aborted event for the opacity animation.
1680 EXPECT_EQ(2u, events->size());
1681 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type);
1682 EXPECT_EQ(Animation::Transform, (*events)[0].target_property);
1683 EXPECT_EQ(AnimationEvent::Aborted, (*events)[1].type);
1684 EXPECT_EQ(Animation::Opacity, (*events)[1].target_property);
1687 } // namespace
1688 } // namespace cc