OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013, Google Inc. All rights reserved. | 2 * Copyright (c) 2013, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "core/animation/ElementAnimation.h" | 32 #include "core/animation/ElementAnimation.h" |
33 | 33 |
34 #include "bindings/v8/Dictionary.h" | 34 #include "bindings/v8/Dictionary.h" |
35 #include "core/animation/AnimatableLength.h" | 35 #include "core/animation/AnimatableLength.h" |
36 #include "core/animation/Animation.h" | 36 #include "core/animation/Animation.h" |
37 #include "core/animation/AnimationClock.h" | 37 #include "core/animation/AnimationClock.h" |
38 #include "core/animation/DocumentTimeline.h" | 38 #include "core/animation/DocumentTimeline.h" |
39 #include "core/animation/KeyframeEffectModel.h" | 39 #include "core/animation/KeyframeEffectModel.h" |
| 40 #include "core/animation/Timing.h" |
40 #include "core/dom/Document.h" | 41 #include "core/dom/Document.h" |
41 #include "core/dom/Element.h" | 42 #include "core/dom/Element.h" |
42 | 43 |
43 #include <gtest/gtest.h> | 44 #include <gtest/gtest.h> |
44 | 45 |
45 namespace WebCore { | 46 namespace WebCore { |
46 | 47 |
47 namespace { | 48 namespace { |
48 | 49 |
49 v8::Handle<v8::Value> stringToV8Value(String string) | 50 v8::Handle<v8::Value> stringToV8Value(String string) |
50 { | 51 { |
51 return v8::Handle<v8::Value>::Cast(v8String(v8::Isolate::GetCurrent(), strin
g)); | 52 return v8::Handle<v8::Value>::Cast(v8String(v8::Isolate::GetCurrent(), strin
g)); |
52 } | 53 } |
53 | 54 |
54 void setV8ObjectProperty(v8::Handle<v8::Object> object, String name, String valu
e) | 55 v8::Handle<v8::Value> doubleToV8Value(double number) |
| 56 { |
| 57 return v8::Handle<v8::Value>::Cast(v8::Number::New(v8::Isolate::GetCurrent()
, number)); |
| 58 } |
| 59 |
| 60 void setV8ObjectPropertyAsString(v8::Handle<v8::Object> object, String name, Str
ing value) |
55 { | 61 { |
56 object->Set(stringToV8Value(name), stringToV8Value(value)); | 62 object->Set(stringToV8Value(name), stringToV8Value(value)); |
57 } | 63 } |
58 | 64 |
| 65 void setV8ObjectPropertyAsNumber(v8::Handle<v8::Object> object, String name, dou
ble value) |
| 66 { |
| 67 object->Set(stringToV8Value(name), doubleToV8Value(value)); |
| 68 } |
| 69 |
59 } // namespace | 70 } // namespace |
60 | 71 |
61 class AnimationElementAnimationTest : public ::testing::Test { | 72 class AnimationElementAnimationTest : public ::testing::Test { |
62 protected: | 73 protected: |
63 virtual void SetUp() | 74 virtual void SetUp() |
64 { | 75 { |
65 document = Document::create(); | 76 document = Document::create(); |
66 document->animationClock().resetTimeForTesting(); | 77 document->animationClock().resetTimeForTesting(); |
67 element = document->createElement("foo", ASSERT_NO_EXCEPTION); | 78 element = document->createElement("foo", ASSERT_NO_EXCEPTION); |
68 document->timeline()->setZeroTime(0); | 79 document->timeline()->setZeroTime(0); |
69 ASSERT_EQ(0, document->timeline()->currentTime()); | 80 ASSERT_EQ(0, document->timeline()->currentTime()); |
70 } | 81 } |
71 | 82 |
72 RefPtr<Document> document; | 83 RefPtr<Document> document; |
73 RefPtr<Element> element; | 84 RefPtr<Element> element; |
74 | 85 |
| 86 void startAnimation(Element* element, Vector<Dictionary> keyframesDictionary
Vector, Dictionary timingInput) |
| 87 { |
| 88 ElementAnimation::startAnimation(element, keyframesDictionaryVector, tim
ingInput); |
| 89 } |
| 90 |
| 91 void startAnimation(Element* element, Vector<Dictionary> keyframesDictionary
Vector, double timingInput) |
| 92 { |
| 93 ElementAnimation::startAnimation(element, keyframesDictionaryVector, tim
ingInput); |
| 94 } |
| 95 |
75 void startAnimation(Element* element, Vector<Dictionary> keyframesDictionary
Vector) | 96 void startAnimation(Element* element, Vector<Dictionary> keyframesDictionary
Vector) |
76 { | 97 { |
77 ElementAnimation::startAnimation(element, keyframesDictionaryVector); | 98 ElementAnimation::startAnimation(element, keyframesDictionaryVector); |
78 } | 99 } |
79 | 100 |
80 void startAnimationWithSpecifiedDuration(Element* element, Vector<Dictionary
> keyframesDictionaryVector, double duration) | 101 void populateTiming(Timing& timing, Dictionary timingInputDictionary) |
81 { | 102 { |
82 ElementAnimation::startAnimation(element, keyframesDictionaryVector, dur
ation); | 103 ElementAnimation::populateTiming(timing, timingInputDictionary); |
| 104 } |
| 105 |
| 106 void applyTimingInputNumber(Timing& timing, v8::Isolate* isolate, String tim
ingProperty, double timingPropertyValue) |
| 107 { |
| 108 v8::Handle<v8::Object> timingInput = v8::Object::New(isolate); |
| 109 setV8ObjectPropertyAsNumber(timingInput, timingProperty, timingPropertyV
alue); |
| 110 Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cas
t(timingInput), isolate); |
| 111 populateTiming(timing, timingInputDictionary); |
| 112 } |
| 113 |
| 114 void applyTimingInputString(Timing& timing, v8::Isolate* isolate, String tim
ingProperty, String timingPropertyValue) |
| 115 { |
| 116 v8::Handle<v8::Object> timingInput = v8::Object::New(isolate); |
| 117 setV8ObjectPropertyAsString(timingInput, timingProperty, timingPropertyV
alue); |
| 118 Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cas
t(timingInput), isolate); |
| 119 populateTiming(timing, timingInputDictionary); |
83 } | 120 } |
84 }; | 121 }; |
85 | 122 |
86 TEST_F(AnimationElementAnimationTest, CanStartAnAnimation) | 123 TEST_F(AnimationElementAnimationTest, CanStartAnAnimation) |
87 { | 124 { |
88 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 125 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
89 v8::HandleScope scope(isolate); | 126 v8::HandleScope scope(isolate); |
90 v8::Local<v8::Context> context = v8::Context::New(isolate); | 127 v8::Local<v8::Context> context = v8::Context::New(isolate); |
91 v8::Context::Scope contextScope(context); | 128 v8::Context::Scope contextScope(context); |
92 | 129 |
93 Vector<Dictionary> jsKeyframes; | 130 Vector<Dictionary> jsKeyframes; |
94 v8::Handle<v8::Object> keyframe1 = v8::Object::New(isolate); | 131 v8::Handle<v8::Object> keyframe1 = v8::Object::New(isolate); |
95 v8::Handle<v8::Object> keyframe2 = v8::Object::New(isolate); | 132 v8::Handle<v8::Object> keyframe2 = v8::Object::New(isolate); |
96 | 133 |
97 setV8ObjectProperty(keyframe1, "width", "100px"); | 134 setV8ObjectPropertyAsString(keyframe1, "width", "100px"); |
98 setV8ObjectProperty(keyframe1, "offset", "0"); | 135 setV8ObjectPropertyAsString(keyframe1, "offset", "0"); |
99 setV8ObjectProperty(keyframe2, "width", "0px"); | 136 setV8ObjectPropertyAsString(keyframe2, "width", "0px"); |
100 setV8ObjectProperty(keyframe2, "offset", "1"); | 137 setV8ObjectPropertyAsString(keyframe2, "offset", "1"); |
101 | 138 |
102 jsKeyframes.append(Dictionary(keyframe1, isolate)); | 139 jsKeyframes.append(Dictionary(keyframe1, isolate)); |
103 jsKeyframes.append(Dictionary(keyframe2, isolate)); | 140 jsKeyframes.append(Dictionary(keyframe2, isolate)); |
104 | 141 |
105 String value1; | 142 String value1; |
106 ASSERT_TRUE(jsKeyframes[0].get("width", value1)); | 143 ASSERT_TRUE(jsKeyframes[0].get("width", value1)); |
107 ASSERT_EQ("100px", value1); | 144 ASSERT_EQ("100px", value1); |
108 | 145 |
109 String value2; | 146 String value2; |
110 ASSERT_TRUE(jsKeyframes[1].get("width", value2)); | 147 ASSERT_TRUE(jsKeyframes[1].get("width", value2)); |
111 ASSERT_EQ("0px", value2); | 148 ASSERT_EQ("0px", value2); |
112 | 149 |
113 startAnimationWithSpecifiedDuration(element.get(), jsKeyframes, 0); | 150 startAnimation(element.get(), jsKeyframes, 0); |
114 | 151 |
115 Player* player = document->timeline()->players().at(0).get(); | 152 Player* player = document->timeline()->players().at(0).get(); |
116 | 153 |
117 Animation* animation = toAnimation(player->source()); | 154 Animation* animation = toAnimation(player->source()); |
118 | 155 |
119 Element* target = animation->target(); | 156 Element* target = animation->target(); |
120 EXPECT_EQ(*element.get(), *target); | 157 EXPECT_EQ(*element.get(), *target); |
121 | 158 |
122 const KeyframeEffectModel::KeyframeVector keyframes = | 159 const KeyframeEffectModel::KeyframeVector keyframes = |
123 toKeyframeEffectModel(animation->effect())->getFrames(); | 160 toKeyframeEffectModel(animation->effect())->getFrames(); |
(...skipping 26 matching lines...) Expand all Loading... |
150 } | 187 } |
151 | 188 |
152 TEST_F(AnimationElementAnimationTest, CanSetDuration) | 189 TEST_F(AnimationElementAnimationTest, CanSetDuration) |
153 { | 190 { |
154 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 191 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
155 v8::HandleScope scope(isolate); | 192 v8::HandleScope scope(isolate); |
156 v8::Local<v8::Context> context = v8::Context::New(isolate); | 193 v8::Local<v8::Context> context = v8::Context::New(isolate); |
157 v8::Context::Scope contextScope(context); | 194 v8::Context::Scope contextScope(context); |
158 | 195 |
159 Vector<Dictionary, 0> jsKeyframes; | 196 Vector<Dictionary, 0> jsKeyframes; |
| 197 |
160 double duration = 2; | 198 double duration = 2; |
161 | 199 startAnimation(element.get(), jsKeyframes, duration); |
162 startAnimationWithSpecifiedDuration(element.get(), jsKeyframes, duration); | |
163 | 200 |
164 Player* player = document->timeline()->players().at(0).get(); | 201 Player* player = document->timeline()->players().at(0).get(); |
165 | 202 |
166 EXPECT_TRUE(player->source()->specified().hasIterationDuration); | 203 EXPECT_TRUE(player->source()->specified().hasIterationDuration); |
167 EXPECT_EQ(duration, player->source()->specified().iterationDuration); | 204 EXPECT_EQ(duration, player->source()->specified().iterationDuration); |
168 } | 205 } |
169 | 206 |
170 TEST_F(AnimationElementAnimationTest, CanOmitSpecifiedDuration) | 207 TEST_F(AnimationElementAnimationTest, CanOmitSpecifiedDuration) |
171 { | 208 { |
172 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 209 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
173 v8::HandleScope scope(isolate); | 210 v8::HandleScope scope(isolate); |
174 v8::Local<v8::Context> context = v8::Context::New(isolate); | 211 v8::Local<v8::Context> context = v8::Context::New(isolate); |
175 v8::Context::Scope contextScope(context); | 212 v8::Context::Scope contextScope(context); |
176 | 213 |
177 Vector<Dictionary, 0> jsKeyframes; | 214 Vector<Dictionary, 0> jsKeyframes; |
178 | 215 |
179 startAnimation(element.get(), jsKeyframes); | 216 startAnimation(element.get(), jsKeyframes); |
180 | 217 |
181 Player* player = document->timeline()->players().at(0).get(); | 218 Player* player = document->timeline()->players().at(0).get(); |
182 | 219 |
183 // FIXME: This is correct for the moment, as using c++ default arguments mea
ns | 220 EXPECT_FALSE(player->source()->specified().hasIterationDuration); |
184 // there is no way to tell whether a duration has been specified by the user
. | |
185 // Once we implment timing object arguments we should be able to tell, and t
his | |
186 // check should be changed to EXPECT_FALSE. | |
187 EXPECT_TRUE(player->source()->specified().hasIterationDuration); | |
188 EXPECT_EQ(0, player->source()->specified().iterationDuration); | 221 EXPECT_EQ(0, player->source()->specified().iterationDuration); |
189 } | 222 } |
190 | 223 |
191 TEST_F(AnimationElementAnimationTest, ClipNegativeDurationToZero) | 224 TEST_F(AnimationElementAnimationTest, ClipNegativeDurationToZero) |
192 { | 225 { |
193 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 226 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
194 v8::HandleScope scope(isolate); | 227 v8::HandleScope scope(isolate); |
195 v8::Local<v8::Context> context = v8::Context::New(isolate); | 228 v8::Local<v8::Context> context = v8::Context::New(isolate); |
196 v8::Context::Scope contextScope(context); | 229 v8::Context::Scope contextScope(context); |
197 | 230 |
198 Vector<Dictionary, 0> jsKeyframes; | 231 Vector<Dictionary, 0> jsKeyframes; |
199 double duration = -2; | |
200 | 232 |
201 startAnimationWithSpecifiedDuration(element.get(), jsKeyframes, duration); | 233 startAnimation(element.get(), jsKeyframes, -2); |
202 | 234 |
203 Player* player = document->timeline()->players().at(0).get(); | 235 Player* player = document->timeline()->players().at(0).get(); |
204 | 236 |
205 EXPECT_TRUE(player->source()->specified().hasIterationDuration); | 237 EXPECT_TRUE(player->source()->specified().hasIterationDuration); |
206 EXPECT_EQ(0, player->source()->specified().iterationDuration); | 238 EXPECT_EQ(0, player->source()->specified().iterationDuration); |
207 } | 239 } |
208 | 240 |
| 241 TEST_F(AnimationElementAnimationTest, TimingInputStartDelay) |
| 242 { |
| 243 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 244 v8::HandleScope scope(isolate); |
| 245 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 246 v8::Context::Scope contextScope(context); |
| 247 |
| 248 Timing timing; |
| 249 EXPECT_EQ(0, timing.startDelay); |
| 250 |
| 251 applyTimingInputNumber(timing, isolate, "delay", 1.1); |
| 252 EXPECT_EQ(1.1, timing.startDelay); |
| 253 timing.startDelay = 0; |
| 254 |
| 255 applyTimingInputNumber(timing, isolate, "delay", -1); |
| 256 EXPECT_EQ(-1, timing.startDelay); |
| 257 timing.startDelay = 0; |
| 258 |
| 259 applyTimingInputString(timing, isolate, "delay", "1"); |
| 260 EXPECT_EQ(1, timing.startDelay); |
| 261 timing.startDelay = 0; |
| 262 |
| 263 applyTimingInputString(timing, isolate, "delay", "1s"); |
| 264 EXPECT_EQ(0, timing.startDelay); |
| 265 timing.startDelay = 0; |
| 266 |
| 267 applyTimingInputString(timing, isolate, "delay", "Infinity"); |
| 268 EXPECT_EQ(0, timing.startDelay); |
| 269 timing.startDelay = 0; |
| 270 |
| 271 applyTimingInputString(timing, isolate, "delay", "-Infinity"); |
| 272 EXPECT_EQ(0, timing.startDelay); |
| 273 timing.startDelay = 0; |
| 274 |
| 275 applyTimingInputString(timing, isolate, "delay", "NaN"); |
| 276 EXPECT_EQ(0, timing.startDelay); |
| 277 timing.startDelay = 0; |
| 278 |
| 279 applyTimingInputString(timing, isolate, "delay", "rubbish"); |
| 280 EXPECT_EQ(0, timing.startDelay); |
| 281 timing.startDelay = 0; |
| 282 } |
| 283 |
| 284 TEST_F(AnimationElementAnimationTest, TimingInputFillMode) |
| 285 { |
| 286 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 287 v8::HandleScope scope(isolate); |
| 288 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 289 v8::Context::Scope contextScope(context); |
| 290 |
| 291 Timing timing; |
| 292 Timing::FillMode defaultFillMode = Timing::FillModeForwards; |
| 293 EXPECT_EQ(defaultFillMode, timing.fillMode); |
| 294 |
| 295 applyTimingInputString(timing, isolate, "fill", "forwards"); |
| 296 EXPECT_EQ(Timing::FillModeForwards, timing.fillMode); |
| 297 timing.fillMode = defaultFillMode; |
| 298 |
| 299 applyTimingInputString(timing, isolate, "fill", "none"); |
| 300 EXPECT_EQ(Timing::FillModeNone, timing.fillMode); |
| 301 timing.fillMode = defaultFillMode; |
| 302 |
| 303 applyTimingInputString(timing, isolate, "fill", "backwards"); |
| 304 EXPECT_EQ(Timing::FillModeBackwards, timing.fillMode); |
| 305 timing.fillMode = defaultFillMode; |
| 306 |
| 307 applyTimingInputString(timing, isolate, "fill", "both"); |
| 308 EXPECT_EQ(Timing::FillModeBoth, timing.fillMode); |
| 309 timing.fillMode = defaultFillMode; |
| 310 |
| 311 applyTimingInputString(timing, isolate, "fill", "everything!"); |
| 312 EXPECT_EQ(defaultFillMode, timing.fillMode); |
| 313 timing.fillMode = defaultFillMode; |
| 314 |
| 315 applyTimingInputString(timing, isolate, "fill", "backwardsandforwards"); |
| 316 EXPECT_EQ(defaultFillMode, timing.fillMode); |
| 317 timing.fillMode = defaultFillMode; |
| 318 |
| 319 applyTimingInputNumber(timing, isolate, "fill", 2); |
| 320 EXPECT_EQ(defaultFillMode, timing.fillMode); |
| 321 timing.fillMode = defaultFillMode; |
| 322 } |
| 323 |
| 324 TEST_F(AnimationElementAnimationTest, TimingInputIterationStart) |
| 325 { |
| 326 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 327 v8::HandleScope scope(isolate); |
| 328 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 329 v8::Context::Scope contextScope(context); |
| 330 |
| 331 Timing timing; |
| 332 EXPECT_EQ(0, timing.iterationStart); |
| 333 |
| 334 applyTimingInputNumber(timing, isolate, "iterationStart", 1.1); |
| 335 EXPECT_EQ(1.1, timing.iterationStart); |
| 336 timing.iterationStart = 0; |
| 337 |
| 338 applyTimingInputNumber(timing, isolate, "iterationStart", -1); |
| 339 EXPECT_EQ(0, timing.iterationStart); |
| 340 timing.iterationStart = 0; |
| 341 |
| 342 applyTimingInputString(timing, isolate, "iterationStart", "Infinity"); |
| 343 EXPECT_EQ(0, timing.iterationStart); |
| 344 timing.iterationStart = 0; |
| 345 |
| 346 applyTimingInputString(timing, isolate, "iterationStart", "-Infinity"); |
| 347 EXPECT_EQ(0, timing.iterationStart); |
| 348 timing.iterationStart = 0; |
| 349 |
| 350 applyTimingInputString(timing, isolate, "iterationStart", "NaN"); |
| 351 EXPECT_EQ(0, timing.iterationStart); |
| 352 timing.iterationStart = 0; |
| 353 |
| 354 applyTimingInputString(timing, isolate, "iterationStart", "rubbish"); |
| 355 EXPECT_EQ(0, timing.iterationStart); |
| 356 timing.iterationStart = 0; |
| 357 } |
| 358 |
| 359 TEST_F(AnimationElementAnimationTest, TimingInputIterationCount) |
| 360 { |
| 361 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 362 v8::HandleScope scope(isolate); |
| 363 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 364 v8::Context::Scope contextScope(context); |
| 365 |
| 366 Timing timing; |
| 367 EXPECT_EQ(1, timing.iterationCount); |
| 368 |
| 369 applyTimingInputNumber(timing, isolate, "iterations", 2.1); |
| 370 EXPECT_EQ(2.1, timing.iterationCount); |
| 371 timing.iterationCount = 1; |
| 372 |
| 373 applyTimingInputNumber(timing, isolate, "iterations", -1); |
| 374 EXPECT_EQ(0, timing.iterationCount); |
| 375 timing.iterationCount = 1; |
| 376 |
| 377 applyTimingInputString(timing, isolate, "iterations", "Infinity"); |
| 378 EXPECT_TRUE(isinf(timing.iterationCount) && (timing.iterationCount > 0)); |
| 379 timing.iterationCount = 1; |
| 380 |
| 381 applyTimingInputString(timing, isolate, "iterations", "-Infinity"); |
| 382 EXPECT_EQ(0, timing.iterationCount); |
| 383 timing.iterationCount = 1; |
| 384 |
| 385 applyTimingInputString(timing, isolate, "iterations", "NaN"); |
| 386 EXPECT_EQ(1, timing.iterationCount); |
| 387 timing.iterationCount = 1; |
| 388 |
| 389 applyTimingInputString(timing, isolate, "iterations", "rubbish"); |
| 390 EXPECT_EQ(1, timing.iterationCount); |
| 391 timing.iterationCount = 1; |
| 392 } |
| 393 |
| 394 TEST_F(AnimationElementAnimationTest, TimingInputIterationDuration) |
| 395 { |
| 396 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 397 v8::HandleScope scope(isolate); |
| 398 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 399 v8::Context::Scope contextScope(context); |
| 400 |
| 401 Timing timing; |
| 402 EXPECT_EQ(0, timing.iterationDuration); |
| 403 EXPECT_FALSE(timing.hasIterationDuration); |
| 404 |
| 405 applyTimingInputNumber(timing, isolate, "duration", 1.1); |
| 406 EXPECT_EQ(1.1, timing.iterationDuration); |
| 407 EXPECT_TRUE(timing.hasIterationDuration); |
| 408 timing.hasIterationDuration = false; |
| 409 timing.iterationDuration = 0; |
| 410 |
| 411 applyTimingInputNumber(timing, isolate, "duration", -1); |
| 412 EXPECT_EQ(0, timing.iterationDuration); |
| 413 EXPECT_TRUE(timing.hasIterationDuration); |
| 414 timing.hasIterationDuration = false; |
| 415 timing.iterationDuration = 0; |
| 416 |
| 417 applyTimingInputString(timing, isolate, "duration", "1"); |
| 418 EXPECT_EQ(1, timing.iterationDuration); |
| 419 EXPECT_TRUE(timing.hasIterationDuration); |
| 420 timing.hasIterationDuration = false; |
| 421 timing.iterationDuration = 0; |
| 422 |
| 423 applyTimingInputString(timing, isolate, "duration", "Infinity"); |
| 424 EXPECT_TRUE(isinf(timing.iterationDuration) && (timing.iterationDuration > 0
)); |
| 425 EXPECT_TRUE(timing.hasIterationDuration); |
| 426 timing.hasIterationDuration = false; |
| 427 timing.iterationDuration = 0; |
| 428 |
| 429 applyTimingInputString(timing, isolate, "duration", "-Infinity"); |
| 430 EXPECT_EQ(0, timing.iterationDuration); |
| 431 EXPECT_TRUE(timing.hasIterationDuration); |
| 432 timing.hasIterationDuration = false; |
| 433 timing.iterationDuration = 0; |
| 434 |
| 435 applyTimingInputString(timing, isolate, "duration", "NaN"); |
| 436 EXPECT_EQ(0, timing.iterationDuration); |
| 437 EXPECT_TRUE(timing.hasIterationDuration); |
| 438 timing.hasIterationDuration = false; |
| 439 timing.iterationDuration = 0; |
| 440 |
| 441 applyTimingInputString(timing, isolate, "duration", "auto"); |
| 442 EXPECT_EQ(0, timing.iterationDuration); |
| 443 EXPECT_TRUE(timing.hasIterationDuration); |
| 444 timing.hasIterationDuration = false; |
| 445 timing.iterationDuration = 0; |
| 446 |
| 447 applyTimingInputString(timing, isolate, "duration", "rubbish"); |
| 448 EXPECT_EQ(0, timing.iterationDuration); |
| 449 EXPECT_TRUE(timing.hasIterationDuration); |
| 450 timing.hasIterationDuration = false; |
| 451 timing.iterationDuration = 0; |
| 452 } |
| 453 |
| 454 TEST_F(AnimationElementAnimationTest, TimingInputPlaybackRate) |
| 455 { |
| 456 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 457 v8::HandleScope scope(isolate); |
| 458 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 459 v8::Context::Scope contextScope(context); |
| 460 |
| 461 Timing timing; |
| 462 EXPECT_EQ(1, timing.playbackRate); |
| 463 |
| 464 applyTimingInputNumber(timing, isolate, "playbackRate", 2.1); |
| 465 EXPECT_EQ(2.1, timing.playbackRate); |
| 466 timing.playbackRate = 1; |
| 467 |
| 468 applyTimingInputNumber(timing, isolate, "playbackRate", -1); |
| 469 EXPECT_EQ(-1, timing.playbackRate); |
| 470 timing.playbackRate = 1; |
| 471 |
| 472 applyTimingInputString(timing, isolate, "playbackRate", "Infinity"); |
| 473 EXPECT_EQ(1, timing.playbackRate); |
| 474 timing.playbackRate = 1; |
| 475 |
| 476 applyTimingInputString(timing, isolate, "playbackRate", "-Infinity"); |
| 477 EXPECT_EQ(1, timing.playbackRate); |
| 478 timing.playbackRate = 1; |
| 479 |
| 480 applyTimingInputString(timing, isolate, "playbackRate", "NaN"); |
| 481 EXPECT_EQ(1, timing.playbackRate); |
| 482 timing.playbackRate = 1; |
| 483 |
| 484 applyTimingInputString(timing, isolate, "playbackRate", "rubbish"); |
| 485 EXPECT_EQ(1, timing.playbackRate); |
| 486 timing.playbackRate = 1; |
| 487 } |
| 488 |
| 489 TEST_F(AnimationElementAnimationTest, TimingInputDirection) |
| 490 { |
| 491 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 492 v8::HandleScope scope(isolate); |
| 493 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 494 v8::Context::Scope contextScope(context); |
| 495 |
| 496 Timing timing; |
| 497 Timing::PlaybackDirection defaultPlaybackDirection = Timing::PlaybackDirecti
onNormal; |
| 498 EXPECT_EQ(defaultPlaybackDirection, timing.direction); |
| 499 |
| 500 applyTimingInputString(timing, isolate, "direction", "normal"); |
| 501 EXPECT_EQ(Timing::PlaybackDirectionNormal, timing.direction); |
| 502 timing.direction = defaultPlaybackDirection; |
| 503 |
| 504 applyTimingInputString(timing, isolate, "direction", "reverse"); |
| 505 EXPECT_EQ(Timing::PlaybackDirectionReverse, timing.direction); |
| 506 timing.direction = defaultPlaybackDirection; |
| 507 |
| 508 applyTimingInputString(timing, isolate, "direction", "alternate"); |
| 509 EXPECT_EQ(Timing::PlaybackDirectionAlternate, timing.direction); |
| 510 timing.direction = defaultPlaybackDirection; |
| 511 |
| 512 applyTimingInputString(timing, isolate, "direction", "alternate-reverse"); |
| 513 EXPECT_EQ(Timing::PlaybackDirectionAlternateReverse, timing.direction); |
| 514 timing.direction = defaultPlaybackDirection; |
| 515 |
| 516 applyTimingInputString(timing, isolate, "direction", "rubbish"); |
| 517 EXPECT_EQ(defaultPlaybackDirection, timing.direction); |
| 518 timing.direction = defaultPlaybackDirection; |
| 519 |
| 520 applyTimingInputNumber(timing, isolate, "direction", 2); |
| 521 EXPECT_EQ(defaultPlaybackDirection, timing.direction); |
| 522 timing.direction = defaultPlaybackDirection; |
| 523 } |
| 524 |
| 525 TEST_F(AnimationElementAnimationTest, TimingInputEmpty) |
| 526 { |
| 527 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 528 v8::HandleScope scope(isolate); |
| 529 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 530 v8::Context::Scope contextScope(context); |
| 531 |
| 532 Timing updatedTiming; |
| 533 Timing controlTiming; |
| 534 |
| 535 v8::Handle<v8::Object> timingInput = v8::Object::New(isolate); |
| 536 Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(ti
mingInput), isolate); |
| 537 populateTiming(updatedTiming, timingInputDictionary); |
| 538 |
| 539 EXPECT_EQ(controlTiming.startDelay, updatedTiming.startDelay); |
| 540 EXPECT_EQ(controlTiming.fillMode, updatedTiming.fillMode); |
| 541 EXPECT_EQ(controlTiming.iterationStart, updatedTiming.iterationStart); |
| 542 EXPECT_EQ(controlTiming.iterationCount, updatedTiming.iterationCount); |
| 543 EXPECT_EQ(controlTiming.iterationDuration, updatedTiming.iterationDuration); |
| 544 EXPECT_EQ(controlTiming.hasIterationDuration, updatedTiming.hasIterationDura
tion); |
| 545 EXPECT_EQ(controlTiming.playbackRate, updatedTiming.playbackRate); |
| 546 EXPECT_EQ(controlTiming.direction, updatedTiming.direction); |
| 547 } |
| 548 |
209 } // namespace WebCore | 549 } // namespace WebCore |
OLD | NEW |