Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Unified Diff: media/filters/decrypting_audio_decoder_unittest.cc

Issue 331863004: Revert 276344 "Add callback in VideoDecoder and AudioDecoder to ..." (Closed) Base URL: svn://svn.chromium.org/chrome/branches/2049/src/
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/filters/decrypting_audio_decoder.cc ('k') | media/filters/decrypting_video_decoder.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/filters/decrypting_audio_decoder_unittest.cc
===================================================================
--- media/filters/decrypting_audio_decoder_unittest.cc (revision 277175)
+++ media/filters/decrypting_audio_decoder_unittest.cc (working copy)
@@ -19,7 +19,6 @@
#include "testing/gmock/include/gmock/gmock.h"
using ::testing::_;
-using ::testing::Assign;
using ::testing::AtMost;
using ::testing::IsNull;
using ::testing::SaveArg;
@@ -60,6 +59,13 @@
arg0.Run(param);
}
+// Mock action which we use to repeatedly call ReadAndExpectFrameReadyWith() if
+// we get kNotEnoughData from a Decode() call to |decoder_|.
+ACTION_P2(CallExpectFrameReadyMoreData, test, buffer) {
+ test->ReadAndExpectFrameReadyWith(
+ CreateFakeEncryptedBuffer(), AudioDecoder::kNotEnoughData, buffer);
+}
+
MATCHER(IsEndOfStream, "end of stream") {
return (arg->end_of_stream());
}
@@ -101,9 +107,7 @@
kNoTimestamp());
decoded_frame_list_.push_back(decoded_frame_);
- decoder_->Initialize(config, NewExpectedStatusCB(status),
- base::Bind(&DecryptingAudioDecoderTest::FrameReady,
- base::Unretained(this)));
+ decoder_->Initialize(config, NewExpectedStatusCB(status));
message_loop_.RunUntilIdle();
}
@@ -132,27 +136,35 @@
.WillOnce(RunCallback<1>(true));
EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _))
.WillOnce(SaveArg<1>(&key_added_cb_));
- decoder_->Initialize(new_config, NewExpectedStatusCB(PIPELINE_OK),
- base::Bind(&DecryptingAudioDecoderTest::FrameReady,
- base::Unretained(this)));
+ decoder_->Initialize(new_config, NewExpectedStatusCB(PIPELINE_OK));
}
- void DecodeAndExpectFrameReadyWith(
+ void ReadAndExpectFrameReadyWith(
scoped_refptr<DecoderBuffer> input,
AudioDecoder::Status status,
- const Decryptor::AudioBuffers& audio_frames) {
- for (Decryptor::AudioBuffers::const_iterator it = audio_frames.begin();
- it != audio_frames.end(); ++it) {
- if ((*it)->end_of_stream()) {
- EXPECT_CALL(*this, FrameReady(IsEndOfStream()));
- } else {
- EXPECT_CALL(*this, FrameReady(*it));
- }
+ const scoped_refptr<AudioBuffer>& audio_frame) {
+
+ const scoped_refptr<AudioBuffer>& buffer = decoder_->GetDecodeOutput();
+
+ if (buffer) {
+ EXPECT_EQ(audio_frame, buffer);
+ EXPECT_EQ(status, AudioDecoder::kOk);
+ return;
}
- EXPECT_CALL(*this, DecodeDone(status));
+ if (status == AudioDecoder::kNotEnoughData)
+ // Keep calling again to give it more data if we get kNotEnoughData.
+ EXPECT_CALL(*this, FrameReady(status, scoped_refptr<AudioBuffer>(NULL))).
+ WillRepeatedly(CallExpectFrameReadyMoreData(this, audio_frame));
+ else if (status != AudioDecoder::kOk)
+ EXPECT_CALL(*this, FrameReady(status, IsNull()));
+ else if (audio_frame->end_of_stream())
+ EXPECT_CALL(*this, FrameReady(status, IsEndOfStream()));
+ else
+ EXPECT_CALL(*this, FrameReady(status, audio_frame));
+
decoder_->Decode(input,
- base::Bind(&DecryptingAudioDecoderTest::DecodeDone,
+ base::Bind(&DecryptingAudioDecoderTest::FrameReady,
base::Unretained(this)));
message_loop_.RunUntilIdle();
}
@@ -167,17 +179,17 @@
.WillRepeatedly(RunCallback<1>(Decryptor::kNeedMoreData,
Decryptor::AudioBuffers()));
- DecodeAndExpectFrameReadyWith(encrypted_buffer_, AudioDecoder::kOk,
- Decryptor::AudioBuffers(1, decoded_frame_));
+ ReadAndExpectFrameReadyWith(
+ encrypted_buffer_, AudioDecoder::kOk, decoded_frame_);
}
// Sets up expectations and actions to put DecryptingAudioDecoder in an end
// of stream state. This function must be called after
// EnterNormalDecodingState() to work.
void EnterEndOfStreamState() {
- DecodeAndExpectFrameReadyWith(
- DecoderBuffer::CreateEOSBuffer(), AudioDecoder::kOk,
- Decryptor::AudioBuffers(1, end_of_stream_frame_));
+ ReadAndExpectFrameReadyWith(DecoderBuffer::CreateEOSBuffer(),
+ AudioDecoder::kOk,
+ end_of_stream_frame_);
}
// Make the audio decode callback pending by saving and not firing it.
@@ -187,7 +199,7 @@
.WillOnce(SaveArg<1>(&pending_audio_decode_cb_));
decoder_->Decode(encrypted_buffer_,
- base::Bind(&DecryptingAudioDecoderTest::DecodeDone,
+ base::Bind(&DecryptingAudioDecoderTest::FrameReady,
base::Unretained(this)));
message_loop_.RunUntilIdle();
// Make sure the Decode() on the decoder triggers a DecryptAndDecode() on
@@ -200,7 +212,7 @@
.WillRepeatedly(RunCallback<1>(Decryptor::kNoKey,
Decryptor::AudioBuffers()));
decoder_->Decode(encrypted_buffer_,
- base::Bind(&DecryptingAudioDecoderTest::DecodeDone,
+ base::Bind(&DecryptingAudioDecoderTest::FrameReady,
base::Unretained(this)));
message_loop_.RunUntilIdle();
}
@@ -242,8 +254,8 @@
MOCK_METHOD1(RequestDecryptorNotification, void(const DecryptorReadyCB&));
- MOCK_METHOD1(FrameReady, void(const scoped_refptr<AudioBuffer>&));
- MOCK_METHOD1(DecodeDone, void(AudioDecoder::Status));
+ MOCK_METHOD2(FrameReady,
+ void(AudioDecoder::Status, const scoped_refptr<AudioBuffer>&));
base::MessageLoop message_loop_;
scoped_ptr<DecryptingAudioDecoder> decoder_;
@@ -320,8 +332,8 @@
.WillRepeatedly(RunCallback<1>(Decryptor::kError,
Decryptor::AudioBuffers()));
- DecodeAndExpectFrameReadyWith(
- encrypted_buffer_, AudioDecoder::kDecodeError, Decryptor::AudioBuffers());
+ ReadAndExpectFrameReadyWith(
+ encrypted_buffer_, AudioDecoder::kDecodeError, NULL);
}
// Test the case where the decryptor returns kNeedMoreData to ask for more
@@ -336,14 +348,9 @@
// We expect it to eventually return kOk, with any number of returns of
// kNotEnoughData beforehand.
- bool frame_delivered = false;
- EXPECT_CALL(*this, FrameReady(decoded_frame_))
- .WillOnce(Assign(&frame_delivered, true));
-
- while (!frame_delivered) {
- ASSERT_NO_FATAL_FAILURE(DecodeAndExpectFrameReadyWith(
- encrypted_buffer_, AudioDecoder::kOk, Decryptor::AudioBuffers()));
- }
+ EXPECT_CALL(*this, FrameReady(AudioDecoder::kOk, decoded_frame_));
+ ReadAndExpectFrameReadyWith(
+ encrypted_buffer_, AudioDecoder::kNotEnoughData, decoded_frame_);
}
// Test the case where the decryptor returns multiple decoded frames.
@@ -368,11 +375,10 @@
EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _))
.WillOnce(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_));
- Decryptor::AudioBuffers buffers;
- buffers.push_back(decoded_frame_);
- buffers.push_back(frame_a);
- buffers.push_back(frame_b);
- DecodeAndExpectFrameReadyWith(encrypted_buffer_, AudioDecoder::kOk, buffers);
+ ReadAndExpectFrameReadyWith(
+ encrypted_buffer_, AudioDecoder::kOk, decoded_frame_);
+ ReadAndExpectFrameReadyWith(encrypted_buffer_, AudioDecoder::kOk, frame_a);
+ ReadAndExpectFrameReadyWith(encrypted_buffer_, AudioDecoder::kOk, frame_b);
}
// Test the case where the decryptor receives end-of-stream buffer.
@@ -410,8 +416,7 @@
EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _))
.WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_));
- EXPECT_CALL(*this, FrameReady(decoded_frame_));
- EXPECT_CALL(*this, DecodeDone(AudioDecoder::kOk));
+ EXPECT_CALL(*this, FrameReady(AudioDecoder::kOk, decoded_frame_));
key_added_cb_.Run();
message_loop_.RunUntilIdle();
}
@@ -424,8 +429,7 @@
EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _))
.WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_));
- EXPECT_CALL(*this, FrameReady(decoded_frame_));
- EXPECT_CALL(*this, DecodeDone(AudioDecoder::kOk));
+ EXPECT_CALL(*this, FrameReady(AudioDecoder::kOk, decoded_frame_));
// The audio decode callback is returned after the correct decryption key is
// added.
key_added_cb_.Run();
@@ -454,7 +458,7 @@
Initialize();
EnterPendingDecodeState();
- EXPECT_CALL(*this, DecodeDone(AudioDecoder::kAborted));
+ EXPECT_CALL(*this, FrameReady(AudioDecoder::kAborted, IsNull()));
Reset();
}
@@ -464,7 +468,7 @@
Initialize();
EnterWaitingForKeyState();
- EXPECT_CALL(*this, DecodeDone(AudioDecoder::kAborted));
+ EXPECT_CALL(*this, FrameReady(AudioDecoder::kAborted, IsNull()));
Reset();
}
« no previous file with comments | « media/filters/decrypting_audio_decoder.cc ('k') | media/filters/decrypting_video_decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698