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" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 } | 47 } |
48 | 48 |
49 // Use anonymous namespace here to prevent the actions to be defined multiple | 49 // 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. | 50 // times across multiple test files. Sadly we can't use static for them. |
51 namespace { | 51 namespace { |
52 | 52 |
53 ACTION_P(ReturnBuffer, buffer) { | 53 ACTION_P(ReturnBuffer, buffer) { |
54 return buffer; | 54 return buffer; |
55 } | 55 } |
56 | 56 |
57 ACTION_P(RunCallbackIfNotNull, param) { | |
58 if (!arg0.is_null()) | |
59 arg0.Run(param); | |
60 } | |
61 | |
62 } // namespace | 57 } // namespace |
63 | 58 |
64 class DecryptingAudioDecoderTest : public testing::Test { | 59 class DecryptingAudioDecoderTest : public testing::Test { |
65 public: | 60 public: |
66 DecryptingAudioDecoderTest() | 61 DecryptingAudioDecoderTest() |
67 : decoder_(new DecryptingAudioDecoder( | 62 : decoder_(new DecryptingAudioDecoder( |
68 message_loop_.message_loop_proxy(), | 63 message_loop_.message_loop_proxy(), |
69 base::Bind( | 64 base::Bind( |
70 &DecryptingAudioDecoderTest::RequestDecryptorNotification, | 65 &DecryptingAudioDecoderTest::RequestDecryptorNotification, |
71 base::Unretained(this)))), | 66 base::Unretained(this)))), |
(...skipping 24 matching lines...) Expand all Loading... |
96 kFakeAudioFrameSize, | 91 kFakeAudioFrameSize, |
97 kNoTimestamp()); | 92 kNoTimestamp()); |
98 decoded_frame_list_.push_back(decoded_frame_); | 93 decoded_frame_list_.push_back(decoded_frame_); |
99 | 94 |
100 decoder_->Initialize(config, NewExpectedStatusCB(status), | 95 decoder_->Initialize(config, NewExpectedStatusCB(status), |
101 base::Bind(&DecryptingAudioDecoderTest::FrameReady, | 96 base::Bind(&DecryptingAudioDecoderTest::FrameReady, |
102 base::Unretained(this))); | 97 base::Unretained(this))); |
103 message_loop_.RunUntilIdle(); | 98 message_loop_.RunUntilIdle(); |
104 } | 99 } |
105 | 100 |
| 101 void ExpectDecryptorNotification(Decryptor* decryptor, bool expected_result) { |
| 102 EXPECT_CALL(*this, RequestDecryptorNotification(_)).WillOnce( |
| 103 RunCallback<0>(decryptor, |
| 104 base::Bind(&DecryptingAudioDecoderTest::DecryptorSet, |
| 105 base::Unretained(this)))); |
| 106 EXPECT_CALL(*this, DecryptorSet(expected_result)); |
| 107 } |
| 108 |
106 void Initialize() { | 109 void Initialize() { |
107 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) | 110 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) |
108 .Times(AtMost(1)) | 111 .Times(AtMost(1)) |
109 .WillOnce(RunCallback<1>(true)); | 112 .WillOnce(RunCallback<1>(true)); |
110 EXPECT_CALL(*this, RequestDecryptorNotification(_)) | 113 ExpectDecryptorNotification(decryptor_.get(), true); |
111 .WillOnce(RunCallbackIfNotNull(decryptor_.get())); | |
112 EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _)) | 114 EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _)) |
113 .WillOnce(SaveArg<1>(&key_added_cb_)); | 115 .WillOnce(SaveArg<1>(&key_added_cb_)); |
114 | 116 |
115 config_.Initialize(kCodecVorbis, kSampleFormatPlanarF32, | 117 config_.Initialize(kCodecVorbis, kSampleFormatPlanarF32, |
116 CHANNEL_LAYOUT_STEREO, kSampleRate, NULL, 0, true, true, | 118 CHANNEL_LAYOUT_STEREO, kSampleRate, NULL, 0, true, true, |
117 base::TimeDelta(), 0); | 119 base::TimeDelta(), 0); |
118 InitializeAndExpectStatus(config_, PIPELINE_OK); | 120 InitializeAndExpectStatus(config_, PIPELINE_OK); |
119 } | 121 } |
120 | 122 |
121 void Reinitialize() { | 123 void Reinitialize() { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 243 |
242 decoder_.reset(); | 244 decoder_.reset(); |
243 message_loop_.RunUntilIdle(); | 245 message_loop_.RunUntilIdle(); |
244 } | 246 } |
245 | 247 |
246 MOCK_METHOD1(RequestDecryptorNotification, void(const DecryptorReadyCB&)); | 248 MOCK_METHOD1(RequestDecryptorNotification, void(const DecryptorReadyCB&)); |
247 | 249 |
248 MOCK_METHOD1(FrameReady, void(const scoped_refptr<AudioBuffer>&)); | 250 MOCK_METHOD1(FrameReady, void(const scoped_refptr<AudioBuffer>&)); |
249 MOCK_METHOD1(DecodeDone, void(AudioDecoder::Status)); | 251 MOCK_METHOD1(DecodeDone, void(AudioDecoder::Status)); |
250 | 252 |
| 253 MOCK_METHOD1(DecryptorSet, void(bool)); |
| 254 |
251 base::MessageLoop message_loop_; | 255 base::MessageLoop message_loop_; |
252 scoped_ptr<DecryptingAudioDecoder> decoder_; | 256 scoped_ptr<DecryptingAudioDecoder> decoder_; |
253 scoped_ptr<StrictMock<MockDecryptor> > decryptor_; | 257 scoped_ptr<StrictMock<MockDecryptor> > decryptor_; |
254 AudioDecoderConfig config_; | 258 AudioDecoderConfig config_; |
255 | 259 |
256 // Variables to help the |decryptor_| to simulate decoding delay and flushing. | 260 // Variables to help the |decryptor_| to simulate decoding delay and flushing. |
257 int num_decrypt_and_decode_calls_; | 261 int num_decrypt_and_decode_calls_; |
258 int num_frames_in_decryptor_; | 262 int num_frames_in_decryptor_; |
259 | 263 |
260 Decryptor::DecoderInitCB pending_init_cb_; | 264 Decryptor::DecoderInitCB pending_init_cb_; |
(...skipping 26 matching lines...) Expand all Loading... |
287 AudioDecoderConfig config(kUnknownAudioCodec, kUnknownSampleFormat, | 291 AudioDecoderConfig config(kUnknownAudioCodec, kUnknownSampleFormat, |
288 CHANNEL_LAYOUT_STEREO, 0, NULL, 0, true); | 292 CHANNEL_LAYOUT_STEREO, 0, NULL, 0, true); |
289 | 293 |
290 InitializeAndExpectStatus(config, PIPELINE_ERROR_DECODE); | 294 InitializeAndExpectStatus(config, PIPELINE_ERROR_DECODE); |
291 } | 295 } |
292 | 296 |
293 // Ensure decoder handles unsupported audio configs without crashing. | 297 // Ensure decoder handles unsupported audio configs without crashing. |
294 TEST_F(DecryptingAudioDecoderTest, Initialize_UnsupportedAudioConfig) { | 298 TEST_F(DecryptingAudioDecoderTest, Initialize_UnsupportedAudioConfig) { |
295 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) | 299 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) |
296 .WillOnce(RunCallback<1>(false)); | 300 .WillOnce(RunCallback<1>(false)); |
297 EXPECT_CALL(*this, RequestDecryptorNotification(_)) | 301 ExpectDecryptorNotification(decryptor_.get(), true); |
298 .WillOnce(RunCallbackIfNotNull(decryptor_.get())); | |
299 | 302 |
300 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32, | 303 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32, |
301 CHANNEL_LAYOUT_STEREO, kSampleRate, NULL, 0, true); | 304 CHANNEL_LAYOUT_STEREO, kSampleRate, NULL, 0, true); |
302 InitializeAndExpectStatus(config, DECODER_ERROR_NOT_SUPPORTED); | 305 InitializeAndExpectStatus(config, DECODER_ERROR_NOT_SUPPORTED); |
303 } | 306 } |
304 | 307 |
305 TEST_F(DecryptingAudioDecoderTest, Initialize_NullDecryptor) { | 308 TEST_F(DecryptingAudioDecoderTest, Initialize_NullDecryptor) { |
306 EXPECT_CALL(*this, RequestDecryptorNotification(_)) | 309 ExpectDecryptorNotification(NULL, false); |
307 .WillRepeatedly(RunCallbackIfNotNull(static_cast<Decryptor*>(NULL))); | |
308 | |
309 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32, | 310 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32, |
310 CHANNEL_LAYOUT_STEREO, kSampleRate, NULL, 0, true); | 311 CHANNEL_LAYOUT_STEREO, kSampleRate, NULL, 0, true); |
311 InitializeAndExpectStatus(config, DECODER_ERROR_NOT_SUPPORTED); | 312 InitializeAndExpectStatus(config, DECODER_ERROR_NOT_SUPPORTED); |
312 } | 313 } |
313 | 314 |
314 // Test normal decrypt and decode case. | 315 // Test normal decrypt and decode case. |
315 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_Normal) { | 316 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_Normal) { |
316 Initialize(); | 317 Initialize(); |
317 EnterNormalDecodingState(); | 318 EnterNormalDecodingState(); |
318 } | 319 } |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 | 463 |
463 // Test resetting after the decoder has been reset. | 464 // Test resetting after the decoder has been reset. |
464 TEST_F(DecryptingAudioDecoderTest, Reset_AfterReset) { | 465 TEST_F(DecryptingAudioDecoderTest, Reset_AfterReset) { |
465 Initialize(); | 466 Initialize(); |
466 EnterNormalDecodingState(); | 467 EnterNormalDecodingState(); |
467 Reset(); | 468 Reset(); |
468 Reset(); | 469 Reset(); |
469 } | 470 } |
470 | 471 |
471 } // namespace media | 472 } // namespace media |
OLD | NEW |