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

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

Issue 11226019: Encrypted Media: Replace DecryptorClient with key event callbacks. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: prototype cl of new approach Created 8 years 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "media/base/decoder_buffer.h" 10 #include "media/base/decoder_buffer.h"
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 std::string(reinterpret_cast<const char*>(key_id), key_id_size), 220 std::string(reinterpret_cast<const char*>(key_id), key_id_size),
221 std::string(reinterpret_cast<const char*>(iv), iv_size), 221 std::string(reinterpret_cast<const char*>(iv), iv_size),
222 data_offset, 222 data_offset,
223 subsample_entries))); 223 subsample_entries)));
224 return encrypted_buffer; 224 return encrypted_buffer;
225 } 225 }
226 226
227 class AesDecryptorTest : public testing::Test { 227 class AesDecryptorTest : public testing::Test {
228 public: 228 public:
229 AesDecryptorTest() 229 AesDecryptorTest()
230 : decryptor_(&client_), 230 : decryptor_(base::Bind(&AesDecryptorTest::KeyAdded,
231 base::Unretained(this)),
232 base::Bind(&AesDecryptorTest::KeyError,
233 base::Unretained(this)),
234 base::Bind(&AesDecryptorTest::KeyMessage,
235 base::Unretained(this)),
236 NeedKeyCB()),
231 decrypt_cb_(base::Bind(&AesDecryptorTest::BufferDecrypted, 237 decrypt_cb_(base::Bind(&AesDecryptorTest::BufferDecrypted,
232 base::Unretained(this))), 238 base::Unretained(this))),
233 subsample_entries_(kSubsampleEntries, 239 subsample_entries_(kSubsampleEntries,
234 kSubsampleEntries + arraysize(kSubsampleEntries)) { 240 kSubsampleEntries + arraysize(kSubsampleEntries)) {
235 } 241 }
236 242
237 protected: 243 protected:
238 void GenerateKeyRequest(const uint8* key_id, int key_id_size) { 244 void GenerateKeyRequest(const uint8* key_id, int key_id_size) {
239 std::string key_id_string(reinterpret_cast<const char*>(key_id), 245 std::string key_id_string(reinterpret_cast<const char*>(key_id),
240 key_id_size); 246 key_id_size);
241 EXPECT_CALL(client_, KeyMessage(kClearKeySystem, 247 EXPECT_CALL(*this, KeyMessage(kClearKeySystem,
242 StrNe(""), StrEq(key_id_string), "")) 248 StrNe(""), StrEq(key_id_string), ""))
243 .WillOnce(SaveArg<1>(&session_id_string_)); 249 .WillOnce(SaveArg<1>(&session_id_string_));
244 EXPECT_TRUE(decryptor_.GenerateKeyRequest(kClearKeySystem, "", 250 EXPECT_TRUE(decryptor_.GenerateKeyRequest(kClearKeySystem, "",
245 key_id, key_id_size)); 251 key_id, key_id_size));
246 } 252 }
247 253
248 void AddKeyAndExpectToSucceed(const uint8* key_id, int key_id_size, 254 void AddKeyAndExpectToSucceed(const uint8* key_id, int key_id_size,
249 const uint8* key, int key_size) { 255 const uint8* key, int key_size) {
250 EXPECT_CALL(client_, KeyAdded(kClearKeySystem, session_id_string_)); 256 EXPECT_CALL(*this, KeyAdded(kClearKeySystem, session_id_string_));
251 decryptor_.AddKey(kClearKeySystem, key, key_size, key_id, key_id_size, 257 decryptor_.AddKey(kClearKeySystem, key, key_size, key_id, key_id_size,
252 session_id_string_); 258 session_id_string_);
253 } 259 }
254 260
255 void AddKeyAndExpectToFail(const uint8* key_id, int key_id_size, 261 void AddKeyAndExpectToFail(const uint8* key_id, int key_id_size,
256 const uint8* key, int key_size) { 262 const uint8* key, int key_size) {
257 EXPECT_CALL(client_, KeyError(kClearKeySystem, session_id_string_, 263 EXPECT_CALL(*this, KeyError(kClearKeySystem, session_id_string_,
258 Decryptor::kUnknownError, 0)); 264 Decryptor::kUnknownError, 0));
259 decryptor_.AddKey(kClearKeySystem, key, key_size, key_id, key_id_size, 265 decryptor_.AddKey(kClearKeySystem, key, key_size, key_id, key_id_size,
260 session_id_string_); 266 session_id_string_);
261 } 267 }
262 268
263 MOCK_METHOD2(BufferDecrypted, void(Decryptor::Status, 269 MOCK_METHOD2(BufferDecrypted, void(Decryptor::Status,
264 const scoped_refptr<DecoderBuffer>&)); 270 const scoped_refptr<DecoderBuffer>&));
265 271
266 void DecryptAndExpectToSucceed(const scoped_refptr<DecoderBuffer>& encrypted, 272 void DecryptAndExpectToSucceed(const scoped_refptr<DecoderBuffer>& encrypted,
267 const uint8* plain_text, int plain_text_size) { 273 const uint8* plain_text, int plain_text_size) {
268 scoped_refptr<DecoderBuffer> decrypted; 274 scoped_refptr<DecoderBuffer> decrypted;
(...skipping 30 matching lines...) Expand all
299 ASSERT_TRUE(decrypted); 305 ASSERT_TRUE(decrypted);
300 EXPECT_NE(plain_text_size, decrypted->GetDataSize()); 306 EXPECT_NE(plain_text_size, decrypted->GetDataSize());
301 EXPECT_NE(0, memcmp(plain_text, decrypted->GetData(), plain_text_size)); 307 EXPECT_NE(0, memcmp(plain_text, decrypted->GetData(), plain_text_size));
302 } 308 }
303 309
304 void DecryptAndExpectToFail(const scoped_refptr<DecoderBuffer>& encrypted) { 310 void DecryptAndExpectToFail(const scoped_refptr<DecoderBuffer>& encrypted) {
305 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kError, IsNull())); 311 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kError, IsNull()));
306 decryptor_.Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_); 312 decryptor_.Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_);
307 } 313 }
308 314
309 MockDecryptorClient client_; 315 MOCK_METHOD2(KeyAdded, void(const std::string&, const std::string&));
316 MOCK_METHOD4(KeyError, void(const std::string&, const std::string&,
317 Decryptor::KeyError, int));
318 MOCK_METHOD4(KeyMessage, void(const std::string& key_system,
319 const std::string& session_id,
320 const std::string& message,
321 const std::string& default_url));
322
310 AesDecryptor decryptor_; 323 AesDecryptor decryptor_;
311 std::string session_id_string_; 324 std::string session_id_string_;
312 AesDecryptor::DecryptCB decrypt_cb_; 325 AesDecryptor::DecryptCB decrypt_cb_;
313 std::vector<SubsampleEntry> subsample_entries_; 326 std::vector<SubsampleEntry> subsample_entries_;
314 }; 327 };
315 328
316 TEST_F(AesDecryptorTest, GenerateKeyRequestWithNullInitData) { 329 TEST_F(AesDecryptorTest, GenerateKeyRequestWithNullInitData) {
317 EXPECT_CALL(client_, KeyMessage(kClearKeySystem, StrNe(""), "", "")); 330 EXPECT_CALL(*this, KeyMessage(kClearKeySystem, StrNe(""), "", ""));
318 EXPECT_TRUE(decryptor_.GenerateKeyRequest(kClearKeySystem, "", NULL, 0)); 331 EXPECT_TRUE(decryptor_.GenerateKeyRequest(kClearKeySystem, "", NULL, 0));
319 } 332 }
320 333
321 TEST_F(AesDecryptorTest, NormalWebMDecryption) { 334 TEST_F(AesDecryptorTest, NormalWebMDecryption) {
322 const WebmEncryptedData& frame = kWebmEncryptedFrames[0]; 335 const WebmEncryptedData& frame = kWebmEncryptedFrames[0];
323 GenerateKeyRequest(frame.key_id, frame.key_id_size); 336 GenerateKeyRequest(frame.key_id, frame.key_id_size);
324 AddKeyAndExpectToSucceed(frame.key_id, frame.key_id_size, 337 AddKeyAndExpectToSucceed(frame.key_id, frame.key_id_size,
325 frame.key, frame.key_size); 338 frame.key, frame.key_size);
326 scoped_refptr<DecoderBuffer> encrypted_data = 339 scoped_refptr<DecoderBuffer> encrypted_data =
327 CreateWebMEncryptedBuffer(frame.encrypted_data, 340 CreateWebMEncryptedBuffer(frame.encrypted_data,
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 scoped_refptr<DecoderBuffer> encrypted_data = CreateSubsampleEncryptedBuffer( 598 scoped_refptr<DecoderBuffer> encrypted_data = CreateSubsampleEncryptedBuffer(
586 kSubsampleData, arraysize(kSubsampleData), 599 kSubsampleData, arraysize(kSubsampleData),
587 kSubsampleKeyId, arraysize(kSubsampleKeyId), 600 kSubsampleKeyId, arraysize(kSubsampleKeyId),
588 kSubsampleIv, arraysize(kSubsampleIv), 601 kSubsampleIv, arraysize(kSubsampleIv),
589 0, 602 0,
590 entries); 603 entries);
591 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail(encrypted_data)); 604 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail(encrypted_data));
592 } 605 }
593 606
594 } // namespace media 607 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698