Chromium Code Reviews| Index: media/filters/decrypting_video_decoder_unittest.cc |
| diff --git a/media/filters/decrypting_video_decoder_unittest.cc b/media/filters/decrypting_video_decoder_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5365494c187f5c99f79b44bb199f2085185c3d30 |
| --- /dev/null |
| +++ b/media/filters/decrypting_video_decoder_unittest.cc |
| @@ -0,0 +1,543 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/bind.h" |
| +#include "base/callback_helpers.h" |
| +#include "base/message_loop.h" |
| +#include "media/base/decoder_buffer.h" |
| +#include "media/base/decrypt_config.h" |
| +#include "media/base/mock_callback.h" |
| +#include "media/base/mock_filters.h" |
| +#include "media/base/video_frame.h" |
| +#include "media/filters/ffmpeg_decoder_unittest.h" |
| +#include "media/filters/decrypting_video_decoder.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| + |
| +using ::testing::_; |
| +using ::testing::Invoke; |
| +using ::testing::IsNull; |
| +using ::testing::ReturnRef; |
| +using ::testing::SaveArg; |
| +using ::testing::StrictMock; |
| + |
| +namespace media { |
| + |
| +static const VideoFrame::Format kVideoFormat = VideoFrame::YV12; |
| +static const gfx::Size kCodedSize(320, 240); |
| +static const gfx::Rect kVisibleRect(320, 240); |
| +static const gfx::Size kNaturalSize(320, 240); |
| +static const uint8 kFakeKeyId[] = { 0x4b, 0x65, 0x79, 0x20, 0x49, 0x44 }; |
| +static const uint8 kFakeIv[DecryptConfig::kDecryptionKeySize] = { 0 }; |
| + |
| +// Create a fake non-empty encrypted buffer. |
| +static scoped_refptr<DecoderBuffer> CreateFakeEncryptedBuffer() { |
| + const int buffer_size = 16; // Need a non-empty buffer; |
| + const int encrypted_frame_offset = 1; // This should be non-zero. |
|
ddorwin
2012/10/01 18:43:20
Why should this be non-zero?
(That was my original
xhwang
2012/10/01 20:09:26
I think this was required before but it seems not
|
| + scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(buffer_size)); |
| + buffer->SetDecryptConfig(scoped_ptr<DecryptConfig>(new DecryptConfig( |
| + std::string(reinterpret_cast<const char*>(kFakeKeyId), |
| + arraysize(kFakeKeyId)), |
| + std::string(reinterpret_cast<const char*>(kFakeIv), arraysize(kFakeIv)), |
| + encrypted_frame_offset, |
| + std::vector<SubsampleEntry>()))); |
| + return buffer; |
| +} |
| + |
| +ACTION_P(ReturnBuffer, buffer) { |
| + arg0.Run(buffer ? DemuxerStream::kOk : DemuxerStream::kAborted, buffer); |
| +} |
| + |
| +ACTION(ReturnConfigChanged) { |
| + arg0.Run(DemuxerStream::kConfigChanged, scoped_refptr<DecoderBuffer>(NULL)); |
| +} |
| + |
| +ACTION_P(RunCallback1, param) { |
| + arg1.Run(param); |
| +} |
| + |
| +ACTION_P2(RunCallback2, param1, param2) { |
| + arg1.Run(param1, param2); |
| +} |
| + |
| +class DecryptingVideoDecoderTest : public testing::Test { |
| + public: |
| + DecryptingVideoDecoderTest() |
| + : decryptor_(new StrictMock<MockDecryptor>()), |
| + decoder_(new StrictMock<DecryptingVideoDecoder>( |
| + base::Bind(&Identity<scoped_refptr<base::MessageLoopProxy> >, |
| + message_loop_.message_loop_proxy()), |
| + decryptor_.get())), |
| + demuxer_(new StrictMock<MockDemuxerStream>()), |
| + encrypted_buffer_(CreateFakeEncryptedBuffer()), |
| + decoded_video_frame_(VideoFrame::CreateBlackFrame(kCodedSize)) { |
| + } |
| + |
| + virtual ~DecryptingVideoDecoderTest() { |
| + Stop(); |
| + } |
| + |
|
xhwang
2012/09/30 19:58:51
Will reorder these functions, but in a later patch
ddorwin
2012/10/01 18:43:20
Thank you!
xhwang
2012/10/04 16:38:33
Done.
|
| + void Initialize() { |
| + EXPECT_CALL(*decryptor_, InitializeVideoDecoder(_, _)) |
| + .WillOnce(RunCallback1(true)); |
| + |
| + config_.Initialize(kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, kVideoFormat, |
| + kCodedSize, kVisibleRect, kNaturalSize, |
| + NULL, 0, true, true); |
| + |
| + InitializeAndExpectStatus(config_, PIPELINE_OK); |
| + } |
| + |
| + void InitializeAndExpectStatus(const VideoDecoderConfig& config, |
| + PipelineStatus status) { |
| + EXPECT_CALL(*demuxer_, video_decoder_config()) |
| + .WillRepeatedly(ReturnRef(config)); |
| + |
| + decoder_->Initialize(demuxer_, NewExpectedStatusCB(status), |
| + base::Bind(&MockStatisticsCB::OnStatistics, |
| + base::Unretained(&statistics_cb_))); |
| + message_loop_.RunAllPending(); |
| + } |
| + |
| + void AbortPendingVideoDecodeCB() { |
| + if (!pending_video_decode_cb_.is_null()) { |
| + base::ResetAndReturn(&pending_video_decode_cb_).Run( |
| + Decryptor::kSuccess, scoped_refptr<VideoFrame>(NULL)); |
| + } |
| + } |
| + |
| + void AbortAllPendingCBs() { |
| + if (!pending_init_cb_.is_null()) { |
| + ASSERT_TRUE(pending_video_decode_cb_.is_null()); |
| + base::ResetAndReturn(&pending_init_cb_).Run(false); |
| + return; |
| + } |
| + |
| + AbortPendingVideoDecodeCB(); |
| + } |
| + |
| + void Reset() { |
| + EXPECT_CALL(*decryptor_, CancelDecryptAndDecodeVideo()) |
| + .WillOnce(Invoke( |
| + this, &DecryptingVideoDecoderTest::AbortPendingVideoDecodeCB)); |
| + |
| + decoder_->Reset(NewExpectedClosure()); |
| + message_loop_.RunAllPending(); |
| + } |
| + |
| + void Stop() { |
| + EXPECT_CALL(*decryptor_, StopVideoDecoder()) |
| + .WillOnce(Invoke( |
| + this, &DecryptingVideoDecoderTest::AbortAllPendingCBs)); |
| + |
| + decoder_->Stop(NewExpectedClosure()); |
| + message_loop_.RunAllPending(); |
| + } |
| + |
| + // Sets up expectations and actions to put DecryptingVideoDecoder in an |
| + // active normal decoding state. |
| + void EnterNormalDecodingState() { |
| + VideoDecoder::Status status = VideoDecoder::kDecodeError; |
| + scoped_refptr<VideoFrame> video_frame; |
| + DecryptAndDecodeSingleFrame(encrypted_buffer_, &status, &video_frame); |
| + |
| + EXPECT_EQ(VideoDecoder::kOk, status); |
| + ASSERT_TRUE(video_frame); |
| + EXPECT_FALSE(video_frame->IsEndOfStream()); |
| + } |
| + |
| + // Sets up expectations and actions to put DecryptingVideoDecoder in an end |
| + // of stream state. |
| + void EnterEndOfStreamState() { |
| + scoped_refptr<VideoFrame> video_frame; |
| + VideoDecoder::Status status = VideoDecoder::kDecodeError; |
| + ReadAndExpectToCompleteWith(&status, &video_frame); |
| + |
| + EXPECT_EQ(VideoDecoder::kOk, status); |
| + ASSERT_TRUE(video_frame); |
| + EXPECT_TRUE(video_frame->IsEndOfStream()); |
| + } |
| + |
| + // Decodes the single compressed frame in |buffer| and writes the |
| + // uncompressed output to |video_frame|. This method works with single |
| + // and multithreaded decoders. End of stream buffers are used to trigger |
| + // the frame to be returned in the multithreaded decoder case. |
| + void DecryptAndDecodeSingleFrame(const scoped_refptr<DecoderBuffer>& buffer, |
| + VideoDecoder::Status* status, |
| + scoped_refptr<VideoFrame>* video_frame) { |
| + EXPECT_CALL(*demuxer_, Read(_)) |
| + .WillOnce(ReturnBuffer(buffer)) |
| + .WillRepeatedly(ReturnBuffer(DecoderBuffer::CreateEOSBuffer())); |
| + EXPECT_CALL(*decryptor_, DecryptAndDecodeVideo(_, _)) |
| + .WillOnce(RunCallback2(Decryptor::kSuccess, decoded_video_frame_)) |
| + .WillRepeatedly(RunCallback2(Decryptor::kSuccess, |
| + VideoFrame::CreateEmptyFrame())); |
| + EXPECT_CALL(statistics_cb_, OnStatistics(_)); |
| + |
| + ReadAndExpectToCompleteWith(status, video_frame); |
| + } |
| + |
| + void ReadAndExpectToCompleteWith(VideoDecoder::Status* status, |
|
ddorwin
2012/10/01 18:43:20
ReadAndExpectToCompleteWithStatus
xhwang
2012/10/01 20:09:26
Changed to ReadAndExpectFrameReadyWithStatusAndFra
|
| + scoped_refptr<VideoFrame>* video_frame) { |
| + EXPECT_CALL(*this, FrameReady(_, _)) |
| + .WillOnce(DoAll(SaveArg<0>(status), SaveArg<1>(video_frame))); |
| + |
| + decoder_->Read(base::Bind(&DecryptingVideoDecoderTest::FrameReady, |
| + base::Unretained(this))); |
| + message_loop_.RunAllPending(); |
| + } |
| + |
| + // Make the read callback pending by saving and not firing it. |
| + void EnterPendingReadState() { |
| + EXPECT_TRUE(pending_demuxer_read_cb_.is_null()); |
| + EXPECT_CALL(*demuxer_, Read(_)) |
| + .WillOnce(SaveArg<0>(&pending_demuxer_read_cb_)); |
| + decoder_->Read(base::Bind(&DecryptingVideoDecoderTest::FrameReady, |
| + base::Unretained(this))); |
| + message_loop_.RunAllPending(); |
| + // Make sure the Read() on the decoder triggers a Read() on the demuxer. |
| + EXPECT_FALSE(pending_demuxer_read_cb_.is_null()); |
| + } |
| + |
| + // Make the video decode callback pending by saving and not firing it. |
| + void EnterPendingDecryptAndDecodeState() { |
| + EXPECT_TRUE(pending_video_decode_cb_.is_null()); |
| + EXPECT_CALL(*demuxer_, Read(_)) |
| + .WillRepeatedly(ReturnBuffer(encrypted_buffer_)); |
| + EXPECT_CALL(*decryptor_, DecryptAndDecodeVideo(encrypted_buffer_, _)) |
| + .WillOnce(SaveArg<1>(&pending_video_decode_cb_)); |
| + |
| + decoder_->Read(base::Bind(&DecryptingVideoDecoderTest::FrameReady, |
| + base::Unretained(this))); |
| + message_loop_.RunAllPending(); |
| + // Make sure the Read() on the decoder triggers a DecryptAndDecode() on the |
| + // decryptor. |
| + EXPECT_FALSE(pending_video_decode_cb_.is_null()); |
| + } |
| + |
| + MOCK_METHOD2(FrameReady, void(VideoDecoder::Status, |
| + const scoped_refptr<VideoFrame>&)); |
| + |
| + MessageLoop message_loop_; |
| + scoped_ptr<StrictMock<MockDecryptor> > decryptor_; |
| + scoped_refptr<StrictMock<DecryptingVideoDecoder> > decoder_; |
| + scoped_refptr<StrictMock<MockDemuxerStream> > demuxer_; |
| + MockStatisticsCB statistics_cb_; |
| + VideoDecoderConfig config_; |
| + |
| + DemuxerStream::ReadCB pending_demuxer_read_cb_; |
| + Decryptor::DecoderInitCB pending_init_cb_; |
| + Decryptor::VideoDecodeCB pending_video_decode_cb_; |
| + |
| + scoped_refptr<DecoderBuffer> encrypted_buffer_; |
| + scoped_refptr<VideoFrame> decoded_video_frame_; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(DecryptingVideoDecoderTest); |
| +}; |
| + |
| +TEST_F(DecryptingVideoDecoderTest, Initialize_Normal) { |
| + Initialize(); |
| +} |
| + |
| +// Ensure that DecryptingVideoDecoder only accepts encrypted video. |
| +TEST_F(DecryptingVideoDecoderTest, Initialize_UnencryptedVideoConfig) { |
| + VideoDecoderConfig config(kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, |
| + kVideoFormat, |
| + kCodedSize, kVisibleRect, kNaturalSize, |
| + NULL, 0, false); |
| + |
| + InitializeAndExpectStatus(config, DECODER_ERROR_NOT_SUPPORTED); |
| +} |
| + |
| +// Ensure decoder handles invalid video configs without crashing. |
| +TEST_F(DecryptingVideoDecoderTest, Initialize_InvalidVideoConfig) { |
| + VideoDecoderConfig config(kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, |
| + VideoFrame::INVALID, |
| + kCodedSize, kVisibleRect, kNaturalSize, |
| + NULL, 0, true); |
| + |
| + InitializeAndExpectStatus(config, PIPELINE_ERROR_DECODE); |
| +} |
| + |
| +// Ensure decoder handles unsupported video configs without crashing. |
| +TEST_F(DecryptingVideoDecoderTest, Initialize_UnsupportedVideoConfig) { |
| + EXPECT_CALL(*decryptor_, InitializeVideoDecoder(_, _)) |
| + .WillOnce(RunCallback1(false)); |
| + |
| + VideoDecoderConfig config(kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, |
| + kVideoFormat, |
| + kCodedSize, kVisibleRect, kNaturalSize, |
| + NULL, 0, true); |
| + |
| + InitializeAndExpectStatus(config, DECODER_ERROR_NOT_SUPPORTED); |
| +} |
| + |
| +// Test normal decrypt and decode case. |
| +TEST_F(DecryptingVideoDecoderTest, DecryptAndDecode_Normal) { |
| + Initialize(); |
| + EnterNormalDecodingState(); |
| +} |
| + |
| +// Test the case where the decryptor returns error when doing decrypt and |
| +// decode. |
| +TEST_F(DecryptingVideoDecoderTest, DecryptAndDecode_DecodeError) { |
| + Initialize(); |
| + |
| + EXPECT_CALL(*demuxer_, Read(_)) |
| + .WillRepeatedly(ReturnBuffer(encrypted_buffer_)); |
| + EXPECT_CALL(*decryptor_, DecryptAndDecodeVideo(_, _)) |
| + .WillRepeatedly(RunCallback2(Decryptor::kError, |
| + scoped_refptr<VideoFrame>(NULL))); |
| + |
| + VideoDecoder::Status status = VideoDecoder::kDecryptError; |
|
ddorwin
2012/10/01 18:43:20
kSuccess would be fine in this case. Then you don'
xhwang
2012/10/01 20:09:26
Done.
|
| + scoped_refptr<VideoFrame> video_frame; |
| + ReadAndExpectToCompleteWith(&status, &video_frame); |
| + |
| + EXPECT_EQ(VideoDecoder::kDecodeError, status); |
| + EXPECT_FALSE(video_frame); |
| +} |
| + |
| +// Test the case where the decryptor does not have the decryption key to do |
| +// decrypt and decode. |
| +TEST_F(DecryptingVideoDecoderTest, DecryptAndDecode_NoKey) { |
| + Initialize(); |
| + |
| + EXPECT_CALL(*demuxer_, Read(_)) |
| + .WillRepeatedly(ReturnBuffer(encrypted_buffer_)); |
| + EXPECT_CALL(*decryptor_, DecryptAndDecodeVideo(_, _)) |
| + .WillRepeatedly(RunCallback2(Decryptor::kNoKey, |
| + scoped_refptr<VideoFrame>(NULL))); |
| + |
| + VideoDecoder::Status status = VideoDecoder::kDecryptError; |
| + scoped_refptr<VideoFrame> video_frame; |
| + ReadAndExpectToCompleteWith(&status, &video_frame); |
| + |
| + EXPECT_EQ(VideoDecoder::kDecodeError, status); |
| + EXPECT_FALSE(video_frame); |
| +} |
| + |
| +// Test the case where the decryptor returns kNeedMoreData to ask for more |
| +// buffers before it can produce a frame. |
| +TEST_F(DecryptingVideoDecoderTest, DecryptAndDecode_NeedMoreData) { |
| + Initialize(); |
| + |
| + EXPECT_CALL(*demuxer_, Read(_)) |
| + .Times(2) |
| + .WillRepeatedly(ReturnBuffer(encrypted_buffer_)); |
| + EXPECT_CALL(*decryptor_, DecryptAndDecodeVideo(_, _)) |
| + .WillOnce(RunCallback2(Decryptor::kNeedMoreData, |
| + scoped_refptr<VideoFrame>(NULL))) |
| + .WillRepeatedly(RunCallback2(Decryptor::kSuccess, decoded_video_frame_)); |
| + EXPECT_CALL(statistics_cb_, OnStatistics(_)) |
| + .Times(2); |
| + |
| + VideoDecoder::Status status = VideoDecoder::kDecodeError; |
| + scoped_refptr<VideoFrame> video_frame; |
| + ReadAndExpectToCompleteWith(&status, &video_frame); |
| + |
| + EXPECT_EQ(VideoDecoder::kOk, status); |
| + EXPECT_EQ(decoded_video_frame_, video_frame); |
| +} |
| + |
| +// Test the case where the decryptor receives end-of-stream buffer. |
| +TEST_F(DecryptingVideoDecoderTest, DecryptAndDecode_EndOfStream) { |
| + Initialize(); |
| + EnterNormalDecodingState(); |
| + EnterEndOfStreamState(); |
| +} |
| + |
| +// Test resetting when decoder has initialized but has not decoded any frame. |
| +TEST_F(DecryptingVideoDecoderTest, Reset_Initialized) { |
| + Initialize(); |
| + Reset(); |
| +} |
| + |
| +// Test resetting when decoder has decoded single frame. |
| +TEST_F(DecryptingVideoDecoderTest, Reset_Decoding) { |
| + Initialize(); |
| + EnterNormalDecodingState(); |
| + Reset(); |
| +} |
| + |
| +// Test resetting when decoder has hit end of stream. |
| +TEST_F(DecryptingVideoDecoderTest, Reset_EndOfStream) { |
| + Initialize(); |
| + EnterNormalDecodingState(); |
| + EnterEndOfStreamState(); |
| + Reset(); |
| +} |
| + |
| +// Test resetting after the decoder has been reset. |
| +TEST_F(DecryptingVideoDecoderTest, Reset_AfterReset) { |
| + Initialize(); |
| + EnterNormalDecodingState(); |
| + Reset(); |
| + Reset(); |
| +} |
| + |
| +// Test resetting when there is a pending read on the demuxer. |
| +TEST_F(DecryptingVideoDecoderTest, Reset_DuringPendingDemuxerRead) { |
| + Initialize(); |
| + EnterPendingReadState(); |
| + |
| + EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, IsNull())); |
| + |
| + Reset(); |
| + base::ResetAndReturn(&pending_demuxer_read_cb_).Run(DemuxerStream::kOk, |
| + encrypted_buffer_); |
| + message_loop_.RunAllPending(); |
| +} |
| + |
| +// Test resetting when there is a pending video decode callback on the |
| +// decryptor. |
| +TEST_F(DecryptingVideoDecoderTest, Reset_DuringPendingDecryptAndDecode) { |
| + Initialize(); |
| + EnterPendingDecryptAndDecodeState(); |
| + |
| + EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, IsNull())); |
| + |
| + Reset(); |
| +} |
| + |
| +// Test stopping when decoder has initialized but has not decoded any frame. |
| +TEST_F(DecryptingVideoDecoderTest, Stop_Initialized) { |
| + Initialize(); |
| + Stop(); |
| +} |
| + |
| +// Test stopping when decoder has decoded single frame. |
| +TEST_F(DecryptingVideoDecoderTest, Stop_Decoding) { |
| + Initialize(); |
| + EnterNormalDecodingState(); |
| + Stop(); |
| +} |
| + |
| +// Test stopping when decoder has hit end of stream. |
| +TEST_F(DecryptingVideoDecoderTest, Stop_EndOfStream) { |
| + Initialize(); |
| + EnterNormalDecodingState(); |
| + EnterEndOfStreamState(); |
| + Stop(); |
| +} |
| + |
| +// Test stopping when there is a pending read on the demuxer. |
| +TEST_F(DecryptingVideoDecoderTest, Stop_DuringPendingInitialize) { |
| + EXPECT_CALL(*decryptor_, InitializeVideoDecoder(_, _)) |
| + .WillOnce(SaveArg<1>(&pending_init_cb_)); |
| + |
| + config_.Initialize(kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, kVideoFormat, |
| + kCodedSize, kVisibleRect, kNaturalSize, NULL, 0, true, |
| + true); |
| + InitializeAndExpectStatus(config_, DECODER_ERROR_NOT_SUPPORTED); |
| + |
| + Stop(); |
| + message_loop_.RunAllPending(); |
| +} |
| + |
| +// Test stopping when there is a pending read on the demuxer. |
| +TEST_F(DecryptingVideoDecoderTest, Stop_DuringPendingDemuxerRead) { |
| + Initialize(); |
| + EnterPendingReadState(); |
| + |
| + EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, IsNull())); |
| + |
| + Stop(); |
| + base::ResetAndReturn(&pending_demuxer_read_cb_).Run(DemuxerStream::kOk, |
| + encrypted_buffer_); |
| + message_loop_.RunAllPending(); |
| +} |
| + |
| +// Test stopping when there is a pending video decode callback on the |
| +// decryptor. |
| +TEST_F(DecryptingVideoDecoderTest, Stop_DuringPendingDecryptAndDecode) { |
| + Initialize(); |
| + EnterPendingDecryptAndDecodeState(); |
| + |
| + EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, IsNull())); |
| + |
| + Stop(); |
| +} |
| + |
| +// Test stopping when there is a pending reset on the decoder. |
| +// Reset is pending because it cannot complete when the video decode callback |
| +// is pending. |
| +TEST_F(DecryptingVideoDecoderTest, Stop_DuringPendingReset) { |
| + Initialize(); |
| + EnterPendingDecryptAndDecodeState(); |
| + |
| + EXPECT_CALL(*decryptor_, CancelDecryptAndDecodeVideo()); |
| + EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, IsNull())); |
| + |
| + decoder_->Reset(NewExpectedClosure()); |
| + Stop(); |
| +} |
| + |
| +// Test stopping after the decoder has been stopped. |
| +TEST_F(DecryptingVideoDecoderTest, Stop_AfterReset) { |
| + Initialize(); |
| + EnterNormalDecodingState(); |
| + Reset(); |
| + Stop(); |
| +} |
| + |
| +// Test stopping after the decoder has been stopped. |
| +TEST_F(DecryptingVideoDecoderTest, Stop_AfterStop) { |
| + Initialize(); |
| + EnterNormalDecodingState(); |
| + Stop(); |
| + Stop(); |
| +} |
| + |
| +// Test aborted read on the demuxer stream. |
| +TEST_F(DecryptingVideoDecoderTest, AbortPendingDemuxerRead) { |
| + Initialize(); |
| + |
| + // ReturnBuffer() with NULL triggers aborted demuxer read. |
| + EXPECT_CALL(*demuxer_, Read(_)) |
| + .WillOnce(ReturnBuffer(scoped_refptr<DecoderBuffer>())); |
| + |
| + VideoDecoder::Status status = VideoDecoder::kDecodeError; |
| + scoped_refptr<VideoFrame> video_frame; |
| + ReadAndExpectToCompleteWith(&status, &video_frame); |
| + |
| + EXPECT_EQ(VideoDecoder::kOk, status); |
| + EXPECT_FALSE(video_frame); |
| +} |
| + |
| +// Test aborted read on the demuxer stream when the decoder is being reset. |
| +TEST_F(DecryptingVideoDecoderTest, AbortPendingDemuxerReadDuringReset) { |
| + Initialize(); |
| + EnterPendingReadState(); |
| + |
| + // Make sure we get a NULL video frame returned. |
| + EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, IsNull())); |
| + |
| + Reset(); |
| + base::ResetAndReturn(&pending_demuxer_read_cb_).Run(DemuxerStream::kAborted, |
| + NULL); |
| + message_loop_.RunAllPending(); |
| +} |
| + |
| +// Test config change on the demuxer stream. |
| +TEST_F(DecryptingVideoDecoderTest, ConfigChanged) { |
| + Initialize(); |
| + |
| + EXPECT_CALL(*demuxer_, Read(_)) |
| + .WillOnce(ReturnConfigChanged()); |
| + |
| + VideoDecoder::Status status = VideoDecoder::kDecryptError; |
| + scoped_refptr<VideoFrame> video_frame; |
| + |
| + ReadAndExpectToCompleteWith(&status, &video_frame); |
| + |
| + // TODO(xhwang): Update this test when kConfigChanged is supported in |
| + // DecryptingVideoDecoder. |
| + EXPECT_EQ(VideoDecoder::kDecodeError, status); |
| + EXPECT_FALSE(video_frame); |
| +} |
| + |
| +} // namespace media |