| 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/cdm_key_information.h" |
| 14 #include "media/base/decoder_buffer.h" | 14 #include "media/base/decoder_buffer.h" |
| 15 #include "media/base/decrypt_config.h" | 15 #include "media/base/decrypt_config.h" |
| 16 #include "media/base/mock_filters.h" | 16 #include "media/base/mock_filters.h" |
| 17 #include "media/cdm/aes_decryptor.h" | 17 #include "media/cdm/aes_decryptor.h" |
| 18 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "url/gurl.h" |
| 20 | 21 |
| 21 using ::testing::_; | 22 using ::testing::_; |
| 22 using ::testing::Gt; | 23 using ::testing::Gt; |
| 23 using ::testing::IsNull; | 24 using ::testing::IsNull; |
| 24 using ::testing::NotNull; | 25 using ::testing::NotNull; |
| 25 using ::testing::SaveArg; | 26 using ::testing::SaveArg; |
| 26 using ::testing::StrNe; | 27 using ::testing::StrNe; |
| 27 using ::testing::Unused; | 28 using ::testing::Unused; |
| 28 | 29 |
| 29 MATCHER(IsEmpty, "") { return arg.empty(); } | 30 MATCHER(IsEmpty, "") { return arg.empty(); } |
| 30 MATCHER(IsNotEmpty, "") { return !arg.empty(); } | 31 MATCHER(IsNotEmpty, "") { return !arg.empty(); } |
| 31 MATCHER(IsJSONDictionary, "") { | 32 MATCHER(IsJSONDictionary, "") { |
| 32 std::string result(arg.begin(), arg.end()); | 33 std::string result(arg.begin(), arg.end()); |
| 33 scoped_ptr<base::Value> root(base::JSONReader().ReadToValue(result)); | 34 scoped_ptr<base::Value> root(base::JSONReader().ReadToValue(result)); |
| 34 return (root.get() && root->GetType() == base::Value::TYPE_DICTIONARY); | 35 return (root.get() && root->GetType() == base::Value::TYPE_DICTIONARY); |
| 35 } | 36 } |
| 36 | 37 |
| 37 class GURL; | |
| 38 | |
| 39 namespace media { | 38 namespace media { |
| 40 | 39 |
| 41 const uint8 kOriginalData[] = "Original subsample data."; | 40 const uint8 kOriginalData[] = "Original subsample data."; |
| 42 const int kOriginalDataSize = 24; | 41 const int kOriginalDataSize = 24; |
| 43 | 42 |
| 44 // In the examples below, 'k'(key) has to be 16 bytes, and will always require | 43 // In the examples below, 'k'(key) has to be 16 bytes, and will always require |
| 45 // 2 bytes of padding. 'kid'(keyid) is variable length, and may require 0, 1, | 44 // 2 bytes of padding. 'kid'(keyid) is variable length, and may require 0, 1, |
| 46 // or 2 bytes of padding. | 45 // or 2 bytes of padding. |
| 47 | 46 |
| 48 const uint8 kKeyId[] = { | 47 const uint8 kKeyId[] = { |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 encrypted_buffer->set_decrypt_config(scoped_ptr<DecryptConfig>( | 207 encrypted_buffer->set_decrypt_config(scoped_ptr<DecryptConfig>( |
| 209 new DecryptConfig(key_id_string, iv_string, subsample_entries))); | 208 new DecryptConfig(key_id_string, iv_string, subsample_entries))); |
| 210 return encrypted_buffer; | 209 return encrypted_buffer; |
| 211 } | 210 } |
| 212 | 211 |
| 213 enum PromiseResult { RESOLVED, REJECTED }; | 212 enum PromiseResult { RESOLVED, REJECTED }; |
| 214 | 213 |
| 215 class AesDecryptorTest : public testing::Test { | 214 class AesDecryptorTest : public testing::Test { |
| 216 public: | 215 public: |
| 217 AesDecryptorTest() | 216 AesDecryptorTest() |
| 218 : decryptor_(base::Bind(&AesDecryptorTest::OnSessionMessage, | 217 : decryptor_(GURL::EmptyGURL(), |
| 218 base::Bind(&AesDecryptorTest::OnSessionMessage, |
| 219 base::Unretained(this)), | 219 base::Unretained(this)), |
| 220 base::Bind(&AesDecryptorTest::OnSessionClosed, | 220 base::Bind(&AesDecryptorTest::OnSessionClosed, |
| 221 base::Unretained(this)), | 221 base::Unretained(this)), |
| 222 base::Bind(&AesDecryptorTest::OnSessionKeysChange, | 222 base::Bind(&AesDecryptorTest::OnSessionKeysChange, |
| 223 base::Unretained(this))), | 223 base::Unretained(this))), |
| 224 decrypt_cb_(base::Bind(&AesDecryptorTest::BufferDecrypted, | 224 decrypt_cb_(base::Bind(&AesDecryptorTest::BufferDecrypted, |
| 225 base::Unretained(this))), | 225 base::Unretained(this))), |
| 226 original_data_(kOriginalData, kOriginalData + kOriginalDataSize), | 226 original_data_(kOriginalData, kOriginalData + kOriginalDataSize), |
| 227 encrypted_data_(kEncryptedData, | 227 encrypted_data_(kEncryptedData, |
| 228 kEncryptedData + arraysize(kEncryptedData)), | 228 kEncryptedData + arraysize(kEncryptedData)), |
| (...skipping 700 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 |