| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 void Initialize() { | 113 void Initialize() { |
| 114 SetCdmType(CDM_WITH_DECRYPTOR); | 114 SetCdmType(CDM_WITH_DECRYPTOR); |
| 115 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) | 115 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) |
| 116 .Times(AtMost(1)) | 116 .Times(AtMost(1)) |
| 117 .WillOnce(RunCallback<1>(true)); | 117 .WillOnce(RunCallback<1>(true)); |
| 118 EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _)) | 118 EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _)) |
| 119 .WillOnce(SaveArg<1>(&key_added_cb_)); | 119 .WillOnce(SaveArg<1>(&key_added_cb_)); |
| 120 | 120 |
| 121 config_.Initialize(kCodecVorbis, kSampleFormatPlanarF32, | 121 config_.Initialize(kCodecVorbis, kSampleFormatPlanarF32, |
| 122 CHANNEL_LAYOUT_STEREO, kSampleRate, EmptyExtraData(), | 122 CHANNEL_LAYOUT_STEREO, kSampleRate, EmptyExtraData(), |
| 123 AesCtrEncryptionScheme(), base::TimeDelta(), 0); | 123 true, base::TimeDelta(), 0); |
| 124 InitializeAndExpectResult(config_, true); | 124 InitializeAndExpectResult(config_, true); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void Reinitialize() { | 127 void Reinitialize() { |
| 128 ReinitializeConfigChange(config_); | 128 ReinitializeConfigChange(config_); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void ReinitializeConfigChange(const AudioDecoderConfig& new_config) { | 131 void ReinitializeConfigChange(const AudioDecoderConfig& new_config) { |
| 132 EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio)); | 132 EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio)); |
| 133 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) | 133 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 }; | 279 }; |
| 280 | 280 |
| 281 TEST_F(DecryptingAudioDecoderTest, Initialize_Normal) { | 281 TEST_F(DecryptingAudioDecoderTest, Initialize_Normal) { |
| 282 Initialize(); | 282 Initialize(); |
| 283 } | 283 } |
| 284 | 284 |
| 285 // Ensure that DecryptingAudioDecoder only accepts encrypted audio. | 285 // Ensure that DecryptingAudioDecoder only accepts encrypted audio. |
| 286 TEST_F(DecryptingAudioDecoderTest, Initialize_UnencryptedAudioConfig) { | 286 TEST_F(DecryptingAudioDecoderTest, Initialize_UnencryptedAudioConfig) { |
| 287 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32, | 287 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32, |
| 288 CHANNEL_LAYOUT_STEREO, kSampleRate, | 288 CHANNEL_LAYOUT_STEREO, kSampleRate, |
| 289 EmptyExtraData(), Unencrypted()); | 289 EmptyExtraData(), false); |
| 290 | 290 |
| 291 InitializeAndExpectResult(config, false); | 291 InitializeAndExpectResult(config, false); |
| 292 } | 292 } |
| 293 | 293 |
| 294 // Ensure decoder handles invalid audio configs without crashing. | 294 // Ensure decoder handles invalid audio configs without crashing. |
| 295 TEST_F(DecryptingAudioDecoderTest, Initialize_InvalidAudioConfig) { | 295 TEST_F(DecryptingAudioDecoderTest, Initialize_InvalidAudioConfig) { |
| 296 AudioDecoderConfig config(kUnknownAudioCodec, kUnknownSampleFormat, | 296 AudioDecoderConfig config(kUnknownAudioCodec, kUnknownSampleFormat, |
| 297 CHANNEL_LAYOUT_STEREO, 0, EmptyExtraData(), | 297 CHANNEL_LAYOUT_STEREO, 0, EmptyExtraData(), true); |
| 298 AesCtrEncryptionScheme()); | |
| 299 | 298 |
| 300 InitializeAndExpectResult(config, false); | 299 InitializeAndExpectResult(config, false); |
| 301 } | 300 } |
| 302 | 301 |
| 303 // Ensure decoder handles unsupported audio configs without crashing. | 302 // Ensure decoder handles unsupported audio configs without crashing. |
| 304 TEST_F(DecryptingAudioDecoderTest, Initialize_UnsupportedAudioConfig) { | 303 TEST_F(DecryptingAudioDecoderTest, Initialize_UnsupportedAudioConfig) { |
| 305 SetCdmType(CDM_WITH_DECRYPTOR); | 304 SetCdmType(CDM_WITH_DECRYPTOR); |
| 306 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) | 305 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) |
| 307 .WillOnce(RunCallback<1>(false)); | 306 .WillOnce(RunCallback<1>(false)); |
| 308 | 307 |
| 309 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32, | 308 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32, |
| 310 CHANNEL_LAYOUT_STEREO, kSampleRate, | 309 CHANNEL_LAYOUT_STEREO, kSampleRate, |
| 311 EmptyExtraData(), AesCtrEncryptionScheme()); | 310 EmptyExtraData(), true); |
| 312 InitializeAndExpectResult(config, false); | 311 InitializeAndExpectResult(config, false); |
| 313 } | 312 } |
| 314 | 313 |
| 315 TEST_F(DecryptingAudioDecoderTest, Initialize_CdmWithoutDecryptor) { | 314 TEST_F(DecryptingAudioDecoderTest, Initialize_CdmWithoutDecryptor) { |
| 316 SetCdmType(CDM_WITHOUT_DECRYPTOR); | 315 SetCdmType(CDM_WITHOUT_DECRYPTOR); |
| 317 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32, | 316 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32, |
| 318 CHANNEL_LAYOUT_STEREO, kSampleRate, | 317 CHANNEL_LAYOUT_STEREO, kSampleRate, |
| 319 EmptyExtraData(), AesCtrEncryptionScheme()); | 318 EmptyExtraData(), true); |
| 320 InitializeAndExpectResult(config, false); | 319 InitializeAndExpectResult(config, false); |
| 321 } | 320 } |
| 322 | 321 |
| 323 // Test normal decrypt and decode case. | 322 // Test normal decrypt and decode case. |
| 324 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_Normal) { | 323 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_Normal) { |
| 325 Initialize(); | 324 Initialize(); |
| 326 EnterNormalDecodingState(); | 325 EnterNormalDecodingState(); |
| 327 } | 326 } |
| 328 | 327 |
| 329 // Test the case where the decryptor returns error when doing decrypt and | 328 // Test the case where the decryptor returns error when doing decrypt and |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 Initialize(); | 377 Initialize(); |
| 379 | 378 |
| 380 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) | 379 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) |
| 381 .Times(AtMost(1)) | 380 .Times(AtMost(1)) |
| 382 .WillOnce(RunCallback<1>(true)); | 381 .WillOnce(RunCallback<1>(true)); |
| 383 | 382 |
| 384 // The new config is different from the initial config in bits-per-channel, | 383 // The new config is different from the initial config in bits-per-channel, |
| 385 // channel layout and samples_per_second. | 384 // channel layout and samples_per_second. |
| 386 AudioDecoderConfig new_config(kCodecVorbis, kSampleFormatPlanarS16, | 385 AudioDecoderConfig new_config(kCodecVorbis, kSampleFormatPlanarS16, |
| 387 CHANNEL_LAYOUT_5_1, 88200, EmptyExtraData(), | 386 CHANNEL_LAYOUT_5_1, 88200, EmptyExtraData(), |
| 388 AesCtrEncryptionScheme()); | 387 true); |
| 389 EXPECT_NE(new_config.bits_per_channel(), config_.bits_per_channel()); | 388 EXPECT_NE(new_config.bits_per_channel(), config_.bits_per_channel()); |
| 390 EXPECT_NE(new_config.channel_layout(), config_.channel_layout()); | 389 EXPECT_NE(new_config.channel_layout(), config_.channel_layout()); |
| 391 EXPECT_NE(new_config.samples_per_second(), config_.samples_per_second()); | 390 EXPECT_NE(new_config.samples_per_second(), config_.samples_per_second()); |
| 392 | 391 |
| 393 ReinitializeConfigChange(new_config); | 392 ReinitializeConfigChange(new_config); |
| 394 message_loop_.RunUntilIdle(); | 393 message_loop_.RunUntilIdle(); |
| 395 } | 394 } |
| 396 | 395 |
| 397 // Test the case where the a key is added when the decryptor is in | 396 // Test the case where the a key is added when the decryptor is in |
| 398 // kWaitingForKey state. | 397 // kWaitingForKey state. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 | 471 |
| 473 // Test resetting after the decoder has been reset. | 472 // Test resetting after the decoder has been reset. |
| 474 TEST_F(DecryptingAudioDecoderTest, Reset_AfterReset) { | 473 TEST_F(DecryptingAudioDecoderTest, Reset_AfterReset) { |
| 475 Initialize(); | 474 Initialize(); |
| 476 EnterNormalDecodingState(); | 475 EnterNormalDecodingState(); |
| 477 Reset(); | 476 Reset(); |
| 478 Reset(); | 477 Reset(); |
| 479 } | 478 } |
| 480 | 479 |
| 481 } // namespace media | 480 } // namespace media |
| OLD | NEW |