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" |
(...skipping 18 matching lines...) Expand all Loading... |
29 EXPECT_EQ(0, document->timeline().currentTime()); | 29 EXPECT_EQ(0, document->timeline().currentTime()); |
30 } | 30 } |
31 | 31 |
32 RefPtr<Document> document; | 32 RefPtr<Document> document; |
33 RefPtr<Element> element; | 33 RefPtr<Element> element; |
34 }; | 34 }; |
35 | 35 |
36 class AnimationAnimationV8Test : public AnimationAnimationTest { | 36 class AnimationAnimationV8Test : public AnimationAnimationTest { |
37 protected: | 37 protected: |
38 AnimationAnimationV8Test() | 38 AnimationAnimationV8Test() |
39 : isolate(v8::Isolate::GetCurrent()) | 39 : m_isolate(v8::Isolate::GetCurrent()) |
40 , scope(isolate) | 40 , m_scope(V8BindingTestScope::create(m_isolate)) |
41 , context(v8::Context::New(isolate)) | |
42 , contextScope(context) | |
43 { | 41 { |
44 } | 42 } |
45 | 43 |
46 v8::Isolate* isolate; | |
47 v8::HandleScope scope; | |
48 v8::Local<v8::Context> context; | |
49 v8::Context::Scope contextScope; | |
50 | |
51 PassRefPtr<Animation> createAnimation(Element* element, Vector<Dictionary> k
eyframeDictionaryVector, Dictionary timingInput) | 44 PassRefPtr<Animation> createAnimation(Element* element, Vector<Dictionary> k
eyframeDictionaryVector, Dictionary timingInput) |
52 { | 45 { |
53 return Animation::createUnsafe(element, keyframeDictionaryVector, timing
Input); | 46 return Animation::createUnsafe(element, keyframeDictionaryVector, timing
Input); |
54 } | 47 } |
55 | 48 |
56 PassRefPtr<Animation> createAnimation(Element* element, Vector<Dictionary> k
eyframeDictionaryVector, double timingInput) | 49 PassRefPtr<Animation> createAnimation(Element* element, Vector<Dictionary> k
eyframeDictionaryVector, double timingInput) |
57 { | 50 { |
58 return Animation::createUnsafe(element, keyframeDictionaryVector, timing
Input); | 51 return Animation::createUnsafe(element, keyframeDictionaryVector, timing
Input); |
59 } | 52 } |
60 | 53 |
61 PassRefPtr<Animation> createAnimation(Element* element, Vector<Dictionary> k
eyframeDictionaryVector) | 54 PassRefPtr<Animation> createAnimation(Element* element, Vector<Dictionary> k
eyframeDictionaryVector) |
62 { | 55 { |
63 return Animation::createUnsafe(element, keyframeDictionaryVector); | 56 return Animation::createUnsafe(element, keyframeDictionaryVector); |
64 } | 57 } |
| 58 |
| 59 v8::Isolate* m_isolate; |
| 60 |
| 61 private: |
| 62 OwnPtr<V8BindingTestScope> m_scope; |
65 }; | 63 }; |
66 | 64 |
67 TEST_F(AnimationAnimationV8Test, CanCreateAnAnimation) | 65 TEST_F(AnimationAnimationV8Test, CanCreateAnAnimation) |
68 { | 66 { |
69 Vector<Dictionary> jsKeyframes; | 67 Vector<Dictionary> jsKeyframes; |
70 v8::Handle<v8::Object> keyframe1 = v8::Object::New(isolate); | 68 v8::Handle<v8::Object> keyframe1 = v8::Object::New(m_isolate); |
71 v8::Handle<v8::Object> keyframe2 = v8::Object::New(isolate); | 69 v8::Handle<v8::Object> keyframe2 = v8::Object::New(m_isolate); |
72 | 70 |
73 setV8ObjectPropertyAsString(keyframe1, "width", "100px"); | 71 setV8ObjectPropertyAsString(keyframe1, "width", "100px"); |
74 setV8ObjectPropertyAsString(keyframe1, "offset", "0"); | 72 setV8ObjectPropertyAsString(keyframe1, "offset", "0"); |
75 setV8ObjectPropertyAsString(keyframe1, "easing", "ease-in-out"); | 73 setV8ObjectPropertyAsString(keyframe1, "easing", "ease-in-out"); |
76 setV8ObjectPropertyAsString(keyframe2, "width", "0px"); | 74 setV8ObjectPropertyAsString(keyframe2, "width", "0px"); |
77 setV8ObjectPropertyAsString(keyframe2, "offset", "1"); | 75 setV8ObjectPropertyAsString(keyframe2, "offset", "1"); |
78 setV8ObjectPropertyAsString(keyframe2, "easing", "cubic-bezier(1, 1, 0.3, 0.
3)"); | 76 setV8ObjectPropertyAsString(keyframe2, "easing", "cubic-bezier(1, 1, 0.3, 0.
3)"); |
79 | 77 |
80 jsKeyframes.append(Dictionary(keyframe1, isolate)); | 78 jsKeyframes.append(Dictionary(keyframe1, m_isolate)); |
81 jsKeyframes.append(Dictionary(keyframe2, isolate)); | 79 jsKeyframes.append(Dictionary(keyframe2, m_isolate)); |
82 | 80 |
83 String value1; | 81 String value1; |
84 ASSERT_TRUE(jsKeyframes[0].get("width", value1)); | 82 ASSERT_TRUE(jsKeyframes[0].get("width", value1)); |
85 ASSERT_EQ("100px", value1); | 83 ASSERT_EQ("100px", value1); |
86 | 84 |
87 String value2; | 85 String value2; |
88 ASSERT_TRUE(jsKeyframes[1].get("width", value2)); | 86 ASSERT_TRUE(jsKeyframes[1].get("width", value2)); |
89 ASSERT_EQ("0px", value2); | 87 ASSERT_EQ("0px", value2); |
90 | 88 |
91 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, 0)
; | 89 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, 0)
; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 { | 133 { |
136 Vector<Dictionary, 0> jsKeyframes; | 134 Vector<Dictionary, 0> jsKeyframes; |
137 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, -2
); | 135 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, -2
); |
138 EXPECT_EQ(0, animation->specifiedTiming().iterationDuration); | 136 EXPECT_EQ(0, animation->specifiedTiming().iterationDuration); |
139 } | 137 } |
140 | 138 |
141 TEST_F(AnimationAnimationV8Test, SpecifiedGetters) | 139 TEST_F(AnimationAnimationV8Test, SpecifiedGetters) |
142 { | 140 { |
143 Vector<Dictionary, 0> jsKeyframes; | 141 Vector<Dictionary, 0> jsKeyframes; |
144 | 142 |
145 v8::Handle<v8::Object> timingInput = v8::Object::New(isolate); | 143 v8::Handle<v8::Object> timingInput = v8::Object::New(m_isolate); |
146 setV8ObjectPropertyAsNumber(timingInput, "delay", 2); | 144 setV8ObjectPropertyAsNumber(timingInput, "delay", 2); |
147 setV8ObjectPropertyAsNumber(timingInput, "endDelay", 0.5); | 145 setV8ObjectPropertyAsNumber(timingInput, "endDelay", 0.5); |
148 setV8ObjectPropertyAsString(timingInput, "fill", "backwards"); | 146 setV8ObjectPropertyAsString(timingInput, "fill", "backwards"); |
149 setV8ObjectPropertyAsNumber(timingInput, "iterationStart", 2); | 147 setV8ObjectPropertyAsNumber(timingInput, "iterationStart", 2); |
150 setV8ObjectPropertyAsNumber(timingInput, "iterations", 10); | 148 setV8ObjectPropertyAsNumber(timingInput, "iterations", 10); |
151 setV8ObjectPropertyAsNumber(timingInput, "playbackRate", 2); | 149 setV8ObjectPropertyAsNumber(timingInput, "playbackRate", 2); |
152 setV8ObjectPropertyAsString(timingInput, "direction", "reverse"); | 150 setV8ObjectPropertyAsString(timingInput, "direction", "reverse"); |
153 setV8ObjectPropertyAsString(timingInput, "easing", "step-start"); | 151 setV8ObjectPropertyAsString(timingInput, "easing", "step-start"); |
154 Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(ti
mingInput), isolate); | 152 Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(ti
mingInput), m_isolate); |
155 | 153 |
156 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, ti
mingInputDictionary); | 154 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, ti
mingInputDictionary); |
157 | 155 |
158 RefPtr<TimedItemTiming> specified = animation->specified(); | 156 RefPtr<TimedItemTiming> specified = animation->specified(); |
159 EXPECT_EQ(2, specified->delay()); | 157 EXPECT_EQ(2, specified->delay()); |
160 EXPECT_EQ(0.5, specified->endDelay()); | 158 EXPECT_EQ(0.5, specified->endDelay()); |
161 EXPECT_EQ("backwards", specified->fill()); | 159 EXPECT_EQ("backwards", specified->fill()); |
162 EXPECT_EQ(2, specified->iterationStart()); | 160 EXPECT_EQ(2, specified->iterationStart()); |
163 EXPECT_EQ(10, specified->iterations()); | 161 EXPECT_EQ(10, specified->iterations()); |
164 EXPECT_EQ(2, specified->playbackRate()); | 162 EXPECT_EQ(2, specified->playbackRate()); |
165 EXPECT_EQ("reverse", specified->direction()); | 163 EXPECT_EQ("reverse", specified->direction()); |
166 EXPECT_EQ("step-start", specified->easing()); | 164 EXPECT_EQ("step-start", specified->easing()); |
167 } | 165 } |
168 | 166 |
169 TEST_F(AnimationAnimationV8Test, SpecifiedDurationGetter) | 167 TEST_F(AnimationAnimationV8Test, SpecifiedDurationGetter) |
170 { | 168 { |
171 Vector<Dictionary, 0> jsKeyframes; | 169 Vector<Dictionary, 0> jsKeyframes; |
172 | 170 |
173 v8::Handle<v8::Object> timingInputWithDuration = v8::Object::New(isolate); | 171 v8::Handle<v8::Object> timingInputWithDuration = v8::Object::New(m_isolate); |
174 setV8ObjectPropertyAsNumber(timingInputWithDuration, "duration", 2.5); | 172 setV8ObjectPropertyAsNumber(timingInputWithDuration, "duration", 2.5); |
175 Dictionary timingInputDictionaryWithDuration = Dictionary(v8::Handle<v8::Val
ue>::Cast(timingInputWithDuration), isolate); | 173 Dictionary timingInputDictionaryWithDuration = Dictionary(v8::Handle<v8::Val
ue>::Cast(timingInputWithDuration), m_isolate); |
176 | 174 |
177 RefPtr<Animation> animationWithDuration = createAnimation(element.get(), jsK
eyframes, timingInputDictionaryWithDuration); | 175 RefPtr<Animation> animationWithDuration = createAnimation(element.get(), jsK
eyframes, timingInputDictionaryWithDuration); |
178 | 176 |
179 RefPtr<TimedItemTiming> specifiedWithDuration = animationWithDuration->speci
fied(); | 177 RefPtr<TimedItemTiming> specifiedWithDuration = animationWithDuration->speci
fied(); |
180 bool isNumber = false; | 178 bool isNumber = false; |
181 double numberDuration = std::numeric_limits<double>::quiet_NaN(); | 179 double numberDuration = std::numeric_limits<double>::quiet_NaN(); |
182 bool isString = false; | 180 bool isString = false; |
183 String stringDuration = ""; | 181 String stringDuration = ""; |
184 specifiedWithDuration->getDuration("duration", isNumber, numberDuration, isS
tring, stringDuration); | 182 specifiedWithDuration->getDuration("duration", isNumber, numberDuration, isS
tring, stringDuration); |
185 EXPECT_TRUE(isNumber); | 183 EXPECT_TRUE(isNumber); |
186 EXPECT_EQ(2.5, numberDuration); | 184 EXPECT_EQ(2.5, numberDuration); |
187 EXPECT_FALSE(isString); | 185 EXPECT_FALSE(isString); |
188 EXPECT_EQ("", stringDuration); | 186 EXPECT_EQ("", stringDuration); |
189 | 187 |
190 | 188 |
191 v8::Handle<v8::Object> timingInputNoDuration = v8::Object::New(isolate); | 189 v8::Handle<v8::Object> timingInputNoDuration = v8::Object::New(m_isolate); |
192 Dictionary timingInputDictionaryNoDuration = Dictionary(v8::Handle<v8::Value
>::Cast(timingInputNoDuration), isolate); | 190 Dictionary timingInputDictionaryNoDuration = Dictionary(v8::Handle<v8::Value
>::Cast(timingInputNoDuration), m_isolate); |
193 | 191 |
194 RefPtr<Animation> animationNoDuration = createAnimation(element.get(), jsKey
frames, timingInputDictionaryNoDuration); | 192 RefPtr<Animation> animationNoDuration = createAnimation(element.get(), jsKey
frames, timingInputDictionaryNoDuration); |
195 | 193 |
196 RefPtr<TimedItemTiming> specifiedNoDuration = animationNoDuration->specified
(); | 194 RefPtr<TimedItemTiming> specifiedNoDuration = animationNoDuration->specified
(); |
197 isNumber = false; | 195 isNumber = false; |
198 numberDuration = std::numeric_limits<double>::quiet_NaN(); | 196 numberDuration = std::numeric_limits<double>::quiet_NaN(); |
199 isString = false; | 197 isString = false; |
200 stringDuration = ""; | 198 stringDuration = ""; |
201 specifiedNoDuration->getDuration("duration", isNumber, numberDuration, isStr
ing, stringDuration); | 199 specifiedNoDuration->getDuration("duration", isNumber, numberDuration, isStr
ing, stringDuration); |
202 EXPECT_FALSE(isNumber); | 200 EXPECT_FALSE(isNumber); |
203 EXPECT_TRUE(std::isnan(numberDuration)); | 201 EXPECT_TRUE(std::isnan(numberDuration)); |
204 EXPECT_TRUE(isString); | 202 EXPECT_TRUE(isString); |
205 EXPECT_EQ("auto", stringDuration); | 203 EXPECT_EQ("auto", stringDuration); |
206 } | 204 } |
207 | 205 |
208 TEST_F(AnimationAnimationV8Test, SpecifiedSetters) | 206 TEST_F(AnimationAnimationV8Test, SpecifiedSetters) |
209 { | 207 { |
210 Vector<Dictionary, 0> jsKeyframes; | 208 Vector<Dictionary, 0> jsKeyframes; |
211 v8::Handle<v8::Object> timingInput = v8::Object::New(isolate); | 209 v8::Handle<v8::Object> timingInput = v8::Object::New(m_isolate); |
212 Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(ti
mingInput), isolate); | 210 Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(ti
mingInput), m_isolate); |
213 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, ti
mingInputDictionary); | 211 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, ti
mingInputDictionary); |
214 | 212 |
215 RefPtr<TimedItemTiming> specified = animation->specified(); | 213 RefPtr<TimedItemTiming> specified = animation->specified(); |
216 | 214 |
217 EXPECT_EQ(0, specified->delay()); | 215 EXPECT_EQ(0, specified->delay()); |
218 specified->setDelay(2); | 216 specified->setDelay(2); |
219 EXPECT_EQ(2, specified->delay()); | 217 EXPECT_EQ(2, specified->delay()); |
220 | 218 |
221 EXPECT_EQ(0, specified->endDelay()); | 219 EXPECT_EQ(0, specified->endDelay()); |
222 specified->setEndDelay(0.5); | 220 specified->setEndDelay(0.5); |
(...skipping 20 matching lines...) Expand all Loading... |
243 EXPECT_EQ("reverse", specified->direction()); | 241 EXPECT_EQ("reverse", specified->direction()); |
244 | 242 |
245 EXPECT_EQ("linear", specified->easing()); | 243 EXPECT_EQ("linear", specified->easing()); |
246 specified->setEasing("step-start"); | 244 specified->setEasing("step-start"); |
247 EXPECT_EQ("step-start", specified->easing()); | 245 EXPECT_EQ("step-start", specified->easing()); |
248 } | 246 } |
249 | 247 |
250 TEST_F(AnimationAnimationV8Test, SetSpecifiedDuration) | 248 TEST_F(AnimationAnimationV8Test, SetSpecifiedDuration) |
251 { | 249 { |
252 Vector<Dictionary, 0> jsKeyframes; | 250 Vector<Dictionary, 0> jsKeyframes; |
253 v8::Handle<v8::Object> timingInput = v8::Object::New(isolate); | 251 v8::Handle<v8::Object> timingInput = v8::Object::New(m_isolate); |
254 Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(ti
mingInput), isolate); | 252 Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(ti
mingInput), m_isolate); |
255 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, ti
mingInputDictionary); | 253 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, ti
mingInputDictionary); |
256 | 254 |
257 RefPtr<TimedItemTiming> specified = animation->specified(); | 255 RefPtr<TimedItemTiming> specified = animation->specified(); |
258 | 256 |
259 bool isNumber = false; | 257 bool isNumber = false; |
260 double numberDuration = std::numeric_limits<double>::quiet_NaN(); | 258 double numberDuration = std::numeric_limits<double>::quiet_NaN(); |
261 bool isString = false; | 259 bool isString = false; |
262 String stringDuration = ""; | 260 String stringDuration = ""; |
263 specified->getDuration("duration", isNumber, numberDuration, isString, strin
gDuration); | 261 specified->getDuration("duration", isNumber, numberDuration, isString, strin
gDuration); |
264 EXPECT_FALSE(isNumber); | 262 EXPECT_FALSE(isNumber); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 player->setCurrentTime(150); | 367 player->setCurrentTime(150); |
370 EXPECT_EQ(inf, animation->timeToForwardsEffectChange()); | 368 EXPECT_EQ(inf, animation->timeToForwardsEffectChange()); |
371 EXPECT_EQ(0, animation->timeToReverseEffectChange()); | 369 EXPECT_EQ(0, animation->timeToReverseEffectChange()); |
372 | 370 |
373 player->setCurrentTime(200); | 371 player->setCurrentTime(200); |
374 EXPECT_EQ(inf, animation->timeToForwardsEffectChange()); | 372 EXPECT_EQ(inf, animation->timeToForwardsEffectChange()); |
375 EXPECT_EQ(50, animation->timeToReverseEffectChange()); | 373 EXPECT_EQ(50, animation->timeToReverseEffectChange()); |
376 } | 374 } |
377 | 375 |
378 } // namespace WebCore | 376 } // namespace WebCore |
OLD | NEW |