Chromium Code Reviews| 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" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "media/base/cdm_callback_promise.h" | 12 #include "media/base/cdm_callback_promise.h" |
| 13 #include "media/base/cdm_key_information.h" | |
| 13 #include "media/base/decoder_buffer.h" | 14 #include "media/base/decoder_buffer.h" |
| 14 #include "media/base/decrypt_config.h" | 15 #include "media/base/decrypt_config.h" |
| 15 #include "media/base/mock_filters.h" | 16 #include "media/base/mock_filters.h" |
| 16 #include "media/cdm/aes_decryptor.h" | 17 #include "media/cdm/aes_decryptor.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 20 |
| 20 using ::testing::_; | 21 using ::testing::_; |
| 21 using ::testing::Gt; | 22 using ::testing::Gt; |
| 22 using ::testing::IsNull; | 23 using ::testing::IsNull; |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 } | 310 } |
| 310 | 311 |
| 311 // Updates the session specified by |session_id| with |key|. |result| | 312 // Updates the session specified by |session_id| with |key|. |result| |
| 312 // tests that the update succeeds or generates an error. | 313 // tests that the update succeeds or generates an error. |
| 313 void UpdateSessionAndExpect(std::string session_id, | 314 void UpdateSessionAndExpect(std::string session_id, |
| 314 const std::string& key, | 315 const std::string& key, |
| 315 PromiseResult expected_result) { | 316 PromiseResult expected_result) { |
| 316 DCHECK(!key.empty()); | 317 DCHECK(!key.empty()); |
| 317 | 318 |
| 318 if (expected_result == RESOLVED) { | 319 if (expected_result == RESOLVED) { |
| 319 EXPECT_CALL(*this, OnSessionKeysChange(session_id, true)); | 320 EXPECT_CALL(*this, OnSessionKeysChange(session_id, true, _)) |
| 321 .WillOnce(SaveArg<2>(&useable_key_ids_)); | |
| 320 } else { | 322 } else { |
| 321 EXPECT_CALL(*this, OnSessionKeysChange(_, _)).Times(0); | 323 EXPECT_CALL(*this, OnSessionKeysChange(_, _, _)).Times(0); |
| 322 } | 324 } |
| 323 | 325 |
| 324 decryptor_.UpdateSession(session_id, | 326 decryptor_.UpdateSession(session_id, |
| 325 reinterpret_cast<const uint8*>(key.c_str()), | 327 reinterpret_cast<const uint8*>(key.c_str()), |
| 326 key.length(), | 328 key.length(), |
| 327 CreatePromise(expected_result)); | 329 CreatePromise(expected_result)); |
| 328 } | 330 } |
| 329 | 331 |
| 332 bool UsableKeyIdsContains(std::vector<uint8> expected) { | |
| 333 for (const auto& key_id : useable_key_ids_) { | |
| 334 if (key_id.KeyId() == expected) | |
| 335 return true; | |
| 336 } | |
| 337 return false; | |
| 338 } | |
| 339 | |
| 330 MOCK_METHOD2(BufferDecrypted, void(Decryptor::Status, | 340 MOCK_METHOD2(BufferDecrypted, void(Decryptor::Status, |
| 331 const scoped_refptr<DecoderBuffer>&)); | 341 const scoped_refptr<DecoderBuffer>&)); |
| 332 | 342 |
| 333 enum DecryptExpectation { | 343 enum DecryptExpectation { |
| 334 SUCCESS, | 344 SUCCESS, |
| 335 DATA_MISMATCH, | 345 DATA_MISMATCH, |
| 336 DATA_AND_SIZE_MISMATCH, | 346 DATA_AND_SIZE_MISMATCH, |
| 337 DECRYPT_ERROR, | 347 DECRYPT_ERROR, |
| 338 NO_KEY | 348 NO_KEY |
| 339 }; | 349 }; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 383 case NO_KEY: | 393 case NO_KEY: |
| 384 EXPECT_TRUE(decrypted_text.empty()); | 394 EXPECT_TRUE(decrypted_text.empty()); |
| 385 break; | 395 break; |
| 386 } | 396 } |
| 387 } | 397 } |
| 388 | 398 |
| 389 MOCK_METHOD3(OnSessionMessage, | 399 MOCK_METHOD3(OnSessionMessage, |
| 390 void(const std::string& web_session_id, | 400 void(const std::string& web_session_id, |
| 391 const std::vector<uint8>& message, | 401 const std::vector<uint8>& message, |
| 392 const GURL& destination_url)); | 402 const GURL& destination_url)); |
| 393 MOCK_METHOD2(OnSessionKeysChange, | 403 MOCK_METHOD3(OnSessionKeysChange, |
| 394 void(const std::string& web_session_id, | 404 void(const std::string& web_session_id, |
| 395 bool has_additional_usable_key)); | 405 bool has_additional_usable_key, |
| 406 const CdmKeyInformationVector& key_information)); | |
| 396 MOCK_METHOD1(OnSessionClosed, void(const std::string& web_session_id)); | 407 MOCK_METHOD1(OnSessionClosed, void(const std::string& web_session_id)); |
| 397 | 408 |
| 398 AesDecryptor decryptor_; | 409 AesDecryptor decryptor_; |
| 399 AesDecryptor::DecryptCB decrypt_cb_; | 410 AesDecryptor::DecryptCB decrypt_cb_; |
| 400 std::string web_session_id_; | 411 std::string web_session_id_; |
| 412 CdmKeyInformationVector useable_key_ids_; | |
|
xhwang
2015/01/02 21:55:07
s/useable/usable?
In chromium, usable is used 191
jrummell
2015/01/05 22:17:59
Done.
| |
| 401 | 413 |
| 402 // Constants for testing. | 414 // Constants for testing. |
| 403 const std::vector<uint8> original_data_; | 415 const std::vector<uint8> original_data_; |
| 404 const std::vector<uint8> encrypted_data_; | 416 const std::vector<uint8> encrypted_data_; |
| 405 const std::vector<uint8> subsample_encrypted_data_; | 417 const std::vector<uint8> subsample_encrypted_data_; |
| 406 const std::vector<uint8> key_id_; | 418 const std::vector<uint8> key_id_; |
| 407 const std::vector<uint8> iv_; | 419 const std::vector<uint8> iv_; |
| 408 const std::vector<SubsampleEntry> normal_subsample_entries_; | 420 const std::vector<SubsampleEntry> normal_subsample_entries_; |
| 409 const std::vector<SubsampleEntry> no_subsample_entries_; | 421 const std::vector<SubsampleEntry> no_subsample_entries_; |
| 410 }; | 422 }; |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 842 " \"alg\": \"A128KW\"," | 854 " \"alg\": \"A128KW\"," |
| 843 " \"kid\": \"\"," | 855 " \"kid\": \"\"," |
| 844 " \"k\": \"BAUGBwgJCgsMDQ4PEBESEw\"" | 856 " \"k\": \"BAUGBwgJCgsMDQ4PEBESEw\"" |
| 845 " }" | 857 " }" |
| 846 " ]" | 858 " ]" |
| 847 "}"; | 859 "}"; |
| 848 UpdateSessionAndExpect(session_id, kJwksWithEmptyKeyId, REJECTED); | 860 UpdateSessionAndExpect(session_id, kJwksWithEmptyKeyId, REJECTED); |
| 849 CloseSession(session_id); | 861 CloseSession(session_id); |
| 850 } | 862 } |
| 851 | 863 |
| 864 TEST_F(AesDecryptorTest, GetKeyIds) { | |
| 865 std::vector<uint8> key_id1(kKeyId, kKeyId + arraysize(kKeyId)); | |
| 866 std::vector<uint8> key_id2(kKeyId2, kKeyId2 + arraysize(kKeyId2)); | |
| 867 | |
| 868 std::string session_id = CreateSession(key_id_); | |
| 869 EXPECT_FALSE(UsableKeyIdsContains(key_id1)); | |
| 870 EXPECT_FALSE(UsableKeyIdsContains(key_id2)); | |
| 871 | |
| 872 // Add 1 key, verify it is returned. | |
| 873 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED); | |
| 874 EXPECT_TRUE(UsableKeyIdsContains(key_id1)); | |
| 875 EXPECT_FALSE(UsableKeyIdsContains(key_id2)); | |
| 876 | |
| 877 // Add second key, verify both IDs returned. | |
| 878 UpdateSessionAndExpect(session_id, kKey2AsJWK, RESOLVED); | |
| 879 EXPECT_TRUE(UsableKeyIdsContains(key_id1)); | |
| 880 EXPECT_TRUE(UsableKeyIdsContains(key_id2)); | |
| 881 } | |
| 882 | |
| 852 } // namespace media | 883 } // namespace media |
| OLD | NEW |