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

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

Issue 52923003: Fixing reflectivity of operator== for timing functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 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/TimingFunction.h ('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
(Empty)
1 /*
2 * Copyright (c) 2013, Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "config.h"
32
33 #include "core/platform/animation/TimingFunction.h"
34
35 #include "core/platform/animation/TimingFunctionTestHelper.h"
36 #include <gmock/gmock.h>
37 #include <gtest/gtest.h>
38 #include <string>
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 using namespace WebCore;
68
69 namespace {
70
71 class TimingFunctionTest : public ::testing::Test {
72 protected:
73 virtual void SetUp()
74 {
75 // Needed for ChainedTimingFunction support
76 RuntimeEnabledFeatures::setWebAnimationsEnabled(true);
77 }
78
79 };
80
81 TEST_F(TimingFunctionTest, BaseOperatorEq)
82 {
83 RefPtr<TimingFunction> linearTiming = LinearTimingFunction::create();
84 RefPtr<TimingFunction> cubicTiming1 = CubicBezierTimingFunction::preset(Cubi cBezierTimingFunction::EaseIn);
85 RefPtr<TimingFunction> cubicTiming2 = CubicBezierTimingFunction::create(0.17 , 0.67, 1, -1.73);
86 RefPtr<TimingFunction> stepsTiming1 = StepsTimingFunction::preset(StepsTimin gFunction::End);
87 RefPtr<TimingFunction> stepsTiming2 = StepsTimingFunction::create(5, true);
88
89 NE_HELPER(v);
90 NE_HELPER_APPEND(v, linearTiming);
91 NE_HELPER_APPEND(v, cubicTiming1);
92 NE_HELPER_APPEND(v, cubicTiming2);
93 NE_HELPER_APPEND(v, stepsTiming1);
94 NE_HELPER_APPEND(v, stepsTiming2);
95 NE_HELPER_LOOP(v);
96 }
97
98 TEST_F(TimingFunctionTest, LinearOperatorEq)
99 {
100 RefPtr<TimingFunction> linearTiming1 = LinearTimingFunction::create();
101 RefPtr<TimingFunction> linearTiming2 = LinearTimingFunction::create();
102 EXPECT_REFV_EQ(linearTiming1, linearTiming1);
103 EXPECT_REFV_EQ(linearTiming1, linearTiming2);
104 }
105
106 TEST_F(TimingFunctionTest, CubicOperatorEq)
107 {
108 RefPtr<TimingFunction> cubicEaseInTiming1 = CubicBezierTimingFunction::prese t(CubicBezierTimingFunction::EaseIn);
109 RefPtr<TimingFunction> cubicEaseInTiming2 = CubicBezierTimingFunction::prese t(CubicBezierTimingFunction::EaseIn);
110 EXPECT_REFV_EQ(cubicEaseInTiming1, cubicEaseInTiming1);
111 EXPECT_REFV_EQ(cubicEaseInTiming1, cubicEaseInTiming2);
112
113 RefPtr<TimingFunction> cubicEaseOutTiming1 = CubicBezierTimingFunction::pres et(CubicBezierTimingFunction::EaseOut);
114 RefPtr<TimingFunction> cubicEaseOutTiming2 = CubicBezierTimingFunction::pres et(CubicBezierTimingFunction::EaseOut);
115 EXPECT_REFV_EQ(cubicEaseOutTiming1, cubicEaseOutTiming2);
116
117 RefPtr<TimingFunction> cubicEaseInOutTiming1 = CubicBezierTimingFunction::pr eset(CubicBezierTimingFunction::EaseInOut);
118 RefPtr<TimingFunction> cubicEaseInOutTiming2 = CubicBezierTimingFunction::pr eset(CubicBezierTimingFunction::EaseInOut);
119 EXPECT_REFV_EQ(cubicEaseInOutTiming1, cubicEaseInOutTiming2);
120
121 RefPtr<TimingFunction> cubicCustomTiming1 = CubicBezierTimingFunction::creat e(0.17, 0.67, 1, -1.73);
122 RefPtr<TimingFunction> cubicCustomTiming2 = CubicBezierTimingFunction::creat e(0.17, 0.67, 1, -1.73);
123 EXPECT_REFV_EQ(cubicCustomTiming1, cubicCustomTiming2);
124
125 NE_HELPER(v);
126 NE_HELPER_APPEND(v, cubicEaseInTiming1);
127 NE_HELPER_APPEND(v, cubicEaseOutTiming1);
128 NE_HELPER_APPEND(v, cubicEaseInOutTiming1);
129 NE_HELPER_APPEND(v, cubicCustomTiming1);
130 NE_HELPER_LOOP(v);
131 }
132
133 TEST_F(TimingFunctionTest, CubicOperatorEqReflectivityBug)
134 {
135 RefPtr<TimingFunction> cubicA = CubicBezierTimingFunction::preset(CubicBezie rTimingFunction::EaseIn);
136 RefPtr<TimingFunction> cubicB = CubicBezierTimingFunction::create(0.42, 0.0, 1.0, 1.0);
137 EXPECT_REFV_NE(cubicA, cubicB);
138 EXPECT_REFV_NE(cubicB, cubicA);
139 }
140
141 TEST_F(TimingFunctionTest, StepsOperatorEq)
142 {
143 RefPtr<TimingFunction> stepsTimingStart1 = StepsTimingFunction::preset(Steps TimingFunction::Start);
144 RefPtr<TimingFunction> stepsTimingStart2 = StepsTimingFunction::preset(Steps TimingFunction::Start);
145 EXPECT_REFV_EQ(stepsTimingStart1, stepsTimingStart1);
146 EXPECT_REFV_EQ(stepsTimingStart1, stepsTimingStart2);
147
148 RefPtr<TimingFunction> stepsTimingEnd1 = StepsTimingFunction::preset(StepsTi mingFunction::End);
149 RefPtr<TimingFunction> stepsTimingEnd2 = StepsTimingFunction::preset(StepsTi mingFunction::End);
150 EXPECT_REFV_EQ(stepsTimingEnd1, stepsTimingEnd2);
151
152 RefPtr<TimingFunction> stepsTimingCustom1 = StepsTimingFunction::create(5, t rue);
153 RefPtr<TimingFunction> stepsTimingCustom2 = StepsTimingFunction::create(5, f alse);
154 RefPtr<TimingFunction> stepsTimingCustom3 = StepsTimingFunction::create(7, t rue);
155 RefPtr<TimingFunction> stepsTimingCustom4 = StepsTimingFunction::create(7, f alse);
156
157 EXPECT_REFV_EQ(stepsTimingCustom1, StepsTimingFunction::create(5, true));
158 EXPECT_REFV_EQ(stepsTimingCustom2, StepsTimingFunction::create(5, false));
159 EXPECT_REFV_EQ(stepsTimingCustom3, StepsTimingFunction::create(7, true));
160 EXPECT_REFV_EQ(stepsTimingCustom4, StepsTimingFunction::create(7, false));
161
162 NE_HELPER(v);
163 NE_HELPER_APPEND(v, stepsTimingStart1);
164 NE_HELPER_APPEND(v, stepsTimingEnd1);
165 NE_HELPER_APPEND(v, stepsTimingCustom1);
166 NE_HELPER_APPEND(v, stepsTimingCustom2);
167 NE_HELPER_APPEND(v, stepsTimingCustom3);
168 NE_HELPER_APPEND(v, stepsTimingCustom4);
169 NE_HELPER_LOOP(v);
170 }
171
172 TEST_F(TimingFunctionTest, StepsOperatorEqReflectivityBug)
173 {
174 RefPtr<TimingFunction> stepsA = StepsTimingFunction::preset(StepsTimingFunct ion::Start);
175 RefPtr<TimingFunction> stepsB = StepsTimingFunction::create(1, true);
176 EXPECT_REFV_NE(stepsA, stepsB);
177 EXPECT_REFV_NE(stepsB, stepsA);
178 }
179
180
181 } // namespace
OLDNEW
« no previous file with comments | « Source/core/platform/animation/TimingFunction.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698