diff options
author | ajuma@chromium.org <ajuma@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-22 18:24:16 +0000 |
---|---|---|
committer | ajuma@chromium.org <ajuma@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-22 18:24:16 +0000 |
commit | 35ff8a00599034d0803fcf4532b48c11e14342ef (patch) | |
tree | 480ef9bcf27b2bd756e2f69a426d5a98a2410ec7 /cc | |
parent | 4643d699bdfa6d5c3567714c68869d7bc3b57265 (diff) | |
download | chromium_src-35ff8a00599034d0803fcf4532b48c11e14342ef.zip chromium_src-35ff8a00599034d0803fcf4532b48c11e14342ef.tar.gz chromium_src-35ff8a00599034d0803fcf4532b48c11e14342ef.tar.bz2 |
Enable tests for AnimationFinished notifications
This enables checks that animations finished, in tests that were added
by https://codereview.chromium.org/13613003. These checks can now be
enabled, since https://codereview.chromium.org/13465014 has landed.
This also changes animation_test_common.cc to use AnimationIdProvider
to obtain animation group ids, rather than always using group id 0.
Using unique group ids is required for enabling one of the
AnimationFinished checks.
BUG=None
Review URL: https://chromiumcodereview.appspot.com/14293012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195557 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
-rw-r--r-- | cc/animation/layer_animation_controller_unittest.cc | 68 | ||||
-rw-r--r-- | cc/test/animation_test_common.cc | 13 | ||||
-rw-r--r-- | cc/trees/layer_tree_host_unittest_animation.cc | 23 |
3 files changed, 60 insertions, 44 deletions
diff --git a/cc/animation/layer_animation_controller_unittest.cc b/cc/animation/layer_animation_controller_unittest.cc index a5c815b..4600f12 100644 --- a/cc/animation/layer_animation_controller_unittest.cc +++ b/cc/animation/layer_animation_controller_unittest.cc @@ -36,15 +36,17 @@ TEST(LayerAnimationControllerTest, SyncNewAnimation) { LayerAnimationController::Create(0)); controller->AddValueObserver(&dummy); - EXPECT_FALSE(controller_impl->GetAnimation(0, Animation::Opacity)); + EXPECT_FALSE(controller_impl->GetAnimation(Animation::Opacity)); AddOpacityTransitionToController(controller, 1, 0, 1, false); + int group_id = controller->GetAnimation(Animation::Opacity)->group(); controller->PushAnimationUpdatesTo(controller_impl.get()); - EXPECT_TRUE(controller_impl->GetAnimation(0, Animation::Opacity)); + EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)); EXPECT_EQ(Animation::WaitingForTargetAvailability, - controller_impl->GetAnimation(0, Animation::Opacity)->run_state()); + controller_impl->GetAnimation(group_id, + Animation::Opacity)->run_state()); } // If an animation is started on the impl thread before it is ticked on the main @@ -59,15 +61,17 @@ TEST(LayerAnimationControllerTest, DoNotClobberStartTimes) { LayerAnimationController::Create(0)); controller->AddValueObserver(&dummy); - EXPECT_FALSE(controller_impl->GetAnimation(0, Animation::Opacity)); + EXPECT_FALSE(controller_impl->GetAnimation(Animation::Opacity)); AddOpacityTransitionToController(controller, 1, 0, 1, false); + int group_id = controller->GetAnimation(Animation::Opacity)->group(); controller->PushAnimationUpdatesTo(controller_impl.get()); - EXPECT_TRUE(controller_impl->GetAnimation(0, Animation::Opacity)); + EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)); EXPECT_EQ(Animation::WaitingForTargetAvailability, - controller_impl->GetAnimation(0, Animation::Opacity)->run_state()); + controller_impl->GetAnimation(group_id, + Animation::Opacity)->run_state()); AnimationEventsVector events; controller_impl->Animate(1.0); @@ -76,14 +80,18 @@ TEST(LayerAnimationControllerTest, DoNotClobberStartTimes) { // Synchronize the start times. EXPECT_EQ(1u, events.size()); controller->NotifyAnimationStarted(events[0], 0.0); - EXPECT_EQ(controller->GetAnimation(0, Animation::Opacity)->start_time(), - controller_impl->GetAnimation(0, Animation::Opacity)->start_time()); + EXPECT_EQ(controller->GetAnimation(group_id, + Animation::Opacity)->start_time(), + controller_impl->GetAnimation(group_id, + Animation::Opacity)->start_time()); // Start the animation on the main thread. Should not affect the start time. controller->Animate(1.5); controller->UpdateState(true, NULL); - EXPECT_EQ(controller->GetAnimation(0, Animation::Opacity)->start_time(), - controller_impl->GetAnimation(0, Animation::Opacity)->start_time()); + EXPECT_EQ(controller->GetAnimation(group_id, + Animation::Opacity)->start_time(), + controller_impl->GetAnimation(group_id, + Animation::Opacity)->start_time()); } TEST(LayerAnimationControllerTest, SyncPauseAndResume) { @@ -96,15 +104,17 @@ TEST(LayerAnimationControllerTest, SyncPauseAndResume) { LayerAnimationController::Create(0)); controller->AddValueObserver(&dummy); - EXPECT_FALSE(controller_impl->GetAnimation(0, Animation::Opacity)); + EXPECT_FALSE(controller_impl->GetAnimation(Animation::Opacity)); AddOpacityTransitionToController(controller, 1, 0, 1, false); + int group_id = controller->GetAnimation(Animation::Opacity)->group(); controller->PushAnimationUpdatesTo(controller_impl.get()); - EXPECT_TRUE(controller_impl->GetAnimation(0, Animation::Opacity)); + EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)); EXPECT_EQ(Animation::WaitingForTargetAvailability, - controller_impl->GetAnimation(0, Animation::Opacity)->run_state()); + controller_impl->GetAnimation(group_id, + Animation::Opacity)->run_state()); // Start the animations on each controller. AnimationEventsVector events; @@ -113,29 +123,35 @@ TEST(LayerAnimationControllerTest, SyncPauseAndResume) { controller->Animate(0.0); controller->UpdateState(true, NULL); EXPECT_EQ(Animation::Running, - controller_impl->GetAnimation(0, Animation::Opacity)->run_state()); + controller_impl->GetAnimation(group_id, + Animation::Opacity)->run_state()); EXPECT_EQ(Animation::Running, - controller->GetAnimation(0, Animation::Opacity)->run_state()); + controller->GetAnimation(group_id, + Animation::Opacity)->run_state()); // Pause the main-thread animation. controller->SuspendAnimations(1.0); EXPECT_EQ(Animation::Paused, - controller->GetAnimation(0, Animation::Opacity)->run_state()); + controller->GetAnimation(group_id, + Animation::Opacity)->run_state()); // The pause run state change should make it to the impl thread controller. controller->PushAnimationUpdatesTo(controller_impl.get()); EXPECT_EQ(Animation::Paused, - controller_impl->GetAnimation(0, Animation::Opacity)->run_state()); + controller_impl->GetAnimation(group_id, + Animation::Opacity)->run_state()); // Resume the main-thread animation. controller->ResumeAnimations(2.0); EXPECT_EQ(Animation::Running, - controller->GetAnimation(0, Animation::Opacity)->run_state()); + controller->GetAnimation(group_id, + Animation::Opacity)->run_state()); // The pause run state change should make it to the impl thread controller. controller->PushAnimationUpdatesTo(controller_impl.get()); EXPECT_EQ(Animation::Running, - controller_impl->GetAnimation(0, Animation::Opacity)->run_state()); + controller_impl->GetAnimation(group_id, + Animation::Opacity)->run_state()); } TEST(LayerAnimationControllerTest, DoNotSyncFinishedAnimation) { @@ -148,32 +164,34 @@ TEST(LayerAnimationControllerTest, DoNotSyncFinishedAnimation) { LayerAnimationController::Create(0)); controller->AddValueObserver(&dummy); - EXPECT_FALSE(controller_impl->GetAnimation(0, Animation::Opacity)); + EXPECT_FALSE(controller_impl->GetAnimation(Animation::Opacity)); int animation_id = AddOpacityTransitionToController(controller, 1, 0, 1, false); + int group_id = controller->GetAnimation(Animation::Opacity)->group(); controller->PushAnimationUpdatesTo(controller_impl.get()); - EXPECT_TRUE(controller_impl->GetAnimation(0, Animation::Opacity)); + EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)); EXPECT_EQ(Animation::WaitingForTargetAvailability, - controller_impl->GetAnimation(0, Animation::Opacity)->run_state()); + controller_impl->GetAnimation(group_id, + Animation::Opacity)->run_state()); // Notify main thread controller that the animation has started. AnimationEvent animation_started_event( - AnimationEvent::Started, 0, 0, Animation::Opacity, 0); + AnimationEvent::Started, 0, group_id, Animation::Opacity, 0); controller->NotifyAnimationStarted(animation_started_event, 0.0); // Force animation to complete on impl thread. controller_impl->RemoveAnimation(animation_id); - EXPECT_FALSE(controller_impl->GetAnimation(animation_id, Animation::Opacity)); + EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity)); controller->PushAnimationUpdatesTo(controller_impl.get()); // Even though the main thread has a 'new' animation, it should not be pushed // because the animation has already completed on the impl thread. - EXPECT_FALSE(controller_impl->GetAnimation(animation_id, Animation::Opacity)); + EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity)); } // Ensure that a finished animation is eventually deleted by both the diff --git a/cc/test/animation_test_common.cc b/cc/test/animation_test_common.cc index 51e89f6..84f9134 100644 --- a/cc/test/animation_test_common.cc +++ b/cc/test/animation_test_common.cc @@ -4,6 +4,7 @@ #include "cc/test/animation_test_common.h" +#include "cc/animation/animation_id_provider.h" #include "cc/animation/keyframed_animation_curve.h" #include "cc/animation/layer_animation_controller.h" #include "cc/animation/transform_operations.h" @@ -21,8 +22,6 @@ using cc::TransformKeyframe; namespace cc { -static int s_next_animation_id = 0; - template <class Target> int AddOpacityTransition(Target* target, double duration, @@ -41,12 +40,12 @@ int AddOpacityTransition(Target* target, end_opacity, scoped_ptr<cc::TimingFunction>())); - int id = s_next_animation_id++; + int id = AnimationIdProvider::NextAnimationId(); scoped_ptr<Animation> animation(Animation::Create( curve.PassAs<AnimationCurve>(), id, - 0, + AnimationIdProvider::NextGroupId(), Animation::Opacity)); animation->set_needs_synchronized_start_time(true); @@ -78,11 +77,13 @@ int AddAnimatedTransform(Target* target, operations, scoped_ptr<cc::TimingFunction>())); - int id = s_next_animation_id++; + int id = AnimationIdProvider::NextAnimationId(); scoped_ptr<Animation> animation(Animation::Create( curve.PassAs<AnimationCurve>(), - id, 0, Animation::Transform)); + id, + AnimationIdProvider::NextGroupId(), + Animation::Transform)); animation->set_needs_synchronized_start_time(true); target->AddAnimation(animation.Pass()); diff --git a/cc/trees/layer_tree_host_unittest_animation.cc b/cc/trees/layer_tree_host_unittest_animation.cc index 425886c..36833c0 100644 --- a/cc/trees/layer_tree_host_unittest_animation.cc +++ b/cc/trees/layer_tree_host_unittest_animation.cc @@ -140,7 +140,7 @@ class LayerTreeHostAnimationTestAddAnimation LayerAnimationController* controller_impl = host_impl->active_tree()->root_layer()->layer_animation_controller(); Animation* animation_impl = - controller_impl->GetAnimation(0, Animation::Opacity); + controller_impl->GetAnimation(Animation::Opacity); if (animation_impl) controller_impl->RemoveAnimation(animation_impl->id()); @@ -157,7 +157,7 @@ class LayerTreeHostAnimationTestAddAnimation LayerAnimationController* controller = layer_tree_host()->root_layer()->layer_animation_controller(); Animation* animation = - controller->GetAnimation(0, Animation::Opacity); + controller->GetAnimation(Animation::Opacity); if (animation) controller->RemoveAnimation(animation->id()); @@ -276,7 +276,7 @@ class LayerTreeHostAnimationTestAddAnimationWithTimingFunction layer_tree_host()->root_layer()->children()[0]-> layer_animation_controller(); Animation* animation = - controller->GetAnimation(0, Animation::Opacity); + controller->GetAnimation(Animation::Opacity); if (!animation) return; @@ -296,7 +296,7 @@ class LayerTreeHostAnimationTestAddAnimationWithTimingFunction host_impl->active_tree()->root_layer()->children()[0]-> layer_animation_controller(); Animation* animation_impl = - controller_impl->GetAnimation(0, Animation::Opacity); + controller_impl->GetAnimation(Animation::Opacity); controller->RemoveAnimation(animation->id()); controller_impl->RemoveAnimation(animation_impl->id()); @@ -338,7 +338,7 @@ class LayerTreeHostAnimationTestSynchronizeAnimationStartTimes layer_tree_host()->root_layer()->children()[0]-> layer_animation_controller(); Animation* animation = - controller->GetAnimation(0, Animation::Opacity); + controller->GetAnimation(Animation::Opacity); main_start_time_ = animation->start_time(); controller->RemoveAnimation(animation->id()); @@ -353,7 +353,7 @@ class LayerTreeHostAnimationTestSynchronizeAnimationStartTimes impl_host->active_tree()->root_layer()->children()[0]-> layer_animation_controller(); Animation* animation = - controller->GetAnimation(0, Animation::Opacity); + controller->GetAnimation(Animation::Opacity); if (!animation) return; @@ -392,7 +392,7 @@ class LayerTreeHostAnimationTestAnimationFinishedEvents LayerAnimationController* controller = layer_tree_host()->root_layer()->layer_animation_controller(); Animation* animation = - controller->GetAnimation(0, Animation::Opacity); + controller->GetAnimation(Animation::Opacity); if (animation) controller->RemoveAnimation(animation->id()); EndTest(); @@ -427,7 +427,7 @@ class LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity LayerAnimationController* controller_impl = host_impl->active_tree()->root_layer()->layer_animation_controller(); Animation* animation_impl = - controller_impl->GetAnimation(0, Animation::Opacity); + controller_impl->GetAnimation(Animation::Opacity); controller_impl->RemoveAnimation(animation_impl->id()); EndTest(); } @@ -606,8 +606,6 @@ class LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw virtual void notifyAnimationStarted(double wall_clock_time) OVERRIDE { started_times_++; - // TODO(ajuma): Remove this EndTest() so we test animation finishing. - EndTest(); } virtual void notifyAnimationFinished(double wall_clock_time) OVERRIDE { @@ -730,7 +728,6 @@ class LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations added_animations_++; break; case 3: - EndTest(); break; } } @@ -744,6 +741,7 @@ class LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations // first animation. EXPECT_EQ(2, added_animations_); finished_times_++; + EndTest(); } virtual void AfterTest() OVERRIDE { @@ -751,8 +749,7 @@ class LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations // of checkerboard. EXPECT_EQ(1, started_times_); // The first animation should still be finished. - // TODO(ajuma): The first animation is not being finished, but it should be. - //EXPECT_EQ(1, finished_times_); + EXPECT_EQ(1, finished_times_); } int added_animations_; |