| 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" |
| 11 #include "base/values.h" |
| 10 #include "media/base/cdm_promise.h" | 12 #include "media/base/cdm_promise.h" |
| 11 #include "media/base/decoder_buffer.h" | 13 #include "media/base/decoder_buffer.h" |
| 12 #include "media/base/decrypt_config.h" | 14 #include "media/base/decrypt_config.h" |
| 13 #include "media/base/mock_filters.h" | 15 #include "media/base/mock_filters.h" |
| 14 #include "media/cdm/aes_decryptor.h" | 16 #include "media/cdm/aes_decryptor.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 19 |
| 18 using ::testing::_; | 20 using ::testing::_; |
| 19 using ::testing::Gt; | 21 using ::testing::Gt; |
| 20 using ::testing::IsNull; | 22 using ::testing::IsNull; |
| 21 using ::testing::NotNull; | 23 using ::testing::NotNull; |
| 22 using ::testing::SaveArg; | 24 using ::testing::SaveArg; |
| 23 using ::testing::StrNe; | 25 using ::testing::StrNe; |
| 24 | 26 |
| 25 MATCHER(IsEmpty, "") { return arg.empty(); } | 27 MATCHER(IsEmpty, "") { return arg.empty(); } |
| 26 MATCHER(IsNotEmpty, "") { return !arg.empty(); } | 28 MATCHER(IsNotEmpty, "") { return !arg.empty(); } |
| 29 MATCHER(IsJSONDictionary, "") { |
| 30 std::string result(arg.begin(), arg.end()); |
| 31 scoped_ptr<base::Value> root(base::JSONReader().ReadToValue(result)); |
| 32 return (root.get() && root->GetType() == base::Value::TYPE_DICTIONARY); |
| 33 } |
| 27 | 34 |
| 28 class GURL; | 35 class GURL; |
| 29 | 36 |
| 30 namespace media { | 37 namespace media { |
| 31 | 38 |
| 32 const uint8 kOriginalData[] = "Original subsample data."; | 39 const uint8 kOriginalData[] = "Original subsample data."; |
| 33 const int kOriginalDataSize = 24; | 40 const int kOriginalDataSize = 24; |
| 34 | 41 |
| 35 // In the examples below, 'k'(key) has to be 16 bytes, and will always require | 42 // In the examples below, 'k'(key) has to be 16 bytes, and will always require |
| 36 // 2 bytes of padding. 'kid'(keyid) is variable length, and may require 0, 1, | 43 // 2 bytes of padding. 'kid'(keyid) is variable length, and may require 0, 1, |
| 37 // or 2 bytes of padding. | 44 // or 2 bytes of padding. |
| 38 | 45 |
| 39 const uint8 kKeyId[] = { | 46 const uint8 kKeyId[] = { |
| 40 // base64 equivalent is AAECAw | 47 // base64 equivalent is AAECAw |
| 41 0x00, 0x01, 0x02, 0x03 | 48 0x00, 0x01, 0x02, 0x03 |
| 42 }; | 49 }; |
| 43 | 50 |
| 44 // Key is 0x0405060708090a0b0c0d0e0f10111213, | 51 // Key is 0x0405060708090a0b0c0d0e0f10111213, |
| 45 // base64 equivalent is BAUGBwgJCgsMDQ4PEBESEw. | 52 // base64 equivalent is BAUGBwgJCgsMDQ4PEBESEw. |
| 46 const char kKeyAsJWK[] = | 53 const char kKeyAsJWK[] = |
| 47 "{" | 54 "{" |
| 48 " \"keys\": [" | 55 " \"keys\": [" |
| 49 " {" | 56 " {" |
| 50 " \"kty\": \"oct\"," | 57 " \"kty\": \"oct\"," |
| 51 " \"kid\": \"AAECAw\"," | 58 " \"kid\": \"AAECAw\"," |
| 52 " \"k\": \"BAUGBwgJCgsMDQ4PEBESEw\"" | 59 " \"k\": \"BAUGBwgJCgsMDQ4PEBESEw\"" |
| 53 " }" | 60 " }" |
| 54 " ]" | 61 " ]," |
| 62 " \"type\": \"temporary\"" |
| 55 "}"; | 63 "}"; |
| 56 | 64 |
| 57 // Same kid as kKeyAsJWK, key to decrypt kEncryptedData2 | 65 // Same kid as kKeyAsJWK, key to decrypt kEncryptedData2 |
| 58 const char kKeyAlternateAsJWK[] = | 66 const char kKeyAlternateAsJWK[] = |
| 59 "{" | 67 "{" |
| 60 " \"keys\": [" | 68 " \"keys\": [" |
| 61 " {" | 69 " {" |
| 62 " \"kty\": \"oct\"," | 70 " \"kty\": \"oct\"," |
| 63 " \"kid\": \"AAECAw\"," | 71 " \"kid\": \"AAECAw\"," |
| 64 " \"k\": \"FBUWFxgZGhscHR4fICEiIw\"" | 72 " \"k\": \"FBUWFxgZGhscHR4fICEiIw\"" |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 base::Bind(&AesDecryptorTest::OnReject, | 288 base::Bind(&AesDecryptorTest::OnReject, |
| 281 base::Unretained(this), | 289 base::Unretained(this), |
| 282 expected_result))); | 290 expected_result))); |
| 283 return promise.Pass(); | 291 return promise.Pass(); |
| 284 } | 292 } |
| 285 | 293 |
| 286 // Creates a new session using |key_id|. Returns the session ID. | 294 // Creates a new session using |key_id|. Returns the session ID. |
| 287 std::string CreateSession(const std::vector<uint8>& key_id) { | 295 std::string CreateSession(const std::vector<uint8>& key_id) { |
| 288 DCHECK(!key_id.empty()); | 296 DCHECK(!key_id.empty()); |
| 289 EXPECT_CALL(*this, | 297 EXPECT_CALL(*this, |
| 290 OnSessionMessage(IsNotEmpty(), key_id, GURL::EmptyGURL())); | 298 OnSessionMessage( |
| 299 IsNotEmpty(), IsJSONDictionary(), GURL::EmptyGURL())); |
| 291 decryptor_.CreateSession(std::string(), | 300 decryptor_.CreateSession(std::string(), |
| 292 &key_id[0], | 301 &key_id[0], |
| 293 key_id.size(), | 302 key_id.size(), |
| 294 MediaKeys::TEMPORARY_SESSION, | 303 MediaKeys::TEMPORARY_SESSION, |
| 295 CreateSessionPromise(RESOLVED)); | 304 CreateSessionPromise(RESOLVED)); |
| 296 // This expects the promise to be called synchronously, which is the case | 305 // This expects the promise to be called synchronously, which is the case |
| 297 // for AesDecryptor. | 306 // for AesDecryptor. |
| 298 return web_session_id_; | 307 return web_session_id_; |
| 299 } | 308 } |
| 300 | 309 |
| (...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 EXPECT_FALSE(UsableKeyIdsContains(key_id2)); | 860 EXPECT_FALSE(UsableKeyIdsContains(key_id2)); |
| 852 | 861 |
| 853 // Add second key, verify both IDs returned. | 862 // Add second key, verify both IDs returned. |
| 854 UpdateSessionAndExpect(session_id, kKey2AsJWK, RESOLVED); | 863 UpdateSessionAndExpect(session_id, kKey2AsJWK, RESOLVED); |
| 855 GetUsableKeyIdsAndExpect(session_id, RESOLVED, 2); | 864 GetUsableKeyIdsAndExpect(session_id, RESOLVED, 2); |
| 856 EXPECT_TRUE(UsableKeyIdsContains(key_id1)); | 865 EXPECT_TRUE(UsableKeyIdsContains(key_id1)); |
| 857 EXPECT_TRUE(UsableKeyIdsContains(key_id2)); | 866 EXPECT_TRUE(UsableKeyIdsContains(key_id2)); |
| 858 } | 867 } |
| 859 | 868 |
| 860 } // namespace media | 869 } // namespace media |
| OLD | NEW |