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

Side by Side Diff: Source/bindings/core/v8/V8BindingTest.cpp

Issue 400493005: Make vector conversion more general in V8Bindings (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: finished self review, PTAL Created 6 years, 5 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 | Annotate | Revision Log
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 "bindings/core/v8/V8Binding.h" 6 #include "bindings/core/v8/V8Binding.h"
7 7
8 #include "core/testing/GarbageCollectedScriptWrappable.h" 8 #include "core/testing/GarbageCollectedScriptWrappable.h"
9 #include "core/testing/RefCountedScriptWrappable.h" 9 #include "core/testing/RefCountedScriptWrappable.h"
10 #include "platform/heap/Heap.h" 10 #include "platform/heap/Heap.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 147
148 TEST_F(V8ValueTraitsTest, vector) 148 TEST_F(V8ValueTraitsTest, vector)
149 { 149 {
150 Vector<RefPtr<RefCountedScriptWrappable> > v; 150 Vector<RefPtr<RefCountedScriptWrappable> > v;
151 v.append(RefCountedScriptWrappable::create("foo")); 151 v.append(RefCountedScriptWrappable::create("foo"));
152 v.append(RefCountedScriptWrappable::create("bar")); 152 v.append(RefCountedScriptWrappable::create("bar"));
153 153
154 CHECK_TOV8VALUE("foo,bar", v); 154 CHECK_TOV8VALUE("foo,bar", v);
155 } 155 }
156 156
157 TEST_F(V8ValueTraitsTest, stringVectors)
158 {
159 Vector<String> stringVector;
160 stringVector.append("foo");
161 stringVector.append("bar");
162 CHECK_TOV8VALUE("foo,bar", stringVector);
163
164 Vector<AtomicString> atomicStringVector;
165 atomicStringVector.append("quux");
166 atomicStringVector.append("bar");
167 CHECK_TOV8VALUE("quux,bar", atomicStringVector);
168 }
169
170 TEST_F(V8ValueTraitsTest, basicTypeVectors)
171 {
172 Vector<int> intVector;
173 intVector.append(42);
174 intVector.append(23);
175 CHECK_TOV8VALUE("42,23", intVector);
176
177 Vector<long> longVector;
178 longVector.append(31773);
179 longVector.append(404);
180 CHECK_TOV8VALUE("31773,404", longVector);
181
182 Vector<unsigned> unsignedVector;
183 unsignedVector.append(1);
184 unsignedVector.append(2);
185 CHECK_TOV8VALUE("1,2", unsignedVector);
186
187 Vector<unsigned long> unsignedLongVector;
188 unsignedLongVector.append(1001);
189 unsignedLongVector.append(2002);
190 CHECK_TOV8VALUE("1001,2002", unsignedLongVector);
191
192 Vector<float> floatVector;
193 floatVector.append(0.125);
194 floatVector.append(1.);
195 CHECK_TOV8VALUE("0.125,1", floatVector);
196
197 Vector<double> doubleVector;
198 doubleVector.append(2.3);
199 doubleVector.append(4.2);
200 CHECK_TOV8VALUE("2.3,4.2", doubleVector);
201
202 Vector<bool> boolVector;
203 boolVector.append(true);
204 boolVector.append(true);
205 boolVector.append(false);
206 CHECK_TOV8VALUE("true,true,false", boolVector);
207 }
208
157 TEST_F(V8ValueTraitsTest, heapVector) 209 TEST_F(V8ValueTraitsTest, heapVector)
158 { 210 {
159 HeapVector<Member<GarbageCollectedScriptWrappable> > v; 211 HeapVector<Member<GarbageCollectedScriptWrappable> > v;
160 v.append(new GarbageCollectedScriptWrappable("hoge")); 212 v.append(new GarbageCollectedScriptWrappable("hoge"));
161 v.append(new GarbageCollectedScriptWrappable("fuga")); 213 v.append(new GarbageCollectedScriptWrappable("fuga"));
162 v.append(nullptr); 214 v.append(nullptr);
163 215
164 CHECK_TOV8VALUE("hoge,fuga,", v); 216 CHECK_TOV8VALUE("hoge,fuga,", v);
165 } 217 }
166 218
219 TEST_F(V8ValueTraitsTest, stringHeapVectors)
220 {
221 HeapVector<String> stringVector;
222 stringVector.append("foo");
223 stringVector.append("bar");
224 CHECK_TOV8VALUE("foo,bar", stringVector);
225
226 HeapVector<AtomicString> atomicStringVector;
227 atomicStringVector.append("quux");
228 atomicStringVector.append("bar");
229 CHECK_TOV8VALUE("quux,bar", atomicStringVector);
230 }
231
232 TEST_F(V8ValueTraitsTest, basicTypeHeapVectors)
233 {
234 HeapVector<int> intVector;
235 intVector.append(42);
236 intVector.append(23);
237 CHECK_TOV8VALUE("42,23", intVector);
238
239 HeapVector<long> longVector;
240 longVector.append(31773);
241 longVector.append(404);
242 CHECK_TOV8VALUE("31773,404", longVector);
243
244 HeapVector<unsigned> unsignedVector;
245 unsignedVector.append(1);
246 unsignedVector.append(2);
247 CHECK_TOV8VALUE("1,2", unsignedVector);
248
249 HeapVector<unsigned long> unsignedLongVector;
250 unsignedLongVector.append(1001);
251 unsignedLongVector.append(2002);
252 CHECK_TOV8VALUE("1001,2002", unsignedLongVector);
253
254 HeapVector<float> floatVector;
255 floatVector.append(0.125);
256 floatVector.append(1.);
257 CHECK_TOV8VALUE("0.125,1", floatVector);
258
259 HeapVector<double> doubleVector;
260 doubleVector.append(2.3);
261 doubleVector.append(4.2);
262 CHECK_TOV8VALUE("2.3,4.2", doubleVector);
263
264 HeapVector<bool> boolVector;
265 boolVector.append(true);
266 boolVector.append(true);
267 boolVector.append(false);
268 CHECK_TOV8VALUE("true,true,false", boolVector);
269 }
270
167 TEST_F(V8ValueTraitsTest, scriptValue) 271 TEST_F(V8ValueTraitsTest, scriptValue)
168 { 272 {
169 ScriptValue value(m_scope.scriptState(), v8::Number::New(m_scope.isolate(), 1234)); 273 ScriptValue value(m_scope.scriptState(), v8::Number::New(m_scope.isolate(), 1234));
170 274
171 CHECK_TOV8VALUE("1234", value); 275 CHECK_TOV8VALUE("1234", value);
172 } 276 }
173 277
174 TEST_F(V8ValueTraitsTest, v8Value) 278 TEST_F(V8ValueTraitsTest, v8Value)
175 { 279 {
176 v8::Local<v8::Value> localValue(v8::Number::New(m_scope.isolate(), 1234)); 280 v8::Local<v8::Value> localValue(v8::Number::New(m_scope.isolate(), 1234));
177 v8::Handle<v8::Value> handleValue(v8::Number::New(m_scope.isolate(), 5678)); 281 v8::Handle<v8::Value> handleValue(v8::Number::New(m_scope.isolate(), 5678));
178 282
179 CHECK_TOV8VALUE("1234", localValue); 283 CHECK_TOV8VALUE("1234", localValue);
180 CHECK_TOV8VALUE("5678", handleValue); 284 CHECK_TOV8VALUE("5678", handleValue);
181 } 285 }
182 286
183 } // namespace 287 } // namespace
184 288
185 } // namespace WebCore 289 } // namespace WebCore
OLDNEW
« Source/bindings/core/v8/V8Binding.h ('K') | « Source/bindings/core/v8/V8Binding.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698