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

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

Issue 2755383004: Encapsulate optional SerializedScriptValue serialize/deserialize parameters. (Closed)
Patch Set: fuzzer Created 3 years, 9 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"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 // Extract message ports and disentangle them. 65 // Extract message ports and disentangle them.
66 MessagePortChannelArray channels; 66 MessagePortChannelArray channels;
67 if (transferables) { 67 if (transferables) {
68 channels = MessagePort::disentanglePorts(scope.getExecutionContext(), 68 channels = MessagePort::disentanglePorts(scope.getExecutionContext(),
69 transferables->messagePorts, 69 transferables->messagePorts,
70 exceptionState); 70 exceptionState);
71 if (exceptionState.hadException()) 71 if (exceptionState.hadException())
72 return v8::Local<v8::Value>(); 72 return v8::Local<v8::Value>();
73 } 73 }
74 74
75 V8ScriptValueSerializer serializer(scriptState); 75 V8ScriptValueSerializer::Options serializeOptions;
76 serializer.setBlobInfoArray(blobInfo); 76 serializeOptions.transferables = transferables;
77 serializeOptions.blobInfo = blobInfo;
78 V8ScriptValueSerializer serializer(scriptState, serializeOptions);
77 RefPtr<SerializedScriptValue> serializedScriptValue = 79 RefPtr<SerializedScriptValue> serializedScriptValue =
78 serializer.serialize(value, transferables, exceptionState); 80 serializer.serialize(value, exceptionState);
79 DCHECK_EQ(!serializedScriptValue, exceptionState.hadException()); 81 DCHECK_EQ(!serializedScriptValue, exceptionState.hadException());
80 if (!serializedScriptValue) 82 if (!serializedScriptValue)
81 return v8::Local<v8::Value>(); 83 return v8::Local<v8::Value>();
82 84
83 // If there are message ports, make new ones and entangle them. 85 // If there are message ports, make new ones and entangle them.
84 MessagePortArray* transferredMessagePorts = MessagePort::entanglePorts( 86 MessagePortArray* transferredMessagePorts = MessagePort::entanglePorts(
85 *scope.getExecutionContext(), std::move(channels)); 87 *scope.getExecutionContext(), std::move(channels));
86 88
87 V8ScriptValueDeserializer deserializer(scriptState, serializedScriptValue); 89 V8ScriptValueDeserializer::Options deserializeOptions;
88 deserializer.setTransferredMessagePorts(transferredMessagePorts); 90 deserializeOptions.messagePorts = transferredMessagePorts;
89 deserializer.setBlobInfoArray(blobInfo); 91 deserializeOptions.blobInfo = blobInfo;
92 V8ScriptValueDeserializer deserializer(scriptState, serializedScriptValue,
93 deserializeOptions);
90 return deserializer.deserialize(); 94 return deserializer.deserialize();
91 } 95 }
92 96
93 v8::Local<v8::Value> eval(const String& source, V8TestingScope& scope) { 97 v8::Local<v8::Value> eval(const String& source, V8TestingScope& scope) {
94 return scope.frame().script().executeScriptInMainWorldAndReturnValue(source); 98 return scope.frame().script().executeScriptInMainWorldAndReturnValue(source);
95 } 99 }
96 100
97 String toJSON(v8::Local<v8::Object> object, const V8TestingScope& scope) { 101 String toJSON(v8::Local<v8::Object> object, const V8TestingScope& scope) {
98 return v8StringToWebCoreString<String>( 102 return v8StringToWebCoreString<String>(
99 v8::JSON::Stringify(scope.context(), object).ToLocalChecked(), 103 v8::JSON::Stringify(scope.context(), object).ToLocalChecked(),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 // are encountered in V8 (for example, cloning a symbol). It should be an 138 // are encountered in V8 (for example, cloning a symbol). It should be an
135 // instance of DOMException, and it should have a proper descriptive 139 // instance of DOMException, and it should have a proper descriptive
136 // message. 140 // message.
137 V8TestingScope scope; 141 V8TestingScope scope;
138 ScriptState* scriptState = scope.getScriptState(); 142 ScriptState* scriptState = scope.getScriptState();
139 ExceptionState exceptionState(scope.isolate(), 143 ExceptionState exceptionState(scope.isolate(),
140 ExceptionState::ExecutionContext, "Window", 144 ExceptionState::ExecutionContext, "Window",
141 "postMessage"); 145 "postMessage");
142 v8::Local<v8::Value> symbol = eval("Symbol()", scope); 146 v8::Local<v8::Value> symbol = eval("Symbol()", scope);
143 DCHECK(symbol->IsSymbol()); 147 DCHECK(symbol->IsSymbol());
144 ASSERT_FALSE(V8ScriptValueSerializer(scriptState) 148 ASSERT_FALSE(
145 .serialize(symbol, nullptr, exceptionState)); 149 V8ScriptValueSerializer(scriptState).serialize(symbol, exceptionState));
146 ASSERT_TRUE(hadDOMException("DataCloneError", scriptState, exceptionState)); 150 ASSERT_TRUE(hadDOMException("DataCloneError", scriptState, exceptionState));
147 DOMException* domException = 151 DOMException* domException =
148 V8DOMException::toImpl(exceptionState.getException().As<v8::Object>()); 152 V8DOMException::toImpl(exceptionState.getException().As<v8::Object>());
149 EXPECT_TRUE(domException->toString().contains("postMessage")); 153 EXPECT_TRUE(domException->toString().contains("postMessage"));
150 } 154 }
151 155
152 TEST(V8ScriptValueSerializerTest, RethrowsScriptError) { 156 TEST(V8ScriptValueSerializerTest, RethrowsScriptError) {
153 // Ensure that other exceptions, like those thrown by script, are properly 157 // Ensure that other exceptions, like those thrown by script, are properly
154 // rethrown. 158 // rethrown.
155 V8TestingScope scope; 159 V8TestingScope scope;
156 ScriptState* scriptState = scope.getScriptState(); 160 ScriptState* scriptState = scope.getScriptState();
157 ExceptionState exceptionState(scope.isolate(), 161 ExceptionState exceptionState(scope.isolate(),
158 ExceptionState::ExecutionContext, "Window", 162 ExceptionState::ExecutionContext, "Window",
159 "postMessage"); 163 "postMessage");
160 v8::Local<v8::Value> exception = eval("myException=new Error()", scope); 164 v8::Local<v8::Value> exception = eval("myException=new Error()", scope);
161 v8::Local<v8::Value> object = 165 v8::Local<v8::Value> object =
162 eval("({ get a() { throw myException; }})", scope); 166 eval("({ get a() { throw myException; }})", scope);
163 DCHECK(object->IsObject()); 167 DCHECK(object->IsObject());
164 ASSERT_FALSE(V8ScriptValueSerializer(scriptState) 168 ASSERT_FALSE(
165 .serialize(object, nullptr, exceptionState)); 169 V8ScriptValueSerializer(scriptState).serialize(object, exceptionState));
166 ASSERT_TRUE(exceptionState.hadException()); 170 ASSERT_TRUE(exceptionState.hadException());
167 EXPECT_EQ(exception, exceptionState.getException()); 171 EXPECT_EQ(exception, exceptionState.getException());
168 } 172 }
169 173
170 TEST(V8ScriptValueSerializerTest, DeserializationErrorReturnsNull) { 174 TEST(V8ScriptValueSerializerTest, DeserializationErrorReturnsNull) {
171 // If there's a problem during deserialization, it results in null, but no 175 // If there's a problem during deserialization, it results in null, but no
172 // exception. 176 // exception.
173 V8TestingScope scope; 177 V8TestingScope scope;
174 ScriptState* scriptState = scope.getScriptState(); 178 ScriptState* scriptState = scope.getScriptState();
175 RefPtr<SerializedScriptValue> invalid = 179 RefPtr<SerializedScriptValue> invalid =
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 ScriptState* scriptState = scope.getScriptState(); 336 ScriptState* scriptState = scope.getScriptState();
333 RefPtr<SerializedScriptValue> input = 337 RefPtr<SerializedScriptValue> input =
334 serializedValue({0xff, 0x09, 0x3f, 0x00, 0x4d, 0x01}); 338 serializedValue({0xff, 0x09, 0x3f, 0x00, 0x4d, 0x01});
335 MessagePort* port1 = makeMessagePort(scope.getExecutionContext()); 339 MessagePort* port1 = makeMessagePort(scope.getExecutionContext());
336 MessagePort* port2 = makeMessagePort(scope.getExecutionContext()); 340 MessagePort* port2 = makeMessagePort(scope.getExecutionContext());
337 { 341 {
338 V8ScriptValueDeserializer deserializer(scriptState, input); 342 V8ScriptValueDeserializer deserializer(scriptState, input);
339 ASSERT_TRUE(deserializer.deserialize()->IsNull()); 343 ASSERT_TRUE(deserializer.deserialize()->IsNull());
340 } 344 }
341 { 345 {
342 V8ScriptValueDeserializer deserializer(scriptState, input); 346 V8ScriptValueDeserializer::Options options;
343 deserializer.setTransferredMessagePorts(new MessagePortArray); 347 options.messagePorts = new MessagePortArray;
348 V8ScriptValueDeserializer deserializer(scriptState, input, options);
344 ASSERT_TRUE(deserializer.deserialize()->IsNull()); 349 ASSERT_TRUE(deserializer.deserialize()->IsNull());
345 } 350 }
346 { 351 {
347 MessagePortArray* ports = new MessagePortArray; 352 V8ScriptValueDeserializer::Options options;
348 ports->push_back(port1); 353 options.messagePorts = new MessagePortArray;
349 V8ScriptValueDeserializer deserializer(scriptState, input); 354 options.messagePorts->push_back(port1);
350 deserializer.setTransferredMessagePorts(ports); 355 V8ScriptValueDeserializer deserializer(scriptState, input, options);
351 ASSERT_TRUE(deserializer.deserialize()->IsNull()); 356 ASSERT_TRUE(deserializer.deserialize()->IsNull());
352 } 357 }
353 { 358 {
354 MessagePortArray* ports = new MessagePortArray; 359 V8ScriptValueDeserializer::Options options;
355 ports->push_back(port1); 360 options.messagePorts = new MessagePortArray;
356 ports->push_back(port2); 361 options.messagePorts->push_back(port1);
357 V8ScriptValueDeserializer deserializer(scriptState, input); 362 options.messagePorts->push_back(port2);
358 deserializer.setTransferredMessagePorts(ports); 363 V8ScriptValueDeserializer deserializer(scriptState, input, options);
359 v8::Local<v8::Value> result = deserializer.deserialize(); 364 v8::Local<v8::Value> result = deserializer.deserialize();
360 ASSERT_TRUE(V8MessagePort::hasInstance(result, scope.isolate())); 365 ASSERT_TRUE(V8MessagePort::hasInstance(result, scope.isolate()));
361 EXPECT_EQ(port2, V8MessagePort::toImpl(result.As<v8::Object>())); 366 EXPECT_EQ(port2, V8MessagePort::toImpl(result.As<v8::Object>()));
362 } 367 }
363 } 368 }
364 369
365 // Decode tests for backward compatibility are not required for message ports 370 // Decode tests for backward compatibility are not required for message ports
366 // because they cannot be persisted to disk. 371 // because they cannot be persisted to disk.
367 372
368 // A more exhaustive set of ImageBitmap cases are covered by LayoutTests. 373 // A more exhaustive set of ImageBitmap cases are covered by LayoutTests.
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 EXPECT_EQ(sizeof(kHelloWorld), static_cast<size_t>(info.size())); 583 EXPECT_EQ(sizeof(kHelloWorld), static_cast<size_t>(info.size()));
579 } 584 }
580 585
581 TEST(V8ScriptValueSerializerTest, DecodeBlobIndex) { 586 TEST(V8ScriptValueSerializerTest, DecodeBlobIndex) {
582 V8TestingScope scope; 587 V8TestingScope scope;
583 RefPtr<SerializedScriptValue> input = 588 RefPtr<SerializedScriptValue> input =
584 serializedValue({0xff, 0x09, 0x3f, 0x00, 0x69, 0x00}); 589 serializedValue({0xff, 0x09, 0x3f, 0x00, 0x69, 0x00});
585 WebBlobInfoArray blobInfoArray; 590 WebBlobInfoArray blobInfoArray;
586 blobInfoArray.emplace_back("d875dfc2-4505-461b-98fe-0cf6cc5eaf44", 591 blobInfoArray.emplace_back("d875dfc2-4505-461b-98fe-0cf6cc5eaf44",
587 "text/plain", 12); 592 "text/plain", 12);
588 V8ScriptValueDeserializer deserializer(scope.getScriptState(), input); 593 V8ScriptValueDeserializer::Options options;
589 deserializer.setBlobInfoArray(&blobInfoArray); 594 options.blobInfo = &blobInfoArray;
595 V8ScriptValueDeserializer deserializer(scope.getScriptState(), input,
596 options);
590 v8::Local<v8::Value> result = deserializer.deserialize(); 597 v8::Local<v8::Value> result = deserializer.deserialize();
591 ASSERT_TRUE(V8Blob::hasInstance(result, scope.isolate())); 598 ASSERT_TRUE(V8Blob::hasInstance(result, scope.isolate()));
592 Blob* newBlob = V8Blob::toImpl(result.As<v8::Object>()); 599 Blob* newBlob = V8Blob::toImpl(result.As<v8::Object>());
593 EXPECT_EQ("d875dfc2-4505-461b-98fe-0cf6cc5eaf44", newBlob->uuid()); 600 EXPECT_EQ("d875dfc2-4505-461b-98fe-0cf6cc5eaf44", newBlob->uuid());
594 EXPECT_EQ("text/plain", newBlob->type()); 601 EXPECT_EQ("text/plain", newBlob->type());
595 EXPECT_EQ(12u, newBlob->size()); 602 EXPECT_EQ(12u, newBlob->size());
596 } 603 }
597 604
598 TEST(V8ScriptValueSerializerTest, DecodeBlobIndexOutOfRange) { 605 TEST(V8ScriptValueSerializerTest, DecodeBlobIndexOutOfRange) {
599 V8TestingScope scope; 606 V8TestingScope scope;
600 RefPtr<SerializedScriptValue> input = 607 RefPtr<SerializedScriptValue> input =
601 serializedValue({0xff, 0x09, 0x3f, 0x00, 0x69, 0x01}); 608 serializedValue({0xff, 0x09, 0x3f, 0x00, 0x69, 0x01});
602 { 609 {
603 V8ScriptValueDeserializer deserializer(scope.getScriptState(), input); 610 V8ScriptValueDeserializer deserializer(scope.getScriptState(), input);
604 ASSERT_TRUE(deserializer.deserialize()->IsNull()); 611 ASSERT_TRUE(deserializer.deserialize()->IsNull());
605 } 612 }
606 { 613 {
607 WebBlobInfoArray blobInfoArray; 614 WebBlobInfoArray blobInfoArray;
608 blobInfoArray.emplace_back("d875dfc2-4505-461b-98fe-0cf6cc5eaf44", 615 blobInfoArray.emplace_back("d875dfc2-4505-461b-98fe-0cf6cc5eaf44",
609 "text/plain", 12); 616 "text/plain", 12);
610 V8ScriptValueDeserializer deserializer(scope.getScriptState(), input); 617 V8ScriptValueDeserializer::Options options;
611 deserializer.setBlobInfoArray(&blobInfoArray); 618 options.blobInfo = &blobInfoArray;
619 V8ScriptValueDeserializer deserializer(scope.getScriptState(), input,
620 options);
612 ASSERT_TRUE(deserializer.deserialize()->IsNull()); 621 ASSERT_TRUE(deserializer.deserialize()->IsNull());
613 } 622 }
614 } 623 }
615 624
616 TEST(V8ScriptValueSerializerTest, RoundTripFileNative) { 625 TEST(V8ScriptValueSerializerTest, RoundTripFileNative) {
617 V8TestingScope scope; 626 V8TestingScope scope;
618 File* file = File::create("/native/path"); 627 File* file = File::create("/native/path");
619 v8::Local<v8::Value> wrapper = ToV8(file, scope.getScriptState()); 628 v8::Local<v8::Value> wrapper = ToV8(file, scope.getScriptState());
620 v8::Local<v8::Value> result = roundTrip(wrapper, scope); 629 v8::Local<v8::Value> result = roundTrip(wrapper, scope);
621 ASSERT_TRUE(V8File::hasInstance(result, scope.isolate())); 630 ASSERT_TRUE(V8File::hasInstance(result, scope.isolate()));
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 EXPECT_EQ(file->uuid(), String(info.uuid())); 842 EXPECT_EQ(file->uuid(), String(info.uuid()));
834 } 843 }
835 844
836 TEST(V8ScriptValueSerializerTest, DecodeFileIndex) { 845 TEST(V8ScriptValueSerializerTest, DecodeFileIndex) {
837 V8TestingScope scope; 846 V8TestingScope scope;
838 RefPtr<SerializedScriptValue> input = 847 RefPtr<SerializedScriptValue> input =
839 serializedValue({0xff, 0x09, 0x3f, 0x00, 0x65, 0x00}); 848 serializedValue({0xff, 0x09, 0x3f, 0x00, 0x65, 0x00});
840 WebBlobInfoArray blobInfoArray; 849 WebBlobInfoArray blobInfoArray;
841 blobInfoArray.emplace_back("d875dfc2-4505-461b-98fe-0cf6cc5eaf44", 850 blobInfoArray.emplace_back("d875dfc2-4505-461b-98fe-0cf6cc5eaf44",
842 "/native/path", "path", "text/plain"); 851 "/native/path", "path", "text/plain");
843 V8ScriptValueDeserializer deserializer(scope.getScriptState(), input); 852 V8ScriptValueDeserializer::Options options;
844 deserializer.setBlobInfoArray(&blobInfoArray); 853 options.blobInfo = &blobInfoArray;
854 V8ScriptValueDeserializer deserializer(scope.getScriptState(), input,
855 options);
845 v8::Local<v8::Value> result = deserializer.deserialize(); 856 v8::Local<v8::Value> result = deserializer.deserialize();
846 ASSERT_TRUE(V8File::hasInstance(result, scope.isolate())); 857 ASSERT_TRUE(V8File::hasInstance(result, scope.isolate()));
847 File* newFile = V8File::toImpl(result.As<v8::Object>()); 858 File* newFile = V8File::toImpl(result.As<v8::Object>());
848 EXPECT_EQ("d875dfc2-4505-461b-98fe-0cf6cc5eaf44", newFile->uuid()); 859 EXPECT_EQ("d875dfc2-4505-461b-98fe-0cf6cc5eaf44", newFile->uuid());
849 EXPECT_EQ("text/plain", newFile->type()); 860 EXPECT_EQ("text/plain", newFile->type());
850 EXPECT_EQ("/native/path", newFile->path()); 861 EXPECT_EQ("/native/path", newFile->path());
851 EXPECT_EQ("path", newFile->name()); 862 EXPECT_EQ("path", newFile->name());
852 } 863 }
853 864
854 TEST(V8ScriptValueSerializerTest, DecodeFileIndexOutOfRange) { 865 TEST(V8ScriptValueSerializerTest, DecodeFileIndexOutOfRange) {
855 V8TestingScope scope; 866 V8TestingScope scope;
856 RefPtr<SerializedScriptValue> input = 867 RefPtr<SerializedScriptValue> input =
857 serializedValue({0xff, 0x09, 0x3f, 0x00, 0x65, 0x01}); 868 serializedValue({0xff, 0x09, 0x3f, 0x00, 0x65, 0x01});
858 { 869 {
859 V8ScriptValueDeserializer deserializer(scope.getScriptState(), input); 870 V8ScriptValueDeserializer deserializer(scope.getScriptState(), input);
860 ASSERT_TRUE(deserializer.deserialize()->IsNull()); 871 ASSERT_TRUE(deserializer.deserialize()->IsNull());
861 } 872 }
862 { 873 {
863 WebBlobInfoArray blobInfoArray; 874 WebBlobInfoArray blobInfoArray;
864 blobInfoArray.emplace_back("d875dfc2-4505-461b-98fe-0cf6cc5eaf44", 875 blobInfoArray.emplace_back("d875dfc2-4505-461b-98fe-0cf6cc5eaf44",
865 "/native/path", "path", "text/plain"); 876 "/native/path", "path", "text/plain");
866 V8ScriptValueDeserializer deserializer(scope.getScriptState(), input); 877 V8ScriptValueDeserializer::Options options;
867 deserializer.setBlobInfoArray(&blobInfoArray); 878 options.blobInfo = &blobInfoArray;
879 V8ScriptValueDeserializer deserializer(scope.getScriptState(), input,
880 options);
868 ASSERT_TRUE(deserializer.deserialize()->IsNull()); 881 ASSERT_TRUE(deserializer.deserialize()->IsNull());
869 } 882 }
870 } 883 }
871 884
872 // Most of the logic for FileList is shared with File, so the tests here are 885 // Most of the logic for FileList is shared with File, so the tests here are
873 // fairly basic. 886 // fairly basic.
874 887
875 TEST(V8ScriptValueSerializerTest, RoundTripFileList) { 888 TEST(V8ScriptValueSerializerTest, RoundTripFileList) {
876 V8TestingScope scope; 889 V8TestingScope scope;
877 FileList* fileList = FileList::create(); 890 FileList* fileList = FileList::create();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 EXPECT_EQ("/native/path", blobInfoArray[0].filePath()); 969 EXPECT_EQ("/native/path", blobInfoArray[0].filePath());
957 EXPECT_TRUE(blobInfoArray[1].isFile()); 970 EXPECT_TRUE(blobInfoArray[1].isFile());
958 EXPECT_EQ("/native/path2", blobInfoArray[1].filePath()); 971 EXPECT_EQ("/native/path2", blobInfoArray[1].filePath());
959 } 972 }
960 973
961 TEST(V8ScriptValueSerializerTest, DecodeEmptyFileListIndex) { 974 TEST(V8ScriptValueSerializerTest, DecodeEmptyFileListIndex) {
962 V8TestingScope scope; 975 V8TestingScope scope;
963 RefPtr<SerializedScriptValue> input = 976 RefPtr<SerializedScriptValue> input =
964 serializedValue({0xff, 0x09, 0x3f, 0x00, 0x4c, 0x00}); 977 serializedValue({0xff, 0x09, 0x3f, 0x00, 0x4c, 0x00});
965 WebBlobInfoArray blobInfoArray; 978 WebBlobInfoArray blobInfoArray;
966 V8ScriptValueDeserializer deserializer(scope.getScriptState(), input); 979 V8ScriptValueDeserializer::Options options;
967 deserializer.setBlobInfoArray(&blobInfoArray); 980 options.blobInfo = &blobInfoArray;
981 V8ScriptValueDeserializer deserializer(scope.getScriptState(), input,
982 options);
968 v8::Local<v8::Value> result = deserializer.deserialize(); 983 v8::Local<v8::Value> result = deserializer.deserialize();
969 ASSERT_TRUE(V8FileList::hasInstance(result, scope.isolate())); 984 ASSERT_TRUE(V8FileList::hasInstance(result, scope.isolate()));
970 FileList* newFileList = V8FileList::toImpl(result.As<v8::Object>()); 985 FileList* newFileList = V8FileList::toImpl(result.As<v8::Object>());
971 EXPECT_EQ(0u, newFileList->length()); 986 EXPECT_EQ(0u, newFileList->length());
972 } 987 }
973 988
974 TEST(V8ScriptValueSerializerTest, DecodeFileListIndexWithInvalidLength) { 989 TEST(V8ScriptValueSerializerTest, DecodeFileListIndexWithInvalidLength) {
975 V8TestingScope scope; 990 V8TestingScope scope;
976 RefPtr<SerializedScriptValue> input = 991 RefPtr<SerializedScriptValue> input =
977 serializedValue({0xff, 0x09, 0x3f, 0x00, 0x4c, 0x02}); 992 serializedValue({0xff, 0x09, 0x3f, 0x00, 0x4c, 0x02});
978 WebBlobInfoArray blobInfoArray; 993 WebBlobInfoArray blobInfoArray;
979 V8ScriptValueDeserializer deserializer(scope.getScriptState(), input); 994 V8ScriptValueDeserializer::Options options;
980 deserializer.setBlobInfoArray(&blobInfoArray); 995 options.blobInfo = &blobInfoArray;
996 V8ScriptValueDeserializer deserializer(scope.getScriptState(), input,
997 options);
981 v8::Local<v8::Value> result = deserializer.deserialize(); 998 v8::Local<v8::Value> result = deserializer.deserialize();
982 EXPECT_TRUE(result->IsNull()); 999 EXPECT_TRUE(result->IsNull());
983 } 1000 }
984 1001
985 TEST(V8ScriptValueSerializerTest, DecodeFileListIndex) { 1002 TEST(V8ScriptValueSerializerTest, DecodeFileListIndex) {
986 V8TestingScope scope; 1003 V8TestingScope scope;
987 RefPtr<SerializedScriptValue> input = 1004 RefPtr<SerializedScriptValue> input =
988 serializedValue({0xff, 0x09, 0x3f, 0x00, 0x4c, 0x01, 0x00, 0x00}); 1005 serializedValue({0xff, 0x09, 0x3f, 0x00, 0x4c, 0x01, 0x00, 0x00});
989 WebBlobInfoArray blobInfoArray; 1006 WebBlobInfoArray blobInfoArray;
990 blobInfoArray.emplace_back("d875dfc2-4505-461b-98fe-0cf6cc5eaf44", 1007 blobInfoArray.emplace_back("d875dfc2-4505-461b-98fe-0cf6cc5eaf44",
991 "/native/path", "name", "text/plain"); 1008 "/native/path", "name", "text/plain");
992 V8ScriptValueDeserializer deserializer(scope.getScriptState(), input); 1009 V8ScriptValueDeserializer::Options options;
993 deserializer.setBlobInfoArray(&blobInfoArray); 1010 options.blobInfo = &blobInfoArray;
1011 V8ScriptValueDeserializer deserializer(scope.getScriptState(), input,
1012 options);
994 v8::Local<v8::Value> result = deserializer.deserialize(); 1013 v8::Local<v8::Value> result = deserializer.deserialize();
995 FileList* newFileList = V8FileList::toImpl(result.As<v8::Object>()); 1014 FileList* newFileList = V8FileList::toImpl(result.As<v8::Object>());
996 EXPECT_EQ(1u, newFileList->length()); 1015 EXPECT_EQ(1u, newFileList->length());
997 File* newFile = newFileList->item(0); 1016 File* newFile = newFileList->item(0);
998 EXPECT_EQ("/native/path", newFile->path()); 1017 EXPECT_EQ("/native/path", newFile->path());
999 EXPECT_EQ("name", newFile->name()); 1018 EXPECT_EQ("name", newFile->name());
1000 EXPECT_EQ("d875dfc2-4505-461b-98fe-0cf6cc5eaf44", newFile->uuid()); 1019 EXPECT_EQ("d875dfc2-4505-461b-98fe-0cf6cc5eaf44", newFile->uuid());
1001 EXPECT_EQ("text/plain", newFile->type()); 1020 EXPECT_EQ("text/plain", newFile->type());
1002 } 1021 }
1003 1022
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 RefPtr<SerializedScriptValue> input = 1090 RefPtr<SerializedScriptValue> input =
1072 serializedValue({0xff, 0x80, 0x09, 0xff, 0x09, 0x54}); 1091 serializedValue({0xff, 0x80, 0x09, 0xff, 0x09, 0x54});
1073 EXPECT_TRUE( 1092 EXPECT_TRUE(
1074 V8ScriptValueDeserializer(scope.getScriptState(), std::move(input)) 1093 V8ScriptValueDeserializer(scope.getScriptState(), std::move(input))
1075 .deserialize() 1094 .deserialize()
1076 ->IsTrue()); 1095 ->IsTrue());
1077 } 1096 }
1078 1097
1079 } // namespace 1098 } // namespace
1080 } // namespace blink 1099 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698