OLD | NEW |
---|---|
(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/TimingFunctionTestHelper.h" | |
34 | |
35 #include <gmock/gmock.h> | |
36 #include <gtest/gtest.h> | |
37 #include <sstream> | |
38 #include <string> | |
39 | |
40 | |
41 using namespace WebCore; | |
42 | |
43 namespace { | |
44 | |
45 class TimingFunctionTestHelperTest : public ::testing::Test { | |
shans
2013/10/31 20:22:54
I'm not a huge fan of these tests:
(1) If TimingFu
Steve Block
2013/11/03 09:18:32
I tend to agree. At a higher level, why do we have
mithro-old
2013/11/03 09:58:24
I think there is a misunderstand what is going on
Steve Block
2013/11/03 23:29:44
I see. I misunderstood your comment about the moti
| |
46 | |
47 protected: | |
48 bool m_enabled; | |
49 | |
50 virtual void SetUp() | |
51 { | |
52 m_enabled = RuntimeEnabledFeatures::webAnimationsEnabled(); | |
53 // Needed for ChainedTimingFunction support | |
54 RuntimeEnabledFeatures::setWebAnimationsEnabled(true); | |
55 } | |
56 | |
57 virtual void TearDown() | |
58 { | |
59 RuntimeEnabledFeatures::setWebAnimationsEnabled(m_enabled); | |
60 } | |
61 | |
62 public: | |
63 // Make sure that the CubicBezierTimingFunction call goes via the generic | |
64 // TimingFunction PrintTo. | |
65 ::std::string PrintToString(RefPtr<CubicBezierTimingFunction> timing) | |
66 { | |
67 RefPtr<TimingFunction> generic = timing; | |
68 return PrintToString(generic.get()); | |
69 } | |
70 | |
71 ::std::string PrintToString(RefPtr<TimingFunction> timing) | |
72 { | |
73 return PrintToString(timing.get()); | |
74 } | |
75 | |
76 ::std::string PrintToString(const TimingFunction* timing) | |
77 { | |
78 return ::testing::PrintToString(*timing); | |
79 } | |
80 }; | |
81 | |
82 TEST_F(TimingFunctionTestHelperTest, LinearPrintTo) | |
83 { | |
84 RefPtr<TimingFunction> linearTiming = LinearTimingFunction::create(); | |
85 EXPECT_THAT( | |
86 PrintToString(linearTiming), | |
87 ::testing::MatchesRegex("LinearTimingFunction@0x\\w+")); | |
88 } | |
89 | |
90 TEST_F(TimingFunctionTestHelperTest, CubicPrintTo) | |
91 { | |
92 RefPtr<TimingFunction> cubicEaseTiming = CubicBezierTimingFunction::preset(C ubicBezierTimingFunction::EaseIn); | |
93 EXPECT_THAT( | |
94 PrintToString(cubicEaseTiming), | |
95 ::testing::MatchesRegex("CubicBezierTimingFunction@0x\\w+\\(EaseIn, 0.42 , 0, 1, 1\\)")); | |
96 | |
97 RefPtr<TimingFunction> cubicCustomTiming = CubicBezierTimingFunction::create (0.17, 0.67, 1, -1.73); | |
98 EXPECT_THAT( | |
99 PrintToString(cubicCustomTiming), | |
100 ::testing::MatchesRegex("CubicBezierTimingFunction@0x\\w+\\(Custom, 0.17 , 0.67, 1, -1.73\\)")); | |
101 } | |
102 | |
103 TEST_F(TimingFunctionTestHelperTest, StepPrintTo) | |
104 { | |
105 RefPtr<TimingFunction> stepTimingStart = StepsTimingFunction::preset(StepsTi mingFunction::Start); | |
106 EXPECT_THAT( | |
107 PrintToString(stepTimingStart), | |
108 ::testing::MatchesRegex("StepsTimingFunction@0x\\w+\\(Start, 1, true\\)" )); | |
109 | |
110 RefPtr<TimingFunction> stepTimingCustom = StepsTimingFunction::create(5, fal se); | |
111 EXPECT_THAT( | |
112 PrintToString(stepTimingCustom), | |
113 ::testing::MatchesRegex("StepsTimingFunction@0x\\w+\\(Custom, 5, false\\ )")); | |
114 } | |
115 | |
116 TEST_F(TimingFunctionTestHelperTest, ChainedPrintTo) | |
117 { | |
118 RefPtr<TimingFunction> linearTiming = LinearTimingFunction::create(); | |
119 RefPtr<ChainedTimingFunction> chainedLinearSingle = ChainedTimingFunction::c reate(); | |
120 chainedLinearSingle->appendSegment(1.0, linearTiming.get()); | |
121 EXPECT_THAT( | |
122 PrintToString(chainedLinearSingle), | |
123 ::testing::MatchesRegex( | |
124 "ChainedTimingFunction@0x\\w+\\(" | |
125 "LinearTimingFunction@0x\\w+\\[0 -> 1\\]" | |
126 "\\)")); | |
127 | |
128 RefPtr<TimingFunction> cubicCustomTiming = CubicBezierTimingFunction::create (1.0, 0.0, 1, -1); | |
129 | |
130 RefPtr<ChainedTimingFunction> chainedMixed = ChainedTimingFunction::create() ; | |
131 chainedMixed->appendSegment(0.75, chainedLinearSingle.get()); | |
132 chainedMixed->appendSegment(1.0, cubicCustomTiming.get()); | |
133 EXPECT_THAT( | |
134 PrintToString(chainedMixed), | |
135 ::testing::MatchesRegex( | |
136 "ChainedTimingFunction@0x\\w+\\(" | |
137 "ChainedTimingFunction@0x\\w+\\(" | |
138 "LinearTimingFunction@0x\\w+\\[0 -> 1\\]" | |
139 "\\)\\[0 -> 0.75\\], " | |
140 "CubicBezierTimingFunction@0x\\w+\\(Custom, 1, 0, 1, -1\\)\\[0.7 5 -> 1\\]" | |
141 "\\)")); | |
142 } | |
143 | |
144 } // namespace | |
OLD | NEW |