1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
9 #include "base/callback_helpers.h"
10 #include "base/message_loop/message_loop.h"
11 #include "media/base/audio_buffer.h"
12 #include "media/base/buffers.h"
13 #include "media/base/decoder_buffer.h"
14 #include "media/base/decrypt_config.h"
15 #include "media/base/gmock_callback_support.h"
16 #include "media/base/mock_filters.h"
17 #include "media/base/test_helpers.h"
18 #include "media/filters/decrypting_audio_decoder.h"
19 #include "testing/gmock/include/gmock/gmock.h"
22 using ::testing::AtMost;
23 using ::testing::IsNull;
24 using ::testing::SaveArg;
25 using ::testing::StrictMock;
29 // Make sure the kFakeAudioFrameSize is a valid frame size for all audio decoder
30 // configs used in this test.
31 static const int kFakeAudioFrameSize = 48;
32 static const uint8 kFakeKeyId[] = { 0x4b, 0x65, 0x79, 0x20, 0x49, 0x44 };
33 static const uint8 kFakeIv[DecryptConfig::kDecryptionKeySize] = { 0 };
35 // Create a fake non-empty encrypted buffer.
36 static scoped_refptr<DecoderBuffer> CreateFakeEncryptedBuffer() {
37 const int buffer_size = 16; // Need a non-empty buffer;
38 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(buffer_size));
39 buffer->set_decrypt_config(scoped_ptr<DecryptConfig>(new DecryptConfig(
40 std::string(reinterpret_cast<const char*>(kFakeKeyId),
41 arraysize(kFakeKeyId)),
42 std::string(reinterpret_cast<const char*>(kFakeIv), arraysize(kFakeIv)),
43 std::vector<SubsampleEntry>())));
47 // Use anonymous namespace here to prevent the actions to be defined multiple
48 // times across multiple test files. Sadly we can't use static for them.
51 ACTION_P(ReturnBuffer, buffer) {
52 arg0.Run(buffer.get() ? DemuxerStream::kOk : DemuxerStream::kAborted, buffer);
55 ACTION_P(RunCallbackIfNotNull, param) {
60 ACTION_P2(ResetAndRunCallback, callback, param) {
61 base::ResetAndReturn(callback).Run(param);
64 MATCHER(IsEndOfStream, "end of stream") {
65 return (arg->end_of_stream());
70 class DecryptingAudioDecoderTest : public testing::Test {
72 DecryptingAudioDecoderTest()
73 : decoder_(new DecryptingAudioDecoder(
74 message_loop_.message_loop_proxy(),
76 &DecryptingAudioDecoderTest::RequestDecryptorNotification,
77 base::Unretained(this)))),
78 decryptor_(new StrictMock<MockDecryptor>()),
79 demuxer_(new StrictMock<MockDemuxerStream>(DemuxerStream::AUDIO)),
80 encrypted_buffer_(CreateFakeEncryptedBuffer()),
82 end_of_stream_frame_(AudioBuffer::CreateEOSBuffer()),
83 decoded_frame_list_() {
86 virtual ~DecryptingAudioDecoderTest() {
90 void InitializeAndExpectStatus(const AudioDecoderConfig& config,
91 PipelineStatus status) {
92 // Initialize data now that the config is known. Since the code uses
93 // invalid values (that CreateEmptyBuffer() doesn't support), tweak them
94 // just for CreateEmptyBuffer().
95 int channels = ChannelLayoutToChannelCount(config.channel_layout());
98 decoded_frame_ = AudioBuffer::CreateEmptyBuffer(
99 channels, kFakeAudioFrameSize, kNoTimestamp(), kNoTimestamp());
100 decoded_frame_list_.push_back(decoded_frame_);
102 demuxer_->set_audio_decoder_config(config);
103 decoder_->Initialize(demuxer_.get(), NewExpectedStatusCB(status),
104 base::Bind(&MockStatisticsCB::OnStatistics,
105 base::Unretained(&statistics_cb_)));
106 message_loop_.RunUntilIdle();
110 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _))
112 .WillOnce(RunCallback<1>(true));
113 EXPECT_CALL(*this, RequestDecryptorNotification(_))
114 .WillOnce(RunCallbackIfNotNull(decryptor_.get()));
115 EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _))
116 .WillOnce(SaveArg<1>(&key_added_cb_));
118 config_.Initialize(kCodecVorbis, kSampleFormatPlanarF32,
119 CHANNEL_LAYOUT_STEREO, 44100, NULL, 0, true, true,
120 base::TimeDelta(), base::TimeDelta());
121 InitializeAndExpectStatus(config_, PIPELINE_OK);
123 EXPECT_EQ(DecryptingAudioDecoder::kSupportedBitsPerChannel,
124 decoder_->bits_per_channel());
125 EXPECT_EQ(config_.channel_layout(), decoder_->channel_layout());
126 EXPECT_EQ(config_.samples_per_second(), decoder_->samples_per_second());
129 void ReadAndExpectFrameReadyWith(
130 AudioDecoder::Status status,
131 const scoped_refptr<AudioBuffer>& audio_frame) {
132 if (status != AudioDecoder::kOk)
133 EXPECT_CALL(*this, FrameReady(status, IsNull()));
134 else if (audio_frame->end_of_stream())
135 EXPECT_CALL(*this, FrameReady(status, IsEndOfStream()));
137 EXPECT_CALL(*this, FrameReady(status, audio_frame));
139 decoder_->Read(base::Bind(&DecryptingAudioDecoderTest::FrameReady,
140 base::Unretained(this)));
141 message_loop_.RunUntilIdle();
144 // Sets up expectations and actions to put DecryptingAudioDecoder in an
145 // active normal decoding state.
146 void EnterNormalDecodingState() {
147 Decryptor::AudioBuffers end_of_stream_frames_(1, end_of_stream_frame_);
149 EXPECT_CALL(*demuxer_, Read(_))
150 .WillOnce(ReturnBuffer(encrypted_buffer_))
151 .WillRepeatedly(ReturnBuffer(DecoderBuffer::CreateEOSBuffer()));
152 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _))
153 .WillOnce(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_))
154 .WillRepeatedly(RunCallback<1>(Decryptor::kNeedMoreData,
155 Decryptor::AudioBuffers()));
156 EXPECT_CALL(statistics_cb_, OnStatistics(_));
158 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, decoded_frame_);
161 // Sets up expectations and actions to put DecryptingAudioDecoder in an end
162 // of stream state. This function must be called after
163 // EnterNormalDecodingState() to work.
164 void EnterEndOfStreamState() {
165 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, end_of_stream_frame_);
168 // Make the read callback pending by saving and not firing it.
169 void EnterPendingReadState() {
170 EXPECT_TRUE(pending_demuxer_read_cb_.is_null());
171 EXPECT_CALL(*demuxer_, Read(_))
172 .WillOnce(SaveArg<0>(&pending_demuxer_read_cb_));
173 decoder_->Read(base::Bind(&DecryptingAudioDecoderTest::FrameReady,
174 base::Unretained(this)));
175 message_loop_.RunUntilIdle();
176 // Make sure the Read() on the decoder triggers a Read() on the demuxer.
177 EXPECT_FALSE(pending_demuxer_read_cb_.is_null());
180 // Make the audio decode callback pending by saving and not firing it.
181 void EnterPendingDecodeState() {
182 EXPECT_TRUE(pending_audio_decode_cb_.is_null());
183 EXPECT_CALL(*demuxer_, Read(_))
184 .WillRepeatedly(ReturnBuffer(encrypted_buffer_));
185 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(encrypted_buffer_, _))
186 .WillOnce(SaveArg<1>(&pending_audio_decode_cb_));
188 decoder_->Read(base::Bind(&DecryptingAudioDecoderTest::FrameReady,
189 base::Unretained(this)));
190 message_loop_.RunUntilIdle();
191 // Make sure the Read() on the decoder triggers a DecryptAndDecode() on the
193 EXPECT_FALSE(pending_audio_decode_cb_.is_null());
196 void EnterWaitingForKeyState() {
197 EXPECT_CALL(*demuxer_, Read(_))
198 .WillRepeatedly(ReturnBuffer(encrypted_buffer_));
199 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(encrypted_buffer_, _))
200 .WillRepeatedly(RunCallback<1>(Decryptor::kNoKey,
201 Decryptor::AudioBuffers()));
202 decoder_->Read(base::Bind(&DecryptingAudioDecoderTest::FrameReady,
203 base::Unretained(this)));
204 message_loop_.RunUntilIdle();
207 void AbortPendingAudioDecodeCB() {
208 if (!pending_audio_decode_cb_.is_null()) {
209 base::ResetAndReturn(&pending_audio_decode_cb_).Run(
210 Decryptor::kSuccess, Decryptor::AudioBuffers());
214 void AbortAllPendingCBs() {
215 if (!pending_init_cb_.is_null()) {
216 ASSERT_TRUE(pending_audio_decode_cb_.is_null());
217 base::ResetAndReturn(&pending_init_cb_).Run(false);
221 AbortPendingAudioDecodeCB();
225 EXPECT_CALL(*decryptor_, ResetDecoder(Decryptor::kAudio))
226 .WillRepeatedly(InvokeWithoutArgs(
227 this, &DecryptingAudioDecoderTest::AbortPendingAudioDecodeCB));
229 decoder_->Reset(NewExpectedClosure());
230 message_loop_.RunUntilIdle();
234 EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio))
235 .WillRepeatedly(InvokeWithoutArgs(
236 this, &DecryptingAudioDecoderTest::AbortAllPendingCBs));
238 decoder_->Stop(NewExpectedClosure());
239 message_loop_.RunUntilIdle();
242 MOCK_METHOD1(RequestDecryptorNotification, void(const DecryptorReadyCB&));
244 MOCK_METHOD2(FrameReady,
245 void(AudioDecoder::Status, const scoped_refptr<AudioBuffer>&));
247 base::MessageLoop message_loop_;
248 scoped_ptr<DecryptingAudioDecoder> decoder_;
249 scoped_ptr<StrictMock<MockDecryptor> > decryptor_;
250 scoped_ptr<StrictMock<MockDemuxerStream> > demuxer_;
251 MockStatisticsCB statistics_cb_;
252 AudioDecoderConfig config_;
254 DemuxerStream::ReadCB pending_demuxer_read_cb_;
255 Decryptor::DecoderInitCB pending_init_cb_;
256 Decryptor::NewKeyCB key_added_cb_;
257 Decryptor::AudioDecodeCB pending_audio_decode_cb_;
259 // Constant buffer/frames to be returned by the |demuxer_| and |decryptor_|.
260 scoped_refptr<DecoderBuffer> encrypted_buffer_;
261 scoped_refptr<AudioBuffer> decoded_frame_;
262 scoped_refptr<AudioBuffer> end_of_stream_frame_;
263 Decryptor::AudioBuffers decoded_frame_list_;
266 DISALLOW_COPY_AND_ASSIGN(DecryptingAudioDecoderTest);
269 TEST_F(DecryptingAudioDecoderTest, Initialize_Normal) {
273 // Ensure that DecryptingAudioDecoder only accepts encrypted audio.
274 TEST_F(DecryptingAudioDecoderTest, Initialize_UnencryptedAudioConfig) {
275 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32,
276 CHANNEL_LAYOUT_STEREO, 44100, NULL, 0, false);
278 InitializeAndExpectStatus(config, DECODER_ERROR_NOT_SUPPORTED);
281 // Ensure decoder handles invalid audio configs without crashing.
282 TEST_F(DecryptingAudioDecoderTest, Initialize_InvalidAudioConfig) {
283 AudioDecoderConfig config(kUnknownAudioCodec, kUnknownSampleFormat,
284 CHANNEL_LAYOUT_STEREO, 0, NULL, 0, true);
286 InitializeAndExpectStatus(config, PIPELINE_ERROR_DECODE);
289 // Ensure decoder handles unsupported audio configs without crashing.
290 TEST_F(DecryptingAudioDecoderTest, Initialize_UnsupportedAudioConfig) {
291 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _))
292 .WillOnce(RunCallback<1>(false));
293 EXPECT_CALL(*this, RequestDecryptorNotification(_))
294 .WillOnce(RunCallbackIfNotNull(decryptor_.get()));
296 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32,
297 CHANNEL_LAYOUT_STEREO, 44100, NULL, 0, true);
298 InitializeAndExpectStatus(config, DECODER_ERROR_NOT_SUPPORTED);
301 TEST_F(DecryptingAudioDecoderTest, Initialize_NullDecryptor) {
302 EXPECT_CALL(*this, RequestDecryptorNotification(_))
303 .WillRepeatedly(RunCallbackIfNotNull(static_cast<Decryptor*>(NULL)));
305 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32,
306 CHANNEL_LAYOUT_STEREO, 44100, NULL, 0, true);
307 InitializeAndExpectStatus(config, DECODER_ERROR_NOT_SUPPORTED);
310 // Test normal decrypt and decode case.
311 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_Normal) {
313 EnterNormalDecodingState();
316 // Test the case where the decryptor returns error when doing decrypt and
318 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_DecodeError) {
321 EXPECT_CALL(*demuxer_, Read(_))
322 .WillRepeatedly(ReturnBuffer(encrypted_buffer_));
323 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _))
324 .WillRepeatedly(RunCallback<1>(Decryptor::kError,
325 Decryptor::AudioBuffers()));
327 ReadAndExpectFrameReadyWith(AudioDecoder::kDecodeError, NULL);
330 // Test the case where the decryptor returns kNeedMoreData to ask for more
331 // buffers before it can produce a frame.
332 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_NeedMoreData) {
335 EXPECT_CALL(*demuxer_, Read(_))
337 .WillRepeatedly(ReturnBuffer(encrypted_buffer_));
338 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _))
339 .WillOnce(RunCallback<1>(Decryptor::kNeedMoreData,
340 Decryptor::AudioBuffers()))
341 .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_));
342 EXPECT_CALL(statistics_cb_, OnStatistics(_))
345 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, decoded_frame_);
348 // Test the case where the decryptor returns multiple decoded frames.
349 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_MultipleFrames) {
352 scoped_refptr<AudioBuffer> frame_a = AudioBuffer::CreateEmptyBuffer(
353 ChannelLayoutToChannelCount(config_.channel_layout()),
357 scoped_refptr<AudioBuffer> frame_b = AudioBuffer::CreateEmptyBuffer(
358 ChannelLayoutToChannelCount(config_.channel_layout()),
362 decoded_frame_list_.push_back(frame_a);
363 decoded_frame_list_.push_back(frame_b);
365 EXPECT_CALL(*demuxer_, Read(_))
366 .WillOnce(ReturnBuffer(encrypted_buffer_));
367 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _))
368 .WillOnce(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_));
369 EXPECT_CALL(statistics_cb_, OnStatistics(_));
371 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, decoded_frame_);
372 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, frame_a);
373 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, frame_b);
376 // Test the case where the decryptor receives end-of-stream buffer.
377 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_EndOfStream) {
379 EnterNormalDecodingState();
380 EnterEndOfStreamState();
383 // Test aborted read on the demuxer stream.
384 TEST_F(DecryptingAudioDecoderTest, DemuxerRead_Aborted) {
387 // ReturnBuffer() with NULL triggers aborted demuxer read.
388 EXPECT_CALL(*demuxer_, Read(_))
389 .WillOnce(ReturnBuffer(scoped_refptr<DecoderBuffer>()));
391 ReadAndExpectFrameReadyWith(AudioDecoder::kAborted, NULL);
394 // Test config change on the demuxer stream.
395 TEST_F(DecryptingAudioDecoderTest, DemuxerRead_ConfigChange) {
398 // The new config is different from the initial config in bits-per-channel,
399 // channel layout and samples_per_second.
400 AudioDecoderConfig new_config(kCodecVorbis, kSampleFormatPlanarS16,
401 CHANNEL_LAYOUT_5_1, 88200, NULL, 0, false);
402 EXPECT_NE(new_config.bits_per_channel(), config_.bits_per_channel());
403 EXPECT_NE(new_config.channel_layout(), config_.channel_layout());
404 EXPECT_NE(new_config.samples_per_second(), config_.samples_per_second());
406 demuxer_->set_audio_decoder_config(new_config);
407 EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio));
408 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _))
409 .WillOnce(RunCallback<1>(true));
410 EXPECT_CALL(*demuxer_, Read(_))
411 .WillOnce(RunCallback<0>(DemuxerStream::kConfigChanged,
412 scoped_refptr<DecoderBuffer>()))
413 .WillRepeatedly(ReturnBuffer(encrypted_buffer_));
414 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _))
415 .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_));
416 EXPECT_CALL(statistics_cb_, OnStatistics(_));
418 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, decoded_frame_);
420 EXPECT_EQ(new_config.bits_per_channel(), decoder_->bits_per_channel());
421 EXPECT_EQ(new_config.channel_layout(), decoder_->channel_layout());
422 EXPECT_EQ(new_config.samples_per_second(), decoder_->samples_per_second());
425 // Test config change failure.
426 TEST_F(DecryptingAudioDecoderTest, DemuxerRead_ConfigChangeFailed) {
429 EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio));
430 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _))
431 .WillOnce(RunCallback<1>(false));
432 EXPECT_CALL(*demuxer_, Read(_))
433 .WillOnce(RunCallback<0>(DemuxerStream::kConfigChanged,
434 scoped_refptr<DecoderBuffer>()))
435 .WillRepeatedly(ReturnBuffer(encrypted_buffer_));
437 ReadAndExpectFrameReadyWith(AudioDecoder::kDecodeError, NULL);
440 // Test the case where the a key is added when the decryptor is in
441 // kWaitingForKey state.
442 TEST_F(DecryptingAudioDecoderTest, KeyAdded_DuringWaitingForKey) {
444 EnterWaitingForKeyState();
446 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _))
447 .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_));
448 EXPECT_CALL(statistics_cb_, OnStatistics(_));
449 EXPECT_CALL(*this, FrameReady(AudioDecoder::kOk, decoded_frame_));
451 message_loop_.RunUntilIdle();
454 // Test the case where the a key is added when the decryptor is in
455 // kPendingDecode state.
456 TEST_F(DecryptingAudioDecoderTest, KeyAdded_DruingPendingDecode) {
458 EnterPendingDecodeState();
460 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _))
461 .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_));
462 EXPECT_CALL(statistics_cb_, OnStatistics(_));
463 EXPECT_CALL(*this, FrameReady(AudioDecoder::kOk, decoded_frame_));
464 // The audio decode callback is returned after the correct decryption key is
467 base::ResetAndReturn(&pending_audio_decode_cb_).Run(
468 Decryptor::kNoKey, Decryptor::AudioBuffers());
469 message_loop_.RunUntilIdle();
472 // Test resetting when the decoder is in kIdle state but has not decoded any
474 TEST_F(DecryptingAudioDecoderTest, Reset_DuringIdleAfterInitialization) {
479 // Test resetting when the decoder is in kIdle state after it has decoded one
481 TEST_F(DecryptingAudioDecoderTest, Reset_DuringIdleAfterDecodedOneFrame) {
483 EnterNormalDecodingState();
487 // Test resetting when the decoder is in kPendingDemuxerRead state and the read
488 // callback is returned with kOk.
489 TEST_F(DecryptingAudioDecoderTest, Reset_DuringDemuxerRead_Ok) {
491 EnterPendingReadState();
493 EXPECT_CALL(*this, FrameReady(AudioDecoder::kAborted, IsNull()));
496 base::ResetAndReturn(&pending_demuxer_read_cb_).Run(DemuxerStream::kOk,
498 message_loop_.RunUntilIdle();
501 // Test resetting when the decoder is in kPendingDemuxerRead state and the read
502 // callback is returned with kAborted.
503 TEST_F(DecryptingAudioDecoderTest, Reset_DuringDemuxerRead_Aborted) {
505 EnterPendingReadState();
507 // Make sure we get a NULL audio frame returned.
508 EXPECT_CALL(*this, FrameReady(AudioDecoder::kAborted, IsNull()));
511 base::ResetAndReturn(&pending_demuxer_read_cb_).Run(DemuxerStream::kAborted,
513 message_loop_.RunUntilIdle();
516 // Test resetting when the decoder is in kPendingDemuxerRead state and the read
517 // callback is returned with kConfigChanged.
518 TEST_F(DecryptingAudioDecoderTest, Reset_DuringDemuxerRead_ConfigChange) {
520 EnterPendingReadState();
524 // The new config is different from the initial config in bits-per-channel,
525 // channel layout and samples_per_second.
526 AudioDecoderConfig new_config(kCodecVorbis, kSampleFormatPlanarS16,
527 CHANNEL_LAYOUT_5_1, 88200, NULL, 0, false);
528 EXPECT_NE(new_config.bits_per_channel(), config_.bits_per_channel());
529 EXPECT_NE(new_config.channel_layout(), config_.channel_layout());
530 EXPECT_NE(new_config.samples_per_second(), config_.samples_per_second());
532 // Even during pending reset, the decoder still needs to be initialized with
534 demuxer_->set_audio_decoder_config(new_config);
535 EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio));
536 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _))
537 .WillOnce(RunCallback<1>(true));
538 EXPECT_CALL(*this, FrameReady(AudioDecoder::kAborted, IsNull()));
540 base::ResetAndReturn(&pending_demuxer_read_cb_)
541 .Run(DemuxerStream::kConfigChanged, NULL);
542 message_loop_.RunUntilIdle();
544 EXPECT_EQ(new_config.bits_per_channel(), decoder_->bits_per_channel());
545 EXPECT_EQ(new_config.channel_layout(), decoder_->channel_layout());
546 EXPECT_EQ(new_config.samples_per_second(), decoder_->samples_per_second());
549 // Test resetting when the decoder is in kPendingDemuxerRead state, the read
550 // callback is returned with kConfigChanged and the config change fails.
551 TEST_F(DecryptingAudioDecoderTest, Reset_DuringDemuxerRead_ConfigChangeFailed) {
553 EnterPendingReadState();
557 // Even during pending reset, the decoder still needs to be initialized with
559 EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio));
560 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _))
561 .WillOnce(RunCallback<1>(false));
562 EXPECT_CALL(*this, FrameReady(AudioDecoder::kDecodeError, IsNull()));
564 base::ResetAndReturn(&pending_demuxer_read_cb_)
565 .Run(DemuxerStream::kConfigChanged, NULL);
566 message_loop_.RunUntilIdle();
569 // Test resetting when the decoder is in kPendingConfigChange state.
570 TEST_F(DecryptingAudioDecoderTest, Reset_DuringPendingConfigChange) {
572 EnterNormalDecodingState();
574 EXPECT_CALL(*demuxer_, Read(_))
575 .WillOnce(RunCallback<0>(DemuxerStream::kConfigChanged,
576 scoped_refptr<DecoderBuffer>()));
577 EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio));
578 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _))
579 .WillOnce(SaveArg<1>(&pending_init_cb_));
581 decoder_->Read(base::Bind(&DecryptingAudioDecoderTest::FrameReady,
582 base::Unretained(this)));
583 message_loop_.RunUntilIdle();
584 EXPECT_FALSE(pending_init_cb_.is_null());
586 EXPECT_CALL(*this, FrameReady(AudioDecoder::kAborted, IsNull()));
589 base::ResetAndReturn(&pending_init_cb_).Run(true);
590 message_loop_.RunUntilIdle();
593 // Test resetting when the decoder is in kPendingDecode state.
594 TEST_F(DecryptingAudioDecoderTest, Reset_DuringPendingDecode) {
596 EnterPendingDecodeState();
598 EXPECT_CALL(*this, FrameReady(AudioDecoder::kAborted, IsNull()));
603 // Test resetting when the decoder is in kWaitingForKey state.
604 TEST_F(DecryptingAudioDecoderTest, Reset_DuringWaitingForKey) {
606 EnterWaitingForKeyState();
608 EXPECT_CALL(*this, FrameReady(AudioDecoder::kAborted, IsNull()));
613 // Test resetting when the decoder has hit end of stream and is in
614 // kDecodeFinished state.
615 TEST_F(DecryptingAudioDecoderTest, Reset_AfterDecodeFinished) {
617 EnterNormalDecodingState();
618 EnterEndOfStreamState();
622 // Test resetting after the decoder has been reset.
623 TEST_F(DecryptingAudioDecoderTest, Reset_AfterReset) {
625 EnterNormalDecodingState();