Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: cc/animation/layer_animation_controller_unittest.cc

Issue 1866203004: Convert //cc from scoped_ptr to std::unique_ptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scopedptrcc: rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/animation/layer_animation_controller.h" 5 #include "cc/animation/layer_animation_controller.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/memory/ptr_util.h"
9 #include "cc/animation/animation.h" 10 #include "cc/animation/animation.h"
10 #include "cc/animation/animation_curve.h" 11 #include "cc/animation/animation_curve.h"
11 #include "cc/animation/animation_delegate.h" 12 #include "cc/animation/animation_delegate.h"
12 #include "cc/animation/animation_events.h" 13 #include "cc/animation/animation_events.h"
13 #include "cc/animation/animation_registrar.h" 14 #include "cc/animation/animation_registrar.h"
14 #include "cc/animation/keyframed_animation_curve.h" 15 #include "cc/animation/keyframed_animation_curve.h"
15 #include "cc/animation/scroll_offset_animation_curve.h" 16 #include "cc/animation/scroll_offset_animation_curve.h"
16 #include "cc/animation/transform_operations.h" 17 #include "cc/animation/transform_operations.h"
17 #include "cc/test/animation_test_common.h" 18 #include "cc/test/animation_test_common.h"
18 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 10 matching lines...) Expand all
29 static base::TimeTicks TicksFromSecondsF(double seconds) { 30 static base::TimeTicks TicksFromSecondsF(double seconds) {
30 return base::TimeTicks::FromInternalValue(seconds * 31 return base::TimeTicks::FromInternalValue(seconds *
31 base::Time::kMicrosecondsPerSecond); 32 base::Time::kMicrosecondsPerSecond);
32 } 33 }
33 34
34 // A LayerAnimationController cannot be ticked at 0.0, since an animation 35 // A LayerAnimationController cannot be ticked at 0.0, since an animation
35 // with start time 0.0 is treated as an animation whose start time has 36 // with start time 0.0 is treated as an animation whose start time has
36 // not yet been set. 37 // not yet been set.
37 const TimeTicks kInitialTickTime = TicksFromSecondsF(1.0); 38 const TimeTicks kInitialTickTime = TicksFromSecondsF(1.0);
38 39
39 scoped_ptr<Animation> CreateAnimation(scoped_ptr<AnimationCurve> curve, 40 std::unique_ptr<Animation> CreateAnimation(
40 int group_id, 41 std::unique_ptr<AnimationCurve> curve,
41 TargetProperty::Type property) { 42 int group_id,
43 TargetProperty::Type property) {
42 return Animation::Create(std::move(curve), 0, group_id, property); 44 return Animation::Create(std::move(curve), 0, group_id, property);
43 } 45 }
44 46
45 TEST(LayerAnimationControllerTest, SyncNewAnimation) { 47 TEST(LayerAnimationControllerTest, SyncNewAnimation) {
46 FakeLayerAnimationValueObserver dummy_impl; 48 FakeLayerAnimationValueObserver dummy_impl;
47 scoped_refptr<LayerAnimationController> controller_impl( 49 scoped_refptr<LayerAnimationController> controller_impl(
48 LayerAnimationController::Create(0)); 50 LayerAnimationController::Create(0));
49 controller_impl->AddValueObserver(&dummy_impl); 51 controller_impl->AddValueObserver(&dummy_impl);
50 FakeLayerAnimationValueObserver dummy; 52 FakeLayerAnimationValueObserver dummy;
51 scoped_refptr<LayerAnimationController> controller( 53 scoped_refptr<LayerAnimationController> controller(
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); 92 EXPECT_FALSE(controller->needs_to_start_animations_for_testing());
91 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing()); 93 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing());
92 94
93 gfx::ScrollOffset initial_value(100.f, 300.f); 95 gfx::ScrollOffset initial_value(100.f, 300.f);
94 gfx::ScrollOffset provider_initial_value(150.f, 300.f); 96 gfx::ScrollOffset provider_initial_value(150.f, 300.f);
95 gfx::ScrollOffset target_value(300.f, 200.f); 97 gfx::ScrollOffset target_value(300.f, 200.f);
96 98
97 dummy_provider_impl.set_scroll_offset(provider_initial_value); 99 dummy_provider_impl.set_scroll_offset(provider_initial_value);
98 100
99 // Animation with initial value set. 101 // Animation with initial value set.
100 scoped_ptr<ScrollOffsetAnimationCurve> curve_fixed( 102 std::unique_ptr<ScrollOffsetAnimationCurve> curve_fixed(
101 ScrollOffsetAnimationCurve::Create(target_value, 103 ScrollOffsetAnimationCurve::Create(target_value,
102 EaseInOutTimingFunction::Create())); 104 EaseInOutTimingFunction::Create()));
103 curve_fixed->SetInitialValue(initial_value); 105 curve_fixed->SetInitialValue(initial_value);
104 scoped_ptr<Animation> animation_fixed( 106 std::unique_ptr<Animation> animation_fixed(
105 Animation::Create(std::move(curve_fixed), 1 /* animation_id */, 0, 107 Animation::Create(std::move(curve_fixed), 1 /* animation_id */, 0,
106 TargetProperty::SCROLL_OFFSET)); 108 TargetProperty::SCROLL_OFFSET));
107 controller->AddAnimation(std::move(animation_fixed)); 109 controller->AddAnimation(std::move(animation_fixed));
108 controller->PushAnimationUpdatesTo(controller_impl.get()); 110 controller->PushAnimationUpdatesTo(controller_impl.get());
109 EXPECT_VECTOR2DF_EQ(initial_value, controller_impl->GetAnimationById(1) 111 EXPECT_VECTOR2DF_EQ(initial_value, controller_impl->GetAnimationById(1)
110 ->curve() 112 ->curve()
111 ->ToScrollOffsetAnimationCurve() 113 ->ToScrollOffsetAnimationCurve()
112 ->GetValue(base::TimeDelta())); 114 ->GetValue(base::TimeDelta()));
113 115
114 // Animation without initial value set. 116 // Animation without initial value set.
115 scoped_ptr<ScrollOffsetAnimationCurve> curve( 117 std::unique_ptr<ScrollOffsetAnimationCurve> curve(
116 ScrollOffsetAnimationCurve::Create(target_value, 118 ScrollOffsetAnimationCurve::Create(target_value,
117 EaseInOutTimingFunction::Create())); 119 EaseInOutTimingFunction::Create()));
118 scoped_ptr<Animation> animation( 120 std::unique_ptr<Animation> animation(
119 Animation::Create(std::move(curve), 2 /* animation id */, 0, 121 Animation::Create(std::move(curve), 2 /* animation id */, 0,
120 TargetProperty::SCROLL_OFFSET)); 122 TargetProperty::SCROLL_OFFSET));
121 controller->AddAnimation(std::move(animation)); 123 controller->AddAnimation(std::move(animation));
122 controller->PushAnimationUpdatesTo(controller_impl.get()); 124 controller->PushAnimationUpdatesTo(controller_impl.get());
123 EXPECT_VECTOR2DF_EQ(provider_initial_value, 125 EXPECT_VECTOR2DF_EQ(provider_initial_value,
124 controller_impl->GetAnimationById(2) 126 controller_impl->GetAnimationById(2)
125 ->curve() 127 ->curve()
126 ->ToScrollOffsetAnimationCurve() 128 ->ToScrollOffsetAnimationCurve()
127 ->GetValue(base::TimeDelta())); 129 ->GetValue(base::TimeDelta()));
128 } 130 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); 210 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
209 controller->UpdateState(true, nullptr); 211 controller->UpdateState(true, nullptr);
210 EXPECT_EQ(start_time, 212 EXPECT_EQ(start_time,
211 controller->GetAnimationById(animation_id)->start_time()); 213 controller->GetAnimationById(animation_id)->start_time());
212 EXPECT_EQ(controller->GetAnimationById(animation_id)->start_time(), 214 EXPECT_EQ(controller->GetAnimationById(animation_id)->start_time(),
213 controller_impl->GetAnimationById(animation_id)->start_time()); 215 controller_impl->GetAnimationById(animation_id)->start_time());
214 } 216 }
215 217
216 // Tests that controllers activate and deactivate as expected. 218 // Tests that controllers activate and deactivate as expected.
217 TEST(LayerAnimationControllerTest, Activation) { 219 TEST(LayerAnimationControllerTest, Activation) {
218 scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::Create(); 220 std::unique_ptr<AnimationRegistrar> registrar = AnimationRegistrar::Create();
219 scoped_ptr<AnimationRegistrar> registrar_impl = AnimationRegistrar::Create(); 221 std::unique_ptr<AnimationRegistrar> registrar_impl =
222 AnimationRegistrar::Create();
220 223
221 FakeLayerAnimationValueObserver dummy_impl; 224 FakeLayerAnimationValueObserver dummy_impl;
222 scoped_refptr<LayerAnimationController> controller_impl( 225 scoped_refptr<LayerAnimationController> controller_impl(
223 LayerAnimationController::Create(0)); 226 LayerAnimationController::Create(0));
224 controller_impl->AddValueObserver(&dummy_impl); 227 controller_impl->AddValueObserver(&dummy_impl);
225 FakeLayerAnimationValueObserver dummy; 228 FakeLayerAnimationValueObserver dummy;
226 scoped_refptr<LayerAnimationController> controller( 229 scoped_refptr<LayerAnimationController> controller(
227 LayerAnimationController::Create(0)); 230 LayerAnimationController::Create(0));
228 controller->AddValueObserver(&dummy); 231 controller->AddValueObserver(&dummy);
229 scoped_ptr<AnimationEvents> events = registrar->CreateEvents(); 232 std::unique_ptr<AnimationEvents> events = registrar->CreateEvents();
230 233
231 controller->SetAnimationRegistrar(registrar.get()); 234 controller->SetAnimationRegistrar(registrar.get());
232 controller_impl->SetAnimationRegistrar(registrar_impl.get()); 235 controller_impl->SetAnimationRegistrar(registrar_impl.get());
233 EXPECT_EQ(1u, registrar->all_animation_controllers_for_testing().size()); 236 EXPECT_EQ(1u, registrar->all_animation_controllers_for_testing().size());
234 EXPECT_EQ(1u, registrar_impl->all_animation_controllers_for_testing().size()); 237 EXPECT_EQ(1u, registrar_impl->all_animation_controllers_for_testing().size());
235 238
236 // Initially, both controllers should be inactive. 239 // Initially, both controllers should be inactive.
237 EXPECT_EQ(0u, registrar->active_animation_controllers_for_testing().size()); 240 EXPECT_EQ(0u, registrar->active_animation_controllers_for_testing().size());
238 EXPECT_EQ(0u, 241 EXPECT_EQ(0u,
239 registrar_impl->active_animation_controllers_for_testing().size()); 242 registrar_impl->active_animation_controllers_for_testing().size());
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 383
381 TEST(LayerAnimationControllerTest, DoNotSyncFinishedAnimation) { 384 TEST(LayerAnimationControllerTest, DoNotSyncFinishedAnimation) {
382 FakeLayerAnimationValueObserver dummy_impl; 385 FakeLayerAnimationValueObserver dummy_impl;
383 scoped_refptr<LayerAnimationController> controller_impl( 386 scoped_refptr<LayerAnimationController> controller_impl(
384 LayerAnimationController::Create(0)); 387 LayerAnimationController::Create(0));
385 controller_impl->AddValueObserver(&dummy_impl); 388 controller_impl->AddValueObserver(&dummy_impl);
386 FakeLayerAnimationValueObserver dummy; 389 FakeLayerAnimationValueObserver dummy;
387 scoped_refptr<LayerAnimationController> controller( 390 scoped_refptr<LayerAnimationController> controller(
388 LayerAnimationController::Create(0)); 391 LayerAnimationController::Create(0));
389 controller->AddValueObserver(&dummy); 392 controller->AddValueObserver(&dummy);
390 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 393 std::unique_ptr<AnimationEvents> events(
394 base::WrapUnique(new AnimationEvents));
391 395
392 EXPECT_FALSE(controller_impl->GetAnimation(TargetProperty::OPACITY)); 396 EXPECT_FALSE(controller_impl->GetAnimation(TargetProperty::OPACITY));
393 397
394 int animation_id = 398 int animation_id =
395 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); 399 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false);
396 400
397 controller->PushAnimationUpdatesTo(controller_impl.get()); 401 controller->PushAnimationUpdatesTo(controller_impl.get());
398 controller_impl->ActivateAnimations(); 402 controller_impl->ActivateAnimations();
399 403
400 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); 404 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id));
(...skipping 25 matching lines...) Expand all
426 controller_impl->ActivateAnimations(); 430 controller_impl->ActivateAnimations();
427 EXPECT_FALSE(controller->GetAnimationById(animation_id)); 431 EXPECT_FALSE(controller->GetAnimationById(animation_id));
428 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)); 432 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id));
429 } 433 }
430 434
431 // Ensure that a finished animation is eventually deleted by both the 435 // Ensure that a finished animation is eventually deleted by both the
432 // main-thread and the impl-thread controllers. 436 // main-thread and the impl-thread controllers.
433 TEST(LayerAnimationControllerTest, AnimationsAreDeleted) { 437 TEST(LayerAnimationControllerTest, AnimationsAreDeleted) {
434 FakeLayerAnimationValueObserver dummy; 438 FakeLayerAnimationValueObserver dummy;
435 FakeLayerAnimationValueObserver dummy_impl; 439 FakeLayerAnimationValueObserver dummy_impl;
436 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 440 std::unique_ptr<AnimationEvents> events(
441 base::WrapUnique(new AnimationEvents));
437 scoped_refptr<LayerAnimationController> controller( 442 scoped_refptr<LayerAnimationController> controller(
438 LayerAnimationController::Create(0)); 443 LayerAnimationController::Create(0));
439 scoped_refptr<LayerAnimationController> controller_impl( 444 scoped_refptr<LayerAnimationController> controller_impl(
440 LayerAnimationController::Create(0)); 445 LayerAnimationController::Create(0));
441 controller->AddValueObserver(&dummy); 446 controller->AddValueObserver(&dummy);
442 controller_impl->AddValueObserver(&dummy_impl); 447 controller_impl->AddValueObserver(&dummy_impl);
443 448
444 AddOpacityTransitionToController(controller.get(), 1.0, 0.0f, 1.0f, false); 449 AddOpacityTransitionToController(controller.get(), 1.0, 0.0f, 1.0f, false);
445 controller->Animate(kInitialTickTime); 450 controller->Animate(kInitialTickTime);
446 controller->UpdateState(true, nullptr); 451 controller->UpdateState(true, nullptr);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 const AnimationEvents* events) { 503 const AnimationEvents* events) {
499 const AnimationEvent* event = 0; 504 const AnimationEvent* event = 0;
500 for (size_t i = 0; i < events->events_.size(); ++i) 505 for (size_t i = 0; i < events->events_.size(); ++i)
501 if (events->events_[i].type == AnimationEvent::PROPERTY_UPDATE) 506 if (events->events_[i].type == AnimationEvent::PROPERTY_UPDATE)
502 event = &events->events_[i]; 507 event = &events->events_[i];
503 508
504 return event; 509 return event;
505 } 510 }
506 511
507 TEST(LayerAnimationControllerTest, TrivialTransition) { 512 TEST(LayerAnimationControllerTest, TrivialTransition) {
508 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 513 std::unique_ptr<AnimationEvents> events(
514 base::WrapUnique(new AnimationEvents));
509 FakeLayerAnimationValueObserver dummy; 515 FakeLayerAnimationValueObserver dummy;
510 scoped_refptr<LayerAnimationController> controller( 516 scoped_refptr<LayerAnimationController> controller(
511 LayerAnimationController::Create(0)); 517 LayerAnimationController::Create(0));
512 controller->AddValueObserver(&dummy); 518 controller->AddValueObserver(&dummy);
513 519
514 scoped_ptr<Animation> to_add(CreateAnimation( 520 std::unique_ptr<Animation> to_add(CreateAnimation(
515 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, 521 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
516 TargetProperty::OPACITY)); 522 1, TargetProperty::OPACITY));
517 523
518 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); 524 EXPECT_FALSE(controller->needs_to_start_animations_for_testing());
519 controller->AddAnimation(std::move(to_add)); 525 controller->AddAnimation(std::move(to_add));
520 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); 526 EXPECT_TRUE(controller->needs_to_start_animations_for_testing());
521 controller->Animate(kInitialTickTime); 527 controller->Animate(kInitialTickTime);
522 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); 528 EXPECT_FALSE(controller->needs_to_start_animations_for_testing());
523 controller->UpdateState(true, events.get()); 529 controller->UpdateState(true, events.get());
524 EXPECT_TRUE(controller->HasActiveAnimation()); 530 EXPECT_TRUE(controller->HasActiveAnimation());
525 EXPECT_EQ(0.f, dummy.opacity()); 531 EXPECT_EQ(0.f, dummy.opacity());
526 // A non-impl-only animation should not generate property updates. 532 // A non-impl-only animation should not generate property updates.
527 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); 533 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get());
528 EXPECT_FALSE(event); 534 EXPECT_FALSE(event);
529 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); 535 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
530 controller->UpdateState(true, events.get()); 536 controller->UpdateState(true, events.get());
531 EXPECT_EQ(1.f, dummy.opacity()); 537 EXPECT_EQ(1.f, dummy.opacity());
532 EXPECT_FALSE(controller->HasActiveAnimation()); 538 EXPECT_FALSE(controller->HasActiveAnimation());
533 event = GetMostRecentPropertyUpdateEvent(events.get()); 539 event = GetMostRecentPropertyUpdateEvent(events.get());
534 EXPECT_FALSE(event); 540 EXPECT_FALSE(event);
535 } 541 }
536 542
537 TEST(LayerAnimationControllerTest, TrivialTransitionOnImpl) { 543 TEST(LayerAnimationControllerTest, TrivialTransitionOnImpl) {
538 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 544 std::unique_ptr<AnimationEvents> events(
545 base::WrapUnique(new AnimationEvents));
539 FakeLayerAnimationValueObserver dummy_impl; 546 FakeLayerAnimationValueObserver dummy_impl;
540 scoped_refptr<LayerAnimationController> controller_impl( 547 scoped_refptr<LayerAnimationController> controller_impl(
541 LayerAnimationController::Create(0)); 548 LayerAnimationController::Create(0));
542 controller_impl->AddValueObserver(&dummy_impl); 549 controller_impl->AddValueObserver(&dummy_impl);
543 550
544 scoped_ptr<Animation> to_add(CreateAnimation( 551 std::unique_ptr<Animation> to_add(CreateAnimation(
545 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, 552 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
546 TargetProperty::OPACITY)); 553 1, TargetProperty::OPACITY));
547 to_add->set_is_impl_only(true); 554 to_add->set_is_impl_only(true);
548 555
549 controller_impl->AddAnimation(std::move(to_add)); 556 controller_impl->AddAnimation(std::move(to_add));
550 controller_impl->Animate(kInitialTickTime); 557 controller_impl->Animate(kInitialTickTime);
551 controller_impl->UpdateState(true, events.get()); 558 controller_impl->UpdateState(true, events.get());
552 EXPECT_TRUE(controller_impl->HasActiveAnimation()); 559 EXPECT_TRUE(controller_impl->HasActiveAnimation());
553 EXPECT_EQ(0.f, dummy_impl.opacity()); 560 EXPECT_EQ(0.f, dummy_impl.opacity());
554 EXPECT_EQ(1u, events->events_.size()); 561 EXPECT_EQ(1u, events->events_.size());
555 const AnimationEvent* start_opacity_event = 562 const AnimationEvent* start_opacity_event =
556 GetMostRecentPropertyUpdateEvent(events.get()); 563 GetMostRecentPropertyUpdateEvent(events.get());
557 EXPECT_EQ(0.f, start_opacity_event->opacity); 564 EXPECT_EQ(0.f, start_opacity_event->opacity);
558 565
559 controller_impl->Animate(kInitialTickTime + 566 controller_impl->Animate(kInitialTickTime +
560 TimeDelta::FromMilliseconds(1000)); 567 TimeDelta::FromMilliseconds(1000));
561 controller_impl->UpdateState(true, events.get()); 568 controller_impl->UpdateState(true, events.get());
562 EXPECT_EQ(1.f, dummy_impl.opacity()); 569 EXPECT_EQ(1.f, dummy_impl.opacity());
563 EXPECT_FALSE(controller_impl->HasActiveAnimation()); 570 EXPECT_FALSE(controller_impl->HasActiveAnimation());
564 EXPECT_EQ(2u, events->events_.size()); 571 EXPECT_EQ(2u, events->events_.size());
565 const AnimationEvent* end_opacity_event = 572 const AnimationEvent* end_opacity_event =
566 GetMostRecentPropertyUpdateEvent(events.get()); 573 GetMostRecentPropertyUpdateEvent(events.get());
567 EXPECT_EQ(1.f, end_opacity_event->opacity); 574 EXPECT_EQ(1.f, end_opacity_event->opacity);
568 } 575 }
569 576
570 TEST(LayerAnimationControllerTest, TrivialTransformOnImpl) { 577 TEST(LayerAnimationControllerTest, TrivialTransformOnImpl) {
571 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 578 std::unique_ptr<AnimationEvents> events(
579 base::WrapUnique(new AnimationEvents));
572 FakeLayerAnimationValueObserver dummy_impl; 580 FakeLayerAnimationValueObserver dummy_impl;
573 scoped_refptr<LayerAnimationController> controller_impl( 581 scoped_refptr<LayerAnimationController> controller_impl(
574 LayerAnimationController::Create(0)); 582 LayerAnimationController::Create(0));
575 controller_impl->AddValueObserver(&dummy_impl); 583 controller_impl->AddValueObserver(&dummy_impl);
576 584
577 // Choose different values for x and y to avoid coincidental values in the 585 // Choose different values for x and y to avoid coincidental values in the
578 // observed transforms. 586 // observed transforms.
579 const float delta_x = 3; 587 const float delta_x = 3;
580 const float delta_y = 4; 588 const float delta_y = 4;
581 589
582 scoped_ptr<KeyframedTransformAnimationCurve> curve( 590 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
583 KeyframedTransformAnimationCurve::Create()); 591 KeyframedTransformAnimationCurve::Create());
584 592
585 // Create simple TRANSFORM animation. 593 // Create simple TRANSFORM animation.
586 TransformOperations operations; 594 TransformOperations operations;
587 curve->AddKeyframe( 595 curve->AddKeyframe(
588 TransformKeyframe::Create(base::TimeDelta(), operations, nullptr)); 596 TransformKeyframe::Create(base::TimeDelta(), operations, nullptr));
589 operations.AppendTranslate(delta_x, delta_y, 0); 597 operations.AppendTranslate(delta_x, delta_y, 0);
590 curve->AddKeyframe(TransformKeyframe::Create( 598 curve->AddKeyframe(TransformKeyframe::Create(
591 base::TimeDelta::FromSecondsD(1.0), operations, nullptr)); 599 base::TimeDelta::FromSecondsD(1.0), operations, nullptr));
592 600
593 scoped_ptr<Animation> animation( 601 std::unique_ptr<Animation> animation(
594 Animation::Create(std::move(curve), 1, 0, TargetProperty::TRANSFORM)); 602 Animation::Create(std::move(curve), 1, 0, TargetProperty::TRANSFORM));
595 animation->set_is_impl_only(true); 603 animation->set_is_impl_only(true);
596 controller_impl->AddAnimation(std::move(animation)); 604 controller_impl->AddAnimation(std::move(animation));
597 605
598 // Run animation. 606 // Run animation.
599 controller_impl->Animate(kInitialTickTime); 607 controller_impl->Animate(kInitialTickTime);
600 controller_impl->UpdateState(true, events.get()); 608 controller_impl->UpdateState(true, events.get());
601 EXPECT_TRUE(controller_impl->HasActiveAnimation()); 609 EXPECT_TRUE(controller_impl->HasActiveAnimation());
602 EXPECT_EQ(gfx::Transform(), dummy_impl.transform()); 610 EXPECT_EQ(gfx::Transform(), dummy_impl.transform());
603 EXPECT_EQ(1u, events->events_.size()); 611 EXPECT_EQ(1u, events->events_.size());
(...skipping 12 matching lines...) Expand all
616 EXPECT_EQ(expected_transform, dummy_impl.transform()); 624 EXPECT_EQ(expected_transform, dummy_impl.transform());
617 EXPECT_FALSE(controller_impl->HasActiveAnimation()); 625 EXPECT_FALSE(controller_impl->HasActiveAnimation());
618 EXPECT_EQ(2u, events->events_.size()); 626 EXPECT_EQ(2u, events->events_.size());
619 const AnimationEvent* end_transform_event = 627 const AnimationEvent* end_transform_event =
620 GetMostRecentPropertyUpdateEvent(events.get()); 628 GetMostRecentPropertyUpdateEvent(events.get());
621 EXPECT_EQ(expected_transform, end_transform_event->transform); 629 EXPECT_EQ(expected_transform, end_transform_event->transform);
622 EXPECT_TRUE(end_transform_event->is_impl_only); 630 EXPECT_TRUE(end_transform_event->is_impl_only);
623 } 631 }
624 632
625 TEST(LayerAnimationControllerTest, FilterTransition) { 633 TEST(LayerAnimationControllerTest, FilterTransition) {
626 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 634 std::unique_ptr<AnimationEvents> events(
635 base::WrapUnique(new AnimationEvents));
627 FakeLayerAnimationValueObserver dummy; 636 FakeLayerAnimationValueObserver dummy;
628 scoped_refptr<LayerAnimationController> controller( 637 scoped_refptr<LayerAnimationController> controller(
629 LayerAnimationController::Create(0)); 638 LayerAnimationController::Create(0));
630 controller->AddValueObserver(&dummy); 639 controller->AddValueObserver(&dummy);
631 640
632 scoped_ptr<KeyframedFilterAnimationCurve> curve( 641 std::unique_ptr<KeyframedFilterAnimationCurve> curve(
633 KeyframedFilterAnimationCurve::Create()); 642 KeyframedFilterAnimationCurve::Create());
634 643
635 FilterOperations start_filters; 644 FilterOperations start_filters;
636 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f)); 645 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f));
637 curve->AddKeyframe( 646 curve->AddKeyframe(
638 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); 647 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr));
639 FilterOperations end_filters; 648 FilterOperations end_filters;
640 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f)); 649 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f));
641 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 650 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
642 end_filters, nullptr)); 651 end_filters, nullptr));
643 652
644 scoped_ptr<Animation> animation( 653 std::unique_ptr<Animation> animation(
645 Animation::Create(std::move(curve), 1, 0, TargetProperty::FILTER)); 654 Animation::Create(std::move(curve), 1, 0, TargetProperty::FILTER));
646 controller->AddAnimation(std::move(animation)); 655 controller->AddAnimation(std::move(animation));
647 656
648 controller->Animate(kInitialTickTime); 657 controller->Animate(kInitialTickTime);
649 controller->UpdateState(true, events.get()); 658 controller->UpdateState(true, events.get());
650 EXPECT_TRUE(controller->HasActiveAnimation()); 659 EXPECT_TRUE(controller->HasActiveAnimation());
651 EXPECT_EQ(start_filters, dummy.filters()); 660 EXPECT_EQ(start_filters, dummy.filters());
652 // A non-impl-only animation should not generate property updates. 661 // A non-impl-only animation should not generate property updates.
653 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); 662 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get());
654 EXPECT_FALSE(event); 663 EXPECT_FALSE(event);
655 664
656 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); 665 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
657 controller->UpdateState(true, events.get()); 666 controller->UpdateState(true, events.get());
658 EXPECT_EQ(1u, dummy.filters().size()); 667 EXPECT_EQ(1u, dummy.filters().size());
659 EXPECT_EQ(FilterOperation::CreateBrightnessFilter(1.5f), 668 EXPECT_EQ(FilterOperation::CreateBrightnessFilter(1.5f),
660 dummy.filters().at(0)); 669 dummy.filters().at(0));
661 event = GetMostRecentPropertyUpdateEvent(events.get()); 670 event = GetMostRecentPropertyUpdateEvent(events.get());
662 EXPECT_FALSE(event); 671 EXPECT_FALSE(event);
663 672
664 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); 673 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
665 controller->UpdateState(true, events.get()); 674 controller->UpdateState(true, events.get());
666 EXPECT_EQ(end_filters, dummy.filters()); 675 EXPECT_EQ(end_filters, dummy.filters());
667 EXPECT_FALSE(controller->HasActiveAnimation()); 676 EXPECT_FALSE(controller->HasActiveAnimation());
668 event = GetMostRecentPropertyUpdateEvent(events.get()); 677 event = GetMostRecentPropertyUpdateEvent(events.get());
669 EXPECT_FALSE(event); 678 EXPECT_FALSE(event);
670 } 679 }
671 680
672 TEST(LayerAnimationControllerTest, FilterTransitionOnImplOnly) { 681 TEST(LayerAnimationControllerTest, FilterTransitionOnImplOnly) {
673 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 682 std::unique_ptr<AnimationEvents> events(
683 base::WrapUnique(new AnimationEvents));
674 FakeLayerAnimationValueObserver dummy_impl; 684 FakeLayerAnimationValueObserver dummy_impl;
675 scoped_refptr<LayerAnimationController> controller_impl( 685 scoped_refptr<LayerAnimationController> controller_impl(
676 LayerAnimationController::Create(0)); 686 LayerAnimationController::Create(0));
677 controller_impl->AddValueObserver(&dummy_impl); 687 controller_impl->AddValueObserver(&dummy_impl);
678 688
679 scoped_ptr<KeyframedFilterAnimationCurve> curve( 689 std::unique_ptr<KeyframedFilterAnimationCurve> curve(
680 KeyframedFilterAnimationCurve::Create()); 690 KeyframedFilterAnimationCurve::Create());
681 691
682 // Create simple FILTER animation. 692 // Create simple FILTER animation.
683 FilterOperations start_filters; 693 FilterOperations start_filters;
684 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f)); 694 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f));
685 curve->AddKeyframe( 695 curve->AddKeyframe(
686 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); 696 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr));
687 FilterOperations end_filters; 697 FilterOperations end_filters;
688 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f)); 698 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f));
689 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 699 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
690 end_filters, nullptr)); 700 end_filters, nullptr));
691 701
692 scoped_ptr<Animation> animation( 702 std::unique_ptr<Animation> animation(
693 Animation::Create(std::move(curve), 1, 0, TargetProperty::FILTER)); 703 Animation::Create(std::move(curve), 1, 0, TargetProperty::FILTER));
694 animation->set_is_impl_only(true); 704 animation->set_is_impl_only(true);
695 controller_impl->AddAnimation(std::move(animation)); 705 controller_impl->AddAnimation(std::move(animation));
696 706
697 // Run animation. 707 // Run animation.
698 controller_impl->Animate(kInitialTickTime); 708 controller_impl->Animate(kInitialTickTime);
699 controller_impl->UpdateState(true, events.get()); 709 controller_impl->UpdateState(true, events.get());
700 EXPECT_TRUE(controller_impl->HasActiveAnimation()); 710 EXPECT_TRUE(controller_impl->HasActiveAnimation());
701 EXPECT_EQ(start_filters, dummy_impl.filters()); 711 EXPECT_EQ(start_filters, dummy_impl.filters());
702 EXPECT_EQ(1u, events->events_.size()); 712 EXPECT_EQ(1u, events->events_.size());
(...skipping 16 matching lines...) Expand all
719 EXPECT_TRUE(end_filter_event->is_impl_only); 729 EXPECT_TRUE(end_filter_event->is_impl_only);
720 } 730 }
721 731
722 TEST(LayerAnimationControllerTest, ScrollOffsetTransition) { 732 TEST(LayerAnimationControllerTest, ScrollOffsetTransition) {
723 FakeLayerAnimationValueObserver dummy_impl; 733 FakeLayerAnimationValueObserver dummy_impl;
724 FakeLayerAnimationValueProvider dummy_provider_impl; 734 FakeLayerAnimationValueProvider dummy_provider_impl;
725 scoped_refptr<LayerAnimationController> controller_impl( 735 scoped_refptr<LayerAnimationController> controller_impl(
726 LayerAnimationController::Create(0)); 736 LayerAnimationController::Create(0));
727 controller_impl->AddValueObserver(&dummy_impl); 737 controller_impl->AddValueObserver(&dummy_impl);
728 controller_impl->set_value_provider(&dummy_provider_impl); 738 controller_impl->set_value_provider(&dummy_provider_impl);
729 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 739 std::unique_ptr<AnimationEvents> events(
740 base::WrapUnique(new AnimationEvents));
730 FakeLayerAnimationValueObserver dummy; 741 FakeLayerAnimationValueObserver dummy;
731 FakeLayerAnimationValueProvider dummy_provider; 742 FakeLayerAnimationValueProvider dummy_provider;
732 scoped_refptr<LayerAnimationController> controller( 743 scoped_refptr<LayerAnimationController> controller(
733 LayerAnimationController::Create(0)); 744 LayerAnimationController::Create(0));
734 controller->AddValueObserver(&dummy); 745 controller->AddValueObserver(&dummy);
735 controller->set_value_provider(&dummy_provider); 746 controller->set_value_provider(&dummy_provider);
736 747
737 gfx::ScrollOffset initial_value(100.f, 300.f); 748 gfx::ScrollOffset initial_value(100.f, 300.f);
738 gfx::ScrollOffset target_value(300.f, 200.f); 749 gfx::ScrollOffset target_value(300.f, 200.f);
739 scoped_ptr<ScrollOffsetAnimationCurve> curve( 750 std::unique_ptr<ScrollOffsetAnimationCurve> curve(
740 ScrollOffsetAnimationCurve::Create(target_value, 751 ScrollOffsetAnimationCurve::Create(target_value,
741 EaseInOutTimingFunction::Create())); 752 EaseInOutTimingFunction::Create()));
742 753
743 scoped_ptr<Animation> animation( 754 std::unique_ptr<Animation> animation(
744 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); 755 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET));
745 animation->set_needs_synchronized_start_time(true); 756 animation->set_needs_synchronized_start_time(true);
746 controller->AddAnimation(std::move(animation)); 757 controller->AddAnimation(std::move(animation));
747 758
748 dummy_provider_impl.set_scroll_offset(initial_value); 759 dummy_provider_impl.set_scroll_offset(initial_value);
749 controller->PushAnimationUpdatesTo(controller_impl.get()); 760 controller->PushAnimationUpdatesTo(controller_impl.get());
750 controller_impl->ActivateAnimations(); 761 controller_impl->ActivateAnimations();
751 EXPECT_TRUE(controller_impl->GetAnimation(TargetProperty::SCROLL_OFFSET)); 762 EXPECT_TRUE(controller_impl->GetAnimation(TargetProperty::SCROLL_OFFSET));
752 TimeDelta duration = 763 TimeDelta duration =
753 controller_impl->GetAnimation(TargetProperty::SCROLL_OFFSET) 764 controller_impl->GetAnimation(TargetProperty::SCROLL_OFFSET)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 } 808 }
798 809
799 // Ensure that when the impl controller doesn't have a value provider, 810 // Ensure that when the impl controller doesn't have a value provider,
800 // the main-thread controller's value provider is used to obtain the intial 811 // the main-thread controller's value provider is used to obtain the intial
801 // scroll offset. 812 // scroll offset.
802 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionNoImplProvider) { 813 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionNoImplProvider) {
803 FakeLayerAnimationValueObserver dummy_impl; 814 FakeLayerAnimationValueObserver dummy_impl;
804 scoped_refptr<LayerAnimationController> controller_impl( 815 scoped_refptr<LayerAnimationController> controller_impl(
805 LayerAnimationController::Create(0)); 816 LayerAnimationController::Create(0));
806 controller_impl->AddValueObserver(&dummy_impl); 817 controller_impl->AddValueObserver(&dummy_impl);
807 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 818 std::unique_ptr<AnimationEvents> events(
819 base::WrapUnique(new AnimationEvents));
808 FakeLayerAnimationValueObserver dummy; 820 FakeLayerAnimationValueObserver dummy;
809 FakeLayerAnimationValueProvider dummy_provider; 821 FakeLayerAnimationValueProvider dummy_provider;
810 scoped_refptr<LayerAnimationController> controller( 822 scoped_refptr<LayerAnimationController> controller(
811 LayerAnimationController::Create(0)); 823 LayerAnimationController::Create(0));
812 controller->AddValueObserver(&dummy); 824 controller->AddValueObserver(&dummy);
813 controller->set_value_provider(&dummy_provider); 825 controller->set_value_provider(&dummy_provider);
814 826
815 gfx::ScrollOffset initial_value(500.f, 100.f); 827 gfx::ScrollOffset initial_value(500.f, 100.f);
816 gfx::ScrollOffset target_value(300.f, 200.f); 828 gfx::ScrollOffset target_value(300.f, 200.f);
817 scoped_ptr<ScrollOffsetAnimationCurve> curve( 829 std::unique_ptr<ScrollOffsetAnimationCurve> curve(
818 ScrollOffsetAnimationCurve::Create(target_value, 830 ScrollOffsetAnimationCurve::Create(target_value,
819 EaseInOutTimingFunction::Create())); 831 EaseInOutTimingFunction::Create()));
820 832
821 scoped_ptr<Animation> animation( 833 std::unique_ptr<Animation> animation(
822 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); 834 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET));
823 animation->set_needs_synchronized_start_time(true); 835 animation->set_needs_synchronized_start_time(true);
824 controller->AddAnimation(std::move(animation)); 836 controller->AddAnimation(std::move(animation));
825 837
826 dummy_provider.set_scroll_offset(initial_value); 838 dummy_provider.set_scroll_offset(initial_value);
827 controller->PushAnimationUpdatesTo(controller_impl.get()); 839 controller->PushAnimationUpdatesTo(controller_impl.get());
828 controller_impl->ActivateAnimations(); 840 controller_impl->ActivateAnimations();
829 EXPECT_TRUE(controller_impl->GetAnimation(TargetProperty::SCROLL_OFFSET)); 841 EXPECT_TRUE(controller_impl->GetAnimation(TargetProperty::SCROLL_OFFSET));
830 TimeDelta duration = 842 TimeDelta duration =
831 controller_impl->GetAnimation(TargetProperty::SCROLL_OFFSET) 843 controller_impl->GetAnimation(TargetProperty::SCROLL_OFFSET)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 controller->UpdateState(true, nullptr); 884 controller->UpdateState(true, nullptr);
873 EXPECT_VECTOR2DF_EQ(target_value, dummy.scroll_offset()); 885 EXPECT_VECTOR2DF_EQ(target_value, dummy.scroll_offset());
874 EXPECT_FALSE(controller->HasActiveAnimation()); 886 EXPECT_FALSE(controller->HasActiveAnimation());
875 } 887 }
876 888
877 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionOnImplOnly) { 889 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionOnImplOnly) {
878 FakeLayerAnimationValueObserver dummy_impl; 890 FakeLayerAnimationValueObserver dummy_impl;
879 scoped_refptr<LayerAnimationController> controller_impl( 891 scoped_refptr<LayerAnimationController> controller_impl(
880 LayerAnimationController::Create(0)); 892 LayerAnimationController::Create(0));
881 controller_impl->AddValueObserver(&dummy_impl); 893 controller_impl->AddValueObserver(&dummy_impl);
882 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 894 std::unique_ptr<AnimationEvents> events(
895 base::WrapUnique(new AnimationEvents));
883 896
884 gfx::ScrollOffset initial_value(100.f, 300.f); 897 gfx::ScrollOffset initial_value(100.f, 300.f);
885 gfx::ScrollOffset target_value(300.f, 200.f); 898 gfx::ScrollOffset target_value(300.f, 200.f);
886 scoped_ptr<ScrollOffsetAnimationCurve> curve( 899 std::unique_ptr<ScrollOffsetAnimationCurve> curve(
887 ScrollOffsetAnimationCurve::Create(target_value, 900 ScrollOffsetAnimationCurve::Create(target_value,
888 EaseInOutTimingFunction::Create())); 901 EaseInOutTimingFunction::Create()));
889 curve->SetInitialValue(initial_value); 902 curve->SetInitialValue(initial_value);
890 double duration_in_seconds = curve->Duration().InSecondsF(); 903 double duration_in_seconds = curve->Duration().InSecondsF();
891 904
892 scoped_ptr<Animation> animation( 905 std::unique_ptr<Animation> animation(
893 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); 906 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET));
894 animation->set_is_impl_only(true); 907 animation->set_is_impl_only(true);
895 controller_impl->AddAnimation(std::move(animation)); 908 controller_impl->AddAnimation(std::move(animation));
896 909
897 controller_impl->Animate(kInitialTickTime); 910 controller_impl->Animate(kInitialTickTime);
898 controller_impl->UpdateState(true, events.get()); 911 controller_impl->UpdateState(true, events.get());
899 EXPECT_TRUE(controller_impl->HasActiveAnimation()); 912 EXPECT_TRUE(controller_impl->HasActiveAnimation());
900 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); 913 EXPECT_EQ(initial_value, dummy_impl.scroll_offset());
901 // Scroll offset animations should not generate property updates. 914 // Scroll offset animations should not generate property updates.
902 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); 915 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get());
(...skipping 17 matching lines...) Expand all
920 EXPECT_FALSE(event); 933 EXPECT_FALSE(event);
921 } 934 }
922 935
923 TEST(LayerAnimationControllerTest, ScrollOffsetRemovalClearsScrollDelta) { 936 TEST(LayerAnimationControllerTest, ScrollOffsetRemovalClearsScrollDelta) {
924 FakeLayerAnimationValueObserver dummy_impl; 937 FakeLayerAnimationValueObserver dummy_impl;
925 FakeLayerAnimationValueProvider dummy_provider_impl; 938 FakeLayerAnimationValueProvider dummy_provider_impl;
926 scoped_refptr<LayerAnimationController> controller_impl( 939 scoped_refptr<LayerAnimationController> controller_impl(
927 LayerAnimationController::Create(0)); 940 LayerAnimationController::Create(0));
928 controller_impl->AddValueObserver(&dummy_impl); 941 controller_impl->AddValueObserver(&dummy_impl);
929 controller_impl->set_value_provider(&dummy_provider_impl); 942 controller_impl->set_value_provider(&dummy_provider_impl);
930 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 943 std::unique_ptr<AnimationEvents> events(
944 base::WrapUnique(new AnimationEvents));
931 FakeLayerAnimationValueObserver dummy; 945 FakeLayerAnimationValueObserver dummy;
932 FakeLayerAnimationValueProvider dummy_provider; 946 FakeLayerAnimationValueProvider dummy_provider;
933 scoped_refptr<LayerAnimationController> controller( 947 scoped_refptr<LayerAnimationController> controller(
934 LayerAnimationController::Create(0)); 948 LayerAnimationController::Create(0));
935 controller->AddValueObserver(&dummy); 949 controller->AddValueObserver(&dummy);
936 controller->set_value_provider(&dummy_provider); 950 controller->set_value_provider(&dummy_provider);
937 951
938 // First test the 1-argument version of RemoveAnimation. 952 // First test the 1-argument version of RemoveAnimation.
939 gfx::ScrollOffset target_value(300.f, 200.f); 953 gfx::ScrollOffset target_value(300.f, 200.f);
940 scoped_ptr<ScrollOffsetAnimationCurve> curve( 954 std::unique_ptr<ScrollOffsetAnimationCurve> curve(
941 ScrollOffsetAnimationCurve::Create(target_value, 955 ScrollOffsetAnimationCurve::Create(target_value,
942 EaseInOutTimingFunction::Create())); 956 EaseInOutTimingFunction::Create()));
943 957
944 int animation_id = 1; 958 int animation_id = 1;
945 scoped_ptr<Animation> animation(Animation::Create( 959 std::unique_ptr<Animation> animation(Animation::Create(
946 std::move(curve), animation_id, 0, TargetProperty::SCROLL_OFFSET)); 960 std::move(curve), animation_id, 0, TargetProperty::SCROLL_OFFSET));
947 animation->set_needs_synchronized_start_time(true); 961 animation->set_needs_synchronized_start_time(true);
948 controller->AddAnimation(std::move(animation)); 962 controller->AddAnimation(std::move(animation));
949 controller->PushAnimationUpdatesTo(controller_impl.get()); 963 controller->PushAnimationUpdatesTo(controller_impl.get());
950 controller_impl->ActivateAnimations(); 964 controller_impl->ActivateAnimations();
951 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted()); 965 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted());
952 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted()); 966 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted());
953 967
954 controller->RemoveAnimation(animation_id); 968 controller->RemoveAnimation(animation_id);
955 EXPECT_TRUE(controller->scroll_offset_animation_was_interrupted()); 969 EXPECT_TRUE(controller->scroll_offset_animation_was_interrupted());
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 1057
1044 void NotifyAnimationAborted(TimeTicks monotonic_time, 1058 void NotifyAnimationAborted(TimeTicks monotonic_time,
1045 TargetProperty::Type target_property, 1059 TargetProperty::Type target_property,
1046 int group) override { 1060 int group) override {
1047 aborted_ = true; 1061 aborted_ = true;
1048 } 1062 }
1049 1063
1050 void NotifyAnimationTakeover(base::TimeTicks monotonic_time, 1064 void NotifyAnimationTakeover(base::TimeTicks monotonic_time,
1051 TargetProperty::Type target_property, 1065 TargetProperty::Type target_property,
1052 double animation_start_time, 1066 double animation_start_time,
1053 scoped_ptr<AnimationCurve> curve) override { 1067 std::unique_ptr<AnimationCurve> curve) override {
1054 takeover_ = true; 1068 takeover_ = true;
1055 } 1069 }
1056 1070
1057 bool started() { return started_; } 1071 bool started() { return started_; }
1058 1072
1059 bool finished() { return finished_; } 1073 bool finished() { return finished_; }
1060 1074
1061 bool aborted() { return aborted_; } 1075 bool aborted() { return aborted_; }
1062 1076
1063 bool takeover() { return takeover_; } 1077 bool takeover() { return takeover_; }
1064 1078
1065 TimeTicks start_time() { return start_time_; } 1079 TimeTicks start_time() { return start_time_; }
1066 1080
1067 private: 1081 private:
1068 bool started_; 1082 bool started_;
1069 bool finished_; 1083 bool finished_;
1070 bool aborted_; 1084 bool aborted_;
1071 bool takeover_; 1085 bool takeover_;
1072 TimeTicks start_time_; 1086 TimeTicks start_time_;
1073 }; 1087 };
1074 1088
1075 // Tests that impl-only animations lead to start and finished notifications 1089 // Tests that impl-only animations lead to start and finished notifications
1076 // on the impl thread controller's animation delegate. 1090 // on the impl thread controller's animation delegate.
1077 TEST(LayerAnimationControllerTest, 1091 TEST(LayerAnimationControllerTest,
1078 NotificationsForImplOnlyAnimationsAreSentToImplThreadDelegate) { 1092 NotificationsForImplOnlyAnimationsAreSentToImplThreadDelegate) {
1079 FakeLayerAnimationValueObserver dummy_impl; 1093 FakeLayerAnimationValueObserver dummy_impl;
1080 scoped_refptr<LayerAnimationController> controller_impl( 1094 scoped_refptr<LayerAnimationController> controller_impl(
1081 LayerAnimationController::Create(0)); 1095 LayerAnimationController::Create(0));
1082 controller_impl->AddValueObserver(&dummy_impl); 1096 controller_impl->AddValueObserver(&dummy_impl);
1083 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 1097 std::unique_ptr<AnimationEvents> events(
1098 base::WrapUnique(new AnimationEvents));
1084 FakeAnimationDelegate delegate; 1099 FakeAnimationDelegate delegate;
1085 controller_impl->set_layer_animation_delegate(&delegate); 1100 controller_impl->set_layer_animation_delegate(&delegate);
1086 1101
1087 scoped_ptr<Animation> to_add(CreateAnimation( 1102 std::unique_ptr<Animation> to_add(CreateAnimation(
1088 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, 1103 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
1089 TargetProperty::OPACITY)); 1104 1, TargetProperty::OPACITY));
1090 to_add->set_is_impl_only(true); 1105 to_add->set_is_impl_only(true);
1091 controller_impl->AddAnimation(std::move(to_add)); 1106 controller_impl->AddAnimation(std::move(to_add));
1092 1107
1093 EXPECT_FALSE(delegate.started()); 1108 EXPECT_FALSE(delegate.started());
1094 EXPECT_FALSE(delegate.finished()); 1109 EXPECT_FALSE(delegate.finished());
1095 1110
1096 controller_impl->Animate(kInitialTickTime); 1111 controller_impl->Animate(kInitialTickTime);
1097 controller_impl->UpdateState(true, events.get()); 1112 controller_impl->UpdateState(true, events.get());
1098 1113
1099 EXPECT_TRUE(delegate.started()); 1114 EXPECT_TRUE(delegate.started());
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 controller->NotifyAnimationStarted(events.events_[0]); 1211 controller->NotifyAnimationStarted(events.events_[0]);
1197 1212
1198 // Validate start time on the event observer. 1213 // Validate start time on the event observer.
1199 EXPECT_EQ(start_time, observer.start_time()); 1214 EXPECT_EQ(start_time, observer.start_time());
1200 } 1215 }
1201 1216
1202 // Tests animations that are waiting for a synchronized start time do not 1217 // Tests animations that are waiting for a synchronized start time do not
1203 // finish. 1218 // finish.
1204 TEST(LayerAnimationControllerTest, 1219 TEST(LayerAnimationControllerTest,
1205 AnimationsWaitingForStartTimeDoNotFinishIfTheyOutwaitTheirFinish) { 1220 AnimationsWaitingForStartTimeDoNotFinishIfTheyOutwaitTheirFinish) {
1206 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 1221 std::unique_ptr<AnimationEvents> events(
1222 base::WrapUnique(new AnimationEvents));
1207 FakeLayerAnimationValueObserver dummy; 1223 FakeLayerAnimationValueObserver dummy;
1208 scoped_refptr<LayerAnimationController> controller( 1224 scoped_refptr<LayerAnimationController> controller(
1209 LayerAnimationController::Create(0)); 1225 LayerAnimationController::Create(0));
1210 controller->AddValueObserver(&dummy); 1226 controller->AddValueObserver(&dummy);
1211 1227
1212 scoped_ptr<Animation> to_add(CreateAnimation( 1228 std::unique_ptr<Animation> to_add(CreateAnimation(
1213 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, 1229 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
1214 TargetProperty::OPACITY)); 1230 1, TargetProperty::OPACITY));
1215 to_add->set_needs_synchronized_start_time(true); 1231 to_add->set_needs_synchronized_start_time(true);
1216 1232
1217 // We should pause at the first keyframe indefinitely waiting for that 1233 // We should pause at the first keyframe indefinitely waiting for that
1218 // animation to start. 1234 // animation to start.
1219 controller->AddAnimation(std::move(to_add)); 1235 controller->AddAnimation(std::move(to_add));
1220 controller->Animate(kInitialTickTime); 1236 controller->Animate(kInitialTickTime);
1221 controller->UpdateState(true, events.get()); 1237 controller->UpdateState(true, events.get());
1222 EXPECT_TRUE(controller->HasActiveAnimation()); 1238 EXPECT_TRUE(controller->HasActiveAnimation());
1223 EXPECT_EQ(0.f, dummy.opacity()); 1239 EXPECT_EQ(0.f, dummy.opacity());
1224 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); 1240 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
(...skipping 10 matching lines...) Expand all
1235 AnimationEvent(AnimationEvent::STARTED, 0, 1, TargetProperty::OPACITY, 1251 AnimationEvent(AnimationEvent::STARTED, 0, 1, TargetProperty::OPACITY,
1236 kInitialTickTime + TimeDelta::FromMilliseconds(2000))); 1252 kInitialTickTime + TimeDelta::FromMilliseconds(2000)));
1237 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(5000)); 1253 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(5000));
1238 controller->UpdateState(true, events.get()); 1254 controller->UpdateState(true, events.get());
1239 EXPECT_EQ(1.f, dummy.opacity()); 1255 EXPECT_EQ(1.f, dummy.opacity());
1240 EXPECT_FALSE(controller->HasActiveAnimation()); 1256 EXPECT_FALSE(controller->HasActiveAnimation());
1241 } 1257 }
1242 1258
1243 // Tests that two queued animations affecting the same property run in sequence. 1259 // Tests that two queued animations affecting the same property run in sequence.
1244 TEST(LayerAnimationControllerTest, TrivialQueuing) { 1260 TEST(LayerAnimationControllerTest, TrivialQueuing) {
1245 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 1261 std::unique_ptr<AnimationEvents> events(
1262 base::WrapUnique(new AnimationEvents));
1246 FakeLayerAnimationValueObserver dummy; 1263 FakeLayerAnimationValueObserver dummy;
1247 scoped_refptr<LayerAnimationController> controller( 1264 scoped_refptr<LayerAnimationController> controller(
1248 LayerAnimationController::Create(0)); 1265 LayerAnimationController::Create(0));
1249 controller->AddValueObserver(&dummy); 1266 controller->AddValueObserver(&dummy);
1250 1267
1251 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); 1268 EXPECT_FALSE(controller->needs_to_start_animations_for_testing());
1252 1269
1253 controller->AddAnimation(CreateAnimation( 1270 controller->AddAnimation(CreateAnimation(
1254 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, 1271 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
1255 TargetProperty::OPACITY)); 1272 1, TargetProperty::OPACITY));
1256 controller->AddAnimation(CreateAnimation( 1273 controller->AddAnimation(CreateAnimation(
1257 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), 2, 1274 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)),
1258 TargetProperty::OPACITY)); 1275 2, TargetProperty::OPACITY));
1259 1276
1260 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); 1277 EXPECT_TRUE(controller->needs_to_start_animations_for_testing());
1261 1278
1262 controller->Animate(kInitialTickTime); 1279 controller->Animate(kInitialTickTime);
1263 1280
1264 // The second animation still needs to be started. 1281 // The second animation still needs to be started.
1265 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); 1282 EXPECT_TRUE(controller->needs_to_start_animations_for_testing());
1266 1283
1267 controller->UpdateState(true, events.get()); 1284 controller->UpdateState(true, events.get());
1268 EXPECT_TRUE(controller->HasActiveAnimation()); 1285 EXPECT_TRUE(controller->HasActiveAnimation());
1269 EXPECT_EQ(0.f, dummy.opacity()); 1286 EXPECT_EQ(0.f, dummy.opacity());
1270 1287
1271 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); 1288 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1272 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); 1289 EXPECT_TRUE(controller->needs_to_start_animations_for_testing());
1273 controller->UpdateState(true, events.get()); 1290 controller->UpdateState(true, events.get());
1274 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); 1291 EXPECT_FALSE(controller->needs_to_start_animations_for_testing());
1275 1292
1276 EXPECT_TRUE(controller->HasActiveAnimation()); 1293 EXPECT_TRUE(controller->HasActiveAnimation());
1277 EXPECT_EQ(1.f, dummy.opacity()); 1294 EXPECT_EQ(1.f, dummy.opacity());
1278 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); 1295 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
1279 controller->UpdateState(true, events.get()); 1296 controller->UpdateState(true, events.get());
1280 EXPECT_EQ(0.5f, dummy.opacity()); 1297 EXPECT_EQ(0.5f, dummy.opacity());
1281 EXPECT_FALSE(controller->HasActiveAnimation()); 1298 EXPECT_FALSE(controller->HasActiveAnimation());
1282 } 1299 }
1283 1300
1284 // Tests interrupting a transition with another transition. 1301 // Tests interrupting a transition with another transition.
1285 TEST(LayerAnimationControllerTest, Interrupt) { 1302 TEST(LayerAnimationControllerTest, Interrupt) {
1286 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 1303 std::unique_ptr<AnimationEvents> events(
1304 base::WrapUnique(new AnimationEvents));
1287 FakeLayerAnimationValueObserver dummy; 1305 FakeLayerAnimationValueObserver dummy;
1288 scoped_refptr<LayerAnimationController> controller( 1306 scoped_refptr<LayerAnimationController> controller(
1289 LayerAnimationController::Create(0)); 1307 LayerAnimationController::Create(0));
1290 controller->AddValueObserver(&dummy); 1308 controller->AddValueObserver(&dummy);
1291 controller->AddAnimation(CreateAnimation( 1309 controller->AddAnimation(CreateAnimation(
1292 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, 1310 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
1293 TargetProperty::OPACITY)); 1311 1, TargetProperty::OPACITY));
1294 controller->Animate(kInitialTickTime); 1312 controller->Animate(kInitialTickTime);
1295 controller->UpdateState(true, events.get()); 1313 controller->UpdateState(true, events.get());
1296 EXPECT_TRUE(controller->HasActiveAnimation()); 1314 EXPECT_TRUE(controller->HasActiveAnimation());
1297 EXPECT_EQ(0.f, dummy.opacity()); 1315 EXPECT_EQ(0.f, dummy.opacity());
1298 1316
1299 scoped_ptr<Animation> to_add(CreateAnimation( 1317 std::unique_ptr<Animation> to_add(CreateAnimation(
1300 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), 2, 1318 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)),
1301 TargetProperty::OPACITY)); 1319 2, TargetProperty::OPACITY));
1302 controller->AbortAnimations(TargetProperty::OPACITY); 1320 controller->AbortAnimations(TargetProperty::OPACITY);
1303 controller->AddAnimation(std::move(to_add)); 1321 controller->AddAnimation(std::move(to_add));
1304 1322
1305 // Since the previous animation was aborted, the new animation should start 1323 // Since the previous animation was aborted, the new animation should start
1306 // right in this call to animate. 1324 // right in this call to animate.
1307 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); 1325 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
1308 controller->UpdateState(true, events.get()); 1326 controller->UpdateState(true, events.get());
1309 EXPECT_TRUE(controller->HasActiveAnimation()); 1327 EXPECT_TRUE(controller->HasActiveAnimation());
1310 EXPECT_EQ(1.f, dummy.opacity()); 1328 EXPECT_EQ(1.f, dummy.opacity());
1311 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1500)); 1329 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1500));
1312 controller->UpdateState(true, events.get()); 1330 controller->UpdateState(true, events.get());
1313 EXPECT_EQ(0.5f, dummy.opacity()); 1331 EXPECT_EQ(0.5f, dummy.opacity());
1314 EXPECT_FALSE(controller->HasActiveAnimation()); 1332 EXPECT_FALSE(controller->HasActiveAnimation());
1315 } 1333 }
1316 1334
1317 // Tests scheduling two animations to run together when only one property is 1335 // Tests scheduling two animations to run together when only one property is
1318 // free. 1336 // free.
1319 TEST(LayerAnimationControllerTest, ScheduleTogetherWhenAPropertyIsBlocked) { 1337 TEST(LayerAnimationControllerTest, ScheduleTogetherWhenAPropertyIsBlocked) {
1320 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 1338 std::unique_ptr<AnimationEvents> events(
1339 base::WrapUnique(new AnimationEvents));
1321 FakeLayerAnimationValueObserver dummy; 1340 FakeLayerAnimationValueObserver dummy;
1322 scoped_refptr<LayerAnimationController> controller( 1341 scoped_refptr<LayerAnimationController> controller(
1323 LayerAnimationController::Create(0)); 1342 LayerAnimationController::Create(0));
1324 controller->AddValueObserver(&dummy); 1343 controller->AddValueObserver(&dummy);
1325 1344
1326 controller->AddAnimation(CreateAnimation( 1345 controller->AddAnimation(CreateAnimation(
1327 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, 1346 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1,
1328 TargetProperty::TRANSFORM)); 1347 TargetProperty::TRANSFORM));
1329 controller->AddAnimation(CreateAnimation( 1348 controller->AddAnimation(CreateAnimation(
1330 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)), 2, 1349 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 2,
1331 TargetProperty::TRANSFORM)); 1350 TargetProperty::TRANSFORM));
1332 controller->AddAnimation(CreateAnimation( 1351 controller->AddAnimation(CreateAnimation(
1333 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 2, 1352 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
1334 TargetProperty::OPACITY)); 1353 2, TargetProperty::OPACITY));
1335 1354
1336 controller->Animate(kInitialTickTime); 1355 controller->Animate(kInitialTickTime);
1337 controller->UpdateState(true, events.get()); 1356 controller->UpdateState(true, events.get());
1338 EXPECT_EQ(0.f, dummy.opacity()); 1357 EXPECT_EQ(0.f, dummy.opacity());
1339 EXPECT_TRUE(controller->HasActiveAnimation()); 1358 EXPECT_TRUE(controller->HasActiveAnimation());
1340 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); 1359 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1341 controller->UpdateState(true, events.get()); 1360 controller->UpdateState(true, events.get());
1342 // Should not have started the float transition yet. 1361 // Should not have started the float transition yet.
1343 EXPECT_TRUE(controller->HasActiveAnimation()); 1362 EXPECT_TRUE(controller->HasActiveAnimation());
1344 EXPECT_EQ(0.f, dummy.opacity()); 1363 EXPECT_EQ(0.f, dummy.opacity());
1345 // The float animation should have started at time 1 and should be done. 1364 // The float animation should have started at time 1 and should be done.
1346 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); 1365 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
1347 controller->UpdateState(true, events.get()); 1366 controller->UpdateState(true, events.get());
1348 EXPECT_EQ(1.f, dummy.opacity()); 1367 EXPECT_EQ(1.f, dummy.opacity());
1349 EXPECT_FALSE(controller->HasActiveAnimation()); 1368 EXPECT_FALSE(controller->HasActiveAnimation());
1350 } 1369 }
1351 1370
1352 // Tests scheduling two animations to run together with different lengths and 1371 // Tests scheduling two animations to run together with different lengths and
1353 // another animation queued to start when the shorter animation finishes (should 1372 // another animation queued to start when the shorter animation finishes (should
1354 // wait for both to finish). 1373 // wait for both to finish).
1355 TEST(LayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting) { 1374 TEST(LayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting) {
1356 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 1375 std::unique_ptr<AnimationEvents> events(
1376 base::WrapUnique(new AnimationEvents));
1357 FakeLayerAnimationValueObserver dummy; 1377 FakeLayerAnimationValueObserver dummy;
1358 scoped_refptr<LayerAnimationController> controller( 1378 scoped_refptr<LayerAnimationController> controller(
1359 LayerAnimationController::Create(0)); 1379 LayerAnimationController::Create(0));
1360 controller->AddValueObserver(&dummy); 1380 controller->AddValueObserver(&dummy);
1361 1381
1362 controller->AddAnimation(CreateAnimation( 1382 controller->AddAnimation(CreateAnimation(
1363 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2)), 1, 1383 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(2)), 1,
1364 TargetProperty::TRANSFORM)); 1384 TargetProperty::TRANSFORM));
1365 controller->AddAnimation(CreateAnimation( 1385 controller->AddAnimation(CreateAnimation(
1366 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, 1386 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
1367 TargetProperty::OPACITY)); 1387 1, TargetProperty::OPACITY));
1368 controller->AddAnimation(CreateAnimation( 1388 controller->AddAnimation(CreateAnimation(
1369 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), 2, 1389 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)),
1370 TargetProperty::OPACITY)); 1390 2, TargetProperty::OPACITY));
1371 1391
1372 // Animations with id 1 should both start now. 1392 // Animations with id 1 should both start now.
1373 controller->Animate(kInitialTickTime); 1393 controller->Animate(kInitialTickTime);
1374 controller->UpdateState(true, events.get()); 1394 controller->UpdateState(true, events.get());
1375 EXPECT_TRUE(controller->HasActiveAnimation()); 1395 EXPECT_TRUE(controller->HasActiveAnimation());
1376 EXPECT_EQ(0.f, dummy.opacity()); 1396 EXPECT_EQ(0.f, dummy.opacity());
1377 // The opacity animation should have finished at time 1, but the group 1397 // The opacity animation should have finished at time 1, but the group
1378 // of animations with id 1 don't finish until time 2 because of the length 1398 // of animations with id 1 don't finish until time 2 because of the length
1379 // of the transform animation. 1399 // of the transform animation.
1380 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); 1400 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
1381 controller->UpdateState(true, events.get()); 1401 controller->UpdateState(true, events.get());
1382 // Should not have started the float transition yet. 1402 // Should not have started the float transition yet.
1383 EXPECT_TRUE(controller->HasActiveAnimation()); 1403 EXPECT_TRUE(controller->HasActiveAnimation());
1384 EXPECT_EQ(1.f, dummy.opacity()); 1404 EXPECT_EQ(1.f, dummy.opacity());
1385 1405
1386 // The second opacity animation should start at time 2 and should be done by 1406 // The second opacity animation should start at time 2 and should be done by
1387 // time 3. 1407 // time 3.
1388 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); 1408 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000));
1389 controller->UpdateState(true, events.get()); 1409 controller->UpdateState(true, events.get());
1390 EXPECT_EQ(0.5f, dummy.opacity()); 1410 EXPECT_EQ(0.5f, dummy.opacity());
1391 EXPECT_FALSE(controller->HasActiveAnimation()); 1411 EXPECT_FALSE(controller->HasActiveAnimation());
1392 } 1412 }
1393 1413
1394 // Test that a looping animation loops and for the correct number of iterations. 1414 // Test that a looping animation loops and for the correct number of iterations.
1395 TEST(LayerAnimationControllerTest, TrivialLooping) { 1415 TEST(LayerAnimationControllerTest, TrivialLooping) {
1396 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 1416 std::unique_ptr<AnimationEvents> events(
1417 base::WrapUnique(new AnimationEvents));
1397 FakeLayerAnimationValueObserver dummy; 1418 FakeLayerAnimationValueObserver dummy;
1398 scoped_refptr<LayerAnimationController> controller( 1419 scoped_refptr<LayerAnimationController> controller(
1399 LayerAnimationController::Create(0)); 1420 LayerAnimationController::Create(0));
1400 controller->AddValueObserver(&dummy); 1421 controller->AddValueObserver(&dummy);
1401 1422
1402 scoped_ptr<Animation> to_add(CreateAnimation( 1423 std::unique_ptr<Animation> to_add(CreateAnimation(
1403 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, 1424 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
1404 TargetProperty::OPACITY)); 1425 1, TargetProperty::OPACITY));
1405 to_add->set_iterations(3); 1426 to_add->set_iterations(3);
1406 controller->AddAnimation(std::move(to_add)); 1427 controller->AddAnimation(std::move(to_add));
1407 1428
1408 controller->Animate(kInitialTickTime); 1429 controller->Animate(kInitialTickTime);
1409 controller->UpdateState(true, events.get()); 1430 controller->UpdateState(true, events.get());
1410 EXPECT_TRUE(controller->HasActiveAnimation()); 1431 EXPECT_TRUE(controller->HasActiveAnimation());
1411 EXPECT_EQ(0.f, dummy.opacity()); 1432 EXPECT_EQ(0.f, dummy.opacity());
1412 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1250)); 1433 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1250));
1413 controller->UpdateState(true, events.get()); 1434 controller->UpdateState(true, events.get());
1414 EXPECT_TRUE(controller->HasActiveAnimation()); 1435 EXPECT_TRUE(controller->HasActiveAnimation());
(...skipping 16 matching lines...) Expand all
1431 EXPECT_EQ(1.f, dummy.opacity()); 1452 EXPECT_EQ(1.f, dummy.opacity());
1432 1453
1433 // Just be extra sure. 1454 // Just be extra sure.
1434 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(4000)); 1455 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(4000));
1435 controller->UpdateState(true, events.get()); 1456 controller->UpdateState(true, events.get());
1436 EXPECT_EQ(1.f, dummy.opacity()); 1457 EXPECT_EQ(1.f, dummy.opacity());
1437 } 1458 }
1438 1459
1439 // Test that an infinitely looping animation does indeed go until aborted. 1460 // Test that an infinitely looping animation does indeed go until aborted.
1440 TEST(LayerAnimationControllerTest, InfiniteLooping) { 1461 TEST(LayerAnimationControllerTest, InfiniteLooping) {
1441 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 1462 std::unique_ptr<AnimationEvents> events(
1463 base::WrapUnique(new AnimationEvents));
1442 FakeLayerAnimationValueObserver dummy; 1464 FakeLayerAnimationValueObserver dummy;
1443 scoped_refptr<LayerAnimationController> controller( 1465 scoped_refptr<LayerAnimationController> controller(
1444 LayerAnimationController::Create(0)); 1466 LayerAnimationController::Create(0));
1445 controller->AddValueObserver(&dummy); 1467 controller->AddValueObserver(&dummy);
1446 1468
1447 scoped_ptr<Animation> to_add(CreateAnimation( 1469 std::unique_ptr<Animation> to_add(CreateAnimation(
1448 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, 1470 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
1449 TargetProperty::OPACITY)); 1471 1, TargetProperty::OPACITY));
1450 to_add->set_iterations(-1); 1472 to_add->set_iterations(-1);
1451 controller->AddAnimation(std::move(to_add)); 1473 controller->AddAnimation(std::move(to_add));
1452 1474
1453 controller->Animate(kInitialTickTime); 1475 controller->Animate(kInitialTickTime);
1454 controller->UpdateState(true, events.get()); 1476 controller->UpdateState(true, events.get());
1455 EXPECT_TRUE(controller->HasActiveAnimation()); 1477 EXPECT_TRUE(controller->HasActiveAnimation());
1456 EXPECT_EQ(0.f, dummy.opacity()); 1478 EXPECT_EQ(0.f, dummy.opacity());
1457 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1250)); 1479 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1250));
1458 controller->UpdateState(true, events.get()); 1480 controller->UpdateState(true, events.get());
1459 EXPECT_TRUE(controller->HasActiveAnimation()); 1481 EXPECT_TRUE(controller->HasActiveAnimation());
(...skipping 17 matching lines...) Expand all
1477 EXPECT_TRUE(controller->GetAnimation(TargetProperty::OPACITY)); 1499 EXPECT_TRUE(controller->GetAnimation(TargetProperty::OPACITY));
1478 controller->GetAnimation(TargetProperty::OPACITY) 1500 controller->GetAnimation(TargetProperty::OPACITY)
1479 ->SetRunState(Animation::ABORTED, 1501 ->SetRunState(Animation::ABORTED,
1480 kInitialTickTime + TimeDelta::FromMilliseconds(750)); 1502 kInitialTickTime + TimeDelta::FromMilliseconds(750));
1481 EXPECT_FALSE(controller->HasActiveAnimation()); 1503 EXPECT_FALSE(controller->HasActiveAnimation());
1482 EXPECT_EQ(0.75f, dummy.opacity()); 1504 EXPECT_EQ(0.75f, dummy.opacity());
1483 } 1505 }
1484 1506
1485 // Test that pausing and resuming work as expected. 1507 // Test that pausing and resuming work as expected.
1486 TEST(LayerAnimationControllerTest, PauseResume) { 1508 TEST(LayerAnimationControllerTest, PauseResume) {
1487 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 1509 std::unique_ptr<AnimationEvents> events(
1510 base::WrapUnique(new AnimationEvents));
1488 FakeLayerAnimationValueObserver dummy; 1511 FakeLayerAnimationValueObserver dummy;
1489 scoped_refptr<LayerAnimationController> controller( 1512 scoped_refptr<LayerAnimationController> controller(
1490 LayerAnimationController::Create(0)); 1513 LayerAnimationController::Create(0));
1491 controller->AddValueObserver(&dummy); 1514 controller->AddValueObserver(&dummy);
1492 1515
1493 controller->AddAnimation(CreateAnimation( 1516 controller->AddAnimation(CreateAnimation(
1494 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, 1517 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
1495 TargetProperty::OPACITY)); 1518 1, TargetProperty::OPACITY));
1496 1519
1497 controller->Animate(kInitialTickTime); 1520 controller->Animate(kInitialTickTime);
1498 controller->UpdateState(true, events.get()); 1521 controller->UpdateState(true, events.get());
1499 EXPECT_TRUE(controller->HasActiveAnimation()); 1522 EXPECT_TRUE(controller->HasActiveAnimation());
1500 EXPECT_EQ(0.f, dummy.opacity()); 1523 EXPECT_EQ(0.f, dummy.opacity());
1501 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); 1524 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
1502 controller->UpdateState(true, events.get()); 1525 controller->UpdateState(true, events.get());
1503 EXPECT_TRUE(controller->HasActiveAnimation()); 1526 EXPECT_TRUE(controller->HasActiveAnimation());
1504 EXPECT_EQ(0.5f, dummy.opacity()); 1527 EXPECT_EQ(0.5f, dummy.opacity());
1505 1528
(...skipping 16 matching lines...) Expand all
1522 EXPECT_TRUE(controller->HasActiveAnimation()); 1545 EXPECT_TRUE(controller->HasActiveAnimation());
1523 EXPECT_EQ(0.75f, dummy.opacity()); 1546 EXPECT_EQ(0.75f, dummy.opacity());
1524 1547
1525 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024500)); 1548 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024500));
1526 controller->UpdateState(true, events.get()); 1549 controller->UpdateState(true, events.get());
1527 EXPECT_FALSE(controller->HasActiveAnimation()); 1550 EXPECT_FALSE(controller->HasActiveAnimation());
1528 EXPECT_EQ(1.f, dummy.opacity()); 1551 EXPECT_EQ(1.f, dummy.opacity());
1529 } 1552 }
1530 1553
1531 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) { 1554 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) {
1532 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 1555 std::unique_ptr<AnimationEvents> events(
1556 base::WrapUnique(new AnimationEvents));
1533 FakeLayerAnimationValueObserver dummy; 1557 FakeLayerAnimationValueObserver dummy;
1534 scoped_refptr<LayerAnimationController> controller( 1558 scoped_refptr<LayerAnimationController> controller(
1535 LayerAnimationController::Create(0)); 1559 LayerAnimationController::Create(0));
1536 controller->AddValueObserver(&dummy); 1560 controller->AddValueObserver(&dummy);
1537 1561
1538 const int animation_id = 2; 1562 const int animation_id = 2;
1539 controller->AddAnimation(Animation::Create( 1563 controller->AddAnimation(Animation::Create(
1540 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, 1, 1564 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, 1,
1541 TargetProperty::TRANSFORM)); 1565 TargetProperty::TRANSFORM));
1542 controller->AddAnimation(Animation::Create( 1566 controller->AddAnimation(Animation::Create(
1543 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)), 1567 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)),
1544 animation_id, 1, TargetProperty::OPACITY)); 1568 animation_id, 1, TargetProperty::OPACITY));
1545 controller->AddAnimation(Animation::Create( 1569 controller->AddAnimation(Animation::Create(
1546 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.75f)), 3, 1570 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.75f)),
1547 2, TargetProperty::OPACITY)); 1571 3, 2, TargetProperty::OPACITY));
1548 1572
1549 controller->Animate(kInitialTickTime); 1573 controller->Animate(kInitialTickTime);
1550 controller->UpdateState(true, events.get()); 1574 controller->UpdateState(true, events.get());
1551 EXPECT_TRUE(controller->HasActiveAnimation()); 1575 EXPECT_TRUE(controller->HasActiveAnimation());
1552 EXPECT_EQ(0.f, dummy.opacity()); 1576 EXPECT_EQ(0.f, dummy.opacity());
1553 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); 1577 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1554 controller->UpdateState(true, events.get()); 1578 controller->UpdateState(true, events.get());
1555 EXPECT_TRUE(controller->HasActiveAnimation()); 1579 EXPECT_TRUE(controller->HasActiveAnimation());
1556 EXPECT_EQ(0.5f, dummy.opacity()); 1580 EXPECT_EQ(0.5f, dummy.opacity());
1557 1581
1558 EXPECT_TRUE(controller->GetAnimationById(animation_id)); 1582 EXPECT_TRUE(controller->GetAnimationById(animation_id));
1559 controller->GetAnimationById(animation_id) 1583 controller->GetAnimationById(animation_id)
1560 ->SetRunState(Animation::ABORTED, 1584 ->SetRunState(Animation::ABORTED,
1561 kInitialTickTime + TimeDelta::FromMilliseconds(1000)); 1585 kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1562 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); 1586 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1563 controller->UpdateState(true, events.get()); 1587 controller->UpdateState(true, events.get());
1564 EXPECT_TRUE(controller->HasActiveAnimation()); 1588 EXPECT_TRUE(controller->HasActiveAnimation());
1565 EXPECT_EQ(1.f, dummy.opacity()); 1589 EXPECT_EQ(1.f, dummy.opacity());
1566 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); 1590 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
1567 controller->UpdateState(true, events.get()); 1591 controller->UpdateState(true, events.get());
1568 EXPECT_TRUE(!controller->HasActiveAnimation()); 1592 EXPECT_TRUE(!controller->HasActiveAnimation());
1569 EXPECT_EQ(0.75f, dummy.opacity()); 1593 EXPECT_EQ(0.75f, dummy.opacity());
1570 } 1594 }
1571 1595
1572 TEST(LayerAnimationControllerTest, PushUpdatesWhenSynchronizedStartTimeNeeded) { 1596 TEST(LayerAnimationControllerTest, PushUpdatesWhenSynchronizedStartTimeNeeded) {
1573 FakeLayerAnimationValueObserver dummy_impl; 1597 FakeLayerAnimationValueObserver dummy_impl;
1574 scoped_refptr<LayerAnimationController> controller_impl( 1598 scoped_refptr<LayerAnimationController> controller_impl(
1575 LayerAnimationController::Create(0)); 1599 LayerAnimationController::Create(0));
1576 controller_impl->AddValueObserver(&dummy_impl); 1600 controller_impl->AddValueObserver(&dummy_impl);
1577 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 1601 std::unique_ptr<AnimationEvents> events(
1602 base::WrapUnique(new AnimationEvents));
1578 FakeLayerAnimationValueObserver dummy; 1603 FakeLayerAnimationValueObserver dummy;
1579 scoped_refptr<LayerAnimationController> controller( 1604 scoped_refptr<LayerAnimationController> controller(
1580 LayerAnimationController::Create(0)); 1605 LayerAnimationController::Create(0));
1581 controller->AddValueObserver(&dummy); 1606 controller->AddValueObserver(&dummy);
1582 1607
1583 scoped_ptr<Animation> to_add(CreateAnimation( 1608 std::unique_ptr<Animation> to_add(CreateAnimation(
1584 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)), 0, 1609 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)),
1585 TargetProperty::OPACITY)); 1610 0, TargetProperty::OPACITY));
1586 to_add->set_needs_synchronized_start_time(true); 1611 to_add->set_needs_synchronized_start_time(true);
1587 controller->AddAnimation(std::move(to_add)); 1612 controller->AddAnimation(std::move(to_add));
1588 1613
1589 controller->Animate(kInitialTickTime); 1614 controller->Animate(kInitialTickTime);
1590 controller->UpdateState(true, events.get()); 1615 controller->UpdateState(true, events.get());
1591 EXPECT_TRUE(controller->HasActiveAnimation()); 1616 EXPECT_TRUE(controller->HasActiveAnimation());
1592 Animation* active_animation = 1617 Animation* active_animation =
1593 controller->GetAnimation(TargetProperty::OPACITY); 1618 controller->GetAnimation(TargetProperty::OPACITY);
1594 EXPECT_TRUE(active_animation); 1619 EXPECT_TRUE(active_animation);
1595 EXPECT_TRUE(active_animation->needs_synchronized_start_time()); 1620 EXPECT_TRUE(active_animation->needs_synchronized_start_time());
1596 1621
1597 controller->PushAnimationUpdatesTo(controller_impl.get()); 1622 controller->PushAnimationUpdatesTo(controller_impl.get());
1598 controller_impl->ActivateAnimations(); 1623 controller_impl->ActivateAnimations();
1599 1624
1600 active_animation = controller_impl->GetAnimation(TargetProperty::OPACITY); 1625 active_animation = controller_impl->GetAnimation(TargetProperty::OPACITY);
1601 EXPECT_TRUE(active_animation); 1626 EXPECT_TRUE(active_animation);
1602 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, 1627 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
1603 active_animation->run_state()); 1628 active_animation->run_state());
1604 } 1629 }
1605 1630
1606 // Tests that skipping a call to UpdateState works as expected. 1631 // Tests that skipping a call to UpdateState works as expected.
1607 TEST(LayerAnimationControllerTest, SkipUpdateState) { 1632 TEST(LayerAnimationControllerTest, SkipUpdateState) {
1608 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 1633 std::unique_ptr<AnimationEvents> events(
1634 base::WrapUnique(new AnimationEvents));
1609 FakeLayerAnimationValueObserver dummy; 1635 FakeLayerAnimationValueObserver dummy;
1610 scoped_refptr<LayerAnimationController> controller( 1636 scoped_refptr<LayerAnimationController> controller(
1611 LayerAnimationController::Create(0)); 1637 LayerAnimationController::Create(0));
1612 controller->AddValueObserver(&dummy); 1638 controller->AddValueObserver(&dummy);
1613 1639
1614 scoped_ptr<Animation> first_animation(CreateAnimation( 1640 std::unique_ptr<Animation> first_animation(CreateAnimation(
1615 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, 1641 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1,
1616 TargetProperty::TRANSFORM)); 1642 TargetProperty::TRANSFORM));
1617 first_animation->set_is_controlling_instance_for_test(true); 1643 first_animation->set_is_controlling_instance_for_test(true);
1618 controller->AddAnimation(std::move(first_animation)); 1644 controller->AddAnimation(std::move(first_animation));
1619 1645
1620 controller->Animate(kInitialTickTime); 1646 controller->Animate(kInitialTickTime);
1621 controller->UpdateState(true, events.get()); 1647 controller->UpdateState(true, events.get());
1622 1648
1623 scoped_ptr<Animation> second_animation(CreateAnimation( 1649 std::unique_ptr<Animation> second_animation(CreateAnimation(
1624 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 2, 1650 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
1625 TargetProperty::OPACITY)); 1651 2, TargetProperty::OPACITY));
1626 second_animation->set_is_controlling_instance_for_test(true); 1652 second_animation->set_is_controlling_instance_for_test(true);
1627 controller->AddAnimation(std::move(second_animation)); 1653 controller->AddAnimation(std::move(second_animation));
1628 1654
1629 // Animate but don't UpdateState. 1655 // Animate but don't UpdateState.
1630 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); 1656 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1631 1657
1632 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); 1658 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
1633 events.reset(new AnimationEvents); 1659 events.reset(new AnimationEvents);
1634 controller->UpdateState(true, events.get()); 1660 controller->UpdateState(true, events.get());
1635 1661
1636 // Should have one STARTED event and one FINISHED event. 1662 // Should have one STARTED event and one FINISHED event.
1637 EXPECT_EQ(2u, events->events_.size()); 1663 EXPECT_EQ(2u, events->events_.size());
1638 EXPECT_NE(events->events_[0].type, events->events_[1].type); 1664 EXPECT_NE(events->events_[0].type, events->events_[1].type);
1639 1665
1640 // The float transition should still be at its starting point. 1666 // The float transition should still be at its starting point.
1641 EXPECT_TRUE(controller->HasActiveAnimation()); 1667 EXPECT_TRUE(controller->HasActiveAnimation());
1642 EXPECT_EQ(0.f, dummy.opacity()); 1668 EXPECT_EQ(0.f, dummy.opacity());
1643 1669
1644 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); 1670 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000));
1645 controller->UpdateState(true, events.get()); 1671 controller->UpdateState(true, events.get());
1646 1672
1647 // The float tranisition should now be done. 1673 // The float tranisition should now be done.
1648 EXPECT_EQ(1.f, dummy.opacity()); 1674 EXPECT_EQ(1.f, dummy.opacity());
1649 EXPECT_FALSE(controller->HasActiveAnimation()); 1675 EXPECT_FALSE(controller->HasActiveAnimation());
1650 } 1676 }
1651 1677
1652 // Tests that an animation controller with only a pending observer gets ticked 1678 // Tests that an animation controller with only a pending observer gets ticked
1653 // but doesn't progress animations past the STARTING state. 1679 // but doesn't progress animations past the STARTING state.
1654 TEST(LayerAnimationControllerTest, InactiveObserverGetsTicked) { 1680 TEST(LayerAnimationControllerTest, InactiveObserverGetsTicked) {
1655 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 1681 std::unique_ptr<AnimationEvents> events(
1682 base::WrapUnique(new AnimationEvents));
1656 FakeLayerAnimationValueObserver dummy; 1683 FakeLayerAnimationValueObserver dummy;
1657 FakeInactiveLayerAnimationValueObserver pending_dummy; 1684 FakeInactiveLayerAnimationValueObserver pending_dummy;
1658 scoped_refptr<LayerAnimationController> controller( 1685 scoped_refptr<LayerAnimationController> controller(
1659 LayerAnimationController::Create(0)); 1686 LayerAnimationController::Create(0));
1660 1687
1661 const int id = 1; 1688 const int id = 1;
1662 controller->AddAnimation(CreateAnimation( 1689 controller->AddAnimation(CreateAnimation(
1663 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.5f, 1.f)), id, 1690 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.5f, 1.f)),
1664 TargetProperty::OPACITY)); 1691 id, TargetProperty::OPACITY));
1665 1692
1666 // Without an observer, the animation shouldn't progress to the STARTING 1693 // Without an observer, the animation shouldn't progress to the STARTING
1667 // state. 1694 // state.
1668 controller->Animate(kInitialTickTime); 1695 controller->Animate(kInitialTickTime);
1669 controller->UpdateState(true, events.get()); 1696 controller->UpdateState(true, events.get());
1670 EXPECT_EQ(0u, events->events_.size()); 1697 EXPECT_EQ(0u, events->events_.size());
1671 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, 1698 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
1672 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); 1699 controller->GetAnimation(TargetProperty::OPACITY)->run_state());
1673 1700
1674 controller->AddValueObserver(&pending_dummy); 1701 controller->AddValueObserver(&pending_dummy);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1707 // The animation should now tick past its starting point. 1734 // The animation should now tick past its starting point.
1708 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3500)); 1735 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3500));
1709 EXPECT_NE(0.5f, pending_dummy.opacity()); 1736 EXPECT_NE(0.5f, pending_dummy.opacity());
1710 EXPECT_NE(0.5f, dummy.opacity()); 1737 EXPECT_NE(0.5f, dummy.opacity());
1711 } 1738 }
1712 1739
1713 TEST(LayerAnimationControllerTest, TransformAnimationBounds) { 1740 TEST(LayerAnimationControllerTest, TransformAnimationBounds) {
1714 scoped_refptr<LayerAnimationController> controller_impl( 1741 scoped_refptr<LayerAnimationController> controller_impl(
1715 LayerAnimationController::Create(0)); 1742 LayerAnimationController::Create(0));
1716 1743
1717 scoped_ptr<KeyframedTransformAnimationCurve> curve1( 1744 std::unique_ptr<KeyframedTransformAnimationCurve> curve1(
1718 KeyframedTransformAnimationCurve::Create()); 1745 KeyframedTransformAnimationCurve::Create());
1719 1746
1720 TransformOperations operations1; 1747 TransformOperations operations1;
1721 curve1->AddKeyframe( 1748 curve1->AddKeyframe(
1722 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); 1749 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
1723 operations1.AppendTranslate(10.0, 15.0, 0.0); 1750 operations1.AppendTranslate(10.0, 15.0, 0.0);
1724 curve1->AddKeyframe(TransformKeyframe::Create( 1751 curve1->AddKeyframe(TransformKeyframe::Create(
1725 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr)); 1752 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr));
1726 1753
1727 scoped_ptr<Animation> animation( 1754 std::unique_ptr<Animation> animation(
1728 Animation::Create(std::move(curve1), 1, 1, TargetProperty::TRANSFORM)); 1755 Animation::Create(std::move(curve1), 1, 1, TargetProperty::TRANSFORM));
1729 controller_impl->AddAnimation(std::move(animation)); 1756 controller_impl->AddAnimation(std::move(animation));
1730 1757
1731 scoped_ptr<KeyframedTransformAnimationCurve> curve2( 1758 std::unique_ptr<KeyframedTransformAnimationCurve> curve2(
1732 KeyframedTransformAnimationCurve::Create()); 1759 KeyframedTransformAnimationCurve::Create());
1733 1760
1734 TransformOperations operations2; 1761 TransformOperations operations2;
1735 curve2->AddKeyframe( 1762 curve2->AddKeyframe(
1736 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr)); 1763 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr));
1737 operations2.AppendScale(2.0, 3.0, 4.0); 1764 operations2.AppendScale(2.0, 3.0, 4.0);
1738 curve2->AddKeyframe(TransformKeyframe::Create( 1765 curve2->AddKeyframe(TransformKeyframe::Create(
1739 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); 1766 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr));
1740 1767
1741 animation = 1768 animation =
(...skipping 15 matching lines...) Expand all
1757 EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 7.f, 16.f, 20.f).ToString(), 1784 EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 7.f, 16.f, 20.f).ToString(),
1758 bounds.ToString()); 1785 bounds.ToString());
1759 1786
1760 controller_impl->GetAnimationById(2) 1787 controller_impl->GetAnimationById(2)
1761 ->SetRunState(Animation::FINISHED, TicksFromSecondsF(0.0)); 1788 ->SetRunState(Animation::FINISHED, TicksFromSecondsF(0.0));
1762 1789
1763 // There are no longer any running animations. 1790 // There are no longer any running animations.
1764 EXPECT_FALSE(controller_impl->HasTransformAnimationThatInflatesBounds()); 1791 EXPECT_FALSE(controller_impl->HasTransformAnimationThatInflatesBounds());
1765 1792
1766 // Add an animation whose bounds we don't yet support computing. 1793 // Add an animation whose bounds we don't yet support computing.
1767 scoped_ptr<KeyframedTransformAnimationCurve> curve3( 1794 std::unique_ptr<KeyframedTransformAnimationCurve> curve3(
1768 KeyframedTransformAnimationCurve::Create()); 1795 KeyframedTransformAnimationCurve::Create());
1769 TransformOperations operations3; 1796 TransformOperations operations3;
1770 gfx::Transform transform3; 1797 gfx::Transform transform3;
1771 transform3.Scale3d(1.0, 2.0, 3.0); 1798 transform3.Scale3d(1.0, 2.0, 3.0);
1772 curve3->AddKeyframe( 1799 curve3->AddKeyframe(
1773 TransformKeyframe::Create(base::TimeDelta(), operations3, nullptr)); 1800 TransformKeyframe::Create(base::TimeDelta(), operations3, nullptr));
1774 operations3.AppendMatrix(transform3); 1801 operations3.AppendMatrix(transform3);
1775 curve3->AddKeyframe(TransformKeyframe::Create( 1802 curve3->AddKeyframe(TransformKeyframe::Create(
1776 base::TimeDelta::FromSecondsD(1.0), operations3, nullptr)); 1803 base::TimeDelta::FromSecondsD(1.0), operations3, nullptr));
1777 animation = 1804 animation =
1778 Animation::Create(std::move(curve3), 3, 3, TargetProperty::TRANSFORM); 1805 Animation::Create(std::move(curve3), 3, 3, TargetProperty::TRANSFORM);
1779 controller_impl->AddAnimation(std::move(animation)); 1806 controller_impl->AddAnimation(std::move(animation));
1780 EXPECT_FALSE(controller_impl->TransformAnimationBoundsForBox(box, &bounds)); 1807 EXPECT_FALSE(controller_impl->TransformAnimationBoundsForBox(box, &bounds));
1781 } 1808 }
1782 1809
1783 // Tests that AbortAnimations aborts all animations targeting the specified 1810 // Tests that AbortAnimations aborts all animations targeting the specified
1784 // property. 1811 // property.
1785 TEST(LayerAnimationControllerTest, AbortAnimations) { 1812 TEST(LayerAnimationControllerTest, AbortAnimations) {
1786 FakeLayerAnimationValueObserver dummy; 1813 FakeLayerAnimationValueObserver dummy;
1787 scoped_refptr<LayerAnimationController> controller( 1814 scoped_refptr<LayerAnimationController> controller(
1788 LayerAnimationController::Create(0)); 1815 LayerAnimationController::Create(0));
1789 controller->AddValueObserver(&dummy); 1816 controller->AddValueObserver(&dummy);
1790 1817
1791 // Start with several animations, and allow some of them to reach the finished 1818 // Start with several animations, and allow some of them to reach the finished
1792 // state. 1819 // state.
1793 controller->AddAnimation(Animation::Create( 1820 controller->AddAnimation(Animation::Create(
1794 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 1, 1, 1821 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 1, 1,
1795 TargetProperty::TRANSFORM)); 1822 TargetProperty::TRANSFORM));
1796 controller->AddAnimation(Animation::Create( 1823 controller->AddAnimation(Animation::Create(
1797 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 2, 2, 1824 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
1798 TargetProperty::OPACITY)); 1825 2, 2, TargetProperty::OPACITY));
1799 controller->AddAnimation(Animation::Create( 1826 controller->AddAnimation(Animation::Create(
1800 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 3, 3, 1827 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 3, 3,
1801 TargetProperty::TRANSFORM)); 1828 TargetProperty::TRANSFORM));
1802 controller->AddAnimation(Animation::Create( 1829 controller->AddAnimation(Animation::Create(
1803 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2.0)), 4, 4, 1830 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(2.0)), 4, 4,
1804 TargetProperty::TRANSFORM)); 1831 TargetProperty::TRANSFORM));
1805 controller->AddAnimation(Animation::Create( 1832 controller->AddAnimation(Animation::Create(
1806 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 5, 5, 1833 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
1807 TargetProperty::OPACITY)); 1834 5, 5, TargetProperty::OPACITY));
1808 1835
1809 controller->Animate(kInitialTickTime); 1836 controller->Animate(kInitialTickTime);
1810 controller->UpdateState(true, nullptr); 1837 controller->UpdateState(true, nullptr);
1811 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); 1838 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1812 controller->UpdateState(true, nullptr); 1839 controller->UpdateState(true, nullptr);
1813 1840
1814 EXPECT_EQ(Animation::FINISHED, controller->GetAnimationById(1)->run_state()); 1841 EXPECT_EQ(Animation::FINISHED, controller->GetAnimationById(1)->run_state());
1815 EXPECT_EQ(Animation::FINISHED, controller->GetAnimationById(2)->run_state()); 1842 EXPECT_EQ(Animation::FINISHED, controller->GetAnimationById(2)->run_state());
1816 EXPECT_EQ(Animation::RUNNING, controller->GetAnimationById(3)->run_state()); 1843 EXPECT_EQ(Animation::RUNNING, controller->GetAnimationById(3)->run_state());
1817 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, 1844 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1930 controller->AddValueObserver(&dummy); 1957 controller->AddValueObserver(&dummy);
1931 FakeAnimationDelegate delegate_impl; 1958 FakeAnimationDelegate delegate_impl;
1932 controller_impl->set_layer_animation_delegate(&delegate_impl); 1959 controller_impl->set_layer_animation_delegate(&delegate_impl);
1933 FakeAnimationDelegate delegate; 1960 FakeAnimationDelegate delegate;
1934 controller->set_layer_animation_delegate(&delegate); 1961 controller->set_layer_animation_delegate(&delegate);
1935 1962
1936 // Add impl-only scroll offset animation. 1963 // Add impl-only scroll offset animation.
1937 int animation_id = 1; 1964 int animation_id = 1;
1938 gfx::ScrollOffset initial_value(100.f, 300.f); 1965 gfx::ScrollOffset initial_value(100.f, 300.f);
1939 gfx::ScrollOffset target_value(300.f, 200.f); 1966 gfx::ScrollOffset target_value(300.f, 200.f);
1940 scoped_ptr<ScrollOffsetAnimationCurve> curve( 1967 std::unique_ptr<ScrollOffsetAnimationCurve> curve(
1941 ScrollOffsetAnimationCurve::Create(target_value, 1968 ScrollOffsetAnimationCurve::Create(target_value,
1942 EaseInOutTimingFunction::Create())); 1969 EaseInOutTimingFunction::Create()));
1943 curve->SetInitialValue(initial_value); 1970 curve->SetInitialValue(initial_value);
1944 scoped_ptr<Animation> animation(Animation::Create( 1971 std::unique_ptr<Animation> animation(Animation::Create(
1945 std::move(curve), animation_id, 0, TargetProperty::SCROLL_OFFSET)); 1972 std::move(curve), animation_id, 0, TargetProperty::SCROLL_OFFSET));
1946 animation->set_start_time(TicksFromSecondsF(123)); 1973 animation->set_start_time(TicksFromSecondsF(123));
1947 animation->set_is_impl_only(true); 1974 animation->set_is_impl_only(true);
1948 controller_impl->AddAnimation(std::move(animation)); 1975 controller_impl->AddAnimation(std::move(animation));
1949 1976
1950 controller->PushAnimationUpdatesTo(controller_impl.get()); 1977 controller->PushAnimationUpdatesTo(controller_impl.get());
1951 controller_impl->ActivateAnimations(); 1978 controller_impl->ActivateAnimations();
1952 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); 1979 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id));
1953 1980
1954 controller_impl->AbortAnimations(TargetProperty::SCROLL_OFFSET, 1981 controller_impl->AbortAnimations(TargetProperty::SCROLL_OFFSET,
(...skipping 24 matching lines...) Expand all
1979 2006
1980 controller->PushAnimationUpdatesTo(controller_impl.get()); 2007 controller->PushAnimationUpdatesTo(controller_impl.get());
1981 controller_impl->ActivateAnimations(); 2008 controller_impl->ActivateAnimations();
1982 EXPECT_FALSE(controller->GetAnimationById(animation_id)); 2009 EXPECT_FALSE(controller->GetAnimationById(animation_id));
1983 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)); 2010 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id));
1984 } 2011 }
1985 2012
1986 // Ensure that we only generate FINISHED events for animations in a group 2013 // Ensure that we only generate FINISHED events for animations in a group
1987 // once all animations in that group are finished. 2014 // once all animations in that group are finished.
1988 TEST(LayerAnimationControllerTest, FinishedEventsForGroup) { 2015 TEST(LayerAnimationControllerTest, FinishedEventsForGroup) {
1989 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 2016 std::unique_ptr<AnimationEvents> events(
2017 base::WrapUnique(new AnimationEvents));
1990 FakeLayerAnimationValueObserver dummy_impl; 2018 FakeLayerAnimationValueObserver dummy_impl;
1991 scoped_refptr<LayerAnimationController> controller_impl( 2019 scoped_refptr<LayerAnimationController> controller_impl(
1992 LayerAnimationController::Create(0)); 2020 LayerAnimationController::Create(0));
1993 controller_impl->AddValueObserver(&dummy_impl); 2021 controller_impl->AddValueObserver(&dummy_impl);
1994 2022
1995 const int group_id = 1; 2023 const int group_id = 1;
1996 2024
1997 // Add two animations with the same group id but different durations. 2025 // Add two animations with the same group id but different durations.
1998 scoped_ptr<Animation> first_animation(Animation::Create( 2026 std::unique_ptr<Animation> first_animation(Animation::Create(
1999 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2.0)), 1, group_id, 2027 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(2.0)), 1,
2000 TargetProperty::TRANSFORM)); 2028 group_id, TargetProperty::TRANSFORM));
2001 first_animation->set_is_controlling_instance_for_test(true); 2029 first_animation->set_is_controlling_instance_for_test(true);
2002 controller_impl->AddAnimation(std::move(first_animation)); 2030 controller_impl->AddAnimation(std::move(first_animation));
2003 2031
2004 scoped_ptr<Animation> second_animation(Animation::Create( 2032 std::unique_ptr<Animation> second_animation(Animation::Create(
2005 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 2, 2033 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
2006 group_id, TargetProperty::OPACITY)); 2034 2, group_id, TargetProperty::OPACITY));
2007 second_animation->set_is_controlling_instance_for_test(true); 2035 second_animation->set_is_controlling_instance_for_test(true);
2008 controller_impl->AddAnimation(std::move(second_animation)); 2036 controller_impl->AddAnimation(std::move(second_animation));
2009 2037
2010 controller_impl->Animate(kInitialTickTime); 2038 controller_impl->Animate(kInitialTickTime);
2011 controller_impl->UpdateState(true, events.get()); 2039 controller_impl->UpdateState(true, events.get());
2012 2040
2013 // Both animations should have started. 2041 // Both animations should have started.
2014 EXPECT_EQ(2u, events->events_.size()); 2042 EXPECT_EQ(2u, events->events_.size());
2015 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type); 2043 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type);
2016 EXPECT_EQ(AnimationEvent::STARTED, events->events_[1].type); 2044 EXPECT_EQ(AnimationEvent::STARTED, events->events_[1].type);
(...skipping 18 matching lines...) Expand all
2035 // Both animations should have generated FINISHED events. 2063 // Both animations should have generated FINISHED events.
2036 EXPECT_EQ(2u, events->events_.size()); 2064 EXPECT_EQ(2u, events->events_.size());
2037 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type); 2065 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type);
2038 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[1].type); 2066 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[1].type);
2039 } 2067 }
2040 2068
2041 // Ensure that when a group has a mix of aborted and finished animations, 2069 // Ensure that when a group has a mix of aborted and finished animations,
2042 // we generate a FINISHED event for the finished animation and an ABORTED 2070 // we generate a FINISHED event for the finished animation and an ABORTED
2043 // event for the aborted animation. 2071 // event for the aborted animation.
2044 TEST(LayerAnimationControllerTest, FinishedAndAbortedEventsForGroup) { 2072 TEST(LayerAnimationControllerTest, FinishedAndAbortedEventsForGroup) {
2045 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 2073 std::unique_ptr<AnimationEvents> events(
2074 base::WrapUnique(new AnimationEvents));
2046 FakeLayerAnimationValueObserver dummy_impl; 2075 FakeLayerAnimationValueObserver dummy_impl;
2047 scoped_refptr<LayerAnimationController> controller_impl( 2076 scoped_refptr<LayerAnimationController> controller_impl(
2048 LayerAnimationController::Create(0)); 2077 LayerAnimationController::Create(0));
2049 controller_impl->AddValueObserver(&dummy_impl); 2078 controller_impl->AddValueObserver(&dummy_impl);
2050 2079
2051 // Add two animations with the same group id. 2080 // Add two animations with the same group id.
2052 scoped_ptr<Animation> first_animation(CreateAnimation( 2081 std::unique_ptr<Animation> first_animation(CreateAnimation(
2053 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 1, 2082 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 1,
2054 TargetProperty::TRANSFORM)); 2083 TargetProperty::TRANSFORM));
2055 first_animation->set_is_controlling_instance_for_test(true); 2084 first_animation->set_is_controlling_instance_for_test(true);
2056 controller_impl->AddAnimation(std::move(first_animation)); 2085 controller_impl->AddAnimation(std::move(first_animation));
2057 2086
2058 scoped_ptr<Animation> second_animation(CreateAnimation( 2087 std::unique_ptr<Animation> second_animation(CreateAnimation(
2059 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, 2088 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
2060 TargetProperty::OPACITY)); 2089 1, TargetProperty::OPACITY));
2061 second_animation->set_is_controlling_instance_for_test(true); 2090 second_animation->set_is_controlling_instance_for_test(true);
2062 controller_impl->AddAnimation(std::move(second_animation)); 2091 controller_impl->AddAnimation(std::move(second_animation));
2063 2092
2064 controller_impl->Animate(kInitialTickTime); 2093 controller_impl->Animate(kInitialTickTime);
2065 controller_impl->UpdateState(true, events.get()); 2094 controller_impl->UpdateState(true, events.get());
2066 2095
2067 // Both animations should have started. 2096 // Both animations should have started.
2068 EXPECT_EQ(2u, events->events_.size()); 2097 EXPECT_EQ(2u, events->events_.size());
2069 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type); 2098 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type);
2070 EXPECT_EQ(AnimationEvent::STARTED, events->events_[1].type); 2099 EXPECT_EQ(AnimationEvent::STARTED, events->events_[1].type);
(...skipping 14 matching lines...) Expand all
2085 EXPECT_EQ(TargetProperty::OPACITY, events->events_[1].target_property); 2114 EXPECT_EQ(TargetProperty::OPACITY, events->events_[1].target_property);
2086 } 2115 }
2087 2116
2088 TEST(LayerAnimationControllerTest, HasAnimationThatAffectsScale) { 2117 TEST(LayerAnimationControllerTest, HasAnimationThatAffectsScale) {
2089 scoped_refptr<LayerAnimationController> controller_impl( 2118 scoped_refptr<LayerAnimationController> controller_impl(
2090 LayerAnimationController::Create(0)); 2119 LayerAnimationController::Create(0));
2091 2120
2092 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale()); 2121 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale());
2093 2122
2094 controller_impl->AddAnimation(CreateAnimation( 2123 controller_impl->AddAnimation(CreateAnimation(
2095 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, 2124 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
2096 TargetProperty::OPACITY)); 2125 1, TargetProperty::OPACITY));
2097 2126
2098 // Opacity animations don't affect scale. 2127 // Opacity animations don't affect scale.
2099 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale()); 2128 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale());
2100 2129
2101 scoped_ptr<KeyframedTransformAnimationCurve> curve1( 2130 std::unique_ptr<KeyframedTransformAnimationCurve> curve1(
2102 KeyframedTransformAnimationCurve::Create()); 2131 KeyframedTransformAnimationCurve::Create());
2103 2132
2104 TransformOperations operations1; 2133 TransformOperations operations1;
2105 curve1->AddKeyframe( 2134 curve1->AddKeyframe(
2106 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); 2135 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
2107 operations1.AppendTranslate(10.0, 15.0, 0.0); 2136 operations1.AppendTranslate(10.0, 15.0, 0.0);
2108 curve1->AddKeyframe(TransformKeyframe::Create( 2137 curve1->AddKeyframe(TransformKeyframe::Create(
2109 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr)); 2138 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr));
2110 2139
2111 scoped_ptr<Animation> animation( 2140 std::unique_ptr<Animation> animation(
2112 Animation::Create(std::move(curve1), 2, 2, TargetProperty::TRANSFORM)); 2141 Animation::Create(std::move(curve1), 2, 2, TargetProperty::TRANSFORM));
2113 controller_impl->AddAnimation(std::move(animation)); 2142 controller_impl->AddAnimation(std::move(animation));
2114 2143
2115 // Translations don't affect scale. 2144 // Translations don't affect scale.
2116 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale()); 2145 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale());
2117 2146
2118 scoped_ptr<KeyframedTransformAnimationCurve> curve2( 2147 std::unique_ptr<KeyframedTransformAnimationCurve> curve2(
2119 KeyframedTransformAnimationCurve::Create()); 2148 KeyframedTransformAnimationCurve::Create());
2120 2149
2121 TransformOperations operations2; 2150 TransformOperations operations2;
2122 curve2->AddKeyframe( 2151 curve2->AddKeyframe(
2123 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr)); 2152 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr));
2124 operations2.AppendScale(2.0, 3.0, 4.0); 2153 operations2.AppendScale(2.0, 3.0, 4.0);
2125 curve2->AddKeyframe(TransformKeyframe::Create( 2154 curve2->AddKeyframe(TransformKeyframe::Create(
2126 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); 2155 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr));
2127 2156
2128 animation = 2157 animation =
(...skipping 13 matching lines...) Expand all
2142 TEST(LayerAnimationControllerTest, HasOnlyTranslationTransforms) { 2171 TEST(LayerAnimationControllerTest, HasOnlyTranslationTransforms) {
2143 scoped_refptr<LayerAnimationController> controller_impl( 2172 scoped_refptr<LayerAnimationController> controller_impl(
2144 LayerAnimationController::Create(0)); 2173 LayerAnimationController::Create(0));
2145 2174
2146 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms( 2175 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms(
2147 LayerAnimationController::ObserverType::ACTIVE)); 2176 LayerAnimationController::ObserverType::ACTIVE));
2148 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms( 2177 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms(
2149 LayerAnimationController::ObserverType::PENDING)); 2178 LayerAnimationController::ObserverType::PENDING));
2150 2179
2151 controller_impl->AddAnimation(CreateAnimation( 2180 controller_impl->AddAnimation(CreateAnimation(
2152 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, 2181 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
2153 TargetProperty::OPACITY)); 2182 1, TargetProperty::OPACITY));
2154 2183
2155 // Opacity animations aren't non-translation transforms. 2184 // Opacity animations aren't non-translation transforms.
2156 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms( 2185 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms(
2157 LayerAnimationController::ObserverType::ACTIVE)); 2186 LayerAnimationController::ObserverType::ACTIVE));
2158 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms( 2187 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms(
2159 LayerAnimationController::ObserverType::PENDING)); 2188 LayerAnimationController::ObserverType::PENDING));
2160 2189
2161 scoped_ptr<KeyframedTransformAnimationCurve> curve1( 2190 std::unique_ptr<KeyframedTransformAnimationCurve> curve1(
2162 KeyframedTransformAnimationCurve::Create()); 2191 KeyframedTransformAnimationCurve::Create());
2163 2192
2164 TransformOperations operations1; 2193 TransformOperations operations1;
2165 curve1->AddKeyframe( 2194 curve1->AddKeyframe(
2166 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); 2195 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
2167 operations1.AppendTranslate(10.0, 15.0, 0.0); 2196 operations1.AppendTranslate(10.0, 15.0, 0.0);
2168 curve1->AddKeyframe(TransformKeyframe::Create( 2197 curve1->AddKeyframe(TransformKeyframe::Create(
2169 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr)); 2198 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr));
2170 2199
2171 scoped_ptr<Animation> animation( 2200 std::unique_ptr<Animation> animation(
2172 Animation::Create(std::move(curve1), 2, 2, TargetProperty::TRANSFORM)); 2201 Animation::Create(std::move(curve1), 2, 2, TargetProperty::TRANSFORM));
2173 controller_impl->AddAnimation(std::move(animation)); 2202 controller_impl->AddAnimation(std::move(animation));
2174 2203
2175 // The only transform animation we've added is a translation. 2204 // The only transform animation we've added is a translation.
2176 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms( 2205 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms(
2177 LayerAnimationController::ObserverType::ACTIVE)); 2206 LayerAnimationController::ObserverType::ACTIVE));
2178 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms( 2207 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms(
2179 LayerAnimationController::ObserverType::PENDING)); 2208 LayerAnimationController::ObserverType::PENDING));
2180 2209
2181 scoped_ptr<KeyframedTransformAnimationCurve> curve2( 2210 std::unique_ptr<KeyframedTransformAnimationCurve> curve2(
2182 KeyframedTransformAnimationCurve::Create()); 2211 KeyframedTransformAnimationCurve::Create());
2183 2212
2184 TransformOperations operations2; 2213 TransformOperations operations2;
2185 curve2->AddKeyframe( 2214 curve2->AddKeyframe(
2186 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr)); 2215 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr));
2187 operations2.AppendScale(2.0, 3.0, 4.0); 2216 operations2.AppendScale(2.0, 3.0, 4.0);
2188 curve2->AddKeyframe(TransformKeyframe::Create( 2217 curve2->AddKeyframe(TransformKeyframe::Create(
2189 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); 2218 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr));
2190 2219
2191 animation = 2220 animation =
(...skipping 26 matching lines...) Expand all
2218 // HasOnlyTranslationTransforms. 2247 // HasOnlyTranslationTransforms.
2219 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms( 2248 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms(
2220 LayerAnimationController::ObserverType::PENDING)); 2249 LayerAnimationController::ObserverType::PENDING));
2221 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms( 2250 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms(
2222 LayerAnimationController::ObserverType::ACTIVE)); 2251 LayerAnimationController::ObserverType::ACTIVE));
2223 } 2252 }
2224 2253
2225 TEST(LayerAnimationControllerTest, AnimationStartScale) { 2254 TEST(LayerAnimationControllerTest, AnimationStartScale) {
2226 scoped_refptr<LayerAnimationController> controller_impl( 2255 scoped_refptr<LayerAnimationController> controller_impl(
2227 LayerAnimationController::Create(0)); 2256 LayerAnimationController::Create(0));
2228 scoped_ptr<KeyframedTransformAnimationCurve> curve1( 2257 std::unique_ptr<KeyframedTransformAnimationCurve> curve1(
2229 KeyframedTransformAnimationCurve::Create()); 2258 KeyframedTransformAnimationCurve::Create());
2230 2259
2231 TransformOperations operations1; 2260 TransformOperations operations1;
2232 operations1.AppendScale(2.0, 3.0, 4.0); 2261 operations1.AppendScale(2.0, 3.0, 4.0);
2233 curve1->AddKeyframe( 2262 curve1->AddKeyframe(
2234 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); 2263 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
2235 TransformOperations operations2; 2264 TransformOperations operations2;
2236 curve1->AddKeyframe(TransformKeyframe::Create( 2265 curve1->AddKeyframe(TransformKeyframe::Create(
2237 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); 2266 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr));
2238 scoped_ptr<Animation> animation( 2267 std::unique_ptr<Animation> animation(
2239 Animation::Create(std::move(curve1), 1, 1, TargetProperty::TRANSFORM)); 2268 Animation::Create(std::move(curve1), 1, 1, TargetProperty::TRANSFORM));
2240 animation->set_affects_active_observers(false); 2269 animation->set_affects_active_observers(false);
2241 controller_impl->AddAnimation(std::move(animation)); 2270 controller_impl->AddAnimation(std::move(animation));
2242 2271
2243 float start_scale = 0.f; 2272 float start_scale = 0.f;
2244 EXPECT_TRUE(controller_impl->AnimationStartScale( 2273 EXPECT_TRUE(controller_impl->AnimationStartScale(
2245 LayerAnimationController::ObserverType::PENDING, &start_scale)); 2274 LayerAnimationController::ObserverType::PENDING, &start_scale));
2246 EXPECT_EQ(4.f, start_scale); 2275 EXPECT_EQ(4.f, start_scale);
2247 EXPECT_TRUE(controller_impl->AnimationStartScale( 2276 EXPECT_TRUE(controller_impl->AnimationStartScale(
2248 LayerAnimationController::ObserverType::ACTIVE, &start_scale)); 2277 LayerAnimationController::ObserverType::ACTIVE, &start_scale));
2249 EXPECT_EQ(0.f, start_scale); 2278 EXPECT_EQ(0.f, start_scale);
2250 2279
2251 controller_impl->ActivateAnimations(); 2280 controller_impl->ActivateAnimations();
2252 EXPECT_TRUE(controller_impl->AnimationStartScale( 2281 EXPECT_TRUE(controller_impl->AnimationStartScale(
2253 LayerAnimationController::ObserverType::PENDING, &start_scale)); 2282 LayerAnimationController::ObserverType::PENDING, &start_scale));
2254 EXPECT_EQ(4.f, start_scale); 2283 EXPECT_EQ(4.f, start_scale);
2255 EXPECT_TRUE(controller_impl->AnimationStartScale( 2284 EXPECT_TRUE(controller_impl->AnimationStartScale(
2256 LayerAnimationController::ObserverType::ACTIVE, &start_scale)); 2285 LayerAnimationController::ObserverType::ACTIVE, &start_scale));
2257 EXPECT_EQ(4.f, start_scale); 2286 EXPECT_EQ(4.f, start_scale);
2258 2287
2259 scoped_ptr<KeyframedTransformAnimationCurve> curve2( 2288 std::unique_ptr<KeyframedTransformAnimationCurve> curve2(
2260 KeyframedTransformAnimationCurve::Create()); 2289 KeyframedTransformAnimationCurve::Create());
2261 2290
2262 TransformOperations operations3; 2291 TransformOperations operations3;
2263 curve2->AddKeyframe( 2292 curve2->AddKeyframe(
2264 TransformKeyframe::Create(base::TimeDelta(), operations3, nullptr)); 2293 TransformKeyframe::Create(base::TimeDelta(), operations3, nullptr));
2265 operations3.AppendScale(6.0, 5.0, 4.0); 2294 operations3.AppendScale(6.0, 5.0, 4.0);
2266 curve2->AddKeyframe(TransformKeyframe::Create( 2295 curve2->AddKeyframe(TransformKeyframe::Create(
2267 base::TimeDelta::FromSecondsD(1.0), operations3, nullptr)); 2296 base::TimeDelta::FromSecondsD(1.0), operations3, nullptr));
2268 2297
2269 controller_impl->RemoveAnimation(1); 2298 controller_impl->RemoveAnimation(1);
2270 animation = 2299 animation =
2271 Animation::Create(std::move(curve2), 2, 2, TargetProperty::TRANSFORM); 2300 Animation::Create(std::move(curve2), 2, 2, TargetProperty::TRANSFORM);
2272 2301
2273 // Reverse Direction 2302 // Reverse Direction
2274 animation->set_direction(Animation::DIRECTION_REVERSE); 2303 animation->set_direction(Animation::DIRECTION_REVERSE);
2275 animation->set_affects_active_observers(false); 2304 animation->set_affects_active_observers(false);
2276 controller_impl->AddAnimation(std::move(animation)); 2305 controller_impl->AddAnimation(std::move(animation));
2277 2306
2278 scoped_ptr<KeyframedTransformAnimationCurve> curve3( 2307 std::unique_ptr<KeyframedTransformAnimationCurve> curve3(
2279 KeyframedTransformAnimationCurve::Create()); 2308 KeyframedTransformAnimationCurve::Create());
2280 2309
2281 TransformOperations operations4; 2310 TransformOperations operations4;
2282 operations4.AppendScale(5.0, 3.0, 1.0); 2311 operations4.AppendScale(5.0, 3.0, 1.0);
2283 curve3->AddKeyframe( 2312 curve3->AddKeyframe(
2284 TransformKeyframe::Create(base::TimeDelta(), operations4, nullptr)); 2313 TransformKeyframe::Create(base::TimeDelta(), operations4, nullptr));
2285 TransformOperations operations5; 2314 TransformOperations operations5;
2286 curve3->AddKeyframe(TransformKeyframe::Create( 2315 curve3->AddKeyframe(TransformKeyframe::Create(
2287 base::TimeDelta::FromSecondsD(1.0), operations5, nullptr)); 2316 base::TimeDelta::FromSecondsD(1.0), operations5, nullptr));
2288 2317
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2324 LayerAnimationController::Create(0)); 2353 LayerAnimationController::Create(0));
2325 2354
2326 float max_scale = 0.f; 2355 float max_scale = 0.f;
2327 EXPECT_TRUE(controller_impl->MaximumTargetScale( 2356 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2328 LayerAnimationController::ObserverType::PENDING, &max_scale)); 2357 LayerAnimationController::ObserverType::PENDING, &max_scale));
2329 EXPECT_EQ(0.f, max_scale); 2358 EXPECT_EQ(0.f, max_scale);
2330 EXPECT_TRUE(controller_impl->MaximumTargetScale( 2359 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2331 LayerAnimationController::ObserverType::ACTIVE, &max_scale)); 2360 LayerAnimationController::ObserverType::ACTIVE, &max_scale));
2332 EXPECT_EQ(0.f, max_scale); 2361 EXPECT_EQ(0.f, max_scale);
2333 2362
2334 scoped_ptr<KeyframedTransformAnimationCurve> curve1( 2363 std::unique_ptr<KeyframedTransformAnimationCurve> curve1(
2335 KeyframedTransformAnimationCurve::Create()); 2364 KeyframedTransformAnimationCurve::Create());
2336 2365
2337 TransformOperations operations1; 2366 TransformOperations operations1;
2338 curve1->AddKeyframe( 2367 curve1->AddKeyframe(
2339 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); 2368 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
2340 operations1.AppendScale(2.0, 3.0, 4.0); 2369 operations1.AppendScale(2.0, 3.0, 4.0);
2341 curve1->AddKeyframe(TransformKeyframe::Create( 2370 curve1->AddKeyframe(TransformKeyframe::Create(
2342 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr)); 2371 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr));
2343 2372
2344 scoped_ptr<Animation> animation( 2373 std::unique_ptr<Animation> animation(
2345 Animation::Create(std::move(curve1), 1, 1, TargetProperty::TRANSFORM)); 2374 Animation::Create(std::move(curve1), 1, 1, TargetProperty::TRANSFORM));
2346 animation->set_affects_active_observers(false); 2375 animation->set_affects_active_observers(false);
2347 controller_impl->AddAnimation(std::move(animation)); 2376 controller_impl->AddAnimation(std::move(animation));
2348 2377
2349 EXPECT_TRUE(controller_impl->MaximumTargetScale( 2378 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2350 LayerAnimationController::ObserverType::PENDING, &max_scale)); 2379 LayerAnimationController::ObserverType::PENDING, &max_scale));
2351 EXPECT_EQ(4.f, max_scale); 2380 EXPECT_EQ(4.f, max_scale);
2352 EXPECT_TRUE(controller_impl->MaximumTargetScale( 2381 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2353 LayerAnimationController::ObserverType::ACTIVE, &max_scale)); 2382 LayerAnimationController::ObserverType::ACTIVE, &max_scale));
2354 EXPECT_EQ(0.f, max_scale); 2383 EXPECT_EQ(0.f, max_scale);
2355 2384
2356 controller_impl->ActivateAnimations(); 2385 controller_impl->ActivateAnimations();
2357 EXPECT_TRUE(controller_impl->MaximumTargetScale( 2386 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2358 LayerAnimationController::ObserverType::PENDING, &max_scale)); 2387 LayerAnimationController::ObserverType::PENDING, &max_scale));
2359 EXPECT_EQ(4.f, max_scale); 2388 EXPECT_EQ(4.f, max_scale);
2360 EXPECT_TRUE(controller_impl->MaximumTargetScale( 2389 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2361 LayerAnimationController::ObserverType::ACTIVE, &max_scale)); 2390 LayerAnimationController::ObserverType::ACTIVE, &max_scale));
2362 EXPECT_EQ(4.f, max_scale); 2391 EXPECT_EQ(4.f, max_scale);
2363 2392
2364 scoped_ptr<KeyframedTransformAnimationCurve> curve2( 2393 std::unique_ptr<KeyframedTransformAnimationCurve> curve2(
2365 KeyframedTransformAnimationCurve::Create()); 2394 KeyframedTransformAnimationCurve::Create());
2366 2395
2367 TransformOperations operations2; 2396 TransformOperations operations2;
2368 curve2->AddKeyframe( 2397 curve2->AddKeyframe(
2369 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr)); 2398 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr));
2370 operations2.AppendScale(6.0, 5.0, 4.0); 2399 operations2.AppendScale(6.0, 5.0, 4.0);
2371 curve2->AddKeyframe(TransformKeyframe::Create( 2400 curve2->AddKeyframe(TransformKeyframe::Create(
2372 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); 2401 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr));
2373 2402
2374 animation = 2403 animation =
2375 Animation::Create(std::move(curve2), 2, 2, TargetProperty::TRANSFORM); 2404 Animation::Create(std::move(curve2), 2, 2, TargetProperty::TRANSFORM);
2376 animation->set_affects_active_observers(false); 2405 animation->set_affects_active_observers(false);
2377 controller_impl->AddAnimation(std::move(animation)); 2406 controller_impl->AddAnimation(std::move(animation));
2378 2407
2379 EXPECT_TRUE(controller_impl->MaximumTargetScale( 2408 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2380 LayerAnimationController::ObserverType::PENDING, &max_scale)); 2409 LayerAnimationController::ObserverType::PENDING, &max_scale));
2381 EXPECT_EQ(6.f, max_scale); 2410 EXPECT_EQ(6.f, max_scale);
2382 EXPECT_TRUE(controller_impl->MaximumTargetScale( 2411 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2383 LayerAnimationController::ObserverType::ACTIVE, &max_scale)); 2412 LayerAnimationController::ObserverType::ACTIVE, &max_scale));
2384 EXPECT_EQ(4.f, max_scale); 2413 EXPECT_EQ(4.f, max_scale);
2385 2414
2386 controller_impl->ActivateAnimations(); 2415 controller_impl->ActivateAnimations();
2387 EXPECT_TRUE(controller_impl->MaximumTargetScale( 2416 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2388 LayerAnimationController::ObserverType::PENDING, &max_scale)); 2417 LayerAnimationController::ObserverType::PENDING, &max_scale));
2389 EXPECT_EQ(6.f, max_scale); 2418 EXPECT_EQ(6.f, max_scale);
2390 EXPECT_TRUE(controller_impl->MaximumTargetScale( 2419 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2391 LayerAnimationController::ObserverType::ACTIVE, &max_scale)); 2420 LayerAnimationController::ObserverType::ACTIVE, &max_scale));
2392 EXPECT_EQ(6.f, max_scale); 2421 EXPECT_EQ(6.f, max_scale);
2393 2422
2394 scoped_ptr<KeyframedTransformAnimationCurve> curve3( 2423 std::unique_ptr<KeyframedTransformAnimationCurve> curve3(
2395 KeyframedTransformAnimationCurve::Create()); 2424 KeyframedTransformAnimationCurve::Create());
2396 2425
2397 TransformOperations operations3; 2426 TransformOperations operations3;
2398 curve3->AddKeyframe( 2427 curve3->AddKeyframe(
2399 TransformKeyframe::Create(base::TimeDelta(), operations3, nullptr)); 2428 TransformKeyframe::Create(base::TimeDelta(), operations3, nullptr));
2400 operations3.AppendPerspective(6.0); 2429 operations3.AppendPerspective(6.0);
2401 curve3->AddKeyframe(TransformKeyframe::Create( 2430 curve3->AddKeyframe(TransformKeyframe::Create(
2402 base::TimeDelta::FromSecondsD(1.0), operations3, nullptr)); 2431 base::TimeDelta::FromSecondsD(1.0), operations3, nullptr));
2403 2432
2404 animation = 2433 animation =
(...skipping 25 matching lines...) Expand all
2430 EXPECT_EQ(4.f, max_scale); 2459 EXPECT_EQ(4.f, max_scale);
2431 EXPECT_TRUE(controller_impl->MaximumTargetScale( 2460 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2432 LayerAnimationController::ObserverType::ACTIVE, &max_scale)); 2461 LayerAnimationController::ObserverType::ACTIVE, &max_scale));
2433 EXPECT_EQ(4.f, max_scale); 2462 EXPECT_EQ(4.f, max_scale);
2434 } 2463 }
2435 2464
2436 TEST(LayerAnimationControllerTest, MaximumTargetScaleWithDirection) { 2465 TEST(LayerAnimationControllerTest, MaximumTargetScaleWithDirection) {
2437 scoped_refptr<LayerAnimationController> controller_impl( 2466 scoped_refptr<LayerAnimationController> controller_impl(
2438 LayerAnimationController::Create(0)); 2467 LayerAnimationController::Create(0));
2439 2468
2440 scoped_ptr<KeyframedTransformAnimationCurve> curve1( 2469 std::unique_ptr<KeyframedTransformAnimationCurve> curve1(
2441 KeyframedTransformAnimationCurve::Create()); 2470 KeyframedTransformAnimationCurve::Create());
2442 TransformOperations operations1; 2471 TransformOperations operations1;
2443 operations1.AppendScale(1.0, 2.0, 3.0); 2472 operations1.AppendScale(1.0, 2.0, 3.0);
2444 curve1->AddKeyframe( 2473 curve1->AddKeyframe(
2445 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); 2474 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
2446 TransformOperations operations2; 2475 TransformOperations operations2;
2447 operations2.AppendScale(4.0, 5.0, 6.0); 2476 operations2.AppendScale(4.0, 5.0, 6.0);
2448 curve1->AddKeyframe(TransformKeyframe::Create( 2477 curve1->AddKeyframe(TransformKeyframe::Create(
2449 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); 2478 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr));
2450 2479
2451 scoped_ptr<Animation> animation_owned( 2480 std::unique_ptr<Animation> animation_owned(
2452 Animation::Create(std::move(curve1), 1, 1, TargetProperty::TRANSFORM)); 2481 Animation::Create(std::move(curve1), 1, 1, TargetProperty::TRANSFORM));
2453 Animation* animation = animation_owned.get(); 2482 Animation* animation = animation_owned.get();
2454 controller_impl->AddAnimation(std::move(animation_owned)); 2483 controller_impl->AddAnimation(std::move(animation_owned));
2455 2484
2456 float max_scale = 0.f; 2485 float max_scale = 0.f;
2457 2486
2458 EXPECT_GT(animation->playback_rate(), 0.0); 2487 EXPECT_GT(animation->playback_rate(), 0.0);
2459 2488
2460 // NORMAL direction with positive playback rate. 2489 // NORMAL direction with positive playback rate.
2461 animation->set_direction(Animation::DIRECTION_NORMAL); 2490 animation->set_direction(Animation::DIRECTION_NORMAL);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
2526 animation->set_direction(Animation::DIRECTION_REVERSE); 2555 animation->set_direction(Animation::DIRECTION_REVERSE);
2527 EXPECT_TRUE(controller_impl->MaximumTargetScale( 2556 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2528 LayerAnimationController::ObserverType::PENDING, &max_scale)); 2557 LayerAnimationController::ObserverType::PENDING, &max_scale));
2529 EXPECT_EQ(6.f, max_scale); 2558 EXPECT_EQ(6.f, max_scale);
2530 EXPECT_TRUE(controller_impl->MaximumTargetScale( 2559 EXPECT_TRUE(controller_impl->MaximumTargetScale(
2531 LayerAnimationController::ObserverType::ACTIVE, &max_scale)); 2560 LayerAnimationController::ObserverType::ACTIVE, &max_scale));
2532 EXPECT_EQ(6.f, max_scale); 2561 EXPECT_EQ(6.f, max_scale);
2533 } 2562 }
2534 2563
2535 TEST(LayerAnimationControllerTest, NewlyPushedAnimationWaitsForActivation) { 2564 TEST(LayerAnimationControllerTest, NewlyPushedAnimationWaitsForActivation) {
2536 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 2565 std::unique_ptr<AnimationEvents> events(
2566 base::WrapUnique(new AnimationEvents));
2537 FakeLayerAnimationValueObserver dummy_impl; 2567 FakeLayerAnimationValueObserver dummy_impl;
2538 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; 2568 FakeInactiveLayerAnimationValueObserver pending_dummy_impl;
2539 scoped_refptr<LayerAnimationController> controller_impl( 2569 scoped_refptr<LayerAnimationController> controller_impl(
2540 LayerAnimationController::Create(0)); 2570 LayerAnimationController::Create(0));
2541 controller_impl->AddValueObserver(&dummy_impl); 2571 controller_impl->AddValueObserver(&dummy_impl);
2542 controller_impl->AddValueObserver(&pending_dummy_impl); 2572 controller_impl->AddValueObserver(&pending_dummy_impl);
2543 FakeLayerAnimationValueObserver dummy; 2573 FakeLayerAnimationValueObserver dummy;
2544 scoped_refptr<LayerAnimationController> controller( 2574 scoped_refptr<LayerAnimationController> controller(
2545 LayerAnimationController::Create(0)); 2575 LayerAnimationController::Create(0));
2546 controller->AddValueObserver(&dummy); 2576 controller->AddValueObserver(&dummy);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2588 2618
2589 // Since the animation has been activated, it should have reached the 2619 // Since the animation has been activated, it should have reached the
2590 // RUNNING state and the active observer should start to get ticked. 2620 // RUNNING state and the active observer should start to get ticked.
2591 EXPECT_EQ(Animation::RUNNING, 2621 EXPECT_EQ(Animation::RUNNING,
2592 controller_impl->GetAnimationById(animation_id)->run_state()); 2622 controller_impl->GetAnimationById(animation_id)->run_state());
2593 EXPECT_EQ(0.5f, pending_dummy_impl.opacity()); 2623 EXPECT_EQ(0.5f, pending_dummy_impl.opacity());
2594 EXPECT_EQ(0.5f, dummy_impl.opacity()); 2624 EXPECT_EQ(0.5f, dummy_impl.opacity());
2595 } 2625 }
2596 2626
2597 TEST(LayerAnimationControllerTest, ActivationBetweenAnimateAndUpdateState) { 2627 TEST(LayerAnimationControllerTest, ActivationBetweenAnimateAndUpdateState) {
2598 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 2628 std::unique_ptr<AnimationEvents> events(
2629 base::WrapUnique(new AnimationEvents));
2599 FakeLayerAnimationValueObserver dummy_impl; 2630 FakeLayerAnimationValueObserver dummy_impl;
2600 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; 2631 FakeInactiveLayerAnimationValueObserver pending_dummy_impl;
2601 scoped_refptr<LayerAnimationController> controller_impl( 2632 scoped_refptr<LayerAnimationController> controller_impl(
2602 LayerAnimationController::Create(0)); 2633 LayerAnimationController::Create(0));
2603 controller_impl->AddValueObserver(&dummy_impl); 2634 controller_impl->AddValueObserver(&dummy_impl);
2604 controller_impl->AddValueObserver(&pending_dummy_impl); 2635 controller_impl->AddValueObserver(&pending_dummy_impl);
2605 FakeLayerAnimationValueObserver dummy; 2636 FakeLayerAnimationValueObserver dummy;
2606 scoped_refptr<LayerAnimationController> controller( 2637 scoped_refptr<LayerAnimationController> controller(
2607 LayerAnimationController::Create(0)); 2638 LayerAnimationController::Create(0));
2608 controller->AddValueObserver(&dummy); 2639 controller->AddValueObserver(&dummy);
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
2791 2822
2792 controller->Animate(kInitialTickTime); 2823 controller->Animate(kInitialTickTime);
2793 EXPECT_EQ(0.f, dummy.opacity()); 2824 EXPECT_EQ(0.f, dummy.opacity());
2794 2825
2795 // Opacity values are clipped [0,1] 2826 // Opacity values are clipped [0,1]
2796 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); 2827 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
2797 EXPECT_EQ(0.f, dummy.opacity()); 2828 EXPECT_EQ(0.f, dummy.opacity());
2798 } 2829 }
2799 2830
2800 TEST(LayerAnimationControllerTest, PushedDeletedAnimationWaitsForActivation) { 2831 TEST(LayerAnimationControllerTest, PushedDeletedAnimationWaitsForActivation) {
2801 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 2832 std::unique_ptr<AnimationEvents> events(
2833 base::WrapUnique(new AnimationEvents));
2802 FakeLayerAnimationValueObserver dummy_impl; 2834 FakeLayerAnimationValueObserver dummy_impl;
2803 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; 2835 FakeInactiveLayerAnimationValueObserver pending_dummy_impl;
2804 scoped_refptr<LayerAnimationController> controller_impl( 2836 scoped_refptr<LayerAnimationController> controller_impl(
2805 LayerAnimationController::Create(0)); 2837 LayerAnimationController::Create(0));
2806 controller_impl->AddValueObserver(&dummy_impl); 2838 controller_impl->AddValueObserver(&dummy_impl);
2807 controller_impl->AddValueObserver(&pending_dummy_impl); 2839 controller_impl->AddValueObserver(&pending_dummy_impl);
2808 FakeLayerAnimationValueObserver dummy; 2840 FakeLayerAnimationValueObserver dummy;
2809 scoped_refptr<LayerAnimationController> controller( 2841 scoped_refptr<LayerAnimationController> controller(
2810 LayerAnimationController::Create(0)); 2842 LayerAnimationController::Create(0));
2811 controller->AddValueObserver(&dummy); 2843 controller->AddValueObserver(&dummy);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2847 2879
2848 controller_impl->ActivateAnimations(); 2880 controller_impl->ActivateAnimations();
2849 2881
2850 // Activation should cause the animation to be deleted. 2882 // Activation should cause the animation to be deleted.
2851 EXPECT_FALSE(controller_impl->has_any_animation()); 2883 EXPECT_FALSE(controller_impl->has_any_animation());
2852 } 2884 }
2853 2885
2854 // Tests that an animation that affects only active observers won't block 2886 // Tests that an animation that affects only active observers won't block
2855 // an animation that affects only pending observers from starting. 2887 // an animation that affects only pending observers from starting.
2856 TEST(LayerAnimationControllerTest, StartAnimationsAffectingDifferentObservers) { 2888 TEST(LayerAnimationControllerTest, StartAnimationsAffectingDifferentObservers) {
2857 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 2889 std::unique_ptr<AnimationEvents> events(
2890 base::WrapUnique(new AnimationEvents));
2858 FakeLayerAnimationValueObserver dummy_impl; 2891 FakeLayerAnimationValueObserver dummy_impl;
2859 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; 2892 FakeInactiveLayerAnimationValueObserver pending_dummy_impl;
2860 scoped_refptr<LayerAnimationController> controller_impl( 2893 scoped_refptr<LayerAnimationController> controller_impl(
2861 LayerAnimationController::Create(0)); 2894 LayerAnimationController::Create(0));
2862 controller_impl->AddValueObserver(&dummy_impl); 2895 controller_impl->AddValueObserver(&dummy_impl);
2863 controller_impl->AddValueObserver(&pending_dummy_impl); 2896 controller_impl->AddValueObserver(&pending_dummy_impl);
2864 FakeLayerAnimationValueObserver dummy; 2897 FakeLayerAnimationValueObserver dummy;
2865 scoped_refptr<LayerAnimationController> controller( 2898 scoped_refptr<LayerAnimationController> controller(
2866 LayerAnimationController::Create(0)); 2899 LayerAnimationController::Create(0));
2867 controller->AddValueObserver(&dummy); 2900 controller->AddValueObserver(&dummy);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
2932 EXPECT_EQ(1.f, dummy_impl.opacity()); 2965 EXPECT_EQ(1.f, dummy_impl.opacity());
2933 } 2966 }
2934 2967
2935 TEST(LayerAnimationControllerTest, TestIsCurrentlyAnimatingProperty) { 2968 TEST(LayerAnimationControllerTest, TestIsCurrentlyAnimatingProperty) {
2936 FakeLayerAnimationValueObserver dummy; 2969 FakeLayerAnimationValueObserver dummy;
2937 scoped_refptr<LayerAnimationController> controller( 2970 scoped_refptr<LayerAnimationController> controller(
2938 LayerAnimationController::Create(0)); 2971 LayerAnimationController::Create(0));
2939 controller->AddValueObserver(&dummy); 2972 controller->AddValueObserver(&dummy);
2940 2973
2941 // Create an animation that initially affects only pending observers. 2974 // Create an animation that initially affects only pending observers.
2942 scoped_ptr<Animation> animation(CreateAnimation( 2975 std::unique_ptr<Animation> animation(CreateAnimation(
2943 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, 2976 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
2944 TargetProperty::OPACITY)); 2977 1, TargetProperty::OPACITY));
2945 animation->set_affects_active_observers(false); 2978 animation->set_affects_active_observers(false);
2946 2979
2947 controller->AddAnimation(std::move(animation)); 2980 controller->AddAnimation(std::move(animation));
2948 controller->Animate(kInitialTickTime); 2981 controller->Animate(kInitialTickTime);
2949 EXPECT_TRUE(controller->IsCurrentlyAnimatingProperty( 2982 EXPECT_TRUE(controller->IsCurrentlyAnimatingProperty(
2950 TargetProperty::OPACITY, 2983 TargetProperty::OPACITY,
2951 LayerAnimationController::ObserverType::PENDING)); 2984 LayerAnimationController::ObserverType::PENDING));
2952 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( 2985 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty(
2953 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); 2986 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE));
2954 controller->UpdateState(true, nullptr); 2987 controller->UpdateState(true, nullptr);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
3009 } 3042 }
3010 3043
3011 TEST(LayerAnimationControllerTest, TestIsAnimatingPropertyTimeOffsetFillMode) { 3044 TEST(LayerAnimationControllerTest, TestIsAnimatingPropertyTimeOffsetFillMode) {
3012 FakeLayerAnimationValueObserver dummy; 3045 FakeLayerAnimationValueObserver dummy;
3013 scoped_refptr<LayerAnimationController> controller( 3046 scoped_refptr<LayerAnimationController> controller(
3014 LayerAnimationController::Create(0)); 3047 LayerAnimationController::Create(0));
3015 controller->AddValueObserver(&dummy); 3048 controller->AddValueObserver(&dummy);
3016 3049
3017 // Create an animation that initially affects only pending observers, and has 3050 // Create an animation that initially affects only pending observers, and has
3018 // a start delay of 2 seconds. 3051 // a start delay of 2 seconds.
3019 scoped_ptr<Animation> animation(CreateAnimation( 3052 std::unique_ptr<Animation> animation(CreateAnimation(
3020 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, 3053 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
3021 TargetProperty::OPACITY)); 3054 1, TargetProperty::OPACITY));
3022 animation->set_fill_mode(Animation::FILL_MODE_NONE); 3055 animation->set_fill_mode(Animation::FILL_MODE_NONE);
3023 animation->set_time_offset(TimeDelta::FromMilliseconds(-2000)); 3056 animation->set_time_offset(TimeDelta::FromMilliseconds(-2000));
3024 animation->set_affects_active_observers(false); 3057 animation->set_affects_active_observers(false);
3025 3058
3026 controller->AddAnimation(std::move(animation)); 3059 controller->AddAnimation(std::move(animation));
3027 3060
3028 controller->Animate(kInitialTickTime); 3061 controller->Animate(kInitialTickTime);
3029 3062
3030 // Since the animation has a start delay, the observers it affects have a 3063 // Since the animation has a start delay, the observers it affects have a
3031 // potentially running transform animation but aren't currently animating 3064 // potentially running transform animation but aren't currently animating
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
3092 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); 3125 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE));
3093 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( 3126 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty(
3094 TargetProperty::OPACITY, 3127 TargetProperty::OPACITY,
3095 LayerAnimationController::ObserverType::PENDING)); 3128 LayerAnimationController::ObserverType::PENDING));
3096 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( 3129 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty(
3097 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); 3130 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE));
3098 } 3131 }
3099 3132
3100 } // namespace 3133 } // namespace
3101 } // namespace cc 3134 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/layer_animation_controller.cc ('k') | cc/animation/scroll_offset_animation_curve.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698