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_animation_element.h" | 5 #include "ui/gfx/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/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" |
14 #include "ui/gfx/compositor/layer_animation_delegate.h" | 15 #include "ui/gfx/compositor/layer_animation_delegate.h" |
15 #include "ui/gfx/compositor/test_utils.h" | 16 #include "ui/gfx/compositor/test_utils.h" |
16 #include "ui/gfx/compositor/test_layer_animation_delegate.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 DummyLayerAnimationDelegate delegate; |
26 Transform start_transform, target_transform, middle_transform; | 26 Transform start_transform, target_transform, middle_transform; |
27 start_transform.SetRotate(-90); | 27 start_transform.SetRotate(-90); |
28 target_transform.SetRotate(90); | 28 target_transform.SetRotate(90); |
29 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 29 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
30 | 30 |
31 scoped_ptr<LayerAnimationElement> element( | 31 scoped_ptr<LayerAnimationElement> element( |
32 LayerAnimationElement::CreateTransformElement(target_transform, delta)); | 32 LayerAnimationElement::CreateTransformElement(target_transform, delta)); |
33 | 33 |
34 for (int i = 0; i < 2; ++i) { | 34 for (int i = 0; i < 2; ++i) { |
35 delegate.SetTransformFromAnimation(start_transform); | 35 delegate.SetTransformFromAnimation(start_transform); |
36 element->Progress(0.0, &delegate); | 36 element->Progress(0.0, &delegate); |
37 CheckApproximatelyEqual(start_transform, | 37 CheckApproximatelyEqual(start_transform, |
38 delegate.GetTransformForAnimation()); | 38 delegate.GetTransformForAnimation()); |
39 element->Progress(0.5, &delegate); | 39 element->Progress(0.5, &delegate); |
40 CheckApproximatelyEqual(middle_transform, | 40 CheckApproximatelyEqual(middle_transform, |
41 delegate.GetTransformForAnimation()); | 41 delegate.GetTransformForAnimation()); |
42 element->Progress(1.0, &delegate); | 42 element->Progress(1.0, &delegate); |
43 CheckApproximatelyEqual(target_transform, | 43 CheckApproximatelyEqual(target_transform, |
44 delegate.GetTransformForAnimation()); | 44 delegate.GetTransformForAnimation()); |
45 } | 45 } |
46 | 46 |
| 47 LayerAnimationElement::TargetValue target_value; |
| 48 element->GetTargetValue(&target_value); |
| 49 CheckApproximatelyEqual(target_transform, target_value.transform); |
| 50 |
47 EXPECT_EQ(delta, element->duration()); | 51 EXPECT_EQ(delta, element->duration()); |
48 } | 52 } |
49 | 53 |
50 // Check that the bounds element progresses the delegate as expected and | 54 // Check that the bounds element progresses the delegate as expected and |
51 // that the element can be reused after it completes. | 55 // that the element can be reused after it completes. |
52 TEST(LayerAnimationElementTest, BoundsElement) { | 56 TEST(LayerAnimationElementTest, BoundsElement) { |
53 TestLayerAnimationDelegate delegate; | 57 DummyLayerAnimationDelegate delegate; |
54 gfx::Rect start, target, middle; | 58 gfx::Rect start, target, middle; |
55 start = target = middle = gfx::Rect(0, 0, 50, 50); | 59 start = target = middle = gfx::Rect(0, 0, 50, 50); |
56 start.set_x(-90); | 60 start.set_x(-90); |
57 target.set_x(90); | 61 target.set_x(90); |
58 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 62 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
59 | 63 |
60 scoped_ptr<LayerAnimationElement> element( | 64 scoped_ptr<LayerAnimationElement> element( |
61 LayerAnimationElement::CreateBoundsElement(target, delta)); | 65 LayerAnimationElement::CreateBoundsElement(target, delta)); |
62 | 66 |
63 for (int i = 0; i < 2; ++i) { | 67 for (int i = 0; i < 2; ++i) { |
64 delegate.SetBoundsFromAnimation(start); | 68 delegate.SetBoundsFromAnimation(start); |
65 element->Progress(0.0, &delegate); | 69 element->Progress(0.0, &delegate); |
66 CheckApproximatelyEqual(start, delegate.GetBoundsForAnimation()); | 70 CheckApproximatelyEqual(start, delegate.GetBoundsForAnimation()); |
67 element->Progress(0.5, &delegate); | 71 element->Progress(0.5, &delegate); |
68 CheckApproximatelyEqual(middle, delegate.GetBoundsForAnimation()); | 72 CheckApproximatelyEqual(middle, delegate.GetBoundsForAnimation()); |
69 element->Progress(1.0, &delegate); | 73 element->Progress(1.0, &delegate); |
70 CheckApproximatelyEqual(target, delegate.GetBoundsForAnimation()); | 74 CheckApproximatelyEqual(target, delegate.GetBoundsForAnimation()); |
71 } | 75 } |
72 | 76 |
| 77 LayerAnimationElement::TargetValue target_value; |
| 78 element->GetTargetValue(&target_value); |
| 79 CheckApproximatelyEqual(target, target_value.bounds); |
| 80 |
73 EXPECT_EQ(delta, element->duration()); | 81 EXPECT_EQ(delta, element->duration()); |
74 } | 82 } |
75 | 83 |
76 // Check that the opacity element progresses the delegate as expected and | 84 // Check that the opacity element progresses the delegate as expected and |
77 // that the element can be reused after it completes. | 85 // that the element can be reused after it completes. |
78 TEST(LayerAnimationElementTest, OpacityElement) { | 86 TEST(LayerAnimationElementTest, OpacityElement) { |
79 TestLayerAnimationDelegate delegate; | 87 DummyLayerAnimationDelegate delegate; |
80 float start = 0.0; | 88 float start = 0.0; |
81 float middle = 0.5; | 89 float middle = 0.5; |
82 float target = 1.0; | 90 float target = 1.0; |
83 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 91 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
84 scoped_ptr<LayerAnimationElement> element( | 92 scoped_ptr<LayerAnimationElement> element( |
85 LayerAnimationElement::CreateOpacityElement(target, delta)); | 93 LayerAnimationElement::CreateOpacityElement(target, delta)); |
86 | 94 |
87 for (int i = 0; i < 2; ++i) { | 95 for (int i = 0; i < 2; ++i) { |
88 delegate.SetOpacityFromAnimation(start); | 96 delegate.SetOpacityFromAnimation(start); |
89 element->Progress(0.0, &delegate); | 97 element->Progress(0.0, &delegate); |
90 EXPECT_FLOAT_EQ(start, delegate.GetOpacityForAnimation()); | 98 EXPECT_FLOAT_EQ(start, delegate.GetOpacityForAnimation()); |
91 element->Progress(0.5, &delegate); | 99 element->Progress(0.5, &delegate); |
92 EXPECT_FLOAT_EQ(middle, delegate.GetOpacityForAnimation()); | 100 EXPECT_FLOAT_EQ(middle, delegate.GetOpacityForAnimation()); |
93 element->Progress(1.0, &delegate); | 101 element->Progress(1.0, &delegate); |
94 EXPECT_FLOAT_EQ(target, delegate.GetOpacityForAnimation()); | 102 EXPECT_FLOAT_EQ(target, delegate.GetOpacityForAnimation()); |
95 } | 103 } |
96 | 104 |
| 105 LayerAnimationElement::TargetValue target_value; |
| 106 element->GetTargetValue(&target_value); |
| 107 EXPECT_FLOAT_EQ(target, target_value.opacity); |
| 108 |
97 EXPECT_EQ(delta, element->duration()); | 109 EXPECT_EQ(delta, element->duration()); |
98 } | 110 } |
99 | 111 |
100 // Check that the pause element progresses the delegate as expected and | 112 // Check that the pause element progresses the delegate as expected and |
101 // that the element can be reused after it completes. | 113 // that the element can be reused after it completes. |
102 TEST(LayerAnimationElementTest, PauseElement) { | 114 TEST(LayerAnimationElementTest, PauseElement) { |
103 LayerAnimationElement::AnimatableProperties properties; | 115 LayerAnimationElement::AnimatableProperties properties; |
104 properties.insert(LayerAnimationElement::TRANSFORM); | 116 properties.insert(LayerAnimationElement::TRANSFORM); |
105 properties.insert(LayerAnimationElement::BOUNDS); | 117 properties.insert(LayerAnimationElement::BOUNDS); |
106 properties.insert(LayerAnimationElement::OPACITY); | 118 properties.insert(LayerAnimationElement::OPACITY); |
107 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 119 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
108 | 120 |
109 scoped_ptr<LayerAnimationElement> element( | 121 scoped_ptr<LayerAnimationElement> element( |
110 LayerAnimationElement::CreatePauseElement(properties, delta)); | 122 LayerAnimationElement::CreatePauseElement(properties, delta)); |
111 | 123 |
112 TestLayerAnimationDelegate delegate; | 124 DummyLayerAnimationDelegate delegate; |
113 TestLayerAnimationDelegate copy = delegate; | 125 DummyLayerAnimationDelegate copy = delegate; |
114 | 126 |
115 element->Progress(1.0, &delegate); | 127 element->Progress(1.0, &delegate); |
116 | 128 |
117 // Nothing should have changed. | 129 // Nothing should have changed. |
118 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), | 130 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), |
119 copy.GetBoundsForAnimation()); | 131 copy.GetBoundsForAnimation()); |
120 CheckApproximatelyEqual(delegate.GetTransformForAnimation(), | 132 CheckApproximatelyEqual(delegate.GetTransformForAnimation(), |
121 copy.GetTransformForAnimation()); | 133 copy.GetTransformForAnimation()); |
122 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), | 134 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), |
123 copy.GetOpacityForAnimation()); | 135 copy.GetOpacityForAnimation()); |
124 | 136 |
125 // Pause should last for |delta|. | 137 // Pause should last for |delta|. |
126 EXPECT_EQ(delta, element->duration()); | 138 EXPECT_EQ(delta, element->duration()); |
127 } | 139 } |
128 | 140 |
129 } // namespace | 141 } // namespace |
130 | 142 |
131 } // namespace ui | 143 } // namespace ui |
OLD | NEW |