OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "cc/keyframed_animation_curve.h" | 5 #include "cc/keyframed_animation_curve.h" |
6 | 6 |
| 7 #include "cc/transform_operations.h" |
7 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "third_party/WebKit/Source/Platform/chromium/public/WebTransformOperati
ons.h" | |
10 #include "third_party/WebKit/Source/Platform/chromium/public/WebTransformationMa
trix.h" | 10 #include "third_party/WebKit/Source/Platform/chromium/public/WebTransformationMa
trix.h" |
11 | 11 |
12 using WebKit::WebTransformationMatrix; | 12 using WebKit::WebTransformationMatrix; |
13 | 13 |
14 namespace cc { | 14 namespace cc { |
15 namespace { | 15 namespace { |
16 | 16 |
17 void expectTranslateX(double translateX, const WebTransformationMatrix& matrix) | 17 void expectTranslateX(double translateX, const WebTransformationMatrix& matrix) |
18 { | 18 { |
19 EXPECT_FLOAT_EQ(translateX, matrix.m41()); | 19 EXPECT_FLOAT_EQ(translateX, matrix.m41()); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 EXPECT_FLOAT_EQ(6, curve->getValue(1.5)); | 80 EXPECT_FLOAT_EQ(6, curve->getValue(1.5)); |
81 EXPECT_FLOAT_EQ(6, curve->getValue(2)); | 81 EXPECT_FLOAT_EQ(6, curve->getValue(2)); |
82 EXPECT_FLOAT_EQ(6, curve->getValue(3)); | 82 EXPECT_FLOAT_EQ(6, curve->getValue(3)); |
83 } | 83 } |
84 | 84 |
85 | 85 |
86 // Tests that a transform animation with one keyframe works as expected. | 86 // Tests that a transform animation with one keyframe works as expected. |
87 TEST(KeyframedAnimationCurveTest, OneTransformKeyframe) | 87 TEST(KeyframedAnimationCurveTest, OneTransformKeyframe) |
88 { | 88 { |
89 scoped_ptr<KeyframedTransformAnimationCurve> curve(KeyframedTransformAnimati
onCurve::create()); | 89 scoped_ptr<KeyframedTransformAnimationCurve> curve(KeyframedTransformAnimati
onCurve::create()); |
90 WebKit::WebTransformOperations operations; | 90 TransformOperations operations; |
91 operations.appendTranslate(2, 0, 0); | 91 operations.AppendTranslate(2, 0, 0); |
92 curve->addKeyframe(TransformKeyframe::create(0, operations, scoped_ptr<Timin
gFunction>())); | 92 curve->addKeyframe(TransformKeyframe::create(0, operations, scoped_ptr<Timin
gFunction>())); |
93 | 93 |
94 expectTranslateX(2, curve->getValue(-1)); | 94 expectTranslateX(2, curve->getValue(-1)); |
95 expectTranslateX(2, curve->getValue(0)); | 95 expectTranslateX(2, curve->getValue(0)); |
96 expectTranslateX(2, curve->getValue(0.5)); | 96 expectTranslateX(2, curve->getValue(0.5)); |
97 expectTranslateX(2, curve->getValue(1)); | 97 expectTranslateX(2, curve->getValue(1)); |
98 expectTranslateX(2, curve->getValue(2)); | 98 expectTranslateX(2, curve->getValue(2)); |
99 } | 99 } |
100 | 100 |
101 // Tests that a transform animation with two keyframes works as expected. | 101 // Tests that a transform animation with two keyframes works as expected. |
102 TEST(KeyframedAnimationCurveTest, TwoTransformKeyframe) | 102 TEST(KeyframedAnimationCurveTest, TwoTransformKeyframe) |
103 { | 103 { |
104 scoped_ptr<KeyframedTransformAnimationCurve> curve(KeyframedTransformAnimati
onCurve::create()); | 104 scoped_ptr<KeyframedTransformAnimationCurve> curve(KeyframedTransformAnimati
onCurve::create()); |
105 WebKit::WebTransformOperations operations1; | 105 TransformOperations operations1; |
106 operations1.appendTranslate(2, 0, 0); | 106 operations1.AppendTranslate(2, 0, 0); |
107 WebKit::WebTransformOperations operations2; | 107 TransformOperations operations2; |
108 operations2.appendTranslate(4, 0, 0); | 108 operations2.AppendTranslate(4, 0, 0); |
109 | 109 |
110 curve->addKeyframe(TransformKeyframe::create(0, operations1, scoped_ptr<Timi
ngFunction>())); | 110 curve->addKeyframe(TransformKeyframe::create(0, operations1, scoped_ptr<Timi
ngFunction>())); |
111 curve->addKeyframe(TransformKeyframe::create(1, operations2, scoped_ptr<Timi
ngFunction>())); | 111 curve->addKeyframe(TransformKeyframe::create(1, operations2, scoped_ptr<Timi
ngFunction>())); |
112 expectTranslateX(2, curve->getValue(-1)); | 112 expectTranslateX(2, curve->getValue(-1)); |
113 expectTranslateX(2, curve->getValue(0)); | 113 expectTranslateX(2, curve->getValue(0)); |
114 expectTranslateX(3, curve->getValue(0.5)); | 114 expectTranslateX(3, curve->getValue(0.5)); |
115 expectTranslateX(4, curve->getValue(1)); | 115 expectTranslateX(4, curve->getValue(1)); |
116 expectTranslateX(4, curve->getValue(2)); | 116 expectTranslateX(4, curve->getValue(2)); |
117 } | 117 } |
118 | 118 |
119 // Tests that a transform animation with three keyframes works as expected. | 119 // Tests that a transform animation with three keyframes works as expected. |
120 TEST(KeyframedAnimationCurveTest, ThreeTransformKeyframe) | 120 TEST(KeyframedAnimationCurveTest, ThreeTransformKeyframe) |
121 { | 121 { |
122 scoped_ptr<KeyframedTransformAnimationCurve> curve(KeyframedTransformAnimati
onCurve::create()); | 122 scoped_ptr<KeyframedTransformAnimationCurve> curve(KeyframedTransformAnimati
onCurve::create()); |
123 WebKit::WebTransformOperations operations1; | 123 TransformOperations operations1; |
124 operations1.appendTranslate(2, 0, 0); | 124 operations1.AppendTranslate(2, 0, 0); |
125 WebKit::WebTransformOperations operations2; | 125 TransformOperations operations2; |
126 operations2.appendTranslate(4, 0, 0); | 126 operations2.AppendTranslate(4, 0, 0); |
127 WebKit::WebTransformOperations operations3; | 127 TransformOperations operations3; |
128 operations3.appendTranslate(8, 0, 0); | 128 operations3.AppendTranslate(8, 0, 0); |
129 curve->addKeyframe(TransformKeyframe::create(0, operations1, scoped_ptr<Timi
ngFunction>())); | 129 curve->addKeyframe(TransformKeyframe::create(0, operations1, scoped_ptr<Timi
ngFunction>())); |
130 curve->addKeyframe(TransformKeyframe::create(1, operations2, scoped_ptr<Timi
ngFunction>())); | 130 curve->addKeyframe(TransformKeyframe::create(1, operations2, scoped_ptr<Timi
ngFunction>())); |
131 curve->addKeyframe(TransformKeyframe::create(2, operations3, scoped_ptr<Timi
ngFunction>())); | 131 curve->addKeyframe(TransformKeyframe::create(2, operations3, scoped_ptr<Timi
ngFunction>())); |
132 expectTranslateX(2, curve->getValue(-1)); | 132 expectTranslateX(2, curve->getValue(-1)); |
133 expectTranslateX(2, curve->getValue(0)); | 133 expectTranslateX(2, curve->getValue(0)); |
134 expectTranslateX(3, curve->getValue(0.5)); | 134 expectTranslateX(3, curve->getValue(0.5)); |
135 expectTranslateX(4, curve->getValue(1)); | 135 expectTranslateX(4, curve->getValue(1)); |
136 expectTranslateX(6, curve->getValue(1.5)); | 136 expectTranslateX(6, curve->getValue(1.5)); |
137 expectTranslateX(8, curve->getValue(2)); | 137 expectTranslateX(8, curve->getValue(2)); |
138 expectTranslateX(8, curve->getValue(3)); | 138 expectTranslateX(8, curve->getValue(3)); |
139 } | 139 } |
140 | 140 |
141 // Tests that a transform animation with multiple keys at a given time works san
ely. | 141 // Tests that a transform animation with multiple keys at a given time works san
ely. |
142 TEST(KeyframedAnimationCurveTest, RepeatedTransformKeyTimes) | 142 TEST(KeyframedAnimationCurveTest, RepeatedTransformKeyTimes) |
143 { | 143 { |
144 scoped_ptr<KeyframedTransformAnimationCurve> curve(KeyframedTransformAnimati
onCurve::create()); | 144 scoped_ptr<KeyframedTransformAnimationCurve> curve(KeyframedTransformAnimati
onCurve::create()); |
145 // A step function. | 145 // A step function. |
146 WebKit::WebTransformOperations operations1; | 146 TransformOperations operations1; |
147 operations1.appendTranslate(4, 0, 0); | 147 operations1.AppendTranslate(4, 0, 0); |
148 WebKit::WebTransformOperations operations2; | 148 TransformOperations operations2; |
149 operations2.appendTranslate(4, 0, 0); | 149 operations2.AppendTranslate(4, 0, 0); |
150 WebKit::WebTransformOperations operations3; | 150 TransformOperations operations3; |
151 operations3.appendTranslate(6, 0, 0); | 151 operations3.AppendTranslate(6, 0, 0); |
152 WebKit::WebTransformOperations operations4; | 152 TransformOperations operations4; |
153 operations4.appendTranslate(6, 0, 0); | 153 operations4.AppendTranslate(6, 0, 0); |
154 curve->addKeyframe(TransformKeyframe::create(0, operations1, scoped_ptr<Timi
ngFunction>())); | 154 curve->addKeyframe(TransformKeyframe::create(0, operations1, scoped_ptr<Timi
ngFunction>())); |
155 curve->addKeyframe(TransformKeyframe::create(1, operations2, scoped_ptr<Timi
ngFunction>())); | 155 curve->addKeyframe(TransformKeyframe::create(1, operations2, scoped_ptr<Timi
ngFunction>())); |
156 curve->addKeyframe(TransformKeyframe::create(1, operations3, scoped_ptr<Timi
ngFunction>())); | 156 curve->addKeyframe(TransformKeyframe::create(1, operations3, scoped_ptr<Timi
ngFunction>())); |
157 curve->addKeyframe(TransformKeyframe::create(2, operations4, scoped_ptr<Timi
ngFunction>())); | 157 curve->addKeyframe(TransformKeyframe::create(2, operations4, scoped_ptr<Timi
ngFunction>())); |
158 | 158 |
159 expectTranslateX(4, curve->getValue(-1)); | 159 expectTranslateX(4, curve->getValue(-1)); |
160 expectTranslateX(4, curve->getValue(0)); | 160 expectTranslateX(4, curve->getValue(0)); |
161 expectTranslateX(4, curve->getValue(0.5)); | 161 expectTranslateX(4, curve->getValue(0.5)); |
162 | 162 |
163 // There is a discontinuity at 1. Any value between 4 and 6 is valid. | 163 // There is a discontinuity at 1. Any value between 4 and 6 is valid. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 EXPECT_LT(0, curve->getValue(0.25)); | 196 EXPECT_LT(0, curve->getValue(0.25)); |
197 EXPECT_GT(0.25, curve->getValue(0.25)); | 197 EXPECT_GT(0.25, curve->getValue(0.25)); |
198 EXPECT_NEAR(curve->getValue(0.5), 0.5, 0.00015); | 198 EXPECT_NEAR(curve->getValue(0.5), 0.5, 0.00015); |
199 EXPECT_LT(0.75, curve->getValue(0.75)); | 199 EXPECT_LT(0.75, curve->getValue(0.75)); |
200 EXPECT_GT(1, curve->getValue(0.75)); | 200 EXPECT_GT(1, curve->getValue(0.75)); |
201 EXPECT_FLOAT_EQ(1, curve->getValue(1)); | 201 EXPECT_FLOAT_EQ(1, curve->getValue(1)); |
202 } | 202 } |
203 | 203 |
204 } // namespace | 204 } // namespace |
205 } // namespace cc | 205 } // namespace cc |
OLD | NEW |