OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "media/base/audio_buffer.h" | 11 #include "media/base/audio_buffer.h" |
12 #include "media/base/buffers.h" | 12 #include "media/base/buffers.h" |
13 #include "media/base/decoder_buffer.h" | 13 #include "media/base/decoder_buffer.h" |
14 #include "media/base/decrypt_config.h" | 14 #include "media/base/decrypt_config.h" |
15 #include "media/base/gmock_callback_support.h" | 15 #include "media/base/gmock_callback_support.h" |
16 #include "media/base/mock_filters.h" | 16 #include "media/base/mock_filters.h" |
17 #include "media/base/test_helpers.h" | 17 #include "media/base/test_helpers.h" |
18 #include "media/filters/decrypting_audio_decoder.h" | 18 #include "media/filters/decrypting_audio_decoder.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
20 | 20 |
21 using ::testing::_; | 21 using ::testing::_; |
22 using ::testing::AtMost; | 22 using ::testing::AtMost; |
23 using ::testing::Eq; | |
23 using ::testing::SaveArg; | 24 using ::testing::SaveArg; |
24 using ::testing::StrictMock; | 25 using ::testing::StrictMock; |
25 | 26 |
26 namespace media { | 27 namespace media { |
27 | 28 |
28 const int kSampleRate = 44100; | 29 const int kSampleRate = 44100; |
29 | 30 |
30 // Make sure the kFakeAudioFrameSize is a valid frame size for all audio decoder | 31 // Make sure the kFakeAudioFrameSize is a valid frame size for all audio decoder |
31 // configs used in this test. | 32 // configs used in this test. |
32 const int kFakeAudioFrameSize = 48; | 33 const int kFakeAudioFrameSize = 48; |
(...skipping 14 matching lines...) Expand all Loading... | |
47 } | 48 } |
48 | 49 |
49 // Use anonymous namespace here to prevent the actions to be defined multiple | 50 // Use anonymous namespace here to prevent the actions to be defined multiple |
50 // times across multiple test files. Sadly we can't use static for them. | 51 // times across multiple test files. Sadly we can't use static for them. |
51 namespace { | 52 namespace { |
52 | 53 |
53 ACTION_P(ReturnBuffer, buffer) { | 54 ACTION_P(ReturnBuffer, buffer) { |
54 return buffer; | 55 return buffer; |
55 } | 56 } |
56 | 57 |
57 ACTION_P(RunCallbackIfNotNull, param) { | 58 ACTION_P2(RunCallbackIfNotNull, p1, p2) { |
58 if (!arg0.is_null()) | 59 if (!arg0.is_null()) |
59 arg0.Run(param); | 60 arg0.Run(p1, p2); |
60 } | 61 } |
61 | 62 |
62 } // namespace | 63 } // namespace |
63 | 64 |
64 class DecryptingAudioDecoderTest : public testing::Test { | 65 class DecryptingAudioDecoderTest : public testing::Test { |
65 public: | 66 public: |
66 DecryptingAudioDecoderTest() | 67 DecryptingAudioDecoderTest() |
67 : decoder_(new DecryptingAudioDecoder( | 68 : decoder_(new DecryptingAudioDecoder( |
68 message_loop_.message_loop_proxy(), | 69 message_loop_.message_loop_proxy(), |
69 base::Bind( | 70 base::Bind( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 base::Bind(&DecryptingAudioDecoderTest::FrameReady, | 102 base::Bind(&DecryptingAudioDecoderTest::FrameReady, |
102 base::Unretained(this))); | 103 base::Unretained(this))); |
103 message_loop_.RunUntilIdle(); | 104 message_loop_.RunUntilIdle(); |
104 } | 105 } |
105 | 106 |
106 void Initialize() { | 107 void Initialize() { |
107 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) | 108 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) |
108 .Times(AtMost(1)) | 109 .Times(AtMost(1)) |
109 .WillOnce(RunCallback<1>(true)); | 110 .WillOnce(RunCallback<1>(true)); |
110 EXPECT_CALL(*this, RequestDecryptorNotification(_)) | 111 EXPECT_CALL(*this, RequestDecryptorNotification(_)) |
111 .WillOnce(RunCallbackIfNotNull(decryptor_.get())); | 112 .WillOnce(RunCallbackIfNotNull( |
113 decryptor_.get(), | |
114 base::Bind(&DecryptingAudioDecoderTest::DecryptorSet, | |
115 base::Unretained(this)))); | |
116 EXPECT_CALL(*this, DecryptorSet(Eq(true))); | |
112 EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _)) | 117 EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _)) |
113 .WillOnce(SaveArg<1>(&key_added_cb_)); | 118 .WillOnce(SaveArg<1>(&key_added_cb_)); |
114 | 119 |
115 config_.Initialize(kCodecVorbis, kSampleFormatPlanarF32, | 120 config_.Initialize(kCodecVorbis, kSampleFormatPlanarF32, |
116 CHANNEL_LAYOUT_STEREO, kSampleRate, NULL, 0, true, true, | 121 CHANNEL_LAYOUT_STEREO, kSampleRate, NULL, 0, true, true, |
117 base::TimeDelta(), 0); | 122 base::TimeDelta(), 0); |
118 InitializeAndExpectStatus(config_, PIPELINE_OK); | 123 InitializeAndExpectStatus(config_, PIPELINE_OK); |
119 } | 124 } |
120 | 125 |
121 void Reinitialize() { | 126 void Reinitialize() { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 | 246 |
242 decoder_.reset(); | 247 decoder_.reset(); |
243 message_loop_.RunUntilIdle(); | 248 message_loop_.RunUntilIdle(); |
244 } | 249 } |
245 | 250 |
246 MOCK_METHOD1(RequestDecryptorNotification, void(const DecryptorReadyCB&)); | 251 MOCK_METHOD1(RequestDecryptorNotification, void(const DecryptorReadyCB&)); |
247 | 252 |
248 MOCK_METHOD1(FrameReady, void(const scoped_refptr<AudioBuffer>&)); | 253 MOCK_METHOD1(FrameReady, void(const scoped_refptr<AudioBuffer>&)); |
249 MOCK_METHOD1(DecodeDone, void(AudioDecoder::Status)); | 254 MOCK_METHOD1(DecodeDone, void(AudioDecoder::Status)); |
250 | 255 |
256 MOCK_METHOD1(DecryptorSet, void(bool)); | |
257 | |
251 base::MessageLoop message_loop_; | 258 base::MessageLoop message_loop_; |
252 scoped_ptr<DecryptingAudioDecoder> decoder_; | 259 scoped_ptr<DecryptingAudioDecoder> decoder_; |
253 scoped_ptr<StrictMock<MockDecryptor> > decryptor_; | 260 scoped_ptr<StrictMock<MockDecryptor> > decryptor_; |
254 AudioDecoderConfig config_; | 261 AudioDecoderConfig config_; |
255 | 262 |
256 // Variables to help the |decryptor_| to simulate decoding delay and flushing. | 263 // Variables to help the |decryptor_| to simulate decoding delay and flushing. |
257 int num_decrypt_and_decode_calls_; | 264 int num_decrypt_and_decode_calls_; |
258 int num_frames_in_decryptor_; | 265 int num_frames_in_decryptor_; |
259 | 266 |
260 Decryptor::DecoderInitCB pending_init_cb_; | 267 Decryptor::DecoderInitCB pending_init_cb_; |
(...skipping 26 matching lines...) Expand all Loading... | |
287 AudioDecoderConfig config(kUnknownAudioCodec, kUnknownSampleFormat, | 294 AudioDecoderConfig config(kUnknownAudioCodec, kUnknownSampleFormat, |
288 CHANNEL_LAYOUT_STEREO, 0, NULL, 0, true); | 295 CHANNEL_LAYOUT_STEREO, 0, NULL, 0, true); |
289 | 296 |
290 InitializeAndExpectStatus(config, PIPELINE_ERROR_DECODE); | 297 InitializeAndExpectStatus(config, PIPELINE_ERROR_DECODE); |
291 } | 298 } |
292 | 299 |
293 // Ensure decoder handles unsupported audio configs without crashing. | 300 // Ensure decoder handles unsupported audio configs without crashing. |
294 TEST_F(DecryptingAudioDecoderTest, Initialize_UnsupportedAudioConfig) { | 301 TEST_F(DecryptingAudioDecoderTest, Initialize_UnsupportedAudioConfig) { |
295 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) | 302 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) |
296 .WillOnce(RunCallback<1>(false)); | 303 .WillOnce(RunCallback<1>(false)); |
297 EXPECT_CALL(*this, RequestDecryptorNotification(_)) | 304 EXPECT_CALL(*this, RequestDecryptorNotification(_)).WillOnce( |
298 .WillOnce(RunCallbackIfNotNull(decryptor_.get())); | 305 RunCallbackIfNotNull(decryptor_.get(), |
306 base::Bind(&DecryptingAudioDecoderTest::DecryptorSet, | |
307 base::Unretained(this)))); | |
308 EXPECT_CALL(*this, DecryptorSet(Eq(true))); | |
ddorwin
2014/08/04 18:59:08
In the unsupported audio config case, do we actual
jrummell
2014/08/07 01:54:25
SetDecryptor() calls the cb with true as long as d
| |
299 | 309 |
300 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32, | 310 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32, |
301 CHANNEL_LAYOUT_STEREO, kSampleRate, NULL, 0, true); | 311 CHANNEL_LAYOUT_STEREO, kSampleRate, NULL, 0, true); |
302 InitializeAndExpectStatus(config, DECODER_ERROR_NOT_SUPPORTED); | 312 InitializeAndExpectStatus(config, DECODER_ERROR_NOT_SUPPORTED); |
303 } | 313 } |
304 | 314 |
305 TEST_F(DecryptingAudioDecoderTest, Initialize_NullDecryptor) { | 315 TEST_F(DecryptingAudioDecoderTest, Initialize_NullDecryptor) { |
306 EXPECT_CALL(*this, RequestDecryptorNotification(_)) | 316 EXPECT_CALL(*this, RequestDecryptorNotification(_)).WillRepeatedly( |
307 .WillRepeatedly(RunCallbackIfNotNull(static_cast<Decryptor*>(NULL))); | 317 RunCallbackIfNotNull(static_cast<Decryptor*>(NULL), |
318 base::Bind(&DecryptingAudioDecoderTest::DecryptorSet, | |
319 base::Unretained(this)))); | |
320 EXPECT_CALL(*this, DecryptorSet(Eq(false))); | |
308 | 321 |
309 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32, | 322 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32, |
310 CHANNEL_LAYOUT_STEREO, kSampleRate, NULL, 0, true); | 323 CHANNEL_LAYOUT_STEREO, kSampleRate, NULL, 0, true); |
311 InitializeAndExpectStatus(config, DECODER_ERROR_NOT_SUPPORTED); | 324 InitializeAndExpectStatus(config, DECODER_ERROR_NOT_SUPPORTED); |
312 } | 325 } |
313 | 326 |
314 // Test normal decrypt and decode case. | 327 // Test normal decrypt and decode case. |
315 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_Normal) { | 328 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_Normal) { |
316 Initialize(); | 329 Initialize(); |
317 EnterNormalDecodingState(); | 330 EnterNormalDecodingState(); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
462 | 475 |
463 // Test resetting after the decoder has been reset. | 476 // Test resetting after the decoder has been reset. |
464 TEST_F(DecryptingAudioDecoderTest, Reset_AfterReset) { | 477 TEST_F(DecryptingAudioDecoderTest, Reset_AfterReset) { |
465 Initialize(); | 478 Initialize(); |
466 EnterNormalDecodingState(); | 479 EnterNormalDecodingState(); |
467 Reset(); | 480 Reset(); |
468 Reset(); | 481 Reset(); |
469 } | 482 } |
470 | 483 |
471 } // namespace media | 484 } // namespace media |
OLD | NEW |