Chromium Code Reviews| Index: media/cdm/aes_decryptor_unittest.cc |
| diff --git a/media/cdm/aes_decryptor_unittest.cc b/media/cdm/aes_decryptor_unittest.cc |
| index 845b216c54af3b56f1722f25c6e227ca18e6bb67..d76bc328a5e98439d07b0c580b0d6b0361bcc923 100644 |
| --- a/media/cdm/aes_decryptor_unittest.cc |
| +++ b/media/cdm/aes_decryptor_unittest.cc |
| @@ -38,11 +38,14 @@ using ::testing::Gt; |
| using ::testing::IsNull; |
| using ::testing::NotNull; |
| using ::testing::SaveArg; |
| +using ::testing::StrictMock; |
| using ::testing::StrNe; |
| using ::testing::Unused; |
| MATCHER(IsEmpty, "") { return arg.empty(); } |
| -MATCHER(IsNotEmpty, "") { return !arg.empty(); } |
| +MATCHER(NotEmpty, "") { |
|
xhwang
2016/12/06 20:51:49
IsEmpty/NotEmpty is consistent with IsNull/NotNull
|
| + return !arg.empty(); |
| +} |
| MATCHER(IsJSONDictionary, "") { |
| std::string result(arg.begin(), arg.end()); |
| std::unique_ptr<base::Value> root(base::JSONReader().ReadToValue(result)); |
| @@ -238,12 +241,12 @@ class AesDecryptorTest : public testing::TestWithParam<std::string> { |
| if (GetParam() == "AesDecryptor") { |
| OnCdmCreated( |
| new AesDecryptor(GURL::EmptyGURL(), |
| - base::Bind(&AesDecryptorTest::OnSessionMessage, |
| - base::Unretained(this)), |
| - base::Bind(&AesDecryptorTest::OnSessionClosed, |
| - base::Unretained(this)), |
| - base::Bind(&AesDecryptorTest::OnSessionKeysChange, |
| - base::Unretained(this))), |
| + base::Bind(&MockCdmClient::OnSessionMessage, |
| + base::Unretained(&cdm_client_)), |
| + base::Bind(&MockCdmClient::OnSessionClosed, |
| + base::Unretained(&cdm_client_)), |
| + base::Bind(&MockCdmClient::OnSessionKeysChange, |
| + base::Unretained(&cdm_client_))), |
| std::string()); |
| } else if (GetParam() == "CdmAdapter") { |
| CdmConfig cdm_config; // default settings of false are sufficient. |
| @@ -254,14 +257,14 @@ class AesDecryptorTest : public testing::TestWithParam<std::string> { |
| helper_->KeySystemName(), helper_->LibraryPath(), cdm_config, |
| std::move(allocator), base::Bind(&AesDecryptorTest::CreateCdmFileIO, |
| base::Unretained(this)), |
| - base::Bind(&AesDecryptorTest::OnSessionMessage, |
| - base::Unretained(this)), |
| - base::Bind(&AesDecryptorTest::OnSessionClosed, |
| - base::Unretained(this)), |
| - base::Bind(&AesDecryptorTest::OnSessionKeysChange, |
| - base::Unretained(this)), |
| - base::Bind(&AesDecryptorTest::OnSessionExpirationUpdate, |
| - base::Unretained(this)), |
| + base::Bind(&MockCdmClient::OnSessionMessage, |
| + base::Unretained(&cdm_client_)), |
| + base::Bind(&MockCdmClient::OnSessionClosed, |
| + base::Unretained(&cdm_client_)), |
| + base::Bind(&MockCdmClient::OnSessionKeysChange, |
| + base::Unretained(&cdm_client_)), |
| + base::Bind(&MockCdmClient::OnSessionExpirationUpdate, |
| + base::Unretained(&cdm_client_)), |
| base::Bind(&AesDecryptorTest::OnCdmCreated, base::Unretained(this))); |
| base::RunLoop().RunUntilIdle(); |
| @@ -323,7 +326,8 @@ class AesDecryptorTest : public testing::TestWithParam<std::string> { |
| // Creates a new session using |key_id|. Returns the session ID. |
| std::string CreateSession(const std::vector<uint8_t>& key_id) { |
| DCHECK(!key_id.empty()); |
| - EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsJSONDictionary())); |
| + EXPECT_CALL(cdm_client_, |
| + OnSessionMessage(NotEmpty(), _, IsJSONDictionary())); |
| cdm_->CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION, |
| EmeInitDataType::WEBM, key_id, |
| CreateSessionPromise(RESOLVED)); |
| @@ -334,7 +338,7 @@ class AesDecryptorTest : public testing::TestWithParam<std::string> { |
| // Closes the session specified by |session_id|. |
| void CloseSession(const std::string& session_id) { |
| - EXPECT_CALL(*this, OnSessionClosed(session_id)); |
| + EXPECT_CALL(cdm_client_, OnSessionClosed(session_id)); |
| cdm_->CloseSession(session_id, CreatePromise(RESOLVED)); |
| } |
| @@ -344,17 +348,6 @@ class AesDecryptorTest : public testing::TestWithParam<std::string> { |
| cdm_->RemoveSession(session_id, CreatePromise(REJECTED)); |
| } |
| - MOCK_METHOD2(OnSessionKeysChangeCalled, |
| - void(const std::string& session_id, |
| - bool has_additional_usable_key)); |
| - |
| - void OnSessionKeysChange(const std::string& session_id, |
| - bool has_additional_usable_key, |
| - CdmKeysInfo keys_info) { |
| - keys_info_.swap(keys_info); |
| - OnSessionKeysChangeCalled(session_id, has_additional_usable_key); |
| - } |
| - |
| // Updates the session specified by |session_id| with |key|. |result| |
| // tests that the update succeeds or generates an error. |
| void UpdateSessionAndExpect(std::string session_id, |
| @@ -364,10 +357,10 @@ class AesDecryptorTest : public testing::TestWithParam<std::string> { |
| DCHECK(!key.empty()); |
| if (expected_result == RESOLVED) { |
| - EXPECT_CALL(*this, |
| + EXPECT_CALL(cdm_client_, |
| OnSessionKeysChangeCalled(session_id, new_key_expected)); |
| } else { |
| - EXPECT_CALL(*this, OnSessionKeysChangeCalled(_, _)).Times(0); |
| + EXPECT_CALL(cdm_client_, OnSessionKeysChangeCalled(_, _)).Times(0); |
| } |
| cdm_->UpdateSession(session_id, |
| @@ -375,8 +368,8 @@ class AesDecryptorTest : public testing::TestWithParam<std::string> { |
| CreatePromise(expected_result)); |
| } |
| - bool KeysInfoContains(std::vector<uint8_t> expected) { |
| - for (auto* key_id : keys_info_) { |
| + bool KeysInfoContains(const std::vector<uint8_t>& expected) { |
| + for (auto* key_id : cdm_client_.keys_info()) { |
| if (key_id->key_id == expected) |
| return true; |
| } |
| @@ -452,19 +445,11 @@ class AesDecryptorTest : public testing::TestWithParam<std::string> { |
| return nullptr; |
| } |
| - MOCK_METHOD3(OnSessionMessage, |
| - void(const std::string& session_id, |
| - MediaKeys::MessageType message_type, |
| - const std::vector<uint8_t>& message)); |
| - MOCK_METHOD1(OnSessionClosed, void(const std::string& session_id)); |
| - MOCK_METHOD2(OnSessionExpirationUpdate, |
| - void(const std::string& session_id, base::Time new_expiry_time)); |
| - |
| + StrictMock<MockCdmClient> cdm_client_; |
| scoped_refptr<MediaKeys> cdm_; |
| Decryptor* decryptor_; |
| Decryptor::DecryptCB decrypt_cb_; |
| std::string session_id_; |
| - CdmKeysInfo keys_info_; |
| // Helper class to load/unload External Clear Key Library, if necessary. |
| std::unique_ptr<ExternalClearKeyTestHelper> helper_; |
| @@ -496,16 +481,19 @@ TEST_P(AesDecryptorTest, CreateSessionWithEmptyInitData) { |
| TEST_P(AesDecryptorTest, CreateSessionWithVariousLengthInitData_WebM) { |
| std::vector<uint8_t> init_data; |
| init_data.resize(1); |
| + EXPECT_CALL(cdm_client_, OnSessionMessage(NotEmpty(), _, IsJSONDictionary())); |
| cdm_->CreateSessionAndGenerateRequest( |
| MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, |
| std::vector<uint8_t>(init_data), CreateSessionPromise(RESOLVED)); |
| init_data.resize(16); // The expected size. |
| + EXPECT_CALL(cdm_client_, OnSessionMessage(NotEmpty(), _, IsJSONDictionary())); |
| cdm_->CreateSessionAndGenerateRequest( |
| MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, |
| std::vector<uint8_t>(init_data), CreateSessionPromise(RESOLVED)); |
| init_data.resize(512); |
| + EXPECT_CALL(cdm_client_, OnSessionMessage(NotEmpty(), _, IsJSONDictionary())); |
| cdm_->CreateSessionAndGenerateRequest( |
| MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, |
| std::vector<uint8_t>(init_data), CreateSessionPromise(RESOLVED)); |
| @@ -517,17 +505,17 @@ TEST_P(AesDecryptorTest, CreateSessionWithVariousLengthInitData_WebM) { |
| } |
| TEST_P(AesDecryptorTest, MultipleCreateSession) { |
| - EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsNotEmpty())); |
| + EXPECT_CALL(cdm_client_, OnSessionMessage(NotEmpty(), _, IsJSONDictionary())); |
| cdm_->CreateSessionAndGenerateRequest( |
| MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, |
| std::vector<uint8_t>(1), CreateSessionPromise(RESOLVED)); |
| - EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsNotEmpty())); |
| + EXPECT_CALL(cdm_client_, OnSessionMessage(NotEmpty(), _, IsJSONDictionary())); |
| cdm_->CreateSessionAndGenerateRequest( |
| MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, |
| std::vector<uint8_t>(1), CreateSessionPromise(RESOLVED)); |
| - EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsNotEmpty())); |
| + EXPECT_CALL(cdm_client_, OnSessionMessage(NotEmpty(), _, IsJSONDictionary())); |
| cdm_->CreateSessionAndGenerateRequest( |
| MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, |
| std::vector<uint8_t>(1), CreateSessionPromise(RESOLVED)); |
| @@ -550,7 +538,7 @@ TEST_P(AesDecryptorTest, CreateSessionWithCencInitData) { |
| }; |
| #if defined(USE_PROPRIETARY_CODECS) |
| - EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsJSONDictionary())); |
| + EXPECT_CALL(cdm_client_, OnSessionMessage(NotEmpty(), _, IsJSONDictionary())); |
| cdm_->CreateSessionAndGenerateRequest( |
| MediaKeys::TEMPORARY_SESSION, EmeInitDataType::CENC, |
| std::vector<uint8_t>(init_data, init_data + arraysize(init_data)), |
| @@ -567,7 +555,7 @@ TEST_P(AesDecryptorTest, CreateSessionWithKeyIdsInitData) { |
| const char init_data[] = |
| "{\"kids\":[\"AQI\",\"AQIDBA\",\"AQIDBAUGBwgJCgsMDQ4PEA\"]}"; |
| - EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsJSONDictionary())); |
| + EXPECT_CALL(cdm_client_, OnSessionMessage(NotEmpty(), _, IsJSONDictionary())); |
| cdm_->CreateSessionAndGenerateRequest( |
| MediaKeys::TEMPORARY_SESSION, EmeInitDataType::KEYIDS, |
| std::vector<uint8_t>(init_data, init_data + arraysize(init_data) - 1), |