OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/base/mock_filters.h" | 5 #include "media/base/mock_filters.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 | 8 |
9 using ::testing::_; | 9 using ::testing::_; |
10 using ::testing::Return; | 10 using ::testing::Return; |
11 using ::testing::SaveArg; | 11 using ::testing::SaveArg; |
| 12 using ::testing::StrictMock; |
12 | 13 |
13 MATCHER(NotEmpty, "") { | 14 MATCHER(NotEmpty, "") { |
14 return !arg.empty(); | 15 return !arg.empty(); |
15 } | 16 } |
16 | 17 |
17 namespace media { | 18 namespace media { |
18 | 19 |
19 MockPipelineClient::MockPipelineClient() {} | 20 MockPipelineClient::MockPipelineClient() {} |
20 MockPipelineClient::~MockPipelineClient() {} | 21 MockPipelineClient::~MockPipelineClient() {} |
21 | 22 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 EXPECT_CALL(*this, resolve(_)).Times(0); | 174 EXPECT_CALL(*this, resolve(_)).Times(0); |
174 EXPECT_CALL(*this, reject(_, _, NotEmpty())); | 175 EXPECT_CALL(*this, reject(_, _, NotEmpty())); |
175 } | 176 } |
176 } | 177 } |
177 | 178 |
178 MockCdmSessionPromise::~MockCdmSessionPromise() { | 179 MockCdmSessionPromise::~MockCdmSessionPromise() { |
179 // The EXPECT calls will verify that the promise is in fact fulfilled. | 180 // The EXPECT calls will verify that the promise is in fact fulfilled. |
180 MarkPromiseSettled(); | 181 MarkPromiseSettled(); |
181 } | 182 } |
182 | 183 |
| 184 MockCdm::MockCdm(const SessionMessageCB& session_message_cb, |
| 185 const SessionClosedCB& session_closed_cb, |
| 186 const SessionKeysChangeCB& session_keys_change_cb, |
| 187 const SessionExpirationUpdateCB& session_expiration_update_cb) |
| 188 : session_message_cb_(session_message_cb), |
| 189 session_closed_cb_(session_closed_cb), |
| 190 session_keys_change_cb_(session_keys_change_cb), |
| 191 session_expiration_update_cb_(session_expiration_update_cb) {} |
| 192 |
| 193 MockCdm::~MockCdm() {} |
| 194 |
| 195 void MockCdm::SetServerCertificate(const std::vector<uint8_t>& certificate, |
| 196 std::unique_ptr<SimpleCdmPromise> promise) { |
| 197 OnSetServerCertificate(certificate, promise); |
| 198 } |
| 199 |
| 200 void MockCdm::CreateSessionAndGenerateRequest( |
| 201 CdmSessionType session_type, |
| 202 EmeInitDataType init_data_type, |
| 203 const std::vector<uint8_t>& init_data, |
| 204 std::unique_ptr<NewSessionCdmPromise> promise) { |
| 205 OnCreateSessionAndGenerateRequest(session_type, init_data_type, init_data, |
| 206 promise); |
| 207 } |
| 208 |
| 209 void MockCdm::LoadSession(CdmSessionType session_type, |
| 210 const std::string& session_id, |
| 211 std::unique_ptr<NewSessionCdmPromise> promise) { |
| 212 OnLoadSession(session_type, session_id, promise); |
| 213 } |
| 214 |
| 215 void MockCdm::UpdateSession(const std::string& session_id, |
| 216 const std::vector<uint8_t>& response, |
| 217 std::unique_ptr<SimpleCdmPromise> promise) { |
| 218 OnUpdateSession(session_id, response, promise); |
| 219 } |
| 220 |
| 221 void MockCdm::CloseSession(const std::string& session_id, |
| 222 std::unique_ptr<SimpleCdmPromise> promise) { |
| 223 OnCloseSession(session_id, promise); |
| 224 } |
| 225 |
| 226 void MockCdm::RemoveSession(const std::string& session_id, |
| 227 std::unique_ptr<SimpleCdmPromise> promise) { |
| 228 OnRemoveSession(session_id, promise); |
| 229 } |
| 230 |
| 231 void MockCdm::CallSessionMessageCB( |
| 232 const std::string& session_id, |
| 233 ContentDecryptionModule::MessageType message_type, |
| 234 const std::vector<uint8_t>& message) { |
| 235 session_message_cb_.Run(session_id, message_type, message); |
| 236 } |
| 237 |
| 238 void MockCdm::CallSessionClosedCB(const std::string& session_id) { |
| 239 session_closed_cb_.Run(session_id); |
| 240 } |
| 241 |
| 242 void MockCdm::CallSessionKeysChangeCB(const std::string& session_id, |
| 243 bool has_additional_usable_key, |
| 244 CdmKeysInfo keys_info) { |
| 245 session_keys_change_cb_.Run(session_id, has_additional_usable_key, |
| 246 std::move(keys_info)); |
| 247 } |
| 248 |
| 249 void MockCdm::CallSessionExpirationUpdateCB(const std::string& session_id, |
| 250 base::Time new_expiry_time) { |
| 251 session_expiration_update_cb_.Run(session_id, new_expiry_time); |
| 252 } |
| 253 |
| 254 MockCdmFactory::MockCdmFactory() {} |
| 255 |
| 256 MockCdmFactory::~MockCdmFactory() {} |
| 257 |
| 258 void MockCdmFactory::Create( |
| 259 const std::string& key_system, |
| 260 const GURL& security_origin, |
| 261 const CdmConfig& cdm_config, |
| 262 const SessionMessageCB& session_message_cb, |
| 263 const SessionClosedCB& session_closed_cb, |
| 264 const SessionKeysChangeCB& session_keys_change_cb, |
| 265 const SessionExpirationUpdateCB& session_expiration_update_cb, |
| 266 const CdmCreatedCB& cdm_created_cb) { |
| 267 // If no key system specified, notify that Create() failed. |
| 268 if (key_system.empty()) { |
| 269 cdm_created_cb.Run(nullptr, "CDM creation failed"); |
| 270 return; |
| 271 } |
| 272 |
| 273 // Since there is a CDM, call |before_creation_cb_| first. |
| 274 if (!before_creation_cb_.is_null()) |
| 275 before_creation_cb_.Run(); |
| 276 |
| 277 // Create and return a new MockCdm. Keep a pointer to the created CDM so |
| 278 // that tests can access it. Calls to GetCdmContext() can be ignored. |
| 279 scoped_refptr<MockCdm> cdm = new StrictMock<MockCdm>( |
| 280 session_message_cb, session_closed_cb, session_keys_change_cb, |
| 281 session_expiration_update_cb); |
| 282 created_cdm_ = cdm.get(); |
| 283 EXPECT_CALL(*created_cdm_.get(), GetCdmContext()); |
| 284 cdm_created_cb.Run(std::move(cdm), ""); |
| 285 } |
| 286 |
| 287 MockCdm* MockCdmFactory::GetCreatedCdm() { |
| 288 return created_cdm_.get(); |
| 289 } |
| 290 |
| 291 void MockCdmFactory::SetBeforeCreationCB( |
| 292 const base::Closure& before_creation_cb) { |
| 293 before_creation_cb_ = before_creation_cb; |
| 294 } |
| 295 |
183 MockStreamParser::MockStreamParser() {} | 296 MockStreamParser::MockStreamParser() {} |
184 | 297 |
185 MockStreamParser::~MockStreamParser() {} | 298 MockStreamParser::~MockStreamParser() {} |
186 | 299 |
187 } // namespace media | 300 } // namespace media |
OLD | NEW |