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

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

Issue 1957533002: cc : Track opacity animation changes on effect tree (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
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 2907 matching lines...) Expand 10 before | Expand all | Expand 10 after
2918 2918
2919 animations_impl->Animate(kInitialTickTime + 2919 animations_impl->Animate(kInitialTickTime +
2920 TimeDelta::FromMilliseconds(4000)); 2920 TimeDelta::FromMilliseconds(4000));
2921 animations_impl->UpdateState(true, events.get()); 2921 animations_impl->UpdateState(true, events.get());
2922 2922
2923 animations->NotifyAnimationAborted(events->events_[0]); 2923 animations->NotifyAnimationAborted(events->events_[0]);
2924 EXPECT_FALSE( 2924 EXPECT_FALSE(
2925 client_.GetTransformIsAnimating(element_id_, ElementListType::ACTIVE)); 2925 client_.GetTransformIsAnimating(element_id_, ElementListType::ACTIVE));
2926 } 2926 }
2927 2927
2928 TEST_F(ElementAnimationsTest, ObserverNotifiedWhenOpacityAnimationChanges) {
2929 CreateTestLayer(true, true);
2930 AttachTimelinePlayerLayer();
2931 CreateImplTimelineAndPlayer();
2932
2933 scoped_refptr<ElementAnimations> animations = element_animations();
2934 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl();
2935
2936 auto events = host_impl_->CreateEvents();
2937
2938 EXPECT_FALSE(client_.GetHasPotentialOpacityAnimation(
2939 element_id_, ElementListType::ACTIVE));
2940 EXPECT_FALSE(client_.GetOpacityIsCurrentlyAnimating(element_id_,
2941 ElementListType::ACTIVE));
2942 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
2943 element_id_, ElementListType::PENDING));
2944 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
2945 element_id_, ElementListType::PENDING));
2946 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
2947 element_id_, ElementListType::ACTIVE));
2948 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
2949 element_id_, ElementListType::ACTIVE));
2950
2951 // Case 1: An animation that's allowed to run until its finish point.
2952 AddOpacityTransitionToElementAnimations(animations.get(), 1.0, 0.f, 1.f,
2953 false /*use_timing_function*/);
2954 EXPECT_TRUE(client_.GetHasPotentialOpacityAnimation(element_id_,
2955 ElementListType::ACTIVE));
2956 EXPECT_TRUE(client_.GetOpacityIsCurrentlyAnimating(element_id_,
2957 ElementListType::ACTIVE));
2958
2959 animations->PushPropertiesTo(animations_impl.get());
2960 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
2961 element_id_, ElementListType::PENDING));
2962 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
2963 element_id_, ElementListType::PENDING));
2964 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
2965 element_id_, ElementListType::ACTIVE));
2966 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
2967 element_id_, ElementListType::ACTIVE));
2968
2969 animations_impl->ActivateAnimations();
2970 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
2971 element_id_, ElementListType::PENDING));
2972 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
2973 element_id_, ElementListType::PENDING));
2974 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
2975 element_id_, ElementListType::ACTIVE));
2976 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
2977 element_id_, ElementListType::ACTIVE));
2978
2979 animations_impl->Animate(kInitialTickTime);
2980 animations_impl->UpdateState(true, events.get());
2981
2982 animations->NotifyAnimationStarted(events->events_[0]);
2983 events->events_.clear();
2984
2985 // Finish the animation.
2986 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
2987 animations->UpdateState(true, nullptr);
2988 EXPECT_FALSE(client_.GetHasPotentialOpacityAnimation(
2989 element_id_, ElementListType::ACTIVE));
2990 EXPECT_FALSE(client_.GetOpacityIsCurrentlyAnimating(element_id_,
2991 ElementListType::ACTIVE));
2992
2993 animations->PushPropertiesTo(animations_impl.get());
2994
2995 // animations_impl hasn't yet ticked at/past the end of the animation.
2996 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
2997 element_id_, ElementListType::PENDING));
2998 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
2999 element_id_, ElementListType::PENDING));
3000 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
3001 element_id_, ElementListType::ACTIVE));
3002 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
3003 element_id_, ElementListType::ACTIVE));
3004
3005 animations_impl->Animate(kInitialTickTime +
3006 TimeDelta::FromMilliseconds(1000));
3007 animations_impl->UpdateState(true, events.get());
3008 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
3009 element_id_, ElementListType::PENDING));
3010 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
3011 element_id_, ElementListType::PENDING));
3012 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
3013 element_id_, ElementListType::ACTIVE));
3014 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
3015 element_id_, ElementListType::ACTIVE));
3016
3017 // Case 2: An animation that's removed before it finishes.
3018 int animation_id = AddOpacityTransitionToElementAnimations(
3019 animations.get(), 10.0, 0.f, 1.f, false /*use_timing_function*/);
3020 EXPECT_TRUE(client_.GetHasPotentialOpacityAnimation(element_id_,
3021 ElementListType::ACTIVE));
3022 EXPECT_TRUE(client_.GetOpacityIsCurrentlyAnimating(element_id_,
3023 ElementListType::ACTIVE));
3024
3025 animations->PushPropertiesTo(animations_impl.get());
3026 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
3027 element_id_, ElementListType::PENDING));
3028 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
3029 element_id_, ElementListType::PENDING));
3030 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
3031 element_id_, ElementListType::ACTIVE));
3032 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
3033 element_id_, ElementListType::ACTIVE));
3034
3035 animations_impl->ActivateAnimations();
3036 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
3037 element_id_, ElementListType::ACTIVE));
3038 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
3039 element_id_, ElementListType::ACTIVE));
3040
3041 animations_impl->Animate(kInitialTickTime +
3042 TimeDelta::FromMilliseconds(2000));
3043 animations_impl->UpdateState(true, events.get());
3044
3045 animations->NotifyAnimationStarted(events->events_[0]);
3046 events->events_.clear();
3047
3048 animations->RemoveAnimation(animation_id);
3049 EXPECT_FALSE(client_.GetHasPotentialOpacityAnimation(
3050 element_id_, ElementListType::ACTIVE));
3051 EXPECT_FALSE(client_.GetOpacityIsCurrentlyAnimating(element_id_,
3052 ElementListType::ACTIVE));
3053
3054 animations->PushPropertiesTo(animations_impl.get());
3055 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
3056 element_id_, ElementListType::PENDING));
3057 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
3058 element_id_, ElementListType::PENDING));
3059 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
3060 element_id_, ElementListType::ACTIVE));
3061 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
3062 element_id_, ElementListType::ACTIVE));
3063
3064 animations_impl->ActivateAnimations();
3065 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
3066 element_id_, ElementListType::ACTIVE));
3067 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
3068 element_id_, ElementListType::ACTIVE));
3069
3070 // Case 3: An animation that's aborted before it finishes.
3071 animation_id = AddOpacityTransitionToElementAnimations(
3072 animations.get(), 10.0, 0.f, 0.5f, false /*use_timing_function*/);
3073 EXPECT_TRUE(client_.GetHasPotentialOpacityAnimation(element_id_,
3074 ElementListType::ACTIVE));
3075 EXPECT_TRUE(client_.GetOpacityIsCurrentlyAnimating(element_id_,
3076 ElementListType::ACTIVE));
3077
3078 animations->PushPropertiesTo(animations_impl.get());
3079 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
3080 element_id_, ElementListType::PENDING));
3081 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
3082 element_id_, ElementListType::PENDING));
3083 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
3084 element_id_, ElementListType::ACTIVE));
3085 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
3086 element_id_, ElementListType::ACTIVE));
3087
3088 animations_impl->ActivateAnimations();
3089 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
3090 element_id_, ElementListType::ACTIVE));
3091 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
3092 element_id_, ElementListType::ACTIVE));
3093
3094 animations_impl->Animate(kInitialTickTime +
3095 TimeDelta::FromMilliseconds(2000));
3096 animations_impl->UpdateState(true, events.get());
3097
3098 animations->NotifyAnimationStarted(events->events_[0]);
3099 events->events_.clear();
3100
3101 animations_impl->AbortAnimations(TargetProperty::OPACITY);
3102 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
3103 element_id_, ElementListType::PENDING));
3104 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
3105 element_id_, ElementListType::PENDING));
3106 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
3107 element_id_, ElementListType::ACTIVE));
3108 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
3109 element_id_, ElementListType::ACTIVE));
3110
3111 animations_impl->Animate(kInitialTickTime +
3112 TimeDelta::FromMilliseconds(4000));
3113 animations_impl->UpdateState(true, events.get());
3114
3115 animations->NotifyAnimationAborted(events->events_[0]);
3116 EXPECT_FALSE(client_.GetHasPotentialOpacityAnimation(
3117 element_id_, ElementListType::ACTIVE));
3118 EXPECT_FALSE(client_.GetOpacityIsCurrentlyAnimating(element_id_,
3119 ElementListType::ACTIVE));
ajuma 2016/05/09 16:56:55 Please also test the case where potentially-animat
jaydasika 2016/05/10 20:22:29 Done.
3120 }
3121
2928 TEST_F(ElementAnimationsTest, ClippedOpacityValues) { 3122 TEST_F(ElementAnimationsTest, ClippedOpacityValues) {
2929 CreateTestLayer(false, false); 3123 CreateTestLayer(false, false);
2930 AttachTimelinePlayerLayer(); 3124 AttachTimelinePlayerLayer();
2931 3125
2932 scoped_refptr<ElementAnimations> animations = element_animations(); 3126 scoped_refptr<ElementAnimations> animations = element_animations();
2933 3127
2934 AddOpacityTransitionToElementAnimations(animations.get(), 1, 1.f, 2.f, true); 3128 AddOpacityTransitionToElementAnimations(animations.get(), 1, 1.f, 2.f, true);
2935 3129
2936 animations->Animate(kInitialTickTime); 3130 animations->Animate(kInitialTickTime);
2937 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 3131 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
3240 EXPECT_FALSE(animations->IsPotentiallyAnimatingProperty( 3434 EXPECT_FALSE(animations->IsPotentiallyAnimatingProperty(
3241 TargetProperty::OPACITY, ElementListType::ACTIVE)); 3435 TargetProperty::OPACITY, ElementListType::ACTIVE));
3242 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( 3436 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty(
3243 TargetProperty::OPACITY, ElementListType::PENDING)); 3437 TargetProperty::OPACITY, ElementListType::PENDING));
3244 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( 3438 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty(
3245 TargetProperty::OPACITY, ElementListType::ACTIVE)); 3439 TargetProperty::OPACITY, ElementListType::ACTIVE));
3246 } 3440 }
3247 3441
3248 } // namespace 3442 } // namespace
3249 } // namespace cc 3443 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/element_animations.cc ('k') | cc/layers/layer.h » ('j') | cc/layers/layer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698