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

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

Issue 2255943002: EME: Remove obsolete legacy APIs related to versions of prefixed EME (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build and add bug reference for obsoletes 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
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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 helper_.reset(new ExternalClearKeyTestHelper()); 250 helper_.reset(new ExternalClearKeyTestHelper());
251 std::unique_ptr<CdmAllocator> allocator(new SimpleCdmAllocator()); 251 std::unique_ptr<CdmAllocator> allocator(new SimpleCdmAllocator());
252 CdmAdapter::Create( 252 CdmAdapter::Create(
253 helper_->KeySystemName(), helper_->LibraryPath(), cdm_config, 253 helper_->KeySystemName(), helper_->LibraryPath(), cdm_config,
254 std::move(allocator), base::Bind(&AesDecryptorTest::CreateCdmFileIO, 254 std::move(allocator), base::Bind(&AesDecryptorTest::CreateCdmFileIO,
255 base::Unretained(this)), 255 base::Unretained(this)),
256 base::Bind(&AesDecryptorTest::OnSessionMessage, 256 base::Bind(&AesDecryptorTest::OnSessionMessage,
257 base::Unretained(this)), 257 base::Unretained(this)),
258 base::Bind(&AesDecryptorTest::OnSessionClosed, 258 base::Bind(&AesDecryptorTest::OnSessionClosed,
259 base::Unretained(this)), 259 base::Unretained(this)),
260 base::Bind(&AesDecryptorTest::OnLegacySessionError,
261 base::Unretained(this)),
262 base::Bind(&AesDecryptorTest::OnSessionKeysChange, 260 base::Bind(&AesDecryptorTest::OnSessionKeysChange,
263 base::Unretained(this)), 261 base::Unretained(this)),
264 base::Bind(&AesDecryptorTest::OnSessionExpirationUpdate, 262 base::Bind(&AesDecryptorTest::OnSessionExpirationUpdate,
265 base::Unretained(this)), 263 base::Unretained(this)),
266 base::Bind(&AesDecryptorTest::OnCdmCreated, base::Unretained(this))); 264 base::Bind(&AesDecryptorTest::OnCdmCreated, base::Unretained(this)));
267 265
268 base::RunLoop().RunUntilIdle(); 266 base::RunLoop().RunUntilIdle();
269 } 267 }
270 } 268 }
271 269
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 base::Bind(&AesDecryptorTest::OnResolveWithSession, 315 base::Bind(&AesDecryptorTest::OnResolveWithSession,
318 base::Unretained(this), expected_result), 316 base::Unretained(this), expected_result),
319 base::Bind(&AesDecryptorTest::OnReject, base::Unretained(this), 317 base::Bind(&AesDecryptorTest::OnReject, base::Unretained(this),
320 expected_result))); 318 expected_result)));
321 return promise; 319 return promise;
322 } 320 }
323 321
324 // Creates a new session using |key_id|. Returns the session ID. 322 // Creates a new session using |key_id|. Returns the session ID.
325 std::string CreateSession(const std::vector<uint8_t>& key_id) { 323 std::string CreateSession(const std::vector<uint8_t>& key_id) {
326 DCHECK(!key_id.empty()); 324 DCHECK(!key_id.empty());
327 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsJSONDictionary(), 325 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsJSONDictionary()));
328 GURL::EmptyGURL()));
329 cdm_->CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION, 326 cdm_->CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION,
330 EmeInitDataType::WEBM, key_id, 327 EmeInitDataType::WEBM, key_id,
331 CreateSessionPromise(RESOLVED)); 328 CreateSessionPromise(RESOLVED));
332 // This expects the promise to be called synchronously, which is the case 329 // This expects the promise to be called synchronously, which is the case
333 // for AesDecryptor. 330 // for AesDecryptor.
334 return session_id_; 331 return session_id_;
335 } 332 }
336 333
337 // Closes the session specified by |session_id|. 334 // Closes the session specified by |session_id|.
338 void CloseSession(const std::string& session_id) { 335 void CloseSession(const std::string& session_id) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 EXPECT_TRUE(decrypted_text.empty()); 445 EXPECT_TRUE(decrypted_text.empty());
449 break; 446 break;
450 } 447 }
451 } 448 }
452 449
453 std::unique_ptr<CdmFileIO> CreateCdmFileIO(cdm::FileIOClient* client) { 450 std::unique_ptr<CdmFileIO> CreateCdmFileIO(cdm::FileIOClient* client) {
454 ADD_FAILURE() << "Should never be called"; 451 ADD_FAILURE() << "Should never be called";
455 return nullptr; 452 return nullptr;
456 } 453 }
457 454
458 MOCK_METHOD4(OnSessionMessage, 455 MOCK_METHOD3(OnSessionMessage,
459 void(const std::string& session_id, 456 void(const std::string& session_id,
460 MediaKeys::MessageType message_type, 457 MediaKeys::MessageType message_type,
461 const std::vector<uint8_t>& message, 458 const std::vector<uint8_t>& message));
462 const GURL& legacy_destination_url));
463 MOCK_METHOD1(OnSessionClosed, void(const std::string& session_id)); 459 MOCK_METHOD1(OnSessionClosed, void(const std::string& session_id));
464 MOCK_METHOD4(OnLegacySessionError,
465 void(const std::string& session_id,
466 MediaKeys::Exception exception,
467 uint32_t system_code,
468 const std::string& error_message));
469 MOCK_METHOD2(OnSessionExpirationUpdate, 460 MOCK_METHOD2(OnSessionExpirationUpdate,
470 void(const std::string& session_id, 461 void(const std::string& session_id,
471 const base::Time& new_expiry_time)); 462 const base::Time& new_expiry_time));
472 463
473 scoped_refptr<MediaKeys> cdm_; 464 scoped_refptr<MediaKeys> cdm_;
474 Decryptor* decryptor_; 465 Decryptor* decryptor_;
475 Decryptor::DecryptCB decrypt_cb_; 466 Decryptor::DecryptCB decrypt_cb_;
476 std::string session_id_; 467 std::string session_id_;
477 CdmKeysInfo keys_info_; 468 CdmKeysInfo keys_info_;
478 469
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, 511 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM,
521 std::vector<uint8_t>(init_data), CreateSessionPromise(RESOLVED)); 512 std::vector<uint8_t>(init_data), CreateSessionPromise(RESOLVED));
522 513
523 init_data.resize(513); 514 init_data.resize(513);
524 cdm_->CreateSessionAndGenerateRequest( 515 cdm_->CreateSessionAndGenerateRequest(
525 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, 516 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM,
526 std::vector<uint8_t>(init_data), CreateSessionPromise(REJECTED)); 517 std::vector<uint8_t>(init_data), CreateSessionPromise(REJECTED));
527 } 518 }
528 519
529 TEST_P(AesDecryptorTest, MultipleCreateSession) { 520 TEST_P(AesDecryptorTest, MultipleCreateSession) {
530 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsNotEmpty(), 521 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsNotEmpty()));
531 GURL::EmptyGURL()));
532 cdm_->CreateSessionAndGenerateRequest( 522 cdm_->CreateSessionAndGenerateRequest(
533 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, 523 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM,
534 std::vector<uint8_t>(1), CreateSessionPromise(RESOLVED)); 524 std::vector<uint8_t>(1), CreateSessionPromise(RESOLVED));
535 525
536 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsNotEmpty(), 526 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsNotEmpty()));
537 GURL::EmptyGURL()));
538 cdm_->CreateSessionAndGenerateRequest( 527 cdm_->CreateSessionAndGenerateRequest(
539 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, 528 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM,
540 std::vector<uint8_t>(1), CreateSessionPromise(RESOLVED)); 529 std::vector<uint8_t>(1), CreateSessionPromise(RESOLVED));
541 530
542 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsNotEmpty(), 531 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsNotEmpty()));
543 GURL::EmptyGURL()));
544 cdm_->CreateSessionAndGenerateRequest( 532 cdm_->CreateSessionAndGenerateRequest(
545 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, 533 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM,
546 std::vector<uint8_t>(1), CreateSessionPromise(RESOLVED)); 534 std::vector<uint8_t>(1), CreateSessionPromise(RESOLVED));
547 } 535 }
548 536
549 TEST_P(AesDecryptorTest, CreateSessionWithCencInitData) { 537 TEST_P(AesDecryptorTest, CreateSessionWithCencInitData) {
550 const uint8_t init_data[] = { 538 const uint8_t init_data[] = {
551 0x00, 0x00, 0x00, 0x44, // size = 68 539 0x00, 0x00, 0x00, 0x44, // size = 68
552 0x70, 0x73, 0x73, 0x68, // 'pssh' 540 0x70, 0x73, 0x73, 0x68, // 'pssh'
553 0x01, // version 541 0x01, // version
554 0x00, 0x00, 0x00, // flags 542 0x00, 0x00, 0x00, // flags
555 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID 543 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID
556 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B, 544 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B,
557 0x00, 0x00, 0x00, 0x02, // key count 545 0x00, 0x00, 0x00, 0x02, // key count
558 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1 546 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1
559 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, 547 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03,
560 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, // key2 548 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, // key2
561 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, 549 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04,
562 0x00, 0x00, 0x00, 0x00 // datasize 550 0x00, 0x00, 0x00, 0x00 // datasize
563 }; 551 };
564 552
565 #if defined(USE_PROPRIETARY_CODECS) 553 #if defined(USE_PROPRIETARY_CODECS)
566 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsJSONDictionary(), 554 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsJSONDictionary()));
567 GURL::EmptyGURL()));
568 cdm_->CreateSessionAndGenerateRequest( 555 cdm_->CreateSessionAndGenerateRequest(
569 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::CENC, 556 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::CENC,
570 std::vector<uint8_t>(init_data, init_data + arraysize(init_data)), 557 std::vector<uint8_t>(init_data, init_data + arraysize(init_data)),
571 CreateSessionPromise(RESOLVED)); 558 CreateSessionPromise(RESOLVED));
572 #else 559 #else
573 cdm_->CreateSessionAndGenerateRequest( 560 cdm_->CreateSessionAndGenerateRequest(
574 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::CENC, 561 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::CENC,
575 std::vector<uint8_t>(init_data, init_data + arraysize(init_data)), 562 std::vector<uint8_t>(init_data, init_data + arraysize(init_data)),
576 CreateSessionPromise(REJECTED)); 563 CreateSessionPromise(REJECTED));
577 #endif 564 #endif
578 } 565 }
579 566
580 TEST_P(AesDecryptorTest, CreateSessionWithKeyIdsInitData) { 567 TEST_P(AesDecryptorTest, CreateSessionWithKeyIdsInitData) {
581 const char init_data[] = 568 const char init_data[] =
582 "{\"kids\":[\"AQI\",\"AQIDBA\",\"AQIDBAUGBwgJCgsMDQ4PEA\"]}"; 569 "{\"kids\":[\"AQI\",\"AQIDBA\",\"AQIDBAUGBwgJCgsMDQ4PEA\"]}";
583 570
584 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsJSONDictionary(), 571 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsJSONDictionary()));
585 GURL::EmptyGURL()));
586 cdm_->CreateSessionAndGenerateRequest( 572 cdm_->CreateSessionAndGenerateRequest(
587 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::KEYIDS, 573 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::KEYIDS,
588 std::vector<uint8_t>(init_data, init_data + arraysize(init_data) - 1), 574 std::vector<uint8_t>(init_data, init_data + arraysize(init_data) - 1),
589 CreateSessionPromise(RESOLVED)); 575 CreateSessionPromise(RESOLVED));
590 } 576 }
591 577
592 TEST_P(AesDecryptorTest, NormalDecryption) { 578 TEST_P(AesDecryptorTest, NormalDecryption) {
593 std::string session_id = CreateSession(key_id_); 579 std::string session_id = CreateSession(key_id_);
594 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED, true); 580 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED, true);
595 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer( 581 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 INSTANTIATE_TEST_CASE_P(CdmAdapter, 1025 INSTANTIATE_TEST_CASE_P(CdmAdapter,
1040 AesDecryptorTest, 1026 AesDecryptorTest,
1041 testing::Values("CdmAdapter")); 1027 testing::Values("CdmAdapter"));
1042 #endif 1028 #endif
1043 1029
1044 // TODO(jrummell): Once MojoCdm/MojoCdmService/MojoDecryptor/ 1030 // TODO(jrummell): Once MojoCdm/MojoCdmService/MojoDecryptor/
1045 // MojoDecryptorService are implemented, add a third version that tests the 1031 // MojoDecryptorService are implemented, add a third version that tests the
1046 // CDM via mojo. 1032 // CDM via mojo.
1047 1033
1048 } // namespace media 1034 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698