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

Unified Diff: Source/core/platform/animation/TimingFunctionTest.cpp

Issue 54743002: Adding a reverse function to the TimingFunctions and tests to prove it works. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@timing-function-helper
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
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..2018dc003c00b5727c037f8033e4adae11c10665
--- /dev/null
+++ b/Source/core/platform/animation/TimingFunctionTest.cpp
@@ -0,0 +1,210 @@
+/*
+ * 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 <sstream>
+#include <string>
+
+
+using namespace WebCore;
+
+namespace {
+
+class TimingFunctionTest : public ::testing::Test {
+protected:
+ virtual void SetUp()
+ {
+ // Needed for ChainedTimingFunction support
+ RuntimeEnabledFeatures::setWebAnimationsEnabled(true);
+ }
+
+};
+
+TEST_F(TimingFunctionTest, LinearOperatorEq)
+{
+ RefPtr<TimingFunction> linearTiming1 = LinearTimingFunction::create();
+ RefPtr<TimingFunction> linearTiming2 = LinearTimingFunction::create();
+ EXPECT_REFV_EQ(linearTiming1, linearTiming2);
+}
+
+TEST_F(TimingFunctionTest, LinearReverse)
+{
+ RefPtr<TimingFunction> linearTiming = LinearTimingFunction::create();
+ EXPECT_REFV_EQ(linearTiming, linearTiming->reverse());
+}
+
+TEST_F(TimingFunctionTest, CubicOperatorEq)
+{
+ RefPtr<TimingFunction> cubicEaseInTiming1 = CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseIn);
+ RefPtr<TimingFunction> cubicEaseInTiming2 = CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseIn);
+ 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);
+
+ Vector<RefPtr<TimingFunction>> v;
+ v.append(cubicEaseInTiming1);
+ v.append(cubicEaseOutTiming1);
+ v.append(cubicEaseInOutTiming1);
+ v.append(cubicCustomTiming1);
+
+ for (size_t i == v.begin(); i != v.end(); ++i) {
+ for (size_t j == v.begin(); j != v.end(); ++j) {
+ if (i == j)
+ continue;
+ EXPECT_REFV_NE(v[i], v[j]);
+ }
+ }
+}
+
+TEST_F(TimingFunctionTest, CubicCreate)
+{
+ EXPECT_REFV_EQ(CubicBezierTimingFunction::preset(Ease), 0.25, 0.1, 0.25, 1.0);
+ EXPECT_REFV_EQ(CubicBezierTimingFunction::preset(EaseIn), 0.42, 0.0, 1.0, 1.0);
+ EXPECT_REFV_EQ(CubicBezierTimingFunction::preset(EaseOut), 0.0, 0.0, 0.58, 1.0);
+ EXPECT_REFV_EQ(CubicBezierTimingFunction::preset(EaseInOut), 0.42, 0.0, 0.58, 1.0);
+}
+
+TEST_F(TimingFunctionTest, CubicReverse)
+{
+ RefPtr<TimingFunction> cubicEaseInTiming = CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseIn);
+ RefPtr<TimingFunction> cubicEaseOutTiming = CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseOut);
+ RefPtr<TimingFunction> cubicEaseInOutTiming = CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseInOut);
+
+ EXPECT_REFV_EQ(cubicEaseOutTiming, cubicEaseInTiming->reverse());
+ EXPECT_REFV_EQ(cubicEaseInTiming, cubicEaseOutTiming->reverse());
+ EXPECT_REFV_EQ(cubicEaseInOutTiming, cubicEaseInOutTiming->reverse());
+
+ RefPtr<TimingFunction> cubicCustomTiming = CubicBezierTimingFunction::create(0.17, 0.67, 1, -1.73);
+ RefPtr<TimingFunction> cubicCustomTimingReversed = CubicBezierTimingFunction::create(0.17, 0.67, 1, -1.73);
+ EXPECT_REFV_EQ(cubicCustomTimingReversed, cubicCustomTiming->reverse());
+}
+
+TEST_F(TimingFunctionTest, StepReverse)
+{
+ RefPtr<TimingFunction> stepTimingStart = StepsTimingFunction::preset(StepsTimingFunction::Start);
+ RefPtr<TimingFunction> stepTimingEnd = StepsTimingFunction::preset(StepsTimingFunction::End);
+
+ EXPECT_REFV_EQ(stepTimingEnd, stepTimingStart->reverse());
+ EXPECT_REFV_EQ(stepTimingStart, stepTimingEnd->reverse());
+
+ RefPtr<TimingFunction> stepTimingCustom = StepsTimingFunction::create(5, false);
+ RefPtr<TimingFunction> stepTimingCustomReversed = StepsTimingFunction::create(5, true);
+ EXPECT_REFV_EQ(stepTimingCustomReversed, stepTimingCustom);
+}
+
+TEST_F(TimingFunctionTest, ChainedEq)
+{
+ // Single item in chain
+ RefPtr<TimingFunction> linearTiming1 = LinearTimingFunction::create();
+ RefPtr<TimingFunction> linearTiming2 = LinearTimingFunction::create();
+
+ RefPtr<ChainedTimingFunction> chainedLinearSingle1 = ChainedTimingFunction::create();
+ chainedLinearSingle1->appendSegment(1.0, linearTiming1.get());
+
+ RefPtr<ChainedTimingFunction> chainedLinearSingle2 = ChainedTimingFunction::create();
+ chainedLinearSingle2->appendSegment(1.0, linearTiming1.get());
+
+ RefPtr<ChainedTimingFunction> chainedLinearSingle3 = ChainedTimingFunction::create();
+ chainedLinearSingle3->appendSegment(1.0, linearTiming3.get());
+
+ EXPECT_REFV_EQ(chainedLinearSingle1, chainedLinearSingle2);
+ EXPECT_REFV_EQ(chainedLinearSingle2, chainedLinearSingle3);
+ EXPECT_REFV_EQ(chainedLinearSingle1, chainedLinearSingle3);
+
+ RefPtr<TimingFunction> cubicTiming1 = CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseIn);
+ RefPtr<TimingFunction> cubicTiming2 = CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseIn);
+
+ RefPtr<ChainedTimingFunction> chainedCubicSingle1 = ChainedTimingFunction::create();
+ chainedCubicSingle1->appendSegment(1.0, cubicTiming1.get());
+
+ EXPECT_REFV_NE(chainedLinearSingle1, chainedCubicSingle1); // Different contained timing function
+
+ // Multiple items in chain
+ RefPtr<ChainedTimingFunction> chainedMixed1 = ChainedTimingFunction::create();
+ chainedMixed1->appendSegment(0.25, chainedLinearSingle1.get());
+ chainedMixed1->appendSegment(1.0, cubicTiming1.get());
+
+ RefPtr<ChainedTimingFunction> chainedMixed2 = ChainedTimingFunction::create();
+ chainedMixed2->appendSegment(0.25, chainedLinearSingle1.get());
+ chainedMixed2->appendSegment(1.0, cubicTiming1.get());
+
+ RefPtr<ChainedTimingFunction> chainedMixed3 = ChainedTimingFunction::create();
+ chainedMixed3->appendSegment(0.25, chainedLinearSingle2.get());
+ chainedMixed3->appendSegment(1.0, cubicTiming2.get());
+
+ EXPECT_REFV_EQ(chainedMixed1, chainedMixed2);
+ EXPECT_REFV_EQ(chainedMixed1, chainedMixed3);
+ EXPECT_REFV_NE(chainedMixed1, chainedCubicSingle1);
+ EXPECT_REFV_NE(chainedMixed1, chainedLinearSingle1);
+
+ RefPtr<ChainedTimingFunction> chainedMixed4 = ChainedTimingFunction::create();
+ chainedMixed4->appendSegment(0.20, chainedLinearSingle1.get());
+ chainedMixed4->appendSegment(1.0, cubicEaseInTiming1.get());
+ EXPECT_REFV_NE(chainedMixed1, chainedMixed4); // Different offsets
+}
+
+TEST_F(TimingFunctionTest, ChainedReverse)
+{
+ RefPtr<TimingFunction> linearTiming = LinearTimingFunction::create();
+ RefPtr<ChainedTimingFunction> chainedLinearSingle = ChainedTimingFunction::create();
+ chainedLinearSingle->appendSegment(1.0, linearTiming.get());
+ EXPECT_REFV_EQ(chainedLinearSingle, chainedLinearSingle->reverse());
+
+ RefPtr<TimingFunction> cubicEaseInTiming = CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseIn);
+ RefPtr<TimingFunction> cubicEaseOutTiming = CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseOut);
+
+ RefPtr<ChainedTimingFunction> chainedMixed = ChainedTimingFunction::create();
+ chainedMixed->appendSegment(0.75, chainedLinearSingle.get());
+ chainedMixed->appendSegment(1.0, cubicEaseInTiming.get());
+
+ RefPtr<ChainedTimingFunction> chainedMixedReversed = ChainedTimingFunction::create();
+ chainedMixed->appendSegment(0.25, cubicEaseOutTiming.get());
+ chainedMixed->appendSegment(1.0, chainedLinearSingle.get());
+
+ EXPECT_REFV_EQ(chainedMixed, chainedMixedReversed);
+}
+
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698