| 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 "cc/transform_operations.h" |
| 8 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "third_party/WebKit/Source/Platform/chromium/public/WebTransformationMa
trix.h" | |
| 11 | |
| 12 using WebKit::WebTransformationMatrix; | |
| 13 | 10 |
| 14 namespace cc { | 11 namespace cc { |
| 15 namespace { | 12 namespace { |
| 16 | 13 |
| 17 void expectTranslateX(double translateX, const WebTransformationMatrix& matrix) | 14 void expectTranslateX(double translateX, const gfx::Transform& transform) |
| 18 { | 15 { |
| 19 EXPECT_FLOAT_EQ(translateX, matrix.m41()); | 16 EXPECT_FLOAT_EQ(translateX, transform.matrix().getDouble(0, 3)); |
| 20 } | 17 } |
| 21 | 18 |
| 22 // Tests that a float animation with one keyframe works as expected. | 19 // Tests that a float animation with one keyframe works as expected. |
| 23 TEST(KeyframedAnimationCurveTest, OneFloatKeyframe) | 20 TEST(KeyframedAnimationCurveTest, OneFloatKeyframe) |
| 24 { | 21 { |
| 25 scoped_ptr<KeyframedFloatAnimationCurve> curve(KeyframedFloatAnimationCurve:
:create()); | 22 scoped_ptr<KeyframedFloatAnimationCurve> curve(KeyframedFloatAnimationCurve:
:create()); |
| 26 curve->addKeyframe(FloatKeyframe::create(0, 2, scoped_ptr<TimingFunction>())
); | 23 curve->addKeyframe(FloatKeyframe::create(0, 2, scoped_ptr<TimingFunction>())
); |
| 27 EXPECT_FLOAT_EQ(2, curve->getValue(-1)); | 24 EXPECT_FLOAT_EQ(2, curve->getValue(-1)); |
| 28 EXPECT_FLOAT_EQ(2, curve->getValue(0)); | 25 EXPECT_FLOAT_EQ(2, curve->getValue(0)); |
| 29 EXPECT_FLOAT_EQ(2, curve->getValue(0.5)); | 26 EXPECT_FLOAT_EQ(2, curve->getValue(0.5)); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 curve->addKeyframe(TransformKeyframe::create(0, operations1, scoped_ptr<Timi
ngFunction>())); | 151 curve->addKeyframe(TransformKeyframe::create(0, operations1, scoped_ptr<Timi
ngFunction>())); |
| 155 curve->addKeyframe(TransformKeyframe::create(1, operations2, scoped_ptr<Timi
ngFunction>())); | 152 curve->addKeyframe(TransformKeyframe::create(1, operations2, scoped_ptr<Timi
ngFunction>())); |
| 156 curve->addKeyframe(TransformKeyframe::create(1, operations3, scoped_ptr<Timi
ngFunction>())); | 153 curve->addKeyframe(TransformKeyframe::create(1, operations3, scoped_ptr<Timi
ngFunction>())); |
| 157 curve->addKeyframe(TransformKeyframe::create(2, operations4, scoped_ptr<Timi
ngFunction>())); | 154 curve->addKeyframe(TransformKeyframe::create(2, operations4, scoped_ptr<Timi
ngFunction>())); |
| 158 | 155 |
| 159 expectTranslateX(4, curve->getValue(-1)); | 156 expectTranslateX(4, curve->getValue(-1)); |
| 160 expectTranslateX(4, curve->getValue(0)); | 157 expectTranslateX(4, curve->getValue(0)); |
| 161 expectTranslateX(4, curve->getValue(0.5)); | 158 expectTranslateX(4, curve->getValue(0.5)); |
| 162 | 159 |
| 163 // There is a discontinuity at 1. Any value between 4 and 6 is valid. | 160 // There is a discontinuity at 1. Any value between 4 and 6 is valid. |
| 164 WebTransformationMatrix value = curve->getValue(1); | 161 gfx::Transform value = curve->getValue(1); |
| 165 EXPECT_TRUE(value.m41() >= 4 && value.m41() <= 6); | 162 EXPECT_TRUE(value.matrix().getDouble(0, 3) >= 4 && value.matrix().getDouble(
0, 3) <= 6); |
| 166 | 163 |
| 167 expectTranslateX(6, curve->getValue(1.5)); | 164 expectTranslateX(6, curve->getValue(1.5)); |
| 168 expectTranslateX(6, curve->getValue(2)); | 165 expectTranslateX(6, curve->getValue(2)); |
| 169 expectTranslateX(6, curve->getValue(3)); | 166 expectTranslateX(6, curve->getValue(3)); |
| 170 } | 167 } |
| 171 | 168 |
| 172 // Tests that the keyframes may be added out of order. | 169 // Tests that the keyframes may be added out of order. |
| 173 TEST(KeyframedAnimationCurveTest, UnsortedKeyframes) | 170 TEST(KeyframedAnimationCurveTest, UnsortedKeyframes) |
| 174 { | 171 { |
| 175 scoped_ptr<KeyframedFloatAnimationCurve> curve(KeyframedFloatAnimationCurve:
:create()); | 172 scoped_ptr<KeyframedFloatAnimationCurve> curve(KeyframedFloatAnimationCurve:
:create()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 196 EXPECT_LT(0, curve->getValue(0.25)); | 193 EXPECT_LT(0, curve->getValue(0.25)); |
| 197 EXPECT_GT(0.25, curve->getValue(0.25)); | 194 EXPECT_GT(0.25, curve->getValue(0.25)); |
| 198 EXPECT_NEAR(curve->getValue(0.5), 0.5, 0.00015); | 195 EXPECT_NEAR(curve->getValue(0.5), 0.5, 0.00015); |
| 199 EXPECT_LT(0.75, curve->getValue(0.75)); | 196 EXPECT_LT(0.75, curve->getValue(0.75)); |
| 200 EXPECT_GT(1, curve->getValue(0.75)); | 197 EXPECT_GT(1, curve->getValue(0.75)); |
| 201 EXPECT_FLOAT_EQ(1, curve->getValue(1)); | 198 EXPECT_FLOAT_EQ(1, curve->getValue(1)); |
| 202 } | 199 } |
| 203 | 200 |
| 204 } // namespace | 201 } // namespace |
| 205 } // namespace cc | 202 } // namespace cc |
| OLD | NEW |