| 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/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "ui/compositor/layer.h" | 13 #include "ui/compositor/layer.h" |
| 14 #include "ui/compositor/layer_animation_delegate.h" | 14 #include "ui/compositor/layer_animation_delegate.h" |
| 15 #include "ui/compositor/layer_animation_element.h" | 15 #include "ui/compositor/layer_animation_element.h" |
| 16 #include "ui/compositor/layer_animation_sequence.h" | 16 #include "ui/compositor/layer_animation_sequence.h" |
| 17 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 17 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
| 18 #include "ui/compositor/scoped_layer_animation_settings.h" | 18 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 19 #include "ui/compositor/test/layer_animator_test_controller.h" | 19 #include "ui/compositor/test/layer_animator_test_controller.h" |
| 20 #include "ui/compositor/test/test_layer_animation_delegate.h" | 20 #include "ui/compositor/test/test_layer_animation_delegate.h" |
| 21 #include "ui/compositor/test/test_layer_animation_observer.h" | 21 #include "ui/compositor/test/test_layer_animation_observer.h" |
| 22 #include "ui/compositor/test/test_utils.h" | 22 #include "ui/compositor/test/test_utils.h" |
| 23 #include "ui/gfx/frame_time.h" |
| 23 #include "ui/gfx/rect.h" | 24 #include "ui/gfx/rect.h" |
| 24 #include "ui/gfx/transform.h" | 25 #include "ui/gfx/transform.h" |
| 25 | 26 |
| 26 using gfx::AnimationContainerElement; | 27 using gfx::AnimationContainerElement; |
| 27 | 28 |
| 28 namespace ui { | 29 namespace ui { |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| 31 | 32 |
| 32 // Converts |color| to a string. Each component of the color is separated by a | 33 // Converts |color| to a string. Each component of the color is separated by a |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 | 162 |
| 162 // Checks that setting a property on an implicit animator causes an animation to | 163 // Checks that setting a property on an implicit animator causes an animation to |
| 163 // happen. | 164 // happen. |
| 164 TEST(LayerAnimatorTest, ImplicitAnimation) { | 165 TEST(LayerAnimatorTest, ImplicitAnimation) { |
| 165 scoped_refptr<LayerAnimator> animator( | 166 scoped_refptr<LayerAnimator> animator( |
| 166 LayerAnimator::CreateImplicitAnimator()); | 167 LayerAnimator::CreateImplicitAnimator()); |
| 167 AnimationContainerElement* element = animator.get(); | 168 AnimationContainerElement* element = animator.get(); |
| 168 animator->set_disable_timer_for_test(true); | 169 animator->set_disable_timer_for_test(true); |
| 169 TestLayerAnimationDelegate delegate; | 170 TestLayerAnimationDelegate delegate; |
| 170 animator->SetDelegate(&delegate); | 171 animator->SetDelegate(&delegate); |
| 171 base::TimeTicks now = base::TimeTicks::Now(); | 172 base::TimeTicks now = gfx::FrameTime::Now(); |
| 172 animator->SetBrightness(0.5); | 173 animator->SetBrightness(0.5); |
| 173 EXPECT_TRUE(animator->is_animating()); | 174 EXPECT_TRUE(animator->is_animating()); |
| 174 element->Step(now + base::TimeDelta::FromSeconds(1)); | 175 element->Step(now + base::TimeDelta::FromSeconds(1)); |
| 175 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), 0.5); | 176 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), 0.5); |
| 176 } | 177 } |
| 177 | 178 |
| 178 // Checks that if the animator is a default animator, that implicit animations | 179 // Checks that if the animator is a default animator, that implicit animations |
| 179 // are not started. | 180 // are not started. |
| 180 TEST(LayerAnimatorTest, NoImplicitAnimation) { | 181 TEST(LayerAnimatorTest, NoImplicitAnimation) { |
| 181 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 182 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| (...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1028 LayerAnimationElement::CreateGrayscaleElement(target_grayscale, | 1029 LayerAnimationElement::CreateGrayscaleElement(target_grayscale, |
| 1029 delta), | 1030 delta), |
| 1030 LayerAnimationElement::CreateBrightnessElement(target_brightness, | 1031 LayerAnimationElement::CreateBrightnessElement(target_brightness, |
| 1031 delta) | 1032 delta) |
| 1032 )); | 1033 )); |
| 1033 | 1034 |
| 1034 // If last step time was not set correctly, the resulting delta should be | 1035 // If last step time was not set correctly, the resulting delta should be |
| 1035 // miniscule (fractions of a millisecond). If set correctly, then the delta | 1036 // miniscule (fractions of a millisecond). If set correctly, then the delta |
| 1036 // should be enormous. Arbitrarily choosing 1 minute as the threshold, | 1037 // should be enormous. Arbitrarily choosing 1 minute as the threshold, |
| 1037 // though a much smaller value would probably have sufficed. | 1038 // though a much smaller value would probably have sufficed. |
| 1038 delta = base::TimeTicks::Now() - animator->last_step_time(); | 1039 delta = gfx::FrameTime::Now() - animator->last_step_time(); |
| 1039 EXPECT_GT(60.0, delta.InSecondsF()); | 1040 EXPECT_GT(60.0, delta.InSecondsF()); |
| 1040 } | 1041 } |
| 1041 | 1042 |
| 1042 //------------------------------------------------------- | 1043 //------------------------------------------------------- |
| 1043 // Preempt by immediately setting new target. | 1044 // Preempt by immediately setting new target. |
| 1044 TEST(LayerAnimatorTest, MultiPreemptBySettingNewTarget) { | 1045 TEST(LayerAnimatorTest, MultiPreemptBySettingNewTarget) { |
| 1045 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1046 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
| 1046 animator->set_disable_timer_for_test(true); | 1047 animator->set_disable_timer_for_test(true); |
| 1047 TestLayerAnimationDelegate delegate; | 1048 TestLayerAnimationDelegate delegate; |
| 1048 animator->SetDelegate(&delegate); | 1049 animator->SetDelegate(&delegate); |
| (...skipping 1414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2463 | 2464 |
| 2464 parent.SetTransform(parent_end); | 2465 parent.SetTransform(parent_end); |
| 2465 | 2466 |
| 2466 EXPECT_TRUE(child.GetAnimator()->is_animating()); | 2467 EXPECT_TRUE(child.GetAnimator()->is_animating()); |
| 2467 EXPECT_TRUE(child.GetTargetTransform().IsIdentity()) | 2468 EXPECT_TRUE(child.GetTargetTransform().IsIdentity()) |
| 2468 << child.GetTargetTransform().ToString(); | 2469 << child.GetTargetTransform().ToString(); |
| 2469 | 2470 |
| 2470 } | 2471 } |
| 2471 | 2472 |
| 2472 } // namespace ui | 2473 } // namespace ui |
| OLD | NEW |