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

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

Issue 693883004: Make cc::animation::TrimTimeToCurrentIteration,cc::AnimationCurve::Duration use TimeTicks/TimeDelta (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
ajuma 2014/11/07 15:58:00 Please leave this blank line as is.
patro 2014/11/10 09:46:52 Done.
7 #include "cc/animation/animation.h" 6 #include "cc/animation/animation.h"
8 #include "cc/animation/animation_curve.h" 7 #include "cc/animation/animation_curve.h"
9 #include "cc/animation/animation_delegate.h" 8 #include "cc/animation/animation_delegate.h"
10 #include "cc/animation/animation_registrar.h" 9 #include "cc/animation/animation_registrar.h"
11 #include "cc/animation/keyframed_animation_curve.h" 10 #include "cc/animation/keyframed_animation_curve.h"
12 #include "cc/animation/scroll_offset_animation_curve.h" 11 #include "cc/animation/scroll_offset_animation_curve.h"
13 #include "cc/animation/transform_operations.h" 12 #include "cc/animation/transform_operations.h"
14 #include "cc/test/animation_test_common.h" 13 #include "cc/test/animation_test_common.h"
15 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 665
667 scoped_ptr<Animation> animation( 666 scoped_ptr<Animation> animation(
668 Animation::Create(curve.Pass(), 1, 0, Animation::ScrollOffset)); 667 Animation::Create(curve.Pass(), 1, 0, Animation::ScrollOffset));
669 animation->set_needs_synchronized_start_time(true); 668 animation->set_needs_synchronized_start_time(true);
670 controller->AddAnimation(animation.Pass()); 669 controller->AddAnimation(animation.Pass());
671 670
672 dummy_provider_impl.set_scroll_offset(initial_value); 671 dummy_provider_impl.set_scroll_offset(initial_value);
673 controller->PushAnimationUpdatesTo(controller_impl.get()); 672 controller->PushAnimationUpdatesTo(controller_impl.get());
674 controller_impl->ActivateAnimations(); 673 controller_impl->ActivateAnimations();
675 EXPECT_TRUE(controller_impl->GetAnimation(Animation::ScrollOffset)); 674 EXPECT_TRUE(controller_impl->GetAnimation(Animation::ScrollOffset));
676 double duration_in_seconds = 675 TimeDelta duration = controller_impl->GetAnimation(Animation::ScrollOffset)
677 controller_impl->GetAnimation(Animation::ScrollOffset) 676 ->curve()
678 ->curve() 677 ->Duration();
679 ->Duration();
680 TimeDelta duration = TimeDelta::FromMicroseconds(
681 duration_in_seconds * base::Time::kMicrosecondsPerSecond);
682 EXPECT_EQ( 678 EXPECT_EQ(
683 duration_in_seconds, 679 duration,
684 controller->GetAnimation(Animation::ScrollOffset)->curve()->Duration()); 680 controller->GetAnimation(Animation::ScrollOffset)->curve()->Duration());
685 681
686 controller->Animate(kInitialTickTime); 682 controller->Animate(kInitialTickTime);
687 controller->UpdateState(true, nullptr); 683 controller->UpdateState(true, nullptr);
688 EXPECT_TRUE(controller->HasActiveAnimation()); 684 EXPECT_TRUE(controller->HasActiveAnimation());
689 EXPECT_EQ(initial_value, dummy.scroll_offset()); 685 EXPECT_EQ(initial_value, dummy.scroll_offset());
690 686
691 controller_impl->Animate(kInitialTickTime); 687 controller_impl->Animate(kInitialTickTime);
692 controller_impl->UpdateState(true, events.get()); 688 controller_impl->UpdateState(true, events.get());
693 EXPECT_TRUE(controller_impl->HasActiveAnimation()); 689 EXPECT_TRUE(controller_impl->HasActiveAnimation());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 744
749 scoped_ptr<Animation> animation( 745 scoped_ptr<Animation> animation(
750 Animation::Create(curve.Pass(), 1, 0, Animation::ScrollOffset)); 746 Animation::Create(curve.Pass(), 1, 0, Animation::ScrollOffset));
751 animation->set_needs_synchronized_start_time(true); 747 animation->set_needs_synchronized_start_time(true);
752 controller->AddAnimation(animation.Pass()); 748 controller->AddAnimation(animation.Pass());
753 749
754 dummy_provider.set_scroll_offset(initial_value); 750 dummy_provider.set_scroll_offset(initial_value);
755 controller->PushAnimationUpdatesTo(controller_impl.get()); 751 controller->PushAnimationUpdatesTo(controller_impl.get());
756 controller_impl->ActivateAnimations(); 752 controller_impl->ActivateAnimations();
757 EXPECT_TRUE(controller_impl->GetAnimation(Animation::ScrollOffset)); 753 EXPECT_TRUE(controller_impl->GetAnimation(Animation::ScrollOffset));
758 double duration_in_seconds = 754 TimeDelta duration = controller_impl->GetAnimation(Animation::ScrollOffset)
759 controller_impl->GetAnimation(Animation::ScrollOffset) 755 ->curve()
760 ->curve() 756 ->Duration();
761 ->Duration();
762 EXPECT_EQ( 757 EXPECT_EQ(
763 duration_in_seconds, 758 duration,
764 controller->GetAnimation(Animation::ScrollOffset)->curve()->Duration()); 759 controller->GetAnimation(Animation::ScrollOffset)->curve()->Duration());
765 760
766 controller->Animate(kInitialTickTime); 761 controller->Animate(kInitialTickTime);
767 controller->UpdateState(true, nullptr); 762 controller->UpdateState(true, nullptr);
768 EXPECT_TRUE(controller->HasActiveAnimation()); 763 EXPECT_TRUE(controller->HasActiveAnimation());
769 EXPECT_EQ(initial_value, dummy.scroll_offset()); 764 EXPECT_EQ(initial_value, dummy.scroll_offset());
770 765
771 controller_impl->Animate(kInitialTickTime); 766 controller_impl->Animate(kInitialTickTime);
772 controller_impl->UpdateState(true, events.get()); 767 controller_impl->UpdateState(true, events.get());
773 EXPECT_TRUE(controller_impl->HasActiveAnimation()); 768 EXPECT_TRUE(controller_impl->HasActiveAnimation());
774 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); 769 EXPECT_EQ(initial_value, dummy_impl.scroll_offset());
775 // Scroll offset animations should not generate property updates. 770 // Scroll offset animations should not generate property updates.
776 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); 771 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get());
777 EXPECT_FALSE(event); 772 EXPECT_FALSE(event);
778 773
779 TimeDelta duration = TimeDelta::FromMicroseconds(
780 duration_in_seconds * base::Time::kMicrosecondsPerSecond);
781 774
782 controller->NotifyAnimationStarted((*events)[0]); 775 controller->NotifyAnimationStarted((*events)[0]);
783 controller->Animate(kInitialTickTime + duration / 2); 776 controller->Animate(kInitialTickTime + duration / 2);
784 controller->UpdateState(true, nullptr); 777 controller->UpdateState(true, nullptr);
785 EXPECT_TRUE(controller->HasActiveAnimation()); 778 EXPECT_TRUE(controller->HasActiveAnimation());
786 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f), dummy.scroll_offset()); 779 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f), dummy.scroll_offset());
787 780
788 controller_impl->Animate(kInitialTickTime + duration / 2); 781 controller_impl->Animate(kInitialTickTime + duration / 2);
789 controller_impl->UpdateState(true, events.get()); 782 controller_impl->UpdateState(true, events.get());
790 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f), 783 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f),
(...skipping 22 matching lines...) Expand all
813 scoped_ptr<AnimationEventsVector> events( 806 scoped_ptr<AnimationEventsVector> events(
814 make_scoped_ptr(new AnimationEventsVector)); 807 make_scoped_ptr(new AnimationEventsVector));
815 808
816 gfx::ScrollOffset initial_value(100.f, 300.f); 809 gfx::ScrollOffset initial_value(100.f, 300.f);
817 gfx::ScrollOffset target_value(300.f, 200.f); 810 gfx::ScrollOffset target_value(300.f, 200.f);
818 scoped_ptr<ScrollOffsetAnimationCurve> curve( 811 scoped_ptr<ScrollOffsetAnimationCurve> curve(
819 ScrollOffsetAnimationCurve::Create( 812 ScrollOffsetAnimationCurve::Create(
820 target_value, 813 target_value,
821 EaseInOutTimingFunction::Create().Pass())); 814 EaseInOutTimingFunction::Create().Pass()));
822 curve->SetInitialValue(initial_value); 815 curve->SetInitialValue(initial_value);
823 double duration_in_seconds = curve->Duration(); 816 double duration_in_seconds = curve->Duration().InSecondsF();
824 817
825 scoped_ptr<Animation> animation( 818 scoped_ptr<Animation> animation(
826 Animation::Create(curve.Pass(), 1, 0, Animation::ScrollOffset)); 819 Animation::Create(curve.Pass(), 1, 0, Animation::ScrollOffset));
827 animation->set_is_impl_only(true); 820 animation->set_is_impl_only(true);
828 controller_impl->AddAnimation(animation.Pass()); 821 controller_impl->AddAnimation(animation.Pass());
829 822
830 controller_impl->Animate(kInitialTickTime); 823 controller_impl->Animate(kInitialTickTime);
831 controller_impl->UpdateState(true, events.get()); 824 controller_impl->UpdateState(true, events.get());
832 EXPECT_TRUE(controller_impl->HasActiveAnimation()); 825 EXPECT_TRUE(controller_impl->HasActiveAnimation());
833 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); 826 EXPECT_EQ(initial_value, dummy_impl.scroll_offset());
(...skipping 1505 matching lines...) Expand 10 before | Expand all | Expand 10 after
2339 EXPECT_FALSE(controller->IsAnimatingProperty(Animation::Opacity)); 2332 EXPECT_FALSE(controller->IsAnimatingProperty(Animation::Opacity));
2340 EXPECT_FALSE(controller->IsAnimatingProperty(Animation::Filter)); 2333 EXPECT_FALSE(controller->IsAnimatingProperty(Animation::Filter));
2341 2334
2342 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); 2335 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
2343 controller->UpdateState(true, nullptr); 2336 controller->UpdateState(true, nullptr);
2344 EXPECT_TRUE(controller->IsAnimatingProperty(Animation::Opacity)); 2337 EXPECT_TRUE(controller->IsAnimatingProperty(Animation::Opacity));
2345 } 2338 }
2346 2339
2347 } // namespace 2340 } // namespace
2348 } // namespace cc 2341 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698