| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "media/base/cdm_callback_promise.h" | 9 #include "media/base/cdm_callback_promise.h" |
| 10 #include "media/base/cdm_key_information.h" | 10 #include "media/base/cdm_key_information.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 // TODO(jrummell): These tests are a subset of those in aes_decryptor_unittest. | 23 // TODO(jrummell): These tests are a subset of those in aes_decryptor_unittest. |
| 24 // Refactor aes_decryptor_unittest.cc to handle AesDecryptor directly and | 24 // Refactor aes_decryptor_unittest.cc to handle AesDecryptor directly and |
| 25 // via CdmAdapter once CdmAdapter supports decrypting functionality. There | 25 // via CdmAdapter once CdmAdapter supports decrypting functionality. There |
| 26 // will also be tests that only CdmAdapter supports, like file IO, which | 26 // will also be tests that only CdmAdapter supports, like file IO, which |
| 27 // will need to be handled separately. | 27 // will need to be handled separately. |
| 28 | 28 |
| 29 namespace media { | 29 namespace media { |
| 30 | 30 |
| 31 // Random key ID used to create a session. | 31 // Random key ID used to create a session. |
| 32 const uint8 kKeyId[] = { | 32 const uint8_t kKeyId[] = { |
| 33 // base64 equivalent is AQIDBAUGBwgJCgsMDQ4PEA | 33 // base64 equivalent is AQIDBAUGBwgJCgsMDQ4PEA |
| 34 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, | 34 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
| 35 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, | 35 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 const char kKeyIdAsJWK[] = "{\"kids\": [\"AQIDBAUGBwgJCgsMDQ4PEA\"]}"; | 38 const char kKeyIdAsJWK[] = "{\"kids\": [\"AQIDBAUGBwgJCgsMDQ4PEA\"]}"; |
| 39 | 39 |
| 40 const uint8 kKeyIdAsPssh[] = { | 40 const uint8_t kKeyIdAsPssh[] = { |
| 41 0x00, 0x00, 0x00, 0x00, 'p', 's', 's', 'h', // size = 0 | 41 0x00, 0x00, 0x00, 0x00, 'p', 's', 's', 'h', // size = 0 |
| 42 0x01, // version = 1 | 42 0x01, // version = 1 |
| 43 0x00, 0x00, 0x00, // flags | 43 0x00, 0x00, 0x00, // flags |
| 44 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // Common SystemID | 44 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // Common SystemID |
| 45 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B, | 45 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B, |
| 46 0x00, 0x00, 0x00, 0x01, // key count | 46 0x00, 0x00, 0x00, 0x01, // key count |
| 47 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, // key | 47 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, // key |
| 48 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, | 48 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, |
| 49 0x00, 0x00, 0x00, 0x00, // datasize | 49 0x00, 0x00, 0x00, 0x00, // datasize |
| 50 }; | 50 }; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 base::Unretained(this)), | 90 base::Unretained(this)), |
| 91 base::Bind(&CdmAdapterTest::OnCdmCreated, base::Unretained(this), | 91 base::Bind(&CdmAdapterTest::OnCdmCreated, base::Unretained(this), |
| 92 expected_result)); | 92 expected_result)); |
| 93 RunUntilIdle(); | 93 RunUntilIdle(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 // Creates a new session using |key_id|. |session_id_| will be set | 96 // Creates a new session using |key_id|. |session_id_| will be set |
| 97 // when the promise is resolved. |expected_result| tests that | 97 // when the promise is resolved. |expected_result| tests that |
| 98 // CreateSessionAndGenerateRequest() succeeds or generates an error. | 98 // CreateSessionAndGenerateRequest() succeeds or generates an error. |
| 99 void CreateSessionAndExpect(EmeInitDataType data_type, | 99 void CreateSessionAndExpect(EmeInitDataType data_type, |
| 100 const std::vector<uint8>& key_id, | 100 const std::vector<uint8_t>& key_id, |
| 101 ExpectedResult expected_result) { | 101 ExpectedResult expected_result) { |
| 102 DCHECK(!key_id.empty()); | 102 DCHECK(!key_id.empty()); |
| 103 | 103 |
| 104 if (expected_result == SUCCESS) { | 104 if (expected_result == SUCCESS) { |
| 105 EXPECT_CALL(*this, | 105 EXPECT_CALL(*this, |
| 106 OnSessionMessage(IsNotEmpty(), _, _, GURL::EmptyGURL())); | 106 OnSessionMessage(IsNotEmpty(), _, _, GURL::EmptyGURL())); |
| 107 } | 107 } |
| 108 | 108 |
| 109 adapter_->CreateSessionAndGenerateRequest( | 109 adapter_->CreateSessionAndGenerateRequest( |
| 110 MediaKeys::TEMPORARY_SESSION, data_type, key_id, | 110 MediaKeys::TEMPORARY_SESSION, data_type, key_id, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 134 DCHECK(!key.empty()); | 134 DCHECK(!key.empty()); |
| 135 | 135 |
| 136 if (expected_result == SUCCESS) { | 136 if (expected_result == SUCCESS) { |
| 137 EXPECT_CALL(*this, | 137 EXPECT_CALL(*this, |
| 138 OnSessionKeysChangeCalled(session_id, new_key_expected)); | 138 OnSessionKeysChangeCalled(session_id, new_key_expected)); |
| 139 } else { | 139 } else { |
| 140 EXPECT_CALL(*this, OnSessionKeysChangeCalled(_, _)).Times(0); | 140 EXPECT_CALL(*this, OnSessionKeysChangeCalled(_, _)).Times(0); |
| 141 } | 141 } |
| 142 | 142 |
| 143 adapter_->UpdateSession(session_id, | 143 adapter_->UpdateSession(session_id, |
| 144 std::vector<uint8>(key.begin(), key.end()), | 144 std::vector<uint8_t>(key.begin(), key.end()), |
| 145 CreatePromise(expected_result)); | 145 CreatePromise(expected_result)); |
| 146 RunUntilIdle(); | 146 RunUntilIdle(); |
| 147 } | 147 } |
| 148 | 148 |
| 149 base::FilePath ExternalClearKeyLibrary() { return helper_.LibraryPath(); } | 149 base::FilePath ExternalClearKeyLibrary() { return helper_.LibraryPath(); } |
| 150 | 150 |
| 151 std::string SessionId() { return session_id_; } | 151 std::string SessionId() { return session_id_; } |
| 152 | 152 |
| 153 private: | 153 private: |
| 154 void OnCdmCreated(ExpectedResult expected_result, | 154 void OnCdmCreated(ExpectedResult expected_result, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 return promise.Pass(); | 196 return promise.Pass(); |
| 197 } | 197 } |
| 198 | 198 |
| 199 void RunUntilIdle() { message_loop_.RunUntilIdle(); } | 199 void RunUntilIdle() { message_loop_.RunUntilIdle(); } |
| 200 | 200 |
| 201 // Methods used for promise resolved/rejected. | 201 // Methods used for promise resolved/rejected. |
| 202 MOCK_METHOD0(OnResolve, void()); | 202 MOCK_METHOD0(OnResolve, void()); |
| 203 MOCK_METHOD1(OnResolveWithSession, void(const std::string& session_id)); | 203 MOCK_METHOD1(OnResolveWithSession, void(const std::string& session_id)); |
| 204 MOCK_METHOD3(OnReject, | 204 MOCK_METHOD3(OnReject, |
| 205 void(MediaKeys::Exception exception_code, | 205 void(MediaKeys::Exception exception_code, |
| 206 uint32 system_code, | 206 uint32_t system_code, |
| 207 const std::string& error_message)); | 207 const std::string& error_message)); |
| 208 | 208 |
| 209 // Methods used for the events possibly generated by CdmAdapater. | 209 // Methods used for the events possibly generated by CdmAdapater. |
| 210 MOCK_METHOD4(OnSessionMessage, | 210 MOCK_METHOD4(OnSessionMessage, |
| 211 void(const std::string& session_id, | 211 void(const std::string& session_id, |
| 212 MediaKeys::MessageType message_type, | 212 MediaKeys::MessageType message_type, |
| 213 const std::vector<uint8_t>& message, | 213 const std::vector<uint8_t>& message, |
| 214 const GURL& legacy_destination_url)); | 214 const GURL& legacy_destination_url)); |
| 215 MOCK_METHOD1(OnSessionClosed, void(const std::string& session_id)); | 215 MOCK_METHOD1(OnSessionClosed, void(const std::string& session_id)); |
| 216 MOCK_METHOD4(OnLegacySessionError, | 216 MOCK_METHOD4(OnLegacySessionError, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 } | 250 } |
| 251 | 251 |
| 252 TEST_F(CdmAdapterTest, BadLibraryPath) { | 252 TEST_F(CdmAdapterTest, BadLibraryPath) { |
| 253 InitializeAndExpect(base::FilePath(FILE_PATH_LITERAL("no_library_here")), | 253 InitializeAndExpect(base::FilePath(FILE_PATH_LITERAL("no_library_here")), |
| 254 FAILURE); | 254 FAILURE); |
| 255 } | 255 } |
| 256 | 256 |
| 257 TEST_F(CdmAdapterTest, CreateWebmSession) { | 257 TEST_F(CdmAdapterTest, CreateWebmSession) { |
| 258 InitializeAndExpect(ExternalClearKeyLibrary(), SUCCESS); | 258 InitializeAndExpect(ExternalClearKeyLibrary(), SUCCESS); |
| 259 | 259 |
| 260 std::vector<uint8> key_id(kKeyId, kKeyId + arraysize(kKeyId)); | 260 std::vector<uint8_t> key_id(kKeyId, kKeyId + arraysize(kKeyId)); |
| 261 CreateSessionAndExpect(EmeInitDataType::WEBM, key_id, SUCCESS); | 261 CreateSessionAndExpect(EmeInitDataType::WEBM, key_id, SUCCESS); |
| 262 } | 262 } |
| 263 | 263 |
| 264 TEST_F(CdmAdapterTest, CreateKeyIdsSession) { | 264 TEST_F(CdmAdapterTest, CreateKeyIdsSession) { |
| 265 InitializeAndExpect(ExternalClearKeyLibrary(), SUCCESS); | 265 InitializeAndExpect(ExternalClearKeyLibrary(), SUCCESS); |
| 266 | 266 |
| 267 // Don't include the trailing /0 from the string in the data passed in. | 267 // Don't include the trailing /0 from the string in the data passed in. |
| 268 std::vector<uint8> key_id(kKeyIdAsJWK, | 268 std::vector<uint8_t> key_id(kKeyIdAsJWK, |
| 269 kKeyIdAsJWK + arraysize(kKeyIdAsJWK) - 1); | 269 kKeyIdAsJWK + arraysize(kKeyIdAsJWK) - 1); |
| 270 CreateSessionAndExpect(EmeInitDataType::KEYIDS, key_id, SUCCESS); | 270 CreateSessionAndExpect(EmeInitDataType::KEYIDS, key_id, SUCCESS); |
| 271 } | 271 } |
| 272 | 272 |
| 273 TEST_F(CdmAdapterTest, CreateCencSession) { | 273 TEST_F(CdmAdapterTest, CreateCencSession) { |
| 274 InitializeAndExpect(ExternalClearKeyLibrary(), SUCCESS); | 274 InitializeAndExpect(ExternalClearKeyLibrary(), SUCCESS); |
| 275 | 275 |
| 276 std::vector<uint8> key_id(kKeyIdAsPssh, | 276 std::vector<uint8_t> key_id(kKeyIdAsPssh, |
| 277 kKeyIdAsPssh + arraysize(kKeyIdAsPssh)); | 277 kKeyIdAsPssh + arraysize(kKeyIdAsPssh)); |
| 278 #if defined(USE_PROPRIETARY_CODECS) | 278 #if defined(USE_PROPRIETARY_CODECS) |
| 279 CreateSessionAndExpect(EmeInitDataType::CENC, key_id, SUCCESS); | 279 CreateSessionAndExpect(EmeInitDataType::CENC, key_id, SUCCESS); |
| 280 #else | 280 #else |
| 281 CreateSessionAndExpect(EmeInitDataType::CENC, key_id, FAILURE); | 281 CreateSessionAndExpect(EmeInitDataType::CENC, key_id, FAILURE); |
| 282 #endif | 282 #endif |
| 283 } | 283 } |
| 284 | 284 |
| 285 TEST_F(CdmAdapterTest, CreateSessionWithBadData) { | 285 TEST_F(CdmAdapterTest, CreateSessionWithBadData) { |
| 286 InitializeAndExpect(ExternalClearKeyLibrary(), SUCCESS); | 286 InitializeAndExpect(ExternalClearKeyLibrary(), SUCCESS); |
| 287 | 287 |
| 288 // Use |kKeyId| but specify KEYIDS format. | 288 // Use |kKeyId| but specify KEYIDS format. |
| 289 std::vector<uint8> key_id(kKeyId, kKeyId + arraysize(kKeyId)); | 289 std::vector<uint8_t> key_id(kKeyId, kKeyId + arraysize(kKeyId)); |
| 290 CreateSessionAndExpect(EmeInitDataType::KEYIDS, key_id, FAILURE); | 290 CreateSessionAndExpect(EmeInitDataType::KEYIDS, key_id, FAILURE); |
| 291 } | 291 } |
| 292 | 292 |
| 293 TEST_F(CdmAdapterTest, LoadSession) { | 293 TEST_F(CdmAdapterTest, LoadSession) { |
| 294 InitializeAndExpect(ExternalClearKeyLibrary(), SUCCESS); | 294 InitializeAndExpect(ExternalClearKeyLibrary(), SUCCESS); |
| 295 | 295 |
| 296 // LoadSession() is not supported by AesDecryptor. | 296 // LoadSession() is not supported by AesDecryptor. |
| 297 std::vector<uint8> key_id(kKeyId, kKeyId + arraysize(kKeyId)); | 297 std::vector<uint8_t> key_id(kKeyId, kKeyId + arraysize(kKeyId)); |
| 298 CreateSessionAndExpect(EmeInitDataType::KEYIDS, key_id, FAILURE); | 298 CreateSessionAndExpect(EmeInitDataType::KEYIDS, key_id, FAILURE); |
| 299 } | 299 } |
| 300 | 300 |
| 301 TEST_F(CdmAdapterTest, UpdateSession) { | 301 TEST_F(CdmAdapterTest, UpdateSession) { |
| 302 InitializeAndExpect(ExternalClearKeyLibrary(), SUCCESS); | 302 InitializeAndExpect(ExternalClearKeyLibrary(), SUCCESS); |
| 303 | 303 |
| 304 std::vector<uint8> key_id(kKeyId, kKeyId + arraysize(kKeyId)); | 304 std::vector<uint8_t> key_id(kKeyId, kKeyId + arraysize(kKeyId)); |
| 305 CreateSessionAndExpect(EmeInitDataType::WEBM, key_id, SUCCESS); | 305 CreateSessionAndExpect(EmeInitDataType::WEBM, key_id, SUCCESS); |
| 306 | 306 |
| 307 UpdateSessionAndExpect(SessionId(), kKeyAsJWK, SUCCESS, true); | 307 UpdateSessionAndExpect(SessionId(), kKeyAsJWK, SUCCESS, true); |
| 308 } | 308 } |
| 309 | 309 |
| 310 TEST_F(CdmAdapterTest, UpdateSessionWithBadData) { | 310 TEST_F(CdmAdapterTest, UpdateSessionWithBadData) { |
| 311 InitializeAndExpect(ExternalClearKeyLibrary(), SUCCESS); | 311 InitializeAndExpect(ExternalClearKeyLibrary(), SUCCESS); |
| 312 | 312 |
| 313 std::vector<uint8> key_id(kKeyId, kKeyId + arraysize(kKeyId)); | 313 std::vector<uint8_t> key_id(kKeyId, kKeyId + arraysize(kKeyId)); |
| 314 CreateSessionAndExpect(EmeInitDataType::WEBM, key_id, SUCCESS); | 314 CreateSessionAndExpect(EmeInitDataType::WEBM, key_id, SUCCESS); |
| 315 | 315 |
| 316 UpdateSessionAndExpect(SessionId(), "random data", FAILURE, true); | 316 UpdateSessionAndExpect(SessionId(), "random data", FAILURE, true); |
| 317 } | 317 } |
| 318 | 318 |
| 319 } // namespace media | 319 } // namespace media |
| OLD | NEW |