| OLD | NEW |
| 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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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( | 288 decryptor_.CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION, |
| 289 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, &key_id[0], | 289 EmeInitDataType::WEBM, key_id, |
| 290 key_id.size(), 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 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 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 reinterpret_cast<const uint8*>(key.c_str()), | 338 std::vector<uint8>(key.begin(), key.end()), |
| 339 key.length(), | |
| 340 CreatePromise(expected_result)); | 339 CreatePromise(expected_result)); |
| 341 } | 340 } |
| 342 | 341 |
| 343 bool KeysInfoContains(std::vector<uint8> expected) { | 342 bool KeysInfoContains(std::vector<uint8> expected) { |
| 344 for (const auto& key_id : keys_info_) { | 343 for (const auto& key_id : keys_info_) { |
| 345 if (key_id->key_id == expected) | 344 if (key_id->key_id == expected) |
| 346 return true; | 345 return true; |
| 347 } | 346 } |
| 348 return false; | 347 return false; |
| 349 } | 348 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 const std::vector<uint8> subsample_encrypted_data_; | 424 const std::vector<uint8> subsample_encrypted_data_; |
| 426 const std::vector<uint8> key_id_; | 425 const std::vector<uint8> key_id_; |
| 427 const std::vector<uint8> iv_; | 426 const std::vector<uint8> iv_; |
| 428 const std::vector<SubsampleEntry> normal_subsample_entries_; | 427 const std::vector<SubsampleEntry> normal_subsample_entries_; |
| 429 const std::vector<SubsampleEntry> no_subsample_entries_; | 428 const std::vector<SubsampleEntry> no_subsample_entries_; |
| 430 }; | 429 }; |
| 431 | 430 |
| 432 TEST_F(AesDecryptorTest, CreateSessionWithNullInitData) { | 431 TEST_F(AesDecryptorTest, CreateSessionWithNullInitData) { |
| 433 EXPECT_CALL(*this, | 432 EXPECT_CALL(*this, |
| 434 OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL())); | 433 OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL())); |
| 435 decryptor_.CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION, | 434 decryptor_.CreateSessionAndGenerateRequest( |
| 436 EmeInitDataType::WEBM, NULL, 0, | 435 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, std::vector<uint8>(), |
| 437 CreateSessionPromise(RESOLVED)); | 436 CreateSessionPromise(RESOLVED)); |
| 438 } | 437 } |
| 439 | 438 |
| 440 TEST_F(AesDecryptorTest, MultipleCreateSession) { | 439 TEST_F(AesDecryptorTest, MultipleCreateSession) { |
| 441 EXPECT_CALL(*this, | 440 EXPECT_CALL(*this, |
| 442 OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL())); | 441 OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL())); |
| 443 decryptor_.CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION, | 442 decryptor_.CreateSessionAndGenerateRequest( |
| 444 EmeInitDataType::WEBM, NULL, 0, | 443 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, std::vector<uint8>(), |
| 445 CreateSessionPromise(RESOLVED)); | 444 CreateSessionPromise(RESOLVED)); |
| 446 | 445 |
| 447 EXPECT_CALL(*this, | 446 EXPECT_CALL(*this, |
| 448 OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL())); | 447 OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL())); |
| 449 decryptor_.CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION, | 448 decryptor_.CreateSessionAndGenerateRequest( |
| 450 EmeInitDataType::WEBM, NULL, 0, | 449 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, std::vector<uint8>(), |
| 451 CreateSessionPromise(RESOLVED)); | 450 CreateSessionPromise(RESOLVED)); |
| 452 | 451 |
| 453 EXPECT_CALL(*this, | 452 EXPECT_CALL(*this, |
| 454 OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL())); | 453 OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL())); |
| 455 decryptor_.CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION, | 454 decryptor_.CreateSessionAndGenerateRequest( |
| 456 EmeInitDataType::WEBM, NULL, 0, | 455 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, std::vector<uint8>(), |
| 457 CreateSessionPromise(RESOLVED)); | 456 CreateSessionPromise(RESOLVED)); |
| 458 } | 457 } |
| 459 | 458 |
| 460 TEST_F(AesDecryptorTest, CreateSessionWithCencInitData) { | 459 TEST_F(AesDecryptorTest, CreateSessionWithCencInitData) { |
| 461 const uint8 init_data[] = { | 460 const uint8 init_data[] = { |
| 462 0x00, 0x00, 0x00, 0x44, // size = 68 | 461 0x00, 0x00, 0x00, 0x44, // size = 68 |
| 463 0x70, 0x73, 0x73, 0x68, // 'pssh' | 462 0x70, 0x73, 0x73, 0x68, // 'pssh' |
| 464 0x01, // version | 463 0x01, // version |
| 465 0x00, 0x00, 0x00, // flags | 464 0x00, 0x00, 0x00, // flags |
| 466 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID | 465 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID |
| 467 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B, | 466 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B, |
| 468 0x00, 0x00, 0x00, 0x02, // key count | 467 0x00, 0x00, 0x00, 0x02, // key count |
| 469 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1 | 468 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1 |
| 470 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, | 469 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, |
| 471 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, // key2 | 470 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, // key2 |
| 472 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, | 471 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, |
| 473 0x00, 0x00, 0x00, 0x00 // datasize | 472 0x00, 0x00, 0x00, 0x00 // datasize |
| 474 }; | 473 }; |
| 475 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsJSONDictionary(), | 474 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsJSONDictionary(), |
| 476 GURL::EmptyGURL())); | 475 GURL::EmptyGURL())); |
| 477 decryptor_.CreateSessionAndGenerateRequest( | 476 decryptor_.CreateSessionAndGenerateRequest( |
| 478 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::CENC, init_data, | 477 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::CENC, |
| 479 arraysize(init_data), CreateSessionPromise(RESOLVED)); | 478 std::vector<uint8>(init_data, init_data + arraysize(init_data)), |
| 479 CreateSessionPromise(RESOLVED)); |
| 480 } | 480 } |
| 481 | 481 |
| 482 TEST_F(AesDecryptorTest, CreateSessionWithKeyIdsInitData) { | 482 TEST_F(AesDecryptorTest, CreateSessionWithKeyIdsInitData) { |
| 483 const char init_data[] = | 483 const char init_data[] = |
| 484 "{\"kids\":[\"AQI\",\"AQIDBA\",\"AQIDBAUGBwgJCgsMDQ4PEA\"]}"; | 484 "{\"kids\":[\"AQI\",\"AQIDBA\",\"AQIDBAUGBwgJCgsMDQ4PEA\"]}"; |
| 485 | 485 |
| 486 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsJSONDictionary(), | 486 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsJSONDictionary(), |
| 487 GURL::EmptyGURL())); | 487 GURL::EmptyGURL())); |
| 488 decryptor_.CreateSessionAndGenerateRequest( | 488 decryptor_.CreateSessionAndGenerateRequest( |
| 489 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::KEYIDS, | 489 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::KEYIDS, |
| 490 reinterpret_cast<const uint8*>(init_data), arraysize(init_data) - 1, | 490 std::vector<uint8>(init_data, init_data + arraysize(init_data) - 1), |
| 491 CreateSessionPromise(RESOLVED)); | 491 CreateSessionPromise(RESOLVED)); |
| 492 } | 492 } |
| 493 | 493 |
| 494 TEST_F(AesDecryptorTest, NormalDecryption) { | 494 TEST_F(AesDecryptorTest, NormalDecryption) { |
| 495 std::string session_id = CreateSession(key_id_); | 495 std::string session_id = CreateSession(key_id_); |
| 496 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED, true); | 496 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED, true); |
| 497 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer( | 497 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer( |
| 498 encrypted_data_, key_id_, iv_, no_subsample_entries_); | 498 encrypted_data_, key_id_, iv_, no_subsample_entries_); |
| 499 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS); | 499 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS); |
| 500 } | 500 } |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 // Add key a second time. | 929 // Add key a second time. |
| 930 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED, false); | 930 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED, false); |
| 931 EXPECT_TRUE(KeysInfoContains(key_id)); | 931 EXPECT_TRUE(KeysInfoContains(key_id)); |
| 932 | 932 |
| 933 // Create a new session. Add key, should indicate key added for this session. | 933 // Create a new session. Add key, should indicate key added for this session. |
| 934 std::string session_id2 = CreateSession(key_id_); | 934 std::string session_id2 = CreateSession(key_id_); |
| 935 UpdateSessionAndExpect(session_id2, kKeyAsJWK, RESOLVED, true); | 935 UpdateSessionAndExpect(session_id2, kKeyAsJWK, RESOLVED, true); |
| 936 } | 936 } |
| 937 | 937 |
| 938 } // namespace media | 938 } // namespace media |
| OLD | NEW |