| 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/decoder_buffer.h" | 12 #include "media/base/decoder_buffer.h" |
| 13 #include "media/base/decrypt_config.h" | 13 #include "media/base/decrypt_config.h" |
| 14 #include "media/base/encryption_scheme.h" |
| 14 #include "media/base/gmock_callback_support.h" | 15 #include "media/base/gmock_callback_support.h" |
| 15 #include "media/base/media_util.h" | 16 #include "media/base/media_util.h" |
| 16 #include "media/base/mock_filters.h" | 17 #include "media/base/mock_filters.h" |
| 17 #include "media/base/test_helpers.h" | 18 #include "media/base/test_helpers.h" |
| 18 #include "media/base/timestamp_constants.h" | 19 #include "media/base/timestamp_constants.h" |
| 19 #include "media/filters/decrypting_audio_decoder.h" | 20 #include "media/filters/decrypting_audio_decoder.h" |
| 20 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 21 | 22 |
| 22 using ::testing::_; | 23 using ::testing::_; |
| 23 using ::testing::AtMost; | 24 using ::testing::AtMost; |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 }; | 296 }; |
| 296 | 297 |
| 297 TEST_F(DecryptingAudioDecoderTest, Initialize_Normal) { | 298 TEST_F(DecryptingAudioDecoderTest, Initialize_Normal) { |
| 298 Initialize(); | 299 Initialize(); |
| 299 } | 300 } |
| 300 | 301 |
| 301 // Ensure that DecryptingAudioDecoder only accepts encrypted audio. | 302 // Ensure that DecryptingAudioDecoder only accepts encrypted audio. |
| 302 TEST_F(DecryptingAudioDecoderTest, Initialize_UnencryptedAudioConfig) { | 303 TEST_F(DecryptingAudioDecoderTest, Initialize_UnencryptedAudioConfig) { |
| 303 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32, | 304 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32, |
| 304 CHANNEL_LAYOUT_STEREO, kSampleRate, | 305 CHANNEL_LAYOUT_STEREO, kSampleRate, |
| 305 EmptyExtraData(), false); | 306 EmptyExtraData(), EncryptionScheme(false)); |
| 306 | 307 |
| 307 InitializeAndExpectResult(config, false); | 308 InitializeAndExpectResult(config, false); |
| 308 } | 309 } |
| 309 | 310 |
| 310 // Ensure decoder handles invalid audio configs without crashing. | 311 // Ensure decoder handles invalid audio configs without crashing. |
| 311 TEST_F(DecryptingAudioDecoderTest, Initialize_InvalidAudioConfig) { | 312 TEST_F(DecryptingAudioDecoderTest, Initialize_InvalidAudioConfig) { |
| 312 AudioDecoderConfig config(kUnknownAudioCodec, kUnknownSampleFormat, | 313 AudioDecoderConfig config(kUnknownAudioCodec, kUnknownSampleFormat, |
| 313 CHANNEL_LAYOUT_STEREO, 0, EmptyExtraData(), true); | 314 CHANNEL_LAYOUT_STEREO, 0, EmptyExtraData(), |
| 315 EncryptionScheme(true)); |
| 314 | 316 |
| 315 InitializeAndExpectResult(config, false); | 317 InitializeAndExpectResult(config, false); |
| 316 } | 318 } |
| 317 | 319 |
| 318 // Ensure decoder handles unsupported audio configs without crashing. | 320 // Ensure decoder handles unsupported audio configs without crashing. |
| 319 TEST_F(DecryptingAudioDecoderTest, Initialize_UnsupportedAudioConfig) { | 321 TEST_F(DecryptingAudioDecoderTest, Initialize_UnsupportedAudioConfig) { |
| 320 SetCdmType(CDM_WITH_DECRYPTOR); | 322 SetCdmType(CDM_WITH_DECRYPTOR); |
| 321 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) | 323 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) |
| 322 .WillOnce(RunCallback<1>(false)); | 324 .WillOnce(RunCallback<1>(false)); |
| 323 | 325 |
| 324 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32, | 326 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32, |
| 325 CHANNEL_LAYOUT_STEREO, kSampleRate, | 327 CHANNEL_LAYOUT_STEREO, kSampleRate, |
| 326 EmptyExtraData(), true); | 328 EmptyExtraData(), EncryptionScheme(true)); |
| 327 InitializeAndExpectResult(config, false); | 329 InitializeAndExpectResult(config, false); |
| 328 } | 330 } |
| 329 | 331 |
| 330 TEST_F(DecryptingAudioDecoderTest, Initialize_NoCdm) { | 332 TEST_F(DecryptingAudioDecoderTest, Initialize_NoCdm) { |
| 331 SetCdmType(NO_CDM); | 333 SetCdmType(NO_CDM); |
| 332 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32, | 334 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32, |
| 333 CHANNEL_LAYOUT_STEREO, kSampleRate, | 335 CHANNEL_LAYOUT_STEREO, kSampleRate, |
| 334 EmptyExtraData(), true); | 336 EmptyExtraData(), true); |
| 335 InitializeAndExpectResult(config, false); | 337 InitializeAndExpectResult(config, false); |
| 336 } | 338 } |
| 337 | 339 |
| 338 TEST_F(DecryptingAudioDecoderTest, Initialize_CdmWithoutDecryptor) { | 340 TEST_F(DecryptingAudioDecoderTest, Initialize_CdmWithoutDecryptor) { |
| 339 SetCdmType(CDM_WITHOUT_DECRYPTOR); | 341 SetCdmType(CDM_WITHOUT_DECRYPTOR); |
| 340 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32, | 342 AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32, |
| 341 CHANNEL_LAYOUT_STEREO, kSampleRate, | 343 CHANNEL_LAYOUT_STEREO, kSampleRate, |
| 342 EmptyExtraData(), true); | 344 EmptyExtraData(), EncryptionScheme(true)); |
| 343 InitializeAndExpectResult(config, false); | 345 InitializeAndExpectResult(config, false); |
| 344 } | 346 } |
| 345 | 347 |
| 346 // Test normal decrypt and decode case. | 348 // Test normal decrypt and decode case. |
| 347 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_Normal) { | 349 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_Normal) { |
| 348 Initialize(); | 350 Initialize(); |
| 349 EnterNormalDecodingState(); | 351 EnterNormalDecodingState(); |
| 350 } | 352 } |
| 351 | 353 |
| 352 // Test the case where the decryptor returns error when doing decrypt and | 354 // 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... |
| 401 Initialize(); | 403 Initialize(); |
| 402 | 404 |
| 403 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) | 405 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) |
| 404 .Times(AtMost(1)) | 406 .Times(AtMost(1)) |
| 405 .WillOnce(RunCallback<1>(true)); | 407 .WillOnce(RunCallback<1>(true)); |
| 406 | 408 |
| 407 // The new config is different from the initial config in bits-per-channel, | 409 // The new config is different from the initial config in bits-per-channel, |
| 408 // channel layout and samples_per_second. | 410 // channel layout and samples_per_second. |
| 409 AudioDecoderConfig new_config(kCodecVorbis, kSampleFormatPlanarS16, | 411 AudioDecoderConfig new_config(kCodecVorbis, kSampleFormatPlanarS16, |
| 410 CHANNEL_LAYOUT_5_1, 88200, EmptyExtraData(), | 412 CHANNEL_LAYOUT_5_1, 88200, EmptyExtraData(), |
| 411 true); | 413 EncryptionScheme(true)); |
| 412 EXPECT_NE(new_config.bits_per_channel(), config_.bits_per_channel()); | 414 EXPECT_NE(new_config.bits_per_channel(), config_.bits_per_channel()); |
| 413 EXPECT_NE(new_config.channel_layout(), config_.channel_layout()); | 415 EXPECT_NE(new_config.channel_layout(), config_.channel_layout()); |
| 414 EXPECT_NE(new_config.samples_per_second(), config_.samples_per_second()); | 416 EXPECT_NE(new_config.samples_per_second(), config_.samples_per_second()); |
| 415 | 417 |
| 416 ReinitializeConfigChange(new_config); | 418 ReinitializeConfigChange(new_config); |
| 417 message_loop_.RunUntilIdle(); | 419 message_loop_.RunUntilIdle(); |
| 418 } | 420 } |
| 419 | 421 |
| 420 // Test the case where the a key is added when the decryptor is in | 422 // Test the case where the a key is added when the decryptor is in |
| 421 // kWaitingForKey state. | 423 // kWaitingForKey state. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 | 497 |
| 496 // Test resetting after the decoder has been reset. | 498 // Test resetting after the decoder has been reset. |
| 497 TEST_F(DecryptingAudioDecoderTest, Reset_AfterReset) { | 499 TEST_F(DecryptingAudioDecoderTest, Reset_AfterReset) { |
| 498 Initialize(); | 500 Initialize(); |
| 499 EnterNormalDecodingState(); | 501 EnterNormalDecodingState(); |
| 500 Reset(); | 502 Reset(); |
| 501 Reset(); | 503 Reset(); |
| 502 } | 504 } |
| 503 | 505 |
| 504 } // namespace media | 506 } // namespace media |
| OLD | NEW |