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 Animation* startAnimation(Element* element, Vector<Dictionary> keyframesDict
ionaryVector, Dictionary timingInput) |
| 87 { |
| 88 return ElementAnimation::startAnimation(element, keyframesDictionaryVect
or, timingInput); |
| 89 } |
| 90 |
| 91 Animation* startAnimation(Element* element, Vector<Dictionary> keyframesDict
ionaryVector, double timingInput) |
| 92 { |
| 93 return ElementAnimation::startAnimation(element, keyframesDictionaryVect
or, timingInput); |
| 94 } |
| 95 |
75 Animation* startAnimation(Element* element, Vector<Dictionary> keyframesDict
ionaryVector) | 96 Animation* startAnimation(Element* element, Vector<Dictionary> keyframesDict
ionaryVector) |
76 { | 97 { |
77 return ElementAnimation::startAnimation(element, keyframesDictionaryVect
or); | 98 return ElementAnimation::startAnimation(element, keyframesDictionaryVect
or); |
78 } | 99 } |
79 | 100 |
80 Animation* startAnimationWithSpecifiedDuration(Element* element, Vector<Dict
ionary> keyframesDictionaryVector, double duration) | 101 void populateTiming(Timing& timing, Dictionary timingInputDictionary) |
81 { | 102 { |
82 return ElementAnimation::startAnimation(element, keyframesDictionaryVect
or, duration); | 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 Animation* animation = startAnimationWithSpecifiedDuration(element.get(), js
Keyframes, 0); | 150 Animation* animation = 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 EXPECT_EQ(animation, player->source()); | 153 EXPECT_EQ(animation, player->source()); |
117 | 154 |
118 Element* target = animation->target(); | 155 Element* target = animation->target(); |
119 EXPECT_EQ(*element.get(), *target); | 156 EXPECT_EQ(*element.get(), *target); |
120 | 157 |
121 const KeyframeEffectModel::KeyframeVector keyframes = | 158 const KeyframeEffectModel::KeyframeVector keyframes = |
122 toKeyframeEffectModel(animation->effect())->getFrames(); | 159 toKeyframeEffectModel(animation->effect())->getFrames(); |
123 | 160 |
(...skipping 27 matching lines...) Expand all Loading... |
151 TEST_F(AnimationElementAnimationTest, CanSetDuration) | 188 TEST_F(AnimationElementAnimationTest, CanSetDuration) |
152 { | 189 { |
153 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 190 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
154 v8::HandleScope scope(isolate); | 191 v8::HandleScope scope(isolate); |
155 v8::Local<v8::Context> context = v8::Context::New(isolate); | 192 v8::Local<v8::Context> context = v8::Context::New(isolate); |
156 v8::Context::Scope contextScope(context); | 193 v8::Context::Scope contextScope(context); |
157 | 194 |
158 Vector<Dictionary, 0> jsKeyframes; | 195 Vector<Dictionary, 0> jsKeyframes; |
159 double duration = 2; | 196 double duration = 2; |
160 | 197 |
161 Animation* animation = startAnimationWithSpecifiedDuration(element.get(), js
Keyframes, duration); | 198 Animation* animation = startAnimation(element.get(), jsKeyframes, duration); |
162 | 199 |
163 Player* player = document->timeline()->players().at(0).get(); | 200 Player* player = document->timeline()->players().at(0).get(); |
164 | 201 |
165 EXPECT_EQ(animation, player->source()); | 202 EXPECT_EQ(animation, player->source()); |
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 Animation* animation = startAnimation(element.get(), jsKeyframes); | 216 Animation* animation = 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 EXPECT_EQ(animation, player->source()); | 219 EXPECT_EQ(animation, player->source()); |
183 | 220 |
184 // FIXME: This is correct for the moment, as using c++ default arguments mea
ns | 221 EXPECT_FALSE(player->source()->specified().hasIterationDuration); |
185 // there is no way to tell whether a duration has been specified by the user
. | |
186 // Once we implment timing object arguments we should be able to tell, and t
his | |
187 // check should be changed to EXPECT_FALSE. | |
188 EXPECT_TRUE(player->source()->specified().hasIterationDuration); | |
189 EXPECT_EQ(0, player->source()->specified().iterationDuration); | 222 EXPECT_EQ(0, player->source()->specified().iterationDuration); |
190 } | 223 } |
191 | 224 |
192 TEST_F(AnimationElementAnimationTest, ClipNegativeDurationToZero) | 225 TEST_F(AnimationElementAnimationTest, ClipNegativeDurationToZero) |
193 { | 226 { |
194 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 227 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
195 v8::HandleScope scope(isolate); | 228 v8::HandleScope scope(isolate); |
196 v8::Local<v8::Context> context = v8::Context::New(isolate); | 229 v8::Local<v8::Context> context = v8::Context::New(isolate); |
197 v8::Context::Scope contextScope(context); | 230 v8::Context::Scope contextScope(context); |
198 | 231 |
199 Vector<Dictionary, 0> jsKeyframes; | 232 Vector<Dictionary, 0> jsKeyframes; |
200 double duration = -2; | |
201 | 233 |
202 Animation* animation = startAnimationWithSpecifiedDuration(element.get(), js
Keyframes, duration); | 234 Animation* animation = startAnimation(element.get(), jsKeyframes, -2); |
203 | 235 |
204 Player* player = document->timeline()->players().at(0).get(); | 236 Player* player = document->timeline()->players().at(0).get(); |
205 EXPECT_EQ(animation, player->source()); | 237 EXPECT_EQ(animation, player->source()); |
206 | 238 |
207 EXPECT_TRUE(player->source()->specified().hasIterationDuration); | 239 EXPECT_TRUE(player->source()->specified().hasIterationDuration); |
208 EXPECT_EQ(0, player->source()->specified().iterationDuration); | 240 EXPECT_EQ(0, player->source()->specified().iterationDuration); |
209 } | 241 } |
210 | 242 |
| 243 TEST_F(AnimationElementAnimationTest, TimingInputStartDelay) |
| 244 { |
| 245 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 246 v8::HandleScope scope(isolate); |
| 247 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 248 v8::Context::Scope contextScope(context); |
| 249 |
| 250 Timing timing; |
| 251 EXPECT_EQ(0, timing.startDelay); |
| 252 |
| 253 applyTimingInputNumber(timing, isolate, "delay", 1.1); |
| 254 EXPECT_EQ(1.1, timing.startDelay); |
| 255 timing.startDelay = 0; |
| 256 |
| 257 applyTimingInputNumber(timing, isolate, "delay", -1); |
| 258 EXPECT_EQ(-1, timing.startDelay); |
| 259 timing.startDelay = 0; |
| 260 |
| 261 applyTimingInputString(timing, isolate, "delay", "1"); |
| 262 EXPECT_EQ(1, timing.startDelay); |
| 263 timing.startDelay = 0; |
| 264 |
| 265 applyTimingInputString(timing, isolate, "delay", "1s"); |
| 266 EXPECT_EQ(0, timing.startDelay); |
| 267 timing.startDelay = 0; |
| 268 |
| 269 applyTimingInputString(timing, isolate, "delay", "Infinity"); |
| 270 EXPECT_EQ(0, timing.startDelay); |
| 271 timing.startDelay = 0; |
| 272 |
| 273 applyTimingInputString(timing, isolate, "delay", "-Infinity"); |
| 274 EXPECT_EQ(0, timing.startDelay); |
| 275 timing.startDelay = 0; |
| 276 |
| 277 applyTimingInputString(timing, isolate, "delay", "NaN"); |
| 278 EXPECT_EQ(0, timing.startDelay); |
| 279 timing.startDelay = 0; |
| 280 |
| 281 applyTimingInputString(timing, isolate, "delay", "rubbish"); |
| 282 EXPECT_EQ(0, timing.startDelay); |
| 283 timing.startDelay = 0; |
| 284 } |
| 285 |
| 286 TEST_F(AnimationElementAnimationTest, TimingInputFillMode) |
| 287 { |
| 288 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 289 v8::HandleScope scope(isolate); |
| 290 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 291 v8::Context::Scope contextScope(context); |
| 292 |
| 293 Timing timing; |
| 294 Timing::FillMode defaultFillMode = Timing::FillModeForwards; |
| 295 EXPECT_EQ(defaultFillMode, timing.fillMode); |
| 296 |
| 297 applyTimingInputString(timing, isolate, "fill", "forwards"); |
| 298 EXPECT_EQ(Timing::FillModeForwards, timing.fillMode); |
| 299 timing.fillMode = defaultFillMode; |
| 300 |
| 301 applyTimingInputString(timing, isolate, "fill", "none"); |
| 302 EXPECT_EQ(Timing::FillModeNone, timing.fillMode); |
| 303 timing.fillMode = defaultFillMode; |
| 304 |
| 305 applyTimingInputString(timing, isolate, "fill", "backwards"); |
| 306 EXPECT_EQ(Timing::FillModeBackwards, timing.fillMode); |
| 307 timing.fillMode = defaultFillMode; |
| 308 |
| 309 applyTimingInputString(timing, isolate, "fill", "both"); |
| 310 EXPECT_EQ(Timing::FillModeBoth, timing.fillMode); |
| 311 timing.fillMode = defaultFillMode; |
| 312 |
| 313 applyTimingInputString(timing, isolate, "fill", "everything!"); |
| 314 EXPECT_EQ(defaultFillMode, timing.fillMode); |
| 315 timing.fillMode = defaultFillMode; |
| 316 |
| 317 applyTimingInputString(timing, isolate, "fill", "backwardsandforwards"); |
| 318 EXPECT_EQ(defaultFillMode, timing.fillMode); |
| 319 timing.fillMode = defaultFillMode; |
| 320 |
| 321 applyTimingInputNumber(timing, isolate, "fill", 2); |
| 322 EXPECT_EQ(defaultFillMode, timing.fillMode); |
| 323 timing.fillMode = defaultFillMode; |
| 324 } |
| 325 |
| 326 TEST_F(AnimationElementAnimationTest, TimingInputIterationStart) |
| 327 { |
| 328 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 329 v8::HandleScope scope(isolate); |
| 330 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 331 v8::Context::Scope contextScope(context); |
| 332 |
| 333 Timing timing; |
| 334 EXPECT_EQ(0, timing.iterationStart); |
| 335 |
| 336 applyTimingInputNumber(timing, isolate, "iterationStart", 1.1); |
| 337 EXPECT_EQ(1.1, timing.iterationStart); |
| 338 timing.iterationStart = 0; |
| 339 |
| 340 applyTimingInputNumber(timing, isolate, "iterationStart", -1); |
| 341 EXPECT_EQ(0, timing.iterationStart); |
| 342 timing.iterationStart = 0; |
| 343 |
| 344 applyTimingInputString(timing, isolate, "iterationStart", "Infinity"); |
| 345 EXPECT_EQ(0, timing.iterationStart); |
| 346 timing.iterationStart = 0; |
| 347 |
| 348 applyTimingInputString(timing, isolate, "iterationStart", "-Infinity"); |
| 349 EXPECT_EQ(0, timing.iterationStart); |
| 350 timing.iterationStart = 0; |
| 351 |
| 352 applyTimingInputString(timing, isolate, "iterationStart", "NaN"); |
| 353 EXPECT_EQ(0, timing.iterationStart); |
| 354 timing.iterationStart = 0; |
| 355 |
| 356 applyTimingInputString(timing, isolate, "iterationStart", "rubbish"); |
| 357 EXPECT_EQ(0, timing.iterationStart); |
| 358 timing.iterationStart = 0; |
| 359 } |
| 360 |
| 361 TEST_F(AnimationElementAnimationTest, TimingInputIterationCount) |
| 362 { |
| 363 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 364 v8::HandleScope scope(isolate); |
| 365 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 366 v8::Context::Scope contextScope(context); |
| 367 |
| 368 Timing timing; |
| 369 EXPECT_EQ(1, timing.iterationCount); |
| 370 |
| 371 applyTimingInputNumber(timing, isolate, "iterations", 2.1); |
| 372 EXPECT_EQ(2.1, timing.iterationCount); |
| 373 timing.iterationCount = 1; |
| 374 |
| 375 applyTimingInputNumber(timing, isolate, "iterations", -1); |
| 376 EXPECT_EQ(0, timing.iterationCount); |
| 377 timing.iterationCount = 1; |
| 378 |
| 379 applyTimingInputString(timing, isolate, "iterations", "Infinity"); |
| 380 EXPECT_TRUE(isinf(timing.iterationCount) && (timing.iterationCount > 0)); |
| 381 timing.iterationCount = 1; |
| 382 |
| 383 applyTimingInputString(timing, isolate, "iterations", "-Infinity"); |
| 384 EXPECT_EQ(0, timing.iterationCount); |
| 385 timing.iterationCount = 1; |
| 386 |
| 387 applyTimingInputString(timing, isolate, "iterations", "NaN"); |
| 388 EXPECT_EQ(1, timing.iterationCount); |
| 389 timing.iterationCount = 1; |
| 390 |
| 391 applyTimingInputString(timing, isolate, "iterations", "rubbish"); |
| 392 EXPECT_EQ(1, timing.iterationCount); |
| 393 timing.iterationCount = 1; |
| 394 } |
| 395 |
| 396 TEST_F(AnimationElementAnimationTest, TimingInputIterationDuration) |
| 397 { |
| 398 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 399 v8::HandleScope scope(isolate); |
| 400 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 401 v8::Context::Scope contextScope(context); |
| 402 |
| 403 Timing timing; |
| 404 EXPECT_EQ(0, timing.iterationDuration); |
| 405 EXPECT_FALSE(timing.hasIterationDuration); |
| 406 |
| 407 applyTimingInputNumber(timing, isolate, "duration", 1.1); |
| 408 EXPECT_EQ(1.1, timing.iterationDuration); |
| 409 EXPECT_TRUE(timing.hasIterationDuration); |
| 410 timing.hasIterationDuration = false; |
| 411 timing.iterationDuration = 0; |
| 412 |
| 413 applyTimingInputNumber(timing, isolate, "duration", -1); |
| 414 EXPECT_EQ(0, timing.iterationDuration); |
| 415 EXPECT_FALSE(timing.hasIterationDuration); |
| 416 timing.hasIterationDuration = false; |
| 417 timing.iterationDuration = 0; |
| 418 |
| 419 applyTimingInputString(timing, isolate, "duration", "1"); |
| 420 EXPECT_EQ(1, timing.iterationDuration); |
| 421 EXPECT_TRUE(timing.hasIterationDuration); |
| 422 timing.hasIterationDuration = false; |
| 423 timing.iterationDuration = 0; |
| 424 |
| 425 applyTimingInputString(timing, isolate, "duration", "Infinity"); |
| 426 EXPECT_TRUE(isinf(timing.iterationDuration) && (timing.iterationDuration > 0
)); |
| 427 EXPECT_TRUE(timing.hasIterationDuration); |
| 428 timing.hasIterationDuration = false; |
| 429 timing.iterationDuration = 0; |
| 430 |
| 431 applyTimingInputString(timing, isolate, "duration", "-Infinity"); |
| 432 EXPECT_EQ(0, timing.iterationDuration); |
| 433 EXPECT_FALSE(timing.hasIterationDuration); |
| 434 timing.hasIterationDuration = false; |
| 435 timing.iterationDuration = 0; |
| 436 |
| 437 applyTimingInputString(timing, isolate, "duration", "NaN"); |
| 438 EXPECT_EQ(0, timing.iterationDuration); |
| 439 EXPECT_FALSE(timing.hasIterationDuration); |
| 440 timing.hasIterationDuration = false; |
| 441 timing.iterationDuration = 0; |
| 442 |
| 443 applyTimingInputString(timing, isolate, "duration", "auto"); |
| 444 EXPECT_EQ(0, timing.iterationDuration); |
| 445 EXPECT_FALSE(timing.hasIterationDuration); |
| 446 timing.hasIterationDuration = false; |
| 447 timing.iterationDuration = 0; |
| 448 |
| 449 applyTimingInputString(timing, isolate, "duration", "rubbish"); |
| 450 EXPECT_EQ(0, timing.iterationDuration); |
| 451 EXPECT_FALSE(timing.hasIterationDuration); |
| 452 timing.hasIterationDuration = false; |
| 453 timing.iterationDuration = 0; |
| 454 } |
| 455 |
| 456 TEST_F(AnimationElementAnimationTest, TimingInputPlaybackRate) |
| 457 { |
| 458 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 459 v8::HandleScope scope(isolate); |
| 460 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 461 v8::Context::Scope contextScope(context); |
| 462 |
| 463 Timing timing; |
| 464 EXPECT_EQ(1, timing.playbackRate); |
| 465 |
| 466 applyTimingInputNumber(timing, isolate, "playbackRate", 2.1); |
| 467 EXPECT_EQ(2.1, timing.playbackRate); |
| 468 timing.playbackRate = 1; |
| 469 |
| 470 applyTimingInputNumber(timing, isolate, "playbackRate", -1); |
| 471 EXPECT_EQ(-1, timing.playbackRate); |
| 472 timing.playbackRate = 1; |
| 473 |
| 474 applyTimingInputString(timing, isolate, "playbackRate", "Infinity"); |
| 475 EXPECT_EQ(1, timing.playbackRate); |
| 476 timing.playbackRate = 1; |
| 477 |
| 478 applyTimingInputString(timing, isolate, "playbackRate", "-Infinity"); |
| 479 EXPECT_EQ(1, timing.playbackRate); |
| 480 timing.playbackRate = 1; |
| 481 |
| 482 applyTimingInputString(timing, isolate, "playbackRate", "NaN"); |
| 483 EXPECT_EQ(1, timing.playbackRate); |
| 484 timing.playbackRate = 1; |
| 485 |
| 486 applyTimingInputString(timing, isolate, "playbackRate", "rubbish"); |
| 487 EXPECT_EQ(1, timing.playbackRate); |
| 488 timing.playbackRate = 1; |
| 489 } |
| 490 |
| 491 TEST_F(AnimationElementAnimationTest, TimingInputDirection) |
| 492 { |
| 493 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 494 v8::HandleScope scope(isolate); |
| 495 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 496 v8::Context::Scope contextScope(context); |
| 497 |
| 498 Timing timing; |
| 499 Timing::PlaybackDirection defaultPlaybackDirection = Timing::PlaybackDirecti
onNormal; |
| 500 EXPECT_EQ(defaultPlaybackDirection, timing.direction); |
| 501 |
| 502 applyTimingInputString(timing, isolate, "direction", "normal"); |
| 503 EXPECT_EQ(Timing::PlaybackDirectionNormal, timing.direction); |
| 504 timing.direction = defaultPlaybackDirection; |
| 505 |
| 506 applyTimingInputString(timing, isolate, "direction", "reverse"); |
| 507 EXPECT_EQ(Timing::PlaybackDirectionReverse, timing.direction); |
| 508 timing.direction = defaultPlaybackDirection; |
| 509 |
| 510 applyTimingInputString(timing, isolate, "direction", "alternate"); |
| 511 EXPECT_EQ(Timing::PlaybackDirectionAlternate, timing.direction); |
| 512 timing.direction = defaultPlaybackDirection; |
| 513 |
| 514 applyTimingInputString(timing, isolate, "direction", "alternate-reverse"); |
| 515 EXPECT_EQ(Timing::PlaybackDirectionAlternateReverse, timing.direction); |
| 516 timing.direction = defaultPlaybackDirection; |
| 517 |
| 518 applyTimingInputString(timing, isolate, "direction", "rubbish"); |
| 519 EXPECT_EQ(defaultPlaybackDirection, timing.direction); |
| 520 timing.direction = defaultPlaybackDirection; |
| 521 |
| 522 applyTimingInputNumber(timing, isolate, "direction", 2); |
| 523 EXPECT_EQ(defaultPlaybackDirection, timing.direction); |
| 524 timing.direction = defaultPlaybackDirection; |
| 525 } |
| 526 |
| 527 TEST_F(AnimationElementAnimationTest, TimingInputEmpty) |
| 528 { |
| 529 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 530 v8::HandleScope scope(isolate); |
| 531 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 532 v8::Context::Scope contextScope(context); |
| 533 |
| 534 Timing updatedTiming; |
| 535 Timing controlTiming; |
| 536 |
| 537 v8::Handle<v8::Object> timingInput = v8::Object::New(isolate); |
| 538 Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(ti
mingInput), isolate); |
| 539 populateTiming(updatedTiming, timingInputDictionary); |
| 540 |
| 541 EXPECT_EQ(controlTiming.startDelay, updatedTiming.startDelay); |
| 542 EXPECT_EQ(controlTiming.fillMode, updatedTiming.fillMode); |
| 543 EXPECT_EQ(controlTiming.iterationStart, updatedTiming.iterationStart); |
| 544 EXPECT_EQ(controlTiming.iterationCount, updatedTiming.iterationCount); |
| 545 EXPECT_EQ(controlTiming.iterationDuration, updatedTiming.iterationDuration); |
| 546 EXPECT_EQ(controlTiming.hasIterationDuration, updatedTiming.hasIterationDura
tion); |
| 547 EXPECT_EQ(controlTiming.playbackRate, updatedTiming.playbackRate); |
| 548 EXPECT_EQ(controlTiming.direction, updatedTiming.direction); |
| 549 } |
| 550 |
211 } // namespace WebCore | 551 } // namespace WebCore |
OLD | NEW |