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/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "media/base/decoder_buffer.h" | 10 #include "media/base/decoder_buffer.h" |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 | 264 |
265 MOCK_METHOD2(BufferDecrypted, void(Decryptor::Status, | 265 MOCK_METHOD2(BufferDecrypted, void(Decryptor::Status, |
266 const scoped_refptr<DecoderBuffer>&)); | 266 const scoped_refptr<DecoderBuffer>&)); |
267 | 267 |
268 void DecryptAndExpectToSucceed(const scoped_refptr<DecoderBuffer>& encrypted, | 268 void DecryptAndExpectToSucceed(const scoped_refptr<DecoderBuffer>& encrypted, |
269 const uint8* plain_text, int plain_text_size) { | 269 const uint8* plain_text, int plain_text_size) { |
270 scoped_refptr<DecoderBuffer> decrypted; | 270 scoped_refptr<DecoderBuffer> decrypted; |
271 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kSuccess, NotNull())) | 271 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kSuccess, NotNull())) |
272 .WillOnce(SaveArg<1>(&decrypted)); | 272 .WillOnce(SaveArg<1>(&decrypted)); |
273 | 273 |
274 decryptor_.Decrypt(encrypted, decrypt_cb_); | 274 decryptor_.Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_); |
275 ASSERT_TRUE(decrypted); | 275 ASSERT_TRUE(decrypted); |
276 ASSERT_EQ(plain_text_size, decrypted->GetDataSize()); | 276 ASSERT_EQ(plain_text_size, decrypted->GetDataSize()); |
277 EXPECT_EQ(0, memcmp(plain_text, decrypted->GetData(), plain_text_size)); | 277 EXPECT_EQ(0, memcmp(plain_text, decrypted->GetData(), plain_text_size)); |
278 } | 278 } |
279 | 279 |
280 void DecryptAndExpectDataMismatch( | 280 void DecryptAndExpectDataMismatch( |
281 const scoped_refptr<DecoderBuffer>& encrypted, | 281 const scoped_refptr<DecoderBuffer>& encrypted, |
282 const uint8* plain_text, int plain_text_size) { | 282 const uint8* plain_text, int plain_text_size) { |
283 scoped_refptr<DecoderBuffer> decrypted; | 283 scoped_refptr<DecoderBuffer> decrypted; |
284 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kSuccess, NotNull())) | 284 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kSuccess, NotNull())) |
285 .WillOnce(SaveArg<1>(&decrypted)); | 285 .WillOnce(SaveArg<1>(&decrypted)); |
286 | 286 |
287 decryptor_.Decrypt(encrypted, decrypt_cb_); | 287 decryptor_.Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_); |
288 ASSERT_TRUE(decrypted); | 288 ASSERT_TRUE(decrypted); |
289 ASSERT_EQ(plain_text_size, decrypted->GetDataSize()); | 289 ASSERT_EQ(plain_text_size, decrypted->GetDataSize()); |
290 EXPECT_NE(0, memcmp(plain_text, decrypted->GetData(), plain_text_size)); | 290 EXPECT_NE(0, memcmp(plain_text, decrypted->GetData(), plain_text_size)); |
291 } | 291 } |
292 | 292 |
293 void DecryptAndExpectSizeDataMismatch( | 293 void DecryptAndExpectSizeDataMismatch( |
294 const scoped_refptr<DecoderBuffer>& encrypted, | 294 const scoped_refptr<DecoderBuffer>& encrypted, |
295 const uint8* plain_text, int plain_text_size) { | 295 const uint8* plain_text, int plain_text_size) { |
296 scoped_refptr<DecoderBuffer> decrypted; | 296 scoped_refptr<DecoderBuffer> decrypted; |
297 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kSuccess, NotNull())) | 297 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kSuccess, NotNull())) |
298 .WillOnce(SaveArg<1>(&decrypted)); | 298 .WillOnce(SaveArg<1>(&decrypted)); |
299 | 299 |
300 decryptor_.Decrypt(encrypted, decrypt_cb_); | 300 decryptor_.Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_); |
301 ASSERT_TRUE(decrypted); | 301 ASSERT_TRUE(decrypted); |
302 EXPECT_NE(plain_text_size, decrypted->GetDataSize()); | 302 EXPECT_NE(plain_text_size, decrypted->GetDataSize()); |
303 EXPECT_NE(0, memcmp(plain_text, decrypted->GetData(), plain_text_size)); | 303 EXPECT_NE(0, memcmp(plain_text, decrypted->GetData(), plain_text_size)); |
304 } | 304 } |
305 | 305 |
306 void DecryptAndExpectToFail(const scoped_refptr<DecoderBuffer>& encrypted) { | 306 void DecryptAndExpectToFail(const scoped_refptr<DecoderBuffer>& encrypted) { |
307 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kError, IsNull())); | 307 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kError, IsNull())); |
308 decryptor_.Decrypt(encrypted, decrypt_cb_); | 308 decryptor_.Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_); |
309 } | 309 } |
310 | 310 |
311 MockDecryptorClient client_; | 311 MockDecryptorClient client_; |
312 AesDecryptor decryptor_; | 312 AesDecryptor decryptor_; |
313 std::string session_id_string_; | 313 std::string session_id_string_; |
314 AesDecryptor::DecryptCB decrypt_cb_; | 314 AesDecryptor::DecryptCB decrypt_cb_; |
315 std::vector<SubsampleEntry> subsample_entries_; | 315 std::vector<SubsampleEntry> subsample_entries_; |
316 }; | 316 }; |
317 | 317 |
318 TEST_F(AesDecryptorTest, NormalWebMDecryption) { | 318 TEST_F(AesDecryptorTest, NormalWebMDecryption) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 } | 363 } |
364 | 364 |
365 TEST_F(AesDecryptorTest, NoKey) { | 365 TEST_F(AesDecryptorTest, NoKey) { |
366 const WebmEncryptedData& frame = kWebmEncryptedFrames[0]; | 366 const WebmEncryptedData& frame = kWebmEncryptedFrames[0]; |
367 GenerateKeyRequest(frame.key_id, frame.key_id_size); | 367 GenerateKeyRequest(frame.key_id, frame.key_id_size); |
368 | 368 |
369 scoped_refptr<DecoderBuffer> encrypted_data = | 369 scoped_refptr<DecoderBuffer> encrypted_data = |
370 CreateWebMEncryptedBuffer(frame.encrypted_data, frame.encrypted_data_size, | 370 CreateWebMEncryptedBuffer(frame.encrypted_data, frame.encrypted_data_size, |
371 frame.key_id, frame.key_id_size); | 371 frame.key_id, frame.key_id_size); |
372 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kNoKey, IsNull())); | 372 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kNoKey, IsNull())); |
373 decryptor_.Decrypt(encrypted_data, decrypt_cb_); | 373 decryptor_.Decrypt(Decryptor::kVideo, encrypted_data, decrypt_cb_); |
374 } | 374 } |
375 | 375 |
376 TEST_F(AesDecryptorTest, KeyReplacement) { | 376 TEST_F(AesDecryptorTest, KeyReplacement) { |
377 const WebmEncryptedData& frame = kWebmEncryptedFrames[0]; | 377 const WebmEncryptedData& frame = kWebmEncryptedFrames[0]; |
378 GenerateKeyRequest(frame.key_id, frame.key_id_size); | 378 GenerateKeyRequest(frame.key_id, frame.key_id_size); |
379 | 379 |
380 // Change the first byte of the key. | 380 // Change the first byte of the key. |
381 std::vector<uint8> wrong_key(frame.key, frame.key + frame.key_size); | 381 std::vector<uint8> wrong_key(frame.key, frame.key + frame.key_size); |
382 wrong_key[0]++; | 382 wrong_key[0]++; |
383 | 383 |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 scoped_refptr<DecoderBuffer> encrypted_data = CreateSubsampleEncryptedBuffer( | 582 scoped_refptr<DecoderBuffer> encrypted_data = CreateSubsampleEncryptedBuffer( |
583 kSubsampleData, arraysize(kSubsampleData), | 583 kSubsampleData, arraysize(kSubsampleData), |
584 kSubsampleKeyId, arraysize(kSubsampleKeyId), | 584 kSubsampleKeyId, arraysize(kSubsampleKeyId), |
585 kSubsampleIv, arraysize(kSubsampleIv), | 585 kSubsampleIv, arraysize(kSubsampleIv), |
586 0, | 586 0, |
587 entries); | 587 entries); |
588 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail(encrypted_data)); | 588 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail(encrypted_data)); |
589 } | 589 } |
590 | 590 |
591 } // namespace media | 591 } // namespace media |
OLD | NEW |