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)),
44 std::vector<SubsampleEntry>())));
48 // Use anonymous namespace here to prevent the actions to be defined multiple
49 // times across multiple test files. Sadly we can't use static for them.
52 ACTION_P(ReturnBuffer, buffer) {
53 arg0.Run(buffer.get() ? DemuxerStream::kOk : DemuxerStream::kAborted, buffer);
56 ACTION_P(RunCallbackIfNotNull, param) {
61 ACTION_P2(ResetAndRunCallback, callback, param) {
62 base::ResetAndReturn(callback).Run(param);
65 MATCHER(IsEndOfStream, "end of stream") {
66 return (arg->end_of_stream());
71 class DecryptingAudioDecoderTest : public testing::Test {
73 DecryptingAudioDecoderTest()
74 : decoder_(new DecryptingAudioDecoder(
75 message_loop_.message_loop_proxy(),
77 &DecryptingAudioDecoderTest::RequestDecryptorNotification,
78 base::Unretained(this)))),
79 decryptor_(new StrictMock<MockDecryptor>()),
80 demuxer_(new StrictMock<MockDemuxerStream>(DemuxerStream::AUDIO)),
81 encrypted_buffer_(CreateFakeEncryptedBuffer()),
83 end_of_stream_frame_(AudioBuffer::CreateEOSBuffer()),
84 decoded_frame_list_() {
87 void InitializeAndExpectStatus(const AudioDecoderConfig& config,
88 PipelineStatus status) {
89 // Initialize data now that the config is known. Since the code uses
90 // invalid values (that CreateEmptyBuffer() doesn't support), tweak them
91 // just for CreateEmptyBuffer().
92 int channels = ChannelLayoutToChannelCount(config.channel_layout());
95 decoded_frame_ = AudioBuffer::CreateEmptyBuffer(
96 channels, kFakeAudioFrameSize, kNoTimestamp(), kNoTimestamp());
97 decoded_frame_list_.push_back(decoded_frame_);
99 demuxer_->set_audio_decoder_config(config);
100 decoder_->Initialize(demuxer_.get(), NewExpectedStatusCB(status),
101 base::Bind(&MockStatisticsCB::OnStatistics,
102 base::Unretained(&statistics_cb_)));
103 message_loop_.RunUntilIdle();
107 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _))
109 .WillOnce(RunCallback<1>(true));
110 EXPECT_CALL(*this, RequestDecryptorNotification(_))
111 .WillOnce(RunCallbackIfNotNull(decryptor_.get()));
112 EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _))
113 .WillOnce(SaveArg<1>(&key_added_cb_));
115 config_.Initialize(kCodecVorbis, kSampleFormatPlanarF32,
116 CHANNEL_LAYOUT_STEREO, 44100, NULL, 0, true, true,
117 base::TimeDelta(), base::TimeDelta());
118 InitializeAndExpectStatus(config_, PIPELINE_OK);
120 EXPECT_EQ(DecryptingAudioDecoder::kSupportedBitsPerChannel,
121 decoder_->bits_per_channel());
122 EXPECT_EQ(config_.channel_layout(), decoder_->channel_layout());
123 EXPECT_EQ(config_.samples_per_second(), decoder_->samples_per_second());
126 void ReadAndExpectFrameReadyWith(
127 AudioDecoder::Status status,
128 const scoped_refptr<AudioBuffer>& audio_frame) {
129 if (status != AudioDecoder::kOk)
130 EXPECT_CALL(*this, FrameReady(status, IsNull()));
131 else if (audio_frame->end_of_stream())
132 EXPECT_CALL(*this, FrameReady(status, IsEndOfStream()));
134 EXPECT_CALL(*this, FrameReady(status, audio_frame));
136 decoder_->Read(base::Bind(&DecryptingAudioDecoderTest::FrameReady,
137 base::Unretained(this)));
138 message_loop_.RunUntilIdle();
141 // Sets up expectations and actions to put DecryptingAudioDecoder in an
142 // active normal decoding state.
143 void EnterNormalDecodingState() {
144 Decryptor::AudioBuffers end_of_stream_frames_(1, end_of_stream_frame_);
146 EXPECT_CALL(*demuxer_, Read(_))
147 .WillOnce(ReturnBuffer(encrypted_buffer_))
148 .WillRepeatedly(ReturnBuffer(DecoderBuffer::CreateEOSBuffer()));
149 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _))
150 .WillOnce(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_))
151 .WillRepeatedly(RunCallback<1>(Decryptor::kNeedMoreData,
152 Decryptor::AudioBuffers()));
153 EXPECT_CALL(statistics_cb_, OnStatistics(_));
155 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, decoded_frame_);
158 // Sets up expectations and actions to put DecryptingAudioDecoder in an end
159 // of stream state. This function must be called after
160 // EnterNormalDecodingState() to work.
161 void EnterEndOfStreamState() {
162 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, end_of_stream_frame_);
165 // Make the read callback pending by saving and not firing it.
166 void EnterPendingReadState() {
167 EXPECT_TRUE(pending_demuxer_read_cb_.is_null());
168 EXPECT_CALL(*demuxer_, Read(_))
169 .WillOnce(SaveArg<0>(&pending_demuxer_read_cb_));
170 decoder_->Read(base::Bind(&DecryptingAudioDecoderTest::FrameReady,
171 base::Unretained(this)));
172 message_loop_.RunUntilIdle();
173 // Make sure the Read() on the decoder triggers a Read() on the demuxer.
174 EXPECT_FALSE(pending_demuxer_read_cb_.is_null());
177 // Make the audio decode callback pending by saving and not firing it.
178 void EnterPendingDecodeState() {
179 EXPECT_TRUE(pending_audio_decode_cb_.is_null());
180 EXPECT_CALL(*demuxer_, Read(_))
181 .WillRepeatedly(ReturnBuffer(encrypted_buffer_));
182 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(encrypted_buffer_, _))
183 .WillOnce(SaveArg<1>(&pending_audio_decode_cb_));
185 decoder_->Read(base::Bind(&DecryptingAudioDecoderTest::FrameReady,
186 base::Unretained(this)));
187 message_loop_.RunUntilIdle();
188 // Make sure the Read() on the decoder triggers a DecryptAndDecode() on the
190 EXPECT_FALSE(pending_audio_decode_cb_.is_null());
193 void EnterWaitingForKeyState() {
194 EXPECT_CALL(*demuxer_, Read(_))
195 .WillRepeatedly(ReturnBuffer(encrypted_buffer_));
196 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(encrypted_buffer_, _))
197 .WillRepeatedly(RunCallback<1>(Decryptor::kNoKey,
198 Decryptor::AudioBuffers()));
199 decoder_->Read(base::Bind(&DecryptingAudioDecoderTest::FrameReady,
200 base::Unretained(this)));
201 message_loop_.RunUntilIdle();
204 void AbortPendingAudioDecodeCB() {
205 if (!pending_audio_decode_cb_.is_null()) {
206 base::ResetAndReturn(&pending_audio_decode_cb_).Run(
207 Decryptor::kSuccess, Decryptor::AudioBuffers());
212 EXPECT_CALL(*decryptor_, ResetDecoder(Decryptor::kAudio))
213 .WillRepeatedly(InvokeWithoutArgs(
214 this, &DecryptingAudioDecoderTest::AbortPendingAudioDecodeCB));
216 decoder_->Reset(NewExpectedClosure());
217 message_loop_.RunUntilIdle();
220 MOCK_METHOD1(RequestDecryptorNotification, void(const DecryptorReadyCB&));
222 MOCK_METHOD2(FrameReady,
223 void(AudioDecoder::Status, const scoped_refptr<AudioBuffer>&));
225 base::MessageLoop message_loop_;
226 scoped_ptr<DecryptingAudioDecoder> decoder_;
227 scoped_ptr<StrictMock<MockDecryptor> > decryptor_;
228 scoped_ptr<StrictMock<MockDemuxerStream> > demuxer_;
229 MockStatisticsCB statistics_cb_;
230 AudioDecoderConfig config_;
232 DemuxerStream::ReadCB pending_demuxer_read_cb_;
233 Decryptor::DecoderInitCB pending_init_cb_;
234 Decryptor::NewKeyCB key_added_cb_;
235 Decryptor::AudioDecodeCB pending_audio_decode_cb_;
237 // Constant buffer/frames to be returned by the |demuxer_| and |decryptor_|.
238 scoped_refptr<DecoderBuffer> encrypted_buffer_;
239 scoped_refptr<AudioBuffer> decoded_frame_;
240 scoped_refptr<AudioBuffer> end_of_stream_frame_;
241 Decryptor::AudioBuffers decoded_frame_list_;
244 DISALLOW_COPY_AND_ASSIGN(DecryptingAudioDecoderTest);
247 TEST_F(DecryptingAudioDecoderTest, Initialize_Normal) {
251 // Ensure that DecryptingAudioDecoder only accepts encrypted audio.
252 TEST_F(DecryptingAudioDecoderTest, Initialize_UnencryptedAudioConfig) {
253 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32,
254 CHANNEL_LAYOUT_STEREO, 44100, NULL, 0, false);
256 InitializeAndExpectStatus(config, DECODER_ERROR_NOT_SUPPORTED);
259 // Ensure decoder handles invalid audio configs without crashing.
260 TEST_F(DecryptingAudioDecoderTest, Initialize_InvalidAudioConfig) {
261 AudioDecoderConfig config(kUnknownAudioCodec, kUnknownSampleFormat,
262 CHANNEL_LAYOUT_STEREO, 0, NULL, 0, true);
264 InitializeAndExpectStatus(config, PIPELINE_ERROR_DECODE);
267 // Ensure decoder handles unsupported audio configs without crashing.
268 TEST_F(DecryptingAudioDecoderTest, Initialize_UnsupportedAudioConfig) {
269 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _))
270 .WillOnce(RunCallback<1>(false));
271 EXPECT_CALL(*this, RequestDecryptorNotification(_))
272 .WillOnce(RunCallbackIfNotNull(decryptor_.get()));
274 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32,
275 CHANNEL_LAYOUT_STEREO, 44100, NULL, 0, true);
276 InitializeAndExpectStatus(config, DECODER_ERROR_NOT_SUPPORTED);
279 TEST_F(DecryptingAudioDecoderTest, Initialize_NullDecryptor) {
280 EXPECT_CALL(*this, RequestDecryptorNotification(_))
281 .WillRepeatedly(RunCallbackIfNotNull(static_cast<Decryptor*>(NULL)));
283 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32,
284 CHANNEL_LAYOUT_STEREO, 44100, NULL, 0, true);
285 InitializeAndExpectStatus(config, DECODER_ERROR_NOT_SUPPORTED);
288 // Test normal decrypt and decode case.
289 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_Normal) {
291 EnterNormalDecodingState();
294 // Test the case where the decryptor returns error when doing decrypt and
296 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_DecodeError) {
299 EXPECT_CALL(*demuxer_, Read(_))
300 .WillRepeatedly(ReturnBuffer(encrypted_buffer_));
301 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _))
302 .WillRepeatedly(RunCallback<1>(Decryptor::kError,
303 Decryptor::AudioBuffers()));
305 ReadAndExpectFrameReadyWith(AudioDecoder::kDecodeError, NULL);
308 // Test the case where the decryptor returns kNeedMoreData to ask for more
309 // buffers before it can produce a frame.
310 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_NeedMoreData) {
313 EXPECT_CALL(*demuxer_, Read(_))
315 .WillRepeatedly(ReturnBuffer(encrypted_buffer_));
316 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _))
317 .WillOnce(RunCallback<1>(Decryptor::kNeedMoreData,
318 Decryptor::AudioBuffers()))
319 .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_));
320 EXPECT_CALL(statistics_cb_, OnStatistics(_))
323 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, decoded_frame_);
326 // Test the case where the decryptor returns multiple decoded frames.
327 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_MultipleFrames) {
330 scoped_refptr<AudioBuffer> frame_a = AudioBuffer::CreateEmptyBuffer(
331 ChannelLayoutToChannelCount(config_.channel_layout()),
335 scoped_refptr<AudioBuffer> frame_b = AudioBuffer::CreateEmptyBuffer(
336 ChannelLayoutToChannelCount(config_.channel_layout()),
340 decoded_frame_list_.push_back(frame_a);
341 decoded_frame_list_.push_back(frame_b);
343 EXPECT_CALL(*demuxer_, Read(_))
344 .WillOnce(ReturnBuffer(encrypted_buffer_));
345 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _))
346 .WillOnce(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_));
347 EXPECT_CALL(statistics_cb_, OnStatistics(_));
349 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, decoded_frame_);
350 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, frame_a);
351 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, frame_b);
354 // Test the case where the decryptor receives end-of-stream buffer.
355 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_EndOfStream) {
357 EnterNormalDecodingState();
358 EnterEndOfStreamState();
361 // Test aborted read on the demuxer stream.
362 TEST_F(DecryptingAudioDecoderTest, DemuxerRead_Aborted) {
365 // ReturnBuffer() with NULL triggers aborted demuxer read.
366 EXPECT_CALL(*demuxer_, Read(_))
367 .WillOnce(ReturnBuffer(scoped_refptr<DecoderBuffer>()));
369 ReadAndExpectFrameReadyWith(AudioDecoder::kAborted, NULL);
372 // Test config change on the demuxer stream.
373 TEST_F(DecryptingAudioDecoderTest, DemuxerRead_ConfigChange) {
376 // The new config is different from the initial config in bits-per-channel,
377 // channel layout and samples_per_second.
378 AudioDecoderConfig new_config(kCodecVorbis, kSampleFormatPlanarS16,
379 CHANNEL_LAYOUT_5_1, 88200, NULL, 0, false);
380 EXPECT_NE(new_config.bits_per_channel(), config_.bits_per_channel());
381 EXPECT_NE(new_config.channel_layout(), config_.channel_layout());
382 EXPECT_NE(new_config.samples_per_second(), config_.samples_per_second());
384 demuxer_->set_audio_decoder_config(new_config);
385 EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio));
386 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _))
387 .WillOnce(RunCallback<1>(true));
388 EXPECT_CALL(*demuxer_, Read(_))
389 .WillOnce(RunCallback<0>(DemuxerStream::kConfigChanged,
390 scoped_refptr<DecoderBuffer>()))
391 .WillRepeatedly(ReturnBuffer(encrypted_buffer_));
392 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _))
393 .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_));
394 EXPECT_CALL(statistics_cb_, OnStatistics(_));
396 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, decoded_frame_);
398 EXPECT_EQ(new_config.bits_per_channel(), decoder_->bits_per_channel());
399 EXPECT_EQ(new_config.channel_layout(), decoder_->channel_layout());
400 EXPECT_EQ(new_config.samples_per_second(), decoder_->samples_per_second());
403 // Test config change failure.
404 TEST_F(DecryptingAudioDecoderTest, DemuxerRead_ConfigChangeFailed) {
407 EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio));
408 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _))
409 .WillOnce(RunCallback<1>(false));
410 EXPECT_CALL(*demuxer_, Read(_))
411 .WillOnce(RunCallback<0>(DemuxerStream::kConfigChanged,
412 scoped_refptr<DecoderBuffer>()))
413 .WillRepeatedly(ReturnBuffer(encrypted_buffer_));
415 ReadAndExpectFrameReadyWith(AudioDecoder::kDecodeError, NULL);
418 // Test the case where the a key is added when the decryptor is in
419 // kWaitingForKey state.
420 TEST_F(DecryptingAudioDecoderTest, KeyAdded_DuringWaitingForKey) {
422 EnterWaitingForKeyState();
424 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _))
425 .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_));
426 EXPECT_CALL(statistics_cb_, OnStatistics(_));
427 EXPECT_CALL(*this, FrameReady(AudioDecoder::kOk, decoded_frame_));
429 message_loop_.RunUntilIdle();
432 // Test the case where the a key is added when the decryptor is in
433 // kPendingDecode state.
434 TEST_F(DecryptingAudioDecoderTest, KeyAdded_DruingPendingDecode) {
436 EnterPendingDecodeState();
438 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _))
439 .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_));
440 EXPECT_CALL(statistics_cb_, OnStatistics(_));
441 EXPECT_CALL(*this, FrameReady(AudioDecoder::kOk, decoded_frame_));
442 // The audio decode callback is returned after the correct decryption key is
445 base::ResetAndReturn(&pending_audio_decode_cb_).Run(
446 Decryptor::kNoKey, Decryptor::AudioBuffers());
447 message_loop_.RunUntilIdle();
450 // Test resetting when the decoder is in kIdle state but has not decoded any
452 TEST_F(DecryptingAudioDecoderTest, Reset_DuringIdleAfterInitialization) {
457 // Test resetting when the decoder is in kIdle state after it has decoded one
459 TEST_F(DecryptingAudioDecoderTest, Reset_DuringIdleAfterDecodedOneFrame) {
461 EnterNormalDecodingState();
465 // Test resetting when the decoder is in kPendingDemuxerRead state and the read
466 // callback is returned with kOk.
467 TEST_F(DecryptingAudioDecoderTest, Reset_DuringDemuxerRead_Ok) {
469 EnterPendingReadState();
471 EXPECT_CALL(*this, FrameReady(AudioDecoder::kAborted, IsNull()));
474 base::ResetAndReturn(&pending_demuxer_read_cb_).Run(DemuxerStream::kOk,
476 message_loop_.RunUntilIdle();
479 // Test resetting when the decoder is in kPendingDemuxerRead state and the read
480 // callback is returned with kAborted.
481 TEST_F(DecryptingAudioDecoderTest, Reset_DuringDemuxerRead_Aborted) {
483 EnterPendingReadState();
485 // Make sure we get a NULL audio frame returned.
486 EXPECT_CALL(*this, FrameReady(AudioDecoder::kAborted, IsNull()));
489 base::ResetAndReturn(&pending_demuxer_read_cb_).Run(DemuxerStream::kAborted,
491 message_loop_.RunUntilIdle();
494 // Test resetting when the decoder is in kPendingDemuxerRead state and the read
495 // callback is returned with kConfigChanged.
496 TEST_F(DecryptingAudioDecoderTest, Reset_DuringDemuxerRead_ConfigChange) {
498 EnterPendingReadState();
502 // The new config is different from the initial config in bits-per-channel,
503 // channel layout and samples_per_second.
504 AudioDecoderConfig new_config(kCodecVorbis, kSampleFormatPlanarS16,
505 CHANNEL_LAYOUT_5_1, 88200, NULL, 0, false);
506 EXPECT_NE(new_config.bits_per_channel(), config_.bits_per_channel());
507 EXPECT_NE(new_config.channel_layout(), config_.channel_layout());
508 EXPECT_NE(new_config.samples_per_second(), config_.samples_per_second());
510 // Even during pending reset, the decoder still needs to be initialized with
512 demuxer_->set_audio_decoder_config(new_config);
513 EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio));
514 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _))
515 .WillOnce(RunCallback<1>(true));
516 EXPECT_CALL(*this, FrameReady(AudioDecoder::kAborted, IsNull()));
518 base::ResetAndReturn(&pending_demuxer_read_cb_)
519 .Run(DemuxerStream::kConfigChanged, NULL);
520 message_loop_.RunUntilIdle();
522 EXPECT_EQ(new_config.bits_per_channel(), decoder_->bits_per_channel());
523 EXPECT_EQ(new_config.channel_layout(), decoder_->channel_layout());
524 EXPECT_EQ(new_config.samples_per_second(), decoder_->samples_per_second());
527 // Test resetting when the decoder is in kPendingDemuxerRead state, the read
528 // callback is returned with kConfigChanged and the config change fails.
529 TEST_F(DecryptingAudioDecoderTest, Reset_DuringDemuxerRead_ConfigChangeFailed) {
531 EnterPendingReadState();
535 // Even during pending reset, the decoder still needs to be initialized with
537 EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio));
538 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _))
539 .WillOnce(RunCallback<1>(false));
540 EXPECT_CALL(*this, FrameReady(AudioDecoder::kDecodeError, IsNull()));
542 base::ResetAndReturn(&pending_demuxer_read_cb_)
543 .Run(DemuxerStream::kConfigChanged, NULL);
544 message_loop_.RunUntilIdle();
547 // Test resetting when the decoder is in kPendingConfigChange state.
548 TEST_F(DecryptingAudioDecoderTest, Reset_DuringPendingConfigChange) {
550 EnterNormalDecodingState();
552 EXPECT_CALL(*demuxer_, Read(_))
553 .WillOnce(RunCallback<0>(DemuxerStream::kConfigChanged,
554 scoped_refptr<DecoderBuffer>()));
555 EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio));
556 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _))
557 .WillOnce(SaveArg<1>(&pending_init_cb_));
559 decoder_->Read(base::Bind(&DecryptingAudioDecoderTest::FrameReady,
560 base::Unretained(this)));
561 message_loop_.RunUntilIdle();
562 EXPECT_FALSE(pending_init_cb_.is_null());
564 EXPECT_CALL(*this, FrameReady(AudioDecoder::kAborted, IsNull()));
567 base::ResetAndReturn(&pending_init_cb_).Run(true);
568 message_loop_.RunUntilIdle();
571 // Test resetting when the decoder is in kPendingDecode state.
572 TEST_F(DecryptingAudioDecoderTest, Reset_DuringPendingDecode) {
574 EnterPendingDecodeState();
576 EXPECT_CALL(*this, FrameReady(AudioDecoder::kAborted, IsNull()));
581 // Test resetting when the decoder is in kWaitingForKey state.
582 TEST_F(DecryptingAudioDecoderTest, Reset_DuringWaitingForKey) {
584 EnterWaitingForKeyState();
586 EXPECT_CALL(*this, FrameReady(AudioDecoder::kAborted, IsNull()));
591 // Test resetting when the decoder has hit end of stream and is in
592 // kDecodeFinished state.
593 TEST_F(DecryptingAudioDecoderTest, Reset_AfterDecodeFinished) {
595 EnterNormalDecodingState();
596 EnterEndOfStreamState();
600 // Test resetting after the decoder has been reset.
601 TEST_F(DecryptingAudioDecoderTest, Reset_AfterReset) {
603 EnterNormalDecodingState();