| 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 17 matching lines...) Expand all Loading... |
| 28 #include "media/cdm/external_clear_key_test_helper.h" | 28 #include "media/cdm/external_clear_key_test_helper.h" |
| 29 #include "media/cdm/simple_cdm_allocator.h" | 29 #include "media/cdm/simple_cdm_allocator.h" |
| 30 #include "media/media_features.h" | 30 #include "media/media_features.h" |
| 31 #include "ppapi/features/features.h" | 31 #include "ppapi/features/features.h" |
| 32 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
| 33 #include "testing/gtest/include/gtest/gtest-param-test.h" | 33 #include "testing/gtest/include/gtest/gtest-param-test.h" |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 35 #include "url/gurl.h" | 35 #include "url/gurl.h" |
| 36 | 36 |
| 37 using ::testing::_; | 37 using ::testing::_; |
| 38 using ::testing::AtMost; |
| 38 using ::testing::Gt; | 39 using ::testing::Gt; |
| 39 using ::testing::IsNull; | 40 using ::testing::IsNull; |
| 40 using ::testing::NotNull; | 41 using ::testing::NotNull; |
| 41 using ::testing::SaveArg; | 42 using ::testing::SaveArg; |
| 42 using ::testing::StrictMock; | 43 using ::testing::StrictMock; |
| 43 using ::testing::StrNe; | 44 using ::testing::StrNe; |
| 44 using ::testing::Unused; | 45 using ::testing::Unused; |
| 45 | 46 |
| 46 MATCHER(IsEmpty, "") { return arg.empty(); } | 47 MATCHER(IsEmpty, "") { return arg.empty(); } |
| 47 MATCHER(NotEmpty, "") { | 48 MATCHER(NotEmpty, "") { |
| 48 return !arg.empty(); | 49 return !arg.empty(); |
| 49 } | 50 } |
| 50 MATCHER(IsJSONDictionary, "") { | 51 MATCHER(IsJSONDictionary, "") { |
| 51 std::string result(arg.begin(), arg.end()); | 52 std::string result(arg.begin(), arg.end()); |
| 52 std::unique_ptr<base::Value> root(base::JSONReader().ReadToValue(result)); | 53 std::unique_ptr<base::Value> root(base::JSONReader().ReadToValue(result)); |
| 53 return (root.get() && root->GetType() == base::Value::Type::DICTIONARY); | 54 return (root.get() && root->GetType() == base::Value::Type::DICTIONARY); |
| 54 } | 55 } |
| 56 MATCHER(IsNullTime, "") { |
| 57 return arg.is_null(); |
| 58 } |
| 55 | 59 |
| 56 namespace media { | 60 namespace media { |
| 57 | 61 |
| 58 const uint8_t kOriginalData[] = "Original subsample data."; | 62 const uint8_t kOriginalData[] = "Original subsample data."; |
| 59 const int kOriginalDataSize = 24; | 63 const int kOriginalDataSize = 24; |
| 60 | 64 |
| 61 // In the examples below, 'k'(key) has to be 16 bytes, and will always require | 65 // In the examples below, 'k'(key) has to be 16 bytes, and will always require |
| 62 // 2 bytes of padding. 'kid'(keyid) is variable length, and may require 0, 1, | 66 // 2 bytes of padding. 'kid'(keyid) is variable length, and may require 0, 1, |
| 63 // or 2 bytes of padding. | 67 // or 2 bytes of padding. |
| 64 | 68 |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 bool new_key_expected) { | 361 bool new_key_expected) { |
| 358 DCHECK(!key.empty()); | 362 DCHECK(!key.empty()); |
| 359 | 363 |
| 360 if (expected_result == RESOLVED) { | 364 if (expected_result == RESOLVED) { |
| 361 EXPECT_CALL(cdm_client_, | 365 EXPECT_CALL(cdm_client_, |
| 362 OnSessionKeysChangeCalled(session_id, new_key_expected)); | 366 OnSessionKeysChangeCalled(session_id, new_key_expected)); |
| 363 } else { | 367 } else { |
| 364 EXPECT_CALL(cdm_client_, OnSessionKeysChangeCalled(_, _)).Times(0); | 368 EXPECT_CALL(cdm_client_, OnSessionKeysChangeCalled(_, _)).Times(0); |
| 365 } | 369 } |
| 366 | 370 |
| 371 // AesDecryptor never calls OnSessionExpirationUpdate() since Clear Key key |
| 372 // system doesn't need it. But ClearKeyCdm does call it for testing purpose. |
| 373 EXPECT_CALL(cdm_client_, |
| 374 OnSessionExpirationUpdate(session_id, IsNullTime())) |
| 375 .Times(AtMost(1)); |
| 376 |
| 367 cdm_->UpdateSession(session_id, | 377 cdm_->UpdateSession(session_id, |
| 368 std::vector<uint8_t>(key.begin(), key.end()), | 378 std::vector<uint8_t>(key.begin(), key.end()), |
| 369 CreatePromise(expected_result)); | 379 CreatePromise(expected_result)); |
| 370 } | 380 } |
| 371 | 381 |
| 372 bool KeysInfoContains(const std::vector<uint8_t>& expected) { | 382 bool KeysInfoContains(const std::vector<uint8_t>& expected) { |
| 373 for (auto* key_id : cdm_client_.keys_info()) { | 383 for (auto* key_id : cdm_client_.keys_info()) { |
| 374 if (key_id->key_id == expected) | 384 if (key_id->key_id == expected) |
| 375 return true; | 385 return true; |
| 376 } | 386 } |
| (...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1013 INSTANTIATE_TEST_CASE_P(CdmAdapter, | 1023 INSTANTIATE_TEST_CASE_P(CdmAdapter, |
| 1014 AesDecryptorTest, | 1024 AesDecryptorTest, |
| 1015 testing::Values("CdmAdapter")); | 1025 testing::Values("CdmAdapter")); |
| 1016 #endif | 1026 #endif |
| 1017 | 1027 |
| 1018 // TODO(jrummell): Once MojoCdm/MojoCdmService/MojoDecryptor/ | 1028 // TODO(jrummell): Once MojoCdm/MojoCdmService/MojoDecryptor/ |
| 1019 // MojoDecryptorService are implemented, add a third version that tests the | 1029 // MojoDecryptorService are implemented, add a third version that tests the |
| 1020 // CDM via mojo. | 1030 // CDM via mojo. |
| 1021 | 1031 |
| 1022 } // namespace media | 1032 } // namespace media |
| OLD | NEW |