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

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

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