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 #ifndef MEDIA_BASE_MOCK_FILTERS_H_ | 5 #ifndef MEDIA_BASE_MOCK_FILTERS_H_ |
6 #define MEDIA_BASE_MOCK_FILTERS_H_ | 6 #define MEDIA_BASE_MOCK_FILTERS_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "media/base/audio_decoder.h" | 15 #include "media/base/audio_decoder.h" |
16 #include "media/base/audio_decoder_config.h" | 16 #include "media/base/audio_decoder_config.h" |
17 #include "media/base/audio_renderer.h" | 17 #include "media/base/audio_renderer.h" |
18 #include "media/base/cdm_config.h" | |
18 #include "media/base/cdm_context.h" | 19 #include "media/base/cdm_context.h" |
20 #include "media/base/cdm_factory.h" | |
19 #include "media/base/cdm_key_information.h" | 21 #include "media/base/cdm_key_information.h" |
20 #include "media/base/cdm_promise.h" | 22 #include "media/base/cdm_promise.h" |
23 #include "media/base/cdm_promise_adapter.h" | |
21 #include "media/base/content_decryption_module.h" | 24 #include "media/base/content_decryption_module.h" |
22 #include "media/base/decoder_buffer.h" | 25 #include "media/base/decoder_buffer.h" |
23 #include "media/base/decryptor.h" | 26 #include "media/base/decryptor.h" |
24 #include "media/base/demuxer.h" | 27 #include "media/base/demuxer.h" |
25 #include "media/base/media_track.h" | 28 #include "media/base/media_track.h" |
26 #include "media/base/pipeline.h" | 29 #include "media/base/pipeline.h" |
27 #include "media/base/pipeline_status.h" | 30 #include "media/base/pipeline_status.h" |
28 #include "media/base/renderer.h" | 31 #include "media/base/renderer.h" |
29 #include "media/base/renderer_client.h" | 32 #include "media/base/renderer_client.h" |
30 #include "media/base/stream_parser.h" | 33 #include "media/base/stream_parser.h" |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
439 ~MockCdmSessionPromise() override; | 442 ~MockCdmSessionPromise() override; |
440 | 443 |
441 MOCK_METHOD1(resolve, void(const std::string&)); | 444 MOCK_METHOD1(resolve, void(const std::string&)); |
442 MOCK_METHOD3(reject, | 445 MOCK_METHOD3(reject, |
443 void(CdmPromise::Exception, uint32_t, const std::string&)); | 446 void(CdmPromise::Exception, uint32_t, const std::string&)); |
444 | 447 |
445 private: | 448 private: |
446 DISALLOW_COPY_AND_ASSIGN(MockCdmSessionPromise); | 449 DISALLOW_COPY_AND_ASSIGN(MockCdmSessionPromise); |
447 }; | 450 }; |
448 | 451 |
452 class MockCdm : public ContentDecryptionModule { | |
453 public: | |
454 MockCdm(const SessionMessageCB& session_message_cb, | |
455 const SessionClosedCB& session_closed_cb, | |
456 const SessionKeysChangeCB& session_keys_change_cb, | |
457 const SessionExpirationUpdateCB& session_expiration_update_cb); | |
458 | |
459 // ContentDecryptionModule implementation. | |
460 // As move-only parameters aren't supported by mock methods, convert promises | |
461 // into IDs and pass them to On... methods. | |
462 void SetServerCertificate(const std::vector<uint8_t>& certificate, | |
463 std::unique_ptr<SimpleCdmPromise> promise) override; | |
464 MOCK_METHOD2(OnSetServerCertificate, | |
465 void(const std::vector<uint8_t>& certificate, | |
466 std::unique_ptr<SimpleCdmPromise>& promise)); | |
467 | |
468 void CreateSessionAndGenerateRequest( | |
469 CdmSessionType session_type, | |
470 EmeInitDataType init_data_type, | |
471 const std::vector<uint8_t>& init_data, | |
472 std::unique_ptr<NewSessionCdmPromise> promise) override; | |
473 MOCK_METHOD4(OnCreateSessionAndGenerateRequest, | |
474 void(CdmSessionType session_type, | |
475 EmeInitDataType init_data_type, | |
476 const std::vector<uint8_t>& init_data, | |
477 std::unique_ptr<NewSessionCdmPromise>& promise)); | |
478 | |
479 void LoadSession(CdmSessionType session_type, | |
480 const std::string& session_id, | |
481 std::unique_ptr<NewSessionCdmPromise> promise) override; | |
482 MOCK_METHOD3(OnLoadSession, | |
483 void(CdmSessionType session_type, | |
484 const std::string& session_id, | |
485 std::unique_ptr<NewSessionCdmPromise>& promise)); | |
486 | |
487 void UpdateSession(const std::string& session_id, | |
488 const std::vector<uint8_t>& response, | |
489 std::unique_ptr<SimpleCdmPromise> promise) override; | |
490 MOCK_METHOD3(OnUpdateSession, | |
491 void(const std::string& session_id, | |
492 const std::vector<uint8_t>& response, | |
493 std::unique_ptr<SimpleCdmPromise>& promise)); | |
494 | |
495 void CloseSession(const std::string& session_id, | |
496 std::unique_ptr<SimpleCdmPromise> promise) override; | |
497 MOCK_METHOD2(OnCloseSession, | |
498 void(const std::string& session_id, | |
499 std::unique_ptr<SimpleCdmPromise>& promise)); | |
500 | |
501 void RemoveSession(const std::string& session_id, | |
502 std::unique_ptr<SimpleCdmPromise> promise) override; | |
503 MOCK_METHOD2(OnRemoveSession, | |
504 void(const std::string& session_id, | |
505 std::unique_ptr<SimpleCdmPromise>& promise)); | |
506 | |
507 MOCK_METHOD0(GetCdmContext, CdmContext*()); | |
508 | |
509 void CallSessionMessageCB(const std::string& session_id, | |
510 ContentDecryptionModule::MessageType message_type, | |
511 const std::vector<uint8_t>& message); | |
512 void CallSessionClosedCB(const std::string& session_id); | |
513 void CallSessionKeysChangeCB(const std::string& session_id, | |
514 bool has_additional_usable_key, | |
515 CdmKeysInfo keys_info); | |
516 void CallSessionExpirationUpdateCB(const std::string& session_id, | |
517 base::Time new_expiry_time); | |
518 | |
519 protected: | |
520 ~MockCdm() override; | |
521 | |
522 private: | |
523 // Callbacks. | |
524 SessionMessageCB session_message_cb_; | |
525 SessionClosedCB session_closed_cb_; | |
526 SessionKeysChangeCB session_keys_change_cb_; | |
527 SessionExpirationUpdateCB session_expiration_update_cb_; | |
528 | |
529 DISALLOW_COPY_AND_ASSIGN(MockCdm); | |
530 }; | |
531 | |
532 class MockCdmFactory : public CdmFactory { | |
533 public: | |
534 MockCdmFactory(); | |
535 ~MockCdmFactory() override; | |
536 | |
537 // CdmFactory implementation. | |
538 // This creates a StrictMock<MockCdm> when called. Although ownership of the | |
539 // created CDM is passed to |cdm_created_cb|, a copy is kept (and available | |
540 // using Cdm()). If |key_system| is empty, no CDM will be created. | |
541 void Create(const std::string& key_system, | |
542 const GURL& security_origin, | |
543 const CdmConfig& cdm_config, | |
544 const SessionMessageCB& session_message_cb, | |
545 const SessionClosedCB& session_closed_cb, | |
546 const SessionKeysChangeCB& session_keys_change_cb, | |
547 const SessionExpirationUpdateCB& session_expiration_update_cb, | |
548 const CdmCreatedCB& cdm_created_cb) override; | |
549 | |
550 // Return a pointer to the created CDM. | |
551 MockCdm* Cdm(); | |
xhwang
2017/01/06 21:00:21
nit: Functions typically start with a verb. How ab
jrummell
2017/01/06 22:49:16
Done (GetCreatedCdm()).
| |
552 | |
553 // Provide a callback to be called before the CDM is created and returned. | |
554 void SetBeforeCreationCB(const base::Closure& before_creation_cb); | |
555 | |
556 private: | |
557 // Reference to the created CDM. | |
558 MockCdm* created_cdm_; | |
xhwang
2017/01/06 21:00:21
nit: It's probably safer to keep a ref to it to av
jrummell
2017/01/06 22:49:16
Done.
| |
559 | |
560 // Callback to be used before Create() successfully calls |cdm_created_cb|. | |
561 base::Closure before_creation_cb_; | |
562 | |
563 DISALLOW_COPY_AND_ASSIGN(MockCdmFactory); | |
564 }; | |
565 | |
449 class MockStreamParser : public StreamParser { | 566 class MockStreamParser : public StreamParser { |
450 public: | 567 public: |
451 MockStreamParser(); | 568 MockStreamParser(); |
452 ~MockStreamParser() override; | 569 ~MockStreamParser() override; |
453 | 570 |
454 // StreamParser interface | 571 // StreamParser interface |
455 MOCK_METHOD8( | 572 MOCK_METHOD8( |
456 Init, | 573 Init, |
457 void(const InitCB& init_cb, | 574 void(const InitCB& init_cb, |
458 const NewConfigCB& config_cb, | 575 const NewConfigCB& config_cb, |
459 const NewBuffersCB& new_buffers_cb, | 576 const NewBuffersCB& new_buffers_cb, |
460 bool ignore_text_track, | 577 bool ignore_text_track, |
461 const EncryptedMediaInitDataCB& encrypted_media_init_data_cb, | 578 const EncryptedMediaInitDataCB& encrypted_media_init_data_cb, |
462 const NewMediaSegmentCB& new_segment_cb, | 579 const NewMediaSegmentCB& new_segment_cb, |
463 const EndMediaSegmentCB& end_of_segment_cb, | 580 const EndMediaSegmentCB& end_of_segment_cb, |
464 const scoped_refptr<MediaLog>& media_log)); | 581 const scoped_refptr<MediaLog>& media_log)); |
465 MOCK_METHOD0(Flush, void()); | 582 MOCK_METHOD0(Flush, void()); |
466 MOCK_METHOD2(Parse, bool(const uint8_t*, int)); | 583 MOCK_METHOD2(Parse, bool(const uint8_t*, int)); |
467 | 584 |
468 private: | 585 private: |
469 DISALLOW_COPY_AND_ASSIGN(MockStreamParser); | 586 DISALLOW_COPY_AND_ASSIGN(MockStreamParser); |
470 }; | 587 }; |
471 | 588 |
472 } // namespace media | 589 } // namespace media |
473 | 590 |
474 #endif // MEDIA_BASE_MOCK_FILTERS_H_ | 591 #endif // MEDIA_BASE_MOCK_FILTERS_H_ |
OLD | NEW |