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

Side by Side Diff: third_party/WebKit/Source/bindings/modules/v8/serialization/V8ScriptValueSerializerForModulesTest.cpp

Issue 2297043002: Web expose FileSystemFileEntry, FileSystemDirectoryEntry and friends (Closed)
Patch Set: Rebased Created 4 years, 1 month 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/ExceptionStatePlaceholder.h" 7 #include "bindings/core/v8/ExceptionStatePlaceholder.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"
11 #include "bindings/core/v8/V8DOMException.h" 11 #include "bindings/core/v8/V8DOMException.h"
12 #include "bindings/modules/v8/V8CryptoKey.h" 12 #include "bindings/modules/v8/V8CryptoKey.h"
13 #include "bindings/modules/v8/V8DOMFileSystem.h" 13 #include "bindings/modules/v8/V8FileSystem.h"
14 #include "bindings/modules/v8/V8RTCCertificate.h" 14 #include "bindings/modules/v8/V8RTCCertificate.h"
15 #include "bindings/modules/v8/serialization/V8ScriptValueDeserializerForModules. h" 15 #include "bindings/modules/v8/serialization/V8ScriptValueDeserializerForModules. h"
16 #include "core/dom/DOMArrayBuffer.h" 16 #include "core/dom/DOMArrayBuffer.h"
17 #include "modules/crypto/CryptoResultImpl.h" 17 #include "modules/crypto/CryptoResultImpl.h"
18 #include "modules/filesystem/DOMFileSystem.h" 18 #include "modules/filesystem/FileSystem.h"
19 #include "modules/peerconnection/RTCCertificate.h" 19 #include "modules/peerconnection/RTCCertificate.h"
20 #include "platform/RuntimeEnabledFeatures.h" 20 #include "platform/RuntimeEnabledFeatures.h"
21 #include "platform/testing/UnitTestHelpers.h" 21 #include "platform/testing/UnitTestHelpers.h"
22 #include "public/platform/Platform.h" 22 #include "public/platform/Platform.h"
23 #include "public/platform/WebCryptoAlgorithmParams.h" 23 #include "public/platform/WebCryptoAlgorithmParams.h"
24 #include "public/platform/WebRTCCertificateGenerator.h" 24 #include "public/platform/WebRTCCertificateGenerator.h"
25 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
26 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
27 27
28 using ::testing::ElementsAre; 28 using ::testing::ElementsAre;
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 869
870 // Input ends before end of declared public exponent size. 870 // Input ends before end of declared public exponent size.
871 EXPECT_TRUE( 871 EXPECT_TRUE(
872 V8ScriptValueDeserializerForModules( 872 V8ScriptValueDeserializerForModules(
873 scriptState, serializedValue({0xff, 0x09, 0x3f, 0x00, 0x4b, 0x04, 873 scriptState, serializedValue({0xff, 0x09, 0x3f, 0x00, 0x4b, 0x04,
874 0x0d, 0x01, 0x80, 0x08, 0x03, 0x01})) 874 0x0d, 0x01, 0x80, 0x08, 0x03, 0x01}))
875 .deserialize() 875 .deserialize()
876 ->IsNull()); 876 ->IsNull());
877 } 877 }
878 878
879 TEST(V8ScriptValueSerializerForModulesTest, RoundTripDOMFileSystem) { 879 TEST(V8ScriptValueSerializerForModulesTest, RoundTripFileSystem) {
880 ScopedEnableV8BasedStructuredClone enable; 880 ScopedEnableV8BasedStructuredClone enable;
881 V8TestingScope scope; 881 V8TestingScope scope;
882 882
883 DOMFileSystem* fs = DOMFileSystem::create( 883 FileSystem* fs = FileSystem::create(
884 scope.getExecutionContext(), "http_example.com_0:Persistent", 884 scope.getExecutionContext(), "http_example.com_0:Persistent",
885 FileSystemTypePersistent, 885 FileSystemTypePersistent,
886 KURL(ParsedURLString, "filesystem:http://example.com/persistent/")); 886 KURL(ParsedURLString, "filesystem:http://example.com/persistent/"));
887 // At time of writing, this can only happen for filesystems from PPAPI. 887 // At time of writing, this can only happen for filesystems from PPAPI.
888 fs->makeClonable(); 888 fs->makeClonable();
889 v8::Local<v8::Value> wrapper = toV8(fs, scope.getScriptState()); 889 v8::Local<v8::Value> wrapper = toV8(fs, scope.getScriptState());
890 v8::Local<v8::Value> result = roundTrip(wrapper, scope); 890 v8::Local<v8::Value> result = roundTrip(wrapper, scope);
891 ASSERT_FALSE(result.IsEmpty()); 891 ASSERT_FALSE(result.IsEmpty());
892 ASSERT_TRUE(V8DOMFileSystem::hasInstance(result, scope.isolate())); 892 ASSERT_TRUE(V8FileSystem::hasInstance(result, scope.isolate()));
893 DOMFileSystem* newFS = V8DOMFileSystem::toImpl(result.As<v8::Object>()); 893 FileSystem* newFS = V8FileSystem::toImpl(result.As<v8::Object>());
894 EXPECT_EQ("http_example.com_0:Persistent", newFS->name()); 894 EXPECT_EQ("http_example.com_0:Persistent", newFS->name());
895 EXPECT_EQ(FileSystemTypePersistent, newFS->type()); 895 EXPECT_EQ(FileSystemTypePersistent, newFS->type());
896 EXPECT_EQ("filesystem:http://example.com/persistent/", 896 EXPECT_EQ("filesystem:http://example.com/persistent/",
897 newFS->rootURL().getString()); 897 newFS->rootURL().getString());
898 } 898 }
899 899
900 TEST(V8ScriptValueSerializerForModulesTest, RoundTripDOMFileSystemNotClonable) { 900 TEST(V8ScriptValueSerializerForModulesTest, RoundTripFileSystemNotClonable) {
901 ScopedEnableV8BasedStructuredClone enable; 901 ScopedEnableV8BasedStructuredClone enable;
902 V8TestingScope scope; 902 V8TestingScope scope;
903 ExceptionState exceptionState(scope.isolate(), 903 ExceptionState exceptionState(scope.isolate(),
904 ExceptionState::ExecutionContext, "Window", 904 ExceptionState::ExecutionContext, "Window",
905 "postMessage"); 905 "postMessage");
906 906
907 DOMFileSystem* fs = DOMFileSystem::create( 907 FileSystem* fs = FileSystem::create(
908 scope.getExecutionContext(), "http_example.com_0:Persistent", 908 scope.getExecutionContext(), "http_example.com_0:Persistent",
909 FileSystemTypePersistent, 909 FileSystemTypePersistent,
910 KURL(ParsedURLString, "filesystem:http://example.com/persistent/0/")); 910 KURL(ParsedURLString, "filesystem:http://example.com/persistent/0/"));
911 ASSERT_FALSE(fs->clonable()); 911 ASSERT_FALSE(fs->clonable());
912 v8::Local<v8::Value> wrapper = toV8(fs, scope.getScriptState()); 912 v8::Local<v8::Value> wrapper = toV8(fs, scope.getScriptState());
913 EXPECT_FALSE(V8ScriptValueSerializer(scope.getScriptState()) 913 EXPECT_FALSE(V8ScriptValueSerializer(scope.getScriptState())
914 .serialize(wrapper, nullptr, exceptionState)); 914 .serialize(wrapper, nullptr, exceptionState));
915 EXPECT_TRUE(hadDOMException("DataCloneError", scope.getScriptState(), 915 EXPECT_TRUE(hadDOMException("DataCloneError", scope.getScriptState(),
916 exceptionState)); 916 exceptionState));
917 } 917 }
918 918
919 TEST(V8ScriptValueSerializerForModulesTest, DecodeDOMFileSystem) { 919 TEST(V8ScriptValueSerializerForModulesTest, DecodeFileSystem) {
920 ScopedEnableV8BasedStructuredClone enable; 920 ScopedEnableV8BasedStructuredClone enable;
921 V8TestingScope scope; 921 V8TestingScope scope;
922 922
923 // This is encoded data generated from Chromium (around M56). 923 // This is encoded data generated from Chromium (around M56).
924 ScriptState* scriptState = scope.getScriptState(); 924 ScriptState* scriptState = scope.getScriptState();
925 RefPtr<SerializedScriptValue> input = serializedValue( 925 RefPtr<SerializedScriptValue> input = serializedValue(
926 {0xff, 0x09, 0x3f, 0x00, 0x64, 0x01, 0x1d, 0x68, 0x74, 0x74, 0x70, 0x5f, 926 {0xff, 0x09, 0x3f, 0x00, 0x64, 0x01, 0x1d, 0x68, 0x74, 0x74, 0x70, 0x5f,
927 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x5f, 927 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x5f,
928 0x30, 0x3a, 0x50, 0x65, 0x72, 0x73, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x74, 928 0x30, 0x3a, 0x50, 0x65, 0x72, 0x73, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x74,
929 0x29, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x3a, 929 0x29, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x3a,
930 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 930 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70,
931 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x65, 0x72, 0x73, 0x69, 931 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x65, 0x72, 0x73, 0x69,
932 0x73, 0x74, 0x65, 0x6e, 0x74, 0x2f}); 932 0x73, 0x74, 0x65, 0x6e, 0x74, 0x2f});
933 933
934 // Decode test. 934 // Decode test.
935 v8::Local<v8::Value> result = 935 v8::Local<v8::Value> result =
936 V8ScriptValueDeserializerForModules(scriptState, input).deserialize(); 936 V8ScriptValueDeserializerForModules(scriptState, input).deserialize();
937 ASSERT_TRUE(V8DOMFileSystem::hasInstance(result, scope.isolate())); 937 ASSERT_TRUE(V8FileSystem::hasInstance(result, scope.isolate()));
938 DOMFileSystem* newFS = V8DOMFileSystem::toImpl(result.As<v8::Object>()); 938 FileSystem* newFS = V8FileSystem::toImpl(result.As<v8::Object>());
939 EXPECT_EQ("http_example.com_0:Persistent", newFS->name()); 939 EXPECT_EQ("http_example.com_0:Persistent", newFS->name());
940 EXPECT_EQ(FileSystemTypePersistent, newFS->type()); 940 EXPECT_EQ(FileSystemTypePersistent, newFS->type());
941 EXPECT_EQ("filesystem:http://example.com/persistent/", 941 EXPECT_EQ("filesystem:http://example.com/persistent/",
942 newFS->rootURL().getString()); 942 newFS->rootURL().getString());
943 } 943 }
944 944
945 TEST(V8ScriptValueSerializerForModulesTest, DecodeInvalidDOMFileSystem) { 945 TEST(V8ScriptValueSerializerForModulesTest, DecodeInvalidFileSystem) {
946 ScopedEnableV8BasedStructuredClone enable; 946 ScopedEnableV8BasedStructuredClone enable;
947 V8TestingScope scope; 947 V8TestingScope scope;
948 ScriptState* scriptState = scope.getScriptState(); 948 ScriptState* scriptState = scope.getScriptState();
949 949
950 // Filesystem type out of range. 950 // Filesystem type out of range.
951 EXPECT_TRUE( 951 EXPECT_TRUE(
952 V8ScriptValueDeserializerForModules( 952 V8ScriptValueDeserializerForModules(
953 scriptState, 953 scriptState,
954 serializedValue({0xff, 0x09, 0x3f, 0x00, 0x64, 0x04, 0x1d, 0x68, 0x74, 954 serializedValue({0xff, 0x09, 0x3f, 0x00, 0x64, 0x04, 0x1d, 0x68, 0x74,
955 0x74, 0x70, 0x5f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 955 0x74, 0x70, 0x5f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c,
956 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x5f, 0x30, 0x3a, 0x50, 956 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x5f, 0x30, 0x3a, 0x50,
957 0x65, 0x72, 0x73, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x74, 957 0x65, 0x72, 0x73, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x74,
958 0x29, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x79, 0x73, 0x74, 958 0x29, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x79, 0x73, 0x74,
959 0x65, 0x6d, 0x3a, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 959 0x65, 0x6d, 0x3a, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f,
960 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 960 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e,
961 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x65, 0x72, 0x73, 0x69, 961 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x65, 0x72, 0x73, 0x69,
962 0x73, 0x74, 0x65, 0x6e, 0x74, 0x2f 962 0x73, 0x74, 0x65, 0x6e, 0x74, 0x2f
963 963
964 })) 964 }))
965 .deserialize() 965 .deserialize()
966 ->IsNull()); 966 ->IsNull());
967 } 967 }
968 968
969 } // namespace 969 } // namespace
970 } // namespace blink 970 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698