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