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/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "media/base/cdm_callback_promise.h" | 14 #include "media/base/cdm_callback_promise.h" |
15 #include "media/base/cdm_key_information.h" | 15 #include "media/base/cdm_key_information.h" |
16 #include "media/base/media_keys.h" | 16 #include "media/base/content_decryption_module.h" |
17 #include "media/base/mock_filters.h" | 17 #include "media/base/mock_filters.h" |
18 #include "media/cdm/cdm_file_io.h" | 18 #include "media/cdm/cdm_file_io.h" |
19 #include "media/cdm/external_clear_key_test_helper.h" | 19 #include "media/cdm/external_clear_key_test_helper.h" |
20 #include "media/cdm/simple_cdm_allocator.h" | 20 #include "media/cdm/simple_cdm_allocator.h" |
21 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
23 | 23 |
24 using ::testing::_; | 24 using ::testing::_; |
25 using ::testing::SaveArg; | 25 using ::testing::SaveArg; |
26 using ::testing::StrictMock; | 26 using ::testing::StrictMock; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 void CreateSessionAndExpect(EmeInitDataType data_type, | 110 void CreateSessionAndExpect(EmeInitDataType data_type, |
111 const std::vector<uint8_t>& key_id, | 111 const std::vector<uint8_t>& key_id, |
112 ExpectedResult expected_result) { | 112 ExpectedResult expected_result) { |
113 DCHECK(!key_id.empty()); | 113 DCHECK(!key_id.empty()); |
114 | 114 |
115 if (expected_result == SUCCESS) { | 115 if (expected_result == SUCCESS) { |
116 EXPECT_CALL(cdm_client_, OnSessionMessage(IsNotEmpty(), _, _)); | 116 EXPECT_CALL(cdm_client_, OnSessionMessage(IsNotEmpty(), _, _)); |
117 } | 117 } |
118 | 118 |
119 adapter_->CreateSessionAndGenerateRequest( | 119 adapter_->CreateSessionAndGenerateRequest( |
120 MediaKeys::TEMPORARY_SESSION, data_type, key_id, | 120 ContentDecryptionModule::TEMPORARY_SESSION, data_type, key_id, |
121 CreateSessionPromise(expected_result)); | 121 CreateSessionPromise(expected_result)); |
122 RunUntilIdle(); | 122 RunUntilIdle(); |
123 } | 123 } |
124 | 124 |
125 // Loads the session specified by |session_id|. |expected_result| tests | 125 // Loads the session specified by |session_id|. |expected_result| tests |
126 // that LoadSession() succeeds or generates an error. | 126 // that LoadSession() succeeds or generates an error. |
127 void LoadSessionAndExpect(const std::string& session_id, | 127 void LoadSessionAndExpect(const std::string& session_id, |
128 ExpectedResult expected_result) { | 128 ExpectedResult expected_result) { |
129 DCHECK(!session_id.empty()); | 129 DCHECK(!session_id.empty()); |
130 ASSERT_EQ(expected_result, FAILURE) << "LoadSession not supported."; | 130 ASSERT_EQ(expected_result, FAILURE) << "LoadSession not supported."; |
131 | 131 |
132 adapter_->LoadSession(MediaKeys::TEMPORARY_SESSION, session_id, | 132 adapter_->LoadSession(ContentDecryptionModule::TEMPORARY_SESSION, |
133 CreateSessionPromise(expected_result)); | 133 session_id, CreateSessionPromise(expected_result)); |
134 RunUntilIdle(); | 134 RunUntilIdle(); |
135 } | 135 } |
136 | 136 |
137 // Updates the session specified by |session_id| with |key|. |expected_result| | 137 // Updates the session specified by |session_id| with |key|. |expected_result| |
138 // tests that the update succeeds or generates an error. |new_key_expected| | 138 // tests that the update succeeds or generates an error. |new_key_expected| |
139 // is the expected parameter when the SessionKeysChange event happens. | 139 // is the expected parameter when the SessionKeysChange event happens. |
140 void UpdateSessionAndExpect(std::string session_id, | 140 void UpdateSessionAndExpect(std::string session_id, |
141 const std::string& key, | 141 const std::string& key, |
142 ExpectedResult expected_result, | 142 ExpectedResult expected_result, |
143 bool new_key_expected) { | 143 bool new_key_expected) { |
(...skipping 11 matching lines...) Expand all Loading... |
155 CreatePromise(expected_result)); | 155 CreatePromise(expected_result)); |
156 RunUntilIdle(); | 156 RunUntilIdle(); |
157 } | 157 } |
158 | 158 |
159 base::FilePath ExternalClearKeyLibrary() { return helper_.LibraryPath(); } | 159 base::FilePath ExternalClearKeyLibrary() { return helper_.LibraryPath(); } |
160 | 160 |
161 std::string SessionId() { return session_id_; } | 161 std::string SessionId() { return session_id_; } |
162 | 162 |
163 private: | 163 private: |
164 void OnCdmCreated(ExpectedResult expected_result, | 164 void OnCdmCreated(ExpectedResult expected_result, |
165 const scoped_refptr<MediaKeys>& cdm, | 165 const scoped_refptr<ContentDecryptionModule>& cdm, |
166 const std::string& error_message) { | 166 const std::string& error_message) { |
167 if (cdm) { | 167 if (cdm) { |
168 EXPECT_EQ(expected_result, SUCCESS) << "CDM should not have loaded."; | 168 EXPECT_EQ(expected_result, SUCCESS) << "CDM should not have loaded."; |
169 adapter_ = cdm; | 169 adapter_ = cdm; |
170 } else { | 170 } else { |
171 EXPECT_EQ(expected_result, FAILURE) << error_message; | 171 EXPECT_EQ(expected_result, FAILURE) << error_message; |
172 } | 172 } |
173 } | 173 } |
174 | 174 |
175 // Create a promise. |expected_result| is used to indicate how the promise | 175 // Create a promise. |expected_result| is used to indicate how the promise |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 void(CdmPromise::Exception exception_code, | 221 void(CdmPromise::Exception exception_code, |
222 uint32_t system_code, | 222 uint32_t system_code, |
223 const std::string& error_message)); | 223 const std::string& error_message)); |
224 | 224 |
225 StrictMock<MockCdmClient> cdm_client_; | 225 StrictMock<MockCdmClient> cdm_client_; |
226 | 226 |
227 // Helper class to load/unload External Clear Key Library. | 227 // Helper class to load/unload External Clear Key Library. |
228 ExternalClearKeyTestHelper helper_; | 228 ExternalClearKeyTestHelper helper_; |
229 | 229 |
230 // Keep track of the loaded CDM. | 230 // Keep track of the loaded CDM. |
231 scoped_refptr<MediaKeys> adapter_; | 231 scoped_refptr<ContentDecryptionModule> adapter_; |
232 | 232 |
233 // |session_id_| is the latest result of calling CreateSession(). | 233 // |session_id_| is the latest result of calling CreateSession(). |
234 std::string session_id_; | 234 std::string session_id_; |
235 | 235 |
236 base::MessageLoop message_loop_; | 236 base::MessageLoop message_loop_; |
237 | 237 |
238 DISALLOW_COPY_AND_ASSIGN(CdmAdapterTest); | 238 DISALLOW_COPY_AND_ASSIGN(CdmAdapterTest); |
239 }; | 239 }; |
240 | 240 |
241 TEST_F(CdmAdapterTest, Initialize) { | 241 TEST_F(CdmAdapterTest, Initialize) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 TEST_F(CdmAdapterTest, UpdateSessionWithBadData) { | 303 TEST_F(CdmAdapterTest, UpdateSessionWithBadData) { |
304 InitializeAndExpect(ExternalClearKeyLibrary(), SUCCESS); | 304 InitializeAndExpect(ExternalClearKeyLibrary(), SUCCESS); |
305 | 305 |
306 std::vector<uint8_t> key_id(kKeyId, kKeyId + arraysize(kKeyId)); | 306 std::vector<uint8_t> key_id(kKeyId, kKeyId + arraysize(kKeyId)); |
307 CreateSessionAndExpect(EmeInitDataType::WEBM, key_id, SUCCESS); | 307 CreateSessionAndExpect(EmeInitDataType::WEBM, key_id, SUCCESS); |
308 | 308 |
309 UpdateSessionAndExpect(SessionId(), "random data", FAILURE, true); | 309 UpdateSessionAndExpect(SessionId(), "random data", FAILURE, true); |
310 } | 310 } |
311 | 311 |
312 } // namespace media | 312 } // namespace media |
OLD | NEW |