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 "core/animation/EffectInput.h" | 5 #include "core/animation/EffectInput.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 "core/animation/AnimationTestHelper.h" | 10 #include "core/animation/AnimationTestHelper.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 V8TestingScope scope; | 29 V8TestingScope scope; |
30 Vector<Dictionary> jsKeyframes; | 30 Vector<Dictionary> jsKeyframes; |
31 v8::Local<v8::Object> keyframe1 = v8::Object::New(scope.isolate()); | 31 v8::Local<v8::Object> keyframe1 = v8::Object::New(scope.isolate()); |
32 v8::Local<v8::Object> keyframe2 = v8::Object::New(scope.isolate()); | 32 v8::Local<v8::Object> keyframe2 = v8::Object::New(scope.isolate()); |
33 | 33 |
34 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "width", "100px"); | 34 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "width", "100px"); |
35 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "offset", "0"); | 35 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "offset", "0"); |
36 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "width", "0px"); | 36 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "width", "0px"); |
37 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "offset", "1"); | 37 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "offset", "1"); |
38 | 38 |
39 jsKeyframes.append( | 39 jsKeyframes.push_back( |
40 Dictionary(scope.isolate(), keyframe1, scope.getExceptionState())); | 40 Dictionary(scope.isolate(), keyframe1, scope.getExceptionState())); |
41 jsKeyframes.append( | 41 jsKeyframes.push_back( |
42 Dictionary(scope.isolate(), keyframe2, scope.getExceptionState())); | 42 Dictionary(scope.isolate(), keyframe2, scope.getExceptionState())); |
43 | 43 |
44 Element* element = appendElement(scope.document()); | 44 Element* element = appendElement(scope.document()); |
45 EffectModel* animationEffect = EffectInput::convert( | 45 EffectModel* animationEffect = EffectInput::convert( |
46 element, | 46 element, |
47 DictionarySequenceOrDictionary::fromDictionarySequence(jsKeyframes), | 47 DictionarySequenceOrDictionary::fromDictionarySequence(jsKeyframes), |
48 nullptr, scope.getExceptionState()); | 48 nullptr, scope.getExceptionState()); |
49 EXPECT_FALSE(scope.getExceptionState().hadException()); | 49 EXPECT_FALSE(scope.getExceptionState().hadException()); |
50 const KeyframeEffectModelBase& keyframeEffect = | 50 const KeyframeEffectModelBase& keyframeEffect = |
51 *toKeyframeEffectModelBase(animationEffect); | 51 *toKeyframeEffectModelBase(animationEffect); |
52 EXPECT_EQ(1.0, keyframeEffect.getFrames()[1]->offset()); | 52 EXPECT_EQ(1.0, keyframeEffect.getFrames()[1]->offset()); |
53 } | 53 } |
54 | 54 |
55 TEST(AnimationEffectInputTest, UnsortedOffsets) { | 55 TEST(AnimationEffectInputTest, UnsortedOffsets) { |
56 V8TestingScope scope; | 56 V8TestingScope scope; |
57 Vector<Dictionary> jsKeyframes; | 57 Vector<Dictionary> jsKeyframes; |
58 v8::Local<v8::Object> keyframe1 = v8::Object::New(scope.isolate()); | 58 v8::Local<v8::Object> keyframe1 = v8::Object::New(scope.isolate()); |
59 v8::Local<v8::Object> keyframe2 = v8::Object::New(scope.isolate()); | 59 v8::Local<v8::Object> keyframe2 = v8::Object::New(scope.isolate()); |
60 | 60 |
61 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "width", "0px"); | 61 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "width", "0px"); |
62 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "offset", "1"); | 62 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "offset", "1"); |
63 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "width", "100px"); | 63 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "width", "100px"); |
64 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "offset", "0"); | 64 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "offset", "0"); |
65 | 65 |
66 jsKeyframes.append( | 66 jsKeyframes.push_back( |
67 Dictionary(scope.isolate(), keyframe1, scope.getExceptionState())); | 67 Dictionary(scope.isolate(), keyframe1, scope.getExceptionState())); |
68 jsKeyframes.append( | 68 jsKeyframes.push_back( |
69 Dictionary(scope.isolate(), keyframe2, scope.getExceptionState())); | 69 Dictionary(scope.isolate(), keyframe2, scope.getExceptionState())); |
70 | 70 |
71 Element* element = appendElement(scope.document()); | 71 Element* element = appendElement(scope.document()); |
72 EffectInput::convert( | 72 EffectInput::convert( |
73 element, | 73 element, |
74 DictionarySequenceOrDictionary::fromDictionarySequence(jsKeyframes), | 74 DictionarySequenceOrDictionary::fromDictionarySequence(jsKeyframes), |
75 nullptr, scope.getExceptionState()); | 75 nullptr, scope.getExceptionState()); |
76 EXPECT_TRUE(scope.getExceptionState().hadException()); | 76 EXPECT_TRUE(scope.getExceptionState().hadException()); |
77 EXPECT_EQ(V8TypeError, scope.getExceptionState().code()); | 77 EXPECT_EQ(V8TypeError, scope.getExceptionState().code()); |
78 } | 78 } |
79 | 79 |
80 TEST(AnimationEffectInputTest, LooslySorted) { | 80 TEST(AnimationEffectInputTest, LooslySorted) { |
81 V8TestingScope scope; | 81 V8TestingScope scope; |
82 Vector<Dictionary> jsKeyframes; | 82 Vector<Dictionary> jsKeyframes; |
83 v8::Local<v8::Object> keyframe1 = v8::Object::New(scope.isolate()); | 83 v8::Local<v8::Object> keyframe1 = v8::Object::New(scope.isolate()); |
84 v8::Local<v8::Object> keyframe2 = v8::Object::New(scope.isolate()); | 84 v8::Local<v8::Object> keyframe2 = v8::Object::New(scope.isolate()); |
85 v8::Local<v8::Object> keyframe3 = v8::Object::New(scope.isolate()); | 85 v8::Local<v8::Object> keyframe3 = v8::Object::New(scope.isolate()); |
86 | 86 |
87 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "width", "100px"); | 87 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "width", "100px"); |
88 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "offset", "0"); | 88 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "offset", "0"); |
89 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "width", "200px"); | 89 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "width", "200px"); |
90 setV8ObjectPropertyAsString(scope.isolate(), keyframe3, "width", "0px"); | 90 setV8ObjectPropertyAsString(scope.isolate(), keyframe3, "width", "0px"); |
91 setV8ObjectPropertyAsString(scope.isolate(), keyframe3, "offset", "1"); | 91 setV8ObjectPropertyAsString(scope.isolate(), keyframe3, "offset", "1"); |
92 | 92 |
93 jsKeyframes.append( | 93 jsKeyframes.push_back( |
94 Dictionary(scope.isolate(), keyframe1, scope.getExceptionState())); | 94 Dictionary(scope.isolate(), keyframe1, scope.getExceptionState())); |
95 jsKeyframes.append( | 95 jsKeyframes.push_back( |
96 Dictionary(scope.isolate(), keyframe2, scope.getExceptionState())); | 96 Dictionary(scope.isolate(), keyframe2, scope.getExceptionState())); |
97 jsKeyframes.append( | 97 jsKeyframes.push_back( |
98 Dictionary(scope.isolate(), keyframe3, scope.getExceptionState())); | 98 Dictionary(scope.isolate(), keyframe3, scope.getExceptionState())); |
99 | 99 |
100 Element* element = appendElement(scope.document()); | 100 Element* element = appendElement(scope.document()); |
101 EffectModel* animationEffect = EffectInput::convert( | 101 EffectModel* animationEffect = EffectInput::convert( |
102 element, | 102 element, |
103 DictionarySequenceOrDictionary::fromDictionarySequence(jsKeyframes), | 103 DictionarySequenceOrDictionary::fromDictionarySequence(jsKeyframes), |
104 nullptr, scope.getExceptionState()); | 104 nullptr, scope.getExceptionState()); |
105 EXPECT_FALSE(scope.getExceptionState().hadException()); | 105 EXPECT_FALSE(scope.getExceptionState().hadException()); |
106 const KeyframeEffectModelBase& keyframeEffect = | 106 const KeyframeEffectModelBase& keyframeEffect = |
107 *toKeyframeEffectModelBase(animationEffect); | 107 *toKeyframeEffectModelBase(animationEffect); |
108 EXPECT_EQ(1, keyframeEffect.getFrames()[2]->offset()); | 108 EXPECT_EQ(1, keyframeEffect.getFrames()[2]->offset()); |
109 } | 109 } |
110 | 110 |
111 TEST(AnimationEffectInputTest, OutOfOrderWithNullOffsets) { | 111 TEST(AnimationEffectInputTest, OutOfOrderWithNullOffsets) { |
112 V8TestingScope scope; | 112 V8TestingScope scope; |
113 Vector<Dictionary> jsKeyframes; | 113 Vector<Dictionary> jsKeyframes; |
114 v8::Local<v8::Object> keyframe1 = v8::Object::New(scope.isolate()); | 114 v8::Local<v8::Object> keyframe1 = v8::Object::New(scope.isolate()); |
115 v8::Local<v8::Object> keyframe2 = v8::Object::New(scope.isolate()); | 115 v8::Local<v8::Object> keyframe2 = v8::Object::New(scope.isolate()); |
116 v8::Local<v8::Object> keyframe3 = v8::Object::New(scope.isolate()); | 116 v8::Local<v8::Object> keyframe3 = v8::Object::New(scope.isolate()); |
117 v8::Local<v8::Object> keyframe4 = v8::Object::New(scope.isolate()); | 117 v8::Local<v8::Object> keyframe4 = v8::Object::New(scope.isolate()); |
118 | 118 |
119 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "height", "100px"); | 119 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "height", "100px"); |
120 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "offset", "0.5"); | 120 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "offset", "0.5"); |
121 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "height", "150px"); | 121 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "height", "150px"); |
122 setV8ObjectPropertyAsString(scope.isolate(), keyframe3, "height", "200px"); | 122 setV8ObjectPropertyAsString(scope.isolate(), keyframe3, "height", "200px"); |
123 setV8ObjectPropertyAsString(scope.isolate(), keyframe3, "offset", "0"); | 123 setV8ObjectPropertyAsString(scope.isolate(), keyframe3, "offset", "0"); |
124 setV8ObjectPropertyAsString(scope.isolate(), keyframe4, "height", "300px"); | 124 setV8ObjectPropertyAsString(scope.isolate(), keyframe4, "height", "300px"); |
125 setV8ObjectPropertyAsString(scope.isolate(), keyframe4, "offset", "1"); | 125 setV8ObjectPropertyAsString(scope.isolate(), keyframe4, "offset", "1"); |
126 | 126 |
127 jsKeyframes.append( | 127 jsKeyframes.push_back( |
128 Dictionary(scope.isolate(), keyframe1, scope.getExceptionState())); | 128 Dictionary(scope.isolate(), keyframe1, scope.getExceptionState())); |
129 jsKeyframes.append( | 129 jsKeyframes.push_back( |
130 Dictionary(scope.isolate(), keyframe2, scope.getExceptionState())); | 130 Dictionary(scope.isolate(), keyframe2, scope.getExceptionState())); |
131 jsKeyframes.append( | 131 jsKeyframes.push_back( |
132 Dictionary(scope.isolate(), keyframe3, scope.getExceptionState())); | 132 Dictionary(scope.isolate(), keyframe3, scope.getExceptionState())); |
133 jsKeyframes.append( | 133 jsKeyframes.push_back( |
134 Dictionary(scope.isolate(), keyframe4, scope.getExceptionState())); | 134 Dictionary(scope.isolate(), keyframe4, scope.getExceptionState())); |
135 | 135 |
136 Element* element = appendElement(scope.document()); | 136 Element* element = appendElement(scope.document()); |
137 EffectInput::convert( | 137 EffectInput::convert( |
138 element, | 138 element, |
139 DictionarySequenceOrDictionary::fromDictionarySequence(jsKeyframes), | 139 DictionarySequenceOrDictionary::fromDictionarySequence(jsKeyframes), |
140 nullptr, scope.getExceptionState()); | 140 nullptr, scope.getExceptionState()); |
141 EXPECT_TRUE(scope.getExceptionState().hadException()); | 141 EXPECT_TRUE(scope.getExceptionState().hadException()); |
142 } | 142 } |
143 | 143 |
144 TEST(AnimationEffectInputTest, Invalid) { | 144 TEST(AnimationEffectInputTest, Invalid) { |
145 V8TestingScope scope; | 145 V8TestingScope scope; |
146 // Not loosely sorted by offset, and there exists a keyframe with null offset. | 146 // Not loosely sorted by offset, and there exists a keyframe with null offset. |
147 Vector<Dictionary> jsKeyframes; | 147 Vector<Dictionary> jsKeyframes; |
148 v8::Local<v8::Object> keyframe1 = v8::Object::New(scope.isolate()); | 148 v8::Local<v8::Object> keyframe1 = v8::Object::New(scope.isolate()); |
149 v8::Local<v8::Object> keyframe2 = v8::Object::New(scope.isolate()); | 149 v8::Local<v8::Object> keyframe2 = v8::Object::New(scope.isolate()); |
150 v8::Local<v8::Object> keyframe3 = v8::Object::New(scope.isolate()); | 150 v8::Local<v8::Object> keyframe3 = v8::Object::New(scope.isolate()); |
151 | 151 |
152 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "width", "0px"); | 152 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "width", "0px"); |
153 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "offset", "1"); | 153 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "offset", "1"); |
154 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "width", "200px"); | 154 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "width", "200px"); |
155 setV8ObjectPropertyAsString(scope.isolate(), keyframe3, "width", "100px"); | 155 setV8ObjectPropertyAsString(scope.isolate(), keyframe3, "width", "100px"); |
156 setV8ObjectPropertyAsString(scope.isolate(), keyframe3, "offset", "0"); | 156 setV8ObjectPropertyAsString(scope.isolate(), keyframe3, "offset", "0"); |
157 | 157 |
158 jsKeyframes.append( | 158 jsKeyframes.push_back( |
159 Dictionary(scope.isolate(), keyframe1, scope.getExceptionState())); | 159 Dictionary(scope.isolate(), keyframe1, scope.getExceptionState())); |
160 jsKeyframes.append( | 160 jsKeyframes.push_back( |
161 Dictionary(scope.isolate(), keyframe2, scope.getExceptionState())); | 161 Dictionary(scope.isolate(), keyframe2, scope.getExceptionState())); |
162 jsKeyframes.append( | 162 jsKeyframes.push_back( |
163 Dictionary(scope.isolate(), keyframe3, scope.getExceptionState())); | 163 Dictionary(scope.isolate(), keyframe3, scope.getExceptionState())); |
164 | 164 |
165 Element* element = appendElement(scope.document()); | 165 Element* element = appendElement(scope.document()); |
166 EffectInput::convert( | 166 EffectInput::convert( |
167 element, | 167 element, |
168 DictionarySequenceOrDictionary::fromDictionarySequence(jsKeyframes), | 168 DictionarySequenceOrDictionary::fromDictionarySequence(jsKeyframes), |
169 nullptr, scope.getExceptionState()); | 169 nullptr, scope.getExceptionState()); |
170 EXPECT_TRUE(scope.getExceptionState().hadException()); | 170 EXPECT_TRUE(scope.getExceptionState().hadException()); |
171 EXPECT_EQ(V8TypeError, scope.getExceptionState().code()); | 171 EXPECT_EQ(V8TypeError, scope.getExceptionState().code()); |
172 } | 172 } |
173 | 173 |
174 } // namespace blink | 174 } // namespace blink |
OLD | NEW |