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/time.h" | 10 #include "base/time/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/scoped_animation_duration_scale_mode.h" |
13 #include "ui/compositor/test/test_layer_animation_delegate.h" | 14 #include "ui/compositor/test/test_layer_animation_delegate.h" |
14 #include "ui/compositor/test/test_utils.h" | 15 #include "ui/compositor/test/test_utils.h" |
15 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/rect.h" |
16 #include "ui/gfx/transform.h" | 17 #include "ui/gfx/transform.h" |
17 | 18 |
18 namespace ui { | 19 namespace ui { |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 // Check that the transformation element progresses the delegate as expected and | 23 // Check that the transformation element progresses the delegate as expected and |
23 // that the element can be reused after it completes. | 24 // that the element can be reused after it completes. |
24 TEST(LayerAnimationElementTest, TransformElement) { | 25 TEST(LayerAnimationElementTest, TransformElement) { |
25 TestLayerAnimationDelegate delegate; | 26 TestLayerAnimationDelegate delegate; |
26 gfx::Transform start_transform, target_transform, middle_transform; | 27 gfx::Transform start_transform, target_transform; |
27 start_transform.Rotate(-30.0); | 28 start_transform.Rotate(-30.0); |
28 target_transform.Rotate(30.0); | 29 target_transform.Rotate(30.0); |
29 base::TimeTicks start_time; | 30 base::TimeTicks start_time; |
30 base::TimeTicks effective_start_time; | 31 base::TimeTicks effective_start_time; |
31 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 32 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
32 | 33 |
33 scoped_ptr<LayerAnimationElement> element( | 34 scoped_ptr<LayerAnimationElement> element( |
34 LayerAnimationElement::CreateTransformElement(target_transform, delta)); | 35 LayerAnimationElement::CreateTransformElement(target_transform, delta)); |
35 element->set_animation_group_id(1); | 36 element->set_animation_group_id(1); |
36 | 37 |
(...skipping 21 matching lines...) Expand all Loading... |
58 EXPECT_FLOAT_EQ(1.0, element->last_progressed_fraction()); | 59 EXPECT_FLOAT_EQ(1.0, element->last_progressed_fraction()); |
59 CheckApproximatelyEqual(target_transform, | 60 CheckApproximatelyEqual(target_transform, |
60 delegate.GetTransformForAnimation()); | 61 delegate.GetTransformForAnimation()); |
61 } | 62 } |
62 | 63 |
63 LayerAnimationElement::TargetValue target_value(&delegate); | 64 LayerAnimationElement::TargetValue target_value(&delegate); |
64 element->GetTargetValue(&target_value); | 65 element->GetTargetValue(&target_value); |
65 CheckApproximatelyEqual(target_transform, target_value.transform); | 66 CheckApproximatelyEqual(target_transform, target_value.transform); |
66 } | 67 } |
67 | 68 |
| 69 // Ensures that duration is copied correctly. |
| 70 TEST(LayerAnimationElementTest, InverseElementDurationNoScale) { |
| 71 gfx::Transform transform; |
| 72 base::TimeDelta delta; |
| 73 |
| 74 scoped_ptr<LayerAnimationElement> base_element( |
| 75 LayerAnimationElement::CreateTransformElement(transform, delta)); |
| 76 |
| 77 scoped_ptr<LayerAnimationElement> inverse_element( |
| 78 LayerAnimationElement::CreateInverseTransformElement(transform, |
| 79 base_element.get())); |
| 80 EXPECT_EQ(base_element->duration(), inverse_element->duration()); |
| 81 } |
| 82 |
| 83 // Ensures that duration is copied correctly and not double scaled. |
| 84 TEST(LayerAnimationElementTest, InverseElementDurationScaled) { |
| 85 gfx::Transform transform; |
| 86 base::TimeDelta delta; |
| 87 |
| 88 ScopedAnimationDurationScaleMode faster_duration( |
| 89 ScopedAnimationDurationScaleMode::FAST_DURATION); |
| 90 scoped_ptr<LayerAnimationElement> base_element( |
| 91 LayerAnimationElement::CreateTransformElement(transform, delta)); |
| 92 |
| 93 scoped_ptr<LayerAnimationElement> inverse_element( |
| 94 LayerAnimationElement::CreateInverseTransformElement(transform, |
| 95 base_element.get())); |
| 96 EXPECT_EQ(base_element->duration(), inverse_element->duration()); |
| 97 } |
| 98 |
68 // Check that the bounds element progresses the delegate as expected and | 99 // Check that the bounds element progresses the delegate as expected and |
69 // that the element can be reused after it completes. | 100 // that the element can be reused after it completes. |
70 TEST(LayerAnimationElementTest, BoundsElement) { | 101 TEST(LayerAnimationElementTest, BoundsElement) { |
71 TestLayerAnimationDelegate delegate; | 102 TestLayerAnimationDelegate delegate; |
72 gfx::Rect start, target, middle; | 103 gfx::Rect start, target, middle; |
73 start = target = middle = gfx::Rect(0, 0, 50, 50); | 104 start = target = middle = gfx::Rect(0, 0, 50, 50); |
74 start.set_x(-90); | 105 start.set_x(-90); |
75 target.set_x(90); | 106 target.set_x(90); |
76 base::TimeTicks start_time; | 107 base::TimeTicks start_time; |
77 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 108 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 element->Abort(&delegate); | 396 element->Abort(&delegate); |
366 target_transform.Blend(start_transform, | 397 target_transform.Blend(start_transform, |
367 Tween::CalculateValue(tween_type, 0.5)); | 398 Tween::CalculateValue(tween_type, 0.5)); |
368 CheckApproximatelyEqual(target_transform, | 399 CheckApproximatelyEqual(target_transform, |
369 delegate.GetTransformForAnimation()); | 400 delegate.GetTransformForAnimation()); |
370 } | 401 } |
371 | 402 |
372 } // namespace | 403 } // namespace |
373 | 404 |
374 } // namespace ui | 405 } // namespace ui |
OLD | NEW |