summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbruthig <bruthig@chromium.org>2015-10-07 13:44:20 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-07 20:45:13 +0000
commitc6e5c539b545cb115d23a05016f19dcb71a03ea7 (patch)
tree17ae997fee32befda482d3b0300afece5fec3be8
parent7762ac7feec141978a783691da89ba2e9a6f1c63 (diff)
downloadchromium_src-c6e5c539b545cb115d23a05016f19dcb71a03ea7.zip
chromium_src-c6e5c539b545cb115d23a05016f19dcb71a03ea7.tar.gz
chromium_src-c6e5c539b545cb115d23a05016f19dcb71a03ea7.tar.bz2
Added an OnLayerAnimationStarted() notification to the LayerAnimationObserver.
BUG=522175, 537614 TEST=LayerAnimatorObserverNotificationOrderTest.SuccessfulCompletionOfSequence TEST=LayerAnimatorObserverNotificationOrderTest.AbortingAScheduledSequence TEST=LayerAnimatorObserverNotificationOrderTest.RunningASequenceThatIsQueuedForLaterStartTime TEST=LayerAnimatorObserverNotificationOrderTest.RunningASequenceThatPreEmptsAnotherSequence Review URL: https://codereview.chromium.org/1381463002 Cr-Commit-Position: refs/heads/master@{#352936}
-rw-r--r--ui/compositor/layer_animation_observer.cc3
-rw-r--r--ui/compositor/layer_animation_observer.h3
-rw-r--r--ui/compositor/layer_animation_sequence.cc7
-rw-r--r--ui/compositor/layer_animation_sequence.h3
-rw-r--r--ui/compositor/layer_animator_unittest.cc488
-rw-r--r--ui/compositor/test/test_layer_animation_observer.cc194
-rw-r--r--ui/compositor/test/test_layer_animation_observer.h91
7 files changed, 605 insertions, 184 deletions
diff --git a/ui/compositor/layer_animation_observer.cc b/ui/compositor/layer_animation_observer.cc
index 658a835..e5db5ec 100644
--- a/ui/compositor/layer_animation_observer.cc
+++ b/ui/compositor/layer_animation_observer.cc
@@ -18,6 +18,9 @@ LayerAnimationObserver::~LayerAnimationObserver() {
StopObserving();
}
+void LayerAnimationObserver::OnLayerAnimationStarted(
+ LayerAnimationSequence* sequence) {}
+
bool LayerAnimationObserver::RequiresNotificationWhenAnimatorDestroyed() const {
return false;
}
diff --git a/ui/compositor/layer_animation_observer.h b/ui/compositor/layer_animation_observer.h
index 35253d3..26bfdfa 100644
--- a/ui/compositor/layer_animation_observer.h
+++ b/ui/compositor/layer_animation_observer.h
@@ -22,6 +22,9 @@ class ImplicitAnimationObserver;
// LayerAnimationObservers are notified when animations complete.
class COMPOSITOR_EXPORT LayerAnimationObserver {
public:
+ // Called when the |sequence| starts.
+ virtual void OnLayerAnimationStarted(LayerAnimationSequence* sequence);
+
// Called when the |sequence| ends. Not called if |sequence| is aborted.
virtual void OnLayerAnimationEnded(
LayerAnimationSequence* sequence) = 0;
diff --git a/ui/compositor/layer_animation_sequence.cc b/ui/compositor/layer_animation_sequence.cc
index 2c01a22..04a91af 100644
--- a/ui/compositor/layer_animation_sequence.cc
+++ b/ui/compositor/layer_animation_sequence.cc
@@ -48,6 +48,8 @@ void LayerAnimationSequence::Start(LayerAnimationDelegate* delegate) {
if (elements_.empty())
return;
+ NotifyStarted();
+
elements_[0]->set_requested_start_time(start_time_);
elements_[0]->Start(delegate, animation_group_id_);
}
@@ -258,6 +260,11 @@ void LayerAnimationSequence::NotifyScheduled() {
OnLayerAnimationScheduled(this));
}
+void LayerAnimationSequence::NotifyStarted() {
+ FOR_EACH_OBSERVER(LayerAnimationObserver, observers_,
+ OnLayerAnimationStarted(this));
+}
+
void LayerAnimationSequence::NotifyEnded() {
FOR_EACH_OBSERVER(LayerAnimationObserver,
observers_,
diff --git a/ui/compositor/layer_animation_sequence.h b/ui/compositor/layer_animation_sequence.h
index 0dad650..98afe9e 100644
--- a/ui/compositor/layer_animation_sequence.h
+++ b/ui/compositor/layer_animation_sequence.h
@@ -140,6 +140,9 @@ class COMPOSITOR_EXPORT LayerAnimationSequence
// Notifies the observers that this sequence has been scheduled.
void NotifyScheduled();
+ // Notifies the observers that this sequence has been started.
+ void NotifyStarted();
+
// Notifies the observers that this sequence has ended.
void NotifyEnded();
diff --git a/ui/compositor/layer_animator_unittest.cc b/ui/compositor/layer_animator_unittest.cc
index b3743ed..3ceeb4d 100644
--- a/ui/compositor/layer_animator_unittest.cc
+++ b/ui/compositor/layer_animator_unittest.cc
@@ -54,6 +54,54 @@ std::vector<LayerAnimationSequence*> CreateMultiSequence(
return animations;
}
+// Creates a default animator with timers disabled for test. |delegate| and
+// |observer| are attached if non-null.
+LayerAnimator* CreateDefaultTestAnimator(LayerAnimationDelegate* delegate,
+ LayerAnimationObserver* observer) {
+ LayerAnimator* animator(LayerAnimator::CreateDefaultAnimator());
+ animator->set_disable_timer_for_test(true);
+ if (delegate)
+ animator->SetDelegate(delegate);
+ if (observer)
+ animator->AddObserver(observer);
+ return animator;
+}
+
+// Creates a default animator with timers disabled for test. |delegate| is
+// attached if non-null.
+LayerAnimator* CreateDefaultTestAnimator(LayerAnimationDelegate* delegate) {
+ return CreateDefaultTestAnimator(delegate, nullptr);
+}
+
+// Creates a default animator with timers disabled for test.
+LayerAnimator* CreateDefaultTestAnimator() {
+ return CreateDefaultTestAnimator(nullptr, nullptr);
+}
+
+// Creates an implicit animator with timers disabled for test. |delegate| and
+// |observer| are attached if non-null.
+LayerAnimator* CreateImplicitTestAnimator(LayerAnimationDelegate* delegate,
+ LayerAnimationObserver* observer) {
+ LayerAnimator* animator(LayerAnimator::CreateImplicitAnimator());
+ animator->set_disable_timer_for_test(true);
+ if (delegate)
+ animator->SetDelegate(delegate);
+ if (observer)
+ animator->AddObserver(observer);
+ return animator;
+}
+
+// Creates an implicit animator with timers disabled for test. |delegate| is
+// attached if non-null.
+LayerAnimator* CreateImplicitTestAnimator(LayerAnimationDelegate* delegate) {
+ return CreateImplicitTestAnimator(delegate, nullptr);
+}
+
+// Creates an implicit animator with timers disabled for test.
+LayerAnimator* CreateImplicitTestAnimator() {
+ return CreateImplicitTestAnimator(nullptr, nullptr);
+}
+
class TestImplicitAnimationObserver : public ImplicitAnimationObserver {
public:
explicit TestImplicitAnimationObserver(bool notify_when_animator_destructed)
@@ -188,11 +236,8 @@ class TestLayerAnimationSequence : public LayerAnimationSequence {
// Checks that setting a property on an implicit animator causes an animation to
// happen.
TEST(LayerAnimatorTest, ImplicitAnimation) {
- scoped_refptr<LayerAnimator> animator(
- LayerAnimator::CreateImplicitAnimator());
- animator->set_disable_timer_for_test(true);
TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateImplicitTestAnimator(&delegate));
base::TimeTicks now = base::TimeTicks::Now();
animator->SetBrightness(0.5);
EXPECT_TRUE(animator->is_animating());
@@ -203,10 +248,8 @@ TEST(LayerAnimatorTest, ImplicitAnimation) {
// Checks that if the animator is a default animator, that implicit animations
// are not started.
TEST(LayerAnimatorTest, NoImplicitAnimation) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_disable_timer_for_test(true);
TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
animator->SetBrightness(0.5);
EXPECT_FALSE(animator->is_animating());
EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), 0.5);
@@ -215,11 +258,8 @@ TEST(LayerAnimatorTest, NoImplicitAnimation) {
// Checks that StopAnimatingProperty stops animation for that property, and also
// skips the stopped animation to the end.
TEST(LayerAnimatorTest, StopAnimatingProperty) {
- scoped_refptr<LayerAnimator> animator(
- LayerAnimator::CreateImplicitAnimator());
- animator->set_disable_timer_for_test(true);
TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateImplicitTestAnimator(&delegate));
double target_opacity(0.5);
gfx::Rect target_bounds(0, 0, 50, 50);
animator->SetOpacity(target_opacity);
@@ -232,14 +272,12 @@ TEST(LayerAnimatorTest, StopAnimatingProperty) {
CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds);
}
-// Checks that multiple running animation for separate properties can be stopped
-// simultaneously and that all animations are advanced to their target values.
+// Checks that multiple running animations for separate properties can be
+// stopped simultaneously and that all animations are advanced to their target
+// values.
TEST(LayerAnimatorTest, StopAnimating) {
- scoped_refptr<LayerAnimator> animator(
- LayerAnimator::CreateImplicitAnimator());
- animator->set_disable_timer_for_test(true);
TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateImplicitTestAnimator(&delegate));
double target_opacity(0.5);
gfx::Rect target_bounds(0, 0, 50, 50);
animator->SetOpacity(target_opacity);
@@ -251,18 +289,16 @@ TEST(LayerAnimatorTest, StopAnimating) {
CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds);
}
-// Checks that multiple running animation for separate properties can be stopped
-// simultaneously and that all animations are advanced to their target values.
+// Checks that multiple running animations for separate properties can be
+// stopped simultaneously and that aborted animations are NOT advanced to their
+// target values.
TEST(LayerAnimatorTest, AbortAllAnimations) {
- scoped_refptr<LayerAnimator> animator(
- LayerAnimator::CreateImplicitAnimator());
- animator->set_disable_timer_for_test(true);
TestLayerAnimationDelegate delegate;
double initial_opacity(1.0);
gfx::Rect initial_bounds(0, 0, 10, 10);
delegate.SetOpacityFromAnimation(initial_opacity);
delegate.SetBoundsFromAnimation(initial_bounds);
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateImplicitTestAnimator(&delegate));
double target_opacity(0.5);
gfx::Rect target_bounds(0, 0, 50, 50);
animator->SetOpacity(target_opacity);
@@ -277,10 +313,8 @@ TEST(LayerAnimatorTest, AbortAllAnimations) {
// Schedule a non-threaded animation that can run immediately. This is the
// trivial case and should result in the animation being started immediately.
TEST(LayerAnimatorTest, ScheduleAnimationThatCanRunImmediately) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_disable_timer_for_test(true);
TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
double start_brightness(0.0);
double middle_brightness(0.5);
@@ -314,12 +348,10 @@ TEST(LayerAnimatorTest, ScheduleAnimationThatCanRunImmediately) {
// Schedule a threaded animation that can run immediately.
TEST(LayerAnimatorTest, ScheduleThreadedAnimationThatCanRunImmediately) {
double epsilon = 0.00001;
+ TestLayerAnimationDelegate delegate;
LayerAnimatorTestController test_controller(
- LayerAnimator::CreateDefaultAnimator());
+ CreateDefaultTestAnimator(&delegate));
LayerAnimator* animator = test_controller.animator();
- test_controller.animator()->set_disable_timer_for_test(true);
- TestLayerAnimationDelegate delegate;
- test_controller.animator()->SetDelegate(&delegate);
double start_opacity(0.0);
double target_opacity(1.0);
@@ -362,10 +394,8 @@ TEST(LayerAnimatorTest, ScheduleThreadedAnimationThatCanRunImmediately) {
// Schedule two non-threaded animations on separate properties. Both animations
// should start immediately and should progress in lock step.
TEST(LayerAnimatorTest, ScheduleTwoAnimationsThatCanRunImmediately) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_disable_timer_for_test(true);
TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
double start_brightness(0.0);
double middle_brightness(0.5);
@@ -413,12 +443,10 @@ TEST(LayerAnimatorTest, ScheduleTwoAnimationsThatCanRunImmediately) {
// animations should progress in lock step.
TEST(LayerAnimatorTest, ScheduleThreadedAndNonThreadedAnimations) {
double epsilon = 0.00001;
+ TestLayerAnimationDelegate delegate;
LayerAnimatorTestController test_controller(
- LayerAnimator::CreateDefaultAnimator());
+ CreateDefaultTestAnimator(&delegate));
LayerAnimator* animator = test_controller.animator();
- test_controller.animator()->set_disable_timer_for_test(true);
- TestLayerAnimationDelegate delegate;
- test_controller.animator()->SetDelegate(&delegate);
double start_opacity(0.0);
double target_opacity(1.0);
@@ -477,10 +505,8 @@ TEST(LayerAnimatorTest, ScheduleThreadedAndNonThreadedAnimations) {
// Schedule two animations on the same property. In this case, the two
// animations should run one after another.
TEST(LayerAnimatorTest, ScheduleTwoAnimationsOnSameProperty) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_disable_timer_for_test(true);
TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
double start_brightness(0.0);
double middle_brightness(0.5);
@@ -530,10 +556,8 @@ TEST(LayerAnimatorTest, ScheduleTwoAnimationsOnSameProperty) {
// is, ensure that all animations targetting a particular property are run in
// order.
TEST(LayerAnimatorTest, ScheduleBlockedAnimation) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_disable_timer_for_test(true);
TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
double start_grayscale(0.0);
double middle_grayscale(0.5);
@@ -609,10 +633,8 @@ TEST(LayerAnimatorTest, ScheduleBlockedAnimation) {
// ScheduleTogether is being used, the bounds animation should not start until
// the second grayscale animation starts.
TEST(LayerAnimatorTest, ScheduleTogether) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_disable_timer_for_test(true);
TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
double start_grayscale(0.0);
double target_grayscale(1.0);
@@ -662,10 +684,8 @@ TEST(LayerAnimatorTest, ScheduleTogether) {
// Start non-threaded animation (that can run immediately). This is the trivial
// case (see the trival case for ScheduleAnimation).
TEST(LayerAnimatorTest, StartAnimationThatCanRunImmediately) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_disable_timer_for_test(true);
TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
double start_brightness(0.0);
double middle_brightness(0.5);
@@ -699,12 +719,10 @@ TEST(LayerAnimatorTest, StartAnimationThatCanRunImmediately) {
// Start threaded animation (that can run immediately).
TEST(LayerAnimatorTest, StartThreadedAnimationThatCanRunImmediately) {
double epsilon = 0.00001;
+ TestLayerAnimationDelegate delegate;
LayerAnimatorTestController test_controller(
- LayerAnimator::CreateDefaultAnimator());
+ CreateDefaultTestAnimator(&delegate));
LayerAnimator* animator = test_controller.animator();
- test_controller.animator()->set_disable_timer_for_test(true);
- TestLayerAnimationDelegate delegate;
- test_controller.animator()->SetDelegate(&delegate);
double start_opacity(0.0);
double target_opacity(1.0);
@@ -745,10 +763,8 @@ TEST(LayerAnimatorTest, StartThreadedAnimationThatCanRunImmediately) {
// Preempt by immediately setting new target.
TEST(LayerAnimatorTest, PreemptBySettingNewTarget) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_disable_timer_for_test(true);
TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
double start_opacity(0.0);
double target_opacity(1.0);
@@ -773,10 +789,8 @@ TEST(LayerAnimatorTest, PreemptBySettingNewTarget) {
// Preempt by animating to new target, with a non-threaded animation.
TEST(LayerAnimatorTest, PreemptByImmediatelyAnimatingToNewTarget) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_disable_timer_for_test(true);
TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
double start_brightness(0.0);
double middle_brightness(0.5);
@@ -828,12 +842,10 @@ TEST(LayerAnimatorTest, PreemptByImmediatelyAnimatingToNewTarget) {
// Preempt by animating to new target, with a threaded animation.
TEST(LayerAnimatorTest, PreemptThreadedByImmediatelyAnimatingToNewTarget) {
double epsilon = 0.00001;
+ TestLayerAnimationDelegate delegate;
LayerAnimatorTestController test_controller(
- LayerAnimator::CreateDefaultAnimator());
+ CreateDefaultTestAnimator(&delegate));
LayerAnimator* animator = test_controller.animator();
- test_controller.animator()->set_disable_timer_for_test(true);
- TestLayerAnimationDelegate delegate;
- test_controller.animator()->SetDelegate(&delegate);
double start_opacity(0.0);
double middle_opacity(0.5);
@@ -899,10 +911,8 @@ TEST(LayerAnimatorTest, PreemptThreadedByImmediatelyAnimatingToNewTarget) {
// Preempt by enqueuing the new animation.
TEST(LayerAnimatorTest, PreemptEnqueueNewAnimation) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_disable_timer_for_test(true);
TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
double start_brightness(0.0);
double middle_brightness(0.5);
@@ -953,10 +963,8 @@ TEST(LayerAnimatorTest, PreemptEnqueueNewAnimation) {
// case, all pending and running animations should be finished, and the new
// animation started.
TEST(LayerAnimatorTest, PreemptyByReplacingQueuedAnimations) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_disable_timer_for_test(true);
TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
double start_brightness(0.0);
double middle_brightness(0.5);
@@ -1009,10 +1017,8 @@ TEST(LayerAnimatorTest, PreemptyByReplacingQueuedAnimations) {
}
TEST(LayerAnimatorTest, StartTogetherSetsLastStepTime) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_disable_timer_for_test(true);
TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
double start_grayscale(0.0);
double target_grayscale(1.0);
@@ -1048,10 +1054,8 @@ TEST(LayerAnimatorTest, StartTogetherSetsLastStepTime) {
//-------------------------------------------------------
// Preempt by immediately setting new target.
TEST(LayerAnimatorTest, MultiPreemptBySettingNewTarget) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_disable_timer_for_test(true);
TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
double start_opacity(0.0);
double target_opacity(1.0);
@@ -1086,10 +1090,8 @@ TEST(LayerAnimatorTest, MultiPreemptBySettingNewTarget) {
// Preempt by animating to new target.
TEST(LayerAnimatorTest, MultiPreemptByImmediatelyAnimatingToNewTarget) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_disable_timer_for_test(true);
TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
double start_grayscale(0.0);
double middle_grayscale(0.5);
@@ -1155,12 +1157,10 @@ TEST(LayerAnimatorTest, MultiPreemptByImmediatelyAnimatingToNewTarget) {
// Preempt a threaded animation by animating to new target.
TEST(LayerAnimatorTest, MultiPreemptThreadedByImmediatelyAnimatingToNewTarget) {
double epsilon = 0.00001;
+ TestLayerAnimationDelegate delegate;
LayerAnimatorTestController test_controller(
- LayerAnimator::CreateDefaultAnimator());
+ CreateDefaultTestAnimator(&delegate));
LayerAnimator* animator = test_controller.animator();
- test_controller.animator()->set_disable_timer_for_test(true);
- TestLayerAnimationDelegate delegate;
- test_controller.animator()->SetDelegate(&delegate);
double start_opacity(0.0);
double middle_opacity(0.5);
@@ -1243,10 +1243,8 @@ TEST(LayerAnimatorTest, MultiPreemptThreadedByImmediatelyAnimatingToNewTarget) {
// Preempt by enqueuing the new animation.
TEST(LayerAnimatorTest, MultiPreemptEnqueueNewAnimation) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_disable_timer_for_test(true);
TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
double start_grayscale(0.0);
double middle_grayscale(0.5);
@@ -1309,10 +1307,8 @@ TEST(LayerAnimatorTest, MultiPreemptEnqueueNewAnimation) {
// case, all pending and running animations should be finished, and the new
// animation started.
TEST(LayerAnimatorTest, MultiPreemptByReplacingQueuedAnimations) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_disable_timer_for_test(true);
TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
double start_grayscale(0.0);
double middle_grayscale(0.5);
@@ -1380,10 +1376,8 @@ TEST(LayerAnimatorTest, MultiPreemptByReplacingQueuedAnimations) {
//-------------------------------------------------------
// Test that non-threaded cyclic sequences continue to animate.
TEST(LayerAnimatorTest, CyclicSequences) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_disable_timer_for_test(true);
TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
double start_brightness(0.0);
double target_brightness(1.0);
@@ -1440,12 +1434,10 @@ TEST(LayerAnimatorTest, CyclicSequences) {
// Test that threaded cyclic sequences continue to animate.
TEST(LayerAnimatorTest, ThreadedCyclicSequences) {
+ TestLayerAnimationDelegate delegate;
LayerAnimatorTestController test_controller(
- LayerAnimator::CreateDefaultAnimator());
+ CreateDefaultTestAnimator(&delegate));
LayerAnimator* animator = test_controller.animator();
- test_controller.animator()->set_disable_timer_for_test(true);
- TestLayerAnimationDelegate delegate;
- test_controller.animator()->SetDelegate(&delegate);
double start_opacity(0.0);
double target_opacity(1.0);
@@ -1534,12 +1526,10 @@ TEST(LayerAnimatorTest, ThreadedCyclicSequences) {
}
TEST(LayerAnimatorTest, AddObserverExplicit) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_disable_timer_for_test(true);
TestLayerAnimationObserver observer;
TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
- animator->AddObserver(&observer);
+ scoped_refptr<LayerAnimator> animator(
+ CreateDefaultTestAnimator(&delegate, &observer));
observer.set_requires_notification_when_animator_destroyed(true);
EXPECT_TRUE(!observer.last_ended_sequence());
@@ -1575,11 +1565,9 @@ TEST(LayerAnimatorTest, AddObserverExplicit) {
// Tests that an observer added to a scoped settings object is still notified
// when the object goes out of scope.
TEST(LayerAnimatorTest, ImplicitAnimationObservers) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_disable_timer_for_test(true);
- TestImplicitAnimationObserver observer(false);
TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
+ TestImplicitAnimationObserver observer(false);
EXPECT_FALSE(observer.animations_completed());
animator->SetBrightness(1.0f);
@@ -1602,11 +1590,9 @@ TEST(LayerAnimatorTest, ImplicitAnimationObservers) {
// Tests that an observer added to a scoped settings object is still notified
// when the object goes out of scope due to the animation being interrupted.
TEST(LayerAnimatorTest, InterruptedImplicitAnimationObservers) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_disable_timer_for_test(true);
- TestImplicitAnimationObserver observer(false);
TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
+ TestImplicitAnimationObserver observer(false);
EXPECT_FALSE(observer.animations_completed());
animator->SetBrightness(1.0f);
@@ -1653,12 +1639,10 @@ TEST(LayerAnimatorTest, AnimatorKeptAliveBySettings) {
// Tests that an observer added to a scoped settings object is not notified
// when the animator is destroyed unless explicitly requested.
TEST(LayerAnimatorTest, ImplicitObserversAtAnimatorDestruction) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_disable_timer_for_test(true);
+ TestLayerAnimationDelegate delegate;
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
TestImplicitAnimationObserver observer_notify(true);
TestImplicitAnimationObserver observer_do_not_notify(false);
- TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
EXPECT_FALSE(observer_notify.animations_completed());
EXPECT_FALSE(observer_do_not_notify.animations_completed());
@@ -1682,11 +1666,9 @@ TEST(LayerAnimatorTest, ImplicitObserversAtAnimatorDestruction) {
}
TEST(LayerAnimatorTest, AbortedAnimationStatusInImplicitObservers) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_disable_timer_for_test(true);
- TestImplicitAnimationObserver observer(false);
TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
+ TestImplicitAnimationObserver observer(false);
EXPECT_FALSE(observer.animations_completed());
animator->SetBrightness(1.0f);
@@ -1722,12 +1704,10 @@ TEST(LayerAnimatorTest, AbortedAnimationStatusInImplicitObservers) {
}
TEST(LayerAnimatorTest, RemoveObserverShouldRemoveFromSequences) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_disable_timer_for_test(true);
+ TestLayerAnimationDelegate delegate;
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
TestLayerAnimationObserver observer;
TestLayerAnimationObserver removed_observer;
- TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
@@ -1757,13 +1737,10 @@ TEST(LayerAnimatorTest, RemoveObserverShouldRemoveFromSequences) {
TEST(LayerAnimatorTest, ObserverReleasedBeforeAnimationSequenceEnds) {
TestLayerAnimationDelegate delegate;
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_disable_timer_for_test(true);
-
scoped_ptr<TestLayerAnimationObserver> observer(
new TestLayerAnimationObserver);
- animator->SetDelegate(&delegate);
- animator->AddObserver(observer.get());
+ scoped_refptr<LayerAnimator> animator(
+ CreateDefaultTestAnimator(&delegate, observer.get()));
delegate.SetOpacityFromAnimation(0.0f);
@@ -1784,12 +1761,10 @@ TEST(LayerAnimatorTest, ObserverReleasedBeforeAnimationSequenceEnds) {
}
TEST(LayerAnimatorTest, ObserverAttachedAfterAnimationStarted) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_disable_timer_for_test(true);
+ TestLayerAnimationDelegate delegate;
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
TestImplicitAnimationObserver observer(false);
- TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
delegate.SetBrightnessFromAnimation(0.0f);
@@ -1818,12 +1793,10 @@ TEST(LayerAnimatorTest, ObserverAttachedAfterAnimationStarted) {
}
TEST(LayerAnimatorTest, ObserverDetachedBeforeAnimationFinished) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_disable_timer_for_test(true);
+ TestLayerAnimationDelegate delegate;
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
TestImplicitAnimationObserver observer(false);
- TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
delegate.SetBrightnessFromAnimation(0.0f);
base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
@@ -2017,10 +1990,8 @@ TEST(LayerAnimatorTest, ObserverDeletesAnimationsOnAbort) {
// Check that setting a property during an animation with a default animator
// cancels the original animation.
TEST(LayerAnimatorTest, SettingPropertyDuringAnAnimation) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_disable_timer_for_test(true);
TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
double start_opacity(0.0);
double target_opacity(1.0);
@@ -2044,11 +2015,9 @@ TEST(LayerAnimatorTest, SettingPropertyDuringAnAnimation) {
// Tests that the preemption mode IMMEDIATELY_SET_NEW_TARGET, doesn't cause the
// second sequence to be leaked.
TEST(LayerAnimatorTest, ImmediatelySettingNewTargetDoesNotLeak) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_preemption_strategy(LayerAnimator::IMMEDIATELY_SET_NEW_TARGET);
- animator->set_disable_timer_for_test(true);
TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
+ animator->set_preemption_strategy(LayerAnimator::IMMEDIATELY_SET_NEW_TARGET);
gfx::Rect start_bounds(0, 0, 50, 50);
gfx::Rect middle_bounds(10, 10, 100, 100);
@@ -2085,10 +2054,8 @@ TEST(LayerAnimatorTest, ImmediatelySettingNewTargetDoesNotLeak) {
// Verifies GetTargetOpacity() works when multiple sequences are scheduled.
TEST(LayerAnimatorTest, GetTargetOpacity) {
TestLayerAnimationDelegate delegate;
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION);
- animator->set_disable_timer_for_test(true);
- animator->SetDelegate(&delegate);
delegate.SetOpacityFromAnimation(0.0);
@@ -2105,11 +2072,9 @@ TEST(LayerAnimatorTest, GetTargetOpacity) {
// Verifies GetTargetBrightness() works when multiple sequences are scheduled.
TEST(LayerAnimatorTest, GetTargetBrightness) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION);
- animator->set_disable_timer_for_test(true);
TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
+ animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION);
delegate.SetBrightnessFromAnimation(0.0);
@@ -2126,11 +2091,9 @@ TEST(LayerAnimatorTest, GetTargetBrightness) {
// Verifies GetTargetGrayscale() works when multiple sequences are scheduled.
TEST(LayerAnimatorTest, GetTargetGrayscale) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION);
- animator->set_disable_timer_for_test(true);
TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
+ animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION);
delegate.SetGrayscaleFromAnimation(0.0);
@@ -2147,10 +2110,8 @@ TEST(LayerAnimatorTest, GetTargetGrayscale) {
// Verifies color property is modified appropriately.
TEST(LayerAnimatorTest, Color) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_disable_timer_for_test(true);
TestLayerAnimationDelegate delegate;
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
SkColor start_color = SkColorSetARGB( 64, 20, 40, 60);
SkColor middle_color = SkColorSetARGB(128, 35, 70, 120);
@@ -2185,7 +2146,7 @@ TEST(LayerAnimatorTest, Color) {
// Verifies SchedulePauseForProperties().
TEST(LayerAnimatorTest, SchedulePauseForProperties) {
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator());
animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION);
animator->SchedulePauseForProperties(
base::TimeDelta::FromMilliseconds(100),
@@ -2198,9 +2159,7 @@ TEST(LayerAnimatorTest, SchedulePauseForProperties) {
class AnimatorOwner {
public:
- AnimatorOwner()
- : animator_(LayerAnimator::CreateDefaultAnimator()) {
- }
+ AnimatorOwner() : animator_(CreateDefaultTestAnimator()) {}
LayerAnimator* animator() { return animator_.get(); }
@@ -2281,7 +2240,6 @@ TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterFinishingAnimation) {
observer->set_delete_on_animation_ended(true);
observer->set_delete_on_animation_aborted(true);
LayerAnimator* animator = observer->animator();
- animator->set_disable_timer_for_test(true);
TestLayerAnimationDelegate delegate;
animator->SetDelegate(&delegate);
@@ -2314,7 +2272,6 @@ TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterStoppingAnimating) {
observer->set_delete_on_animation_ended(true);
observer->set_delete_on_animation_aborted(true);
LayerAnimator* animator = observer->animator();
- animator->set_disable_timer_for_test(true);
TestLayerAnimationDelegate delegate;
animator->SetDelegate(&delegate);
@@ -2346,7 +2303,6 @@ TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterScheduling) {
DeletingObserver* observer = new DeletingObserver(&observer_was_deleted);
observer->set_delete_on_animation_scheduled(true);
LayerAnimator* animator = observer->animator();
- animator->set_disable_timer_for_test(true);
animator->SetDelegate(&delegate);
delegate.SetOpacityFromAnimation(0.0f);
@@ -2379,7 +2335,6 @@ TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterAborted) {
LayerAnimator* animator = observer->animator();
animator->set_preemption_strategy(
LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
- animator->set_disable_timer_for_test(true);
animator->SetDelegate(&delegate);
delegate.SetOpacityFromAnimation(0.0f);
@@ -2412,10 +2367,7 @@ TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterAborted) {
TEST(LayerAnimatorTest, TestSetterRespectEnqueueStrategy) {
TestLayerAnimationDelegate delegate;
- scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
- animator->set_disable_timer_for_test(true);
-
- animator->SetDelegate(&delegate);
+ scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
float start_opacity = 0.0f;
float target_opacity = 1.0f;
@@ -2618,9 +2570,7 @@ class LayerOwnerAnimationObserver : public LayerAnimationObserver {
};
TEST(LayerAnimatorTest, ObserverDeletesLayerInStopAnimating) {
- scoped_refptr<LayerAnimator> animator(
- LayerAnimator::CreateImplicitAnimator());
- animator->set_disable_timer_for_test(true);
+ scoped_refptr<LayerAnimator> animator(CreateImplicitTestAnimator());
LayerOwnerAnimationObserver observer(animator.get());
LayerAnimationDelegate* delegate = observer.animator_layer();
@@ -2649,4 +2599,206 @@ TEST(LayerAnimatorTest, ObserverDeletesLayerInStopAnimating) {
EXPECT_TRUE(animator->is_animating());
}
+// Verifies the LayerAnimatorObserver notification order for an animation
+// sequence that completes successfully.
+TEST(LayerAnimatorObserverNotificationOrderTest,
+ SuccessfulCompletionOfSequence) {
+ TestLayerAnimationObserver observer;
+ TestLayerAnimationDelegate delegate;
+ scoped_refptr<LayerAnimator> animator(
+ CreateDefaultTestAnimator(&delegate, &observer));
+ observer.set_requires_notification_when_animator_destroyed(true);
+
+ const base::TimeDelta animation_duration = base::TimeDelta::FromSeconds(100);
+
+ LayerAnimationSequence* sequence = new LayerAnimationSequence(
+ LayerAnimationElement::CreateBrightnessElement(1.0f, animation_duration));
+
+ EXPECT_TRUE(observer.NoEventsObserved());
+
+ animator->StartAnimation(sequence);
+
+ EXPECT_EQ(observer.last_attached_sequence(), sequence);
+ EXPECT_EQ(observer.last_scheduled_sequence(), sequence);
+ EXPECT_EQ(observer.last_started_sequence(), sequence);
+ EXPECT_EQ(observer.last_aborted_sequence(), nullptr);
+ EXPECT_EQ(observer.last_ended_sequence(), nullptr);
+ EXPECT_EQ(observer.last_detached_sequence(), nullptr);
+
+ EXPECT_TRUE(observer.AttachedEpochIsBeforeScheduledEpoch());
+ EXPECT_TRUE(observer.ScheduledEpochIsBeforeStartedEpoch());
+
+ observer.ResetLayerAnimationObserverations();
+
+ const base::TimeTicks start_time = animator->last_step_time();
+
+ animator->Step(start_time + animation_duration);
+
+ EXPECT_EQ(observer.last_attached_sequence(), nullptr);
+ EXPECT_EQ(observer.last_scheduled_sequence(), nullptr);
+ EXPECT_EQ(observer.last_started_sequence(), nullptr);
+ EXPECT_EQ(observer.last_aborted_sequence(), nullptr);
+ EXPECT_EQ(observer.last_ended_sequence(), sequence);
+ EXPECT_EQ(observer.last_detached_sequence(), sequence);
+
+ EXPECT_TRUE(observer.EndedEpochIsBeforeDetachedEpoch());
+}
+
+// Verifies the LayerAnimatorObserver notification order for an animation
+// sequence that is aborted after being scheduled.
+TEST(LayerAnimatorObserverNotificationOrderTest, AbortingAScheduledSequence) {
+ TestLayerAnimationObserver observer;
+ TestLayerAnimationDelegate delegate;
+ scoped_refptr<LayerAnimator> animator(
+ CreateDefaultTestAnimator(&delegate, &observer));
+ observer.set_requires_notification_when_animator_destroyed(true);
+
+ const base::TimeDelta animation_duration = base::TimeDelta::FromSeconds(100);
+
+ LayerAnimationSequence* sequence = new LayerAnimationSequence(
+ LayerAnimationElement::CreateBrightnessElement(1.0f, animation_duration));
+
+ EXPECT_TRUE(observer.NoEventsObserved());
+
+ animator->StartAnimation(sequence);
+
+ EXPECT_EQ(observer.last_attached_sequence(), sequence);
+ EXPECT_EQ(observer.last_scheduled_sequence(), sequence);
+ EXPECT_EQ(observer.last_started_sequence(), sequence);
+ EXPECT_EQ(observer.last_aborted_sequence(), nullptr);
+ EXPECT_EQ(observer.last_ended_sequence(), nullptr);
+ EXPECT_EQ(observer.last_detached_sequence(), nullptr);
+
+ EXPECT_TRUE(observer.AttachedEpochIsBeforeScheduledEpoch());
+ EXPECT_TRUE(observer.ScheduledEpochIsBeforeStartedEpoch());
+
+ observer.ResetLayerAnimationObserverations();
+
+ animator->AbortAllAnimations();
+
+ EXPECT_EQ(observer.last_attached_sequence(), nullptr);
+ EXPECT_EQ(observer.last_scheduled_sequence(), nullptr);
+ EXPECT_EQ(observer.last_started_sequence(), nullptr);
+ EXPECT_EQ(observer.last_aborted_sequence(), sequence);
+ EXPECT_EQ(observer.last_ended_sequence(), nullptr);
+ EXPECT_EQ(observer.last_detached_sequence(), sequence);
+
+ EXPECT_TRUE(observer.AbortedEpochIsBeforeDetachedEpoch());
+}
+
+// Verifies the LayerAnimatorObserver notification order for an animation
+// sequence that is queued up after another sequence that
+// completes successfully.
+TEST(LayerAnimatorObserverNotificationOrderTest,
+ RunningASequenceThatIsQueuedForLaterStartTime) {
+ TestLayerAnimationObserver observer;
+ TestLayerAnimationDelegate delegate;
+ scoped_refptr<LayerAnimator> animator(
+ CreateDefaultTestAnimator(&delegate, &observer));
+ observer.set_requires_notification_when_animator_destroyed(true);
+
+ const base::TimeDelta animation_duration = base::TimeDelta::FromSeconds(100);
+
+ LayerAnimationSequence* first_sequence = new LayerAnimationSequence(
+ LayerAnimationElement::CreateBrightnessElement(1.0f, animation_duration));
+
+ LayerAnimationSequence* queued_sequence = new LayerAnimationSequence(
+ LayerAnimationElement::CreateBrightnessElement(1.0f, animation_duration));
+
+ EXPECT_TRUE(observer.NoEventsObserved());
+
+ animator->StartAnimation(first_sequence);
+
+ EXPECT_EQ(observer.last_attached_sequence(), first_sequence);
+ EXPECT_EQ(observer.last_scheduled_sequence(), first_sequence);
+ EXPECT_EQ(observer.last_started_sequence(), first_sequence);
+ EXPECT_EQ(observer.last_aborted_sequence(), nullptr);
+ EXPECT_EQ(observer.last_ended_sequence(), nullptr);
+ EXPECT_EQ(observer.last_detached_sequence(), nullptr);
+
+ EXPECT_TRUE(observer.AttachedEpochIsBeforeScheduledEpoch());
+ EXPECT_TRUE(observer.ScheduledEpochIsBeforeStartedEpoch());
+
+ observer.ResetLayerAnimationObserverations();
+
+ animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION);
+ animator->StartAnimation(queued_sequence);
+
+ EXPECT_EQ(observer.last_attached_sequence(), queued_sequence);
+ EXPECT_EQ(observer.last_scheduled_sequence(), queued_sequence);
+ EXPECT_EQ(observer.last_started_sequence(), nullptr);
+ EXPECT_EQ(observer.last_aborted_sequence(), nullptr);
+ EXPECT_EQ(observer.last_ended_sequence(), nullptr);
+ EXPECT_EQ(observer.last_detached_sequence(), nullptr);
+
+ EXPECT_TRUE(observer.AttachedEpochIsBeforeScheduledEpoch());
+
+ observer.ResetLayerAnimationObserverations();
+
+ base::TimeTicks start_time = animator->last_step_time();
+
+ animator->Step(start_time + animation_duration);
+
+ EXPECT_EQ(observer.last_attached_sequence(), nullptr);
+ EXPECT_EQ(observer.last_scheduled_sequence(), nullptr);
+ EXPECT_EQ(observer.last_started_sequence(), queued_sequence);
+ EXPECT_EQ(observer.last_aborted_sequence(), nullptr);
+ EXPECT_EQ(observer.last_ended_sequence(), first_sequence);
+ EXPECT_EQ(observer.last_detached_sequence(), first_sequence);
+
+ EXPECT_TRUE(observer.EndedEpochIsBeforeDetachedEpoch());
+ EXPECT_TRUE(observer.EndedEpochIsBeforeStartedEpoch());
+}
+
+// Verifies the LayerAnimatorObserver notification order for an animation
+// sequence that pre-empts another sequence.
+TEST(LayerAnimatorObserverNotificationOrderTest,
+ RunningASequenceThatPreEmptsAnotherSequence) {
+ TestLayerAnimationObserver observer;
+ TestLayerAnimationDelegate delegate;
+ scoped_refptr<LayerAnimator> animator(
+ CreateDefaultTestAnimator(&delegate, &observer));
+ observer.set_requires_notification_when_animator_destroyed(true);
+
+ const base::TimeDelta animation_duration = base::TimeDelta::FromSeconds(100);
+
+ LayerAnimationSequence* first_sequence = new LayerAnimationSequence(
+ LayerAnimationElement::CreateBrightnessElement(1.0f, animation_duration));
+
+ LayerAnimationSequence* queued_sequence = new LayerAnimationSequence(
+ LayerAnimationElement::CreateBrightnessElement(1.0f, animation_duration));
+
+ EXPECT_TRUE(observer.NoEventsObserved());
+
+ animator->StartAnimation(first_sequence);
+
+ EXPECT_EQ(observer.last_attached_sequence(), first_sequence);
+ EXPECT_EQ(observer.last_scheduled_sequence(), first_sequence);
+ EXPECT_EQ(observer.last_started_sequence(), first_sequence);
+ EXPECT_EQ(observer.last_aborted_sequence(), nullptr);
+ EXPECT_EQ(observer.last_ended_sequence(), nullptr);
+ EXPECT_EQ(observer.last_detached_sequence(), nullptr);
+
+ EXPECT_TRUE(observer.AttachedEpochIsBeforeScheduledEpoch());
+ EXPECT_TRUE(observer.ScheduledEpochIsBeforeStartedEpoch());
+
+ observer.ResetLayerAnimationObserverations();
+
+ animator->set_preemption_strategy(
+ LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
+ animator->StartAnimation(queued_sequence);
+
+ EXPECT_EQ(observer.last_attached_sequence(), queued_sequence);
+ EXPECT_EQ(observer.last_scheduled_sequence(), queued_sequence);
+ EXPECT_EQ(observer.last_started_sequence(), queued_sequence);
+ EXPECT_EQ(observer.last_aborted_sequence(), first_sequence);
+ EXPECT_EQ(observer.last_ended_sequence(), nullptr);
+ EXPECT_EQ(observer.last_detached_sequence(), first_sequence);
+
+ EXPECT_TRUE(observer.AbortedEpochIsBeforeDetachedEpoch());
+ EXPECT_TRUE(observer.AbortedEpochIsBeforeStartedEpoch());
+ EXPECT_TRUE(observer.AttachedEpochIsBeforeScheduledEpoch());
+ EXPECT_TRUE(observer.ScheduledEpochIsBeforeStartedEpoch());
+}
+
} // namespace ui
diff --git a/ui/compositor/test/test_layer_animation_observer.cc b/ui/compositor/test/test_layer_animation_observer.cc
index abc74ae..838b7f2 100644
--- a/ui/compositor/test/test_layer_animation_observer.cc
+++ b/ui/compositor/test/test_layer_animation_observer.cc
@@ -9,28 +9,74 @@
namespace ui {
TestLayerAnimationObserver::TestLayerAnimationObserver()
- : last_ended_sequence_(NULL),
- last_scheduled_sequence_(NULL),
- last_aborted_sequence_(NULL),
- requires_notification_when_animator_destroyed_(false) {
-}
+ : next_epoch_(0),
+ last_attached_sequence_(nullptr),
+ last_attached_sequence_epoch_(-1),
+ last_scheduled_sequence_(nullptr),
+ last_scheduled_sequence_epoch_(-1),
+ last_started_sequence_(nullptr),
+ last_started_sequence_epoch_(-1),
+ last_aborted_sequence_(nullptr),
+ last_aborted_sequence_epoch_(-1),
+ last_ended_sequence_(nullptr),
+ last_ended_sequence_epoch_(-1),
+ last_detached_sequence_(nullptr),
+ last_detached_sequence_epoch_(-1),
+ requires_notification_when_animator_destroyed_(false) {}
TestLayerAnimationObserver::~TestLayerAnimationObserver() {
}
-void TestLayerAnimationObserver::OnLayerAnimationEnded(
+void TestLayerAnimationObserver::ResetLayerAnimationObserverations() {
+ next_epoch_ = 0;
+ last_attached_sequence_ = nullptr;
+ last_attached_sequence_epoch_ = -1;
+ last_scheduled_sequence_ = nullptr;
+ last_scheduled_sequence_epoch_ = -1;
+ last_started_sequence_ = nullptr;
+ last_started_sequence_epoch_ = -1;
+ last_aborted_sequence_ = nullptr;
+ last_aborted_sequence_epoch_ = -1;
+ last_ended_sequence_ = nullptr;
+ last_ended_sequence_epoch_ = -1;
+ last_detached_sequence_ = nullptr;
+ last_detached_sequence_epoch_ = -1;
+}
+
+void TestLayerAnimationObserver::OnAttachedToSequence(
LayerAnimationSequence* sequence) {
- last_ended_sequence_ = sequence;
+ last_attached_sequence_ = sequence;
+ last_attached_sequence_epoch_ = next_epoch_++;
+}
+
+void TestLayerAnimationObserver::OnLayerAnimationScheduled(
+ LayerAnimationSequence* sequence) {
+ last_scheduled_sequence_ = sequence;
+ last_scheduled_sequence_epoch_ = next_epoch_++;
+}
+
+void TestLayerAnimationObserver::OnLayerAnimationStarted(
+ LayerAnimationSequence* sequence) {
+ last_started_sequence_ = sequence;
+ last_started_sequence_epoch_ = next_epoch_++;
}
void TestLayerAnimationObserver::OnLayerAnimationAborted(
LayerAnimationSequence* sequence) {
last_aborted_sequence_ = sequence;
+ last_aborted_sequence_epoch_ = next_epoch_++;
}
-void TestLayerAnimationObserver::OnLayerAnimationScheduled(
+void TestLayerAnimationObserver::OnLayerAnimationEnded(
LayerAnimationSequence* sequence) {
- last_scheduled_sequence_ = sequence;
+ last_ended_sequence_ = sequence;
+ last_ended_sequence_epoch_ = next_epoch_++;
+}
+
+void TestLayerAnimationObserver::OnDetachedFromSequence(
+ LayerAnimationSequence* sequence) {
+ last_detached_sequence_ = sequence;
+ last_detached_sequence_epoch_ = next_epoch_++;
}
bool
@@ -38,4 +84,134 @@ TestLayerAnimationObserver::RequiresNotificationWhenAnimatorDestroyed() const {
return requires_notification_when_animator_destroyed_;
}
+testing::AssertionResult TestLayerAnimationObserver::NoEventsObserved() {
+ if (!last_attached_sequence_ && !last_scheduled_sequence_ &&
+ !last_started_sequence_ && !last_aborted_sequence_ &&
+ !last_ended_sequence_ && !last_detached_sequence_) {
+ return testing::AssertionSuccess();
+ } else {
+ testing::AssertionResult assertion_failure = testing::AssertionFailure();
+ assertion_failure << "The following events have been observed:";
+ if (last_attached_sequence_) {
+ assertion_failure << "\n\tlast_attached_sequence_="
+ << last_attached_sequence_;
+ }
+ if (last_scheduled_sequence_) {
+ assertion_failure << "\n\tlast_scheduled_sequence_="
+ << last_scheduled_sequence_;
+ }
+ if (last_started_sequence_) {
+ assertion_failure << "\n\tlast_started_sequence_="
+ << last_started_sequence_;
+ }
+ if (last_aborted_sequence_) {
+ assertion_failure << "\n\tlast_aborted_sequence_="
+ << last_aborted_sequence_;
+ }
+ if (last_ended_sequence_) {
+ assertion_failure << "\n\tlast_ended_sequence_" << last_ended_sequence_;
+ }
+ if (last_detached_sequence_) {
+ assertion_failure << "\n\tlast_detached_sequence_="
+ << last_detached_sequence_;
+ }
+ return assertion_failure;
+ }
+}
+
+testing::AssertionResult
+TestLayerAnimationObserver::AttachedEpochIsBeforeScheduledEpoch() {
+ if (last_attached_sequence_epoch_ < last_scheduled_sequence_epoch_) {
+ return testing::AssertionSuccess();
+ } else {
+ return testing::AssertionFailure()
+ << "The attached epoch=" << last_attached_sequence_epoch_
+ << " is NOT before the scheduled epoch="
+ << last_scheduled_sequence_epoch_;
+ }
+}
+
+testing::AssertionResult
+TestLayerAnimationObserver::ScheduledEpochIsBeforeStartedEpoch() {
+ if (last_scheduled_sequence_epoch_ < last_started_sequence_epoch_) {
+ return testing::AssertionSuccess();
+ } else {
+ return testing::AssertionFailure()
+ << "The scheduled epoch=" << last_scheduled_sequence_epoch_
+ << " is NOT before the started epoch="
+ << last_started_sequence_epoch_;
+ }
+}
+
+testing::AssertionResult
+TestLayerAnimationObserver::StartedEpochIsBeforeEndedEpoch() {
+ if (last_started_sequence_epoch_ < last_ended_sequence_epoch_) {
+ return testing::AssertionSuccess();
+ } else {
+ return testing::AssertionFailure()
+ << "The started epoch=" << last_started_sequence_epoch_
+ << " is NOT before the ended epoch=" << last_ended_sequence_epoch_;
+ }
+}
+
+testing::AssertionResult
+TestLayerAnimationObserver::StartedEpochIsBeforeAbortedEpoch() {
+ if (last_started_sequence_epoch_ < last_aborted_sequence_epoch_) {
+ return testing::AssertionSuccess();
+ } else {
+ return testing::AssertionFailure()
+ << "The started epoch=" << last_started_sequence_epoch_
+ << " is NOT before the aborted epoch="
+ << last_aborted_sequence_epoch_;
+ }
+}
+
+testing::AssertionResult
+TestLayerAnimationObserver::AbortedEpochIsBeforeStartedEpoch() {
+ if (last_aborted_sequence_epoch_ < last_started_sequence_epoch_) {
+ return testing::AssertionSuccess();
+ } else {
+ return testing::AssertionFailure()
+ << "The aborted epoch=" << last_aborted_sequence_epoch_
+ << " is NOT before the started epoch="
+ << last_started_sequence_epoch_;
+ }
+}
+
+testing::AssertionResult
+TestLayerAnimationObserver::AbortedEpochIsBeforeDetachedEpoch() {
+ if (last_aborted_sequence_epoch_ < last_detached_sequence_epoch_) {
+ return testing::AssertionSuccess();
+ } else {
+ return testing::AssertionFailure()
+ << "The aborted epoch=" << last_aborted_sequence_epoch_
+ << " is NOT before the detached epoch="
+ << last_detached_sequence_epoch_;
+ }
+}
+
+testing::AssertionResult
+TestLayerAnimationObserver::EndedEpochIsBeforeStartedEpoch() {
+ if (last_ended_sequence_epoch_ < last_started_sequence_epoch_) {
+ return testing::AssertionSuccess();
+ } else {
+ return testing::AssertionFailure()
+ << "The ended epoch=" << last_ended_sequence_epoch_
+ << " is NOT before the started epoch="
+ << last_started_sequence_epoch_;
+ }
+}
+
+testing::AssertionResult
+TestLayerAnimationObserver::EndedEpochIsBeforeDetachedEpoch() {
+ if (last_ended_sequence_epoch_ < last_detached_sequence_epoch_) {
+ return testing::AssertionSuccess();
+ } else {
+ return testing::AssertionFailure()
+ << "The ended epoch=" << last_ended_sequence_epoch_
+ << " is NOT before the detached epoch="
+ << last_detached_sequence_epoch_;
+ }
+}
+
} // namespace ui
diff --git a/ui/compositor/test/test_layer_animation_observer.h b/ui/compositor/test/test_layer_animation_observer.h
index 0f0a18e..6860b17 100644
--- a/ui/compositor/test/test_layer_animation_observer.h
+++ b/ui/compositor/test/test_layer_animation_observer.h
@@ -6,6 +6,7 @@
#define UI_COMPOSITOR_TEST_TEST_LAYER_ANIMATION_OBSERVER_H_
#include "base/compiler_specific.h"
+#include "testing/gtest/include/gtest/gtest.h"
#include "ui/compositor/layer_animation_observer.h"
namespace ui {
@@ -19,34 +20,110 @@ class TestLayerAnimationObserver : public LayerAnimationObserver {
TestLayerAnimationObserver();
~TestLayerAnimationObserver() override;
- void OnLayerAnimationEnded(LayerAnimationSequence* sequence) override;
-
- void OnLayerAnimationAborted(LayerAnimationSequence* sequence) override;
+ // Resets all the data tracking LayerAnimationObserver observations.
+ void ResetLayerAnimationObserverations();
+ // LayerAnimationObserver:
void OnLayerAnimationScheduled(LayerAnimationSequence* sequence) override;
-
+ void OnLayerAnimationStarted(LayerAnimationSequence* sequence) override;
+ void OnLayerAnimationAborted(LayerAnimationSequence* sequence) override;
+ void OnLayerAnimationEnded(LayerAnimationSequence* sequence) override;
bool RequiresNotificationWhenAnimatorDestroyed() const override;
- const LayerAnimationSequence* last_ended_sequence() const {
- return last_ended_sequence_;
+ const LayerAnimationSequence* last_attached_sequence() const {
+ return last_attached_sequence_;
+ }
+
+ int last_attached_sequence_epoch() const {
+ return last_attached_sequence_epoch_;
}
const LayerAnimationSequence* last_scheduled_sequence() const {
return last_scheduled_sequence_;
}
+ int last_scheduled_sequence_epoch() const {
+ return last_scheduled_sequence_epoch_;
+ }
+
+ const LayerAnimationSequence* last_started_sequence() const {
+ return last_started_sequence_;
+ }
+
+ int last_started_sequence_epoch() const {
+ return last_started_sequence_epoch_;
+ }
+
const LayerAnimationSequence* last_aborted_sequence() const {
return last_aborted_sequence_;
}
+ int last_aborted_sequence_epoch() const {
+ return last_aborted_sequence_epoch_;
+ }
+
+ const LayerAnimationSequence* last_ended_sequence() const {
+ return last_ended_sequence_;
+ }
+
+ int last_ended_sequence_epoch() const { return last_ended_sequence_epoch_; }
+
+ const LayerAnimationSequence* last_detached_sequence() const {
+ return last_detached_sequence_;
+ }
+
+ int last_detached_sequence_epoch() const {
+ return last_detached_sequence_epoch_;
+ }
+
void set_requires_notification_when_animator_destroyed(bool value) {
requires_notification_when_animator_destroyed_ = value;
}
+ testing::AssertionResult NoEventsObserved();
+
+ testing::AssertionResult AttachedEpochIsBeforeScheduledEpoch();
+
+ testing::AssertionResult ScheduledEpochIsBeforeStartedEpoch();
+
+ testing::AssertionResult StartedEpochIsBeforeEndedEpoch();
+
+ testing::AssertionResult StartedEpochIsBeforeAbortedEpoch();
+
+ testing::AssertionResult AbortedEpochIsBeforeStartedEpoch();
+
+ testing::AssertionResult AbortedEpochIsBeforeDetachedEpoch();
+
+ testing::AssertionResult EndedEpochIsBeforeStartedEpoch();
+
+ testing::AssertionResult EndedEpochIsBeforeDetachedEpoch();
+
+ protected:
+ // LayerAnimationObserver:
+ void OnAttachedToSequence(LayerAnimationSequence* sequence) override;
+ void OnDetachedFromSequence(LayerAnimationSequence* sequence) override;
+
private:
- const LayerAnimationSequence* last_ended_sequence_;
+ int next_epoch_;
+
+ const LayerAnimationSequence* last_attached_sequence_;
+ int last_attached_sequence_epoch_;
+
const LayerAnimationSequence* last_scheduled_sequence_;
+ int last_scheduled_sequence_epoch_;
+
+ const LayerAnimationSequence* last_started_sequence_;
+ int last_started_sequence_epoch_;
+
const LayerAnimationSequence* last_aborted_sequence_;
+ int last_aborted_sequence_epoch_;
+
+ const LayerAnimationSequence* last_ended_sequence_;
+ int last_ended_sequence_epoch_;
+
+ const LayerAnimationSequence* last_detached_sequence_;
+ int last_detached_sequence_epoch_;
+
bool requires_notification_when_animator_destroyed_;
// Copy and assign are allowed.