Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: media/cdm/aes_decryptor_unittest.cc

Issue 427993002: Implement ClearKey message format as JSON. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updates Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 expected), 263 expected),
256 base::Bind( 264 base::Bind(
257 &AesDecryptorTest::OnReject, base::Unretained(this), expected))); 265 &AesDecryptorTest::OnReject, base::Unretained(this), expected)));
258 return promise.Pass(); 266 return promise.Pass();
259 } 267 }
260 268
261 // Creates a new session using |key_id|. Returns the session ID. 269 // Creates a new session using |key_id|. Returns the session ID.
262 std::string CreateSession(const std::vector<uint8>& key_id) { 270 std::string CreateSession(const std::vector<uint8>& key_id) {
263 DCHECK(!key_id.empty()); 271 DCHECK(!key_id.empty());
264 EXPECT_CALL(*this, 272 EXPECT_CALL(*this,
265 OnSessionMessage(IsNotEmpty(), key_id, GURL::EmptyGURL())); 273 OnSessionMessage(
274 IsNotEmpty(), IsJSONDictionary(), GURL::EmptyGURL()));
266 decryptor_.CreateSession(std::string(), 275 decryptor_.CreateSession(std::string(),
267 &key_id[0], 276 &key_id[0],
268 key_id.size(), 277 key_id.size(),
269 MediaKeys::TEMPORARY_SESSION, 278 MediaKeys::TEMPORARY_SESSION,
270 CreateSessionPromise(RESOLVED)); 279 CreateSessionPromise(RESOLVED));
271 // This expects the promise to be called synchronously, which is the case 280 // This expects the promise to be called synchronously, which is the case
272 // for AesDecryptor. 281 // for AesDecryptor.
273 return web_session_id_; 282 return web_session_id_;
274 } 283 }
275 284
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 " \"kid\": \"\"," 792 " \"kid\": \"\","
784 " \"k\": \"BAUGBwgJCgsMDQ4PEBESEw\"" 793 " \"k\": \"BAUGBwgJCgsMDQ4PEBESEw\""
785 " }" 794 " }"
786 " ]" 795 " ]"
787 "}"; 796 "}";
788 UpdateSessionAndExpect(session_id, kJwksWithEmptyKeyId, REJECTED); 797 UpdateSessionAndExpect(session_id, kJwksWithEmptyKeyId, REJECTED);
789 ReleaseSession(session_id); 798 ReleaseSession(session_id);
790 } 799 }
791 800
792 } // namespace media 801 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698