OLD | NEW |
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/V8RTCCertificate.h" | 14 #include "bindings/modules/v8/V8RTCCertificate.h" |
14 #include "bindings/modules/v8/serialization/V8ScriptValueDeserializerForModules.
h" | 15 #include "bindings/modules/v8/serialization/V8ScriptValueDeserializerForModules.
h" |
15 #include "core/dom/DOMArrayBuffer.h" | 16 #include "core/dom/DOMArrayBuffer.h" |
16 #include "modules/crypto/CryptoResultImpl.h" | 17 #include "modules/crypto/CryptoResultImpl.h" |
| 18 #include "modules/filesystem/DOMFileSystem.h" |
17 #include "modules/peerconnection/RTCCertificate.h" | 19 #include "modules/peerconnection/RTCCertificate.h" |
18 #include "platform/RuntimeEnabledFeatures.h" | 20 #include "platform/RuntimeEnabledFeatures.h" |
19 #include "platform/testing/UnitTestHelpers.h" | 21 #include "platform/testing/UnitTestHelpers.h" |
20 #include "public/platform/Platform.h" | 22 #include "public/platform/Platform.h" |
21 #include "public/platform/WebCryptoAlgorithmParams.h" | 23 #include "public/platform/WebCryptoAlgorithmParams.h" |
22 #include "public/platform/WebRTCCertificateGenerator.h" | 24 #include "public/platform/WebRTCCertificateGenerator.h" |
23 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
25 | 27 |
26 using ::testing::ElementsAre; | 28 using ::testing::ElementsAre; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 V8ScriptValueSerializerForModules(scriptState) | 62 V8ScriptValueSerializerForModules(scriptState) |
61 .serialize(value, nullptr, exceptionState); | 63 .serialize(value, nullptr, exceptionState); |
62 DCHECK_EQ(!serializedScriptValue, exceptionState.hadException()); | 64 DCHECK_EQ(!serializedScriptValue, exceptionState.hadException()); |
63 EXPECT_TRUE(serializedScriptValue); | 65 EXPECT_TRUE(serializedScriptValue); |
64 if (!serializedScriptValue) | 66 if (!serializedScriptValue) |
65 return v8::Local<v8::Value>(); | 67 return v8::Local<v8::Value>(); |
66 return V8ScriptValueDeserializerForModules(scriptState, serializedScriptValue) | 68 return V8ScriptValueDeserializerForModules(scriptState, serializedScriptValue) |
67 .deserialize(); | 69 .deserialize(); |
68 } | 70 } |
69 | 71 |
| 72 // Checks for a DOM exception, including a rethrown one. |
| 73 ::testing::AssertionResult hadDOMException(const StringView& name, |
| 74 ScriptState* scriptState, |
| 75 ExceptionState& exceptionState) { |
| 76 if (!exceptionState.hadException()) |
| 77 return ::testing::AssertionFailure() << "no exception thrown"; |
| 78 DOMException* domException = V8DOMException::toImplWithTypeCheck( |
| 79 scriptState->isolate(), exceptionState.getException()); |
| 80 if (!domException) { |
| 81 return ::testing::AssertionFailure() |
| 82 << "exception thrown was not a DOMException"; |
| 83 } |
| 84 if (domException->name() != name) |
| 85 return ::testing::AssertionFailure() << "was " << domException->name(); |
| 86 return ::testing::AssertionSuccess(); |
| 87 } |
| 88 |
70 static const char kEcdsaPrivateKey[] = | 89 static const char kEcdsaPrivateKey[] = |
71 "-----BEGIN PRIVATE KEY-----\n" | 90 "-----BEGIN PRIVATE KEY-----\n" |
72 "MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQghHwQ1xYtCoEhFk7r\n" | 91 "MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQghHwQ1xYtCoEhFk7r\n" |
73 "92u3ozy/MFR4I+9FiN8RYv5J96GhRANCAATLfi7OZLD9sIe5UMfMQnHQgAFaQD8h\n" | 92 "92u3ozy/MFR4I+9FiN8RYv5J96GhRANCAATLfi7OZLD9sIe5UMfMQnHQgAFaQD8h\n" |
74 "/cy6tB8wXZcixp7bZDp5t0GCDHqAUZT3Sa/NHaCelmmgPp3zW3lszXKP\n" | 93 "/cy6tB8wXZcixp7bZDp5t0GCDHqAUZT3Sa/NHaCelmmgPp3zW3lszXKP\n" |
75 "-----END PRIVATE KEY-----\n"; | 94 "-----END PRIVATE KEY-----\n"; |
76 | 95 |
77 static const char kEcdsaCertificate[] = | 96 static const char kEcdsaCertificate[] = |
78 "-----BEGIN CERTIFICATE-----\n" | 97 "-----BEGIN CERTIFICATE-----\n" |
79 "MIIBFjCBvaADAgECAgkApnGS+DzNWkUwCgYIKoZIzj0EAwIwETEPMA0GA1UEAwwG\n" | 98 "MIIBFjCBvaADAgECAgkApnGS+DzNWkUwCgYIKoZIzj0EAwIwETEPMA0GA1UEAwwG\n" |
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 | 849 |
831 // Input ends before end of declared public exponent size. | 850 // Input ends before end of declared public exponent size. |
832 EXPECT_TRUE( | 851 EXPECT_TRUE( |
833 V8ScriptValueDeserializerForModules( | 852 V8ScriptValueDeserializerForModules( |
834 scriptState, serializedValue({0xff, 0x09, 0x3f, 0x00, 0x4b, 0x04, | 853 scriptState, serializedValue({0xff, 0x09, 0x3f, 0x00, 0x4b, 0x04, |
835 0x0d, 0x01, 0x80, 0x08, 0x03, 0x01})) | 854 0x0d, 0x01, 0x80, 0x08, 0x03, 0x01})) |
836 .deserialize() | 855 .deserialize() |
837 ->IsNull()); | 856 ->IsNull()); |
838 } | 857 } |
839 | 858 |
| 859 TEST(V8ScriptValueSerializerForModulesTest, RoundTripDOMFileSystem) { |
| 860 ScopedEnableV8BasedStructuredClone enable; |
| 861 V8TestingScope scope; |
| 862 |
| 863 DOMFileSystem* fs = DOMFileSystem::create( |
| 864 scope.getExecutionContext(), "http_example.com_0:Persistent", |
| 865 FileSystemTypePersistent, |
| 866 KURL(ParsedURLString, "filesystem:http://example.com/persistent/")); |
| 867 // At time of writing, this can only happen for filesystems from PPAPI. |
| 868 fs->makeClonable(); |
| 869 v8::Local<v8::Value> wrapper = toV8(fs, scope.getScriptState()); |
| 870 v8::Local<v8::Value> result = roundTrip(wrapper, scope); |
| 871 ASSERT_FALSE(result.IsEmpty()); |
| 872 ASSERT_TRUE(V8DOMFileSystem::hasInstance(result, scope.isolate())); |
| 873 DOMFileSystem* newFS = V8DOMFileSystem::toImpl(result.As<v8::Object>()); |
| 874 EXPECT_EQ("http_example.com_0:Persistent", newFS->name()); |
| 875 EXPECT_EQ(FileSystemTypePersistent, newFS->type()); |
| 876 EXPECT_EQ("filesystem:http://example.com/persistent/", |
| 877 newFS->rootURL().getString()); |
| 878 } |
| 879 |
| 880 TEST(V8ScriptValueSerializerForModulesTest, RoundTripDOMFileSystemNotClonable) { |
| 881 ScopedEnableV8BasedStructuredClone enable; |
| 882 V8TestingScope scope; |
| 883 ExceptionState exceptionState(scope.isolate(), |
| 884 ExceptionState::ExecutionContext, "Window", |
| 885 "postMessage"); |
| 886 |
| 887 DOMFileSystem* fs = DOMFileSystem::create( |
| 888 scope.getExecutionContext(), "http_example.com_0:Persistent", |
| 889 FileSystemTypePersistent, |
| 890 KURL(ParsedURLString, "filesystem:http://example.com/persistent/0/")); |
| 891 ASSERT_FALSE(fs->clonable()); |
| 892 v8::Local<v8::Value> wrapper = toV8(fs, scope.getScriptState()); |
| 893 EXPECT_FALSE(V8ScriptValueSerializer(scope.getScriptState()) |
| 894 .serialize(wrapper, nullptr, exceptionState)); |
| 895 EXPECT_TRUE(hadDOMException("DataCloneError", scope.getScriptState(), |
| 896 exceptionState)); |
| 897 } |
| 898 |
| 899 TEST(V8ScriptValueSerializerForModulesTest, DecodeDOMFileSystem) { |
| 900 ScopedEnableV8BasedStructuredClone enable; |
| 901 V8TestingScope scope; |
| 902 |
| 903 // This is encoded data generated from Chromium (around M56). |
| 904 ScriptState* scriptState = scope.getScriptState(); |
| 905 RefPtr<SerializedScriptValue> input = serializedValue( |
| 906 {0xff, 0x09, 0x3f, 0x00, 0x64, 0x01, 0x1d, 0x68, 0x74, 0x74, 0x70, 0x5f, |
| 907 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x5f, |
| 908 0x30, 0x3a, 0x50, 0x65, 0x72, 0x73, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x74, |
| 909 0x29, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x3a, |
| 910 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, |
| 911 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x65, 0x72, 0x73, 0x69, |
| 912 0x73, 0x74, 0x65, 0x6e, 0x74, 0x2f}); |
| 913 |
| 914 // Decode test. |
| 915 v8::Local<v8::Value> result = |
| 916 V8ScriptValueDeserializerForModules(scriptState, input).deserialize(); |
| 917 ASSERT_TRUE(V8DOMFileSystem::hasInstance(result, scope.isolate())); |
| 918 DOMFileSystem* newFS = V8DOMFileSystem::toImpl(result.As<v8::Object>()); |
| 919 EXPECT_EQ("http_example.com_0:Persistent", newFS->name()); |
| 920 EXPECT_EQ(FileSystemTypePersistent, newFS->type()); |
| 921 EXPECT_EQ("filesystem:http://example.com/persistent/", |
| 922 newFS->rootURL().getString()); |
| 923 } |
| 924 |
| 925 TEST(V8ScriptValueSerializerForModulesTest, DecodeInvalidDOMFileSystem) { |
| 926 ScopedEnableV8BasedStructuredClone enable; |
| 927 V8TestingScope scope; |
| 928 ScriptState* scriptState = scope.getScriptState(); |
| 929 |
| 930 // Filesystem type out of range. |
| 931 EXPECT_TRUE( |
| 932 V8ScriptValueDeserializerForModules( |
| 933 scriptState, |
| 934 serializedValue({0xff, 0x09, 0x3f, 0x00, 0x64, 0x04, 0x1d, 0x68, 0x74, |
| 935 0x74, 0x70, 0x5f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, |
| 936 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x5f, 0x30, 0x3a, 0x50, |
| 937 0x65, 0x72, 0x73, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x74, |
| 938 0x29, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x79, 0x73, 0x74, |
| 939 0x65, 0x6d, 0x3a, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, |
| 940 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, |
| 941 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x65, 0x72, 0x73, 0x69, |
| 942 0x73, 0x74, 0x65, 0x6e, 0x74, 0x2f |
| 943 |
| 944 })) |
| 945 .deserialize() |
| 946 ->IsNull()); |
| 947 } |
| 948 |
840 } // namespace | 949 } // namespace |
841 } // namespace blink | 950 } // namespace blink |
OLD | NEW |