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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 // function names. But for testing purpose, they all use an audio input | 124 // function names. But for testing purpose, they all use an audio input |
125 // demuxer stream. | 125 // demuxer stream. |
126 | 126 |
127 void Initialize() { | 127 void Initialize() { |
128 SetCdmType(CDM_WITH_DECRYPTOR); | 128 SetCdmType(CDM_WITH_DECRYPTOR); |
129 EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _)) | 129 EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _)) |
130 .WillOnce(SaveArg<1>(&key_added_cb_)); | 130 .WillOnce(SaveArg<1>(&key_added_cb_)); |
131 | 131 |
132 AudioDecoderConfig input_config(kCodecVorbis, kSampleFormatPlanarF32, | 132 AudioDecoderConfig input_config(kCodecVorbis, kSampleFormatPlanarF32, |
133 CHANNEL_LAYOUT_STEREO, 44100, | 133 CHANNEL_LAYOUT_STEREO, 44100, |
134 EmptyExtraData(), AesCtrEncryptionScheme()); | 134 EmptyExtraData(), true); |
135 InitializeAudioAndExpectStatus(input_config, PIPELINE_OK); | 135 InitializeAudioAndExpectStatus(input_config, PIPELINE_OK); |
136 | 136 |
137 const AudioDecoderConfig& output_config = | 137 const AudioDecoderConfig& output_config = |
138 demuxer_stream_->audio_decoder_config(); | 138 demuxer_stream_->audio_decoder_config(); |
139 EXPECT_EQ(DemuxerStream::AUDIO, demuxer_stream_->type()); | 139 EXPECT_EQ(DemuxerStream::AUDIO, demuxer_stream_->type()); |
140 EXPECT_FALSE(output_config.is_encrypted()); | 140 EXPECT_FALSE(output_config.is_encrypted()); |
141 EXPECT_EQ(input_config.bits_per_channel(), | 141 EXPECT_EQ(input_config.bits_per_channel(), |
142 output_config.bits_per_channel()); | 142 output_config.bits_per_channel()); |
143 EXPECT_EQ(input_config.channel_layout(), output_config.channel_layout()); | 143 EXPECT_EQ(input_config.channel_layout(), output_config.channel_layout()); |
144 EXPECT_EQ(input_config.sample_format(), output_config.sample_format()); | 144 EXPECT_EQ(input_config.sample_format(), output_config.sample_format()); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 EXPECT_EQ(input_config.coded_size(), output_config.coded_size()); | 298 EXPECT_EQ(input_config.coded_size(), output_config.coded_size()); |
299 EXPECT_EQ(input_config.visible_rect(), output_config.visible_rect()); | 299 EXPECT_EQ(input_config.visible_rect(), output_config.visible_rect()); |
300 EXPECT_EQ(input_config.natural_size(), output_config.natural_size()); | 300 EXPECT_EQ(input_config.natural_size(), output_config.natural_size()); |
301 ASSERT_EQ(input_config.extra_data(), output_config.extra_data()); | 301 ASSERT_EQ(input_config.extra_data(), output_config.extra_data()); |
302 } | 302 } |
303 | 303 |
304 TEST_F(DecryptingDemuxerStreamTest, Initialize_CdmWithoutDecryptor) { | 304 TEST_F(DecryptingDemuxerStreamTest, Initialize_CdmWithoutDecryptor) { |
305 SetCdmType(CDM_WITHOUT_DECRYPTOR); | 305 SetCdmType(CDM_WITHOUT_DECRYPTOR); |
306 AudioDecoderConfig input_config(kCodecVorbis, kSampleFormatPlanarF32, | 306 AudioDecoderConfig input_config(kCodecVorbis, kSampleFormatPlanarF32, |
307 CHANNEL_LAYOUT_STEREO, 44100, | 307 CHANNEL_LAYOUT_STEREO, 44100, |
308 EmptyExtraData(), AesCtrEncryptionScheme()); | 308 EmptyExtraData(), true); |
309 InitializeAudioAndExpectStatus(input_config, DECODER_ERROR_NOT_SUPPORTED); | 309 InitializeAudioAndExpectStatus(input_config, DECODER_ERROR_NOT_SUPPORTED); |
310 } | 310 } |
311 | 311 |
312 // Test normal read case where the buffer is encrypted. | 312 // Test normal read case where the buffer is encrypted. |
313 TEST_F(DecryptingDemuxerStreamTest, Read_Normal) { | 313 TEST_F(DecryptingDemuxerStreamTest, Read_Normal) { |
314 Initialize(); | 314 Initialize(); |
315 EnterNormalReadingState(); | 315 EnterNormalReadingState(); |
316 } | 316 } |
317 | 317 |
318 // Test normal read case where the buffer is clear. | 318 // Test normal read case where the buffer is clear. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 | 354 |
355 EXPECT_CALL(*decryptor_, Decrypt(_, encrypted_buffer_, _)) | 355 EXPECT_CALL(*decryptor_, Decrypt(_, encrypted_buffer_, _)) |
356 .WillRepeatedly(RunCallback<2>(Decryptor::kSuccess, decrypted_buffer_)); | 356 .WillRepeatedly(RunCallback<2>(Decryptor::kSuccess, decrypted_buffer_)); |
357 EXPECT_CALL(*this, BufferReady(DemuxerStream::kOk, decrypted_buffer_)); | 357 EXPECT_CALL(*this, BufferReady(DemuxerStream::kOk, decrypted_buffer_)); |
358 key_added_cb_.Run(); | 358 key_added_cb_.Run(); |
359 message_loop_.RunUntilIdle(); | 359 message_loop_.RunUntilIdle(); |
360 } | 360 } |
361 | 361 |
362 // Test the case where the a key is added when the decryptor is in | 362 // Test the case where the a key is added when the decryptor is in |
363 // kPendingDecrypt state. | 363 // kPendingDecrypt state. |
364 TEST_F(DecryptingDemuxerStreamTest, KeyAdded_DuringPendingDecrypt) { | 364 TEST_F(DecryptingDemuxerStreamTest, KeyAdded_DruingPendingDecrypt) { |
365 Initialize(); | 365 Initialize(); |
366 EnterPendingDecryptState(); | 366 EnterPendingDecryptState(); |
367 | 367 |
368 EXPECT_CALL(*decryptor_, Decrypt(_, encrypted_buffer_, _)) | 368 EXPECT_CALL(*decryptor_, Decrypt(_, encrypted_buffer_, _)) |
369 .WillRepeatedly(RunCallback<2>(Decryptor::kSuccess, decrypted_buffer_)); | 369 .WillRepeatedly(RunCallback<2>(Decryptor::kSuccess, decrypted_buffer_)); |
370 EXPECT_CALL(*this, BufferReady(DemuxerStream::kOk, decrypted_buffer_)); | 370 EXPECT_CALL(*this, BufferReady(DemuxerStream::kOk, decrypted_buffer_)); |
371 // The decrypt callback is returned after the correct decryption key is added. | 371 // The decrypt callback is returned after the correct decryption key is added. |
372 key_added_cb_.Run(); | 372 key_added_cb_.Run(); |
373 base::ResetAndReturn(&pending_decrypt_cb_).Run(Decryptor::kNoKey, NULL); | 373 base::ResetAndReturn(&pending_decrypt_cb_).Run(Decryptor::kNoKey, NULL); |
374 message_loop_.RunUntilIdle(); | 374 message_loop_.RunUntilIdle(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 SatisfyPendingDemuxerReadCB(DemuxerStream::kAborted); | 450 SatisfyPendingDemuxerReadCB(DemuxerStream::kAborted); |
451 message_loop_.RunUntilIdle(); | 451 message_loop_.RunUntilIdle(); |
452 } | 452 } |
453 | 453 |
454 // Test config change on the input demuxer stream. | 454 // Test config change on the input demuxer stream. |
455 TEST_F(DecryptingDemuxerStreamTest, DemuxerRead_ConfigChanged) { | 455 TEST_F(DecryptingDemuxerStreamTest, DemuxerRead_ConfigChanged) { |
456 Initialize(); | 456 Initialize(); |
457 | 457 |
458 AudioDecoderConfig new_config(kCodecVorbis, kSampleFormatPlanarF32, | 458 AudioDecoderConfig new_config(kCodecVorbis, kSampleFormatPlanarF32, |
459 CHANNEL_LAYOUT_STEREO, 88200, EmptyExtraData(), | 459 CHANNEL_LAYOUT_STEREO, 88200, EmptyExtraData(), |
460 AesCtrEncryptionScheme()); | 460 true); |
461 input_audio_stream_->set_audio_decoder_config(new_config); | 461 input_audio_stream_->set_audio_decoder_config(new_config); |
462 | 462 |
463 EXPECT_CALL(*input_audio_stream_, Read(_)) | 463 EXPECT_CALL(*input_audio_stream_, Read(_)) |
464 .WillOnce(RunCallback<0>(DemuxerStream::kConfigChanged, | 464 .WillOnce(RunCallback<0>(DemuxerStream::kConfigChanged, |
465 scoped_refptr<DecoderBuffer>())); | 465 scoped_refptr<DecoderBuffer>())); |
466 | 466 |
467 ReadAndExpectBufferReadyWith(DemuxerStream::kConfigChanged, NULL); | 467 ReadAndExpectBufferReadyWith(DemuxerStream::kConfigChanged, NULL); |
468 } | 468 } |
469 | 469 |
470 // Test resetting when waiting for a config changed read. | 470 // Test resetting when waiting for a config changed read. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 } | 519 } |
520 | 520 |
521 // Test destruction after reset. | 521 // Test destruction after reset. |
522 TEST_F(DecryptingDemuxerStreamTest, Destroy_AfterReset) { | 522 TEST_F(DecryptingDemuxerStreamTest, Destroy_AfterReset) { |
523 Initialize(); | 523 Initialize(); |
524 EnterNormalReadingState(); | 524 EnterNormalReadingState(); |
525 Reset(); | 525 Reset(); |
526 } | 526 } |
527 | 527 |
528 } // namespace media | 528 } // namespace media |
OLD | NEW |