Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: Source/core/animation/AnimationTest.cpp

Issue 190763007: [WIP] Web Animations API: Constructing an Animation from partial keyframes throws a JS exception (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 13 matching lines...) Expand all
24 : document(Document::create()) 24 : document(Document::create())
25 , element(document->createElement("foo", ASSERT_NO_EXCEPTION)) 25 , element(document->createElement("foo", ASSERT_NO_EXCEPTION))
26 { 26 {
27 document->animationClock().resetTimeForTesting(); 27 document->animationClock().resetTimeForTesting();
28 document->timeline().setZeroTime(0); 28 document->timeline().setZeroTime(0);
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 TrackExceptionState exceptionState;
34 }; 35 };
35 36
36 class AnimationAnimationV8Test : public AnimationAnimationTest { 37 class AnimationAnimationV8Test : public AnimationAnimationTest {
37 protected: 38 protected:
38 AnimationAnimationV8Test() 39 AnimationAnimationV8Test()
39 : m_isolate(v8::Isolate::GetCurrent()) 40 : m_isolate(v8::Isolate::GetCurrent())
40 , m_scope(V8BindingTestScope::create(m_isolate)) 41 , m_scope(V8BindingTestScope::create(m_isolate))
41 { 42 {
42 } 43 }
43 44
44 template<typename T> 45 template<typename T>
45 static PassRefPtr<Animation> createAnimation(Element* element, Vector<Dictio nary> keyframeDictionaryVector, T timingInput) 46 static PassRefPtr<Animation> createAnimation(Element* element, Vector<Dictio nary> keyframeDictionaryVector, T timingInput, ExceptionState& exceptionState)
46 { 47 {
47 return Animation::create(element, EffectInput::convert(element, keyframe DictionaryVector, true), timingInput); 48 return Animation::create(element, EffectInput::convert(element, keyframe DictionaryVector, exceptionState, true), timingInput);
48 } 49 }
49 static PassRefPtr<Animation> createAnimation(Element* element, Vector<Dictio nary> keyframeDictionaryVector) 50 static PassRefPtr<Animation> createAnimation(Element* element, Vector<Dictio nary> keyframeDictionaryVector, ExceptionState& exceptionState)
50 { 51 {
51 return Animation::create(element, EffectInput::convert(element, keyframe DictionaryVector, true)); 52 return Animation::create(element, EffectInput::convert(element, keyframe DictionaryVector, exceptionState, true));
52 } 53 }
53 54
54 v8::Isolate* m_isolate; 55 v8::Isolate* m_isolate;
55 56
56 private: 57 private:
57 OwnPtr<V8BindingTestScope> m_scope; 58 OwnPtr<V8BindingTestScope> m_scope;
58 }; 59 };
59 60
60 TEST_F(AnimationAnimationV8Test, CanCreateAnAnimation) 61 TEST_F(AnimationAnimationV8Test, CanCreateAnAnimation)
61 { 62 {
(...skipping 12 matching lines...) Expand all
74 jsKeyframes.append(Dictionary(keyframe2, m_isolate)); 75 jsKeyframes.append(Dictionary(keyframe2, m_isolate));
75 76
76 String value1; 77 String value1;
77 ASSERT_TRUE(jsKeyframes[0].get("width", value1)); 78 ASSERT_TRUE(jsKeyframes[0].get("width", value1));
78 ASSERT_EQ("100px", value1); 79 ASSERT_EQ("100px", value1);
79 80
80 String value2; 81 String value2;
81 ASSERT_TRUE(jsKeyframes[1].get("width", value2)); 82 ASSERT_TRUE(jsKeyframes[1].get("width", value2));
82 ASSERT_EQ("0px", value2); 83 ASSERT_EQ("0px", value2);
83 84
84 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, 0) ; 85 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, 0, exceptionState);
86
87 EXPECT_FALSE(exceptionState.hadException());
85 88
86 Element* target = animation->target(); 89 Element* target = animation->target();
87 EXPECT_EQ(*element.get(), *target); 90 EXPECT_EQ(*element.get(), *target);
88 91
89 const KeyframeEffectModel::KeyframeVector keyframes = 92 const KeyframeEffectModel::KeyframeVector keyframes =
90 toKeyframeEffectModel(animation->effect())->getFrames(); 93 toKeyframeEffectModel(animation->effect())->getFrames();
91 94
92 EXPECT_EQ(0, keyframes[0]->offset()); 95 EXPECT_EQ(0, keyframes[0]->offset());
93 EXPECT_EQ(1, keyframes[1]->offset()); 96 EXPECT_EQ(1, keyframes[1]->offset());
94 97
(...skipping 10 matching lines...) Expand all
105 108
106 EXPECT_EQ(*(CubicBezierTimingFunction::preset(CubicBezierTimingFunction::Eas eInOut)), *keyframes[0]->easing()); 109 EXPECT_EQ(*(CubicBezierTimingFunction::preset(CubicBezierTimingFunction::Eas eInOut)), *keyframes[0]->easing());
107 EXPECT_EQ(*(CubicBezierTimingFunction::create(1, 1, 0.3, 0.3).get()), *keyfr ames[1]->easing()); 110 EXPECT_EQ(*(CubicBezierTimingFunction::create(1, 1, 0.3, 0.3).get()), *keyfr ames[1]->easing());
108 } 111 }
109 112
110 TEST_F(AnimationAnimationV8Test, CanSetDuration) 113 TEST_F(AnimationAnimationV8Test, CanSetDuration)
111 { 114 {
112 Vector<Dictionary, 0> jsKeyframes; 115 Vector<Dictionary, 0> jsKeyframes;
113 double duration = 2; 116 double duration = 2;
114 117
115 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, du ration); 118 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, du ration, exceptionState);
116 119
117 EXPECT_EQ(duration, animation->specifiedTiming().iterationDuration); 120 EXPECT_EQ(duration, animation->specifiedTiming().iterationDuration);
118 } 121 }
119 122
120 TEST_F(AnimationAnimationV8Test, CanOmitSpecifiedDuration) 123 TEST_F(AnimationAnimationV8Test, CanOmitSpecifiedDuration)
121 { 124 {
122 Vector<Dictionary, 0> jsKeyframes; 125 Vector<Dictionary, 0> jsKeyframes;
123 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes); 126 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, ex ceptionState);
124 EXPECT_TRUE(std::isnan(animation->specifiedTiming().iterationDuration)); 127 EXPECT_TRUE(std::isnan(animation->specifiedTiming().iterationDuration));
125 } 128 }
126 129
127 TEST_F(AnimationAnimationV8Test, NegativeDurationIsAuto) 130 TEST_F(AnimationAnimationV8Test, NegativeDurationIsAuto)
128 { 131 {
129 Vector<Dictionary, 0> jsKeyframes; 132 Vector<Dictionary, 0> jsKeyframes;
130 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, -2 ); 133 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, -2 , exceptionState);
131 EXPECT_TRUE(std::isnan(animation->specifiedTiming().iterationDuration)); 134 EXPECT_TRUE(std::isnan(animation->specifiedTiming().iterationDuration));
132 } 135 }
133 136
137 TEST_F(AnimationAnimationV8Test, PartialKeyframeRaisesException)
138 {
139 Vector<Dictionary> jsKeyframes;
140 v8::Handle<v8::Object> keyframe1 = v8::Object::New(m_isolate);
141 v8::Handle<v8::Object> keyframe2 = v8::Object::New(m_isolate);
142
143 setV8ObjectPropertyAsString(keyframe1, "width", "100px");
144 setV8ObjectPropertyAsString(keyframe1, "offset", "0");
145
146 // Height property appears only in keyframe2
147 setV8ObjectPropertyAsString(keyframe2, "height", "100px");
148 setV8ObjectPropertyAsString(keyframe2, "width", "0px");
149 setV8ObjectPropertyAsString(keyframe2, "offset", "1");
150
151 jsKeyframes.append(Dictionary(keyframe1, m_isolate));
152 jsKeyframes.append(Dictionary(keyframe2, m_isolate));
153
154 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, 0, exceptionState);
155
156 EXPECT_TRUE(exceptionState.hadException());
157 EXPECT_EQ(NotSupportedError, exceptionState.code());
158 }
159
134 TEST_F(AnimationAnimationV8Test, SpecifiedGetters) 160 TEST_F(AnimationAnimationV8Test, SpecifiedGetters)
135 { 161 {
136 Vector<Dictionary, 0> jsKeyframes; 162 Vector<Dictionary, 0> jsKeyframes;
137 163
138 v8::Handle<v8::Object> timingInput = v8::Object::New(m_isolate); 164 v8::Handle<v8::Object> timingInput = v8::Object::New(m_isolate);
139 setV8ObjectPropertyAsNumber(timingInput, "delay", 2); 165 setV8ObjectPropertyAsNumber(timingInput, "delay", 2);
140 setV8ObjectPropertyAsNumber(timingInput, "endDelay", 0.5); 166 setV8ObjectPropertyAsNumber(timingInput, "endDelay", 0.5);
141 setV8ObjectPropertyAsString(timingInput, "fill", "backwards"); 167 setV8ObjectPropertyAsString(timingInput, "fill", "backwards");
142 setV8ObjectPropertyAsNumber(timingInput, "iterationStart", 2); 168 setV8ObjectPropertyAsNumber(timingInput, "iterationStart", 2);
143 setV8ObjectPropertyAsNumber(timingInput, "iterations", 10); 169 setV8ObjectPropertyAsNumber(timingInput, "iterations", 10);
144 setV8ObjectPropertyAsNumber(timingInput, "playbackRate", 2); 170 setV8ObjectPropertyAsNumber(timingInput, "playbackRate", 2);
145 setV8ObjectPropertyAsString(timingInput, "direction", "reverse"); 171 setV8ObjectPropertyAsString(timingInput, "direction", "reverse");
146 setV8ObjectPropertyAsString(timingInput, "easing", "step-start"); 172 setV8ObjectPropertyAsString(timingInput, "easing", "step-start");
147 Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(ti mingInput), m_isolate); 173 Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(ti mingInput), m_isolate);
148 174
149 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, ti mingInputDictionary); 175 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, ti mingInputDictionary, exceptionState);
150 176
151 RefPtr<TimedItemTiming> specified = animation->specified(); 177 RefPtr<TimedItemTiming> specified = animation->specified();
152 EXPECT_EQ(2, specified->delay()); 178 EXPECT_EQ(2, specified->delay());
153 EXPECT_EQ(0.5, specified->endDelay()); 179 EXPECT_EQ(0.5, specified->endDelay());
154 EXPECT_EQ("backwards", specified->fill()); 180 EXPECT_EQ("backwards", specified->fill());
155 EXPECT_EQ(2, specified->iterationStart()); 181 EXPECT_EQ(2, specified->iterationStart());
156 EXPECT_EQ(10, specified->iterations()); 182 EXPECT_EQ(10, specified->iterations());
157 EXPECT_EQ(2, specified->playbackRate()); 183 EXPECT_EQ(2, specified->playbackRate());
158 EXPECT_EQ("reverse", specified->direction()); 184 EXPECT_EQ("reverse", specified->direction());
159 EXPECT_EQ("step-start", specified->easing()); 185 EXPECT_EQ("step-start", specified->easing());
160 } 186 }
161 187
162 TEST_F(AnimationAnimationV8Test, SpecifiedDurationGetter) 188 TEST_F(AnimationAnimationV8Test, SpecifiedDurationGetter)
163 { 189 {
164 Vector<Dictionary, 0> jsKeyframes; 190 Vector<Dictionary, 0> jsKeyframes;
165 191
166 v8::Handle<v8::Object> timingInputWithDuration = v8::Object::New(m_isolate); 192 v8::Handle<v8::Object> timingInputWithDuration = v8::Object::New(m_isolate);
167 setV8ObjectPropertyAsNumber(timingInputWithDuration, "duration", 2.5); 193 setV8ObjectPropertyAsNumber(timingInputWithDuration, "duration", 2.5);
168 Dictionary timingInputDictionaryWithDuration = Dictionary(v8::Handle<v8::Val ue>::Cast(timingInputWithDuration), m_isolate); 194 Dictionary timingInputDictionaryWithDuration = Dictionary(v8::Handle<v8::Val ue>::Cast(timingInputWithDuration), m_isolate);
169 195
170 RefPtr<Animation> animationWithDuration = createAnimation(element.get(), jsK eyframes, timingInputDictionaryWithDuration); 196 RefPtr<Animation> animationWithDuration = createAnimation(element.get(), jsK eyframes, timingInputDictionaryWithDuration, exceptionState);
171 197
172 RefPtr<TimedItemTiming> specifiedWithDuration = animationWithDuration->speci fied(); 198 RefPtr<TimedItemTiming> specifiedWithDuration = animationWithDuration->speci fied();
173 bool isNumber = false; 199 bool isNumber = false;
174 double numberDuration = std::numeric_limits<double>::quiet_NaN(); 200 double numberDuration = std::numeric_limits<double>::quiet_NaN();
175 bool isString = false; 201 bool isString = false;
176 String stringDuration = ""; 202 String stringDuration = "";
177 specifiedWithDuration->getDuration("duration", isNumber, numberDuration, isS tring, stringDuration); 203 specifiedWithDuration->getDuration("duration", isNumber, numberDuration, isS tring, stringDuration);
178 EXPECT_TRUE(isNumber); 204 EXPECT_TRUE(isNumber);
179 EXPECT_EQ(2.5, numberDuration); 205 EXPECT_EQ(2.5, numberDuration);
180 EXPECT_FALSE(isString); 206 EXPECT_FALSE(isString);
181 EXPECT_EQ("", stringDuration); 207 EXPECT_EQ("", stringDuration);
182 208
183 209
184 v8::Handle<v8::Object> timingInputNoDuration = v8::Object::New(m_isolate); 210 v8::Handle<v8::Object> timingInputNoDuration = v8::Object::New(m_isolate);
185 Dictionary timingInputDictionaryNoDuration = Dictionary(v8::Handle<v8::Value >::Cast(timingInputNoDuration), m_isolate); 211 Dictionary timingInputDictionaryNoDuration = Dictionary(v8::Handle<v8::Value >::Cast(timingInputNoDuration), m_isolate);
186 212
187 RefPtr<Animation> animationNoDuration = createAnimation(element.get(), jsKey frames, timingInputDictionaryNoDuration); 213 RefPtr<Animation> animationNoDuration = createAnimation(element.get(), jsKey frames, timingInputDictionaryNoDuration, exceptionState);
188 214
189 RefPtr<TimedItemTiming> specifiedNoDuration = animationNoDuration->specified (); 215 RefPtr<TimedItemTiming> specifiedNoDuration = animationNoDuration->specified ();
190 isNumber = false; 216 isNumber = false;
191 numberDuration = std::numeric_limits<double>::quiet_NaN(); 217 numberDuration = std::numeric_limits<double>::quiet_NaN();
192 isString = false; 218 isString = false;
193 stringDuration = ""; 219 stringDuration = "";
194 specifiedNoDuration->getDuration("duration", isNumber, numberDuration, isStr ing, stringDuration); 220 specifiedNoDuration->getDuration("duration", isNumber, numberDuration, isStr ing, stringDuration);
195 EXPECT_FALSE(isNumber); 221 EXPECT_FALSE(isNumber);
196 EXPECT_TRUE(std::isnan(numberDuration)); 222 EXPECT_TRUE(std::isnan(numberDuration));
197 EXPECT_TRUE(isString); 223 EXPECT_TRUE(isString);
198 EXPECT_EQ("auto", stringDuration); 224 EXPECT_EQ("auto", stringDuration);
199 } 225 }
200 226
201 TEST_F(AnimationAnimationV8Test, SpecifiedSetters) 227 TEST_F(AnimationAnimationV8Test, SpecifiedSetters)
202 { 228 {
203 Vector<Dictionary, 0> jsKeyframes; 229 Vector<Dictionary, 0> jsKeyframes;
204 v8::Handle<v8::Object> timingInput = v8::Object::New(m_isolate); 230 v8::Handle<v8::Object> timingInput = v8::Object::New(m_isolate);
205 Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(ti mingInput), m_isolate); 231 Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(ti mingInput), m_isolate);
206 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, ti mingInputDictionary); 232 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, ti mingInputDictionary, exceptionState);
207 233
208 RefPtr<TimedItemTiming> specified = animation->specified(); 234 RefPtr<TimedItemTiming> specified = animation->specified();
209 235
210 EXPECT_EQ(0, specified->delay()); 236 EXPECT_EQ(0, specified->delay());
211 specified->setDelay(2); 237 specified->setDelay(2);
212 EXPECT_EQ(2, specified->delay()); 238 EXPECT_EQ(2, specified->delay());
213 239
214 EXPECT_EQ(0, specified->endDelay()); 240 EXPECT_EQ(0, specified->endDelay());
215 specified->setEndDelay(0.5); 241 specified->setEndDelay(0.5);
216 EXPECT_EQ(0.5, specified->endDelay()); 242 EXPECT_EQ(0.5, specified->endDelay());
(...skipping 21 matching lines...) Expand all
238 EXPECT_EQ("linear", specified->easing()); 264 EXPECT_EQ("linear", specified->easing());
239 specified->setEasing("step-start"); 265 specified->setEasing("step-start");
240 EXPECT_EQ("step-start", specified->easing()); 266 EXPECT_EQ("step-start", specified->easing());
241 } 267 }
242 268
243 TEST_F(AnimationAnimationV8Test, SetSpecifiedDuration) 269 TEST_F(AnimationAnimationV8Test, SetSpecifiedDuration)
244 { 270 {
245 Vector<Dictionary, 0> jsKeyframes; 271 Vector<Dictionary, 0> jsKeyframes;
246 v8::Handle<v8::Object> timingInput = v8::Object::New(m_isolate); 272 v8::Handle<v8::Object> timingInput = v8::Object::New(m_isolate);
247 Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(ti mingInput), m_isolate); 273 Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(ti mingInput), m_isolate);
248 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, ti mingInputDictionary); 274 RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, ti mingInputDictionary, exceptionState);
249 275
250 RefPtr<TimedItemTiming> specified = animation->specified(); 276 RefPtr<TimedItemTiming> specified = animation->specified();
251 277
252 bool isNumber = false; 278 bool isNumber = false;
253 double numberDuration = std::numeric_limits<double>::quiet_NaN(); 279 double numberDuration = std::numeric_limits<double>::quiet_NaN();
254 bool isString = false; 280 bool isString = false;
255 String stringDuration = ""; 281 String stringDuration = "";
256 specified->getDuration("duration", isNumber, numberDuration, isString, strin gDuration); 282 specified->getDuration("duration", isNumber, numberDuration, isString, strin gDuration);
257 EXPECT_FALSE(isNumber); 283 EXPECT_FALSE(isNumber);
258 EXPECT_TRUE(std::isnan(numberDuration)); 284 EXPECT_TRUE(std::isnan(numberDuration));
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 player->setCurrentTime(150); 388 player->setCurrentTime(150);
363 EXPECT_EQ(inf, animation->timeToForwardsEffectChange()); 389 EXPECT_EQ(inf, animation->timeToForwardsEffectChange());
364 EXPECT_EQ(0, animation->timeToReverseEffectChange()); 390 EXPECT_EQ(0, animation->timeToReverseEffectChange());
365 391
366 player->setCurrentTime(200); 392 player->setCurrentTime(200);
367 EXPECT_EQ(inf, animation->timeToForwardsEffectChange()); 393 EXPECT_EQ(inf, animation->timeToForwardsEffectChange());
368 EXPECT_EQ(50, animation->timeToReverseEffectChange()); 394 EXPECT_EQ(50, animation->timeToReverseEffectChange());
369 } 395 }
370 396
371 } // namespace WebCore 397 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698