| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/gfx/compositor/layer_animator.h" | 5 #include "ui/gfx/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" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/gfx/rect.h" | 12 #include "ui/gfx/rect.h" |
| 13 #include "ui/gfx/transform.h" | 13 #include "ui/gfx/transform.h" |
| 14 #include "ui/gfx/compositor/dummy_layer_animation_delegate.h" | |
| 15 #include "ui/gfx/compositor/layer_animation_delegate.h" | 14 #include "ui/gfx/compositor/layer_animation_delegate.h" |
| 16 #include "ui/gfx/compositor/layer_animation_element.h" | 15 #include "ui/gfx/compositor/layer_animation_element.h" |
| 17 #include "ui/gfx/compositor/layer_animation_sequence.h" | 16 #include "ui/gfx/compositor/layer_animation_sequence.h" |
| 17 #include "ui/gfx/compositor/test_layer_animation_delegate.h" |
| 18 #include "ui/gfx/compositor/test_layer_animation_observer.h" |
| 18 #include "ui/gfx/compositor/test_utils.h" | 19 #include "ui/gfx/compositor/test_utils.h" |
| 19 | 20 |
| 20 namespace ui { | 21 namespace ui { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 // Checks that setting a property on an implicit animator causes an animation to | 25 // Checks that setting a property on an implicit animator causes an animation to |
| 25 // happen. | 26 // happen. |
| 26 TEST(LayerAnimatorTest, ImplicitAnimation) { | 27 TEST(LayerAnimatorTest, ImplicitAnimation) { |
| 27 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateImplicitAnimator()); | 28 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateImplicitAnimator()); |
| 28 AnimationContainerElement* element = animator.get(); | 29 AnimationContainerElement* element = animator.get(); |
| 29 animator->set_disable_timer_for_test(true); | 30 animator->set_disable_timer_for_test(true); |
| 30 DummyLayerAnimationDelegate delegate; | 31 TestLayerAnimationDelegate delegate; |
| 31 animator->SetDelegate(&delegate); | 32 animator->SetDelegate(&delegate); |
| 32 base::TimeTicks now = base::TimeTicks::Now(); | 33 base::TimeTicks now = base::TimeTicks::Now(); |
| 33 animator->SetOpacity(0.5); | 34 animator->SetOpacity(0.5); |
| 34 EXPECT_TRUE(animator->is_animating()); | 35 EXPECT_TRUE(animator->is_animating()); |
| 35 element->Step(now + base::TimeDelta::FromSeconds(1)); | 36 element->Step(now + base::TimeDelta::FromSeconds(1)); |
| 36 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5); | 37 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5); |
| 37 } | 38 } |
| 38 | 39 |
| 39 // Checks that if the animator is a default animator, that implicit animations | 40 // Checks that if the animator is a default animator, that implicit animations |
| 40 // are not started. | 41 // are not started. |
| 41 TEST(LayerAnimatorTest, NoImplicitAnimation) { | 42 TEST(LayerAnimatorTest, NoImplicitAnimation) { |
| 42 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 43 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 43 animator->set_disable_timer_for_test(true); | 44 animator->set_disable_timer_for_test(true); |
| 44 DummyLayerAnimationDelegate delegate; | 45 TestLayerAnimationDelegate delegate; |
| 45 animator->SetDelegate(&delegate); | 46 animator->SetDelegate(&delegate); |
| 46 base::TimeTicks now = base::TimeTicks::Now(); | 47 base::TimeTicks now = base::TimeTicks::Now(); |
| 47 animator->SetOpacity(0.5); | 48 animator->SetOpacity(0.5); |
| 48 EXPECT_FALSE(animator->is_animating()); | 49 EXPECT_FALSE(animator->is_animating()); |
| 49 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5); | 50 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5); |
| 50 } | 51 } |
| 51 | 52 |
| 52 // Checks that StopAnimatingProperty stops animation for that property, and also | 53 // Checks that StopAnimatingProperty stops animation for that property, and also |
| 53 // skips the stopped animation to the end. | 54 // skips the stopped animation to the end. |
| 54 TEST(LayerAnimatorTest, StopAnimatingProperty) { | 55 TEST(LayerAnimatorTest, StopAnimatingProperty) { |
| 55 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateImplicitAnimator()); | 56 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateImplicitAnimator()); |
| 56 animator->set_disable_timer_for_test(true); | 57 animator->set_disable_timer_for_test(true); |
| 57 DummyLayerAnimationDelegate delegate; | 58 TestLayerAnimationDelegate delegate; |
| 58 animator->SetDelegate(&delegate); | 59 animator->SetDelegate(&delegate); |
| 59 base::TimeTicks now = base::TimeTicks::Now(); | 60 base::TimeTicks now = base::TimeTicks::Now(); |
| 60 double target_opacity(0.5); | 61 double target_opacity(0.5); |
| 61 gfx::Rect target_bounds(0, 0, 50, 50); | 62 gfx::Rect target_bounds(0, 0, 50, 50); |
| 62 animator->SetOpacity(target_opacity); | 63 animator->SetOpacity(target_opacity); |
| 63 animator->SetBounds(target_bounds); | 64 animator->SetBounds(target_bounds); |
| 64 animator->StopAnimatingProperty(LayerAnimationElement::OPACITY); | 65 animator->StopAnimatingProperty(LayerAnimationElement::OPACITY); |
| 65 EXPECT_TRUE(animator->is_animating()); | 66 EXPECT_TRUE(animator->is_animating()); |
| 66 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5); | 67 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5); |
| 67 animator->StopAnimatingProperty(LayerAnimationElement::BOUNDS); | 68 animator->StopAnimatingProperty(LayerAnimationElement::BOUNDS); |
| 68 EXPECT_FALSE(animator->is_animating()); | 69 EXPECT_FALSE(animator->is_animating()); |
| 69 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); | 70 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); |
| 70 } | 71 } |
| 71 | 72 |
| 72 // Checks that multiple running animation for separate properties can be stopped | 73 // Checks that multiple running animation for separate properties can be stopped |
| 73 // simultaneously and that all animations are advanced to their target values. | 74 // simultaneously and that all animations are advanced to their target values. |
| 74 TEST(LayerAnimatorTest, StopAnimating) { | 75 TEST(LayerAnimatorTest, StopAnimating) { |
| 75 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateImplicitAnimator()); | 76 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateImplicitAnimator()); |
| 76 animator->set_disable_timer_for_test(true); | 77 animator->set_disable_timer_for_test(true); |
| 77 DummyLayerAnimationDelegate delegate; | 78 TestLayerAnimationDelegate delegate; |
| 78 animator->SetDelegate(&delegate); | 79 animator->SetDelegate(&delegate); |
| 79 base::TimeTicks now = base::TimeTicks::Now(); | 80 base::TimeTicks now = base::TimeTicks::Now(); |
| 80 double target_opacity(0.5); | 81 double target_opacity(0.5); |
| 81 gfx::Rect target_bounds(0, 0, 50, 50); | 82 gfx::Rect target_bounds(0, 0, 50, 50); |
| 82 animator->SetOpacity(target_opacity); | 83 animator->SetOpacity(target_opacity); |
| 83 animator->SetBounds(target_bounds); | 84 animator->SetBounds(target_bounds); |
| 84 EXPECT_TRUE(animator->is_animating()); | 85 EXPECT_TRUE(animator->is_animating()); |
| 85 animator->StopAnimating(); | 86 animator->StopAnimating(); |
| 86 EXPECT_FALSE(animator->is_animating()); | 87 EXPECT_FALSE(animator->is_animating()); |
| 87 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5); | 88 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5); |
| 88 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); | 89 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); |
| 89 } | 90 } |
| 90 | 91 |
| 91 // Schedule an animation that can run immediately. This is the trivial case and | 92 // Schedule an animation that can run immediately. This is the trivial case and |
| 92 // should result in the animation being started immediately. | 93 // should result in the animation being started immediately. |
| 93 TEST(LayerAnimatorTest, ScheduleAnimationThatCanRunImmediately) { | 94 TEST(LayerAnimatorTest, ScheduleAnimationThatCanRunImmediately) { |
| 94 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 95 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 95 AnimationContainerElement* element = animator.get(); | 96 AnimationContainerElement* element = animator.get(); |
| 96 animator->set_disable_timer_for_test(true); | 97 animator->set_disable_timer_for_test(true); |
| 97 DummyLayerAnimationDelegate delegate; | 98 TestLayerAnimationDelegate delegate; |
| 98 animator->SetDelegate(&delegate); | 99 animator->SetDelegate(&delegate); |
| 99 | 100 |
| 100 double start_opacity(0.0); | 101 double start_opacity(0.0); |
| 101 double middle_opacity(0.5); | 102 double middle_opacity(0.5); |
| 102 double target_opacity(1.0); | 103 double target_opacity(1.0); |
| 103 | 104 |
| 104 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 105 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 105 | 106 |
| 106 delegate.SetOpacityFromAnimation(start_opacity); | 107 delegate.SetOpacityFromAnimation(start_opacity); |
| 107 | 108 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 124 EXPECT_FALSE(animator->is_animating()); | 125 EXPECT_FALSE(animator->is_animating()); |
| 125 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); | 126 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); |
| 126 } | 127 } |
| 127 | 128 |
| 128 // Schedule two animations on separate properties. Both animations should | 129 // Schedule two animations on separate properties. Both animations should |
| 129 // start immediately and should progress in lock step. | 130 // start immediately and should progress in lock step. |
| 130 TEST(LayerAnimatorTest, ScheduleTwoAnimationsThatCanRunImmediately) { | 131 TEST(LayerAnimatorTest, ScheduleTwoAnimationsThatCanRunImmediately) { |
| 131 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 132 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 132 AnimationContainerElement* element = animator.get(); | 133 AnimationContainerElement* element = animator.get(); |
| 133 animator->set_disable_timer_for_test(true); | 134 animator->set_disable_timer_for_test(true); |
| 134 DummyLayerAnimationDelegate delegate; | 135 TestLayerAnimationDelegate delegate; |
| 135 animator->SetDelegate(&delegate); | 136 animator->SetDelegate(&delegate); |
| 136 | 137 |
| 137 double start_opacity(0.0); | 138 double start_opacity(0.0); |
| 138 double middle_opacity(0.5); | 139 double middle_opacity(0.5); |
| 139 double target_opacity(1.0); | 140 double target_opacity(1.0); |
| 140 | 141 |
| 141 gfx::Rect start_bounds, target_bounds, middle_bounds; | 142 gfx::Rect start_bounds, target_bounds, middle_bounds; |
| 142 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50); | 143 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50); |
| 143 start_bounds.set_x(-90); | 144 start_bounds.set_x(-90); |
| 144 target_bounds.set_x(90); | 145 target_bounds.set_x(90); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 174 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); | 175 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); |
| 175 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); | 176 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); |
| 176 } | 177 } |
| 177 | 178 |
| 178 // Schedule two animations on the same property. In this case, the two | 179 // Schedule two animations on the same property. In this case, the two |
| 179 // animations should run one after another. | 180 // animations should run one after another. |
| 180 TEST(LayerAnimatorTest, ScheduleTwoAnimationsOnSameProperty) { | 181 TEST(LayerAnimatorTest, ScheduleTwoAnimationsOnSameProperty) { |
| 181 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 182 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 182 AnimationContainerElement* element = animator.get(); | 183 AnimationContainerElement* element = animator.get(); |
| 183 animator->set_disable_timer_for_test(true); | 184 animator->set_disable_timer_for_test(true); |
| 184 DummyLayerAnimationDelegate delegate; | 185 TestLayerAnimationDelegate delegate; |
| 185 animator->SetDelegate(&delegate); | 186 animator->SetDelegate(&delegate); |
| 186 | 187 |
| 187 double start_opacity(0.0); | 188 double start_opacity(0.0); |
| 188 double middle_opacity(0.5); | 189 double middle_opacity(0.5); |
| 189 double target_opacity(1.0); | 190 double target_opacity(1.0); |
| 190 | 191 |
| 191 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 192 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 192 | 193 |
| 193 delegate.SetOpacityFromAnimation(start_opacity); | 194 delegate.SetOpacityFromAnimation(start_opacity); |
| 194 | 195 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 227 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
| 227 } | 228 } |
| 228 | 229 |
| 229 // Schedule [{o}, {o,b}, {b}] and ensure that {b} doesn't run right away. That | 230 // Schedule [{o}, {o,b}, {b}] and ensure that {b} doesn't run right away. That |
| 230 // is, ensure that all animations targetting a particular property are run in | 231 // is, ensure that all animations targetting a particular property are run in |
| 231 // order. | 232 // order. |
| 232 TEST(LayerAnimatorTest, ScheduleBlockedAnimation) { | 233 TEST(LayerAnimatorTest, ScheduleBlockedAnimation) { |
| 233 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 234 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 234 AnimationContainerElement* element = animator.get(); | 235 AnimationContainerElement* element = animator.get(); |
| 235 animator->set_disable_timer_for_test(true); | 236 animator->set_disable_timer_for_test(true); |
| 236 DummyLayerAnimationDelegate delegate; | 237 TestLayerAnimationDelegate delegate; |
| 237 animator->SetDelegate(&delegate); | 238 animator->SetDelegate(&delegate); |
| 238 | 239 |
| 239 double start_opacity(0.0); | 240 double start_opacity(0.0); |
| 240 double middle_opacity(0.5); | 241 double middle_opacity(0.5); |
| 241 double target_opacity(1.0); | 242 double target_opacity(1.0); |
| 242 | 243 |
| 243 gfx::Rect start_bounds, target_bounds, middle_bounds; | 244 gfx::Rect start_bounds, target_bounds, middle_bounds; |
| 244 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50); | 245 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50); |
| 245 start_bounds.set_x(-90); | 246 start_bounds.set_x(-90); |
| 246 target_bounds.set_x(90); | 247 target_bounds.set_x(90); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); | 305 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); |
| 305 } | 306 } |
| 306 | 307 |
| 307 // Schedule {o} and then schedule {o} and {b} together. In this case, since | 308 // Schedule {o} and then schedule {o} and {b} together. In this case, since |
| 308 // ScheduleTogether is being used, the bounds animation should not start until | 309 // ScheduleTogether is being used, the bounds animation should not start until |
| 309 // the second opacity animation starts. | 310 // the second opacity animation starts. |
| 310 TEST(LayerAnimatorTest, ScheduleTogether) { | 311 TEST(LayerAnimatorTest, ScheduleTogether) { |
| 311 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 312 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 312 AnimationContainerElement* element = animator.get(); | 313 AnimationContainerElement* element = animator.get(); |
| 313 animator->set_disable_timer_for_test(true); | 314 animator->set_disable_timer_for_test(true); |
| 314 DummyLayerAnimationDelegate delegate; | 315 TestLayerAnimationDelegate delegate; |
| 315 animator->SetDelegate(&delegate); | 316 animator->SetDelegate(&delegate); |
| 316 | 317 |
| 317 double start_opacity(0.0); | 318 double start_opacity(0.0); |
| 318 double target_opacity(1.0); | 319 double target_opacity(1.0); |
| 319 | 320 |
| 320 gfx::Rect start_bounds, target_bounds, middle_bounds; | 321 gfx::Rect start_bounds, target_bounds, middle_bounds; |
| 321 start_bounds = target_bounds = gfx::Rect(0, 0, 50, 50); | 322 start_bounds = target_bounds = gfx::Rect(0, 0, 50, 50); |
| 322 start_bounds.set_x(-90); | 323 start_bounds.set_x(-90); |
| 323 target_bounds.set_x(90); | 324 target_bounds.set_x(90); |
| 324 | 325 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 358 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
| 358 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); | 359 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); |
| 359 } | 360 } |
| 360 | 361 |
| 361 // Start animation (that can run immediately). This is the trivial case (see | 362 // Start animation (that can run immediately). This is the trivial case (see |
| 362 // the trival case for ScheduleAnimation). | 363 // the trival case for ScheduleAnimation). |
| 363 TEST(LayerAnimatorTest, StartAnimationThatCanRunImmediately) { | 364 TEST(LayerAnimatorTest, StartAnimationThatCanRunImmediately) { |
| 364 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 365 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 365 AnimationContainerElement* element = animator.get(); | 366 AnimationContainerElement* element = animator.get(); |
| 366 animator->set_disable_timer_for_test(true); | 367 animator->set_disable_timer_for_test(true); |
| 367 DummyLayerAnimationDelegate delegate; | 368 TestLayerAnimationDelegate delegate; |
| 368 animator->SetDelegate(&delegate); | 369 animator->SetDelegate(&delegate); |
| 369 | 370 |
| 370 double start_opacity(0.0); | 371 double start_opacity(0.0); |
| 371 double middle_opacity(0.5); | 372 double middle_opacity(0.5); |
| 372 double target_opacity(1.0); | 373 double target_opacity(1.0); |
| 373 | 374 |
| 374 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 375 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 375 | 376 |
| 376 delegate.SetOpacityFromAnimation(start_opacity); | 377 delegate.SetOpacityFromAnimation(start_opacity); |
| 377 | 378 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 392 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 393 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
| 393 | 394 |
| 394 EXPECT_FALSE(animator->is_animating()); | 395 EXPECT_FALSE(animator->is_animating()); |
| 395 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); | 396 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); |
| 396 } | 397 } |
| 397 | 398 |
| 398 // Preempt by immediately setting new target. | 399 // Preempt by immediately setting new target. |
| 399 TEST(LayerAnimatorTest, PreemptBySettingNewTarget) { | 400 TEST(LayerAnimatorTest, PreemptBySettingNewTarget) { |
| 400 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 401 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 401 animator->set_disable_timer_for_test(true); | 402 animator->set_disable_timer_for_test(true); |
| 402 DummyLayerAnimationDelegate delegate; | 403 TestLayerAnimationDelegate delegate; |
| 403 animator->SetDelegate(&delegate); | 404 animator->SetDelegate(&delegate); |
| 404 | 405 |
| 405 double start_opacity(0.0); | 406 double start_opacity(0.0); |
| 406 double target_opacity(1.0); | 407 double target_opacity(1.0); |
| 407 | 408 |
| 408 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 409 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 409 | 410 |
| 410 delegate.SetOpacityFromAnimation(start_opacity); | 411 delegate.SetOpacityFromAnimation(start_opacity); |
| 411 | 412 |
| 412 animator->set_preemption_strategy(LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); | 413 animator->set_preemption_strategy(LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); |
| 413 | 414 |
| 414 animator->StartAnimation( | 415 animator->StartAnimation( |
| 415 new LayerAnimationSequence( | 416 new LayerAnimationSequence( |
| 416 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); | 417 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); |
| 417 | 418 |
| 418 animator->StartAnimation( | 419 animator->StartAnimation( |
| 419 new LayerAnimationSequence( | 420 new LayerAnimationSequence( |
| 420 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); | 421 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); |
| 421 | 422 |
| 422 EXPECT_FALSE(animator->is_animating()); | 423 EXPECT_FALSE(animator->is_animating()); |
| 423 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 424 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
| 424 } | 425 } |
| 425 | 426 |
| 426 // Preempt by animating to new target. | 427 // Preempt by animating to new target. |
| 427 TEST(LayerAnimatorTest, PreemptByImmediatelyAnimatingToNewTarget) { | 428 TEST(LayerAnimatorTest, PreemptByImmediatelyAnimatingToNewTarget) { |
| 428 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 429 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 429 AnimationContainerElement* element = animator.get(); | 430 AnimationContainerElement* element = animator.get(); |
| 430 animator->set_disable_timer_for_test(true); | 431 animator->set_disable_timer_for_test(true); |
| 431 DummyLayerAnimationDelegate delegate; | 432 TestLayerAnimationDelegate delegate; |
| 432 animator->SetDelegate(&delegate); | 433 animator->SetDelegate(&delegate); |
| 433 | 434 |
| 434 double start_opacity(0.0); | 435 double start_opacity(0.0); |
| 435 double middle_opacity(0.5); | 436 double middle_opacity(0.5); |
| 436 double target_opacity(1.0); | 437 double target_opacity(1.0); |
| 437 | 438 |
| 438 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 439 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 439 | 440 |
| 440 delegate.SetOpacityFromAnimation(start_opacity); | 441 delegate.SetOpacityFromAnimation(start_opacity); |
| 441 | 442 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 | 474 |
| 474 EXPECT_FALSE(animator->is_animating()); | 475 EXPECT_FALSE(animator->is_animating()); |
| 475 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 476 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
| 476 } | 477 } |
| 477 | 478 |
| 478 // Preempt by enqueuing the new animation. | 479 // Preempt by enqueuing the new animation. |
| 479 TEST(LayerAnimatorTest, PreemptEnqueueNewAnimation) { | 480 TEST(LayerAnimatorTest, PreemptEnqueueNewAnimation) { |
| 480 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 481 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 481 AnimationContainerElement* element = animator.get(); | 482 AnimationContainerElement* element = animator.get(); |
| 482 animator->set_disable_timer_for_test(true); | 483 animator->set_disable_timer_for_test(true); |
| 483 DummyLayerAnimationDelegate delegate; | 484 TestLayerAnimationDelegate delegate; |
| 484 animator->SetDelegate(&delegate); | 485 animator->SetDelegate(&delegate); |
| 485 | 486 |
| 486 double start_opacity(0.0); | 487 double start_opacity(0.0); |
| 487 double middle_opacity(0.5); | 488 double middle_opacity(0.5); |
| 488 double target_opacity(1.0); | 489 double target_opacity(1.0); |
| 489 | 490 |
| 490 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 491 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 491 | 492 |
| 492 delegate.SetOpacityFromAnimation(start_opacity); | 493 delegate.SetOpacityFromAnimation(start_opacity); |
| 493 | 494 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 527 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
| 527 } | 528 } |
| 528 | 529 |
| 529 // Start an animation when there are sequences waiting in the queue. In this | 530 // Start an animation when there are sequences waiting in the queue. In this |
| 530 // case, all pending and running animations should be finished, and the new | 531 // case, all pending and running animations should be finished, and the new |
| 531 // animation started. | 532 // animation started. |
| 532 TEST(LayerAnimatorTest, PreemptyByReplacingQueuedAnimations) { | 533 TEST(LayerAnimatorTest, PreemptyByReplacingQueuedAnimations) { |
| 533 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 534 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 534 AnimationContainerElement* element = animator.get(); | 535 AnimationContainerElement* element = animator.get(); |
| 535 animator->set_disable_timer_for_test(true); | 536 animator->set_disable_timer_for_test(true); |
| 536 DummyLayerAnimationDelegate delegate; | 537 TestLayerAnimationDelegate delegate; |
| 537 animator->SetDelegate(&delegate); | 538 animator->SetDelegate(&delegate); |
| 538 | 539 |
| 539 double start_opacity(0.0); | 540 double start_opacity(0.0); |
| 540 double middle_opacity(0.5); | 541 double middle_opacity(0.5); |
| 541 double target_opacity(1.0); | 542 double target_opacity(1.0); |
| 542 | 543 |
| 543 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 544 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 544 | 545 |
| 545 delegate.SetOpacityFromAnimation(start_opacity); | 546 delegate.SetOpacityFromAnimation(start_opacity); |
| 546 | 547 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 | 582 |
| 582 EXPECT_FALSE(animator->is_animating()); | 583 EXPECT_FALSE(animator->is_animating()); |
| 583 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 584 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
| 584 } | 585 } |
| 585 | 586 |
| 586 // Test that cyclic sequences continue to animate. | 587 // Test that cyclic sequences continue to animate. |
| 587 TEST(LayerAnimatorTest, CyclicSequences) { | 588 TEST(LayerAnimatorTest, CyclicSequences) { |
| 588 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 589 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 589 AnimationContainerElement* element = animator.get(); | 590 AnimationContainerElement* element = animator.get(); |
| 590 animator->set_disable_timer_for_test(true); | 591 animator->set_disable_timer_for_test(true); |
| 591 DummyLayerAnimationDelegate delegate; | 592 TestLayerAnimationDelegate delegate; |
| 592 animator->SetDelegate(&delegate); | 593 animator->SetDelegate(&delegate); |
| 593 | 594 |
| 594 double start_opacity(0.0); | 595 double start_opacity(0.0); |
| 595 double target_opacity(1.0); | 596 double target_opacity(1.0); |
| 596 | 597 |
| 597 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 598 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 598 | 599 |
| 599 delegate.SetOpacityFromAnimation(start_opacity); | 600 delegate.SetOpacityFromAnimation(start_opacity); |
| 600 | 601 |
| 601 scoped_ptr<LayerAnimationSequence> sequence( | 602 scoped_ptr<LayerAnimationSequence> sequence( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000000001000)); | 637 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000000001000)); |
| 637 | 638 |
| 638 EXPECT_TRUE(animator->is_animating()); | 639 EXPECT_TRUE(animator->is_animating()); |
| 639 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); | 640 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); |
| 640 | 641 |
| 641 animator->StopAnimatingProperty(LayerAnimationElement::OPACITY); | 642 animator->StopAnimatingProperty(LayerAnimationElement::OPACITY); |
| 642 | 643 |
| 643 EXPECT_FALSE(animator->is_animating()); | 644 EXPECT_FALSE(animator->is_animating()); |
| 644 } | 645 } |
| 645 | 646 |
| 647 TEST(LayerAnimatorTest, AddObserverExplicit) { |
| 648 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 649 AnimationContainerElement* element = animator.get(); |
| 650 animator->set_disable_timer_for_test(true); |
| 651 TestLayerAnimationObserver observer; |
| 652 TestLayerAnimationDelegate delegate; |
| 653 animator->SetDelegate(&delegate); |
| 654 animator->AddObserver(&observer); |
| 655 |
| 656 EXPECT_TRUE(!observer.last_ended_sequence()); |
| 657 |
| 658 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 659 |
| 660 delegate.SetOpacityFromAnimation(0.0f); |
| 661 |
| 662 LayerAnimationSequence* sequence = new LayerAnimationSequence( |
| 663 LayerAnimationElement::CreateOpacityElement(1.0f, delta)); |
| 664 |
| 665 animator->StartAnimation(sequence); |
| 666 |
| 667 EXPECT_EQ(observer.last_scheduled_sequence(), sequence); |
| 668 |
| 669 base::TimeTicks start_time = animator->get_last_step_time_for_test(); |
| 670 |
| 671 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
| 672 |
| 673 EXPECT_EQ(observer.last_ended_sequence(), sequence); |
| 674 |
| 675 // |sequence| has been destroyed. Recreate it to test abort. |
| 676 sequence = new LayerAnimationSequence( |
| 677 LayerAnimationElement::CreateOpacityElement(1.0f, delta)); |
| 678 |
| 679 animator->StartAnimation(sequence); |
| 680 |
| 681 animator.reset(); |
| 682 |
| 683 EXPECT_EQ(observer.last_aborted_sequence(), sequence); |
| 684 } |
| 685 |
| 686 TEST(LayerAnimatorTest, AddObserverImplicit) { |
| 687 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 688 AnimationContainerElement* element = animator.get(); |
| 689 animator->set_disable_timer_for_test(true); |
| 690 TestLayerAnimationObserver observer; |
| 691 TestLayerAnimationDelegate delegate; |
| 692 animator->SetDelegate(&delegate); |
| 693 animator->AddObserver(&observer); |
| 694 |
| 695 // Should not end a sequence with the default animator. |
| 696 EXPECT_TRUE(!observer.last_ended_sequence()); |
| 697 animator->SetOpacity(1.0f); |
| 698 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 699 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
| 700 EXPECT_TRUE(!observer.last_ended_sequence()); |
| 701 |
| 702 TestLayerAnimationObserver scoped_observer; |
| 703 { |
| 704 LayerAnimator::ScopedSettings settings(animator.get()); |
| 705 settings.AddObserver(&scoped_observer); |
| 706 for (int i = 0; i < 2; ++i) { |
| 707 // reset the observer |
| 708 scoped_observer = TestLayerAnimationObserver(); |
| 709 EXPECT_TRUE(!scoped_observer.last_ended_sequence()); |
| 710 animator->SetOpacity(1.0f); |
| 711 start_time = animator->get_last_step_time_for_test(); |
| 712 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
| 713 EXPECT_FALSE(!scoped_observer.last_ended_sequence()); |
| 714 } |
| 715 } |
| 716 |
| 717 scoped_observer = TestLayerAnimationObserver(); |
| 718 EXPECT_TRUE(!scoped_observer.last_ended_sequence()); |
| 719 animator->SetOpacity(1.0f); |
| 720 start_time = base::TimeTicks::Now(); |
| 721 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
| 722 EXPECT_TRUE(!scoped_observer.last_ended_sequence()); |
| 723 } |
| 724 |
| 646 } // namespace | 725 } // namespace |
| 647 | 726 |
| 648 } // namespace ui | 727 } // namespace ui |
| OLD | NEW |