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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/platform/animation/TimingFunction.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/platform/animation/TimingFunctionTest.cpp
diff --git a/Source/core/platform/animation/TimingFunctionTest.cpp b/Source/core/platform/animation/TimingFunctionTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..24fe02982187f4fca4c18257356fd4c04249dbc1
--- /dev/null
+++ b/Source/core/platform/animation/TimingFunctionTest.cpp
@@ -0,0 +1,181 @@
+/*
+ * Copyright (c) 2013, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "core/platform/animation/TimingFunction.h"
+
+#include "core/platform/animation/TimingFunctionTestHelper.h"
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <string>
+
+// FIXME: Remove once https://codereview.chromium.org/50603011/ lands.
+#define EXPECT_REFV_EQ(a, b) EXPECT_EQ(*(a.get()), *(b.get()))
+#define EXPECT_REFV_NE(a, b) EXPECT_NE(*(a.get()), *(b.get()))
+
+// Couple of macros to quickly assert a bunch of timing functions are not
+// equal.
+#define NE_STRINGIZE(x) NE_STRINGIZE2(x)
+#define NE_STRINGIZE2(x) #x
+#define NE_HELPER(v) \
+ Vector<std::pair<std::string, RefPtr<TimingFunction> > > v;
+#define NE_HELPER_APPEND(v, x) \
+ v.append(std::make_pair(std::string("Line " NE_STRINGIZE(__LINE__) ":" # x), x))
+#define NE_HELPER_LOOP(v) \
+ for (size_t i = 0; i != v.size(); ++i) { \
+ for (size_t j = 0; j != v.size(); ++j) { \
+ if (i == j) \
+ continue; \
+ EXPECT_REFV_NE(v[i].second, v[j].second) \
+ << v[i].first \
+ << " (" << ::testing::PrintToString(*v[i].second.get()) << ")" \
+ << " == " \
+ << v[j].first \
+ << " (" << ::testing::PrintToString(*v[j].second.get()) << ")" \
+ << "\n"; \
+ } \
+ }
+
+using namespace WebCore;
+
+namespace {
+
+class TimingFunctionTest : public ::testing::Test {
+protected:
+ virtual void SetUp()
+ {
+ // Needed for ChainedTimingFunction support
+ RuntimeEnabledFeatures::setWebAnimationsEnabled(true);
+ }
+
+};
+
+TEST_F(TimingFunctionTest, BaseOperatorEq)
+{
+ RefPtr<TimingFunction> linearTiming = LinearTimingFunction::create();
+ RefPtr<TimingFunction> cubicTiming1 = CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseIn);
+ RefPtr<TimingFunction> cubicTiming2 = CubicBezierTimingFunction::create(0.17, 0.67, 1, -1.73);
+ RefPtr<TimingFunction> stepsTiming1 = StepsTimingFunction::preset(StepsTimingFunction::End);
+ RefPtr<TimingFunction> stepsTiming2 = StepsTimingFunction::create(5, true);
+
+ NE_HELPER(v);
+ NE_HELPER_APPEND(v, linearTiming);
+ NE_HELPER_APPEND(v, cubicTiming1);
+ NE_HELPER_APPEND(v, cubicTiming2);
+ NE_HELPER_APPEND(v, stepsTiming1);
+ NE_HELPER_APPEND(v, stepsTiming2);
+ NE_HELPER_LOOP(v);
+}
+
+TEST_F(TimingFunctionTest, LinearOperatorEq)
+{
+ RefPtr<TimingFunction> linearTiming1 = LinearTimingFunction::create();
+ RefPtr<TimingFunction> linearTiming2 = LinearTimingFunction::create();
+ EXPECT_REFV_EQ(linearTiming1, linearTiming1);
+ EXPECT_REFV_EQ(linearTiming1, linearTiming2);
+}
+
+TEST_F(TimingFunctionTest, CubicOperatorEq)
+{
+ RefPtr<TimingFunction> cubicEaseInTiming1 = CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseIn);
+ RefPtr<TimingFunction> cubicEaseInTiming2 = CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseIn);
+ EXPECT_REFV_EQ(cubicEaseInTiming1, cubicEaseInTiming1);
+ EXPECT_REFV_EQ(cubicEaseInTiming1, cubicEaseInTiming2);
+
+ RefPtr<TimingFunction> cubicEaseOutTiming1 = CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseOut);
+ RefPtr<TimingFunction> cubicEaseOutTiming2 = CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseOut);
+ EXPECT_REFV_EQ(cubicEaseOutTiming1, cubicEaseOutTiming2);
+
+ RefPtr<TimingFunction> cubicEaseInOutTiming1 = CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseInOut);
+ RefPtr<TimingFunction> cubicEaseInOutTiming2 = CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseInOut);
+ EXPECT_REFV_EQ(cubicEaseInOutTiming1, cubicEaseInOutTiming2);
+
+ RefPtr<TimingFunction> cubicCustomTiming1 = CubicBezierTimingFunction::create(0.17, 0.67, 1, -1.73);
+ RefPtr<TimingFunction> cubicCustomTiming2 = CubicBezierTimingFunction::create(0.17, 0.67, 1, -1.73);
+ EXPECT_REFV_EQ(cubicCustomTiming1, cubicCustomTiming2);
+
+ NE_HELPER(v);
+ NE_HELPER_APPEND(v, cubicEaseInTiming1);
+ NE_HELPER_APPEND(v, cubicEaseOutTiming1);
+ NE_HELPER_APPEND(v, cubicEaseInOutTiming1);
+ NE_HELPER_APPEND(v, cubicCustomTiming1);
+ NE_HELPER_LOOP(v);
+}
+
+TEST_F(TimingFunctionTest, CubicOperatorEqReflectivityBug)
+{
+ RefPtr<TimingFunction> cubicA = CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseIn);
+ RefPtr<TimingFunction> cubicB = CubicBezierTimingFunction::create(0.42, 0.0, 1.0, 1.0);
+ EXPECT_REFV_NE(cubicA, cubicB);
+ EXPECT_REFV_NE(cubicB, cubicA);
+}
+
+TEST_F(TimingFunctionTest, StepsOperatorEq)
+{
+ RefPtr<TimingFunction> stepsTimingStart1 = StepsTimingFunction::preset(StepsTimingFunction::Start);
+ RefPtr<TimingFunction> stepsTimingStart2 = StepsTimingFunction::preset(StepsTimingFunction::Start);
+ EXPECT_REFV_EQ(stepsTimingStart1, stepsTimingStart1);
+ EXPECT_REFV_EQ(stepsTimingStart1, stepsTimingStart2);
+
+ RefPtr<TimingFunction> stepsTimingEnd1 = StepsTimingFunction::preset(StepsTimingFunction::End);
+ RefPtr<TimingFunction> stepsTimingEnd2 = StepsTimingFunction::preset(StepsTimingFunction::End);
+ EXPECT_REFV_EQ(stepsTimingEnd1, stepsTimingEnd2);
+
+ RefPtr<TimingFunction> stepsTimingCustom1 = StepsTimingFunction::create(5, true);
+ RefPtr<TimingFunction> stepsTimingCustom2 = StepsTimingFunction::create(5, false);
+ RefPtr<TimingFunction> stepsTimingCustom3 = StepsTimingFunction::create(7, true);
+ RefPtr<TimingFunction> stepsTimingCustom4 = StepsTimingFunction::create(7, false);
+
+ EXPECT_REFV_EQ(stepsTimingCustom1, StepsTimingFunction::create(5, true));
+ EXPECT_REFV_EQ(stepsTimingCustom2, StepsTimingFunction::create(5, false));
+ EXPECT_REFV_EQ(stepsTimingCustom3, StepsTimingFunction::create(7, true));
+ EXPECT_REFV_EQ(stepsTimingCustom4, StepsTimingFunction::create(7, false));
+
+ NE_HELPER(v);
+ NE_HELPER_APPEND(v, stepsTimingStart1);
+ NE_HELPER_APPEND(v, stepsTimingEnd1);
+ NE_HELPER_APPEND(v, stepsTimingCustom1);
+ NE_HELPER_APPEND(v, stepsTimingCustom2);
+ NE_HELPER_APPEND(v, stepsTimingCustom3);
+ NE_HELPER_APPEND(v, stepsTimingCustom4);
+ NE_HELPER_LOOP(v);
+}
+
+TEST_F(TimingFunctionTest, StepsOperatorEqReflectivityBug)
+{
+ RefPtr<TimingFunction> stepsA = StepsTimingFunction::preset(StepsTimingFunction::Start);
+ RefPtr<TimingFunction> stepsB = StepsTimingFunction::create(1, true);
+ EXPECT_REFV_NE(stepsA, stepsB);
+ EXPECT_REFV_NE(stepsB, stepsA);
+}
+
+
+} // namespace
« 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