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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 std::string(reinterpret_cast<const char*>(key_id), key_id_size), | 220 std::string(reinterpret_cast<const char*>(key_id), key_id_size), |
221 std::string(reinterpret_cast<const char*>(iv), iv_size), | 221 std::string(reinterpret_cast<const char*>(iv), iv_size), |
222 data_offset, | 222 data_offset, |
223 subsample_entries))); | 223 subsample_entries))); |
224 return encrypted_buffer; | 224 return encrypted_buffer; |
225 } | 225 } |
226 | 226 |
227 class AesDecryptorTest : public testing::Test { | 227 class AesDecryptorTest : public testing::Test { |
228 public: | 228 public: |
229 AesDecryptorTest() | 229 AesDecryptorTest() |
230 : decryptor_(&client_), | 230 : decryptor_( |
| 231 base::Bind(&AesDecryptorTest::KeyAdded, base::Unretained(this)), |
| 232 base::Bind(&AesDecryptorTest::KeyError, base::Unretained(this)), |
| 233 base::Bind(&AesDecryptorTest::KeyMessage, base::Unretained(this)), |
| 234 NeedKeyCB()), |
231 decrypt_cb_(base::Bind(&AesDecryptorTest::BufferDecrypted, | 235 decrypt_cb_(base::Bind(&AesDecryptorTest::BufferDecrypted, |
232 base::Unretained(this))), | 236 base::Unretained(this))), |
233 subsample_entries_(kSubsampleEntries, | 237 subsample_entries_(kSubsampleEntries, |
234 kSubsampleEntries + arraysize(kSubsampleEntries)) { | 238 kSubsampleEntries + arraysize(kSubsampleEntries)) { |
235 } | 239 } |
236 | 240 |
237 protected: | 241 protected: |
238 void GenerateKeyRequest(const uint8* key_id, int key_id_size) { | 242 void GenerateKeyRequest(const uint8* key_id, int key_id_size) { |
239 std::string key_id_string(reinterpret_cast<const char*>(key_id), | 243 std::string key_id_string(reinterpret_cast<const char*>(key_id), |
240 key_id_size); | 244 key_id_size); |
241 EXPECT_CALL(client_, KeyMessage(kClearKeySystem, | 245 EXPECT_CALL(*this, KeyMessage(kClearKeySystem, |
242 StrNe(""), StrEq(key_id_string), "")) | 246 StrNe(""), StrEq(key_id_string), "")) |
243 .WillOnce(SaveArg<1>(&session_id_string_)); | 247 .WillOnce(SaveArg<1>(&session_id_string_)); |
244 EXPECT_TRUE(decryptor_.GenerateKeyRequest(kClearKeySystem, "", | 248 EXPECT_TRUE(decryptor_.GenerateKeyRequest(kClearKeySystem, "", |
245 key_id, key_id_size)); | 249 key_id, key_id_size)); |
246 } | 250 } |
247 | 251 |
248 void AddKeyAndExpectToSucceed(const uint8* key_id, int key_id_size, | 252 void AddKeyAndExpectToSucceed(const uint8* key_id, int key_id_size, |
249 const uint8* key, int key_size) { | 253 const uint8* key, int key_size) { |
250 EXPECT_CALL(client_, KeyAdded(kClearKeySystem, session_id_string_)); | 254 EXPECT_CALL(*this, KeyAdded(kClearKeySystem, session_id_string_)); |
251 decryptor_.AddKey(kClearKeySystem, key, key_size, key_id, key_id_size, | 255 decryptor_.AddKey(kClearKeySystem, key, key_size, key_id, key_id_size, |
252 session_id_string_); | 256 session_id_string_); |
253 } | 257 } |
254 | 258 |
255 void AddKeyAndExpectToFail(const uint8* key_id, int key_id_size, | 259 void AddKeyAndExpectToFail(const uint8* key_id, int key_id_size, |
256 const uint8* key, int key_size) { | 260 const uint8* key, int key_size) { |
257 EXPECT_CALL(client_, KeyError(kClearKeySystem, session_id_string_, | 261 EXPECT_CALL(*this, KeyError(kClearKeySystem, session_id_string_, |
258 Decryptor::kUnknownError, 0)); | 262 Decryptor::kUnknownError, 0)); |
259 decryptor_.AddKey(kClearKeySystem, key, key_size, key_id, key_id_size, | 263 decryptor_.AddKey(kClearKeySystem, key, key_size, key_id, key_id_size, |
260 session_id_string_); | 264 session_id_string_); |
261 } | 265 } |
262 | 266 |
263 MOCK_METHOD2(BufferDecrypted, void(Decryptor::Status, | 267 MOCK_METHOD2(BufferDecrypted, void(Decryptor::Status, |
264 const scoped_refptr<DecoderBuffer>&)); | 268 const scoped_refptr<DecoderBuffer>&)); |
265 | 269 |
266 void DecryptAndExpectToSucceed(const scoped_refptr<DecoderBuffer>& encrypted, | 270 void DecryptAndExpectToSucceed(const scoped_refptr<DecoderBuffer>& encrypted, |
267 const uint8* plain_text, int plain_text_size) { | 271 const uint8* plain_text, int plain_text_size) { |
268 scoped_refptr<DecoderBuffer> decrypted; | 272 scoped_refptr<DecoderBuffer> decrypted; |
(...skipping 30 matching lines...) Expand all Loading... |
299 ASSERT_TRUE(decrypted); | 303 ASSERT_TRUE(decrypted); |
300 EXPECT_NE(plain_text_size, decrypted->GetDataSize()); | 304 EXPECT_NE(plain_text_size, decrypted->GetDataSize()); |
301 EXPECT_NE(0, memcmp(plain_text, decrypted->GetData(), plain_text_size)); | 305 EXPECT_NE(0, memcmp(plain_text, decrypted->GetData(), plain_text_size)); |
302 } | 306 } |
303 | 307 |
304 void DecryptAndExpectToFail(const scoped_refptr<DecoderBuffer>& encrypted) { | 308 void DecryptAndExpectToFail(const scoped_refptr<DecoderBuffer>& encrypted) { |
305 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kError, IsNull())); | 309 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kError, IsNull())); |
306 decryptor_.Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_); | 310 decryptor_.Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_); |
307 } | 311 } |
308 | 312 |
309 MockDecryptorClient client_; | 313 MOCK_METHOD2(KeyAdded, void(const std::string&, const std::string&)); |
| 314 MOCK_METHOD4(KeyError, void(const std::string&, const std::string&, |
| 315 Decryptor::KeyError, int)); |
| 316 MOCK_METHOD4(KeyMessage, void(const std::string& key_system, |
| 317 const std::string& session_id, |
| 318 const std::string& message, |
| 319 const std::string& default_url)); |
| 320 |
310 AesDecryptor decryptor_; | 321 AesDecryptor decryptor_; |
311 std::string session_id_string_; | 322 std::string session_id_string_; |
312 AesDecryptor::DecryptCB decrypt_cb_; | 323 AesDecryptor::DecryptCB decrypt_cb_; |
313 std::vector<SubsampleEntry> subsample_entries_; | 324 std::vector<SubsampleEntry> subsample_entries_; |
314 }; | 325 }; |
315 | 326 |
316 TEST_F(AesDecryptorTest, GenerateKeyRequestWithNullInitData) { | 327 TEST_F(AesDecryptorTest, GenerateKeyRequestWithNullInitData) { |
317 EXPECT_CALL(client_, KeyMessage(kClearKeySystem, StrNe(""), "", "")); | 328 EXPECT_CALL(*this, KeyMessage(kClearKeySystem, StrNe(""), "", "")); |
318 EXPECT_TRUE(decryptor_.GenerateKeyRequest(kClearKeySystem, "", NULL, 0)); | 329 EXPECT_TRUE(decryptor_.GenerateKeyRequest(kClearKeySystem, "", NULL, 0)); |
319 } | 330 } |
320 | 331 |
321 TEST_F(AesDecryptorTest, NormalWebMDecryption) { | 332 TEST_F(AesDecryptorTest, NormalWebMDecryption) { |
322 const WebmEncryptedData& frame = kWebmEncryptedFrames[0]; | 333 const WebmEncryptedData& frame = kWebmEncryptedFrames[0]; |
323 GenerateKeyRequest(frame.key_id, frame.key_id_size); | 334 GenerateKeyRequest(frame.key_id, frame.key_id_size); |
324 AddKeyAndExpectToSucceed(frame.key_id, frame.key_id_size, | 335 AddKeyAndExpectToSucceed(frame.key_id, frame.key_id_size, |
325 frame.key, frame.key_size); | 336 frame.key, frame.key_size); |
326 scoped_refptr<DecoderBuffer> encrypted_data = | 337 scoped_refptr<DecoderBuffer> encrypted_data = |
327 CreateWebMEncryptedBuffer(frame.encrypted_data, | 338 CreateWebMEncryptedBuffer(frame.encrypted_data, |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 scoped_refptr<DecoderBuffer> encrypted_data = CreateSubsampleEncryptedBuffer( | 596 scoped_refptr<DecoderBuffer> encrypted_data = CreateSubsampleEncryptedBuffer( |
586 kSubsampleData, arraysize(kSubsampleData), | 597 kSubsampleData, arraysize(kSubsampleData), |
587 kSubsampleKeyId, arraysize(kSubsampleKeyId), | 598 kSubsampleKeyId, arraysize(kSubsampleKeyId), |
588 kSubsampleIv, arraysize(kSubsampleIv), | 599 kSubsampleIv, arraysize(kSubsampleIv), |
589 0, | 600 0, |
590 entries); | 601 entries); |
591 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail(encrypted_data)); | 602 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail(encrypted_data)); |
592 } | 603 } |
593 | 604 |
594 } // namespace media | 605 } // namespace media |
OLD | NEW |