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: third_party/WebKit/Source/core/animation/KeyframeEffectTest.cpp

Issue 2272313003: binding: Makes ExceptionState STACK_ALLOCATED(). (Closed)
Patch Set: Synced. Created 4 years, 3 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 "core/animation/KeyframeEffect.h" 5 #include "core/animation/KeyframeEffect.h"
6 6
7 #include "bindings/core/v8/Dictionary.h" 7 #include "bindings/core/v8/Dictionary.h"
8 #include "bindings/core/v8/DictionarySequenceOrDictionary.h" 8 #include "bindings/core/v8/DictionarySequenceOrDictionary.h"
9 #include "bindings/core/v8/V8BindingForTesting.h" 9 #include "bindings/core/v8/V8BindingForTesting.h"
10 #include "bindings/core/v8/V8KeyframeEffectOptions.h" 10 #include "bindings/core/v8/V8KeyframeEffectOptions.h"
(...skipping 20 matching lines...) Expand all
31 31
32 document().animationClock().resetTimeForTesting(document().timeline().ze roTime()); 32 document().animationClock().resetTimeForTesting(document().timeline().ze roTime());
33 document().documentElement()->appendChild(element.get()); 33 document().documentElement()->appendChild(element.get());
34 EXPECT_EQ(0, document().timeline().currentTime()); 34 EXPECT_EQ(0, document().timeline().currentTime());
35 } 35 }
36 36
37 Document& document() const { return pageHolder->document(); } 37 Document& document() const { return pageHolder->document(); }
38 38
39 std::unique_ptr<DummyPageHolder> pageHolder; 39 std::unique_ptr<DummyPageHolder> pageHolder;
40 Persistent<Element> element; 40 Persistent<Element> element;
41 TrackExceptionState exceptionState;
42 }; 41 };
43 42
44 class AnimationKeyframeEffectV8Test : public KeyframeEffectTest { 43 class AnimationKeyframeEffectV8Test : public KeyframeEffectTest {
45 protected: 44 protected:
46 template<typename T> 45 template<typename T>
47 static KeyframeEffect* createAnimation(Element* element, Vector<Dictionary> keyframeDictionaryVector, T timingInput, ExceptionState& exceptionState) 46 static KeyframeEffect* createAnimation(Element* element, Vector<Dictionary> keyframeDictionaryVector, T timingInput)
48 { 47 {
48 NonThrowableExceptionState exceptionState;
49 return KeyframeEffect::create(nullptr, element, DictionarySequenceOrDict ionary::fromDictionarySequence(keyframeDictionaryVector), timingInput, exception State); 49 return KeyframeEffect::create(nullptr, element, DictionarySequenceOrDict ionary::fromDictionarySequence(keyframeDictionaryVector), timingInput, exception State);
50 } 50 }
51 static KeyframeEffect* createAnimation(Element* element, Vector<Dictionary> keyframeDictionaryVector, ExceptionState& exceptionState) 51 static KeyframeEffect* createAnimation(Element* element, Vector<Dictionary> keyframeDictionaryVector)
52 { 52 {
53 NonThrowableExceptionState exceptionState;
53 return KeyframeEffect::create(nullptr, element, DictionarySequenceOrDict ionary::fromDictionarySequence(keyframeDictionaryVector), exceptionState); 54 return KeyframeEffect::create(nullptr, element, DictionarySequenceOrDict ionary::fromDictionarySequence(keyframeDictionaryVector), exceptionState);
54 } 55 }
55 }; 56 };
56 57
57 TEST_F(AnimationKeyframeEffectV8Test, CanCreateAnAnimation) 58 TEST_F(AnimationKeyframeEffectV8Test, CanCreateAnAnimation)
58 { 59 {
59 V8TestingScope scope; 60 V8TestingScope scope;
60 Vector<Dictionary> jsKeyframes; 61 Vector<Dictionary> jsKeyframes;
61 v8::Local<v8::Object> keyframe1 = v8::Object::New(scope.isolate()); 62 v8::Local<v8::Object> keyframe1 = v8::Object::New(scope.isolate());
62 v8::Local<v8::Object> keyframe2 = v8::Object::New(scope.isolate()); 63 v8::Local<v8::Object> keyframe2 = v8::Object::New(scope.isolate());
63 64
64 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "width", "100px"); 65 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "width", "100px");
65 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "offset", "0"); 66 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "offset", "0");
66 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "easing", "ease-in-o ut"); 67 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "easing", "ease-in-o ut");
67 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "width", "0px"); 68 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "width", "0px");
68 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "offset", "1"); 69 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "offset", "1");
69 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "easing", "cubic-bez ier(1, 1, 0.3, 0.3)"); 70 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "easing", "cubic-bez ier(1, 1, 0.3, 0.3)");
70 71
71 jsKeyframes.append(Dictionary(keyframe1, scope.isolate(), exceptionState)); 72 jsKeyframes.append(Dictionary(scope.isolate(), keyframe1));
72 jsKeyframes.append(Dictionary(keyframe2, scope.isolate(), exceptionState)); 73 jsKeyframes.append(Dictionary(scope.isolate(), keyframe2));
73 74
74 String value1; 75 String value1;
75 ASSERT_TRUE(DictionaryHelper::get(jsKeyframes[0], "width", value1)); 76 ASSERT_TRUE(DictionaryHelper::get(jsKeyframes[0], "width", value1));
76 ASSERT_EQ("100px", value1); 77 ASSERT_EQ("100px", value1);
77 78
78 String value2; 79 String value2;
79 ASSERT_TRUE(DictionaryHelper::get(jsKeyframes[1], "width", value2)); 80 ASSERT_TRUE(DictionaryHelper::get(jsKeyframes[1], "width", value2));
80 ASSERT_EQ("0px", value2); 81 ASSERT_EQ("0px", value2);
81 82
82 KeyframeEffect* animation = createAnimation(element.get(), jsKeyframes, 0, e xceptionState); 83 KeyframeEffect* animation = createAnimation(element.get(), jsKeyframes, 0);
83 84
84 Element* target = animation->target(); 85 Element* target = animation->target();
85 EXPECT_EQ(*element.get(), *target); 86 EXPECT_EQ(*element.get(), *target);
86 87
87 const KeyframeVector keyframes = toKeyframeEffectModelBase(animation->model( ))->getFrames(); 88 const KeyframeVector keyframes = toKeyframeEffectModelBase(animation->model( ))->getFrames();
88 89
89 EXPECT_EQ(0, keyframes[0]->offset()); 90 EXPECT_EQ(0, keyframes[0]->offset());
90 EXPECT_EQ(1, keyframes[1]->offset()); 91 EXPECT_EQ(1, keyframes[1]->offset());
91 92
92 const CSSValue& keyframe1Width = toStringKeyframe(keyframes[0].get())->cssPr opertyValue(CSSPropertyWidth); 93 const CSSValue& keyframe1Width = toStringKeyframe(keyframes[0].get())->cssPr opertyValue(CSSPropertyWidth);
93 const CSSValue& keyframe2Width = toStringKeyframe(keyframes[1].get())->cssPr opertyValue(CSSPropertyWidth); 94 const CSSValue& keyframe2Width = toStringKeyframe(keyframes[1].get())->cssPr opertyValue(CSSPropertyWidth);
94 95
95 EXPECT_EQ("100px", keyframe1Width.cssText()); 96 EXPECT_EQ("100px", keyframe1Width.cssText());
96 EXPECT_EQ("0px", keyframe2Width.cssText()); 97 EXPECT_EQ("0px", keyframe2Width.cssText());
97 98
98 EXPECT_EQ(*(CubicBezierTimingFunction::preset(CubicBezierTimingFunction::Eas eType::EASE_IN_OUT)), keyframes[0]->easing()); 99 EXPECT_EQ(*(CubicBezierTimingFunction::preset(CubicBezierTimingFunction::Eas eType::EASE_IN_OUT)), keyframes[0]->easing());
99 EXPECT_EQ(*(CubicBezierTimingFunction::create(1, 1, 0.3, 0.3).get()), keyfra mes[1]->easing()); 100 EXPECT_EQ(*(CubicBezierTimingFunction::create(1, 1, 0.3, 0.3).get()), keyfra mes[1]->easing());
100 } 101 }
101 102
102 TEST_F(AnimationKeyframeEffectV8Test, CanSetDuration) 103 TEST_F(AnimationKeyframeEffectV8Test, CanSetDuration)
103 { 104 {
104 Vector<Dictionary, 0> jsKeyframes; 105 Vector<Dictionary, 0> jsKeyframes;
105 double duration = 2000; 106 double duration = 2000;
106 107
107 KeyframeEffect* animation = createAnimation(element.get(), jsKeyframes, dura tion, exceptionState); 108 KeyframeEffect* animation = createAnimation(element.get(), jsKeyframes, dura tion);
108 109
109 EXPECT_EQ(duration / 1000, animation->specifiedTiming().iterationDuration); 110 EXPECT_EQ(duration / 1000, animation->specifiedTiming().iterationDuration);
110 } 111 }
111 112
112 TEST_F(AnimationKeyframeEffectV8Test, CanOmitSpecifiedDuration) 113 TEST_F(AnimationKeyframeEffectV8Test, CanOmitSpecifiedDuration)
113 { 114 {
114 Vector<Dictionary, 0> jsKeyframes; 115 Vector<Dictionary, 0> jsKeyframes;
115 KeyframeEffect* animation = createAnimation(element.get(), jsKeyframes, exce ptionState); 116 KeyframeEffect* animation = createAnimation(element.get(), jsKeyframes);
116 EXPECT_TRUE(std::isnan(animation->specifiedTiming().iterationDuration)); 117 EXPECT_TRUE(std::isnan(animation->specifiedTiming().iterationDuration));
117 } 118 }
118 119
119 TEST_F(AnimationKeyframeEffectV8Test, SpecifiedGetters) 120 TEST_F(AnimationKeyframeEffectV8Test, SpecifiedGetters)
120 { 121 {
121 V8TestingScope scope; 122 V8TestingScope scope;
122 Vector<Dictionary, 0> jsKeyframes; 123 Vector<Dictionary, 0> jsKeyframes;
123 124
124 v8::Local<v8::Object> timingInput = v8::Object::New(scope.isolate()); 125 v8::Local<v8::Object> timingInput = v8::Object::New(scope.isolate());
125 setV8ObjectPropertyAsNumber(scope.isolate(), timingInput, "delay", 2); 126 setV8ObjectPropertyAsNumber(scope.isolate(), timingInput, "delay", 2);
126 setV8ObjectPropertyAsNumber(scope.isolate(), timingInput, "endDelay", 0.5); 127 setV8ObjectPropertyAsNumber(scope.isolate(), timingInput, "endDelay", 0.5);
127 setV8ObjectPropertyAsString(scope.isolate(), timingInput, "fill", "backwards "); 128 setV8ObjectPropertyAsString(scope.isolate(), timingInput, "fill", "backwards ");
128 setV8ObjectPropertyAsNumber(scope.isolate(), timingInput, "iterationStart", 2); 129 setV8ObjectPropertyAsNumber(scope.isolate(), timingInput, "iterationStart", 2);
129 setV8ObjectPropertyAsNumber(scope.isolate(), timingInput, "iterations", 10); 130 setV8ObjectPropertyAsNumber(scope.isolate(), timingInput, "iterations", 10);
130 setV8ObjectPropertyAsString(scope.isolate(), timingInput, "direction", "reve rse"); 131 setV8ObjectPropertyAsString(scope.isolate(), timingInput, "direction", "reve rse");
131 setV8ObjectPropertyAsString(scope.isolate(), timingInput, "easing", "step-st art"); 132 setV8ObjectPropertyAsString(scope.isolate(), timingInput, "easing", "step-st art");
132 KeyframeEffectOptions timingInputDictionary; 133 KeyframeEffectOptions timingInputDictionary;
134 TrackExceptionState exceptionState;
133 V8KeyframeEffectOptions::toImpl(scope.isolate(), timingInput, timingInputDic tionary, exceptionState); 135 V8KeyframeEffectOptions::toImpl(scope.isolate(), timingInput, timingInputDic tionary, exceptionState);
136 EXPECT_FALSE(exceptionState.hadException());
134 137
135 KeyframeEffect* animation = createAnimation(element.get(), jsKeyframes, timi ngInputDictionary, exceptionState); 138 KeyframeEffect* animation = createAnimation(element.get(), jsKeyframes, timi ngInputDictionary);
136 139
137 AnimationEffectTiming* specified = animation->timing(); 140 AnimationEffectTiming* specified = animation->timing();
138 EXPECT_EQ(2, specified->delay()); 141 EXPECT_EQ(2, specified->delay());
139 EXPECT_EQ(0.5, specified->endDelay()); 142 EXPECT_EQ(0.5, specified->endDelay());
140 EXPECT_EQ("backwards", specified->fill()); 143 EXPECT_EQ("backwards", specified->fill());
141 EXPECT_EQ(2, specified->iterationStart()); 144 EXPECT_EQ(2, specified->iterationStart());
142 EXPECT_EQ(10, specified->iterations()); 145 EXPECT_EQ(10, specified->iterations());
143 EXPECT_EQ("reverse", specified->direction()); 146 EXPECT_EQ("reverse", specified->direction());
144 EXPECT_EQ("step-start", specified->easing()); 147 EXPECT_EQ("step-start", specified->easing());
145 } 148 }
146 149
147 TEST_F(AnimationKeyframeEffectV8Test, SpecifiedDurationGetter) 150 TEST_F(AnimationKeyframeEffectV8Test, SpecifiedDurationGetter)
148 { 151 {
149 V8TestingScope scope; 152 V8TestingScope scope;
150 Vector<Dictionary, 0> jsKeyframes; 153 Vector<Dictionary, 0> jsKeyframes;
151 154
152 v8::Local<v8::Object> timingInputWithDuration = v8::Object::New(scope.isolat e()); 155 v8::Local<v8::Object> timingInputWithDuration = v8::Object::New(scope.isolat e());
153 setV8ObjectPropertyAsNumber(scope.isolate(), timingInputWithDuration, "durat ion", 2.5); 156 setV8ObjectPropertyAsNumber(scope.isolate(), timingInputWithDuration, "durat ion", 2.5);
154 KeyframeEffectOptions timingInputDictionaryWithDuration; 157 KeyframeEffectOptions timingInputDictionaryWithDuration;
158 TrackExceptionState exceptionState;
155 V8KeyframeEffectOptions::toImpl(scope.isolate(), timingInputWithDuration, ti mingInputDictionaryWithDuration, exceptionState); 159 V8KeyframeEffectOptions::toImpl(scope.isolate(), timingInputWithDuration, ti mingInputDictionaryWithDuration, exceptionState);
160 EXPECT_FALSE(exceptionState.hadException());
156 161
157 KeyframeEffect* animationWithDuration = createAnimation(element.get(), jsKey frames, timingInputDictionaryWithDuration, exceptionState); 162 KeyframeEffect* animationWithDuration = createAnimation(element.get(), jsKey frames, timingInputDictionaryWithDuration);
158 163
159 AnimationEffectTiming* specifiedWithDuration = animationWithDuration->timing (); 164 AnimationEffectTiming* specifiedWithDuration = animationWithDuration->timing ();
160 UnrestrictedDoubleOrString duration; 165 UnrestrictedDoubleOrString duration;
161 specifiedWithDuration->duration(duration); 166 specifiedWithDuration->duration(duration);
162 EXPECT_TRUE(duration.isUnrestrictedDouble()); 167 EXPECT_TRUE(duration.isUnrestrictedDouble());
163 EXPECT_EQ(2.5, duration.getAsUnrestrictedDouble()); 168 EXPECT_EQ(2.5, duration.getAsUnrestrictedDouble());
164 EXPECT_FALSE(duration.isString()); 169 EXPECT_FALSE(duration.isString());
165 170
166 171
167 v8::Local<v8::Object> timingInputNoDuration = v8::Object::New(scope.isolate( )); 172 v8::Local<v8::Object> timingInputNoDuration = v8::Object::New(scope.isolate( ));
168 KeyframeEffectOptions timingInputDictionaryNoDuration; 173 KeyframeEffectOptions timingInputDictionaryNoDuration;
169 V8KeyframeEffectOptions::toImpl(scope.isolate(), timingInputNoDuration, timi ngInputDictionaryNoDuration, exceptionState); 174 V8KeyframeEffectOptions::toImpl(scope.isolate(), timingInputNoDuration, timi ngInputDictionaryNoDuration, exceptionState);
175 EXPECT_FALSE(exceptionState.hadException());
170 176
171 KeyframeEffect* animationNoDuration = createAnimation(element.get(), jsKeyfr ames, timingInputDictionaryNoDuration, exceptionState); 177 KeyframeEffect* animationNoDuration = createAnimation(element.get(), jsKeyfr ames, timingInputDictionaryNoDuration);
172 178
173 AnimationEffectTiming* specifiedNoDuration = animationNoDuration->timing(); 179 AnimationEffectTiming* specifiedNoDuration = animationNoDuration->timing();
174 UnrestrictedDoubleOrString duration2; 180 UnrestrictedDoubleOrString duration2;
175 specifiedNoDuration->duration(duration2); 181 specifiedNoDuration->duration(duration2);
176 EXPECT_FALSE(duration2.isUnrestrictedDouble()); 182 EXPECT_FALSE(duration2.isUnrestrictedDouble());
177 EXPECT_TRUE(duration2.isString()); 183 EXPECT_TRUE(duration2.isString());
178 EXPECT_EQ("auto", duration2.getAsString()); 184 EXPECT_EQ("auto", duration2.getAsString());
179 } 185 }
180 186
181 TEST_F(AnimationKeyframeEffectV8Test, SpecifiedSetters) 187 TEST_F(AnimationKeyframeEffectV8Test, SpecifiedSetters)
182 { 188 {
183 V8TestingScope scope; 189 V8TestingScope scope;
184 Vector<Dictionary, 0> jsKeyframes; 190 Vector<Dictionary, 0> jsKeyframes;
185 v8::Local<v8::Object> timingInput = v8::Object::New(scope.isolate()); 191 v8::Local<v8::Object> timingInput = v8::Object::New(scope.isolate());
186 KeyframeEffectOptions timingInputDictionary; 192 KeyframeEffectOptions timingInputDictionary;
193 TrackExceptionState exceptionState;
187 V8KeyframeEffectOptions::toImpl(scope.isolate(), timingInput, timingInputDic tionary, exceptionState); 194 V8KeyframeEffectOptions::toImpl(scope.isolate(), timingInput, timingInputDic tionary, exceptionState);
188 KeyframeEffect* animation = createAnimation(element.get(), jsKeyframes, timi ngInputDictionary, exceptionState); 195 EXPECT_FALSE(exceptionState.hadException());
196 KeyframeEffect* animation = createAnimation(element.get(), jsKeyframes, timi ngInputDictionary);
189 197
190 AnimationEffectTiming* specified = animation->timing(); 198 AnimationEffectTiming* specified = animation->timing();
191 199
192 EXPECT_EQ(0, specified->delay()); 200 EXPECT_EQ(0, specified->delay());
193 specified->setDelay(2); 201 specified->setDelay(2);
194 EXPECT_EQ(2, specified->delay()); 202 EXPECT_EQ(2, specified->delay());
195 203
196 EXPECT_EQ(0, specified->endDelay()); 204 EXPECT_EQ(0, specified->endDelay());
197 specified->setEndDelay(0.5); 205 specified->setEndDelay(0.5);
198 EXPECT_EQ(0.5, specified->endDelay()); 206 EXPECT_EQ(0.5, specified->endDelay());
(...skipping 25 matching lines...) Expand all
224 ASSERT_FALSE(exceptionState.hadException()); 232 ASSERT_FALSE(exceptionState.hadException());
225 EXPECT_EQ("step-start", specified->easing()); 233 EXPECT_EQ("step-start", specified->easing());
226 } 234 }
227 235
228 TEST_F(AnimationKeyframeEffectV8Test, SetSpecifiedDuration) 236 TEST_F(AnimationKeyframeEffectV8Test, SetSpecifiedDuration)
229 { 237 {
230 V8TestingScope scope; 238 V8TestingScope scope;
231 Vector<Dictionary, 0> jsKeyframes; 239 Vector<Dictionary, 0> jsKeyframes;
232 v8::Local<v8::Object> timingInput = v8::Object::New(scope.isolate()); 240 v8::Local<v8::Object> timingInput = v8::Object::New(scope.isolate());
233 KeyframeEffectOptions timingInputDictionary; 241 KeyframeEffectOptions timingInputDictionary;
242 TrackExceptionState exceptionState;
234 V8KeyframeEffectOptions::toImpl(scope.isolate(), timingInput, timingInputDic tionary, exceptionState); 243 V8KeyframeEffectOptions::toImpl(scope.isolate(), timingInput, timingInputDic tionary, exceptionState);
235 KeyframeEffect* animation = createAnimation(element.get(), jsKeyframes, timi ngInputDictionary, exceptionState); 244 EXPECT_FALSE(exceptionState.hadException());
245 KeyframeEffect* animation = createAnimation(element.get(), jsKeyframes, timi ngInputDictionary);
236 246
237 AnimationEffectTiming* specified = animation->timing(); 247 AnimationEffectTiming* specified = animation->timing();
238 248
239 UnrestrictedDoubleOrString duration; 249 UnrestrictedDoubleOrString duration;
240 specified->duration(duration); 250 specified->duration(duration);
241 EXPECT_FALSE(duration.isUnrestrictedDouble()); 251 EXPECT_FALSE(duration.isUnrestrictedDouble());
242 EXPECT_TRUE(duration.isString()); 252 EXPECT_TRUE(duration.isString());
243 EXPECT_EQ("auto", duration.getAsString()); 253 EXPECT_EQ("auto", duration.getAsString());
244 254
245 UnrestrictedDoubleOrString inDuration; 255 UnrestrictedDoubleOrString inDuration;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 Timing timing; 367 Timing timing;
358 timing.iterationDuration = 5; 368 timing.iterationDuration = 5;
359 KeyframeEffect* animation = KeyframeEffect::create(element.get(), nullptr, t iming); 369 KeyframeEffect* animation = KeyframeEffect::create(element.get(), nullptr, t iming);
360 EXPECT_EQ(element.get(), animation->target()); 370 EXPECT_EQ(element.get(), animation->target());
361 document().timeline().play(animation); 371 document().timeline().play(animation);
362 pageHolder.reset(); 372 pageHolder.reset();
363 element.clear(); 373 element.clear();
364 } 374 }
365 375
366 } // namespace blink 376 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698