| 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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 | 269 |
| 270 base::RunLoop().RunUntilIdle(); | 270 base::RunLoop().RunUntilIdle(); |
| 271 } | 271 } |
| 272 } | 272 } |
| 273 | 273 |
| 274 void TearDown() override { | 274 void TearDown() override { |
| 275 if (GetParam() == "CdmAdapter") | 275 if (GetParam() == "CdmAdapter") |
| 276 helper_.reset(); | 276 helper_.reset(); |
| 277 } | 277 } |
| 278 | 278 |
| 279 void OnCdmCreated(const scoped_refptr<MediaKeys>& cdm, | 279 void OnCdmCreated(const scoped_refptr<ContentDecryptionModule>& cdm, |
| 280 const std::string& error_message) { | 280 const std::string& error_message) { |
| 281 EXPECT_EQ(error_message, ""); | 281 EXPECT_EQ(error_message, ""); |
| 282 cdm_ = cdm; | 282 cdm_ = cdm; |
| 283 decryptor_ = cdm_->GetCdmContext()->GetDecryptor(); | 283 decryptor_ = cdm_->GetCdmContext()->GetDecryptor(); |
| 284 } | 284 } |
| 285 | 285 |
| 286 void OnResolveWithSession(ExpectedResult expected_result, | 286 void OnResolveWithSession(ExpectedResult expected_result, |
| 287 const std::string& session_id) { | 287 const std::string& session_id) { |
| 288 EXPECT_EQ(expected_result, RESOLVED) << "Unexpectedly resolved."; | 288 EXPECT_EQ(expected_result, RESOLVED) << "Unexpectedly resolved."; |
| 289 EXPECT_GT(session_id.length(), 0ul); | 289 EXPECT_GT(session_id.length(), 0ul); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 base::Bind(&AesDecryptorTest::OnReject, base::Unretained(this), | 321 base::Bind(&AesDecryptorTest::OnReject, base::Unretained(this), |
| 322 expected_result))); | 322 expected_result))); |
| 323 return promise; | 323 return promise; |
| 324 } | 324 } |
| 325 | 325 |
| 326 // Creates a new session using |key_id|. Returns the session ID. | 326 // Creates a new session using |key_id|. Returns the session ID. |
| 327 std::string CreateSession(const std::vector<uint8_t>& key_id) { | 327 std::string CreateSession(const std::vector<uint8_t>& key_id) { |
| 328 DCHECK(!key_id.empty()); | 328 DCHECK(!key_id.empty()); |
| 329 EXPECT_CALL(cdm_client_, | 329 EXPECT_CALL(cdm_client_, |
| 330 OnSessionMessage(NotEmpty(), _, IsJSONDictionary())); | 330 OnSessionMessage(NotEmpty(), _, IsJSONDictionary())); |
| 331 cdm_->CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION, | 331 cdm_->CreateSessionAndGenerateRequest( |
| 332 EmeInitDataType::WEBM, key_id, | 332 ContentDecryptionModule::TEMPORARY_SESSION, EmeInitDataType::WEBM, |
| 333 CreateSessionPromise(RESOLVED)); | 333 key_id, CreateSessionPromise(RESOLVED)); |
| 334 // This expects the promise to be called synchronously, which is the case | 334 // This expects the promise to be called synchronously, which is the case |
| 335 // for AesDecryptor. | 335 // for AesDecryptor. |
| 336 return session_id_; | 336 return session_id_; |
| 337 } | 337 } |
| 338 | 338 |
| 339 // Closes the session specified by |session_id|. | 339 // Closes the session specified by |session_id|. |
| 340 void CloseSession(const std::string& session_id) { | 340 void CloseSession(const std::string& session_id) { |
| 341 EXPECT_CALL(cdm_client_, OnSessionClosed(session_id)); | 341 EXPECT_CALL(cdm_client_, OnSessionClosed(session_id)); |
| 342 cdm_->CloseSession(session_id, CreatePromise(RESOLVED)); | 342 cdm_->CloseSession(session_id, CreatePromise(RESOLVED)); |
| 343 } | 343 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 break; | 439 break; |
| 440 } | 440 } |
| 441 } | 441 } |
| 442 | 442 |
| 443 std::unique_ptr<CdmFileIO> CreateCdmFileIO(cdm::FileIOClient* client) { | 443 std::unique_ptr<CdmFileIO> CreateCdmFileIO(cdm::FileIOClient* client) { |
| 444 ADD_FAILURE() << "Should never be called"; | 444 ADD_FAILURE() << "Should never be called"; |
| 445 return nullptr; | 445 return nullptr; |
| 446 } | 446 } |
| 447 | 447 |
| 448 StrictMock<MockCdmClient> cdm_client_; | 448 StrictMock<MockCdmClient> cdm_client_; |
| 449 scoped_refptr<MediaKeys> cdm_; | 449 scoped_refptr<ContentDecryptionModule> cdm_; |
| 450 Decryptor* decryptor_; | 450 Decryptor* decryptor_; |
| 451 Decryptor::DecryptCB decrypt_cb_; | 451 Decryptor::DecryptCB decrypt_cb_; |
| 452 std::string session_id_; | 452 std::string session_id_; |
| 453 | 453 |
| 454 // Helper class to load/unload External Clear Key Library, if necessary. | 454 // Helper class to load/unload External Clear Key Library, if necessary. |
| 455 std::unique_ptr<ExternalClearKeyTestHelper> helper_; | 455 std::unique_ptr<ExternalClearKeyTestHelper> helper_; |
| 456 | 456 |
| 457 base::MessageLoop message_loop_; | 457 base::MessageLoop message_loop_; |
| 458 | 458 |
| 459 // Constants for testing. | 459 // Constants for testing. |
| 460 const std::vector<uint8_t> original_data_; | 460 const std::vector<uint8_t> original_data_; |
| 461 const std::vector<uint8_t> encrypted_data_; | 461 const std::vector<uint8_t> encrypted_data_; |
| 462 const std::vector<uint8_t> subsample_encrypted_data_; | 462 const std::vector<uint8_t> subsample_encrypted_data_; |
| 463 const std::vector<uint8_t> key_id_; | 463 const std::vector<uint8_t> key_id_; |
| 464 const std::vector<uint8_t> iv_; | 464 const std::vector<uint8_t> iv_; |
| 465 const std::vector<SubsampleEntry> normal_subsample_entries_; | 465 const std::vector<SubsampleEntry> normal_subsample_entries_; |
| 466 const std::vector<SubsampleEntry> no_subsample_entries_; | 466 const std::vector<SubsampleEntry> no_subsample_entries_; |
| 467 }; | 467 }; |
| 468 | 468 |
| 469 TEST_P(AesDecryptorTest, CreateSessionWithEmptyInitData) { | 469 TEST_P(AesDecryptorTest, CreateSessionWithEmptyInitData) { |
| 470 cdm_->CreateSessionAndGenerateRequest( | 470 cdm_->CreateSessionAndGenerateRequest( |
| 471 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, | 471 ContentDecryptionModule::TEMPORARY_SESSION, EmeInitDataType::WEBM, |
| 472 std::vector<uint8_t>(), CreateSessionPromise(REJECTED)); | 472 std::vector<uint8_t>(), CreateSessionPromise(REJECTED)); |
| 473 cdm_->CreateSessionAndGenerateRequest( | 473 cdm_->CreateSessionAndGenerateRequest( |
| 474 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::CENC, | 474 ContentDecryptionModule::TEMPORARY_SESSION, EmeInitDataType::CENC, |
| 475 std::vector<uint8_t>(), CreateSessionPromise(REJECTED)); | 475 std::vector<uint8_t>(), CreateSessionPromise(REJECTED)); |
| 476 cdm_->CreateSessionAndGenerateRequest( | 476 cdm_->CreateSessionAndGenerateRequest( |
| 477 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::KEYIDS, | 477 ContentDecryptionModule::TEMPORARY_SESSION, EmeInitDataType::KEYIDS, |
| 478 std::vector<uint8_t>(), CreateSessionPromise(REJECTED)); | 478 std::vector<uint8_t>(), CreateSessionPromise(REJECTED)); |
| 479 } | 479 } |
| 480 | 480 |
| 481 TEST_P(AesDecryptorTest, CreateSessionWithVariousLengthInitData_WebM) { | 481 TEST_P(AesDecryptorTest, CreateSessionWithVariousLengthInitData_WebM) { |
| 482 std::vector<uint8_t> init_data; | 482 std::vector<uint8_t> init_data; |
| 483 init_data.resize(1); | 483 init_data.resize(1); |
| 484 EXPECT_CALL(cdm_client_, OnSessionMessage(NotEmpty(), _, IsJSONDictionary())); | 484 EXPECT_CALL(cdm_client_, OnSessionMessage(NotEmpty(), _, IsJSONDictionary())); |
| 485 cdm_->CreateSessionAndGenerateRequest( | 485 cdm_->CreateSessionAndGenerateRequest( |
| 486 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, | 486 ContentDecryptionModule::TEMPORARY_SESSION, EmeInitDataType::WEBM, |
| 487 std::vector<uint8_t>(init_data), CreateSessionPromise(RESOLVED)); | 487 std::vector<uint8_t>(init_data), CreateSessionPromise(RESOLVED)); |
| 488 | 488 |
| 489 init_data.resize(16); // The expected size. | 489 init_data.resize(16); // The expected size. |
| 490 EXPECT_CALL(cdm_client_, OnSessionMessage(NotEmpty(), _, IsJSONDictionary())); | 490 EXPECT_CALL(cdm_client_, OnSessionMessage(NotEmpty(), _, IsJSONDictionary())); |
| 491 cdm_->CreateSessionAndGenerateRequest( | 491 cdm_->CreateSessionAndGenerateRequest( |
| 492 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, | 492 ContentDecryptionModule::TEMPORARY_SESSION, EmeInitDataType::WEBM, |
| 493 std::vector<uint8_t>(init_data), CreateSessionPromise(RESOLVED)); | 493 std::vector<uint8_t>(init_data), CreateSessionPromise(RESOLVED)); |
| 494 | 494 |
| 495 init_data.resize(512); | 495 init_data.resize(512); |
| 496 EXPECT_CALL(cdm_client_, OnSessionMessage(NotEmpty(), _, IsJSONDictionary())); | 496 EXPECT_CALL(cdm_client_, OnSessionMessage(NotEmpty(), _, IsJSONDictionary())); |
| 497 cdm_->CreateSessionAndGenerateRequest( | 497 cdm_->CreateSessionAndGenerateRequest( |
| 498 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, | 498 ContentDecryptionModule::TEMPORARY_SESSION, EmeInitDataType::WEBM, |
| 499 std::vector<uint8_t>(init_data), CreateSessionPromise(RESOLVED)); | 499 std::vector<uint8_t>(init_data), CreateSessionPromise(RESOLVED)); |
| 500 | 500 |
| 501 init_data.resize(513); | 501 init_data.resize(513); |
| 502 cdm_->CreateSessionAndGenerateRequest( | 502 cdm_->CreateSessionAndGenerateRequest( |
| 503 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, | 503 ContentDecryptionModule::TEMPORARY_SESSION, EmeInitDataType::WEBM, |
| 504 std::vector<uint8_t>(init_data), CreateSessionPromise(REJECTED)); | 504 std::vector<uint8_t>(init_data), CreateSessionPromise(REJECTED)); |
| 505 } | 505 } |
| 506 | 506 |
| 507 TEST_P(AesDecryptorTest, MultipleCreateSession) { | 507 TEST_P(AesDecryptorTest, MultipleCreateSession) { |
| 508 EXPECT_CALL(cdm_client_, OnSessionMessage(NotEmpty(), _, IsJSONDictionary())); | 508 EXPECT_CALL(cdm_client_, OnSessionMessage(NotEmpty(), _, IsJSONDictionary())); |
| 509 cdm_->CreateSessionAndGenerateRequest( | 509 cdm_->CreateSessionAndGenerateRequest( |
| 510 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, | 510 ContentDecryptionModule::TEMPORARY_SESSION, EmeInitDataType::WEBM, |
| 511 std::vector<uint8_t>(1), CreateSessionPromise(RESOLVED)); | 511 std::vector<uint8_t>(1), CreateSessionPromise(RESOLVED)); |
| 512 | 512 |
| 513 EXPECT_CALL(cdm_client_, OnSessionMessage(NotEmpty(), _, IsJSONDictionary())); | 513 EXPECT_CALL(cdm_client_, OnSessionMessage(NotEmpty(), _, IsJSONDictionary())); |
| 514 cdm_->CreateSessionAndGenerateRequest( | 514 cdm_->CreateSessionAndGenerateRequest( |
| 515 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, | 515 ContentDecryptionModule::TEMPORARY_SESSION, EmeInitDataType::WEBM, |
| 516 std::vector<uint8_t>(1), CreateSessionPromise(RESOLVED)); | 516 std::vector<uint8_t>(1), CreateSessionPromise(RESOLVED)); |
| 517 | 517 |
| 518 EXPECT_CALL(cdm_client_, OnSessionMessage(NotEmpty(), _, IsJSONDictionary())); | 518 EXPECT_CALL(cdm_client_, OnSessionMessage(NotEmpty(), _, IsJSONDictionary())); |
| 519 cdm_->CreateSessionAndGenerateRequest( | 519 cdm_->CreateSessionAndGenerateRequest( |
| 520 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, | 520 ContentDecryptionModule::TEMPORARY_SESSION, EmeInitDataType::WEBM, |
| 521 std::vector<uint8_t>(1), CreateSessionPromise(RESOLVED)); | 521 std::vector<uint8_t>(1), CreateSessionPromise(RESOLVED)); |
| 522 } | 522 } |
| 523 | 523 |
| 524 TEST_P(AesDecryptorTest, CreateSessionWithCencInitData) { | 524 TEST_P(AesDecryptorTest, CreateSessionWithCencInitData) { |
| 525 const uint8_t init_data[] = { | 525 const uint8_t init_data[] = { |
| 526 0x00, 0x00, 0x00, 0x44, // size = 68 | 526 0x00, 0x00, 0x00, 0x44, // size = 68 |
| 527 0x70, 0x73, 0x73, 0x68, // 'pssh' | 527 0x70, 0x73, 0x73, 0x68, // 'pssh' |
| 528 0x01, // version | 528 0x01, // version |
| 529 0x00, 0x00, 0x00, // flags | 529 0x00, 0x00, 0x00, // flags |
| 530 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID | 530 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID |
| 531 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B, | 531 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B, |
| 532 0x00, 0x00, 0x00, 0x02, // key count | 532 0x00, 0x00, 0x00, 0x02, // key count |
| 533 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1 | 533 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1 |
| 534 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, | 534 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, |
| 535 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, // key2 | 535 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, // key2 |
| 536 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, | 536 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, |
| 537 0x00, 0x00, 0x00, 0x00 // datasize | 537 0x00, 0x00, 0x00, 0x00 // datasize |
| 538 }; | 538 }; |
| 539 | 539 |
| 540 #if defined(USE_PROPRIETARY_CODECS) | 540 #if defined(USE_PROPRIETARY_CODECS) |
| 541 EXPECT_CALL(cdm_client_, OnSessionMessage(NotEmpty(), _, IsJSONDictionary())); | 541 EXPECT_CALL(cdm_client_, OnSessionMessage(NotEmpty(), _, IsJSONDictionary())); |
| 542 cdm_->CreateSessionAndGenerateRequest( | 542 cdm_->CreateSessionAndGenerateRequest( |
| 543 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::CENC, | 543 ContentDecryptionModule::TEMPORARY_SESSION, EmeInitDataType::CENC, |
| 544 std::vector<uint8_t>(init_data, init_data + arraysize(init_data)), | 544 std::vector<uint8_t>(init_data, init_data + arraysize(init_data)), |
| 545 CreateSessionPromise(RESOLVED)); | 545 CreateSessionPromise(RESOLVED)); |
| 546 #else | 546 #else |
| 547 cdm_->CreateSessionAndGenerateRequest( | 547 cdm_->CreateSessionAndGenerateRequest( |
| 548 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::CENC, | 548 ContentDecryptionModule::TEMPORARY_SESSION, EmeInitDataType::CENC, |
| 549 std::vector<uint8_t>(init_data, init_data + arraysize(init_data)), | 549 std::vector<uint8_t>(init_data, init_data + arraysize(init_data)), |
| 550 CreateSessionPromise(REJECTED)); | 550 CreateSessionPromise(REJECTED)); |
| 551 #endif | 551 #endif |
| 552 } | 552 } |
| 553 | 553 |
| 554 TEST_P(AesDecryptorTest, CreateSessionWithKeyIdsInitData) { | 554 TEST_P(AesDecryptorTest, CreateSessionWithKeyIdsInitData) { |
| 555 const char init_data[] = | 555 const char init_data[] = |
| 556 "{\"kids\":[\"AQI\",\"AQIDBA\",\"AQIDBAUGBwgJCgsMDQ4PEA\"]}"; | 556 "{\"kids\":[\"AQI\",\"AQIDBA\",\"AQIDBAUGBwgJCgsMDQ4PEA\"]}"; |
| 557 | 557 |
| 558 EXPECT_CALL(cdm_client_, OnSessionMessage(NotEmpty(), _, IsJSONDictionary())); | 558 EXPECT_CALL(cdm_client_, OnSessionMessage(NotEmpty(), _, IsJSONDictionary())); |
| 559 cdm_->CreateSessionAndGenerateRequest( | 559 cdm_->CreateSessionAndGenerateRequest( |
| 560 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::KEYIDS, | 560 ContentDecryptionModule::TEMPORARY_SESSION, EmeInitDataType::KEYIDS, |
| 561 std::vector<uint8_t>(init_data, init_data + arraysize(init_data) - 1), | 561 std::vector<uint8_t>(init_data, init_data + arraysize(init_data) - 1), |
| 562 CreateSessionPromise(RESOLVED)); | 562 CreateSessionPromise(RESOLVED)); |
| 563 } | 563 } |
| 564 | 564 |
| 565 TEST_P(AesDecryptorTest, NormalDecryption) { | 565 TEST_P(AesDecryptorTest, NormalDecryption) { |
| 566 std::string session_id = CreateSession(key_id_); | 566 std::string session_id = CreateSession(key_id_); |
| 567 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED, true); | 567 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED, true); |
| 568 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer( | 568 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer( |
| 569 encrypted_data_, key_id_, iv_, no_subsample_entries_); | 569 encrypted_data_, key_id_, iv_, no_subsample_entries_); |
| 570 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS); | 570 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS); |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1012 INSTANTIATE_TEST_CASE_P(CdmAdapter, | 1012 INSTANTIATE_TEST_CASE_P(CdmAdapter, |
| 1013 AesDecryptorTest, | 1013 AesDecryptorTest, |
| 1014 testing::Values("CdmAdapter")); | 1014 testing::Values("CdmAdapter")); |
| 1015 #endif | 1015 #endif |
| 1016 | 1016 |
| 1017 // TODO(jrummell): Once MojoCdm/MojoCdmService/MojoDecryptor/ | 1017 // TODO(jrummell): Once MojoCdm/MojoCdmService/MojoDecryptor/ |
| 1018 // MojoDecryptorService are implemented, add a third version that tests the | 1018 // MojoDecryptorService are implemented, add a third version that tests the |
| 1019 // CDM via mojo. | 1019 // CDM via mojo. |
| 1020 | 1020 |
| 1021 } // namespace media | 1021 } // namespace media |
| OLD | NEW |