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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 protected: | 245 protected: |
246 void SetUp() override { | 246 void SetUp() override { |
247 if (GetParam() == "AesDecryptor") { | 247 if (GetParam() == "AesDecryptor") { |
248 OnCdmCreated( | 248 OnCdmCreated( |
249 new AesDecryptor(GURL::EmptyGURL(), | 249 new AesDecryptor(GURL::EmptyGURL(), |
250 base::Bind(&MockCdmClient::OnSessionMessage, | 250 base::Bind(&MockCdmClient::OnSessionMessage, |
251 base::Unretained(&cdm_client_)), | 251 base::Unretained(&cdm_client_)), |
252 base::Bind(&MockCdmClient::OnSessionClosed, | 252 base::Bind(&MockCdmClient::OnSessionClosed, |
253 base::Unretained(&cdm_client_)), | 253 base::Unretained(&cdm_client_)), |
254 base::Bind(&MockCdmClient::OnSessionKeysChange, | 254 base::Bind(&MockCdmClient::OnSessionKeysChange, |
255 base::Unretained(&cdm_client_)), | |
256 base::Bind(&MockCdmClient::OnSessionExpirationUpdate, | |
255 base::Unretained(&cdm_client_))), | 257 base::Unretained(&cdm_client_))), |
256 std::string()); | 258 std::string()); |
257 } else if (GetParam() == "CdmAdapter") { | 259 } else if (GetParam() == "CdmAdapter") { |
258 CdmConfig cdm_config; // default settings of false are sufficient. | 260 CdmConfig cdm_config; // default settings of false are sufficient. |
259 | 261 |
260 helper_.reset(new ExternalClearKeyTestHelper()); | 262 helper_.reset(new ExternalClearKeyTestHelper()); |
261 std::unique_ptr<CdmAllocator> allocator(new SimpleCdmAllocator()); | 263 std::unique_ptr<CdmAllocator> allocator(new SimpleCdmAllocator()); |
262 CdmAdapter::Create( | 264 CdmAdapter::Create( |
263 helper_->KeySystemName(), helper_->LibraryPath(), cdm_config, | 265 helper_->KeySystemName(), helper_->LibraryPath(), cdm_config, |
264 std::move(allocator), base::Bind(&AesDecryptorTest::CreateCdmFileIO, | 266 std::move(allocator), base::Bind(&AesDecryptorTest::CreateCdmFileIO, |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
341 // for AesDecryptor. | 343 // for AesDecryptor. |
342 return session_id_; | 344 return session_id_; |
343 } | 345 } |
344 | 346 |
345 // Closes the session specified by |session_id|. | 347 // Closes the session specified by |session_id|. |
346 void CloseSession(const std::string& session_id) { | 348 void CloseSession(const std::string& session_id) { |
347 EXPECT_CALL(cdm_client_, OnSessionClosed(session_id)); | 349 EXPECT_CALL(cdm_client_, OnSessionClosed(session_id)); |
348 cdm_->CloseSession(session_id, CreatePromise(RESOLVED)); | 350 cdm_->CloseSession(session_id, CreatePromise(RESOLVED)); |
349 } | 351 } |
350 | 352 |
351 // Only persistent sessions can be removed. | 353 // Removes the session specified by |session_id|. |
352 void RemoveSession(const std::string& session_id) { | 354 void RemoveSession(const std::string& session_id) { |
353 // TODO(ddorwin): This should be RESOLVED after https://crbug.com/616166. | 355 EXPECT_CALL(cdm_client_, OnSessionKeysChangeCalled(session_id, false)); |
354 cdm_->RemoveSession(session_id, CreatePromise(REJECTED)); | 356 EXPECT_CALL(cdm_client_, |
357 OnSessionExpirationUpdate(session_id, IsNullTime())); | |
358 cdm_->RemoveSession(session_id, CreatePromise(RESOLVED)); | |
355 } | 359 } |
356 | 360 |
357 // Updates the session specified by |session_id| with |key|. |result| | 361 // Updates the session specified by |session_id| with |key|. |result| |
358 // tests that the update succeeds or generates an error. | 362 // tests that the update succeeds or generates an error. |
359 void UpdateSessionAndExpect(std::string session_id, | 363 void UpdateSessionAndExpect(std::string session_id, |
360 const std::string& key, | 364 const std::string& key, |
361 ExpectedResult expected_result, | 365 ExpectedResult expected_result, |
362 bool new_key_expected) { | 366 bool new_key_expected) { |
363 DCHECK(!key.empty()); | 367 DCHECK(!key.empty()); |
364 | 368 |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
773 | 777 |
774 TEST_P(AesDecryptorTest, RemoveSession) { | 778 TEST_P(AesDecryptorTest, RemoveSession) { |
775 std::string session_id = CreateSession(key_id_); | 779 std::string session_id = CreateSession(key_id_); |
776 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer( | 780 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer( |
777 encrypted_data_, key_id_, iv_, no_subsample_entries_); | 781 encrypted_data_, key_id_, iv_, no_subsample_entries_); |
778 | 782 |
779 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED, true); | 783 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED, true); |
780 ASSERT_NO_FATAL_FAILURE( | 784 ASSERT_NO_FATAL_FAILURE( |
781 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS)); | 785 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS)); |
782 | 786 |
783 RemoveSession(session_id); | 787 RemoveSession(session_id); |
xhwang
2017/04/21 18:00:28
Can we decrypt again and make sure the keys are no
jrummell
2017/04/22 00:23:17
Done (and added a test to remove then close the se
| |
784 } | 788 } |
785 | 789 |
786 TEST_P(AesDecryptorTest, NoKeyAfterCloseSession) { | 790 TEST_P(AesDecryptorTest, NoKeyAfterCloseSession) { |
787 std::string session_id = CreateSession(key_id_); | 791 std::string session_id = CreateSession(key_id_); |
788 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer( | 792 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer( |
789 encrypted_data_, key_id_, iv_, no_subsample_entries_); | 793 encrypted_data_, key_id_, iv_, no_subsample_entries_); |
790 | 794 |
791 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED, true); | 795 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED, true); |
792 ASSERT_NO_FATAL_FAILURE( | 796 ASSERT_NO_FATAL_FAILURE( |
793 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS)); | 797 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS)); |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1024 INSTANTIATE_TEST_CASE_P(CdmAdapter, | 1028 INSTANTIATE_TEST_CASE_P(CdmAdapter, |
1025 AesDecryptorTest, | 1029 AesDecryptorTest, |
1026 testing::Values("CdmAdapter")); | 1030 testing::Values("CdmAdapter")); |
1027 #endif | 1031 #endif |
1028 | 1032 |
1029 // TODO(jrummell): Once MojoCdm/MojoCdmService/MojoDecryptor/ | 1033 // TODO(jrummell): Once MojoCdm/MojoCdmService/MojoDecryptor/ |
1030 // MojoDecryptorService are implemented, add a third version that tests the | 1034 // MojoDecryptorService are implemented, add a third version that tests the |
1031 // CDM via mojo. | 1035 // CDM via mojo. |
1032 | 1036 |
1033 } // namespace media | 1037 } // namespace media |
OLD | NEW |