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

Side by Side Diff: cc/CCKeyframedAnimationCurveTest.cpp

Issue 11108020: [cc] Change cc_tests.gyp filenames to Chromium style (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « cc/CCHeadsUpDisplayTest.cpp ('k') | cc/CCLayerAnimationControllerTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "config.h"
6
7 #include "CCKeyframedAnimationCurve.h"
8
9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include <public/WebTransformOperations.h>
12 #include <public/WebTransformationMatrix.h>
13
14 using namespace cc;
15 using WebKit::WebTransformationMatrix;
16
17 namespace {
18
19 void expectTranslateX(double translateX, const WebTransformationMatrix& matrix)
20 {
21 EXPECT_FLOAT_EQ(translateX, matrix.m41());
22 }
23
24 // Tests that a float animation with one keyframe works as expected.
25 TEST(CCKeyframedAnimationCurveTest, OneFloatKeyframe)
26 {
27 scoped_ptr<CCKeyframedFloatAnimationCurve> curve(CCKeyframedFloatAnimationCu rve::create());
28 curve->addKeyframe(CCFloatKeyframe::create(0, 2, scoped_ptr<CCTimingFunction >()));
29 EXPECT_FLOAT_EQ(2, curve->getValue(-1));
30 EXPECT_FLOAT_EQ(2, curve->getValue(0));
31 EXPECT_FLOAT_EQ(2, curve->getValue(0.5));
32 EXPECT_FLOAT_EQ(2, curve->getValue(1));
33 EXPECT_FLOAT_EQ(2, curve->getValue(2));
34 }
35
36 // Tests that a float animation with two keyframes works as expected.
37 TEST(CCKeyframedAnimationCurveTest, TwoFloatKeyframe)
38 {
39 scoped_ptr<CCKeyframedFloatAnimationCurve> curve(CCKeyframedFloatAnimationCu rve::create());
40 curve->addKeyframe(CCFloatKeyframe::create(0, 2, scoped_ptr<CCTimingFunction >()));
41 curve->addKeyframe(CCFloatKeyframe::create(1, 4, scoped_ptr<CCTimingFunction >()));
42 EXPECT_FLOAT_EQ(2, curve->getValue(-1));
43 EXPECT_FLOAT_EQ(2, curve->getValue(0));
44 EXPECT_FLOAT_EQ(3, curve->getValue(0.5));
45 EXPECT_FLOAT_EQ(4, curve->getValue(1));
46 EXPECT_FLOAT_EQ(4, curve->getValue(2));
47 }
48
49 // Tests that a float animation with three keyframes works as expected.
50 TEST(CCKeyframedAnimationCurveTest, ThreeFloatKeyframe)
51 {
52 scoped_ptr<CCKeyframedFloatAnimationCurve> curve(CCKeyframedFloatAnimationCu rve::create());
53 curve->addKeyframe(CCFloatKeyframe::create(0, 2, scoped_ptr<CCTimingFunction >()));
54 curve->addKeyframe(CCFloatKeyframe::create(1, 4, scoped_ptr<CCTimingFunction >()));
55 curve->addKeyframe(CCFloatKeyframe::create(2, 8, scoped_ptr<CCTimingFunction >()));
56 EXPECT_FLOAT_EQ(2, curve->getValue(-1));
57 EXPECT_FLOAT_EQ(2, curve->getValue(0));
58 EXPECT_FLOAT_EQ(3, curve->getValue(0.5));
59 EXPECT_FLOAT_EQ(4, curve->getValue(1));
60 EXPECT_FLOAT_EQ(6, curve->getValue(1.5));
61 EXPECT_FLOAT_EQ(8, curve->getValue(2));
62 EXPECT_FLOAT_EQ(8, curve->getValue(3));
63 }
64
65 // Tests that a float animation with multiple keys at a given time works sanely.
66 TEST(CCKeyframedAnimationCurveTest, RepeatedFloatKeyTimes)
67 {
68 scoped_ptr<CCKeyframedFloatAnimationCurve> curve(CCKeyframedFloatAnimationCu rve::create());
69 curve->addKeyframe(CCFloatKeyframe::create(0, 4, scoped_ptr<CCTimingFunction >()));
70 curve->addKeyframe(CCFloatKeyframe::create(1, 4, scoped_ptr<CCTimingFunction >()));
71 curve->addKeyframe(CCFloatKeyframe::create(1, 6, scoped_ptr<CCTimingFunction >()));
72 curve->addKeyframe(CCFloatKeyframe::create(2, 6, scoped_ptr<CCTimingFunction >()));
73
74 EXPECT_FLOAT_EQ(4, curve->getValue(-1));
75 EXPECT_FLOAT_EQ(4, curve->getValue(0));
76 EXPECT_FLOAT_EQ(4, curve->getValue(0.5));
77
78 // There is a discontinuity at 1. Any value between 4 and 6 is valid.
79 float value = curve->getValue(1);
80 EXPECT_TRUE(value >= 4 && value <= 6);
81
82 EXPECT_FLOAT_EQ(6, curve->getValue(1.5));
83 EXPECT_FLOAT_EQ(6, curve->getValue(2));
84 EXPECT_FLOAT_EQ(6, curve->getValue(3));
85 }
86
87
88 // Tests that a transform animation with one keyframe works as expected.
89 TEST(CCKeyframedAnimationCurveTest, OneTransformKeyframe)
90 {
91 scoped_ptr<CCKeyframedTransformAnimationCurve> curve(CCKeyframedTransformAni mationCurve::create());
92 WebKit::WebTransformOperations operations;
93 operations.appendTranslate(2, 0, 0);
94 curve->addKeyframe(CCTransformKeyframe::create(0, operations, scoped_ptr<CCT imingFunction>()));
95
96 expectTranslateX(2, curve->getValue(-1));
97 expectTranslateX(2, curve->getValue(0));
98 expectTranslateX(2, curve->getValue(0.5));
99 expectTranslateX(2, curve->getValue(1));
100 expectTranslateX(2, curve->getValue(2));
101 }
102
103 // Tests that a transform animation with two keyframes works as expected.
104 TEST(CCKeyframedAnimationCurveTest, TwoTransformKeyframe)
105 {
106 scoped_ptr<CCKeyframedTransformAnimationCurve> curve(CCKeyframedTransformAni mationCurve::create());
107 WebKit::WebTransformOperations operations1;
108 operations1.appendTranslate(2, 0, 0);
109 WebKit::WebTransformOperations operations2;
110 operations2.appendTranslate(4, 0, 0);
111
112 curve->addKeyframe(CCTransformKeyframe::create(0, operations1, scoped_ptr<CC TimingFunction>()));
113 curve->addKeyframe(CCTransformKeyframe::create(1, operations2, scoped_ptr<CC TimingFunction>()));
114 expectTranslateX(2, curve->getValue(-1));
115 expectTranslateX(2, curve->getValue(0));
116 expectTranslateX(3, curve->getValue(0.5));
117 expectTranslateX(4, curve->getValue(1));
118 expectTranslateX(4, curve->getValue(2));
119 }
120
121 // Tests that a transform animation with three keyframes works as expected.
122 TEST(CCKeyframedAnimationCurveTest, ThreeTransformKeyframe)
123 {
124 scoped_ptr<CCKeyframedTransformAnimationCurve> curve(CCKeyframedTransformAni mationCurve::create());
125 WebKit::WebTransformOperations operations1;
126 operations1.appendTranslate(2, 0, 0);
127 WebKit::WebTransformOperations operations2;
128 operations2.appendTranslate(4, 0, 0);
129 WebKit::WebTransformOperations operations3;
130 operations3.appendTranslate(8, 0, 0);
131 curve->addKeyframe(CCTransformKeyframe::create(0, operations1, scoped_ptr<CC TimingFunction>()));
132 curve->addKeyframe(CCTransformKeyframe::create(1, operations2, scoped_ptr<CC TimingFunction>()));
133 curve->addKeyframe(CCTransformKeyframe::create(2, operations3, scoped_ptr<CC TimingFunction>()));
134 expectTranslateX(2, curve->getValue(-1));
135 expectTranslateX(2, curve->getValue(0));
136 expectTranslateX(3, curve->getValue(0.5));
137 expectTranslateX(4, curve->getValue(1));
138 expectTranslateX(6, curve->getValue(1.5));
139 expectTranslateX(8, curve->getValue(2));
140 expectTranslateX(8, curve->getValue(3));
141 }
142
143 // Tests that a transform animation with multiple keys at a given time works san ely.
144 TEST(CCKeyframedAnimationCurveTest, RepeatedTransformKeyTimes)
145 {
146 scoped_ptr<CCKeyframedTransformAnimationCurve> curve(CCKeyframedTransformAni mationCurve::create());
147 // A step function.
148 WebKit::WebTransformOperations operations1;
149 operations1.appendTranslate(4, 0, 0);
150 WebKit::WebTransformOperations operations2;
151 operations2.appendTranslate(4, 0, 0);
152 WebKit::WebTransformOperations operations3;
153 operations3.appendTranslate(6, 0, 0);
154 WebKit::WebTransformOperations operations4;
155 operations4.appendTranslate(6, 0, 0);
156 curve->addKeyframe(CCTransformKeyframe::create(0, operations1, scoped_ptr<CC TimingFunction>()));
157 curve->addKeyframe(CCTransformKeyframe::create(1, operations2, scoped_ptr<CC TimingFunction>()));
158 curve->addKeyframe(CCTransformKeyframe::create(1, operations3, scoped_ptr<CC TimingFunction>()));
159 curve->addKeyframe(CCTransformKeyframe::create(2, operations4, scoped_ptr<CC TimingFunction>()));
160
161 expectTranslateX(4, curve->getValue(-1));
162 expectTranslateX(4, curve->getValue(0));
163 expectTranslateX(4, curve->getValue(0.5));
164
165 // There is a discontinuity at 1. Any value between 4 and 6 is valid.
166 WebTransformationMatrix value = curve->getValue(1);
167 EXPECT_TRUE(value.m41() >= 4 && value.m41() <= 6);
168
169 expectTranslateX(6, curve->getValue(1.5));
170 expectTranslateX(6, curve->getValue(2));
171 expectTranslateX(6, curve->getValue(3));
172 }
173
174 // Tests that the keyframes may be added out of order.
175 TEST(CCKeyframedAnimationCurveTest, UnsortedKeyframes)
176 {
177 scoped_ptr<CCKeyframedFloatAnimationCurve> curve(CCKeyframedFloatAnimationCu rve::create());
178 curve->addKeyframe(CCFloatKeyframe::create(2, 8, scoped_ptr<CCTimingFunction >()));
179 curve->addKeyframe(CCFloatKeyframe::create(0, 2, scoped_ptr<CCTimingFunction >()));
180 curve->addKeyframe(CCFloatKeyframe::create(1, 4, scoped_ptr<CCTimingFunction >()));
181 EXPECT_FLOAT_EQ(2, curve->getValue(-1));
182 EXPECT_FLOAT_EQ(2, curve->getValue(0));
183 EXPECT_FLOAT_EQ(3, curve->getValue(0.5));
184 EXPECT_FLOAT_EQ(4, curve->getValue(1));
185 EXPECT_FLOAT_EQ(6, curve->getValue(1.5));
186 EXPECT_FLOAT_EQ(8, curve->getValue(2));
187 EXPECT_FLOAT_EQ(8, curve->getValue(3));
188 }
189
190 // Tests that a cubic bezier timing function works as expected.
191 TEST(CCKeyframedAnimationCurveTest, CubicBezierTimingFunction)
192 {
193 scoped_ptr<CCKeyframedFloatAnimationCurve> curve(CCKeyframedFloatAnimationCu rve::create());
194 curve->addKeyframe(CCFloatKeyframe::create(0, 0, CCCubicBezierTimingFunction ::create(0.25, 0, 0.75, 1).PassAs<CCTimingFunction>()));
195 curve->addKeyframe(CCFloatKeyframe::create(1, 1, scoped_ptr<CCTimingFunction >()));
196
197 EXPECT_FLOAT_EQ(0, curve->getValue(0));
198 EXPECT_LT(0, curve->getValue(0.25));
199 EXPECT_GT(0.25, curve->getValue(0.25));
200 EXPECT_FLOAT_EQ(0.5, curve->getValue(0.5));
201 EXPECT_LT(0.75, curve->getValue(0.75));
202 EXPECT_GT(1, curve->getValue(0.75));
203 EXPECT_FLOAT_EQ(1, curve->getValue(1));
204 }
205
206 } // namespace
OLDNEW
« no previous file with comments | « cc/CCHeadsUpDisplayTest.cpp ('k') | cc/CCLayerAnimationControllerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698