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().size());
175 EXPECT_EQ(1u, registrar_impl
->all_animation_controllers().size());
177 // Initially, both controllers should be inactive.
178 EXPECT_EQ(0u, registrar
->active_animation_controllers().size());
179 EXPECT_EQ(0u, registrar_impl
->active_animation_controllers().size());
181 AddOpacityTransitionToController(controller
.get(), 1, 0, 1, false);
182 // The main thread controller should now be active.
183 EXPECT_EQ(1u, registrar
->active_animation_controllers().size());
185 controller
->PushAnimationUpdatesTo(controller_impl
.get());
186 controller_impl
->ActivateAnimations();
187 // Both controllers should now be active.
188 EXPECT_EQ(1u, registrar
->active_animation_controllers().size());
189 EXPECT_EQ(1u, registrar_impl
->active_animation_controllers().size());
191 controller_impl
->Animate(kInitialTickTime
);
192 controller_impl
->UpdateState(true, events
.get());
193 EXPECT_EQ(1u, events
->size());
194 controller
->NotifyAnimationStarted((*events
)[0]);
196 EXPECT_EQ(1u, registrar
->active_animation_controllers().size());
197 EXPECT_EQ(1u, registrar_impl
->active_animation_controllers().size());
199 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(500));
200 controller
->UpdateState(true, nullptr);
201 EXPECT_EQ(1u, registrar
->active_animation_controllers().size());
203 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1000));
204 controller
->UpdateState(true, nullptr);
205 EXPECT_EQ(Animation::FINISHED
,
206 controller
->GetAnimation(Animation::OPACITY
)->run_state());
207 EXPECT_EQ(1u, registrar
->active_animation_controllers().size());
209 events
.reset(new AnimationEventsVector
);
210 controller_impl
->Animate(kInitialTickTime
+
211 TimeDelta::FromMilliseconds(1500));
212 controller_impl
->UpdateState(true, events
.get());
214 EXPECT_EQ(Animation::WAITING_FOR_DELETION
,
215 controller_impl
->GetAnimation(Animation::OPACITY
)->run_state());
216 // The impl thread controller should have de-activated.
217 EXPECT_EQ(0u, registrar_impl
->active_animation_controllers().size());
219 EXPECT_EQ(1u, events
->size());
220 controller
->NotifyAnimationFinished((*events
)[0]);
221 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1500));
222 controller
->UpdateState(true, nullptr);
224 EXPECT_EQ(Animation::WAITING_FOR_DELETION
,
225 controller
->GetAnimation(Animation::OPACITY
)->run_state());
226 // The main thread controller should have de-activated.
227 EXPECT_EQ(0u, registrar
->active_animation_controllers().size());
229 controller
->PushAnimationUpdatesTo(controller_impl
.get());
230 controller_impl
->ActivateAnimations();
231 EXPECT_FALSE(controller
->has_any_animation());
232 EXPECT_FALSE(controller_impl
->has_any_animation());
233 EXPECT_EQ(0u, registrar
->active_animation_controllers().size());
234 EXPECT_EQ(0u, registrar_impl
->active_animation_controllers().size());
236 controller
->SetAnimationRegistrar(nullptr);
237 controller_impl
->SetAnimationRegistrar(nullptr);
240 TEST(LayerAnimationControllerTest
, SyncPause
) {
241 FakeLayerAnimationValueObserver dummy_impl
;
242 scoped_refptr
<LayerAnimationController
> controller_impl(
243 LayerAnimationController::Create(0));
244 controller_impl
->AddValueObserver(&dummy_impl
);
245 FakeLayerAnimationValueObserver dummy
;
246 scoped_refptr
<LayerAnimationController
> controller(
247 LayerAnimationController::Create(0));
248 controller
->AddValueObserver(&dummy
);
250 EXPECT_FALSE(controller_impl
->GetAnimation(Animation::OPACITY
));
253 AddOpacityTransitionToController(controller
.get(), 1, 0, 1, false);
255 controller
->PushAnimationUpdatesTo(controller_impl
.get());
256 controller_impl
->ActivateAnimations();
258 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
));
259 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY
,
260 controller_impl
->GetAnimationById(animation_id
)->run_state());
262 // Start the animations on each controller.
263 AnimationEventsVector events
;
264 controller_impl
->Animate(kInitialTickTime
);
265 controller_impl
->UpdateState(true, &events
);
266 controller
->Animate(kInitialTickTime
);
267 controller
->UpdateState(true, nullptr);
268 EXPECT_EQ(Animation::RUNNING
,
269 controller_impl
->GetAnimationById(animation_id
)->run_state());
270 EXPECT_EQ(Animation::RUNNING
,
271 controller
->GetAnimationById(animation_id
)->run_state());
273 // Pause the main-thread animation.
274 controller
->PauseAnimation(
276 TimeDelta::FromMilliseconds(1000) + TimeDelta::FromMilliseconds(1000));
277 EXPECT_EQ(Animation::PAUSED
,
278 controller
->GetAnimationById(animation_id
)->run_state());
280 // The pause run state change should make it to the impl thread controller.
281 controller
->PushAnimationUpdatesTo(controller_impl
.get());
282 controller_impl
->ActivateAnimations();
283 EXPECT_EQ(Animation::PAUSED
,
284 controller_impl
->GetAnimationById(animation_id
)->run_state());
287 TEST(LayerAnimationControllerTest
, DoNotSyncFinishedAnimation
) {
288 FakeLayerAnimationValueObserver dummy_impl
;
289 scoped_refptr
<LayerAnimationController
> controller_impl(
290 LayerAnimationController::Create(0));
291 controller_impl
->AddValueObserver(&dummy_impl
);
292 FakeLayerAnimationValueObserver dummy
;
293 scoped_refptr
<LayerAnimationController
> controller(
294 LayerAnimationController::Create(0));
295 controller
->AddValueObserver(&dummy
);
297 EXPECT_FALSE(controller_impl
->GetAnimation(Animation::OPACITY
));
300 AddOpacityTransitionToController(controller
.get(), 1, 0, 1, false);
301 int group_id
= controller
->GetAnimationById(animation_id
)->group();
303 controller
->PushAnimationUpdatesTo(controller_impl
.get());
304 controller_impl
->ActivateAnimations();
306 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
));
307 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY
,
308 controller_impl
->GetAnimationById(animation_id
)->run_state());
310 // Notify main thread controller that the animation has started.
311 AnimationEvent
animation_started_event(AnimationEvent::STARTED
, 0, group_id
,
312 Animation::OPACITY
, kInitialTickTime
);
313 controller
->NotifyAnimationStarted(animation_started_event
);
315 // Force animation to complete on impl thread.
316 controller_impl
->RemoveAnimation(animation_id
);
318 EXPECT_FALSE(controller_impl
->GetAnimationById(animation_id
));
320 controller
->PushAnimationUpdatesTo(controller_impl
.get());
321 controller_impl
->ActivateAnimations();
323 // Even though the main thread has a 'new' animation, it should not be pushed
324 // because the animation has already completed on the impl thread.
325 EXPECT_FALSE(controller_impl
->GetAnimationById(animation_id
));
328 // Ensure that a finished animation is eventually deleted by both the
329 // main-thread and the impl-thread controllers.
330 TEST(LayerAnimationControllerTest
, AnimationsAreDeleted
) {
331 FakeLayerAnimationValueObserver dummy
;
332 FakeLayerAnimationValueObserver dummy_impl
;
333 scoped_ptr
<AnimationEventsVector
> events(
334 make_scoped_ptr(new AnimationEventsVector
));
335 scoped_refptr
<LayerAnimationController
> controller(
336 LayerAnimationController::Create(0));
337 scoped_refptr
<LayerAnimationController
> controller_impl(
338 LayerAnimationController::Create(0));
339 controller
->AddValueObserver(&dummy
);
340 controller_impl
->AddValueObserver(&dummy_impl
);
342 AddOpacityTransitionToController(controller
.get(), 1.0, 0.0f
, 1.0f
, false);
343 controller
->Animate(kInitialTickTime
);
344 controller
->UpdateState(true, nullptr);
345 controller
->PushAnimationUpdatesTo(controller_impl
.get());
346 controller_impl
->ActivateAnimations();
348 controller_impl
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(500));
349 controller_impl
->UpdateState(true, events
.get());
351 // There should be a STARTED event for the animation.
352 EXPECT_EQ(1u, events
->size());
353 EXPECT_EQ(AnimationEvent::STARTED
, (*events
)[0].type
);
354 controller
->NotifyAnimationStarted((*events
)[0]);
356 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1000));
357 controller
->UpdateState(true, nullptr);
359 EXPECT_FALSE(dummy
.animation_waiting_for_deletion());
360 EXPECT_FALSE(dummy_impl
.animation_waiting_for_deletion());
362 events
.reset(new AnimationEventsVector
);
363 controller_impl
->Animate(kInitialTickTime
+
364 TimeDelta::FromMilliseconds(2000));
365 controller_impl
->UpdateState(true, events
.get());
367 EXPECT_TRUE(dummy_impl
.animation_waiting_for_deletion());
369 // There should be a FINISHED event for the animation.
370 EXPECT_EQ(1u, events
->size());
371 EXPECT_EQ(AnimationEvent::FINISHED
, (*events
)[0].type
);
373 // Neither controller should have deleted the animation yet.
374 EXPECT_TRUE(controller
->GetAnimation(Animation::OPACITY
));
375 EXPECT_TRUE(controller_impl
->GetAnimation(Animation::OPACITY
));
377 controller
->NotifyAnimationFinished((*events
)[0]);
379 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(3000));
380 controller
->UpdateState(true, nullptr);
381 EXPECT_TRUE(dummy
.animation_waiting_for_deletion());
383 controller
->PushAnimationUpdatesTo(controller_impl
.get());
385 // Both controllers should now have deleted the animation. The impl controller
386 // should have deleted the animation even though activation has not occurred,
387 // since the animation was already waiting for deletion when
388 // PushAnimationUpdatesTo was called.
389 EXPECT_FALSE(controller
->has_any_animation());
390 EXPECT_FALSE(controller_impl
->has_any_animation());
393 // Tests that transitioning opacity from 0 to 1 works as expected.
395 static const AnimationEvent
* GetMostRecentPropertyUpdateEvent(
396 const AnimationEventsVector
* events
) {
397 const AnimationEvent
* event
= 0;
398 for (size_t i
= 0; i
< events
->size(); ++i
)
399 if ((*events
)[i
].type
== AnimationEvent::PROPERTY_UPDATE
)
400 event
= &(*events
)[i
];
405 TEST(LayerAnimationControllerTest
, TrivialTransition
) {
406 scoped_ptr
<AnimationEventsVector
> events(
407 make_scoped_ptr(new AnimationEventsVector
));
408 FakeLayerAnimationValueObserver dummy
;
409 scoped_refptr
<LayerAnimationController
> controller(
410 LayerAnimationController::Create(0));
411 controller
->AddValueObserver(&dummy
);
413 scoped_ptr
<Animation
> to_add(CreateAnimation(
414 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
415 1, Animation::OPACITY
));
417 EXPECT_FALSE(controller
->needs_to_start_animations_for_testing());
418 controller
->AddAnimation(to_add
.Pass());
419 EXPECT_TRUE(controller
->needs_to_start_animations_for_testing());
420 controller
->Animate(kInitialTickTime
);
421 EXPECT_FALSE(controller
->needs_to_start_animations_for_testing());
422 controller
->UpdateState(true, events
.get());
423 EXPECT_TRUE(controller
->HasActiveAnimation());
424 EXPECT_EQ(0.f
, dummy
.opacity());
425 // A non-impl-only animation should not generate property updates.
426 const AnimationEvent
* event
= GetMostRecentPropertyUpdateEvent(events
.get());
428 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1000));
429 controller
->UpdateState(true, events
.get());
430 EXPECT_EQ(1.f
, dummy
.opacity());
431 EXPECT_FALSE(controller
->HasActiveAnimation());
432 event
= GetMostRecentPropertyUpdateEvent(events
.get());
436 TEST(LayerAnimationControllerTest
, TrivialTransitionOnImpl
) {
437 scoped_ptr
<AnimationEventsVector
> events(
438 make_scoped_ptr(new AnimationEventsVector
));
439 FakeLayerAnimationValueObserver dummy_impl
;
440 scoped_refptr
<LayerAnimationController
> controller_impl(
441 LayerAnimationController::Create(0));
442 controller_impl
->AddValueObserver(&dummy_impl
);
444 scoped_ptr
<Animation
> to_add(CreateAnimation(
445 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
446 1, Animation::OPACITY
));
447 to_add
->set_is_impl_only(true);
449 controller_impl
->AddAnimation(to_add
.Pass());
450 controller_impl
->Animate(kInitialTickTime
);
451 controller_impl
->UpdateState(true, events
.get());
452 EXPECT_TRUE(controller_impl
->HasActiveAnimation());
453 EXPECT_EQ(0.f
, dummy_impl
.opacity());
454 EXPECT_EQ(1u, events
->size());
455 const AnimationEvent
* start_opacity_event
=
456 GetMostRecentPropertyUpdateEvent(events
.get());
457 EXPECT_EQ(0.f
, start_opacity_event
->opacity
);
459 controller_impl
->Animate(kInitialTickTime
+
460 TimeDelta::FromMilliseconds(1000));
461 controller_impl
->UpdateState(true, events
.get());
462 EXPECT_EQ(1.f
, dummy_impl
.opacity());
463 EXPECT_FALSE(controller_impl
->HasActiveAnimation());
464 EXPECT_EQ(2u, events
->size());
465 const AnimationEvent
* end_opacity_event
=
466 GetMostRecentPropertyUpdateEvent(events
.get());
467 EXPECT_EQ(1.f
, end_opacity_event
->opacity
);
470 TEST(LayerAnimationControllerTest
, TrivialTransformOnImpl
) {
471 scoped_ptr
<AnimationEventsVector
> events(
472 make_scoped_ptr(new AnimationEventsVector
));
473 FakeLayerAnimationValueObserver dummy_impl
;
474 scoped_refptr
<LayerAnimationController
> controller_impl(
475 LayerAnimationController::Create(0));
476 controller_impl
->AddValueObserver(&dummy_impl
);
478 // Choose different values for x and y to avoid coincidental values in the
479 // observed transforms.
480 const float delta_x
= 3;
481 const float delta_y
= 4;
483 scoped_ptr
<KeyframedTransformAnimationCurve
> curve(
484 KeyframedTransformAnimationCurve::Create());
486 // Create simple TRANSFORM animation.
487 TransformOperations operations
;
489 TransformKeyframe::Create(base::TimeDelta(), operations
, nullptr));
490 operations
.AppendTranslate(delta_x
, delta_y
, 0);
491 curve
->AddKeyframe(TransformKeyframe::Create(
492 base::TimeDelta::FromSecondsD(1.0), operations
, nullptr));
494 scoped_ptr
<Animation
> animation(
495 Animation::Create(curve
.Pass(), 1, 0, Animation::TRANSFORM
));
496 animation
->set_is_impl_only(true);
497 controller_impl
->AddAnimation(animation
.Pass());
500 controller_impl
->Animate(kInitialTickTime
);
501 controller_impl
->UpdateState(true, events
.get());
502 EXPECT_TRUE(controller_impl
->HasActiveAnimation());
503 EXPECT_EQ(gfx::Transform(), dummy_impl
.transform());
504 EXPECT_EQ(1u, events
->size());
505 const AnimationEvent
* start_transform_event
=
506 GetMostRecentPropertyUpdateEvent(events
.get());
507 ASSERT_TRUE(start_transform_event
);
508 EXPECT_EQ(gfx::Transform(), start_transform_event
->transform
);
509 EXPECT_TRUE(start_transform_event
->is_impl_only
);
511 gfx::Transform expected_transform
;
512 expected_transform
.Translate(delta_x
, delta_y
);
514 controller_impl
->Animate(kInitialTickTime
+
515 TimeDelta::FromMilliseconds(1000));
516 controller_impl
->UpdateState(true, events
.get());
517 EXPECT_EQ(expected_transform
, dummy_impl
.transform());
518 EXPECT_FALSE(controller_impl
->HasActiveAnimation());
519 EXPECT_EQ(2u, events
->size());
520 const AnimationEvent
* end_transform_event
=
521 GetMostRecentPropertyUpdateEvent(events
.get());
522 EXPECT_EQ(expected_transform
, end_transform_event
->transform
);
523 EXPECT_TRUE(end_transform_event
->is_impl_only
);
526 TEST(LayerAnimationControllerTest
, FilterTransition
) {
527 scoped_ptr
<AnimationEventsVector
> events(
528 make_scoped_ptr(new AnimationEventsVector
));
529 FakeLayerAnimationValueObserver dummy
;
530 scoped_refptr
<LayerAnimationController
> controller(
531 LayerAnimationController::Create(0));
532 controller
->AddValueObserver(&dummy
);
534 scoped_ptr
<KeyframedFilterAnimationCurve
> curve(
535 KeyframedFilterAnimationCurve::Create());
537 FilterOperations start_filters
;
538 start_filters
.Append(FilterOperation::CreateBrightnessFilter(1.f
));
540 FilterKeyframe::Create(base::TimeDelta(), start_filters
, nullptr));
541 FilterOperations end_filters
;
542 end_filters
.Append(FilterOperation::CreateBrightnessFilter(2.f
));
543 curve
->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
544 end_filters
, nullptr));
546 scoped_ptr
<Animation
> animation(
547 Animation::Create(curve
.Pass(), 1, 0, Animation::FILTER
));
548 controller
->AddAnimation(animation
.Pass());
550 controller
->Animate(kInitialTickTime
);
551 controller
->UpdateState(true, events
.get());
552 EXPECT_TRUE(controller
->HasActiveAnimation());
553 EXPECT_EQ(start_filters
, dummy
.filters());
554 // A non-impl-only animation should not generate property updates.
555 const AnimationEvent
* event
= GetMostRecentPropertyUpdateEvent(events
.get());
558 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(500));
559 controller
->UpdateState(true, events
.get());
560 EXPECT_EQ(1u, dummy
.filters().size());
561 EXPECT_EQ(FilterOperation::CreateBrightnessFilter(1.5f
),
562 dummy
.filters().at(0));
563 event
= GetMostRecentPropertyUpdateEvent(events
.get());
566 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1000));
567 controller
->UpdateState(true, events
.get());
568 EXPECT_EQ(end_filters
, dummy
.filters());
569 EXPECT_FALSE(controller
->HasActiveAnimation());
570 event
= GetMostRecentPropertyUpdateEvent(events
.get());
574 TEST(LayerAnimationControllerTest
, FilterTransitionOnImplOnly
) {
575 scoped_ptr
<AnimationEventsVector
> events(
576 make_scoped_ptr(new AnimationEventsVector
));
577 FakeLayerAnimationValueObserver dummy_impl
;
578 scoped_refptr
<LayerAnimationController
> controller_impl(
579 LayerAnimationController::Create(0));
580 controller_impl
->AddValueObserver(&dummy_impl
);
582 scoped_ptr
<KeyframedFilterAnimationCurve
> curve(
583 KeyframedFilterAnimationCurve::Create());
585 // Create simple FILTER animation.
586 FilterOperations start_filters
;
587 start_filters
.Append(FilterOperation::CreateBrightnessFilter(1.f
));
589 FilterKeyframe::Create(base::TimeDelta(), start_filters
, nullptr));
590 FilterOperations end_filters
;
591 end_filters
.Append(FilterOperation::CreateBrightnessFilter(2.f
));
592 curve
->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
593 end_filters
, nullptr));
595 scoped_ptr
<Animation
> animation(
596 Animation::Create(curve
.Pass(), 1, 0, Animation::FILTER
));
597 animation
->set_is_impl_only(true);
598 controller_impl
->AddAnimation(animation
.Pass());
601 controller_impl
->Animate(kInitialTickTime
);
602 controller_impl
->UpdateState(true, events
.get());
603 EXPECT_TRUE(controller_impl
->HasActiveAnimation());
604 EXPECT_EQ(start_filters
, dummy_impl
.filters());
605 EXPECT_EQ(1u, events
->size());
606 const AnimationEvent
* start_filter_event
=
607 GetMostRecentPropertyUpdateEvent(events
.get());
608 EXPECT_TRUE(start_filter_event
);
609 EXPECT_EQ(start_filters
, start_filter_event
->filters
);
610 EXPECT_TRUE(start_filter_event
->is_impl_only
);
612 controller_impl
->Animate(kInitialTickTime
+
613 TimeDelta::FromMilliseconds(1000));
614 controller_impl
->UpdateState(true, events
.get());
615 EXPECT_EQ(end_filters
, dummy_impl
.filters());
616 EXPECT_FALSE(controller_impl
->HasActiveAnimation());
617 EXPECT_EQ(2u, events
->size());
618 const AnimationEvent
* end_filter_event
=
619 GetMostRecentPropertyUpdateEvent(events
.get());
620 EXPECT_TRUE(end_filter_event
);
621 EXPECT_EQ(end_filters
, end_filter_event
->filters
);
622 EXPECT_TRUE(end_filter_event
->is_impl_only
);
625 TEST(LayerAnimationControllerTest
, ScrollOffsetTransition
) {
626 FakeLayerAnimationValueObserver dummy_impl
;
627 FakeLayerAnimationValueProvider dummy_provider_impl
;
628 scoped_refptr
<LayerAnimationController
> controller_impl(
629 LayerAnimationController::Create(0));
630 controller_impl
->AddValueObserver(&dummy_impl
);
631 controller_impl
->set_value_provider(&dummy_provider_impl
);
632 scoped_ptr
<AnimationEventsVector
> events(
633 make_scoped_ptr(new AnimationEventsVector
));
634 FakeLayerAnimationValueObserver dummy
;
635 FakeLayerAnimationValueProvider dummy_provider
;
636 scoped_refptr
<LayerAnimationController
> controller(
637 LayerAnimationController::Create(0));
638 controller
->AddValueObserver(&dummy
);
639 controller
->set_value_provider(&dummy_provider
);
641 gfx::ScrollOffset
initial_value(100.f
, 300.f
);
642 gfx::ScrollOffset
target_value(300.f
, 200.f
);
643 scoped_ptr
<ScrollOffsetAnimationCurve
> curve(
644 ScrollOffsetAnimationCurve::Create(
646 EaseInOutTimingFunction::Create().Pass()));
648 scoped_ptr
<Animation
> animation(
649 Animation::Create(curve
.Pass(), 1, 0, Animation::SCROLL_OFFSET
));
650 animation
->set_needs_synchronized_start_time(true);
651 controller
->AddAnimation(animation
.Pass());
653 dummy_provider_impl
.set_scroll_offset(initial_value
);
654 controller
->PushAnimationUpdatesTo(controller_impl
.get());
655 controller_impl
->ActivateAnimations();
656 EXPECT_TRUE(controller_impl
->GetAnimation(Animation::SCROLL_OFFSET
));
657 TimeDelta duration
= controller_impl
->GetAnimation(Animation::SCROLL_OFFSET
)
662 controller
->GetAnimation(Animation::SCROLL_OFFSET
)->curve()->Duration());
664 controller
->Animate(kInitialTickTime
);
665 controller
->UpdateState(true, nullptr);
666 EXPECT_TRUE(controller
->HasActiveAnimation());
667 EXPECT_EQ(initial_value
, dummy
.scroll_offset());
669 controller_impl
->Animate(kInitialTickTime
);
670 controller_impl
->UpdateState(true, events
.get());
671 EXPECT_TRUE(controller_impl
->HasActiveAnimation());
672 EXPECT_EQ(initial_value
, dummy_impl
.scroll_offset());
673 // Scroll offset animations should not generate property updates.
674 const AnimationEvent
* event
= GetMostRecentPropertyUpdateEvent(events
.get());
677 controller
->NotifyAnimationStarted((*events
)[0]);
678 controller
->Animate(kInitialTickTime
+ duration
/ 2);
679 controller
->UpdateState(true, nullptr);
680 EXPECT_TRUE(controller
->HasActiveAnimation());
681 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f
, 250.f
), dummy
.scroll_offset());
683 controller_impl
->Animate(kInitialTickTime
+ duration
/ 2);
684 controller_impl
->UpdateState(true, events
.get());
685 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f
, 250.f
),
686 dummy_impl
.scroll_offset());
687 event
= GetMostRecentPropertyUpdateEvent(events
.get());
690 controller_impl
->Animate(kInitialTickTime
+ duration
);
691 controller_impl
->UpdateState(true, events
.get());
692 EXPECT_VECTOR2DF_EQ(target_value
, dummy_impl
.scroll_offset());
693 EXPECT_FALSE(controller_impl
->HasActiveAnimation());
694 event
= GetMostRecentPropertyUpdateEvent(events
.get());
697 controller
->Animate(kInitialTickTime
+ duration
);
698 controller
->UpdateState(true, nullptr);
699 EXPECT_VECTOR2DF_EQ(target_value
, dummy
.scroll_offset());
700 EXPECT_FALSE(controller
->HasActiveAnimation());
703 // Ensure that when the impl controller doesn't have a value provider,
704 // the main-thread controller's value provider is used to obtain the intial
706 TEST(LayerAnimationControllerTest
, ScrollOffsetTransitionNoImplProvider
) {
707 FakeLayerAnimationValueObserver dummy_impl
;
708 scoped_refptr
<LayerAnimationController
> controller_impl(
709 LayerAnimationController::Create(0));
710 controller_impl
->AddValueObserver(&dummy_impl
);
711 scoped_ptr
<AnimationEventsVector
> events(
712 make_scoped_ptr(new AnimationEventsVector
));
713 FakeLayerAnimationValueObserver dummy
;
714 FakeLayerAnimationValueProvider dummy_provider
;
715 scoped_refptr
<LayerAnimationController
> controller(
716 LayerAnimationController::Create(0));
717 controller
->AddValueObserver(&dummy
);
718 controller
->set_value_provider(&dummy_provider
);
720 gfx::ScrollOffset
initial_value(500.f
, 100.f
);
721 gfx::ScrollOffset
target_value(300.f
, 200.f
);
722 scoped_ptr
<ScrollOffsetAnimationCurve
> curve(
723 ScrollOffsetAnimationCurve::Create(
725 EaseInOutTimingFunction::Create().Pass()));
727 scoped_ptr
<Animation
> animation(
728 Animation::Create(curve
.Pass(), 1, 0, Animation::SCROLL_OFFSET
));
729 animation
->set_needs_synchronized_start_time(true);
730 controller
->AddAnimation(animation
.Pass());
732 dummy_provider
.set_scroll_offset(initial_value
);
733 controller
->PushAnimationUpdatesTo(controller_impl
.get());
734 controller_impl
->ActivateAnimations();
735 EXPECT_TRUE(controller_impl
->GetAnimation(Animation::SCROLL_OFFSET
));
736 TimeDelta duration
= controller_impl
->GetAnimation(Animation::SCROLL_OFFSET
)
741 controller
->GetAnimation(Animation::SCROLL_OFFSET
)->curve()->Duration());
743 controller
->Animate(kInitialTickTime
);
744 controller
->UpdateState(true, nullptr);
745 EXPECT_TRUE(controller
->HasActiveAnimation());
746 EXPECT_EQ(initial_value
, dummy
.scroll_offset());
748 controller_impl
->Animate(kInitialTickTime
);
749 controller_impl
->UpdateState(true, events
.get());
750 EXPECT_TRUE(controller_impl
->HasActiveAnimation());
751 EXPECT_EQ(initial_value
, dummy_impl
.scroll_offset());
752 // Scroll offset animations should not generate property updates.
753 const AnimationEvent
* event
= GetMostRecentPropertyUpdateEvent(events
.get());
757 controller
->NotifyAnimationStarted((*events
)[0]);
758 controller
->Animate(kInitialTickTime
+ duration
/ 2);
759 controller
->UpdateState(true, nullptr);
760 EXPECT_TRUE(controller
->HasActiveAnimation());
761 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f
, 150.f
), dummy
.scroll_offset());
763 controller_impl
->Animate(kInitialTickTime
+ duration
/ 2);
764 controller_impl
->UpdateState(true, events
.get());
765 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f
, 150.f
),
766 dummy_impl
.scroll_offset());
767 event
= GetMostRecentPropertyUpdateEvent(events
.get());
770 controller_impl
->Animate(kInitialTickTime
+ duration
);
771 controller_impl
->UpdateState(true, events
.get());
772 EXPECT_VECTOR2DF_EQ(target_value
, dummy_impl
.scroll_offset());
773 EXPECT_FALSE(controller_impl
->HasActiveAnimation());
774 event
= GetMostRecentPropertyUpdateEvent(events
.get());
777 controller
->Animate(kInitialTickTime
+ duration
);
778 controller
->UpdateState(true, nullptr);
779 EXPECT_VECTOR2DF_EQ(target_value
, dummy
.scroll_offset());
780 EXPECT_FALSE(controller
->HasActiveAnimation());
783 TEST(LayerAnimationControllerTest
, ScrollOffsetTransitionOnImplOnly
) {
784 FakeLayerAnimationValueObserver dummy_impl
;
785 scoped_refptr
<LayerAnimationController
> controller_impl(
786 LayerAnimationController::Create(0));
787 controller_impl
->AddValueObserver(&dummy_impl
);
788 scoped_ptr
<AnimationEventsVector
> events(
789 make_scoped_ptr(new AnimationEventsVector
));
791 gfx::ScrollOffset
initial_value(100.f
, 300.f
);
792 gfx::ScrollOffset
target_value(300.f
, 200.f
);
793 scoped_ptr
<ScrollOffsetAnimationCurve
> curve(
794 ScrollOffsetAnimationCurve::Create(
796 EaseInOutTimingFunction::Create().Pass()));
797 curve
->SetInitialValue(initial_value
);
798 double duration_in_seconds
= curve
->Duration().InSecondsF();
800 scoped_ptr
<Animation
> animation(
801 Animation::Create(curve
.Pass(), 1, 0, Animation::SCROLL_OFFSET
));
802 animation
->set_is_impl_only(true);
803 controller_impl
->AddAnimation(animation
.Pass());
805 controller_impl
->Animate(kInitialTickTime
);
806 controller_impl
->UpdateState(true, events
.get());
807 EXPECT_TRUE(controller_impl
->HasActiveAnimation());
808 EXPECT_EQ(initial_value
, dummy_impl
.scroll_offset());
809 // Scroll offset animations should not generate property updates.
810 const AnimationEvent
* event
= GetMostRecentPropertyUpdateEvent(events
.get());
813 TimeDelta duration
= TimeDelta::FromMicroseconds(
814 duration_in_seconds
* base::Time::kMicrosecondsPerSecond
);
816 controller_impl
->Animate(kInitialTickTime
+ duration
/ 2);
817 controller_impl
->UpdateState(true, events
.get());
818 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f
, 250.f
),
819 dummy_impl
.scroll_offset());
820 event
= GetMostRecentPropertyUpdateEvent(events
.get());
823 controller_impl
->Animate(kInitialTickTime
+ duration
);
824 controller_impl
->UpdateState(true, events
.get());
825 EXPECT_VECTOR2DF_EQ(target_value
, dummy_impl
.scroll_offset());
826 EXPECT_FALSE(controller_impl
->HasActiveAnimation());
827 event
= GetMostRecentPropertyUpdateEvent(events
.get());
831 TEST(LayerAnimationControllerTest
, ScrollOffsetRemovalClearsScrollDelta
) {
832 FakeLayerAnimationValueObserver dummy_impl
;
833 FakeLayerAnimationValueProvider dummy_provider_impl
;
834 scoped_refptr
<LayerAnimationController
> controller_impl(
835 LayerAnimationController::Create(0));
836 controller_impl
->AddValueObserver(&dummy_impl
);
837 controller_impl
->set_value_provider(&dummy_provider_impl
);
838 scoped_ptr
<AnimationEventsVector
> events(
839 make_scoped_ptr(new AnimationEventsVector
));
840 FakeLayerAnimationValueObserver dummy
;
841 FakeLayerAnimationValueProvider dummy_provider
;
842 scoped_refptr
<LayerAnimationController
> controller(
843 LayerAnimationController::Create(0));
844 controller
->AddValueObserver(&dummy
);
845 controller
->set_value_provider(&dummy_provider
);
847 // First test the 1-argument version of RemoveAnimation.
848 gfx::ScrollOffset
target_value(300.f
, 200.f
);
849 scoped_ptr
<ScrollOffsetAnimationCurve
> curve(
850 ScrollOffsetAnimationCurve::Create(
851 target_value
, EaseInOutTimingFunction::Create().Pass()));
853 int animation_id
= 1;
854 scoped_ptr
<Animation
> animation(Animation::Create(
855 curve
.Pass(), animation_id
, 0, Animation::SCROLL_OFFSET
));
856 animation
->set_needs_synchronized_start_time(true);
857 controller
->AddAnimation(animation
.Pass());
858 controller
->PushAnimationUpdatesTo(controller_impl
.get());
859 controller_impl
->ActivateAnimations();
860 EXPECT_FALSE(controller
->scroll_offset_animation_was_interrupted());
861 EXPECT_FALSE(controller_impl
->scroll_offset_animation_was_interrupted());
863 controller
->RemoveAnimation(animation_id
);
864 EXPECT_TRUE(controller
->scroll_offset_animation_was_interrupted());
866 controller
->PushAnimationUpdatesTo(controller_impl
.get());
867 EXPECT_TRUE(controller_impl
->scroll_offset_animation_was_interrupted());
868 EXPECT_FALSE(controller
->scroll_offset_animation_was_interrupted());
870 controller_impl
->ActivateAnimations();
871 EXPECT_FALSE(controller_impl
->scroll_offset_animation_was_interrupted());
873 // Now, test the 2-argument version of RemoveAnimation.
874 curve
= ScrollOffsetAnimationCurve::Create(
875 target_value
, EaseInOutTimingFunction::Create().Pass());
876 animation
= Animation::Create(curve
.Pass(), animation_id
, 0,
877 Animation::SCROLL_OFFSET
);
878 animation
->set_needs_synchronized_start_time(true);
879 controller
->AddAnimation(animation
.Pass());
880 controller
->PushAnimationUpdatesTo(controller_impl
.get());
881 controller_impl
->ActivateAnimations();
882 EXPECT_FALSE(controller
->scroll_offset_animation_was_interrupted());
883 EXPECT_FALSE(controller_impl
->scroll_offset_animation_was_interrupted());
885 controller
->RemoveAnimation(animation_id
);
886 EXPECT_TRUE(controller
->scroll_offset_animation_was_interrupted());
888 controller
->PushAnimationUpdatesTo(controller_impl
.get());
889 EXPECT_TRUE(controller_impl
->scroll_offset_animation_was_interrupted());
890 EXPECT_FALSE(controller
->scroll_offset_animation_was_interrupted());
892 controller_impl
->ActivateAnimations();
893 EXPECT_FALSE(controller_impl
->scroll_offset_animation_was_interrupted());
895 // Check that removing non-scroll-offset animations does not cause
896 // scroll_offset_animation_was_interrupted() to get set.
897 animation_id
= AddAnimatedTransformToController(controller
.get(), 1.0, 1, 2);
898 controller
->PushAnimationUpdatesTo(controller_impl
.get());
899 controller_impl
->ActivateAnimations();
900 EXPECT_FALSE(controller
->scroll_offset_animation_was_interrupted());
901 EXPECT_FALSE(controller_impl
->scroll_offset_animation_was_interrupted());
903 controller
->RemoveAnimation(animation_id
);
904 EXPECT_FALSE(controller
->scroll_offset_animation_was_interrupted());
906 controller
->PushAnimationUpdatesTo(controller_impl
.get());
907 EXPECT_FALSE(controller_impl
->scroll_offset_animation_was_interrupted());
908 EXPECT_FALSE(controller
->scroll_offset_animation_was_interrupted());
910 controller_impl
->ActivateAnimations();
911 EXPECT_FALSE(controller_impl
->scroll_offset_animation_was_interrupted());
914 AddAnimatedFilterToController(controller
.get(), 1.0, 0.1f
, 0.2f
);
915 controller
->PushAnimationUpdatesTo(controller_impl
.get());
916 controller_impl
->ActivateAnimations();
917 EXPECT_FALSE(controller
->scroll_offset_animation_was_interrupted());
918 EXPECT_FALSE(controller_impl
->scroll_offset_animation_was_interrupted());
920 controller
->RemoveAnimation(animation_id
);
921 EXPECT_FALSE(controller
->scroll_offset_animation_was_interrupted());
923 controller
->PushAnimationUpdatesTo(controller_impl
.get());
924 EXPECT_FALSE(controller_impl
->scroll_offset_animation_was_interrupted());
925 EXPECT_FALSE(controller
->scroll_offset_animation_was_interrupted());
927 controller_impl
->ActivateAnimations();
928 EXPECT_FALSE(controller_impl
->scroll_offset_animation_was_interrupted());
931 class FakeAnimationDelegate
: public AnimationDelegate
{
933 FakeAnimationDelegate()
937 void NotifyAnimationStarted(TimeTicks monotonic_time
,
938 Animation::TargetProperty target_property
,
939 int group
) override
{
943 void NotifyAnimationFinished(TimeTicks monotonic_time
,
944 Animation::TargetProperty target_property
,
945 int group
) override
{
949 bool started() { return started_
; }
951 bool finished() { return finished_
; }
958 // Tests that impl-only animations lead to start and finished notifications
959 // on the impl thread controller's animation delegate.
960 TEST(LayerAnimationControllerTest
,
961 NotificationsForImplOnlyAnimationsAreSentToImplThreadDelegate
) {
962 FakeLayerAnimationValueObserver dummy_impl
;
963 scoped_refptr
<LayerAnimationController
> controller_impl(
964 LayerAnimationController::Create(0));
965 controller_impl
->AddValueObserver(&dummy_impl
);
966 scoped_ptr
<AnimationEventsVector
> events(
967 make_scoped_ptr(new AnimationEventsVector
));
968 FakeAnimationDelegate delegate
;
969 controller_impl
->set_layer_animation_delegate(&delegate
);
971 scoped_ptr
<Animation
> to_add(CreateAnimation(
972 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
973 1, Animation::OPACITY
));
974 to_add
->set_is_impl_only(true);
975 controller_impl
->AddAnimation(to_add
.Pass());
977 EXPECT_FALSE(delegate
.started());
978 EXPECT_FALSE(delegate
.finished());
980 controller_impl
->Animate(kInitialTickTime
);
981 controller_impl
->UpdateState(true, events
.get());
983 EXPECT_TRUE(delegate
.started());
984 EXPECT_FALSE(delegate
.finished());
986 events
.reset(new AnimationEventsVector
);
987 controller_impl
->Animate(kInitialTickTime
+
988 TimeDelta::FromMilliseconds(1000));
989 controller_impl
->UpdateState(true, events
.get());
991 EXPECT_TRUE(delegate
.started());
992 EXPECT_TRUE(delegate
.finished());
995 // Tests animations that are waiting for a synchronized start time do not
997 TEST(LayerAnimationControllerTest
,
998 AnimationsWaitingForStartTimeDoNotFinishIfTheyOutwaitTheirFinish
) {
999 scoped_ptr
<AnimationEventsVector
> events(
1000 make_scoped_ptr(new AnimationEventsVector
));
1001 FakeLayerAnimationValueObserver dummy
;
1002 scoped_refptr
<LayerAnimationController
> controller(
1003 LayerAnimationController::Create(0));
1004 controller
->AddValueObserver(&dummy
);
1006 scoped_ptr
<Animation
> to_add(CreateAnimation(
1007 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1008 1, Animation::OPACITY
));
1009 to_add
->set_needs_synchronized_start_time(true);
1011 // We should pause at the first keyframe indefinitely waiting for that
1012 // animation to start.
1013 controller
->AddAnimation(to_add
.Pass());
1014 controller
->Animate(kInitialTickTime
);
1015 controller
->UpdateState(true, events
.get());
1016 EXPECT_TRUE(controller
->HasActiveAnimation());
1017 EXPECT_EQ(0.f
, dummy
.opacity());
1018 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1000));
1019 controller
->UpdateState(true, events
.get());
1020 EXPECT_TRUE(controller
->HasActiveAnimation());
1021 EXPECT_EQ(0.f
, dummy
.opacity());
1022 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(2000));
1023 controller
->UpdateState(true, events
.get());
1024 EXPECT_TRUE(controller
->HasActiveAnimation());
1025 EXPECT_EQ(0.f
, dummy
.opacity());
1027 // Send the synchronized start time.
1028 controller
->NotifyAnimationStarted(
1029 AnimationEvent(AnimationEvent::STARTED
, 0, 1, Animation::OPACITY
,
1030 kInitialTickTime
+ TimeDelta::FromMilliseconds(2000)));
1031 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(5000));
1032 controller
->UpdateState(true, events
.get());
1033 EXPECT_EQ(1.f
, dummy
.opacity());
1034 EXPECT_FALSE(controller
->HasActiveAnimation());
1037 // Tests that two queued animations affecting the same property run in sequence.
1038 TEST(LayerAnimationControllerTest
, TrivialQueuing
) {
1039 scoped_ptr
<AnimationEventsVector
> events(
1040 make_scoped_ptr(new AnimationEventsVector
));
1041 FakeLayerAnimationValueObserver dummy
;
1042 scoped_refptr
<LayerAnimationController
> controller(
1043 LayerAnimationController::Create(0));
1044 controller
->AddValueObserver(&dummy
);
1046 EXPECT_FALSE(controller
->needs_to_start_animations_for_testing());
1048 controller
->AddAnimation(CreateAnimation(
1049 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1050 1, Animation::OPACITY
));
1051 controller
->AddAnimation(CreateAnimation(
1052 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 1.f
, 0.5f
))
1054 2, Animation::OPACITY
));
1056 EXPECT_TRUE(controller
->needs_to_start_animations_for_testing());
1058 controller
->Animate(kInitialTickTime
);
1060 // The second animation still needs to be started.
1061 EXPECT_TRUE(controller
->needs_to_start_animations_for_testing());
1063 controller
->UpdateState(true, events
.get());
1064 EXPECT_TRUE(controller
->HasActiveAnimation());
1065 EXPECT_EQ(0.f
, dummy
.opacity());
1067 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1000));
1068 EXPECT_TRUE(controller
->needs_to_start_animations_for_testing());
1069 controller
->UpdateState(true, events
.get());
1070 EXPECT_FALSE(controller
->needs_to_start_animations_for_testing());
1072 EXPECT_TRUE(controller
->HasActiveAnimation());
1073 EXPECT_EQ(1.f
, dummy
.opacity());
1074 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(2000));
1075 controller
->UpdateState(true, events
.get());
1076 EXPECT_EQ(0.5f
, dummy
.opacity());
1077 EXPECT_FALSE(controller
->HasActiveAnimation());
1080 // Tests interrupting a transition with another transition.
1081 TEST(LayerAnimationControllerTest
, Interrupt
) {
1082 scoped_ptr
<AnimationEventsVector
> events(
1083 make_scoped_ptr(new AnimationEventsVector
));
1084 FakeLayerAnimationValueObserver dummy
;
1085 scoped_refptr
<LayerAnimationController
> controller(
1086 LayerAnimationController::Create(0));
1087 controller
->AddValueObserver(&dummy
);
1088 controller
->AddAnimation(CreateAnimation(
1089 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1090 1, Animation::OPACITY
));
1091 controller
->Animate(kInitialTickTime
);
1092 controller
->UpdateState(true, events
.get());
1093 EXPECT_TRUE(controller
->HasActiveAnimation());
1094 EXPECT_EQ(0.f
, dummy
.opacity());
1096 scoped_ptr
<Animation
> to_add(CreateAnimation(
1097 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 1.f
, 0.5f
))
1099 2, Animation::OPACITY
));
1100 controller
->AbortAnimations(Animation::OPACITY
);
1101 controller
->AddAnimation(to_add
.Pass());
1103 // Since the previous animation was aborted, the new animation should start
1104 // right in this call to animate.
1105 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(500));
1106 controller
->UpdateState(true, events
.get());
1107 EXPECT_TRUE(controller
->HasActiveAnimation());
1108 EXPECT_EQ(1.f
, dummy
.opacity());
1109 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1500));
1110 controller
->UpdateState(true, events
.get());
1111 EXPECT_EQ(0.5f
, dummy
.opacity());
1112 EXPECT_FALSE(controller
->HasActiveAnimation());
1115 // Tests scheduling two animations to run together when only one property is
1117 TEST(LayerAnimationControllerTest
, ScheduleTogetherWhenAPropertyIsBlocked
) {
1118 scoped_ptr
<AnimationEventsVector
> events(
1119 make_scoped_ptr(new AnimationEventsVector
));
1120 FakeLayerAnimationValueObserver dummy
;
1121 scoped_refptr
<LayerAnimationController
> controller(
1122 LayerAnimationController::Create(0));
1123 controller
->AddValueObserver(&dummy
);
1125 controller
->AddAnimation(CreateAnimation(
1126 scoped_ptr
<AnimationCurve
>(new FakeTransformTransition(1)).Pass(), 1,
1127 Animation::TRANSFORM
));
1128 controller
->AddAnimation(CreateAnimation(
1129 scoped_ptr
<AnimationCurve
>(new FakeTransformTransition(1)).Pass(), 2,
1130 Animation::TRANSFORM
));
1131 controller
->AddAnimation(CreateAnimation(
1132 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1133 2, Animation::OPACITY
));
1135 controller
->Animate(kInitialTickTime
);
1136 controller
->UpdateState(true, events
.get());
1137 EXPECT_EQ(0.f
, dummy
.opacity());
1138 EXPECT_TRUE(controller
->HasActiveAnimation());
1139 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1000));
1140 controller
->UpdateState(true, events
.get());
1141 // Should not have started the float transition yet.
1142 EXPECT_TRUE(controller
->HasActiveAnimation());
1143 EXPECT_EQ(0.f
, dummy
.opacity());
1144 // The float animation should have started at time 1 and should be done.
1145 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(2000));
1146 controller
->UpdateState(true, events
.get());
1147 EXPECT_EQ(1.f
, dummy
.opacity());
1148 EXPECT_FALSE(controller
->HasActiveAnimation());
1151 // Tests scheduling two animations to run together with different lengths and
1152 // another animation queued to start when the shorter animation finishes (should
1153 // wait for both to finish).
1154 TEST(LayerAnimationControllerTest
, ScheduleTogetherWithAnAnimWaiting
) {
1155 scoped_ptr
<AnimationEventsVector
> events(
1156 make_scoped_ptr(new AnimationEventsVector
));
1157 FakeLayerAnimationValueObserver dummy
;
1158 scoped_refptr
<LayerAnimationController
> controller(
1159 LayerAnimationController::Create(0));
1160 controller
->AddValueObserver(&dummy
);
1162 controller
->AddAnimation(CreateAnimation(
1163 scoped_ptr
<AnimationCurve
>(new FakeTransformTransition(2)).Pass(), 1,
1164 Animation::TRANSFORM
));
1165 controller
->AddAnimation(CreateAnimation(
1166 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1167 1, Animation::OPACITY
));
1168 controller
->AddAnimation(CreateAnimation(
1169 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 1.f
, 0.5f
))
1171 2, Animation::OPACITY
));
1173 // Animations with id 1 should both start now.
1174 controller
->Animate(kInitialTickTime
);
1175 controller
->UpdateState(true, events
.get());
1176 EXPECT_TRUE(controller
->HasActiveAnimation());
1177 EXPECT_EQ(0.f
, dummy
.opacity());
1178 // The opacity animation should have finished at time 1, but the group
1179 // of animations with id 1 don't finish until time 2 because of the length
1180 // of the transform animation.
1181 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(2000));
1182 controller
->UpdateState(true, events
.get());
1183 // Should not have started the float transition yet.
1184 EXPECT_TRUE(controller
->HasActiveAnimation());
1185 EXPECT_EQ(1.f
, dummy
.opacity());
1187 // The second opacity animation should start at time 2 and should be done by
1189 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(3000));
1190 controller
->UpdateState(true, events
.get());
1191 EXPECT_EQ(0.5f
, dummy
.opacity());
1192 EXPECT_FALSE(controller
->HasActiveAnimation());
1195 // Test that a looping animation loops and for the correct number of iterations.
1196 TEST(LayerAnimationControllerTest
, TrivialLooping
) {
1197 scoped_ptr
<AnimationEventsVector
> events(
1198 make_scoped_ptr(new AnimationEventsVector
));
1199 FakeLayerAnimationValueObserver dummy
;
1200 scoped_refptr
<LayerAnimationController
> controller(
1201 LayerAnimationController::Create(0));
1202 controller
->AddValueObserver(&dummy
);
1204 scoped_ptr
<Animation
> to_add(CreateAnimation(
1205 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1206 1, Animation::OPACITY
));
1207 to_add
->set_iterations(3);
1208 controller
->AddAnimation(to_add
.Pass());
1210 controller
->Animate(kInitialTickTime
);
1211 controller
->UpdateState(true, events
.get());
1212 EXPECT_TRUE(controller
->HasActiveAnimation());
1213 EXPECT_EQ(0.f
, dummy
.opacity());
1214 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1250));
1215 controller
->UpdateState(true, events
.get());
1216 EXPECT_TRUE(controller
->HasActiveAnimation());
1217 EXPECT_EQ(0.25f
, dummy
.opacity());
1218 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1750));
1219 controller
->UpdateState(true, events
.get());
1220 EXPECT_TRUE(controller
->HasActiveAnimation());
1221 EXPECT_EQ(0.75f
, dummy
.opacity());
1222 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(2250));
1223 controller
->UpdateState(true, events
.get());
1224 EXPECT_TRUE(controller
->HasActiveAnimation());
1225 EXPECT_EQ(0.25f
, dummy
.opacity());
1226 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(2750));
1227 controller
->UpdateState(true, events
.get());
1228 EXPECT_TRUE(controller
->HasActiveAnimation());
1229 EXPECT_EQ(0.75f
, dummy
.opacity());
1230 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(3000));
1231 controller
->UpdateState(true, events
.get());
1232 EXPECT_FALSE(controller
->HasActiveAnimation());
1233 EXPECT_EQ(1.f
, dummy
.opacity());
1235 // Just be extra sure.
1236 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(4000));
1237 controller
->UpdateState(true, events
.get());
1238 EXPECT_EQ(1.f
, dummy
.opacity());
1241 // Test that an infinitely looping animation does indeed go until aborted.
1242 TEST(LayerAnimationControllerTest
, InfiniteLooping
) {
1243 scoped_ptr
<AnimationEventsVector
> events(
1244 make_scoped_ptr(new AnimationEventsVector
));
1245 FakeLayerAnimationValueObserver dummy
;
1246 scoped_refptr
<LayerAnimationController
> controller(
1247 LayerAnimationController::Create(0));
1248 controller
->AddValueObserver(&dummy
);
1250 scoped_ptr
<Animation
> to_add(CreateAnimation(
1251 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1252 1, Animation::OPACITY
));
1253 to_add
->set_iterations(-1);
1254 controller
->AddAnimation(to_add
.Pass());
1256 controller
->Animate(kInitialTickTime
);
1257 controller
->UpdateState(true, events
.get());
1258 EXPECT_TRUE(controller
->HasActiveAnimation());
1259 EXPECT_EQ(0.f
, dummy
.opacity());
1260 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1250));
1261 controller
->UpdateState(true, events
.get());
1262 EXPECT_TRUE(controller
->HasActiveAnimation());
1263 EXPECT_EQ(0.25f
, dummy
.opacity());
1264 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1750));
1265 controller
->UpdateState(true, events
.get());
1266 EXPECT_TRUE(controller
->HasActiveAnimation());
1267 EXPECT_EQ(0.75f
, dummy
.opacity());
1269 controller
->Animate(kInitialTickTime
+
1270 TimeDelta::FromMilliseconds(1073741824250));
1271 controller
->UpdateState(true, events
.get());
1272 EXPECT_TRUE(controller
->HasActiveAnimation());
1273 EXPECT_EQ(0.25f
, dummy
.opacity());
1274 controller
->Animate(kInitialTickTime
+
1275 TimeDelta::FromMilliseconds(1073741824750));
1276 controller
->UpdateState(true, events
.get());
1277 EXPECT_TRUE(controller
->HasActiveAnimation());
1278 EXPECT_EQ(0.75f
, dummy
.opacity());
1280 EXPECT_TRUE(controller
->GetAnimation(Animation::OPACITY
));
1281 controller
->GetAnimation(Animation::OPACITY
)
1282 ->SetRunState(Animation::ABORTED
,
1283 kInitialTickTime
+ TimeDelta::FromMilliseconds(750));
1284 EXPECT_FALSE(controller
->HasActiveAnimation());
1285 EXPECT_EQ(0.75f
, dummy
.opacity());
1288 // Test that pausing and resuming work as expected.
1289 TEST(LayerAnimationControllerTest
, PauseResume
) {
1290 scoped_ptr
<AnimationEventsVector
> events(
1291 make_scoped_ptr(new AnimationEventsVector
));
1292 FakeLayerAnimationValueObserver dummy
;
1293 scoped_refptr
<LayerAnimationController
> controller(
1294 LayerAnimationController::Create(0));
1295 controller
->AddValueObserver(&dummy
);
1297 controller
->AddAnimation(CreateAnimation(
1298 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1299 1, Animation::OPACITY
));
1301 controller
->Animate(kInitialTickTime
);
1302 controller
->UpdateState(true, events
.get());
1303 EXPECT_TRUE(controller
->HasActiveAnimation());
1304 EXPECT_EQ(0.f
, dummy
.opacity());
1305 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(500));
1306 controller
->UpdateState(true, events
.get());
1307 EXPECT_TRUE(controller
->HasActiveAnimation());
1308 EXPECT_EQ(0.5f
, dummy
.opacity());
1310 EXPECT_TRUE(controller
->GetAnimation(Animation::OPACITY
));
1311 controller
->GetAnimation(Animation::OPACITY
)
1312 ->SetRunState(Animation::PAUSED
,
1313 kInitialTickTime
+ TimeDelta::FromMilliseconds(500));
1315 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1024000));
1316 controller
->UpdateState(true, events
.get());
1317 EXPECT_TRUE(controller
->HasActiveAnimation());
1318 EXPECT_EQ(0.5f
, dummy
.opacity());
1320 EXPECT_TRUE(controller
->GetAnimation(Animation::OPACITY
));
1321 controller
->GetAnimation(Animation::OPACITY
)
1322 ->SetRunState(Animation::RUNNING
,
1323 kInitialTickTime
+ TimeDelta::FromMilliseconds(1024000));
1324 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1024250));
1325 controller
->UpdateState(true, events
.get());
1326 EXPECT_TRUE(controller
->HasActiveAnimation());
1327 EXPECT_EQ(0.75f
, dummy
.opacity());
1329 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1024500));
1330 controller
->UpdateState(true, events
.get());
1331 EXPECT_FALSE(controller
->HasActiveAnimation());
1332 EXPECT_EQ(1.f
, dummy
.opacity());
1335 TEST(LayerAnimationControllerTest
, AbortAGroupedAnimation
) {
1336 scoped_ptr
<AnimationEventsVector
> events(
1337 make_scoped_ptr(new AnimationEventsVector
));
1338 FakeLayerAnimationValueObserver dummy
;
1339 scoped_refptr
<LayerAnimationController
> controller(
1340 LayerAnimationController::Create(0));
1341 controller
->AddValueObserver(&dummy
);
1343 const int animation_id
= 2;
1344 controller
->AddAnimation(Animation::Create(
1345 scoped_ptr
<AnimationCurve
>(new FakeTransformTransition(1)).Pass(), 1, 1,
1346 Animation::TRANSFORM
));
1347 controller
->AddAnimation(Animation::Create(
1348 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(2.0, 0.f
, 1.f
)).Pass(),
1349 animation_id
, 1, Animation::OPACITY
));
1350 controller
->AddAnimation(Animation::Create(
1351 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 1.f
, 0.75f
))
1353 3, 2, Animation::OPACITY
));
1355 controller
->Animate(kInitialTickTime
);
1356 controller
->UpdateState(true, events
.get());
1357 EXPECT_TRUE(controller
->HasActiveAnimation());
1358 EXPECT_EQ(0.f
, dummy
.opacity());
1359 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1000));
1360 controller
->UpdateState(true, events
.get());
1361 EXPECT_TRUE(controller
->HasActiveAnimation());
1362 EXPECT_EQ(0.5f
, dummy
.opacity());
1364 EXPECT_TRUE(controller
->GetAnimationById(animation_id
));
1365 controller
->GetAnimationById(animation_id
)
1366 ->SetRunState(Animation::ABORTED
,
1367 kInitialTickTime
+ TimeDelta::FromMilliseconds(1000));
1368 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1000));
1369 controller
->UpdateState(true, events
.get());
1370 EXPECT_TRUE(controller
->HasActiveAnimation());
1371 EXPECT_EQ(1.f
, dummy
.opacity());
1372 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(2000));
1373 controller
->UpdateState(true, events
.get());
1374 EXPECT_TRUE(!controller
->HasActiveAnimation());
1375 EXPECT_EQ(0.75f
, dummy
.opacity());
1378 TEST(LayerAnimationControllerTest
, PushUpdatesWhenSynchronizedStartTimeNeeded
) {
1379 FakeLayerAnimationValueObserver dummy_impl
;
1380 scoped_refptr
<LayerAnimationController
> controller_impl(
1381 LayerAnimationController::Create(0));
1382 controller_impl
->AddValueObserver(&dummy_impl
);
1383 scoped_ptr
<AnimationEventsVector
> events(
1384 make_scoped_ptr(new AnimationEventsVector
));
1385 FakeLayerAnimationValueObserver dummy
;
1386 scoped_refptr
<LayerAnimationController
> controller(
1387 LayerAnimationController::Create(0));
1388 controller
->AddValueObserver(&dummy
);
1390 scoped_ptr
<Animation
> to_add(CreateAnimation(
1391 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(2.0, 0.f
, 1.f
)).Pass(),
1392 0, Animation::OPACITY
));
1393 to_add
->set_needs_synchronized_start_time(true);
1394 controller
->AddAnimation(to_add
.Pass());
1396 controller
->Animate(kInitialTickTime
);
1397 controller
->UpdateState(true, events
.get());
1398 EXPECT_TRUE(controller
->HasActiveAnimation());
1399 Animation
* active_animation
= controller
->GetAnimation(Animation::OPACITY
);
1400 EXPECT_TRUE(active_animation
);
1401 EXPECT_TRUE(active_animation
->needs_synchronized_start_time());
1403 controller
->PushAnimationUpdatesTo(controller_impl
.get());
1404 controller_impl
->ActivateAnimations();
1406 active_animation
= controller_impl
->GetAnimation(Animation::OPACITY
);
1407 EXPECT_TRUE(active_animation
);
1408 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY
,
1409 active_animation
->run_state());
1412 // Tests that skipping a call to UpdateState works as expected.
1413 TEST(LayerAnimationControllerTest
, SkipUpdateState
) {
1414 scoped_ptr
<AnimationEventsVector
> events(
1415 make_scoped_ptr(new AnimationEventsVector
));
1416 FakeLayerAnimationValueObserver dummy
;
1417 scoped_refptr
<LayerAnimationController
> controller(
1418 LayerAnimationController::Create(0));
1419 controller
->AddValueObserver(&dummy
);
1421 controller
->AddAnimation(CreateAnimation(
1422 scoped_ptr
<AnimationCurve
>(new FakeTransformTransition(1)).Pass(), 1,
1423 Animation::TRANSFORM
));
1425 controller
->Animate(kInitialTickTime
);
1426 controller
->UpdateState(true, events
.get());
1428 controller
->AddAnimation(CreateAnimation(
1429 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1430 2, Animation::OPACITY
));
1432 // Animate but don't UpdateState.
1433 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1000));
1435 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(2000));
1436 events
.reset(new AnimationEventsVector
);
1437 controller
->UpdateState(true, events
.get());
1439 // Should have one STARTED event and one FINISHED event.
1440 EXPECT_EQ(2u, events
->size());
1441 EXPECT_NE((*events
)[0].type
, (*events
)[1].type
);
1443 // The float transition should still be at its starting point.
1444 EXPECT_TRUE(controller
->HasActiveAnimation());
1445 EXPECT_EQ(0.f
, dummy
.opacity());
1447 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(3000));
1448 controller
->UpdateState(true, events
.get());
1450 // The float tranisition should now be done.
1451 EXPECT_EQ(1.f
, dummy
.opacity());
1452 EXPECT_FALSE(controller
->HasActiveAnimation());
1455 // Tests that an animation controller with only a pending observer gets ticked
1456 // but doesn't progress animations past the STARTING state.
1457 TEST(LayerAnimationControllerTest
, InactiveObserverGetsTicked
) {
1458 scoped_ptr
<AnimationEventsVector
> events(
1459 make_scoped_ptr(new AnimationEventsVector
));
1460 FakeLayerAnimationValueObserver dummy
;
1461 FakeInactiveLayerAnimationValueObserver pending_dummy
;
1462 scoped_refptr
<LayerAnimationController
> controller(
1463 LayerAnimationController::Create(0));
1466 controller
->AddAnimation(CreateAnimation(
1467 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.5f
, 1.f
))
1469 id
, Animation::OPACITY
));
1471 // Without an observer, the animation shouldn't progress to the STARTING
1473 controller
->Animate(kInitialTickTime
);
1474 controller
->UpdateState(true, events
.get());
1475 EXPECT_EQ(0u, events
->size());
1476 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY
,
1477 controller
->GetAnimation(Animation::OPACITY
)->run_state());
1479 controller
->AddValueObserver(&pending_dummy
);
1481 // With only a pending observer, the animation should progress to the
1482 // STARTING state and get ticked at its starting point, but should not
1483 // progress to RUNNING.
1484 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1000));
1485 controller
->UpdateState(true, events
.get());
1486 EXPECT_EQ(0u, events
->size());
1487 EXPECT_EQ(Animation::STARTING
,
1488 controller
->GetAnimation(Animation::OPACITY
)->run_state());
1489 EXPECT_EQ(0.5f
, pending_dummy
.opacity());
1491 // Even when already in the STARTING state, the animation should stay
1492 // there, and shouldn't be ticked past its starting point.
1493 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(2000));
1494 controller
->UpdateState(true, events
.get());
1495 EXPECT_EQ(0u, events
->size());
1496 EXPECT_EQ(Animation::STARTING
,
1497 controller
->GetAnimation(Animation::OPACITY
)->run_state());
1498 EXPECT_EQ(0.5f
, pending_dummy
.opacity());
1500 controller
->AddValueObserver(&dummy
);
1502 // Now that an active observer has been added, the animation should still
1503 // initially tick at its starting point, but should now progress to RUNNING.
1504 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(3000));
1505 controller
->UpdateState(true, events
.get());
1506 EXPECT_EQ(1u, events
->size());
1507 EXPECT_EQ(Animation::RUNNING
,
1508 controller
->GetAnimation(Animation::OPACITY
)->run_state());
1509 EXPECT_EQ(0.5f
, pending_dummy
.opacity());
1510 EXPECT_EQ(0.5f
, dummy
.opacity());
1512 // The animation should now tick past its starting point.
1513 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(3500));
1514 EXPECT_NE(0.5f
, pending_dummy
.opacity());
1515 EXPECT_NE(0.5f
, dummy
.opacity());
1518 TEST(LayerAnimationControllerTest
, TransformAnimationBounds
) {
1519 scoped_refptr
<LayerAnimationController
> controller_impl(
1520 LayerAnimationController::Create(0));
1522 scoped_ptr
<KeyframedTransformAnimationCurve
> curve1(
1523 KeyframedTransformAnimationCurve::Create());
1525 TransformOperations operations1
;
1526 curve1
->AddKeyframe(
1527 TransformKeyframe::Create(base::TimeDelta(), operations1
, nullptr));
1528 operations1
.AppendTranslate(10.0, 15.0, 0.0);
1529 curve1
->AddKeyframe(TransformKeyframe::Create(
1530 base::TimeDelta::FromSecondsD(1.0), operations1
, nullptr));
1532 scoped_ptr
<Animation
> animation(
1533 Animation::Create(curve1
.Pass(), 1, 1, Animation::TRANSFORM
));
1534 controller_impl
->AddAnimation(animation
.Pass());
1536 scoped_ptr
<KeyframedTransformAnimationCurve
> curve2(
1537 KeyframedTransformAnimationCurve::Create());
1539 TransformOperations operations2
;
1540 curve2
->AddKeyframe(
1541 TransformKeyframe::Create(base::TimeDelta(), operations2
, nullptr));
1542 operations2
.AppendScale(2.0, 3.0, 4.0);
1543 curve2
->AddKeyframe(TransformKeyframe::Create(
1544 base::TimeDelta::FromSecondsD(1.0), operations2
, nullptr));
1546 animation
= Animation::Create(curve2
.Pass(), 2, 2, Animation::TRANSFORM
);
1547 controller_impl
->AddAnimation(animation
.Pass());
1549 gfx::BoxF
box(1.f
, 2.f
, -1.f
, 3.f
, 4.f
, 5.f
);
1552 EXPECT_TRUE(controller_impl
->TransformAnimationBoundsForBox(box
, &bounds
));
1553 EXPECT_EQ(gfx::BoxF(1.f
, 2.f
, -4.f
, 13.f
, 19.f
, 20.f
).ToString(),
1556 controller_impl
->GetAnimationById(1)
1557 ->SetRunState(Animation::FINISHED
, TicksFromSecondsF(0.0));
1559 // Only the unfinished animation should affect the animated bounds.
1560 EXPECT_TRUE(controller_impl
->TransformAnimationBoundsForBox(box
, &bounds
));
1561 EXPECT_EQ(gfx::BoxF(1.f
, 2.f
, -4.f
, 7.f
, 16.f
, 20.f
).ToString(),
1564 controller_impl
->GetAnimationById(2)
1565 ->SetRunState(Animation::FINISHED
, TicksFromSecondsF(0.0));
1567 // There are no longer any running animations.
1568 EXPECT_FALSE(controller_impl
->HasTransformAnimationThatInflatesBounds());
1570 // Add an animation whose bounds we don't yet support computing.
1571 scoped_ptr
<KeyframedTransformAnimationCurve
> curve3(
1572 KeyframedTransformAnimationCurve::Create());
1573 TransformOperations operations3
;
1574 gfx::Transform transform3
;
1575 transform3
.Scale3d(1.0, 2.0, 3.0);
1576 curve3
->AddKeyframe(
1577 TransformKeyframe::Create(base::TimeDelta(), operations3
, nullptr));
1578 operations3
.AppendMatrix(transform3
);
1579 curve3
->AddKeyframe(TransformKeyframe::Create(
1580 base::TimeDelta::FromSecondsD(1.0), operations3
, nullptr));
1581 animation
= Animation::Create(curve3
.Pass(), 3, 3, Animation::TRANSFORM
);
1582 controller_impl
->AddAnimation(animation
.Pass());
1583 EXPECT_FALSE(controller_impl
->TransformAnimationBoundsForBox(box
, &bounds
));
1586 // Tests that AbortAnimations aborts all animations targeting the specified
1588 TEST(LayerAnimationControllerTest
, AbortAnimations
) {
1589 FakeLayerAnimationValueObserver dummy
;
1590 scoped_refptr
<LayerAnimationController
> controller(
1591 LayerAnimationController::Create(0));
1592 controller
->AddValueObserver(&dummy
);
1594 // Start with several animations, and allow some of them to reach the finished
1596 controller
->AddAnimation(Animation::Create(
1597 scoped_ptr
<AnimationCurve
>(new FakeTransformTransition(1.0)).Pass(), 1, 1,
1598 Animation::TRANSFORM
));
1599 controller
->AddAnimation(Animation::Create(
1600 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1601 2, 2, Animation::OPACITY
));
1602 controller
->AddAnimation(Animation::Create(
1603 scoped_ptr
<AnimationCurve
>(new FakeTransformTransition(1.0)).Pass(), 3, 3,
1604 Animation::TRANSFORM
));
1605 controller
->AddAnimation(Animation::Create(
1606 scoped_ptr
<AnimationCurve
>(new FakeTransformTransition(2.0)).Pass(), 4, 4,
1607 Animation::TRANSFORM
));
1608 controller
->AddAnimation(Animation::Create(
1609 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1610 5, 5, Animation::OPACITY
));
1612 controller
->Animate(kInitialTickTime
);
1613 controller
->UpdateState(true, nullptr);
1614 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1000));
1615 controller
->UpdateState(true, nullptr);
1617 EXPECT_EQ(Animation::FINISHED
, controller
->GetAnimationById(1)->run_state());
1618 EXPECT_EQ(Animation::FINISHED
, controller
->GetAnimationById(2)->run_state());
1619 EXPECT_EQ(Animation::RUNNING
, controller
->GetAnimationById(3)->run_state());
1620 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY
,
1621 controller
->GetAnimationById(4)->run_state());
1622 EXPECT_EQ(Animation::RUNNING
, controller
->GetAnimationById(5)->run_state());
1624 controller
->AbortAnimations(Animation::TRANSFORM
);
1626 // Only un-finished TRANSFORM animations should have been aborted.
1627 EXPECT_EQ(Animation::FINISHED
, controller
->GetAnimationById(1)->run_state());
1628 EXPECT_EQ(Animation::FINISHED
, controller
->GetAnimationById(2)->run_state());
1629 EXPECT_EQ(Animation::ABORTED
, controller
->GetAnimationById(3)->run_state());
1630 EXPECT_EQ(Animation::ABORTED
, controller
->GetAnimationById(4)->run_state());
1631 EXPECT_EQ(Animation::RUNNING
, controller
->GetAnimationById(5)->run_state());
1634 // An animation aborted on the main thread should get deleted on both threads.
1635 TEST(LayerAnimationControllerTest
, MainThreadAbortedAnimationGetsDeleted
) {
1636 FakeLayerAnimationValueObserver dummy_impl
;
1637 scoped_refptr
<LayerAnimationController
> controller_impl(
1638 LayerAnimationController::Create(0));
1639 controller_impl
->AddValueObserver(&dummy_impl
);
1640 FakeLayerAnimationValueObserver dummy
;
1641 scoped_refptr
<LayerAnimationController
> controller(
1642 LayerAnimationController::Create(0));
1643 controller
->AddValueObserver(&dummy
);
1646 AddOpacityTransitionToController(controller
.get(), 1.0, 0.f
, 1.f
, false);
1648 controller
->PushAnimationUpdatesTo(controller_impl
.get());
1649 controller_impl
->ActivateAnimations();
1650 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
));
1652 controller
->AbortAnimations(Animation::OPACITY
);
1653 EXPECT_EQ(Animation::ABORTED
,
1654 controller
->GetAnimation(Animation::OPACITY
)->run_state());
1655 EXPECT_FALSE(dummy
.animation_waiting_for_deletion());
1656 EXPECT_FALSE(dummy_impl
.animation_waiting_for_deletion());
1658 controller
->Animate(kInitialTickTime
);
1659 controller
->UpdateState(true, nullptr);
1660 EXPECT_TRUE(dummy
.animation_waiting_for_deletion());
1661 EXPECT_EQ(Animation::WAITING_FOR_DELETION
,
1662 controller
->GetAnimation(Animation::OPACITY
)->run_state());
1664 controller
->PushAnimationUpdatesTo(controller_impl
.get());
1665 controller_impl
->ActivateAnimations();
1666 EXPECT_FALSE(controller
->GetAnimationById(animation_id
));
1667 EXPECT_FALSE(controller_impl
->GetAnimationById(animation_id
));
1670 // An animation aborted on the impl thread should get deleted on both threads.
1671 TEST(LayerAnimationControllerTest
, ImplThreadAbortedAnimationGetsDeleted
) {
1672 FakeLayerAnimationValueObserver dummy_impl
;
1673 scoped_refptr
<LayerAnimationController
> controller_impl(
1674 LayerAnimationController::Create(0));
1675 controller_impl
->AddValueObserver(&dummy_impl
);
1676 FakeLayerAnimationValueObserver dummy
;
1677 scoped_refptr
<LayerAnimationController
> controller(
1678 LayerAnimationController::Create(0));
1679 controller
->AddValueObserver(&dummy
);
1682 AddOpacityTransitionToController(controller
.get(), 1.0, 0.f
, 1.f
, false);
1684 controller
->PushAnimationUpdatesTo(controller_impl
.get());
1685 controller_impl
->ActivateAnimations();
1686 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
));
1688 controller_impl
->AbortAnimations(Animation::OPACITY
);
1689 EXPECT_EQ(Animation::ABORTED
,
1690 controller_impl
->GetAnimation(Animation::OPACITY
)->run_state());
1691 EXPECT_FALSE(dummy
.animation_waiting_for_deletion());
1692 EXPECT_FALSE(dummy_impl
.animation_waiting_for_deletion());
1694 AnimationEventsVector events
;
1695 controller_impl
->Animate(kInitialTickTime
);
1696 controller_impl
->UpdateState(true, &events
);
1697 EXPECT_TRUE(dummy_impl
.animation_waiting_for_deletion());
1698 EXPECT_EQ(1u, events
.size());
1699 EXPECT_EQ(AnimationEvent::ABORTED
, events
[0].type
);
1700 EXPECT_EQ(Animation::WAITING_FOR_DELETION
,
1701 controller_impl
->GetAnimation(Animation::OPACITY
)->run_state());
1703 controller
->NotifyAnimationAborted(events
[0]);
1704 EXPECT_EQ(Animation::ABORTED
,
1705 controller
->GetAnimation(Animation::OPACITY
)->run_state());
1707 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(500));
1708 controller
->UpdateState(true, nullptr);
1709 EXPECT_TRUE(dummy
.animation_waiting_for_deletion());
1710 EXPECT_EQ(Animation::WAITING_FOR_DELETION
,
1711 controller
->GetAnimation(Animation::OPACITY
)->run_state());
1713 controller
->PushAnimationUpdatesTo(controller_impl
.get());
1714 controller_impl
->ActivateAnimations();
1715 EXPECT_FALSE(controller
->GetAnimationById(animation_id
));
1716 EXPECT_FALSE(controller_impl
->GetAnimationById(animation_id
));
1719 // Ensure that we only generate FINISHED events for animations in a group
1720 // once all animations in that group are finished.
1721 TEST(LayerAnimationControllerTest
, FinishedEventsForGroup
) {
1722 scoped_ptr
<AnimationEventsVector
> events(
1723 make_scoped_ptr(new AnimationEventsVector
));
1724 FakeLayerAnimationValueObserver dummy_impl
;
1725 scoped_refptr
<LayerAnimationController
> controller_impl(
1726 LayerAnimationController::Create(0));
1727 controller_impl
->AddValueObserver(&dummy_impl
);
1729 const int group_id
= 1;
1731 // Add two animations with the same group id but different durations.
1732 controller_impl
->AddAnimation(Animation::Create(
1733 scoped_ptr
<AnimationCurve
>(new FakeTransformTransition(2.0)).Pass(), 1,
1734 group_id
, Animation::TRANSFORM
));
1735 controller_impl
->AddAnimation(Animation::Create(
1736 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1737 2, group_id
, Animation::OPACITY
));
1739 controller_impl
->Animate(kInitialTickTime
);
1740 controller_impl
->UpdateState(true, events
.get());
1742 // Both animations should have started.
1743 EXPECT_EQ(2u, events
->size());
1744 EXPECT_EQ(AnimationEvent::STARTED
, (*events
)[0].type
);
1745 EXPECT_EQ(AnimationEvent::STARTED
, (*events
)[1].type
);
1747 events
.reset(new AnimationEventsVector
);
1748 controller_impl
->Animate(kInitialTickTime
+
1749 TimeDelta::FromMilliseconds(1000));
1750 controller_impl
->UpdateState(true, events
.get());
1752 // The opacity animation should be finished, but should not have generated
1753 // a FINISHED event yet.
1754 EXPECT_EQ(0u, events
->size());
1755 EXPECT_EQ(Animation::FINISHED
,
1756 controller_impl
->GetAnimationById(2)->run_state());
1757 EXPECT_EQ(Animation::RUNNING
,
1758 controller_impl
->GetAnimationById(1)->run_state());
1760 controller_impl
->Animate(kInitialTickTime
+
1761 TimeDelta::FromMilliseconds(2000));
1762 controller_impl
->UpdateState(true, events
.get());
1764 // Both animations should have generated FINISHED events.
1765 EXPECT_EQ(2u, events
->size());
1766 EXPECT_EQ(AnimationEvent::FINISHED
, (*events
)[0].type
);
1767 EXPECT_EQ(AnimationEvent::FINISHED
, (*events
)[1].type
);
1770 // Ensure that when a group has a mix of aborted and finished animations,
1771 // we generate a FINISHED event for the finished animation and an ABORTED
1772 // event for the aborted animation.
1773 TEST(LayerAnimationControllerTest
, FinishedAndAbortedEventsForGroup
) {
1774 scoped_ptr
<AnimationEventsVector
> events(
1775 make_scoped_ptr(new AnimationEventsVector
));
1776 FakeLayerAnimationValueObserver dummy_impl
;
1777 scoped_refptr
<LayerAnimationController
> controller_impl(
1778 LayerAnimationController::Create(0));
1779 controller_impl
->AddValueObserver(&dummy_impl
);
1781 // Add two animations with the same group id.
1782 controller_impl
->AddAnimation(CreateAnimation(
1783 scoped_ptr
<AnimationCurve
>(new FakeTransformTransition(1.0)).Pass(), 1,
1784 Animation::TRANSFORM
));
1785 controller_impl
->AddAnimation(CreateAnimation(
1786 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1787 1, Animation::OPACITY
));
1789 controller_impl
->Animate(kInitialTickTime
);
1790 controller_impl
->UpdateState(true, events
.get());
1792 // Both animations should have started.
1793 EXPECT_EQ(2u, events
->size());
1794 EXPECT_EQ(AnimationEvent::STARTED
, (*events
)[0].type
);
1795 EXPECT_EQ(AnimationEvent::STARTED
, (*events
)[1].type
);
1797 controller_impl
->AbortAnimations(Animation::OPACITY
);
1799 events
.reset(new AnimationEventsVector
);
1800 controller_impl
->Animate(kInitialTickTime
+
1801 TimeDelta::FromMilliseconds(1000));
1802 controller_impl
->UpdateState(true, events
.get());
1804 // We should have exactly 2 events: a FINISHED event for the tranform
1805 // animation, and an ABORTED event for the opacity animation.
1806 EXPECT_EQ(2u, events
->size());
1807 EXPECT_EQ(AnimationEvent::FINISHED
, (*events
)[0].type
);
1808 EXPECT_EQ(Animation::TRANSFORM
, (*events
)[0].target_property
);
1809 EXPECT_EQ(AnimationEvent::ABORTED
, (*events
)[1].type
);
1810 EXPECT_EQ(Animation::OPACITY
, (*events
)[1].target_property
);
1813 TEST(LayerAnimationControllerTest
, HasAnimationThatAffectsScale
) {
1814 scoped_refptr
<LayerAnimationController
> controller_impl(
1815 LayerAnimationController::Create(0));
1817 EXPECT_FALSE(controller_impl
->HasAnimationThatAffectsScale());
1819 controller_impl
->AddAnimation(CreateAnimation(
1820 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1821 1, Animation::OPACITY
));
1823 // Opacity animations don't affect scale.
1824 EXPECT_FALSE(controller_impl
->HasAnimationThatAffectsScale());
1826 scoped_ptr
<KeyframedTransformAnimationCurve
> curve1(
1827 KeyframedTransformAnimationCurve::Create());
1829 TransformOperations operations1
;
1830 curve1
->AddKeyframe(
1831 TransformKeyframe::Create(base::TimeDelta(), operations1
, nullptr));
1832 operations1
.AppendTranslate(10.0, 15.0, 0.0);
1833 curve1
->AddKeyframe(TransformKeyframe::Create(
1834 base::TimeDelta::FromSecondsD(1.0), operations1
, nullptr));
1836 scoped_ptr
<Animation
> animation(
1837 Animation::Create(curve1
.Pass(), 2, 2, Animation::TRANSFORM
));
1838 controller_impl
->AddAnimation(animation
.Pass());
1840 // Translations don't affect scale.
1841 EXPECT_FALSE(controller_impl
->HasAnimationThatAffectsScale());
1843 scoped_ptr
<KeyframedTransformAnimationCurve
> curve2(
1844 KeyframedTransformAnimationCurve::Create());
1846 TransformOperations operations2
;
1847 curve2
->AddKeyframe(
1848 TransformKeyframe::Create(base::TimeDelta(), operations2
, nullptr));
1849 operations2
.AppendScale(2.0, 3.0, 4.0);
1850 curve2
->AddKeyframe(TransformKeyframe::Create(
1851 base::TimeDelta::FromSecondsD(1.0), operations2
, nullptr));
1853 animation
= Animation::Create(curve2
.Pass(), 3, 3, Animation::TRANSFORM
);
1854 controller_impl
->AddAnimation(animation
.Pass());
1856 EXPECT_TRUE(controller_impl
->HasAnimationThatAffectsScale());
1858 controller_impl
->GetAnimationById(3)
1859 ->SetRunState(Animation::FINISHED
, TicksFromSecondsF(0.0));
1861 // Only unfinished animations should be considered by
1862 // HasAnimationThatAffectsScale.
1863 EXPECT_FALSE(controller_impl
->HasAnimationThatAffectsScale());
1866 TEST(LayerAnimationControllerTest
, HasOnlyTranslationTransforms
) {
1867 scoped_refptr
<LayerAnimationController
> controller_impl(
1868 LayerAnimationController::Create(0));
1870 EXPECT_TRUE(controller_impl
->HasOnlyTranslationTransforms());
1872 controller_impl
->AddAnimation(CreateAnimation(
1873 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
1874 1, Animation::OPACITY
));
1876 // Opacity animations aren't non-translation transforms.
1877 EXPECT_TRUE(controller_impl
->HasOnlyTranslationTransforms());
1879 scoped_ptr
<KeyframedTransformAnimationCurve
> curve1(
1880 KeyframedTransformAnimationCurve::Create());
1882 TransformOperations operations1
;
1883 curve1
->AddKeyframe(
1884 TransformKeyframe::Create(base::TimeDelta(), operations1
, nullptr));
1885 operations1
.AppendTranslate(10.0, 15.0, 0.0);
1886 curve1
->AddKeyframe(TransformKeyframe::Create(
1887 base::TimeDelta::FromSecondsD(1.0), operations1
, nullptr));
1889 scoped_ptr
<Animation
> animation(
1890 Animation::Create(curve1
.Pass(), 2, 2, Animation::TRANSFORM
));
1891 controller_impl
->AddAnimation(animation
.Pass());
1893 // The only transform animation we've added is a translation.
1894 EXPECT_TRUE(controller_impl
->HasOnlyTranslationTransforms());
1896 scoped_ptr
<KeyframedTransformAnimationCurve
> curve2(
1897 KeyframedTransformAnimationCurve::Create());
1899 TransformOperations operations2
;
1900 curve2
->AddKeyframe(
1901 TransformKeyframe::Create(base::TimeDelta(), operations2
, nullptr));
1902 operations2
.AppendScale(2.0, 3.0, 4.0);
1903 curve2
->AddKeyframe(TransformKeyframe::Create(
1904 base::TimeDelta::FromSecondsD(1.0), operations2
, nullptr));
1906 animation
= Animation::Create(curve2
.Pass(), 3, 3, Animation::TRANSFORM
);
1907 controller_impl
->AddAnimation(animation
.Pass());
1909 // A scale animation is not a translation.
1910 EXPECT_FALSE(controller_impl
->HasOnlyTranslationTransforms());
1912 controller_impl
->GetAnimationById(3)
1913 ->SetRunState(Animation::FINISHED
, TicksFromSecondsF(0.0));
1915 // Only unfinished animations should be considered by
1916 // HasOnlyTranslationTransforms.
1917 EXPECT_TRUE(controller_impl
->HasOnlyTranslationTransforms());
1920 TEST(LayerAnimationControllerTest
, MaximumTargetScale
) {
1921 scoped_refptr
<LayerAnimationController
> controller_impl(
1922 LayerAnimationController::Create(0));
1924 float max_scale
= 0.f
;
1925 EXPECT_TRUE(controller_impl
->MaximumTargetScale(&max_scale
));
1926 EXPECT_EQ(0.f
, max_scale
);
1928 scoped_ptr
<KeyframedTransformAnimationCurve
> curve1(
1929 KeyframedTransformAnimationCurve::Create());
1931 TransformOperations operations1
;
1932 curve1
->AddKeyframe(
1933 TransformKeyframe::Create(base::TimeDelta(), operations1
, nullptr));
1934 operations1
.AppendScale(2.0, 3.0, 4.0);
1935 curve1
->AddKeyframe(TransformKeyframe::Create(
1936 base::TimeDelta::FromSecondsD(1.0), operations1
, nullptr));
1938 scoped_ptr
<Animation
> animation(
1939 Animation::Create(curve1
.Pass(), 1, 1, Animation::TRANSFORM
));
1940 controller_impl
->AddAnimation(animation
.Pass());
1942 EXPECT_TRUE(controller_impl
->MaximumTargetScale(&max_scale
));
1943 EXPECT_EQ(4.f
, max_scale
);
1945 scoped_ptr
<KeyframedTransformAnimationCurve
> curve2(
1946 KeyframedTransformAnimationCurve::Create());
1948 TransformOperations operations2
;
1949 curve2
->AddKeyframe(
1950 TransformKeyframe::Create(base::TimeDelta(), operations2
, nullptr));
1951 operations2
.AppendScale(6.0, 5.0, 4.0);
1952 curve2
->AddKeyframe(TransformKeyframe::Create(
1953 base::TimeDelta::FromSecondsD(1.0), operations2
, nullptr));
1955 animation
= Animation::Create(curve2
.Pass(), 2, 2, Animation::TRANSFORM
);
1956 controller_impl
->AddAnimation(animation
.Pass());
1958 EXPECT_TRUE(controller_impl
->MaximumTargetScale(&max_scale
));
1959 EXPECT_EQ(6.f
, max_scale
);
1961 scoped_ptr
<KeyframedTransformAnimationCurve
> curve3(
1962 KeyframedTransformAnimationCurve::Create());
1964 TransformOperations operations3
;
1965 curve3
->AddKeyframe(
1966 TransformKeyframe::Create(base::TimeDelta(), operations3
, nullptr));
1967 operations3
.AppendPerspective(6.0);
1968 curve3
->AddKeyframe(TransformKeyframe::Create(
1969 base::TimeDelta::FromSecondsD(1.0), operations3
, nullptr));
1971 animation
= Animation::Create(curve3
.Pass(), 3, 3, Animation::TRANSFORM
);
1972 controller_impl
->AddAnimation(animation
.Pass());
1974 EXPECT_FALSE(controller_impl
->MaximumTargetScale(&max_scale
));
1976 controller_impl
->GetAnimationById(3)
1977 ->SetRunState(Animation::FINISHED
, TicksFromSecondsF(0.0));
1978 controller_impl
->GetAnimationById(2)
1979 ->SetRunState(Animation::FINISHED
, TicksFromSecondsF(0.0));
1981 // Only unfinished animations should be considered by
1982 // MaximumTargetScale.
1983 EXPECT_TRUE(controller_impl
->MaximumTargetScale(&max_scale
));
1984 EXPECT_EQ(4.f
, max_scale
);
1987 TEST(LayerAnimationControllerTest
, MaximumTargetScaleWithDirection
) {
1988 scoped_refptr
<LayerAnimationController
> controller_impl(
1989 LayerAnimationController::Create(0));
1991 scoped_ptr
<KeyframedTransformAnimationCurve
> curve1(
1992 KeyframedTransformAnimationCurve::Create());
1993 TransformOperations operations1
;
1994 operations1
.AppendScale(1.0, 2.0, 3.0);
1995 curve1
->AddKeyframe(
1996 TransformKeyframe::Create(base::TimeDelta(), operations1
, nullptr));
1997 TransformOperations operations2
;
1998 operations2
.AppendScale(4.0, 5.0, 6.0);
1999 curve1
->AddKeyframe(TransformKeyframe::Create(
2000 base::TimeDelta::FromSecondsD(1.0), operations2
, nullptr));
2002 scoped_ptr
<Animation
> animation_owned(
2003 Animation::Create(curve1
.Pass(), 1, 1, Animation::TRANSFORM
));
2004 Animation
* animation
= animation_owned
.get();
2005 controller_impl
->AddAnimation(animation_owned
.Pass());
2007 float max_scale
= 0.f
;
2009 EXPECT_GT(animation
->playback_rate(), 0.0);
2011 // NORMAL direction with positive playback rate.
2012 animation
->set_direction(Animation::DIRECTION_NORMAL
);
2013 EXPECT_TRUE(controller_impl
->MaximumTargetScale(&max_scale
));
2014 EXPECT_EQ(6.f
, max_scale
);
2016 // ALTERNATE direction with positive playback rate.
2017 animation
->set_direction(Animation::DIRECTION_ALTERNATE
);
2018 EXPECT_TRUE(controller_impl
->MaximumTargetScale(&max_scale
));
2019 EXPECT_EQ(6.f
, max_scale
);
2021 // REVERSE direction with positive playback rate.
2022 animation
->set_direction(Animation::DIRECTION_REVERSE
);
2023 EXPECT_TRUE(controller_impl
->MaximumTargetScale(&max_scale
));
2024 EXPECT_EQ(3.f
, max_scale
);
2026 // ALTERNATE reverse direction.
2027 animation
->set_direction(Animation::DIRECTION_REVERSE
);
2028 EXPECT_TRUE(controller_impl
->MaximumTargetScale(&max_scale
));
2029 EXPECT_EQ(3.f
, max_scale
);
2031 animation
->set_playback_rate(-1.0);
2033 // NORMAL direction with negative playback rate.
2034 animation
->set_direction(Animation::DIRECTION_NORMAL
);
2035 EXPECT_TRUE(controller_impl
->MaximumTargetScale(&max_scale
));
2036 EXPECT_EQ(3.f
, max_scale
);
2038 // ALTERNATE direction with negative playback rate.
2039 animation
->set_direction(Animation::DIRECTION_ALTERNATE
);
2040 EXPECT_TRUE(controller_impl
->MaximumTargetScale(&max_scale
));
2041 EXPECT_EQ(3.f
, max_scale
);
2043 // REVERSE direction with negative playback rate.
2044 animation
->set_direction(Animation::DIRECTION_REVERSE
);
2045 EXPECT_TRUE(controller_impl
->MaximumTargetScale(&max_scale
));
2046 EXPECT_EQ(6.f
, max_scale
);
2048 // ALTERNATE reverse direction with negative playback rate.
2049 animation
->set_direction(Animation::DIRECTION_REVERSE
);
2050 EXPECT_TRUE(controller_impl
->MaximumTargetScale(&max_scale
));
2051 EXPECT_EQ(6.f
, max_scale
);
2054 TEST(LayerAnimationControllerTest
, NewlyPushedAnimationWaitsForActivation
) {
2055 scoped_ptr
<AnimationEventsVector
> events(
2056 make_scoped_ptr(new AnimationEventsVector
));
2057 FakeLayerAnimationValueObserver dummy_impl
;
2058 FakeInactiveLayerAnimationValueObserver pending_dummy_impl
;
2059 scoped_refptr
<LayerAnimationController
> controller_impl(
2060 LayerAnimationController::Create(0));
2061 controller_impl
->AddValueObserver(&dummy_impl
);
2062 controller_impl
->AddValueObserver(&pending_dummy_impl
);
2063 FakeLayerAnimationValueObserver dummy
;
2064 scoped_refptr
<LayerAnimationController
> controller(
2065 LayerAnimationController::Create(0));
2066 controller
->AddValueObserver(&dummy
);
2068 EXPECT_FALSE(controller
->needs_to_start_animations_for_testing());
2070 AddOpacityTransitionToController(controller
.get(), 1, 0.5f
, 1.f
, false);
2071 EXPECT_TRUE(controller
->needs_to_start_animations_for_testing());
2073 EXPECT_FALSE(controller_impl
->needs_to_start_animations_for_testing());
2074 controller
->PushAnimationUpdatesTo(controller_impl
.get());
2075 EXPECT_TRUE(controller_impl
->needs_to_start_animations_for_testing());
2077 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
));
2078 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY
,
2079 controller_impl
->GetAnimationById(animation_id
)->run_state());
2080 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
)
2081 ->affects_pending_observers());
2082 EXPECT_FALSE(controller_impl
->GetAnimationById(animation_id
)
2083 ->affects_active_observers());
2085 controller_impl
->Animate(kInitialTickTime
);
2086 EXPECT_FALSE(controller_impl
->needs_to_start_animations_for_testing());
2087 controller_impl
->UpdateState(true, events
.get());
2089 // Since the animation hasn't been activated, it should still be STARTING
2090 // rather than RUNNING.
2091 EXPECT_EQ(Animation::STARTING
,
2092 controller_impl
->GetAnimationById(animation_id
)->run_state());
2094 // Since the animation hasn't been activated, only the pending observer
2095 // should have been ticked.
2096 EXPECT_EQ(0.5f
, pending_dummy_impl
.opacity());
2097 EXPECT_EQ(0.f
, dummy_impl
.opacity());
2099 controller_impl
->ActivateAnimations();
2100 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
)
2101 ->affects_pending_observers());
2102 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
)
2103 ->affects_active_observers());
2105 controller_impl
->Animate(kInitialTickTime
+
2106 TimeDelta::FromMilliseconds(1000));
2107 controller_impl
->UpdateState(true, events
.get());
2109 // Since the animation has been activated, it should have reached the
2110 // RUNNING state and the active observer should start to get ticked.
2111 EXPECT_EQ(Animation::RUNNING
,
2112 controller_impl
->GetAnimationById(animation_id
)->run_state());
2113 EXPECT_EQ(0.5f
, pending_dummy_impl
.opacity());
2114 EXPECT_EQ(0.5f
, dummy_impl
.opacity());
2117 TEST(LayerAnimationControllerTest
, ActivationBetweenAnimateAndUpdateState
) {
2118 scoped_ptr
<AnimationEventsVector
> events(
2119 make_scoped_ptr(new AnimationEventsVector
));
2120 FakeLayerAnimationValueObserver dummy_impl
;
2121 FakeInactiveLayerAnimationValueObserver pending_dummy_impl
;
2122 scoped_refptr
<LayerAnimationController
> controller_impl(
2123 LayerAnimationController::Create(0));
2124 controller_impl
->AddValueObserver(&dummy_impl
);
2125 controller_impl
->AddValueObserver(&pending_dummy_impl
);
2126 FakeLayerAnimationValueObserver dummy
;
2127 scoped_refptr
<LayerAnimationController
> controller(
2128 LayerAnimationController::Create(0));
2129 controller
->AddValueObserver(&dummy
);
2132 AddOpacityTransitionToController(controller
.get(), 1, 0.5f
, 1.f
, true);
2134 controller
->PushAnimationUpdatesTo(controller_impl
.get());
2136 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
));
2137 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY
,
2138 controller_impl
->GetAnimationById(animation_id
)->run_state());
2139 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
)
2140 ->affects_pending_observers());
2141 EXPECT_FALSE(controller_impl
->GetAnimationById(animation_id
)
2142 ->affects_active_observers());
2144 controller_impl
->Animate(kInitialTickTime
);
2146 // Since the animation hasn't been activated, only the pending observer
2147 // should have been ticked.
2148 EXPECT_EQ(0.5f
, pending_dummy_impl
.opacity());
2149 EXPECT_EQ(0.f
, dummy_impl
.opacity());
2151 controller_impl
->ActivateAnimations();
2152 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
)
2153 ->affects_pending_observers());
2154 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
)
2155 ->affects_active_observers());
2157 controller_impl
->UpdateState(true, events
.get());
2159 // Since the animation has been activated, it should have reached the
2161 EXPECT_EQ(Animation::RUNNING
,
2162 controller_impl
->GetAnimationById(animation_id
)->run_state());
2164 controller_impl
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(500));
2166 // Both observers should have been ticked.
2167 EXPECT_EQ(0.75f
, pending_dummy_impl
.opacity());
2168 EXPECT_EQ(0.75f
, dummy_impl
.opacity());
2171 TEST(LayerAnimationControllerTest
, ClippedOpacityValues
) {
2172 FakeLayerAnimationValueObserver dummy
;
2173 scoped_refptr
<LayerAnimationController
> controller(
2174 LayerAnimationController::Create(0));
2175 controller
->AddValueObserver(&dummy
);
2177 AddOpacityTransitionToController(controller
.get(), 1, 1.f
, 2.f
, true);
2179 controller
->Animate(kInitialTickTime
);
2180 EXPECT_EQ(1.f
, dummy
.opacity());
2182 // Opacity values are clipped [0,1]
2183 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1000));
2184 EXPECT_EQ(1.f
, dummy
.opacity());
2187 TEST(LayerAnimationControllerTest
, ClippedNegativeOpacityValues
) {
2188 FakeLayerAnimationValueObserver dummy
;
2189 scoped_refptr
<LayerAnimationController
> controller(
2190 LayerAnimationController::Create(0));
2191 controller
->AddValueObserver(&dummy
);
2193 AddOpacityTransitionToController(controller
.get(), 1, 0.f
, -2.f
, true);
2195 controller
->Animate(kInitialTickTime
);
2196 EXPECT_EQ(0.f
, dummy
.opacity());
2198 // Opacity values are clipped [0,1]
2199 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(1000));
2200 EXPECT_EQ(0.f
, dummy
.opacity());
2203 TEST(LayerAnimationControllerTest
, PushedDeletedAnimationWaitsForActivation
) {
2204 scoped_ptr
<AnimationEventsVector
> events(
2205 make_scoped_ptr(new AnimationEventsVector
));
2206 FakeLayerAnimationValueObserver dummy_impl
;
2207 FakeInactiveLayerAnimationValueObserver pending_dummy_impl
;
2208 scoped_refptr
<LayerAnimationController
> controller_impl(
2209 LayerAnimationController::Create(0));
2210 controller_impl
->AddValueObserver(&dummy_impl
);
2211 controller_impl
->AddValueObserver(&pending_dummy_impl
);
2212 FakeLayerAnimationValueObserver dummy
;
2213 scoped_refptr
<LayerAnimationController
> controller(
2214 LayerAnimationController::Create(0));
2215 controller
->AddValueObserver(&dummy
);
2218 AddOpacityTransitionToController(controller
.get(), 1, 0.5f
, 1.f
, true);
2220 controller
->PushAnimationUpdatesTo(controller_impl
.get());
2221 controller_impl
->ActivateAnimations();
2222 controller_impl
->Animate(kInitialTickTime
);
2223 controller_impl
->UpdateState(true, events
.get());
2224 EXPECT_EQ(Animation::RUNNING
,
2225 controller_impl
->GetAnimationById(animation_id
)->run_state());
2226 EXPECT_EQ(0.5f
, pending_dummy_impl
.opacity());
2227 EXPECT_EQ(0.5f
, dummy_impl
.opacity());
2229 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
)
2230 ->affects_pending_observers());
2231 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
)
2232 ->affects_active_observers());
2234 // Delete the animation on the main-thread controller.
2235 controller
->RemoveAnimation(
2236 controller
->GetAnimation(Animation::OPACITY
)->id());
2237 controller
->PushAnimationUpdatesTo(controller_impl
.get());
2239 // The animation should no longer affect pending observers.
2240 EXPECT_FALSE(controller_impl
->GetAnimationById(animation_id
)
2241 ->affects_pending_observers());
2242 EXPECT_TRUE(controller_impl
->GetAnimationById(animation_id
)
2243 ->affects_active_observers());
2245 controller_impl
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(500));
2246 controller_impl
->UpdateState(true, events
.get());
2248 // Only the active observer should have been ticked.
2249 EXPECT_EQ(0.5f
, pending_dummy_impl
.opacity());
2250 EXPECT_EQ(0.75f
, dummy_impl
.opacity());
2252 controller_impl
->ActivateAnimations();
2254 // Activation should cause the animation to be deleted.
2255 EXPECT_FALSE(controller_impl
->has_any_animation());
2258 // Tests that an animation that affects only active observers won't block
2259 // an animation that affects only pending observers from starting.
2260 TEST(LayerAnimationControllerTest
, StartAnimationsAffectingDifferentObservers
) {
2261 scoped_ptr
<AnimationEventsVector
> events(
2262 make_scoped_ptr(new AnimationEventsVector
));
2263 FakeLayerAnimationValueObserver dummy_impl
;
2264 FakeInactiveLayerAnimationValueObserver pending_dummy_impl
;
2265 scoped_refptr
<LayerAnimationController
> controller_impl(
2266 LayerAnimationController::Create(0));
2267 controller_impl
->AddValueObserver(&dummy_impl
);
2268 controller_impl
->AddValueObserver(&pending_dummy_impl
);
2269 FakeLayerAnimationValueObserver dummy
;
2270 scoped_refptr
<LayerAnimationController
> controller(
2271 LayerAnimationController::Create(0));
2272 controller
->AddValueObserver(&dummy
);
2274 int first_animation_id
=
2275 AddOpacityTransitionToController(controller
.get(), 1, 0.f
, 1.f
, true);
2277 controller
->PushAnimationUpdatesTo(controller_impl
.get());
2278 controller_impl
->ActivateAnimations();
2279 controller_impl
->Animate(kInitialTickTime
);
2280 controller_impl
->UpdateState(true, events
.get());
2282 // Remove the first animation from the main-thread controller, and add a
2283 // new animation affecting the same property.
2284 controller
->RemoveAnimation(
2285 controller
->GetAnimation(Animation::OPACITY
)->id());
2286 int second_animation_id
=
2287 AddOpacityTransitionToController(controller
.get(), 1, 1.f
, 0.5f
, true);
2288 controller
->PushAnimationUpdatesTo(controller_impl
.get());
2290 // The original animation should only affect active observers, and the new
2291 // animation should only affect pending observers.
2292 EXPECT_FALSE(controller_impl
->GetAnimationById(first_animation_id
)
2293 ->affects_pending_observers());
2294 EXPECT_TRUE(controller_impl
->GetAnimationById(first_animation_id
)
2295 ->affects_active_observers());
2296 EXPECT_TRUE(controller_impl
->GetAnimationById(second_animation_id
)
2297 ->affects_pending_observers());
2298 EXPECT_FALSE(controller_impl
->GetAnimationById(second_animation_id
)
2299 ->affects_active_observers());
2301 controller_impl
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(500));
2302 controller_impl
->UpdateState(true, events
.get());
2304 // The original animation should still be running, and the new animation
2305 // should be starting.
2306 EXPECT_EQ(Animation::RUNNING
,
2307 controller_impl
->GetAnimationById(first_animation_id
)->run_state());
2309 Animation::STARTING
,
2310 controller_impl
->GetAnimationById(second_animation_id
)->run_state());
2312 // The active observer should have been ticked by the original animation,
2313 // and the pending observer should have been ticked by the new animation.
2314 EXPECT_EQ(1.f
, pending_dummy_impl
.opacity());
2315 EXPECT_EQ(0.5f
, dummy_impl
.opacity());
2317 controller_impl
->ActivateAnimations();
2319 // The original animation should have been deleted, and the new animation
2320 // should now affect both observers.
2321 EXPECT_FALSE(controller_impl
->GetAnimationById(first_animation_id
));
2322 EXPECT_TRUE(controller_impl
->GetAnimationById(second_animation_id
)
2323 ->affects_pending_observers());
2324 EXPECT_TRUE(controller_impl
->GetAnimationById(second_animation_id
)
2325 ->affects_active_observers());
2327 controller_impl
->Animate(kInitialTickTime
+
2328 TimeDelta::FromMilliseconds(1000));
2329 controller_impl
->UpdateState(true, events
.get());
2331 // The new animation should be running, and the active observer should have
2332 // been ticked at the new animation's starting point.
2335 controller_impl
->GetAnimationById(second_animation_id
)->run_state());
2336 EXPECT_EQ(1.f
, pending_dummy_impl
.opacity());
2337 EXPECT_EQ(1.f
, dummy_impl
.opacity());
2340 TEST(LayerAnimationControllerTest
, TestIsAnimatingProperty
) {
2341 FakeLayerAnimationValueObserver dummy
;
2342 scoped_refptr
<LayerAnimationController
> controller(
2343 LayerAnimationController::Create(0));
2344 controller
->AddValueObserver(&dummy
);
2346 scoped_ptr
<Animation
> animation(CreateAnimation(
2347 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
2348 1, Animation::OPACITY
));
2349 controller
->AddAnimation(animation
.Pass());
2350 controller
->Animate(kInitialTickTime
);
2351 EXPECT_TRUE(controller
->IsAnimatingProperty(Animation::OPACITY
));
2352 controller
->UpdateState(true, nullptr);
2353 EXPECT_TRUE(controller
->HasActiveAnimation());
2354 EXPECT_TRUE(controller
->IsAnimatingProperty(Animation::OPACITY
));
2355 EXPECT_FALSE(controller
->IsAnimatingProperty(Animation::FILTER
));
2356 EXPECT_EQ(0.f
, dummy
.opacity());
2359 TEST(LayerAnimationControllerTest
, TestIsAnimatingPropertyTimeOffsetFillMode
) {
2360 FakeLayerAnimationValueObserver dummy
;
2361 scoped_refptr
<LayerAnimationController
> controller(
2362 LayerAnimationController::Create(0));
2363 controller
->AddValueObserver(&dummy
);
2365 scoped_ptr
<Animation
> animation(CreateAnimation(
2366 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
2367 1, Animation::OPACITY
));
2368 animation
->set_fill_mode(Animation::FILL_MODE_NONE
);
2369 animation
->set_time_offset(TimeDelta::FromMilliseconds(-2000));
2370 controller
->AddAnimation(animation
.Pass());
2372 controller
->Animate(kInitialTickTime
);
2373 controller
->UpdateState(true, nullptr);
2374 EXPECT_FALSE(controller
->IsAnimatingProperty(Animation::OPACITY
));
2375 EXPECT_TRUE(controller
->HasActiveAnimation());
2376 EXPECT_FALSE(controller
->IsAnimatingProperty(Animation::OPACITY
));
2377 EXPECT_FALSE(controller
->IsAnimatingProperty(Animation::FILTER
));
2379 controller
->Animate(kInitialTickTime
+ TimeDelta::FromMilliseconds(2000));
2380 controller
->UpdateState(true, nullptr);
2381 EXPECT_TRUE(controller
->IsAnimatingProperty(Animation::OPACITY
));