| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/compositor/layer_animator.h" | 5 #include "ui/compositor/layer_animator.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 private: | 71 private: |
| 72 LayerAnimator* animator_; | 72 LayerAnimator* animator_; |
| 73 LayerAnimationSequence* sequence_; | 73 LayerAnimationSequence* sequence_; |
| 74 | 74 |
| 75 DISALLOW_COPY_AND_ASSIGN(DeletingLayerAnimationObserver); | 75 DISALLOW_COPY_AND_ASSIGN(DeletingLayerAnimationObserver); |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 class TestLayerAnimator : public LayerAnimator { | 78 class TestLayerAnimator : public LayerAnimator { |
| 79 public: | 79 public: |
| 80 TestLayerAnimator() : LayerAnimator(base::TimeDelta::FromSeconds(0)) {} | 80 TestLayerAnimator() : LayerAnimator(base::TimeDelta::FromSeconds(0)) {} |
| 81 |
| 82 protected: |
| 81 virtual ~TestLayerAnimator() {} | 83 virtual ~TestLayerAnimator() {} |
| 82 | 84 |
| 83 protected: | 85 virtual void ProgressAnimation(LayerAnimationSequence* sequence, |
| 84 virtual bool ProgressAnimation(LayerAnimationSequence* sequence, | |
| 85 base::TimeDelta delta) OVERRIDE { | 86 base::TimeDelta delta) OVERRIDE { |
| 86 EXPECT_TRUE(HasAnimation(sequence)); | 87 EXPECT_TRUE(HasAnimation(sequence)); |
| 87 return LayerAnimator::ProgressAnimation(sequence, delta); | 88 LayerAnimator::ProgressAnimation(sequence, delta); |
| 88 } | 89 } |
| 89 | 90 |
| 90 private: | 91 private: |
| 91 DISALLOW_COPY_AND_ASSIGN(TestLayerAnimator); | 92 DISALLOW_COPY_AND_ASSIGN(TestLayerAnimator); |
| 92 }; | 93 }; |
| 93 | 94 |
| 94 // The test layer animation sequence updates a live instances count when it is | 95 // The test layer animation sequence updates a live instances count when it is |
| 95 // created and destroyed. | 96 // created and destroyed. |
| 96 class TestLayerAnimationSequence : public LayerAnimationSequence { | 97 class TestLayerAnimationSequence : public LayerAnimationSequence { |
| 97 public: | 98 public: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 110 int* num_live_instances_; | 111 int* num_live_instances_; |
| 111 | 112 |
| 112 DISALLOW_COPY_AND_ASSIGN(TestLayerAnimationSequence); | 113 DISALLOW_COPY_AND_ASSIGN(TestLayerAnimationSequence); |
| 113 }; | 114 }; |
| 114 | 115 |
| 115 } // namespace | 116 } // namespace |
| 116 | 117 |
| 117 // Checks that setting a property on an implicit animator causes an animation to | 118 // Checks that setting a property on an implicit animator causes an animation to |
| 118 // happen. | 119 // happen. |
| 119 TEST(LayerAnimatorTest, ImplicitAnimation) { | 120 TEST(LayerAnimatorTest, ImplicitAnimation) { |
| 120 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateImplicitAnimator()); | 121 scoped_refptr<LayerAnimator> animator( |
| 122 LayerAnimator::CreateImplicitAnimator()); |
| 121 AnimationContainerElement* element = animator.get(); | 123 AnimationContainerElement* element = animator.get(); |
| 122 animator->set_disable_timer_for_test(true); | 124 animator->set_disable_timer_for_test(true); |
| 123 TestLayerAnimationDelegate delegate; | 125 TestLayerAnimationDelegate delegate; |
| 124 animator->SetDelegate(&delegate); | 126 animator->SetDelegate(&delegate); |
| 125 base::TimeTicks now = base::TimeTicks::Now(); | 127 base::TimeTicks now = base::TimeTicks::Now(); |
| 126 animator->SetOpacity(0.5); | 128 animator->SetOpacity(0.5); |
| 127 EXPECT_TRUE(animator->is_animating()); | 129 EXPECT_TRUE(animator->is_animating()); |
| 128 element->Step(now + base::TimeDelta::FromSeconds(1)); | 130 element->Step(now + base::TimeDelta::FromSeconds(1)); |
| 129 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5); | 131 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5); |
| 130 } | 132 } |
| 131 | 133 |
| 132 // Checks that if the animator is a default animator, that implicit animations | 134 // Checks that if the animator is a default animator, that implicit animations |
| 133 // are not started. | 135 // are not started. |
| 134 TEST(LayerAnimatorTest, NoImplicitAnimation) { | 136 TEST(LayerAnimatorTest, NoImplicitAnimation) { |
| 135 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 137 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 136 animator->set_disable_timer_for_test(true); | 138 animator->set_disable_timer_for_test(true); |
| 137 TestLayerAnimationDelegate delegate; | 139 TestLayerAnimationDelegate delegate; |
| 138 animator->SetDelegate(&delegate); | 140 animator->SetDelegate(&delegate); |
| 139 animator->SetOpacity(0.5); | 141 animator->SetOpacity(0.5); |
| 140 EXPECT_FALSE(animator->is_animating()); | 142 EXPECT_FALSE(animator->is_animating()); |
| 141 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5); | 143 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5); |
| 142 } | 144 } |
| 143 | 145 |
| 144 // Checks that StopAnimatingProperty stops animation for that property, and also | 146 // Checks that StopAnimatingProperty stops animation for that property, and also |
| 145 // skips the stopped animation to the end. | 147 // skips the stopped animation to the end. |
| 146 TEST(LayerAnimatorTest, StopAnimatingProperty) { | 148 TEST(LayerAnimatorTest, StopAnimatingProperty) { |
| 147 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateImplicitAnimator()); | 149 scoped_refptr<LayerAnimator> animator( |
| 150 LayerAnimator::CreateImplicitAnimator()); |
| 148 animator->set_disable_timer_for_test(true); | 151 animator->set_disable_timer_for_test(true); |
| 149 TestLayerAnimationDelegate delegate; | 152 TestLayerAnimationDelegate delegate; |
| 150 animator->SetDelegate(&delegate); | 153 animator->SetDelegate(&delegate); |
| 151 double target_opacity(0.5); | 154 double target_opacity(0.5); |
| 152 gfx::Rect target_bounds(0, 0, 50, 50); | 155 gfx::Rect target_bounds(0, 0, 50, 50); |
| 153 animator->SetOpacity(target_opacity); | 156 animator->SetOpacity(target_opacity); |
| 154 animator->SetBounds(target_bounds); | 157 animator->SetBounds(target_bounds); |
| 155 animator->StopAnimatingProperty(LayerAnimationElement::OPACITY); | 158 animator->StopAnimatingProperty(LayerAnimationElement::OPACITY); |
| 156 EXPECT_TRUE(animator->is_animating()); | 159 EXPECT_TRUE(animator->is_animating()); |
| 157 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5); | 160 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5); |
| 158 animator->StopAnimatingProperty(LayerAnimationElement::BOUNDS); | 161 animator->StopAnimatingProperty(LayerAnimationElement::BOUNDS); |
| 159 EXPECT_FALSE(animator->is_animating()); | 162 EXPECT_FALSE(animator->is_animating()); |
| 160 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); | 163 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); |
| 161 } | 164 } |
| 162 | 165 |
| 163 // Checks that multiple running animation for separate properties can be stopped | 166 // Checks that multiple running animation for separate properties can be stopped |
| 164 // simultaneously and that all animations are advanced to their target values. | 167 // simultaneously and that all animations are advanced to their target values. |
| 165 TEST(LayerAnimatorTest, StopAnimating) { | 168 TEST(LayerAnimatorTest, StopAnimating) { |
| 166 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateImplicitAnimator()); | 169 scoped_refptr<LayerAnimator> animator( |
| 170 LayerAnimator::CreateImplicitAnimator()); |
| 167 animator->set_disable_timer_for_test(true); | 171 animator->set_disable_timer_for_test(true); |
| 168 TestLayerAnimationDelegate delegate; | 172 TestLayerAnimationDelegate delegate; |
| 169 animator->SetDelegate(&delegate); | 173 animator->SetDelegate(&delegate); |
| 170 double target_opacity(0.5); | 174 double target_opacity(0.5); |
| 171 gfx::Rect target_bounds(0, 0, 50, 50); | 175 gfx::Rect target_bounds(0, 0, 50, 50); |
| 172 animator->SetOpacity(target_opacity); | 176 animator->SetOpacity(target_opacity); |
| 173 animator->SetBounds(target_bounds); | 177 animator->SetBounds(target_bounds); |
| 174 EXPECT_TRUE(animator->is_animating()); | 178 EXPECT_TRUE(animator->is_animating()); |
| 175 animator->StopAnimating(); | 179 animator->StopAnimating(); |
| 176 EXPECT_FALSE(animator->is_animating()); | 180 EXPECT_FALSE(animator->is_animating()); |
| 177 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5); | 181 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5); |
| 178 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); | 182 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); |
| 179 } | 183 } |
| 180 | 184 |
| 181 // Schedule an animation that can run immediately. This is the trivial case and | 185 // Schedule an animation that can run immediately. This is the trivial case and |
| 182 // should result in the animation being started immediately. | 186 // should result in the animation being started immediately. |
| 183 TEST(LayerAnimatorTest, ScheduleAnimationThatCanRunImmediately) { | 187 TEST(LayerAnimatorTest, ScheduleAnimationThatCanRunImmediately) { |
| 184 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 188 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 185 AnimationContainerElement* element = animator.get(); | 189 AnimationContainerElement* element = animator.get(); |
| 186 animator->set_disable_timer_for_test(true); | 190 animator->set_disable_timer_for_test(true); |
| 187 TestLayerAnimationDelegate delegate; | 191 TestLayerAnimationDelegate delegate; |
| 188 animator->SetDelegate(&delegate); | 192 animator->SetDelegate(&delegate); |
| 189 | 193 |
| 190 double start_opacity(0.0); | 194 double start_opacity(0.0); |
| 191 double middle_opacity(0.5); | 195 double middle_opacity(0.5); |
| 192 double target_opacity(1.0); | 196 double target_opacity(1.0); |
| 193 | 197 |
| 194 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 198 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 211 | 215 |
| 212 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 216 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
| 213 | 217 |
| 214 EXPECT_FALSE(animator->is_animating()); | 218 EXPECT_FALSE(animator->is_animating()); |
| 215 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); | 219 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); |
| 216 } | 220 } |
| 217 | 221 |
| 218 // Schedule two animations on separate properties. Both animations should | 222 // Schedule two animations on separate properties. Both animations should |
| 219 // start immediately and should progress in lock step. | 223 // start immediately and should progress in lock step. |
| 220 TEST(LayerAnimatorTest, ScheduleTwoAnimationsThatCanRunImmediately) { | 224 TEST(LayerAnimatorTest, ScheduleTwoAnimationsThatCanRunImmediately) { |
| 221 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 225 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 222 AnimationContainerElement* element = animator.get(); | 226 AnimationContainerElement* element = animator.get(); |
| 223 animator->set_disable_timer_for_test(true); | 227 animator->set_disable_timer_for_test(true); |
| 224 TestLayerAnimationDelegate delegate; | 228 TestLayerAnimationDelegate delegate; |
| 225 animator->SetDelegate(&delegate); | 229 animator->SetDelegate(&delegate); |
| 226 | 230 |
| 227 double start_opacity(0.0); | 231 double start_opacity(0.0); |
| 228 double middle_opacity(0.5); | 232 double middle_opacity(0.5); |
| 229 double target_opacity(1.0); | 233 double target_opacity(1.0); |
| 230 | 234 |
| 231 gfx::Rect start_bounds, target_bounds, middle_bounds; | 235 gfx::Rect start_bounds, target_bounds, middle_bounds; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 261 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 265 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
| 262 | 266 |
| 263 EXPECT_FALSE(animator->is_animating()); | 267 EXPECT_FALSE(animator->is_animating()); |
| 264 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); | 268 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); |
| 265 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); | 269 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); |
| 266 } | 270 } |
| 267 | 271 |
| 268 // Schedule two animations on the same property. In this case, the two | 272 // Schedule two animations on the same property. In this case, the two |
| 269 // animations should run one after another. | 273 // animations should run one after another. |
| 270 TEST(LayerAnimatorTest, ScheduleTwoAnimationsOnSameProperty) { | 274 TEST(LayerAnimatorTest, ScheduleTwoAnimationsOnSameProperty) { |
| 271 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 275 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 272 AnimationContainerElement* element = animator.get(); | 276 AnimationContainerElement* element = animator.get(); |
| 273 animator->set_disable_timer_for_test(true); | 277 animator->set_disable_timer_for_test(true); |
| 274 TestLayerAnimationDelegate delegate; | 278 TestLayerAnimationDelegate delegate; |
| 275 animator->SetDelegate(&delegate); | 279 animator->SetDelegate(&delegate); |
| 276 | 280 |
| 277 double start_opacity(0.0); | 281 double start_opacity(0.0); |
| 278 double middle_opacity(0.5); | 282 double middle_opacity(0.5); |
| 279 double target_opacity(1.0); | 283 double target_opacity(1.0); |
| 280 | 284 |
| 281 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 285 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); | 317 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); |
| 314 | 318 |
| 315 EXPECT_FALSE(animator->is_animating()); | 319 EXPECT_FALSE(animator->is_animating()); |
| 316 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 320 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
| 317 } | 321 } |
| 318 | 322 |
| 319 // Schedule [{o}, {o,b}, {b}] and ensure that {b} doesn't run right away. That | 323 // Schedule [{o}, {o,b}, {b}] and ensure that {b} doesn't run right away. That |
| 320 // is, ensure that all animations targetting a particular property are run in | 324 // is, ensure that all animations targetting a particular property are run in |
| 321 // order. | 325 // order. |
| 322 TEST(LayerAnimatorTest, ScheduleBlockedAnimation) { | 326 TEST(LayerAnimatorTest, ScheduleBlockedAnimation) { |
| 323 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 327 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 324 AnimationContainerElement* element = animator.get(); | 328 AnimationContainerElement* element = animator.get(); |
| 325 animator->set_disable_timer_for_test(true); | 329 animator->set_disable_timer_for_test(true); |
| 326 TestLayerAnimationDelegate delegate; | 330 TestLayerAnimationDelegate delegate; |
| 327 animator->SetDelegate(&delegate); | 331 animator->SetDelegate(&delegate); |
| 328 | 332 |
| 329 double start_opacity(0.0); | 333 double start_opacity(0.0); |
| 330 double middle_opacity(0.5); | 334 double middle_opacity(0.5); |
| 331 double target_opacity(1.0); | 335 double target_opacity(1.0); |
| 332 | 336 |
| 333 gfx::Rect start_bounds, target_bounds, middle_bounds; | 337 gfx::Rect start_bounds, target_bounds, middle_bounds; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 | 395 |
| 392 EXPECT_FALSE(animator->is_animating()); | 396 EXPECT_FALSE(animator->is_animating()); |
| 393 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 397 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
| 394 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); | 398 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); |
| 395 } | 399 } |
| 396 | 400 |
| 397 // Schedule {o} and then schedule {o} and {b} together. In this case, since | 401 // Schedule {o} and then schedule {o} and {b} together. In this case, since |
| 398 // ScheduleTogether is being used, the bounds animation should not start until | 402 // ScheduleTogether is being used, the bounds animation should not start until |
| 399 // the second opacity animation starts. | 403 // the second opacity animation starts. |
| 400 TEST(LayerAnimatorTest, ScheduleTogether) { | 404 TEST(LayerAnimatorTest, ScheduleTogether) { |
| 401 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 405 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 402 AnimationContainerElement* element = animator.get(); | 406 AnimationContainerElement* element = animator.get(); |
| 403 animator->set_disable_timer_for_test(true); | 407 animator->set_disable_timer_for_test(true); |
| 404 TestLayerAnimationDelegate delegate; | 408 TestLayerAnimationDelegate delegate; |
| 405 animator->SetDelegate(&delegate); | 409 animator->SetDelegate(&delegate); |
| 406 | 410 |
| 407 double start_opacity(0.0); | 411 double start_opacity(0.0); |
| 408 double target_opacity(1.0); | 412 double target_opacity(1.0); |
| 409 | 413 |
| 410 gfx::Rect start_bounds, target_bounds, middle_bounds; | 414 gfx::Rect start_bounds, target_bounds, middle_bounds; |
| 411 start_bounds = target_bounds = gfx::Rect(0, 0, 50, 50); | 415 start_bounds = target_bounds = gfx::Rect(0, 0, 50, 50); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); | 448 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); |
| 445 | 449 |
| 446 EXPECT_FALSE(animator->is_animating()); | 450 EXPECT_FALSE(animator->is_animating()); |
| 447 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 451 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
| 448 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); | 452 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); |
| 449 } | 453 } |
| 450 | 454 |
| 451 // Start animation (that can run immediately). This is the trivial case (see | 455 // Start animation (that can run immediately). This is the trivial case (see |
| 452 // the trival case for ScheduleAnimation). | 456 // the trival case for ScheduleAnimation). |
| 453 TEST(LayerAnimatorTest, StartAnimationThatCanRunImmediately) { | 457 TEST(LayerAnimatorTest, StartAnimationThatCanRunImmediately) { |
| 454 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 458 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 455 AnimationContainerElement* element = animator.get(); | 459 AnimationContainerElement* element = animator.get(); |
| 456 animator->set_disable_timer_for_test(true); | 460 animator->set_disable_timer_for_test(true); |
| 457 TestLayerAnimationDelegate delegate; | 461 TestLayerAnimationDelegate delegate; |
| 458 animator->SetDelegate(&delegate); | 462 animator->SetDelegate(&delegate); |
| 459 | 463 |
| 460 double start_opacity(0.0); | 464 double start_opacity(0.0); |
| 461 double middle_opacity(0.5); | 465 double middle_opacity(0.5); |
| 462 double target_opacity(1.0); | 466 double target_opacity(1.0); |
| 463 | 467 |
| 464 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 468 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 480 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity); | 484 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity); |
| 481 | 485 |
| 482 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 486 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
| 483 | 487 |
| 484 EXPECT_FALSE(animator->is_animating()); | 488 EXPECT_FALSE(animator->is_animating()); |
| 485 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); | 489 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); |
| 486 } | 490 } |
| 487 | 491 |
| 488 // Preempt by immediately setting new target. | 492 // Preempt by immediately setting new target. |
| 489 TEST(LayerAnimatorTest, PreemptBySettingNewTarget) { | 493 TEST(LayerAnimatorTest, PreemptBySettingNewTarget) { |
| 490 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 494 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 491 animator->set_disable_timer_for_test(true); | 495 animator->set_disable_timer_for_test(true); |
| 492 TestLayerAnimationDelegate delegate; | 496 TestLayerAnimationDelegate delegate; |
| 493 animator->SetDelegate(&delegate); | 497 animator->SetDelegate(&delegate); |
| 494 | 498 |
| 495 double start_opacity(0.0); | 499 double start_opacity(0.0); |
| 496 double target_opacity(1.0); | 500 double target_opacity(1.0); |
| 497 | 501 |
| 498 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 502 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 499 | 503 |
| 500 delegate.SetOpacityFromAnimation(start_opacity); | 504 delegate.SetOpacityFromAnimation(start_opacity); |
| 501 | 505 |
| 502 animator->set_preemption_strategy(LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); | 506 animator->set_preemption_strategy(LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); |
| 503 | 507 |
| 504 animator->StartAnimation( | 508 animator->StartAnimation( |
| 505 new LayerAnimationSequence( | 509 new LayerAnimationSequence( |
| 506 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); | 510 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); |
| 507 | 511 |
| 508 animator->StartAnimation( | 512 animator->StartAnimation( |
| 509 new LayerAnimationSequence( | 513 new LayerAnimationSequence( |
| 510 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); | 514 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); |
| 511 | 515 |
| 512 EXPECT_FALSE(animator->is_animating()); | 516 EXPECT_FALSE(animator->is_animating()); |
| 513 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 517 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
| 514 } | 518 } |
| 515 | 519 |
| 516 // Preempt by animating to new target. | 520 // Preempt by animating to new target. |
| 517 TEST(LayerAnimatorTest, PreemptByImmediatelyAnimatingToNewTarget) { | 521 TEST(LayerAnimatorTest, PreemptByImmediatelyAnimatingToNewTarget) { |
| 518 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 522 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 519 AnimationContainerElement* element = animator.get(); | 523 AnimationContainerElement* element = animator.get(); |
| 520 animator->set_disable_timer_for_test(true); | 524 animator->set_disable_timer_for_test(true); |
| 521 TestLayerAnimationDelegate delegate; | 525 TestLayerAnimationDelegate delegate; |
| 522 animator->SetDelegate(&delegate); | 526 animator->SetDelegate(&delegate); |
| 523 | 527 |
| 524 double start_opacity(0.0); | 528 double start_opacity(0.0); |
| 525 double middle_opacity(0.5); | 529 double middle_opacity(0.5); |
| 526 double target_opacity(1.0); | 530 double target_opacity(1.0); |
| 527 | 531 |
| 528 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 532 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 0.5 * (start_opacity + middle_opacity)); | 564 0.5 * (start_opacity + middle_opacity)); |
| 561 | 565 |
| 562 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); | 566 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); |
| 563 | 567 |
| 564 EXPECT_FALSE(animator->is_animating()); | 568 EXPECT_FALSE(animator->is_animating()); |
| 565 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 569 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
| 566 } | 570 } |
| 567 | 571 |
| 568 // Preempt by enqueuing the new animation. | 572 // Preempt by enqueuing the new animation. |
| 569 TEST(LayerAnimatorTest, PreemptEnqueueNewAnimation) { | 573 TEST(LayerAnimatorTest, PreemptEnqueueNewAnimation) { |
| 570 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 574 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 571 AnimationContainerElement* element = animator.get(); | 575 AnimationContainerElement* element = animator.get(); |
| 572 animator->set_disable_timer_for_test(true); | 576 animator->set_disable_timer_for_test(true); |
| 573 TestLayerAnimationDelegate delegate; | 577 TestLayerAnimationDelegate delegate; |
| 574 animator->SetDelegate(&delegate); | 578 animator->SetDelegate(&delegate); |
| 575 | 579 |
| 576 double start_opacity(0.0); | 580 double start_opacity(0.0); |
| 577 double middle_opacity(0.5); | 581 double middle_opacity(0.5); |
| 578 double target_opacity(1.0); | 582 double target_opacity(1.0); |
| 579 | 583 |
| 580 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 584 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); | 617 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); |
| 614 | 618 |
| 615 EXPECT_FALSE(animator->is_animating()); | 619 EXPECT_FALSE(animator->is_animating()); |
| 616 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 620 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
| 617 } | 621 } |
| 618 | 622 |
| 619 // Start an animation when there are sequences waiting in the queue. In this | 623 // Start an animation when there are sequences waiting in the queue. In this |
| 620 // case, all pending and running animations should be finished, and the new | 624 // case, all pending and running animations should be finished, and the new |
| 621 // animation started. | 625 // animation started. |
| 622 TEST(LayerAnimatorTest, PreemptyByReplacingQueuedAnimations) { | 626 TEST(LayerAnimatorTest, PreemptyByReplacingQueuedAnimations) { |
| 623 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 627 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 624 AnimationContainerElement* element = animator.get(); | 628 AnimationContainerElement* element = animator.get(); |
| 625 animator->set_disable_timer_for_test(true); | 629 animator->set_disable_timer_for_test(true); |
| 626 TestLayerAnimationDelegate delegate; | 630 TestLayerAnimationDelegate delegate; |
| 627 animator->SetDelegate(&delegate); | 631 animator->SetDelegate(&delegate); |
| 628 | 632 |
| 629 double start_opacity(0.0); | 633 double start_opacity(0.0); |
| 630 double middle_opacity(0.5); | 634 double middle_opacity(0.5); |
| 631 double target_opacity(1.0); | 635 double target_opacity(1.0); |
| 632 | 636 |
| 633 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 637 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity); | 672 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity); |
| 669 | 673 |
| 670 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); | 674 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); |
| 671 | 675 |
| 672 EXPECT_FALSE(animator->is_animating()); | 676 EXPECT_FALSE(animator->is_animating()); |
| 673 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 677 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
| 674 } | 678 } |
| 675 | 679 |
| 676 // Test that cyclic sequences continue to animate. | 680 // Test that cyclic sequences continue to animate. |
| 677 TEST(LayerAnimatorTest, CyclicSequences) { | 681 TEST(LayerAnimatorTest, CyclicSequences) { |
| 678 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 682 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 679 AnimationContainerElement* element = animator.get(); | 683 AnimationContainerElement* element = animator.get(); |
| 680 animator->set_disable_timer_for_test(true); | 684 animator->set_disable_timer_for_test(true); |
| 681 TestLayerAnimationDelegate delegate; | 685 TestLayerAnimationDelegate delegate; |
| 682 animator->SetDelegate(&delegate); | 686 animator->SetDelegate(&delegate); |
| 683 | 687 |
| 684 double start_opacity(0.0); | 688 double start_opacity(0.0); |
| 685 double target_opacity(1.0); | 689 double target_opacity(1.0); |
| 686 | 690 |
| 687 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 691 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 688 | 692 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 | 731 |
| 728 EXPECT_TRUE(animator->is_animating()); | 732 EXPECT_TRUE(animator->is_animating()); |
| 729 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); | 733 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); |
| 730 | 734 |
| 731 animator->StopAnimatingProperty(LayerAnimationElement::OPACITY); | 735 animator->StopAnimatingProperty(LayerAnimationElement::OPACITY); |
| 732 | 736 |
| 733 EXPECT_FALSE(animator->is_animating()); | 737 EXPECT_FALSE(animator->is_animating()); |
| 734 } | 738 } |
| 735 | 739 |
| 736 TEST(LayerAnimatorTest, AddObserverExplicit) { | 740 TEST(LayerAnimatorTest, AddObserverExplicit) { |
| 737 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 741 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 738 AnimationContainerElement* element = animator.get(); | 742 AnimationContainerElement* element = animator.get(); |
| 739 animator->set_disable_timer_for_test(true); | 743 animator->set_disable_timer_for_test(true); |
| 740 TestLayerAnimationObserver observer; | 744 TestLayerAnimationObserver observer; |
| 741 TestLayerAnimationDelegate delegate; | 745 TestLayerAnimationDelegate delegate; |
| 742 animator->SetDelegate(&delegate); | 746 animator->SetDelegate(&delegate); |
| 743 animator->AddObserver(&observer); | 747 animator->AddObserver(&observer); |
| 744 observer.set_requires_notification_when_animator_destroyed(true); | 748 observer.set_requires_notification_when_animator_destroyed(true); |
| 745 | 749 |
| 746 EXPECT_TRUE(!observer.last_ended_sequence()); | 750 EXPECT_TRUE(!observer.last_ended_sequence()); |
| 747 | 751 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 761 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 765 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
| 762 | 766 |
| 763 EXPECT_EQ(observer.last_ended_sequence(), sequence); | 767 EXPECT_EQ(observer.last_ended_sequence(), sequence); |
| 764 | 768 |
| 765 // |sequence| has been destroyed. Recreate it to test abort. | 769 // |sequence| has been destroyed. Recreate it to test abort. |
| 766 sequence = new LayerAnimationSequence( | 770 sequence = new LayerAnimationSequence( |
| 767 LayerAnimationElement::CreateOpacityElement(1.0f, delta)); | 771 LayerAnimationElement::CreateOpacityElement(1.0f, delta)); |
| 768 | 772 |
| 769 animator->StartAnimation(sequence); | 773 animator->StartAnimation(sequence); |
| 770 | 774 |
| 771 animator.reset(); | 775 animator = NULL; |
| 772 | 776 |
| 773 EXPECT_EQ(observer.last_aborted_sequence(), sequence); | 777 EXPECT_EQ(observer.last_aborted_sequence(), sequence); |
| 774 } | 778 } |
| 775 | 779 |
| 776 // Tests that an observer added to a scoped settings object is still notified | 780 // Tests that an observer added to a scoped settings object is still notified |
| 777 // when the object goes out of scope. | 781 // when the object goes out of scope. |
| 778 TEST(LayerAnimatorTest, ImplicitAnimationObservers) { | 782 TEST(LayerAnimatorTest, ImplicitAnimationObservers) { |
| 779 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 783 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 780 AnimationContainerElement* element = animator.get(); | 784 AnimationContainerElement* element = animator.get(); |
| 781 animator->set_disable_timer_for_test(true); | 785 animator->set_disable_timer_for_test(true); |
| 782 TestImplicitAnimationObserver observer(false); | 786 TestImplicitAnimationObserver observer(false); |
| 783 TestLayerAnimationDelegate delegate; | 787 TestLayerAnimationDelegate delegate; |
| 784 animator->SetDelegate(&delegate); | 788 animator->SetDelegate(&delegate); |
| 785 | 789 |
| 786 EXPECT_FALSE(observer.animations_completed()); | 790 EXPECT_FALSE(observer.animations_completed()); |
| 787 animator->SetOpacity(1.0f); | 791 animator->SetOpacity(1.0f); |
| 788 | 792 |
| 789 { | 793 { |
| 790 ScopedLayerAnimationSettings settings(animator.get()); | 794 ScopedLayerAnimationSettings settings(animator.get()); |
| 791 settings.AddObserver(&observer); | 795 settings.AddObserver(&observer); |
| 792 animator->SetOpacity(0.0f); | 796 animator->SetOpacity(0.0f); |
| 793 } | 797 } |
| 794 | 798 |
| 795 EXPECT_FALSE(observer.animations_completed()); | 799 EXPECT_FALSE(observer.animations_completed()); |
| 796 base::TimeTicks start_time = animator->last_step_time(); | 800 base::TimeTicks start_time = animator->last_step_time(); |
| 797 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 801 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
| 798 EXPECT_TRUE(observer.animations_completed()); | 802 EXPECT_TRUE(observer.animations_completed()); |
| 799 EXPECT_FLOAT_EQ(0.0f, delegate.GetOpacityForAnimation()); | 803 EXPECT_FLOAT_EQ(0.0f, delegate.GetOpacityForAnimation()); |
| 800 } | 804 } |
| 801 | 805 |
| 802 // Tests that an observer added to a scoped settings object is still notified | 806 // Tests that an observer added to a scoped settings object is still notified |
| 803 // when the object goes out of scope due to the animation being interrupted. | 807 // when the object goes out of scope due to the animation being interrupted. |
| 804 TEST(LayerAnimatorTest, InterruptedImplicitAnimationObservers) { | 808 TEST(LayerAnimatorTest, InterruptedImplicitAnimationObservers) { |
| 805 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 809 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 806 animator->set_disable_timer_for_test(true); | 810 animator->set_disable_timer_for_test(true); |
| 807 TestImplicitAnimationObserver observer(false); | 811 TestImplicitAnimationObserver observer(false); |
| 808 TestLayerAnimationDelegate delegate; | 812 TestLayerAnimationDelegate delegate; |
| 809 animator->SetDelegate(&delegate); | 813 animator->SetDelegate(&delegate); |
| 810 | 814 |
| 811 EXPECT_FALSE(observer.animations_completed()); | 815 EXPECT_FALSE(observer.animations_completed()); |
| 812 animator->SetOpacity(1.0f); | 816 animator->SetOpacity(1.0f); |
| 813 | 817 |
| 814 { | 818 { |
| 815 ScopedLayerAnimationSettings settings(animator.get()); | 819 ScopedLayerAnimationSettings settings(animator.get()); |
| 816 settings.AddObserver(&observer); | 820 settings.AddObserver(&observer); |
| 817 animator->SetOpacity(0.0f); | 821 animator->SetOpacity(0.0f); |
| 818 } | 822 } |
| 819 | 823 |
| 820 EXPECT_FALSE(observer.animations_completed()); | 824 EXPECT_FALSE(observer.animations_completed()); |
| 821 // This should interrupt the implicit animation causing the observer to be | 825 // This should interrupt the implicit animation causing the observer to be |
| 822 // notified immediately. | 826 // notified immediately. |
| 823 animator->SetOpacity(1.0f); | 827 animator->SetOpacity(1.0f); |
| 824 EXPECT_TRUE(observer.animations_completed()); | 828 EXPECT_TRUE(observer.animations_completed()); |
| 825 EXPECT_FLOAT_EQ(1.0f, delegate.GetOpacityForAnimation()); | 829 EXPECT_FLOAT_EQ(1.0f, delegate.GetOpacityForAnimation()); |
| 826 } | 830 } |
| 827 | 831 |
| 828 // Tests that an observer added to a scoped settings object is not notified | 832 // Tests that an observer added to a scoped settings object is not notified |
| 829 // when the animator is destroyed unless explicitly requested. | 833 // when the animator is destroyed unless explicitly requested. |
| 830 TEST(LayerAnimatorTest, ImplicitObserversAtAnimatorDestruction) { | 834 TEST(LayerAnimatorTest, ImplicitObserversAtAnimatorDestruction) { |
| 831 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 835 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 832 animator->set_disable_timer_for_test(true); | 836 animator->set_disable_timer_for_test(true); |
| 833 TestImplicitAnimationObserver observer_notify(true); | 837 TestImplicitAnimationObserver observer_notify(true); |
| 834 TestImplicitAnimationObserver observer_do_not_notify(false); | 838 TestImplicitAnimationObserver observer_do_not_notify(false); |
| 835 TestLayerAnimationDelegate delegate; | 839 TestLayerAnimationDelegate delegate; |
| 836 animator->SetDelegate(&delegate); | 840 animator->SetDelegate(&delegate); |
| 837 | 841 |
| 838 EXPECT_FALSE(observer_notify.animations_completed()); | 842 EXPECT_FALSE(observer_notify.animations_completed()); |
| 839 EXPECT_FALSE(observer_do_not_notify.animations_completed()); | 843 EXPECT_FALSE(observer_do_not_notify.animations_completed()); |
| 840 | 844 |
| 841 animator->SetOpacity(1.0f); | 845 animator->SetOpacity(1.0f); |
| 842 | 846 |
| 843 { | 847 { |
| 844 ScopedLayerAnimationSettings settings(animator.get()); | 848 ScopedLayerAnimationSettings settings(animator.get()); |
| 845 settings.AddObserver(&observer_notify); | 849 settings.AddObserver(&observer_notify); |
| 846 settings.AddObserver(&observer_do_not_notify); | 850 settings.AddObserver(&observer_do_not_notify); |
| 847 animator->SetOpacity(0.0f); | 851 animator->SetOpacity(0.0f); |
| 848 } | 852 } |
| 849 | 853 |
| 850 EXPECT_FALSE(observer_notify.animations_completed()); | 854 EXPECT_FALSE(observer_notify.animations_completed()); |
| 851 EXPECT_FALSE(observer_do_not_notify.animations_completed()); | 855 EXPECT_FALSE(observer_do_not_notify.animations_completed()); |
| 852 animator.reset(NULL); | 856 animator = NULL; |
| 853 EXPECT_TRUE(observer_notify.animations_completed()); | 857 EXPECT_TRUE(observer_notify.animations_completed()); |
| 854 EXPECT_FALSE(observer_do_not_notify.animations_completed()); | 858 EXPECT_FALSE(observer_do_not_notify.animations_completed()); |
| 855 } | 859 } |
| 856 | 860 |
| 857 | 861 |
| 858 TEST(LayerAnimatorTest, RemoveObserverShouldRemoveFromSequences) { | 862 TEST(LayerAnimatorTest, RemoveObserverShouldRemoveFromSequences) { |
| 859 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 863 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 860 AnimationContainerElement* element = animator.get(); | 864 AnimationContainerElement* element = animator.get(); |
| 861 animator->set_disable_timer_for_test(true); | 865 animator->set_disable_timer_for_test(true); |
| 862 TestLayerAnimationObserver observer; | 866 TestLayerAnimationObserver observer; |
| 863 TestLayerAnimationObserver removed_observer; | 867 TestLayerAnimationObserver removed_observer; |
| 864 TestLayerAnimationDelegate delegate; | 868 TestLayerAnimationDelegate delegate; |
| 865 animator->SetDelegate(&delegate); | 869 animator->SetDelegate(&delegate); |
| 866 | 870 |
| 867 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 871 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 868 | 872 |
| 869 LayerAnimationSequence* sequence = new LayerAnimationSequence( | 873 LayerAnimationSequence* sequence = new LayerAnimationSequence( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 884 | 888 |
| 885 base::TimeTicks start_time = animator->last_step_time(); | 889 base::TimeTicks start_time = animator->last_step_time(); |
| 886 | 890 |
| 887 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 891 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
| 888 | 892 |
| 889 EXPECT_EQ(observer.last_ended_sequence(), sequence); | 893 EXPECT_EQ(observer.last_ended_sequence(), sequence); |
| 890 EXPECT_TRUE(!removed_observer.last_ended_sequence()); | 894 EXPECT_TRUE(!removed_observer.last_ended_sequence()); |
| 891 } | 895 } |
| 892 | 896 |
| 893 TEST(LayerAnimatorTest, ObserverReleasedBeforeAnimationSequenceEnds) { | 897 TEST(LayerAnimatorTest, ObserverReleasedBeforeAnimationSequenceEnds) { |
| 894 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 898 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 895 animator->set_disable_timer_for_test(true); | 899 animator->set_disable_timer_for_test(true); |
| 896 | 900 |
| 897 scoped_ptr<TestLayerAnimationObserver> observer( | 901 scoped_ptr<TestLayerAnimationObserver> observer( |
| 898 new TestLayerAnimationObserver); | 902 new TestLayerAnimationObserver); |
| 899 TestLayerAnimationDelegate delegate; | 903 TestLayerAnimationDelegate delegate; |
| 900 animator->SetDelegate(&delegate); | 904 animator->SetDelegate(&delegate); |
| 901 animator->AddObserver(observer.get()); | 905 animator->AddObserver(observer.get()); |
| 902 | 906 |
| 903 delegate.SetOpacityFromAnimation(0.0f); | 907 delegate.SetOpacityFromAnimation(0.0f); |
| 904 | 908 |
| 905 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 909 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 906 LayerAnimationSequence* sequence = new LayerAnimationSequence( | 910 LayerAnimationSequence* sequence = new LayerAnimationSequence( |
| 907 LayerAnimationElement::CreateOpacityElement(1.0f, delta)); | 911 LayerAnimationElement::CreateOpacityElement(1.0f, delta)); |
| 908 | 912 |
| 909 animator->StartAnimation(sequence); | 913 animator->StartAnimation(sequence); |
| 910 | 914 |
| 911 // |observer| should be attached to |sequence|. | 915 // |observer| should be attached to |sequence|. |
| 912 EXPECT_EQ(static_cast<size_t>(1), sequence->observers_.size()); | 916 EXPECT_EQ(static_cast<size_t>(1), sequence->observers_.size()); |
| 913 | 917 |
| 914 // Now, release |observer| | 918 // Now, release |observer| |
| 915 observer.reset(); | 919 observer.reset(); |
| 916 | 920 |
| 917 // And |sequence| should no longer be attached to |observer|. | 921 // And |sequence| should no longer be attached to |observer|. |
| 918 EXPECT_EQ(static_cast<size_t>(0), sequence->observers_.size()); | 922 EXPECT_EQ(static_cast<size_t>(0), sequence->observers_.size()); |
| 919 } | 923 } |
| 920 | 924 |
| 921 TEST(LayerAnimatorTest, ObserverAttachedAfterAnimationStarted) { | 925 TEST(LayerAnimatorTest, ObserverAttachedAfterAnimationStarted) { |
| 922 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 926 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 923 AnimationContainerElement* element = animator.get(); | 927 AnimationContainerElement* element = animator.get(); |
| 924 animator->set_disable_timer_for_test(true); | 928 animator->set_disable_timer_for_test(true); |
| 925 | 929 |
| 926 TestImplicitAnimationObserver observer(false); | 930 TestImplicitAnimationObserver observer(false); |
| 927 TestLayerAnimationDelegate delegate; | 931 TestLayerAnimationDelegate delegate; |
| 928 animator->SetDelegate(&delegate); | 932 animator->SetDelegate(&delegate); |
| 929 | 933 |
| 930 delegate.SetOpacityFromAnimation(0.0f); | 934 delegate.SetOpacityFromAnimation(0.0f); |
| 931 | 935 |
| 932 { | 936 { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 945 // Start observing an in-flight animation. | 949 // Start observing an in-flight animation. |
| 946 sequence->AddObserver(&observer); | 950 sequence->AddObserver(&observer); |
| 947 | 951 |
| 948 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 952 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
| 949 } | 953 } |
| 950 | 954 |
| 951 EXPECT_TRUE(observer.animations_completed()); | 955 EXPECT_TRUE(observer.animations_completed()); |
| 952 } | 956 } |
| 953 | 957 |
| 954 TEST(LayerAnimatorTest, ObserverDetachedBeforeAnimationFinished) { | 958 TEST(LayerAnimatorTest, ObserverDetachedBeforeAnimationFinished) { |
| 955 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 959 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 956 AnimationContainerElement* element = animator.get(); | 960 AnimationContainerElement* element = animator.get(); |
| 957 animator->set_disable_timer_for_test(true); | 961 animator->set_disable_timer_for_test(true); |
| 958 | 962 |
| 959 TestImplicitAnimationObserver observer(false); | 963 TestImplicitAnimationObserver observer(false); |
| 960 TestLayerAnimationDelegate delegate; | 964 TestLayerAnimationDelegate delegate; |
| 961 animator->SetDelegate(&delegate); | 965 animator->SetDelegate(&delegate); |
| 962 | 966 |
| 963 delegate.SetOpacityFromAnimation(0.0f); | 967 delegate.SetOpacityFromAnimation(0.0f); |
| 964 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 968 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 965 LayerAnimationSequence* sequence = new LayerAnimationSequence( | 969 LayerAnimationSequence* sequence = new LayerAnimationSequence( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 982 EXPECT_TRUE(observer.animations_completed()); | 986 EXPECT_TRUE(observer.animations_completed()); |
| 983 } | 987 } |
| 984 | 988 |
| 985 // This checks that if an animation is deleted due to a callback, that the | 989 // This checks that if an animation is deleted due to a callback, that the |
| 986 // animator does not try to use the deleted animation. For example, if we have | 990 // animator does not try to use the deleted animation. For example, if we have |
| 987 // two running animations, and the first finishes and the resulting callback | 991 // two running animations, and the first finishes and the resulting callback |
| 988 // causes the second to be deleted, we should not attempt to animate the second | 992 // causes the second to be deleted, we should not attempt to animate the second |
| 989 // animation. | 993 // animation. |
| 990 TEST(LayerAnimatorTest, ObserverDeletesAnimations) { | 994 TEST(LayerAnimatorTest, ObserverDeletesAnimations) { |
| 991 LayerAnimator::set_disable_animations_for_test(false); | 995 LayerAnimator::set_disable_animations_for_test(false); |
| 992 scoped_ptr<LayerAnimator> animator(new TestLayerAnimator()); | 996 scoped_refptr<LayerAnimator> animator(new TestLayerAnimator()); |
| 993 AnimationContainerElement* element = animator.get(); | 997 AnimationContainerElement* element = animator.get(); |
| 994 animator->set_disable_timer_for_test(true); | 998 animator->set_disable_timer_for_test(true); |
| 995 TestLayerAnimationDelegate delegate; | 999 TestLayerAnimationDelegate delegate; |
| 996 animator->SetDelegate(&delegate); | 1000 animator->SetDelegate(&delegate); |
| 997 | 1001 |
| 998 double start_opacity(0.0); | 1002 double start_opacity(0.0); |
| 999 double target_opacity(1.0); | 1003 double target_opacity(1.0); |
| 1000 | 1004 |
| 1001 gfx::Rect start_bounds(0, 0, 50, 50); | 1005 gfx::Rect start_bounds(0, 0, 50, 50); |
| 1002 gfx::Rect target_bounds(5, 5, 5, 5); | 1006 gfx::Rect target_bounds(5, 5, 5, 5); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1025 | 1029 |
| 1026 base::TimeTicks start_time = animator->last_step_time(); | 1030 base::TimeTicks start_time = animator->last_step_time(); |
| 1027 element->Step(start_time + halfway_delta); | 1031 element->Step(start_time + halfway_delta); |
| 1028 | 1032 |
| 1029 animator->RemoveObserver(observer.get()); | 1033 animator->RemoveObserver(observer.get()); |
| 1030 } | 1034 } |
| 1031 | 1035 |
| 1032 // Check that setting a property during an animation with a default animator | 1036 // Check that setting a property during an animation with a default animator |
| 1033 // cancels the original animation. | 1037 // cancels the original animation. |
| 1034 TEST(LayerAnimatorTest, SettingPropertyDuringAnAnimation) { | 1038 TEST(LayerAnimatorTest, SettingPropertyDuringAnAnimation) { |
| 1035 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1039 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 1036 animator->set_disable_timer_for_test(true); | 1040 animator->set_disable_timer_for_test(true); |
| 1037 TestLayerAnimationDelegate delegate; | 1041 TestLayerAnimationDelegate delegate; |
| 1038 animator->SetDelegate(&delegate); | 1042 animator->SetDelegate(&delegate); |
| 1039 | 1043 |
| 1040 double start_opacity(0.0); | 1044 double start_opacity(0.0); |
| 1041 double target_opacity(1.0); | 1045 double target_opacity(1.0); |
| 1042 | 1046 |
| 1043 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 1047 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 1044 | 1048 |
| 1045 delegate.SetOpacityFromAnimation(start_opacity); | 1049 delegate.SetOpacityFromAnimation(start_opacity); |
| 1046 | 1050 |
| 1047 scoped_ptr<LayerAnimationSequence> sequence( | 1051 scoped_ptr<LayerAnimationSequence> sequence( |
| 1048 new LayerAnimationSequence( | 1052 new LayerAnimationSequence( |
| 1049 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); | 1053 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); |
| 1050 | 1054 |
| 1051 animator->StartAnimation(sequence.release()); | 1055 animator->StartAnimation(sequence.release()); |
| 1052 | 1056 |
| 1053 animator->SetOpacity(0.5); | 1057 animator->SetOpacity(0.5); |
| 1054 | 1058 |
| 1055 EXPECT_FALSE(animator->is_animating()); | 1059 EXPECT_FALSE(animator->is_animating()); |
| 1056 EXPECT_EQ(0.5, animator->GetTargetOpacity()); | 1060 EXPECT_EQ(0.5, animator->GetTargetOpacity()); |
| 1057 } | 1061 } |
| 1058 | 1062 |
| 1059 // Tests that the preemption mode IMMEDIATELY_SET_NEW_TARGET, doesn't cause the | 1063 // Tests that the preemption mode IMMEDIATELY_SET_NEW_TARGET, doesn't cause the |
| 1060 // second sequence to be leaked. | 1064 // second sequence to be leaked. |
| 1061 TEST(LayerAnimatorTest, ImmediatelySettingNewTargetDoesNotLeak) { | 1065 TEST(LayerAnimatorTest, ImmediatelySettingNewTargetDoesNotLeak) { |
| 1062 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1066 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 1063 animator->set_preemption_strategy(LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); | 1067 animator->set_preemption_strategy(LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); |
| 1064 animator->set_disable_timer_for_test(true); | 1068 animator->set_disable_timer_for_test(true); |
| 1065 TestLayerAnimationDelegate delegate; | 1069 TestLayerAnimationDelegate delegate; |
| 1066 animator->SetDelegate(&delegate); | 1070 animator->SetDelegate(&delegate); |
| 1067 | 1071 |
| 1068 gfx::Rect start_bounds(0, 0, 50, 50); | 1072 gfx::Rect start_bounds(0, 0, 50, 50); |
| 1069 gfx::Rect middle_bounds(10, 10, 100, 100); | 1073 gfx::Rect middle_bounds(10, 10, 100, 100); |
| 1070 gfx::Rect target_bounds(5, 5, 5, 5); | 1074 gfx::Rect target_bounds(5, 5, 5, 5); |
| 1071 | 1075 |
| 1072 delegate.SetBoundsFromAnimation(start_bounds); | 1076 delegate.SetBoundsFromAnimation(start_bounds); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1092 // the target value. The sequence should alse be destructed. | 1096 // the target value. The sequence should alse be destructed. |
| 1093 animator->StartAnimation(sequence.release()); | 1097 animator->StartAnimation(sequence.release()); |
| 1094 | 1098 |
| 1095 EXPECT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); | 1099 EXPECT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); |
| 1096 EXPECT_EQ(0, num_live_instances); | 1100 EXPECT_EQ(0, num_live_instances); |
| 1097 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); | 1101 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); |
| 1098 } | 1102 } |
| 1099 | 1103 |
| 1100 // Verifies GetTargetOpacity() works when multiple sequences are scheduled. | 1104 // Verifies GetTargetOpacity() works when multiple sequences are scheduled. |
| 1101 TEST(LayerAnimatorTest, GetTargetOpacity) { | 1105 TEST(LayerAnimatorTest, GetTargetOpacity) { |
| 1102 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1106 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 1103 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); | 1107 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); |
| 1104 animator->set_disable_timer_for_test(true); | 1108 animator->set_disable_timer_for_test(true); |
| 1105 TestLayerAnimationDelegate delegate; | 1109 TestLayerAnimationDelegate delegate; |
| 1106 animator->SetDelegate(&delegate); | 1110 animator->SetDelegate(&delegate); |
| 1107 | 1111 |
| 1108 delegate.SetOpacityFromAnimation(0.0); | 1112 delegate.SetOpacityFromAnimation(0.0); |
| 1109 | 1113 |
| 1110 { | 1114 { |
| 1111 ScopedLayerAnimationSettings settings(animator.get()); | 1115 ScopedLayerAnimationSettings settings(animator.get()); |
| 1112 animator->SetOpacity(0.5); | 1116 animator->SetOpacity(0.5); |
| 1113 EXPECT_EQ(0.5, animator->GetTargetOpacity()); | 1117 EXPECT_EQ(0.5, animator->GetTargetOpacity()); |
| 1114 | 1118 |
| 1115 // Because the strategy is ENQUEUE_NEW_ANIMATION the target should now be 1. | 1119 // Because the strategy is ENQUEUE_NEW_ANIMATION the target should now be 1. |
| 1116 animator->SetOpacity(1.0); | 1120 animator->SetOpacity(1.0); |
| 1117 EXPECT_EQ(1.0, animator->GetTargetOpacity()); | 1121 EXPECT_EQ(1.0, animator->GetTargetOpacity()); |
| 1118 } | 1122 } |
| 1119 } | 1123 } |
| 1120 | 1124 |
| 1121 // Verifies GetTargetBrightness() works when multiple sequences are scheduled. | 1125 // Verifies GetTargetBrightness() works when multiple sequences are scheduled. |
| 1122 TEST(LayerAnimatorTest, GetTargetBrightness) { | 1126 TEST(LayerAnimatorTest, GetTargetBrightness) { |
| 1123 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1127 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 1124 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); | 1128 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); |
| 1125 animator->set_disable_timer_for_test(true); | 1129 animator->set_disable_timer_for_test(true); |
| 1126 TestLayerAnimationDelegate delegate; | 1130 TestLayerAnimationDelegate delegate; |
| 1127 animator->SetDelegate(&delegate); | 1131 animator->SetDelegate(&delegate); |
| 1128 | 1132 |
| 1129 delegate.SetBrightnessFromAnimation(0.0); | 1133 delegate.SetBrightnessFromAnimation(0.0); |
| 1130 | 1134 |
| 1131 { | 1135 { |
| 1132 ScopedLayerAnimationSettings settings(animator.get()); | 1136 ScopedLayerAnimationSettings settings(animator.get()); |
| 1133 animator->SetBrightness(0.5); | 1137 animator->SetBrightness(0.5); |
| 1134 EXPECT_EQ(0.5, animator->GetTargetBrightness()); | 1138 EXPECT_EQ(0.5, animator->GetTargetBrightness()); |
| 1135 | 1139 |
| 1136 // Because the strategy is ENQUEUE_NEW_ANIMATION the target should now be 1. | 1140 // Because the strategy is ENQUEUE_NEW_ANIMATION the target should now be 1. |
| 1137 animator->SetBrightness(1.0); | 1141 animator->SetBrightness(1.0); |
| 1138 EXPECT_EQ(1.0, animator->GetTargetBrightness()); | 1142 EXPECT_EQ(1.0, animator->GetTargetBrightness()); |
| 1139 } | 1143 } |
| 1140 } | 1144 } |
| 1141 | 1145 |
| 1142 // Verifies GetTargetGrayscale() works when multiple sequences are scheduled. | 1146 // Verifies GetTargetGrayscale() works when multiple sequences are scheduled. |
| 1143 TEST(LayerAnimatorTest, GetTargetGrayscale) { | 1147 TEST(LayerAnimatorTest, GetTargetGrayscale) { |
| 1144 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1148 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 1145 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); | 1149 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); |
| 1146 animator->set_disable_timer_for_test(true); | 1150 animator->set_disable_timer_for_test(true); |
| 1147 TestLayerAnimationDelegate delegate; | 1151 TestLayerAnimationDelegate delegate; |
| 1148 animator->SetDelegate(&delegate); | 1152 animator->SetDelegate(&delegate); |
| 1149 | 1153 |
| 1150 delegate.SetGrayscaleFromAnimation(0.0); | 1154 delegate.SetGrayscaleFromAnimation(0.0); |
| 1151 | 1155 |
| 1152 { | 1156 { |
| 1153 ScopedLayerAnimationSettings settings(animator.get()); | 1157 ScopedLayerAnimationSettings settings(animator.get()); |
| 1154 animator->SetGrayscale(0.5); | 1158 animator->SetGrayscale(0.5); |
| 1155 EXPECT_EQ(0.5, animator->GetTargetGrayscale()); | 1159 EXPECT_EQ(0.5, animator->GetTargetGrayscale()); |
| 1156 | 1160 |
| 1157 // Because the strategy is ENQUEUE_NEW_ANIMATION the target should now be 1. | 1161 // Because the strategy is ENQUEUE_NEW_ANIMATION the target should now be 1. |
| 1158 animator->SetGrayscale(1.0); | 1162 animator->SetGrayscale(1.0); |
| 1159 EXPECT_EQ(1.0, animator->GetTargetGrayscale()); | 1163 EXPECT_EQ(1.0, animator->GetTargetGrayscale()); |
| 1160 } | 1164 } |
| 1161 } | 1165 } |
| 1162 | 1166 |
| 1163 // Verifies SchedulePauseForProperties(). | 1167 // Verifies SchedulePauseForProperties(). |
| 1164 TEST(LayerAnimatorTest, SchedulePauseForProperties) { | 1168 TEST(LayerAnimatorTest, SchedulePauseForProperties) { |
| 1165 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1169 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 1166 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); | 1170 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); |
| 1167 animator->SchedulePauseForProperties(base::TimeDelta::FromMilliseconds(100), | 1171 animator->SchedulePauseForProperties(base::TimeDelta::FromMilliseconds(100), |
| 1168 LayerAnimationElement::TRANSFORM, | 1172 LayerAnimationElement::TRANSFORM, |
| 1169 LayerAnimationElement::BOUNDS, -1); | 1173 LayerAnimationElement::BOUNDS, -1); |
| 1170 EXPECT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::TRANSFORM)); | 1174 EXPECT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::TRANSFORM)); |
| 1171 EXPECT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); | 1175 EXPECT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); |
| 1172 EXPECT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::OPACITY)); | 1176 EXPECT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::OPACITY)); |
| 1173 } | 1177 } |
| 1174 | 1178 |
| 1179 |
| 1180 class AnimatorOwner { |
| 1181 public: |
| 1182 AnimatorOwner() |
| 1183 : animator_(LayerAnimator::CreateDefaultAnimator()) { |
| 1184 } |
| 1185 |
| 1186 LayerAnimator* animator() { return animator_.get(); } |
| 1187 |
| 1188 private: |
| 1189 scoped_refptr<LayerAnimator> animator_; |
| 1190 |
| 1191 DISALLOW_COPY_AND_ASSIGN(AnimatorOwner); |
| 1192 }; |
| 1193 |
| 1194 class DeletingObserver : public LayerAnimationObserver { |
| 1195 public: |
| 1196 DeletingObserver(bool* was_deleted) |
| 1197 : animator_owner_(new AnimatorOwner), |
| 1198 delete_on_animation_ended_(false), |
| 1199 delete_on_animation_aborted_(false), |
| 1200 delete_on_animation_scheduled_(false), |
| 1201 was_deleted_(was_deleted) { |
| 1202 animator()->AddObserver(this); |
| 1203 } |
| 1204 |
| 1205 ~DeletingObserver() { |
| 1206 animator()->RemoveObserver(this); |
| 1207 *was_deleted_ = true; |
| 1208 } |
| 1209 |
| 1210 LayerAnimator* animator() { return animator_owner_->animator(); } |
| 1211 |
| 1212 bool delete_on_animation_ended() const { |
| 1213 return delete_on_animation_ended_; |
| 1214 } |
| 1215 void set_delete_on_animation_ended(bool enabled) { |
| 1216 delete_on_animation_ended_ = enabled; |
| 1217 } |
| 1218 |
| 1219 bool delete_on_animation_aborted() const { |
| 1220 return delete_on_animation_aborted_; |
| 1221 } |
| 1222 void set_delete_on_animation_aborted(bool enabled) { |
| 1223 delete_on_animation_aborted_ = enabled; |
| 1224 } |
| 1225 |
| 1226 bool delete_on_animation_scheduled() const { |
| 1227 return delete_on_animation_scheduled_; |
| 1228 } |
| 1229 void set_delete_on_animation_scheduled(bool enabled) { |
| 1230 delete_on_animation_scheduled_ = enabled; |
| 1231 } |
| 1232 |
| 1233 // LayerAnimationObserver implementation. |
| 1234 virtual void OnLayerAnimationEnded( |
| 1235 LayerAnimationSequence* sequence) OVERRIDE { |
| 1236 if (delete_on_animation_ended_) |
| 1237 delete this; |
| 1238 } |
| 1239 |
| 1240 virtual void OnLayerAnimationAborted( |
| 1241 LayerAnimationSequence* sequence) OVERRIDE { |
| 1242 if (delete_on_animation_aborted_) |
| 1243 delete this; |
| 1244 } |
| 1245 |
| 1246 virtual void OnLayerAnimationScheduled( |
| 1247 LayerAnimationSequence* sequence) { |
| 1248 if (delete_on_animation_scheduled_) |
| 1249 delete this; |
| 1250 } |
| 1251 |
| 1252 private: |
| 1253 scoped_ptr<AnimatorOwner> animator_owner_; |
| 1254 bool delete_on_animation_ended_; |
| 1255 bool delete_on_animation_aborted_; |
| 1256 bool delete_on_animation_scheduled_; |
| 1257 bool* was_deleted_; |
| 1258 |
| 1259 DISALLOW_COPY_AND_ASSIGN(DeletingObserver); |
| 1260 }; |
| 1261 |
| 1262 TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterFinishingAnimation) { |
| 1263 bool observer_was_deleted = false; |
| 1264 DeletingObserver* observer = new DeletingObserver(&observer_was_deleted); |
| 1265 observer->set_delete_on_animation_ended(true); |
| 1266 observer->set_delete_on_animation_aborted(true); |
| 1267 LayerAnimator* animator = observer->animator(); |
| 1268 AnimationContainerElement* element = observer->animator(); |
| 1269 animator->set_disable_timer_for_test(true); |
| 1270 TestLayerAnimationDelegate delegate; |
| 1271 animator->SetDelegate(&delegate); |
| 1272 |
| 1273 delegate.SetOpacityFromAnimation(0.0f); |
| 1274 |
| 1275 gfx::Rect start_bounds(0, 0, 50, 50); |
| 1276 gfx::Rect target_bounds(10, 10, 100, 100); |
| 1277 |
| 1278 delegate.SetBoundsFromAnimation(start_bounds); |
| 1279 |
| 1280 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 1281 LayerAnimationSequence* opacity_sequence = new LayerAnimationSequence( |
| 1282 LayerAnimationElement::CreateOpacityElement(1.0f, delta)); |
| 1283 animator->StartAnimation(opacity_sequence); |
| 1284 |
| 1285 delta = base::TimeDelta::FromSeconds(2); |
| 1286 LayerAnimationSequence* bounds_sequence = new LayerAnimationSequence( |
| 1287 LayerAnimationElement::CreateBoundsElement(target_bounds, delta)); |
| 1288 animator->StartAnimation(bounds_sequence); |
| 1289 |
| 1290 base::TimeTicks start_time = animator->last_step_time(); |
| 1291 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); |
| 1292 |
| 1293 EXPECT_TRUE(observer_was_deleted); |
| 1294 } |
| 1295 |
| 1296 TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterStoppingAnimating) { |
| 1297 bool observer_was_deleted = false; |
| 1298 DeletingObserver* observer = new DeletingObserver(&observer_was_deleted); |
| 1299 observer->set_delete_on_animation_ended(true); |
| 1300 observer->set_delete_on_animation_aborted(true); |
| 1301 LayerAnimator* animator = observer->animator(); |
| 1302 animator->set_disable_timer_for_test(true); |
| 1303 TestLayerAnimationDelegate delegate; |
| 1304 animator->SetDelegate(&delegate); |
| 1305 |
| 1306 delegate.SetOpacityFromAnimation(0.0f); |
| 1307 |
| 1308 gfx::Rect start_bounds(0, 0, 50, 50); |
| 1309 gfx::Rect target_bounds(10, 10, 100, 100); |
| 1310 |
| 1311 delegate.SetBoundsFromAnimation(start_bounds); |
| 1312 |
| 1313 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 1314 LayerAnimationSequence* opacity_sequence = new LayerAnimationSequence( |
| 1315 LayerAnimationElement::CreateOpacityElement(1.0f, delta)); |
| 1316 animator->StartAnimation(opacity_sequence); |
| 1317 |
| 1318 delta = base::TimeDelta::FromSeconds(2); |
| 1319 LayerAnimationSequence* bounds_sequence = new LayerAnimationSequence( |
| 1320 LayerAnimationElement::CreateBoundsElement(target_bounds, delta)); |
| 1321 animator->StartAnimation(bounds_sequence); |
| 1322 |
| 1323 animator->StopAnimating(); |
| 1324 |
| 1325 EXPECT_TRUE(observer_was_deleted); |
| 1326 } |
| 1327 |
| 1328 TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterScheduling) { |
| 1329 bool observer_was_deleted = false; |
| 1330 DeletingObserver* observer = new DeletingObserver(&observer_was_deleted); |
| 1331 observer->set_delete_on_animation_scheduled(true); |
| 1332 LayerAnimator* animator = observer->animator(); |
| 1333 animator->set_disable_timer_for_test(true); |
| 1334 TestLayerAnimationDelegate delegate; |
| 1335 animator->SetDelegate(&delegate); |
| 1336 |
| 1337 delegate.SetOpacityFromAnimation(0.0f); |
| 1338 |
| 1339 gfx::Rect start_bounds(0, 0, 50, 50); |
| 1340 gfx::Rect target_bounds(10, 10, 100, 100); |
| 1341 |
| 1342 delegate.SetBoundsFromAnimation(start_bounds); |
| 1343 |
| 1344 std::vector<LayerAnimationSequence*> to_start; |
| 1345 |
| 1346 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 1347 to_start.push_back(new LayerAnimationSequence( |
| 1348 LayerAnimationElement::CreateOpacityElement(1.0f, delta))); |
| 1349 |
| 1350 delta = base::TimeDelta::FromSeconds(2); |
| 1351 to_start.push_back(new LayerAnimationSequence( |
| 1352 LayerAnimationElement::CreateBoundsElement(target_bounds, delta))); |
| 1353 |
| 1354 animator->ScheduleTogether(to_start); |
| 1355 |
| 1356 EXPECT_TRUE(observer_was_deleted); |
| 1357 } |
| 1358 |
| 1359 TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterAborted) { |
| 1360 bool observer_was_deleted = false; |
| 1361 DeletingObserver* observer = new DeletingObserver(&observer_was_deleted); |
| 1362 observer->set_delete_on_animation_aborted(true); |
| 1363 LayerAnimator* animator = observer->animator(); |
| 1364 animator->set_preemption_strategy( |
| 1365 LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 1366 animator->set_disable_timer_for_test(true); |
| 1367 TestLayerAnimationDelegate delegate; |
| 1368 animator->SetDelegate(&delegate); |
| 1369 |
| 1370 delegate.SetOpacityFromAnimation(0.0f); |
| 1371 |
| 1372 gfx::Rect start_bounds(0, 0, 50, 50); |
| 1373 gfx::Rect target_bounds(10, 10, 100, 100); |
| 1374 |
| 1375 delegate.SetBoundsFromAnimation(start_bounds); |
| 1376 |
| 1377 std::vector<LayerAnimationSequence*> to_start; |
| 1378 |
| 1379 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 1380 to_start.push_back(new LayerAnimationSequence( |
| 1381 LayerAnimationElement::CreateOpacityElement(1.0f, delta))); |
| 1382 |
| 1383 delta = base::TimeDelta::FromSeconds(2); |
| 1384 to_start.push_back(new LayerAnimationSequence( |
| 1385 LayerAnimationElement::CreateBoundsElement(target_bounds, delta))); |
| 1386 |
| 1387 animator->ScheduleTogether(to_start); |
| 1388 |
| 1389 EXPECT_FALSE(observer_was_deleted); |
| 1390 |
| 1391 animator->StartAnimation(new LayerAnimationSequence( |
| 1392 LayerAnimationElement::CreateOpacityElement(1.0f, delta))); |
| 1393 |
| 1394 EXPECT_TRUE(observer_was_deleted); |
| 1395 } |
| 1396 |
| 1175 } // namespace ui | 1397 } // namespace ui |
| OLD | NEW |