Chromium Code Reviews| Index: media/filters/audio_decoder_selector_unittest.cc |
| diff --git a/media/filters/audio_decoder_selector_unittest.cc b/media/filters/audio_decoder_selector_unittest.cc |
| index eb0e8dbd3c4606db23ec86518f46613b41989eca..6725e2f1a9f5e86e8df51e50344da77886b403e3 100644 |
| --- a/media/filters/audio_decoder_selector_unittest.cc |
| +++ b/media/filters/audio_decoder_selector_unittest.cc |
| @@ -14,6 +14,8 @@ |
| #include "testing/gtest/include/gtest/gtest.h" |
| using ::testing::_; |
| +using ::testing::Eq; |
| +using ::testing::InvokeWithoutArgs; |
| using ::testing::IsNull; |
| using ::testing::NiceMock; |
| using ::testing::NotNull; |
| @@ -48,9 +50,30 @@ class AudioDecoderSelectorTest : public ::testing::Test { |
| message_loop_.RunUntilIdle(); |
| } |
| + // Used to verify that the number of calls to SetDecryptorReadyCallback() |
| + // match the number of calls to DecryptorSet() and that the calls happen in |
| + // pairs (e.g. DecryptorSet() called after every SetDecryptorReadyCallback() |
| + // call). There may be any number of pairs (including 0). |
| + class CallbackVerifier { |
| + public: |
| + CallbackVerifier() : ready_called_(0), set_called_(0) {} |
| + ~CallbackVerifier() { Verify(); } |
| + void SetDecryptorReadyCallbackCalled() { ++ready_called_; } |
|
ddorwin
2014/08/04 18:59:08
Is it okay/expected for the values to be >1 apart?
jrummell
2014/08/07 01:54:25
Done.
|
| + void DecryptorSetCalled() { |
| + ++set_called_; |
| + Verify(); |
| + } |
| + void Verify() { EXPECT_EQ(set_called_, ready_called_); } |
| + |
| + private: |
| + int ready_called_; |
| + int set_called_; |
| + }; |
| + |
| MOCK_METHOD1(SetDecryptorReadyCallback, void(const media::DecryptorReadyCB&)); |
| MOCK_METHOD2(OnDecoderSelected, |
| void(AudioDecoder*, DecryptingDemuxerStream*)); |
| + MOCK_METHOD1(DecryptorSet, void(bool)); |
| void MockOnDecoderSelected(scoped_ptr<AudioDecoder> decoder, |
| scoped_ptr<DecryptingDemuxerStream> stream) { |
| @@ -83,9 +106,14 @@ class AudioDecoderSelectorTest : public ::testing::Test { |
| if (decryptor_capability == kDecryptOnly || |
| decryptor_capability == kDecryptAndDecode) { |
| - |
| - EXPECT_CALL(*this, SetDecryptorReadyCallback(_)) |
| - .WillRepeatedly(RunCallback<0>(decryptor_.get())); |
| + EXPECT_CALL(*this, SetDecryptorReadyCallback(_)).WillRepeatedly(DoAll( |
|
ddorwin
2014/08/04 18:59:08
This looks odd. Do we need SetDecryptorReadyCallba
jrummell
2014/08/07 01:54:25
The problem is that SetDecryptorReadyCallback() is
|
| + InvokeWithoutArgs(&verifier_, |
| + &CallbackVerifier::SetDecryptorReadyCallbackCalled), |
| + RunCallback<0>(decryptor_.get(), |
| + base::Bind(&AudioDecoderSelectorTest::DecryptorSet, |
| + base::Unretained(this))))); |
| + EXPECT_CALL(*this, DecryptorSet(Eq(true))).WillRepeatedly( |
| + InvokeWithoutArgs(&verifier_, &CallbackVerifier::DecryptorSetCalled)); |
| if (decryptor_capability == kDecryptOnly) { |
| EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) |
| @@ -149,6 +177,8 @@ class AudioDecoderSelectorTest : public ::testing::Test { |
| base::MessageLoop message_loop_; |
| + CallbackVerifier verifier_; |
| + |
| private: |
| DISALLOW_COPY_AND_ASSIGN(AudioDecoderSelectorTest); |
| }; |