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

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

Issue 17289006: Separate CDM initialization from GenerateKeyRequest & remove key_system parameters. (Closed) Base URL: master
Patch Set: rebase only Created 7 years, 6 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
« no previous file with comments | « media/crypto/aes_decryptor.cc ('k') | media/filters/pipeline_integration_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 subsample_entries_(kSubsampleEntries, 237 subsample_entries_(kSubsampleEntries,
238 kSubsampleEntries + arraysize(kSubsampleEntries)) { 238 kSubsampleEntries + arraysize(kSubsampleEntries)) {
239 } 239 }
240 240
241 protected: 241 protected:
242 void GenerateKeyRequest(const uint8* key_id, int key_id_size) { 242 void GenerateKeyRequest(const uint8* key_id, int key_id_size) {
243 std::string key_id_string(reinterpret_cast<const char*>(key_id), 243 std::string key_id_string(reinterpret_cast<const char*>(key_id),
244 key_id_size); 244 key_id_size);
245 EXPECT_CALL( 245 EXPECT_CALL(
246 *this, 246 *this,
247 KeyMessage( 247 KeyMessage(StrNe(std::string()), StrEq(key_id_string), ""))
248 kClearKeySystem, StrNe(std::string()), StrEq(key_id_string), ""))
249 .WillOnce(SaveArg<1>(&session_id_string_)); 248 .WillOnce(SaveArg<1>(&session_id_string_));
250 EXPECT_TRUE(decryptor_.GenerateKeyRequest( 249 EXPECT_TRUE(decryptor_.GenerateKeyRequest(
251 kClearKeySystem, std::string(), key_id, key_id_size)); 250 std::string(), key_id, key_id_size));
252 } 251 }
253 252
254 void AddKeyAndExpectToSucceed(const uint8* key_id, int key_id_size, 253 void AddKeyAndExpectToSucceed(const uint8* key_id, int key_id_size,
255 const uint8* key, int key_size) { 254 const uint8* key, int key_size) {
256 EXPECT_CALL(*this, KeyAdded(kClearKeySystem, session_id_string_)); 255 EXPECT_CALL(*this, KeyAdded(session_id_string_));
257 decryptor_.AddKey(kClearKeySystem, key, key_size, key_id, key_id_size, 256 decryptor_.AddKey(key, key_size, key_id, key_id_size,
258 session_id_string_); 257 session_id_string_);
259 } 258 }
260 259
261 void AddKeyAndExpectToFail(const uint8* key_id, int key_id_size, 260 void AddKeyAndExpectToFail(const uint8* key_id, int key_id_size,
262 const uint8* key, int key_size) { 261 const uint8* key, int key_size) {
263 EXPECT_CALL(*this, KeyError(kClearKeySystem, session_id_string_, 262 EXPECT_CALL(*this, KeyError(session_id_string_,
264 MediaKeys::kUnknownError, 0)); 263 MediaKeys::kUnknownError, 0));
265 decryptor_.AddKey(kClearKeySystem, key, key_size, key_id, key_id_size, 264 decryptor_.AddKey(key, key_size, key_id, key_id_size, session_id_string_);
266 session_id_string_);
267 } 265 }
268 266
269 MOCK_METHOD2(BufferDecrypted, void(Decryptor::Status, 267 MOCK_METHOD2(BufferDecrypted, void(Decryptor::Status,
270 const scoped_refptr<DecoderBuffer>&)); 268 const scoped_refptr<DecoderBuffer>&));
271 269
272 void DecryptAndExpectToSucceed(const scoped_refptr<DecoderBuffer>& encrypted, 270 void DecryptAndExpectToSucceed(const scoped_refptr<DecoderBuffer>& encrypted,
273 const uint8* plain_text, int plain_text_size) { 271 const uint8* plain_text, int plain_text_size) {
274 scoped_refptr<DecoderBuffer> decrypted; 272 scoped_refptr<DecoderBuffer> decrypted;
275 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kSuccess, NotNull())) 273 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kSuccess, NotNull()))
276 .WillOnce(SaveArg<1>(&decrypted)); 274 .WillOnce(SaveArg<1>(&decrypted));
(...skipping 28 matching lines...) Expand all
305 ASSERT_TRUE(decrypted.get()); 303 ASSERT_TRUE(decrypted.get());
306 EXPECT_NE(plain_text_size, decrypted->GetDataSize()); 304 EXPECT_NE(plain_text_size, decrypted->GetDataSize());
307 EXPECT_NE(0, memcmp(plain_text, decrypted->GetData(), plain_text_size)); 305 EXPECT_NE(0, memcmp(plain_text, decrypted->GetData(), plain_text_size));
308 } 306 }
309 307
310 void DecryptAndExpectToFail(const scoped_refptr<DecoderBuffer>& encrypted) { 308 void DecryptAndExpectToFail(const scoped_refptr<DecoderBuffer>& encrypted) {
311 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kError, IsNull())); 309 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kError, IsNull()));
312 decryptor_.Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_); 310 decryptor_.Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_);
313 } 311 }
314 312
315 MOCK_METHOD2(KeyAdded, void(const std::string&, const std::string&)); 313 MOCK_METHOD1(KeyAdded, void(const std::string&));
316 MOCK_METHOD4(KeyError, void(const std::string&, const std::string&, 314 MOCK_METHOD3(KeyError, void(const std::string&,
317 MediaKeys::KeyError, int)); 315 MediaKeys::KeyError, int));
318 MOCK_METHOD4(KeyMessage, void(const std::string& key_system, 316 MOCK_METHOD3(KeyMessage, void(const std::string& session_id,
319 const std::string& session_id,
320 const std::string& message, 317 const std::string& message,
321 const std::string& default_url)); 318 const std::string& default_url));
322 319
323 AesDecryptor decryptor_; 320 AesDecryptor decryptor_;
324 std::string session_id_string_; 321 std::string session_id_string_;
325 AesDecryptor::DecryptCB decrypt_cb_; 322 AesDecryptor::DecryptCB decrypt_cb_;
326 std::vector<SubsampleEntry> subsample_entries_; 323 std::vector<SubsampleEntry> subsample_entries_;
327 }; 324 };
328 325
329 TEST_F(AesDecryptorTest, GenerateKeyRequestWithNullInitData) { 326 TEST_F(AesDecryptorTest, GenerateKeyRequestWithNullInitData) {
330 EXPECT_CALL(*this, KeyMessage(kClearKeySystem, StrNe(std::string()), "", "")); 327 EXPECT_CALL(*this, KeyMessage(StrNe(std::string()), "", ""));
331 EXPECT_TRUE( 328 EXPECT_TRUE(decryptor_.GenerateKeyRequest(std::string(), NULL, 0));
332 decryptor_.GenerateKeyRequest(kClearKeySystem, std::string(), NULL, 0));
333 } 329 }
334 330
335 TEST_F(AesDecryptorTest, NormalWebMDecryption) { 331 TEST_F(AesDecryptorTest, NormalWebMDecryption) {
336 const WebmEncryptedData& frame = kWebmEncryptedFrames[0]; 332 const WebmEncryptedData& frame = kWebmEncryptedFrames[0];
337 GenerateKeyRequest(frame.key_id, frame.key_id_size); 333 GenerateKeyRequest(frame.key_id, frame.key_id_size);
338 AddKeyAndExpectToSucceed(frame.key_id, frame.key_id_size, 334 AddKeyAndExpectToSucceed(frame.key_id, frame.key_id_size,
339 frame.key, frame.key_size); 335 frame.key, frame.key_size);
340 scoped_refptr<DecoderBuffer> encrypted_data = 336 scoped_refptr<DecoderBuffer> encrypted_data =
341 CreateWebMEncryptedBuffer(frame.encrypted_data, 337 CreateWebMEncryptedBuffer(frame.encrypted_data,
342 frame.encrypted_data_size, 338 frame.encrypted_data_size,
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 scoped_refptr<DecoderBuffer> encrypted_data = CreateSubsampleEncryptedBuffer( 595 scoped_refptr<DecoderBuffer> encrypted_data = CreateSubsampleEncryptedBuffer(
600 kSubsampleData, arraysize(kSubsampleData), 596 kSubsampleData, arraysize(kSubsampleData),
601 kSubsampleKeyId, arraysize(kSubsampleKeyId), 597 kSubsampleKeyId, arraysize(kSubsampleKeyId),
602 kSubsampleIv, arraysize(kSubsampleIv), 598 kSubsampleIv, arraysize(kSubsampleIv),
603 0, 599 0,
604 entries); 600 entries);
605 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail(encrypted_data)); 601 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail(encrypted_data));
606 } 602 }
607 603
608 } // namespace media 604 } // namespace media
OLDNEW
« no previous file with comments | « media/crypto/aes_decryptor.cc ('k') | media/filters/pipeline_integration_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698