Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "media/cdm/aes_decryptor.h" | 5 #include "media/cdm/aes_decryptor.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 // for AesDecryptor. | 332 // for AesDecryptor. |
| 333 return session_id_; | 333 return session_id_; |
| 334 } | 334 } |
| 335 | 335 |
| 336 // Closes the session specified by |session_id|. | 336 // Closes the session specified by |session_id|. |
| 337 void CloseSession(const std::string& session_id) { | 337 void CloseSession(const std::string& session_id) { |
| 338 EXPECT_CALL(*this, OnSessionClosed(session_id)); | 338 EXPECT_CALL(*this, OnSessionClosed(session_id)); |
| 339 cdm_->CloseSession(session_id, CreatePromise(RESOLVED)); | 339 cdm_->CloseSession(session_id, CreatePromise(RESOLVED)); |
| 340 } | 340 } |
| 341 | 341 |
| 342 // Removes the session specified by |session_id|. This should simply do a | 342 // Only persistent sessions can be removed. |
| 343 // CloseSession(). | |
| 344 // TODO(jrummell): Clean this up when the prefixed API is removed. | |
| 345 // http://crbug.com/249976. | |
| 346 void RemoveSession(const std::string& session_id) { | 343 void RemoveSession(const std::string& session_id) { |
| 347 if (GetParam() == "AesDecryptor") { | 344 cdm_->RemoveSession(session_id, CreatePromise(REJECTED)); |
| 348 EXPECT_CALL(*this, OnSessionClosed(session_id)); | |
| 349 cdm_->RemoveSession(session_id, CreatePromise(RESOLVED)); | |
| 350 } else { | |
| 351 // CdmAdapter fails as only persistent sessions can be removed. | |
| 352 cdm_->RemoveSession(session_id, CreatePromise(REJECTED)); | |
| 353 } | |
| 354 } | 345 } |
| 355 | 346 |
| 356 MOCK_METHOD2(OnSessionKeysChangeCalled, | 347 MOCK_METHOD2(OnSessionKeysChangeCalled, |
| 357 void(const std::string& session_id, | 348 void(const std::string& session_id, |
| 358 bool has_additional_usable_key)); | 349 bool has_additional_usable_key)); |
| 359 | 350 |
| 360 void OnSessionKeysChange(const std::string& session_id, | 351 void OnSessionKeysChange(const std::string& session_id, |
| 361 bool has_additional_usable_key, | 352 bool has_additional_usable_key, |
| 362 CdmKeysInfo keys_info) { | 353 CdmKeysInfo keys_info) { |
| 363 keys_info_.swap(keys_info); | 354 keys_info_.swap(keys_info); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 490 // Constants for testing. | 481 // Constants for testing. |
| 491 const std::vector<uint8_t> original_data_; | 482 const std::vector<uint8_t> original_data_; |
| 492 const std::vector<uint8_t> encrypted_data_; | 483 const std::vector<uint8_t> encrypted_data_; |
| 493 const std::vector<uint8_t> subsample_encrypted_data_; | 484 const std::vector<uint8_t> subsample_encrypted_data_; |
| 494 const std::vector<uint8_t> key_id_; | 485 const std::vector<uint8_t> key_id_; |
| 495 const std::vector<uint8_t> iv_; | 486 const std::vector<uint8_t> iv_; |
| 496 const std::vector<SubsampleEntry> normal_subsample_entries_; | 487 const std::vector<SubsampleEntry> normal_subsample_entries_; |
| 497 const std::vector<SubsampleEntry> no_subsample_entries_; | 488 const std::vector<SubsampleEntry> no_subsample_entries_; |
| 498 }; | 489 }; |
| 499 | 490 |
| 500 TEST_P(AesDecryptorTest, CreateSessionWithNullInitData) { | 491 TEST_P(AesDecryptorTest, CreateSessionWithEmptyInitData) { |
| 501 EXPECT_CALL(*this, | |
| 502 OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL())); | |
| 503 cdm_->CreateSessionAndGenerateRequest( | 492 cdm_->CreateSessionAndGenerateRequest( |
| 504 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, | 493 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, |
| 505 std::vector<uint8_t>(), CreateSessionPromise(RESOLVED)); | 494 std::vector<uint8_t>(), CreateSessionPromise(REJECTED)); |
| 495 cdm_->CreateSessionAndGenerateRequest( | |
| 496 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::CENC, | |
| 497 std::vector<uint8_t>(), CreateSessionPromise(REJECTED)); | |
| 498 cdm_->CreateSessionAndGenerateRequest( | |
| 499 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::KEYIDS, | |
| 500 std::vector<uint8_t>(), CreateSessionPromise(REJECTED)); | |
| 501 } | |
| 502 | |
| 503 TEST_P(AesDecryptorTest, CreateSessionWithVariousLengthInitData_WebM) { | |
| 504 std::vector<uint8_t> init_data; | |
| 505 init_data.resize(1); | |
| 506 cdm_->CreateSessionAndGenerateRequest( | |
| 507 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, | |
| 508 std::vector<uint8_t>(init_data), CreateSessionPromise(RESOLVED)); | |
| 509 | |
| 510 init_data.resize(16); // The expected size. | |
| 511 cdm_->CreateSessionAndGenerateRequest( | |
| 512 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, | |
| 513 std::vector<uint8_t>(init_data), CreateSessionPromise(RESOLVED)); | |
| 514 | |
| 515 init_data.resize(512); | |
|
jrummell
2016/06/25 00:39:38
Should limits::kMaxKeyIdLength be used here (and +
ddorwin
2016/08/11 20:28:32
Tests should avoid using the same constants as the
jrummell
2016/08/12 19:24:25
Acknowledged.
| |
| 516 cdm_->CreateSessionAndGenerateRequest( | |
| 517 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, | |
| 518 std::vector<uint8_t>(init_data), CreateSessionPromise(RESOLVED)); | |
| 519 | |
| 520 init_data.resize(513); | |
| 521 cdm_->CreateSessionAndGenerateRequest( | |
| 522 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, | |
| 523 std::vector<uint8_t>(init_data), CreateSessionPromise(REJECTED)); | |
| 506 } | 524 } |
| 507 | 525 |
| 508 TEST_P(AesDecryptorTest, MultipleCreateSession) { | 526 TEST_P(AesDecryptorTest, MultipleCreateSession) { |
| 509 EXPECT_CALL(*this, | 527 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsNotEmpty(), |
| 510 OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL())); | 528 GURL::EmptyGURL())); |
| 511 cdm_->CreateSessionAndGenerateRequest( | 529 cdm_->CreateSessionAndGenerateRequest( |
| 512 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, | 530 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, |
| 513 std::vector<uint8_t>(), CreateSessionPromise(RESOLVED)); | 531 std::vector<uint8_t>(1), CreateSessionPromise(RESOLVED)); |
| 514 | 532 |
| 515 EXPECT_CALL(*this, | 533 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsNotEmpty(), |
| 516 OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL())); | 534 GURL::EmptyGURL())); |
| 517 cdm_->CreateSessionAndGenerateRequest( | 535 cdm_->CreateSessionAndGenerateRequest( |
| 518 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, | 536 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, |
| 519 std::vector<uint8_t>(), CreateSessionPromise(RESOLVED)); | 537 std::vector<uint8_t>(1), CreateSessionPromise(RESOLVED)); |
| 520 | 538 |
| 521 EXPECT_CALL(*this, | 539 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsNotEmpty(), |
| 522 OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL())); | 540 GURL::EmptyGURL())); |
| 523 cdm_->CreateSessionAndGenerateRequest( | 541 cdm_->CreateSessionAndGenerateRequest( |
| 524 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, | 542 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, |
| 525 std::vector<uint8_t>(), CreateSessionPromise(RESOLVED)); | 543 std::vector<uint8_t>(1), CreateSessionPromise(RESOLVED)); |
| 526 } | 544 } |
| 527 | 545 |
| 528 TEST_P(AesDecryptorTest, CreateSessionWithCencInitData) { | 546 TEST_P(AesDecryptorTest, CreateSessionWithCencInitData) { |
| 529 const uint8_t init_data[] = { | 547 const uint8_t init_data[] = { |
| 530 0x00, 0x00, 0x00, 0x44, // size = 68 | 548 0x00, 0x00, 0x00, 0x44, // size = 68 |
| 531 0x70, 0x73, 0x73, 0x68, // 'pssh' | 549 0x70, 0x73, 0x73, 0x68, // 'pssh' |
| 532 0x01, // version | 550 0x01, // version |
| 533 0x00, 0x00, 0x00, // flags | 551 0x00, 0x00, 0x00, // flags |
| 534 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID | 552 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID |
| 535 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B, | 553 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B, |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 758 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer( | 776 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer( |
| 759 encrypted_data_, key_id_, iv_, no_subsample_entries_); | 777 encrypted_data_, key_id_, iv_, no_subsample_entries_); |
| 760 | 778 |
| 761 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED, true); | 779 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED, true); |
| 762 ASSERT_NO_FATAL_FAILURE( | 780 ASSERT_NO_FATAL_FAILURE( |
| 763 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS)); | 781 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS)); |
| 764 | 782 |
| 765 CloseSession(session_id); | 783 CloseSession(session_id); |
| 766 } | 784 } |
| 767 | 785 |
| 768 TEST_P(AesDecryptorTest, RemoveSession) { | 786 // Re-enable if https://crbug.com/416194 is fixed. |
| 769 // TODO(jrummell): Clean this up when the prefixed API is removed. | 787 TEST_P(AesDecryptorTest, RemoveSession_DISABLED) { |
| 770 // http://crbug.com/249976. | |
| 771 std::string session_id = CreateSession(key_id_); | 788 std::string session_id = CreateSession(key_id_); |
| 772 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer( | 789 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer( |
| 773 encrypted_data_, key_id_, iv_, no_subsample_entries_); | 790 encrypted_data_, key_id_, iv_, no_subsample_entries_); |
| 774 | 791 |
| 775 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED, true); | 792 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED, true); |
| 776 ASSERT_NO_FATAL_FAILURE( | 793 ASSERT_NO_FATAL_FAILURE( |
| 777 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS)); | 794 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS)); |
| 778 | 795 |
| 779 RemoveSession(session_id); | 796 RemoveSession(session_id); |
| 780 } | 797 } |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1020 INSTANTIATE_TEST_CASE_P(CdmAdapter, | 1037 INSTANTIATE_TEST_CASE_P(CdmAdapter, |
| 1021 AesDecryptorTest, | 1038 AesDecryptorTest, |
| 1022 testing::Values("CdmAdapter")); | 1039 testing::Values("CdmAdapter")); |
| 1023 #endif | 1040 #endif |
| 1024 | 1041 |
| 1025 // TODO(jrummell): Once MojoCdm/MojoCdmService/MojoDecryptor/ | 1042 // TODO(jrummell): Once MojoCdm/MojoCdmService/MojoDecryptor/ |
| 1026 // MojoDecryptorService are implemented, add a third version that tests the | 1043 // MojoDecryptorService are implemented, add a third version that tests the |
| 1027 // CDM via mojo. | 1044 // CDM via mojo. |
| 1028 | 1045 |
| 1029 } // namespace media | 1046 } // namespace media |
| OLD | NEW |