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

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

Issue 2494333002: Replace wrapUnique(new T(args)) by makeUnique<T>(args) in Blink (Closed)
Patch Set: Drop redundant WTF:: 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"
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 420
421 // Check that the keys have the same raw representation. 421 // Check that the keys have the same raw representation.
422 WebVector<uint8_t> keyRaw = 422 WebVector<uint8_t> keyRaw =
423 syncExportKey(scriptState, WebCryptoKeyFormatRaw, key->key()); 423 syncExportKey(scriptState, WebCryptoKeyFormatRaw, key->key());
424 WebVector<uint8_t> newKeyRaw = 424 WebVector<uint8_t> newKeyRaw =
425 syncExportKey(scriptState, WebCryptoKeyFormatRaw, newKey->key()); 425 syncExportKey(scriptState, WebCryptoKeyFormatRaw, newKey->key());
426 EXPECT_THAT(newKeyRaw, ElementsAreArray(keyRaw)); 426 EXPECT_THAT(newKeyRaw, ElementsAreArray(keyRaw));
427 427
428 // Check that one can decrypt data encrypted with the other. 428 // Check that one can decrypt data encrypted with the other.
429 Vector<unsigned char> iv(16, 0); 429 Vector<unsigned char> iv(16, 0);
430 WebCryptoAlgorithm encryptAlgorithm( 430 WebCryptoAlgorithm encryptAlgorithm(WebCryptoAlgorithmIdAesCbc,
431 WebCryptoAlgorithmIdAesCbc, wrapUnique(new WebCryptoAesCbcParams(iv))); 431 makeUnique<WebCryptoAesCbcParams>(iv));
432 Vector<unsigned char> plaintext{1, 2, 3}; 432 Vector<unsigned char> plaintext{1, 2, 3};
433 WebVector<uint8_t> ciphertext = 433 WebVector<uint8_t> ciphertext =
434 syncEncrypt(scriptState, encryptAlgorithm, key->key(), plaintext); 434 syncEncrypt(scriptState, encryptAlgorithm, key->key(), plaintext);
435 WebVector<uint8_t> newPlaintext = 435 WebVector<uint8_t> newPlaintext =
436 syncDecrypt(scriptState, encryptAlgorithm, newKey->key(), ciphertext); 436 syncDecrypt(scriptState, encryptAlgorithm, newKey->key(), ciphertext);
437 EXPECT_THAT(newPlaintext, ElementsAre(1, 2, 3)); 437 EXPECT_THAT(newPlaintext, ElementsAre(1, 2, 3));
438 } 438 }
439 439
440 TEST(V8ScriptValueSerializerForModulesTest, DecodeCryptoKeyAES) { 440 TEST(V8ScriptValueSerializerForModulesTest, DecodeCryptoKeyAES) {
441 ScopedEnableV8BasedStructuredClone enable; 441 ScopedEnableV8BasedStructuredClone enable;
(...skipping 10 matching lines...) Expand all
452 ASSERT_TRUE(V8CryptoKey::hasInstance(result, scope.isolate())); 452 ASSERT_TRUE(V8CryptoKey::hasInstance(result, scope.isolate()));
453 CryptoKey* newKey = V8CryptoKey::toImpl(result.As<v8::Object>()); 453 CryptoKey* newKey = V8CryptoKey::toImpl(result.As<v8::Object>());
454 EXPECT_EQ("secret", newKey->type()); 454 EXPECT_EQ("secret", newKey->type());
455 EXPECT_FALSE(newKey->extractable()); 455 EXPECT_FALSE(newKey->extractable());
456 EXPECT_THAT(newKey->usages(), UnorderedElementsAre("decrypt")); 456 EXPECT_THAT(newKey->usages(), UnorderedElementsAre("decrypt"));
457 457
458 // Check that it can successfully decrypt data. 458 // Check that it can successfully decrypt data.
459 Vector<uint8_t> iv(16, 0); 459 Vector<uint8_t> iv(16, 0);
460 Vector<uint8_t> ciphertext{0x33, 0x26, 0xe7, 0x64, 0x11, 0x5e, 0xf4, 0x60, 460 Vector<uint8_t> ciphertext{0x33, 0x26, 0xe7, 0x64, 0x11, 0x5e, 0xf4, 0x60,
461 0x96, 0x08, 0x11, 0xaf, 0x65, 0x8b, 0x87, 0x04}; 461 0x96, 0x08, 0x11, 0xaf, 0x65, 0x8b, 0x87, 0x04};
462 WebCryptoAlgorithm encryptAlgorithm( 462 WebCryptoAlgorithm encryptAlgorithm(WebCryptoAlgorithmIdAesCbc,
463 WebCryptoAlgorithmIdAesCbc, wrapUnique(new WebCryptoAesCbcParams(iv))); 463 makeUnique<WebCryptoAesCbcParams>(iv));
464 WebVector<uint8_t> plaintext = 464 WebVector<uint8_t> plaintext =
465 syncDecrypt(scriptState, encryptAlgorithm, newKey->key(), ciphertext); 465 syncDecrypt(scriptState, encryptAlgorithm, newKey->key(), ciphertext);
466 EXPECT_THAT(plaintext, ElementsAre(1, 2, 3)); 466 EXPECT_THAT(plaintext, ElementsAre(1, 2, 3));
467 } 467 }
468 468
469 // HMAC-SHA256 uses HMAC key params. 469 // HMAC-SHA256 uses HMAC key params.
470 TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyHMAC) { 470 TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyHMAC) {
471 ScopedEnableV8BasedStructuredClone enable; 471 ScopedEnableV8BasedStructuredClone enable;
472 V8TestingScope scope; 472 V8TestingScope scope;
473 ScriptState* scriptState = scope.getScriptState(); 473 ScriptState* scriptState = scope.getScriptState();
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 // Check that the keys have the same PKCS8 representation. 570 // Check that the keys have the same PKCS8 representation.
571 WebVector<uint8_t> keyRaw = 571 WebVector<uint8_t> keyRaw =
572 syncExportKey(scriptState, WebCryptoKeyFormatPkcs8, privateKey->key()); 572 syncExportKey(scriptState, WebCryptoKeyFormatPkcs8, privateKey->key());
573 WebVector<uint8_t> newKeyRaw = 573 WebVector<uint8_t> newKeyRaw =
574 syncExportKey(scriptState, WebCryptoKeyFormatPkcs8, newPrivateKey->key()); 574 syncExportKey(scriptState, WebCryptoKeyFormatPkcs8, newPrivateKey->key());
575 EXPECT_THAT(newKeyRaw, ElementsAreArray(keyRaw)); 575 EXPECT_THAT(newKeyRaw, ElementsAreArray(keyRaw));
576 576
577 // Check that one can verify a message signed by the other. 577 // Check that one can verify a message signed by the other.
578 Vector<uint8_t> message{1, 2, 3}; 578 Vector<uint8_t> message{1, 2, 3};
579 WebCryptoAlgorithm algorithm(WebCryptoAlgorithmIdRsaPss, 579 WebCryptoAlgorithm algorithm(WebCryptoAlgorithmIdRsaPss,
580 wrapUnique(new WebCryptoRsaPssParams(16))); 580 makeUnique<WebCryptoRsaPssParams>(16));
581 WebVector<uint8_t> signature = 581 WebVector<uint8_t> signature =
582 syncSign(scriptState, algorithm, newPrivateKey->key(), message); 582 syncSign(scriptState, algorithm, newPrivateKey->key(), message);
583 EXPECT_TRUE(syncVerifySignature(scriptState, algorithm, publicKey->key(), 583 EXPECT_TRUE(syncVerifySignature(scriptState, algorithm, publicKey->key(),
584 signature, message)); 584 signature, message));
585 } 585 }
586 586
587 TEST(V8ScriptValueSerializerForModulesTest, DecodeCryptoKeyRSAHashed) { 587 TEST(V8ScriptValueSerializerForModulesTest, DecodeCryptoKeyRSAHashed) {
588 ScopedEnableV8BasedStructuredClone enable; 588 ScopedEnableV8BasedStructuredClone enable;
589 V8TestingScope scope; 589 V8TestingScope scope;
590 ScriptState* scriptState = scope.getScriptState(); 590 ScriptState* scriptState = scope.getScriptState();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 0x98, 0x1f, 0xf3, 0x9d, 0x32, 0x87, 0xdc, 0xbb, 0xb6, 0x3a, 0xa4, 0x6d, 622 0x98, 0x1f, 0xf3, 0x9d, 0x32, 0x87, 0xdc, 0xbb, 0xb6, 0x3a, 0xa4, 0x6d,
623 0xd4, 0xb5, 0x52, 0x83, 0x24, 0x02, 0xc7, 0x62, 0x1f, 0xb7, 0x27, 0x2b, 623 0xd4, 0xb5, 0x52, 0x83, 0x24, 0x02, 0xc7, 0x62, 0x1f, 0xb7, 0x27, 0x2b,
624 0x5a, 0x54, 0x59, 0x17, 0x81, 0x8a, 0xf5, 0x0c, 0x17, 0x01, 0x45, 0x3f, 624 0x5a, 0x54, 0x59, 0x17, 0x81, 0x8a, 0xf5, 0x0c, 0x17, 0x01, 0x45, 0x3f,
625 0x14, 0xf2, 0x3c, 0x27, 0x4d, 0xfa, 0xc0, 0x0a, 0x82, 0x4b, 0xb2, 0xf4, 625 0x14, 0xf2, 0x3c, 0x27, 0x4d, 0xfa, 0xc0, 0x0a, 0x82, 0x4b, 0xb2, 0xf4,
626 0x7b, 0x14, 0x1b, 0xd8, 0xbc, 0xe9, 0x2e, 0xd4, 0x55, 0x27, 0x62, 0x83, 626 0x7b, 0x14, 0x1b, 0xd8, 0xbc, 0xe9, 0x2e, 0xd4, 0x55, 0x27, 0x62, 0x83,
627 0x11, 0xed, 0xc2, 0x81, 0x7d, 0xa9, 0x4f, 0xe0, 0xef, 0x0e, 0xa5, 0xa5, 627 0x11, 0xed, 0xc2, 0x81, 0x7d, 0xa9, 0x4f, 0xe0, 0xef, 0x0e, 0xa5, 0xa5,
628 0xc6, 0x40, 0x46, 0xbf, 0x90, 0x19, 0xfc, 0xc8, 0x51, 0x0e, 0x0f, 0x62, 628 0xc6, 0x40, 0x46, 0xbf, 0x90, 0x19, 0xfc, 0xc8, 0x51, 0x0e, 0x0f, 0x62,
629 0xeb, 0x17, 0x68, 0x1f, 0xbd, 0xfa, 0xf7, 0xd6, 0x1f, 0xa4, 0x7c, 0x9e, 629 0xeb, 0x17, 0x68, 0x1f, 0xbd, 0xfa, 0xf7, 0xd6, 0x1f, 0xa4, 0x7c, 0x9e,
630 0x9e, 0xb1, 0x96, 0x8f, 0xe6, 0x5e, 0x89, 0x99}; 630 0x9e, 0xb1, 0x96, 0x8f, 0xe6, 0x5e, 0x89, 0x99};
631 WebCryptoAlgorithm algorithm(WebCryptoAlgorithmIdRsaPss, 631 WebCryptoAlgorithm algorithm(WebCryptoAlgorithmIdRsaPss,
632 wrapUnique(new WebCryptoRsaPssParams(16))); 632 makeUnique<WebCryptoRsaPssParams>(16));
633 EXPECT_TRUE(syncVerifySignature(scriptState, algorithm, newPublicKey->key(), 633 EXPECT_TRUE(syncVerifySignature(scriptState, algorithm, newPublicKey->key(),
634 signature, message)); 634 signature, message));
635 } 635 }
636 636
637 // ECDSA uses EC key params. 637 // ECDSA uses EC key params.
638 TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyEC) { 638 TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyEC) {
639 ScopedEnableV8BasedStructuredClone enable; 639 ScopedEnableV8BasedStructuredClone enable;
640 V8TestingScope scope; 640 V8TestingScope scope;
641 ScriptState* scriptState = scope.getScriptState(); 641 ScriptState* scriptState = scope.getScriptState();
642 642
(...skipping 21 matching lines...) Expand all
664 WebVector<uint8_t> keyRaw = 664 WebVector<uint8_t> keyRaw =
665 syncExportKey(scriptState, WebCryptoKeyFormatPkcs8, privateKey->key()); 665 syncExportKey(scriptState, WebCryptoKeyFormatPkcs8, privateKey->key());
666 WebVector<uint8_t> newKeyRaw = 666 WebVector<uint8_t> newKeyRaw =
667 syncExportKey(scriptState, WebCryptoKeyFormatPkcs8, newPrivateKey->key()); 667 syncExportKey(scriptState, WebCryptoKeyFormatPkcs8, newPrivateKey->key());
668 EXPECT_THAT(newKeyRaw, ElementsAreArray(keyRaw)); 668 EXPECT_THAT(newKeyRaw, ElementsAreArray(keyRaw));
669 669
670 // Check that one can verify a message signed by the other. 670 // Check that one can verify a message signed by the other.
671 WebCryptoAlgorithm hash(WebCryptoAlgorithmIdSha256, nullptr); 671 WebCryptoAlgorithm hash(WebCryptoAlgorithmIdSha256, nullptr);
672 Vector<uint8_t> message{1, 2, 3}; 672 Vector<uint8_t> message{1, 2, 3};
673 WebCryptoAlgorithm algorithm(WebCryptoAlgorithmIdEcdsa, 673 WebCryptoAlgorithm algorithm(WebCryptoAlgorithmIdEcdsa,
674 wrapUnique(new WebCryptoEcdsaParams(hash))); 674 makeUnique<WebCryptoEcdsaParams>(hash));
675 WebVector<uint8_t> signature = 675 WebVector<uint8_t> signature =
676 syncSign(scriptState, algorithm, newPrivateKey->key(), message); 676 syncSign(scriptState, algorithm, newPrivateKey->key(), message);
677 EXPECT_TRUE(syncVerifySignature(scriptState, algorithm, publicKey->key(), 677 EXPECT_TRUE(syncVerifySignature(scriptState, algorithm, publicKey->key(),
678 signature, message)); 678 signature, message));
679 } 679 }
680 680
681 TEST(V8ScriptValueSerializerForModulesTest, DecodeCryptoKeyEC) { 681 TEST(V8ScriptValueSerializerForModulesTest, DecodeCryptoKeyEC) {
682 ScopedEnableV8BasedStructuredClone enable; 682 ScopedEnableV8BasedStructuredClone enable;
683 V8TestingScope scope; 683 V8TestingScope scope;
684 ScriptState* scriptState = scope.getScriptState(); 684 ScriptState* scriptState = scope.getScriptState();
(...skipping 21 matching lines...) Expand all
706 Vector<uint8_t> message{1, 2, 3}; 706 Vector<uint8_t> message{1, 2, 3};
707 Vector<uint8_t> signature{ 707 Vector<uint8_t> signature{
708 0xee, 0x63, 0xa2, 0xa3, 0x87, 0x6c, 0x9f, 0xc5, 0x64, 0x12, 0x87, 708 0xee, 0x63, 0xa2, 0xa3, 0x87, 0x6c, 0x9f, 0xc5, 0x64, 0x12, 0x87,
709 0x0d, 0xc7, 0xff, 0x3c, 0xd2, 0x6c, 0x2b, 0x2c, 0x0b, 0x2b, 0x8d, 709 0x0d, 0xc7, 0xff, 0x3c, 0xd2, 0x6c, 0x2b, 0x2c, 0x0b, 0x2b, 0x8d,
710 0x3c, 0xe0, 0x3f, 0xd3, 0xfc, 0x28, 0xf0, 0xa1, 0x22, 0x69, 0x0a, 710 0x3c, 0xe0, 0x3f, 0xd3, 0xfc, 0x28, 0xf0, 0xa1, 0x22, 0x69, 0x0a,
711 0x33, 0x4d, 0x48, 0x97, 0xad, 0x67, 0xa9, 0x6e, 0x24, 0xe7, 0x31, 711 0x33, 0x4d, 0x48, 0x97, 0xad, 0x67, 0xa9, 0x6e, 0x24, 0xe7, 0x31,
712 0x09, 0xdb, 0xa8, 0x92, 0x48, 0x70, 0xa6, 0x6c, 0x46, 0x4d, 0x0b, 712 0x09, 0xdb, 0xa8, 0x92, 0x48, 0x70, 0xa6, 0x6c, 0x46, 0x4d, 0x0b,
713 0x83, 0x27, 0x37, 0x69, 0x4d, 0x32, 0x63, 0x1e, 0x82}; 713 0x83, 0x27, 0x37, 0x69, 0x4d, 0x32, 0x63, 0x1e, 0x82};
714 WebCryptoAlgorithm hash(WebCryptoAlgorithmIdSha256, nullptr); 714 WebCryptoAlgorithm hash(WebCryptoAlgorithmIdSha256, nullptr);
715 WebCryptoAlgorithm algorithm(WebCryptoAlgorithmIdEcdsa, 715 WebCryptoAlgorithm algorithm(WebCryptoAlgorithmIdEcdsa,
716 wrapUnique(new WebCryptoEcdsaParams(hash))); 716 makeUnique<WebCryptoEcdsaParams>(hash));
717 EXPECT_TRUE(syncVerifySignature(scriptState, algorithm, newPublicKey->key(), 717 EXPECT_TRUE(syncVerifySignature(scriptState, algorithm, newPublicKey->key(),
718 signature, message)); 718 signature, message));
719 } 719 }
720 720
721 TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyNoParams) { 721 TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyNoParams) {
722 ScopedEnableV8BasedStructuredClone enable; 722 ScopedEnableV8BasedStructuredClone enable;
723 V8TestingScope scope; 723 V8TestingScope scope;
724 ScriptState* scriptState = scope.getScriptState(); 724 ScriptState* scriptState = scope.getScriptState();
725 725
726 // Import some data into a PBKDF2 state. 726 // Import some data into a PBKDF2 state.
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x65, 0x72, 0x73, 0x69, 960 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x65, 0x72, 0x73, 0x69,
961 0x73, 0x74, 0x65, 0x6e, 0x74, 0x2f 961 0x73, 0x74, 0x65, 0x6e, 0x74, 0x2f
962 962
963 })) 963 }))
964 .deserialize() 964 .deserialize()
965 ->IsNull()); 965 ->IsNull());
966 } 966 }
967 967
968 } // namespace 968 } // namespace
969 } // namespace blink 969 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698