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

Side by Side Diff: Source/core/platform/animation/TimingFunctionTestHelperTest.cpp

Issue 60323005: Adding operator== to TimingFunctionTestHelper. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase + Fixing "control reaches end of non-void function". Created 7 years, 1 month 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 | « Source/core/platform/animation/TimingFunctionTestHelper.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013, Google Inc. All rights reserved. 2 * Copyright (c) 2013, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 19 matching lines...) Expand all
30 30
31 #include "config.h" 31 #include "config.h"
32 32
33 #include "core/platform/animation/TimingFunctionTestHelper.h" 33 #include "core/platform/animation/TimingFunctionTestHelper.h"
34 34
35 #include <gmock/gmock.h> 35 #include <gmock/gmock.h>
36 #include <gtest/gtest.h> 36 #include <gtest/gtest.h>
37 #include <sstream> 37 #include <sstream>
38 #include <string> 38 #include <string>
39 39
40 // FIXME: Remove once https://codereview.chromium.org/50603011/ lands.
41 #define EXPECT_REFV_EQ(a, b) EXPECT_EQ(*(a.get()), *(b.get()))
42 #define EXPECT_REFV_NE(a, b) EXPECT_NE(*(a.get()), *(b.get()))
43
44 // Couple of macros to quickly assert a bunch of timing functions are not
45 // equal.
46 #define NE_STRINGIZE(x) NE_STRINGIZE2(x)
47 #define NE_STRINGIZE2(x) #x
48 #define NE_HELPER(v) \
49 Vector<std::pair<std::string, RefPtr<TimingFunction> > > v;
50 #define NE_HELPER_APPEND(v, x) \
51 v.append(std::make_pair(std::string("Line " NE_STRINGIZE(__LINE__) ":" # x), x))
52 #define NE_HELPER_LOOP(v) \
53 for (size_t i = 0; i != v.size(); ++i) { \
54 for (size_t j = 0; j != v.size(); ++j) { \
55 if (i == j) \
56 continue; \
57 EXPECT_REFV_NE(v[i].second, v[j].second) \
58 << v[i].first \
59 << " (" << ::testing::PrintToString(*v[i].second.get()) << ")" \
60 << " == " \
61 << v[j].first \
62 << " (" << ::testing::PrintToString(*v[j].second.get()) << ")" \
63 << "\n"; \
64 } \
65 }
66
67 namespace {
40 68
41 using namespace WebCore; 69 using namespace WebCore;
42 70
43 namespace {
44
45 class TimingFunctionTestHelperTest : public ::testing::Test { 71 class TimingFunctionTestHelperTest : public ::testing::Test {
46 72
47 protected: 73 protected:
48 bool m_enabled; 74 bool m_enabled;
49 75
50 virtual void SetUp() 76 virtual void SetUp()
51 { 77 {
52 m_enabled = RuntimeEnabledFeatures::webAnimationsEnabled(); 78 m_enabled = RuntimeEnabledFeatures::webAnimationsEnabled();
53 // Needed for ChainedTimingFunction support 79 // Needed for ChainedTimingFunction support
54 RuntimeEnabledFeatures::setWebAnimationsEnabled(true); 80 RuntimeEnabledFeatures::setWebAnimationsEnabled(true);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 PrintToString(chainedMixed), 160 PrintToString(chainedMixed),
135 ::testing::MatchesRegex( 161 ::testing::MatchesRegex(
136 "ChainedTimingFunction@.*\\(" 162 "ChainedTimingFunction@.*\\("
137 "ChainedTimingFunction@.*\\(" 163 "ChainedTimingFunction@.*\\("
138 "LinearTimingFunction@.*\\[0 -> 1\\]" 164 "LinearTimingFunction@.*\\[0 -> 1\\]"
139 "\\)\\[0 -> 0.75\\], " 165 "\\)\\[0 -> 0.75\\], "
140 "CubicBezierTimingFunction@.*\\(Custom, 1, 0, 1, -1\\)\\[0.75 -> 1\\]" 166 "CubicBezierTimingFunction@.*\\(Custom, 1, 0, 1, -1\\)\\[0.75 -> 1\\]"
141 "\\)")); 167 "\\)"));
142 } 168 }
143 169
170 TEST_F(TimingFunctionTestHelperTest, BaseOperatorEq)
171 {
172 RefPtr<TimingFunction> linearTiming = LinearTimingFunction::create();
173 RefPtr<TimingFunction> cubicTiming1 = CubicBezierTimingFunction::preset(Cubi cBezierTimingFunction::EaseIn);
174 RefPtr<TimingFunction> cubicTiming2 = CubicBezierTimingFunction::create(0.17 , 0.67, 1, -1.73);
175 RefPtr<TimingFunction> stepsTiming1 = StepsTimingFunction::preset(StepsTimin gFunction::End);
176 RefPtr<TimingFunction> stepsTiming2 = StepsTimingFunction::create(5, true);
177
178 RefPtr<ChainedTimingFunction> chainedTiming1 = ChainedTimingFunction::create ();
179 chainedTiming1->appendSegment(1.0, linearTiming.get());
180
181 RefPtr<ChainedTimingFunction> chainedTiming2 = ChainedTimingFunction::create ();
182 chainedTiming2->appendSegment(0.5, cubicTiming1.get());
183 chainedTiming2->appendSegment(1.0, cubicTiming2.get());
184
185 NE_HELPER(v);
186 NE_HELPER_APPEND(v, linearTiming);
187 NE_HELPER_APPEND(v, cubicTiming1);
188 NE_HELPER_APPEND(v, cubicTiming2);
189 NE_HELPER_APPEND(v, stepsTiming1);
190 NE_HELPER_APPEND(v, stepsTiming2);
191 NE_HELPER_APPEND(v, chainedTiming1);
192 NE_HELPER_APPEND(v, chainedTiming2);
193 NE_HELPER_LOOP(v);
194 }
195
196 TEST_F(TimingFunctionTestHelperTest, LinearOperatorEq)
197 {
198 RefPtr<TimingFunction> linearTiming1 = LinearTimingFunction::create();
199 RefPtr<TimingFunction> linearTiming2 = LinearTimingFunction::create();
200 EXPECT_REFV_EQ(linearTiming1, linearTiming1);
201 EXPECT_REFV_EQ(linearTiming1, linearTiming2);
202 }
203
204 TEST_F(TimingFunctionTestHelperTest, CubicOperatorEq)
205 {
206 RefPtr<TimingFunction> cubicEaseInTiming1 = CubicBezierTimingFunction::prese t(CubicBezierTimingFunction::EaseIn);
207 RefPtr<TimingFunction> cubicEaseInTiming2 = CubicBezierTimingFunction::prese t(CubicBezierTimingFunction::EaseIn);
208 EXPECT_REFV_EQ(cubicEaseInTiming1, cubicEaseInTiming1);
209 EXPECT_REFV_EQ(cubicEaseInTiming1, cubicEaseInTiming2);
210
211 RefPtr<TimingFunction> cubicEaseOutTiming1 = CubicBezierTimingFunction::pres et(CubicBezierTimingFunction::EaseOut);
212 RefPtr<TimingFunction> cubicEaseOutTiming2 = CubicBezierTimingFunction::pres et(CubicBezierTimingFunction::EaseOut);
213 EXPECT_REFV_EQ(cubicEaseOutTiming1, cubicEaseOutTiming2);
214
215 RefPtr<TimingFunction> cubicEaseInOutTiming1 = CubicBezierTimingFunction::pr eset(CubicBezierTimingFunction::EaseInOut);
216 RefPtr<TimingFunction> cubicEaseInOutTiming2 = CubicBezierTimingFunction::pr eset(CubicBezierTimingFunction::EaseInOut);
217 EXPECT_REFV_EQ(cubicEaseInOutTiming1, cubicEaseInOutTiming2);
218
219 RefPtr<TimingFunction> cubicCustomTiming1 = CubicBezierTimingFunction::creat e(0.17, 0.67, 1, -1.73);
220 RefPtr<TimingFunction> cubicCustomTiming2 = CubicBezierTimingFunction::creat e(0.17, 0.67, 1, -1.73);
221 EXPECT_REFV_EQ(cubicCustomTiming1, cubicCustomTiming2);
222
223 NE_HELPER(v);
224 NE_HELPER_APPEND(v, cubicEaseInTiming1);
225 NE_HELPER_APPEND(v, cubicEaseOutTiming1);
226 NE_HELPER_APPEND(v, cubicEaseInOutTiming1);
227 NE_HELPER_APPEND(v, cubicCustomTiming1);
228 NE_HELPER_LOOP(v);
229 }
230
231 TEST_F(TimingFunctionTestHelperTest, CubicOperatorEqReflectivity)
232 {
233 RefPtr<TimingFunction> cubicA = CubicBezierTimingFunction::preset(CubicBezie rTimingFunction::EaseIn);
234 RefPtr<TimingFunction> cubicB = CubicBezierTimingFunction::create(0.42, 0.0, 1.0, 1.0);
235 EXPECT_REFV_NE(cubicA, cubicB);
236 EXPECT_REFV_NE(cubicB, cubicA);
237 }
238
239 TEST_F(TimingFunctionTestHelperTest, StepsOperatorEq)
240 {
241 RefPtr<TimingFunction> stepsTimingStart1 = StepsTimingFunction::preset(Steps TimingFunction::Start);
242 RefPtr<TimingFunction> stepsTimingStart2 = StepsTimingFunction::preset(Steps TimingFunction::Start);
243 EXPECT_REFV_EQ(stepsTimingStart1, stepsTimingStart1);
244 EXPECT_REFV_EQ(stepsTimingStart1, stepsTimingStart2);
245
246 RefPtr<TimingFunction> stepsTimingEnd1 = StepsTimingFunction::preset(StepsTi mingFunction::End);
247 RefPtr<TimingFunction> stepsTimingEnd2 = StepsTimingFunction::preset(StepsTi mingFunction::End);
248 EXPECT_REFV_EQ(stepsTimingEnd1, stepsTimingEnd2);
249
250 RefPtr<TimingFunction> stepsTimingCustom1 = StepsTimingFunction::create(5, t rue);
251 RefPtr<TimingFunction> stepsTimingCustom2 = StepsTimingFunction::create(5, f alse);
252 RefPtr<TimingFunction> stepsTimingCustom3 = StepsTimingFunction::create(7, t rue);
253 RefPtr<TimingFunction> stepsTimingCustom4 = StepsTimingFunction::create(7, f alse);
254
255 EXPECT_REFV_EQ(stepsTimingCustom1, StepsTimingFunction::create(5, true));
256 EXPECT_REFV_EQ(stepsTimingCustom2, StepsTimingFunction::create(5, false));
257 EXPECT_REFV_EQ(stepsTimingCustom3, StepsTimingFunction::create(7, true));
258 EXPECT_REFV_EQ(stepsTimingCustom4, StepsTimingFunction::create(7, false));
259
260 NE_HELPER(v);
261 NE_HELPER_APPEND(v, stepsTimingStart1);
262 NE_HELPER_APPEND(v, stepsTimingEnd1);
263 NE_HELPER_APPEND(v, stepsTimingCustom1);
264 NE_HELPER_APPEND(v, stepsTimingCustom2);
265 NE_HELPER_APPEND(v, stepsTimingCustom3);
266 NE_HELPER_APPEND(v, stepsTimingCustom4);
267 NE_HELPER_LOOP(v);
268 }
269
270 TEST_F(TimingFunctionTestHelperTest, StepsOperatorEqReflectivity)
271 {
272 RefPtr<TimingFunction> stepsA = StepsTimingFunction::preset(StepsTimingFunct ion::Start);
273 RefPtr<TimingFunction> stepsB = StepsTimingFunction::create(1, true);
274 EXPECT_REFV_NE(stepsA, stepsB);
275 EXPECT_REFV_NE(stepsB, stepsA);
276 }
277
278 TEST_F(TimingFunctionTestHelperTest, ChainedEq)
279 {
280 // Single item in chain
281 RefPtr<TimingFunction> cubicTiming1 = CubicBezierTimingFunction::create(0.25 , 0.1, 0.25, 1.0);
282 RefPtr<TimingFunction> cubicTiming2 = CubicBezierTimingFunction::create(0.25 , 0.1, 0.25, 1.0);
283 RefPtr<TimingFunction> cubicTiming3 = CubicBezierTimingFunction::preset(Cubi cBezierTimingFunction::EaseOut);
284
285 RefPtr<ChainedTimingFunction> chainedSingleCubic1 = ChainedTimingFunction::c reate();
286 chainedSingleCubic1->appendSegment(1.0, cubicTiming1.get());
287 EXPECT_REFV_EQ(chainedSingleCubic1, chainedSingleCubic1);
288
289 RefPtr<ChainedTimingFunction> chainedSingleCubic2 = ChainedTimingFunction::c reate();
290 chainedSingleCubic2->appendSegment(1.0, cubicTiming1.get()); // Same inner t iming function
291 EXPECT_REFV_EQ(chainedSingleCubic1, chainedSingleCubic2);
292
293 RefPtr<ChainedTimingFunction> chainedSingleCubic3 = ChainedTimingFunction::c reate();
294 chainedSingleCubic3->appendSegment(1.0, cubicTiming2.get()); // == inner tim ing function
295 EXPECT_REFV_EQ(chainedSingleCubic1, chainedSingleCubic3);
296
297 RefPtr<ChainedTimingFunction> chainedSingleCubic4 = ChainedTimingFunction::c reate();
298 chainedSingleCubic4->appendSegment(0.5, cubicTiming1.get()); // Different of fset
299 EXPECT_REFV_NE(chainedSingleCubic1, chainedSingleCubic4);
300 EXPECT_REFV_NE(chainedSingleCubic3, chainedSingleCubic4);
301
302 RefPtr<ChainedTimingFunction> chainedSingleCubic5 = ChainedTimingFunction::c reate();
303 chainedSingleCubic5->appendSegment(1.0, cubicTiming3.get()); // != inner tim ing function (same type)
304 EXPECT_REFV_NE(chainedSingleCubic1, chainedSingleCubic5);
305 EXPECT_REFV_NE(chainedSingleCubic2, chainedSingleCubic5);
306 EXPECT_REFV_NE(chainedSingleCubic3, chainedSingleCubic5);
307 EXPECT_REFV_NE(chainedSingleCubic4, chainedSingleCubic5);
308
309 RefPtr<TimingFunction> linearTiming1 = LinearTimingFunction::create();
310 RefPtr<ChainedTimingFunction> chainedSingleLinear1 = ChainedTimingFunction:: create();
311 chainedSingleLinear1->appendSegment(1.0, linearTiming1.get()); // != inner t iming function (different type)
312 EXPECT_REFV_NE(chainedSingleLinear1, chainedSingleCubic1);
313 EXPECT_REFV_NE(chainedSingleLinear1, chainedSingleCubic2);
314 EXPECT_REFV_NE(chainedSingleLinear1, chainedSingleCubic3);
315 EXPECT_REFV_NE(chainedSingleLinear1, chainedSingleCubic4);
316
317 // Multiple items in chain
318 RefPtr<ChainedTimingFunction> chainedMixed1 = ChainedTimingFunction::create( );
319 chainedMixed1->appendSegment(0.25, chainedSingleLinear1.get());
320 chainedMixed1->appendSegment(1.0, cubicTiming1.get());
321
322 RefPtr<ChainedTimingFunction> chainedMixed2 = ChainedTimingFunction::create( );
323 chainedMixed2->appendSegment(0.25, chainedSingleLinear1.get());
324 chainedMixed2->appendSegment(1.0, cubicTiming1.get());
325
326 RefPtr<ChainedTimingFunction> chainedMixed3 = ChainedTimingFunction::create( );
327 chainedMixed3->appendSegment(0.25, chainedSingleLinear1.get());
328 chainedMixed3->appendSegment(1.0, cubicTiming2.get());
329
330 EXPECT_REFV_EQ(chainedMixed1, chainedMixed2);
331 EXPECT_REFV_EQ(chainedMixed1, chainedMixed3);
332 EXPECT_REFV_NE(chainedMixed1, chainedSingleCubic1);
333 EXPECT_REFV_NE(chainedMixed1, chainedSingleLinear1);
334
335 RefPtr<ChainedTimingFunction> chainedMixed4 = ChainedTimingFunction::create( );
336 chainedMixed4->appendSegment(0.20, chainedSingleLinear1.get()); // Different offset
337 chainedMixed4->appendSegment(1.0, cubicTiming1.get());
338 EXPECT_REFV_NE(chainedMixed1, chainedMixed4);
339 }
340
144 } // namespace 341 } // namespace
OLDNEW
« no previous file with comments | « Source/core/platform/animation/TimingFunctionTestHelper.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698