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 "config.h" | 5 #include "config.h" |
6 #include "core/animation/InterpolationEffect.h" | 6 #include "core/animation/InterpolationEffect.h" |
7 | 7 |
8 #include <gtest/gtest.h> | 8 #include <gtest/gtest.h> |
9 | 9 |
10 namespace { | |
11 | |
12 const double kDuration = 1.0; | |
shans
2014/03/21 04:41:41
'duration' is fine.
Eric Willigers
2014/03/21 04:52:30
Done.
| |
13 | |
14 } // namespace | |
15 | |
10 namespace WebCore { | 16 namespace WebCore { |
11 | 17 |
12 class AnimationInterpolationEffectTest : public ::testing::Test { | 18 class AnimationInterpolationEffectTest : public ::testing::Test { |
13 protected: | 19 protected: |
14 InterpolableValue* interpolationValue(Interpolation& interpolation) | 20 InterpolableValue* interpolationValue(Interpolation& interpolation) |
15 { | 21 { |
16 return interpolation.getCachedValueForTesting(); | 22 return interpolation.getCachedValueForTesting(); |
17 } | 23 } |
18 | 24 |
19 double getInterpolableNumber(PassRefPtr<Interpolation> value) | 25 double getInterpolableNumber(PassRefPtr<Interpolation> value) |
20 { | 26 { |
21 return toInterpolableNumber(interpolationValue(*value.get()))->value(); | 27 return toInterpolableNumber(interpolationValue(*value.get()))->value(); |
22 } | 28 } |
23 }; | 29 }; |
24 | 30 |
25 TEST_F(AnimationInterpolationEffectTest, SingleInterpolation) | 31 TEST_F(AnimationInterpolationEffectTest, SingleInterpolation) |
26 { | 32 { |
27 RefPtr<InterpolationEffect> interpolationEffect = InterpolationEffect::creat e(); | 33 RefPtr<InterpolationEffect> interpolationEffect = InterpolationEffect::creat e(); |
28 interpolationEffect->addInterpolation(Interpolation::create(InterpolableNumb er::create(0), InterpolableNumber::create(10)), | 34 interpolationEffect->addInterpolation(Interpolation::create(InterpolableNumb er::create(0), InterpolableNumber::create(10)), |
29 RefPtr<TimingFunction>(), 0, 1, -1, 2); | 35 RefPtr<TimingFunction>(), 0, 1, -1, 2); |
30 | 36 |
31 OwnPtr<Vector<RefPtr<Interpolation> > > activeInterpolations = interpolation Effect->getActiveInterpolations(-2); | 37 OwnPtr<Vector<RefPtr<Interpolation> > > activeInterpolations = interpolation Effect->getActiveInterpolations(-2, kDuration); |
32 EXPECT_EQ(0ul, activeInterpolations->size()); | 38 EXPECT_EQ(0ul, activeInterpolations->size()); |
33 | 39 |
34 activeInterpolations = interpolationEffect->getActiveInterpolations(-0.5); | 40 activeInterpolations = interpolationEffect->getActiveInterpolations(-0.5, kD uration); |
35 EXPECT_EQ(1ul, activeInterpolations->size()); | 41 EXPECT_EQ(1ul, activeInterpolations->size()); |
36 EXPECT_EQ(-5, getInterpolableNumber(activeInterpolations->at(0))); | 42 EXPECT_EQ(-5, getInterpolableNumber(activeInterpolations->at(0))); |
37 | 43 |
38 activeInterpolations = interpolationEffect->getActiveInterpolations(0.5); | 44 activeInterpolations = interpolationEffect->getActiveInterpolations(0.5, kDu ration); |
39 EXPECT_EQ(1ul, activeInterpolations->size()); | 45 EXPECT_EQ(1ul, activeInterpolations->size()); |
40 EXPECT_FLOAT_EQ(5, getInterpolableNumber(activeInterpolations->at(0))); | 46 EXPECT_FLOAT_EQ(5, getInterpolableNumber(activeInterpolations->at(0))); |
41 | 47 |
42 activeInterpolations = interpolationEffect->getActiveInterpolations(1.5); | 48 activeInterpolations = interpolationEffect->getActiveInterpolations(1.5, kDu ration); |
43 EXPECT_EQ(1ul, activeInterpolations->size()); | 49 EXPECT_EQ(1ul, activeInterpolations->size()); |
44 EXPECT_FLOAT_EQ(15, getInterpolableNumber(activeInterpolations->at(0))); | 50 EXPECT_FLOAT_EQ(15, getInterpolableNumber(activeInterpolations->at(0))); |
45 | 51 |
46 activeInterpolations = interpolationEffect->getActiveInterpolations(3); | 52 activeInterpolations = interpolationEffect->getActiveInterpolations(3, kDura tion); |
47 EXPECT_EQ(0ul, activeInterpolations->size()); | 53 EXPECT_EQ(0ul, activeInterpolations->size()); |
48 } | 54 } |
49 | 55 |
50 TEST_F(AnimationInterpolationEffectTest, MultipleInterpolations) | 56 TEST_F(AnimationInterpolationEffectTest, MultipleInterpolations) |
51 { | 57 { |
52 RefPtr<InterpolationEffect> interpolationEffect = InterpolationEffect::creat e(); | 58 RefPtr<InterpolationEffect> interpolationEffect = InterpolationEffect::creat e(); |
53 interpolationEffect->addInterpolation(Interpolation::create(InterpolableNumb er::create(10), InterpolableNumber::create(15)), | 59 interpolationEffect->addInterpolation(Interpolation::create(InterpolableNumb er::create(10), InterpolableNumber::create(15)), |
54 RefPtr<TimingFunction>(), 1, 2, 1, 3); | 60 RefPtr<TimingFunction>(), 1, 2, 1, 3); |
55 interpolationEffect->addInterpolation(Interpolation::create(InterpolableNumb er::create(0), InterpolableNumber::create(1)), | 61 interpolationEffect->addInterpolation(Interpolation::create(InterpolableNumb er::create(0), InterpolableNumber::create(1)), |
56 LinearTimingFunction::preset(), 0, 1, 0, 1); | 62 LinearTimingFunction::preset(), 0, 1, 0, 1); |
57 interpolationEffect->addInterpolation(Interpolation::create(InterpolableNumb er::create(1), InterpolableNumber::create(6)), | 63 interpolationEffect->addInterpolation(Interpolation::create(InterpolableNumb er::create(1), InterpolableNumber::create(6)), |
58 CubicBezierTimingFunction::preset(CubicBezierTimingFunction::Ease), 0.5, 1.5, 0.5, 1.5); | 64 CubicBezierTimingFunction::preset(CubicBezierTimingFunction::Ease), 0.5, 1.5, 0.5, 1.5); |
59 | 65 |
60 OwnPtr<Vector<RefPtr<Interpolation> > > activeInterpolations = interpolation Effect->getActiveInterpolations(-0.5); | 66 OwnPtr<Vector<RefPtr<Interpolation> > > activeInterpolations = interpolation Effect->getActiveInterpolations(-0.5, kDuration); |
61 EXPECT_EQ(0ul, activeInterpolations->size()); | 67 EXPECT_EQ(0ul, activeInterpolations->size()); |
62 | 68 |
63 activeInterpolations = interpolationEffect->getActiveInterpolations(0); | 69 activeInterpolations = interpolationEffect->getActiveInterpolations(0, kDura tion); |
64 EXPECT_EQ(1ul, activeInterpolations->size()); | 70 EXPECT_EQ(1ul, activeInterpolations->size()); |
65 EXPECT_FLOAT_EQ(0, getInterpolableNumber(activeInterpolations->at(0))); | 71 EXPECT_FLOAT_EQ(0, getInterpolableNumber(activeInterpolations->at(0))); |
66 | 72 |
67 activeInterpolations = interpolationEffect->getActiveInterpolations(0.5); | 73 activeInterpolations = interpolationEffect->getActiveInterpolations(0.5, kDu ration); |
68 EXPECT_EQ(2ul, activeInterpolations->size()); | 74 EXPECT_EQ(2ul, activeInterpolations->size()); |
69 EXPECT_FLOAT_EQ(0.5f, getInterpolableNumber(activeInterpolations->at(0))); | 75 EXPECT_FLOAT_EQ(0.5f, getInterpolableNumber(activeInterpolations->at(0))); |
70 EXPECT_FLOAT_EQ(1, getInterpolableNumber(activeInterpolations->at(1))); | 76 EXPECT_FLOAT_EQ(1, getInterpolableNumber(activeInterpolations->at(1))); |
71 | 77 |
72 activeInterpolations = interpolationEffect->getActiveInterpolations(1); | 78 activeInterpolations = interpolationEffect->getActiveInterpolations(1, kDura tion); |
79 EXPECT_EQ(2ul, activeInterpolations->size()); | |
80 EXPECT_FLOAT_EQ(10, getInterpolableNumber(activeInterpolations->at(0))); | |
81 EXPECT_FLOAT_EQ(5.0282884f, getInterpolableNumber(activeInterpolations->at(1 ))); | |
82 | |
83 activeInterpolations = interpolationEffect->getActiveInterpolations(1, kDura tion * 1000); | |
73 EXPECT_EQ(2ul, activeInterpolations->size()); | 84 EXPECT_EQ(2ul, activeInterpolations->size()); |
74 EXPECT_FLOAT_EQ(10, getInterpolableNumber(activeInterpolations->at(0))); | 85 EXPECT_FLOAT_EQ(10, getInterpolableNumber(activeInterpolations->at(0))); |
75 EXPECT_FLOAT_EQ(5.0120168f, getInterpolableNumber(activeInterpolations->at(1 ))); | 86 EXPECT_FLOAT_EQ(5.0120168f, getInterpolableNumber(activeInterpolations->at(1 ))); |
76 | 87 |
77 activeInterpolations = interpolationEffect->getActiveInterpolations(1.5); | 88 activeInterpolations = interpolationEffect->getActiveInterpolations(1.5, kDu ration); |
78 EXPECT_EQ(1ul, activeInterpolations->size()); | 89 EXPECT_EQ(1ul, activeInterpolations->size()); |
79 EXPECT_FLOAT_EQ(12.5f, getInterpolableNumber(activeInterpolations->at(0))); | 90 EXPECT_FLOAT_EQ(12.5f, getInterpolableNumber(activeInterpolations->at(0))); |
80 | 91 |
81 activeInterpolations = interpolationEffect->getActiveInterpolations(2); | 92 activeInterpolations = interpolationEffect->getActiveInterpolations(2, kDura tion); |
82 EXPECT_EQ(1ul, activeInterpolations->size()); | 93 EXPECT_EQ(1ul, activeInterpolations->size()); |
83 EXPECT_FLOAT_EQ(15, getInterpolableNumber(activeInterpolations->at(0))); | 94 EXPECT_FLOAT_EQ(15, getInterpolableNumber(activeInterpolations->at(0))); |
84 } | 95 } |
85 | 96 |
86 } | 97 } |
87 | 98 |
OLD | NEW |