Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: third_party/WebKit/Source/core/animation/InterpolationEffectTest.cpp

Issue 2236193002: WIP: Implement CSS transitions on top of InterpolationTypes instead of AnimatableValues (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@_environmentStyle
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include <memory> 8 #include <memory>
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 PassRefPtr<Interpolation> create(std::unique_ptr<InterpolableValue> s tart, std::unique_ptr<InterpolableValue> end) 16 static PassRefPtr<Interpolation> create(double start, double end)
17 { 17 {
18 return adoptRef(new SampleInterpolation(std::move(start), std::move(end) )); 18 return adoptRef(new SampleInterpolation(start, end));
19 } 19 }
20 20
21 PropertyHandle getProperty() const override 21 PropertyHandle getProperty() const override
22 { 22 {
23 return PropertyHandle(CSSPropertyBackgroundColor); 23 return PropertyHandle(CSSPropertyBackgroundColor);
24 } 24 }
25
26 const double start;
27 const double end;
28 double current;
29
30 protected:
31 void interpolateImpl() final
32 {
33 current = blend(start, end, m_currentFraction);
34 }
35
25 private: 36 private:
26 SampleInterpolation(std::unique_ptr<InterpolableValue> start, std::unique_pt r<InterpolableValue> end) 37 SampleInterpolation(double start, double end)
27 : Interpolation(std::move(start), std::move(end)) 38 : start(start)
28 { 39 , end(end)
29 } 40 , current(start)
41 { }
30 }; 42 };
31 43
32 const double duration = 1.0; 44 const double duration = 1.0;
33 45
34 } // namespace 46 } // namespace
35 47
36 class AnimationInterpolationEffectTest : public ::testing::Test { 48 class AnimationInterpolationEffectTest : public ::testing::Test {
37 protected: 49 protected:
38 InterpolableValue* interpolationValue(Interpolation& interpolation) 50 double getNumber(PassRefPtr<Interpolation> value)
39 { 51 {
40 return interpolation.getCachedValueForTesting(); 52 return static_cast<SampleInterpolation&>(*value).current;
41 }
42
43 double getInterpolableNumber(PassRefPtr<Interpolation> value)
44 {
45 return toInterpolableNumber(interpolationValue(*value.get()))->value();
46 } 53 }
47 }; 54 };
48 55
49 TEST_F(AnimationInterpolationEffectTest, SingleInterpolation) 56 TEST_F(AnimationInterpolationEffectTest, SingleInterpolation)
50 { 57 {
51 InterpolationEffect interpolationEffect; 58 InterpolationEffect interpolationEffect;
52 interpolationEffect.addInterpolation(SampleInterpolation::create(Interpolabl eNumber::create(0), InterpolableNumber::create(10)), 59 interpolationEffect.addInterpolation(SampleInterpolation::create(0, 10),
53 RefPtr<TimingFunction>(), 0, 1, -1, 2); 60 RefPtr<TimingFunction>(), 0, 1, -1, 2);
54 61
55 Vector<RefPtr<Interpolation>> activeInterpolations; 62 Vector<RefPtr<Interpolation>> activeInterpolations;
56 interpolationEffect.getActiveInterpolations(-2, duration, activeInterpolatio ns); 63 interpolationEffect.getActiveInterpolations(-2, duration, activeInterpolatio ns);
57 EXPECT_EQ(0ul, activeInterpolations.size()); 64 EXPECT_EQ(0ul, activeInterpolations.size());
58 65
59 interpolationEffect.getActiveInterpolations(-0.5, duration, activeInterpolat ions); 66 interpolationEffect.getActiveInterpolations(-0.5, duration, activeInterpolat ions);
60 EXPECT_EQ(1ul, activeInterpolations.size()); 67 EXPECT_EQ(1ul, activeInterpolations.size());
61 EXPECT_EQ(-5, getInterpolableNumber(activeInterpolations.at(0))); 68 EXPECT_EQ(-5, getNumber(activeInterpolations.at(0)));
62 69
63 interpolationEffect.getActiveInterpolations(0.5, duration, activeInterpolati ons); 70 interpolationEffect.getActiveInterpolations(0.5, duration, activeInterpolati ons);
64 EXPECT_EQ(1ul, activeInterpolations.size()); 71 EXPECT_EQ(1ul, activeInterpolations.size());
65 EXPECT_FLOAT_EQ(5, getInterpolableNumber(activeInterpolations.at(0))); 72 EXPECT_FLOAT_EQ(5, getNumber(activeInterpolations.at(0)));
66 73
67 interpolationEffect.getActiveInterpolations(1.5, duration, activeInterpolati ons); 74 interpolationEffect.getActiveInterpolations(1.5, duration, activeInterpolati ons);
68 EXPECT_EQ(1ul, activeInterpolations.size()); 75 EXPECT_EQ(1ul, activeInterpolations.size());
69 EXPECT_FLOAT_EQ(15, getInterpolableNumber(activeInterpolations.at(0))); 76 EXPECT_FLOAT_EQ(15, getNumber(activeInterpolations.at(0)));
70 77
71 interpolationEffect.getActiveInterpolations(3, duration, activeInterpolation s); 78 interpolationEffect.getActiveInterpolations(3, duration, activeInterpolation s);
72 EXPECT_EQ(0ul, activeInterpolations.size()); 79 EXPECT_EQ(0ul, activeInterpolations.size());
73 } 80 }
74 81
75 TEST_F(AnimationInterpolationEffectTest, MultipleInterpolations) 82 TEST_F(AnimationInterpolationEffectTest, MultipleInterpolations)
76 { 83 {
77 InterpolationEffect interpolationEffect; 84 InterpolationEffect interpolationEffect;
78 interpolationEffect.addInterpolation(SampleInterpolation::create(Interpolabl eNumber::create(10), InterpolableNumber::create(15)), 85 interpolationEffect.addInterpolation(SampleInterpolation::create(10, 15),
79 RefPtr<TimingFunction>(), 1, 2, 1, 3); 86 RefPtr<TimingFunction>(), 1, 2, 1, 3);
80 interpolationEffect.addInterpolation(SampleInterpolation::create(Interpolabl eNumber::create(0), InterpolableNumber::create(1)), 87 interpolationEffect.addInterpolation(SampleInterpolation::create(0, 1),
81 LinearTimingFunction::shared(), 0, 1, 0, 1); 88 LinearTimingFunction::shared(), 0, 1, 0, 1);
82 interpolationEffect.addInterpolation(SampleInterpolation::create(Interpolabl eNumber::create(1), InterpolableNumber::create(6)), 89 interpolationEffect.addInterpolation(SampleInterpolation::create(1, 6),
83 CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseType::E ASE), 0.5, 1.5, 0.5, 1.5); 90 CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseType::E ASE), 0.5, 1.5, 0.5, 1.5);
84 91
85 Vector<RefPtr<Interpolation>> activeInterpolations; 92 Vector<RefPtr<Interpolation>> activeInterpolations;
86 interpolationEffect.getActiveInterpolations(-0.5, duration, activeInterpolat ions); 93 interpolationEffect.getActiveInterpolations(-0.5, duration, activeInterpolat ions);
87 EXPECT_EQ(0ul, activeInterpolations.size()); 94 EXPECT_EQ(0ul, activeInterpolations.size());
88 95
89 interpolationEffect.getActiveInterpolations(0, duration, activeInterpolation s); 96 interpolationEffect.getActiveInterpolations(0, duration, activeInterpolation s);
90 EXPECT_EQ(1ul, activeInterpolations.size()); 97 EXPECT_EQ(1ul, activeInterpolations.size());
91 EXPECT_FLOAT_EQ(0, getInterpolableNumber(activeInterpolations.at(0))); 98 EXPECT_FLOAT_EQ(0, getNumber(activeInterpolations.at(0)));
92 99
93 interpolationEffect.getActiveInterpolations(0.5, duration, activeInterpolati ons); 100 interpolationEffect.getActiveInterpolations(0.5, duration, activeInterpolati ons);
94 EXPECT_EQ(2ul, activeInterpolations.size()); 101 EXPECT_EQ(2ul, activeInterpolations.size());
95 EXPECT_FLOAT_EQ(0.5f, getInterpolableNumber(activeInterpolations.at(0))); 102 EXPECT_FLOAT_EQ(0.5f, getNumber(activeInterpolations.at(0)));
96 EXPECT_FLOAT_EQ(1, getInterpolableNumber(activeInterpolations.at(1))); 103 EXPECT_FLOAT_EQ(1, getNumber(activeInterpolations.at(1)));
97 104
98 interpolationEffect.getActiveInterpolations(1, duration, activeInterpolation s); 105 interpolationEffect.getActiveInterpolations(1, duration, activeInterpolation s);
99 EXPECT_EQ(2ul, activeInterpolations.size()); 106 EXPECT_EQ(2ul, activeInterpolations.size());
100 EXPECT_FLOAT_EQ(10, getInterpolableNumber(activeInterpolations.at(0))); 107 EXPECT_FLOAT_EQ(10, getNumber(activeInterpolations.at(0)));
101 EXPECT_FLOAT_EQ(5.0282884f, getInterpolableNumber(activeInterpolations.at(1) )); 108 EXPECT_FLOAT_EQ(5.0282884f, getNumber(activeInterpolations.at(1)));
102 109
103 interpolationEffect.getActiveInterpolations(1, duration * 1000, activeInterp olations); 110 interpolationEffect.getActiveInterpolations(1, duration * 1000, activeInterp olations);
104 EXPECT_EQ(2ul, activeInterpolations.size()); 111 EXPECT_EQ(2ul, activeInterpolations.size());
105 EXPECT_FLOAT_EQ(10, getInterpolableNumber(activeInterpolations.at(0))); 112 EXPECT_FLOAT_EQ(10, getNumber(activeInterpolations.at(0)));
106 EXPECT_FLOAT_EQ(5.0120168f, getInterpolableNumber(activeInterpolations.at(1) )); 113 EXPECT_FLOAT_EQ(5.0120168f, getNumber(activeInterpolations.at(1)));
107 114
108 interpolationEffect.getActiveInterpolations(1.5, duration, activeInterpolati ons); 115 interpolationEffect.getActiveInterpolations(1.5, duration, activeInterpolati ons);
109 EXPECT_EQ(1ul, activeInterpolations.size()); 116 EXPECT_EQ(1ul, activeInterpolations.size());
110 EXPECT_FLOAT_EQ(12.5f, getInterpolableNumber(activeInterpolations.at(0))); 117 EXPECT_FLOAT_EQ(12.5f, getNumber(activeInterpolations.at(0)));
111 118
112 interpolationEffect.getActiveInterpolations(2, duration, activeInterpolation s); 119 interpolationEffect.getActiveInterpolations(2, duration, activeInterpolation s);
113 EXPECT_EQ(1ul, activeInterpolations.size()); 120 EXPECT_EQ(1ul, activeInterpolations.size());
114 EXPECT_FLOAT_EQ(15, getInterpolableNumber(activeInterpolations.at(0))); 121 EXPECT_FLOAT_EQ(15, getNumber(activeInterpolations.at(0)));
115 } 122 }
116 123
117 } // namespace blink 124 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698