Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(601)

Side by Side Diff: media/mojo/clients/mojo_cdm_unittest.cc

Issue 2592913002: [eme] Break mojo connection during call (Closed)
Patch Set: changes Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« media/base/mock_filters.cc ('K') | « media/mojo/clients/mojo_cdm.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/memory/ref_counted.h"
10 #include "base/run_loop.h" 11 #include "base/run_loop.h"
11 #include "base/test/test_message_loop.h" 12 #include "base/test/test_message_loop.h"
13 #include "base/time/time.h"
12 #include "media/base/cdm_config.h" 14 #include "media/base/cdm_config.h"
13 #include "media/base/content_decryption_module.h" 15 #include "media/base/content_decryption_module.h"
14 #include "media/base/mock_filters.h" 16 #include "media/base/mock_filters.h"
15 #include "media/cdm/default_cdm_factory.h" 17 #include "media/cdm/default_cdm_factory.h"
16 #include "media/mojo/clients/mojo_cdm.h" 18 #include "media/mojo/clients/mojo_cdm.h"
17 #include "media/mojo/interfaces/content_decryption_module.mojom.h" 19 #include "media/mojo/interfaces/content_decryption_module.mojom.h"
18 #include "media/mojo/services/mojo_cdm_service.h" 20 #include "media/mojo/services/mojo_cdm_service.h"
19 #include "media/mojo/services/mojo_cdm_service_context.h" 21 #include "media/mojo/services/mojo_cdm_service_context.h"
20 #include "mojo/public/cpp/bindings/interface_request.h" 22 #include "mojo/public/cpp/bindings/interface_request.h"
21 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
22 24
23 using ::testing::_; 25 using ::testing::_;
26 using ::testing::DoAll;
27 using ::testing::Invoke;
28 using ::testing::ReturnNull;
24 using ::testing::StrictMock; 29 using ::testing::StrictMock;
30 using ::testing::WithArg;
31 using ::testing::WithArgs;
32 using ::testing::WithoutArgs;
25 33
26 MATCHER(NotEmpty, "") { 34 MATCHER(NotEmpty, "") {
27 return !arg.empty(); 35 return !arg.empty();
28 } 36 }
29 37
38 ACTION_P2(CdmCreated, cdm, error_message) {
39 arg0.Run(cdm, error_message);
40 }
41
42 ACTION_P3(InvokeFunction, classPointer, memberFunc, p1) {
43 (classPointer->*memberFunc)(arg0, p1);
44 }
45
46 ACTION_P4(InvokeFunction2, classPointer, memberFunc, p1, p2) {
47 (classPointer->*memberFunc)(arg0, p1, p2);
48 }
49
30 namespace media { 50 namespace media {
31 51
32 namespace { 52 namespace {
33 53
34 const char kClearKeyKeySystem[] = "org.w3.clearkey"; 54 const char kClearKeyKeySystem[] = "org.w3.clearkey";
35 const char kTestSecurityOrigin[] = "https://www.test.com"; 55 const char kTestSecurityOrigin[] = "https://www.test.com";
36 56
37 // Random key ID used to create a session. 57 // Random key ID used to create a session.
38 const uint8_t kKeyId[] = { 58 const uint8_t kKeyId[] = {
39 // base64 equivalent is AQIDBAUGBwgJCgsMDQ4PEA 59 // base64 equivalent is AQIDBAUGBwgJCgsMDQ4PEA
40 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 60 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
41 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 61 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
42 }; 62 };
43 63
44 } // namespace 64 } // namespace
45 65
46 class MojoCdmTest : public ::testing::Test { 66 class MojoCdmTest : public ::testing::Test {
47 public: 67 public:
48 enum ExpectedResult { SUCCESS, CONNECTION_ERROR, FAILURE }; 68 enum ExpectedResult {
69 SUCCESS,
70 CONNECTION_ERROR_BEFORE,
71 CONNECTION_ERROR_DURING,
72 FAILURE
73 };
49 74
50 MojoCdmTest() 75 MojoCdmTest()
51 : mojo_cdm_service_(base::MakeUnique<MojoCdmService>( 76 : mojo_cdm_service_(base::MakeUnique<MojoCdmService>(
52 mojo_cdm_service_context_.GetWeakPtr(), 77 mojo_cdm_service_context_.GetWeakPtr(),
53 &cdm_factory_)), 78 &cdm_factory_)),
54 cdm_binding_(mojo_cdm_service_.get()) {} 79 cdm_binding_(mojo_cdm_service_.get()) {}
55 80
56 virtual ~MojoCdmTest() {} 81 virtual ~MojoCdmTest() {}
57 82
58 void Initialize(const std::string& key_system, 83 void Initialize(ExpectedResult expected_result) {
59 ExpectedResult expected_result) {
60 mojom::ContentDecryptionModulePtr remote_cdm; 84 mojom::ContentDecryptionModulePtr remote_cdm;
61 auto cdm_request = mojo::MakeRequest(&remote_cdm); 85 auto cdm_request = mojo::MakeRequest(&remote_cdm);
62 86
63 switch (expected_result) { 87 cdm_binding_.Bind(std::move(cdm_request));
64 case SUCCESS: 88
65 case FAILURE: 89 if (expected_result == CONNECTION_ERROR_BEFORE) {
66 cdm_binding_.Bind(std::move(cdm_request)); 90 // Break the connection before the call. No |remote_cdm_| needed.
67 break; 91 ForceConnectionError();
68 case CONNECTION_ERROR: 92 } else if (expected_result != FAILURE) {
69 cdm_request.ResetWithReason(0, "Request dropped for testing."); 93 // In the remaining cases, CDM is expected, so create one that will be
70 break; 94 // returned. Calls to GetCdmContext() can be ignored.
95 remote_cdm_ = new StrictMock<MockCdm>();
96 EXPECT_CALL(*remote_cdm_.get(), GetCdmContext());
97
98 base::Closure callback;
99 if (expected_result == CONNECTION_ERROR_DURING) {
100 // Create() will be successful, so provide a callback that will break
101 // the connection before returning |remote_cdm_|.
102 callback = base::Bind(&MojoCdmTest::ForceConnectionError,
103 base::Unretained(this));
104 }
105
106 cdm_factory_.Initialize(remote_cdm_, callback);
71 } 107 }
72 108
73 MojoCdm::Create(key_system, GURL(kTestSecurityOrigin), CdmConfig(), 109 MojoCdm::Create(kClearKeyKeySystem, GURL(kTestSecurityOrigin), CdmConfig(),
74 std::move(remote_cdm), 110 std::move(remote_cdm),
75 base::Bind(&MockCdmClient::OnSessionMessage, 111 base::Bind(&MockCdmClient::OnSessionMessage,
76 base::Unretained(&cdm_client_)), 112 base::Unretained(&cdm_client_)),
77 base::Bind(&MockCdmClient::OnSessionClosed, 113 base::Bind(&MockCdmClient::OnSessionClosed,
78 base::Unretained(&cdm_client_)), 114 base::Unretained(&cdm_client_)),
79 base::Bind(&MockCdmClient::OnSessionKeysChange, 115 base::Bind(&MockCdmClient::OnSessionKeysChange,
80 base::Unretained(&cdm_client_)), 116 base::Unretained(&cdm_client_)),
81 base::Bind(&MockCdmClient::OnSessionExpirationUpdate, 117 base::Bind(&MockCdmClient::OnSessionExpirationUpdate,
82 base::Unretained(&cdm_client_)), 118 base::Unretained(&cdm_client_)),
83 base::Bind(&MojoCdmTest::OnCdmCreated, 119 base::Bind(&MojoCdmTest::OnCdmCreated,
84 base::Unretained(this), expected_result)); 120 base::Unretained(this), expected_result));
85
86 base::RunLoop().RunUntilIdle(); 121 base::RunLoop().RunUntilIdle();
87 } 122 }
88 123
89 void OnCdmCreated(ExpectedResult expected_result, 124 void OnCdmCreated(ExpectedResult expected_result,
90 const scoped_refptr<ContentDecryptionModule>& cdm, 125 const scoped_refptr<ContentDecryptionModule>& cdm,
91 const std::string& error_message) { 126 const std::string& error_message) {
92 if (!cdm) { 127 if (!cdm) {
93 EXPECT_NE(SUCCESS, expected_result); 128 EXPECT_NE(SUCCESS, expected_result);
94 DVLOG(1) << error_message; 129 DVLOG(1) << error_message;
95 return; 130 return;
96 } 131 }
97 132
98 EXPECT_EQ(SUCCESS, expected_result); 133 EXPECT_EQ(SUCCESS, expected_result);
99 mojo_cdm_ = cdm; 134 mojo_cdm_ = cdm;
100 } 135 }
101 136
102 void ForceConnectionError() { 137 void ForceConnectionError() {
103 // If there is an existing session it will get closed when the connection
104 // is broken.
105 if (!session_id_.empty()) {
106 EXPECT_CALL(cdm_client_, OnSessionClosed(session_id_));
107 }
108
109 cdm_binding_.CloseWithReason(2, "Test closed connection."); 138 cdm_binding_.CloseWithReason(2, "Test closed connection.");
110
111 base::RunLoop().RunUntilIdle(); 139 base::RunLoop().RunUntilIdle();
112 } 140 }
113 141
114 void SetServerCertificateAndExpect(const std::vector<uint8_t>& certificate, 142 void SetServerCertificateAndExpect(const std::vector<uint8_t>& certificate,
115 ExpectedResult expected_result) { 143 ExpectedResult expected_result) {
144 if (expected_result == CONNECTION_ERROR_BEFORE) {
145 // Break the connection before the call, so SetServerCertificate() is
146 // never called.
147 ForceConnectionError();
148 } else {
149 EXPECT_CALL(*remote_cdm_.get(), OnSetServerCertificate(certificate, _))
150 .WillOnce(WithArg<1>(InvokeFunction(this, &MojoCdmTest::HandlePromise,
151 expected_result)));
152 }
153
116 mojo_cdm_->SetServerCertificate( 154 mojo_cdm_->SetServerCertificate(
117 certificate, 155 certificate,
118 base::MakeUnique<MockCdmPromise>(expected_result == SUCCESS)); 156 base::MakeUnique<MockCdmPromise>(expected_result == SUCCESS));
119 157 base::RunLoop().RunUntilIdle();
120 base::RunLoop().RunUntilIdle(); 158 }
121 } 159
122 160 void CreateSessionAndExpect(const std::string& session_id,
123 void CreateSessionAndExpect(EmeInitDataType data_type,
124 const std::vector<uint8_t>& key_id,
125 ExpectedResult expected_result) { 161 ExpectedResult expected_result) {
162 // Specify parameters needed to call CreateSessionAndGenerateRequest() in
163 // order to verify that the data is passed properly.
164 const CdmSessionType session_type = CdmSessionType::TEMPORARY_SESSION;
165 const EmeInitDataType data_type = EmeInitDataType::WEBM;
166 const std::vector<uint8_t> key_id(kKeyId, kKeyId + arraysize(kKeyId));
167 std::string created_session_id;
168
169 if (expected_result == CONNECTION_ERROR_BEFORE) {
170 // Break the connection before the call, so
171 // CreateSessionAndGenerateRequest() is never called.
172 ForceConnectionError();
173 } else {
174 EXPECT_CALL(*remote_cdm_.get(), OnCreateSessionAndGenerateRequest(
175 session_type, data_type, key_id, _))
176 .WillOnce(WithArg<3>(
177 InvokeFunction2(this, &MojoCdmTest::HandleSessionPromise,
178 session_id, expected_result)));
179 }
180
181 // Note that although it's called CreateSessionAndGenerateRequest, no
182 // request is generated.
183 mojo_cdm_->CreateSessionAndGenerateRequest(
184 session_type, data_type, key_id,
185 base::MakeUnique<MockCdmSessionPromise>(expected_result == SUCCESS,
186 &created_session_id));
187 base::RunLoop().RunUntilIdle();
188
189 // If the session was "created" ...
126 if (expected_result == SUCCESS) { 190 if (expected_result == SUCCESS) {
127 EXPECT_CALL(cdm_client_, OnSessionMessage(NotEmpty(), _, _)); 191 // Returned session ID must match the session ID provided.
128 } 192 EXPECT_EQ(session_id, created_session_id);
129 193
130 mojo_cdm_->CreateSessionAndGenerateRequest( 194 // MojoCdm expects the session to be closed, so invoke SessionClosedCB
131 CdmSessionType::TEMPORARY_SESSION, data_type, key_id, 195 // to "close" it.
132 base::MakeUnique<MockCdmSessionPromise>(expected_result == SUCCESS, 196 EXPECT_CALL(cdm_client_, OnSessionClosed(session_id));
133 &session_id_)); 197 remote_cdm_->CallSessionClosedCB(session_id);
134 198 base::RunLoop().RunUntilIdle();
135 base::RunLoop().RunUntilIdle(); 199 }
136 } 200 }
137 201
138 void CloseSessionAndExpect(ExpectedResult expected_result) { 202 void LoadSessionAndExpect(const std::string& session_id,
139 DCHECK(!session_id_.empty()) << "CloseSessionAndExpect() must be called " 203 ExpectedResult expected_result) {
140 "after a successful " 204 const CdmSessionType session_type =
141 "CreateSessionAndExpect()"; 205 CdmSessionType::PERSISTENT_LICENSE_SESSION;
142 206 std::string loaded_session_id;
207
208 if (expected_result == CONNECTION_ERROR_BEFORE) {
209 // Break the connection before the call, so LoadSession() is never called.
210 ForceConnectionError();
211 } else {
212 EXPECT_CALL(*remote_cdm_.get(),
213 OnLoadSession(session_type, session_id, _))
214 .WillOnce(WithArg<2>(
215 InvokeFunction2(this, &MojoCdmTest::HandleSessionPromise,
216 session_id, expected_result)));
217 }
218
219 mojo_cdm_->LoadSession(session_type, session_id,
220 base::MakeUnique<MockCdmSessionPromise>(
221 expected_result == SUCCESS, &loaded_session_id));
222 base::RunLoop().RunUntilIdle();
223
224 // If the session was "loaded" ...
143 if (expected_result == SUCCESS) { 225 if (expected_result == SUCCESS) {
144 EXPECT_CALL(cdm_client_, OnSessionClosed(session_id_)); 226 // Returned session ID must match the session ID provided.
145 } 227 EXPECT_EQ(session_id, loaded_session_id);
146 228
147 mojo_cdm_->CloseSession(session_id_, base::MakeUnique<MockCdmPromise>( 229 // MojoCdm expects the session to be closed, so invoke SessionClosedCB
230 // to "close" it.
231 EXPECT_CALL(cdm_client_, OnSessionClosed(session_id));
232 remote_cdm_->CallSessionClosedCB(session_id);
233 base::RunLoop().RunUntilIdle();
234 }
235 }
236
237 void UpdateSessionAndExpect(const std::string& session_id,
238 ExpectedResult expected_result) {
239 // Specify parameters to UpdateSession() in order to verify that
240 // the data is passed properly.
241 const std::vector<uint8_t> response = {1, 2, 3, 4, 5, 6};
242
243 if (expected_result == CONNECTION_ERROR_BEFORE) {
244 // Break the connection before the call, so UpdateSession() is never
245 // called.
246 ForceConnectionError();
247 } else {
248 EXPECT_CALL(*remote_cdm_.get(), OnUpdateSession(session_id, response, _))
249 .WillOnce(WithArg<2>(InvokeFunction(this, &MojoCdmTest::HandlePromise,
250 expected_result)));
251 }
252
253 mojo_cdm_->UpdateSession(
254 session_id, response,
255 base::MakeUnique<MockCdmPromise>(expected_result == SUCCESS));
256 base::RunLoop().RunUntilIdle();
257 }
258
259 void CloseSessionAndExpect(const std::string& session_id,
260 ExpectedResult expected_result) {
261 if (expected_result == CONNECTION_ERROR_BEFORE) {
262 // Break the connection before the call, so CloseSession() is never
263 // called.
264 ForceConnectionError();
265 } else {
266 EXPECT_CALL(*remote_cdm_.get(), OnCloseSession(session_id, _))
267 .WillOnce(WithArg<1>(InvokeFunction(this, &MojoCdmTest::HandlePromise,
268 expected_result)));
269 }
270
271 mojo_cdm_->CloseSession(session_id, base::MakeUnique<MockCdmPromise>(
272 expected_result == SUCCESS));
273 base::RunLoop().RunUntilIdle();
274 }
275
276 void RemoveSessionAndExpect(const std::string& session_id,
277 ExpectedResult expected_result) {
278 if (expected_result == CONNECTION_ERROR_BEFORE) {
279 // Break the connection before the call, so RemoveSession() is never
280 // called.
281 ForceConnectionError();
282 } else {
283 EXPECT_CALL(*remote_cdm_.get(), OnRemoveSession(session_id, _))
284 .WillOnce(WithArg<1>(InvokeFunction(this, &MojoCdmTest::HandlePromise,
285 expected_result)));
286 }
287
288 mojo_cdm_->RemoveSession(session_id, base::MakeUnique<MockCdmPromise>(
148 expected_result == SUCCESS)); 289 expected_result == SUCCESS));
149 290 base::RunLoop().RunUntilIdle();
150 base::RunLoop().RunUntilIdle(); 291 }
292
293 void HandlePromise(std::unique_ptr<SimpleCdmPromise>& promise,
294 ExpectedResult expected_result) {
295 switch (expected_result) {
296 case SUCCESS:
297 promise->resolve();
298 break;
299
300 case FAILURE:
301 promise->reject(media::CdmPromise::UNKNOWN_ERROR, 0,
302 "Promise rejected");
303 break;
304
305 case CONNECTION_ERROR_BEFORE:
306 // Connection should be broken before this is called.
307 NOTREACHED();
308 break;
309
310 case CONNECTION_ERROR_DURING:
311 ForceConnectionError();
312
313 // Now that the connection is broken the promise result won't be passed
314 // back. However, since we check that every promise is fulfilled, we
315 // need to do something with this promise. Resolve the promise to
316 // fulfill it, but note that the original caller will get back a
317 // failed promise due to the connection being broken.
318 promise->resolve();
319 break;
320 }
321 }
322
323 void HandleSessionPromise(std::unique_ptr<NewSessionCdmPromise>& promise,
324 const std::string& session_id,
325 ExpectedResult expected_result) {
326 switch (expected_result) {
327 case SUCCESS:
328 promise->resolve(session_id);
329 break;
330
331 case FAILURE:
332 promise->reject(media::CdmPromise::UNKNOWN_ERROR, 0,
333 "Promise rejected");
334 break;
335
336 case CONNECTION_ERROR_BEFORE:
337 // Connection should be broken before this is called.
338 NOTREACHED();
339 break;
340
341 case CONNECTION_ERROR_DURING:
342 ForceConnectionError();
343
344 // Now that the connection is broken the promise result won't be passed
345 // back. However, since we check that every promise is fulfilled, we
346 // need to do something with this promise. Resolve the promise to
347 // fulfill it, but note that the original caller will get back a
348 // failed promise due to the connection being broken.
349 promise->resolve(session_id);
350 break;
351 }
151 } 352 }
152 353
153 // Fixture members. 354 // Fixture members.
154 base::TestMessageLoop message_loop_; 355 base::TestMessageLoop message_loop_;
155 356
357 // |remote_cdm_| represents the CDM at the end of the mojo message pipe.
358 // |cdm_factory_| will return |remote_cdm_| when the CDM is needed.
359 scoped_refptr<StrictMock<MockCdm>> remote_cdm_;
360 MockCdmFactory cdm_factory_;
361
156 MojoCdmServiceContext mojo_cdm_service_context_; 362 MojoCdmServiceContext mojo_cdm_service_context_;
157 StrictMock<MockCdmClient> cdm_client_; 363 StrictMock<MockCdmClient> cdm_client_;
158 364
159 // TODO(jrummell): Use a MockCdmFactory to create a MockCdm here for more test
160 // coverage.
161 DefaultCdmFactory cdm_factory_;
162
163 std::unique_ptr<MojoCdmService> mojo_cdm_service_; 365 std::unique_ptr<MojoCdmService> mojo_cdm_service_;
164 mojo::Binding<mojom::ContentDecryptionModule> cdm_binding_; 366 mojo::Binding<mojom::ContentDecryptionModule> cdm_binding_;
165 scoped_refptr<ContentDecryptionModule> mojo_cdm_; 367 scoped_refptr<ContentDecryptionModule> mojo_cdm_;
166 368
167 // |session_id_| is the latest successful result of calling CreateSession().
168 std::string session_id_;
169
170 private: 369 private:
171 DISALLOW_COPY_AND_ASSIGN(MojoCdmTest); 370 DISALLOW_COPY_AND_ASSIGN(MojoCdmTest);
172 }; 371 };
173 372
174 TEST_F(MojoCdmTest, Create_Success) { 373 TEST_F(MojoCdmTest, Create_Success) {
175 Initialize(kClearKeyKeySystem, SUCCESS); 374 Initialize(SUCCESS);
176 }
177
178 TEST_F(MojoCdmTest, Create_ConnectionError) {
179 Initialize(kClearKeyKeySystem, CONNECTION_ERROR);
180 } 375 }
181 376
182 TEST_F(MojoCdmTest, Create_Failure) { 377 TEST_F(MojoCdmTest, Create_Failure) {
183 // This fails as DefaultCdmFactory only supports Clear Key. 378 Initialize(FAILURE);
184 Initialize("org.random.cdm", FAILURE); 379 }
185 } 380
186 381 TEST_F(MojoCdmTest, Create_ConnectionErrorBefore) {
187 TEST_F(MojoCdmTest, SetServerCertificate_AfterConnectionError) { 382 Initialize(CONNECTION_ERROR_BEFORE);
188 Initialize(kClearKeyKeySystem, SUCCESS); 383 }
189 ForceConnectionError(); 384
190 SetServerCertificateAndExpect({0, 1, 2}, FAILURE); 385 TEST_F(MojoCdmTest, Create_ConnectionErrorDuring) {
191 } 386 Initialize(CONNECTION_ERROR_DURING);
192 387 }
193 TEST_F(MojoCdmTest, CreateSessionAndGenerateRequest_AfterConnectionError) { 388
194 std::vector<uint8_t> key_id(kKeyId, kKeyId + arraysize(kKeyId)); 389 TEST_F(MojoCdmTest, SetServerCertificate_Success) {
195 390 const std::vector<uint8_t> certificate = {0, 1, 2};
196 Initialize(kClearKeyKeySystem, SUCCESS); 391 Initialize(SUCCESS);
197 ForceConnectionError(); 392 SetServerCertificateAndExpect(certificate, SUCCESS);
198 CreateSessionAndExpect(EmeInitDataType::WEBM, key_id, FAILURE); 393 }
394
395 TEST_F(MojoCdmTest, SetServerCertificate_Failure) {
396 const std::vector<uint8_t> certificate = {1, 2, 3, 4, 5};
397 Initialize(SUCCESS);
398 SetServerCertificateAndExpect(certificate, FAILURE);
399 }
400
401 TEST_F(MojoCdmTest, SetServerCertificate_ConnectionErrorBefore) {
402 const std::vector<uint8_t> certificate = {3, 4};
403 Initialize(SUCCESS);
404 SetServerCertificateAndExpect(certificate, CONNECTION_ERROR_BEFORE);
405 }
406
407 TEST_F(MojoCdmTest, SetServerCertificate_ConnectionErrorDuring) {
408 const std::vector<uint8_t> certificate = {10, 11, 12};
409 Initialize(SUCCESS);
410 SetServerCertificateAndExpect(certificate, CONNECTION_ERROR_DURING);
411 }
412
413 TEST_F(MojoCdmTest, CreateSession_Success) {
414 const std::string session_id = "create1";
415 Initialize(SUCCESS);
416 CreateSessionAndExpect(session_id, SUCCESS);
417 }
418
419 TEST_F(MojoCdmTest, CreateSession_Failure) {
420 const std::string session_id = "create2";
421 Initialize(SUCCESS);
422 CreateSessionAndExpect(session_id, FAILURE);
423 }
424
425 TEST_F(MojoCdmTest, CreateSession_ConnectionErrorBefore) {
426 const std::string session_id = "create3";
427 Initialize(SUCCESS);
428 CreateSessionAndExpect(session_id, CONNECTION_ERROR_BEFORE);
429 }
430
431 TEST_F(MojoCdmTest, CreateSession_ConnectionErrorDuring) {
432 const std::string session_id = "create4";
433 Initialize(SUCCESS);
434 CreateSessionAndExpect(session_id, CONNECTION_ERROR_DURING);
435 }
436
437 TEST_F(MojoCdmTest, LoadSession_Success) {
438 const std::string session_id = "load1";
439 Initialize(SUCCESS);
440 LoadSessionAndExpect(session_id, SUCCESS);
441 }
442
443 TEST_F(MojoCdmTest, LoadSession_Failure) {
444 const std::string session_id = "load2";
445 Initialize(SUCCESS);
446 LoadSessionAndExpect(session_id, FAILURE);
447 }
448
449 TEST_F(MojoCdmTest, LoadSession_ConnectionErrorBefore) {
450 const std::string session_id = "load3";
451 Initialize(SUCCESS);
452 LoadSessionAndExpect(session_id, CONNECTION_ERROR_BEFORE);
453 }
454
455 TEST_F(MojoCdmTest, LoadSession_ConnectionErrorDuring) {
456 const std::string session_id = "load4";
457 Initialize(SUCCESS);
458 LoadSessionAndExpect(session_id, CONNECTION_ERROR_DURING);
459 }
460
461 TEST_F(MojoCdmTest, UpdateSession_Success) {
462 const std::string session_id = "update1";
463 Initialize(SUCCESS);
464 UpdateSessionAndExpect(session_id, SUCCESS);
465 }
466
467 TEST_F(MojoCdmTest, UpdateSession_Failure) {
468 const std::string session_id = "update2";
469 Initialize(SUCCESS);
470 UpdateSessionAndExpect(session_id, FAILURE);
471 }
472
473 TEST_F(MojoCdmTest, UpdateSession_ConnectionErrorBefore) {
474 const std::string session_id = "update3";
475 Initialize(SUCCESS);
476 UpdateSessionAndExpect(session_id, CONNECTION_ERROR_BEFORE);
477 }
478
479 TEST_F(MojoCdmTest, UpdateSession_ConnectionErrorDuring) {
480 const std::string session_id = "update4";
481 Initialize(SUCCESS);
482 UpdateSessionAndExpect(session_id, CONNECTION_ERROR_DURING);
199 } 483 }
200 484
201 TEST_F(MojoCdmTest, CloseSession_Success) { 485 TEST_F(MojoCdmTest, CloseSession_Success) {
202 std::vector<uint8_t> key_id(kKeyId, kKeyId + arraysize(kKeyId)); 486 const std::string session_id = "close1";
203 487 Initialize(SUCCESS);
204 Initialize(kClearKeyKeySystem, SUCCESS); 488 CloseSessionAndExpect(session_id, SUCCESS);
205 CreateSessionAndExpect(EmeInitDataType::WEBM, key_id, SUCCESS); 489 }
206 CloseSessionAndExpect(SUCCESS); 490
207 } 491 TEST_F(MojoCdmTest, CloseSession_Failure) {
208 492 const std::string session_id = "close2";
209 TEST_F(MojoCdmTest, CloseSession_AfterConnectionError) { 493 Initialize(SUCCESS);
210 std::vector<uint8_t> key_id(kKeyId, kKeyId + arraysize(kKeyId)); 494 CloseSessionAndExpect(session_id, FAILURE);
211 495 }
212 Initialize(kClearKeyKeySystem, SUCCESS); 496
213 CreateSessionAndExpect(EmeInitDataType::WEBM, key_id, SUCCESS); 497 TEST_F(MojoCdmTest, CloseSession_ConnectionErrorBefore) {
214 ForceConnectionError(); 498 const std::string session_id = "close3";
215 CloseSessionAndExpect(FAILURE); 499 Initialize(SUCCESS);
500 CloseSessionAndExpect(session_id, CONNECTION_ERROR_BEFORE);
501 }
502
503 TEST_F(MojoCdmTest, CloseSession_ConnectionErrorDuring) {
504 const std::string session_id = "close4";
505 Initialize(SUCCESS);
506 CloseSessionAndExpect(session_id, CONNECTION_ERROR_DURING);
507 }
508
509 TEST_F(MojoCdmTest, RemoveSession_Success) {
510 const std::string session_id = "remove1";
511 Initialize(SUCCESS);
512 RemoveSessionAndExpect(session_id, SUCCESS);
513 }
514
515 TEST_F(MojoCdmTest, RemoveSession_Failure) {
516 const std::string session_id = "remove2";
517 Initialize(SUCCESS);
518 RemoveSessionAndExpect(session_id, FAILURE);
519 }
520
521 TEST_F(MojoCdmTest, RemoveSession_ConnectionErrorBefore) {
522 const std::string session_id = "remove3";
523 Initialize(SUCCESS);
524 RemoveSessionAndExpect(session_id, CONNECTION_ERROR_BEFORE);
525 }
526
527 TEST_F(MojoCdmTest, RemoveSession_ConnectionErrorDuring) {
528 const std::string session_id = "remove4";
529 Initialize(SUCCESS);
530 RemoveSessionAndExpect(session_id, CONNECTION_ERROR_DURING);
531 }
532
533 // Note that MojoCdm requires a session to exist when SessionClosedCB is called,
534 // so it is currently tested in the success cases for CreateSession/LoadSession.
535
536 TEST_F(MojoCdmTest, SessionMessageCB_Success) {
537 const std::string session_id = "message";
538 const ContentDecryptionModule::MessageType message_type =
539 ContentDecryptionModule::LICENSE_REQUEST;
540 const std::vector<uint8_t> message = {0, 1, 2};
541 Initialize(SUCCESS);
542 EXPECT_CALL(cdm_client_, OnSessionMessage(session_id, message_type, message));
543 remote_cdm_->CallSessionMessageCB(session_id, message_type, message);
544 base::RunLoop().RunUntilIdle();
545 }
546
547 TEST_F(MojoCdmTest, SessionExpirationChangeCB_Success) {
548 const std::string session_id = "expiration";
549 const base::Time time = base::Time::Now();
550 Initialize(SUCCESS);
551 EXPECT_CALL(cdm_client_, OnSessionExpirationUpdate(session_id, time));
552 remote_cdm_->CallSessionExpirationUpdateCB(session_id, time);
553 base::RunLoop().RunUntilIdle();
554 }
555
556 TEST_F(MojoCdmTest, SessionKeysChangeCB_Success) {
557 const std::string session_id = "change";
558 bool has_additional_usable_key = true;
559 CdmKeysInfo keys_info;
560 Initialize(SUCCESS);
561 EXPECT_CALL(cdm_client_,
562 OnSessionKeysChangeCalled(session_id, has_additional_usable_key));
563 remote_cdm_->CallSessionKeysChangeCB(session_id, has_additional_usable_key,
564 std::move(keys_info));
565 base::RunLoop().RunUntilIdle();
216 } 566 }
217 567
218 } // namespace media 568 } // namespace media
OLDNEW
« media/base/mock_filters.cc ('K') | « media/mojo/clients/mojo_cdm.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698