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

Unified Diff: cc/layer_animation_controller_unittest.cc

Issue 12453010: Allow impl-only animations, and return opacity values via AnimationEvents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update transform on Layer also. Created 7 years, 9 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/layer_animation_controller_unittest.cc
diff --git a/cc/layer_animation_controller_unittest.cc b/cc/layer_animation_controller_unittest.cc
index c451952a1260227847feeb30471787d6ae546b33..77a15954c5b98a5e990d1bb984cfab5234a31f8d 100644
--- a/cc/layer_animation_controller_unittest.cc
+++ b/cc/layer_animation_controller_unittest.cc
@@ -6,7 +6,9 @@
#include "cc/animation.h"
#include "cc/animation_curve.h"
+#include "cc/keyframed_animation_curve.h"
#include "cc/test/animation_test_common.h"
+#include "cc/transform_operations.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/transform.h"
@@ -156,6 +158,17 @@ TEST(LayerAnimationControllerTest, doNotSyncFinishedAnimation)
}
// Tests that transitioning opacity from 0 to 1 works as expected.
+
+static const AnimationEvent* getMostRecentPropertyUpdateEvent(const AnimationEventsVector* events)
+{
+ const AnimationEvent* event = 0;
+ for (size_t i = 0; i < events->size(); ++i)
+ if ((*events)[i].type == AnimationEvent::PropertyUpdate)
+ event = &(*events)[i];
+
+ return event;
+}
+
TEST(LayerAnimationControllerTest, TrivialTransition)
{
scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEventsVector));
@@ -176,6 +189,80 @@ TEST(LayerAnimationControllerTest, TrivialTransition)
EXPECT_FALSE(controller->hasActiveAnimation());
}
Ian Vollick 2013/03/06 23:29:45 I'd also like you to confirm that we don't generat
wjmaclean 2013/03/07 13:49:29 We already do that implicitly, in that the checks
+TEST(LayerAnimationControllerTest, TrivialTransitionOnImpl)
+{
+ scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEventsVector));
+ FakeLayerAnimationValueObserver dummyImpl;
+ scoped_refptr<LayerAnimationController> controllerImpl(LayerAnimationController::create(0));
+ controllerImpl->addObserver(&dummyImpl);
+
+ scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTransition(1, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity));
+ toAdd->setIsImplOnly(true);
+
+ controllerImpl->addAnimation(toAdd.Pass());
+ controllerImpl->animate(0);
+ controllerImpl->updateState(events.get());
+ EXPECT_TRUE(controllerImpl->hasActiveAnimation());
+ EXPECT_EQ(0, dummyImpl.opacity());
+ EXPECT_EQ(2, events->size());
+ const AnimationEvent* startOpacityEvent = getMostRecentPropertyUpdateEvent(events.get());
+ EXPECT_EQ(0, startOpacityEvent->value);
+
+ controllerImpl->animate(1);
+ controllerImpl->updateState(events.get());
+ EXPECT_EQ(1, dummyImpl.opacity());
+ EXPECT_FALSE(controllerImpl->hasActiveAnimation());
+ EXPECT_EQ(4, events->size());
+ const AnimationEvent* endOpacityEvent = getMostRecentPropertyUpdateEvent(events.get());
+ EXPECT_EQ(1, endOpacityEvent->value);
+}
+
+TEST(LayerAnimationControllerTest, TrivialTransformOnImpl)
+{
+ scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEventsVector));
+ FakeLayerAnimationValueObserver dummyImpl;
+ scoped_refptr<LayerAnimationController> controllerImpl(LayerAnimationController::create(0));
+ controllerImpl->addObserver(&dummyImpl);
+
+ // Choose different values for x and y to avoid coincidental values in the
+ // observed transforms.
+ const float deltaX = 3;
+ const float deltaY = 4;
+
+ scoped_ptr<KeyframedTransformAnimationCurve> curve(KeyframedTransformAnimationCurve::create());
+
+ // Create simple Transform animation.
+ TransformOperations operations;
+ curve->addKeyframe(TransformKeyframe::create(0, operations, scoped_ptr<cc::TimingFunction>()));
+ operations.AppendTranslate(deltaX, deltaY, 0);
+ curve->addKeyframe(TransformKeyframe::create(1, operations, scoped_ptr<cc::TimingFunction>()));
+
+ scoped_ptr<Animation> animation(Animation::create(curve.PassAs<AnimationCurve>(), 1, 0, Animation::Transform));
+ animation->setIsImplOnly(true);
+ controllerImpl->addAnimation(animation.Pass());
+
+ // Run animation.
+ controllerImpl->animate(0);
+ controllerImpl->updateState(events.get());
+ EXPECT_TRUE(controllerImpl->hasActiveAnimation());
+ EXPECT_EQ(gfx::Transform(), dummyImpl.transform());
+ EXPECT_EQ(2, events->size());
+ const AnimationEvent* startTransformEvent = getMostRecentPropertyUpdateEvent(events.get());
+ ASSERT_TRUE(startTransformEvent);
+ EXPECT_EQ(gfx::Transform(), startTransformEvent->transform);
+
+ gfx::Transform expectedTransform;
+ expectedTransform.Translate(deltaX, deltaY);
+
+ controllerImpl->animate(1);
+ controllerImpl->updateState(events.get());
+ EXPECT_EQ(expectedTransform, dummyImpl.transform());
+ EXPECT_FALSE(controllerImpl->hasActiveAnimation());
+ EXPECT_EQ(4, events->size());
+ const AnimationEvent* endTransformEvent = getMostRecentPropertyUpdateEvent(events.get());
+ EXPECT_EQ(expectedTransform, endTransformEvent->transform);
+}
+
// Tests animations that are waiting for a synchronized start time do not finish.
TEST(LayerAnimationControllerTest, AnimationsWaitingForStartTimeDoNotFinishIfTheyWaitLongerToStartThanTheirDuration)
{

Powered by Google App Engine
This is Rietveld 408576698