OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "sky/engine/config.h" | |
6 #include "sky/engine/core/animation/TimingInput.h" | |
7 | |
8 #include <gtest/gtest.h> | |
9 | |
10 #include "sky/engine/bindings/core/v8/Dictionary.h" | |
11 #include "sky/engine/core/animation/AnimationNodeTiming.h" | |
12 #include "sky/engine/core/animation/AnimationTestHelper.h" | |
13 #include "v8/include/v8.h" | |
14 | |
15 namespace blink { | |
16 | |
17 class AnimationTimingInputTest : public ::testing::Test { | |
18 protected: | |
19 AnimationTimingInputTest() | |
20 : m_isolate(v8::Isolate::GetCurrent()) | |
21 , m_scope(m_isolate) | |
22 { | |
23 } | |
24 | |
25 Timing applyTimingInputNumber(String timingProperty, double timingPropertyVa
lue) | |
26 { | |
27 v8::Handle<v8::Object> timingInput = v8::Object::New(m_isolate); | |
28 setV8ObjectPropertyAsNumber(timingInput, timingProperty, timingPropertyV
alue); | |
29 Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cas
t(timingInput), m_isolate); | |
30 return TimingInput::convert(timingInputDictionary); | |
31 } | |
32 | |
33 Timing applyTimingInputString(String timingProperty, String timingPropertyVa
lue) | |
34 { | |
35 v8::Handle<v8::Object> timingInput = v8::Object::New(m_isolate); | |
36 setV8ObjectPropertyAsString(timingInput, timingProperty, timingPropertyV
alue); | |
37 Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cas
t(timingInput), m_isolate); | |
38 return TimingInput::convert(timingInputDictionary); | |
39 } | |
40 | |
41 v8::Isolate* m_isolate; | |
42 | |
43 private: | |
44 V8TestingScope m_scope; | |
45 }; | |
46 | |
47 TEST_F(AnimationTimingInputTest, TimingInputStartDelay) | |
48 { | |
49 EXPECT_EQ(1.1, applyTimingInputNumber("delay", 1100).startDelay); | |
50 EXPECT_EQ(-1, applyTimingInputNumber("delay", -1000).startDelay); | |
51 EXPECT_EQ(1, applyTimingInputString("delay", "1000").startDelay); | |
52 EXPECT_EQ(0, applyTimingInputString("delay", "1s").startDelay); | |
53 EXPECT_EQ(0, applyTimingInputString("delay", "Infinity").startDelay); | |
54 EXPECT_EQ(0, applyTimingInputString("delay", "-Infinity").startDelay); | |
55 EXPECT_EQ(0, applyTimingInputString("delay", "NaN").startDelay); | |
56 EXPECT_EQ(0, applyTimingInputString("delay", "rubbish").startDelay); | |
57 } | |
58 | |
59 TEST_F(AnimationTimingInputTest, TimingInputEndDelay) | |
60 { | |
61 EXPECT_EQ(10, applyTimingInputNumber("endDelay", 10000).endDelay); | |
62 EXPECT_EQ(-2.5, applyTimingInputNumber("endDelay", -2500).endDelay); | |
63 } | |
64 | |
65 TEST_F(AnimationTimingInputTest, TimingInputFillMode) | |
66 { | |
67 Timing::FillMode defaultFillMode = Timing::FillModeAuto; | |
68 | |
69 EXPECT_EQ(Timing::FillModeAuto, applyTimingInputString("fill", "auto").fillM
ode); | |
70 EXPECT_EQ(Timing::FillModeForwards, applyTimingInputString("fill", "forwards
").fillMode); | |
71 EXPECT_EQ(Timing::FillModeNone, applyTimingInputString("fill", "none").fillM
ode); | |
72 EXPECT_EQ(Timing::FillModeBackwards, applyTimingInputString("fill", "backwar
ds").fillMode); | |
73 EXPECT_EQ(Timing::FillModeBoth, applyTimingInputString("fill", "both").fillM
ode); | |
74 EXPECT_EQ(defaultFillMode, applyTimingInputString("fill", "everything!").fil
lMode); | |
75 EXPECT_EQ(defaultFillMode, applyTimingInputString("fill", "backwardsandforwa
rds").fillMode); | |
76 EXPECT_EQ(defaultFillMode, applyTimingInputNumber("fill", 2).fillMode); | |
77 } | |
78 | |
79 TEST_F(AnimationTimingInputTest, TimingInputIterationStart) | |
80 { | |
81 EXPECT_EQ(1.1, applyTimingInputNumber("iterationStart", 1.1).iterationStart)
; | |
82 EXPECT_EQ(0, applyTimingInputNumber("iterationStart", -1).iterationStart); | |
83 EXPECT_EQ(0, applyTimingInputString("iterationStart", "Infinity").iterationS
tart); | |
84 EXPECT_EQ(0, applyTimingInputString("iterationStart", "-Infinity").iteration
Start); | |
85 EXPECT_EQ(0, applyTimingInputString("iterationStart", "NaN").iterationStart)
; | |
86 EXPECT_EQ(0, applyTimingInputString("iterationStart", "rubbish").iterationSt
art); | |
87 } | |
88 | |
89 TEST_F(AnimationTimingInputTest, TimingInputIterationCount) | |
90 { | |
91 EXPECT_EQ(2.1, applyTimingInputNumber("iterations", 2.1).iterationCount); | |
92 EXPECT_EQ(0, applyTimingInputNumber("iterations", -1).iterationCount); | |
93 | |
94 Timing timing = applyTimingInputString("iterations", "Infinity"); | |
95 EXPECT_TRUE(std::isinf(timing.iterationCount)); | |
96 EXPECT_GT(timing.iterationCount, 0); | |
97 | |
98 EXPECT_EQ(0, applyTimingInputString("iterations", "-Infinity").iterationCoun
t); | |
99 EXPECT_EQ(1, applyTimingInputString("iterations", "NaN").iterationCount); | |
100 EXPECT_EQ(1, applyTimingInputString("iterations", "rubbish").iterationCount)
; | |
101 } | |
102 | |
103 TEST_F(AnimationTimingInputTest, TimingInputIterationDuration) | |
104 { | |
105 EXPECT_EQ(1.1, applyTimingInputNumber("duration", 1100).iterationDuration); | |
106 EXPECT_TRUE(std::isnan(applyTimingInputNumber("duration", -1000).iterationDu
ration)); | |
107 EXPECT_EQ(1, applyTimingInputString("duration", "1000").iterationDuration); | |
108 | |
109 Timing timing = applyTimingInputString("duration", "Infinity"); | |
110 EXPECT_TRUE(std::isinf(timing.iterationDuration)); | |
111 EXPECT_GT(timing.iterationDuration, 0); | |
112 | |
113 EXPECT_TRUE(std::isnan(applyTimingInputString("duration", "-Infinity").itera
tionDuration)); | |
114 EXPECT_TRUE(std::isnan(applyTimingInputString("duration", "NaN").iterationDu
ration)); | |
115 EXPECT_TRUE(std::isnan(applyTimingInputString("duration", "auto").iterationD
uration)); | |
116 EXPECT_TRUE(std::isnan(applyTimingInputString("duration", "rubbish").iterati
onDuration)); | |
117 } | |
118 | |
119 TEST_F(AnimationTimingInputTest, TimingInputPlaybackRate) | |
120 { | |
121 EXPECT_EQ(2.1, applyTimingInputNumber("playbackRate", 2.1).playbackRate); | |
122 EXPECT_EQ(-1, applyTimingInputNumber("playbackRate", -1).playbackRate); | |
123 EXPECT_EQ(1, applyTimingInputString("playbackRate", "Infinity").playbackRate
); | |
124 EXPECT_EQ(1, applyTimingInputString("playbackRate", "-Infinity").playbackRat
e); | |
125 EXPECT_EQ(1, applyTimingInputString("playbackRate", "NaN").playbackRate); | |
126 EXPECT_EQ(1, applyTimingInputString("playbackRate", "rubbish").playbackRate)
; | |
127 } | |
128 | |
129 TEST_F(AnimationTimingInputTest, TimingInputDirection) | |
130 { | |
131 Timing::PlaybackDirection defaultPlaybackDirection = Timing::PlaybackDirecti
onNormal; | |
132 | |
133 EXPECT_EQ(Timing::PlaybackDirectionNormal, applyTimingInputString("direction
", "normal").direction); | |
134 EXPECT_EQ(Timing::PlaybackDirectionReverse, applyTimingInputString("directio
n", "reverse").direction); | |
135 EXPECT_EQ(Timing::PlaybackDirectionAlternate, applyTimingInputString("direct
ion", "alternate").direction); | |
136 EXPECT_EQ(Timing::PlaybackDirectionAlternateReverse, applyTimingInputString(
"direction", "alternate-reverse").direction); | |
137 EXPECT_EQ(defaultPlaybackDirection, applyTimingInputString("direction", "rub
bish").direction); | |
138 EXPECT_EQ(defaultPlaybackDirection, applyTimingInputNumber("direction", 2).d
irection); | |
139 } | |
140 | |
141 TEST_F(AnimationTimingInputTest, TimingInputTimingFunction) | |
142 { | |
143 const RefPtr<TimingFunction> defaultTimingFunction = LinearTimingFunction::s
hared(); | |
144 | |
145 EXPECT_EQ(*CubicBezierTimingFunction::preset(CubicBezierTimingFunction::Ease
), *applyTimingInputString("easing", "ease").timingFunction); | |
146 EXPECT_EQ(*CubicBezierTimingFunction::preset(CubicBezierTimingFunction::Ease
In), *applyTimingInputString("easing", "ease-in").timingFunction); | |
147 EXPECT_EQ(*CubicBezierTimingFunction::preset(CubicBezierTimingFunction::Ease
Out), *applyTimingInputString("easing", "ease-out").timingFunction); | |
148 EXPECT_EQ(*CubicBezierTimingFunction::preset(CubicBezierTimingFunction::Ease
InOut), *applyTimingInputString("easing", "ease-in-out").timingFunction); | |
149 EXPECT_EQ(*LinearTimingFunction::shared(), *applyTimingInputString("easing",
"linear").timingFunction); | |
150 EXPECT_EQ(*StepsTimingFunction::preset(StepsTimingFunction::Start), *applyTi
mingInputString("easing", "step-start").timingFunction); | |
151 EXPECT_EQ(*StepsTimingFunction::preset(StepsTimingFunction::Middle), *applyT
imingInputString("easing", "step-middle").timingFunction); | |
152 EXPECT_EQ(*StepsTimingFunction::preset(StepsTimingFunction::End), *applyTimi
ngInputString("easing", "step-end").timingFunction); | |
153 EXPECT_EQ(*CubicBezierTimingFunction::create(1, 1, 0.3, 0.3), *applyTimingIn
putString("easing", "cubic-bezier(1, 1, 0.3, 0.3)").timingFunction); | |
154 EXPECT_EQ(*StepsTimingFunction::create(3, StepsTimingFunction::StepAtStart),
*applyTimingInputString("easing", "steps(3, start)").timingFunction); | |
155 EXPECT_EQ(*StepsTimingFunction::create(5, StepsTimingFunction::StepAtMiddle)
, *applyTimingInputString("easing", "steps(5, middle)").timingFunction); | |
156 EXPECT_EQ(*StepsTimingFunction::create(5, StepsTimingFunction::StepAtEnd), *
applyTimingInputString("easing", "steps(5, end)").timingFunction); | |
157 EXPECT_EQ(*defaultTimingFunction, *applyTimingInputString("easing", "steps(5
.6, end)").timingFunction); | |
158 EXPECT_EQ(*defaultTimingFunction, *applyTimingInputString("easing", "cubic-b
ezier(2, 2, 0.3, 0.3)").timingFunction); | |
159 EXPECT_EQ(*defaultTimingFunction, *applyTimingInputString("easing", "rubbish
").timingFunction); | |
160 EXPECT_EQ(*defaultTimingFunction, *applyTimingInputNumber("easing", 2).timin
gFunction); | |
161 EXPECT_EQ(*defaultTimingFunction, *applyTimingInputString("easing", "initial
").timingFunction); | |
162 } | |
163 | |
164 TEST_F(AnimationTimingInputTest, TimingInputEmpty) | |
165 { | |
166 Timing controlTiming; | |
167 | |
168 v8::Handle<v8::Object> timingInput = v8::Object::New(m_isolate); | |
169 Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(ti
mingInput), m_isolate); | |
170 Timing updatedTiming = TimingInput::convert(timingInputDictionary); | |
171 | |
172 EXPECT_EQ(controlTiming.startDelay, updatedTiming.startDelay); | |
173 EXPECT_EQ(controlTiming.fillMode, updatedTiming.fillMode); | |
174 EXPECT_EQ(controlTiming.iterationStart, updatedTiming.iterationStart); | |
175 EXPECT_EQ(controlTiming.iterationCount, updatedTiming.iterationCount); | |
176 EXPECT_TRUE(std::isnan(updatedTiming.iterationDuration)); | |
177 EXPECT_EQ(controlTiming.playbackRate, updatedTiming.playbackRate); | |
178 EXPECT_EQ(controlTiming.direction, updatedTiming.direction); | |
179 EXPECT_EQ(*controlTiming.timingFunction, *updatedTiming.timingFunction); | |
180 } | |
181 | |
182 } // namespace blink | |
OLD | NEW |