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 "media/cdm/aes_decryptor.h" | 5 #include "media/cdm/aes_decryptor.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 25 matching lines...) Expand all Loading... |
36 using ::testing::IsNull; | 36 using ::testing::IsNull; |
37 using ::testing::NotNull; | 37 using ::testing::NotNull; |
38 using ::testing::SaveArg; | 38 using ::testing::SaveArg; |
39 using ::testing::StrNe; | 39 using ::testing::StrNe; |
40 using ::testing::Unused; | 40 using ::testing::Unused; |
41 | 41 |
42 MATCHER(IsEmpty, "") { return arg.empty(); } | 42 MATCHER(IsEmpty, "") { return arg.empty(); } |
43 MATCHER(IsNotEmpty, "") { return !arg.empty(); } | 43 MATCHER(IsNotEmpty, "") { return !arg.empty(); } |
44 MATCHER(IsJSONDictionary, "") { | 44 MATCHER(IsJSONDictionary, "") { |
45 std::string result(arg.begin(), arg.end()); | 45 std::string result(arg.begin(), arg.end()); |
46 scoped_ptr<base::Value> root(base::JSONReader().ReadToValue(result)); | 46 std::unique_ptr<base::Value> root(base::JSONReader().ReadToValue(result)); |
47 return (root.get() && root->GetType() == base::Value::TYPE_DICTIONARY); | 47 return (root.get() && root->GetType() == base::Value::TYPE_DICTIONARY); |
48 } | 48 } |
49 | 49 |
50 namespace media { | 50 namespace media { |
51 | 51 |
52 const uint8_t kOriginalData[] = "Original subsample data."; | 52 const uint8_t kOriginalData[] = "Original subsample data."; |
53 const int kOriginalDataSize = 24; | 53 const int kOriginalDataSize = 24; |
54 | 54 |
55 // In the examples below, 'k'(key) has to be 16 bytes, and will always require | 55 // In the examples below, 'k'(key) has to be 16 bytes, and will always require |
56 // 2 bytes of padding. 'kid'(keyid) is variable length, and may require 0, 1, | 56 // 2 bytes of padding. 'kid'(keyid) is variable length, and may require 0, 1, |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 const std::vector<SubsampleEntry>& subsample_entries) { | 196 const std::vector<SubsampleEntry>& subsample_entries) { |
197 DCHECK(!data.empty()); | 197 DCHECK(!data.empty()); |
198 scoped_refptr<DecoderBuffer> encrypted_buffer(new DecoderBuffer(data.size())); | 198 scoped_refptr<DecoderBuffer> encrypted_buffer(new DecoderBuffer(data.size())); |
199 memcpy(encrypted_buffer->writable_data(), &data[0], data.size()); | 199 memcpy(encrypted_buffer->writable_data(), &data[0], data.size()); |
200 CHECK(encrypted_buffer.get()); | 200 CHECK(encrypted_buffer.get()); |
201 std::string key_id_string( | 201 std::string key_id_string( |
202 reinterpret_cast<const char*>(key_id.empty() ? NULL : &key_id[0]), | 202 reinterpret_cast<const char*>(key_id.empty() ? NULL : &key_id[0]), |
203 key_id.size()); | 203 key_id.size()); |
204 std::string iv_string( | 204 std::string iv_string( |
205 reinterpret_cast<const char*>(iv.empty() ? NULL : &iv[0]), iv.size()); | 205 reinterpret_cast<const char*>(iv.empty() ? NULL : &iv[0]), iv.size()); |
206 encrypted_buffer->set_decrypt_config(scoped_ptr<DecryptConfig>( | 206 encrypted_buffer->set_decrypt_config(std::unique_ptr<DecryptConfig>( |
207 new DecryptConfig(key_id_string, iv_string, subsample_entries))); | 207 new DecryptConfig(key_id_string, iv_string, subsample_entries))); |
208 return encrypted_buffer; | 208 return encrypted_buffer; |
209 } | 209 } |
210 | 210 |
211 enum ExpectedResult { RESOLVED, REJECTED }; | 211 enum ExpectedResult { RESOLVED, REJECTED }; |
212 | 212 |
213 // These tests only test decryption logic (no decoding). Parameter to this | 213 // These tests only test decryption logic (no decoding). Parameter to this |
214 // test specifies how the CDM should be loaded. | 214 // test specifies how the CDM should be loaded. |
215 // "AesDecryptor" - use AesDecryptor directly. | 215 // "AesDecryptor" - use AesDecryptor directly. |
216 // "CdmAdapter" - load ExternalClearKey using CdmAdapter. | 216 // "CdmAdapter" - load ExternalClearKey using CdmAdapter. |
(...skipping 23 matching lines...) Expand all Loading... |
240 base::Unretained(this)), | 240 base::Unretained(this)), |
241 base::Bind(&AesDecryptorTest::OnSessionClosed, | 241 base::Bind(&AesDecryptorTest::OnSessionClosed, |
242 base::Unretained(this)), | 242 base::Unretained(this)), |
243 base::Bind(&AesDecryptorTest::OnSessionKeysChange, | 243 base::Bind(&AesDecryptorTest::OnSessionKeysChange, |
244 base::Unretained(this))), | 244 base::Unretained(this))), |
245 std::string()); | 245 std::string()); |
246 } else if (GetParam() == "CdmAdapter") { | 246 } else if (GetParam() == "CdmAdapter") { |
247 CdmConfig cdm_config; // default settings of false are sufficient. | 247 CdmConfig cdm_config; // default settings of false are sufficient. |
248 | 248 |
249 helper_.reset(new ExternalClearKeyTestHelper()); | 249 helper_.reset(new ExternalClearKeyTestHelper()); |
250 scoped_ptr<CdmAllocator> allocator(new SimpleCdmAllocator()); | 250 std::unique_ptr<CdmAllocator> allocator(new SimpleCdmAllocator()); |
251 CdmAdapter::Create( | 251 CdmAdapter::Create( |
252 helper_->KeySystemName(), helper_->LibraryPath(), cdm_config, | 252 helper_->KeySystemName(), helper_->LibraryPath(), cdm_config, |
253 std::move(allocator), base::Bind(&AesDecryptorTest::CreateCdmFileIO, | 253 std::move(allocator), base::Bind(&AesDecryptorTest::CreateCdmFileIO, |
254 base::Unretained(this)), | 254 base::Unretained(this)), |
255 base::Bind(&AesDecryptorTest::OnSessionMessage, | 255 base::Bind(&AesDecryptorTest::OnSessionMessage, |
256 base::Unretained(this)), | 256 base::Unretained(this)), |
257 base::Bind(&AesDecryptorTest::OnSessionClosed, | 257 base::Bind(&AesDecryptorTest::OnSessionClosed, |
258 base::Unretained(this)), | 258 base::Unretained(this)), |
259 base::Bind(&AesDecryptorTest::OnLegacySessionError, | 259 base::Bind(&AesDecryptorTest::OnLegacySessionError, |
260 base::Unretained(this)), | 260 base::Unretained(this)), |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 } | 292 } |
293 | 293 |
294 void OnReject(ExpectedResult expected_result, | 294 void OnReject(ExpectedResult expected_result, |
295 MediaKeys::Exception exception_code, | 295 MediaKeys::Exception exception_code, |
296 uint32_t system_code, | 296 uint32_t system_code, |
297 const std::string& error_message) { | 297 const std::string& error_message) { |
298 EXPECT_EQ(expected_result, REJECTED) | 298 EXPECT_EQ(expected_result, REJECTED) |
299 << "Unexpectedly rejected with message: " << error_message; | 299 << "Unexpectedly rejected with message: " << error_message; |
300 } | 300 } |
301 | 301 |
302 scoped_ptr<SimpleCdmPromise> CreatePromise(ExpectedResult expected_result) { | 302 std::unique_ptr<SimpleCdmPromise> CreatePromise( |
303 scoped_ptr<SimpleCdmPromise> promise( | 303 ExpectedResult expected_result) { |
304 new CdmCallbackPromise<>(base::Bind(&AesDecryptorTest::OnResolve, | 304 std::unique_ptr<SimpleCdmPromise> promise(new CdmCallbackPromise<>( |
305 base::Unretained(this), | 305 base::Bind(&AesDecryptorTest::OnResolve, base::Unretained(this), |
306 expected_result), | 306 expected_result), |
307 base::Bind(&AesDecryptorTest::OnReject, | 307 base::Bind(&AesDecryptorTest::OnReject, base::Unretained(this), |
308 base::Unretained(this), | 308 expected_result))); |
309 expected_result))); | |
310 return promise; | 309 return promise; |
311 } | 310 } |
312 | 311 |
313 scoped_ptr<NewSessionCdmPromise> CreateSessionPromise( | 312 std::unique_ptr<NewSessionCdmPromise> CreateSessionPromise( |
314 ExpectedResult expected_result) { | 313 ExpectedResult expected_result) { |
315 scoped_ptr<NewSessionCdmPromise> promise( | 314 std::unique_ptr<NewSessionCdmPromise> promise( |
316 new CdmCallbackPromise<std::string>( | 315 new CdmCallbackPromise<std::string>( |
317 base::Bind(&AesDecryptorTest::OnResolveWithSession, | 316 base::Bind(&AesDecryptorTest::OnResolveWithSession, |
318 base::Unretained(this), | 317 base::Unretained(this), expected_result), |
319 expected_result), | 318 base::Bind(&AesDecryptorTest::OnReject, base::Unretained(this), |
320 base::Bind(&AesDecryptorTest::OnReject, | |
321 base::Unretained(this), | |
322 expected_result))); | 319 expected_result))); |
323 return promise; | 320 return promise; |
324 } | 321 } |
325 | 322 |
326 // Creates a new session using |key_id|. Returns the session ID. | 323 // Creates a new session using |key_id|. Returns the session ID. |
327 std::string CreateSession(const std::vector<uint8_t>& key_id) { | 324 std::string CreateSession(const std::vector<uint8_t>& key_id) { |
328 DCHECK(!key_id.empty()); | 325 DCHECK(!key_id.empty()); |
329 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsJSONDictionary(), | 326 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsJSONDictionary(), |
330 GURL::EmptyGURL())); | 327 GURL::EmptyGURL())); |
331 cdm_->CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION, | 328 cdm_->CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION, |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 void(const std::string& session_id, | 476 void(const std::string& session_id, |
480 const base::Time& new_expiry_time)); | 477 const base::Time& new_expiry_time)); |
481 | 478 |
482 scoped_refptr<MediaKeys> cdm_; | 479 scoped_refptr<MediaKeys> cdm_; |
483 Decryptor* decryptor_; | 480 Decryptor* decryptor_; |
484 Decryptor::DecryptCB decrypt_cb_; | 481 Decryptor::DecryptCB decrypt_cb_; |
485 std::string session_id_; | 482 std::string session_id_; |
486 CdmKeysInfo keys_info_; | 483 CdmKeysInfo keys_info_; |
487 | 484 |
488 // Helper class to load/unload External Clear Key Library, if necessary. | 485 // Helper class to load/unload External Clear Key Library, if necessary. |
489 scoped_ptr<ExternalClearKeyTestHelper> helper_; | 486 std::unique_ptr<ExternalClearKeyTestHelper> helper_; |
490 | 487 |
491 base::MessageLoop message_loop_; | 488 base::MessageLoop message_loop_; |
492 | 489 |
493 // Constants for testing. | 490 // Constants for testing. |
494 const std::vector<uint8_t> original_data_; | 491 const std::vector<uint8_t> original_data_; |
495 const std::vector<uint8_t> encrypted_data_; | 492 const std::vector<uint8_t> encrypted_data_; |
496 const std::vector<uint8_t> subsample_encrypted_data_; | 493 const std::vector<uint8_t> subsample_encrypted_data_; |
497 const std::vector<uint8_t> key_id_; | 494 const std::vector<uint8_t> key_id_; |
498 const std::vector<uint8_t> iv_; | 495 const std::vector<uint8_t> iv_; |
499 const std::vector<SubsampleEntry> normal_subsample_entries_; | 496 const std::vector<SubsampleEntry> normal_subsample_entries_; |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1023 INSTANTIATE_TEST_CASE_P(CdmAdapter, | 1020 INSTANTIATE_TEST_CASE_P(CdmAdapter, |
1024 AesDecryptorTest, | 1021 AesDecryptorTest, |
1025 testing::Values("CdmAdapter")); | 1022 testing::Values("CdmAdapter")); |
1026 #endif | 1023 #endif |
1027 | 1024 |
1028 // TODO(jrummell): Once MojoCdm/MojoCdmService/MojoDecryptor/ | 1025 // TODO(jrummell): Once MojoCdm/MojoCdmService/MojoDecryptor/ |
1029 // MojoDecryptorService are implemented, add a third version that tests the | 1026 // MojoDecryptorService are implemented, add a third version that tests the |
1030 // CDM via mojo. | 1027 // CDM via mojo. |
1031 | 1028 |
1032 } // namespace media | 1029 } // namespace media |
OLD | NEW |