OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "core/animation/Animation.h" | 6 #include "core/animation/Animation.h" |
7 | 7 |
8 #include "bindings/v8/Dictionary.h" | 8 #include "bindings/v8/Dictionary.h" |
9 #include "core/animation/AnimatableLength.h" | 9 #include "core/animation/AnimatableLength.h" |
10 #include "core/animation/AnimationClock.h" | 10 #include "core/animation/AnimationClock.h" |
11 #include "core/animation/AnimationHelpers.h" | 11 #include "core/animation/AnimationHelpers.h" |
12 #include "core/animation/DocumentTimeline.h" | 12 #include "core/animation/DocumentTimeline.h" |
13 #include "core/animation/KeyframeEffectModel.h" | 13 #include "core/animation/KeyframeEffectModel.h" |
| 14 #include "core/animation/TimedItemTiming.h" |
14 #include "platform/animation/TimingFunctionTestHelper.h" | 15 #include "platform/animation/TimingFunctionTestHelper.h" |
15 | 16 |
16 #include <gtest/gtest.h> | 17 #include <gtest/gtest.h> |
17 | 18 |
18 namespace WebCore { | 19 namespace WebCore { |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 v8::Handle<v8::Value> stringToV8Value(String string) | 23 v8::Handle<v8::Value> stringToV8Value(String string) |
23 { | 24 { |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 153 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
153 v8::HandleScope scope(isolate); | 154 v8::HandleScope scope(isolate); |
154 v8::Local<v8::Context> context = v8::Context::New(isolate); | 155 v8::Local<v8::Context> context = v8::Context::New(isolate); |
155 v8::Context::Scope contextScope(context); | 156 v8::Context::Scope contextScope(context); |
156 | 157 |
157 Vector<Dictionary, 0> jsKeyframes; | 158 Vector<Dictionary, 0> jsKeyframes; |
158 double duration = 2; | 159 double duration = 2; |
159 | 160 |
160 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, du
ration); | 161 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, du
ration); |
161 | 162 |
162 EXPECT_EQ(duration, animation->specified().iterationDuration); | 163 EXPECT_EQ(duration, animation->specifiedTiming().iterationDuration); |
163 } | 164 } |
164 | 165 |
165 TEST_F(AnimationAnimationTest, CanOmitSpecifiedDuration) | 166 TEST_F(AnimationAnimationTest, CanOmitSpecifiedDuration) |
166 { | 167 { |
167 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 168 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
168 v8::HandleScope scope(isolate); | 169 v8::HandleScope scope(isolate); |
169 v8::Local<v8::Context> context = v8::Context::New(isolate); | 170 v8::Local<v8::Context> context = v8::Context::New(isolate); |
170 v8::Context::Scope contextScope(context); | 171 v8::Context::Scope contextScope(context); |
171 | 172 |
172 Vector<Dictionary, 0> jsKeyframes; | 173 Vector<Dictionary, 0> jsKeyframes; |
173 | 174 |
174 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes); | 175 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes); |
175 | 176 |
176 EXPECT_TRUE(std::isnan(animation->specified().iterationDuration)); | 177 EXPECT_TRUE(std::isnan(animation->specifiedTiming().iterationDuration)); |
177 } | 178 } |
178 | 179 |
179 TEST_F(AnimationAnimationTest, ClipNegativeDurationToZero) | 180 TEST_F(AnimationAnimationTest, ClipNegativeDurationToZero) |
180 { | 181 { |
181 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 182 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
182 v8::HandleScope scope(isolate); | 183 v8::HandleScope scope(isolate); |
183 v8::Local<v8::Context> context = v8::Context::New(isolate); | 184 v8::Local<v8::Context> context = v8::Context::New(isolate); |
184 v8::Context::Scope contextScope(context); | 185 v8::Context::Scope contextScope(context); |
185 | 186 |
186 Vector<Dictionary, 0> jsKeyframes; | 187 Vector<Dictionary, 0> jsKeyframes; |
187 | 188 |
188 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, -2
); | 189 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, -2
); |
189 | 190 |
190 EXPECT_EQ(0, animation->specified().iterationDuration); | 191 EXPECT_EQ(0, animation->specifiedTiming().iterationDuration); |
| 192 } |
| 193 |
| 194 TEST_F(AnimationAnimationTest, SpecifiedGetters) |
| 195 { |
| 196 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 197 v8::HandleScope scope(isolate); |
| 198 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 199 v8::Context::Scope contextScope(context); |
| 200 |
| 201 Vector<Dictionary, 0> jsKeyframes; |
| 202 |
| 203 v8::Handle<v8::Object> timingInput = v8::Object::New(isolate); |
| 204 setV8ObjectPropertyAsNumber(timingInput, "delay", 2); |
| 205 setV8ObjectPropertyAsString(timingInput, "fill", "backwards"); |
| 206 setV8ObjectPropertyAsNumber(timingInput, "iterationStart", 2); |
| 207 setV8ObjectPropertyAsNumber(timingInput, "iterations", 10); |
| 208 setV8ObjectPropertyAsNumber(timingInput, "playbackRate", 2); |
| 209 setV8ObjectPropertyAsString(timingInput, "direction", "reverse"); |
| 210 setV8ObjectPropertyAsString(timingInput, "easing", "step-start"); |
| 211 Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(ti
mingInput), isolate); |
| 212 |
| 213 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, ti
mingInputDictionary); |
| 214 |
| 215 RefPtr<TimedItemTiming> specified = animation->specified(); |
| 216 EXPECT_EQ(2, specified->delay()); |
| 217 EXPECT_EQ("backwards", specified->fill()); |
| 218 EXPECT_EQ(2, specified->iterationStart()); |
| 219 EXPECT_EQ(10, specified->iterations()); |
| 220 EXPECT_EQ(2, specified->playbackRate()); |
| 221 EXPECT_EQ("reverse", specified->direction()); |
| 222 EXPECT_EQ("step-start", specified->easing()); |
| 223 } |
| 224 |
| 225 TEST_F(AnimationAnimationTest, SpecifiedDurationGetter) |
| 226 { |
| 227 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 228 v8::HandleScope scope(isolate); |
| 229 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 230 v8::Context::Scope contextScope(context); |
| 231 |
| 232 Vector<Dictionary, 0> jsKeyframes; |
| 233 |
| 234 v8::Handle<v8::Object> timingInputWithDuration = v8::Object::New(isolate); |
| 235 setV8ObjectPropertyAsNumber(timingInputWithDuration, "duration", 2.5); |
| 236 Dictionary timingInputDictionaryWithDuration = Dictionary(v8::Handle<v8::Val
ue>::Cast(timingInputWithDuration), isolate); |
| 237 |
| 238 RefPtr<Animation> animationWithDuration = createAnimation(element.get(), jsK
eyframes, timingInputDictionaryWithDuration); |
| 239 |
| 240 RefPtr<TimedItemTiming> specifiedWithDuration = animationWithDuration->speci
fied(); |
| 241 bool isNumber = false; |
| 242 double numberDuration = std::numeric_limits<double>::quiet_NaN(); |
| 243 bool isString = false; |
| 244 String stringDuration = ""; |
| 245 specifiedWithDuration->duration("duration", isNumber, numberDuration, isStri
ng, stringDuration); |
| 246 EXPECT_TRUE(isNumber); |
| 247 EXPECT_EQ(2.5, numberDuration); |
| 248 EXPECT_FALSE(isString); |
| 249 EXPECT_EQ("", stringDuration); |
| 250 |
| 251 |
| 252 v8::Handle<v8::Object> timingInputNoDuration = v8::Object::New(isolate); |
| 253 Dictionary timingInputDictionaryNoDuration = Dictionary(v8::Handle<v8::Value
>::Cast(timingInputNoDuration), isolate); |
| 254 |
| 255 RefPtr<Animation> animationNoDuration = createAnimation(element.get(), jsKey
frames, timingInputDictionaryNoDuration); |
| 256 |
| 257 RefPtr<TimedItemTiming> specifiedNoDuration = animationNoDuration->specified
(); |
| 258 isNumber = false; |
| 259 numberDuration = std::numeric_limits<double>::quiet_NaN(); |
| 260 isString = false; |
| 261 stringDuration = ""; |
| 262 specifiedNoDuration->duration("duration", isNumber, numberDuration, isString
, stringDuration); |
| 263 EXPECT_FALSE(isNumber); |
| 264 EXPECT_TRUE(std::isnan(numberDuration)); |
| 265 EXPECT_TRUE(isString); |
| 266 EXPECT_EQ("auto", stringDuration); |
191 } | 267 } |
192 | 268 |
193 TEST_F(AnimationAnimationTest, TimingInputStartDelay) | 269 TEST_F(AnimationAnimationTest, TimingInputStartDelay) |
194 { | 270 { |
195 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 271 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
196 v8::HandleScope scope(isolate); | 272 v8::HandleScope scope(isolate); |
197 v8::Local<v8::Context> context = v8::Context::New(isolate); | 273 v8::Local<v8::Context> context = v8::Context::New(isolate); |
198 v8::Context::Scope contextScope(context); | 274 v8::Context::Scope contextScope(context); |
199 | 275 |
200 Timing timing; | 276 Timing timing; |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 EXPECT_EQ(controlTiming.fillMode, updatedTiming.fillMode); | 632 EXPECT_EQ(controlTiming.fillMode, updatedTiming.fillMode); |
557 EXPECT_EQ(controlTiming.iterationStart, updatedTiming.iterationStart); | 633 EXPECT_EQ(controlTiming.iterationStart, updatedTiming.iterationStart); |
558 EXPECT_EQ(controlTiming.iterationCount, updatedTiming.iterationCount); | 634 EXPECT_EQ(controlTiming.iterationCount, updatedTiming.iterationCount); |
559 EXPECT_TRUE(std::isnan(updatedTiming.iterationDuration)); | 635 EXPECT_TRUE(std::isnan(updatedTiming.iterationDuration)); |
560 EXPECT_EQ(controlTiming.playbackRate, updatedTiming.playbackRate); | 636 EXPECT_EQ(controlTiming.playbackRate, updatedTiming.playbackRate); |
561 EXPECT_EQ(controlTiming.direction, updatedTiming.direction); | 637 EXPECT_EQ(controlTiming.direction, updatedTiming.direction); |
562 EXPECT_EQ(*controlTiming.timingFunction.get(), *updatedTiming.timingFunction
.get()); | 638 EXPECT_EQ(*controlTiming.timingFunction.get(), *updatedTiming.timingFunction
.get()); |
563 } | 639 } |
564 | 640 |
565 } // namespace WebCore | 641 } // namespace WebCore |
OLD | NEW |