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

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

Issue 2627793002: Remove unused code in InvalidatableInterpolation (Closed)
Patch Set: Simplify test in response to review Created 3 years, 11 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/animation/Interpolation.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/InterpolableValue.h" 5 #include "core/animation/InterpolableValue.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 } // namespace 31 } // namespace
32 32
33 class AnimationInterpolableValueTest : public ::testing::Test { 33 class AnimationInterpolableValueTest : public ::testing::Test {
34 protected: 34 protected:
35 InterpolableValue* interpolationValue(Interpolation& interpolation) { 35 InterpolableValue* interpolationValue(
36 LegacyStyleInterpolation& interpolation) {
36 return interpolation.getCachedValueForTesting(); 37 return interpolation.getCachedValueForTesting();
37 } 38 }
38 39
39 double interpolateNumbers(double a, double b, double progress) { 40 double interpolateNumbers(double a, double b, double progress) {
40 RefPtr<Interpolation> i = SampleInterpolation::create( 41 RefPtr<LegacyStyleInterpolation> i = SampleInterpolation::create(
41 InterpolableNumber::create(a), InterpolableNumber::create(b)); 42 InterpolableNumber::create(a), InterpolableNumber::create(b));
42 i->interpolate(0, progress); 43 i->interpolate(0, progress);
43 return toInterpolableNumber(interpolationValue(*i.get()))->value(); 44 return toInterpolableNumber(interpolationValue(*i.get()))->value();
44 } 45 }
45 46
46 void scaleAndAdd(InterpolableValue& base, 47 void scaleAndAdd(InterpolableValue& base,
47 double scale, 48 double scale,
48 const InterpolableValue& add) { 49 const InterpolableValue& add) {
49 base.scaleAndAdd(scale, add); 50 base.scaleAndAdd(scale, add);
50 } 51 }
51 52
52 PassRefPtr<Interpolation> interpolateLists( 53 PassRefPtr<LegacyStyleInterpolation> interpolateLists(
53 std::unique_ptr<InterpolableList> listA, 54 std::unique_ptr<InterpolableList> listA,
54 std::unique_ptr<InterpolableList> listB, 55 std::unique_ptr<InterpolableList> listB,
55 double progress) { 56 double progress) {
56 RefPtr<Interpolation> i = 57 RefPtr<LegacyStyleInterpolation> i =
57 SampleInterpolation::create(std::move(listA), std::move(listB)); 58 SampleInterpolation::create(std::move(listA), std::move(listB));
58 i->interpolate(0, progress); 59 i->interpolate(0, progress);
59 return i; 60 return i;
60 } 61 }
61 }; 62 };
62 63
63 TEST_F(AnimationInterpolableValueTest, InterpolateNumbers) { 64 TEST_F(AnimationInterpolableValueTest, InterpolateNumbers) {
64 EXPECT_FLOAT_EQ(126, interpolateNumbers(42, 0, -2)); 65 EXPECT_FLOAT_EQ(126, interpolateNumbers(42, 0, -2));
65 EXPECT_FLOAT_EQ(42, interpolateNumbers(42, 0, 0)); 66 EXPECT_FLOAT_EQ(42, interpolateNumbers(42, 0, 0));
66 EXPECT_FLOAT_EQ(29.4f, interpolateNumbers(42, 0, 0.3)); 67 EXPECT_FLOAT_EQ(29.4f, interpolateNumbers(42, 0, 0.3));
67 EXPECT_FLOAT_EQ(21, interpolateNumbers(42, 0, 0.5)); 68 EXPECT_FLOAT_EQ(21, interpolateNumbers(42, 0, 0.5));
68 EXPECT_FLOAT_EQ(0, interpolateNumbers(42, 0, 1)); 69 EXPECT_FLOAT_EQ(0, interpolateNumbers(42, 0, 1));
69 EXPECT_FLOAT_EQ(-21, interpolateNumbers(42, 0, 1.5)); 70 EXPECT_FLOAT_EQ(-21, interpolateNumbers(42, 0, 1.5));
70 } 71 }
71 72
72 TEST_F(AnimationInterpolableValueTest, SimpleList) { 73 TEST_F(AnimationInterpolableValueTest, SimpleList) {
73 std::unique_ptr<InterpolableList> listA = InterpolableList::create(3); 74 std::unique_ptr<InterpolableList> listA = InterpolableList::create(3);
74 listA->set(0, InterpolableNumber::create(0)); 75 listA->set(0, InterpolableNumber::create(0));
75 listA->set(1, InterpolableNumber::create(42)); 76 listA->set(1, InterpolableNumber::create(42));
76 listA->set(2, InterpolableNumber::create(20.5)); 77 listA->set(2, InterpolableNumber::create(20.5));
77 78
78 std::unique_ptr<InterpolableList> listB = InterpolableList::create(3); 79 std::unique_ptr<InterpolableList> listB = InterpolableList::create(3);
79 listB->set(0, InterpolableNumber::create(100)); 80 listB->set(0, InterpolableNumber::create(100));
80 listB->set(1, InterpolableNumber::create(-200)); 81 listB->set(1, InterpolableNumber::create(-200));
81 listB->set(2, InterpolableNumber::create(300)); 82 listB->set(2, InterpolableNumber::create(300));
82 83
83 RefPtr<Interpolation> i = 84 RefPtr<LegacyStyleInterpolation> i =
84 interpolateLists(std::move(listA), std::move(listB), 0.3); 85 interpolateLists(std::move(listA), std::move(listB), 0.3);
85 InterpolableList* outList = toInterpolableList(interpolationValue(*i.get())); 86 InterpolableList* outList = toInterpolableList(interpolationValue(*i.get()));
86 EXPECT_FLOAT_EQ(30, toInterpolableNumber(outList->get(0))->value()); 87 EXPECT_FLOAT_EQ(30, toInterpolableNumber(outList->get(0))->value());
87 EXPECT_FLOAT_EQ(-30.6f, toInterpolableNumber(outList->get(1))->value()); 88 EXPECT_FLOAT_EQ(-30.6f, toInterpolableNumber(outList->get(1))->value());
88 EXPECT_FLOAT_EQ(104.35f, toInterpolableNumber(outList->get(2))->value()); 89 EXPECT_FLOAT_EQ(104.35f, toInterpolableNumber(outList->get(2))->value());
89 } 90 }
90 91
91 TEST_F(AnimationInterpolableValueTest, NestedList) { 92 TEST_F(AnimationInterpolableValueTest, NestedList) {
92 std::unique_ptr<InterpolableList> listA = InterpolableList::create(3); 93 std::unique_ptr<InterpolableList> listA = InterpolableList::create(3);
93 listA->set(0, InterpolableNumber::create(0)); 94 listA->set(0, InterpolableNumber::create(0));
94 std::unique_ptr<InterpolableList> subListA = InterpolableList::create(1); 95 std::unique_ptr<InterpolableList> subListA = InterpolableList::create(1);
95 subListA->set(0, InterpolableNumber::create(100)); 96 subListA->set(0, InterpolableNumber::create(100));
96 listA->set(1, std::move(subListA)); 97 listA->set(1, std::move(subListA));
97 listA->set(2, InterpolableNumber::create(0)); 98 listA->set(2, InterpolableNumber::create(0));
98 99
99 std::unique_ptr<InterpolableList> listB = InterpolableList::create(3); 100 std::unique_ptr<InterpolableList> listB = InterpolableList::create(3);
100 listB->set(0, InterpolableNumber::create(100)); 101 listB->set(0, InterpolableNumber::create(100));
101 std::unique_ptr<InterpolableList> subListB = InterpolableList::create(1); 102 std::unique_ptr<InterpolableList> subListB = InterpolableList::create(1);
102 subListB->set(0, InterpolableNumber::create(50)); 103 subListB->set(0, InterpolableNumber::create(50));
103 listB->set(1, std::move(subListB)); 104 listB->set(1, std::move(subListB));
104 listB->set(2, InterpolableNumber::create(1)); 105 listB->set(2, InterpolableNumber::create(1));
105 106
106 RefPtr<Interpolation> i = 107 RefPtr<LegacyStyleInterpolation> i =
107 interpolateLists(std::move(listA), std::move(listB), 0.5); 108 interpolateLists(std::move(listA), std::move(listB), 0.5);
108 InterpolableList* outList = toInterpolableList(interpolationValue(*i.get())); 109 InterpolableList* outList = toInterpolableList(interpolationValue(*i.get()));
109 EXPECT_FLOAT_EQ(50, toInterpolableNumber(outList->get(0))->value()); 110 EXPECT_FLOAT_EQ(50, toInterpolableNumber(outList->get(0))->value());
110 EXPECT_FLOAT_EQ( 111 EXPECT_FLOAT_EQ(
111 75, toInterpolableNumber(toInterpolableList(outList->get(1))->get(0)) 112 75, toInterpolableNumber(toInterpolableList(outList->get(1))->get(0))
112 ->value()); 113 ->value());
113 EXPECT_FLOAT_EQ(0.5, toInterpolableNumber(outList->get(2))->value()); 114 EXPECT_FLOAT_EQ(0.5, toInterpolableNumber(outList->get(2))->value());
114 } 115 }
115 116
116 TEST_F(AnimationInterpolableValueTest, ScaleAndAddNumbers) { 117 TEST_F(AnimationInterpolableValueTest, ScaleAndAddNumbers) {
(...skipping 19 matching lines...) Expand all
136 addList->set(0, InterpolableNumber::create(1)); 137 addList->set(0, InterpolableNumber::create(1));
137 addList->set(1, InterpolableNumber::create(2)); 138 addList->set(1, InterpolableNumber::create(2));
138 addList->set(2, InterpolableNumber::create(3)); 139 addList->set(2, InterpolableNumber::create(3));
139 scaleAndAdd(*baseList, 2, *addList); 140 scaleAndAdd(*baseList, 2, *addList);
140 EXPECT_FLOAT_EQ(11, toInterpolableNumber(baseList->get(0))->value()); 141 EXPECT_FLOAT_EQ(11, toInterpolableNumber(baseList->get(0))->value());
141 EXPECT_FLOAT_EQ(22, toInterpolableNumber(baseList->get(1))->value()); 142 EXPECT_FLOAT_EQ(22, toInterpolableNumber(baseList->get(1))->value());
142 EXPECT_FLOAT_EQ(33, toInterpolableNumber(baseList->get(2))->value()); 143 EXPECT_FLOAT_EQ(33, toInterpolableNumber(baseList->get(2))->value());
143 } 144 }
144 145
145 } // namespace blink 146 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/animation/Interpolation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698