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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/serialization/V8ScriptValueSerializerTest.cpp

Issue 2874203003: Implement serialization/deserialization of geometry interfaces (Closed)
Patch Set: x Created 3 years, 6 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "bindings/core/v8/serialization/V8ScriptValueSerializer.h" 5 #include "bindings/core/v8/serialization/V8ScriptValueSerializer.h"
6 6
7 #include "bindings/core/v8/ExceptionState.h" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "bindings/core/v8/ScriptController.h" 8 #include "bindings/core/v8/ScriptController.h"
9 #include "bindings/core/v8/ScriptSourceCode.h" 9 #include "bindings/core/v8/ScriptSourceCode.h"
10 #include "bindings/core/v8/V8BindingForTesting.h" 10 #include "bindings/core/v8/V8BindingForTesting.h"
11 #include "bindings/core/v8/V8Blob.h" 11 #include "bindings/core/v8/V8Blob.h"
12 #include "bindings/core/v8/V8CompositorProxy.h" 12 #include "bindings/core/v8/V8CompositorProxy.h"
13 #include "bindings/core/v8/V8DOMException.h" 13 #include "bindings/core/v8/V8DOMException.h"
14 #include "bindings/core/v8/V8DOMMatrix.h"
15 #include "bindings/core/v8/V8DOMMatrixReadOnly.h"
16 #include "bindings/core/v8/V8DOMPoint.h"
17 #include "bindings/core/v8/V8DOMPointInit.h"
18 #include "bindings/core/v8/V8DOMPointReadOnly.h"
19 #include "bindings/core/v8/V8DOMQuad.h"
20 #include "bindings/core/v8/V8DOMRect.h"
21 #include "bindings/core/v8/V8DOMRectReadOnly.h"
14 #include "bindings/core/v8/V8File.h" 22 #include "bindings/core/v8/V8File.h"
15 #include "bindings/core/v8/V8FileList.h" 23 #include "bindings/core/v8/V8FileList.h"
16 #include "bindings/core/v8/V8ImageBitmap.h" 24 #include "bindings/core/v8/V8ImageBitmap.h"
17 #include "bindings/core/v8/V8ImageData.h" 25 #include "bindings/core/v8/V8ImageData.h"
18 #include "bindings/core/v8/V8MessagePort.h" 26 #include "bindings/core/v8/V8MessagePort.h"
19 #include "bindings/core/v8/V8OffscreenCanvas.h" 27 #include "bindings/core/v8/V8OffscreenCanvas.h"
20 #include "bindings/core/v8/V8StringResource.h" 28 #include "bindings/core/v8/V8StringResource.h"
21 #include "bindings/core/v8/serialization/V8ScriptValueDeserializer.h" 29 #include "bindings/core/v8/serialization/V8ScriptValueDeserializer.h"
22 #include "core/dom/CompositorProxy.h" 30 #include "core/dom/CompositorProxy.h"
23 #include "core/dom/MessagePort.h" 31 #include "core/dom/MessagePort.h"
24 #include "core/fileapi/Blob.h" 32 #include "core/fileapi/Blob.h"
25 #include "core/fileapi/File.h" 33 #include "core/fileapi/File.h"
26 #include "core/fileapi/FileList.h" 34 #include "core/fileapi/FileList.h"
27 #include "core/frame/LocalFrame.h" 35 #include "core/frame/LocalFrame.h"
36 #include "core/geometry/DOMMatrix.h"
37 #include "core/geometry/DOMMatrixReadOnly.h"
38 #include "core/geometry/DOMPoint.h"
39 #include "core/geometry/DOMPointReadOnly.h"
40 #include "core/geometry/DOMQuad.h"
41 #include "core/geometry/DOMRect.h"
42 #include "core/geometry/DOMRectReadOnly.h"
28 #include "core/html/ImageData.h" 43 #include "core/html/ImageData.h"
29 #include "core/offscreencanvas/OffscreenCanvas.h" 44 #include "core/offscreencanvas/OffscreenCanvas.h"
30 #include "platform/RuntimeEnabledFeatures.h" 45 #include "platform/RuntimeEnabledFeatures.h"
31 #include "platform/graphics/CompositorMutableProperties.h" 46 #include "platform/graphics/CompositorMutableProperties.h"
32 #include "platform/graphics/StaticBitmapImage.h" 47 #include "platform/graphics/StaticBitmapImage.h"
33 #include "platform/wtf/CurrentTime.h" 48 #include "platform/wtf/CurrentTime.h"
34 #include "platform/wtf/DateMath.h" 49 #include "platform/wtf/DateMath.h"
35 #include "public/platform/WebBlobInfo.h" 50 #include "public/platform/WebBlobInfo.h"
36 #include "public/platform/WebMessagePortChannel.h" 51 #include "public/platform/WebMessagePortChannel.h"
37 #include "public/platform/WebMessagePortChannelClient.h" 52 #include "public/platform/WebMessagePortChannelClient.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 90
76 V8ScriptValueSerializer::Options serialize_options; 91 V8ScriptValueSerializer::Options serialize_options;
77 serialize_options.transferables = transferables; 92 serialize_options.transferables = transferables;
78 serialize_options.blob_info = blob_info; 93 serialize_options.blob_info = blob_info;
79 V8ScriptValueSerializer serializer(script_state, serialize_options); 94 V8ScriptValueSerializer serializer(script_state, serialize_options);
80 RefPtr<SerializedScriptValue> serialized_script_value = 95 RefPtr<SerializedScriptValue> serialized_script_value =
81 serializer.Serialize(value, exception_state); 96 serializer.Serialize(value, exception_state);
82 DCHECK_EQ(!serialized_script_value, exception_state.HadException()); 97 DCHECK_EQ(!serialized_script_value, exception_state.HadException());
83 if (!serialized_script_value) 98 if (!serialized_script_value)
84 return v8::Local<v8::Value>(); 99 return v8::Local<v8::Value>();
85
86 // If there are message ports, make new ones and entangle them. 100 // If there are message ports, make new ones and entangle them.
87 MessagePortArray* transferred_message_ports = MessagePort::EntanglePorts( 101 MessagePortArray* transferred_message_ports = MessagePort::EntanglePorts(
88 *scope.GetExecutionContext(), std::move(channels)); 102 *scope.GetExecutionContext(), std::move(channels));
89 103
90 V8ScriptValueDeserializer::Options deserialize_options; 104 V8ScriptValueDeserializer::Options deserialize_options;
91 deserialize_options.message_ports = transferred_message_ports; 105 deserialize_options.message_ports = transferred_message_ports;
92 deserialize_options.blob_info = blob_info; 106 deserialize_options.blob_info = blob_info;
93 V8ScriptValueDeserializer deserializer(script_state, serialized_script_value, 107 V8ScriptValueDeserializer deserializer(script_state, serialized_script_value,
94 deserialize_options); 108 deserialize_options);
95 return deserializer.Deserialize(); 109 return deserializer.Deserialize();
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 Transferables transferables; 215 Transferables transferables;
202 transferables.array_buffers.push_back(array_buffer); 216 transferables.array_buffers.push_back(array_buffer);
203 217
204 RoundTrip(object, scope, &exception_state, &transferables); 218 RoundTrip(object, scope, &exception_state, &transferables);
205 ASSERT_TRUE(exception_state.HadException()); 219 ASSERT_TRUE(exception_state.HadException());
206 EXPECT_FALSE(HadDOMException("DataCloneError", scope.GetScriptState(), 220 EXPECT_FALSE(HadDOMException("DataCloneError", scope.GetScriptState(),
207 exception_state)); 221 exception_state));
208 EXPECT_FALSE(array_buffer->IsNeutered()); 222 EXPECT_FALSE(array_buffer->IsNeutered());
209 } 223 }
210 224
225 TEST(V8ScriptValueSerializerTest, RoundTripDOMPoint) {
226 // DOMPoint objects should serialize and deserialize correctly.
227 V8TestingScope scope;
228 DOMPoint* point = DOMPoint::Create(1, 2, 3, 4);
229 v8::Local<v8::Value> wrapper =
230 ToV8(point, scope.GetContext()->Global(), scope.GetIsolate());
231 v8::Local<v8::Value> result = RoundTrip(wrapper, scope);
232 ASSERT_TRUE(V8DOMPoint::hasInstance(result, scope.GetIsolate()));
233 DOMPoint* new_point = V8DOMPoint::toImpl(result.As<v8::Object>());
234 EXPECT_NE(point, new_point);
235 EXPECT_EQ(point->x(), new_point->x());
236 EXPECT_EQ(point->y(), new_point->y());
237 EXPECT_EQ(point->z(), new_point->z());
238 EXPECT_EQ(point->w(), new_point->w());
239 }
240
241 TEST(V8ScriptValueSerializerTest, DecodeDOMPoint) {
242 V8TestingScope scope;
243 ScriptState* script_state = scope.GetScriptState();
244 RefPtr<SerializedScriptValue> input = SerializedValue(
245 {0xff, 0x11, 0xff, 0x0d, 0x5c, 'Q', 0x00, 0x00, 0x00, 0x00,
246 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
247 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x40,
248 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x40});
249 v8::Local<v8::Value> result =
250 V8ScriptValueDeserializer(script_state, input).Deserialize();
251 ASSERT_TRUE(V8DOMPoint::hasInstance(result, scope.GetIsolate()));
252 DOMPoint* point = V8DOMPoint::toImpl(result.As<v8::Object>());
253 EXPECT_EQ(1, point->x());
254 EXPECT_EQ(2, point->y());
255 EXPECT_EQ(3, point->z());
256 EXPECT_EQ(4, point->w());
257 }
258
259 TEST(V8ScriptValueSerializerTest, RoundTripDOMPointReadOnly) {
260 // DOMPointReadOnly objects should serialize and deserialize correctly.
261 V8TestingScope scope;
262 DOMPointReadOnly* point = DOMPointReadOnly::Create(1, 2, 3, 4);
263 v8::Local<v8::Value> wrapper =
264 ToV8(point, scope.GetContext()->Global(), scope.GetIsolate());
265 v8::Local<v8::Value> result = RoundTrip(wrapper, scope);
266 ASSERT_TRUE(V8DOMPointReadOnly::hasInstance(result, scope.GetIsolate()));
267 EXPECT_FALSE(V8DOMPoint::hasInstance(result, scope.GetIsolate()));
268 DOMPointReadOnly* new_point =
269 V8DOMPointReadOnly::toImpl(result.As<v8::Object>());
270 EXPECT_NE(point, new_point);
271 EXPECT_EQ(point->x(), new_point->x());
272 EXPECT_EQ(point->y(), new_point->y());
273 EXPECT_EQ(point->z(), new_point->z());
274 EXPECT_EQ(point->w(), new_point->w());
275 }
276
277 TEST(V8ScriptValueSerializerTest, DecodeDOMPointReadOnly) {
278 V8TestingScope scope;
279 ScriptState* script_state = scope.GetScriptState();
280 RefPtr<SerializedScriptValue> input = SerializedValue(
281 {0xff, 0x11, 0xff, 0x0d, 0x5c, 'W', 0x00, 0x00, 0x00, 0x00,
282 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
283 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x40,
284 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x40});
285 v8::Local<v8::Value> result =
286 V8ScriptValueDeserializer(script_state, input).Deserialize();
287 ASSERT_TRUE(V8DOMPointReadOnly::hasInstance(result, scope.GetIsolate()));
288 DOMPointReadOnly* point = V8DOMPointReadOnly::toImpl(result.As<v8::Object>());
289 EXPECT_EQ(1, point->x());
290 EXPECT_EQ(2, point->y());
291 EXPECT_EQ(3, point->z());
292 EXPECT_EQ(4, point->w());
293 }
294
295 TEST(V8ScriptValueSerializerTest, RoundTripDOMRect) {
296 // DOMRect objects should serialize and deserialize correctly.
297 V8TestingScope scope;
298 DOMRect* rect = DOMRect::Create(1, 2, 3, 4);
299 v8::Local<v8::Value> wrapper =
300 ToV8(rect, scope.GetContext()->Global(), scope.GetIsolate());
301 v8::Local<v8::Value> result = RoundTrip(wrapper, scope);
302 ASSERT_TRUE(V8DOMRect::hasInstance(result, scope.GetIsolate()));
303 DOMRect* new_rect = V8DOMRect::toImpl(result.As<v8::Object>());
304 EXPECT_NE(rect, new_rect);
305 EXPECT_EQ(rect->x(), new_rect->x());
306 EXPECT_EQ(rect->y(), new_rect->y());
307 EXPECT_EQ(rect->width(), new_rect->width());
308 EXPECT_EQ(rect->height(), new_rect->height());
309 }
310
311 TEST(V8ScriptValueSerializerTest, DecodeDOMRect) {
312 V8TestingScope scope;
313 ScriptState* script_state = scope.GetScriptState();
314 RefPtr<SerializedScriptValue> input = SerializedValue(
315 {0xff, 0x11, 0xff, 0x0d, 0x5c, 'E', 0x00, 0x00, 0x00, 0x00,
316 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
317 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x40,
318 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x40});
319 v8::Local<v8::Value> result =
320 V8ScriptValueDeserializer(script_state, input).Deserialize();
321 ASSERT_TRUE(V8DOMRect::hasInstance(result, scope.GetIsolate()));
322 DOMRect* rect = V8DOMRect::toImpl(result.As<v8::Object>());
323 EXPECT_EQ(1, rect->x());
324 EXPECT_EQ(2, rect->y());
325 EXPECT_EQ(3, rect->width());
326 EXPECT_EQ(4, rect->height());
327 }
328
329 TEST(V8ScriptValueSerializerTest, RoundTripDOMRectReadOnly) {
330 // DOMRectReadOnly objects should serialize and deserialize correctly.
331 V8TestingScope scope;
332 DOMRectReadOnly* rect = DOMRectReadOnly::Create(1, 2, 3, 4);
333 v8::Local<v8::Value> wrapper =
334 ToV8(rect, scope.GetContext()->Global(), scope.GetIsolate());
335 v8::Local<v8::Value> result = RoundTrip(wrapper, scope);
336 ASSERT_TRUE(V8DOMRectReadOnly::hasInstance(result, scope.GetIsolate()));
337 EXPECT_FALSE(V8DOMRect::hasInstance(result, scope.GetIsolate()));
338 DOMRectReadOnly* new_rect =
339 V8DOMRectReadOnly::toImpl(result.As<v8::Object>());
340 EXPECT_NE(rect, new_rect);
341 EXPECT_EQ(rect->x(), new_rect->x());
342 EXPECT_EQ(rect->y(), new_rect->y());
343 EXPECT_EQ(rect->width(), new_rect->width());
344 EXPECT_EQ(rect->height(), new_rect->height());
345 }
346
347 TEST(V8ScriptValueSerializerTest, DecodeDOMRectReadOnly) {
348 V8TestingScope scope;
349 ScriptState* script_state = scope.GetScriptState();
350 RefPtr<SerializedScriptValue> input = SerializedValue(
351 {0xff, 0x11, 0xff, 0x0d, 0x5c, 'R', 0x00, 0x00, 0x00, 0x00,
352 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
353 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x40,
354 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x40});
355 v8::Local<v8::Value> result =
356 V8ScriptValueDeserializer(script_state, input).Deserialize();
357 ASSERT_TRUE(V8DOMRectReadOnly::hasInstance(result, scope.GetIsolate()));
358 DOMRectReadOnly* rect = V8DOMRectReadOnly::toImpl(result.As<v8::Object>());
359 EXPECT_EQ(1, rect->x());
360 EXPECT_EQ(2, rect->y());
361 EXPECT_EQ(3, rect->width());
362 EXPECT_EQ(4, rect->height());
363 }
364
365 TEST(V8ScriptValueSerializerTest, RoundTripDOMQuad) {
366 // DOMQuad objects should serialize and deserialize correctly.
367 V8TestingScope scope;
368 DOMPointInit pi1;
369 pi1.setX(1);
370 pi1.setY(5);
371 pi1.setZ(9);
372 pi1.setW(13);
373 DOMPointInit pi2;
374 pi2.setX(2);
375 pi2.setY(6);
376 pi2.setZ(10);
377 pi2.setW(14);
378 DOMPointInit pi3;
379 pi3.setX(3);
380 pi3.setY(7);
381 pi3.setZ(11);
382 pi3.setW(15);
383 DOMPointInit pi4;
384 pi4.setX(4);
385 pi4.setY(8);
386 pi4.setZ(12);
387 pi4.setW(16);
388 DOMQuad* quad = DOMQuad::Create(pi1, pi2, pi3, pi4);
389 v8::Local<v8::Value> wrapper =
390 ToV8(quad, scope.GetContext()->Global(), scope.GetIsolate());
391 v8::Local<v8::Value> result = RoundTrip(wrapper, scope);
392 ASSERT_TRUE(V8DOMQuad::hasInstance(result, scope.GetIsolate()));
393 DOMQuad* new_quad = V8DOMQuad::toImpl(result.As<v8::Object>());
394 EXPECT_NE(quad, new_quad);
395 EXPECT_NE(quad->p1(), new_quad->p1());
396 EXPECT_NE(quad->p2(), new_quad->p2());
397 EXPECT_NE(quad->p3(), new_quad->p3());
398 EXPECT_NE(quad->p4(), new_quad->p4());
399 EXPECT_EQ(quad->p1()->x(), new_quad->p1()->x());
400 EXPECT_EQ(quad->p1()->y(), new_quad->p1()->y());
401 EXPECT_EQ(quad->p1()->z(), new_quad->p1()->z());
402 EXPECT_EQ(quad->p1()->w(), new_quad->p1()->w());
403 EXPECT_EQ(quad->p2()->x(), new_quad->p2()->x());
404 EXPECT_EQ(quad->p2()->y(), new_quad->p2()->y());
405 EXPECT_EQ(quad->p2()->z(), new_quad->p2()->z());
406 EXPECT_EQ(quad->p2()->w(), new_quad->p2()->w());
407 EXPECT_EQ(quad->p3()->x(), new_quad->p3()->x());
408 EXPECT_EQ(quad->p3()->y(), new_quad->p3()->y());
409 EXPECT_EQ(quad->p3()->z(), new_quad->p3()->z());
410 EXPECT_EQ(quad->p3()->w(), new_quad->p3()->w());
411 EXPECT_EQ(quad->p4()->x(), new_quad->p4()->x());
412 EXPECT_EQ(quad->p4()->y(), new_quad->p4()->y());
413 EXPECT_EQ(quad->p4()->z(), new_quad->p4()->z());
414 EXPECT_EQ(quad->p4()->w(), new_quad->p4()->w());
415 }
416
417 TEST(V8ScriptValueSerializerTest, DecodeDOMQuad) {
418 V8TestingScope scope;
419 ScriptState* script_state = scope.GetScriptState();
420 RefPtr<SerializedScriptValue> input = SerializedValue(
421 {0xff, 0x11, 0xff, 0x0d, 0x5c, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
422 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x40, 0x00, 0x00,
423 0x00, 0x00, 0x00, 0x00, 0x22, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
424 0x2a, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00,
425 0x00, 0x00, 0x00, 0x00, 0x18, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
426 0x24, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x40, 0x00, 0x00,
427 0x00, 0x00, 0x00, 0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
428 0x1c, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x40, 0x00, 0x00,
429 0x00, 0x00, 0x00, 0x00, 0x2e, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
430 0x10, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x40, 0x00, 0x00,
431 0x00, 0x00, 0x00, 0x00, 0x28, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
432 0x30, 0x40});
433 v8::Local<v8::Value> result =
434 V8ScriptValueDeserializer(script_state, input).Deserialize();
435 ASSERT_TRUE(V8DOMQuad::hasInstance(result, scope.GetIsolate()));
436 DOMQuad* quad = V8DOMQuad::toImpl(result.As<v8::Object>());
437 EXPECT_EQ(1, quad->p1()->x());
438 EXPECT_EQ(5, quad->p1()->y());
439 EXPECT_EQ(9, quad->p1()->z());
440 EXPECT_EQ(13, quad->p1()->w());
441 EXPECT_EQ(2, quad->p2()->x());
442 EXPECT_EQ(6, quad->p2()->y());
443 EXPECT_EQ(10, quad->p2()->z());
444 EXPECT_EQ(14, quad->p2()->w());
445 EXPECT_EQ(3, quad->p3()->x());
446 EXPECT_EQ(7, quad->p3()->y());
447 EXPECT_EQ(11, quad->p3()->z());
448 EXPECT_EQ(15, quad->p3()->w());
449 EXPECT_EQ(4, quad->p4()->x());
450 EXPECT_EQ(8, quad->p4()->y());
451 EXPECT_EQ(12, quad->p4()->z());
452 EXPECT_EQ(16, quad->p4()->w());
453 }
454
455 TEST(V8ScriptValueSerializerTest, RoundTripDOMMatrix2D) {
456 // DOMMatrix objects should serialize and deserialize correctly.
457 V8TestingScope scope;
458 DOMMatrixInit init;
459 init.setIs2D(true);
460 init.setA(1.0);
461 init.setB(2.0);
462 init.setC(3.0);
463 init.setD(4.0);
464 init.setE(5.0);
465 init.setF(6.0);
466 DOMMatrix* matrix = DOMMatrix::fromMatrix(init, scope.GetExceptionState());
467 EXPECT_TRUE(matrix->is2D());
468 v8::Local<v8::Value> wrapper =
469 ToV8(matrix, scope.GetContext()->Global(), scope.GetIsolate());
470 v8::Local<v8::Value> result = RoundTrip(wrapper, scope);
471 ASSERT_TRUE(V8DOMMatrix::hasInstance(result, scope.GetIsolate()));
472 DOMMatrix* new_matrix = V8DOMMatrix::toImpl(result.As<v8::Object>());
473 EXPECT_NE(matrix, new_matrix);
474 EXPECT_TRUE(new_matrix->is2D());
475 EXPECT_EQ(matrix->a(), new_matrix->a());
476 EXPECT_EQ(matrix->b(), new_matrix->b());
477 EXPECT_EQ(matrix->c(), new_matrix->c());
478 EXPECT_EQ(matrix->d(), new_matrix->d());
479 EXPECT_EQ(matrix->e(), new_matrix->e());
480 EXPECT_EQ(matrix->f(), new_matrix->f());
481 }
482
483 TEST(V8ScriptValueSerializerTest, DecodeDOMMatrix2D) {
484 V8TestingScope scope;
485 ScriptState* script_state = scope.GetScriptState();
486 RefPtr<SerializedScriptValue> input = SerializedValue({
487 0xff, 0x11, 0xff, 0x0d, 0x5c, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
488 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00,
489 0x00, 0x00, 0x00, 0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
490 0x10, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x40, 0x00, 0x00,
491 0x00, 0x00, 0x00, 0x00, 0x18, 0x40, 0xff, 0x11, 0xff, 0x0d, 0x5c, 0x49,
492 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00,
493 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x40,
494 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x40, 0x00, 0x00, 0x00, 0x00,
495 0x00, 0x00, 0x14, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x40,
496 });
497 v8::Local<v8::Value> result =
498 V8ScriptValueDeserializer(script_state, input).Deserialize();
499 ASSERT_TRUE(V8DOMMatrix::hasInstance(result, scope.GetIsolate()));
500 DOMMatrix* matrix = V8DOMMatrix::toImpl(result.As<v8::Object>());
501 EXPECT_TRUE(matrix->is2D());
502 EXPECT_EQ(1.0, matrix->a());
503 EXPECT_EQ(2.0, matrix->b());
504 EXPECT_EQ(3.0, matrix->c());
505 EXPECT_EQ(4.0, matrix->d());
506 EXPECT_EQ(5.0, matrix->e());
507 EXPECT_EQ(6.0, matrix->f());
508 }
509
510 TEST(V8ScriptValueSerializerTest, RoundTripDOMMatrixReadOnly2D) {
511 // DOMMatrix objects should serialize and deserialize correctly.
512 V8TestingScope scope;
513 DOMMatrixInit init;
514 init.setIs2D(true);
515 init.setA(1.0);
516 init.setB(2.0);
517 init.setC(3.0);
518 init.setD(4.0);
519 init.setE(5.0);
520 init.setF(6.0);
521 DOMMatrixReadOnly* matrix =
522 DOMMatrixReadOnly::fromMatrix(init, scope.GetExceptionState());
523 EXPECT_TRUE(matrix->is2D());
524 v8::Local<v8::Value> wrapper =
525 ToV8(matrix, scope.GetContext()->Global(), scope.GetIsolate());
526 v8::Local<v8::Value> result = RoundTrip(wrapper, scope);
527 ASSERT_TRUE(V8DOMMatrixReadOnly::hasInstance(result, scope.GetIsolate()));
528 EXPECT_FALSE(V8DOMMatrix::hasInstance(result, scope.GetIsolate()));
529 DOMMatrixReadOnly* new_matrix =
530 V8DOMMatrixReadOnly::toImpl(result.As<v8::Object>());
531 EXPECT_NE(matrix, new_matrix);
532 EXPECT_TRUE(new_matrix->is2D());
533 EXPECT_EQ(matrix->a(), new_matrix->a());
534 EXPECT_EQ(matrix->b(), new_matrix->b());
535 EXPECT_EQ(matrix->c(), new_matrix->c());
536 EXPECT_EQ(matrix->d(), new_matrix->d());
537 EXPECT_EQ(matrix->e(), new_matrix->e());
538 EXPECT_EQ(matrix->f(), new_matrix->f());
539 }
540
541 TEST(V8ScriptValueSerializerTest, DecodeDOMMatrixReadOnly2D) {
542 V8TestingScope scope;
543 ScriptState* script_state = scope.GetScriptState();
544 RefPtr<SerializedScriptValue> input = SerializedValue({
545 0xff, 0x11, 0xff, 0x0d, 0x5c, 0x4f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
546 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00,
547 0x00, 0x00, 0x00, 0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
548 0x10, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x40, 0x00, 0x00,
549 0x00, 0x00, 0x00, 0x00, 0x18, 0x40, 0xff, 0x11, 0xff, 0x0d, 0x5c, 0x49,
550 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00,
551 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x40,
552 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x40, 0x00, 0x00, 0x00, 0x00,
553 0x00, 0x00, 0x14, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x40,
554 });
555 v8::Local<v8::Value> result =
556 V8ScriptValueDeserializer(script_state, input).Deserialize();
557 ASSERT_TRUE(V8DOMMatrixReadOnly::hasInstance(result, scope.GetIsolate()));
558 DOMMatrixReadOnly* matrix =
559 V8DOMMatrixReadOnly::toImpl(result.As<v8::Object>());
560 EXPECT_TRUE(matrix->is2D());
561 EXPECT_EQ(1.0, matrix->a());
562 EXPECT_EQ(2.0, matrix->b());
563 EXPECT_EQ(3.0, matrix->c());
564 EXPECT_EQ(4.0, matrix->d());
565 EXPECT_EQ(5.0, matrix->e());
566 EXPECT_EQ(6.0, matrix->f());
567 }
568
569 TEST(V8ScriptValueSerializerTest, RoundTripDOMMatrix) {
570 // DOMMatrix objects should serialize and deserialize correctly.
571 V8TestingScope scope;
572 DOMMatrixInit init;
573 init.setIs2D(false);
574 init.setM11(1.1);
575 init.setM12(1.2);
576 init.setM13(1.3);
577 init.setM14(1.4);
578 init.setM21(2.1);
579 init.setM22(2.2);
580 init.setM23(2.3);
581 init.setM24(2.4);
582 init.setM31(3.1);
583 init.setM32(3.2);
584 init.setM33(3.3);
585 init.setM34(3.4);
586 init.setM41(4.1);
587 init.setM42(4.2);
588 init.setM43(4.3);
589 init.setM44(4.4);
590 DOMMatrix* matrix = DOMMatrix::fromMatrix(init, scope.GetExceptionState());
591 EXPECT_FALSE(matrix->is2D());
592 v8::Local<v8::Value> wrapper =
593 ToV8(matrix, scope.GetContext()->Global(), scope.GetIsolate());
594 v8::Local<v8::Value> result = RoundTrip(wrapper, scope);
595 ASSERT_TRUE(V8DOMMatrix::hasInstance(result, scope.GetIsolate()));
596 DOMMatrix* new_matrix = V8DOMMatrix::toImpl(result.As<v8::Object>());
597 EXPECT_NE(matrix, new_matrix);
598 EXPECT_FALSE(new_matrix->is2D());
599 EXPECT_EQ(matrix->m11(), new_matrix->m11());
600 EXPECT_EQ(matrix->m12(), new_matrix->m12());
601 EXPECT_EQ(matrix->m13(), new_matrix->m13());
602 EXPECT_EQ(matrix->m14(), new_matrix->m14());
603 EXPECT_EQ(matrix->m21(), new_matrix->m21());
604 EXPECT_EQ(matrix->m22(), new_matrix->m22());
605 EXPECT_EQ(matrix->m23(), new_matrix->m23());
606 EXPECT_EQ(matrix->m24(), new_matrix->m24());
607 EXPECT_EQ(matrix->m31(), new_matrix->m31());
608 EXPECT_EQ(matrix->m32(), new_matrix->m32());
609 EXPECT_EQ(matrix->m33(), new_matrix->m33());
610 EXPECT_EQ(matrix->m34(), new_matrix->m34());
611 EXPECT_EQ(matrix->m41(), new_matrix->m41());
612 EXPECT_EQ(matrix->m42(), new_matrix->m42());
613 EXPECT_EQ(matrix->m43(), new_matrix->m43());
614 EXPECT_EQ(matrix->m44(), new_matrix->m44());
615 }
616
617 TEST(V8ScriptValueSerializerTest, DecodeDOMMatrix) {
618 V8TestingScope scope;
619 ScriptState* script_state = scope.GetScriptState();
620 RefPtr<SerializedScriptValue> input = SerializedValue({
621 0xff, 0x11, 0xff, 0x0d, 0x5c, 0x59, 0x9a, 0x99, 0x99, 0x99, 0x99, 0x99,
622 0xf1, 0x3f, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0xf3, 0x3f, 0xcd, 0xcc,
623 0xcc, 0xcc, 0xcc, 0xcc, 0xf4, 0x3f, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
624 0xf6, 0x3f, 0xcd, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x00, 0x40, 0x9a, 0x99,
625 0x99, 0x99, 0x99, 0x99, 0x01, 0x40, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
626 0x02, 0x40, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x03, 0x40, 0xcd, 0xcc,
627 0xcc, 0xcc, 0xcc, 0xcc, 0x08, 0x40, 0x9a, 0x99, 0x99, 0x99, 0x99, 0x99,
628 0x09, 0x40, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x0a, 0x40, 0x33, 0x33,
629 0x33, 0x33, 0x33, 0x33, 0x0b, 0x40, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
630 0x10, 0x40, 0xcd, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x10, 0x40, 0x33, 0x33,
631 0x33, 0x33, 0x33, 0x33, 0x11, 0x40, 0x9a, 0x99, 0x99, 0x99, 0x99, 0x99,
632 0x11, 0x40,
633 });
634 v8::Local<v8::Value> result =
635 V8ScriptValueDeserializer(script_state, input).Deserialize();
636 ASSERT_TRUE(V8DOMMatrix::hasInstance(result, scope.GetIsolate()));
637 DOMMatrix* matrix = V8DOMMatrix::toImpl(result.As<v8::Object>());
638 EXPECT_FALSE(matrix->is2D());
639 EXPECT_EQ(1.1, matrix->m11());
640 EXPECT_EQ(1.2, matrix->m12());
641 EXPECT_EQ(1.3, matrix->m13());
642 EXPECT_EQ(1.4, matrix->m14());
643 EXPECT_EQ(2.1, matrix->m21());
644 EXPECT_EQ(2.2, matrix->m22());
645 EXPECT_EQ(2.3, matrix->m23());
646 EXPECT_EQ(2.4, matrix->m24());
647 EXPECT_EQ(3.1, matrix->m31());
648 EXPECT_EQ(3.2, matrix->m32());
649 EXPECT_EQ(3.3, matrix->m33());
650 EXPECT_EQ(3.4, matrix->m34());
651 EXPECT_EQ(4.1, matrix->m41());
652 EXPECT_EQ(4.2, matrix->m42());
653 EXPECT_EQ(4.3, matrix->m43());
654 EXPECT_EQ(4.4, matrix->m44());
655 }
656
657 TEST(V8ScriptValueSerializerTest, RoundTripDOMMatrixReadOnly) {
658 // DOMMatrixReadOnly objects should serialize and deserialize correctly.
659 V8TestingScope scope;
660 DOMMatrixInit init;
661 init.setIs2D(false);
662 init.setM11(1.1);
663 init.setM12(1.2);
664 init.setM13(1.3);
665 init.setM14(1.4);
666 init.setM21(2.1);
667 init.setM22(2.2);
668 init.setM23(2.3);
669 init.setM24(2.4);
670 init.setM31(3.1);
671 init.setM32(3.2);
672 init.setM33(3.3);
673 init.setM34(3.4);
674 init.setM41(4.1);
675 init.setM42(4.2);
676 init.setM43(4.3);
677 init.setM44(4.4);
678 DOMMatrixReadOnly* matrix =
679 DOMMatrixReadOnly::fromMatrix(init, scope.GetExceptionState());
680 EXPECT_FALSE(matrix->is2D());
681 v8::Local<v8::Value> wrapper =
682 ToV8(matrix, scope.GetContext()->Global(), scope.GetIsolate());
683 v8::Local<v8::Value> result = RoundTrip(wrapper, scope);
684 ASSERT_TRUE(V8DOMMatrixReadOnly::hasInstance(result, scope.GetIsolate()));
685 EXPECT_FALSE(V8DOMMatrix::hasInstance(result, scope.GetIsolate()));
686 DOMMatrixReadOnly* new_matrix =
687 V8DOMMatrixReadOnly::toImpl(result.As<v8::Object>());
688 EXPECT_NE(matrix, new_matrix);
689 EXPECT_FALSE(new_matrix->is2D());
690 EXPECT_EQ(matrix->m11(), new_matrix->m11());
691 EXPECT_EQ(matrix->m12(), new_matrix->m12());
692 EXPECT_EQ(matrix->m13(), new_matrix->m13());
693 EXPECT_EQ(matrix->m14(), new_matrix->m14());
694 EXPECT_EQ(matrix->m21(), new_matrix->m21());
695 EXPECT_EQ(matrix->m22(), new_matrix->m22());
696 EXPECT_EQ(matrix->m23(), new_matrix->m23());
697 EXPECT_EQ(matrix->m24(), new_matrix->m24());
698 EXPECT_EQ(matrix->m31(), new_matrix->m31());
699 EXPECT_EQ(matrix->m32(), new_matrix->m32());
700 EXPECT_EQ(matrix->m33(), new_matrix->m33());
701 EXPECT_EQ(matrix->m34(), new_matrix->m34());
702 EXPECT_EQ(matrix->m41(), new_matrix->m41());
703 EXPECT_EQ(matrix->m42(), new_matrix->m42());
704 EXPECT_EQ(matrix->m43(), new_matrix->m43());
705 EXPECT_EQ(matrix->m44(), new_matrix->m44());
706 }
707
708 TEST(V8ScriptValueSerializerTest, DecodeDOMMatrixReadOnly) {
709 V8TestingScope scope;
710 ScriptState* script_state = scope.GetScriptState();
711 RefPtr<SerializedScriptValue> input = SerializedValue({
712 0xff, 0x11, 0xff, 0x0d, 0x5c, 0x55, 0x9a, 0x99, 0x99, 0x99, 0x99, 0x99,
713 0xf1, 0x3f, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0xf3, 0x3f, 0xcd, 0xcc,
714 0xcc, 0xcc, 0xcc, 0xcc, 0xf4, 0x3f, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
715 0xf6, 0x3f, 0xcd, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x00, 0x40, 0x9a, 0x99,
716 0x99, 0x99, 0x99, 0x99, 0x01, 0x40, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
717 0x02, 0x40, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x03, 0x40, 0xcd, 0xcc,
718 0xcc, 0xcc, 0xcc, 0xcc, 0x08, 0x40, 0x9a, 0x99, 0x99, 0x99, 0x99, 0x99,
719 0x09, 0x40, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x0a, 0x40, 0x33, 0x33,
720 0x33, 0x33, 0x33, 0x33, 0x0b, 0x40, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
721 0x10, 0x40, 0xcd, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x10, 0x40, 0x33, 0x33,
722 0x33, 0x33, 0x33, 0x33, 0x11, 0x40, 0x9a, 0x99, 0x99, 0x99, 0x99, 0x99,
723 0x11, 0x40,
724
725 });
726 v8::Local<v8::Value> result =
727 V8ScriptValueDeserializer(script_state, input).Deserialize();
728 ASSERT_TRUE(V8DOMMatrixReadOnly::hasInstance(result, scope.GetIsolate()));
729 DOMMatrixReadOnly* matrix =
730 V8DOMMatrixReadOnly::toImpl(result.As<v8::Object>());
731 EXPECT_FALSE(matrix->is2D());
732 EXPECT_EQ(1.1, matrix->m11());
733 EXPECT_EQ(1.2, matrix->m12());
734 EXPECT_EQ(1.3, matrix->m13());
735 EXPECT_EQ(1.4, matrix->m14());
736 EXPECT_EQ(2.1, matrix->m21());
737 EXPECT_EQ(2.2, matrix->m22());
738 EXPECT_EQ(2.3, matrix->m23());
739 EXPECT_EQ(2.4, matrix->m24());
740 EXPECT_EQ(3.1, matrix->m31());
741 EXPECT_EQ(3.2, matrix->m32());
742 EXPECT_EQ(3.3, matrix->m33());
743 EXPECT_EQ(3.4, matrix->m34());
744 EXPECT_EQ(4.1, matrix->m41());
745 EXPECT_EQ(4.2, matrix->m42());
746 EXPECT_EQ(4.3, matrix->m43());
747 EXPECT_EQ(4.4, matrix->m44());
748 }
749
211 TEST(V8ScriptValueSerializerTest, RoundTripImageData) { 750 TEST(V8ScriptValueSerializerTest, RoundTripImageData) {
212 // ImageData objects should serialize and deserialize correctly. 751 // ImageData objects should serialize and deserialize correctly.
213 V8TestingScope scope; 752 V8TestingScope scope;
214 ImageData* image_data = ImageData::Create(2, 1, ASSERT_NO_EXCEPTION); 753 ImageData* image_data = ImageData::Create(2, 1, ASSERT_NO_EXCEPTION);
215 image_data->data()->Data()[0] = 200; 754 image_data->data()->Data()[0] = 200;
216 v8::Local<v8::Value> wrapper = 755 v8::Local<v8::Value> wrapper =
217 ToV8(image_data, scope.GetContext()->Global(), scope.GetIsolate()); 756 ToV8(image_data, scope.GetContext()->Global(), scope.GetIsolate());
218 v8::Local<v8::Value> result = RoundTrip(wrapper, scope); 757 v8::Local<v8::Value> result = RoundTrip(wrapper, scope);
219 ASSERT_TRUE(V8ImageData::hasInstance(result, scope.GetIsolate())); 758 ASSERT_TRUE(V8ImageData::hasInstance(result, scope.GetIsolate()));
220 ImageData* new_image_data = V8ImageData::toImpl(result.As<v8::Object>()); 759 ImageData* new_image_data = V8ImageData::toImpl(result.As<v8::Object>());
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 RefPtr<SerializedScriptValue> input = 1640 RefPtr<SerializedScriptValue> input =
1102 SerializedValue({0xff, 0x80, 0x09, 0xff, 0x09, 0x54}); 1641 SerializedValue({0xff, 0x80, 0x09, 0xff, 0x09, 0x54});
1103 EXPECT_TRUE( 1642 EXPECT_TRUE(
1104 V8ScriptValueDeserializer(scope.GetScriptState(), std::move(input)) 1643 V8ScriptValueDeserializer(scope.GetScriptState(), std::move(input))
1105 .Deserialize() 1644 .Deserialize()
1106 ->IsTrue()); 1645 ->IsTrue());
1107 } 1646 }
1108 1647
1109 } // namespace 1648 } // namespace
1110 } // namespace blink 1649 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698