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

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

Issue 1920433003: EME: Address TODOs related to the removal of prefixed EME (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update per crbug.com/616166: Remove NOTREACHED and re-enable test. Created 4 years, 4 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/ppapi/external_clear_key/clear_key_cdm.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 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // TODO(ddorwin): This should be RESOLVED after https://crbug.com/616166.
350 EXPECT_CALL(*this, OnSessionClosed(session_id)); 347 cdm_->RemoveSession(session_id, CreatePromise(REJECTED));
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 } 348 }
358 349
359 MOCK_METHOD2(OnSessionKeysChangeCalled, 350 MOCK_METHOD2(OnSessionKeysChangeCalled,
360 void(const std::string& session_id, 351 void(const std::string& session_id,
361 bool has_additional_usable_key)); 352 bool has_additional_usable_key));
362 353
363 void OnSessionKeysChange(const std::string& session_id, 354 void OnSessionKeysChange(const std::string& session_id,
364 bool has_additional_usable_key, 355 bool has_additional_usable_key,
365 CdmKeysInfo keys_info) { 356 CdmKeysInfo keys_info) {
366 keys_info_.swap(keys_info); 357 keys_info_.swap(keys_info);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 // Constants for testing. 484 // Constants for testing.
494 const std::vector<uint8_t> original_data_; 485 const std::vector<uint8_t> original_data_;
495 const std::vector<uint8_t> encrypted_data_; 486 const std::vector<uint8_t> encrypted_data_;
496 const std::vector<uint8_t> subsample_encrypted_data_; 487 const std::vector<uint8_t> subsample_encrypted_data_;
497 const std::vector<uint8_t> key_id_; 488 const std::vector<uint8_t> key_id_;
498 const std::vector<uint8_t> iv_; 489 const std::vector<uint8_t> iv_;
499 const std::vector<SubsampleEntry> normal_subsample_entries_; 490 const std::vector<SubsampleEntry> normal_subsample_entries_;
500 const std::vector<SubsampleEntry> no_subsample_entries_; 491 const std::vector<SubsampleEntry> no_subsample_entries_;
501 }; 492 };
502 493
503 TEST_P(AesDecryptorTest, CreateSessionWithNullInitData) { 494 TEST_P(AesDecryptorTest, CreateSessionWithEmptyInitData) {
504 EXPECT_CALL(*this,
505 OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL()));
506 cdm_->CreateSessionAndGenerateRequest( 495 cdm_->CreateSessionAndGenerateRequest(
507 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, 496 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM,
508 std::vector<uint8_t>(), CreateSessionPromise(RESOLVED)); 497 std::vector<uint8_t>(), CreateSessionPromise(REJECTED));
498 cdm_->CreateSessionAndGenerateRequest(
499 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::CENC,
500 std::vector<uint8_t>(), CreateSessionPromise(REJECTED));
501 cdm_->CreateSessionAndGenerateRequest(
502 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::KEYIDS,
503 std::vector<uint8_t>(), CreateSessionPromise(REJECTED));
504 }
505
506 TEST_P(AesDecryptorTest, CreateSessionWithVariousLengthInitData_WebM) {
507 std::vector<uint8_t> init_data;
508 init_data.resize(1);
509 cdm_->CreateSessionAndGenerateRequest(
510 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM,
511 std::vector<uint8_t>(init_data), CreateSessionPromise(RESOLVED));
512
513 init_data.resize(16); // The expected size.
514 cdm_->CreateSessionAndGenerateRequest(
515 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM,
516 std::vector<uint8_t>(init_data), CreateSessionPromise(RESOLVED));
517
518 init_data.resize(512);
519 cdm_->CreateSessionAndGenerateRequest(
520 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM,
521 std::vector<uint8_t>(init_data), CreateSessionPromise(RESOLVED));
522
523 init_data.resize(513);
524 cdm_->CreateSessionAndGenerateRequest(
525 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM,
526 std::vector<uint8_t>(init_data), CreateSessionPromise(REJECTED));
509 } 527 }
510 528
511 TEST_P(AesDecryptorTest, MultipleCreateSession) { 529 TEST_P(AesDecryptorTest, MultipleCreateSession) {
512 EXPECT_CALL(*this, 530 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsNotEmpty(),
513 OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL())); 531 GURL::EmptyGURL()));
514 cdm_->CreateSessionAndGenerateRequest( 532 cdm_->CreateSessionAndGenerateRequest(
515 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, 533 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM,
516 std::vector<uint8_t>(), CreateSessionPromise(RESOLVED)); 534 std::vector<uint8_t>(1), CreateSessionPromise(RESOLVED));
517 535
518 EXPECT_CALL(*this, 536 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsNotEmpty(),
519 OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL())); 537 GURL::EmptyGURL()));
520 cdm_->CreateSessionAndGenerateRequest( 538 cdm_->CreateSessionAndGenerateRequest(
521 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, 539 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM,
522 std::vector<uint8_t>(), CreateSessionPromise(RESOLVED)); 540 std::vector<uint8_t>(1), CreateSessionPromise(RESOLVED));
523 541
524 EXPECT_CALL(*this, 542 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsNotEmpty(),
525 OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL())); 543 GURL::EmptyGURL()));
526 cdm_->CreateSessionAndGenerateRequest( 544 cdm_->CreateSessionAndGenerateRequest(
527 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, 545 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM,
528 std::vector<uint8_t>(), CreateSessionPromise(RESOLVED)); 546 std::vector<uint8_t>(1), CreateSessionPromise(RESOLVED));
529 } 547 }
530 548
531 TEST_P(AesDecryptorTest, CreateSessionWithCencInitData) { 549 TEST_P(AesDecryptorTest, CreateSessionWithCencInitData) {
532 const uint8_t init_data[] = { 550 const uint8_t init_data[] = {
533 0x00, 0x00, 0x00, 0x44, // size = 68 551 0x00, 0x00, 0x00, 0x44, // size = 68
534 0x70, 0x73, 0x73, 0x68, // 'pssh' 552 0x70, 0x73, 0x73, 0x68, // 'pssh'
535 0x01, // version 553 0x01, // version
536 0x00, 0x00, 0x00, // flags 554 0x00, 0x00, 0x00, // flags
537 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID 555 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID
538 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B, 556 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B,
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 encrypted_data_, key_id_, iv_, no_subsample_entries_); 780 encrypted_data_, key_id_, iv_, no_subsample_entries_);
763 781
764 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED, true); 782 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED, true);
765 ASSERT_NO_FATAL_FAILURE( 783 ASSERT_NO_FATAL_FAILURE(
766 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS)); 784 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS));
767 785
768 CloseSession(session_id); 786 CloseSession(session_id);
769 } 787 }
770 788
771 TEST_P(AesDecryptorTest, RemoveSession) { 789 TEST_P(AesDecryptorTest, RemoveSession) {
772 // TODO(jrummell): Clean this up when the prefixed API is removed.
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
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
OLDNEW
« no previous file with comments | « media/cdm/aes_decryptor.cc ('k') | media/cdm/ppapi/external_clear_key/clear_key_cdm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698