| 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 blink { | 10 namespace blink { |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 class SampleInterpolation : public Interpolation { | 14 class SampleInterpolation : public Interpolation { |
| 15 public: | 15 public: |
| 16 static PassRefPtrWillBeRawPtr<Interpolation> create(PassOwnPtrWillBeRawPtr<I
nterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableValue> end) | 16 static PassRefPtr<Interpolation> create(PassOwnPtr<InterpolableValue> start,
PassOwnPtr<InterpolableValue> end) |
| 17 { | 17 { |
| 18 return adoptRefWillBeNoop(new SampleInterpolation(start, end)); | 18 return adoptRef(new SampleInterpolation(start, end)); |
| 19 } | 19 } |
| 20 | 20 |
| 21 PropertyHandle property() const override | 21 PropertyHandle property() const override |
| 22 { | 22 { |
| 23 return PropertyHandle(CSSPropertyBackgroundColor); | 23 return PropertyHandle(CSSPropertyBackgroundColor); |
| 24 } | 24 } |
| 25 private: | 25 private: |
| 26 SampleInterpolation(PassOwnPtrWillBeRawPtr<InterpolableValue> start, PassOwn
PtrWillBeRawPtr<InterpolableValue> end) | 26 SampleInterpolation(PassOwnPtr<InterpolableValue> start, PassOwnPtr<Interpol
ableValue> end) |
| 27 : Interpolation(start, end) | 27 : Interpolation(start, end) |
| 28 { | 28 { |
| 29 } | 29 } |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 const double duration = 1.0; | 32 const double duration = 1.0; |
| 33 | 33 |
| 34 } // namespace | 34 } // namespace |
| 35 | 35 |
| 36 class AnimationInterpolationEffectTest : public ::testing::Test { | 36 class AnimationInterpolationEffectTest : public ::testing::Test { |
| 37 protected: | 37 protected: |
| 38 InterpolableValue* interpolationValue(Interpolation& interpolation) | 38 InterpolableValue* interpolationValue(Interpolation& interpolation) |
| 39 { | 39 { |
| 40 return interpolation.getCachedValueForTesting(); | 40 return interpolation.getCachedValueForTesting(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 double getInterpolableNumber(PassRefPtrWillBeRawPtr<Interpolation> value) | 43 double getInterpolableNumber(PassRefPtr<Interpolation> value) |
| 44 { | 44 { |
| 45 return toInterpolableNumber(interpolationValue(*value.get()))->value(); | 45 return toInterpolableNumber(interpolationValue(*value.get()))->value(); |
| 46 } | 46 } |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 TEST_F(AnimationInterpolationEffectTest, SingleInterpolation) | 49 TEST_F(AnimationInterpolationEffectTest, SingleInterpolation) |
| 50 { | 50 { |
| 51 InterpolationEffect* interpolationEffect = InterpolationEffect::create(); | 51 RefPtr<InterpolationEffect> interpolationEffect = InterpolationEffect::creat
e(); |
| 52 interpolationEffect->addInterpolation(SampleInterpolation::create(Interpolab
leNumber::create(0), InterpolableNumber::create(10)), | 52 interpolationEffect->addInterpolation(SampleInterpolation::create(Interpolab
leNumber::create(0), InterpolableNumber::create(10)), |
| 53 RefPtr<TimingFunction>(), 0, 1, -1, 2); | 53 RefPtr<TimingFunction>(), 0, 1, -1, 2); |
| 54 | 54 |
| 55 OwnPtrWillBeRawPtr<WillBeHeapVector<RefPtrWillBeMember<Interpolation>>> acti
veInterpolations = nullptr; | 55 OwnPtr<Vector<RefPtr<Interpolation>>> activeInterpolations = nullptr; |
| 56 interpolationEffect->getActiveInterpolations(-2, duration, activeInterpolati
ons); | 56 interpolationEffect->getActiveInterpolations(-2, duration, activeInterpolati
ons); |
| 57 EXPECT_EQ(0ul, activeInterpolations->size()); | 57 EXPECT_EQ(0ul, activeInterpolations->size()); |
| 58 | 58 |
| 59 interpolationEffect->getActiveInterpolations(-0.5, duration, activeInterpola
tions); | 59 interpolationEffect->getActiveInterpolations(-0.5, duration, activeInterpola
tions); |
| 60 EXPECT_EQ(1ul, activeInterpolations->size()); | 60 EXPECT_EQ(1ul, activeInterpolations->size()); |
| 61 EXPECT_EQ(-5, getInterpolableNumber(activeInterpolations->at(0))); | 61 EXPECT_EQ(-5, getInterpolableNumber(activeInterpolations->at(0))); |
| 62 | 62 |
| 63 interpolationEffect->getActiveInterpolations(0.5, duration, activeInterpolat
ions); | 63 interpolationEffect->getActiveInterpolations(0.5, duration, activeInterpolat
ions); |
| 64 EXPECT_EQ(1ul, activeInterpolations->size()); | 64 EXPECT_EQ(1ul, activeInterpolations->size()); |
| 65 EXPECT_FLOAT_EQ(5, getInterpolableNumber(activeInterpolations->at(0))); | 65 EXPECT_FLOAT_EQ(5, getInterpolableNumber(activeInterpolations->at(0))); |
| 66 | 66 |
| 67 interpolationEffect->getActiveInterpolations(1.5, duration, activeInterpolat
ions); | 67 interpolationEffect->getActiveInterpolations(1.5, duration, activeInterpolat
ions); |
| 68 EXPECT_EQ(1ul, activeInterpolations->size()); | 68 EXPECT_EQ(1ul, activeInterpolations->size()); |
| 69 EXPECT_FLOAT_EQ(15, getInterpolableNumber(activeInterpolations->at(0))); | 69 EXPECT_FLOAT_EQ(15, getInterpolableNumber(activeInterpolations->at(0))); |
| 70 | 70 |
| 71 interpolationEffect->getActiveInterpolations(3, duration, activeInterpolatio
ns); | 71 interpolationEffect->getActiveInterpolations(3, duration, activeInterpolatio
ns); |
| 72 EXPECT_EQ(0ul, activeInterpolations->size()); | 72 EXPECT_EQ(0ul, activeInterpolations->size()); |
| 73 } | 73 } |
| 74 | 74 |
| 75 TEST_F(AnimationInterpolationEffectTest, MultipleInterpolations) | 75 TEST_F(AnimationInterpolationEffectTest, MultipleInterpolations) |
| 76 { | 76 { |
| 77 InterpolationEffect* interpolationEffect = InterpolationEffect::create(); | 77 RefPtr<InterpolationEffect> interpolationEffect = InterpolationEffect::creat
e(); |
| 78 interpolationEffect->addInterpolation(SampleInterpolation::create(Interpolab
leNumber::create(10), InterpolableNumber::create(15)), | 78 interpolationEffect->addInterpolation(SampleInterpolation::create(Interpolab
leNumber::create(10), InterpolableNumber::create(15)), |
| 79 RefPtr<TimingFunction>(), 1, 2, 1, 3); | 79 RefPtr<TimingFunction>(), 1, 2, 1, 3); |
| 80 interpolationEffect->addInterpolation(SampleInterpolation::create(Interpolab
leNumber::create(0), InterpolableNumber::create(1)), | 80 interpolationEffect->addInterpolation(SampleInterpolation::create(Interpolab
leNumber::create(0), InterpolableNumber::create(1)), |
| 81 LinearTimingFunction::shared(), 0, 1, 0, 1); | 81 LinearTimingFunction::shared(), 0, 1, 0, 1); |
| 82 interpolationEffect->addInterpolation(SampleInterpolation::create(Interpolab
leNumber::create(1), InterpolableNumber::create(6)), | 82 interpolationEffect->addInterpolation(SampleInterpolation::create(Interpolab
leNumber::create(1), InterpolableNumber::create(6)), |
| 83 CubicBezierTimingFunction::preset(CubicBezierTimingFunction::Ease), 0.5,
1.5, 0.5, 1.5); | 83 CubicBezierTimingFunction::preset(CubicBezierTimingFunction::Ease), 0.5,
1.5, 0.5, 1.5); |
| 84 | 84 |
| 85 OwnPtrWillBeRawPtr<WillBeHeapVector<RefPtrWillBeMember<Interpolation>>> acti
veInterpolations = nullptr; | 85 OwnPtr<Vector<RefPtr<Interpolation>>> activeInterpolations = nullptr; |
| 86 interpolationEffect->getActiveInterpolations(-0.5, duration, activeInterpola
tions); | 86 interpolationEffect->getActiveInterpolations(-0.5, duration, activeInterpola
tions); |
| 87 EXPECT_EQ(0ul, activeInterpolations->size()); | 87 EXPECT_EQ(0ul, activeInterpolations->size()); |
| 88 | 88 |
| 89 interpolationEffect->getActiveInterpolations(0, duration, activeInterpolatio
ns); | 89 interpolationEffect->getActiveInterpolations(0, duration, activeInterpolatio
ns); |
| 90 EXPECT_EQ(1ul, activeInterpolations->size()); | 90 EXPECT_EQ(1ul, activeInterpolations->size()); |
| 91 EXPECT_FLOAT_EQ(0, getInterpolableNumber(activeInterpolations->at(0))); | 91 EXPECT_FLOAT_EQ(0, getInterpolableNumber(activeInterpolations->at(0))); |
| 92 | 92 |
| 93 interpolationEffect->getActiveInterpolations(0.5, duration, activeInterpolat
ions); | 93 interpolationEffect->getActiveInterpolations(0.5, duration, activeInterpolat
ions); |
| 94 EXPECT_EQ(2ul, activeInterpolations->size()); | 94 EXPECT_EQ(2ul, activeInterpolations->size()); |
| 95 EXPECT_FLOAT_EQ(0.5f, getInterpolableNumber(activeInterpolations->at(0))); | 95 EXPECT_FLOAT_EQ(0.5f, getInterpolableNumber(activeInterpolations->at(0))); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 108 interpolationEffect->getActiveInterpolations(1.5, duration, activeInterpolat
ions); | 108 interpolationEffect->getActiveInterpolations(1.5, duration, activeInterpolat
ions); |
| 109 EXPECT_EQ(1ul, activeInterpolations->size()); | 109 EXPECT_EQ(1ul, activeInterpolations->size()); |
| 110 EXPECT_FLOAT_EQ(12.5f, getInterpolableNumber(activeInterpolations->at(0))); | 110 EXPECT_FLOAT_EQ(12.5f, getInterpolableNumber(activeInterpolations->at(0))); |
| 111 | 111 |
| 112 interpolationEffect->getActiveInterpolations(2, duration, activeInterpolatio
ns); | 112 interpolationEffect->getActiveInterpolations(2, duration, activeInterpolatio
ns); |
| 113 EXPECT_EQ(1ul, activeInterpolations->size()); | 113 EXPECT_EQ(1ul, activeInterpolations->size()); |
| 114 EXPECT_FLOAT_EQ(15, getInterpolableNumber(activeInterpolations->at(0))); | 114 EXPECT_FLOAT_EQ(15, getInterpolableNumber(activeInterpolations->at(0))); |
| 115 } | 115 } |
| 116 | 116 |
| 117 } | 117 } |
| OLD | NEW |