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"
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
34 const TimeTicks kInitialTickTime
= TicksFromSecondsF(1.0);
36 scoped_ptr
<Animation
> CreateAnimation(scoped_ptr
<AnimationCurve
> curve
,
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());
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
));
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
);
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());
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());
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());
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.
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());
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
));
258 AddOpacityTransitionToController(controller
.get(), 1, 0, 1, false);
260 controller
->PushAnimationUpdatesTo(controller_impl
.get());
261 controller_impl
->ActivateAnimations();
263 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
));
264 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY
,
265 controller_impl
->GetAnimationById(animation_id
)->run_state());
267 // Start the animations on each controller.
268 AnimationEventsVector events
;
269 controller_impl
->Animate(kInitialTickTime
);
270 controller_impl
->UpdateState(true, &events
);
271 controller
->Animate(kInitialTickTime
);
272 controller
->UpdateState(true, nullptr);
273 EXPECT_EQ(Animation::RUNNING
,
274 controller_impl
->GetAnimationById(animation_id
)->run_state());
275 EXPECT_EQ(Animation::RUNNING
,
276 controller
->GetAnimationById(animation_id
)->run_state());
278 // Pause the main-thread animation.
279 controller
->PauseAnimation(
281 TimeDelta::FromMilliseconds(1000) + TimeDelta::FromMilliseconds(1000));
282 EXPECT_EQ(Animation::PAUSED
,
283 controller
->GetAnimationById(animation_id
)->run_state());
285 // The pause run state change should make it to the impl thread controller.
286 controller
->PushAnimationUpdatesTo(controller_impl
.get());
287 controller_impl
->ActivateAnimations();
288 EXPECT_EQ(Animation::PAUSED
,
289 controller_impl
->GetAnimationById(animation_id
)->run_state());
292 TEST(LayerAnimationControllerTest
, DoNotSyncFinishedAnimation
) {
293 FakeLayerAnimationValueObserver dummy_impl
;
294 scoped_refptr
<LayerAnimationController
> controller_impl(
295 LayerAnimationController::Create(0));
296 controller_impl
->AddValueObserver(&dummy_impl
);
297 FakeLayerAnimationValueObserver dummy
;
298 scoped_refptr
<LayerAnimationController
> controller(
299 LayerAnimationController::Create(0));
300 controller
->AddValueObserver(&dummy
);
302 EXPECT_FALSE(controller_impl
->GetAnimation(Animation::OPACITY
));
305 AddOpacityTransitionToController(controller
.get(), 1, 0, 1, false);
306 int group_id
= controller
->GetAnimationById(animation_id
)->group();
308 controller
->PushAnimationUpdatesTo(controller_impl
.get());
309 controller_impl
->ActivateAnimations();
311 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
));
312 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY
,
313 controller_impl
->GetAnimationById(animation_id
)->run_state());
315 // Notify main thread controller that the animation has started.
316 AnimationEvent
animation_started_event(AnimationEvent::STARTED
, 0, group_id
,
317 Animation::OPACITY
, kInitialTickTime
);
318 controller
->NotifyAnimationStarted(animation_started_event
);
320 // Force animation to complete on impl thread.
321 controller_impl
->RemoveAnimation(animation_id
);
323 EXPECT_FALSE(controller_impl
->GetAnimationById(animation_id
));
325 controller
->PushAnimationUpdatesTo(controller_impl
.get());
326 controller_impl
->ActivateAnimations();
328 // Even though the main thread has a 'new' animation, it should not be pushed
329 // because the animation has already completed on the impl thread.
330 EXPECT_FALSE(controller_impl
->GetAnimationById(animation_id
));
333 // Ensure that a finished animation is eventually deleted by both the
334 // main-thread and the impl-thread controllers.
335 TEST(LayerAnimationControllerTest
, AnimationsAreDeleted
) {
336 FakeLayerAnimationValueObserver dummy
;
337 FakeLayerAnimationValueObserver dummy_impl
;
338 scoped_ptr
<AnimationEventsVector
> events(
339 make_scoped_ptr(new AnimationEventsVector
));
340 scoped_refptr
<LayerAnimationController
> controller(
341 LayerAnimationController::Create(0));
342 scoped_refptr
<LayerAnimationController
> controller_impl(
343 LayerAnimationController::Create(0));
344 controller
->AddValueObserver(&dummy
);
345 controller_impl
->AddValueObserver(&dummy_impl
);
347 AddOpacityTransitionToController(controller
.get(), 1.0, 0.0f
, 1.0f
, false);
348 controller
->Animate(kInitialTickTime
);
349 controller
->UpdateState(true, nullptr);
350 controller
->PushAnimationUpdatesTo(controller_impl
.get());
351 controller_impl
->ActivateAnimations();
353 controller_impl
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(500));
354 controller_impl
->UpdateState(true, events
.get());
356 // There should be a STARTED event for the animation.
357 EXPECT_EQ(1u, events
->size());
358 EXPECT_EQ(AnimationEvent::STARTED
, (*events
)[0].type
);
359 controller
->NotifyAnimationStarted((*events
)[0]);
361 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1000));
362 controller
->UpdateState(true, nullptr);
364 EXPECT_FALSE(dummy
.animation_waiting_for_deletion());
365 EXPECT_FALSE(dummy_impl
.animation_waiting_for_deletion());
367 events
.reset(new AnimationEventsVector
);
368 controller_impl
->Animate(kInitialTickTime
+
369 TimeDelta::FromMilliseconds(2000));
370 controller_impl
->UpdateState(true, events
.get());
372 EXPECT_TRUE(dummy_impl
.animation_waiting_for_deletion());
374 // There should be a FINISHED event for the animation.
375 EXPECT_EQ(1u, events
->size());
376 EXPECT_EQ(AnimationEvent::FINISHED
, (*events
)[0].type
);
378 // Neither controller should have deleted the animation yet.
379 EXPECT_TRUE(controller
->GetAnimation(Animation::OPACITY
));
380 EXPECT_TRUE(controller_impl
->GetAnimation(Animation::OPACITY
));
382 controller
->NotifyAnimationFinished((*events
)[0]);
384 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(3000));
385 controller
->UpdateState(true, nullptr);
386 EXPECT_TRUE(dummy
.animation_waiting_for_deletion());
388 controller
->PushAnimationUpdatesTo(controller_impl
.get());
390 // Both controllers should now have deleted the animation. The impl controller
391 // should have deleted the animation even though activation has not occurred,
392 // since the animation was already waiting for deletion when
393 // PushAnimationUpdatesTo was called.
394 EXPECT_FALSE(controller
->has_any_animation());
395 EXPECT_FALSE(controller_impl
->has_any_animation());
398 // Tests that transitioning opacity from 0 to 1 works as expected.
400 static const AnimationEvent
* GetMostRecentPropertyUpdateEvent(
401 const AnimationEventsVector
* events
) {
402 const AnimationEvent
* event
= 0;
403 for (size_t i
= 0; i
< events
->size(); ++i
)
404 if ((*events
)[i
].type
== AnimationEvent::PROPERTY_UPDATE
)
405 event
= &(*events
)[i
];
410 TEST(LayerAnimationControllerTest
, TrivialTransition
) {
411 scoped_ptr
<AnimationEventsVector
> events(
412 make_scoped_ptr(new AnimationEventsVector
));
413 FakeLayerAnimationValueObserver dummy
;
414 scoped_refptr
<LayerAnimationController
> controller(
415 LayerAnimationController::Create(0));
416 controller
->AddValueObserver(&dummy
);
418 scoped_ptr
<Animation
> to_add(CreateAnimation(
419 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
420 1, Animation::OPACITY
));
422 EXPECT_FALSE(controller
->needs_to_start_animations_for_testing());
423 controller
->AddAnimation(to_add
.Pass());
424 EXPECT_TRUE(controller
->needs_to_start_animations_for_testing());
425 controller
->Animate(kInitialTickTime
);
426 EXPECT_FALSE(controller
->needs_to_start_animations_for_testing());
427 controller
->UpdateState(true, events
.get());
428 EXPECT_TRUE(controller
->HasActiveAnimation());
429 EXPECT_EQ(0.f
, dummy
.opacity());
430 // A non-impl-only animation should not generate property updates.
431 const AnimationEvent
* event
= GetMostRecentPropertyUpdateEvent(events
.get());
433 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1000));
434 controller
->UpdateState(true, events
.get());
435 EXPECT_EQ(1.f
, dummy
.opacity());
436 EXPECT_FALSE(controller
->HasActiveAnimation());
437 event
= GetMostRecentPropertyUpdateEvent(events
.get());
441 TEST(LayerAnimationControllerTest
, TrivialTransitionOnImpl
) {
442 scoped_ptr
<AnimationEventsVector
> events(
443 make_scoped_ptr(new AnimationEventsVector
));
444 FakeLayerAnimationValueObserver dummy_impl
;
445 scoped_refptr
<LayerAnimationController
> controller_impl(
446 LayerAnimationController::Create(0));
447 controller_impl
->AddValueObserver(&dummy_impl
);
449 scoped_ptr
<Animation
> to_add(CreateAnimation(
450 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
451 1, Animation::OPACITY
));
452 to_add
->set_is_impl_only(true);
454 controller_impl
->AddAnimation(to_add
.Pass());
455 controller_impl
->Animate(kInitialTickTime
);
456 controller_impl
->UpdateState(true, events
.get());
457 EXPECT_TRUE(controller_impl
->HasActiveAnimation());
458 EXPECT_EQ(0.f
, dummy_impl
.opacity());
459 EXPECT_EQ(1u, events
->size());
460 const AnimationEvent
* start_opacity_event
=
461 GetMostRecentPropertyUpdateEvent(events
.get());
462 EXPECT_EQ(0.f
, start_opacity_event
->opacity
);
464 controller_impl
->Animate(kInitialTickTime
+
465 TimeDelta::FromMilliseconds(1000));
466 controller_impl
->UpdateState(true, events
.get());
467 EXPECT_EQ(1.f
, dummy_impl
.opacity());
468 EXPECT_FALSE(controller_impl
->HasActiveAnimation());
469 EXPECT_EQ(2u, events
->size());
470 const AnimationEvent
* end_opacity_event
=
471 GetMostRecentPropertyUpdateEvent(events
.get());
472 EXPECT_EQ(1.f
, end_opacity_event
->opacity
);
475 TEST(LayerAnimationControllerTest
, TrivialTransformOnImpl
) {
476 scoped_ptr
<AnimationEventsVector
> events(
477 make_scoped_ptr(new AnimationEventsVector
));
478 FakeLayerAnimationValueObserver dummy_impl
;
479 scoped_refptr
<LayerAnimationController
> controller_impl(
480 LayerAnimationController::Create(0));
481 controller_impl
->AddValueObserver(&dummy_impl
);
483 // Choose different values for x and y to avoid coincidental values in the
484 // observed transforms.
485 const float delta_x
= 3;
486 const float delta_y
= 4;
488 scoped_ptr
<KeyframedTransformAnimationCurve
> curve(
489 KeyframedTransformAnimationCurve::Create());
491 // Create simple TRANSFORM animation.
492 TransformOperations operations
;
494 TransformKeyframe::Create(base::TimeDelta(), operations
, nullptr));
495 operations
.AppendTranslate(delta_x
, delta_y
, 0);
496 curve
->AddKeyframe(TransformKeyframe::Create(
497 base::TimeDelta::FromSecondsD(1.0), operations
, nullptr));
499 scoped_ptr
<Animation
> animation(
500 Animation::Create(curve
.Pass(), 1, 0, Animation::TRANSFORM
));
501 animation
->set_is_impl_only(true);
502 controller_impl
->AddAnimation(animation
.Pass());
505 controller_impl
->Animate(kInitialTickTime
);
506 controller_impl
->UpdateState(true, events
.get());
507 EXPECT_TRUE(controller_impl
->HasActiveAnimation());
508 EXPECT_EQ(gfx::Transform(), dummy_impl
.transform());
509 EXPECT_EQ(1u, events
->size());
510 const AnimationEvent
* start_transform_event
=
511 GetMostRecentPropertyUpdateEvent(events
.get());
512 ASSERT_TRUE(start_transform_event
);
513 EXPECT_EQ(gfx::Transform(), start_transform_event
->transform
);
514 EXPECT_TRUE(start_transform_event
->is_impl_only
);
516 gfx::Transform expected_transform
;
517 expected_transform
.Translate(delta_x
, delta_y
);
519 controller_impl
->Animate(kInitialTickTime
+
520 TimeDelta::FromMilliseconds(1000));
521 controller_impl
->UpdateState(true, events
.get());
522 EXPECT_EQ(expected_transform
, dummy_impl
.transform());
523 EXPECT_FALSE(controller_impl
->HasActiveAnimation());
524 EXPECT_EQ(2u, events
->size());
525 const AnimationEvent
* end_transform_event
=
526 GetMostRecentPropertyUpdateEvent(events
.get());
527 EXPECT_EQ(expected_transform
, end_transform_event
->transform
);
528 EXPECT_TRUE(end_transform_event
->is_impl_only
);
531 TEST(LayerAnimationControllerTest
, FilterTransition
) {
532 scoped_ptr
<AnimationEventsVector
> events(
533 make_scoped_ptr(new AnimationEventsVector
));
534 FakeLayerAnimationValueObserver dummy
;
535 scoped_refptr
<LayerAnimationController
> controller(
536 LayerAnimationController::Create(0));
537 controller
->AddValueObserver(&dummy
);
539 scoped_ptr
<KeyframedFilterAnimationCurve
> curve(
540 KeyframedFilterAnimationCurve::Create());
542 FilterOperations start_filters
;
543 start_filters
.Append(FilterOperation::CreateBrightnessFilter(1.f
));
545 FilterKeyframe::Create(base::TimeDelta(), start_filters
, nullptr));
546 FilterOperations end_filters
;
547 end_filters
.Append(FilterOperation::CreateBrightnessFilter(2.f
));
548 curve
->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
549 end_filters
, nullptr));
551 scoped_ptr
<Animation
> animation(
552 Animation::Create(curve
.Pass(), 1, 0, Animation::FILTER
));
553 controller
->AddAnimation(animation
.Pass());
555 controller
->Animate(kInitialTickTime
);
556 controller
->UpdateState(true, events
.get());
557 EXPECT_TRUE(controller
->HasActiveAnimation());
558 EXPECT_EQ(start_filters
, dummy
.filters());
559 // A non-impl-only animation should not generate property updates.
560 const AnimationEvent
* event
= GetMostRecentPropertyUpdateEvent(events
.get());
563 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(500));
564 controller
->UpdateState(true, events
.get());
565 EXPECT_EQ(1u, dummy
.filters().size());
566 EXPECT_EQ(FilterOperation::CreateBrightnessFilter(1.5f
),
567 dummy
.filters().at(0));
568 event
= GetMostRecentPropertyUpdateEvent(events
.get());
571 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1000));
572 controller
->UpdateState(true, events
.get());
573 EXPECT_EQ(end_filters
, dummy
.filters());
574 EXPECT_FALSE(controller
->HasActiveAnimation());
575 event
= GetMostRecentPropertyUpdateEvent(events
.get());
579 TEST(LayerAnimationControllerTest
, FilterTransitionOnImplOnly
) {
580 scoped_ptr
<AnimationEventsVector
> events(
581 make_scoped_ptr(new AnimationEventsVector
));
582 FakeLayerAnimationValueObserver dummy_impl
;
583 scoped_refptr
<LayerAnimationController
> controller_impl(
584 LayerAnimationController::Create(0));
585 controller_impl
->AddValueObserver(&dummy_impl
);
587 scoped_ptr
<KeyframedFilterAnimationCurve
> curve(
588 KeyframedFilterAnimationCurve::Create());
590 // Create simple FILTER animation.
591 FilterOperations start_filters
;
592 start_filters
.Append(FilterOperation::CreateBrightnessFilter(1.f
));
594 FilterKeyframe::Create(base::TimeDelta(), start_filters
, nullptr));
595 FilterOperations end_filters
;
596 end_filters
.Append(FilterOperation::CreateBrightnessFilter(2.f
));
597 curve
->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
598 end_filters
, nullptr));
600 scoped_ptr
<Animation
> animation(
601 Animation::Create(curve
.Pass(), 1, 0, Animation::FILTER
));
602 animation
->set_is_impl_only(true);
603 controller_impl
->AddAnimation(animation
.Pass());
606 controller_impl
->Animate(kInitialTickTime
);
607 controller_impl
->UpdateState(true, events
.get());
608 EXPECT_TRUE(controller_impl
->HasActiveAnimation());
609 EXPECT_EQ(start_filters
, dummy_impl
.filters());
610 EXPECT_EQ(1u, events
->size());
611 const AnimationEvent
* start_filter_event
=
612 GetMostRecentPropertyUpdateEvent(events
.get());
613 EXPECT_TRUE(start_filter_event
);
614 EXPECT_EQ(start_filters
, start_filter_event
->filters
);
615 EXPECT_TRUE(start_filter_event
->is_impl_only
);
617 controller_impl
->Animate(kInitialTickTime
+
618 TimeDelta::FromMilliseconds(1000));
619 controller_impl
->UpdateState(true, events
.get());
620 EXPECT_EQ(end_filters
, dummy_impl
.filters());
621 EXPECT_FALSE(controller_impl
->HasActiveAnimation());
622 EXPECT_EQ(2u, events
->size());
623 const AnimationEvent
* end_filter_event
=
624 GetMostRecentPropertyUpdateEvent(events
.get());
625 EXPECT_TRUE(end_filter_event
);
626 EXPECT_EQ(end_filters
, end_filter_event
->filters
);
627 EXPECT_TRUE(end_filter_event
->is_impl_only
);
630 TEST(LayerAnimationControllerTest
, ScrollOffsetTransition
) {
631 FakeLayerAnimationValueObserver dummy_impl
;
632 FakeLayerAnimationValueProvider dummy_provider_impl
;
633 scoped_refptr
<LayerAnimationController
> controller_impl(
634 LayerAnimationController::Create(0));
635 controller_impl
->AddValueObserver(&dummy_impl
);
636 controller_impl
->set_value_provider(&dummy_provider_impl
);
637 scoped_ptr
<AnimationEventsVector
> events(
638 make_scoped_ptr(new AnimationEventsVector
));
639 FakeLayerAnimationValueObserver dummy
;
640 FakeLayerAnimationValueProvider dummy_provider
;
641 scoped_refptr
<LayerAnimationController
> controller(
642 LayerAnimationController::Create(0));
643 controller
->AddValueObserver(&dummy
);
644 controller
->set_value_provider(&dummy_provider
);
646 gfx::ScrollOffset
initial_value(100.f
, 300.f
);
647 gfx::ScrollOffset
target_value(300.f
, 200.f
);
648 scoped_ptr
<ScrollOffsetAnimationCurve
> curve(
649 ScrollOffsetAnimationCurve::Create(
651 EaseInOutTimingFunction::Create().Pass()));
653 scoped_ptr
<Animation
> animation(
654 Animation::Create(curve
.Pass(), 1, 0, Animation::SCROLL_OFFSET
));
655 animation
->set_needs_synchronized_start_time(true);
656 controller
->AddAnimation(animation
.Pass());
658 dummy_provider_impl
.set_scroll_offset(initial_value
);
659 controller
->PushAnimationUpdatesTo(controller_impl
.get());
660 controller_impl
->ActivateAnimations();
661 EXPECT_TRUE(controller_impl
->GetAnimation(Animation::SCROLL_OFFSET
));
662 TimeDelta duration
= controller_impl
->GetAnimation(Animation::SCROLL_OFFSET
)
667 controller
->GetAnimation(Animation::SCROLL_OFFSET
)->curve()->Duration());
669 controller
->Animate(kInitialTickTime
);
670 controller
->UpdateState(true, nullptr);
671 EXPECT_TRUE(controller
->HasActiveAnimation());
672 EXPECT_EQ(initial_value
, dummy
.scroll_offset());
674 controller_impl
->Animate(kInitialTickTime
);
675 controller_impl
->UpdateState(true, events
.get());
676 EXPECT_TRUE(controller_impl
->HasActiveAnimation());
677 EXPECT_EQ(initial_value
, dummy_impl
.scroll_offset());
678 // Scroll offset animations should not generate property updates.
679 const AnimationEvent
* event
= GetMostRecentPropertyUpdateEvent(events
.get());
682 controller
->NotifyAnimationStarted((*events
)[0]);
683 controller
->Animate(kInitialTickTime
+ duration
/ 2);
684 controller
->UpdateState(true, nullptr);
685 EXPECT_TRUE(controller
->HasActiveAnimation());
686 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f
, 250.f
), dummy
.scroll_offset());
688 controller_impl
->Animate(kInitialTickTime
+ duration
/ 2);
689 controller_impl
->UpdateState(true, events
.get());
690 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f
, 250.f
),
691 dummy_impl
.scroll_offset());
692 event
= GetMostRecentPropertyUpdateEvent(events
.get());
695 controller_impl
->Animate(kInitialTickTime
+ duration
);
696 controller_impl
->UpdateState(true, events
.get());
697 EXPECT_VECTOR2DF_EQ(target_value
, dummy_impl
.scroll_offset());
698 EXPECT_FALSE(controller_impl
->HasActiveAnimation());
699 event
= GetMostRecentPropertyUpdateEvent(events
.get());
702 controller
->Animate(kInitialTickTime
+ duration
);
703 controller
->UpdateState(true, nullptr);
704 EXPECT_VECTOR2DF_EQ(target_value
, dummy
.scroll_offset());
705 EXPECT_FALSE(controller
->HasActiveAnimation());
708 // Ensure that when the impl controller doesn't have a value provider,
709 // the main-thread controller's value provider is used to obtain the intial
711 TEST(LayerAnimationControllerTest
, ScrollOffsetTransitionNoImplProvider
) {
712 FakeLayerAnimationValueObserver dummy_impl
;
713 scoped_refptr
<LayerAnimationController
> controller_impl(
714 LayerAnimationController::Create(0));
715 controller_impl
->AddValueObserver(&dummy_impl
);
716 scoped_ptr
<AnimationEventsVector
> events(
717 make_scoped_ptr(new AnimationEventsVector
));
718 FakeLayerAnimationValueObserver dummy
;
719 FakeLayerAnimationValueProvider dummy_provider
;
720 scoped_refptr
<LayerAnimationController
> controller(
721 LayerAnimationController::Create(0));
722 controller
->AddValueObserver(&dummy
);
723 controller
->set_value_provider(&dummy_provider
);
725 gfx::ScrollOffset
initial_value(500.f
, 100.f
);
726 gfx::ScrollOffset
target_value(300.f
, 200.f
);
727 scoped_ptr
<ScrollOffsetAnimationCurve
> curve(
728 ScrollOffsetAnimationCurve::Create(
730 EaseInOutTimingFunction::Create().Pass()));
732 scoped_ptr
<Animation
> animation(
733 Animation::Create(curve
.Pass(), 1, 0, Animation::SCROLL_OFFSET
));
734 animation
->set_needs_synchronized_start_time(true);
735 controller
->AddAnimation(animation
.Pass());
737 dummy_provider
.set_scroll_offset(initial_value
);
738 controller
->PushAnimationUpdatesTo(controller_impl
.get());
739 controller_impl
->ActivateAnimations();
740 EXPECT_TRUE(controller_impl
->GetAnimation(Animation::SCROLL_OFFSET
));
741 TimeDelta duration
= controller_impl
->GetAnimation(Animation::SCROLL_OFFSET
)
746 controller
->GetAnimation(Animation::SCROLL_OFFSET
)->curve()->Duration());
748 controller
->Animate(kInitialTickTime
);
749 controller
->UpdateState(true, nullptr);
750 EXPECT_TRUE(controller
->HasActiveAnimation());
751 EXPECT_EQ(initial_value
, dummy
.scroll_offset());
753 controller_impl
->Animate(kInitialTickTime
);
754 controller_impl
->UpdateState(true, events
.get());
755 EXPECT_TRUE(controller_impl
->HasActiveAnimation());
756 EXPECT_EQ(initial_value
, dummy_impl
.scroll_offset());
757 // Scroll offset animations should not generate property updates.
758 const AnimationEvent
* event
= GetMostRecentPropertyUpdateEvent(events
.get());
762 controller
->NotifyAnimationStarted((*events
)[0]);
763 controller
->Animate(kInitialTickTime
+ duration
/ 2);
764 controller
->UpdateState(true, nullptr);
765 EXPECT_TRUE(controller
->HasActiveAnimation());
766 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f
, 150.f
), dummy
.scroll_offset());
768 controller_impl
->Animate(kInitialTickTime
+ duration
/ 2);
769 controller_impl
->UpdateState(true, events
.get());
770 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f
, 150.f
),
771 dummy_impl
.scroll_offset());
772 event
= GetMostRecentPropertyUpdateEvent(events
.get());
775 controller_impl
->Animate(kInitialTickTime
+ duration
);
776 controller_impl
->UpdateState(true, events
.get());
777 EXPECT_VECTOR2DF_EQ(target_value
, dummy_impl
.scroll_offset());
778 EXPECT_FALSE(controller_impl
->HasActiveAnimation());
779 event
= GetMostRecentPropertyUpdateEvent(events
.get());
782 controller
->Animate(kInitialTickTime
+ duration
);
783 controller
->UpdateState(true, nullptr);
784 EXPECT_VECTOR2DF_EQ(target_value
, dummy
.scroll_offset());
785 EXPECT_FALSE(controller
->HasActiveAnimation());
788 TEST(LayerAnimationControllerTest
, ScrollOffsetTransitionOnImplOnly
) {
789 FakeLayerAnimationValueObserver dummy_impl
;
790 scoped_refptr
<LayerAnimationController
> controller_impl(
791 LayerAnimationController::Create(0));
792 controller_impl
->AddValueObserver(&dummy_impl
);
793 scoped_ptr
<AnimationEventsVector
> events(
794 make_scoped_ptr(new AnimationEventsVector
));
796 gfx::ScrollOffset
initial_value(100.f
, 300.f
);
797 gfx::ScrollOffset
target_value(300.f
, 200.f
);
798 scoped_ptr
<ScrollOffsetAnimationCurve
> curve(
799 ScrollOffsetAnimationCurve::Create(
801 EaseInOutTimingFunction::Create().Pass()));
802 curve
->SetInitialValue(initial_value
);
803 double duration_in_seconds
= curve
->Duration().InSecondsF();
805 scoped_ptr
<Animation
> animation(
806 Animation::Create(curve
.Pass(), 1, 0, Animation::SCROLL_OFFSET
));
807 animation
->set_is_impl_only(true);
808 controller_impl
->AddAnimation(animation
.Pass());
810 controller_impl
->Animate(kInitialTickTime
);
811 controller_impl
->UpdateState(true, events
.get());
812 EXPECT_TRUE(controller_impl
->HasActiveAnimation());
813 EXPECT_EQ(initial_value
, dummy_impl
.scroll_offset());
814 // Scroll offset animations should not generate property updates.
815 const AnimationEvent
* event
= GetMostRecentPropertyUpdateEvent(events
.get());
818 TimeDelta duration
= TimeDelta::FromMicroseconds(
819 duration_in_seconds
* base::Time::kMicrosecondsPerSecond
);
821 controller_impl
->Animate(kInitialTickTime
+ duration
/ 2);
822 controller_impl
->UpdateState(true, events
.get());
823 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f
, 250.f
),
824 dummy_impl
.scroll_offset());
825 event
= GetMostRecentPropertyUpdateEvent(events
.get());
828 controller_impl
->Animate(kInitialTickTime
+ duration
);
829 controller_impl
->UpdateState(true, events
.get());
830 EXPECT_VECTOR2DF_EQ(target_value
, dummy_impl
.scroll_offset());
831 EXPECT_FALSE(controller_impl
->HasActiveAnimation());
832 event
= GetMostRecentPropertyUpdateEvent(events
.get());
836 TEST(LayerAnimationControllerTest
, ScrollOffsetRemovalClearsScrollDelta
) {
837 FakeLayerAnimationValueObserver dummy_impl
;
838 FakeLayerAnimationValueProvider dummy_provider_impl
;
839 scoped_refptr
<LayerAnimationController
> controller_impl(
840 LayerAnimationController::Create(0));
841 controller_impl
->AddValueObserver(&dummy_impl
);
842 controller_impl
->set_value_provider(&dummy_provider_impl
);
843 scoped_ptr
<AnimationEventsVector
> events(
844 make_scoped_ptr(new AnimationEventsVector
));
845 FakeLayerAnimationValueObserver dummy
;
846 FakeLayerAnimationValueProvider dummy_provider
;
847 scoped_refptr
<LayerAnimationController
> controller(
848 LayerAnimationController::Create(0));
849 controller
->AddValueObserver(&dummy
);
850 controller
->set_value_provider(&dummy_provider
);
852 // First test the 1-argument version of RemoveAnimation.
853 gfx::ScrollOffset
target_value(300.f
, 200.f
);
854 scoped_ptr
<ScrollOffsetAnimationCurve
> curve(
855 ScrollOffsetAnimationCurve::Create(
856 target_value
, EaseInOutTimingFunction::Create().Pass()));
858 int animation_id
= 1;
859 scoped_ptr
<Animation
> animation(Animation::Create(
860 curve
.Pass(), animation_id
, 0, Animation::SCROLL_OFFSET
));
861 animation
->set_needs_synchronized_start_time(true);
862 controller
->AddAnimation(animation
.Pass());
863 controller
->PushAnimationUpdatesTo(controller_impl
.get());
864 controller_impl
->ActivateAnimations();
865 EXPECT_FALSE(controller
->scroll_offset_animation_was_interrupted());
866 EXPECT_FALSE(controller_impl
->scroll_offset_animation_was_interrupted());
868 controller
->RemoveAnimation(animation_id
);
869 EXPECT_TRUE(controller
->scroll_offset_animation_was_interrupted());
871 controller
->PushAnimationUpdatesTo(controller_impl
.get());
872 EXPECT_TRUE(controller_impl
->scroll_offset_animation_was_interrupted());
873 EXPECT_FALSE(controller
->scroll_offset_animation_was_interrupted());
875 controller_impl
->ActivateAnimations();
876 EXPECT_FALSE(controller_impl
->scroll_offset_animation_was_interrupted());
878 // Now, test the 2-argument version of RemoveAnimation.
879 curve
= ScrollOffsetAnimationCurve::Create(
880 target_value
, EaseInOutTimingFunction::Create().Pass());
881 animation
= Animation::Create(curve
.Pass(), animation_id
, 0,
882 Animation::SCROLL_OFFSET
);
883 animation
->set_needs_synchronized_start_time(true);
884 controller
->AddAnimation(animation
.Pass());
885 controller
->PushAnimationUpdatesTo(controller_impl
.get());
886 controller_impl
->ActivateAnimations();
887 EXPECT_FALSE(controller
->scroll_offset_animation_was_interrupted());
888 EXPECT_FALSE(controller_impl
->scroll_offset_animation_was_interrupted());
890 controller
->RemoveAnimation(animation_id
);
891 EXPECT_TRUE(controller
->scroll_offset_animation_was_interrupted());
893 controller
->PushAnimationUpdatesTo(controller_impl
.get());
894 EXPECT_TRUE(controller_impl
->scroll_offset_animation_was_interrupted());
895 EXPECT_FALSE(controller
->scroll_offset_animation_was_interrupted());
897 controller_impl
->ActivateAnimations();
898 EXPECT_FALSE(controller_impl
->scroll_offset_animation_was_interrupted());
900 // Check that removing non-scroll-offset animations does not cause
901 // scroll_offset_animation_was_interrupted() to get set.
902 animation_id
= AddAnimatedTransformToController(controller
.get(), 1.0, 1, 2);
903 controller
->PushAnimationUpdatesTo(controller_impl
.get());
904 controller_impl
->ActivateAnimations();
905 EXPECT_FALSE(controller
->scroll_offset_animation_was_interrupted());
906 EXPECT_FALSE(controller_impl
->scroll_offset_animation_was_interrupted());
908 controller
->RemoveAnimation(animation_id
);
909 EXPECT_FALSE(controller
->scroll_offset_animation_was_interrupted());
911 controller
->PushAnimationUpdatesTo(controller_impl
.get());
912 EXPECT_FALSE(controller_impl
->scroll_offset_animation_was_interrupted());
913 EXPECT_FALSE(controller
->scroll_offset_animation_was_interrupted());
915 controller_impl
->ActivateAnimations();
916 EXPECT_FALSE(controller_impl
->scroll_offset_animation_was_interrupted());
919 AddAnimatedFilterToController(controller
.get(), 1.0, 0.1f
, 0.2f
);
920 controller
->PushAnimationUpdatesTo(controller_impl
.get());
921 controller_impl
->ActivateAnimations();
922 EXPECT_FALSE(controller
->scroll_offset_animation_was_interrupted());
923 EXPECT_FALSE(controller_impl
->scroll_offset_animation_was_interrupted());
925 controller
->RemoveAnimation(animation_id
);
926 EXPECT_FALSE(controller
->scroll_offset_animation_was_interrupted());
928 controller
->PushAnimationUpdatesTo(controller_impl
.get());
929 EXPECT_FALSE(controller_impl
->scroll_offset_animation_was_interrupted());
930 EXPECT_FALSE(controller
->scroll_offset_animation_was_interrupted());
932 controller_impl
->ActivateAnimations();
933 EXPECT_FALSE(controller_impl
->scroll_offset_animation_was_interrupted());
936 class FakeAnimationDelegate
: public AnimationDelegate
{
938 FakeAnimationDelegate()
942 void NotifyAnimationStarted(TimeTicks monotonic_time
,
943 Animation::TargetProperty target_property
,
944 int group
) override
{
948 void NotifyAnimationFinished(TimeTicks monotonic_time
,
949 Animation::TargetProperty target_property
,
950 int group
) override
{
954 bool started() { return started_
; }
956 bool finished() { return finished_
; }
963 // Tests that impl-only animations lead to start and finished notifications
964 // on the impl thread controller's animation delegate.
965 TEST(LayerAnimationControllerTest
,
966 NotificationsForImplOnlyAnimationsAreSentToImplThreadDelegate
) {
967 FakeLayerAnimationValueObserver dummy_impl
;
968 scoped_refptr
<LayerAnimationController
> controller_impl(
969 LayerAnimationController::Create(0));
970 controller_impl
->AddValueObserver(&dummy_impl
);
971 scoped_ptr
<AnimationEventsVector
> events(
972 make_scoped_ptr(new AnimationEventsVector
));
973 FakeAnimationDelegate delegate
;
974 controller_impl
->set_layer_animation_delegate(&delegate
);
976 scoped_ptr
<Animation
> to_add(CreateAnimation(
977 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
978 1, Animation::OPACITY
));
979 to_add
->set_is_impl_only(true);
980 controller_impl
->AddAnimation(to_add
.Pass());
982 EXPECT_FALSE(delegate
.started());
983 EXPECT_FALSE(delegate
.finished());
985 controller_impl
->Animate(kInitialTickTime
);
986 controller_impl
->UpdateState(true, events
.get());
988 EXPECT_TRUE(delegate
.started());
989 EXPECT_FALSE(delegate
.finished());
991 events
.reset(new AnimationEventsVector
);
992 controller_impl
->Animate(kInitialTickTime
+
993 TimeDelta::FromMilliseconds(1000));
994 controller_impl
->UpdateState(true, events
.get());
996 EXPECT_TRUE(delegate
.started());
997 EXPECT_TRUE(delegate
.finished());
1000 // Tests animations that are waiting for a synchronized start time do not
1002 TEST(LayerAnimationControllerTest
,
1003 AnimationsWaitingForStartTimeDoNotFinishIfTheyOutwaitTheirFinish
) {
1004 scoped_ptr
<AnimationEventsVector
> events(
1005 make_scoped_ptr(new AnimationEventsVector
));
1006 FakeLayerAnimationValueObserver dummy
;
1007 scoped_refptr
<LayerAnimationController
> controller(
1008 LayerAnimationController::Create(0));
1009 controller
->AddValueObserver(&dummy
);
1011 scoped_ptr
<Animation
> to_add(CreateAnimation(
1012 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1013 1, Animation::OPACITY
));
1014 to_add
->set_needs_synchronized_start_time(true);
1016 // We should pause at the first keyframe indefinitely waiting for that
1017 // animation to start.
1018 controller
->AddAnimation(to_add
.Pass());
1019 controller
->Animate(kInitialTickTime
);
1020 controller
->UpdateState(true, events
.get());
1021 EXPECT_TRUE(controller
->HasActiveAnimation());
1022 EXPECT_EQ(0.f
, dummy
.opacity());
1023 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1000));
1024 controller
->UpdateState(true, events
.get());
1025 EXPECT_TRUE(controller
->HasActiveAnimation());
1026 EXPECT_EQ(0.f
, dummy
.opacity());
1027 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(2000));
1028 controller
->UpdateState(true, events
.get());
1029 EXPECT_TRUE(controller
->HasActiveAnimation());
1030 EXPECT_EQ(0.f
, dummy
.opacity());
1032 // Send the synchronized start time.
1033 controller
->NotifyAnimationStarted(
1034 AnimationEvent(AnimationEvent::STARTED
, 0, 1, Animation::OPACITY
,
1035 kInitialTickTime
+ TimeDelta::FromMilliseconds(2000)));
1036 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(5000));
1037 controller
->UpdateState(true, events
.get());
1038 EXPECT_EQ(1.f
, dummy
.opacity());
1039 EXPECT_FALSE(controller
->HasActiveAnimation());
1042 // Tests that two queued animations affecting the same property run in sequence.
1043 TEST(LayerAnimationControllerTest
, TrivialQueuing
) {
1044 scoped_ptr
<AnimationEventsVector
> events(
1045 make_scoped_ptr(new AnimationEventsVector
));
1046 FakeLayerAnimationValueObserver dummy
;
1047 scoped_refptr
<LayerAnimationController
> controller(
1048 LayerAnimationController::Create(0));
1049 controller
->AddValueObserver(&dummy
);
1051 EXPECT_FALSE(controller
->needs_to_start_animations_for_testing());
1053 controller
->AddAnimation(CreateAnimation(
1054 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1055 1, Animation::OPACITY
));
1056 controller
->AddAnimation(CreateAnimation(
1057 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 1.f
, 0.5f
))
1059 2, Animation::OPACITY
));
1061 EXPECT_TRUE(controller
->needs_to_start_animations_for_testing());
1063 controller
->Animate(kInitialTickTime
);
1065 // The second animation still needs to be started.
1066 EXPECT_TRUE(controller
->needs_to_start_animations_for_testing());
1068 controller
->UpdateState(true, events
.get());
1069 EXPECT_TRUE(controller
->HasActiveAnimation());
1070 EXPECT_EQ(0.f
, dummy
.opacity());
1072 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1000));
1073 EXPECT_TRUE(controller
->needs_to_start_animations_for_testing());
1074 controller
->UpdateState(true, events
.get());
1075 EXPECT_FALSE(controller
->needs_to_start_animations_for_testing());
1077 EXPECT_TRUE(controller
->HasActiveAnimation());
1078 EXPECT_EQ(1.f
, dummy
.opacity());
1079 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(2000));
1080 controller
->UpdateState(true, events
.get());
1081 EXPECT_EQ(0.5f
, dummy
.opacity());
1082 EXPECT_FALSE(controller
->HasActiveAnimation());
1085 // Tests interrupting a transition with another transition.
1086 TEST(LayerAnimationControllerTest
, Interrupt
) {
1087 scoped_ptr
<AnimationEventsVector
> events(
1088 make_scoped_ptr(new AnimationEventsVector
));
1089 FakeLayerAnimationValueObserver dummy
;
1090 scoped_refptr
<LayerAnimationController
> controller(
1091 LayerAnimationController::Create(0));
1092 controller
->AddValueObserver(&dummy
);
1093 controller
->AddAnimation(CreateAnimation(
1094 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1095 1, Animation::OPACITY
));
1096 controller
->Animate(kInitialTickTime
);
1097 controller
->UpdateState(true, events
.get());
1098 EXPECT_TRUE(controller
->HasActiveAnimation());
1099 EXPECT_EQ(0.f
, dummy
.opacity());
1101 scoped_ptr
<Animation
> to_add(CreateAnimation(
1102 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 1.f
, 0.5f
))
1104 2, Animation::OPACITY
));
1105 controller
->AbortAnimations(Animation::OPACITY
);
1106 controller
->AddAnimation(to_add
.Pass());
1108 // Since the previous animation was aborted, the new animation should start
1109 // right in this call to animate.
1110 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(500));
1111 controller
->UpdateState(true, events
.get());
1112 EXPECT_TRUE(controller
->HasActiveAnimation());
1113 EXPECT_EQ(1.f
, dummy
.opacity());
1114 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1500));
1115 controller
->UpdateState(true, events
.get());
1116 EXPECT_EQ(0.5f
, dummy
.opacity());
1117 EXPECT_FALSE(controller
->HasActiveAnimation());
1120 // Tests scheduling two animations to run together when only one property is
1122 TEST(LayerAnimationControllerTest
, ScheduleTogetherWhenAPropertyIsBlocked
) {
1123 scoped_ptr
<AnimationEventsVector
> events(
1124 make_scoped_ptr(new AnimationEventsVector
));
1125 FakeLayerAnimationValueObserver dummy
;
1126 scoped_refptr
<LayerAnimationController
> controller(
1127 LayerAnimationController::Create(0));
1128 controller
->AddValueObserver(&dummy
);
1130 controller
->AddAnimation(CreateAnimation(
1131 scoped_ptr
<AnimationCurve
>(new FakeTransformTransition(1)).Pass(), 1,
1132 Animation::TRANSFORM
));
1133 controller
->AddAnimation(CreateAnimation(
1134 scoped_ptr
<AnimationCurve
>(new FakeTransformTransition(1)).Pass(), 2,
1135 Animation::TRANSFORM
));
1136 controller
->AddAnimation(CreateAnimation(
1137 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1138 2, Animation::OPACITY
));
1140 controller
->Animate(kInitialTickTime
);
1141 controller
->UpdateState(true, events
.get());
1142 EXPECT_EQ(0.f
, dummy
.opacity());
1143 EXPECT_TRUE(controller
->HasActiveAnimation());
1144 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1000));
1145 controller
->UpdateState(true, events
.get());
1146 // Should not have started the float transition yet.
1147 EXPECT_TRUE(controller
->HasActiveAnimation());
1148 EXPECT_EQ(0.f
, dummy
.opacity());
1149 // The float animation should have started at time 1 and should be done.
1150 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(2000));
1151 controller
->UpdateState(true, events
.get());
1152 EXPECT_EQ(1.f
, dummy
.opacity());
1153 EXPECT_FALSE(controller
->HasActiveAnimation());
1156 // Tests scheduling two animations to run together with different lengths and
1157 // another animation queued to start when the shorter animation finishes (should
1158 // wait for both to finish).
1159 TEST(LayerAnimationControllerTest
, ScheduleTogetherWithAnAnimWaiting
) {
1160 scoped_ptr
<AnimationEventsVector
> events(
1161 make_scoped_ptr(new AnimationEventsVector
));
1162 FakeLayerAnimationValueObserver dummy
;
1163 scoped_refptr
<LayerAnimationController
> controller(
1164 LayerAnimationController::Create(0));
1165 controller
->AddValueObserver(&dummy
);
1167 controller
->AddAnimation(CreateAnimation(
1168 scoped_ptr
<AnimationCurve
>(new FakeTransformTransition(2)).Pass(), 1,
1169 Animation::TRANSFORM
));
1170 controller
->AddAnimation(CreateAnimation(
1171 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1172 1, Animation::OPACITY
));
1173 controller
->AddAnimation(CreateAnimation(
1174 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 1.f
, 0.5f
))
1176 2, Animation::OPACITY
));
1178 // Animations with id 1 should both start now.
1179 controller
->Animate(kInitialTickTime
);
1180 controller
->UpdateState(true, events
.get());
1181 EXPECT_TRUE(controller
->HasActiveAnimation());
1182 EXPECT_EQ(0.f
, dummy
.opacity());
1183 // The opacity animation should have finished at time 1, but the group
1184 // of animations with id 1 don't finish until time 2 because of the length
1185 // of the transform animation.
1186 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(2000));
1187 controller
->UpdateState(true, events
.get());
1188 // Should not have started the float transition yet.
1189 EXPECT_TRUE(controller
->HasActiveAnimation());
1190 EXPECT_EQ(1.f
, dummy
.opacity());
1192 // The second opacity animation should start at time 2 and should be done by
1194 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(3000));
1195 controller
->UpdateState(true, events
.get());
1196 EXPECT_EQ(0.5f
, dummy
.opacity());
1197 EXPECT_FALSE(controller
->HasActiveAnimation());
1200 // Test that a looping animation loops and for the correct number of iterations.
1201 TEST(LayerAnimationControllerTest
, TrivialLooping
) {
1202 scoped_ptr
<AnimationEventsVector
> events(
1203 make_scoped_ptr(new AnimationEventsVector
));
1204 FakeLayerAnimationValueObserver dummy
;
1205 scoped_refptr
<LayerAnimationController
> controller(
1206 LayerAnimationController::Create(0));
1207 controller
->AddValueObserver(&dummy
);
1209 scoped_ptr
<Animation
> to_add(CreateAnimation(
1210 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1211 1, Animation::OPACITY
));
1212 to_add
->set_iterations(3);
1213 controller
->AddAnimation(to_add
.Pass());
1215 controller
->Animate(kInitialTickTime
);
1216 controller
->UpdateState(true, events
.get());
1217 EXPECT_TRUE(controller
->HasActiveAnimation());
1218 EXPECT_EQ(0.f
, dummy
.opacity());
1219 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1250));
1220 controller
->UpdateState(true, events
.get());
1221 EXPECT_TRUE(controller
->HasActiveAnimation());
1222 EXPECT_EQ(0.25f
, dummy
.opacity());
1223 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1750));
1224 controller
->UpdateState(true, events
.get());
1225 EXPECT_TRUE(controller
->HasActiveAnimation());
1226 EXPECT_EQ(0.75f
, dummy
.opacity());
1227 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(2250));
1228 controller
->UpdateState(true, events
.get());
1229 EXPECT_TRUE(controller
->HasActiveAnimation());
1230 EXPECT_EQ(0.25f
, dummy
.opacity());
1231 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(2750));
1232 controller
->UpdateState(true, events
.get());
1233 EXPECT_TRUE(controller
->HasActiveAnimation());
1234 EXPECT_EQ(0.75f
, dummy
.opacity());
1235 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(3000));
1236 controller
->UpdateState(true, events
.get());
1237 EXPECT_FALSE(controller
->HasActiveAnimation());
1238 EXPECT_EQ(1.f
, dummy
.opacity());
1240 // Just be extra sure.
1241 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(4000));
1242 controller
->UpdateState(true, events
.get());
1243 EXPECT_EQ(1.f
, dummy
.opacity());
1246 // Test that an infinitely looping animation does indeed go until aborted.
1247 TEST(LayerAnimationControllerTest
, InfiniteLooping
) {
1248 scoped_ptr
<AnimationEventsVector
> events(
1249 make_scoped_ptr(new AnimationEventsVector
));
1250 FakeLayerAnimationValueObserver dummy
;
1251 scoped_refptr
<LayerAnimationController
> controller(
1252 LayerAnimationController::Create(0));
1253 controller
->AddValueObserver(&dummy
);
1255 scoped_ptr
<Animation
> to_add(CreateAnimation(
1256 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1257 1, Animation::OPACITY
));
1258 to_add
->set_iterations(-1);
1259 controller
->AddAnimation(to_add
.Pass());
1261 controller
->Animate(kInitialTickTime
);
1262 controller
->UpdateState(true, events
.get());
1263 EXPECT_TRUE(controller
->HasActiveAnimation());
1264 EXPECT_EQ(0.f
, dummy
.opacity());
1265 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1250));
1266 controller
->UpdateState(true, events
.get());
1267 EXPECT_TRUE(controller
->HasActiveAnimation());
1268 EXPECT_EQ(0.25f
, dummy
.opacity());
1269 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1750));
1270 controller
->UpdateState(true, events
.get());
1271 EXPECT_TRUE(controller
->HasActiveAnimation());
1272 EXPECT_EQ(0.75f
, dummy
.opacity());
1274 controller
->Animate(kInitialTickTime
+
1275 TimeDelta::FromMilliseconds(1073741824250));
1276 controller
->UpdateState(true, events
.get());
1277 EXPECT_TRUE(controller
->HasActiveAnimation());
1278 EXPECT_EQ(0.25f
, dummy
.opacity());
1279 controller
->Animate(kInitialTickTime
+
1280 TimeDelta::FromMilliseconds(1073741824750));
1281 controller
->UpdateState(true, events
.get());
1282 EXPECT_TRUE(controller
->HasActiveAnimation());
1283 EXPECT_EQ(0.75f
, dummy
.opacity());
1285 EXPECT_TRUE(controller
->GetAnimation(Animation::OPACITY
));
1286 controller
->GetAnimation(Animation::OPACITY
)
1287 ->SetRunState(Animation::ABORTED
,
1288 kInitialTickTime
+ TimeDelta::FromMilliseconds(750));
1289 EXPECT_FALSE(controller
->HasActiveAnimation());
1290 EXPECT_EQ(0.75f
, dummy
.opacity());
1293 // Test that pausing and resuming work as expected.
1294 TEST(LayerAnimationControllerTest
, PauseResume
) {
1295 scoped_ptr
<AnimationEventsVector
> events(
1296 make_scoped_ptr(new AnimationEventsVector
));
1297 FakeLayerAnimationValueObserver dummy
;
1298 scoped_refptr
<LayerAnimationController
> controller(
1299 LayerAnimationController::Create(0));
1300 controller
->AddValueObserver(&dummy
);
1302 controller
->AddAnimation(CreateAnimation(
1303 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1304 1, Animation::OPACITY
));
1306 controller
->Animate(kInitialTickTime
);
1307 controller
->UpdateState(true, events
.get());
1308 EXPECT_TRUE(controller
->HasActiveAnimation());
1309 EXPECT_EQ(0.f
, dummy
.opacity());
1310 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(500));
1311 controller
->UpdateState(true, events
.get());
1312 EXPECT_TRUE(controller
->HasActiveAnimation());
1313 EXPECT_EQ(0.5f
, dummy
.opacity());
1315 EXPECT_TRUE(controller
->GetAnimation(Animation::OPACITY
));
1316 controller
->GetAnimation(Animation::OPACITY
)
1317 ->SetRunState(Animation::PAUSED
,
1318 kInitialTickTime
+ TimeDelta::FromMilliseconds(500));
1320 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1024000));
1321 controller
->UpdateState(true, events
.get());
1322 EXPECT_TRUE(controller
->HasActiveAnimation());
1323 EXPECT_EQ(0.5f
, dummy
.opacity());
1325 EXPECT_TRUE(controller
->GetAnimation(Animation::OPACITY
));
1326 controller
->GetAnimation(Animation::OPACITY
)
1327 ->SetRunState(Animation::RUNNING
,
1328 kInitialTickTime
+ TimeDelta::FromMilliseconds(1024000));
1329 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1024250));
1330 controller
->UpdateState(true, events
.get());
1331 EXPECT_TRUE(controller
->HasActiveAnimation());
1332 EXPECT_EQ(0.75f
, dummy
.opacity());
1334 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1024500));
1335 controller
->UpdateState(true, events
.get());
1336 EXPECT_FALSE(controller
->HasActiveAnimation());
1337 EXPECT_EQ(1.f
, dummy
.opacity());
1340 TEST(LayerAnimationControllerTest
, AbortAGroupedAnimation
) {
1341 scoped_ptr
<AnimationEventsVector
> events(
1342 make_scoped_ptr(new AnimationEventsVector
));
1343 FakeLayerAnimationValueObserver dummy
;
1344 scoped_refptr
<LayerAnimationController
> controller(
1345 LayerAnimationController::Create(0));
1346 controller
->AddValueObserver(&dummy
);
1348 const int animation_id
= 2;
1349 controller
->AddAnimation(Animation::Create(
1350 scoped_ptr
<AnimationCurve
>(new FakeTransformTransition(1)).Pass(), 1, 1,
1351 Animation::TRANSFORM
));
1352 controller
->AddAnimation(Animation::Create(
1353 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(2.0, 0.f
, 1.f
)).Pass(),
1354 animation_id
, 1, Animation::OPACITY
));
1355 controller
->AddAnimation(Animation::Create(
1356 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 1.f
, 0.75f
))
1358 3, 2, Animation::OPACITY
));
1360 controller
->Animate(kInitialTickTime
);
1361 controller
->UpdateState(true, events
.get());
1362 EXPECT_TRUE(controller
->HasActiveAnimation());
1363 EXPECT_EQ(0.f
, dummy
.opacity());
1364 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1000));
1365 controller
->UpdateState(true, events
.get());
1366 EXPECT_TRUE(controller
->HasActiveAnimation());
1367 EXPECT_EQ(0.5f
, dummy
.opacity());
1369 EXPECT_TRUE(controller
->GetAnimationById(animation_id
));
1370 controller
->GetAnimationById(animation_id
)
1371 ->SetRunState(Animation::ABORTED
,
1372 kInitialTickTime
+ TimeDelta::FromMilliseconds(1000));
1373 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1000));
1374 controller
->UpdateState(true, events
.get());
1375 EXPECT_TRUE(controller
->HasActiveAnimation());
1376 EXPECT_EQ(1.f
, dummy
.opacity());
1377 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(2000));
1378 controller
->UpdateState(true, events
.get());
1379 EXPECT_TRUE(!controller
->HasActiveAnimation());
1380 EXPECT_EQ(0.75f
, dummy
.opacity());
1383 TEST(LayerAnimationControllerTest
, PushUpdatesWhenSynchronizedStartTimeNeeded
) {
1384 FakeLayerAnimationValueObserver dummy_impl
;
1385 scoped_refptr
<LayerAnimationController
> controller_impl(
1386 LayerAnimationController::Create(0));
1387 controller_impl
->AddValueObserver(&dummy_impl
);
1388 scoped_ptr
<AnimationEventsVector
> events(
1389 make_scoped_ptr(new AnimationEventsVector
));
1390 FakeLayerAnimationValueObserver dummy
;
1391 scoped_refptr
<LayerAnimationController
> controller(
1392 LayerAnimationController::Create(0));
1393 controller
->AddValueObserver(&dummy
);
1395 scoped_ptr
<Animation
> to_add(CreateAnimation(
1396 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(2.0, 0.f
, 1.f
)).Pass(),
1397 0, Animation::OPACITY
));
1398 to_add
->set_needs_synchronized_start_time(true);
1399 controller
->AddAnimation(to_add
.Pass());
1401 controller
->Animate(kInitialTickTime
);
1402 controller
->UpdateState(true, events
.get());
1403 EXPECT_TRUE(controller
->HasActiveAnimation());
1404 Animation
* active_animation
= controller
->GetAnimation(Animation::OPACITY
);
1405 EXPECT_TRUE(active_animation
);
1406 EXPECT_TRUE(active_animation
->needs_synchronized_start_time());
1408 controller
->PushAnimationUpdatesTo(controller_impl
.get());
1409 controller_impl
->ActivateAnimations();
1411 active_animation
= controller_impl
->GetAnimation(Animation::OPACITY
);
1412 EXPECT_TRUE(active_animation
);
1413 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY
,
1414 active_animation
->run_state());
1417 // Tests that skipping a call to UpdateState works as expected.
1418 TEST(LayerAnimationControllerTest
, SkipUpdateState
) {
1419 scoped_ptr
<AnimationEventsVector
> events(
1420 make_scoped_ptr(new AnimationEventsVector
));
1421 FakeLayerAnimationValueObserver dummy
;
1422 scoped_refptr
<LayerAnimationController
> controller(
1423 LayerAnimationController::Create(0));
1424 controller
->AddValueObserver(&dummy
);
1426 controller
->AddAnimation(CreateAnimation(
1427 scoped_ptr
<AnimationCurve
>(new FakeTransformTransition(1)).Pass(), 1,
1428 Animation::TRANSFORM
));
1430 controller
->Animate(kInitialTickTime
);
1431 controller
->UpdateState(true, events
.get());
1433 controller
->AddAnimation(CreateAnimation(
1434 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1435 2, Animation::OPACITY
));
1437 // Animate but don't UpdateState.
1438 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1000));
1440 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(2000));
1441 events
.reset(new AnimationEventsVector
);
1442 controller
->UpdateState(true, events
.get());
1444 // Should have one STARTED event and one FINISHED event.
1445 EXPECT_EQ(2u, events
->size());
1446 EXPECT_NE((*events
)[0].type
, (*events
)[1].type
);
1448 // The float transition should still be at its starting point.
1449 EXPECT_TRUE(controller
->HasActiveAnimation());
1450 EXPECT_EQ(0.f
, dummy
.opacity());
1452 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(3000));
1453 controller
->UpdateState(true, events
.get());
1455 // The float tranisition should now be done.
1456 EXPECT_EQ(1.f
, dummy
.opacity());
1457 EXPECT_FALSE(controller
->HasActiveAnimation());
1460 // Tests that an animation controller with only a pending observer gets ticked
1461 // but doesn't progress animations past the STARTING state.
1462 TEST(LayerAnimationControllerTest
, InactiveObserverGetsTicked
) {
1463 scoped_ptr
<AnimationEventsVector
> events(
1464 make_scoped_ptr(new AnimationEventsVector
));
1465 FakeLayerAnimationValueObserver dummy
;
1466 FakeInactiveLayerAnimationValueObserver pending_dummy
;
1467 scoped_refptr
<LayerAnimationController
> controller(
1468 LayerAnimationController::Create(0));
1471 controller
->AddAnimation(CreateAnimation(
1472 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.5f
, 1.f
))
1474 id
, Animation::OPACITY
));
1476 // Without an observer, the animation shouldn't progress to the STARTING
1478 controller
->Animate(kInitialTickTime
);
1479 controller
->UpdateState(true, events
.get());
1480 EXPECT_EQ(0u, events
->size());
1481 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY
,
1482 controller
->GetAnimation(Animation::OPACITY
)->run_state());
1484 controller
->AddValueObserver(&pending_dummy
);
1486 // With only a pending observer, the animation should progress to the
1487 // STARTING state and get ticked at its starting point, but should not
1488 // progress to RUNNING.
1489 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1000));
1490 controller
->UpdateState(true, events
.get());
1491 EXPECT_EQ(0u, events
->size());
1492 EXPECT_EQ(Animation::STARTING
,
1493 controller
->GetAnimation(Animation::OPACITY
)->run_state());
1494 EXPECT_EQ(0.5f
, pending_dummy
.opacity());
1496 // Even when already in the STARTING state, the animation should stay
1497 // there, and shouldn't be ticked past its starting point.
1498 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(2000));
1499 controller
->UpdateState(true, events
.get());
1500 EXPECT_EQ(0u, events
->size());
1501 EXPECT_EQ(Animation::STARTING
,
1502 controller
->GetAnimation(Animation::OPACITY
)->run_state());
1503 EXPECT_EQ(0.5f
, pending_dummy
.opacity());
1505 controller
->AddValueObserver(&dummy
);
1507 // Now that an active observer has been added, the animation should still
1508 // initially tick at its starting point, but should now progress to RUNNING.
1509 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(3000));
1510 controller
->UpdateState(true, events
.get());
1511 EXPECT_EQ(1u, events
->size());
1512 EXPECT_EQ(Animation::RUNNING
,
1513 controller
->GetAnimation(Animation::OPACITY
)->run_state());
1514 EXPECT_EQ(0.5f
, pending_dummy
.opacity());
1515 EXPECT_EQ(0.5f
, dummy
.opacity());
1517 // The animation should now tick past its starting point.
1518 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(3500));
1519 EXPECT_NE(0.5f
, pending_dummy
.opacity());
1520 EXPECT_NE(0.5f
, dummy
.opacity());
1523 TEST(LayerAnimationControllerTest
, TransformAnimationBounds
) {
1524 scoped_refptr
<LayerAnimationController
> controller_impl(
1525 LayerAnimationController::Create(0));
1527 scoped_ptr
<KeyframedTransformAnimationCurve
> curve1(
1528 KeyframedTransformAnimationCurve::Create());
1530 TransformOperations operations1
;
1531 curve1
->AddKeyframe(
1532 TransformKeyframe::Create(base::TimeDelta(), operations1
, nullptr));
1533 operations1
.AppendTranslate(10.0, 15.0, 0.0);
1534 curve1
->AddKeyframe(TransformKeyframe::Create(
1535 base::TimeDelta::FromSecondsD(1.0), operations1
, nullptr));
1537 scoped_ptr
<Animation
> animation(
1538 Animation::Create(curve1
.Pass(), 1, 1, Animation::TRANSFORM
));
1539 controller_impl
->AddAnimation(animation
.Pass());
1541 scoped_ptr
<KeyframedTransformAnimationCurve
> curve2(
1542 KeyframedTransformAnimationCurve::Create());
1544 TransformOperations operations2
;
1545 curve2
->AddKeyframe(
1546 TransformKeyframe::Create(base::TimeDelta(), operations2
, nullptr));
1547 operations2
.AppendScale(2.0, 3.0, 4.0);
1548 curve2
->AddKeyframe(TransformKeyframe::Create(
1549 base::TimeDelta::FromSecondsD(1.0), operations2
, nullptr));
1551 animation
= Animation::Create(curve2
.Pass(), 2, 2, Animation::TRANSFORM
);
1552 controller_impl
->AddAnimation(animation
.Pass());
1554 gfx::BoxF
box(1.f
, 2.f
, -1.f
, 3.f
, 4.f
, 5.f
);
1557 EXPECT_TRUE(controller_impl
->TransformAnimationBoundsForBox(box
, &bounds
));
1558 EXPECT_EQ(gfx::BoxF(1.f
, 2.f
, -4.f
, 13.f
, 19.f
, 20.f
).ToString(),
1561 controller_impl
->GetAnimationById(1)
1562 ->SetRunState(Animation::FINISHED
, TicksFromSecondsF(0.0));
1564 // Only the unfinished animation should affect the animated bounds.
1565 EXPECT_TRUE(controller_impl
->TransformAnimationBoundsForBox(box
, &bounds
));
1566 EXPECT_EQ(gfx::BoxF(1.f
, 2.f
, -4.f
, 7.f
, 16.f
, 20.f
).ToString(),
1569 controller_impl
->GetAnimationById(2)
1570 ->SetRunState(Animation::FINISHED
, TicksFromSecondsF(0.0));
1572 // There are no longer any running animations.
1573 EXPECT_FALSE(controller_impl
->HasTransformAnimationThatInflatesBounds());
1575 // Add an animation whose bounds we don't yet support computing.
1576 scoped_ptr
<KeyframedTransformAnimationCurve
> curve3(
1577 KeyframedTransformAnimationCurve::Create());
1578 TransformOperations operations3
;
1579 gfx::Transform transform3
;
1580 transform3
.Scale3d(1.0, 2.0, 3.0);
1581 curve3
->AddKeyframe(
1582 TransformKeyframe::Create(base::TimeDelta(), operations3
, nullptr));
1583 operations3
.AppendMatrix(transform3
);
1584 curve3
->AddKeyframe(TransformKeyframe::Create(
1585 base::TimeDelta::FromSecondsD(1.0), operations3
, nullptr));
1586 animation
= Animation::Create(curve3
.Pass(), 3, 3, Animation::TRANSFORM
);
1587 controller_impl
->AddAnimation(animation
.Pass());
1588 EXPECT_FALSE(controller_impl
->TransformAnimationBoundsForBox(box
, &bounds
));
1591 // Tests that AbortAnimations aborts all animations targeting the specified
1593 TEST(LayerAnimationControllerTest
, AbortAnimations
) {
1594 FakeLayerAnimationValueObserver dummy
;
1595 scoped_refptr
<LayerAnimationController
> controller(
1596 LayerAnimationController::Create(0));
1597 controller
->AddValueObserver(&dummy
);
1599 // Start with several animations, and allow some of them to reach the finished
1601 controller
->AddAnimation(Animation::Create(
1602 scoped_ptr
<AnimationCurve
>(new FakeTransformTransition(1.0)).Pass(), 1, 1,
1603 Animation::TRANSFORM
));
1604 controller
->AddAnimation(Animation::Create(
1605 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1606 2, 2, Animation::OPACITY
));
1607 controller
->AddAnimation(Animation::Create(
1608 scoped_ptr
<AnimationCurve
>(new FakeTransformTransition(1.0)).Pass(), 3, 3,
1609 Animation::TRANSFORM
));
1610 controller
->AddAnimation(Animation::Create(
1611 scoped_ptr
<AnimationCurve
>(new FakeTransformTransition(2.0)).Pass(), 4, 4,
1612 Animation::TRANSFORM
));
1613 controller
->AddAnimation(Animation::Create(
1614 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1615 5, 5, Animation::OPACITY
));
1617 controller
->Animate(kInitialTickTime
);
1618 controller
->UpdateState(true, nullptr);
1619 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1000));
1620 controller
->UpdateState(true, nullptr);
1622 EXPECT_EQ(Animation::FINISHED
, controller
->GetAnimationById(1)->run_state());
1623 EXPECT_EQ(Animation::FINISHED
, controller
->GetAnimationById(2)->run_state());
1624 EXPECT_EQ(Animation::RUNNING
, controller
->GetAnimationById(3)->run_state());
1625 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY
,
1626 controller
->GetAnimationById(4)->run_state());
1627 EXPECT_EQ(Animation::RUNNING
, controller
->GetAnimationById(5)->run_state());
1629 controller
->AbortAnimations(Animation::TRANSFORM
);
1631 // Only un-finished TRANSFORM animations should have been aborted.
1632 EXPECT_EQ(Animation::FINISHED
, controller
->GetAnimationById(1)->run_state());
1633 EXPECT_EQ(Animation::FINISHED
, controller
->GetAnimationById(2)->run_state());
1634 EXPECT_EQ(Animation::ABORTED
, controller
->GetAnimationById(3)->run_state());
1635 EXPECT_EQ(Animation::ABORTED
, controller
->GetAnimationById(4)->run_state());
1636 EXPECT_EQ(Animation::RUNNING
, controller
->GetAnimationById(5)->run_state());
1639 // An animation aborted on the main thread should get deleted on both threads.
1640 TEST(LayerAnimationControllerTest
, MainThreadAbortedAnimationGetsDeleted
) {
1641 FakeLayerAnimationValueObserver dummy_impl
;
1642 scoped_refptr
<LayerAnimationController
> controller_impl(
1643 LayerAnimationController::Create(0));
1644 controller_impl
->AddValueObserver(&dummy_impl
);
1645 FakeLayerAnimationValueObserver dummy
;
1646 scoped_refptr
<LayerAnimationController
> controller(
1647 LayerAnimationController::Create(0));
1648 controller
->AddValueObserver(&dummy
);
1651 AddOpacityTransitionToController(controller
.get(), 1.0, 0.f
, 1.f
, false);
1653 controller
->PushAnimationUpdatesTo(controller_impl
.get());
1654 controller_impl
->ActivateAnimations();
1655 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
));
1657 controller
->AbortAnimations(Animation::OPACITY
);
1658 EXPECT_EQ(Animation::ABORTED
,
1659 controller
->GetAnimation(Animation::OPACITY
)->run_state());
1660 EXPECT_FALSE(dummy
.animation_waiting_for_deletion());
1661 EXPECT_FALSE(dummy_impl
.animation_waiting_for_deletion());
1663 controller
->Animate(kInitialTickTime
);
1664 controller
->UpdateState(true, nullptr);
1665 EXPECT_TRUE(dummy
.animation_waiting_for_deletion());
1666 EXPECT_EQ(Animation::WAITING_FOR_DELETION
,
1667 controller
->GetAnimation(Animation::OPACITY
)->run_state());
1669 controller
->PushAnimationUpdatesTo(controller_impl
.get());
1670 controller_impl
->ActivateAnimations();
1671 EXPECT_FALSE(controller
->GetAnimationById(animation_id
));
1672 EXPECT_FALSE(controller_impl
->GetAnimationById(animation_id
));
1675 // An animation aborted on the impl thread should get deleted on both threads.
1676 TEST(LayerAnimationControllerTest
, ImplThreadAbortedAnimationGetsDeleted
) {
1677 FakeLayerAnimationValueObserver dummy_impl
;
1678 scoped_refptr
<LayerAnimationController
> controller_impl(
1679 LayerAnimationController::Create(0));
1680 controller_impl
->AddValueObserver(&dummy_impl
);
1681 FakeLayerAnimationValueObserver dummy
;
1682 scoped_refptr
<LayerAnimationController
> controller(
1683 LayerAnimationController::Create(0));
1684 controller
->AddValueObserver(&dummy
);
1687 AddOpacityTransitionToController(controller
.get(), 1.0, 0.f
, 1.f
, false);
1689 controller
->PushAnimationUpdatesTo(controller_impl
.get());
1690 controller_impl
->ActivateAnimations();
1691 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
));
1693 controller_impl
->AbortAnimations(Animation::OPACITY
);
1694 EXPECT_EQ(Animation::ABORTED
,
1695 controller_impl
->GetAnimation(Animation::OPACITY
)->run_state());
1696 EXPECT_FALSE(dummy
.animation_waiting_for_deletion());
1697 EXPECT_FALSE(dummy_impl
.animation_waiting_for_deletion());
1699 AnimationEventsVector events
;
1700 controller_impl
->Animate(kInitialTickTime
);
1701 controller_impl
->UpdateState(true, &events
);
1702 EXPECT_TRUE(dummy_impl
.animation_waiting_for_deletion());
1703 EXPECT_EQ(1u, events
.size());
1704 EXPECT_EQ(AnimationEvent::ABORTED
, events
[0].type
);
1705 EXPECT_EQ(Animation::WAITING_FOR_DELETION
,
1706 controller_impl
->GetAnimation(Animation::OPACITY
)->run_state());
1708 controller
->NotifyAnimationAborted(events
[0]);
1709 EXPECT_EQ(Animation::ABORTED
,
1710 controller
->GetAnimation(Animation::OPACITY
)->run_state());
1712 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(500));
1713 controller
->UpdateState(true, nullptr);
1714 EXPECT_TRUE(dummy
.animation_waiting_for_deletion());
1715 EXPECT_EQ(Animation::WAITING_FOR_DELETION
,
1716 controller
->GetAnimation(Animation::OPACITY
)->run_state());
1718 controller
->PushAnimationUpdatesTo(controller_impl
.get());
1719 controller_impl
->ActivateAnimations();
1720 EXPECT_FALSE(controller
->GetAnimationById(animation_id
));
1721 EXPECT_FALSE(controller_impl
->GetAnimationById(animation_id
));
1724 // Ensure that we only generate FINISHED events for animations in a group
1725 // once all animations in that group are finished.
1726 TEST(LayerAnimationControllerTest
, FinishedEventsForGroup
) {
1727 scoped_ptr
<AnimationEventsVector
> events(
1728 make_scoped_ptr(new AnimationEventsVector
));
1729 FakeLayerAnimationValueObserver dummy_impl
;
1730 scoped_refptr
<LayerAnimationController
> controller_impl(
1731 LayerAnimationController::Create(0));
1732 controller_impl
->AddValueObserver(&dummy_impl
);
1734 const int group_id
= 1;
1736 // Add two animations with the same group id but different durations.
1737 controller_impl
->AddAnimation(Animation::Create(
1738 scoped_ptr
<AnimationCurve
>(new FakeTransformTransition(2.0)).Pass(), 1,
1739 group_id
, Animation::TRANSFORM
));
1740 controller_impl
->AddAnimation(Animation::Create(
1741 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1742 2, group_id
, Animation::OPACITY
));
1744 controller_impl
->Animate(kInitialTickTime
);
1745 controller_impl
->UpdateState(true, events
.get());
1747 // Both animations should have started.
1748 EXPECT_EQ(2u, events
->size());
1749 EXPECT_EQ(AnimationEvent::STARTED
, (*events
)[0].type
);
1750 EXPECT_EQ(AnimationEvent::STARTED
, (*events
)[1].type
);
1752 events
.reset(new AnimationEventsVector
);
1753 controller_impl
->Animate(kInitialTickTime
+
1754 TimeDelta::FromMilliseconds(1000));
1755 controller_impl
->UpdateState(true, events
.get());
1757 // The opacity animation should be finished, but should not have generated
1758 // a FINISHED event yet.
1759 EXPECT_EQ(0u, events
->size());
1760 EXPECT_EQ(Animation::FINISHED
,
1761 controller_impl
->GetAnimationById(2)->run_state());
1762 EXPECT_EQ(Animation::RUNNING
,
1763 controller_impl
->GetAnimationById(1)->run_state());
1765 controller_impl
->Animate(kInitialTickTime
+
1766 TimeDelta::FromMilliseconds(2000));
1767 controller_impl
->UpdateState(true, events
.get());
1769 // Both animations should have generated FINISHED events.
1770 EXPECT_EQ(2u, events
->size());
1771 EXPECT_EQ(AnimationEvent::FINISHED
, (*events
)[0].type
);
1772 EXPECT_EQ(AnimationEvent::FINISHED
, (*events
)[1].type
);
1775 // Ensure that when a group has a mix of aborted and finished animations,
1776 // we generate a FINISHED event for the finished animation and an ABORTED
1777 // event for the aborted animation.
1778 TEST(LayerAnimationControllerTest
, FinishedAndAbortedEventsForGroup
) {
1779 scoped_ptr
<AnimationEventsVector
> events(
1780 make_scoped_ptr(new AnimationEventsVector
));
1781 FakeLayerAnimationValueObserver dummy_impl
;
1782 scoped_refptr
<LayerAnimationController
> controller_impl(
1783 LayerAnimationController::Create(0));
1784 controller_impl
->AddValueObserver(&dummy_impl
);
1786 // Add two animations with the same group id.
1787 controller_impl
->AddAnimation(CreateAnimation(
1788 scoped_ptr
<AnimationCurve
>(new FakeTransformTransition(1.0)).Pass(), 1,
1789 Animation::TRANSFORM
));
1790 controller_impl
->AddAnimation(CreateAnimation(
1791 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1792 1, Animation::OPACITY
));
1794 controller_impl
->Animate(kInitialTickTime
);
1795 controller_impl
->UpdateState(true, events
.get());
1797 // Both animations should have started.
1798 EXPECT_EQ(2u, events
->size());
1799 EXPECT_EQ(AnimationEvent::STARTED
, (*events
)[0].type
);
1800 EXPECT_EQ(AnimationEvent::STARTED
, (*events
)[1].type
);
1802 controller_impl
->AbortAnimations(Animation::OPACITY
);
1804 events
.reset(new AnimationEventsVector
);
1805 controller_impl
->Animate(kInitialTickTime
+
1806 TimeDelta::FromMilliseconds(1000));
1807 controller_impl
->UpdateState(true, events
.get());
1809 // We should have exactly 2 events: a FINISHED event for the tranform
1810 // animation, and an ABORTED event for the opacity animation.
1811 EXPECT_EQ(2u, events
->size());
1812 EXPECT_EQ(AnimationEvent::FINISHED
, (*events
)[0].type
);
1813 EXPECT_EQ(Animation::TRANSFORM
, (*events
)[0].target_property
);
1814 EXPECT_EQ(AnimationEvent::ABORTED
, (*events
)[1].type
);
1815 EXPECT_EQ(Animation::OPACITY
, (*events
)[1].target_property
);
1818 TEST(LayerAnimationControllerTest
, HasAnimationThatAffectsScale
) {
1819 scoped_refptr
<LayerAnimationController
> controller_impl(
1820 LayerAnimationController::Create(0));
1822 EXPECT_FALSE(controller_impl
->HasAnimationThatAffectsScale());
1824 controller_impl
->AddAnimation(CreateAnimation(
1825 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1826 1, Animation::OPACITY
));
1828 // Opacity animations don't affect scale.
1829 EXPECT_FALSE(controller_impl
->HasAnimationThatAffectsScale());
1831 scoped_ptr
<KeyframedTransformAnimationCurve
> curve1(
1832 KeyframedTransformAnimationCurve::Create());
1834 TransformOperations operations1
;
1835 curve1
->AddKeyframe(
1836 TransformKeyframe::Create(base::TimeDelta(), operations1
, nullptr));
1837 operations1
.AppendTranslate(10.0, 15.0, 0.0);
1838 curve1
->AddKeyframe(TransformKeyframe::Create(
1839 base::TimeDelta::FromSecondsD(1.0), operations1
, nullptr));
1841 scoped_ptr
<Animation
> animation(
1842 Animation::Create(curve1
.Pass(), 2, 2, Animation::TRANSFORM
));
1843 controller_impl
->AddAnimation(animation
.Pass());
1845 // Translations don't affect scale.
1846 EXPECT_FALSE(controller_impl
->HasAnimationThatAffectsScale());
1848 scoped_ptr
<KeyframedTransformAnimationCurve
> curve2(
1849 KeyframedTransformAnimationCurve::Create());
1851 TransformOperations operations2
;
1852 curve2
->AddKeyframe(
1853 TransformKeyframe::Create(base::TimeDelta(), operations2
, nullptr));
1854 operations2
.AppendScale(2.0, 3.0, 4.0);
1855 curve2
->AddKeyframe(TransformKeyframe::Create(
1856 base::TimeDelta::FromSecondsD(1.0), operations2
, nullptr));
1858 animation
= Animation::Create(curve2
.Pass(), 3, 3, Animation::TRANSFORM
);
1859 controller_impl
->AddAnimation(animation
.Pass());
1861 EXPECT_TRUE(controller_impl
->HasAnimationThatAffectsScale());
1863 controller_impl
->GetAnimationById(3)
1864 ->SetRunState(Animation::FINISHED
, TicksFromSecondsF(0.0));
1866 // Only unfinished animations should be considered by
1867 // HasAnimationThatAffectsScale.
1868 EXPECT_FALSE(controller_impl
->HasAnimationThatAffectsScale());
1871 TEST(LayerAnimationControllerTest
, HasOnlyTranslationTransforms
) {
1872 scoped_refptr
<LayerAnimationController
> controller_impl(
1873 LayerAnimationController::Create(0));
1875 EXPECT_TRUE(controller_impl
->HasOnlyTranslationTransforms());
1877 controller_impl
->AddAnimation(CreateAnimation(
1878 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1879 1, Animation::OPACITY
));
1881 // Opacity animations aren't non-translation transforms.
1882 EXPECT_TRUE(controller_impl
->HasOnlyTranslationTransforms());
1884 scoped_ptr
<KeyframedTransformAnimationCurve
> curve1(
1885 KeyframedTransformAnimationCurve::Create());
1887 TransformOperations operations1
;
1888 curve1
->AddKeyframe(
1889 TransformKeyframe::Create(base::TimeDelta(), operations1
, nullptr));
1890 operations1
.AppendTranslate(10.0, 15.0, 0.0);
1891 curve1
->AddKeyframe(TransformKeyframe::Create(
1892 base::TimeDelta::FromSecondsD(1.0), operations1
, nullptr));
1894 scoped_ptr
<Animation
> animation(
1895 Animation::Create(curve1
.Pass(), 2, 2, Animation::TRANSFORM
));
1896 controller_impl
->AddAnimation(animation
.Pass());
1898 // The only transform animation we've added is a translation.
1899 EXPECT_TRUE(controller_impl
->HasOnlyTranslationTransforms());
1901 scoped_ptr
<KeyframedTransformAnimationCurve
> curve2(
1902 KeyframedTransformAnimationCurve::Create());
1904 TransformOperations operations2
;
1905 curve2
->AddKeyframe(
1906 TransformKeyframe::Create(base::TimeDelta(), operations2
, nullptr));
1907 operations2
.AppendScale(2.0, 3.0, 4.0);
1908 curve2
->AddKeyframe(TransformKeyframe::Create(
1909 base::TimeDelta::FromSecondsD(1.0), operations2
, nullptr));
1911 animation
= Animation::Create(curve2
.Pass(), 3, 3, Animation::TRANSFORM
);
1912 controller_impl
->AddAnimation(animation
.Pass());
1914 // A scale animation is not a translation.
1915 EXPECT_FALSE(controller_impl
->HasOnlyTranslationTransforms());
1917 controller_impl
->GetAnimationById(3)
1918 ->SetRunState(Animation::FINISHED
, TicksFromSecondsF(0.0));
1920 // Only unfinished animations should be considered by
1921 // HasOnlyTranslationTransforms.
1922 EXPECT_TRUE(controller_impl
->HasOnlyTranslationTransforms());
1925 TEST(LayerAnimationControllerTest
, AnimationStartScale
) {
1926 scoped_refptr
<LayerAnimationController
> controller_impl(
1927 LayerAnimationController::Create(0));
1928 scoped_ptr
<KeyframedTransformAnimationCurve
> curve1(
1929 KeyframedTransformAnimationCurve::Create());
1931 TransformOperations operations1
;
1932 operations1
.AppendScale(2.0, 3.0, 4.0);
1933 curve1
->AddKeyframe(
1934 TransformKeyframe::Create(base::TimeDelta(), operations1
, nullptr));
1935 TransformOperations operations2
;
1936 curve1
->AddKeyframe(TransformKeyframe::Create(
1937 base::TimeDelta::FromSecondsD(1.0), operations2
, nullptr));
1938 scoped_ptr
<Animation
> animation(
1939 Animation::Create(curve1
.Pass(), 1, 1, Animation::TRANSFORM
));
1940 controller_impl
->AddAnimation(animation
.Pass());
1942 float start_scale
= 0.f
;
1943 EXPECT_TRUE(controller_impl
->AnimationStartScale(&start_scale
));
1944 EXPECT_EQ(4.f
, start_scale
);
1946 scoped_ptr
<KeyframedTransformAnimationCurve
> curve2(
1947 KeyframedTransformAnimationCurve::Create());
1949 TransformOperations operations3
;
1950 curve2
->AddKeyframe(
1951 TransformKeyframe::Create(base::TimeDelta(), operations3
, nullptr));
1952 operations3
.AppendScale(6.0, 5.0, 4.0);
1953 curve2
->AddKeyframe(TransformKeyframe::Create(
1954 base::TimeDelta::FromSecondsD(1.0), operations3
, nullptr));
1956 controller_impl
->RemoveAnimation(1);
1957 animation
= Animation::Create(curve2
.Pass(), 2, 2, Animation::TRANSFORM
);
1959 // Reverse Direction
1960 animation
->set_direction(Animation::DIRECTION_REVERSE
);
1961 controller_impl
->AddAnimation(animation
.Pass());
1963 scoped_ptr
<KeyframedTransformAnimationCurve
> curve3(
1964 KeyframedTransformAnimationCurve::Create());
1966 TransformOperations operations4
;
1967 operations4
.AppendScale(5.0, 3.0, 1.0);
1968 curve3
->AddKeyframe(
1969 TransformKeyframe::Create(base::TimeDelta(), operations4
, nullptr));
1970 TransformOperations operations5
;
1971 curve3
->AddKeyframe(TransformKeyframe::Create(
1972 base::TimeDelta::FromSecondsD(1.0), operations5
, nullptr));
1974 animation
= Animation::Create(curve3
.Pass(), 3, 3, Animation::TRANSFORM
);
1975 controller_impl
->AddAnimation(animation
.Pass());
1977 EXPECT_TRUE(controller_impl
->AnimationStartScale(&start_scale
));
1978 EXPECT_EQ(6.f
, start_scale
);
1980 controller_impl
->GetAnimationById(2)
1981 ->SetRunState(Animation::FINISHED
, TicksFromSecondsF(0.0));
1983 // Only unfinished animations should be considered by
1984 // AnimationStartScale.
1985 EXPECT_TRUE(controller_impl
->AnimationStartScale(&start_scale
));
1986 EXPECT_EQ(5.f
, start_scale
);
1989 TEST(LayerAnimationControllerTest
, MaximumTargetScale
) {
1990 scoped_refptr
<LayerAnimationController
> controller_impl(
1991 LayerAnimationController::Create(0));
1993 float max_scale
= 0.f
;
1994 EXPECT_TRUE(controller_impl
->MaximumTargetScale(&max_scale
));
1995 EXPECT_EQ(0.f
, max_scale
);
1997 scoped_ptr
<KeyframedTransformAnimationCurve
> curve1(
1998 KeyframedTransformAnimationCurve::Create());
2000 TransformOperations operations1
;
2001 curve1
->AddKeyframe(
2002 TransformKeyframe::Create(base::TimeDelta(), operations1
, nullptr));
2003 operations1
.AppendScale(2.0, 3.0, 4.0);
2004 curve1
->AddKeyframe(TransformKeyframe::Create(
2005 base::TimeDelta::FromSecondsD(1.0), operations1
, nullptr));
2007 scoped_ptr
<Animation
> animation(
2008 Animation::Create(curve1
.Pass(), 1, 1, Animation::TRANSFORM
));
2009 controller_impl
->AddAnimation(animation
.Pass());
2011 EXPECT_TRUE(controller_impl
->MaximumTargetScale(&max_scale
));
2012 EXPECT_EQ(4.f
, max_scale
);
2014 scoped_ptr
<KeyframedTransformAnimationCurve
> curve2(
2015 KeyframedTransformAnimationCurve::Create());
2017 TransformOperations operations2
;
2018 curve2
->AddKeyframe(
2019 TransformKeyframe::Create(base::TimeDelta(), operations2
, nullptr));
2020 operations2
.AppendScale(6.0, 5.0, 4.0);
2021 curve2
->AddKeyframe(TransformKeyframe::Create(
2022 base::TimeDelta::FromSecondsD(1.0), operations2
, nullptr));
2024 animation
= Animation::Create(curve2
.Pass(), 2, 2, Animation::TRANSFORM
);
2025 controller_impl
->AddAnimation(animation
.Pass());
2027 EXPECT_TRUE(controller_impl
->MaximumTargetScale(&max_scale
));
2028 EXPECT_EQ(6.f
, max_scale
);
2030 scoped_ptr
<KeyframedTransformAnimationCurve
> curve3(
2031 KeyframedTransformAnimationCurve::Create());
2033 TransformOperations operations3
;
2034 curve3
->AddKeyframe(
2035 TransformKeyframe::Create(base::TimeDelta(), operations3
, nullptr));
2036 operations3
.AppendPerspective(6.0);
2037 curve3
->AddKeyframe(TransformKeyframe::Create(
2038 base::TimeDelta::FromSecondsD(1.0), operations3
, nullptr));
2040 animation
= Animation::Create(curve3
.Pass(), 3, 3, Animation::TRANSFORM
);
2041 controller_impl
->AddAnimation(animation
.Pass());
2043 EXPECT_FALSE(controller_impl
->MaximumTargetScale(&max_scale
));
2045 controller_impl
->GetAnimationById(3)
2046 ->SetRunState(Animation::FINISHED
, TicksFromSecondsF(0.0));
2047 controller_impl
->GetAnimationById(2)
2048 ->SetRunState(Animation::FINISHED
, TicksFromSecondsF(0.0));
2050 // Only unfinished animations should be considered by
2051 // MaximumTargetScale.
2052 EXPECT_TRUE(controller_impl
->MaximumTargetScale(&max_scale
));
2053 EXPECT_EQ(4.f
, max_scale
);
2056 TEST(LayerAnimationControllerTest
, MaximumTargetScaleWithDirection
) {
2057 scoped_refptr
<LayerAnimationController
> controller_impl(
2058 LayerAnimationController::Create(0));
2060 scoped_ptr
<KeyframedTransformAnimationCurve
> curve1(
2061 KeyframedTransformAnimationCurve::Create());
2062 TransformOperations operations1
;
2063 operations1
.AppendScale(1.0, 2.0, 3.0);
2064 curve1
->AddKeyframe(
2065 TransformKeyframe::Create(base::TimeDelta(), operations1
, nullptr));
2066 TransformOperations operations2
;
2067 operations2
.AppendScale(4.0, 5.0, 6.0);
2068 curve1
->AddKeyframe(TransformKeyframe::Create(
2069 base::TimeDelta::FromSecondsD(1.0), operations2
, nullptr));
2071 scoped_ptr
<Animation
> animation_owned(
2072 Animation::Create(curve1
.Pass(), 1, 1, Animation::TRANSFORM
));
2073 Animation
* animation
= animation_owned
.get();
2074 controller_impl
->AddAnimation(animation_owned
.Pass());
2076 float max_scale
= 0.f
;
2078 EXPECT_GT(animation
->playback_rate(), 0.0);
2080 // NORMAL direction with positive playback rate.
2081 animation
->set_direction(Animation::DIRECTION_NORMAL
);
2082 EXPECT_TRUE(controller_impl
->MaximumTargetScale(&max_scale
));
2083 EXPECT_EQ(6.f
, max_scale
);
2085 // ALTERNATE direction with positive playback rate.
2086 animation
->set_direction(Animation::DIRECTION_ALTERNATE
);
2087 EXPECT_TRUE(controller_impl
->MaximumTargetScale(&max_scale
));
2088 EXPECT_EQ(6.f
, max_scale
);
2090 // REVERSE direction with positive playback rate.
2091 animation
->set_direction(Animation::DIRECTION_REVERSE
);
2092 EXPECT_TRUE(controller_impl
->MaximumTargetScale(&max_scale
));
2093 EXPECT_EQ(3.f
, max_scale
);
2095 // ALTERNATE reverse direction.
2096 animation
->set_direction(Animation::DIRECTION_REVERSE
);
2097 EXPECT_TRUE(controller_impl
->MaximumTargetScale(&max_scale
));
2098 EXPECT_EQ(3.f
, max_scale
);
2100 animation
->set_playback_rate(-1.0);
2102 // NORMAL direction with negative playback rate.
2103 animation
->set_direction(Animation::DIRECTION_NORMAL
);
2104 EXPECT_TRUE(controller_impl
->MaximumTargetScale(&max_scale
));
2105 EXPECT_EQ(3.f
, max_scale
);
2107 // ALTERNATE direction with negative playback rate.
2108 animation
->set_direction(Animation::DIRECTION_ALTERNATE
);
2109 EXPECT_TRUE(controller_impl
->MaximumTargetScale(&max_scale
));
2110 EXPECT_EQ(3.f
, max_scale
);
2112 // REVERSE direction with negative playback rate.
2113 animation
->set_direction(Animation::DIRECTION_REVERSE
);
2114 EXPECT_TRUE(controller_impl
->MaximumTargetScale(&max_scale
));
2115 EXPECT_EQ(6.f
, max_scale
);
2117 // ALTERNATE reverse direction with negative playback rate.
2118 animation
->set_direction(Animation::DIRECTION_REVERSE
);
2119 EXPECT_TRUE(controller_impl
->MaximumTargetScale(&max_scale
));
2120 EXPECT_EQ(6.f
, max_scale
);
2123 TEST(LayerAnimationControllerTest
, NewlyPushedAnimationWaitsForActivation
) {
2124 scoped_ptr
<AnimationEventsVector
> events(
2125 make_scoped_ptr(new AnimationEventsVector
));
2126 FakeLayerAnimationValueObserver dummy_impl
;
2127 FakeInactiveLayerAnimationValueObserver pending_dummy_impl
;
2128 scoped_refptr
<LayerAnimationController
> controller_impl(
2129 LayerAnimationController::Create(0));
2130 controller_impl
->AddValueObserver(&dummy_impl
);
2131 controller_impl
->AddValueObserver(&pending_dummy_impl
);
2132 FakeLayerAnimationValueObserver dummy
;
2133 scoped_refptr
<LayerAnimationController
> controller(
2134 LayerAnimationController::Create(0));
2135 controller
->AddValueObserver(&dummy
);
2137 EXPECT_FALSE(controller
->needs_to_start_animations_for_testing());
2139 AddOpacityTransitionToController(controller
.get(), 1, 0.5f
, 1.f
, false);
2140 EXPECT_TRUE(controller
->needs_to_start_animations_for_testing());
2142 EXPECT_FALSE(controller_impl
->needs_to_start_animations_for_testing());
2143 controller
->PushAnimationUpdatesTo(controller_impl
.get());
2144 EXPECT_TRUE(controller_impl
->needs_to_start_animations_for_testing());
2146 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
));
2147 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY
,
2148 controller_impl
->GetAnimationById(animation_id
)->run_state());
2149 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
)
2150 ->affects_pending_observers());
2151 EXPECT_FALSE(controller_impl
->GetAnimationById(animation_id
)
2152 ->affects_active_observers());
2154 controller_impl
->Animate(kInitialTickTime
);
2155 EXPECT_FALSE(controller_impl
->needs_to_start_animations_for_testing());
2156 controller_impl
->UpdateState(true, events
.get());
2158 // Since the animation hasn't been activated, it should still be STARTING
2159 // rather than RUNNING.
2160 EXPECT_EQ(Animation::STARTING
,
2161 controller_impl
->GetAnimationById(animation_id
)->run_state());
2163 // Since the animation hasn't been activated, only the pending observer
2164 // should have been ticked.
2165 EXPECT_EQ(0.5f
, pending_dummy_impl
.opacity());
2166 EXPECT_EQ(0.f
, dummy_impl
.opacity());
2168 controller_impl
->ActivateAnimations();
2169 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
)
2170 ->affects_pending_observers());
2171 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
)
2172 ->affects_active_observers());
2174 controller_impl
->Animate(kInitialTickTime
+
2175 TimeDelta::FromMilliseconds(1000));
2176 controller_impl
->UpdateState(true, events
.get());
2178 // Since the animation has been activated, it should have reached the
2179 // RUNNING state and the active observer should start to get ticked.
2180 EXPECT_EQ(Animation::RUNNING
,
2181 controller_impl
->GetAnimationById(animation_id
)->run_state());
2182 EXPECT_EQ(0.5f
, pending_dummy_impl
.opacity());
2183 EXPECT_EQ(0.5f
, dummy_impl
.opacity());
2186 TEST(LayerAnimationControllerTest
, ActivationBetweenAnimateAndUpdateState
) {
2187 scoped_ptr
<AnimationEventsVector
> events(
2188 make_scoped_ptr(new AnimationEventsVector
));
2189 FakeLayerAnimationValueObserver dummy_impl
;
2190 FakeInactiveLayerAnimationValueObserver pending_dummy_impl
;
2191 scoped_refptr
<LayerAnimationController
> controller_impl(
2192 LayerAnimationController::Create(0));
2193 controller_impl
->AddValueObserver(&dummy_impl
);
2194 controller_impl
->AddValueObserver(&pending_dummy_impl
);
2195 FakeLayerAnimationValueObserver dummy
;
2196 scoped_refptr
<LayerAnimationController
> controller(
2197 LayerAnimationController::Create(0));
2198 controller
->AddValueObserver(&dummy
);
2201 AddOpacityTransitionToController(controller
.get(), 1, 0.5f
, 1.f
, true);
2203 controller
->PushAnimationUpdatesTo(controller_impl
.get());
2205 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
));
2206 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY
,
2207 controller_impl
->GetAnimationById(animation_id
)->run_state());
2208 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
)
2209 ->affects_pending_observers());
2210 EXPECT_FALSE(controller_impl
->GetAnimationById(animation_id
)
2211 ->affects_active_observers());
2213 controller_impl
->Animate(kInitialTickTime
);
2215 // Since the animation hasn't been activated, only the pending observer
2216 // should have been ticked.
2217 EXPECT_EQ(0.5f
, pending_dummy_impl
.opacity());
2218 EXPECT_EQ(0.f
, dummy_impl
.opacity());
2220 controller_impl
->ActivateAnimations();
2221 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
)
2222 ->affects_pending_observers());
2223 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
)
2224 ->affects_active_observers());
2226 controller_impl
->UpdateState(true, events
.get());
2228 // Since the animation has been activated, it should have reached the
2230 EXPECT_EQ(Animation::RUNNING
,
2231 controller_impl
->GetAnimationById(animation_id
)->run_state());
2233 controller_impl
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(500));
2235 // Both observers should have been ticked.
2236 EXPECT_EQ(0.75f
, pending_dummy_impl
.opacity());
2237 EXPECT_EQ(0.75f
, dummy_impl
.opacity());
2240 TEST(LayerAnimationControllerTest
, ClippedOpacityValues
) {
2241 FakeLayerAnimationValueObserver dummy
;
2242 scoped_refptr
<LayerAnimationController
> controller(
2243 LayerAnimationController::Create(0));
2244 controller
->AddValueObserver(&dummy
);
2246 AddOpacityTransitionToController(controller
.get(), 1, 1.f
, 2.f
, true);
2248 controller
->Animate(kInitialTickTime
);
2249 EXPECT_EQ(1.f
, dummy
.opacity());
2251 // Opacity values are clipped [0,1]
2252 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1000));
2253 EXPECT_EQ(1.f
, dummy
.opacity());
2256 TEST(LayerAnimationControllerTest
, ClippedNegativeOpacityValues
) {
2257 FakeLayerAnimationValueObserver dummy
;
2258 scoped_refptr
<LayerAnimationController
> controller(
2259 LayerAnimationController::Create(0));
2260 controller
->AddValueObserver(&dummy
);
2262 AddOpacityTransitionToController(controller
.get(), 1, 0.f
, -2.f
, true);
2264 controller
->Animate(kInitialTickTime
);
2265 EXPECT_EQ(0.f
, dummy
.opacity());
2267 // Opacity values are clipped [0,1]
2268 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1000));
2269 EXPECT_EQ(0.f
, dummy
.opacity());
2272 TEST(LayerAnimationControllerTest
, PushedDeletedAnimationWaitsForActivation
) {
2273 scoped_ptr
<AnimationEventsVector
> events(
2274 make_scoped_ptr(new AnimationEventsVector
));
2275 FakeLayerAnimationValueObserver dummy_impl
;
2276 FakeInactiveLayerAnimationValueObserver pending_dummy_impl
;
2277 scoped_refptr
<LayerAnimationController
> controller_impl(
2278 LayerAnimationController::Create(0));
2279 controller_impl
->AddValueObserver(&dummy_impl
);
2280 controller_impl
->AddValueObserver(&pending_dummy_impl
);
2281 FakeLayerAnimationValueObserver dummy
;
2282 scoped_refptr
<LayerAnimationController
> controller(
2283 LayerAnimationController::Create(0));
2284 controller
->AddValueObserver(&dummy
);
2287 AddOpacityTransitionToController(controller
.get(), 1, 0.5f
, 1.f
, true);
2289 controller
->PushAnimationUpdatesTo(controller_impl
.get());
2290 controller_impl
->ActivateAnimations();
2291 controller_impl
->Animate(kInitialTickTime
);
2292 controller_impl
->UpdateState(true, events
.get());
2293 EXPECT_EQ(Animation::RUNNING
,
2294 controller_impl
->GetAnimationById(animation_id
)->run_state());
2295 EXPECT_EQ(0.5f
, pending_dummy_impl
.opacity());
2296 EXPECT_EQ(0.5f
, dummy_impl
.opacity());
2298 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
)
2299 ->affects_pending_observers());
2300 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
)
2301 ->affects_active_observers());
2303 // Delete the animation on the main-thread controller.
2304 controller
->RemoveAnimation(
2305 controller
->GetAnimation(Animation::OPACITY
)->id());
2306 controller
->PushAnimationUpdatesTo(controller_impl
.get());
2308 // The animation should no longer affect pending observers.
2309 EXPECT_FALSE(controller_impl
->GetAnimationById(animation_id
)
2310 ->affects_pending_observers());
2311 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
)
2312 ->affects_active_observers());
2314 controller_impl
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(500));
2315 controller_impl
->UpdateState(true, events
.get());
2317 // Only the active observer should have been ticked.
2318 EXPECT_EQ(0.5f
, pending_dummy_impl
.opacity());
2319 EXPECT_EQ(0.75f
, dummy_impl
.opacity());
2321 controller_impl
->ActivateAnimations();
2323 // Activation should cause the animation to be deleted.
2324 EXPECT_FALSE(controller_impl
->has_any_animation());
2327 // Tests that an animation that affects only active observers won't block
2328 // an animation that affects only pending observers from starting.
2329 TEST(LayerAnimationControllerTest
, StartAnimationsAffectingDifferentObservers
) {
2330 scoped_ptr
<AnimationEventsVector
> events(
2331 make_scoped_ptr(new AnimationEventsVector
));
2332 FakeLayerAnimationValueObserver dummy_impl
;
2333 FakeInactiveLayerAnimationValueObserver pending_dummy_impl
;
2334 scoped_refptr
<LayerAnimationController
> controller_impl(
2335 LayerAnimationController::Create(0));
2336 controller_impl
->AddValueObserver(&dummy_impl
);
2337 controller_impl
->AddValueObserver(&pending_dummy_impl
);
2338 FakeLayerAnimationValueObserver dummy
;
2339 scoped_refptr
<LayerAnimationController
> controller(
2340 LayerAnimationController::Create(0));
2341 controller
->AddValueObserver(&dummy
);
2343 int first_animation_id
=
2344 AddOpacityTransitionToController(controller
.get(), 1, 0.f
, 1.f
, true);
2346 controller
->PushAnimationUpdatesTo(controller_impl
.get());
2347 controller_impl
->ActivateAnimations();
2348 controller_impl
->Animate(kInitialTickTime
);
2349 controller_impl
->UpdateState(true, events
.get());
2351 // Remove the first animation from the main-thread controller, and add a
2352 // new animation affecting the same property.
2353 controller
->RemoveAnimation(
2354 controller
->GetAnimation(Animation::OPACITY
)->id());
2355 int second_animation_id
=
2356 AddOpacityTransitionToController(controller
.get(), 1, 1.f
, 0.5f
, true);
2357 controller
->PushAnimationUpdatesTo(controller_impl
.get());
2359 // The original animation should only affect active observers, and the new
2360 // animation should only affect pending observers.
2361 EXPECT_FALSE(controller_impl
->GetAnimationById(first_animation_id
)
2362 ->affects_pending_observers());
2363 EXPECT_TRUE(controller_impl
->GetAnimationById(first_animation_id
)
2364 ->affects_active_observers());
2365 EXPECT_TRUE(controller_impl
->GetAnimationById(second_animation_id
)
2366 ->affects_pending_observers());
2367 EXPECT_FALSE(controller_impl
->GetAnimationById(second_animation_id
)
2368 ->affects_active_observers());
2370 controller_impl
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(500));
2371 controller_impl
->UpdateState(true, events
.get());
2373 // The original animation should still be running, and the new animation
2374 // should be starting.
2375 EXPECT_EQ(Animation::RUNNING
,
2376 controller_impl
->GetAnimationById(first_animation_id
)->run_state());
2378 Animation::STARTING
,
2379 controller_impl
->GetAnimationById(second_animation_id
)->run_state());
2381 // The active observer should have been ticked by the original animation,
2382 // and the pending observer should have been ticked by the new animation.
2383 EXPECT_EQ(1.f
, pending_dummy_impl
.opacity());
2384 EXPECT_EQ(0.5f
, dummy_impl
.opacity());
2386 controller_impl
->ActivateAnimations();
2388 // The original animation should have been deleted, and the new animation
2389 // should now affect both observers.
2390 EXPECT_FALSE(controller_impl
->GetAnimationById(first_animation_id
));
2391 EXPECT_TRUE(controller_impl
->GetAnimationById(second_animation_id
)
2392 ->affects_pending_observers());
2393 EXPECT_TRUE(controller_impl
->GetAnimationById(second_animation_id
)
2394 ->affects_active_observers());
2396 controller_impl
->Animate(kInitialTickTime
+
2397 TimeDelta::FromMilliseconds(1000));
2398 controller_impl
->UpdateState(true, events
.get());
2400 // The new animation should be running, and the active observer should have
2401 // been ticked at the new animation's starting point.
2404 controller_impl
->GetAnimationById(second_animation_id
)->run_state());
2405 EXPECT_EQ(1.f
, pending_dummy_impl
.opacity());
2406 EXPECT_EQ(1.f
, dummy_impl
.opacity());
2409 TEST(LayerAnimationControllerTest
, TestIsAnimatingProperty
) {
2410 FakeLayerAnimationValueObserver dummy
;
2411 scoped_refptr
<LayerAnimationController
> controller(
2412 LayerAnimationController::Create(0));
2413 controller
->AddValueObserver(&dummy
);
2415 scoped_ptr
<Animation
> animation(CreateAnimation(
2416 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
2417 1, Animation::OPACITY
));
2418 controller
->AddAnimation(animation
.Pass());
2419 controller
->Animate(kInitialTickTime
);
2420 EXPECT_TRUE(controller
->IsAnimatingProperty(Animation::OPACITY
));
2421 controller
->UpdateState(true, nullptr);
2422 EXPECT_TRUE(controller
->HasActiveAnimation());
2423 EXPECT_TRUE(controller
->IsAnimatingProperty(Animation::OPACITY
));
2424 EXPECT_FALSE(controller
->IsAnimatingProperty(Animation::FILTER
));
2425 EXPECT_EQ(0.f
, dummy
.opacity());
2428 TEST(LayerAnimationControllerTest
, TestIsAnimatingPropertyTimeOffsetFillMode
) {
2429 FakeLayerAnimationValueObserver dummy
;
2430 scoped_refptr
<LayerAnimationController
> controller(
2431 LayerAnimationController::Create(0));
2432 controller
->AddValueObserver(&dummy
);
2434 scoped_ptr
<Animation
> animation(CreateAnimation(
2435 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
2436 1, Animation::OPACITY
));
2437 animation
->set_fill_mode(Animation::FILL_MODE_NONE
);
2438 animation
->set_time_offset(TimeDelta::FromMilliseconds(-2000));
2439 controller
->AddAnimation(animation
.Pass());
2441 controller
->Animate(kInitialTickTime
);
2442 controller
->UpdateState(true, nullptr);
2443 EXPECT_FALSE(controller
->IsAnimatingProperty(Animation::OPACITY
));
2444 EXPECT_TRUE(controller
->HasActiveAnimation());
2445 EXPECT_FALSE(controller
->IsAnimatingProperty(Animation::OPACITY
));
2446 EXPECT_FALSE(controller
->IsAnimatingProperty(Animation::FILTER
));
2448 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(2000));
2449 controller
->UpdateState(true, nullptr);
2450 EXPECT_TRUE(controller
->IsAnimatingProperty(Animation::OPACITY
));