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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 // times across multiple test files. Sadly we can't use static for them. | 46 // times across multiple test files. Sadly we can't use static for them. |
47 namespace { | 47 namespace { |
48 | 48 |
49 ACTION_P(ReturnBuffer, buffer) { | 49 ACTION_P(ReturnBuffer, buffer) { |
50 arg0.Run(buffer.get() ? DemuxerStream::kOk : DemuxerStream::kAborted, buffer); | 50 arg0.Run(buffer.get() ? DemuxerStream::kOk : DemuxerStream::kAborted, buffer); |
51 } | 51 } |
52 | 52 |
53 // Sets the |decryptor| if the DecryptorReadyCB (arg0) is not null. Sets | 53 // Sets the |decryptor| if the DecryptorReadyCB (arg0) is not null. Sets |
54 // |is_decryptor_set| to true if a non-NULL |decryptor| has been set through the | 54 // |is_decryptor_set| to true if a non-NULL |decryptor| has been set through the |
55 // callback. | 55 // callback. |
56 ACTION_P2(SetDecryptorIfNotNull, decryptor, is_decryptor_set) { | 56 ACTION_P3(SetDecryptorIfNotNull, decryptor, done_cb, is_decryptor_set) { |
57 if (!arg0.is_null()) | 57 if (!arg0.is_null()) |
58 arg0.Run(decryptor); | 58 arg0.Run(decryptor, done_cb); |
59 | 59 |
60 *is_decryptor_set = !arg0.is_null() && decryptor; | 60 *is_decryptor_set = !arg0.is_null() && decryptor; |
61 } | 61 } |
62 | 62 |
63 ACTION_P2(ResetAndRunCallback, callback, param) { | 63 ACTION_P2(ResetAndRunCallback, callback, param) { |
64 base::ResetAndReturn(callback).Run(param); | 64 base::ResetAndReturn(callback).Run(param); |
65 } | 65 } |
66 | 66 |
67 MATCHER(IsEndOfStream, "end of stream") { | 67 MATCHER(IsEndOfStream, "end of stream") { |
68 return arg->end_of_stream(); | 68 return arg->end_of_stream(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 } | 105 } |
106 | 106 |
107 void InitializeVideoAndExpectStatus(const VideoDecoderConfig& config, | 107 void InitializeVideoAndExpectStatus(const VideoDecoderConfig& config, |
108 PipelineStatus status) { | 108 PipelineStatus status) { |
109 input_video_stream_->set_video_decoder_config(config); | 109 input_video_stream_->set_video_decoder_config(config); |
110 demuxer_stream_->Initialize(input_video_stream_.get(), | 110 demuxer_stream_->Initialize(input_video_stream_.get(), |
111 NewExpectedStatusCB(status)); | 111 NewExpectedStatusCB(status)); |
112 message_loop_.RunUntilIdle(); | 112 message_loop_.RunUntilIdle(); |
113 } | 113 } |
114 | 114 |
| 115 void ExpectDecryptorNotification(Decryptor* decryptor, bool expected_result) { |
| 116 EXPECT_CALL(*this, RequestDecryptorNotification(_)) |
| 117 .WillOnce(SetDecryptorIfNotNull( |
| 118 decryptor, |
| 119 base::Bind(&DecryptingDemuxerStreamTest::DecryptorSet, |
| 120 base::Unretained(this)), |
| 121 &is_decryptor_set_)); |
| 122 EXPECT_CALL(*this, DecryptorSet(expected_result)); |
| 123 } |
| 124 |
115 // The following functions are used to test stream-type-neutral logic in | 125 // The following functions are used to test stream-type-neutral logic in |
116 // DecryptingDemuxerStream. Therefore, we don't specify audio or video in the | 126 // DecryptingDemuxerStream. Therefore, we don't specify audio or video in the |
117 // function names. But for testing purpose, they all use an audio input | 127 // function names. But for testing purpose, they all use an audio input |
118 // demuxer stream. | 128 // demuxer stream. |
119 | 129 |
120 void Initialize() { | 130 void Initialize() { |
121 EXPECT_CALL(*this, RequestDecryptorNotification(_)) | 131 ExpectDecryptorNotification(decryptor_.get(), true); |
122 .WillOnce(SetDecryptorIfNotNull(decryptor_.get(), &is_decryptor_set_)); | |
123 EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _)) | 132 EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _)) |
124 .WillOnce(SaveArg<1>(&key_added_cb_)); | 133 .WillOnce(SaveArg<1>(&key_added_cb_)); |
125 | 134 |
126 AudioDecoderConfig input_config( | 135 AudioDecoderConfig input_config( |
127 kCodecVorbis, kSampleFormatPlanarF32, CHANNEL_LAYOUT_STEREO, 44100, | 136 kCodecVorbis, kSampleFormatPlanarF32, CHANNEL_LAYOUT_STEREO, 44100, |
128 NULL, 0, true); | 137 NULL, 0, true); |
129 InitializeAudioAndExpectStatus(input_config, PIPELINE_OK); | 138 InitializeAudioAndExpectStatus(input_config, PIPELINE_OK); |
130 | 139 |
131 const AudioDecoderConfig& output_config = | 140 const AudioDecoderConfig& output_config = |
132 demuxer_stream_->audio_decoder_config(); | 141 demuxer_stream_->audio_decoder_config(); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 | 251 |
243 demuxer_stream_->Reset(NewExpectedClosure()); | 252 demuxer_stream_->Reset(NewExpectedClosure()); |
244 message_loop_.RunUntilIdle(); | 253 message_loop_.RunUntilIdle(); |
245 } | 254 } |
246 | 255 |
247 MOCK_METHOD1(RequestDecryptorNotification, void(const DecryptorReadyCB&)); | 256 MOCK_METHOD1(RequestDecryptorNotification, void(const DecryptorReadyCB&)); |
248 | 257 |
249 MOCK_METHOD2(BufferReady, void(DemuxerStream::Status, | 258 MOCK_METHOD2(BufferReady, void(DemuxerStream::Status, |
250 const scoped_refptr<DecoderBuffer>&)); | 259 const scoped_refptr<DecoderBuffer>&)); |
251 | 260 |
| 261 MOCK_METHOD1(DecryptorSet, void(bool)); |
| 262 |
252 base::MessageLoop message_loop_; | 263 base::MessageLoop message_loop_; |
253 scoped_ptr<DecryptingDemuxerStream> demuxer_stream_; | 264 scoped_ptr<DecryptingDemuxerStream> demuxer_stream_; |
254 scoped_ptr<StrictMock<MockDecryptor> > decryptor_; | 265 scoped_ptr<StrictMock<MockDecryptor> > decryptor_; |
255 // Whether a valid Decryptor has been set in the |demuxer_stream_|. | 266 // Whether a valid Decryptor has been set in the |demuxer_stream_|. |
256 bool is_decryptor_set_; | 267 bool is_decryptor_set_; |
257 scoped_ptr<StrictMock<MockDemuxerStream> > input_audio_stream_; | 268 scoped_ptr<StrictMock<MockDemuxerStream> > input_audio_stream_; |
258 scoped_ptr<StrictMock<MockDemuxerStream> > input_video_stream_; | 269 scoped_ptr<StrictMock<MockDemuxerStream> > input_video_stream_; |
259 | 270 |
260 DemuxerStream::ReadCB pending_demuxer_read_cb_; | 271 DemuxerStream::ReadCB pending_demuxer_read_cb_; |
261 Decryptor::NewKeyCB key_added_cb_; | 272 Decryptor::NewKeyCB key_added_cb_; |
262 Decryptor::DecryptCB pending_decrypt_cb_; | 273 Decryptor::DecryptCB pending_decrypt_cb_; |
263 | 274 |
264 // Constant buffers to be returned by the input demuxer streams and the | 275 // Constant buffers to be returned by the input demuxer streams and the |
265 // |decryptor_|. | 276 // |decryptor_|. |
266 scoped_refptr<DecoderBuffer> clear_buffer_; | 277 scoped_refptr<DecoderBuffer> clear_buffer_; |
267 scoped_refptr<DecoderBuffer> encrypted_buffer_; | 278 scoped_refptr<DecoderBuffer> encrypted_buffer_; |
268 scoped_refptr<DecoderBuffer> decrypted_buffer_; | 279 scoped_refptr<DecoderBuffer> decrypted_buffer_; |
269 | 280 |
270 private: | 281 private: |
271 DISALLOW_COPY_AND_ASSIGN(DecryptingDemuxerStreamTest); | 282 DISALLOW_COPY_AND_ASSIGN(DecryptingDemuxerStreamTest); |
272 }; | 283 }; |
273 | 284 |
274 TEST_F(DecryptingDemuxerStreamTest, Initialize_NormalAudio) { | 285 TEST_F(DecryptingDemuxerStreamTest, Initialize_NormalAudio) { |
275 Initialize(); | 286 Initialize(); |
276 } | 287 } |
277 | 288 |
278 TEST_F(DecryptingDemuxerStreamTest, Initialize_NormalVideo) { | 289 TEST_F(DecryptingDemuxerStreamTest, Initialize_NormalVideo) { |
279 EXPECT_CALL(*this, RequestDecryptorNotification(_)) | 290 ExpectDecryptorNotification(decryptor_.get(), true); |
280 .WillOnce(SetDecryptorIfNotNull(decryptor_.get(), &is_decryptor_set_)); | |
281 EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kVideo, _)) | 291 EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kVideo, _)) |
282 .WillOnce(SaveArg<1>(&key_added_cb_)); | 292 .WillOnce(SaveArg<1>(&key_added_cb_)); |
283 | 293 |
284 VideoDecoderConfig input_config = TestVideoConfig::NormalEncrypted(); | 294 VideoDecoderConfig input_config = TestVideoConfig::NormalEncrypted(); |
285 InitializeVideoAndExpectStatus(input_config, PIPELINE_OK); | 295 InitializeVideoAndExpectStatus(input_config, PIPELINE_OK); |
286 | 296 |
287 const VideoDecoderConfig& output_config = | 297 const VideoDecoderConfig& output_config = |
288 demuxer_stream_->video_decoder_config(); | 298 demuxer_stream_->video_decoder_config(); |
289 EXPECT_EQ(DemuxerStream::VIDEO, demuxer_stream_->type()); | 299 EXPECT_EQ(DemuxerStream::VIDEO, demuxer_stream_->type()); |
290 EXPECT_FALSE(output_config.is_encrypted()); | 300 EXPECT_FALSE(output_config.is_encrypted()); |
291 EXPECT_EQ(input_config.codec(), output_config.codec()); | 301 EXPECT_EQ(input_config.codec(), output_config.codec()); |
292 EXPECT_EQ(input_config.format(), output_config.format()); | 302 EXPECT_EQ(input_config.format(), output_config.format()); |
293 EXPECT_EQ(input_config.profile(), output_config.profile()); | 303 EXPECT_EQ(input_config.profile(), output_config.profile()); |
294 EXPECT_EQ(input_config.coded_size(), output_config.coded_size()); | 304 EXPECT_EQ(input_config.coded_size(), output_config.coded_size()); |
295 EXPECT_EQ(input_config.visible_rect(), output_config.visible_rect()); | 305 EXPECT_EQ(input_config.visible_rect(), output_config.visible_rect()); |
296 EXPECT_EQ(input_config.natural_size(), output_config.natural_size()); | 306 EXPECT_EQ(input_config.natural_size(), output_config.natural_size()); |
297 ASSERT_EQ(input_config.extra_data_size(), output_config.extra_data_size()); | 307 ASSERT_EQ(input_config.extra_data_size(), output_config.extra_data_size()); |
298 if (input_config.extra_data_size() > 0) { | 308 if (input_config.extra_data_size() > 0) { |
299 EXPECT_FALSE(output_config.extra_data()); | 309 EXPECT_FALSE(output_config.extra_data()); |
300 EXPECT_EQ(0, memcmp(output_config.extra_data(), input_config.extra_data(), | 310 EXPECT_EQ(0, memcmp(output_config.extra_data(), input_config.extra_data(), |
301 input_config.extra_data_size())); | 311 input_config.extra_data_size())); |
302 } | 312 } |
303 } | 313 } |
304 | 314 |
305 TEST_F(DecryptingDemuxerStreamTest, Initialize_NullDecryptor) { | 315 TEST_F(DecryptingDemuxerStreamTest, Initialize_NullDecryptor) { |
306 EXPECT_CALL(*this, RequestDecryptorNotification(_)) | 316 ExpectDecryptorNotification(NULL, false); |
307 .WillRepeatedly(SetDecryptorIfNotNull(static_cast<Decryptor*>(NULL), | |
308 &is_decryptor_set_)); | |
309 | |
310 AudioDecoderConfig input_config(kCodecVorbis, kSampleFormatPlanarF32, | 317 AudioDecoderConfig input_config(kCodecVorbis, kSampleFormatPlanarF32, |
311 CHANNEL_LAYOUT_STEREO, 44100, NULL, 0, true); | 318 CHANNEL_LAYOUT_STEREO, 44100, NULL, 0, true); |
312 InitializeAudioAndExpectStatus(input_config, DECODER_ERROR_NOT_SUPPORTED); | 319 InitializeAudioAndExpectStatus(input_config, DECODER_ERROR_NOT_SUPPORTED); |
313 } | 320 } |
314 | 321 |
315 // Test normal read case where the buffer is encrypted. | 322 // Test normal read case where the buffer is encrypted. |
316 TEST_F(DecryptingDemuxerStreamTest, Read_Normal) { | 323 TEST_F(DecryptingDemuxerStreamTest, Read_Normal) { |
317 Initialize(); | 324 Initialize(); |
318 EnterNormalReadingState(); | 325 EnterNormalReadingState(); |
319 } | 326 } |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 } | 552 } |
546 | 553 |
547 // Test destruction after reset. | 554 // Test destruction after reset. |
548 TEST_F(DecryptingDemuxerStreamTest, Destroy_AfterReset) { | 555 TEST_F(DecryptingDemuxerStreamTest, Destroy_AfterReset) { |
549 Initialize(); | 556 Initialize(); |
550 EnterNormalReadingState(); | 557 EnterNormalReadingState(); |
551 Reset(); | 558 Reset(); |
552 } | 559 } |
553 | 560 |
554 } // namespace media | 561 } // namespace media |
OLD | NEW |