| 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_animation_element.h" | 5 #include "ui/compositor/layer_animation_element.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/compositor/layer_animation_delegate.h" | 12 #include "ui/compositor/layer_animation_delegate.h" |
| 13 #include "ui/compositor/test/test_layer_animation_delegate.h" | 13 #include "ui/compositor/test/test_layer_animation_delegate.h" |
| 14 #include "ui/compositor/test/test_utils.h" | 14 #include "ui/compositor/test/test_utils.h" |
| 15 #include "ui/gfx/rect.h" | 15 #include "ui/gfx/rect.h" |
| 16 #include "ui/gfx/transform.h" | 16 #include "ui/gfx/transform.h" |
| 17 | 17 |
| 18 namespace ui { | 18 namespace ui { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 // Check that the transformation element progresses the delegate as expected and | 22 // Check that the transformation element progresses the delegate as expected and |
| 23 // that the element can be reused after it completes. | 23 // that the element can be reused after it completes. |
| 24 TEST(LayerAnimationElementTest, TransformElement) { | 24 TEST(LayerAnimationElementTest, TransformElement) { |
| 25 TestLayerAnimationDelegate delegate; | 25 TestLayerAnimationDelegate delegate; |
| 26 gfx::Transform start_transform, target_transform, middle_transform; | 26 gfx::Transform start_transform, target_transform, middle_transform; |
| 27 start_transform.Rotate(-30.0); | 27 start_transform.Rotate(-30.0); |
| 28 target_transform.Rotate(30.0); | 28 target_transform.Rotate(30.0); |
| 29 base::TimeTicks start_time; | 29 base::TimeTicks start_time; |
| 30 base::TimeTicks effective_start_time; |
| 30 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 31 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 31 | 32 |
| 32 scoped_ptr<LayerAnimationElement> element( | 33 scoped_ptr<LayerAnimationElement> element( |
| 33 LayerAnimationElement::CreateTransformElement(target_transform, delta)); | 34 LayerAnimationElement::CreateTransformElement(target_transform, delta)); |
| 35 element->set_animation_group_id(1); |
| 34 | 36 |
| 35 for (int i = 0; i < 2; ++i) { | 37 for (int i = 0; i < 2; ++i) { |
| 36 start_time += delta; | 38 start_time = effective_start_time + delta; |
| 37 element->set_requested_start_time(start_time); | 39 element->set_requested_start_time(start_time); |
| 38 delegate.SetTransformFromAnimation(start_transform); | 40 delegate.SetTransformFromAnimation(start_transform); |
| 39 element->Progress(start_time, &delegate); | 41 element->Progress(start_time, &delegate); |
| 40 CheckApproximatelyEqual(start_transform, | 42 CheckApproximatelyEqual(start_transform, |
| 41 delegate.GetTransformForAnimation()); | 43 delegate.GetTransformForAnimation()); |
| 42 element->Progress(start_time + delta/2, &delegate); | 44 effective_start_time = start_time + delta; |
| 43 CheckApproximatelyEqual(middle_transform, | 45 element->set_effective_start_time(effective_start_time); |
| 44 delegate.GetTransformForAnimation()); | 46 element->Progress(effective_start_time, &delegate); |
| 47 EXPECT_FLOAT_EQ(0.0, element->last_progressed_fraction()); |
| 48 element->Progress(effective_start_time + delta/2, &delegate); |
| 49 EXPECT_FLOAT_EQ(0.5, element->last_progressed_fraction()); |
| 45 | 50 |
| 46 base::TimeDelta element_duration; | 51 base::TimeDelta element_duration; |
| 47 EXPECT_TRUE(element->IsFinished(start_time + delta, &element_duration)); | 52 EXPECT_TRUE(element->IsFinished(effective_start_time + delta, |
| 48 EXPECT_EQ(delta, element_duration); | 53 &element_duration)); |
| 54 EXPECT_EQ(2 * delta, element_duration); |
| 49 | 55 |
| 50 element->Progress(start_time + delta, &delegate); | 56 element->Progress(effective_start_time + delta, &delegate); |
| 57 EXPECT_FLOAT_EQ(1.0, element->last_progressed_fraction()); |
| 51 CheckApproximatelyEqual(target_transform, | 58 CheckApproximatelyEqual(target_transform, |
| 52 delegate.GetTransformForAnimation()); | 59 delegate.GetTransformForAnimation()); |
| 53 } | 60 } |
| 54 | 61 |
| 55 LayerAnimationElement::TargetValue target_value(&delegate); | 62 LayerAnimationElement::TargetValue target_value(&delegate); |
| 56 element->GetTargetValue(&target_value); | 63 element->GetTargetValue(&target_value); |
| 57 CheckApproximatelyEqual(target_transform, target_value.transform); | 64 CheckApproximatelyEqual(target_transform, target_value.transform); |
| 58 } | 65 } |
| 59 | 66 |
| 60 // Check that the bounds element progresses the delegate as expected and | 67 // Check that the bounds element progresses the delegate as expected and |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 copy.GetOpacityForAnimation()); | 280 copy.GetOpacityForAnimation()); |
| 274 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), | 281 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), |
| 275 copy.GetBrightnessForAnimation()); | 282 copy.GetBrightnessForAnimation()); |
| 276 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), | 283 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), |
| 277 copy.GetGrayscaleForAnimation()); | 284 copy.GetGrayscaleForAnimation()); |
| 278 } | 285 } |
| 279 | 286 |
| 280 } // namespace | 287 } // namespace |
| 281 | 288 |
| 282 } // namespace ui | 289 } // namespace ui |
| OLD | NEW |