| Index: third_party/WebKit/Source/bindings/core/v8/SerializedScriptValueTest.cpp
|
| diff --git a/third_party/WebKit/Source/bindings/core/v8/SerializedScriptValueTest.cpp b/third_party/WebKit/Source/bindings/core/v8/SerializedScriptValueTest.cpp
|
| index 0e8a41fe5b36ac08325ed81463832feb28b231e2..9ac40fc1ced1fac7e2d207230b7ddeff1c88dbf3 100644
|
| --- a/third_party/WebKit/Source/bindings/core/v8/SerializedScriptValueTest.cpp
|
| +++ b/third_party/WebKit/Source/bindings/core/v8/SerializedScriptValueTest.cpp
|
| @@ -9,12 +9,122 @@
|
| #include "bindings/core/v8/V8Binding.h"
|
| #include "bindings/core/v8/V8BindingForTesting.h"
|
| #include "bindings/core/v8/V8File.h"
|
| +#include "bindings/core/v8/V8ImageData.h"
|
| #include "core/fileapi/File.h"
|
| #include "platform/testing/UnitTestHelpers.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| namespace blink {
|
|
|
| +TEST(SerializedScriptValueTest, WireFormatRoundTrip) {
|
| + V8TestingScope scope;
|
| +
|
| + v8::Local<v8::Value> v8OriginalTrue = v8::Boolean::New(scope.isolate(), true);
|
| + RefPtr<SerializedScriptValue> sourceSerializedScriptValue =
|
| + SerializedScriptValue::serialize(
|
| + scope.isolate(), v8OriginalTrue,
|
| + SerializedScriptValue::SerializeOptions(), ASSERT_NO_EXCEPTION);
|
| +
|
| + Vector<char> wireData;
|
| + sourceSerializedScriptValue->toWireBytes(wireData);
|
| +
|
| + RefPtr<SerializedScriptValue> serializedScriptValue =
|
| + SerializedScriptValue::create(wireData.data(), wireData.size());
|
| + v8::Local<v8::Value> deserialized =
|
| + serializedScriptValue->deserialize(scope.isolate());
|
| + EXPECT_TRUE(deserialized->IsTrue());
|
| +}
|
| +
|
| +TEST(SerializedScriptValueTest, WireFormatVersion17NoByteFlipping) {
|
| + V8TestingScope scope;
|
| +
|
| + const uint8_t data[] = {0xFF, 0x11, 0xFF, 0x0D, 0x54, 0x00};
|
| + RefPtr<SerializedScriptValue> serializedScriptValue =
|
| + SerializedScriptValue::create(reinterpret_cast<const char*>(data), 6);
|
| + v8::Local<v8::Value> deserialized =
|
| + serializedScriptValue->deserialize(scope.isolate());
|
| + EXPECT_TRUE(deserialized->IsTrue());
|
| +}
|
| +
|
| +TEST(SerializedScriptValueTest, WireFormatVersion16ByteFlipping) {
|
| + V8TestingScope scope;
|
| +
|
| + // Using UChar instead of uint8_t to get ntohs() byte flipping.
|
| + const UChar data[] = {0xFF10, 0xFF0D, 0x5400};
|
| + RefPtr<SerializedScriptValue> serializedScriptValue =
|
| + SerializedScriptValue::create(reinterpret_cast<const char*>(data), 6);
|
| + v8::Local<v8::Value> deserialized =
|
| + serializedScriptValue->deserialize(scope.isolate());
|
| + EXPECT_TRUE(deserialized->IsTrue());
|
| +}
|
| +
|
| +TEST(SerializedScriptValueTest, WireFormatVersion13ByteFlipping) {
|
| + V8TestingScope scope;
|
| +
|
| + // Using UChar instead of uint8_t to get ntohs() byte flipping.
|
| + const UChar data[] = {0xFF0D, 0x5400};
|
| + RefPtr<SerializedScriptValue> serializedScriptValue =
|
| + SerializedScriptValue::create(reinterpret_cast<const char*>(data), 4);
|
| + v8::Local<v8::Value> deserialized =
|
| + serializedScriptValue->deserialize(scope.isolate());
|
| + EXPECT_TRUE(deserialized->IsTrue());
|
| +}
|
| +
|
| +TEST(SerializedScriptValueTest, WireFormatVersion0ByteFlipping) {
|
| + V8TestingScope scope;
|
| +
|
| + // Using UChar instead of uint8_t to get ntohs() byte flipping.
|
| + const UChar data[] = {0x5400};
|
| + RefPtr<SerializedScriptValue> serializedScriptValue =
|
| + SerializedScriptValue::create(reinterpret_cast<const char*>(data), 2);
|
| + v8::Local<v8::Value> deserialized =
|
| + serializedScriptValue->deserialize(scope.isolate());
|
| + EXPECT_TRUE(deserialized->IsTrue());
|
| +}
|
| +
|
| +TEST(SerializedScriptValueTest, WireFormatVersion0ImageData) {
|
| + V8TestingScope scope;
|
| + v8::Isolate* isolate = scope.isolate();
|
| +
|
| + // Using UChar instead of uint8_t to get ntohs() byte flipping.
|
| + //
|
| + // This builds the smallest possible ImageData whose first data byte is 0xFF,
|
| + // as follows.
|
| + //
|
| + // width = 127, encoded as 0xFF 0x00 (degenerate varint)
|
| + // height = 1, encoded as 0x01 (varint)
|
| + // pixelLength = 508 (127 * 1 * 4), encoded as 0xFC 0x03 (varint)
|
| + // pixel data = 508 bytes, all zero
|
| + Vector<UChar> data;
|
| + data.push_back(0x23FF);
|
| + data.push_back(0x001);
|
| + data.push_back(0xFC03);
|
| + data.resize(257); // (508 pixel data + 6 header bytes) / 2
|
| +
|
| + // Using UChar instead of uint8_t to get ntohs() byte flipping.
|
| + RefPtr<SerializedScriptValue> serializedScriptValue =
|
| + SerializedScriptValue::create(reinterpret_cast<const char*>(data.data()),
|
| + 514);
|
| + v8::Local<v8::Value> deserialized =
|
| + serializedScriptValue->deserialize(isolate);
|
| + ASSERT_TRUE(deserialized->IsObject());
|
| + v8::Local<v8::Object> deserializedObject = deserialized.As<v8::Object>();
|
| + ASSERT_TRUE(V8ImageData::hasInstance(deserializedObject, isolate));
|
| + ImageData* imageData = V8ImageData::toImpl(deserializedObject);
|
| + EXPECT_EQ(imageData->width(), 127);
|
| + EXPECT_EQ(imageData->height(), 1);
|
| +}
|
| +
|
| +TEST(SerializedScriptValueTest, NullValue) {
|
| + V8TestingScope scope;
|
| +
|
| + RefPtr<SerializedScriptValue> serializedScriptValue =
|
| + SerializedScriptValue::nullValue();
|
| + v8::Local<v8::Value> deserialized =
|
| + serializedScriptValue->deserialize(scope.isolate());
|
| + EXPECT_TRUE(deserialized->IsNull());
|
| +}
|
| +
|
| TEST(SerializedScriptValueTest, UserSelectedFile) {
|
| V8TestingScope scope;
|
| String filePath = testing::blinkRootDir();
|
|
|