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 "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 } | 245 } |
246 | 246 |
247 void OnResolve(PromiseResult expected_result) { | 247 void OnResolve(PromiseResult expected_result) { |
248 EXPECT_EQ(expected_result, RESOLVED) << "Unexpectedly resolved."; | 248 EXPECT_EQ(expected_result, RESOLVED) << "Unexpectedly resolved."; |
249 } | 249 } |
250 | 250 |
251 void OnReject(PromiseResult expected_result, | 251 void OnReject(PromiseResult expected_result, |
252 MediaKeys::Exception exception_code, | 252 MediaKeys::Exception exception_code, |
253 uint32 system_code, | 253 uint32 system_code, |
254 const std::string& error_message) { | 254 const std::string& error_message) { |
255 EXPECT_EQ(expected_result, REJECTED) << "Unexpectedly rejected."; | 255 EXPECT_EQ(expected_result, REJECTED) |
| 256 << "Unexpectedly rejected with message: " << error_message; |
256 } | 257 } |
257 | 258 |
258 scoped_ptr<SimpleCdmPromise> CreatePromise(PromiseResult expected_result) { | 259 scoped_ptr<SimpleCdmPromise> CreatePromise(PromiseResult expected_result) { |
259 scoped_ptr<SimpleCdmPromise> promise( | 260 scoped_ptr<SimpleCdmPromise> promise( |
260 new CdmCallbackPromise<>(base::Bind(&AesDecryptorTest::OnResolve, | 261 new CdmCallbackPromise<>(base::Bind(&AesDecryptorTest::OnResolve, |
261 base::Unretained(this), | 262 base::Unretained(this), |
262 expected_result), | 263 expected_result), |
263 base::Bind(&AesDecryptorTest::OnReject, | 264 base::Bind(&AesDecryptorTest::OnReject, |
264 base::Unretained(this), | 265 base::Unretained(this), |
265 expected_result))); | 266 expected_result))); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 "webm", NULL, 0, | 448 "webm", NULL, 0, |
448 CreateSessionPromise(RESOLVED)); | 449 CreateSessionPromise(RESOLVED)); |
449 | 450 |
450 EXPECT_CALL(*this, | 451 EXPECT_CALL(*this, |
451 OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL())); | 452 OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL())); |
452 decryptor_.CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION, | 453 decryptor_.CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION, |
453 "webm", NULL, 0, | 454 "webm", NULL, 0, |
454 CreateSessionPromise(RESOLVED)); | 455 CreateSessionPromise(RESOLVED)); |
455 } | 456 } |
456 | 457 |
| 458 TEST_F(AesDecryptorTest, CreateSessionWithCencInitData) { |
| 459 const uint8 init_data[] = { |
| 460 0x00, 0x00, 0x00, 0x44, // size = 68 |
| 461 0x70, 0x73, 0x73, 0x68, // 'pssh' |
| 462 0x01, // version |
| 463 0x00, 0x00, 0x00, // flags |
| 464 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID |
| 465 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B, |
| 466 0x00, 0x00, 0x00, 0x02, // key count |
| 467 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1 |
| 468 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, |
| 469 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, // key2 |
| 470 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, |
| 471 0x00, 0x00, 0x00, 0x00 // datasize |
| 472 }; |
| 473 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsJSONDictionary(), |
| 474 GURL::EmptyGURL())); |
| 475 decryptor_.CreateSessionAndGenerateRequest( |
| 476 MediaKeys::TEMPORARY_SESSION, "cenc", init_data, arraysize(init_data), |
| 477 CreateSessionPromise(RESOLVED)); |
| 478 } |
| 479 |
| 480 TEST_F(AesDecryptorTest, CreateSessionWithKeyIdsInitData) { |
| 481 const char init_data[] = |
| 482 "{\"kids\":[\"AQI\",\"AQIDBA\",\"AQIDBAUGBwgJCgsMDQ4PEA\"]}"; |
| 483 |
| 484 EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsJSONDictionary(), |
| 485 GURL::EmptyGURL())); |
| 486 decryptor_.CreateSessionAndGenerateRequest( |
| 487 MediaKeys::TEMPORARY_SESSION, "keyids", |
| 488 reinterpret_cast<const uint8*>(init_data), arraysize(init_data) - 1, |
| 489 CreateSessionPromise(RESOLVED)); |
| 490 } |
| 491 |
457 TEST_F(AesDecryptorTest, NormalDecryption) { | 492 TEST_F(AesDecryptorTest, NormalDecryption) { |
458 std::string session_id = CreateSession(key_id_); | 493 std::string session_id = CreateSession(key_id_); |
459 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED); | 494 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED); |
460 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer( | 495 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer( |
461 encrypted_data_, key_id_, iv_, no_subsample_entries_); | 496 encrypted_data_, key_id_, iv_, no_subsample_entries_); |
462 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS); | 497 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS); |
463 } | 498 } |
464 | 499 |
465 TEST_F(AesDecryptorTest, UnencryptedFrame) { | 500 TEST_F(AesDecryptorTest, UnencryptedFrame) { |
466 // An empty iv string signals that the frame is unencrypted. | 501 // An empty iv string signals that the frame is unencrypted. |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 EXPECT_TRUE(KeysInfoContains(key_id1)); | 906 EXPECT_TRUE(KeysInfoContains(key_id1)); |
872 EXPECT_FALSE(KeysInfoContains(key_id2)); | 907 EXPECT_FALSE(KeysInfoContains(key_id2)); |
873 | 908 |
874 // Add second key, verify both IDs returned. | 909 // Add second key, verify both IDs returned. |
875 UpdateSessionAndExpect(session_id, kKey2AsJWK, RESOLVED); | 910 UpdateSessionAndExpect(session_id, kKey2AsJWK, RESOLVED); |
876 EXPECT_TRUE(KeysInfoContains(key_id1)); | 911 EXPECT_TRUE(KeysInfoContains(key_id1)); |
877 EXPECT_TRUE(KeysInfoContains(key_id2)); | 912 EXPECT_TRUE(KeysInfoContains(key_id2)); |
878 } | 913 } |
879 | 914 |
880 } // namespace media | 915 } // namespace media |
OLD | NEW |