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

Side by Side Diff: third_party/WebKit/Source/bindings/modules/v8/serialization/V8ScriptValueSerializerForModulesTest.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/modules/v8/serialization/V8ScriptValueSerializerForModules.h" 5 #include "bindings/modules/v8/serialization/V8ScriptValueSerializerForModules.h"
6 6
7 #include "bindings/core/v8/ExceptionState.h" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "bindings/core/v8/ToV8.h" 8 #include "bindings/core/v8/ToV8.h"
9 #include "bindings/core/v8/V8ArrayBuffer.h" 9 #include "bindings/core/v8/V8ArrayBuffer.h"
10 #include "bindings/core/v8/V8BindingForTesting.h" 10 #include "bindings/core/v8/V8BindingForTesting.h"
(...skipping 27 matching lines...) Expand all
38 DCHECK_EQ(bytes.size() % 2, 0u); 38 DCHECK_EQ(bytes.size() % 2, 0u);
39 return SerializedScriptValue::create( 39 return SerializedScriptValue::create(
40 String(reinterpret_cast<const UChar*>(&bytes[0]), bytes.size() / 2)); 40 String(reinterpret_cast<const UChar*>(&bytes[0]), bytes.size() / 2));
41 } 41 }
42 42
43 v8::Local<v8::Value> roundTrip(v8::Local<v8::Value> value, 43 v8::Local<v8::Value> roundTrip(v8::Local<v8::Value> value,
44 V8TestingScope& scope) { 44 V8TestingScope& scope) {
45 RefPtr<ScriptState> scriptState = scope.getScriptState(); 45 RefPtr<ScriptState> scriptState = scope.getScriptState();
46 ExceptionState& exceptionState = scope.getExceptionState(); 46 ExceptionState& exceptionState = scope.getExceptionState();
47 RefPtr<SerializedScriptValue> serializedScriptValue = 47 RefPtr<SerializedScriptValue> serializedScriptValue =
48 V8ScriptValueSerializerForModules(scriptState) 48 V8ScriptValueSerializerForModules(
49 .serialize(value, nullptr, exceptionState); 49 scriptState, V8ScriptValueSerializerForModules::Options())
50 .serialize(value, exceptionState);
50 DCHECK_EQ(!serializedScriptValue, exceptionState.hadException()); 51 DCHECK_EQ(!serializedScriptValue, exceptionState.hadException());
51 EXPECT_TRUE(serializedScriptValue); 52 EXPECT_TRUE(serializedScriptValue);
52 if (!serializedScriptValue) 53 if (!serializedScriptValue)
53 return v8::Local<v8::Value>(); 54 return v8::Local<v8::Value>();
54 return V8ScriptValueDeserializerForModules(scriptState, serializedScriptValue) 55 return V8ScriptValueDeserializerForModules(scriptState, serializedScriptValue)
55 .deserialize(); 56 .deserialize();
56 } 57 }
57 58
58 // Checks for a DOM exception, including a rethrown one. 59 // Checks for a DOM exception, including a rethrown one.
59 ::testing::AssertionResult hadDOMException(const StringView& name, 60 ::testing::AssertionResult hadDOMException(const StringView& name,
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 ExceptionState::ExecutionContext, "Window", 885 ExceptionState::ExecutionContext, "Window",
885 "postMessage"); 886 "postMessage");
886 887
887 DOMFileSystem* fs = DOMFileSystem::create( 888 DOMFileSystem* fs = DOMFileSystem::create(
888 scope.getExecutionContext(), "http_example.com_0:Persistent", 889 scope.getExecutionContext(), "http_example.com_0:Persistent",
889 FileSystemTypePersistent, 890 FileSystemTypePersistent,
890 KURL(ParsedURLString, "filesystem:http://example.com/persistent/0/")); 891 KURL(ParsedURLString, "filesystem:http://example.com/persistent/0/"));
891 ASSERT_FALSE(fs->clonable()); 892 ASSERT_FALSE(fs->clonable());
892 v8::Local<v8::Value> wrapper = ToV8(fs, scope.getScriptState()); 893 v8::Local<v8::Value> wrapper = ToV8(fs, scope.getScriptState());
893 EXPECT_FALSE(V8ScriptValueSerializer(scope.getScriptState()) 894 EXPECT_FALSE(V8ScriptValueSerializer(scope.getScriptState())
894 .serialize(wrapper, nullptr, exceptionState)); 895 .serialize(wrapper, exceptionState));
895 EXPECT_TRUE(hadDOMException("DataCloneError", scope.getScriptState(), 896 EXPECT_TRUE(hadDOMException("DataCloneError", scope.getScriptState(),
896 exceptionState)); 897 exceptionState));
897 } 898 }
898 899
899 TEST(V8ScriptValueSerializerForModulesTest, DecodeDOMFileSystem) { 900 TEST(V8ScriptValueSerializerForModulesTest, DecodeDOMFileSystem) {
900 V8TestingScope scope; 901 V8TestingScope scope;
901 902
902 // This is encoded data generated from Chromium (around M56). 903 // This is encoded data generated from Chromium (around M56).
903 ScriptState* scriptState = scope.getScriptState(); 904 ScriptState* scriptState = scope.getScriptState();
904 RefPtr<SerializedScriptValue> input = serializedValue( 905 RefPtr<SerializedScriptValue> input = serializedValue(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x65, 0x72, 0x73, 0x69, 940 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x65, 0x72, 0x73, 0x69,
940 0x73, 0x74, 0x65, 0x6e, 0x74, 0x2f 941 0x73, 0x74, 0x65, 0x6e, 0x74, 0x2f
941 942
942 })) 943 }))
943 .deserialize() 944 .deserialize()
944 ->IsNull()); 945 ->IsNull());
945 } 946 }
946 947
947 } // namespace 948 } // namespace
948 } // namespace blink 949 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698