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

Side by Side Diff: webkit/renderer/compositor_bindings/web_float_animation_curve_unittest.cc

Issue 317163002: Moving compositor_bindings from webkit to content (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changing dependencies due to failing ios bots Created 6 years, 6 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
(Empty)
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/memory/scoped_ptr.h"
6 #include "cc/animation/timing_function.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "webkit/renderer/compositor_bindings/web_float_animation_curve_impl.h"
9
10 using blink::WebAnimationCurve;
11 using blink::WebFloatAnimationCurve;
12 using blink::WebFloatKeyframe;
13
14 namespace webkit {
15 namespace {
16
17 // Tests that a float animation with one keyframe works as expected.
18 TEST(WebFloatAnimationCurveTest, OneFloatKeyframe) {
19 scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl);
20 curve->add(WebFloatKeyframe(0, 2),
21 WebAnimationCurve::TimingFunctionTypeLinear);
22 EXPECT_FLOAT_EQ(2, curve->getValue(-1));
23 EXPECT_FLOAT_EQ(2, curve->getValue(0));
24 EXPECT_FLOAT_EQ(2, curve->getValue(0.5));
25 EXPECT_FLOAT_EQ(2, curve->getValue(1));
26 EXPECT_FLOAT_EQ(2, curve->getValue(2));
27 }
28
29 // Tests that a float animation with two keyframes works as expected.
30 TEST(WebFloatAnimationCurveTest, TwoFloatKeyframe) {
31 scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl);
32 curve->add(WebFloatKeyframe(0, 2),
33 WebAnimationCurve::TimingFunctionTypeLinear);
34 curve->add(WebFloatKeyframe(1, 4),
35 WebAnimationCurve::TimingFunctionTypeLinear);
36 EXPECT_FLOAT_EQ(2, curve->getValue(-1));
37 EXPECT_FLOAT_EQ(2, curve->getValue(0));
38 EXPECT_FLOAT_EQ(3, curve->getValue(0.5));
39 EXPECT_FLOAT_EQ(4, curve->getValue(1));
40 EXPECT_FLOAT_EQ(4, curve->getValue(2));
41 }
42
43 // Tests that a float animation with three keyframes works as expected.
44 TEST(WebFloatAnimationCurveTest, ThreeFloatKeyframe) {
45 scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl);
46 curve->add(WebFloatKeyframe(0, 2),
47 WebAnimationCurve::TimingFunctionTypeLinear);
48 curve->add(WebFloatKeyframe(1, 4),
49 WebAnimationCurve::TimingFunctionTypeLinear);
50 curve->add(WebFloatKeyframe(2, 8),
51 WebAnimationCurve::TimingFunctionTypeLinear);
52 EXPECT_FLOAT_EQ(2, curve->getValue(-1));
53 EXPECT_FLOAT_EQ(2, curve->getValue(0));
54 EXPECT_FLOAT_EQ(3, curve->getValue(0.5));
55 EXPECT_FLOAT_EQ(4, curve->getValue(1));
56 EXPECT_FLOAT_EQ(6, curve->getValue(1.5));
57 EXPECT_FLOAT_EQ(8, curve->getValue(2));
58 EXPECT_FLOAT_EQ(8, curve->getValue(3));
59 }
60
61 // Tests that a float animation with multiple keys at a given time works sanely.
62 TEST(WebFloatAnimationCurveTest, RepeatedFloatKeyTimes) {
63 scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl);
64 curve->add(WebFloatKeyframe(0, 4),
65 WebAnimationCurve::TimingFunctionTypeLinear);
66 curve->add(WebFloatKeyframe(1, 4),
67 WebAnimationCurve::TimingFunctionTypeLinear);
68 curve->add(WebFloatKeyframe(1, 6),
69 WebAnimationCurve::TimingFunctionTypeLinear);
70 curve->add(WebFloatKeyframe(2, 6),
71 WebAnimationCurve::TimingFunctionTypeLinear);
72
73 EXPECT_FLOAT_EQ(4, curve->getValue(-1));
74 EXPECT_FLOAT_EQ(4, curve->getValue(0));
75 EXPECT_FLOAT_EQ(4, curve->getValue(0.5));
76
77 // There is a discontinuity at 1. Any value between 4 and 6 is valid.
78 float value = curve->getValue(1);
79 EXPECT_TRUE(value >= 4 && value <= 6);
80
81 EXPECT_FLOAT_EQ(6, curve->getValue(1.5));
82 EXPECT_FLOAT_EQ(6, curve->getValue(2));
83 EXPECT_FLOAT_EQ(6, curve->getValue(3));
84 }
85
86 // Tests that the keyframes may be added out of order.
87 TEST(WebFloatAnimationCurveTest, UnsortedKeyframes) {
88 scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl);
89 curve->add(WebFloatKeyframe(2, 8),
90 WebAnimationCurve::TimingFunctionTypeLinear);
91 curve->add(WebFloatKeyframe(0, 2),
92 WebAnimationCurve::TimingFunctionTypeLinear);
93 curve->add(WebFloatKeyframe(1, 4),
94 WebAnimationCurve::TimingFunctionTypeLinear);
95
96 EXPECT_FLOAT_EQ(2, curve->getValue(-1));
97 EXPECT_FLOAT_EQ(2, curve->getValue(0));
98 EXPECT_FLOAT_EQ(3, curve->getValue(0.5));
99 EXPECT_FLOAT_EQ(4, curve->getValue(1));
100 EXPECT_FLOAT_EQ(6, curve->getValue(1.5));
101 EXPECT_FLOAT_EQ(8, curve->getValue(2));
102 EXPECT_FLOAT_EQ(8, curve->getValue(3));
103 }
104
105 // Tests that a cubic bezier timing function works as expected.
106 TEST(WebFloatAnimationCurveTest, CubicBezierTimingFunction) {
107 scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl);
108 curve->add(WebFloatKeyframe(0, 0), 0.25, 0, 0.75, 1);
109 curve->add(WebFloatKeyframe(1, 1),
110 WebAnimationCurve::TimingFunctionTypeLinear);
111
112 EXPECT_FLOAT_EQ(0, curve->getValue(0));
113 EXPECT_LT(0, curve->getValue(0.25));
114 EXPECT_GT(0.25, curve->getValue(0.25));
115 EXPECT_NEAR(curve->getValue(0.5), 0.5, 0.00015);
116 EXPECT_LT(0.75, curve->getValue(0.75));
117 EXPECT_GT(1, curve->getValue(0.75));
118 EXPECT_FLOAT_EQ(1, curve->getValue(1));
119 }
120
121 // Tests that an ease timing function works as expected.
122 TEST(WebFloatAnimationCurveTest, EaseTimingFunction) {
123 scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl);
124 curve->add(WebFloatKeyframe(0, 0), WebAnimationCurve::TimingFunctionTypeEase);
125 curve->add(WebFloatKeyframe(1, 1),
126 WebAnimationCurve::TimingFunctionTypeLinear);
127
128 scoped_ptr<cc::TimingFunction> timing_function(
129 cc::EaseTimingFunction::Create());
130 for (int i = 0; i <= 4; ++i) {
131 const double time = i * 0.25;
132 EXPECT_FLOAT_EQ(timing_function->GetValue(time), curve->getValue(time));
133 }
134 }
135
136 // Tests using a linear timing function.
137 TEST(WebFloatAnimationCurveTest, LinearTimingFunction) {
138 scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl);
139 curve->add(WebFloatKeyframe(0, 0),
140 WebAnimationCurve::TimingFunctionTypeLinear);
141 curve->add(WebFloatKeyframe(1, 1),
142 WebAnimationCurve::TimingFunctionTypeLinear);
143
144 for (int i = 0; i <= 4; ++i) {
145 const double time = i * 0.25;
146 EXPECT_FLOAT_EQ(time, curve->getValue(time));
147 }
148 }
149
150 // Tests that an ease in timing function works as expected.
151 TEST(WebFloatAnimationCurveTest, EaseInTimingFunction) {
152 scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl);
153 curve->add(WebFloatKeyframe(0, 0),
154 WebAnimationCurve::TimingFunctionTypeEaseIn);
155 curve->add(WebFloatKeyframe(1, 1),
156 WebAnimationCurve::TimingFunctionTypeLinear);
157
158 scoped_ptr<cc::TimingFunction> timing_function(
159 cc::EaseInTimingFunction::Create());
160 for (int i = 0; i <= 4; ++i) {
161 const double time = i * 0.25;
162 EXPECT_FLOAT_EQ(timing_function->GetValue(time), curve->getValue(time));
163 }
164 }
165
166 // Tests that an ease in timing function works as expected.
167 TEST(WebFloatAnimationCurveTest, EaseOutTimingFunction) {
168 scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl);
169 curve->add(WebFloatKeyframe(0, 0),
170 WebAnimationCurve::TimingFunctionTypeEaseOut);
171 curve->add(WebFloatKeyframe(1, 1),
172 WebAnimationCurve::TimingFunctionTypeLinear);
173
174 scoped_ptr<cc::TimingFunction> timing_function(
175 cc::EaseOutTimingFunction::Create());
176 for (int i = 0; i <= 4; ++i) {
177 const double time = i * 0.25;
178 EXPECT_FLOAT_EQ(timing_function->GetValue(time), curve->getValue(time));
179 }
180 }
181
182 // Tests that an ease in timing function works as expected.
183 TEST(WebFloatAnimationCurveTest, EaseInOutTimingFunction) {
184 scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl);
185 curve->add(WebFloatKeyframe(0, 0),
186 WebAnimationCurve::TimingFunctionTypeEaseInOut);
187 curve->add(WebFloatKeyframe(1, 1),
188 WebAnimationCurve::TimingFunctionTypeLinear);
189
190 scoped_ptr<cc::TimingFunction> timing_function(
191 cc::EaseInOutTimingFunction::Create());
192 for (int i = 0; i <= 4; ++i) {
193 const double time = i * 0.25;
194 EXPECT_FLOAT_EQ(timing_function->GetValue(time), curve->getValue(time));
195 }
196 }
197
198 // Tests that an ease in timing function works as expected.
199 TEST(WebFloatAnimationCurveTest, CustomBezierTimingFunction) {
200 scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl);
201 double x1 = 0.3;
202 double y1 = 0.2;
203 double x2 = 0.8;
204 double y2 = 0.7;
205 curve->add(WebFloatKeyframe(0, 0), x1, y1, x2, y2);
206 curve->add(WebFloatKeyframe(1, 1),
207 WebAnimationCurve::TimingFunctionTypeLinear);
208
209 scoped_ptr<cc::TimingFunction> timing_function(
210 cc::CubicBezierTimingFunction::Create(x1, y1, x2, y2));
211 for (int i = 0; i <= 4; ++i) {
212 const double time = i * 0.25;
213 EXPECT_FLOAT_EQ(timing_function->GetValue(time), curve->getValue(time));
214 }
215 }
216
217 // Tests that the default timing function is indeed ease.
218 TEST(WebFloatAnimationCurveTest, DefaultTimingFunction) {
219 scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl);
220 curve->add(WebFloatKeyframe(0, 0));
221 curve->add(WebFloatKeyframe(1, 1),
222 WebAnimationCurve::TimingFunctionTypeLinear);
223
224 scoped_ptr<cc::TimingFunction> timing_function(
225 cc::EaseTimingFunction::Create());
226 for (int i = 0; i <= 4; ++i) {
227 const double time = i * 0.25;
228 EXPECT_FLOAT_EQ(timing_function->GetValue(time), curve->getValue(time));
229 }
230 }
231
232 } // namespace
233 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698