OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "core/animation/InterpolationEffect.h" | 5 #include "core/animation/InterpolationEffect.h" |
6 | 6 |
7 #include "core/animation/LegacyStyleInterpolation.h" | 7 #include "core/animation/LegacyStyleInterpolation.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 namespace blink { | 11 namespace blink { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 class SampleInterpolation : public LegacyStyleInterpolation { | 15 class SampleInterpolation : public LegacyStyleInterpolation { |
16 public: | 16 public: |
17 static PassRefPtr<Interpolation> create( | 17 static PassRefPtr<LegacyStyleInterpolation> create( |
18 std::unique_ptr<InterpolableValue> start, | 18 std::unique_ptr<InterpolableValue> start, |
19 std::unique_ptr<InterpolableValue> end) { | 19 std::unique_ptr<InterpolableValue> end) { |
20 return adoptRef(new SampleInterpolation(std::move(start), std::move(end))); | 20 return adoptRef(new SampleInterpolation(std::move(start), std::move(end))); |
21 } | 21 } |
22 | 22 |
23 private: | 23 private: |
24 SampleInterpolation(std::unique_ptr<InterpolableValue> start, | 24 SampleInterpolation(std::unique_ptr<InterpolableValue> start, |
25 std::unique_ptr<InterpolableValue> end) | 25 std::unique_ptr<InterpolableValue> end) |
26 : LegacyStyleInterpolation(std::move(start), | 26 : LegacyStyleInterpolation(std::move(start), |
27 std::move(end), | 27 std::move(end), |
28 CSSPropertyBackgroundColor) {} | 28 CSSPropertyBackgroundColor) {} |
29 }; | 29 }; |
30 | 30 |
31 const double duration = 1.0; | 31 const double duration = 1.0; |
32 | 32 |
33 } // namespace | 33 } // namespace |
34 | 34 |
35 class AnimationInterpolationEffectTest : public ::testing::Test { | 35 class AnimationInterpolationEffectTest : public ::testing::Test { |
36 protected: | 36 protected: |
37 InterpolableValue* interpolationValue(Interpolation& interpolation) { | 37 InterpolableValue* interpolationValue( |
| 38 LegacyStyleInterpolation& interpolation) { |
38 return interpolation.getCachedValueForTesting(); | 39 return interpolation.getCachedValueForTesting(); |
39 } | 40 } |
40 | 41 |
41 double getInterpolableNumber(PassRefPtr<Interpolation> value) { | 42 double getInterpolableNumber(PassRefPtr<Interpolation> value) { |
42 return toInterpolableNumber(interpolationValue(*value.get()))->value(); | 43 LegacyStyleInterpolation& interpolation = |
| 44 toLegacyStyleInterpolation(*value.get()); |
| 45 return toInterpolableNumber(interpolationValue(interpolation))->value(); |
43 } | 46 } |
44 }; | 47 }; |
45 | 48 |
46 TEST_F(AnimationInterpolationEffectTest, SingleInterpolation) { | 49 TEST_F(AnimationInterpolationEffectTest, SingleInterpolation) { |
47 InterpolationEffect interpolationEffect; | 50 InterpolationEffect interpolationEffect; |
48 interpolationEffect.addInterpolation( | 51 interpolationEffect.addInterpolation( |
49 SampleInterpolation::create(InterpolableNumber::create(0), | 52 SampleInterpolation::create(InterpolableNumber::create(0), |
50 InterpolableNumber::create(10)), | 53 InterpolableNumber::create(10)), |
51 RefPtr<TimingFunction>(), 0, 1, -1, 2); | 54 RefPtr<TimingFunction>(), 0, 1, -1, 2); |
52 | 55 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 EXPECT_EQ(1ul, activeInterpolations.size()); | 130 EXPECT_EQ(1ul, activeInterpolations.size()); |
128 EXPECT_FLOAT_EQ(12.5f, getInterpolableNumber(activeInterpolations.at(0))); | 131 EXPECT_FLOAT_EQ(12.5f, getInterpolableNumber(activeInterpolations.at(0))); |
129 | 132 |
130 interpolationEffect.getActiveInterpolations(2, duration, | 133 interpolationEffect.getActiveInterpolations(2, duration, |
131 activeInterpolations); | 134 activeInterpolations); |
132 EXPECT_EQ(1ul, activeInterpolations.size()); | 135 EXPECT_EQ(1ul, activeInterpolations.size()); |
133 EXPECT_FLOAT_EQ(15, getInterpolableNumber(activeInterpolations.at(0))); | 136 EXPECT_FLOAT_EQ(15, getInterpolableNumber(activeInterpolations.at(0))); |
134 } | 137 } |
135 | 138 |
136 } // namespace blink | 139 } // namespace blink |
OLD | NEW |