Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: media/cdm/aes_decryptor_unittest.cc

Issue 1407933010: media: Make MediaKeys ref-counted. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase only Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/cdm/aes_decryptor.h ('k') | media/cdm/default_cdm_factory.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 encrypted_buffer->set_decrypt_config(scoped_ptr<DecryptConfig>( 207 encrypted_buffer->set_decrypt_config(scoped_ptr<DecryptConfig>(
208 new DecryptConfig(key_id_string, iv_string, subsample_entries))); 208 new DecryptConfig(key_id_string, iv_string, subsample_entries)));
209 return encrypted_buffer; 209 return encrypted_buffer;
210 } 210 }
211 211
212 enum PromiseResult { RESOLVED, REJECTED }; 212 enum PromiseResult { RESOLVED, REJECTED };
213 213
214 class AesDecryptorTest : public testing::Test { 214 class AesDecryptorTest : public testing::Test {
215 public: 215 public:
216 AesDecryptorTest() 216 AesDecryptorTest()
217 : decryptor_(GURL::EmptyGURL(), 217 : decryptor_(
218 base::Bind(&AesDecryptorTest::OnSessionMessage, 218 new AesDecryptor(GURL::EmptyGURL(),
219 base::Unretained(this)), 219 base::Bind(&AesDecryptorTest::OnSessionMessage,
220 base::Bind(&AesDecryptorTest::OnSessionClosed, 220 base::Unretained(this)),
221 base::Unretained(this)), 221 base::Bind(&AesDecryptorTest::OnSessionClosed,
222 base::Bind(&AesDecryptorTest::OnSessionKeysChange, 222 base::Unretained(this)),
223 base::Unretained(this))), 223 base::Bind(&AesDecryptorTest::OnSessionKeysChange,
224 base::Unretained(this)))),
224 decrypt_cb_(base::Bind(&AesDecryptorTest::BufferDecrypted, 225 decrypt_cb_(base::Bind(&AesDecryptorTest::BufferDecrypted,
225 base::Unretained(this))), 226 base::Unretained(this))),
226 original_data_(kOriginalData, kOriginalData + kOriginalDataSize), 227 original_data_(kOriginalData, kOriginalData + kOriginalDataSize),
227 encrypted_data_(kEncryptedData, 228 encrypted_data_(kEncryptedData,
228 kEncryptedData + arraysize(kEncryptedData)), 229 kEncryptedData + arraysize(kEncryptedData)),
229 subsample_encrypted_data_( 230 subsample_encrypted_data_(
230 kSubsampleEncryptedData, 231 kSubsampleEncryptedData,
231 kSubsampleEncryptedData + arraysize(kSubsampleEncryptedData)), 232 kSubsampleEncryptedData + arraysize(kSubsampleEncryptedData)),
232 key_id_(kKeyId, kKeyId + arraysize(kKeyId)), 233 key_id_(kKeyId, kKeyId + arraysize(kKeyId)),
233 iv_(kIv, kIv + arraysize(kIv)), 234 iv_(kIv, kIv + arraysize(kIv)),
234 normal_subsample_entries_( 235 normal_subsample_entries_(
235 kSubsampleEntriesNormal, 236 kSubsampleEntriesNormal,
236 kSubsampleEntriesNormal + arraysize(kSubsampleEntriesNormal)) { 237 kSubsampleEntriesNormal + arraysize(kSubsampleEntriesNormal)) {}
237 }
238 238
239 protected: 239 protected:
240 void OnResolveWithSession(PromiseResult expected_result, 240 void OnResolveWithSession(PromiseResult expected_result,
241 const std::string& session_id) { 241 const std::string& session_id) {
242 EXPECT_EQ(expected_result, RESOLVED) << "Unexpectedly resolved."; 242 EXPECT_EQ(expected_result, RESOLVED) << "Unexpectedly resolved.";
243 EXPECT_GT(session_id.length(), 0ul); 243 EXPECT_GT(session_id.length(), 0ul);
244 session_id_ = session_id; 244 session_id_ = session_id;
245 } 245 }
246 246
247 void OnResolve(PromiseResult expected_result) { 247 void OnResolve(PromiseResult expected_result) {
(...skipping 30 matching lines...) Expand all
278 base::Unretained(this), 278 base::Unretained(this),
279 expected_result))); 279 expected_result)));
280 return promise.Pass(); 280 return promise.Pass();
281 } 281 }
282 282
283 // Creates a new session using |key_id|. Returns the session ID. 283 // Creates a new session using |key_id|. Returns the session ID.
284 std::string CreateSession(const std::vector<uint8>& key_id) { 284 std::string CreateSession(const std::vector<uint8>& key_id) {
285 DCHECK(!key_id.empty()); 285 DCHECK(!key_id.empty());
286 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsJSONDictionary(), 286 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsJSONDictionary(),
287 GURL::EmptyGURL())); 287 GURL::EmptyGURL()));
288 decryptor_.CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION, 288 decryptor_->CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION,
289 EmeInitDataType::WEBM, key_id, 289 EmeInitDataType::WEBM, key_id,
290 CreateSessionPromise(RESOLVED)); 290 CreateSessionPromise(RESOLVED));
291 // This expects the promise to be called synchronously, which is the case 291 // This expects the promise to be called synchronously, which is the case
292 // for AesDecryptor. 292 // for AesDecryptor.
293 return session_id_; 293 return session_id_;
294 } 294 }
295 295
296 // Closes the session specified by |session_id|. 296 // Closes the session specified by |session_id|.
297 void CloseSession(const std::string& session_id) { 297 void CloseSession(const std::string& session_id) {
298 EXPECT_CALL(*this, OnSessionClosed(session_id)); 298 EXPECT_CALL(*this, OnSessionClosed(session_id));
299 decryptor_.CloseSession(session_id, CreatePromise(RESOLVED)); 299 decryptor_->CloseSession(session_id, CreatePromise(RESOLVED));
300 } 300 }
301 301
302 // Removes the session specified by |session_id|. This should simply do a 302 // Removes the session specified by |session_id|. This should simply do a
303 // CloseSession(). 303 // CloseSession().
304 // TODO(jrummell): Clean this up when the prefixed API is removed. 304 // TODO(jrummell): Clean this up when the prefixed API is removed.
305 // http://crbug.com/249976. 305 // http://crbug.com/249976.
306 void RemoveSession(const std::string& session_id) { 306 void RemoveSession(const std::string& session_id) {
307 EXPECT_CALL(*this, OnSessionClosed(session_id)); 307 EXPECT_CALL(*this, OnSessionClosed(session_id));
308 decryptor_.RemoveSession(session_id, CreatePromise(RESOLVED)); 308 decryptor_->RemoveSession(session_id, CreatePromise(RESOLVED));
309 } 309 }
310 310
311 MOCK_METHOD2(OnSessionKeysChangeCalled, 311 MOCK_METHOD2(OnSessionKeysChangeCalled,
312 void(const std::string& session_id, 312 void(const std::string& session_id,
313 bool has_additional_usable_key)); 313 bool has_additional_usable_key));
314 314
315 void OnSessionKeysChange(const std::string& session_id, 315 void OnSessionKeysChange(const std::string& session_id,
316 bool has_additional_usable_key, 316 bool has_additional_usable_key,
317 CdmKeysInfo keys_info) { 317 CdmKeysInfo keys_info) {
318 keys_info_.swap(keys_info); 318 keys_info_.swap(keys_info);
319 OnSessionKeysChangeCalled(session_id, has_additional_usable_key); 319 OnSessionKeysChangeCalled(session_id, has_additional_usable_key);
320 } 320 }
321 321
322 // Updates the session specified by |session_id| with |key|. |result| 322 // Updates the session specified by |session_id| with |key|. |result|
323 // tests that the update succeeds or generates an error. 323 // tests that the update succeeds or generates an error.
324 void UpdateSessionAndExpect(std::string session_id, 324 void UpdateSessionAndExpect(std::string session_id,
325 const std::string& key, 325 const std::string& key,
326 PromiseResult expected_result, 326 PromiseResult expected_result,
327 bool new_key_expected) { 327 bool new_key_expected) {
328 DCHECK(!key.empty()); 328 DCHECK(!key.empty());
329 329
330 if (expected_result == RESOLVED) { 330 if (expected_result == RESOLVED) {
331 EXPECT_CALL(*this, 331 EXPECT_CALL(*this,
332 OnSessionKeysChangeCalled(session_id, new_key_expected)); 332 OnSessionKeysChangeCalled(session_id, new_key_expected));
333 } else { 333 } else {
334 EXPECT_CALL(*this, OnSessionKeysChangeCalled(_, _)).Times(0); 334 EXPECT_CALL(*this, OnSessionKeysChangeCalled(_, _)).Times(0);
335 } 335 }
336 336
337 decryptor_.UpdateSession(session_id, 337 decryptor_->UpdateSession(session_id,
338 std::vector<uint8>(key.begin(), key.end()), 338 std::vector<uint8>(key.begin(), key.end()),
339 CreatePromise(expected_result)); 339 CreatePromise(expected_result));
340 } 340 }
341 341
342 bool KeysInfoContains(std::vector<uint8> expected) { 342 bool KeysInfoContains(std::vector<uint8> expected) {
343 for (const auto& key_id : keys_info_) { 343 for (const auto& key_id : keys_info_) {
344 if (key_id->key_id == expected) 344 if (key_id->key_id == expected)
345 return true; 345 return true;
346 } 346 }
347 return false; 347 return false;
348 } 348 }
349 349
(...skipping 23 matching lines...) Expand all
373 case DECRYPT_ERROR: 373 case DECRYPT_ERROR:
374 EXPECT_CALL(*this, BufferDecrypted(Decryptor::kError, IsNull())) 374 EXPECT_CALL(*this, BufferDecrypted(Decryptor::kError, IsNull()))
375 .WillOnce(SaveArg<1>(&decrypted)); 375 .WillOnce(SaveArg<1>(&decrypted));
376 break; 376 break;
377 case NO_KEY: 377 case NO_KEY:
378 EXPECT_CALL(*this, BufferDecrypted(Decryptor::kNoKey, IsNull())) 378 EXPECT_CALL(*this, BufferDecrypted(Decryptor::kNoKey, IsNull()))
379 .WillOnce(SaveArg<1>(&decrypted)); 379 .WillOnce(SaveArg<1>(&decrypted));
380 break; 380 break;
381 } 381 }
382 382
383 decryptor_.Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_); 383 decryptor_->Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_);
384 384
385 std::vector<uint8> decrypted_text; 385 std::vector<uint8> decrypted_text;
386 if (decrypted.get() && decrypted->data_size()) { 386 if (decrypted.get() && decrypted->data_size()) {
387 decrypted_text.assign( 387 decrypted_text.assign(
388 decrypted->data(), decrypted->data() + decrypted->data_size()); 388 decrypted->data(), decrypted->data() + decrypted->data_size());
389 } 389 }
390 390
391 switch (result) { 391 switch (result) {
392 case SUCCESS: 392 case SUCCESS:
393 EXPECT_EQ(plain_text, decrypted_text); 393 EXPECT_EQ(plain_text, decrypted_text);
(...skipping 12 matching lines...) Expand all
406 } 406 }
407 } 407 }
408 408
409 MOCK_METHOD4(OnSessionMessage, 409 MOCK_METHOD4(OnSessionMessage,
410 void(const std::string& session_id, 410 void(const std::string& session_id,
411 MediaKeys::MessageType message_type, 411 MediaKeys::MessageType message_type,
412 const std::vector<uint8>& message, 412 const std::vector<uint8>& message,
413 const GURL& legacy_destination_url)); 413 const GURL& legacy_destination_url));
414 MOCK_METHOD1(OnSessionClosed, void(const std::string& session_id)); 414 MOCK_METHOD1(OnSessionClosed, void(const std::string& session_id));
415 415
416 AesDecryptor decryptor_; 416 scoped_refptr<AesDecryptor> decryptor_;
417 AesDecryptor::DecryptCB decrypt_cb_; 417 AesDecryptor::DecryptCB decrypt_cb_;
418 std::string session_id_; 418 std::string session_id_;
419 CdmKeysInfo keys_info_; 419 CdmKeysInfo keys_info_;
420 420
421 // Constants for testing. 421 // Constants for testing.
422 const std::vector<uint8> original_data_; 422 const std::vector<uint8> original_data_;
423 const std::vector<uint8> encrypted_data_; 423 const std::vector<uint8> encrypted_data_;
424 const std::vector<uint8> subsample_encrypted_data_; 424 const std::vector<uint8> subsample_encrypted_data_;
425 const std::vector<uint8> key_id_; 425 const std::vector<uint8> key_id_;
426 const std::vector<uint8> iv_; 426 const std::vector<uint8> iv_;
427 const std::vector<SubsampleEntry> normal_subsample_entries_; 427 const std::vector<SubsampleEntry> normal_subsample_entries_;
428 const std::vector<SubsampleEntry> no_subsample_entries_; 428 const std::vector<SubsampleEntry> no_subsample_entries_;
429 }; 429 };
430 430
431 TEST_F(AesDecryptorTest, CreateSessionWithNullInitData) { 431 TEST_F(AesDecryptorTest, CreateSessionWithNullInitData) {
432 EXPECT_CALL(*this, 432 EXPECT_CALL(*this,
433 OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL())); 433 OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL()));
434 decryptor_.CreateSessionAndGenerateRequest( 434 decryptor_->CreateSessionAndGenerateRequest(
435 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, std::vector<uint8>(), 435 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, std::vector<uint8>(),
436 CreateSessionPromise(RESOLVED)); 436 CreateSessionPromise(RESOLVED));
437 } 437 }
438 438
439 TEST_F(AesDecryptorTest, MultipleCreateSession) { 439 TEST_F(AesDecryptorTest, MultipleCreateSession) {
440 EXPECT_CALL(*this, 440 EXPECT_CALL(*this,
441 OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL())); 441 OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL()));
442 decryptor_.CreateSessionAndGenerateRequest( 442 decryptor_->CreateSessionAndGenerateRequest(
443 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, std::vector<uint8>(), 443 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, std::vector<uint8>(),
444 CreateSessionPromise(RESOLVED)); 444 CreateSessionPromise(RESOLVED));
445 445
446 EXPECT_CALL(*this, 446 EXPECT_CALL(*this,
447 OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL())); 447 OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL()));
448 decryptor_.CreateSessionAndGenerateRequest( 448 decryptor_->CreateSessionAndGenerateRequest(
449 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, std::vector<uint8>(), 449 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, std::vector<uint8>(),
450 CreateSessionPromise(RESOLVED)); 450 CreateSessionPromise(RESOLVED));
451 451
452 EXPECT_CALL(*this, 452 EXPECT_CALL(*this,
453 OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL())); 453 OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL()));
454 decryptor_.CreateSessionAndGenerateRequest( 454 decryptor_->CreateSessionAndGenerateRequest(
455 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, std::vector<uint8>(), 455 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, std::vector<uint8>(),
456 CreateSessionPromise(RESOLVED)); 456 CreateSessionPromise(RESOLVED));
457 } 457 }
458 458
459 TEST_F(AesDecryptorTest, CreateSessionWithCencInitData) { 459 TEST_F(AesDecryptorTest, CreateSessionWithCencInitData) {
460 const uint8 init_data[] = { 460 const uint8 init_data[] = {
461 0x00, 0x00, 0x00, 0x44, // size = 68 461 0x00, 0x00, 0x00, 0x44, // size = 68
462 0x70, 0x73, 0x73, 0x68, // 'pssh' 462 0x70, 0x73, 0x73, 0x68, // 'pssh'
463 0x01, // version 463 0x01, // version
464 0x00, 0x00, 0x00, // flags 464 0x00, 0x00, 0x00, // flags
465 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID 465 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID
466 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B, 466 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B,
467 0x00, 0x00, 0x00, 0x02, // key count 467 0x00, 0x00, 0x00, 0x02, // key count
468 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1 468 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1
469 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, 469 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03,
470 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, // key2 470 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, // key2
471 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, 471 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04,
472 0x00, 0x00, 0x00, 0x00 // datasize 472 0x00, 0x00, 0x00, 0x00 // datasize
473 }; 473 };
474 #if defined(USE_PROPRIETARY_CODECS) 474 #if defined(USE_PROPRIETARY_CODECS)
475 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsJSONDictionary(), 475 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsJSONDictionary(),
476 GURL::EmptyGURL())); 476 GURL::EmptyGURL()));
477 decryptor_.CreateSessionAndGenerateRequest( 477 decryptor_->CreateSessionAndGenerateRequest(
478 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::CENC, 478 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::CENC,
479 std::vector<uint8>(init_data, init_data + arraysize(init_data)), 479 std::vector<uint8>(init_data, init_data + arraysize(init_data)),
480 CreateSessionPromise(RESOLVED)); 480 CreateSessionPromise(RESOLVED));
481 #else 481 #else
482 decryptor_.CreateSessionAndGenerateRequest( 482 decryptor_->CreateSessionAndGenerateRequest(
483 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::CENC, 483 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::CENC,
484 std::vector<uint8>(init_data, init_data + arraysize(init_data)), 484 std::vector<uint8>(init_data, init_data + arraysize(init_data)),
485 CreateSessionPromise(REJECTED)); 485 CreateSessionPromise(REJECTED));
486 #endif 486 #endif
487 } 487 }
488 488
489 TEST_F(AesDecryptorTest, CreateSessionWithKeyIdsInitData) { 489 TEST_F(AesDecryptorTest, CreateSessionWithKeyIdsInitData) {
490 const char init_data[] = 490 const char init_data[] =
491 "{\"kids\":[\"AQI\",\"AQIDBA\",\"AQIDBAUGBwgJCgsMDQ4PEA\"]}"; 491 "{\"kids\":[\"AQI\",\"AQIDBA\",\"AQIDBAUGBwgJCgsMDQ4PEA\"]}";
492 492
493 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsJSONDictionary(), 493 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsJSONDictionary(),
494 GURL::EmptyGURL())); 494 GURL::EmptyGURL()));
495 decryptor_.CreateSessionAndGenerateRequest( 495 decryptor_->CreateSessionAndGenerateRequest(
496 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::KEYIDS, 496 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::KEYIDS,
497 std::vector<uint8>(init_data, init_data + arraysize(init_data) - 1), 497 std::vector<uint8>(init_data, init_data + arraysize(init_data) - 1),
498 CreateSessionPromise(RESOLVED)); 498 CreateSessionPromise(RESOLVED));
499 } 499 }
500 500
501 TEST_F(AesDecryptorTest, NormalDecryption) { 501 TEST_F(AesDecryptorTest, NormalDecryption) {
502 std::string session_id = CreateSession(key_id_); 502 std::string session_id = CreateSession(key_id_);
503 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED, true); 503 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED, true);
504 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer( 504 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
505 encrypted_data_, key_id_, iv_, no_subsample_entries_); 505 encrypted_data_, key_id_, iv_, no_subsample_entries_);
(...skipping 12 matching lines...) Expand all
518 UpdateSessionAndExpect(session_id, kWrongKeyAsJWK, RESOLVED, true); 518 UpdateSessionAndExpect(session_id, kWrongKeyAsJWK, RESOLVED, true);
519 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer( 519 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
520 encrypted_data_, key_id_, iv_, no_subsample_entries_); 520 encrypted_data_, key_id_, iv_, no_subsample_entries_);
521 DecryptAndExpect(encrypted_buffer, original_data_, DATA_MISMATCH); 521 DecryptAndExpect(encrypted_buffer, original_data_, DATA_MISMATCH);
522 } 522 }
523 523
524 TEST_F(AesDecryptorTest, NoKey) { 524 TEST_F(AesDecryptorTest, NoKey) {
525 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer( 525 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
526 encrypted_data_, key_id_, iv_, no_subsample_entries_); 526 encrypted_data_, key_id_, iv_, no_subsample_entries_);
527 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kNoKey, IsNull())); 527 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kNoKey, IsNull()));
528 decryptor_.Decrypt(Decryptor::kVideo, encrypted_buffer, decrypt_cb_); 528 decryptor_->Decrypt(Decryptor::kVideo, encrypted_buffer, decrypt_cb_);
529 } 529 }
530 530
531 TEST_F(AesDecryptorTest, KeyReplacement) { 531 TEST_F(AesDecryptorTest, KeyReplacement) {
532 std::string session_id = CreateSession(key_id_); 532 std::string session_id = CreateSession(key_id_);
533 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer( 533 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
534 encrypted_data_, key_id_, iv_, no_subsample_entries_); 534 encrypted_data_, key_id_, iv_, no_subsample_entries_);
535 535
536 UpdateSessionAndExpect(session_id, kWrongKeyAsJWK, RESOLVED, true); 536 UpdateSessionAndExpect(session_id, kWrongKeyAsJWK, RESOLVED, true);
537 ASSERT_NO_FATAL_FAILURE(DecryptAndExpect( 537 ASSERT_NO_FATAL_FAILURE(DecryptAndExpect(
538 encrypted_buffer, original_data_, DATA_MISMATCH)); 538 encrypted_buffer, original_data_, DATA_MISMATCH));
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 // Add key a second time. 936 // Add key a second time.
937 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED, false); 937 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED, false);
938 EXPECT_TRUE(KeysInfoContains(key_id)); 938 EXPECT_TRUE(KeysInfoContains(key_id));
939 939
940 // Create a new session. Add key, should indicate key added for this session. 940 // Create a new session. Add key, should indicate key added for this session.
941 std::string session_id2 = CreateSession(key_id_); 941 std::string session_id2 = CreateSession(key_id_);
942 UpdateSessionAndExpect(session_id2, kKeyAsJWK, RESOLVED, true); 942 UpdateSessionAndExpect(session_id2, kKeyAsJWK, RESOLVED, true);
943 } 943 }
944 944
945 } // namespace media 945 } // namespace media
OLDNEW
« no previous file with comments | « media/cdm/aes_decryptor.h ('k') | media/cdm/default_cdm_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698