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

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

Issue 864003002: cc: Make LayerAnimationController keep state for clearing scroll delta (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments Created 5 years, 11 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 "cc/animation/animation.h" 7 #include "cc/animation/animation.h"
8 #include "cc/animation/animation_curve.h" 8 #include "cc/animation/animation_curve.h"
9 #include "cc/animation/animation_delegate.h" 9 #include "cc/animation/animation_delegate.h"
10 #include "cc/animation/animation_registrar.h" 10 #include "cc/animation/animation_registrar.h"
(...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 EXPECT_FALSE(event); 826 EXPECT_FALSE(event);
827 827
828 controller_impl->Animate(kInitialTickTime + duration); 828 controller_impl->Animate(kInitialTickTime + duration);
829 controller_impl->UpdateState(true, events.get()); 829 controller_impl->UpdateState(true, events.get());
830 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset()); 830 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset());
831 EXPECT_FALSE(controller_impl->HasActiveAnimation()); 831 EXPECT_FALSE(controller_impl->HasActiveAnimation());
832 event = GetMostRecentPropertyUpdateEvent(events.get()); 832 event = GetMostRecentPropertyUpdateEvent(events.get());
833 EXPECT_FALSE(event); 833 EXPECT_FALSE(event);
834 } 834 }
835 835
836 TEST(LayerAnimationControllerTest, ScrollOffsetRemovalNotifiesObserver) { 836 TEST(LayerAnimationControllerTest, ScrollOffsetRemovalClearsScrollDelta) {
837 FakeLayerAnimationValueObserver dummy_impl;
838 FakeLayerAnimationValueProvider dummy_provider_impl;
839 scoped_refptr<LayerAnimationController> controller_impl(
840 LayerAnimationController::Create(0));
841 controller_impl->AddValueObserver(&dummy_impl);
842 controller_impl->set_value_provider(&dummy_provider_impl);
843 scoped_ptr<AnimationEventsVector> events(
844 make_scoped_ptr(new AnimationEventsVector));
837 FakeLayerAnimationValueObserver dummy; 845 FakeLayerAnimationValueObserver dummy;
846 FakeLayerAnimationValueProvider dummy_provider;
838 scoped_refptr<LayerAnimationController> controller( 847 scoped_refptr<LayerAnimationController> controller(
839 LayerAnimationController::Create(0)); 848 LayerAnimationController::Create(0));
840 controller->AddValueObserver(&dummy); 849 controller->AddValueObserver(&dummy);
850 controller->set_value_provider(&dummy_provider);
841 851
842 // First test the 1-argument version of RemoveAnimation. 852 // First test the 1-argument version of RemoveAnimation.
843 gfx::ScrollOffset target_value(300.f, 200.f); 853 gfx::ScrollOffset target_value(300.f, 200.f);
844 scoped_ptr<ScrollOffsetAnimationCurve> curve( 854 scoped_ptr<ScrollOffsetAnimationCurve> curve(
845 ScrollOffsetAnimationCurve::Create( 855 ScrollOffsetAnimationCurve::Create(
846 target_value, EaseInOutTimingFunction::Create().Pass())); 856 target_value, EaseInOutTimingFunction::Create().Pass()));
847 857
848 int animation_id = 1; 858 int animation_id = 1;
849 scoped_ptr<Animation> animation(Animation::Create( 859 scoped_ptr<Animation> animation(Animation::Create(
850 curve.Pass(), animation_id, 0, Animation::ScrollOffset)); 860 curve.Pass(), animation_id, 0, Animation::ScrollOffset));
861 animation->set_needs_synchronized_start_time(true);
851 controller->AddAnimation(animation.Pass()); 862 controller->AddAnimation(animation.Pass());
863 controller->PushAnimationUpdatesTo(controller_impl.get());
864 controller_impl->ActivateAnimations();
865 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted());
866 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted());
852 867
853 controller->RemoveAnimation(animation_id); 868 controller->RemoveAnimation(animation_id);
854 EXPECT_TRUE(dummy.scroll_offset_animation_removed()); 869 EXPECT_TRUE(controller->scroll_offset_animation_was_interrupted());
870
871 controller->PushAnimationUpdatesTo(controller_impl.get());
872 EXPECT_TRUE(controller_impl->scroll_offset_animation_was_interrupted());
873 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted());
874
875 controller_impl->ActivateAnimations();
876 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted());
855 877
856 // Now, test the 2-argument version of RemoveAnimation. 878 // Now, test the 2-argument version of RemoveAnimation.
857 dummy.reset_scroll_offset_animation_removed();
858 curve = ScrollOffsetAnimationCurve::Create( 879 curve = ScrollOffsetAnimationCurve::Create(
859 target_value, EaseInOutTimingFunction::Create().Pass()); 880 target_value, EaseInOutTimingFunction::Create().Pass());
860 animation = 881 animation =
861 Animation::Create(curve.Pass(), animation_id, 0, Animation::ScrollOffset); 882 Animation::Create(curve.Pass(), animation_id, 0, Animation::ScrollOffset);
883 animation->set_needs_synchronized_start_time(true);
862 controller->AddAnimation(animation.Pass()); 884 controller->AddAnimation(animation.Pass());
885 controller->PushAnimationUpdatesTo(controller_impl.get());
886 controller_impl->ActivateAnimations();
887 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted());
888 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted());
863 889
864 controller->RemoveAnimation(animation_id, Animation::ScrollOffset); 890 controller->RemoveAnimation(animation_id);
865 EXPECT_TRUE(dummy.scroll_offset_animation_removed()); 891 EXPECT_TRUE(controller->scroll_offset_animation_was_interrupted());
866 892
867 // Check that removing non-scroll-offset animations does not cause the 893 controller->PushAnimationUpdatesTo(controller_impl.get());
868 // observer to get notified. 894 EXPECT_TRUE(controller_impl->scroll_offset_animation_was_interrupted());
869 dummy.reset_scroll_offset_animation_removed(); 895 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted());
896
897 controller_impl->ActivateAnimations();
898 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted());
899
900 // Check that removing non-scroll-offset animations does not cause
901 // scroll_offset_animation_was_interrupted() to get set.
870 animation_id = AddAnimatedTransformToController(controller.get(), 1.0, 1, 2); 902 animation_id = AddAnimatedTransformToController(controller.get(), 1.0, 1, 2);
903 controller->PushAnimationUpdatesTo(controller_impl.get());
904 controller_impl->ActivateAnimations();
905 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted());
906 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted());
907
871 controller->RemoveAnimation(animation_id); 908 controller->RemoveAnimation(animation_id);
872 EXPECT_FALSE(dummy.scroll_offset_animation_removed()); 909 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted());
873 910
874 dummy.reset_scroll_offset_animation_removed(); 911 controller->PushAnimationUpdatesTo(controller_impl.get());
912 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted());
913 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted());
914
915 controller_impl->ActivateAnimations();
916 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted());
917
875 animation_id = 918 animation_id =
876 AddAnimatedFilterToController(controller.get(), 1.0, 0.1f, 0.2f); 919 AddAnimatedFilterToController(controller.get(), 1.0, 0.1f, 0.2f);
877 controller->RemoveAnimation(animation_id, Animation::Filter); 920 controller->PushAnimationUpdatesTo(controller_impl.get());
878 EXPECT_FALSE(dummy.scroll_offset_animation_removed()); 921 controller_impl->ActivateAnimations();
922 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted());
923 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted());
924
925 controller->RemoveAnimation(animation_id);
926 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted());
927
928 controller->PushAnimationUpdatesTo(controller_impl.get());
929 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted());
930 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted());
931
932 controller_impl->ActivateAnimations();
933 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted());
879 } 934 }
880 935
881 class FakeAnimationDelegate : public AnimationDelegate { 936 class FakeAnimationDelegate : public AnimationDelegate {
882 public: 937 public:
883 FakeAnimationDelegate() 938 FakeAnimationDelegate()
884 : started_(false), 939 : started_(false),
885 finished_(false) {} 940 finished_(false) {}
886 941
887 void NotifyAnimationStarted(TimeTicks monotonic_time, 942 void NotifyAnimationStarted(TimeTicks monotonic_time,
888 Animation::TargetProperty target_property, 943 Animation::TargetProperty target_property,
(...skipping 1462 matching lines...) Expand 10 before | Expand all | Expand 10 after
2351 EXPECT_FALSE(controller->IsAnimatingProperty(Animation::Opacity)); 2406 EXPECT_FALSE(controller->IsAnimatingProperty(Animation::Opacity));
2352 EXPECT_FALSE(controller->IsAnimatingProperty(Animation::Filter)); 2407 EXPECT_FALSE(controller->IsAnimatingProperty(Animation::Filter));
2353 2408
2354 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); 2409 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
2355 controller->UpdateState(true, nullptr); 2410 controller->UpdateState(true, nullptr);
2356 EXPECT_TRUE(controller->IsAnimatingProperty(Animation::Opacity)); 2411 EXPECT_TRUE(controller->IsAnimatingProperty(Animation::Opacity));
2357 } 2412 }
2358 2413
2359 } // namespace 2414 } // namespace
2360 } // namespace cc 2415 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/layer_animation_controller.cc ('k') | cc/animation/layer_animation_value_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698