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

Unified Diff: cc/animation/layer_animation_controller_unittest.cc

Issue 13465014: LayerTreeHost::SetAnimationEvents should use AnimationRegistrar (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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/animation/layer_animation_controller_unittest.cc
diff --git a/cc/animation/layer_animation_controller_unittest.cc b/cc/animation/layer_animation_controller_unittest.cc
index 4f837666c2630f0bbad3193a4d00643aefe83e2a..20de468f79b32d5d836396ed9fe1f34b5cea8cfc 100644
--- a/cc/animation/layer_animation_controller_unittest.cc
+++ b/cc/animation/layer_animation_controller_unittest.cc
@@ -29,11 +29,11 @@ TEST(LayerAnimationControllerTest, SyncNewAnimation) {
FakeLayerAnimationValueObserver dummy_impl;
scoped_refptr<LayerAnimationController> controller_impl(
LayerAnimationController::Create(0));
- controller_impl->AddObserver(&dummy_impl);
+ controller_impl->AddValueObserver(&dummy_impl);
FakeLayerAnimationValueObserver dummy;
scoped_refptr<LayerAnimationController> controller(
LayerAnimationController::Create(0));
- controller->AddObserver(&dummy);
+ controller->AddValueObserver(&dummy);
EXPECT_FALSE(controller_impl->GetAnimation(0, Animation::Opacity));
@@ -52,11 +52,11 @@ TEST(LayerAnimationControllerTest, DoNotClobberStartTimes) {
FakeLayerAnimationValueObserver dummy_impl;
scoped_refptr<LayerAnimationController> controller_impl(
LayerAnimationController::Create(0));
- controller_impl->AddObserver(&dummy_impl);
+ controller_impl->AddValueObserver(&dummy_impl);
FakeLayerAnimationValueObserver dummy;
scoped_refptr<LayerAnimationController> controller(
LayerAnimationController::Create(0));
- controller->AddObserver(&dummy);
+ controller->AddValueObserver(&dummy);
EXPECT_FALSE(controller_impl->GetAnimation(0, Animation::Opacity));
@@ -74,7 +74,7 @@ TEST(LayerAnimationControllerTest, DoNotClobberStartTimes) {
// Synchronize the start times.
EXPECT_EQ(1u, events.size());
- controller->OnAnimationStarted(events[0]);
+ controller->NotifyAnimationStarted(events[0], 0.0);
EXPECT_EQ(controller->GetAnimation(0, Animation::Opacity)->start_time(),
controller_impl->GetAnimation(0, Animation::Opacity)->start_time());
@@ -89,11 +89,11 @@ TEST(LayerAnimationControllerTest, SyncPauseAndResume) {
FakeLayerAnimationValueObserver dummy_impl;
scoped_refptr<LayerAnimationController> controller_impl(
LayerAnimationController::Create(0));
- controller_impl->AddObserver(&dummy_impl);
+ controller_impl->AddValueObserver(&dummy_impl);
FakeLayerAnimationValueObserver dummy;
scoped_refptr<LayerAnimationController> controller(
LayerAnimationController::Create(0));
- controller->AddObserver(&dummy);
+ controller->AddValueObserver(&dummy);
EXPECT_FALSE(controller_impl->GetAnimation(0, Animation::Opacity));
@@ -141,11 +141,11 @@ TEST(LayerAnimationControllerTest, DoNotSyncFinishedAnimation) {
FakeLayerAnimationValueObserver dummy_impl;
scoped_refptr<LayerAnimationController> controller_impl(
LayerAnimationController::Create(0));
- controller_impl->AddObserver(&dummy_impl);
+ controller_impl->AddValueObserver(&dummy_impl);
FakeLayerAnimationValueObserver dummy;
scoped_refptr<LayerAnimationController> controller(
LayerAnimationController::Create(0));
- controller->AddObserver(&dummy);
+ controller->AddValueObserver(&dummy);
EXPECT_FALSE(controller_impl->GetAnimation(0, Animation::Opacity));
@@ -161,7 +161,7 @@ TEST(LayerAnimationControllerTest, DoNotSyncFinishedAnimation) {
// Notify main thread controller that the animation has started.
AnimationEvent animation_started_event(
AnimationEvent::Started, 0, 0, Animation::Opacity, 0);
- controller->OnAnimationStarted(animation_started_event);
+ controller->NotifyAnimationStarted(animation_started_event, 0.0);
// Force animation to complete on impl thread.
controller_impl->RemoveAnimation(animation_id);
@@ -175,6 +175,82 @@ TEST(LayerAnimationControllerTest, DoNotSyncFinishedAnimation) {
EXPECT_FALSE(controller_impl->GetAnimation(animation_id, Animation::Opacity));
}
+// Ensure that a finished animation is eventually deleted by both the
+// main-thread and the impl-thread controllers.
+TEST(LayerAnimationControllerTest, AnimationsAreDeleted) {
+ FakeLayerAnimationValueObserver dummy;
+ FakeLayerAnimationValueObserver dummy_impl;
+ scoped_ptr<AnimationEventsVector> events(
+ make_scoped_ptr(new AnimationEventsVector));
+ scoped_refptr<LayerAnimationController> controller(
+ LayerAnimationController::Create(0));
+ scoped_refptr<LayerAnimationController> controller_impl(
+ LayerAnimationController::Create(0));
+ controller->AddValueObserver(&dummy);
+ controller_impl->AddValueObserver(&dummy_impl);
+
+ AddOpacityTransitionToController(controller, 1.0, 0.0f, 1.0f, false);
+ controller->Animate(0.0);
+ controller->UpdateState(NULL);
+ controller->PushAnimationUpdatesTo(controller_impl.get());
+
+ controller_impl->Animate(0.5);
+ controller_impl->UpdateState(events.get());
+
+ // There should be a Started event for the animation.
+ EXPECT_EQ(1u, events->size());
+ EXPECT_EQ(AnimationEvent::Started, (*events)[0].type);
+ controller->NotifyAnimationStarted((*events)[0], 0.0);
+
+ controller->Animate(1.0);
+ controller->UpdateState(NULL);
+
+ events.reset(new AnimationEventsVector);
+ controller_impl->Animate(2.0);
+ controller_impl->UpdateState(events.get());
+
+ // There should be a Finished event for the animation.
+ EXPECT_EQ(1u, events->size());
+ EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type);
+
+ // Neither controller should have deleted the animation yet.
+ EXPECT_TRUE(controller->GetAnimation(Animation::Opacity));
+ EXPECT_TRUE(controller_impl->GetAnimation(Animation::Opacity));
+
+ controller->NotifyAnimationFinished((*events)[0], 0.0);
+
+ controller->Animate(3.0);
+ controller->UpdateState(NULL);
+
+ controller->PushAnimationUpdatesTo(controller_impl.get());
+
+ // Both controllers should now have deleted the animation.
+ EXPECT_FALSE(controller->has_any_animation());
+ EXPECT_FALSE(controller_impl->has_any_animation());
+}
Ian Vollick 2013/04/04 18:38:58 Great test!
+
+TEST(LayerAnimationControllerTest, TransferAnimationsTo) {
+ scoped_refptr<LayerAnimationController> controller(
+ LayerAnimationController::Create(0));
+ scoped_refptr<LayerAnimationController> other_controller(
+ LayerAnimationController::Create(1));
+
+ int opacity_animation_id =
+ AddOpacityTransitionToController(controller, 1.0, 0.0f, 1.0f, false);
+
+ int transform_animation_id =
+ AddAnimatedTransformToController(controller, 1.0, 10, 10);
+
+ controller->TransferAnimationsTo(other_controller);
+
+ // Ensure both animations have been transfered.
Ian Vollick 2013/04/04 18:38:58 Can you also confirm that the run states are ident
ajuma 2013/04/05 14:38:18 Done.
+ EXPECT_FALSE(controller->has_any_animation());
+ EXPECT_EQ(other_controller->GetAnimation(Animation::Opacity)->id(),
+ opacity_animation_id);
+ EXPECT_EQ(other_controller->GetAnimation(Animation::Transform)->id(),
+ transform_animation_id);
+}
+
// Tests that transitioning opacity from 0 to 1 works as expected.
static const AnimationEvent* GetMostRecentPropertyUpdateEvent(
@@ -193,7 +269,7 @@ TEST(LayerAnimationControllerTest, TrivialTransition) {
FakeLayerAnimationValueObserver dummy;
scoped_refptr<LayerAnimationController> controller(
LayerAnimationController::Create(0));
- controller->AddObserver(&dummy);
+ controller->AddValueObserver(&dummy);
scoped_ptr<Animation> to_add(CreateAnimation(
scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
@@ -222,7 +298,7 @@ TEST(LayerAnimationControllerTest, TrivialTransitionOnImpl) {
FakeLayerAnimationValueObserver dummy_impl;
scoped_refptr<LayerAnimationController> controller_impl(
LayerAnimationController::Create(0));
- controller_impl->AddObserver(&dummy_impl);
+ controller_impl->AddValueObserver(&dummy_impl);
scoped_ptr<Animation> to_add(CreateAnimation(
scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
@@ -256,7 +332,7 @@ TEST(LayerAnimationControllerTest, TrivialTransformOnImpl) {
FakeLayerAnimationValueObserver dummy_impl;
scoped_refptr<LayerAnimationController> controller_impl(
LayerAnimationController::Create(0));
- controller_impl->AddObserver(&dummy_impl);
+ controller_impl->AddValueObserver(&dummy_impl);
// Choose different values for x and y to avoid coincidental values in the
// observed transforms.
@@ -312,7 +388,7 @@ TEST(LayerAnimationControllerTest,
FakeLayerAnimationValueObserver dummy;
scoped_refptr<LayerAnimationController> controller(
LayerAnimationController::Create(0));
- controller->AddObserver(&dummy);
+ controller->AddValueObserver(&dummy);
scoped_ptr<Animation> to_add(CreateAnimation(
scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
@@ -337,8 +413,9 @@ TEST(LayerAnimationControllerTest,
EXPECT_EQ(0.f, dummy.opacity());
// Send the synchronized start time.
- controller->OnAnimationStarted(AnimationEvent(
- AnimationEvent::Started, 0, 1, Animation::Opacity, 2));
+ controller->NotifyAnimationStarted(
+ AnimationEvent(AnimationEvent::Started, 0, 1, Animation::Opacity, 2),
+ 0.0);
controller->Animate(5.0);
controller->UpdateState(events.get());
EXPECT_EQ(1.f, dummy.opacity());
@@ -352,7 +429,7 @@ TEST(LayerAnimationControllerTest, TrivialQueuing) {
FakeLayerAnimationValueObserver dummy;
scoped_refptr<LayerAnimationController> controller(
LayerAnimationController::Create(0));
- controller->AddObserver(&dummy);
+ controller->AddValueObserver(&dummy);
controller->AddAnimation(CreateAnimation(
scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
@@ -385,7 +462,7 @@ TEST(LayerAnimationControllerTest, Interrupt) {
FakeLayerAnimationValueObserver dummy;
scoped_refptr<LayerAnimationController> controller(
LayerAnimationController::Create(0));
- controller->AddObserver(&dummy);
+ controller->AddValueObserver(&dummy);
controller->AddAnimation(CreateAnimation(
scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1,
@@ -423,7 +500,7 @@ TEST(LayerAnimationControllerTest, ScheduleTogetherWhenAPropertyIsBlocked) {
FakeLayerAnimationValueObserver dummy;
scoped_refptr<LayerAnimationController> controller(
LayerAnimationController::Create(0));
- controller->AddObserver(&dummy);
+ controller->AddValueObserver(&dummy);
controller->AddAnimation(CreateAnimation(
scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(),
@@ -463,7 +540,7 @@ TEST(LayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting) {
FakeLayerAnimationValueObserver dummy;
scoped_refptr<LayerAnimationController> controller(
LayerAnimationController::Create(0));
- controller->AddObserver(&dummy);
+ controller->AddValueObserver(&dummy);
controller->AddAnimation(CreateAnimation(
scoped_ptr<AnimationCurve>(new FakeTransformTransition(2)).Pass(),
@@ -508,7 +585,7 @@ TEST(LayerAnimationControllerTest, ScheduleAnimation) {
FakeLayerAnimationValueObserver dummy;
scoped_refptr<LayerAnimationController> controller(
LayerAnimationController::Create(0));
- controller->AddObserver(&dummy);
+ controller->AddValueObserver(&dummy);
scoped_ptr<Animation> to_add(CreateAnimation(
scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
@@ -541,7 +618,7 @@ TEST(LayerAnimationControllerTest,
FakeLayerAnimationValueObserver dummy;
scoped_refptr<LayerAnimationController> controller(
LayerAnimationController::Create(0));
- controller->AddObserver(&dummy);
+ controller->AddValueObserver(&dummy);
controller->AddAnimation(CreateAnimation(
scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(),
@@ -585,7 +662,7 @@ TEST(LayerAnimationControllerTest,
FakeLayerAnimationValueObserver dummy;
scoped_refptr<LayerAnimationController> controller(
LayerAnimationController::Create(0));
- controller->AddObserver(&dummy);
+ controller->AddValueObserver(&dummy);
controller->AddAnimation(CreateAnimation(
scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(),
@@ -638,7 +715,7 @@ TEST(LayerAnimationControllerTest, TrivialLooping) {
FakeLayerAnimationValueObserver dummy;
scoped_refptr<LayerAnimationController> controller(
LayerAnimationController::Create(0));
- controller->AddObserver(&dummy);
+ controller->AddValueObserver(&dummy);
scoped_ptr<Animation> to_add(CreateAnimation(
scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
@@ -685,7 +762,7 @@ TEST(LayerAnimationControllerTest, InfiniteLooping) {
FakeLayerAnimationValueObserver dummy;
scoped_refptr<LayerAnimationController> controller(
LayerAnimationController::Create(0));
- controller->AddObserver(&dummy);
+ controller->AddValueObserver(&dummy);
const int id = 1;
scoped_ptr<Animation> to_add(CreateAnimation(
@@ -731,7 +808,7 @@ TEST(LayerAnimationControllerTest, PauseResume) {
FakeLayerAnimationValueObserver dummy;
scoped_refptr<LayerAnimationController> controller(
LayerAnimationController::Create(0));
- controller->AddObserver(&dummy);
+ controller->AddValueObserver(&dummy);
const int id = 1;
controller->AddAnimation(CreateAnimation(
@@ -777,7 +854,7 @@ TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) {
FakeLayerAnimationValueObserver dummy;
scoped_refptr<LayerAnimationController> controller(
LayerAnimationController::Create(0));
- controller->AddObserver(&dummy);
+ controller->AddValueObserver(&dummy);
const int id = 1;
controller->AddAnimation(CreateAnimation(
@@ -820,13 +897,13 @@ TEST(LayerAnimationControllerTest, ForceSyncWhenSynchronizedStartTimeNeeded) {
FakeLayerAnimationValueObserver dummy_impl;
scoped_refptr<LayerAnimationController> controller_impl(
LayerAnimationController::Create(0));
- controller_impl->AddObserver(&dummy_impl);
+ controller_impl->AddValueObserver(&dummy_impl);
scoped_ptr<AnimationEventsVector> events(
make_scoped_ptr(new AnimationEventsVector));
FakeLayerAnimationValueObserver dummy;
scoped_refptr<LayerAnimationController> controller(
LayerAnimationController::Create(0));
- controller->AddObserver(&dummy);
+ controller->AddValueObserver(&dummy);
scoped_ptr<Animation> to_add(CreateAnimation(
scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(),
@@ -859,7 +936,7 @@ TEST(LayerAnimationControllerTest, SkipUpdateState) {
FakeLayerAnimationValueObserver dummy;
scoped_refptr<LayerAnimationController> controller(
LayerAnimationController::Create(0));
- controller->AddObserver(&dummy);
+ controller->AddValueObserver(&dummy);
controller->AddAnimation(CreateAnimation(
scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(),

Powered by Google App Engine
This is Rietveld 408576698