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

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

Issue 2684843005: Inline the V8BasedStructuredClone feature. (Closed)
Patch Set: Created 3 years, 10 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 14 matching lines...) Expand all
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;
29 using ::testing::ElementsAreArray; 29 using ::testing::ElementsAreArray;
30 using ::testing::UnorderedElementsAre; 30 using ::testing::UnorderedElementsAre;
31 31
32 namespace blink { 32 namespace blink {
33 namespace { 33 namespace {
34 34
35 class ScopedEnableV8BasedStructuredClone {
36 public:
37 ScopedEnableV8BasedStructuredClone()
38 : m_wasEnabled(RuntimeEnabledFeatures::v8BasedStructuredCloneEnabled()) {
39 RuntimeEnabledFeatures::setV8BasedStructuredCloneEnabled(true);
40 }
41 ~ScopedEnableV8BasedStructuredClone() {
42 RuntimeEnabledFeatures::setV8BasedStructuredCloneEnabled(m_wasEnabled);
43 }
44
45 private:
46 bool m_wasEnabled;
47 };
48
49 RefPtr<SerializedScriptValue> serializedValue(const Vector<uint8_t>& bytes) { 35 RefPtr<SerializedScriptValue> serializedValue(const Vector<uint8_t>& bytes) {
50 // TODO(jbroman): Fix this once SerializedScriptValue can take bytes without 36 // TODO(jbroman): Fix this once SerializedScriptValue can take bytes without
51 // endianness swapping. 37 // endianness swapping.
52 DCHECK_EQ(bytes.size() % 2, 0u); 38 DCHECK_EQ(bytes.size() % 2, 0u);
53 return SerializedScriptValue::create( 39 return SerializedScriptValue::create(
54 String(reinterpret_cast<const UChar*>(&bytes[0]), bytes.size() / 2)); 40 String(reinterpret_cast<const UChar*>(&bytes[0]), bytes.size() / 2));
55 } 41 }
56 42
57 v8::Local<v8::Value> roundTrip(v8::Local<v8::Value> value, 43 v8::Local<v8::Value> roundTrip(v8::Local<v8::Value> value,
58 V8TestingScope& scope) { 44 V8TestingScope& scope) {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 0x2b, 0x37, 0x0a, 0x4c, 0x6b, 0x48, 0x32, 0x51, 0x6d, 0x78, 0x49, 0x43, 143 0x2b, 0x37, 0x0a, 0x4c, 0x6b, 0x48, 0x32, 0x51, 0x6d, 0x78, 0x49, 0x43,
158 0x77, 0x49, 0x68, 0x41, 0x4a, 0x43, 0x75, 0x6a, 0x6f, 0x7a, 0x4e, 0x33, 144 0x77, 0x49, 0x68, 0x41, 0x4a, 0x43, 0x75, 0x6a, 0x6f, 0x7a, 0x4e, 0x33,
159 0x67, 0x6a, 0x49, 0x75, 0x37, 0x4e, 0x4d, 0x78, 0x53, 0x58, 0x75, 0x54, 145 0x67, 0x6a, 0x49, 0x75, 0x37, 0x4e, 0x4d, 0x78, 0x53, 0x58, 0x75, 0x54,
160 0x71, 0x75, 0x65, 0x75, 0x56, 0x7a, 0x35, 0x38, 0x53, 0x65, 0x66, 0x43, 146 0x71, 0x75, 0x65, 0x75, 0x56, 0x7a, 0x35, 0x38, 0x53, 0x65, 0x66, 0x43,
161 0x4d, 0x41, 0x37, 0x2f, 0x76, 0x6a, 0x31, 0x54, 0x67, 0x66, 0x56, 0x0a, 147 0x4d, 0x41, 0x37, 0x2f, 0x76, 0x6a, 0x31, 0x54, 0x67, 0x66, 0x56, 0x0a,
162 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20, 0x43, 0x45, 0x52, 148 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20, 0x43, 0x45, 0x52,
163 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2d, 0x2d, 0x2d, 0x2d, 149 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2d, 0x2d, 0x2d, 0x2d,
164 0x2d, 0x0a}; 150 0x2d, 0x0a};
165 151
166 TEST(V8ScriptValueSerializerForModulesTest, RoundTripRTCCertificate) { 152 TEST(V8ScriptValueSerializerForModulesTest, RoundTripRTCCertificate) {
167 ScopedEnableV8BasedStructuredClone enable;
168 V8TestingScope scope; 153 V8TestingScope scope;
169 154
170 // Make a certificate with the existing key above. 155 // Make a certificate with the existing key above.
171 std::unique_ptr<WebRTCCertificateGenerator> certificateGenerator( 156 std::unique_ptr<WebRTCCertificateGenerator> certificateGenerator(
172 Platform::current()->createRTCCertificateGenerator()); 157 Platform::current()->createRTCCertificateGenerator());
173 std::unique_ptr<WebRTCCertificate> webCertificate = 158 std::unique_ptr<WebRTCCertificate> webCertificate =
174 certificateGenerator->fromPEM( 159 certificateGenerator->fromPEM(
175 WebString::fromUTF8(kEcdsaPrivateKey, sizeof(kEcdsaPrivateKey)), 160 WebString::fromUTF8(kEcdsaPrivateKey, sizeof(kEcdsaPrivateKey)),
176 WebString::fromUTF8(kEcdsaCertificate, sizeof(kEcdsaCertificate))); 161 WebString::fromUTF8(kEcdsaCertificate, sizeof(kEcdsaCertificate)));
177 ASSERT_TRUE(webCertificate); 162 ASSERT_TRUE(webCertificate);
178 RTCCertificate* certificate = new RTCCertificate(std::move(webCertificate)); 163 RTCCertificate* certificate = new RTCCertificate(std::move(webCertificate));
179 164
180 // Round trip test. 165 // Round trip test.
181 v8::Local<v8::Value> wrapper = 166 v8::Local<v8::Value> wrapper =
182 ToV8(certificate, scope.context()->Global(), scope.isolate()); 167 ToV8(certificate, scope.context()->Global(), scope.isolate());
183 v8::Local<v8::Value> result = roundTrip(wrapper, scope); 168 v8::Local<v8::Value> result = roundTrip(wrapper, scope);
184 ASSERT_TRUE(V8RTCCertificate::hasInstance(result, scope.isolate())); 169 ASSERT_TRUE(V8RTCCertificate::hasInstance(result, scope.isolate()));
185 RTCCertificate* newCertificate = 170 RTCCertificate* newCertificate =
186 V8RTCCertificate::toImpl(result.As<v8::Object>()); 171 V8RTCCertificate::toImpl(result.As<v8::Object>());
187 WebRTCCertificatePEM pem = newCertificate->certificate().toPEM(); 172 WebRTCCertificatePEM pem = newCertificate->certificate().toPEM();
188 EXPECT_EQ(kEcdsaPrivateKey, pem.privateKey()); 173 EXPECT_EQ(kEcdsaPrivateKey, pem.privateKey());
189 EXPECT_EQ(kEcdsaCertificate, pem.certificate()); 174 EXPECT_EQ(kEcdsaCertificate, pem.certificate());
190 } 175 }
191 176
192 TEST(V8ScriptValueSerializerForModulesTest, DecodeRTCCertificate) { 177 TEST(V8ScriptValueSerializerForModulesTest, DecodeRTCCertificate) {
193 ScopedEnableV8BasedStructuredClone enable;
194 V8TestingScope scope; 178 V8TestingScope scope;
195 179
196 // This is encoded data generated from Chromium (around M55). 180 // This is encoded data generated from Chromium (around M55).
197 ScriptState* scriptState = scope.getScriptState(); 181 ScriptState* scriptState = scope.getScriptState();
198 Vector<uint8_t> encodedData; 182 Vector<uint8_t> encodedData;
199 encodedData.append(kEcdsaCertificateEncoded, 183 encodedData.append(kEcdsaCertificateEncoded,
200 sizeof(kEcdsaCertificateEncoded)); 184 sizeof(kEcdsaCertificateEncoded));
201 RefPtr<SerializedScriptValue> input = serializedValue(encodedData); 185 RefPtr<SerializedScriptValue> input = serializedValue(encodedData);
202 186
203 // Decode test. 187 // Decode test.
204 v8::Local<v8::Value> result = 188 v8::Local<v8::Value> result =
205 V8ScriptValueDeserializerForModules(scriptState, input).deserialize(); 189 V8ScriptValueDeserializerForModules(scriptState, input).deserialize();
206 ASSERT_TRUE(V8RTCCertificate::hasInstance(result, scope.isolate())); 190 ASSERT_TRUE(V8RTCCertificate::hasInstance(result, scope.isolate()));
207 RTCCertificate* newCertificate = 191 RTCCertificate* newCertificate =
208 V8RTCCertificate::toImpl(result.As<v8::Object>()); 192 V8RTCCertificate::toImpl(result.As<v8::Object>());
209 WebRTCCertificatePEM pem = newCertificate->certificate().toPEM(); 193 WebRTCCertificatePEM pem = newCertificate->certificate().toPEM();
210 EXPECT_EQ(kEcdsaPrivateKey, pem.privateKey()); 194 EXPECT_EQ(kEcdsaPrivateKey, pem.privateKey());
211 EXPECT_EQ(kEcdsaCertificate, pem.certificate()); 195 EXPECT_EQ(kEcdsaCertificate, pem.certificate());
212 } 196 }
213 197
214 TEST(V8ScriptValueSerializerForModulesTest, DecodeInvalidRTCCertificate) { 198 TEST(V8ScriptValueSerializerForModulesTest, DecodeInvalidRTCCertificate) {
215 ScopedEnableV8BasedStructuredClone enable;
216 V8TestingScope scope; 199 V8TestingScope scope;
217 200
218 // This is valid, except that "private" is not a valid private key PEM and 201 // This is valid, except that "private" is not a valid private key PEM and
219 // "certificate" is not a valid certificate PEM. This checks what happens if 202 // "certificate" is not a valid certificate PEM. This checks what happens if
220 // these fail validation inside WebRTC. 203 // these fail validation inside WebRTC.
221 ScriptState* scriptState = scope.getScriptState(); 204 ScriptState* scriptState = scope.getScriptState();
222 RefPtr<SerializedScriptValue> input = serializedValue( 205 RefPtr<SerializedScriptValue> input = serializedValue(
223 {0xff, 0x09, 0x3f, 0x00, 0x6b, 0x07, 'p', 'r', 'i', 'v', 'a', 't', 'e', 206 {0xff, 0x09, 0x3f, 0x00, 0x6b, 0x07, 'p', 'r', 'i', 'v', 'a', 't', 'e',
224 0x0b, 'c', 'e', 'r', 't', 'i', 'f', 'i', 'c', 'a', 't', 'e', 0x00}); 207 0x0b, 'c', 'e', 'r', 't', 'i', 'f', 'i', 'c', 'a', 't', 'e', 0x00});
225 208
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 WebVector<uint8_t> syncDeriveBits(ScriptState* scriptState, 374 WebVector<uint8_t> syncDeriveBits(ScriptState* scriptState,
392 const WebCryptoAlgorithm& algorithm, 375 const WebCryptoAlgorithm& algorithm,
393 const WebCryptoKey& key, 376 const WebCryptoKey& key,
394 unsigned length) { 377 unsigned length) {
395 return subtleCryptoSync<WebVector<uint8_t>>( 378 return subtleCryptoSync<WebVector<uint8_t>>(
396 scriptState, &WebCrypto::deriveBits, algorithm, key, length); 379 scriptState, &WebCrypto::deriveBits, algorithm, key, length);
397 } 380 }
398 381
399 // AES-128-CBC uses AES key params. 382 // AES-128-CBC uses AES key params.
400 TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyAES) { 383 TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyAES) {
401 ScopedEnableV8BasedStructuredClone enable;
402 V8TestingScope scope; 384 V8TestingScope scope;
403 ScriptState* scriptState = scope.getScriptState(); 385 ScriptState* scriptState = scope.getScriptState();
404 386
405 // Generate a 128-bit AES key. 387 // Generate a 128-bit AES key.
406 std::unique_ptr<WebCryptoAlgorithmParams> params( 388 std::unique_ptr<WebCryptoAlgorithmParams> params(
407 new WebCryptoAesKeyGenParams(128)); 389 new WebCryptoAesKeyGenParams(128));
408 WebCryptoAlgorithm algorithm(WebCryptoAlgorithmIdAesCbc, std::move(params)); 390 WebCryptoAlgorithm algorithm(WebCryptoAlgorithmIdAesCbc, std::move(params));
409 CryptoKey* key = 391 CryptoKey* key =
410 syncGenerateKey(scriptState, algorithm, true, 392 syncGenerateKey(scriptState, algorithm, true,
411 WebCryptoKeyUsageEncrypt | WebCryptoKeyUsageDecrypt); 393 WebCryptoKeyUsageEncrypt | WebCryptoKeyUsageDecrypt);
(...skipping 20 matching lines...) Expand all
432 WebCryptoAlgorithmIdAesCbc, WTF::makeUnique<WebCryptoAesCbcParams>(iv)); 414 WebCryptoAlgorithmIdAesCbc, WTF::makeUnique<WebCryptoAesCbcParams>(iv));
433 Vector<unsigned char> plaintext{1, 2, 3}; 415 Vector<unsigned char> plaintext{1, 2, 3};
434 WebVector<uint8_t> ciphertext = 416 WebVector<uint8_t> ciphertext =
435 syncEncrypt(scriptState, encryptAlgorithm, key->key(), plaintext); 417 syncEncrypt(scriptState, encryptAlgorithm, key->key(), plaintext);
436 WebVector<uint8_t> newPlaintext = 418 WebVector<uint8_t> newPlaintext =
437 syncDecrypt(scriptState, encryptAlgorithm, newKey->key(), ciphertext); 419 syncDecrypt(scriptState, encryptAlgorithm, newKey->key(), ciphertext);
438 EXPECT_THAT(newPlaintext, ElementsAre(1, 2, 3)); 420 EXPECT_THAT(newPlaintext, ElementsAre(1, 2, 3));
439 } 421 }
440 422
441 TEST(V8ScriptValueSerializerForModulesTest, DecodeCryptoKeyAES) { 423 TEST(V8ScriptValueSerializerForModulesTest, DecodeCryptoKeyAES) {
442 ScopedEnableV8BasedStructuredClone enable;
443 V8TestingScope scope; 424 V8TestingScope scope;
444 ScriptState* scriptState = scope.getScriptState(); 425 ScriptState* scriptState = scope.getScriptState();
445 426
446 // Decode a 128-bit AES key (non-extractable, decrypt only). 427 // Decode a 128-bit AES key (non-extractable, decrypt only).
447 RefPtr<SerializedScriptValue> input = 428 RefPtr<SerializedScriptValue> input =
448 serializedValue({0xff, 0x09, 0x3f, 0x00, 0x4b, 0x01, 0x01, 0x10, 0x04, 429 serializedValue({0xff, 0x09, 0x3f, 0x00, 0x4b, 0x01, 0x01, 0x10, 0x04,
449 0x10, 0x7e, 0x25, 0xb2, 0xe8, 0x62, 0x3e, 0xd7, 0x83, 430 0x10, 0x7e, 0x25, 0xb2, 0xe8, 0x62, 0x3e, 0xd7, 0x83,
450 0x70, 0xa2, 0xae, 0x98, 0x79, 0x1b, 0xc5, 0xf7}); 431 0x70, 0xa2, 0xae, 0x98, 0x79, 0x1b, 0xc5, 0xf7});
451 v8::Local<v8::Value> result = 432 v8::Local<v8::Value> result =
452 V8ScriptValueDeserializerForModules(scriptState, input).deserialize(); 433 V8ScriptValueDeserializerForModules(scriptState, input).deserialize();
453 ASSERT_TRUE(V8CryptoKey::hasInstance(result, scope.isolate())); 434 ASSERT_TRUE(V8CryptoKey::hasInstance(result, scope.isolate()));
454 CryptoKey* newKey = V8CryptoKey::toImpl(result.As<v8::Object>()); 435 CryptoKey* newKey = V8CryptoKey::toImpl(result.As<v8::Object>());
455 EXPECT_EQ("secret", newKey->type()); 436 EXPECT_EQ("secret", newKey->type());
456 EXPECT_FALSE(newKey->extractable()); 437 EXPECT_FALSE(newKey->extractable());
457 EXPECT_THAT(newKey->usages(), UnorderedElementsAre("decrypt")); 438 EXPECT_THAT(newKey->usages(), UnorderedElementsAre("decrypt"));
458 439
459 // Check that it can successfully decrypt data. 440 // Check that it can successfully decrypt data.
460 Vector<uint8_t> iv(16, 0); 441 Vector<uint8_t> iv(16, 0);
461 Vector<uint8_t> ciphertext{0x33, 0x26, 0xe7, 0x64, 0x11, 0x5e, 0xf4, 0x60, 442 Vector<uint8_t> ciphertext{0x33, 0x26, 0xe7, 0x64, 0x11, 0x5e, 0xf4, 0x60,
462 0x96, 0x08, 0x11, 0xaf, 0x65, 0x8b, 0x87, 0x04}; 443 0x96, 0x08, 0x11, 0xaf, 0x65, 0x8b, 0x87, 0x04};
463 WebCryptoAlgorithm encryptAlgorithm( 444 WebCryptoAlgorithm encryptAlgorithm(
464 WebCryptoAlgorithmIdAesCbc, WTF::makeUnique<WebCryptoAesCbcParams>(iv)); 445 WebCryptoAlgorithmIdAesCbc, WTF::makeUnique<WebCryptoAesCbcParams>(iv));
465 WebVector<uint8_t> plaintext = 446 WebVector<uint8_t> plaintext =
466 syncDecrypt(scriptState, encryptAlgorithm, newKey->key(), ciphertext); 447 syncDecrypt(scriptState, encryptAlgorithm, newKey->key(), ciphertext);
467 EXPECT_THAT(plaintext, ElementsAre(1, 2, 3)); 448 EXPECT_THAT(plaintext, ElementsAre(1, 2, 3));
468 } 449 }
469 450
470 // HMAC-SHA256 uses HMAC key params. 451 // HMAC-SHA256 uses HMAC key params.
471 TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyHMAC) { 452 TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyHMAC) {
472 ScopedEnableV8BasedStructuredClone enable;
473 V8TestingScope scope; 453 V8TestingScope scope;
474 ScriptState* scriptState = scope.getScriptState(); 454 ScriptState* scriptState = scope.getScriptState();
475 455
476 // Generate an HMAC-SHA256 key. 456 // Generate an HMAC-SHA256 key.
477 WebCryptoAlgorithm hash(WebCryptoAlgorithmIdSha256, nullptr); 457 WebCryptoAlgorithm hash(WebCryptoAlgorithmIdSha256, nullptr);
478 std::unique_ptr<WebCryptoAlgorithmParams> generateKeyParams( 458 std::unique_ptr<WebCryptoAlgorithmParams> generateKeyParams(
479 new WebCryptoHmacKeyGenParams(hash, false, 0)); 459 new WebCryptoHmacKeyGenParams(hash, false, 0));
480 WebCryptoAlgorithm generateKeyAlgorithm(WebCryptoAlgorithmIdHmac, 460 WebCryptoAlgorithm generateKeyAlgorithm(WebCryptoAlgorithmIdHmac,
481 std::move(generateKeyParams)); 461 std::move(generateKeyParams));
482 CryptoKey* key = 462 CryptoKey* key =
(...skipping 19 matching lines...) Expand all
502 // Check that one can verify a message signed by the other. 482 // Check that one can verify a message signed by the other.
503 Vector<uint8_t> message{1, 2, 3}; 483 Vector<uint8_t> message{1, 2, 3};
504 WebCryptoAlgorithm algorithm(WebCryptoAlgorithmIdHmac, nullptr); 484 WebCryptoAlgorithm algorithm(WebCryptoAlgorithmIdHmac, nullptr);
505 WebVector<uint8_t> signature = 485 WebVector<uint8_t> signature =
506 syncSign(scriptState, algorithm, key->key(), message); 486 syncSign(scriptState, algorithm, key->key(), message);
507 EXPECT_TRUE(syncVerifySignature(scriptState, algorithm, newKey->key(), 487 EXPECT_TRUE(syncVerifySignature(scriptState, algorithm, newKey->key(),
508 signature, message)); 488 signature, message));
509 } 489 }
510 490
511 TEST(V8ScriptValueSerializerForModulesTest, DecodeCryptoKeyHMAC) { 491 TEST(V8ScriptValueSerializerForModulesTest, DecodeCryptoKeyHMAC) {
512 ScopedEnableV8BasedStructuredClone enable;
513 V8TestingScope scope; 492 V8TestingScope scope;
514 ScriptState* scriptState = scope.getScriptState(); 493 ScriptState* scriptState = scope.getScriptState();
515 494
516 // Decode an HMAC-SHA256 key (non-extractable, verify only). 495 // Decode an HMAC-SHA256 key (non-extractable, verify only).
517 RefPtr<SerializedScriptValue> input = serializedValue( 496 RefPtr<SerializedScriptValue> input = serializedValue(
518 {0xff, 0x09, 0x3f, 0x00, 0x4b, 0x02, 0x40, 0x06, 0x10, 0x40, 0xd9, 497 {0xff, 0x09, 0x3f, 0x00, 0x4b, 0x02, 0x40, 0x06, 0x10, 0x40, 0xd9,
519 0xbd, 0x0e, 0x84, 0x24, 0x3c, 0xb0, 0xbc, 0xee, 0x36, 0x61, 0xdc, 498 0xbd, 0x0e, 0x84, 0x24, 0x3c, 0xb0, 0xbc, 0xee, 0x36, 0x61, 0xdc,
520 0xd0, 0xb0, 0xf5, 0x62, 0x09, 0xab, 0x93, 0x8c, 0x21, 0xaf, 0xb7, 499 0xd0, 0xb0, 0xf5, 0x62, 0x09, 0xab, 0x93, 0x8c, 0x21, 0xaf, 0xb7,
521 0x66, 0xa9, 0xfc, 0xd2, 0xaa, 0xd8, 0xd4, 0x79, 0xf2, 0x55, 0x3a, 500 0x66, 0xa9, 0xfc, 0xd2, 0xaa, 0xd8, 0xd4, 0x79, 0xf2, 0x55, 0x3a,
522 0xef, 0x46, 0x03, 0xec, 0x64, 0x2f, 0x68, 0xea, 0x9f, 0x9d, 0x1d, 501 0xef, 0x46, 0x03, 0xec, 0x64, 0x2f, 0x68, 0xea, 0x9f, 0x9d, 0x1d,
(...skipping 13 matching lines...) Expand all
536 0x2d, 0x18, 0x91, 0x88, 0xd0, 0x56, 0x4d, 0xb6, 515 0x2d, 0x18, 0x91, 0x88, 0xd0, 0x56, 0x4d, 0xb6,
537 0x46, 0xc8, 0xb2, 0xa4, 0x2e, 0x1f, 0x0d, 0xe2, 516 0x46, 0xc8, 0xb2, 0xa4, 0x2e, 0x1f, 0x0d, 0xe2,
538 0xd6, 0x60, 0xf9, 0xee, 0xb7, 0xd4, 0x55, 0x12}; 517 0xd6, 0x60, 0xf9, 0xee, 0xb7, 0xd4, 0x55, 0x12};
539 WebCryptoAlgorithm algorithm(WebCryptoAlgorithmIdHmac, nullptr); 518 WebCryptoAlgorithm algorithm(WebCryptoAlgorithmIdHmac, nullptr);
540 EXPECT_TRUE(syncVerifySignature(scriptState, algorithm, newKey->key(), 519 EXPECT_TRUE(syncVerifySignature(scriptState, algorithm, newKey->key(),
541 signature, message)); 520 signature, message));
542 } 521 }
543 522
544 // RSA-PSS-SHA256 uses RSA hashed key params. 523 // RSA-PSS-SHA256 uses RSA hashed key params.
545 TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyRSAHashed) { 524 TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyRSAHashed) {
546 ScopedEnableV8BasedStructuredClone enable;
547 V8TestingScope scope; 525 V8TestingScope scope;
548 ScriptState* scriptState = scope.getScriptState(); 526 ScriptState* scriptState = scope.getScriptState();
549 527
550 // Generate an RSA-PSS-SHA256 key pair. 528 // Generate an RSA-PSS-SHA256 key pair.
551 WebCryptoAlgorithm hash(WebCryptoAlgorithmIdSha256, nullptr); 529 WebCryptoAlgorithm hash(WebCryptoAlgorithmIdSha256, nullptr);
552 std::unique_ptr<WebCryptoAlgorithmParams> generateKeyParams( 530 std::unique_ptr<WebCryptoAlgorithmParams> generateKeyParams(
553 new WebCryptoRsaHashedKeyGenParams(hash, 1024, Vector<uint8_t>{1, 0, 1})); 531 new WebCryptoRsaHashedKeyGenParams(hash, 1024, Vector<uint8_t>{1, 0, 1}));
554 WebCryptoAlgorithm generateKeyAlgorithm(WebCryptoAlgorithmIdRsaPss, 532 WebCryptoAlgorithm generateKeyAlgorithm(WebCryptoAlgorithmIdRsaPss,
555 std::move(generateKeyParams)); 533 std::move(generateKeyParams));
556 CryptoKey* publicKey; 534 CryptoKey* publicKey;
(...skipping 22 matching lines...) Expand all
579 Vector<uint8_t> message{1, 2, 3}; 557 Vector<uint8_t> message{1, 2, 3};
580 WebCryptoAlgorithm algorithm(WebCryptoAlgorithmIdRsaPss, 558 WebCryptoAlgorithm algorithm(WebCryptoAlgorithmIdRsaPss,
581 WTF::makeUnique<WebCryptoRsaPssParams>(16)); 559 WTF::makeUnique<WebCryptoRsaPssParams>(16));
582 WebVector<uint8_t> signature = 560 WebVector<uint8_t> signature =
583 syncSign(scriptState, algorithm, newPrivateKey->key(), message); 561 syncSign(scriptState, algorithm, newPrivateKey->key(), message);
584 EXPECT_TRUE(syncVerifySignature(scriptState, algorithm, publicKey->key(), 562 EXPECT_TRUE(syncVerifySignature(scriptState, algorithm, publicKey->key(),
585 signature, message)); 563 signature, message));
586 } 564 }
587 565
588 TEST(V8ScriptValueSerializerForModulesTest, DecodeCryptoKeyRSAHashed) { 566 TEST(V8ScriptValueSerializerForModulesTest, DecodeCryptoKeyRSAHashed) {
589 ScopedEnableV8BasedStructuredClone enable;
590 V8TestingScope scope; 567 V8TestingScope scope;
591 ScriptState* scriptState = scope.getScriptState(); 568 ScriptState* scriptState = scope.getScriptState();
592 569
593 // Decode an RSA-PSS-SHA256 public key (extractable, verify only). 570 // Decode an RSA-PSS-SHA256 public key (extractable, verify only).
594 RefPtr<SerializedScriptValue> input = serializedValue( 571 RefPtr<SerializedScriptValue> input = serializedValue(
595 {0xff, 0x09, 0x3f, 0x00, 0x4b, 0x04, 0x0d, 0x01, 0x80, 0x08, 0x03, 0x01, 572 {0xff, 0x09, 0x3f, 0x00, 0x4b, 0x04, 0x0d, 0x01, 0x80, 0x08, 0x03, 0x01,
596 0x00, 0x01, 0x06, 0x11, 0xa2, 0x01, 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 573 0x00, 0x01, 0x06, 0x11, 0xa2, 0x01, 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06,
597 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 574 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00,
598 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xae, 575 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xae,
599 0xef, 0x7f, 0xee, 0x3a, 0x48, 0x48, 0xea, 0xce, 0x18, 0x0b, 0x86, 0x34, 576 0xef, 0x7f, 0xee, 0x3a, 0x48, 0x48, 0xea, 0xce, 0x18, 0x0b, 0x86, 0x34,
(...skipping 30 matching lines...) Expand all
630 0xeb, 0x17, 0x68, 0x1f, 0xbd, 0xfa, 0xf7, 0xd6, 0x1f, 0xa4, 0x7c, 0x9e, 607 0xeb, 0x17, 0x68, 0x1f, 0xbd, 0xfa, 0xf7, 0xd6, 0x1f, 0xa4, 0x7c, 0x9e,
631 0x9e, 0xb1, 0x96, 0x8f, 0xe6, 0x5e, 0x89, 0x99}; 608 0x9e, 0xb1, 0x96, 0x8f, 0xe6, 0x5e, 0x89, 0x99};
632 WebCryptoAlgorithm algorithm(WebCryptoAlgorithmIdRsaPss, 609 WebCryptoAlgorithm algorithm(WebCryptoAlgorithmIdRsaPss,
633 WTF::makeUnique<WebCryptoRsaPssParams>(16)); 610 WTF::makeUnique<WebCryptoRsaPssParams>(16));
634 EXPECT_TRUE(syncVerifySignature(scriptState, algorithm, newPublicKey->key(), 611 EXPECT_TRUE(syncVerifySignature(scriptState, algorithm, newPublicKey->key(),
635 signature, message)); 612 signature, message));
636 } 613 }
637 614
638 // ECDSA uses EC key params. 615 // ECDSA uses EC key params.
639 TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyEC) { 616 TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyEC) {
640 ScopedEnableV8BasedStructuredClone enable;
641 V8TestingScope scope; 617 V8TestingScope scope;
642 ScriptState* scriptState = scope.getScriptState(); 618 ScriptState* scriptState = scope.getScriptState();
643 619
644 // Generate an ECDSA key pair with the NIST P-256 curve. 620 // Generate an ECDSA key pair with the NIST P-256 curve.
645 std::unique_ptr<WebCryptoAlgorithmParams> generateKeyParams( 621 std::unique_ptr<WebCryptoAlgorithmParams> generateKeyParams(
646 new WebCryptoEcKeyGenParams(WebCryptoNamedCurveP256)); 622 new WebCryptoEcKeyGenParams(WebCryptoNamedCurveP256));
647 WebCryptoAlgorithm generateKeyAlgorithm(WebCryptoAlgorithmIdEcdsa, 623 WebCryptoAlgorithm generateKeyAlgorithm(WebCryptoAlgorithmIdEcdsa,
648 std::move(generateKeyParams)); 624 std::move(generateKeyParams));
649 CryptoKey* publicKey; 625 CryptoKey* publicKey;
650 CryptoKey* privateKey; 626 CryptoKey* privateKey;
(...skipping 22 matching lines...) Expand all
673 Vector<uint8_t> message{1, 2, 3}; 649 Vector<uint8_t> message{1, 2, 3};
674 WebCryptoAlgorithm algorithm(WebCryptoAlgorithmIdEcdsa, 650 WebCryptoAlgorithm algorithm(WebCryptoAlgorithmIdEcdsa,
675 WTF::makeUnique<WebCryptoEcdsaParams>(hash)); 651 WTF::makeUnique<WebCryptoEcdsaParams>(hash));
676 WebVector<uint8_t> signature = 652 WebVector<uint8_t> signature =
677 syncSign(scriptState, algorithm, newPrivateKey->key(), message); 653 syncSign(scriptState, algorithm, newPrivateKey->key(), message);
678 EXPECT_TRUE(syncVerifySignature(scriptState, algorithm, publicKey->key(), 654 EXPECT_TRUE(syncVerifySignature(scriptState, algorithm, publicKey->key(),
679 signature, message)); 655 signature, message));
680 } 656 }
681 657
682 TEST(V8ScriptValueSerializerForModulesTest, DecodeCryptoKeyEC) { 658 TEST(V8ScriptValueSerializerForModulesTest, DecodeCryptoKeyEC) {
683 ScopedEnableV8BasedStructuredClone enable;
684 V8TestingScope scope; 659 V8TestingScope scope;
685 ScriptState* scriptState = scope.getScriptState(); 660 ScriptState* scriptState = scope.getScriptState();
686 661
687 // Decode an ECDSA public key with the NIST P-256 curve (extractable). 662 // Decode an ECDSA public key with the NIST P-256 curve (extractable).
688 RefPtr<SerializedScriptValue> input = serializedValue( 663 RefPtr<SerializedScriptValue> input = serializedValue(
689 {0xff, 0x09, 0x3f, 0x00, 0x4b, 0x05, 0x0e, 0x01, 0x01, 0x11, 0x5b, 0x30, 664 {0xff, 0x09, 0x3f, 0x00, 0x4b, 0x05, 0x0e, 0x01, 0x01, 0x11, 0x5b, 0x30,
690 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 665 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01,
691 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 666 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42,
692 0x00, 0x04, 0xfe, 0x16, 0x70, 0x29, 0x07, 0x2c, 0x11, 0xbf, 0xcf, 0xb7, 667 0x00, 0x04, 0xfe, 0x16, 0x70, 0x29, 0x07, 0x2c, 0x11, 0xbf, 0xcf, 0xb7,
693 0x9d, 0x54, 0x35, 0x3d, 0xc7, 0x85, 0x66, 0x26, 0xa5, 0xda, 0x69, 0x4c, 668 0x9d, 0x54, 0x35, 0x3d, 0xc7, 0x85, 0x66, 0x26, 0xa5, 0xda, 0x69, 0x4c,
(...skipping 19 matching lines...) Expand all
713 0x09, 0xdb, 0xa8, 0x92, 0x48, 0x70, 0xa6, 0x6c, 0x46, 0x4d, 0x0b, 688 0x09, 0xdb, 0xa8, 0x92, 0x48, 0x70, 0xa6, 0x6c, 0x46, 0x4d, 0x0b,
714 0x83, 0x27, 0x37, 0x69, 0x4d, 0x32, 0x63, 0x1e, 0x82}; 689 0x83, 0x27, 0x37, 0x69, 0x4d, 0x32, 0x63, 0x1e, 0x82};
715 WebCryptoAlgorithm hash(WebCryptoAlgorithmIdSha256, nullptr); 690 WebCryptoAlgorithm hash(WebCryptoAlgorithmIdSha256, nullptr);
716 WebCryptoAlgorithm algorithm(WebCryptoAlgorithmIdEcdsa, 691 WebCryptoAlgorithm algorithm(WebCryptoAlgorithmIdEcdsa,
717 WTF::makeUnique<WebCryptoEcdsaParams>(hash)); 692 WTF::makeUnique<WebCryptoEcdsaParams>(hash));
718 EXPECT_TRUE(syncVerifySignature(scriptState, algorithm, newPublicKey->key(), 693 EXPECT_TRUE(syncVerifySignature(scriptState, algorithm, newPublicKey->key(),
719 signature, message)); 694 signature, message));
720 } 695 }
721 696
722 TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyNoParams) { 697 TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyNoParams) {
723 ScopedEnableV8BasedStructuredClone enable;
724 V8TestingScope scope; 698 V8TestingScope scope;
725 ScriptState* scriptState = scope.getScriptState(); 699 ScriptState* scriptState = scope.getScriptState();
726 700
727 // Import some data into a PBKDF2 state. 701 // Import some data into a PBKDF2 state.
728 WebCryptoAlgorithm importKeyAlgorithm(WebCryptoAlgorithmIdPbkdf2, nullptr); 702 WebCryptoAlgorithm importKeyAlgorithm(WebCryptoAlgorithmIdPbkdf2, nullptr);
729 CryptoKey* key = syncImportKey(scriptState, WebCryptoKeyFormatRaw, 703 CryptoKey* key = syncImportKey(scriptState, WebCryptoKeyFormatRaw,
730 Vector<uint8_t>{1, 2, 3}, importKeyAlgorithm, 704 Vector<uint8_t>{1, 2, 3}, importKeyAlgorithm,
731 false, WebCryptoKeyUsageDeriveBits); 705 false, WebCryptoKeyUsageDeriveBits);
732 706
733 // Round trip the key and check the visible attributes. 707 // Round trip the key and check the visible attributes.
(...skipping 13 matching lines...) Expand all
747 WebCryptoAlgorithm algorithm(WebCryptoAlgorithmIdPbkdf2, std::move(params)); 721 WebCryptoAlgorithm algorithm(WebCryptoAlgorithmIdPbkdf2, std::move(params));
748 WebVector<uint8_t> bitsRaw = 722 WebVector<uint8_t> bitsRaw =
749 syncDeriveBits(scriptState, algorithm, key->key(), 16); 723 syncDeriveBits(scriptState, algorithm, key->key(), 16);
750 WebVector<uint8_t> newBitsRaw = 724 WebVector<uint8_t> newBitsRaw =
751 syncDeriveBits(scriptState, algorithm, newKey->key(), 16); 725 syncDeriveBits(scriptState, algorithm, newKey->key(), 16);
752 EXPECT_EQ(2u, bitsRaw.size()); 726 EXPECT_EQ(2u, bitsRaw.size());
753 EXPECT_THAT(newBitsRaw, ElementsAreArray(bitsRaw)); 727 EXPECT_THAT(newBitsRaw, ElementsAreArray(bitsRaw));
754 } 728 }
755 729
756 TEST(V8ScriptValueSerializerForModulesTest, DecodeCryptoKeyNoParams) { 730 TEST(V8ScriptValueSerializerForModulesTest, DecodeCryptoKeyNoParams) {
757 ScopedEnableV8BasedStructuredClone enable;
758 V8TestingScope scope; 731 V8TestingScope scope;
759 ScriptState* scriptState = scope.getScriptState(); 732 ScriptState* scriptState = scope.getScriptState();
760 733
761 // Decode PBKDF2 state seeded with {1,2,3}. 734 // Decode PBKDF2 state seeded with {1,2,3}.
762 RefPtr<SerializedScriptValue> input = 735 RefPtr<SerializedScriptValue> input =
763 serializedValue({0xff, 0x09, 0x3f, 0x00, 0x4b, 0x06, 0x11, 0xa0, 0x02, 736 serializedValue({0xff, 0x09, 0x3f, 0x00, 0x4b, 0x06, 0x11, 0xa0, 0x02,
764 0x03, 0x01, 0x02, 0x03, 0x00}); 737 0x03, 0x01, 0x02, 0x03, 0x00});
765 v8::Local<v8::Value> result = 738 v8::Local<v8::Value> result =
766 V8ScriptValueDeserializerForModules(scriptState, input).deserialize(); 739 V8ScriptValueDeserializerForModules(scriptState, input).deserialize();
767 ASSERT_TRUE(V8CryptoKey::hasInstance(result, scope.isolate())); 740 ASSERT_TRUE(V8CryptoKey::hasInstance(result, scope.isolate()));
768 CryptoKey* newKey = V8CryptoKey::toImpl(result.As<v8::Object>()); 741 CryptoKey* newKey = V8CryptoKey::toImpl(result.As<v8::Object>());
769 EXPECT_EQ("secret", newKey->type()); 742 EXPECT_EQ("secret", newKey->type());
770 EXPECT_FALSE(newKey->extractable()); 743 EXPECT_FALSE(newKey->extractable());
771 EXPECT_THAT(newKey->usages(), 744 EXPECT_THAT(newKey->usages(),
772 UnorderedElementsAre("deriveKey", "deriveBits")); 745 UnorderedElementsAre("deriveKey", "deriveBits"));
773 746
774 // Check that it derives the right bits. 747 // Check that it derives the right bits.
775 WebCryptoAlgorithm hash(WebCryptoAlgorithmIdSha256, nullptr); 748 WebCryptoAlgorithm hash(WebCryptoAlgorithmIdSha256, nullptr);
776 WebVector<uint8_t> salt(static_cast<size_t>(16)); 749 WebVector<uint8_t> salt(static_cast<size_t>(16));
777 std::unique_ptr<WebCryptoAlgorithmParams> params( 750 std::unique_ptr<WebCryptoAlgorithmParams> params(
778 new WebCryptoPbkdf2Params(hash, salt, 3)); 751 new WebCryptoPbkdf2Params(hash, salt, 3));
779 WebCryptoAlgorithm algorithm(WebCryptoAlgorithmIdPbkdf2, std::move(params)); 752 WebCryptoAlgorithm algorithm(WebCryptoAlgorithmIdPbkdf2, std::move(params));
780 WebVector<uint8_t> bitsRaw = 753 WebVector<uint8_t> bitsRaw =
781 syncDeriveBits(scriptState, algorithm, newKey->key(), 32); 754 syncDeriveBits(scriptState, algorithm, newKey->key(), 32);
782 EXPECT_THAT(bitsRaw, ElementsAre(0xd8, 0x0e, 0x2f, 0x69)); 755 EXPECT_THAT(bitsRaw, ElementsAre(0xd8, 0x0e, 0x2f, 0x69));
783 } 756 }
784 757
785 TEST(V8ScriptValueSerializerForModulesTest, DecodeCryptoKeyInvalid) { 758 TEST(V8ScriptValueSerializerForModulesTest, DecodeCryptoKeyInvalid) {
786 ScopedEnableV8BasedStructuredClone enable;
787 V8TestingScope scope; 759 V8TestingScope scope;
788 ScriptState* scriptState = scope.getScriptState(); 760 ScriptState* scriptState = scope.getScriptState();
789 761
790 // Invalid algorithm ID. 762 // Invalid algorithm ID.
791 EXPECT_TRUE(V8ScriptValueDeserializerForModules( 763 EXPECT_TRUE(V8ScriptValueDeserializerForModules(
792 scriptState, 764 scriptState,
793 serializedValue({0xff, 0x09, 0x3f, 0x00, 0x4b, 0x06, 0x7f, 765 serializedValue({0xff, 0x09, 0x3f, 0x00, 0x4b, 0x06, 0x7f,
794 0xa0, 0x02, 0x03, 0x01, 0x02, 0x03, 0x00})) 766 0xa0, 0x02, 0x03, 0x01, 0x02, 0x03, 0x00}))
795 .deserialize() 767 .deserialize()
796 ->IsNull()); 768 ->IsNull());
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 // Input ends before end of declared public exponent size. 852 // Input ends before end of declared public exponent size.
881 EXPECT_TRUE( 853 EXPECT_TRUE(
882 V8ScriptValueDeserializerForModules( 854 V8ScriptValueDeserializerForModules(
883 scriptState, serializedValue({0xff, 0x09, 0x3f, 0x00, 0x4b, 0x04, 855 scriptState, serializedValue({0xff, 0x09, 0x3f, 0x00, 0x4b, 0x04,
884 0x0d, 0x01, 0x80, 0x08, 0x03, 0x01})) 856 0x0d, 0x01, 0x80, 0x08, 0x03, 0x01}))
885 .deserialize() 857 .deserialize()
886 ->IsNull()); 858 ->IsNull());
887 } 859 }
888 860
889 TEST(V8ScriptValueSerializerForModulesTest, RoundTripDOMFileSystem) { 861 TEST(V8ScriptValueSerializerForModulesTest, RoundTripDOMFileSystem) {
890 ScopedEnableV8BasedStructuredClone enable;
891 V8TestingScope scope; 862 V8TestingScope scope;
892 863
893 DOMFileSystem* fs = DOMFileSystem::create( 864 DOMFileSystem* fs = DOMFileSystem::create(
894 scope.getExecutionContext(), "http_example.com_0:Persistent", 865 scope.getExecutionContext(), "http_example.com_0:Persistent",
895 FileSystemTypePersistent, 866 FileSystemTypePersistent,
896 KURL(ParsedURLString, "filesystem:http://example.com/persistent/")); 867 KURL(ParsedURLString, "filesystem:http://example.com/persistent/"));
897 // At time of writing, this can only happen for filesystems from PPAPI. 868 // At time of writing, this can only happen for filesystems from PPAPI.
898 fs->makeClonable(); 869 fs->makeClonable();
899 v8::Local<v8::Value> wrapper = ToV8(fs, scope.getScriptState()); 870 v8::Local<v8::Value> wrapper = ToV8(fs, scope.getScriptState());
900 v8::Local<v8::Value> result = roundTrip(wrapper, scope); 871 v8::Local<v8::Value> result = roundTrip(wrapper, scope);
901 ASSERT_FALSE(result.IsEmpty()); 872 ASSERT_FALSE(result.IsEmpty());
902 ASSERT_TRUE(V8DOMFileSystem::hasInstance(result, scope.isolate())); 873 ASSERT_TRUE(V8DOMFileSystem::hasInstance(result, scope.isolate()));
903 DOMFileSystem* newFS = V8DOMFileSystem::toImpl(result.As<v8::Object>()); 874 DOMFileSystem* newFS = V8DOMFileSystem::toImpl(result.As<v8::Object>());
904 EXPECT_EQ("http_example.com_0:Persistent", newFS->name()); 875 EXPECT_EQ("http_example.com_0:Persistent", newFS->name());
905 EXPECT_EQ(FileSystemTypePersistent, newFS->type()); 876 EXPECT_EQ(FileSystemTypePersistent, newFS->type());
906 EXPECT_EQ("filesystem:http://example.com/persistent/", 877 EXPECT_EQ("filesystem:http://example.com/persistent/",
907 newFS->rootURL().getString()); 878 newFS->rootURL().getString());
908 } 879 }
909 880
910 TEST(V8ScriptValueSerializerForModulesTest, RoundTripDOMFileSystemNotClonable) { 881 TEST(V8ScriptValueSerializerForModulesTest, RoundTripDOMFileSystemNotClonable) {
911 ScopedEnableV8BasedStructuredClone enable;
912 V8TestingScope scope; 882 V8TestingScope scope;
913 ExceptionState exceptionState(scope.isolate(), 883 ExceptionState exceptionState(scope.isolate(),
914 ExceptionState::ExecutionContext, "Window", 884 ExceptionState::ExecutionContext, "Window",
915 "postMessage"); 885 "postMessage");
916 886
917 DOMFileSystem* fs = DOMFileSystem::create( 887 DOMFileSystem* fs = DOMFileSystem::create(
918 scope.getExecutionContext(), "http_example.com_0:Persistent", 888 scope.getExecutionContext(), "http_example.com_0:Persistent",
919 FileSystemTypePersistent, 889 FileSystemTypePersistent,
920 KURL(ParsedURLString, "filesystem:http://example.com/persistent/0/")); 890 KURL(ParsedURLString, "filesystem:http://example.com/persistent/0/"));
921 ASSERT_FALSE(fs->clonable()); 891 ASSERT_FALSE(fs->clonable());
922 v8::Local<v8::Value> wrapper = ToV8(fs, scope.getScriptState()); 892 v8::Local<v8::Value> wrapper = ToV8(fs, scope.getScriptState());
923 EXPECT_FALSE(V8ScriptValueSerializer(scope.getScriptState()) 893 EXPECT_FALSE(V8ScriptValueSerializer(scope.getScriptState())
924 .serialize(wrapper, nullptr, exceptionState)); 894 .serialize(wrapper, nullptr, exceptionState));
925 EXPECT_TRUE(hadDOMException("DataCloneError", scope.getScriptState(), 895 EXPECT_TRUE(hadDOMException("DataCloneError", scope.getScriptState(),
926 exceptionState)); 896 exceptionState));
927 } 897 }
928 898
929 TEST(V8ScriptValueSerializerForModulesTest, DecodeDOMFileSystem) { 899 TEST(V8ScriptValueSerializerForModulesTest, DecodeDOMFileSystem) {
930 ScopedEnableV8BasedStructuredClone enable;
931 V8TestingScope scope; 900 V8TestingScope scope;
932 901
933 // This is encoded data generated from Chromium (around M56). 902 // This is encoded data generated from Chromium (around M56).
934 ScriptState* scriptState = scope.getScriptState(); 903 ScriptState* scriptState = scope.getScriptState();
935 RefPtr<SerializedScriptValue> input = serializedValue( 904 RefPtr<SerializedScriptValue> input = serializedValue(
936 {0xff, 0x09, 0x3f, 0x00, 0x64, 0x01, 0x1d, 0x68, 0x74, 0x74, 0x70, 0x5f, 905 {0xff, 0x09, 0x3f, 0x00, 0x64, 0x01, 0x1d, 0x68, 0x74, 0x74, 0x70, 0x5f,
937 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x5f, 906 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x5f,
938 0x30, 0x3a, 0x50, 0x65, 0x72, 0x73, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x74, 907 0x30, 0x3a, 0x50, 0x65, 0x72, 0x73, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x74,
939 0x29, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x3a, 908 0x29, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x3a,
940 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 909 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70,
941 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x65, 0x72, 0x73, 0x69, 910 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x65, 0x72, 0x73, 0x69,
942 0x73, 0x74, 0x65, 0x6e, 0x74, 0x2f}); 911 0x73, 0x74, 0x65, 0x6e, 0x74, 0x2f});
943 912
944 // Decode test. 913 // Decode test.
945 v8::Local<v8::Value> result = 914 v8::Local<v8::Value> result =
946 V8ScriptValueDeserializerForModules(scriptState, input).deserialize(); 915 V8ScriptValueDeserializerForModules(scriptState, input).deserialize();
947 ASSERT_TRUE(V8DOMFileSystem::hasInstance(result, scope.isolate())); 916 ASSERT_TRUE(V8DOMFileSystem::hasInstance(result, scope.isolate()));
948 DOMFileSystem* newFS = V8DOMFileSystem::toImpl(result.As<v8::Object>()); 917 DOMFileSystem* newFS = V8DOMFileSystem::toImpl(result.As<v8::Object>());
949 EXPECT_EQ("http_example.com_0:Persistent", newFS->name()); 918 EXPECT_EQ("http_example.com_0:Persistent", newFS->name());
950 EXPECT_EQ(FileSystemTypePersistent, newFS->type()); 919 EXPECT_EQ(FileSystemTypePersistent, newFS->type());
951 EXPECT_EQ("filesystem:http://example.com/persistent/", 920 EXPECT_EQ("filesystem:http://example.com/persistent/",
952 newFS->rootURL().getString()); 921 newFS->rootURL().getString());
953 } 922 }
954 923
955 TEST(V8ScriptValueSerializerForModulesTest, DecodeInvalidDOMFileSystem) { 924 TEST(V8ScriptValueSerializerForModulesTest, DecodeInvalidDOMFileSystem) {
956 ScopedEnableV8BasedStructuredClone enable;
957 V8TestingScope scope; 925 V8TestingScope scope;
958 ScriptState* scriptState = scope.getScriptState(); 926 ScriptState* scriptState = scope.getScriptState();
959 927
960 // Filesystem type out of range. 928 // Filesystem type out of range.
961 EXPECT_TRUE( 929 EXPECT_TRUE(
962 V8ScriptValueDeserializerForModules( 930 V8ScriptValueDeserializerForModules(
963 scriptState, 931 scriptState,
964 serializedValue({0xff, 0x09, 0x3f, 0x00, 0x64, 0x04, 0x1d, 0x68, 0x74, 932 serializedValue({0xff, 0x09, 0x3f, 0x00, 0x64, 0x04, 0x1d, 0x68, 0x74,
965 0x74, 0x70, 0x5f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 933 0x74, 0x70, 0x5f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c,
966 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x5f, 0x30, 0x3a, 0x50, 934 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x5f, 0x30, 0x3a, 0x50,
967 0x65, 0x72, 0x73, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x74, 935 0x65, 0x72, 0x73, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x74,
968 0x29, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x79, 0x73, 0x74, 936 0x29, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x79, 0x73, 0x74,
969 0x65, 0x6d, 0x3a, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 937 0x65, 0x6d, 0x3a, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f,
970 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 938 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e,
971 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x65, 0x72, 0x73, 0x69, 939 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x65, 0x72, 0x73, 0x69,
972 0x73, 0x74, 0x65, 0x6e, 0x74, 0x2f 940 0x73, 0x74, 0x65, 0x6e, 0x74, 0x2f
973 941
974 })) 942 }))
975 .deserialize() 943 .deserialize()
976 ->IsNull()); 944 ->IsNull());
977 } 945 }
978 946
979 } // namespace 947 } // namespace
980 } // namespace blink 948 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698