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