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

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

Issue 1988293003: cc : Delete code not used outside tests related to impl-only animations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « cc/animation/element_animations.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/element_animations.h" 5 #include "cc/animation/element_animations.h"
6 6
7 #include "cc/animation/animation_delegate.h" 7 #include "cc/animation/animation_delegate.h"
8 #include "cc/animation/animation_host.h" 8 #include "cc/animation/animation_host.h"
9 #include "cc/animation/animation_id_provider.h" 9 #include "cc/animation/animation_id_provider.h"
10 #include "cc/animation/animation_player.h" 10 #include "cc/animation/animation_player.h"
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); 691 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get());
692 EXPECT_FALSE(event); 692 EXPECT_FALSE(event);
693 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); 693 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
694 animations->UpdateState(true, events.get()); 694 animations->UpdateState(true, events.get());
695 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 695 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
696 EXPECT_FALSE(animations->HasActiveAnimation()); 696 EXPECT_FALSE(animations->HasActiveAnimation());
697 event = GetMostRecentPropertyUpdateEvent(events.get()); 697 event = GetMostRecentPropertyUpdateEvent(events.get());
698 EXPECT_FALSE(event); 698 EXPECT_FALSE(event);
699 } 699 }
700 700
701 TEST_F(ElementAnimationsTest, TrivialTransitionOnImpl) {
702 CreateTestLayer(true, false);
703 AttachTimelinePlayerLayer();
704 CreateImplTimelineAndPlayer();
705
706 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl();
707
708 auto events = host_impl_->CreateEvents();
709
710 std::unique_ptr<Animation> to_add(CreateAnimation(
711 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
712 1, TargetProperty::OPACITY));
713 to_add->set_is_impl_only(true);
714
715 animations_impl->AddAnimation(std::move(to_add));
716 animations_impl->Animate(kInitialTickTime);
717 animations_impl->UpdateState(true, events.get());
718 EXPECT_TRUE(animations_impl->HasActiveAnimation());
719 EXPECT_EQ(0.f, client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE));
720 EXPECT_EQ(1u, events->events_.size());
721 const AnimationEvent* start_opacity_event =
722 GetMostRecentPropertyUpdateEvent(events.get());
723 EXPECT_EQ(0.f, start_opacity_event->opacity);
724
725 animations_impl->Animate(kInitialTickTime +
726 TimeDelta::FromMilliseconds(1000));
727 animations_impl->UpdateState(true, events.get());
728 EXPECT_EQ(1.f, client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE));
729 EXPECT_FALSE(animations_impl->HasActiveAnimation());
730 EXPECT_EQ(2u, events->events_.size());
731 const AnimationEvent* end_opacity_event =
732 GetMostRecentPropertyUpdateEvent(events.get());
733 EXPECT_EQ(1.f, end_opacity_event->opacity);
734 }
735
736 TEST_F(ElementAnimationsTest, TrivialTransformOnImpl) {
737 CreateTestLayer(true, false);
738 AttachTimelinePlayerLayer();
739 CreateImplTimelineAndPlayer();
740
741 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl();
742
743 auto events = host_impl_->CreateEvents();
744
745 // Choose different values for x and y to avoid coincidental values in the
746 // observed transforms.
747 const float delta_x = 3;
748 const float delta_y = 4;
749
750 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
751 KeyframedTransformAnimationCurve::Create());
752
753 // Create simple TRANSFORM animation.
754 TransformOperations operations;
755 curve->AddKeyframe(
756 TransformKeyframe::Create(base::TimeDelta(), operations, nullptr));
757 operations.AppendTranslate(delta_x, delta_y, 0);
758 curve->AddKeyframe(TransformKeyframe::Create(
759 base::TimeDelta::FromSecondsD(1.0), operations, nullptr));
760
761 std::unique_ptr<Animation> animation(
762 Animation::Create(std::move(curve), 1, 0, TargetProperty::TRANSFORM));
763 animation->set_is_impl_only(true);
764 animations_impl->AddAnimation(std::move(animation));
765
766 // Run animation.
767 animations_impl->Animate(kInitialTickTime);
768 animations_impl->UpdateState(true, events.get());
769 EXPECT_TRUE(animations_impl->HasActiveAnimation());
770 EXPECT_EQ(gfx::Transform(),
771 client_impl_.GetTransform(element_id_, ElementListType::ACTIVE));
772 EXPECT_EQ(1u, events->events_.size());
773 const AnimationEvent* start_transform_event =
774 GetMostRecentPropertyUpdateEvent(events.get());
775 ASSERT_TRUE(start_transform_event);
776 EXPECT_EQ(gfx::Transform(), start_transform_event->transform);
777 EXPECT_TRUE(start_transform_event->is_impl_only);
778
779 gfx::Transform expected_transform;
780 expected_transform.Translate(delta_x, delta_y);
781
782 animations_impl->Animate(kInitialTickTime +
783 TimeDelta::FromMilliseconds(1000));
784 animations_impl->UpdateState(true, events.get());
785 EXPECT_EQ(expected_transform,
786 client_impl_.GetTransform(element_id_, ElementListType::ACTIVE));
787 EXPECT_FALSE(animations_impl->HasActiveAnimation());
788 EXPECT_EQ(2u, events->events_.size());
789 const AnimationEvent* end_transform_event =
790 GetMostRecentPropertyUpdateEvent(events.get());
791 EXPECT_EQ(expected_transform, end_transform_event->transform);
792 EXPECT_TRUE(end_transform_event->is_impl_only);
793 }
794
795 TEST_F(ElementAnimationsTest, FilterTransition) { 701 TEST_F(ElementAnimationsTest, FilterTransition) {
796 CreateTestLayer(true, false); 702 CreateTestLayer(true, false);
797 AttachTimelinePlayerLayer(); 703 AttachTimelinePlayerLayer();
798 704
799 scoped_refptr<ElementAnimations> animations = element_animations(); 705 scoped_refptr<ElementAnimations> animations = element_animations();
800 706
801 auto events = host_impl_->CreateEvents(); 707 auto events = host_impl_->CreateEvents();
802 708
803 std::unique_ptr<KeyframedFilterAnimationCurve> curve( 709 std::unique_ptr<KeyframedFilterAnimationCurve> curve(
804 KeyframedFilterAnimationCurve::Create()); 710 KeyframedFilterAnimationCurve::Create());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 742
837 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); 743 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
838 animations->UpdateState(true, events.get()); 744 animations->UpdateState(true, events.get());
839 EXPECT_EQ(end_filters, 745 EXPECT_EQ(end_filters,
840 client_.GetFilters(element_id_, ElementListType::ACTIVE)); 746 client_.GetFilters(element_id_, ElementListType::ACTIVE));
841 EXPECT_FALSE(animations->HasActiveAnimation()); 747 EXPECT_FALSE(animations->HasActiveAnimation());
842 event = GetMostRecentPropertyUpdateEvent(events.get()); 748 event = GetMostRecentPropertyUpdateEvent(events.get());
843 EXPECT_FALSE(event); 749 EXPECT_FALSE(event);
844 } 750 }
845 751
846 TEST_F(ElementAnimationsTest, FilterTransitionOnImplOnly) {
847 CreateTestLayer(true, false);
848 AttachTimelinePlayerLayer();
849 CreateImplTimelineAndPlayer();
850
851 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl();
852
853 auto events = host_impl_->CreateEvents();
854
855 std::unique_ptr<KeyframedFilterAnimationCurve> curve(
856 KeyframedFilterAnimationCurve::Create());
857
858 // Create simple FILTER animation.
859 FilterOperations start_filters;
860 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f));
861 curve->AddKeyframe(
862 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr));
863 FilterOperations end_filters;
864 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f));
865 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
866 end_filters, nullptr));
867
868 std::unique_ptr<Animation> animation(
869 Animation::Create(std::move(curve), 1, 0, TargetProperty::FILTER));
870 animation->set_is_impl_only(true);
871 animations_impl->AddAnimation(std::move(animation));
872
873 // Run animation.
874 animations_impl->Animate(kInitialTickTime);
875 animations_impl->UpdateState(true, events.get());
876 EXPECT_TRUE(animations_impl->HasActiveAnimation());
877 EXPECT_EQ(start_filters,
878 client_impl_.GetFilters(element_id_, ElementListType::ACTIVE));
879 EXPECT_EQ(1u, events->events_.size());
880 const AnimationEvent* start_filter_event =
881 GetMostRecentPropertyUpdateEvent(events.get());
882 EXPECT_TRUE(start_filter_event);
883 EXPECT_EQ(start_filters, start_filter_event->filters);
884 EXPECT_TRUE(start_filter_event->is_impl_only);
885
886 animations_impl->Animate(kInitialTickTime +
887 TimeDelta::FromMilliseconds(1000));
888 animations_impl->UpdateState(true, events.get());
889 EXPECT_EQ(end_filters,
890 client_impl_.GetFilters(element_id_, ElementListType::ACTIVE));
891 EXPECT_FALSE(animations_impl->HasActiveAnimation());
892 EXPECT_EQ(2u, events->events_.size());
893 const AnimationEvent* end_filter_event =
894 GetMostRecentPropertyUpdateEvent(events.get());
895 EXPECT_TRUE(end_filter_event);
896 EXPECT_EQ(end_filters, end_filter_event->filters);
897 EXPECT_TRUE(end_filter_event->is_impl_only);
898 }
899
900 TEST_F(ElementAnimationsTest, ScrollOffsetTransition) { 752 TEST_F(ElementAnimationsTest, ScrollOffsetTransition) {
901 CreateTestLayer(true, false); 753 CreateTestLayer(true, false);
902 AttachTimelinePlayerLayer(); 754 AttachTimelinePlayerLayer();
903 CreateImplTimelineAndPlayer(); 755 CreateImplTimelineAndPlayer();
904 756
905 scoped_refptr<ElementAnimations> animations = element_animations(); 757 scoped_refptr<ElementAnimations> animations = element_animations();
906 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); 758 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl();
907 759
908 auto events = host_impl_->CreateEvents(); 760 auto events = host_impl_->CreateEvents();
909 761
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 CreateImplTimelineAndPlayer(); 1078 CreateImplTimelineAndPlayer();
1227 1079
1228 scoped_refptr<ElementAnimations> animations = element_animations(); 1080 scoped_refptr<ElementAnimations> animations = element_animations();
1229 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); 1081 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl();
1230 1082
1231 auto events = host_impl_->CreateEvents(); 1083 auto events = host_impl_->CreateEvents();
1232 1084
1233 TestAnimationDelegate delegate; 1085 TestAnimationDelegate delegate;
1234 player_impl_->set_animation_delegate(&delegate); 1086 player_impl_->set_animation_delegate(&delegate);
1235 1087
1236 std::unique_ptr<Animation> to_add(CreateAnimation( 1088 gfx::ScrollOffset initial_value(100.f, 300.f);
1237 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1089 gfx::ScrollOffset target_value(300.f, 200.f);
1238 1, TargetProperty::OPACITY)); 1090 std::unique_ptr<ScrollOffsetAnimationCurve> curve(
1091 ScrollOffsetAnimationCurve::Create(target_value,
1092 EaseInOutTimingFunction::Create()));
1093 curve->SetInitialValue(initial_value);
1094 double duration_in_seconds = curve->Duration().InSecondsF();
ajuma 2016/05/19 20:56:47 Can we make this a TimeDelta instead (set to curve
jaydasika 2016/05/19 22:30:52 Done.
1095 std::unique_ptr<Animation> to_add(
1096 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET));
1239 to_add->set_is_impl_only(true); 1097 to_add->set_is_impl_only(true);
1240 animations_impl->AddAnimation(std::move(to_add)); 1098 animations_impl->AddAnimation(std::move(to_add));
1241 1099
1242 EXPECT_FALSE(delegate.started()); 1100 EXPECT_FALSE(delegate.started());
1243 EXPECT_FALSE(delegate.finished()); 1101 EXPECT_FALSE(delegate.finished());
1244 1102
1245 animations_impl->Animate(kInitialTickTime); 1103 animations_impl->Animate(kInitialTickTime);
1246 animations_impl->UpdateState(true, events.get()); 1104 animations_impl->UpdateState(true, events.get());
1247 1105
1248 EXPECT_TRUE(delegate.started()); 1106 EXPECT_TRUE(delegate.started());
1249 EXPECT_FALSE(delegate.finished()); 1107 EXPECT_FALSE(delegate.finished());
1250 1108
1109 TimeDelta duration = TimeDelta::FromMicroseconds(
1110 duration_in_seconds * base::Time::kMicrosecondsPerSecond);
1251 events = host_impl_->CreateEvents(); 1111 events = host_impl_->CreateEvents();
1252 animations_impl->Animate(kInitialTickTime + 1112 animations_impl->Animate(kInitialTickTime + duration);
1253 TimeDelta::FromMilliseconds(1000)); 1113 EXPECT_EQ(duration,
1114 animations_impl->GetAnimation(TargetProperty::SCROLL_OFFSET)
1115 ->curve()
1116 ->Duration());
1254 animations_impl->UpdateState(true, events.get()); 1117 animations_impl->UpdateState(true, events.get());
1255 1118
1256 EXPECT_TRUE(delegate.started()); 1119 EXPECT_TRUE(delegate.started());
1257 EXPECT_TRUE(delegate.finished()); 1120 EXPECT_TRUE(delegate.finished());
1258 } 1121 }
1259 1122
1260 // Tests that specified start times are sent to the main thread delegate 1123 // Tests that specified start times are sent to the main thread delegate
1261 TEST_F(ElementAnimationsTest, SpecifiedStartTimesAreSentToMainThreadDelegate) { 1124 TEST_F(ElementAnimationsTest, SpecifiedStartTimesAreSentToMainThreadDelegate) {
1262 CreateTestLayer(true, false); 1125 CreateTestLayer(true, false);
1263 AttachTimelinePlayerLayer(); 1126 AttachTimelinePlayerLayer();
(...skipping 2194 matching lines...) Expand 10 before | Expand all | Expand 10 after
3458 EXPECT_FALSE(animations->IsPotentiallyAnimatingProperty( 3321 EXPECT_FALSE(animations->IsPotentiallyAnimatingProperty(
3459 TargetProperty::OPACITY, ElementListType::ACTIVE)); 3322 TargetProperty::OPACITY, ElementListType::ACTIVE));
3460 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( 3323 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty(
3461 TargetProperty::OPACITY, ElementListType::PENDING)); 3324 TargetProperty::OPACITY, ElementListType::PENDING));
3462 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( 3325 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty(
3463 TargetProperty::OPACITY, ElementListType::ACTIVE)); 3326 TargetProperty::OPACITY, ElementListType::ACTIVE));
3464 } 3327 }
3465 3328
3466 } // namespace 3329 } // namespace
3467 } // namespace cc 3330 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/element_animations.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698