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

Unified 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, 7 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/bindings/core/v8/serialization/V8ScriptValueSerializerTest.cpp
diff --git a/third_party/WebKit/Source/bindings/core/v8/serialization/V8ScriptValueSerializerTest.cpp b/third_party/WebKit/Source/bindings/core/v8/serialization/V8ScriptValueSerializerTest.cpp
index 3d4eea2827565c6206174b81a9ea80c1f27abd5f..045943f7c96c2d6146176e381006a631222a3ef5 100644
--- a/third_party/WebKit/Source/bindings/core/v8/serialization/V8ScriptValueSerializerTest.cpp
+++ b/third_party/WebKit/Source/bindings/core/v8/serialization/V8ScriptValueSerializerTest.cpp
@@ -11,6 +11,14 @@
#include "bindings/core/v8/V8Blob.h"
#include "bindings/core/v8/V8CompositorProxy.h"
#include "bindings/core/v8/V8DOMException.h"
+#include "bindings/core/v8/V8DOMMatrix.h"
+#include "bindings/core/v8/V8DOMMatrixReadOnly.h"
+#include "bindings/core/v8/V8DOMPoint.h"
+#include "bindings/core/v8/V8DOMPointInit.h"
+#include "bindings/core/v8/V8DOMPointReadOnly.h"
+#include "bindings/core/v8/V8DOMQuad.h"
+#include "bindings/core/v8/V8DOMRect.h"
+#include "bindings/core/v8/V8DOMRectReadOnly.h"
#include "bindings/core/v8/V8File.h"
#include "bindings/core/v8/V8FileList.h"
#include "bindings/core/v8/V8ImageBitmap.h"
@@ -25,6 +33,13 @@
#include "core/fileapi/File.h"
#include "core/fileapi/FileList.h"
#include "core/frame/LocalFrame.h"
+#include "core/geometry/DOMMatrix.h"
+#include "core/geometry/DOMMatrixReadOnly.h"
+#include "core/geometry/DOMPoint.h"
+#include "core/geometry/DOMPointReadOnly.h"
+#include "core/geometry/DOMQuad.h"
+#include "core/geometry/DOMRect.h"
+#include "core/geometry/DOMRectReadOnly.h"
#include "core/html/ImageData.h"
#include "core/offscreencanvas/OffscreenCanvas.h"
#include "platform/RuntimeEnabledFeatures.h"
@@ -208,6 +223,279 @@ TEST(V8ScriptValueSerializerTest, NeuteringHappensAfterSerialization) {
EXPECT_FALSE(array_buffer->IsNeutered());
}
+TEST(V8ScriptValueSerializerTest, RoundTripDOMPoint) {
+ // DOMPoint objects should serialize and deserialize correctly.
+ V8TestingScope scope;
+ DOMPoint* point = DOMPoint::Create(1, 2, 3, 4);
+ v8::Local<v8::Value> wrapper =
+ ToV8(point, scope.GetContext()->Global(), scope.GetIsolate());
+ v8::Local<v8::Value> result = RoundTrip(wrapper, scope);
+ ASSERT_TRUE(V8DOMPoint::hasInstance(result, scope.GetIsolate()));
+ DOMPoint* new_point = V8DOMPoint::toImpl(result.As<v8::Object>());
+ EXPECT_NE(point, new_point);
+ EXPECT_EQ(point->x(), new_point->x());
+ EXPECT_EQ(point->y(), new_point->y());
+ EXPECT_EQ(point->z(), new_point->z());
+ EXPECT_EQ(point->w(), new_point->w());
+}
+
+TEST(V8ScriptValueSerializerTest, RoundTripDOMPointReadOnly) {
+ // DOMPointReadOnly objects should serialize and deserialize correctly.
+ V8TestingScope scope;
+ DOMPointReadOnly* point = DOMPointReadOnly::Create(1, 2, 3, 4);
+ v8::Local<v8::Value> wrapper =
+ ToV8(point, scope.GetContext()->Global(), scope.GetIsolate());
+ v8::Local<v8::Value> result = RoundTrip(wrapper, scope);
+ ASSERT_TRUE(V8DOMPointReadOnly::hasInstance(result, scope.GetIsolate()));
+ DOMPointReadOnly* new_point =
+ V8DOMPointReadOnly::toImpl(result.As<v8::Object>());
jbroman 2017/05/15 17:02:55 Suggest also checking that the result isn't a DOMP
fserb 2017/05/15 17:52:17 good catch. :)
+ EXPECT_NE(point, new_point);
+ EXPECT_EQ(point->x(), new_point->x());
+ EXPECT_EQ(point->y(), new_point->y());
+ EXPECT_EQ(point->z(), new_point->z());
+ EXPECT_EQ(point->w(), new_point->w());
+}
+
+TEST(V8ScriptValueSerializerTest, RoundTripDOMRect) {
+ // DOMRect objects should serialize and deserialize correctly.
+ V8TestingScope scope;
+ DOMRect* rect = DOMRect::Create(1, 2, 3, 4);
+ v8::Local<v8::Value> wrapper =
+ ToV8(rect, scope.GetContext()->Global(), scope.GetIsolate());
+ v8::Local<v8::Value> result = RoundTrip(wrapper, scope);
+ ASSERT_TRUE(V8DOMRect::hasInstance(result, scope.GetIsolate()));
+ DOMRect* new_rect = V8DOMRect::toImpl(result.As<v8::Object>());
+ EXPECT_NE(rect, new_rect);
+ EXPECT_EQ(rect->x(), new_rect->x());
+ EXPECT_EQ(rect->y(), new_rect->y());
+ EXPECT_EQ(rect->width(), new_rect->width());
+ EXPECT_EQ(rect->height(), new_rect->height());
+}
+
+TEST(V8ScriptValueSerializerTest, RoundTripDOMRectReadOnly) {
+ // DOMRectReadOnly objects should serialize and deserialize correctly.
+ V8TestingScope scope;
+ DOMRectReadOnly* rect = DOMRectReadOnly::Create(1, 2, 3, 4);
+ v8::Local<v8::Value> wrapper =
+ ToV8(rect, scope.GetContext()->Global(), scope.GetIsolate());
+ v8::Local<v8::Value> result = RoundTrip(wrapper, scope);
+ ASSERT_TRUE(V8DOMRectReadOnly::hasInstance(result, scope.GetIsolate()));
+ DOMRectReadOnly* new_rect = V8DOMRect::toImpl(result.As<v8::Object>());
+ EXPECT_NE(rect, new_rect);
+ EXPECT_EQ(rect->x(), new_rect->x());
+ EXPECT_EQ(rect->y(), new_rect->y());
+ EXPECT_EQ(rect->width(), new_rect->width());
+ EXPECT_EQ(rect->height(), new_rect->height());
+}
+
+TEST(V8ScriptValueSerializerTest, RoundTripDOMQuad) {
+ // DOMQuad objects should serialize and deserialize correctly.
+ V8TestingScope scope;
+ DOMPointInit pi1;
+ pi1.setX(1);
+ pi1.setY(5);
+ pi1.setZ(9);
+ pi1.setW(13);
+ DOMPointInit pi2;
+ pi2.setX(2);
+ pi2.setY(6);
+ pi2.setZ(10);
+ pi2.setW(14);
+ DOMPointInit pi3;
+ pi3.setX(3);
+ pi3.setY(7);
+ pi3.setZ(11);
+ pi3.setW(15);
+ DOMPointInit pi4;
+ pi4.setX(4);
+ pi4.setY(8);
+ pi4.setZ(12);
+ pi4.setW(16);
+ DOMQuad* quad = DOMQuad::Create(pi1, pi2, pi3, pi4);
+ v8::Local<v8::Value> wrapper =
+ ToV8(quad, scope.GetContext()->Global(), scope.GetIsolate());
+ v8::Local<v8::Value> result = RoundTrip(wrapper, scope);
+ ASSERT_TRUE(V8DOMQuad::hasInstance(result, scope.GetIsolate()));
+ DOMQuad* new_quad = V8DOMQuad::toImpl(result.As<v8::Object>());
+ EXPECT_NE(quad, new_quad);
+ EXPECT_NE(quad->p1(), new_quad->p1());
+ EXPECT_NE(quad->p2(), new_quad->p2());
+ EXPECT_NE(quad->p3(), new_quad->p3());
+ EXPECT_NE(quad->p4(), new_quad->p4());
+ EXPECT_EQ(quad->p1()->x(), new_quad->p1()->x());
+ EXPECT_EQ(quad->p1()->y(), new_quad->p1()->y());
+ EXPECT_EQ(quad->p1()->z(), new_quad->p1()->z());
+ EXPECT_EQ(quad->p1()->w(), new_quad->p1()->w());
+ EXPECT_EQ(quad->p2()->x(), new_quad->p2()->x());
+ EXPECT_EQ(quad->p2()->y(), new_quad->p2()->y());
+ EXPECT_EQ(quad->p2()->z(), new_quad->p2()->z());
+ EXPECT_EQ(quad->p2()->w(), new_quad->p2()->w());
+ EXPECT_EQ(quad->p3()->x(), new_quad->p3()->x());
+ EXPECT_EQ(quad->p3()->y(), new_quad->p3()->y());
+ EXPECT_EQ(quad->p3()->z(), new_quad->p3()->z());
+ EXPECT_EQ(quad->p3()->w(), new_quad->p3()->w());
+ EXPECT_EQ(quad->p4()->x(), new_quad->p4()->x());
+ EXPECT_EQ(quad->p4()->y(), new_quad->p4()->y());
+ EXPECT_EQ(quad->p4()->z(), new_quad->p4()->z());
+ EXPECT_EQ(quad->p4()->w(), new_quad->p4()->w());
+}
+
+TEST(V8ScriptValueSerializerTest, RoundTripDOMMatrix2D) {
+ // DOMMatrix objects should serialize and deserialize correctly.
+ V8TestingScope scope;
+ DOMMatrixInit init;
+ init.setIs2D(true);
+ init.setA(1.0);
+ init.setB(2.0);
+ init.setC(3.0);
+ init.setD(4.0);
+ init.setE(5.0);
+ init.setF(6.0);
+ DOMMatrix* matrix = DOMMatrix::fromMatrix(init, scope.GetExceptionState());
+ EXPECT_TRUE(matrix->is2D());
+ v8::Local<v8::Value> wrapper =
+ ToV8(matrix, scope.GetContext()->Global(), scope.GetIsolate());
+ v8::Local<v8::Value> result = RoundTrip(wrapper, scope);
+ ASSERT_TRUE(V8DOMMatrix::hasInstance(result, scope.GetIsolate()));
+ DOMMatrix* new_matrix = V8DOMMatrix::toImpl(result.As<v8::Object>());
+ EXPECT_NE(matrix, new_matrix);
+ EXPECT_TRUE(new_matrix->is2D());
+ EXPECT_EQ(matrix->a(), new_matrix->a());
+ EXPECT_EQ(matrix->b(), new_matrix->b());
+ EXPECT_EQ(matrix->c(), new_matrix->c());
+ EXPECT_EQ(matrix->d(), new_matrix->d());
+ EXPECT_EQ(matrix->e(), new_matrix->e());
+ EXPECT_EQ(matrix->f(), new_matrix->f());
+}
+
+TEST(V8ScriptValueSerializerTest, RoundTripDOMMatrixReadOnly2D) {
+ // DOMMatrix objects should serialize and deserialize correctly.
+ V8TestingScope scope;
+ DOMMatrixInit init;
+ init.setIs2D(true);
+ init.setA(1.0);
+ init.setB(2.0);
+ init.setC(3.0);
+ init.setD(4.0);
+ init.setE(5.0);
+ init.setF(6.0);
+ DOMMatrixReadOnly* matrix =
+ DOMMatrixReadOnly::fromMatrix(init, scope.GetExceptionState());
+ EXPECT_TRUE(matrix->is2D());
+ v8::Local<v8::Value> wrapper =
+ ToV8(matrix, scope.GetContext()->Global(), scope.GetIsolate());
+ v8::Local<v8::Value> result = RoundTrip(wrapper, scope);
+ ASSERT_TRUE(V8DOMMatrixReadOnly::hasInstance(result, scope.GetIsolate()));
+ DOMMatrixReadOnly* new_matrix =
+ V8DOMMatrixReadOnly::toImpl(result.As<v8::Object>());
+ EXPECT_NE(matrix, new_matrix);
+ EXPECT_TRUE(new_matrix->is2D());
+ EXPECT_EQ(matrix->a(), new_matrix->a());
+ EXPECT_EQ(matrix->b(), new_matrix->b());
+ EXPECT_EQ(matrix->c(), new_matrix->c());
+ EXPECT_EQ(matrix->d(), new_matrix->d());
+ EXPECT_EQ(matrix->e(), new_matrix->e());
+ EXPECT_EQ(matrix->f(), new_matrix->f());
+}
+
+TEST(V8ScriptValueSerializerTest, RoundTripDOMMatrix) {
+ // DOMMatrix objects should serialize and deserialize correctly.
+ V8TestingScope scope;
+ DOMMatrixInit init;
+ init.setIs2D(false);
+ init.setM11(1.1);
+ init.setM12(1.2);
+ init.setM13(1.3);
+ init.setM14(1.4);
+ init.setM21(2.1);
+ init.setM22(2.2);
+ init.setM23(2.3);
+ init.setM24(2.4);
+ init.setM31(3.1);
+ init.setM32(3.2);
+ init.setM33(3.3);
+ init.setM34(3.4);
+ init.setM41(4.1);
+ init.setM42(4.2);
+ init.setM43(4.3);
+ init.setM44(4.4);
+ DOMMatrix* matrix = DOMMatrix::fromMatrix(init, scope.GetExceptionState());
+ EXPECT_FALSE(matrix->is2D());
+ v8::Local<v8::Value> wrapper =
+ ToV8(matrix, scope.GetContext()->Global(), scope.GetIsolate());
+ v8::Local<v8::Value> result = RoundTrip(wrapper, scope);
+ ASSERT_TRUE(V8DOMMatrix::hasInstance(result, scope.GetIsolate()));
+ DOMMatrix* new_matrix = V8DOMMatrix::toImpl(result.As<v8::Object>());
+ EXPECT_NE(matrix, new_matrix);
+ EXPECT_FALSE(new_matrix->is2D());
+ EXPECT_EQ(matrix->m11(), new_matrix->m11());
+ EXPECT_EQ(matrix->m12(), new_matrix->m12());
+ EXPECT_EQ(matrix->m13(), new_matrix->m13());
+ EXPECT_EQ(matrix->m14(), new_matrix->m14());
+ EXPECT_EQ(matrix->m21(), new_matrix->m21());
+ EXPECT_EQ(matrix->m22(), new_matrix->m22());
+ EXPECT_EQ(matrix->m23(), new_matrix->m23());
+ EXPECT_EQ(matrix->m24(), new_matrix->m24());
+ EXPECT_EQ(matrix->m31(), new_matrix->m31());
+ EXPECT_EQ(matrix->m32(), new_matrix->m32());
+ EXPECT_EQ(matrix->m33(), new_matrix->m33());
+ EXPECT_EQ(matrix->m34(), new_matrix->m34());
+ EXPECT_EQ(matrix->m41(), new_matrix->m41());
+ EXPECT_EQ(matrix->m42(), new_matrix->m42());
+ EXPECT_EQ(matrix->m43(), new_matrix->m43());
+ EXPECT_EQ(matrix->m44(), new_matrix->m44());
+}
+
+TEST(V8ScriptValueSerializerTest, RoundTripDOMMatrixReadOnly) {
+ // DOMMatrixReadOnly objects should serialize and deserialize correctly.
+ V8TestingScope scope;
+ DOMMatrixInit init;
+ init.setIs2D(false);
+ init.setM11(1.1);
+ init.setM12(1.2);
+ init.setM13(1.3);
+ init.setM14(1.4);
+ init.setM21(2.1);
+ init.setM22(2.2);
+ init.setM23(2.3);
+ init.setM24(2.4);
+ init.setM31(3.1);
+ init.setM32(3.2);
+ init.setM33(3.3);
+ init.setM34(3.4);
+ init.setM41(4.1);
+ init.setM42(4.2);
+ init.setM43(4.3);
+ init.setM44(4.4);
+ DOMMatrixReadOnly* matrix =
+ DOMMatrixReadOnly::fromMatrix(init, scope.GetExceptionState());
+ EXPECT_FALSE(matrix->is2D());
+ v8::Local<v8::Value> wrapper =
+ ToV8(matrix, scope.GetContext()->Global(), scope.GetIsolate());
+ v8::Local<v8::Value> result = RoundTrip(wrapper, scope);
+ ASSERT_TRUE(V8DOMMatrixReadOnly::hasInstance(result, scope.GetIsolate()));
+ DOMMatrixReadOnly* new_matrix =
+ V8DOMMatrixReadOnly::toImpl(result.As<v8::Object>());
+ EXPECT_NE(matrix, new_matrix);
+ EXPECT_FALSE(new_matrix->is2D());
+ EXPECT_EQ(matrix->m11(), new_matrix->m11());
+ EXPECT_EQ(matrix->m12(), new_matrix->m12());
+ EXPECT_EQ(matrix->m13(), new_matrix->m13());
+ EXPECT_EQ(matrix->m14(), new_matrix->m14());
+ EXPECT_EQ(matrix->m21(), new_matrix->m21());
+ EXPECT_EQ(matrix->m22(), new_matrix->m22());
+ EXPECT_EQ(matrix->m23(), new_matrix->m23());
+ EXPECT_EQ(matrix->m24(), new_matrix->m24());
+ EXPECT_EQ(matrix->m31(), new_matrix->m31());
+ EXPECT_EQ(matrix->m32(), new_matrix->m32());
+ EXPECT_EQ(matrix->m33(), new_matrix->m33());
+ EXPECT_EQ(matrix->m34(), new_matrix->m34());
+ EXPECT_EQ(matrix->m41(), new_matrix->m41());
+ EXPECT_EQ(matrix->m42(), new_matrix->m42());
+ EXPECT_EQ(matrix->m43(), new_matrix->m43());
+ EXPECT_EQ(matrix->m44(), new_matrix->m44());
+}
+
jbroman 2017/05/15 17:02:55 Please also add decode tests to ensure that if we
TEST(V8ScriptValueSerializerTest, RoundTripImageData) {
// ImageData objects should serialize and deserialize correctly.
V8TestingScope scope;
@@ -529,6 +817,23 @@ TEST(V8ScriptValueSerializerTest, TransferOffscreenCanvas) {
EXPECT_FALSE(new_canvas->IsNeutered());
}
+// TEST(V8ScriptValueSerializerTest, TransferDOMPoint) {
jbroman 2017/05/15 17:02:55 Delete this?
+// V8TestingScope scope;
+// DOMPoint* point = DOMPoint::Create(1, 2, 3, 4);
+// v8::Local<v8::Value> wrapper = ToV8(point, scope.GetScriptState());
+// Transferables transferables;
+// transferables.offscreen_canvases.push_back(canvas);
+// v8::Local<v8::Value> result =
+// RoundTrip(wrapper, scope, nullptr, &transferables);
+// ASSERT_TRUE(V8OffscreenCanvas::hasInstance(result, scope.GetIsolate()));
+// OffscreenCanvas* new_canvas =
+// V8OffscreenCanvas::toImpl(result.As<v8::Object>());
+// EXPECT_EQ(IntSize(10, 7), new_canvas->Size());
+// EXPECT_EQ(519u, new_canvas->PlaceholderCanvasId());
+// EXPECT_TRUE(canvas->IsNeutered());
+// EXPECT_FALSE(new_canvas->IsNeutered());
+// }
+
TEST(V8ScriptValueSerializerTest, RoundTripBlob) {
V8TestingScope scope;
const char kHelloWorld[] = "Hello world!";

Powered by Google App Engine
This is Rietveld 408576698