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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: cc/animation/element_animations_unittest.cc
diff --git a/cc/animation/element_animations_unittest.cc b/cc/animation/element_animations_unittest.cc
index 305b47d0990b9344cfa748b835c1ba2b3f908e1f..1d04726bae3dd098dcc4c0712289989788b31e61 100644
--- a/cc/animation/element_animations_unittest.cc
+++ b/cc/animation/element_animations_unittest.cc
@@ -2925,6 +2925,200 @@ TEST_F(ElementAnimationsTest,
client_.GetTransformIsAnimating(element_id_, ElementListType::ACTIVE));
}
+TEST_F(ElementAnimationsTest, ObserverNotifiedWhenOpacityAnimationChanges) {
+ CreateTestLayer(true, true);
+ AttachTimelinePlayerLayer();
+ CreateImplTimelineAndPlayer();
+
+ scoped_refptr<ElementAnimations> animations = element_animations();
+ scoped_refptr<ElementAnimations> animations_impl = element_animations_impl();
+
+ auto events = host_impl_->CreateEvents();
+
+ EXPECT_FALSE(client_.GetHasPotentialOpacityAnimation(
+ element_id_, ElementListType::ACTIVE));
+ EXPECT_FALSE(client_.GetOpacityIsCurrentlyAnimating(element_id_,
+ ElementListType::ACTIVE));
+ EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
+ element_id_, ElementListType::PENDING));
+ EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
+ element_id_, ElementListType::PENDING));
+ EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
+ element_id_, ElementListType::ACTIVE));
+ EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
+ element_id_, ElementListType::ACTIVE));
+
+ // Case 1: An animation that's allowed to run until its finish point.
+ AddOpacityTransitionToElementAnimations(animations.get(), 1.0, 0.f, 1.f,
+ false /*use_timing_function*/);
+ EXPECT_TRUE(client_.GetHasPotentialOpacityAnimation(element_id_,
+ ElementListType::ACTIVE));
+ EXPECT_TRUE(client_.GetOpacityIsCurrentlyAnimating(element_id_,
+ ElementListType::ACTIVE));
+
+ animations->PushPropertiesTo(animations_impl.get());
+ EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
+ element_id_, ElementListType::PENDING));
+ EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
+ element_id_, ElementListType::PENDING));
+ EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
+ element_id_, ElementListType::ACTIVE));
+ EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
+ element_id_, ElementListType::ACTIVE));
+
+ animations_impl->ActivateAnimations();
+ EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
+ element_id_, ElementListType::PENDING));
+ EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
+ element_id_, ElementListType::PENDING));
+ EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
+ element_id_, ElementListType::ACTIVE));
+ EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
+ element_id_, ElementListType::ACTIVE));
+
+ animations_impl->Animate(kInitialTickTime);
+ animations_impl->UpdateState(true, events.get());
+
+ animations->NotifyAnimationStarted(events->events_[0]);
+ events->events_.clear();
+
+ // Finish the animation.
+ animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
+ animations->UpdateState(true, nullptr);
+ EXPECT_FALSE(client_.GetHasPotentialOpacityAnimation(
+ element_id_, ElementListType::ACTIVE));
+ EXPECT_FALSE(client_.GetOpacityIsCurrentlyAnimating(element_id_,
+ ElementListType::ACTIVE));
+
+ animations->PushPropertiesTo(animations_impl.get());
+
+ // animations_impl hasn't yet ticked at/past the end of the animation.
+ EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
+ element_id_, ElementListType::PENDING));
+ EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
+ element_id_, ElementListType::PENDING));
+ EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
+ element_id_, ElementListType::ACTIVE));
+ EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
+ element_id_, ElementListType::ACTIVE));
+
+ animations_impl->Animate(kInitialTickTime +
+ TimeDelta::FromMilliseconds(1000));
+ animations_impl->UpdateState(true, events.get());
+ EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
+ element_id_, ElementListType::PENDING));
+ EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
+ element_id_, ElementListType::PENDING));
+ EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
+ element_id_, ElementListType::ACTIVE));
+ EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
+ element_id_, ElementListType::ACTIVE));
+
+ // Case 2: An animation that's removed before it finishes.
+ int animation_id = AddOpacityTransitionToElementAnimations(
+ animations.get(), 10.0, 0.f, 1.f, false /*use_timing_function*/);
+ EXPECT_TRUE(client_.GetHasPotentialOpacityAnimation(element_id_,
+ ElementListType::ACTIVE));
+ EXPECT_TRUE(client_.GetOpacityIsCurrentlyAnimating(element_id_,
+ ElementListType::ACTIVE));
+
+ animations->PushPropertiesTo(animations_impl.get());
+ EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
+ element_id_, ElementListType::PENDING));
+ EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
+ element_id_, ElementListType::PENDING));
+ EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
+ element_id_, ElementListType::ACTIVE));
+ EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
+ element_id_, ElementListType::ACTIVE));
+
+ animations_impl->ActivateAnimations();
+ EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
+ element_id_, ElementListType::ACTIVE));
+ EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
+ element_id_, ElementListType::ACTIVE));
+
+ animations_impl->Animate(kInitialTickTime +
+ TimeDelta::FromMilliseconds(2000));
+ animations_impl->UpdateState(true, events.get());
+
+ animations->NotifyAnimationStarted(events->events_[0]);
+ events->events_.clear();
+
+ animations->RemoveAnimation(animation_id);
+ EXPECT_FALSE(client_.GetHasPotentialOpacityAnimation(
+ element_id_, ElementListType::ACTIVE));
+ EXPECT_FALSE(client_.GetOpacityIsCurrentlyAnimating(element_id_,
+ ElementListType::ACTIVE));
+
+ animations->PushPropertiesTo(animations_impl.get());
+ EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
+ element_id_, ElementListType::PENDING));
+ EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
+ element_id_, ElementListType::PENDING));
+ EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
+ element_id_, ElementListType::ACTIVE));
+ EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
+ element_id_, ElementListType::ACTIVE));
+
+ animations_impl->ActivateAnimations();
+ EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
+ element_id_, ElementListType::ACTIVE));
+ EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
+ element_id_, ElementListType::ACTIVE));
+
+ // Case 3: An animation that's aborted before it finishes.
+ animation_id = AddOpacityTransitionToElementAnimations(
+ animations.get(), 10.0, 0.f, 0.5f, false /*use_timing_function*/);
+ EXPECT_TRUE(client_.GetHasPotentialOpacityAnimation(element_id_,
+ ElementListType::ACTIVE));
+ EXPECT_TRUE(client_.GetOpacityIsCurrentlyAnimating(element_id_,
+ ElementListType::ACTIVE));
+
+ animations->PushPropertiesTo(animations_impl.get());
+ EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
+ element_id_, ElementListType::PENDING));
+ EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
+ element_id_, ElementListType::PENDING));
+ EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
+ element_id_, ElementListType::ACTIVE));
+ EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
+ element_id_, ElementListType::ACTIVE));
+
+ animations_impl->ActivateAnimations();
+ EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
+ element_id_, ElementListType::ACTIVE));
+ EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
+ element_id_, ElementListType::ACTIVE));
+
+ animations_impl->Animate(kInitialTickTime +
+ TimeDelta::FromMilliseconds(2000));
+ animations_impl->UpdateState(true, events.get());
+
+ animations->NotifyAnimationStarted(events->events_[0]);
+ events->events_.clear();
+
+ animations_impl->AbortAnimations(TargetProperty::OPACITY);
+ EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
+ element_id_, ElementListType::PENDING));
+ EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
+ element_id_, ElementListType::PENDING));
+ EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
+ element_id_, ElementListType::ACTIVE));
+ EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
+ element_id_, ElementListType::ACTIVE));
+
+ animations_impl->Animate(kInitialTickTime +
+ TimeDelta::FromMilliseconds(4000));
+ animations_impl->UpdateState(true, events.get());
+
+ animations->NotifyAnimationAborted(events->events_[0]);
+ EXPECT_FALSE(client_.GetHasPotentialOpacityAnimation(
+ element_id_, ElementListType::ACTIVE));
+ EXPECT_FALSE(client_.GetOpacityIsCurrentlyAnimating(element_id_,
+ 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.
+}
+
TEST_F(ElementAnimationsTest, ClippedOpacityValues) {
CreateTestLayer(false, false);
AttachTimelinePlayerLayer();
« 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