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

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

Issue 297703002: Using GURL in place of std::string for destination_url (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 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/cdm/aes_decryptor.cc ('k') | media/cdm/ppapi/external_clear_key/clear_key_cdm.h » ('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 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 "media/base/decoder_buffer.h" 10 #include "media/base/decoder_buffer.h"
11 #include "media/base/decrypt_config.h" 11 #include "media/base/decrypt_config.h"
12 #include "media/base/mock_filters.h" 12 #include "media/base/mock_filters.h"
13 #include "media/cdm/aes_decryptor.h" 13 #include "media/cdm/aes_decryptor.h"
14 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 using ::testing::_; 17 using ::testing::_;
18 using ::testing::Gt; 18 using ::testing::Gt;
19 using ::testing::IsNull; 19 using ::testing::IsNull;
20 using ::testing::NotNull; 20 using ::testing::NotNull;
21 using ::testing::SaveArg; 21 using ::testing::SaveArg;
22 using ::testing::StrNe; 22 using ::testing::StrNe;
23 23
24 MATCHER(IsEmpty, "") { return arg.empty(); } 24 MATCHER(IsEmpty, "") { return arg.empty(); }
25 25
26 class GURL;
27
26 namespace media { 28 namespace media {
27 29
28 const uint8 kOriginalData[] = "Original subsample data."; 30 const uint8 kOriginalData[] = "Original subsample data.";
29 const int kOriginalDataSize = 24; 31 const int kOriginalDataSize = 24;
30 32
31 // In the examples below, 'k'(key) has to be 16 bytes, and will always require 33 // In the examples below, 'k'(key) has to be 16 bytes, and will always require
32 // 2 bytes of padding. 'kid'(keyid) is variable length, and may require 0, 1, 34 // 2 bytes of padding. 'kid'(keyid) is variable length, and may require 0, 1,
33 // or 2 bytes of padding. 35 // or 2 bytes of padding.
34 36
35 const uint8 kKeyId[] = { 37 const uint8 kKeyId[] = {
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 kSubsampleEntriesNormal + arraysize(kSubsampleEntriesNormal)), 221 kSubsampleEntriesNormal + arraysize(kSubsampleEntriesNormal)),
220 next_session_id_(1) { 222 next_session_id_(1) {
221 } 223 }
222 224
223 protected: 225 protected:
224 // Creates a new session using |key_id|. Returns the session ID. 226 // Creates a new session using |key_id|. Returns the session ID.
225 uint32 CreateSession(const std::vector<uint8>& key_id) { 227 uint32 CreateSession(const std::vector<uint8>& key_id) {
226 DCHECK(!key_id.empty()); 228 DCHECK(!key_id.empty());
227 uint32 session_id = next_session_id_++; 229 uint32 session_id = next_session_id_++;
228 EXPECT_CALL(*this, OnSessionCreated(session_id, StrNe(std::string()))); 230 EXPECT_CALL(*this, OnSessionCreated(session_id, StrNe(std::string())));
229 EXPECT_CALL(*this, OnSessionMessage(session_id, key_id, "")); 231 EXPECT_CALL(*this, OnSessionMessage(session_id, key_id, GURL::EmptyGURL()));
230 EXPECT_TRUE(decryptor_.CreateSession( 232 EXPECT_TRUE(decryptor_.CreateSession(
231 session_id, std::string(), &key_id[0], key_id.size())); 233 session_id, std::string(), &key_id[0], key_id.size()));
232 return session_id; 234 return session_id;
233 } 235 }
234 236
235 // Releases the session specified by |session_id|. 237 // Releases the session specified by |session_id|.
236 void ReleaseSession(uint32 session_id) { 238 void ReleaseSession(uint32 session_id) {
237 EXPECT_CALL(*this, OnSessionClosed(session_id)); 239 EXPECT_CALL(*this, OnSessionClosed(session_id));
238 decryptor_.ReleaseSession(session_id); 240 decryptor_.ReleaseSession(session_id);
239 } 241 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 EXPECT_TRUE(decrypted_text.empty()); 323 EXPECT_TRUE(decrypted_text.empty());
322 break; 324 break;
323 } 325 }
324 } 326 }
325 327
326 MOCK_METHOD2(OnSessionCreated, 328 MOCK_METHOD2(OnSessionCreated,
327 void(uint32 session_id, const std::string& web_session_id)); 329 void(uint32 session_id, const std::string& web_session_id));
328 MOCK_METHOD3(OnSessionMessage, 330 MOCK_METHOD3(OnSessionMessage,
329 void(uint32 session_id, 331 void(uint32 session_id,
330 const std::vector<uint8>& message, 332 const std::vector<uint8>& message,
331 const std::string& default_url)); 333 const GURL& default_url));
332 MOCK_METHOD1(OnSessionReady, void(uint32 session_id)); 334 MOCK_METHOD1(OnSessionReady, void(uint32 session_id));
333 MOCK_METHOD1(OnSessionClosed, void(uint32 session_id)); 335 MOCK_METHOD1(OnSessionClosed, void(uint32 session_id));
334 MOCK_METHOD3(OnSessionError, 336 MOCK_METHOD3(OnSessionError,
335 void(uint32 session_id, 337 void(uint32 session_id,
336 MediaKeys::KeyError, 338 MediaKeys::KeyError,
337 uint32 system_code)); 339 uint32 system_code));
338 340
339 AesDecryptor decryptor_; 341 AesDecryptor decryptor_;
340 AesDecryptor::DecryptCB decrypt_cb_; 342 AesDecryptor::DecryptCB decrypt_cb_;
341 343
342 // Constants for testing. 344 // Constants for testing.
343 const std::vector<uint8> original_data_; 345 const std::vector<uint8> original_data_;
344 const std::vector<uint8> encrypted_data_; 346 const std::vector<uint8> encrypted_data_;
345 const std::vector<uint8> subsample_encrypted_data_; 347 const std::vector<uint8> subsample_encrypted_data_;
346 const std::vector<uint8> key_id_; 348 const std::vector<uint8> key_id_;
347 const std::vector<uint8> iv_; 349 const std::vector<uint8> iv_;
348 const std::vector<SubsampleEntry> normal_subsample_entries_; 350 const std::vector<SubsampleEntry> normal_subsample_entries_;
349 const std::vector<SubsampleEntry> no_subsample_entries_; 351 const std::vector<SubsampleEntry> no_subsample_entries_;
350 352
351 // Generate new session ID every time 353 // Generate new session ID every time
352 uint32 next_session_id_; 354 uint32 next_session_id_;
353 }; 355 };
354 356
355 TEST_F(AesDecryptorTest, CreateSessionWithNullInitData) { 357 TEST_F(AesDecryptorTest, CreateSessionWithNullInitData) {
356 uint32 session_id = 8; 358 uint32 session_id = 8;
357 EXPECT_CALL(*this, OnSessionMessage(session_id, IsEmpty(), "")); 359 EXPECT_CALL(*this,
360 OnSessionMessage(session_id, IsEmpty(), GURL::EmptyGURL()));
358 EXPECT_CALL(*this, OnSessionCreated(session_id, StrNe(std::string()))); 361 EXPECT_CALL(*this, OnSessionCreated(session_id, StrNe(std::string())));
359 EXPECT_TRUE(decryptor_.CreateSession(session_id, std::string(), NULL, 0)); 362 EXPECT_TRUE(decryptor_.CreateSession(session_id, std::string(), NULL, 0));
360 } 363 }
361 364
362 TEST_F(AesDecryptorTest, MultipleCreateSession) { 365 TEST_F(AesDecryptorTest, MultipleCreateSession) {
363 uint32 session_id1 = 10; 366 uint32 session_id1 = 10;
364 EXPECT_CALL(*this, OnSessionMessage(session_id1, IsEmpty(), "")); 367 EXPECT_CALL(*this,
368 OnSessionMessage(session_id1, IsEmpty(), GURL::EmptyGURL()));
365 EXPECT_CALL(*this, OnSessionCreated(session_id1, StrNe(std::string()))); 369 EXPECT_CALL(*this, OnSessionCreated(session_id1, StrNe(std::string())));
366 EXPECT_TRUE(decryptor_.CreateSession(session_id1, std::string(), NULL, 0)); 370 EXPECT_TRUE(decryptor_.CreateSession(session_id1, std::string(), NULL, 0));
367 371
368 uint32 session_id2 = 11; 372 uint32 session_id2 = 11;
369 EXPECT_CALL(*this, OnSessionMessage(session_id2, IsEmpty(), "")); 373 EXPECT_CALL(*this,
374 OnSessionMessage(session_id2, IsEmpty(), GURL::EmptyGURL()));
370 EXPECT_CALL(*this, OnSessionCreated(session_id2, StrNe(std::string()))); 375 EXPECT_CALL(*this, OnSessionCreated(session_id2, StrNe(std::string())));
371 EXPECT_TRUE(decryptor_.CreateSession(session_id2, std::string(), NULL, 0)); 376 EXPECT_TRUE(decryptor_.CreateSession(session_id2, std::string(), NULL, 0));
372 377
373 uint32 session_id3 = 23; 378 uint32 session_id3 = 23;
374 EXPECT_CALL(*this, OnSessionMessage(session_id3, IsEmpty(), "")); 379 EXPECT_CALL(*this,
380 OnSessionMessage(session_id3, IsEmpty(), GURL::EmptyGURL()));
375 EXPECT_CALL(*this, OnSessionCreated(session_id3, StrNe(std::string()))); 381 EXPECT_CALL(*this, OnSessionCreated(session_id3, StrNe(std::string())));
376 EXPECT_TRUE(decryptor_.CreateSession(session_id3, std::string(), NULL, 0)); 382 EXPECT_TRUE(decryptor_.CreateSession(session_id3, std::string(), NULL, 0));
377 } 383 }
378 384
379 TEST_F(AesDecryptorTest, NormalDecryption) { 385 TEST_F(AesDecryptorTest, NormalDecryption) {
380 uint32 session_id = CreateSession(key_id_); 386 uint32 session_id = CreateSession(key_id_);
381 UpdateSessionAndExpect(session_id, kKeyAsJWK, SESSION_READY); 387 UpdateSessionAndExpect(session_id, kKeyAsJWK, SESSION_READY);
382 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer( 388 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
383 encrypted_data_, key_id_, iv_, no_subsample_entries_); 389 encrypted_data_, key_id_, iv_, no_subsample_entries_);
384 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS); 390 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS);
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 " \"kid\": \"\"," 760 " \"kid\": \"\","
755 " \"k\": \"BAUGBwgJCgsMDQ4PEBESEw\"" 761 " \"k\": \"BAUGBwgJCgsMDQ4PEBESEw\""
756 " }" 762 " }"
757 " ]" 763 " ]"
758 "}"; 764 "}";
759 UpdateSessionAndExpect(session_id, kJwksWithEmptyKeyId, SESSION_ERROR); 765 UpdateSessionAndExpect(session_id, kJwksWithEmptyKeyId, SESSION_ERROR);
760 ReleaseSession(session_id); 766 ReleaseSession(session_id);
761 } 767 }
762 768
763 } // namespace media 769 } // namespace media
OLDNEW
« no previous file with comments | « media/cdm/aes_decryptor.cc ('k') | media/cdm/ppapi/external_clear_key/clear_key_cdm.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698