| Index: media/filters/decrypting_audio_decoder_unittest.cc
|
| diff --git a/media/filters/decrypting_audio_decoder_unittest.cc b/media/filters/decrypting_audio_decoder_unittest.cc
|
| index 4f749ceaacca748b0f13ef966174c3b4f1718a8d..016e09a4c13404c8f453c60ba809208b00f135e8 100644
|
| --- a/media/filters/decrypting_audio_decoder_unittest.cc
|
| +++ b/media/filters/decrypting_audio_decoder_unittest.cc
|
| @@ -21,6 +21,7 @@
|
|
|
| using ::testing::_;
|
| using ::testing::AtMost;
|
| +using ::testing::Return;
|
| using ::testing::SaveArg;
|
| using ::testing::StrictMock;
|
|
|
| @@ -63,11 +64,11 @@ class DecryptingAudioDecoderTest : public testing::Test {
|
| : decoder_(new DecryptingAudioDecoder(
|
| message_loop_.task_runner(),
|
| new MediaLog(),
|
| - base::Bind(
|
| - &DecryptingAudioDecoderTest::RequestDecryptorNotification,
|
| - base::Unretained(this)),
|
| + base::Bind(&DecryptingAudioDecoderTest::RequestCdmNotification,
|
| + base::Unretained(this)),
|
| base::Bind(&DecryptingAudioDecoderTest::OnWaitingForDecryptionKey,
|
| base::Unretained(this)))),
|
| + cdm_context_(new StrictMock<MockCdmContext>()),
|
| decryptor_(new StrictMock<MockDecryptor>()),
|
| num_decrypt_and_decode_calls_(0),
|
| num_frames_in_decryptor_(0),
|
| @@ -76,8 +77,7 @@ class DecryptingAudioDecoderTest : public testing::Test {
|
| decoded_frame_list_() {}
|
|
|
| virtual ~DecryptingAudioDecoderTest() {
|
| - EXPECT_CALL(*this, RequestDecryptorNotification(_))
|
| - .Times(testing::AnyNumber());
|
| + EXPECT_CALL(*this, RequestCdmNotification(_)).Times(testing::AnyNumber());
|
| Destroy();
|
| }
|
|
|
| @@ -102,19 +102,30 @@ class DecryptingAudioDecoderTest : public testing::Test {
|
| message_loop_.RunUntilIdle();
|
| }
|
|
|
| - void ExpectDecryptorNotification(Decryptor* decryptor, bool expected_result) {
|
| - EXPECT_CALL(*this, RequestDecryptorNotification(_)).WillOnce(
|
| - RunCallback<0>(decryptor,
|
| - base::Bind(&DecryptingAudioDecoderTest::DecryptorSet,
|
| - base::Unretained(this))));
|
| - EXPECT_CALL(*this, DecryptorSet(expected_result));
|
| + enum CdmType { NO_CDM, CDM_WITHOUT_DECRYPTOR, CDM_WITH_DECRYPTOR };
|
| +
|
| + void SetCdmType(CdmType cdm_type) {
|
| + const bool has_cdm = cdm_type != NO_CDM;
|
| + const bool has_decryptor = cdm_type == CDM_WITH_DECRYPTOR;
|
| +
|
| + EXPECT_CALL(*this, RequestCdmNotification(_))
|
| + .WillOnce(RunCallback<0>(has_cdm ? cdm_context_.get() : nullptr,
|
| + base::Bind(&DecryptingAudioDecoderTest::CdmSet,
|
| + base::Unretained(this))));
|
| +
|
| + if (has_cdm) {
|
| + EXPECT_CALL(*cdm_context_, GetDecryptor())
|
| + .WillRepeatedly(Return(has_decryptor ? decryptor_.get() : nullptr));
|
| + }
|
| +
|
| + EXPECT_CALL(*this, CdmSet(has_decryptor));
|
| }
|
|
|
| void Initialize() {
|
| + SetCdmType(CDM_WITH_DECRYPTOR);
|
| EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _))
|
| .Times(AtMost(1))
|
| .WillOnce(RunCallback<1>(true));
|
| - ExpectDecryptorNotification(decryptor_.get(), true);
|
| EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _))
|
| .WillOnce(SaveArg<1>(&key_added_cb_));
|
|
|
| @@ -250,18 +261,19 @@ class DecryptingAudioDecoderTest : public testing::Test {
|
| message_loop_.RunUntilIdle();
|
| }
|
|
|
| - MOCK_METHOD1(RequestDecryptorNotification, void(const DecryptorReadyCB&));
|
| + MOCK_METHOD1(RequestCdmNotification, void(const CdmReadyCB&));
|
|
|
| MOCK_METHOD1(FrameReady, void(const scoped_refptr<AudioBuffer>&));
|
| MOCK_METHOD1(DecodeDone, void(AudioDecoder::Status));
|
|
|
| - MOCK_METHOD1(DecryptorSet, void(bool));
|
| + MOCK_METHOD1(CdmSet, void(bool));
|
|
|
| MOCK_METHOD0(OnWaitingForDecryptionKey, void(void));
|
|
|
| base::MessageLoop message_loop_;
|
| scoped_ptr<DecryptingAudioDecoder> decoder_;
|
| - scoped_ptr<StrictMock<MockDecryptor> > decryptor_;
|
| + scoped_ptr<StrictMock<MockCdmContext>> cdm_context_;
|
| + scoped_ptr<StrictMock<MockDecryptor>> decryptor_;
|
| AudioDecoderConfig config_;
|
|
|
| // Variables to help the |decryptor_| to simulate decoding delay and flushing.
|
| @@ -304,9 +316,9 @@ TEST_F(DecryptingAudioDecoderTest, Initialize_InvalidAudioConfig) {
|
|
|
| // Ensure decoder handles unsupported audio configs without crashing.
|
| TEST_F(DecryptingAudioDecoderTest, Initialize_UnsupportedAudioConfig) {
|
| + SetCdmType(CDM_WITH_DECRYPTOR);
|
| EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _))
|
| .WillOnce(RunCallback<1>(false));
|
| - ExpectDecryptorNotification(decryptor_.get(), true);
|
|
|
| AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32,
|
| CHANNEL_LAYOUT_STEREO, kSampleRate,
|
| @@ -314,8 +326,16 @@ TEST_F(DecryptingAudioDecoderTest, Initialize_UnsupportedAudioConfig) {
|
| InitializeAndExpectResult(config, false);
|
| }
|
|
|
| -TEST_F(DecryptingAudioDecoderTest, Initialize_NullDecryptor) {
|
| - ExpectDecryptorNotification(NULL, false);
|
| +TEST_F(DecryptingAudioDecoderTest, Initialize_NoCdm) {
|
| + SetCdmType(NO_CDM);
|
| + AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32,
|
| + CHANNEL_LAYOUT_STEREO, kSampleRate,
|
| + EmptyExtraData(), true);
|
| + InitializeAndExpectResult(config, false);
|
| +}
|
| +
|
| +TEST_F(DecryptingAudioDecoderTest, Initialize_CdmWithoutDecryptor) {
|
| + SetCdmType(CDM_WITHOUT_DECRYPTOR);
|
| AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32,
|
| CHANNEL_LAYOUT_STEREO, kSampleRate,
|
| EmptyExtraData(), true);
|
|
|