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

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: narrower 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 160
161 TEST_F(V8ValueTraitsTest, vector) 161 TEST_F(V8ValueTraitsTest, vector)
162 { 162 {
163 Vector<RefPtr<RefCountedScriptWrappable> > v; 163 Vector<RefPtr<RefCountedScriptWrappable> > v;
164 v.append(RefCountedScriptWrappable::create("foo")); 164 v.append(RefCountedScriptWrappable::create("foo"));
165 v.append(RefCountedScriptWrappable::create("bar")); 165 v.append(RefCountedScriptWrappable::create("bar"));
166 166
167 CHECK_TOV8VALUE("foo,bar", v); 167 CHECK_TOV8VALUE("foo,bar", v);
168 } 168 }
169 169
170 TEST_F(V8ValueTraitsTest, stringVectors)
171 {
172 Vector<String> stringVector;
173 stringVector.append("foo");
174 stringVector.append("bar");
175 CHECK_TOV8VALUE("foo,bar", stringVector);
176
177 Vector<AtomicString> atomicStringVector;
178 atomicStringVector.append("quux");
179 atomicStringVector.append("bar");
180 CHECK_TOV8VALUE("quux,bar", atomicStringVector);
181 }
182
183 TEST_F(V8ValueTraitsTest, basicTypeVectors)
184 {
185 Vector<int> intVector;
186 intVector.append(42);
187 intVector.append(23);
188 CHECK_TOV8VALUE("42,23", intVector);
189
190 Vector<long> longVector;
191 longVector.append(31773);
192 longVector.append(404);
193 CHECK_TOV8VALUE("31773,404", longVector);
194
195 Vector<unsigned> unsignedVector;
196 unsignedVector.append(1);
197 unsignedVector.append(2);
198 CHECK_TOV8VALUE("1,2", unsignedVector);
199
200 Vector<unsigned long> unsignedLongVector;
201 unsignedLongVector.append(1001);
202 unsignedLongVector.append(2002);
203 CHECK_TOV8VALUE("1001,2002", unsignedLongVector);
204
205 Vector<float> floatVector;
206 floatVector.append(0.125);
207 floatVector.append(1.);
208 CHECK_TOV8VALUE("0.125,1", floatVector);
209
210 Vector<double> doubleVector;
211 doubleVector.append(2.3);
212 doubleVector.append(4.2);
213 CHECK_TOV8VALUE("2.3,4.2", doubleVector);
214
215 Vector<bool> boolVector;
216 boolVector.append(true);
217 boolVector.append(true);
218 boolVector.append(false);
219 CHECK_TOV8VALUE("true,true,false", boolVector);
220 }
221
170 TEST_F(V8ValueTraitsTest, heapVector) 222 TEST_F(V8ValueTraitsTest, heapVector)
171 { 223 {
172 HeapVector<Member<GarbageCollectedScriptWrappable> > v; 224 HeapVector<Member<GarbageCollectedScriptWrappable> > v;
173 v.append(new GarbageCollectedScriptWrappable("hoge")); 225 v.append(new GarbageCollectedScriptWrappable("hoge"));
174 v.append(new GarbageCollectedScriptWrappable("fuga")); 226 v.append(new GarbageCollectedScriptWrappable("fuga"));
175 v.append(nullptr); 227 v.append(nullptr);
176 228
177 CHECK_TOV8VALUE("hoge,fuga,", v); 229 CHECK_TOV8VALUE("hoge,fuga,", v);
178 } 230 }
179 231
232 TEST_F(V8ValueTraitsTest, stringHeapVectors)
233 {
234 HeapVector<String> stringVector;
235 stringVector.append("foo");
236 stringVector.append("bar");
237 CHECK_TOV8VALUE("foo,bar", stringVector);
238
239 HeapVector<AtomicString> atomicStringVector;
240 atomicStringVector.append("quux");
241 atomicStringVector.append("bar");
242 CHECK_TOV8VALUE("quux,bar", atomicStringVector);
243 }
244
245 TEST_F(V8ValueTraitsTest, basicTypeHeapVectors)
246 {
247 HeapVector<int> intVector;
248 intVector.append(42);
249 intVector.append(23);
250 CHECK_TOV8VALUE("42,23", intVector);
251
252 HeapVector<long> longVector;
253 longVector.append(31773);
254 longVector.append(404);
255 CHECK_TOV8VALUE("31773,404", longVector);
256
257 HeapVector<unsigned> unsignedVector;
258 unsignedVector.append(1);
259 unsignedVector.append(2);
260 CHECK_TOV8VALUE("1,2", unsignedVector);
261
262 HeapVector<unsigned long> unsignedLongVector;
263 unsignedLongVector.append(1001);
264 unsignedLongVector.append(2002);
265 CHECK_TOV8VALUE("1001,2002", unsignedLongVector);
266
267 HeapVector<float> floatVector;
268 floatVector.append(0.125);
269 floatVector.append(1.);
270 CHECK_TOV8VALUE("0.125,1", floatVector);
271
272 HeapVector<double> doubleVector;
273 doubleVector.append(2.3);
274 doubleVector.append(4.2);
275 CHECK_TOV8VALUE("2.3,4.2", doubleVector);
276
277 HeapVector<bool> boolVector;
278 boolVector.append(true);
279 boolVector.append(true);
280 boolVector.append(false);
281 CHECK_TOV8VALUE("true,true,false", boolVector);
282 }
283
180 TEST_F(V8ValueTraitsTest, scriptValue) 284 TEST_F(V8ValueTraitsTest, scriptValue)
181 { 285 {
182 ScriptValue value(m_scope.scriptState(), v8::Number::New(m_scope.isolate(), 1234)); 286 ScriptValue value(m_scope.scriptState(), v8::Number::New(m_scope.isolate(), 1234));
183 287
184 CHECK_TOV8VALUE("1234", value); 288 CHECK_TOV8VALUE("1234", value);
185 } 289 }
186 290
187 TEST_F(V8ValueTraitsTest, v8Value) 291 TEST_F(V8ValueTraitsTest, v8Value)
188 { 292 {
189 v8::Local<v8::Value> localValue(v8::Number::New(m_scope.isolate(), 1234)); 293 v8::Local<v8::Value> localValue(v8::Number::New(m_scope.isolate(), 1234));
190 v8::Handle<v8::Value> handleValue(v8::Number::New(m_scope.isolate(), 5678)); 294 v8::Handle<v8::Value> handleValue(v8::Number::New(m_scope.isolate(), 5678));
191 295
192 CHECK_TOV8VALUE("1234", localValue); 296 CHECK_TOV8VALUE("1234", localValue);
193 CHECK_TOV8VALUE("5678", handleValue); 297 CHECK_TOV8VALUE("5678", handleValue);
194 } 298 }
195 299
196 } // namespace 300 } // namespace
197 301
198 } // namespace blink 302 } // namespace blink
OLDNEW
« Source/bindings/core/v8/V8Binding.h ('K') | « Source/bindings/core/v8/V8Binding.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698