| 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 "media/cdm/cdm_adapter.h" | 5 #include "media/cdm/cdm_adapter.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 15 #include "media/base/cdm_callback_promise.h" | 14 #include "media/base/cdm_callback_promise.h" |
| 16 #include "media/base/cdm_key_information.h" | 15 #include "media/base/cdm_key_information.h" |
| 17 #include "media/base/media_keys.h" | 16 #include "media/base/media_keys.h" |
| 18 #include "media/cdm/cdm_file_io.h" | 17 #include "media/cdm/cdm_file_io.h" |
| 19 #include "media/cdm/external_clear_key_test_helper.h" | 18 #include "media/cdm/external_clear_key_test_helper.h" |
| 20 #include "media/cdm/simple_cdm_allocator.h" | 19 #include "media/cdm/simple_cdm_allocator.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 22 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 76 |
| 78 CdmAdapterTest() {} | 77 CdmAdapterTest() {} |
| 79 ~CdmAdapterTest() override {} | 78 ~CdmAdapterTest() override {} |
| 80 | 79 |
| 81 protected: | 80 protected: |
| 82 // Initializes the adapter. |expected_result| tests that the call succeeds | 81 // Initializes the adapter. |expected_result| tests that the call succeeds |
| 83 // or generates an error. | 82 // or generates an error. |
| 84 void InitializeAndExpect(base::FilePath library_path, | 83 void InitializeAndExpect(base::FilePath library_path, |
| 85 ExpectedResult expected_result) { | 84 ExpectedResult expected_result) { |
| 86 CdmConfig cdm_config; // default settings of false are sufficient. | 85 CdmConfig cdm_config; // default settings of false are sufficient. |
| 87 scoped_ptr<CdmAllocator> allocator(new SimpleCdmAllocator()); | 86 std::unique_ptr<CdmAllocator> allocator(new SimpleCdmAllocator()); |
| 88 CdmAdapter::Create( | 87 CdmAdapter::Create( |
| 89 helper_.KeySystemName(), library_path, cdm_config, std::move(allocator), | 88 helper_.KeySystemName(), library_path, cdm_config, std::move(allocator), |
| 90 base::Bind(&CdmAdapterTest::CreateCdmFileIO, base::Unretained(this)), | 89 base::Bind(&CdmAdapterTest::CreateCdmFileIO, base::Unretained(this)), |
| 91 base::Bind(&CdmAdapterTest::OnSessionMessage, base::Unretained(this)), | 90 base::Bind(&CdmAdapterTest::OnSessionMessage, base::Unretained(this)), |
| 92 base::Bind(&CdmAdapterTest::OnSessionClosed, base::Unretained(this)), | 91 base::Bind(&CdmAdapterTest::OnSessionClosed, base::Unretained(this)), |
| 93 base::Bind(&CdmAdapterTest::OnLegacySessionError, | 92 base::Bind(&CdmAdapterTest::OnLegacySessionError, |
| 94 base::Unretained(this)), | 93 base::Unretained(this)), |
| 95 base::Bind(&CdmAdapterTest::OnSessionKeysChange, | 94 base::Bind(&CdmAdapterTest::OnSessionKeysChange, |
| 96 base::Unretained(this)), | 95 base::Unretained(this)), |
| 97 base::Bind(&CdmAdapterTest::OnSessionExpirationUpdate, | 96 base::Bind(&CdmAdapterTest::OnSessionExpirationUpdate, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 if (cdm) { | 164 if (cdm) { |
| 166 EXPECT_EQ(expected_result, SUCCESS) << "CDM should not have loaded."; | 165 EXPECT_EQ(expected_result, SUCCESS) << "CDM should not have loaded."; |
| 167 adapter_ = cdm; | 166 adapter_ = cdm; |
| 168 } else { | 167 } else { |
| 169 EXPECT_EQ(expected_result, FAILURE) << error_message; | 168 EXPECT_EQ(expected_result, FAILURE) << error_message; |
| 170 } | 169 } |
| 171 } | 170 } |
| 172 | 171 |
| 173 // Create a promise. |expected_result| is used to indicate how the promise | 172 // Create a promise. |expected_result| is used to indicate how the promise |
| 174 // should be fulfilled. | 173 // should be fulfilled. |
| 175 scoped_ptr<SimpleCdmPromise> CreatePromise(ExpectedResult expected_result) { | 174 std::unique_ptr<SimpleCdmPromise> CreatePromise( |
| 175 ExpectedResult expected_result) { |
| 176 if (expected_result == SUCCESS) { | 176 if (expected_result == SUCCESS) { |
| 177 EXPECT_CALL(*this, OnResolve()); | 177 EXPECT_CALL(*this, OnResolve()); |
| 178 } else { | 178 } else { |
| 179 EXPECT_CALL(*this, OnReject(_, _, IsNotEmpty())); | 179 EXPECT_CALL(*this, OnReject(_, _, IsNotEmpty())); |
| 180 } | 180 } |
| 181 | 181 |
| 182 scoped_ptr<SimpleCdmPromise> promise(new CdmCallbackPromise<>( | 182 std::unique_ptr<SimpleCdmPromise> promise(new CdmCallbackPromise<>( |
| 183 base::Bind(&CdmAdapterTest::OnResolve, base::Unretained(this)), | 183 base::Bind(&CdmAdapterTest::OnResolve, base::Unretained(this)), |
| 184 base::Bind(&CdmAdapterTest::OnReject, base::Unretained(this)))); | 184 base::Bind(&CdmAdapterTest::OnReject, base::Unretained(this)))); |
| 185 return promise; | 185 return promise; |
| 186 } | 186 } |
| 187 | 187 |
| 188 // Create a promise to be used when a new session is created. | 188 // Create a promise to be used when a new session is created. |
| 189 // |expected_result| is used to indicate how the promise should be fulfilled. | 189 // |expected_result| is used to indicate how the promise should be fulfilled. |
| 190 scoped_ptr<NewSessionCdmPromise> CreateSessionPromise( | 190 std::unique_ptr<NewSessionCdmPromise> CreateSessionPromise( |
| 191 ExpectedResult expected_result) { | 191 ExpectedResult expected_result) { |
| 192 if (expected_result == SUCCESS) { | 192 if (expected_result == SUCCESS) { |
| 193 EXPECT_CALL(*this, OnResolveWithSession(_)) | 193 EXPECT_CALL(*this, OnResolveWithSession(_)) |
| 194 .WillOnce(SaveArg<0>(&session_id_)); | 194 .WillOnce(SaveArg<0>(&session_id_)); |
| 195 } else { | 195 } else { |
| 196 EXPECT_CALL(*this, OnReject(_, _, IsNotEmpty())); | 196 EXPECT_CALL(*this, OnReject(_, _, IsNotEmpty())); |
| 197 } | 197 } |
| 198 | 198 |
| 199 scoped_ptr<NewSessionCdmPromise> promise( | 199 std::unique_ptr<NewSessionCdmPromise> promise( |
| 200 new CdmCallbackPromise<std::string>( | 200 new CdmCallbackPromise<std::string>( |
| 201 base::Bind(&CdmAdapterTest::OnResolveWithSession, | 201 base::Bind(&CdmAdapterTest::OnResolveWithSession, |
| 202 base::Unretained(this)), | 202 base::Unretained(this)), |
| 203 base::Bind(&CdmAdapterTest::OnReject, base::Unretained(this)))); | 203 base::Bind(&CdmAdapterTest::OnReject, base::Unretained(this)))); |
| 204 return promise; | 204 return promise; |
| 205 } | 205 } |
| 206 | 206 |
| 207 void RunUntilIdle() { message_loop_.RunUntilIdle(); } | 207 void RunUntilIdle() { message_loop_.RunUntilIdle(); } |
| 208 | 208 |
| 209 std::unique_ptr<CdmFileIO> CreateCdmFileIO(cdm::FileIOClient* client) { | 209 std::unique_ptr<CdmFileIO> CreateCdmFileIO(cdm::FileIOClient* client) { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 TEST_F(CdmAdapterTest, UpdateSessionWithBadData) { | 323 TEST_F(CdmAdapterTest, UpdateSessionWithBadData) { |
| 324 InitializeAndExpect(ExternalClearKeyLibrary(), SUCCESS); | 324 InitializeAndExpect(ExternalClearKeyLibrary(), SUCCESS); |
| 325 | 325 |
| 326 std::vector<uint8_t> key_id(kKeyId, kKeyId + arraysize(kKeyId)); | 326 std::vector<uint8_t> key_id(kKeyId, kKeyId + arraysize(kKeyId)); |
| 327 CreateSessionAndExpect(EmeInitDataType::WEBM, key_id, SUCCESS); | 327 CreateSessionAndExpect(EmeInitDataType::WEBM, key_id, SUCCESS); |
| 328 | 328 |
| 329 UpdateSessionAndExpect(SessionId(), "random data", FAILURE, true); | 329 UpdateSessionAndExpect(SessionId(), "random data", FAILURE, true); |
| 330 } | 330 } |
| 331 | 331 |
| 332 } // namespace media | 332 } // namespace media |
| OLD | NEW |