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

Side by Side Diff: media/cdm/aes_decryptor_unittest.cc

Issue 2831963003: EME: Allow temporary sessions to be removed for ClearKey only. (Closed)
Patch Set: rebase Created 3 years, 7 months 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
« no previous file with comments | « media/cdm/aes_decryptor.cc ('k') | media/cdm/default_cdm_factory.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
365 if (expected_result == RESOLVED) { 369 if (expected_result == RESOLVED) {
366 EXPECT_CALL(cdm_client_, 370 EXPECT_CALL(cdm_client_,
367 OnSessionKeysChangeCalled(session_id, new_key_expected)); 371 OnSessionKeysChangeCalled(session_id, new_key_expected));
368 } else { 372 } else {
369 EXPECT_CALL(cdm_client_, OnSessionKeysChangeCalled(_, _)).Times(0); 373 EXPECT_CALL(cdm_client_, OnSessionKeysChangeCalled(_, _)).Times(0);
370 } 374 }
371 375
372 // AesDecryptor never calls OnSessionExpirationUpdate() since Clear Key key 376 // AesDecryptor never calls OnSessionExpirationUpdate() since Clear Key key
373 // system doesn't need it. But ClearKeyCdm does call it for testing purpose. 377 // system doesn't need it. But ClearKeyCdm does call it for testing purpose.
374 EXPECT_CALL(cdm_client_, 378 EXPECT_CALL(cdm_client_,
375 OnSessionExpirationUpdate(session_id, IsNullTime())) 379 OnSessionExpirationUpdate(session_id, IsNullTime()))
376 .Times(AtMost(1)); 380 .Times(AtMost(1));
377 381
378 cdm_->UpdateSession(session_id, 382 cdm_->UpdateSession(session_id,
379 std::vector<uint8_t>(key.begin(), key.end()), 383 std::vector<uint8_t>(key.begin(), key.end()),
380 CreatePromise(expected_result)); 384 CreatePromise(expected_result));
381 } 385 }
382 386
383 bool KeysInfoContains(const std::vector<uint8_t>& expected) { 387 bool KeysInfoContains(const std::vector<uint8_t>& expected_key_id,
388 CdmKeyInformation::KeyStatus expected_status =
389 CdmKeyInformation::USABLE) {
384 for (auto* key_id : cdm_client_.keys_info()) { 390 for (auto* key_id : cdm_client_.keys_info()) {
385 if (key_id->key_id == expected) 391 if (key_id->key_id == expected_key_id &&
392 key_id->status == expected_status) {
386 return true; 393 return true;
394 }
387 } 395 }
388 return false; 396 return false;
389 } 397 }
390 398
391 MOCK_METHOD2(BufferDecrypted, void(Decryptor::Status, 399 MOCK_METHOD2(BufferDecrypted, void(Decryptor::Status,
392 const scoped_refptr<DecoderBuffer>&)); 400 const scoped_refptr<DecoderBuffer>&));
393 401
394 enum DecryptExpectation { 402 enum DecryptExpectation {
395 SUCCESS, 403 SUCCESS,
396 DATA_MISMATCH, 404 DATA_MISMATCH,
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 TEST_P(AesDecryptorTest, RemoveSession) { 782 TEST_P(AesDecryptorTest, RemoveSession) {
775 std::string session_id = CreateSession(key_id_); 783 std::string session_id = CreateSession(key_id_);
776 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer( 784 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
777 encrypted_data_, key_id_, iv_, no_subsample_entries_); 785 encrypted_data_, key_id_, iv_, no_subsample_entries_);
778 786
779 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED, true); 787 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED, true);
780 ASSERT_NO_FATAL_FAILURE( 788 ASSERT_NO_FATAL_FAILURE(
781 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS)); 789 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS));
782 790
783 RemoveSession(session_id); 791 RemoveSession(session_id);
792 ASSERT_NO_FATAL_FAILURE(
793 DecryptAndExpect(encrypted_buffer, original_data_, NO_KEY));
794 }
795
796 TEST_P(AesDecryptorTest, RemoveThenCloseSession) {
797 std::string session_id = CreateSession(key_id_);
798 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
799 encrypted_data_, key_id_, iv_, no_subsample_entries_);
800
801 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED, true);
802 EXPECT_TRUE(KeysInfoContains(key_id_, CdmKeyInformation::USABLE));
803 ASSERT_NO_FATAL_FAILURE(
804 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS));
805
806 RemoveSession(session_id);
807 EXPECT_TRUE(KeysInfoContains(key_id_, CdmKeyInformation::RELEASED));
808 ASSERT_NO_FATAL_FAILURE(
809 DecryptAndExpect(encrypted_buffer, original_data_, NO_KEY));
810
811 CloseSession(session_id);
784 } 812 }
785 813
786 TEST_P(AesDecryptorTest, NoKeyAfterCloseSession) { 814 TEST_P(AesDecryptorTest, NoKeyAfterCloseSession) {
787 std::string session_id = CreateSession(key_id_); 815 std::string session_id = CreateSession(key_id_);
788 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer( 816 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
789 encrypted_data_, key_id_, iv_, no_subsample_entries_); 817 encrypted_data_, key_id_, iv_, no_subsample_entries_);
790 818
791 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED, true); 819 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED, true);
792 ASSERT_NO_FATAL_FAILURE( 820 ASSERT_NO_FATAL_FAILURE(
793 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS)); 821 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS));
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 INSTANTIATE_TEST_CASE_P(CdmAdapter, 1052 INSTANTIATE_TEST_CASE_P(CdmAdapter,
1025 AesDecryptorTest, 1053 AesDecryptorTest,
1026 testing::Values("CdmAdapter")); 1054 testing::Values("CdmAdapter"));
1027 #endif 1055 #endif
1028 1056
1029 // TODO(jrummell): Once MojoCdm/MojoCdmService/MojoDecryptor/ 1057 // TODO(jrummell): Once MojoCdm/MojoCdmService/MojoDecryptor/
1030 // MojoDecryptorService are implemented, add a third version that tests the 1058 // MojoDecryptorService are implemented, add a third version that tests the
1031 // CDM via mojo. 1059 // CDM via mojo.
1032 1060
1033 } // namespace media 1061 } // namespace media
OLDNEW
« no previous file with comments | « media/cdm/aes_decryptor.cc ('k') | media/cdm/default_cdm_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698