Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / cc / animation / layer_animation_controller_unittest.cc
blob8089ebfe294d8159808be2d4e4da77a59dadf489
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/geometry/box_f.h"
18 #include "ui/gfx/transform.h"
20 namespace cc {
21 namespace {
23 using base::TimeDelta;
24 using base::TimeTicks;
26 static base::TimeTicks TicksFromSecondsF(double seconds) {
27 return base::TimeTicks::FromInternalValue(seconds *
28 base::Time::kMicrosecondsPerSecond);
31 // A LayerAnimationController cannot be ticked at 0.0, since an animation
32 // with start time 0.0 is treated as an animation whose start time has
33 // not yet been set.
34 const TimeTicks kInitialTickTime = TicksFromSecondsF(1.0);
36 scoped_ptr<Animation> CreateAnimation(scoped_ptr<AnimationCurve> curve,
37 int group_id,
38 Animation::TargetProperty property) {
39 return Animation::Create(curve.Pass(), 0, group_id, property);
42 TEST(LayerAnimationControllerTest, SyncNewAnimation) {
43 FakeLayerAnimationValueObserver dummy_impl;
44 scoped_refptr<LayerAnimationController> controller_impl(
45 LayerAnimationController::Create(0));
46 controller_impl->AddValueObserver(&dummy_impl);
47 FakeLayerAnimationValueObserver dummy;
48 scoped_refptr<LayerAnimationController> controller(
49 LayerAnimationController::Create(0));
50 controller->AddValueObserver(&dummy);
52 EXPECT_FALSE(controller_impl->GetAnimation(Animation::OPACITY));
54 EXPECT_FALSE(controller->needs_to_start_animations_for_testing());
55 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing());
57 int animation_id =
58 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false);
59 EXPECT_TRUE(controller->needs_to_start_animations_for_testing());
61 controller->PushAnimationUpdatesTo(controller_impl.get());
62 EXPECT_TRUE(controller_impl->needs_to_start_animations_for_testing());
63 controller_impl->ActivateAnimations();
65 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id));
66 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
67 controller_impl->GetAnimationById(animation_id)->run_state());
70 // If an animation is started on the impl thread before it is ticked on the main
71 // thread, we must be sure to respect the synchronized start time.
72 TEST(LayerAnimationControllerTest, DoNotClobberStartTimes) {
73 FakeLayerAnimationValueObserver dummy_impl;
74 scoped_refptr<LayerAnimationController> controller_impl(
75 LayerAnimationController::Create(0));
76 controller_impl->AddValueObserver(&dummy_impl);
77 FakeLayerAnimationValueObserver dummy;
78 scoped_refptr<LayerAnimationController> controller(
79 LayerAnimationController::Create(0));
80 controller->AddValueObserver(&dummy);
82 EXPECT_FALSE(controller_impl->GetAnimation(Animation::OPACITY));
84 int animation_id =
85 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false);
87 controller->PushAnimationUpdatesTo(controller_impl.get());
88 controller_impl->ActivateAnimations();
90 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id));
91 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
92 controller_impl->GetAnimationById(animation_id)->run_state());
94 AnimationEventsVector events;
95 controller_impl->Animate(kInitialTickTime);
96 controller_impl->UpdateState(true, &events);
98 // Synchronize the start times.
99 EXPECT_EQ(1u, events.size());
100 controller->NotifyAnimationStarted(events[0]);
101 EXPECT_EQ(controller->GetAnimationById(animation_id)->start_time(),
102 controller_impl->GetAnimationById(animation_id)->start_time());
104 // Start the animation on the main thread. Should not affect the start time.
105 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
106 controller->UpdateState(true, nullptr);
107 EXPECT_EQ(controller->GetAnimationById(animation_id)->start_time(),
108 controller_impl->GetAnimationById(animation_id)->start_time());
111 TEST(LayerAnimationControllerTest, UseSpecifiedStartTimes) {
112 FakeLayerAnimationValueObserver dummy_impl;
113 scoped_refptr<LayerAnimationController> controller_impl(
114 LayerAnimationController::Create(0));
115 controller_impl->AddValueObserver(&dummy_impl);
116 FakeLayerAnimationValueObserver dummy;
117 scoped_refptr<LayerAnimationController> controller(
118 LayerAnimationController::Create(0));
119 controller->AddValueObserver(&dummy);
121 int animation_id =
122 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false);
124 const TimeTicks start_time = TicksFromSecondsF(123);
125 controller->GetAnimation(Animation::OPACITY)->set_start_time(start_time);
127 controller->PushAnimationUpdatesTo(controller_impl.get());
128 controller_impl->ActivateAnimations();
130 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id));
131 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
132 controller_impl->GetAnimationById(animation_id)->run_state());
134 AnimationEventsVector events;
135 controller_impl->Animate(kInitialTickTime);
136 controller_impl->UpdateState(true, &events);
138 // Synchronize the start times.
139 EXPECT_EQ(1u, events.size());
140 controller->NotifyAnimationStarted(events[0]);
142 EXPECT_EQ(start_time,
143 controller->GetAnimationById(animation_id)->start_time());
144 EXPECT_EQ(controller->GetAnimationById(animation_id)->start_time(),
145 controller_impl->GetAnimationById(animation_id)->start_time());
147 // Start the animation on the main thread. Should not affect the start time.
148 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
149 controller->UpdateState(true, nullptr);
150 EXPECT_EQ(start_time,
151 controller->GetAnimationById(animation_id)->start_time());
152 EXPECT_EQ(controller->GetAnimationById(animation_id)->start_time(),
153 controller_impl->GetAnimationById(animation_id)->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_for_testing().size());
175 EXPECT_EQ(1u, registrar_impl->all_animation_controllers_for_testing().size());
177 // Initially, both controllers should be inactive.
178 EXPECT_EQ(0u, registrar->active_animation_controllers_for_testing().size());
179 EXPECT_EQ(0u,
180 registrar_impl->active_animation_controllers_for_testing().size());
182 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false);
183 // The main thread controller should now be active.
184 EXPECT_EQ(1u, registrar->active_animation_controllers_for_testing().size());
186 controller->PushAnimationUpdatesTo(controller_impl.get());
187 controller_impl->ActivateAnimations();
188 // Both controllers should now be active.
189 EXPECT_EQ(1u, registrar->active_animation_controllers_for_testing().size());
190 EXPECT_EQ(1u,
191 registrar_impl->active_animation_controllers_for_testing().size());
193 controller_impl->Animate(kInitialTickTime);
194 controller_impl->UpdateState(true, events.get());
195 EXPECT_EQ(1u, events->size());
196 controller->NotifyAnimationStarted((*events)[0]);
198 EXPECT_EQ(1u, registrar->active_animation_controllers_for_testing().size());
199 EXPECT_EQ(1u,
200 registrar_impl->active_animation_controllers_for_testing().size());
202 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
203 controller->UpdateState(true, nullptr);
204 EXPECT_EQ(1u, registrar->active_animation_controllers_for_testing().size());
206 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
207 controller->UpdateState(true, nullptr);
208 EXPECT_EQ(Animation::FINISHED,
209 controller->GetAnimation(Animation::OPACITY)->run_state());
210 EXPECT_EQ(1u, registrar->active_animation_controllers_for_testing().size());
212 events.reset(new AnimationEventsVector);
213 controller_impl->Animate(kInitialTickTime +
214 TimeDelta::FromMilliseconds(1500));
215 controller_impl->UpdateState(true, events.get());
217 EXPECT_EQ(Animation::WAITING_FOR_DELETION,
218 controller_impl->GetAnimation(Animation::OPACITY)->run_state());
219 // The impl thread controller should have de-activated.
220 EXPECT_EQ(0u,
221 registrar_impl->active_animation_controllers_for_testing().size());
223 EXPECT_EQ(1u, events->size());
224 controller->NotifyAnimationFinished((*events)[0]);
225 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1500));
226 controller->UpdateState(true, nullptr);
228 EXPECT_EQ(Animation::WAITING_FOR_DELETION,
229 controller->GetAnimation(Animation::OPACITY)->run_state());
230 // The main thread controller should have de-activated.
231 EXPECT_EQ(0u, registrar->active_animation_controllers_for_testing().size());
233 controller->PushAnimationUpdatesTo(controller_impl.get());
234 controller_impl->ActivateAnimations();
235 EXPECT_FALSE(controller->has_any_animation());
236 EXPECT_FALSE(controller_impl->has_any_animation());
237 EXPECT_EQ(0u, registrar->active_animation_controllers_for_testing().size());
238 EXPECT_EQ(0u,
239 registrar_impl->active_animation_controllers_for_testing().size());
241 controller->SetAnimationRegistrar(nullptr);
242 controller_impl->SetAnimationRegistrar(nullptr);
245 TEST(LayerAnimationControllerTest, SyncPause) {
246 FakeLayerAnimationValueObserver dummy_impl;
247 scoped_refptr<LayerAnimationController> controller_impl(
248 LayerAnimationController::Create(0));
249 controller_impl->AddValueObserver(&dummy_impl);
250 FakeLayerAnimationValueObserver dummy;
251 scoped_refptr<LayerAnimationController> controller(
252 LayerAnimationController::Create(0));
253 controller->AddValueObserver(&dummy);
255 EXPECT_FALSE(controller_impl->GetAnimation(Animation::OPACITY));
257 // Two steps, three ranges: [0-1) -> 0.2, [1-2) -> 0.3, [2-3] -> 0.4.
258 const double duration = 3.0;
259 const int animation_id =
260 AddOpacityStepsToController(controller.get(), duration, 0.2f, 0.4f, 2);
262 // Set start offset to be at the beginning of the second range.
263 controller->GetAnimationById(animation_id)
264 ->set_time_offset(TimeDelta::FromSecondsD(1.01));
266 controller->PushAnimationUpdatesTo(controller_impl.get());
267 controller_impl->ActivateAnimations();
269 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id));
270 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
271 controller_impl->GetAnimationById(animation_id)->run_state());
273 TimeTicks time = kInitialTickTime;
275 // Start the animations on each controller.
276 AnimationEventsVector events;
277 controller_impl->Animate(time);
278 controller_impl->UpdateState(true, &events);
279 EXPECT_EQ(1u, events.size());
281 controller->Animate(time);
282 controller->UpdateState(true, nullptr);
283 controller->NotifyAnimationStarted(events[0]);
285 EXPECT_EQ(Animation::RUNNING,
286 controller_impl->GetAnimationById(animation_id)->run_state());
287 EXPECT_EQ(Animation::RUNNING,
288 controller->GetAnimationById(animation_id)->run_state());
290 EXPECT_EQ(0.3f, dummy.opacity());
291 EXPECT_EQ(0.3f, dummy_impl.opacity());
293 EXPECT_EQ(kInitialTickTime,
294 controller->GetAnimationById(animation_id)->start_time());
295 EXPECT_EQ(kInitialTickTime,
296 controller_impl->GetAnimationById(animation_id)->start_time());
298 // Pause the animation at the middle of the second range so the offset
299 // delays animation until the middle of the third range.
300 controller->PauseAnimation(animation_id, TimeDelta::FromSecondsD(1.5));
301 EXPECT_EQ(Animation::PAUSED,
302 controller->GetAnimationById(animation_id)->run_state());
304 // The pause run state change should make it to the impl thread controller.
305 controller->PushAnimationUpdatesTo(controller_impl.get());
306 controller_impl->ActivateAnimations();
308 // Advance time so it stays within the first range.
309 time += TimeDelta::FromMilliseconds(10);
310 controller->Animate(time);
311 controller_impl->Animate(time);
313 EXPECT_EQ(Animation::PAUSED,
314 controller_impl->GetAnimationById(animation_id)->run_state());
316 // Opacity value doesn't depend on time if paused at specified time offset.
317 EXPECT_EQ(0.4f, dummy.opacity());
318 EXPECT_EQ(0.4f, dummy_impl.opacity());
321 TEST(LayerAnimationControllerTest, DoNotSyncFinishedAnimation) {
322 FakeLayerAnimationValueObserver dummy_impl;
323 scoped_refptr<LayerAnimationController> controller_impl(
324 LayerAnimationController::Create(0));
325 controller_impl->AddValueObserver(&dummy_impl);
326 FakeLayerAnimationValueObserver dummy;
327 scoped_refptr<LayerAnimationController> controller(
328 LayerAnimationController::Create(0));
329 controller->AddValueObserver(&dummy);
330 scoped_ptr<AnimationEventsVector> events(
331 make_scoped_ptr(new AnimationEventsVector));
333 EXPECT_FALSE(controller_impl->GetAnimation(Animation::OPACITY));
335 int animation_id =
336 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false);
338 controller->PushAnimationUpdatesTo(controller_impl.get());
339 controller_impl->ActivateAnimations();
341 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id));
342 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
343 controller_impl->GetAnimationById(animation_id)->run_state());
345 events.reset(new AnimationEventsVector);
346 controller_impl->Animate(kInitialTickTime);
347 controller_impl->UpdateState(true, events.get());
348 EXPECT_EQ(1u, events->size());
349 EXPECT_EQ(AnimationEvent::STARTED, (*events)[0].type);
351 // Notify main thread controller that the animation has started.
352 controller->NotifyAnimationStarted((*events)[0]);
354 // Complete animation on impl thread.
355 events.reset(new AnimationEventsVector);
356 controller_impl->Animate(kInitialTickTime + TimeDelta::FromSeconds(1));
357 controller_impl->UpdateState(true, events.get());
358 EXPECT_EQ(1u, events->size());
359 EXPECT_EQ(AnimationEvent::FINISHED, (*events)[0].type);
361 controller->NotifyAnimationFinished((*events)[0]);
363 controller->Animate(kInitialTickTime + TimeDelta::FromSeconds(2));
364 controller->UpdateState(true, nullptr);
366 controller->PushAnimationUpdatesTo(controller_impl.get());
367 controller_impl->ActivateAnimations();
368 EXPECT_FALSE(controller->GetAnimationById(animation_id));
369 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id));
372 // Ensure that a finished animation is eventually deleted by both the
373 // main-thread and the impl-thread controllers.
374 TEST(LayerAnimationControllerTest, AnimationsAreDeleted) {
375 FakeLayerAnimationValueObserver dummy;
376 FakeLayerAnimationValueObserver dummy_impl;
377 scoped_ptr<AnimationEventsVector> events(
378 make_scoped_ptr(new AnimationEventsVector));
379 scoped_refptr<LayerAnimationController> controller(
380 LayerAnimationController::Create(0));
381 scoped_refptr<LayerAnimationController> controller_impl(
382 LayerAnimationController::Create(0));
383 controller->AddValueObserver(&dummy);
384 controller_impl->AddValueObserver(&dummy_impl);
386 AddOpacityTransitionToController(controller.get(), 1.0, 0.0f, 1.0f, false);
387 controller->Animate(kInitialTickTime);
388 controller->UpdateState(true, nullptr);
389 controller->PushAnimationUpdatesTo(controller_impl.get());
390 controller_impl->ActivateAnimations();
392 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
393 controller_impl->UpdateState(true, events.get());
395 // There should be a STARTED event for the animation.
396 EXPECT_EQ(1u, events->size());
397 EXPECT_EQ(AnimationEvent::STARTED, (*events)[0].type);
398 controller->NotifyAnimationStarted((*events)[0]);
400 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
401 controller->UpdateState(true, nullptr);
403 EXPECT_FALSE(dummy.animation_waiting_for_deletion());
404 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion());
406 events.reset(new AnimationEventsVector);
407 controller_impl->Animate(kInitialTickTime +
408 TimeDelta::FromMilliseconds(2000));
409 controller_impl->UpdateState(true, events.get());
411 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion());
413 // There should be a FINISHED event for the animation.
414 EXPECT_EQ(1u, events->size());
415 EXPECT_EQ(AnimationEvent::FINISHED, (*events)[0].type);
417 // Neither controller should have deleted the animation yet.
418 EXPECT_TRUE(controller->GetAnimation(Animation::OPACITY));
419 EXPECT_TRUE(controller_impl->GetAnimation(Animation::OPACITY));
421 controller->NotifyAnimationFinished((*events)[0]);
423 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000));
424 controller->UpdateState(true, nullptr);
425 EXPECT_TRUE(dummy.animation_waiting_for_deletion());
427 controller->PushAnimationUpdatesTo(controller_impl.get());
429 // Both controllers should now have deleted the animation. The impl controller
430 // should have deleted the animation even though activation has not occurred,
431 // since the animation was already waiting for deletion when
432 // PushAnimationUpdatesTo was called.
433 EXPECT_FALSE(controller->has_any_animation());
434 EXPECT_FALSE(controller_impl->has_any_animation());
437 // Tests that transitioning opacity from 0 to 1 works as expected.
439 static const AnimationEvent* GetMostRecentPropertyUpdateEvent(
440 const AnimationEventsVector* events) {
441 const AnimationEvent* event = 0;
442 for (size_t i = 0; i < events->size(); ++i)
443 if ((*events)[i].type == AnimationEvent::PROPERTY_UPDATE)
444 event = &(*events)[i];
446 return event;
449 TEST(LayerAnimationControllerTest, TrivialTransition) {
450 scoped_ptr<AnimationEventsVector> events(
451 make_scoped_ptr(new AnimationEventsVector));
452 FakeLayerAnimationValueObserver dummy;
453 scoped_refptr<LayerAnimationController> controller(
454 LayerAnimationController::Create(0));
455 controller->AddValueObserver(&dummy);
457 scoped_ptr<Animation> to_add(CreateAnimation(
458 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
459 1, Animation::OPACITY));
461 EXPECT_FALSE(controller->needs_to_start_animations_for_testing());
462 controller->AddAnimation(to_add.Pass());
463 EXPECT_TRUE(controller->needs_to_start_animations_for_testing());
464 controller->Animate(kInitialTickTime);
465 EXPECT_FALSE(controller->needs_to_start_animations_for_testing());
466 controller->UpdateState(true, events.get());
467 EXPECT_TRUE(controller->HasActiveAnimation());
468 EXPECT_EQ(0.f, dummy.opacity());
469 // A non-impl-only animation should not generate property updates.
470 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get());
471 EXPECT_FALSE(event);
472 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
473 controller->UpdateState(true, events.get());
474 EXPECT_EQ(1.f, dummy.opacity());
475 EXPECT_FALSE(controller->HasActiveAnimation());
476 event = GetMostRecentPropertyUpdateEvent(events.get());
477 EXPECT_FALSE(event);
480 TEST(LayerAnimationControllerTest, TrivialTransitionOnImpl) {
481 scoped_ptr<AnimationEventsVector> events(
482 make_scoped_ptr(new AnimationEventsVector));
483 FakeLayerAnimationValueObserver dummy_impl;
484 scoped_refptr<LayerAnimationController> controller_impl(
485 LayerAnimationController::Create(0));
486 controller_impl->AddValueObserver(&dummy_impl);
488 scoped_ptr<Animation> to_add(CreateAnimation(
489 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
490 1, Animation::OPACITY));
491 to_add->set_is_impl_only(true);
493 controller_impl->AddAnimation(to_add.Pass());
494 controller_impl->Animate(kInitialTickTime);
495 controller_impl->UpdateState(true, events.get());
496 EXPECT_TRUE(controller_impl->HasActiveAnimation());
497 EXPECT_EQ(0.f, dummy_impl.opacity());
498 EXPECT_EQ(1u, events->size());
499 const AnimationEvent* start_opacity_event =
500 GetMostRecentPropertyUpdateEvent(events.get());
501 EXPECT_EQ(0.f, start_opacity_event->opacity);
503 controller_impl->Animate(kInitialTickTime +
504 TimeDelta::FromMilliseconds(1000));
505 controller_impl->UpdateState(true, events.get());
506 EXPECT_EQ(1.f, dummy_impl.opacity());
507 EXPECT_FALSE(controller_impl->HasActiveAnimation());
508 EXPECT_EQ(2u, events->size());
509 const AnimationEvent* end_opacity_event =
510 GetMostRecentPropertyUpdateEvent(events.get());
511 EXPECT_EQ(1.f, end_opacity_event->opacity);
514 TEST(LayerAnimationControllerTest, TrivialTransformOnImpl) {
515 scoped_ptr<AnimationEventsVector> events(
516 make_scoped_ptr(new AnimationEventsVector));
517 FakeLayerAnimationValueObserver dummy_impl;
518 scoped_refptr<LayerAnimationController> controller_impl(
519 LayerAnimationController::Create(0));
520 controller_impl->AddValueObserver(&dummy_impl);
522 // Choose different values for x and y to avoid coincidental values in the
523 // observed transforms.
524 const float delta_x = 3;
525 const float delta_y = 4;
527 scoped_ptr<KeyframedTransformAnimationCurve> curve(
528 KeyframedTransformAnimationCurve::Create());
530 // Create simple TRANSFORM animation.
531 TransformOperations operations;
532 curve->AddKeyframe(
533 TransformKeyframe::Create(base::TimeDelta(), operations, nullptr));
534 operations.AppendTranslate(delta_x, delta_y, 0);
535 curve->AddKeyframe(TransformKeyframe::Create(
536 base::TimeDelta::FromSecondsD(1.0), operations, nullptr));
538 scoped_ptr<Animation> animation(
539 Animation::Create(curve.Pass(), 1, 0, Animation::TRANSFORM));
540 animation->set_is_impl_only(true);
541 controller_impl->AddAnimation(animation.Pass());
543 // Run animation.
544 controller_impl->Animate(kInitialTickTime);
545 controller_impl->UpdateState(true, events.get());
546 EXPECT_TRUE(controller_impl->HasActiveAnimation());
547 EXPECT_EQ(gfx::Transform(), dummy_impl.transform());
548 EXPECT_EQ(1u, events->size());
549 const AnimationEvent* start_transform_event =
550 GetMostRecentPropertyUpdateEvent(events.get());
551 ASSERT_TRUE(start_transform_event);
552 EXPECT_EQ(gfx::Transform(), start_transform_event->transform);
553 EXPECT_TRUE(start_transform_event->is_impl_only);
555 gfx::Transform expected_transform;
556 expected_transform.Translate(delta_x, delta_y);
558 controller_impl->Animate(kInitialTickTime +
559 TimeDelta::FromMilliseconds(1000));
560 controller_impl->UpdateState(true, events.get());
561 EXPECT_EQ(expected_transform, dummy_impl.transform());
562 EXPECT_FALSE(controller_impl->HasActiveAnimation());
563 EXPECT_EQ(2u, events->size());
564 const AnimationEvent* end_transform_event =
565 GetMostRecentPropertyUpdateEvent(events.get());
566 EXPECT_EQ(expected_transform, end_transform_event->transform);
567 EXPECT_TRUE(end_transform_event->is_impl_only);
570 TEST(LayerAnimationControllerTest, FilterTransition) {
571 scoped_ptr<AnimationEventsVector> events(
572 make_scoped_ptr(new AnimationEventsVector));
573 FakeLayerAnimationValueObserver dummy;
574 scoped_refptr<LayerAnimationController> controller(
575 LayerAnimationController::Create(0));
576 controller->AddValueObserver(&dummy);
578 scoped_ptr<KeyframedFilterAnimationCurve> curve(
579 KeyframedFilterAnimationCurve::Create());
581 FilterOperations start_filters;
582 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f));
583 curve->AddKeyframe(
584 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr));
585 FilterOperations end_filters;
586 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f));
587 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
588 end_filters, nullptr));
590 scoped_ptr<Animation> animation(
591 Animation::Create(curve.Pass(), 1, 0, Animation::FILTER));
592 controller->AddAnimation(animation.Pass());
594 controller->Animate(kInitialTickTime);
595 controller->UpdateState(true, events.get());
596 EXPECT_TRUE(controller->HasActiveAnimation());
597 EXPECT_EQ(start_filters, dummy.filters());
598 // A non-impl-only animation should not generate property updates.
599 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get());
600 EXPECT_FALSE(event);
602 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
603 controller->UpdateState(true, events.get());
604 EXPECT_EQ(1u, dummy.filters().size());
605 EXPECT_EQ(FilterOperation::CreateBrightnessFilter(1.5f),
606 dummy.filters().at(0));
607 event = GetMostRecentPropertyUpdateEvent(events.get());
608 EXPECT_FALSE(event);
610 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
611 controller->UpdateState(true, events.get());
612 EXPECT_EQ(end_filters, dummy.filters());
613 EXPECT_FALSE(controller->HasActiveAnimation());
614 event = GetMostRecentPropertyUpdateEvent(events.get());
615 EXPECT_FALSE(event);
618 TEST(LayerAnimationControllerTest, FilterTransitionOnImplOnly) {
619 scoped_ptr<AnimationEventsVector> events(
620 make_scoped_ptr(new AnimationEventsVector));
621 FakeLayerAnimationValueObserver dummy_impl;
622 scoped_refptr<LayerAnimationController> controller_impl(
623 LayerAnimationController::Create(0));
624 controller_impl->AddValueObserver(&dummy_impl);
626 scoped_ptr<KeyframedFilterAnimationCurve> curve(
627 KeyframedFilterAnimationCurve::Create());
629 // Create simple FILTER animation.
630 FilterOperations start_filters;
631 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f));
632 curve->AddKeyframe(
633 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr));
634 FilterOperations end_filters;
635 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f));
636 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
637 end_filters, nullptr));
639 scoped_ptr<Animation> animation(
640 Animation::Create(curve.Pass(), 1, 0, Animation::FILTER));
641 animation->set_is_impl_only(true);
642 controller_impl->AddAnimation(animation.Pass());
644 // Run animation.
645 controller_impl->Animate(kInitialTickTime);
646 controller_impl->UpdateState(true, events.get());
647 EXPECT_TRUE(controller_impl->HasActiveAnimation());
648 EXPECT_EQ(start_filters, dummy_impl.filters());
649 EXPECT_EQ(1u, events->size());
650 const AnimationEvent* start_filter_event =
651 GetMostRecentPropertyUpdateEvent(events.get());
652 EXPECT_TRUE(start_filter_event);
653 EXPECT_EQ(start_filters, start_filter_event->filters);
654 EXPECT_TRUE(start_filter_event->is_impl_only);
656 controller_impl->Animate(kInitialTickTime +
657 TimeDelta::FromMilliseconds(1000));
658 controller_impl->UpdateState(true, events.get());
659 EXPECT_EQ(end_filters, dummy_impl.filters());
660 EXPECT_FALSE(controller_impl->HasActiveAnimation());
661 EXPECT_EQ(2u, events->size());
662 const AnimationEvent* end_filter_event =
663 GetMostRecentPropertyUpdateEvent(events.get());
664 EXPECT_TRUE(end_filter_event);
665 EXPECT_EQ(end_filters, end_filter_event->filters);
666 EXPECT_TRUE(end_filter_event->is_impl_only);
669 TEST(LayerAnimationControllerTest, ScrollOffsetTransition) {
670 FakeLayerAnimationValueObserver dummy_impl;
671 FakeLayerAnimationValueProvider dummy_provider_impl;
672 scoped_refptr<LayerAnimationController> controller_impl(
673 LayerAnimationController::Create(0));
674 controller_impl->AddValueObserver(&dummy_impl);
675 controller_impl->set_value_provider(&dummy_provider_impl);
676 scoped_ptr<AnimationEventsVector> events(
677 make_scoped_ptr(new AnimationEventsVector));
678 FakeLayerAnimationValueObserver dummy;
679 FakeLayerAnimationValueProvider dummy_provider;
680 scoped_refptr<LayerAnimationController> controller(
681 LayerAnimationController::Create(0));
682 controller->AddValueObserver(&dummy);
683 controller->set_value_provider(&dummy_provider);
685 gfx::ScrollOffset initial_value(100.f, 300.f);
686 gfx::ScrollOffset target_value(300.f, 200.f);
687 scoped_ptr<ScrollOffsetAnimationCurve> curve(
688 ScrollOffsetAnimationCurve::Create(
689 target_value,
690 EaseInOutTimingFunction::Create().Pass()));
692 scoped_ptr<Animation> animation(
693 Animation::Create(curve.Pass(), 1, 0, Animation::SCROLL_OFFSET));
694 animation->set_needs_synchronized_start_time(true);
695 controller->AddAnimation(animation.Pass());
697 dummy_provider_impl.set_scroll_offset(initial_value);
698 controller->PushAnimationUpdatesTo(controller_impl.get());
699 controller_impl->ActivateAnimations();
700 EXPECT_TRUE(controller_impl->GetAnimation(Animation::SCROLL_OFFSET));
701 TimeDelta duration = controller_impl->GetAnimation(Animation::SCROLL_OFFSET)
702 ->curve()
703 ->Duration();
704 EXPECT_EQ(
705 duration,
706 controller->GetAnimation(Animation::SCROLL_OFFSET)->curve()->Duration());
708 controller->Animate(kInitialTickTime);
709 controller->UpdateState(true, nullptr);
710 EXPECT_TRUE(controller->HasActiveAnimation());
711 EXPECT_EQ(initial_value, dummy.scroll_offset());
713 controller_impl->Animate(kInitialTickTime);
714 controller_impl->UpdateState(true, events.get());
715 EXPECT_TRUE(controller_impl->HasActiveAnimation());
716 EXPECT_EQ(initial_value, dummy_impl.scroll_offset());
717 // Scroll offset animations should not generate property updates.
718 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get());
719 EXPECT_FALSE(event);
721 controller->NotifyAnimationStarted((*events)[0]);
722 controller->Animate(kInitialTickTime + duration / 2);
723 controller->UpdateState(true, nullptr);
724 EXPECT_TRUE(controller->HasActiveAnimation());
725 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), dummy.scroll_offset());
727 controller_impl->Animate(kInitialTickTime + duration / 2);
728 controller_impl->UpdateState(true, events.get());
729 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f),
730 dummy_impl.scroll_offset());
731 event = GetMostRecentPropertyUpdateEvent(events.get());
732 EXPECT_FALSE(event);
734 controller_impl->Animate(kInitialTickTime + duration);
735 controller_impl->UpdateState(true, events.get());
736 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset());
737 EXPECT_FALSE(controller_impl->HasActiveAnimation());
738 event = GetMostRecentPropertyUpdateEvent(events.get());
739 EXPECT_FALSE(event);
741 controller->Animate(kInitialTickTime + duration);
742 controller->UpdateState(true, nullptr);
743 EXPECT_VECTOR2DF_EQ(target_value, dummy.scroll_offset());
744 EXPECT_FALSE(controller->HasActiveAnimation());
747 // Ensure that when the impl controller doesn't have a value provider,
748 // the main-thread controller's value provider is used to obtain the intial
749 // scroll offset.
750 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionNoImplProvider) {
751 FakeLayerAnimationValueObserver dummy_impl;
752 scoped_refptr<LayerAnimationController> controller_impl(
753 LayerAnimationController::Create(0));
754 controller_impl->AddValueObserver(&dummy_impl);
755 scoped_ptr<AnimationEventsVector> events(
756 make_scoped_ptr(new AnimationEventsVector));
757 FakeLayerAnimationValueObserver dummy;
758 FakeLayerAnimationValueProvider dummy_provider;
759 scoped_refptr<LayerAnimationController> controller(
760 LayerAnimationController::Create(0));
761 controller->AddValueObserver(&dummy);
762 controller->set_value_provider(&dummy_provider);
764 gfx::ScrollOffset initial_value(500.f, 100.f);
765 gfx::ScrollOffset target_value(300.f, 200.f);
766 scoped_ptr<ScrollOffsetAnimationCurve> curve(
767 ScrollOffsetAnimationCurve::Create(
768 target_value,
769 EaseInOutTimingFunction::Create().Pass()));
771 scoped_ptr<Animation> animation(
772 Animation::Create(curve.Pass(), 1, 0, Animation::SCROLL_OFFSET));
773 animation->set_needs_synchronized_start_time(true);
774 controller->AddAnimation(animation.Pass());
776 dummy_provider.set_scroll_offset(initial_value);
777 controller->PushAnimationUpdatesTo(controller_impl.get());
778 controller_impl->ActivateAnimations();
779 EXPECT_TRUE(controller_impl->GetAnimation(Animation::SCROLL_OFFSET));
780 TimeDelta duration = controller_impl->GetAnimation(Animation::SCROLL_OFFSET)
781 ->curve()
782 ->Duration();
783 EXPECT_EQ(
784 duration,
785 controller->GetAnimation(Animation::SCROLL_OFFSET)->curve()->Duration());
787 controller->Animate(kInitialTickTime);
788 controller->UpdateState(true, nullptr);
789 EXPECT_TRUE(controller->HasActiveAnimation());
790 EXPECT_EQ(initial_value, dummy.scroll_offset());
792 controller_impl->Animate(kInitialTickTime);
793 controller_impl->UpdateState(true, events.get());
794 EXPECT_TRUE(controller_impl->HasActiveAnimation());
795 EXPECT_EQ(initial_value, dummy_impl.scroll_offset());
796 // Scroll offset animations should not generate property updates.
797 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get());
798 EXPECT_FALSE(event);
801 controller->NotifyAnimationStarted((*events)[0]);
802 controller->Animate(kInitialTickTime + duration / 2);
803 controller->UpdateState(true, nullptr);
804 EXPECT_TRUE(controller->HasActiveAnimation());
805 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f), dummy.scroll_offset());
807 controller_impl->Animate(kInitialTickTime + duration / 2);
808 controller_impl->UpdateState(true, events.get());
809 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f),
810 dummy_impl.scroll_offset());
811 event = GetMostRecentPropertyUpdateEvent(events.get());
812 EXPECT_FALSE(event);
814 controller_impl->Animate(kInitialTickTime + duration);
815 controller_impl->UpdateState(true, events.get());
816 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset());
817 EXPECT_FALSE(controller_impl->HasActiveAnimation());
818 event = GetMostRecentPropertyUpdateEvent(events.get());
819 EXPECT_FALSE(event);
821 controller->Animate(kInitialTickTime + duration);
822 controller->UpdateState(true, nullptr);
823 EXPECT_VECTOR2DF_EQ(target_value, dummy.scroll_offset());
824 EXPECT_FALSE(controller->HasActiveAnimation());
827 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionOnImplOnly) {
828 FakeLayerAnimationValueObserver dummy_impl;
829 scoped_refptr<LayerAnimationController> controller_impl(
830 LayerAnimationController::Create(0));
831 controller_impl->AddValueObserver(&dummy_impl);
832 scoped_ptr<AnimationEventsVector> events(
833 make_scoped_ptr(new AnimationEventsVector));
835 gfx::ScrollOffset initial_value(100.f, 300.f);
836 gfx::ScrollOffset target_value(300.f, 200.f);
837 scoped_ptr<ScrollOffsetAnimationCurve> curve(
838 ScrollOffsetAnimationCurve::Create(
839 target_value,
840 EaseInOutTimingFunction::Create().Pass()));
841 curve->SetInitialValue(initial_value);
842 double duration_in_seconds = curve->Duration().InSecondsF();
844 scoped_ptr<Animation> animation(
845 Animation::Create(curve.Pass(), 1, 0, Animation::SCROLL_OFFSET));
846 animation->set_is_impl_only(true);
847 controller_impl->AddAnimation(animation.Pass());
849 controller_impl->Animate(kInitialTickTime);
850 controller_impl->UpdateState(true, events.get());
851 EXPECT_TRUE(controller_impl->HasActiveAnimation());
852 EXPECT_EQ(initial_value, dummy_impl.scroll_offset());
853 // Scroll offset animations should not generate property updates.
854 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get());
855 EXPECT_FALSE(event);
857 TimeDelta duration = TimeDelta::FromMicroseconds(
858 duration_in_seconds * base::Time::kMicrosecondsPerSecond);
860 controller_impl->Animate(kInitialTickTime + duration / 2);
861 controller_impl->UpdateState(true, events.get());
862 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f),
863 dummy_impl.scroll_offset());
864 event = GetMostRecentPropertyUpdateEvent(events.get());
865 EXPECT_FALSE(event);
867 controller_impl->Animate(kInitialTickTime + duration);
868 controller_impl->UpdateState(true, events.get());
869 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset());
870 EXPECT_FALSE(controller_impl->HasActiveAnimation());
871 event = GetMostRecentPropertyUpdateEvent(events.get());
872 EXPECT_FALSE(event);
875 TEST(LayerAnimationControllerTest, ScrollOffsetRemovalClearsScrollDelta) {
876 FakeLayerAnimationValueObserver dummy_impl;
877 FakeLayerAnimationValueProvider dummy_provider_impl;
878 scoped_refptr<LayerAnimationController> controller_impl(
879 LayerAnimationController::Create(0));
880 controller_impl->AddValueObserver(&dummy_impl);
881 controller_impl->set_value_provider(&dummy_provider_impl);
882 scoped_ptr<AnimationEventsVector> events(
883 make_scoped_ptr(new AnimationEventsVector));
884 FakeLayerAnimationValueObserver dummy;
885 FakeLayerAnimationValueProvider dummy_provider;
886 scoped_refptr<LayerAnimationController> controller(
887 LayerAnimationController::Create(0));
888 controller->AddValueObserver(&dummy);
889 controller->set_value_provider(&dummy_provider);
891 // First test the 1-argument version of RemoveAnimation.
892 gfx::ScrollOffset target_value(300.f, 200.f);
893 scoped_ptr<ScrollOffsetAnimationCurve> curve(
894 ScrollOffsetAnimationCurve::Create(
895 target_value, EaseInOutTimingFunction::Create().Pass()));
897 int animation_id = 1;
898 scoped_ptr<Animation> animation(Animation::Create(
899 curve.Pass(), animation_id, 0, Animation::SCROLL_OFFSET));
900 animation->set_needs_synchronized_start_time(true);
901 controller->AddAnimation(animation.Pass());
902 controller->PushAnimationUpdatesTo(controller_impl.get());
903 controller_impl->ActivateAnimations();
904 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted());
905 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted());
907 controller->RemoveAnimation(animation_id);
908 EXPECT_TRUE(controller->scroll_offset_animation_was_interrupted());
910 controller->PushAnimationUpdatesTo(controller_impl.get());
911 EXPECT_TRUE(controller_impl->scroll_offset_animation_was_interrupted());
912 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted());
914 controller_impl->ActivateAnimations();
915 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted());
917 // Now, test the 2-argument version of RemoveAnimation.
918 curve = ScrollOffsetAnimationCurve::Create(
919 target_value, EaseInOutTimingFunction::Create().Pass());
920 animation = Animation::Create(curve.Pass(), animation_id, 0,
921 Animation::SCROLL_OFFSET);
922 animation->set_needs_synchronized_start_time(true);
923 controller->AddAnimation(animation.Pass());
924 controller->PushAnimationUpdatesTo(controller_impl.get());
925 controller_impl->ActivateAnimations();
926 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted());
927 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted());
929 controller->RemoveAnimation(animation_id);
930 EXPECT_TRUE(controller->scroll_offset_animation_was_interrupted());
932 controller->PushAnimationUpdatesTo(controller_impl.get());
933 EXPECT_TRUE(controller_impl->scroll_offset_animation_was_interrupted());
934 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted());
936 controller_impl->ActivateAnimations();
937 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted());
939 // Check that removing non-scroll-offset animations does not cause
940 // scroll_offset_animation_was_interrupted() to get set.
941 animation_id = AddAnimatedTransformToController(controller.get(), 1.0, 1, 2);
942 controller->PushAnimationUpdatesTo(controller_impl.get());
943 controller_impl->ActivateAnimations();
944 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted());
945 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted());
947 controller->RemoveAnimation(animation_id);
948 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted());
950 controller->PushAnimationUpdatesTo(controller_impl.get());
951 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted());
952 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted());
954 controller_impl->ActivateAnimations();
955 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted());
957 animation_id =
958 AddAnimatedFilterToController(controller.get(), 1.0, 0.1f, 0.2f);
959 controller->PushAnimationUpdatesTo(controller_impl.get());
960 controller_impl->ActivateAnimations();
961 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted());
962 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted());
964 controller->RemoveAnimation(animation_id);
965 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted());
967 controller->PushAnimationUpdatesTo(controller_impl.get());
968 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted());
969 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted());
971 controller_impl->ActivateAnimations();
972 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted());
975 class FakeAnimationDelegate : public AnimationDelegate {
976 public:
977 FakeAnimationDelegate()
978 : started_(false), finished_(false), start_time_(base::TimeTicks()) {}
980 void NotifyAnimationStarted(TimeTicks monotonic_time,
981 Animation::TargetProperty target_property,
982 int group) override {
983 started_ = true;
984 start_time_ = monotonic_time;
987 void NotifyAnimationFinished(TimeTicks monotonic_time,
988 Animation::TargetProperty target_property,
989 int group) override {
990 finished_ = true;
993 bool started() { return started_; }
995 bool finished() { return finished_; }
997 TimeTicks start_time() { return start_time_; }
999 private:
1000 bool started_;
1001 bool finished_;
1002 TimeTicks start_time_;
1005 // Tests that impl-only animations lead to start and finished notifications
1006 // on the impl thread controller's animation delegate.
1007 TEST(LayerAnimationControllerTest,
1008 NotificationsForImplOnlyAnimationsAreSentToImplThreadDelegate) {
1009 FakeLayerAnimationValueObserver dummy_impl;
1010 scoped_refptr<LayerAnimationController> controller_impl(
1011 LayerAnimationController::Create(0));
1012 controller_impl->AddValueObserver(&dummy_impl);
1013 scoped_ptr<AnimationEventsVector> events(
1014 make_scoped_ptr(new AnimationEventsVector));
1015 FakeAnimationDelegate delegate;
1016 controller_impl->set_layer_animation_delegate(&delegate);
1018 scoped_ptr<Animation> to_add(CreateAnimation(
1019 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1020 1, Animation::OPACITY));
1021 to_add->set_is_impl_only(true);
1022 controller_impl->AddAnimation(to_add.Pass());
1024 EXPECT_FALSE(delegate.started());
1025 EXPECT_FALSE(delegate.finished());
1027 controller_impl->Animate(kInitialTickTime);
1028 controller_impl->UpdateState(true, events.get());
1030 EXPECT_TRUE(delegate.started());
1031 EXPECT_FALSE(delegate.finished());
1033 events.reset(new AnimationEventsVector);
1034 controller_impl->Animate(kInitialTickTime +
1035 TimeDelta::FromMilliseconds(1000));
1036 controller_impl->UpdateState(true, events.get());
1038 EXPECT_TRUE(delegate.started());
1039 EXPECT_TRUE(delegate.finished());
1042 // Tests that specified start times are sent to the main thread delegate
1043 TEST(LayerAnimationControllerTest,
1044 SpecifiedStartTimesAreSentToMainThreadDelegate) {
1045 FakeLayerAnimationValueObserver dummy_impl;
1046 scoped_refptr<LayerAnimationController> controller_impl(
1047 LayerAnimationController::Create(0));
1048 controller_impl->AddValueObserver(&dummy_impl);
1049 FakeLayerAnimationValueObserver dummy;
1050 scoped_refptr<LayerAnimationController> controller(
1051 LayerAnimationController::Create(0));
1052 controller->AddValueObserver(&dummy);
1053 FakeAnimationDelegate delegate;
1054 controller->set_layer_animation_delegate(&delegate);
1056 int animation_id =
1057 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false);
1059 const TimeTicks start_time = TicksFromSecondsF(123);
1060 controller->GetAnimation(Animation::OPACITY)->set_start_time(start_time);
1062 controller->PushAnimationUpdatesTo(controller_impl.get());
1063 controller_impl->ActivateAnimations();
1065 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id));
1066 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
1067 controller_impl->GetAnimationById(animation_id)->run_state());
1069 AnimationEventsVector events;
1070 controller_impl->Animate(kInitialTickTime);
1071 controller_impl->UpdateState(true, &events);
1073 // Synchronize the start times.
1074 EXPECT_EQ(1u, events.size());
1075 controller->NotifyAnimationStarted(events[0]);
1077 // Validate start time on the main thread delegate.
1078 EXPECT_EQ(start_time, delegate.start_time());
1081 class FakeLayerAnimationEventObserver : public LayerAnimationEventObserver {
1082 public:
1083 FakeLayerAnimationEventObserver() : start_time_(base::TimeTicks()) {}
1085 void OnAnimationStarted(const AnimationEvent& event) override {
1086 start_time_ = event.monotonic_time;
1089 TimeTicks start_time() { return start_time_; }
1091 private:
1092 TimeTicks start_time_;
1095 // Tests that specified start times are sent to the event observers
1096 TEST(LayerAnimationControllerTest, SpecifiedStartTimesAreSentToEventObservers) {
1097 FakeLayerAnimationValueObserver dummy_impl;
1098 scoped_refptr<LayerAnimationController> controller_impl(
1099 LayerAnimationController::Create(0));
1100 controller_impl->AddValueObserver(&dummy_impl);
1101 FakeLayerAnimationValueObserver dummy;
1102 scoped_refptr<LayerAnimationController> controller(
1103 LayerAnimationController::Create(0));
1104 controller->AddValueObserver(&dummy);
1105 FakeLayerAnimationEventObserver observer;
1106 controller->AddEventObserver(&observer);
1108 int animation_id =
1109 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false);
1111 const TimeTicks start_time = TicksFromSecondsF(123);
1112 controller->GetAnimation(Animation::OPACITY)->set_start_time(start_time);
1114 controller->PushAnimationUpdatesTo(controller_impl.get());
1115 controller_impl->ActivateAnimations();
1117 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id));
1118 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
1119 controller_impl->GetAnimationById(animation_id)->run_state());
1121 AnimationEventsVector events;
1122 controller_impl->Animate(kInitialTickTime);
1123 controller_impl->UpdateState(true, &events);
1125 // Synchronize the start times.
1126 EXPECT_EQ(1u, events.size());
1127 controller->NotifyAnimationStarted(events[0]);
1129 // Validate start time on the event observer.
1130 EXPECT_EQ(start_time, observer.start_time());
1133 // Tests animations that are waiting for a synchronized start time do not
1134 // finish.
1135 TEST(LayerAnimationControllerTest,
1136 AnimationsWaitingForStartTimeDoNotFinishIfTheyOutwaitTheirFinish) {
1137 scoped_ptr<AnimationEventsVector> events(
1138 make_scoped_ptr(new AnimationEventsVector));
1139 FakeLayerAnimationValueObserver dummy;
1140 scoped_refptr<LayerAnimationController> controller(
1141 LayerAnimationController::Create(0));
1142 controller->AddValueObserver(&dummy);
1144 scoped_ptr<Animation> to_add(CreateAnimation(
1145 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1146 1, Animation::OPACITY));
1147 to_add->set_needs_synchronized_start_time(true);
1149 // We should pause at the first keyframe indefinitely waiting for that
1150 // animation to start.
1151 controller->AddAnimation(to_add.Pass());
1152 controller->Animate(kInitialTickTime);
1153 controller->UpdateState(true, events.get());
1154 EXPECT_TRUE(controller->HasActiveAnimation());
1155 EXPECT_EQ(0.f, dummy.opacity());
1156 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1157 controller->UpdateState(true, events.get());
1158 EXPECT_TRUE(controller->HasActiveAnimation());
1159 EXPECT_EQ(0.f, dummy.opacity());
1160 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
1161 controller->UpdateState(true, events.get());
1162 EXPECT_TRUE(controller->HasActiveAnimation());
1163 EXPECT_EQ(0.f, dummy.opacity());
1165 // Send the synchronized start time.
1166 controller->NotifyAnimationStarted(
1167 AnimationEvent(AnimationEvent::STARTED, 0, 1, Animation::OPACITY,
1168 kInitialTickTime + TimeDelta::FromMilliseconds(2000)));
1169 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(5000));
1170 controller->UpdateState(true, events.get());
1171 EXPECT_EQ(1.f, dummy.opacity());
1172 EXPECT_FALSE(controller->HasActiveAnimation());
1175 // Tests that two queued animations affecting the same property run in sequence.
1176 TEST(LayerAnimationControllerTest, TrivialQueuing) {
1177 scoped_ptr<AnimationEventsVector> events(
1178 make_scoped_ptr(new AnimationEventsVector));
1179 FakeLayerAnimationValueObserver dummy;
1180 scoped_refptr<LayerAnimationController> controller(
1181 LayerAnimationController::Create(0));
1182 controller->AddValueObserver(&dummy);
1184 EXPECT_FALSE(controller->needs_to_start_animations_for_testing());
1186 controller->AddAnimation(CreateAnimation(
1187 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1188 1, Animation::OPACITY));
1189 controller->AddAnimation(CreateAnimation(
1190 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f))
1191 .Pass(),
1192 2, Animation::OPACITY));
1194 EXPECT_TRUE(controller->needs_to_start_animations_for_testing());
1196 controller->Animate(kInitialTickTime);
1198 // The second animation still needs to be started.
1199 EXPECT_TRUE(controller->needs_to_start_animations_for_testing());
1201 controller->UpdateState(true, events.get());
1202 EXPECT_TRUE(controller->HasActiveAnimation());
1203 EXPECT_EQ(0.f, dummy.opacity());
1205 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1206 EXPECT_TRUE(controller->needs_to_start_animations_for_testing());
1207 controller->UpdateState(true, events.get());
1208 EXPECT_FALSE(controller->needs_to_start_animations_for_testing());
1210 EXPECT_TRUE(controller->HasActiveAnimation());
1211 EXPECT_EQ(1.f, dummy.opacity());
1212 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
1213 controller->UpdateState(true, events.get());
1214 EXPECT_EQ(0.5f, dummy.opacity());
1215 EXPECT_FALSE(controller->HasActiveAnimation());
1218 // Tests interrupting a transition with another transition.
1219 TEST(LayerAnimationControllerTest, Interrupt) {
1220 scoped_ptr<AnimationEventsVector> events(
1221 make_scoped_ptr(new AnimationEventsVector));
1222 FakeLayerAnimationValueObserver dummy;
1223 scoped_refptr<LayerAnimationController> controller(
1224 LayerAnimationController::Create(0));
1225 controller->AddValueObserver(&dummy);
1226 controller->AddAnimation(CreateAnimation(
1227 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1228 1, Animation::OPACITY));
1229 controller->Animate(kInitialTickTime);
1230 controller->UpdateState(true, events.get());
1231 EXPECT_TRUE(controller->HasActiveAnimation());
1232 EXPECT_EQ(0.f, dummy.opacity());
1234 scoped_ptr<Animation> to_add(CreateAnimation(
1235 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f))
1236 .Pass(),
1237 2, Animation::OPACITY));
1238 controller->AbortAnimations(Animation::OPACITY);
1239 controller->AddAnimation(to_add.Pass());
1241 // Since the previous animation was aborted, the new animation should start
1242 // right in this call to animate.
1243 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
1244 controller->UpdateState(true, events.get());
1245 EXPECT_TRUE(controller->HasActiveAnimation());
1246 EXPECT_EQ(1.f, dummy.opacity());
1247 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1500));
1248 controller->UpdateState(true, events.get());
1249 EXPECT_EQ(0.5f, dummy.opacity());
1250 EXPECT_FALSE(controller->HasActiveAnimation());
1253 // Tests scheduling two animations to run together when only one property is
1254 // free.
1255 TEST(LayerAnimationControllerTest, ScheduleTogetherWhenAPropertyIsBlocked) {
1256 scoped_ptr<AnimationEventsVector> events(
1257 make_scoped_ptr(new AnimationEventsVector));
1258 FakeLayerAnimationValueObserver dummy;
1259 scoped_refptr<LayerAnimationController> controller(
1260 LayerAnimationController::Create(0));
1261 controller->AddValueObserver(&dummy);
1263 controller->AddAnimation(CreateAnimation(
1264 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), 1,
1265 Animation::TRANSFORM));
1266 controller->AddAnimation(CreateAnimation(
1267 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), 2,
1268 Animation::TRANSFORM));
1269 controller->AddAnimation(CreateAnimation(
1270 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1271 2, Animation::OPACITY));
1273 controller->Animate(kInitialTickTime);
1274 controller->UpdateState(true, events.get());
1275 EXPECT_EQ(0.f, dummy.opacity());
1276 EXPECT_TRUE(controller->HasActiveAnimation());
1277 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1278 controller->UpdateState(true, events.get());
1279 // Should not have started the float transition yet.
1280 EXPECT_TRUE(controller->HasActiveAnimation());
1281 EXPECT_EQ(0.f, dummy.opacity());
1282 // The float animation should have started at time 1 and should be done.
1283 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
1284 controller->UpdateState(true, events.get());
1285 EXPECT_EQ(1.f, dummy.opacity());
1286 EXPECT_FALSE(controller->HasActiveAnimation());
1289 // Tests scheduling two animations to run together with different lengths and
1290 // another animation queued to start when the shorter animation finishes (should
1291 // wait for both to finish).
1292 TEST(LayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting) {
1293 scoped_ptr<AnimationEventsVector> events(
1294 make_scoped_ptr(new AnimationEventsVector));
1295 FakeLayerAnimationValueObserver dummy;
1296 scoped_refptr<LayerAnimationController> controller(
1297 LayerAnimationController::Create(0));
1298 controller->AddValueObserver(&dummy);
1300 controller->AddAnimation(CreateAnimation(
1301 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2)).Pass(), 1,
1302 Animation::TRANSFORM));
1303 controller->AddAnimation(CreateAnimation(
1304 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1305 1, Animation::OPACITY));
1306 controller->AddAnimation(CreateAnimation(
1307 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f))
1308 .Pass(),
1309 2, Animation::OPACITY));
1311 // Animations with id 1 should both start now.
1312 controller->Animate(kInitialTickTime);
1313 controller->UpdateState(true, events.get());
1314 EXPECT_TRUE(controller->HasActiveAnimation());
1315 EXPECT_EQ(0.f, dummy.opacity());
1316 // The opacity animation should have finished at time 1, but the group
1317 // of animations with id 1 don't finish until time 2 because of the length
1318 // of the transform animation.
1319 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
1320 controller->UpdateState(true, events.get());
1321 // Should not have started the float transition yet.
1322 EXPECT_TRUE(controller->HasActiveAnimation());
1323 EXPECT_EQ(1.f, dummy.opacity());
1325 // The second opacity animation should start at time 2 and should be done by
1326 // time 3.
1327 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000));
1328 controller->UpdateState(true, events.get());
1329 EXPECT_EQ(0.5f, dummy.opacity());
1330 EXPECT_FALSE(controller->HasActiveAnimation());
1333 // Test that a looping animation loops and for the correct number of iterations.
1334 TEST(LayerAnimationControllerTest, TrivialLooping) {
1335 scoped_ptr<AnimationEventsVector> events(
1336 make_scoped_ptr(new AnimationEventsVector));
1337 FakeLayerAnimationValueObserver dummy;
1338 scoped_refptr<LayerAnimationController> controller(
1339 LayerAnimationController::Create(0));
1340 controller->AddValueObserver(&dummy);
1342 scoped_ptr<Animation> to_add(CreateAnimation(
1343 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1344 1, Animation::OPACITY));
1345 to_add->set_iterations(3);
1346 controller->AddAnimation(to_add.Pass());
1348 controller->Animate(kInitialTickTime);
1349 controller->UpdateState(true, events.get());
1350 EXPECT_TRUE(controller->HasActiveAnimation());
1351 EXPECT_EQ(0.f, dummy.opacity());
1352 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1250));
1353 controller->UpdateState(true, events.get());
1354 EXPECT_TRUE(controller->HasActiveAnimation());
1355 EXPECT_EQ(0.25f, dummy.opacity());
1356 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1750));
1357 controller->UpdateState(true, events.get());
1358 EXPECT_TRUE(controller->HasActiveAnimation());
1359 EXPECT_EQ(0.75f, dummy.opacity());
1360 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2250));
1361 controller->UpdateState(true, events.get());
1362 EXPECT_TRUE(controller->HasActiveAnimation());
1363 EXPECT_EQ(0.25f, dummy.opacity());
1364 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2750));
1365 controller->UpdateState(true, events.get());
1366 EXPECT_TRUE(controller->HasActiveAnimation());
1367 EXPECT_EQ(0.75f, dummy.opacity());
1368 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000));
1369 controller->UpdateState(true, events.get());
1370 EXPECT_FALSE(controller->HasActiveAnimation());
1371 EXPECT_EQ(1.f, dummy.opacity());
1373 // Just be extra sure.
1374 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(4000));
1375 controller->UpdateState(true, events.get());
1376 EXPECT_EQ(1.f, dummy.opacity());
1379 // Test that an infinitely looping animation does indeed go until aborted.
1380 TEST(LayerAnimationControllerTest, InfiniteLooping) {
1381 scoped_ptr<AnimationEventsVector> events(
1382 make_scoped_ptr(new AnimationEventsVector));
1383 FakeLayerAnimationValueObserver dummy;
1384 scoped_refptr<LayerAnimationController> controller(
1385 LayerAnimationController::Create(0));
1386 controller->AddValueObserver(&dummy);
1388 scoped_ptr<Animation> to_add(CreateAnimation(
1389 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1390 1, Animation::OPACITY));
1391 to_add->set_iterations(-1);
1392 controller->AddAnimation(to_add.Pass());
1394 controller->Animate(kInitialTickTime);
1395 controller->UpdateState(true, events.get());
1396 EXPECT_TRUE(controller->HasActiveAnimation());
1397 EXPECT_EQ(0.f, dummy.opacity());
1398 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1250));
1399 controller->UpdateState(true, events.get());
1400 EXPECT_TRUE(controller->HasActiveAnimation());
1401 EXPECT_EQ(0.25f, dummy.opacity());
1402 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1750));
1403 controller->UpdateState(true, events.get());
1404 EXPECT_TRUE(controller->HasActiveAnimation());
1405 EXPECT_EQ(0.75f, dummy.opacity());
1407 controller->Animate(kInitialTickTime +
1408 TimeDelta::FromMilliseconds(1073741824250));
1409 controller->UpdateState(true, events.get());
1410 EXPECT_TRUE(controller->HasActiveAnimation());
1411 EXPECT_EQ(0.25f, dummy.opacity());
1412 controller->Animate(kInitialTickTime +
1413 TimeDelta::FromMilliseconds(1073741824750));
1414 controller->UpdateState(true, events.get());
1415 EXPECT_TRUE(controller->HasActiveAnimation());
1416 EXPECT_EQ(0.75f, dummy.opacity());
1418 EXPECT_TRUE(controller->GetAnimation(Animation::OPACITY));
1419 controller->GetAnimation(Animation::OPACITY)
1420 ->SetRunState(Animation::ABORTED,
1421 kInitialTickTime + TimeDelta::FromMilliseconds(750));
1422 EXPECT_FALSE(controller->HasActiveAnimation());
1423 EXPECT_EQ(0.75f, dummy.opacity());
1426 // Test that pausing and resuming work as expected.
1427 TEST(LayerAnimationControllerTest, PauseResume) {
1428 scoped_ptr<AnimationEventsVector> events(
1429 make_scoped_ptr(new AnimationEventsVector));
1430 FakeLayerAnimationValueObserver dummy;
1431 scoped_refptr<LayerAnimationController> controller(
1432 LayerAnimationController::Create(0));
1433 controller->AddValueObserver(&dummy);
1435 controller->AddAnimation(CreateAnimation(
1436 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1437 1, Animation::OPACITY));
1439 controller->Animate(kInitialTickTime);
1440 controller->UpdateState(true, events.get());
1441 EXPECT_TRUE(controller->HasActiveAnimation());
1442 EXPECT_EQ(0.f, dummy.opacity());
1443 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
1444 controller->UpdateState(true, events.get());
1445 EXPECT_TRUE(controller->HasActiveAnimation());
1446 EXPECT_EQ(0.5f, dummy.opacity());
1448 EXPECT_TRUE(controller->GetAnimation(Animation::OPACITY));
1449 controller->GetAnimation(Animation::OPACITY)
1450 ->SetRunState(Animation::PAUSED,
1451 kInitialTickTime + TimeDelta::FromMilliseconds(500));
1453 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024000));
1454 controller->UpdateState(true, events.get());
1455 EXPECT_TRUE(controller->HasActiveAnimation());
1456 EXPECT_EQ(0.5f, dummy.opacity());
1458 EXPECT_TRUE(controller->GetAnimation(Animation::OPACITY));
1459 controller->GetAnimation(Animation::OPACITY)
1460 ->SetRunState(Animation::RUNNING,
1461 kInitialTickTime + TimeDelta::FromMilliseconds(1024000));
1462 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024250));
1463 controller->UpdateState(true, events.get());
1464 EXPECT_TRUE(controller->HasActiveAnimation());
1465 EXPECT_EQ(0.75f, dummy.opacity());
1467 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024500));
1468 controller->UpdateState(true, events.get());
1469 EXPECT_FALSE(controller->HasActiveAnimation());
1470 EXPECT_EQ(1.f, dummy.opacity());
1473 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) {
1474 scoped_ptr<AnimationEventsVector> events(
1475 make_scoped_ptr(new AnimationEventsVector));
1476 FakeLayerAnimationValueObserver dummy;
1477 scoped_refptr<LayerAnimationController> controller(
1478 LayerAnimationController::Create(0));
1479 controller->AddValueObserver(&dummy);
1481 const int animation_id = 2;
1482 controller->AddAnimation(Animation::Create(
1483 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), 1, 1,
1484 Animation::TRANSFORM));
1485 controller->AddAnimation(Animation::Create(
1486 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(),
1487 animation_id, 1, Animation::OPACITY));
1488 controller->AddAnimation(Animation::Create(
1489 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.75f))
1490 .Pass(),
1491 3, 2, Animation::OPACITY));
1493 controller->Animate(kInitialTickTime);
1494 controller->UpdateState(true, events.get());
1495 EXPECT_TRUE(controller->HasActiveAnimation());
1496 EXPECT_EQ(0.f, dummy.opacity());
1497 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1498 controller->UpdateState(true, events.get());
1499 EXPECT_TRUE(controller->HasActiveAnimation());
1500 EXPECT_EQ(0.5f, dummy.opacity());
1502 EXPECT_TRUE(controller->GetAnimationById(animation_id));
1503 controller->GetAnimationById(animation_id)
1504 ->SetRunState(Animation::ABORTED,
1505 kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1506 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1507 controller->UpdateState(true, events.get());
1508 EXPECT_TRUE(controller->HasActiveAnimation());
1509 EXPECT_EQ(1.f, dummy.opacity());
1510 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
1511 controller->UpdateState(true, events.get());
1512 EXPECT_TRUE(!controller->HasActiveAnimation());
1513 EXPECT_EQ(0.75f, dummy.opacity());
1516 TEST(LayerAnimationControllerTest, PushUpdatesWhenSynchronizedStartTimeNeeded) {
1517 FakeLayerAnimationValueObserver dummy_impl;
1518 scoped_refptr<LayerAnimationController> controller_impl(
1519 LayerAnimationController::Create(0));
1520 controller_impl->AddValueObserver(&dummy_impl);
1521 scoped_ptr<AnimationEventsVector> events(
1522 make_scoped_ptr(new AnimationEventsVector));
1523 FakeLayerAnimationValueObserver dummy;
1524 scoped_refptr<LayerAnimationController> controller(
1525 LayerAnimationController::Create(0));
1526 controller->AddValueObserver(&dummy);
1528 scoped_ptr<Animation> to_add(CreateAnimation(
1529 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(),
1530 0, Animation::OPACITY));
1531 to_add->set_needs_synchronized_start_time(true);
1532 controller->AddAnimation(to_add.Pass());
1534 controller->Animate(kInitialTickTime);
1535 controller->UpdateState(true, events.get());
1536 EXPECT_TRUE(controller->HasActiveAnimation());
1537 Animation* active_animation = controller->GetAnimation(Animation::OPACITY);
1538 EXPECT_TRUE(active_animation);
1539 EXPECT_TRUE(active_animation->needs_synchronized_start_time());
1541 controller->PushAnimationUpdatesTo(controller_impl.get());
1542 controller_impl->ActivateAnimations();
1544 active_animation = controller_impl->GetAnimation(Animation::OPACITY);
1545 EXPECT_TRUE(active_animation);
1546 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
1547 active_animation->run_state());
1550 // Tests that skipping a call to UpdateState works as expected.
1551 TEST(LayerAnimationControllerTest, SkipUpdateState) {
1552 scoped_ptr<AnimationEventsVector> events(
1553 make_scoped_ptr(new AnimationEventsVector));
1554 FakeLayerAnimationValueObserver dummy;
1555 scoped_refptr<LayerAnimationController> controller(
1556 LayerAnimationController::Create(0));
1557 controller->AddValueObserver(&dummy);
1559 scoped_ptr<Animation> first_animation(CreateAnimation(
1560 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), 1,
1561 Animation::TRANSFORM));
1562 first_animation->set_is_controlling_instance_for_test(true);
1563 controller->AddAnimation(first_animation.Pass());
1565 controller->Animate(kInitialTickTime);
1566 controller->UpdateState(true, events.get());
1568 scoped_ptr<Animation> second_animation(CreateAnimation(
1569 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1570 2, Animation::OPACITY));
1571 second_animation->set_is_controlling_instance_for_test(true);
1572 controller->AddAnimation(second_animation.Pass());
1574 // Animate but don't UpdateState.
1575 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1577 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
1578 events.reset(new AnimationEventsVector);
1579 controller->UpdateState(true, events.get());
1581 // Should have one STARTED event and one FINISHED event.
1582 EXPECT_EQ(2u, events->size());
1583 EXPECT_NE((*events)[0].type, (*events)[1].type);
1585 // The float transition should still be at its starting point.
1586 EXPECT_TRUE(controller->HasActiveAnimation());
1587 EXPECT_EQ(0.f, dummy.opacity());
1589 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000));
1590 controller->UpdateState(true, events.get());
1592 // The float tranisition should now be done.
1593 EXPECT_EQ(1.f, dummy.opacity());
1594 EXPECT_FALSE(controller->HasActiveAnimation());
1597 // Tests that an animation controller with only a pending observer gets ticked
1598 // but doesn't progress animations past the STARTING state.
1599 TEST(LayerAnimationControllerTest, InactiveObserverGetsTicked) {
1600 scoped_ptr<AnimationEventsVector> events(
1601 make_scoped_ptr(new AnimationEventsVector));
1602 FakeLayerAnimationValueObserver dummy;
1603 FakeInactiveLayerAnimationValueObserver pending_dummy;
1604 scoped_refptr<LayerAnimationController> controller(
1605 LayerAnimationController::Create(0));
1607 const int id = 1;
1608 controller->AddAnimation(CreateAnimation(
1609 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.5f, 1.f))
1610 .Pass(),
1611 id, Animation::OPACITY));
1613 // Without an observer, the animation shouldn't progress to the STARTING
1614 // state.
1615 controller->Animate(kInitialTickTime);
1616 controller->UpdateState(true, events.get());
1617 EXPECT_EQ(0u, events->size());
1618 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
1619 controller->GetAnimation(Animation::OPACITY)->run_state());
1621 controller->AddValueObserver(&pending_dummy);
1623 // With only a pending observer, the animation should progress to the
1624 // STARTING state and get ticked at its starting point, but should not
1625 // progress to RUNNING.
1626 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1627 controller->UpdateState(true, events.get());
1628 EXPECT_EQ(0u, events->size());
1629 EXPECT_EQ(Animation::STARTING,
1630 controller->GetAnimation(Animation::OPACITY)->run_state());
1631 EXPECT_EQ(0.5f, pending_dummy.opacity());
1633 // Even when already in the STARTING state, the animation should stay
1634 // there, and shouldn't be ticked past its starting point.
1635 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
1636 controller->UpdateState(true, events.get());
1637 EXPECT_EQ(0u, events->size());
1638 EXPECT_EQ(Animation::STARTING,
1639 controller->GetAnimation(Animation::OPACITY)->run_state());
1640 EXPECT_EQ(0.5f, pending_dummy.opacity());
1642 controller->AddValueObserver(&dummy);
1644 // Now that an active observer has been added, the animation should still
1645 // initially tick at its starting point, but should now progress to RUNNING.
1646 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000));
1647 controller->UpdateState(true, events.get());
1648 EXPECT_EQ(1u, events->size());
1649 EXPECT_EQ(Animation::RUNNING,
1650 controller->GetAnimation(Animation::OPACITY)->run_state());
1651 EXPECT_EQ(0.5f, pending_dummy.opacity());
1652 EXPECT_EQ(0.5f, dummy.opacity());
1654 // The animation should now tick past its starting point.
1655 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3500));
1656 EXPECT_NE(0.5f, pending_dummy.opacity());
1657 EXPECT_NE(0.5f, dummy.opacity());
1660 TEST(LayerAnimationControllerTest, TransformAnimationBounds) {
1661 scoped_refptr<LayerAnimationController> controller_impl(
1662 LayerAnimationController::Create(0));
1664 scoped_ptr<KeyframedTransformAnimationCurve> curve1(
1665 KeyframedTransformAnimationCurve::Create());
1667 TransformOperations operations1;
1668 curve1->AddKeyframe(
1669 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
1670 operations1.AppendTranslate(10.0, 15.0, 0.0);
1671 curve1->AddKeyframe(TransformKeyframe::Create(
1672 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr));
1674 scoped_ptr<Animation> animation(
1675 Animation::Create(curve1.Pass(), 1, 1, Animation::TRANSFORM));
1676 controller_impl->AddAnimation(animation.Pass());
1678 scoped_ptr<KeyframedTransformAnimationCurve> curve2(
1679 KeyframedTransformAnimationCurve::Create());
1681 TransformOperations operations2;
1682 curve2->AddKeyframe(
1683 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr));
1684 operations2.AppendScale(2.0, 3.0, 4.0);
1685 curve2->AddKeyframe(TransformKeyframe::Create(
1686 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr));
1688 animation = Animation::Create(curve2.Pass(), 2, 2, Animation::TRANSFORM);
1689 controller_impl->AddAnimation(animation.Pass());
1691 gfx::BoxF box(1.f, 2.f, -1.f, 3.f, 4.f, 5.f);
1692 gfx::BoxF bounds;
1694 EXPECT_TRUE(controller_impl->TransformAnimationBoundsForBox(box, &bounds));
1695 EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 13.f, 19.f, 20.f).ToString(),
1696 bounds.ToString());
1698 controller_impl->GetAnimationById(1)
1699 ->SetRunState(Animation::FINISHED, TicksFromSecondsF(0.0));
1701 // Only the unfinished animation should affect the animated bounds.
1702 EXPECT_TRUE(controller_impl->TransformAnimationBoundsForBox(box, &bounds));
1703 EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 7.f, 16.f, 20.f).ToString(),
1704 bounds.ToString());
1706 controller_impl->GetAnimationById(2)
1707 ->SetRunState(Animation::FINISHED, TicksFromSecondsF(0.0));
1709 // There are no longer any running animations.
1710 EXPECT_FALSE(controller_impl->HasTransformAnimationThatInflatesBounds());
1712 // Add an animation whose bounds we don't yet support computing.
1713 scoped_ptr<KeyframedTransformAnimationCurve> curve3(
1714 KeyframedTransformAnimationCurve::Create());
1715 TransformOperations operations3;
1716 gfx::Transform transform3;
1717 transform3.Scale3d(1.0, 2.0, 3.0);
1718 curve3->AddKeyframe(
1719 TransformKeyframe::Create(base::TimeDelta(), operations3, nullptr));
1720 operations3.AppendMatrix(transform3);
1721 curve3->AddKeyframe(TransformKeyframe::Create(
1722 base::TimeDelta::FromSecondsD(1.0), operations3, nullptr));
1723 animation = Animation::Create(curve3.Pass(), 3, 3, Animation::TRANSFORM);
1724 controller_impl->AddAnimation(animation.Pass());
1725 EXPECT_FALSE(controller_impl->TransformAnimationBoundsForBox(box, &bounds));
1728 // Tests that AbortAnimations aborts all animations targeting the specified
1729 // property.
1730 TEST(LayerAnimationControllerTest, AbortAnimations) {
1731 FakeLayerAnimationValueObserver dummy;
1732 scoped_refptr<LayerAnimationController> controller(
1733 LayerAnimationController::Create(0));
1734 controller->AddValueObserver(&dummy);
1736 // Start with several animations, and allow some of them to reach the finished
1737 // state.
1738 controller->AddAnimation(Animation::Create(
1739 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)).Pass(), 1, 1,
1740 Animation::TRANSFORM));
1741 controller->AddAnimation(Animation::Create(
1742 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1743 2, 2, Animation::OPACITY));
1744 controller->AddAnimation(Animation::Create(
1745 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)).Pass(), 3, 3,
1746 Animation::TRANSFORM));
1747 controller->AddAnimation(Animation::Create(
1748 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2.0)).Pass(), 4, 4,
1749 Animation::TRANSFORM));
1750 controller->AddAnimation(Animation::Create(
1751 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1752 5, 5, Animation::OPACITY));
1754 controller->Animate(kInitialTickTime);
1755 controller->UpdateState(true, nullptr);
1756 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1757 controller->UpdateState(true, nullptr);
1759 EXPECT_EQ(Animation::FINISHED, controller->GetAnimationById(1)->run_state());
1760 EXPECT_EQ(Animation::FINISHED, controller->GetAnimationById(2)->run_state());
1761 EXPECT_EQ(Animation::RUNNING, controller->GetAnimationById(3)->run_state());
1762 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
1763 controller->GetAnimationById(4)->run_state());
1764 EXPECT_EQ(Animation::RUNNING, controller->GetAnimationById(5)->run_state());
1766 controller->AbortAnimations(Animation::TRANSFORM);
1768 // Only un-finished TRANSFORM animations should have been aborted.
1769 EXPECT_EQ(Animation::FINISHED, controller->GetAnimationById(1)->run_state());
1770 EXPECT_EQ(Animation::FINISHED, controller->GetAnimationById(2)->run_state());
1771 EXPECT_EQ(Animation::ABORTED, controller->GetAnimationById(3)->run_state());
1772 EXPECT_EQ(Animation::ABORTED, controller->GetAnimationById(4)->run_state());
1773 EXPECT_EQ(Animation::RUNNING, controller->GetAnimationById(5)->run_state());
1776 // An animation aborted on the main thread should get deleted on both threads.
1777 TEST(LayerAnimationControllerTest, MainThreadAbortedAnimationGetsDeleted) {
1778 FakeLayerAnimationValueObserver dummy_impl;
1779 scoped_refptr<LayerAnimationController> controller_impl(
1780 LayerAnimationController::Create(0));
1781 controller_impl->AddValueObserver(&dummy_impl);
1782 FakeLayerAnimationValueObserver dummy;
1783 scoped_refptr<LayerAnimationController> controller(
1784 LayerAnimationController::Create(0));
1785 controller->AddValueObserver(&dummy);
1787 int animation_id =
1788 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false);
1790 controller->PushAnimationUpdatesTo(controller_impl.get());
1791 controller_impl->ActivateAnimations();
1792 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id));
1794 controller->AbortAnimations(Animation::OPACITY);
1795 EXPECT_EQ(Animation::ABORTED,
1796 controller->GetAnimation(Animation::OPACITY)->run_state());
1797 EXPECT_FALSE(dummy.animation_waiting_for_deletion());
1798 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion());
1800 controller->Animate(kInitialTickTime);
1801 controller->UpdateState(true, nullptr);
1802 EXPECT_TRUE(dummy.animation_waiting_for_deletion());
1803 EXPECT_EQ(Animation::WAITING_FOR_DELETION,
1804 controller->GetAnimation(Animation::OPACITY)->run_state());
1806 controller->PushAnimationUpdatesTo(controller_impl.get());
1807 controller_impl->ActivateAnimations();
1808 EXPECT_FALSE(controller->GetAnimationById(animation_id));
1809 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id));
1812 // An animation aborted on the impl thread should get deleted on both threads.
1813 TEST(LayerAnimationControllerTest, ImplThreadAbortedAnimationGetsDeleted) {
1814 FakeLayerAnimationValueObserver dummy_impl;
1815 scoped_refptr<LayerAnimationController> controller_impl(
1816 LayerAnimationController::Create(0));
1817 controller_impl->AddValueObserver(&dummy_impl);
1818 FakeLayerAnimationValueObserver dummy;
1819 scoped_refptr<LayerAnimationController> controller(
1820 LayerAnimationController::Create(0));
1821 controller->AddValueObserver(&dummy);
1823 int animation_id =
1824 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false);
1826 controller->PushAnimationUpdatesTo(controller_impl.get());
1827 controller_impl->ActivateAnimations();
1828 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id));
1830 controller_impl->AbortAnimations(Animation::OPACITY);
1831 EXPECT_EQ(Animation::ABORTED,
1832 controller_impl->GetAnimation(Animation::OPACITY)->run_state());
1833 EXPECT_FALSE(dummy.animation_waiting_for_deletion());
1834 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion());
1836 AnimationEventsVector events;
1837 controller_impl->Animate(kInitialTickTime);
1838 controller_impl->UpdateState(true, &events);
1839 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion());
1840 EXPECT_EQ(1u, events.size());
1841 EXPECT_EQ(AnimationEvent::ABORTED, events[0].type);
1842 EXPECT_EQ(Animation::WAITING_FOR_DELETION,
1843 controller_impl->GetAnimation(Animation::OPACITY)->run_state());
1845 controller->NotifyAnimationAborted(events[0]);
1846 EXPECT_EQ(Animation::ABORTED,
1847 controller->GetAnimation(Animation::OPACITY)->run_state());
1849 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
1850 controller->UpdateState(true, nullptr);
1851 EXPECT_TRUE(dummy.animation_waiting_for_deletion());
1852 EXPECT_EQ(Animation::WAITING_FOR_DELETION,
1853 controller->GetAnimation(Animation::OPACITY)->run_state());
1855 controller->PushAnimationUpdatesTo(controller_impl.get());
1856 controller_impl->ActivateAnimations();
1857 EXPECT_FALSE(controller->GetAnimationById(animation_id));
1858 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id));
1861 // Ensure that we only generate FINISHED events for animations in a group
1862 // once all animations in that group are finished.
1863 TEST(LayerAnimationControllerTest, FinishedEventsForGroup) {
1864 scoped_ptr<AnimationEventsVector> events(
1865 make_scoped_ptr(new AnimationEventsVector));
1866 FakeLayerAnimationValueObserver dummy_impl;
1867 scoped_refptr<LayerAnimationController> controller_impl(
1868 LayerAnimationController::Create(0));
1869 controller_impl->AddValueObserver(&dummy_impl);
1871 const int group_id = 1;
1873 // Add two animations with the same group id but different durations.
1874 scoped_ptr<Animation> first_animation(Animation::Create(
1875 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2.0)).Pass(), 1,
1876 group_id, Animation::TRANSFORM));
1877 first_animation->set_is_controlling_instance_for_test(true);
1878 controller_impl->AddAnimation(first_animation.Pass());
1880 scoped_ptr<Animation> second_animation(Animation::Create(
1881 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1882 2, group_id, Animation::OPACITY));
1883 second_animation->set_is_controlling_instance_for_test(true);
1884 controller_impl->AddAnimation(second_animation.Pass());
1886 controller_impl->Animate(kInitialTickTime);
1887 controller_impl->UpdateState(true, events.get());
1889 // Both animations should have started.
1890 EXPECT_EQ(2u, events->size());
1891 EXPECT_EQ(AnimationEvent::STARTED, (*events)[0].type);
1892 EXPECT_EQ(AnimationEvent::STARTED, (*events)[1].type);
1894 events.reset(new AnimationEventsVector);
1895 controller_impl->Animate(kInitialTickTime +
1896 TimeDelta::FromMilliseconds(1000));
1897 controller_impl->UpdateState(true, events.get());
1899 // The opacity animation should be finished, but should not have generated
1900 // a FINISHED event yet.
1901 EXPECT_EQ(0u, events->size());
1902 EXPECT_EQ(Animation::FINISHED,
1903 controller_impl->GetAnimationById(2)->run_state());
1904 EXPECT_EQ(Animation::RUNNING,
1905 controller_impl->GetAnimationById(1)->run_state());
1907 controller_impl->Animate(kInitialTickTime +
1908 TimeDelta::FromMilliseconds(2000));
1909 controller_impl->UpdateState(true, events.get());
1911 // Both animations should have generated FINISHED events.
1912 EXPECT_EQ(2u, events->size());
1913 EXPECT_EQ(AnimationEvent::FINISHED, (*events)[0].type);
1914 EXPECT_EQ(AnimationEvent::FINISHED, (*events)[1].type);
1917 // Ensure that when a group has a mix of aborted and finished animations,
1918 // we generate a FINISHED event for the finished animation and an ABORTED
1919 // event for the aborted animation.
1920 TEST(LayerAnimationControllerTest, FinishedAndAbortedEventsForGroup) {
1921 scoped_ptr<AnimationEventsVector> events(
1922 make_scoped_ptr(new AnimationEventsVector));
1923 FakeLayerAnimationValueObserver dummy_impl;
1924 scoped_refptr<LayerAnimationController> controller_impl(
1925 LayerAnimationController::Create(0));
1926 controller_impl->AddValueObserver(&dummy_impl);
1928 // Add two animations with the same group id.
1929 scoped_ptr<Animation> first_animation(CreateAnimation(
1930 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)).Pass(), 1,
1931 Animation::TRANSFORM));
1932 first_animation->set_is_controlling_instance_for_test(true);
1933 controller_impl->AddAnimation(first_animation.Pass());
1935 scoped_ptr<Animation> second_animation(CreateAnimation(
1936 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1937 1, Animation::OPACITY));
1938 second_animation->set_is_controlling_instance_for_test(true);
1939 controller_impl->AddAnimation(second_animation.Pass());
1941 controller_impl->Animate(kInitialTickTime);
1942 controller_impl->UpdateState(true, events.get());
1944 // Both animations should have started.
1945 EXPECT_EQ(2u, events->size());
1946 EXPECT_EQ(AnimationEvent::STARTED, (*events)[0].type);
1947 EXPECT_EQ(AnimationEvent::STARTED, (*events)[1].type);
1949 controller_impl->AbortAnimations(Animation::OPACITY);
1951 events.reset(new AnimationEventsVector);
1952 controller_impl->Animate(kInitialTickTime +
1953 TimeDelta::FromMilliseconds(1000));
1954 controller_impl->UpdateState(true, events.get());
1956 // We should have exactly 2 events: a FINISHED event for the tranform
1957 // animation, and an ABORTED event for the opacity animation.
1958 EXPECT_EQ(2u, events->size());
1959 EXPECT_EQ(AnimationEvent::FINISHED, (*events)[0].type);
1960 EXPECT_EQ(Animation::TRANSFORM, (*events)[0].target_property);
1961 EXPECT_EQ(AnimationEvent::ABORTED, (*events)[1].type);
1962 EXPECT_EQ(Animation::OPACITY, (*events)[1].target_property);
1965 TEST(LayerAnimationControllerTest, HasAnimationThatAffectsScale) {
1966 scoped_refptr<LayerAnimationController> controller_impl(
1967 LayerAnimationController::Create(0));
1969 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale());
1971 controller_impl->AddAnimation(CreateAnimation(
1972 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1973 1, Animation::OPACITY));
1975 // Opacity animations don't affect scale.
1976 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale());
1978 scoped_ptr<KeyframedTransformAnimationCurve> curve1(
1979 KeyframedTransformAnimationCurve::Create());
1981 TransformOperations operations1;
1982 curve1->AddKeyframe(
1983 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
1984 operations1.AppendTranslate(10.0, 15.0, 0.0);
1985 curve1->AddKeyframe(TransformKeyframe::Create(
1986 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr));
1988 scoped_ptr<Animation> animation(
1989 Animation::Create(curve1.Pass(), 2, 2, Animation::TRANSFORM));
1990 controller_impl->AddAnimation(animation.Pass());
1992 // Translations don't affect scale.
1993 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale());
1995 scoped_ptr<KeyframedTransformAnimationCurve> curve2(
1996 KeyframedTransformAnimationCurve::Create());
1998 TransformOperations operations2;
1999 curve2->AddKeyframe(
2000 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr));
2001 operations2.AppendScale(2.0, 3.0, 4.0);
2002 curve2->AddKeyframe(TransformKeyframe::Create(
2003 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr));
2005 animation = Animation::Create(curve2.Pass(), 3, 3, Animation::TRANSFORM);
2006 controller_impl->AddAnimation(animation.Pass());
2008 EXPECT_TRUE(controller_impl->HasAnimationThatAffectsScale());
2010 controller_impl->GetAnimationById(3)
2011 ->SetRunState(Animation::FINISHED, TicksFromSecondsF(0.0));
2013 // Only unfinished animations should be considered by
2014 // HasAnimationThatAffectsScale.
2015 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale());
2018 TEST(LayerAnimationControllerTest, HasOnlyTranslationTransforms) {
2019 scoped_refptr<LayerAnimationController> controller_impl(
2020 LayerAnimationController::Create(0));
2022 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms(
2023 LayerAnimationController::ObserverType::ACTIVE));
2024 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms(
2025 LayerAnimationController::ObserverType::PENDING));
2027 controller_impl->AddAnimation(CreateAnimation(
2028 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
2029 1, Animation::OPACITY));
2031 // Opacity animations aren't non-translation transforms.
2032 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms(
2033 LayerAnimationController::ObserverType::ACTIVE));
2034 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms(
2035 LayerAnimationController::ObserverType::PENDING));
2037 scoped_ptr<KeyframedTransformAnimationCurve> curve1(
2038 KeyframedTransformAnimationCurve::Create());
2040 TransformOperations operations1;
2041 curve1->AddKeyframe(
2042 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
2043 operations1.AppendTranslate(10.0, 15.0, 0.0);
2044 curve1->AddKeyframe(TransformKeyframe::Create(
2045 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr));
2047 scoped_ptr<Animation> animation(
2048 Animation::Create(curve1.Pass(), 2, 2, Animation::TRANSFORM));
2049 controller_impl->AddAnimation(animation.Pass());
2051 // The only transform animation we've added is a translation.
2052 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms(
2053 LayerAnimationController::ObserverType::ACTIVE));
2054 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms(
2055 LayerAnimationController::ObserverType::PENDING));
2057 scoped_ptr<KeyframedTransformAnimationCurve> curve2(
2058 KeyframedTransformAnimationCurve::Create());
2060 TransformOperations operations2;
2061 curve2->AddKeyframe(
2062 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr));
2063 operations2.AppendScale(2.0, 3.0, 4.0);
2064 curve2->AddKeyframe(TransformKeyframe::Create(
2065 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr));
2067 animation = Animation::Create(curve2.Pass(), 3, 3, Animation::TRANSFORM);
2068 animation->set_affects_active_observers(false);
2069 controller_impl->AddAnimation(animation.Pass());
2071 // A scale animation is not a translation.
2072 EXPECT_FALSE(controller_impl->HasOnlyTranslationTransforms(
2073 LayerAnimationController::ObserverType::PENDING));
2074 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms(
2075 LayerAnimationController::ObserverType::ACTIVE));
2077 controller_impl->ActivateAnimations();
2078 EXPECT_FALSE(controller_impl->HasOnlyTranslationTransforms(
2079 LayerAnimationController::ObserverType::PENDING));
2080 EXPECT_FALSE(controller_impl->HasOnlyTranslationTransforms(
2081 LayerAnimationController::ObserverType::ACTIVE));
2083 controller_impl->GetAnimationById(3)->set_affects_pending_observers(false);
2084 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms(
2085 LayerAnimationController::ObserverType::PENDING));
2086 EXPECT_FALSE(controller_impl->HasOnlyTranslationTransforms(
2087 LayerAnimationController::ObserverType::ACTIVE));
2089 controller_impl->GetAnimationById(3)
2090 ->SetRunState(Animation::FINISHED, TicksFromSecondsF(0.0));
2092 // Only unfinished animations should be considered by
2093 // HasOnlyTranslationTransforms.
2094 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms(
2095 LayerAnimationController::ObserverType::PENDING));
2096 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms(
2097 LayerAnimationController::ObserverType::ACTIVE));
2100 TEST(LayerAnimationControllerTest, AnimationStartScale) {
2101 scoped_refptr<LayerAnimationController> controller_impl(
2102 LayerAnimationController::Create(0));
2103 scoped_ptr<KeyframedTransformAnimationCurve> curve1(
2104 KeyframedTransformAnimationCurve::Create());
2106 TransformOperations operations1;
2107 operations1.AppendScale(2.0, 3.0, 4.0);
2108 curve1->AddKeyframe(
2109 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
2110 TransformOperations operations2;
2111 curve1->AddKeyframe(TransformKeyframe::Create(
2112 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr));
2113 scoped_ptr<Animation> animation(
2114 Animation::Create(curve1.Pass(), 1, 1, Animation::TRANSFORM));
2115 animation->set_affects_active_observers(false);
2116 controller_impl->AddAnimation(animation.Pass());
2118 float start_scale = 0.f;
2119 EXPECT_TRUE(controller_impl->AnimationStartScale(
2120 LayerAnimationController::ObserverType::PENDING, &start_scale));
2121 EXPECT_EQ(4.f, start_scale);
2122 EXPECT_TRUE(controller_impl->AnimationStartScale(
2123 LayerAnimationController::ObserverType::ACTIVE, &start_scale));
2124 EXPECT_EQ(0.f, start_scale);
2126 controller_impl->ActivateAnimations();
2127 EXPECT_TRUE(controller_impl->AnimationStartScale(
2128 LayerAnimationController::ObserverType::PENDING, &start_scale));
2129 EXPECT_EQ(4.f, start_scale);
2130 EXPECT_TRUE(controller_impl->AnimationStartScale(
2131 LayerAnimationController::ObserverType::ACTIVE, &start_scale));
2132 EXPECT_EQ(4.f, start_scale);
2134 scoped_ptr<KeyframedTransformAnimationCurve> curve2(
2135 KeyframedTransformAnimationCurve::Create());
2137 TransformOperations operations3;
2138 curve2->AddKeyframe(
2139 TransformKeyframe::Create(base::TimeDelta(), operations3, nullptr));
2140 operations3.AppendScale(6.0, 5.0, 4.0);
2141 curve2->AddKeyframe(TransformKeyframe::Create(
2142 base::TimeDelta::FromSecondsD(1.0), operations3, nullptr));
2144 controller_impl->RemoveAnimation(1);
2145 animation = Animation::Create(curve2.Pass(), 2, 2, Animation::TRANSFORM);
2147 // Reverse Direction
2148 animation->set_direction(Animation::DIRECTION_REVERSE);
2149 animation->set_affects_active_observers(false);
2150 controller_impl->AddAnimation(animation.Pass());
2152 scoped_ptr<KeyframedTransformAnimationCurve> curve3(
2153 KeyframedTransformAnimationCurve::Create());
2155 TransformOperations operations4;
2156 operations4.AppendScale(5.0, 3.0, 1.0);
2157 curve3->AddKeyframe(
2158 TransformKeyframe::Create(base::TimeDelta(), operations4, nullptr));
2159 TransformOperations operations5;
2160 curve3->AddKeyframe(TransformKeyframe::Create(
2161 base::TimeDelta::FromSecondsD(1.0), operations5, nullptr));
2163 animation = Animation::Create(curve3.Pass(), 3, 3, Animation::TRANSFORM);
2164 animation->set_affects_active_observers(false);
2165 controller_impl->AddAnimation(animation.Pass());
2167 EXPECT_TRUE(controller_impl->AnimationStartScale(
2168 LayerAnimationController::ObserverType::PENDING, &start_scale));
2169 EXPECT_EQ(6.f, start_scale);
2170 EXPECT_TRUE(controller_impl->AnimationStartScale(
2171 LayerAnimationController::ObserverType::ACTIVE, &start_scale));
2172 EXPECT_EQ(0.f, start_scale);
2174 controller_impl->ActivateAnimations();
2175 EXPECT_TRUE(controller_impl->AnimationStartScale(
2176 LayerAnimationController::ObserverType::PENDING, &start_scale));
2177 EXPECT_EQ(6.f, start_scale);
2178 EXPECT_TRUE(controller_impl->AnimationStartScale(
2179 LayerAnimationController::ObserverType::ACTIVE, &start_scale));
2180 EXPECT_EQ(6.f, start_scale);
2182 controller_impl->GetAnimationById(2)
2183 ->SetRunState(Animation::FINISHED, TicksFromSecondsF(0.0));
2185 // Only unfinished animations should be considered by
2186 // AnimationStartScale.
2187 EXPECT_TRUE(controller_impl->AnimationStartScale(
2188 LayerAnimationController::ObserverType::PENDING, &start_scale));
2189 EXPECT_EQ(5.f, start_scale);
2190 EXPECT_TRUE(controller_impl->AnimationStartScale(
2191 LayerAnimationController::ObserverType::ACTIVE, &start_scale));
2192 EXPECT_EQ(5.f, start_scale);
2195 TEST(LayerAnimationControllerTest, MaximumTargetScale) {
2196 scoped_refptr<LayerAnimationController> controller_impl(
2197 LayerAnimationController::Create(0));
2199 float max_scale = 0.f;
2200 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2201 LayerAnimationController::ObserverType::PENDING, &max_scale));
2202 EXPECT_EQ(0.f, max_scale);
2203 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2204 LayerAnimationController::ObserverType::ACTIVE, &max_scale));
2205 EXPECT_EQ(0.f, max_scale);
2207 scoped_ptr<KeyframedTransformAnimationCurve> curve1(
2208 KeyframedTransformAnimationCurve::Create());
2210 TransformOperations operations1;
2211 curve1->AddKeyframe(
2212 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
2213 operations1.AppendScale(2.0, 3.0, 4.0);
2214 curve1->AddKeyframe(TransformKeyframe::Create(
2215 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr));
2217 scoped_ptr<Animation> animation(
2218 Animation::Create(curve1.Pass(), 1, 1, Animation::TRANSFORM));
2219 animation->set_affects_active_observers(false);
2220 controller_impl->AddAnimation(animation.Pass());
2222 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2223 LayerAnimationController::ObserverType::PENDING, &max_scale));
2224 EXPECT_EQ(4.f, max_scale);
2225 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2226 LayerAnimationController::ObserverType::ACTIVE, &max_scale));
2227 EXPECT_EQ(0.f, max_scale);
2229 controller_impl->ActivateAnimations();
2230 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2231 LayerAnimationController::ObserverType::PENDING, &max_scale));
2232 EXPECT_EQ(4.f, max_scale);
2233 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2234 LayerAnimationController::ObserverType::ACTIVE, &max_scale));
2235 EXPECT_EQ(4.f, max_scale);
2237 scoped_ptr<KeyframedTransformAnimationCurve> curve2(
2238 KeyframedTransformAnimationCurve::Create());
2240 TransformOperations operations2;
2241 curve2->AddKeyframe(
2242 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr));
2243 operations2.AppendScale(6.0, 5.0, 4.0);
2244 curve2->AddKeyframe(TransformKeyframe::Create(
2245 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr));
2247 animation = Animation::Create(curve2.Pass(), 2, 2, Animation::TRANSFORM);
2248 animation->set_affects_active_observers(false);
2249 controller_impl->AddAnimation(animation.Pass());
2251 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2252 LayerAnimationController::ObserverType::PENDING, &max_scale));
2253 EXPECT_EQ(6.f, max_scale);
2254 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2255 LayerAnimationController::ObserverType::ACTIVE, &max_scale));
2256 EXPECT_EQ(4.f, max_scale);
2258 controller_impl->ActivateAnimations();
2259 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2260 LayerAnimationController::ObserverType::PENDING, &max_scale));
2261 EXPECT_EQ(6.f, max_scale);
2262 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2263 LayerAnimationController::ObserverType::ACTIVE, &max_scale));
2264 EXPECT_EQ(6.f, max_scale);
2266 scoped_ptr<KeyframedTransformAnimationCurve> curve3(
2267 KeyframedTransformAnimationCurve::Create());
2269 TransformOperations operations3;
2270 curve3->AddKeyframe(
2271 TransformKeyframe::Create(base::TimeDelta(), operations3, nullptr));
2272 operations3.AppendPerspective(6.0);
2273 curve3->AddKeyframe(TransformKeyframe::Create(
2274 base::TimeDelta::FromSecondsD(1.0), operations3, nullptr));
2276 animation = Animation::Create(curve3.Pass(), 3, 3, Animation::TRANSFORM);
2277 animation->set_affects_active_observers(false);
2278 controller_impl->AddAnimation(animation.Pass());
2280 EXPECT_FALSE(controller_impl->MaximumTargetScale(
2281 LayerAnimationController::ObserverType::PENDING, &max_scale));
2282 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2283 LayerAnimationController::ObserverType::ACTIVE, &max_scale));
2284 EXPECT_EQ(6.f, max_scale);
2286 controller_impl->ActivateAnimations();
2287 EXPECT_FALSE(controller_impl->MaximumTargetScale(
2288 LayerAnimationController::ObserverType::PENDING, &max_scale));
2289 EXPECT_FALSE(controller_impl->MaximumTargetScale(
2290 LayerAnimationController::ObserverType::ACTIVE, &max_scale));
2292 controller_impl->GetAnimationById(3)
2293 ->SetRunState(Animation::FINISHED, TicksFromSecondsF(0.0));
2294 controller_impl->GetAnimationById(2)
2295 ->SetRunState(Animation::FINISHED, TicksFromSecondsF(0.0));
2297 // Only unfinished animations should be considered by
2298 // MaximumTargetScale.
2299 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2300 LayerAnimationController::ObserverType::PENDING, &max_scale));
2301 EXPECT_EQ(4.f, max_scale);
2302 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2303 LayerAnimationController::ObserverType::ACTIVE, &max_scale));
2304 EXPECT_EQ(4.f, max_scale);
2307 TEST(LayerAnimationControllerTest, MaximumTargetScaleWithDirection) {
2308 scoped_refptr<LayerAnimationController> controller_impl(
2309 LayerAnimationController::Create(0));
2311 scoped_ptr<KeyframedTransformAnimationCurve> curve1(
2312 KeyframedTransformAnimationCurve::Create());
2313 TransformOperations operations1;
2314 operations1.AppendScale(1.0, 2.0, 3.0);
2315 curve1->AddKeyframe(
2316 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
2317 TransformOperations operations2;
2318 operations2.AppendScale(4.0, 5.0, 6.0);
2319 curve1->AddKeyframe(TransformKeyframe::Create(
2320 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr));
2322 scoped_ptr<Animation> animation_owned(
2323 Animation::Create(curve1.Pass(), 1, 1, Animation::TRANSFORM));
2324 Animation* animation = animation_owned.get();
2325 controller_impl->AddAnimation(animation_owned.Pass());
2327 float max_scale = 0.f;
2329 EXPECT_GT(animation->playback_rate(), 0.0);
2331 // NORMAL direction with positive playback rate.
2332 animation->set_direction(Animation::DIRECTION_NORMAL);
2333 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2334 LayerAnimationController::ObserverType::PENDING, &max_scale));
2335 EXPECT_EQ(6.f, max_scale);
2336 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2337 LayerAnimationController::ObserverType::ACTIVE, &max_scale));
2338 EXPECT_EQ(6.f, max_scale);
2340 // ALTERNATE direction with positive playback rate.
2341 animation->set_direction(Animation::DIRECTION_ALTERNATE);
2342 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2343 LayerAnimationController::ObserverType::PENDING, &max_scale));
2344 EXPECT_EQ(6.f, max_scale);
2345 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2346 LayerAnimationController::ObserverType::ACTIVE, &max_scale));
2347 EXPECT_EQ(6.f, max_scale);
2349 // REVERSE direction with positive playback rate.
2350 animation->set_direction(Animation::DIRECTION_REVERSE);
2351 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2352 LayerAnimationController::ObserverType::PENDING, &max_scale));
2353 EXPECT_EQ(3.f, max_scale);
2354 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2355 LayerAnimationController::ObserverType::ACTIVE, &max_scale));
2356 EXPECT_EQ(3.f, max_scale);
2358 // ALTERNATE reverse direction.
2359 animation->set_direction(Animation::DIRECTION_REVERSE);
2360 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2361 LayerAnimationController::ObserverType::PENDING, &max_scale));
2362 EXPECT_EQ(3.f, max_scale);
2363 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2364 LayerAnimationController::ObserverType::ACTIVE, &max_scale));
2365 EXPECT_EQ(3.f, max_scale);
2367 animation->set_playback_rate(-1.0);
2369 // NORMAL direction with negative playback rate.
2370 animation->set_direction(Animation::DIRECTION_NORMAL);
2371 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2372 LayerAnimationController::ObserverType::PENDING, &max_scale));
2373 EXPECT_EQ(3.f, max_scale);
2374 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2375 LayerAnimationController::ObserverType::ACTIVE, &max_scale));
2376 EXPECT_EQ(3.f, max_scale);
2378 // ALTERNATE direction with negative playback rate.
2379 animation->set_direction(Animation::DIRECTION_ALTERNATE);
2380 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2381 LayerAnimationController::ObserverType::PENDING, &max_scale));
2382 EXPECT_EQ(3.f, max_scale);
2383 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2384 LayerAnimationController::ObserverType::ACTIVE, &max_scale));
2385 EXPECT_EQ(3.f, max_scale);
2387 // REVERSE direction with negative playback rate.
2388 animation->set_direction(Animation::DIRECTION_REVERSE);
2389 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2390 LayerAnimationController::ObserverType::PENDING, &max_scale));
2391 EXPECT_EQ(6.f, max_scale);
2392 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2393 LayerAnimationController::ObserverType::ACTIVE, &max_scale));
2394 EXPECT_EQ(6.f, max_scale);
2396 // ALTERNATE reverse direction with negative playback rate.
2397 animation->set_direction(Animation::DIRECTION_REVERSE);
2398 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2399 LayerAnimationController::ObserverType::PENDING, &max_scale));
2400 EXPECT_EQ(6.f, max_scale);
2401 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2402 LayerAnimationController::ObserverType::ACTIVE, &max_scale));
2403 EXPECT_EQ(6.f, max_scale);
2406 TEST(LayerAnimationControllerTest, NewlyPushedAnimationWaitsForActivation) {
2407 scoped_ptr<AnimationEventsVector> events(
2408 make_scoped_ptr(new AnimationEventsVector));
2409 FakeLayerAnimationValueObserver dummy_impl;
2410 FakeInactiveLayerAnimationValueObserver pending_dummy_impl;
2411 scoped_refptr<LayerAnimationController> controller_impl(
2412 LayerAnimationController::Create(0));
2413 controller_impl->AddValueObserver(&dummy_impl);
2414 controller_impl->AddValueObserver(&pending_dummy_impl);
2415 FakeLayerAnimationValueObserver dummy;
2416 scoped_refptr<LayerAnimationController> controller(
2417 LayerAnimationController::Create(0));
2418 controller->AddValueObserver(&dummy);
2420 EXPECT_FALSE(controller->needs_to_start_animations_for_testing());
2421 int animation_id =
2422 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, false);
2423 EXPECT_TRUE(controller->needs_to_start_animations_for_testing());
2425 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing());
2426 controller->PushAnimationUpdatesTo(controller_impl.get());
2427 EXPECT_TRUE(controller_impl->needs_to_start_animations_for_testing());
2429 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id));
2430 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
2431 controller_impl->GetAnimationById(animation_id)->run_state());
2432 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)
2433 ->affects_pending_observers());
2434 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)
2435 ->affects_active_observers());
2437 controller_impl->Animate(kInitialTickTime);
2438 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing());
2439 controller_impl->UpdateState(true, events.get());
2441 // Since the animation hasn't been activated, it should still be STARTING
2442 // rather than RUNNING.
2443 EXPECT_EQ(Animation::STARTING,
2444 controller_impl->GetAnimationById(animation_id)->run_state());
2446 // Since the animation hasn't been activated, only the pending observer
2447 // should have been ticked.
2448 EXPECT_EQ(0.5f, pending_dummy_impl.opacity());
2449 EXPECT_EQ(0.f, dummy_impl.opacity());
2451 controller_impl->ActivateAnimations();
2452 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)
2453 ->affects_pending_observers());
2454 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)
2455 ->affects_active_observers());
2457 controller_impl->Animate(kInitialTickTime +
2458 TimeDelta::FromMilliseconds(1000));
2459 controller_impl->UpdateState(true, events.get());
2461 // Since the animation has been activated, it should have reached the
2462 // RUNNING state and the active observer should start to get ticked.
2463 EXPECT_EQ(Animation::RUNNING,
2464 controller_impl->GetAnimationById(animation_id)->run_state());
2465 EXPECT_EQ(0.5f, pending_dummy_impl.opacity());
2466 EXPECT_EQ(0.5f, dummy_impl.opacity());
2469 TEST(LayerAnimationControllerTest, ActivationBetweenAnimateAndUpdateState) {
2470 scoped_ptr<AnimationEventsVector> events(
2471 make_scoped_ptr(new AnimationEventsVector));
2472 FakeLayerAnimationValueObserver dummy_impl;
2473 FakeInactiveLayerAnimationValueObserver pending_dummy_impl;
2474 scoped_refptr<LayerAnimationController> controller_impl(
2475 LayerAnimationController::Create(0));
2476 controller_impl->AddValueObserver(&dummy_impl);
2477 controller_impl->AddValueObserver(&pending_dummy_impl);
2478 FakeLayerAnimationValueObserver dummy;
2479 scoped_refptr<LayerAnimationController> controller(
2480 LayerAnimationController::Create(0));
2481 controller->AddValueObserver(&dummy);
2483 int animation_id =
2484 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, true);
2486 controller->PushAnimationUpdatesTo(controller_impl.get());
2488 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id));
2489 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
2490 controller_impl->GetAnimationById(animation_id)->run_state());
2491 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)
2492 ->affects_pending_observers());
2493 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)
2494 ->affects_active_observers());
2496 controller_impl->Animate(kInitialTickTime);
2498 // Since the animation hasn't been activated, only the pending observer
2499 // should have been ticked.
2500 EXPECT_EQ(0.5f, pending_dummy_impl.opacity());
2501 EXPECT_EQ(0.f, dummy_impl.opacity());
2503 controller_impl->ActivateAnimations();
2504 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)
2505 ->affects_pending_observers());
2506 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)
2507 ->affects_active_observers());
2509 controller_impl->UpdateState(true, events.get());
2511 // Since the animation has been activated, it should have reached the
2512 // RUNNING state.
2513 EXPECT_EQ(Animation::RUNNING,
2514 controller_impl->GetAnimationById(animation_id)->run_state());
2516 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
2518 // Both observers should have been ticked.
2519 EXPECT_EQ(0.75f, pending_dummy_impl.opacity());
2520 EXPECT_EQ(0.75f, dummy_impl.opacity());
2523 TEST(LayerAnimationControllerTest,
2524 ObserverNotifiedWhenTransformIsPotentiallyAnimatingChanges) {
2525 AnimationEventsVector events;
2526 FakeLayerAnimationValueObserver active_dummy_impl;
2527 FakeInactiveLayerAnimationValueObserver pending_dummy_impl;
2528 scoped_refptr<LayerAnimationController> controller_impl(
2529 LayerAnimationController::Create(0));
2530 controller_impl->AddValueObserver(&active_dummy_impl);
2531 controller_impl->AddValueObserver(&pending_dummy_impl);
2532 FakeLayerAnimationValueObserver dummy;
2533 scoped_refptr<LayerAnimationController> controller(
2534 LayerAnimationController::Create(0));
2535 controller->AddValueObserver(&dummy);
2537 EXPECT_FALSE(dummy.transform_is_animating());
2538 EXPECT_FALSE(pending_dummy_impl.transform_is_animating());
2539 EXPECT_FALSE(active_dummy_impl.transform_is_animating());
2541 // Case 1: An animation that's allowed to run until its finish point.
2542 AddAnimatedTransformToController(controller.get(), 1.0, 1, 1);
2543 EXPECT_TRUE(dummy.transform_is_animating());
2545 controller->PushAnimationUpdatesTo(controller_impl.get());
2546 EXPECT_TRUE(pending_dummy_impl.transform_is_animating());
2547 EXPECT_FALSE(active_dummy_impl.transform_is_animating());
2549 controller_impl->ActivateAnimations();
2550 EXPECT_TRUE(pending_dummy_impl.transform_is_animating());
2551 EXPECT_TRUE(active_dummy_impl.transform_is_animating());
2553 controller_impl->Animate(kInitialTickTime);
2554 controller_impl->UpdateState(true, &events);
2556 controller->NotifyAnimationStarted(events[0]);
2557 events.clear();
2559 // Finish the animation.
2560 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
2561 controller->UpdateState(true, nullptr);
2562 EXPECT_FALSE(dummy.transform_is_animating());
2564 controller->PushAnimationUpdatesTo(controller_impl.get());
2566 // controller_impl hasn't yet ticked at/past the end of the animation.
2567 EXPECT_TRUE(pending_dummy_impl.transform_is_animating());
2568 EXPECT_TRUE(active_dummy_impl.transform_is_animating());
2570 controller_impl->Animate(kInitialTickTime +
2571 TimeDelta::FromMilliseconds(1000));
2572 controller_impl->UpdateState(true, &events);
2573 EXPECT_FALSE(pending_dummy_impl.transform_is_animating());
2574 EXPECT_FALSE(active_dummy_impl.transform_is_animating());
2576 controller->NotifyAnimationFinished(events[0]);
2577 events.clear();
2579 // Case 2: An animation that's removed before it finishes.
2580 int animation_id =
2581 AddAnimatedTransformToController(controller.get(), 10.0, 2, 2);
2582 EXPECT_TRUE(dummy.transform_is_animating());
2584 controller->PushAnimationUpdatesTo(controller_impl.get());
2585 EXPECT_TRUE(pending_dummy_impl.transform_is_animating());
2586 EXPECT_FALSE(active_dummy_impl.transform_is_animating());
2588 controller_impl->ActivateAnimations();
2589 EXPECT_TRUE(pending_dummy_impl.transform_is_animating());
2590 EXPECT_TRUE(active_dummy_impl.transform_is_animating());
2592 controller_impl->Animate(kInitialTickTime +
2593 TimeDelta::FromMilliseconds(2000));
2594 controller_impl->UpdateState(true, &events);
2596 controller->NotifyAnimationStarted(events[0]);
2597 events.clear();
2599 controller->RemoveAnimation(animation_id);
2600 EXPECT_FALSE(dummy.transform_is_animating());
2602 controller->PushAnimationUpdatesTo(controller_impl.get());
2603 EXPECT_FALSE(pending_dummy_impl.transform_is_animating());
2604 EXPECT_TRUE(active_dummy_impl.transform_is_animating());
2606 controller_impl->ActivateAnimations();
2607 EXPECT_FALSE(pending_dummy_impl.transform_is_animating());
2608 EXPECT_FALSE(active_dummy_impl.transform_is_animating());
2610 // Case 3: An animation that's aborted before it finishes.
2611 animation_id = AddAnimatedTransformToController(controller.get(), 10.0, 3, 3);
2612 EXPECT_TRUE(dummy.transform_is_animating());
2614 controller->PushAnimationUpdatesTo(controller_impl.get());
2615 EXPECT_TRUE(pending_dummy_impl.transform_is_animating());
2616 EXPECT_FALSE(active_dummy_impl.transform_is_animating());
2618 controller_impl->ActivateAnimations();
2619 EXPECT_TRUE(pending_dummy_impl.transform_is_animating());
2620 EXPECT_TRUE(active_dummy_impl.transform_is_animating());
2622 controller_impl->Animate(kInitialTickTime +
2623 TimeDelta::FromMilliseconds(3000));
2624 controller_impl->UpdateState(true, &events);
2626 controller->NotifyAnimationStarted(events[0]);
2627 events.clear();
2629 controller_impl->AbortAnimations(Animation::TRANSFORM);
2630 EXPECT_FALSE(pending_dummy_impl.transform_is_animating());
2631 EXPECT_FALSE(active_dummy_impl.transform_is_animating());
2633 controller_impl->Animate(kInitialTickTime +
2634 TimeDelta::FromMilliseconds(4000));
2635 controller_impl->UpdateState(true, &events);
2637 controller->NotifyAnimationAborted(events[0]);
2638 EXPECT_FALSE(dummy.transform_is_animating());
2641 TEST(LayerAnimationControllerTest, ClippedOpacityValues) {
2642 FakeLayerAnimationValueObserver dummy;
2643 scoped_refptr<LayerAnimationController> controller(
2644 LayerAnimationController::Create(0));
2645 controller->AddValueObserver(&dummy);
2647 AddOpacityTransitionToController(controller.get(), 1, 1.f, 2.f, true);
2649 controller->Animate(kInitialTickTime);
2650 EXPECT_EQ(1.f, dummy.opacity());
2652 // Opacity values are clipped [0,1]
2653 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
2654 EXPECT_EQ(1.f, dummy.opacity());
2657 TEST(LayerAnimationControllerTest, ClippedNegativeOpacityValues) {
2658 FakeLayerAnimationValueObserver dummy;
2659 scoped_refptr<LayerAnimationController> controller(
2660 LayerAnimationController::Create(0));
2661 controller->AddValueObserver(&dummy);
2663 AddOpacityTransitionToController(controller.get(), 1, 0.f, -2.f, true);
2665 controller->Animate(kInitialTickTime);
2666 EXPECT_EQ(0.f, dummy.opacity());
2668 // Opacity values are clipped [0,1]
2669 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
2670 EXPECT_EQ(0.f, dummy.opacity());
2673 TEST(LayerAnimationControllerTest, PushedDeletedAnimationWaitsForActivation) {
2674 scoped_ptr<AnimationEventsVector> events(
2675 make_scoped_ptr(new AnimationEventsVector));
2676 FakeLayerAnimationValueObserver dummy_impl;
2677 FakeInactiveLayerAnimationValueObserver pending_dummy_impl;
2678 scoped_refptr<LayerAnimationController> controller_impl(
2679 LayerAnimationController::Create(0));
2680 controller_impl->AddValueObserver(&dummy_impl);
2681 controller_impl->AddValueObserver(&pending_dummy_impl);
2682 FakeLayerAnimationValueObserver dummy;
2683 scoped_refptr<LayerAnimationController> controller(
2684 LayerAnimationController::Create(0));
2685 controller->AddValueObserver(&dummy);
2687 int animation_id =
2688 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, true);
2690 controller->PushAnimationUpdatesTo(controller_impl.get());
2691 controller_impl->ActivateAnimations();
2692 controller_impl->Animate(kInitialTickTime);
2693 controller_impl->UpdateState(true, events.get());
2694 EXPECT_EQ(Animation::RUNNING,
2695 controller_impl->GetAnimationById(animation_id)->run_state());
2696 EXPECT_EQ(0.5f, pending_dummy_impl.opacity());
2697 EXPECT_EQ(0.5f, dummy_impl.opacity());
2699 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)
2700 ->affects_pending_observers());
2701 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)
2702 ->affects_active_observers());
2704 // Delete the animation on the main-thread controller.
2705 controller->RemoveAnimation(
2706 controller->GetAnimation(Animation::OPACITY)->id());
2707 controller->PushAnimationUpdatesTo(controller_impl.get());
2709 // The animation should no longer affect pending observers.
2710 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)
2711 ->affects_pending_observers());
2712 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)
2713 ->affects_active_observers());
2715 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
2716 controller_impl->UpdateState(true, events.get());
2718 // Only the active observer should have been ticked.
2719 EXPECT_EQ(0.5f, pending_dummy_impl.opacity());
2720 EXPECT_EQ(0.75f, dummy_impl.opacity());
2722 controller_impl->ActivateAnimations();
2724 // Activation should cause the animation to be deleted.
2725 EXPECT_FALSE(controller_impl->has_any_animation());
2728 // Tests that an animation that affects only active observers won't block
2729 // an animation that affects only pending observers from starting.
2730 TEST(LayerAnimationControllerTest, StartAnimationsAffectingDifferentObservers) {
2731 scoped_ptr<AnimationEventsVector> events(
2732 make_scoped_ptr(new AnimationEventsVector));
2733 FakeLayerAnimationValueObserver dummy_impl;
2734 FakeInactiveLayerAnimationValueObserver pending_dummy_impl;
2735 scoped_refptr<LayerAnimationController> controller_impl(
2736 LayerAnimationController::Create(0));
2737 controller_impl->AddValueObserver(&dummy_impl);
2738 controller_impl->AddValueObserver(&pending_dummy_impl);
2739 FakeLayerAnimationValueObserver dummy;
2740 scoped_refptr<LayerAnimationController> controller(
2741 LayerAnimationController::Create(0));
2742 controller->AddValueObserver(&dummy);
2744 int first_animation_id =
2745 AddOpacityTransitionToController(controller.get(), 1, 0.f, 1.f, true);
2747 controller->PushAnimationUpdatesTo(controller_impl.get());
2748 controller_impl->ActivateAnimations();
2749 controller_impl->Animate(kInitialTickTime);
2750 controller_impl->UpdateState(true, events.get());
2752 // Remove the first animation from the main-thread controller, and add a
2753 // new animation affecting the same property.
2754 controller->RemoveAnimation(
2755 controller->GetAnimation(Animation::OPACITY)->id());
2756 int second_animation_id =
2757 AddOpacityTransitionToController(controller.get(), 1, 1.f, 0.5f, true);
2758 controller->PushAnimationUpdatesTo(controller_impl.get());
2760 // The original animation should only affect active observers, and the new
2761 // animation should only affect pending observers.
2762 EXPECT_FALSE(controller_impl->GetAnimationById(first_animation_id)
2763 ->affects_pending_observers());
2764 EXPECT_TRUE(controller_impl->GetAnimationById(first_animation_id)
2765 ->affects_active_observers());
2766 EXPECT_TRUE(controller_impl->GetAnimationById(second_animation_id)
2767 ->affects_pending_observers());
2768 EXPECT_FALSE(controller_impl->GetAnimationById(second_animation_id)
2769 ->affects_active_observers());
2771 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
2772 controller_impl->UpdateState(true, events.get());
2774 // The original animation should still be running, and the new animation
2775 // should be starting.
2776 EXPECT_EQ(Animation::RUNNING,
2777 controller_impl->GetAnimationById(first_animation_id)->run_state());
2778 EXPECT_EQ(
2779 Animation::STARTING,
2780 controller_impl->GetAnimationById(second_animation_id)->run_state());
2782 // The active observer should have been ticked by the original animation,
2783 // and the pending observer should have been ticked by the new animation.
2784 EXPECT_EQ(1.f, pending_dummy_impl.opacity());
2785 EXPECT_EQ(0.5f, dummy_impl.opacity());
2787 controller_impl->ActivateAnimations();
2789 // The original animation should have been deleted, and the new animation
2790 // should now affect both observers.
2791 EXPECT_FALSE(controller_impl->GetAnimationById(first_animation_id));
2792 EXPECT_TRUE(controller_impl->GetAnimationById(second_animation_id)
2793 ->affects_pending_observers());
2794 EXPECT_TRUE(controller_impl->GetAnimationById(second_animation_id)
2795 ->affects_active_observers());
2797 controller_impl->Animate(kInitialTickTime +
2798 TimeDelta::FromMilliseconds(1000));
2799 controller_impl->UpdateState(true, events.get());
2801 // The new animation should be running, and the active observer should have
2802 // been ticked at the new animation's starting point.
2803 EXPECT_EQ(
2804 Animation::RUNNING,
2805 controller_impl->GetAnimationById(second_animation_id)->run_state());
2806 EXPECT_EQ(1.f, pending_dummy_impl.opacity());
2807 EXPECT_EQ(1.f, dummy_impl.opacity());
2810 TEST(LayerAnimationControllerTest, TestIsCurrentlyAnimatingProperty) {
2811 FakeLayerAnimationValueObserver dummy;
2812 scoped_refptr<LayerAnimationController> controller(
2813 LayerAnimationController::Create(0));
2814 controller->AddValueObserver(&dummy);
2816 // Create an animation that initially affects only pending observers.
2817 scoped_ptr<Animation> animation(CreateAnimation(
2818 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
2819 1, Animation::OPACITY));
2820 animation->set_affects_active_observers(false);
2822 controller->AddAnimation(animation.Pass());
2823 controller->Animate(kInitialTickTime);
2824 EXPECT_TRUE(controller->IsCurrentlyAnimatingProperty(
2825 Animation::OPACITY, LayerAnimationController::ObserverType::PENDING));
2826 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty(
2827 Animation::OPACITY, LayerAnimationController::ObserverType::ACTIVE));
2828 controller->UpdateState(true, nullptr);
2829 EXPECT_TRUE(controller->HasActiveAnimation());
2831 EXPECT_TRUE(controller->IsCurrentlyAnimatingProperty(
2832 Animation::OPACITY, LayerAnimationController::ObserverType::PENDING));
2833 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty(
2834 Animation::OPACITY, LayerAnimationController::ObserverType::ACTIVE));
2835 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty(
2836 Animation::FILTER, LayerAnimationController::ObserverType::PENDING));
2837 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty(
2838 Animation::FILTER, LayerAnimationController::ObserverType::ACTIVE));
2840 controller->ActivateAnimations();
2842 EXPECT_TRUE(controller->IsCurrentlyAnimatingProperty(
2843 Animation::OPACITY, LayerAnimationController::ObserverType::PENDING));
2844 EXPECT_TRUE(controller->IsCurrentlyAnimatingProperty(
2845 Animation::OPACITY, LayerAnimationController::ObserverType::ACTIVE));
2846 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty(
2847 Animation::FILTER, LayerAnimationController::ObserverType::PENDING));
2848 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty(
2849 Animation::FILTER, LayerAnimationController::ObserverType::ACTIVE));
2851 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(10));
2852 controller->UpdateState(true, nullptr);
2854 EXPECT_TRUE(controller->IsCurrentlyAnimatingProperty(
2855 Animation::OPACITY, LayerAnimationController::ObserverType::PENDING));
2856 EXPECT_TRUE(controller->IsCurrentlyAnimatingProperty(
2857 Animation::OPACITY, LayerAnimationController::ObserverType::ACTIVE));
2858 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty(
2859 Animation::FILTER, LayerAnimationController::ObserverType::PENDING));
2860 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty(
2861 Animation::FILTER, LayerAnimationController::ObserverType::ACTIVE));
2863 EXPECT_EQ(0.f, dummy.opacity());
2865 // Tick past the end of the animation.
2866 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1100));
2867 controller->UpdateState(true, nullptr);
2869 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty(
2870 Animation::OPACITY, LayerAnimationController::ObserverType::PENDING));
2871 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty(
2872 Animation::OPACITY, LayerAnimationController::ObserverType::ACTIVE));
2873 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty(
2874 Animation::FILTER, LayerAnimationController::ObserverType::PENDING));
2875 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty(
2876 Animation::FILTER, LayerAnimationController::ObserverType::ACTIVE));
2878 EXPECT_EQ(1.f, dummy.opacity());
2881 TEST(LayerAnimationControllerTest, TestIsAnimatingPropertyTimeOffsetFillMode) {
2882 FakeLayerAnimationValueObserver dummy;
2883 scoped_refptr<LayerAnimationController> controller(
2884 LayerAnimationController::Create(0));
2885 controller->AddValueObserver(&dummy);
2887 // Create an animation that initially affects only pending observers, and has
2888 // a start delay of 2 seconds.
2889 scoped_ptr<Animation> animation(CreateAnimation(
2890 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
2891 1, Animation::OPACITY));
2892 animation->set_fill_mode(Animation::FILL_MODE_NONE);
2893 animation->set_time_offset(TimeDelta::FromMilliseconds(-2000));
2894 animation->set_affects_active_observers(false);
2896 controller->AddAnimation(animation.Pass());
2898 controller->Animate(kInitialTickTime);
2900 // Since the animation has a start delay, the observers it affects have a
2901 // potentially running transform animation but aren't currently animating
2902 // transform.
2903 EXPECT_TRUE(controller->IsPotentiallyAnimatingProperty(
2904 Animation::OPACITY, LayerAnimationController::ObserverType::PENDING));
2905 EXPECT_FALSE(controller->IsPotentiallyAnimatingProperty(
2906 Animation::OPACITY, LayerAnimationController::ObserverType::ACTIVE));
2907 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty(
2908 Animation::OPACITY, LayerAnimationController::ObserverType::PENDING));
2909 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty(
2910 Animation::OPACITY, LayerAnimationController::ObserverType::ACTIVE));
2911 EXPECT_TRUE(controller->HasActiveAnimation());
2912 EXPECT_FALSE(controller->IsPotentiallyAnimatingProperty(
2913 Animation::FILTER, LayerAnimationController::ObserverType::PENDING));
2914 EXPECT_FALSE(controller->IsPotentiallyAnimatingProperty(
2915 Animation::FILTER, LayerAnimationController::ObserverType::ACTIVE));
2917 controller->ActivateAnimations();
2919 EXPECT_TRUE(controller->IsPotentiallyAnimatingProperty(
2920 Animation::OPACITY, LayerAnimationController::ObserverType::PENDING));
2921 EXPECT_TRUE(controller->IsPotentiallyAnimatingProperty(
2922 Animation::OPACITY, LayerAnimationController::ObserverType::ACTIVE));
2923 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty(
2924 Animation::OPACITY, LayerAnimationController::ObserverType::PENDING));
2925 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty(
2926 Animation::OPACITY, LayerAnimationController::ObserverType::ACTIVE));
2927 EXPECT_TRUE(controller->HasActiveAnimation());
2928 EXPECT_FALSE(controller->IsPotentiallyAnimatingProperty(
2929 Animation::FILTER, LayerAnimationController::ObserverType::PENDING));
2930 EXPECT_FALSE(controller->IsPotentiallyAnimatingProperty(
2931 Animation::FILTER, LayerAnimationController::ObserverType::ACTIVE));
2933 controller->UpdateState(true, nullptr);
2935 // Tick past the start delay.
2936 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
2937 controller->UpdateState(true, nullptr);
2938 EXPECT_TRUE(controller->IsPotentiallyAnimatingProperty(
2939 Animation::OPACITY, LayerAnimationController::ObserverType::PENDING));
2940 EXPECT_TRUE(controller->IsPotentiallyAnimatingProperty(
2941 Animation::OPACITY, LayerAnimationController::ObserverType::ACTIVE));
2942 EXPECT_TRUE(controller->IsCurrentlyAnimatingProperty(
2943 Animation::OPACITY, LayerAnimationController::ObserverType::PENDING));
2944 EXPECT_TRUE(controller->IsCurrentlyAnimatingProperty(
2945 Animation::OPACITY, LayerAnimationController::ObserverType::ACTIVE));
2947 // After the animaton finishes, the observers it affects have neither a
2948 // potentially running transform animation nor a currently running transform
2949 // animation.
2950 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(4000));
2951 controller->UpdateState(true, nullptr);
2952 EXPECT_FALSE(controller->IsPotentiallyAnimatingProperty(
2953 Animation::OPACITY, LayerAnimationController::ObserverType::PENDING));
2954 EXPECT_FALSE(controller->IsPotentiallyAnimatingProperty(
2955 Animation::OPACITY, LayerAnimationController::ObserverType::ACTIVE));
2956 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty(
2957 Animation::OPACITY, LayerAnimationController::ObserverType::PENDING));
2958 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty(
2959 Animation::OPACITY, LayerAnimationController::ObserverType::ACTIVE));
2962 } // namespace
2963 } // namespace cc