OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "platform/animation/CompositorFloatAnimationCurve.h" | 5 #include "platform/animation/CompositorFloatAnimationCurve.h" |
6 | 6 |
7 #include "cc/animation/timing_function.h" | 7 #include "cc/animation/timing_function.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 EXPECT_NEAR(curve->getValue(0.5), 0.5, 0.00015); | 124 EXPECT_NEAR(curve->getValue(0.5), 0.5, 0.00015); |
125 EXPECT_LT(0.75, curve->getValue(0.75)); | 125 EXPECT_LT(0.75, curve->getValue(0.75)); |
126 EXPECT_GT(1, curve->getValue(0.75)); | 126 EXPECT_GT(1, curve->getValue(0.75)); |
127 EXPECT_FLOAT_EQ(1, curve->getValue(1)); | 127 EXPECT_FLOAT_EQ(1, curve->getValue(1)); |
128 } | 128 } |
129 | 129 |
130 // Tests that an ease timing function works as expected. | 130 // Tests that an ease timing function works as expected. |
131 TEST(WebFloatAnimationCurveTest, EaseTimingFunction) { | 131 TEST(WebFloatAnimationCurveTest, EaseTimingFunction) { |
132 std::unique_ptr<CompositorFloatAnimationCurve> curve = | 132 std::unique_ptr<CompositorFloatAnimationCurve> curve = |
133 CompositorFloatAnimationCurve::create(); | 133 CompositorFloatAnimationCurve::create(); |
134 curve->addKeyframe(CompositorFloatKeyframe( | 134 curve->addKeyframe( |
135 0, 0, *CubicBezierTimingFunction::preset( | 135 CompositorFloatKeyframe(0, 0, |
136 CubicBezierTimingFunction::EaseType::EASE))); | 136 *CubicBezierTimingFunction::preset( |
| 137 CubicBezierTimingFunction::EaseType::EASE))); |
137 curve->addKeyframe( | 138 curve->addKeyframe( |
138 CompositorFloatKeyframe(1, 1, *LinearTimingFunction::shared())); | 139 CompositorFloatKeyframe(1, 1, *LinearTimingFunction::shared())); |
139 | 140 |
140 std::unique_ptr<cc::TimingFunction> timingFunction( | 141 std::unique_ptr<cc::TimingFunction> timingFunction( |
141 cc::CubicBezierTimingFunction::CreatePreset( | 142 cc::CubicBezierTimingFunction::CreatePreset( |
142 CubicBezierTimingFunction::EaseType::EASE)); | 143 CubicBezierTimingFunction::EaseType::EASE)); |
143 for (int i = 0; i <= 4; ++i) { | 144 for (int i = 0; i <= 4; ++i) { |
144 const double time = i * 0.25; | 145 const double time = i * 0.25; |
145 EXPECT_FLOAT_EQ(timingFunction->GetValue(time), curve->getValue(time)); | 146 EXPECT_FLOAT_EQ(timingFunction->GetValue(time), curve->getValue(time)); |
146 } | 147 } |
(...skipping 12 matching lines...) Expand all Loading... |
159 const double time = i * 0.25; | 160 const double time = i * 0.25; |
160 EXPECT_FLOAT_EQ(time, curve->getValue(time)); | 161 EXPECT_FLOAT_EQ(time, curve->getValue(time)); |
161 } | 162 } |
162 } | 163 } |
163 | 164 |
164 // Tests that an ease in timing function works as expected. | 165 // Tests that an ease in timing function works as expected. |
165 TEST(WebFloatAnimationCurveTest, EaseInTimingFunction) { | 166 TEST(WebFloatAnimationCurveTest, EaseInTimingFunction) { |
166 std::unique_ptr<CompositorFloatAnimationCurve> curve = | 167 std::unique_ptr<CompositorFloatAnimationCurve> curve = |
167 CompositorFloatAnimationCurve::create(); | 168 CompositorFloatAnimationCurve::create(); |
168 curve->addKeyframe(CompositorFloatKeyframe( | 169 curve->addKeyframe(CompositorFloatKeyframe( |
169 0, 0, *CubicBezierTimingFunction::preset( | 170 0, 0, |
170 CubicBezierTimingFunction::EaseType::EASE_IN))); | 171 *CubicBezierTimingFunction::preset( |
| 172 CubicBezierTimingFunction::EaseType::EASE_IN))); |
171 curve->addKeyframe( | 173 curve->addKeyframe( |
172 CompositorFloatKeyframe(1, 1, *LinearTimingFunction::shared())); | 174 CompositorFloatKeyframe(1, 1, *LinearTimingFunction::shared())); |
173 | 175 |
174 std::unique_ptr<cc::TimingFunction> timingFunction( | 176 std::unique_ptr<cc::TimingFunction> timingFunction( |
175 cc::CubicBezierTimingFunction::CreatePreset( | 177 cc::CubicBezierTimingFunction::CreatePreset( |
176 CubicBezierTimingFunction::EaseType::EASE_IN)); | 178 CubicBezierTimingFunction::EaseType::EASE_IN)); |
177 for (int i = 0; i <= 4; ++i) { | 179 for (int i = 0; i <= 4; ++i) { |
178 const double time = i * 0.25; | 180 const double time = i * 0.25; |
179 EXPECT_FLOAT_EQ(timingFunction->GetValue(time), curve->getValue(time)); | 181 EXPECT_FLOAT_EQ(timingFunction->GetValue(time), curve->getValue(time)); |
180 } | 182 } |
181 } | 183 } |
182 | 184 |
183 // Tests that an ease in timing function works as expected. | 185 // Tests that an ease in timing function works as expected. |
184 TEST(WebFloatAnimationCurveTest, EaseOutTimingFunction) { | 186 TEST(WebFloatAnimationCurveTest, EaseOutTimingFunction) { |
185 std::unique_ptr<CompositorFloatAnimationCurve> curve = | 187 std::unique_ptr<CompositorFloatAnimationCurve> curve = |
186 CompositorFloatAnimationCurve::create(); | 188 CompositorFloatAnimationCurve::create(); |
187 curve->addKeyframe(CompositorFloatKeyframe( | 189 curve->addKeyframe(CompositorFloatKeyframe( |
188 0, 0, *CubicBezierTimingFunction::preset( | 190 0, 0, |
189 CubicBezierTimingFunction::EaseType::EASE_OUT))); | 191 *CubicBezierTimingFunction::preset( |
| 192 CubicBezierTimingFunction::EaseType::EASE_OUT))); |
190 curve->addKeyframe( | 193 curve->addKeyframe( |
191 CompositorFloatKeyframe(1, 1, *LinearTimingFunction::shared())); | 194 CompositorFloatKeyframe(1, 1, *LinearTimingFunction::shared())); |
192 | 195 |
193 std::unique_ptr<cc::TimingFunction> timingFunction( | 196 std::unique_ptr<cc::TimingFunction> timingFunction( |
194 cc::CubicBezierTimingFunction::CreatePreset( | 197 cc::CubicBezierTimingFunction::CreatePreset( |
195 CubicBezierTimingFunction::EaseType::EASE_OUT)); | 198 CubicBezierTimingFunction::EaseType::EASE_OUT)); |
196 for (int i = 0; i <= 4; ++i) { | 199 for (int i = 0; i <= 4; ++i) { |
197 const double time = i * 0.25; | 200 const double time = i * 0.25; |
198 EXPECT_FLOAT_EQ(timingFunction->GetValue(time), curve->getValue(time)); | 201 EXPECT_FLOAT_EQ(timingFunction->GetValue(time), curve->getValue(time)); |
199 } | 202 } |
200 } | 203 } |
201 | 204 |
202 // Tests that an ease in timing function works as expected. | 205 // Tests that an ease in timing function works as expected. |
203 TEST(WebFloatAnimationCurveTest, EaseInOutTimingFunction) { | 206 TEST(WebFloatAnimationCurveTest, EaseInOutTimingFunction) { |
204 std::unique_ptr<CompositorFloatAnimationCurve> curve = | 207 std::unique_ptr<CompositorFloatAnimationCurve> curve = |
205 CompositorFloatAnimationCurve::create(); | 208 CompositorFloatAnimationCurve::create(); |
206 curve->addKeyframe(CompositorFloatKeyframe( | 209 curve->addKeyframe(CompositorFloatKeyframe( |
207 0, 0, *CubicBezierTimingFunction::preset( | 210 0, 0, |
208 CubicBezierTimingFunction::EaseType::EASE_IN_OUT))); | 211 *CubicBezierTimingFunction::preset( |
| 212 CubicBezierTimingFunction::EaseType::EASE_IN_OUT))); |
209 curve->addKeyframe( | 213 curve->addKeyframe( |
210 CompositorFloatKeyframe(1, 1, *LinearTimingFunction::shared())); | 214 CompositorFloatKeyframe(1, 1, *LinearTimingFunction::shared())); |
211 | 215 |
212 std::unique_ptr<cc::TimingFunction> timingFunction( | 216 std::unique_ptr<cc::TimingFunction> timingFunction( |
213 cc::CubicBezierTimingFunction::CreatePreset( | 217 cc::CubicBezierTimingFunction::CreatePreset( |
214 CubicBezierTimingFunction::EaseType::EASE_IN_OUT)); | 218 CubicBezierTimingFunction::EaseType::EASE_IN_OUT)); |
215 for (int i = 0; i <= 4; ++i) { | 219 for (int i = 0; i <= 4; ++i) { |
216 const double time = i * 0.25; | 220 const double time = i * 0.25; |
217 EXPECT_FLOAT_EQ(timingFunction->GetValue(time), curve->getValue(time)); | 221 EXPECT_FLOAT_EQ(timingFunction->GetValue(time), curve->getValue(time)); |
218 } | 222 } |
(...skipping 18 matching lines...) Expand all Loading... |
237 for (int i = 0; i <= 4; ++i) { | 241 for (int i = 0; i <= 4; ++i) { |
238 const double time = i * 0.25; | 242 const double time = i * 0.25; |
239 EXPECT_FLOAT_EQ(timingFunction->GetValue(time), curve->getValue(time)); | 243 EXPECT_FLOAT_EQ(timingFunction->GetValue(time), curve->getValue(time)); |
240 } | 244 } |
241 } | 245 } |
242 | 246 |
243 // Tests that the default timing function is indeed ease. | 247 // Tests that the default timing function is indeed ease. |
244 TEST(WebFloatAnimationCurveTest, DefaultTimingFunction) { | 248 TEST(WebFloatAnimationCurveTest, DefaultTimingFunction) { |
245 std::unique_ptr<CompositorFloatAnimationCurve> curve = | 249 std::unique_ptr<CompositorFloatAnimationCurve> curve = |
246 CompositorFloatAnimationCurve::create(); | 250 CompositorFloatAnimationCurve::create(); |
247 curve->addKeyframe(CompositorFloatKeyframe( | 251 curve->addKeyframe( |
248 0, 0, *CubicBezierTimingFunction::preset( | 252 CompositorFloatKeyframe(0, 0, |
249 CubicBezierTimingFunction::EaseType::EASE))); | 253 *CubicBezierTimingFunction::preset( |
| 254 CubicBezierTimingFunction::EaseType::EASE))); |
250 curve->addKeyframe( | 255 curve->addKeyframe( |
251 CompositorFloatKeyframe(1, 1, *LinearTimingFunction::shared())); | 256 CompositorFloatKeyframe(1, 1, *LinearTimingFunction::shared())); |
252 | 257 |
253 std::unique_ptr<cc::TimingFunction> timingFunction( | 258 std::unique_ptr<cc::TimingFunction> timingFunction( |
254 cc::CubicBezierTimingFunction::CreatePreset( | 259 cc::CubicBezierTimingFunction::CreatePreset( |
255 CubicBezierTimingFunction::EaseType::EASE)); | 260 CubicBezierTimingFunction::EaseType::EASE)); |
256 for (int i = 0; i <= 4; ++i) { | 261 for (int i = 0; i <= 4; ++i) { |
257 const double time = i * 0.25; | 262 const double time = i * 0.25; |
258 EXPECT_FLOAT_EQ(timingFunction->GetValue(time), curve->getValue(time)); | 263 EXPECT_FLOAT_EQ(timingFunction->GetValue(time), curve->getValue(time)); |
259 } | 264 } |
260 } | 265 } |
261 | 266 |
262 } // namespace blink | 267 } // namespace blink |
OLD | NEW |