Chromium Code Reviews| 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_context.h" | 18 #include "media/base/cdm_context.h" |
| 19 #include "media/base/cdm_factory.h" | |
| 19 #include "media/base/cdm_key_information.h" | 20 #include "media/base/cdm_key_information.h" |
| 20 #include "media/base/cdm_promise.h" | 21 #include "media/base/cdm_promise.h" |
| 22 #include "media/base/cdm_promise_adapter.h" | |
| 21 #include "media/base/content_decryption_module.h" | 23 #include "media/base/content_decryption_module.h" |
| 22 #include "media/base/decoder_buffer.h" | 24 #include "media/base/decoder_buffer.h" |
| 23 #include "media/base/decryptor.h" | 25 #include "media/base/decryptor.h" |
| 24 #include "media/base/demuxer.h" | 26 #include "media/base/demuxer.h" |
| 25 #include "media/base/media_track.h" | 27 #include "media/base/media_track.h" |
| 26 #include "media/base/pipeline.h" | 28 #include "media/base/pipeline.h" |
| 27 #include "media/base/pipeline_status.h" | 29 #include "media/base/pipeline_status.h" |
| 28 #include "media/base/renderer.h" | 30 #include "media/base/renderer.h" |
| 29 #include "media/base/renderer_client.h" | 31 #include "media/base/renderer_client.h" |
| 30 #include "media/base/stream_parser.h" | 32 #include "media/base/stream_parser.h" |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 439 ~MockCdmSessionPromise() override; | 441 ~MockCdmSessionPromise() override; |
| 440 | 442 |
| 441 MOCK_METHOD1(resolve, void(const std::string&)); | 443 MOCK_METHOD1(resolve, void(const std::string&)); |
| 442 MOCK_METHOD3(reject, | 444 MOCK_METHOD3(reject, |
| 443 void(CdmPromise::Exception, uint32_t, const std::string&)); | 445 void(CdmPromise::Exception, uint32_t, const std::string&)); |
| 444 | 446 |
| 445 private: | 447 private: |
| 446 DISALLOW_COPY_AND_ASSIGN(MockCdmSessionPromise); | 448 DISALLOW_COPY_AND_ASSIGN(MockCdmSessionPromise); |
| 447 }; | 449 }; |
| 448 | 450 |
| 451 class MockCdm : public ContentDecryptionModule { | |
| 452 public: | |
| 453 MockCdm(); | |
| 454 | |
| 455 // ContentDecryptionModule implementation. | |
| 456 // As move-only parameters aren't supported by mock methods, convert promises | |
| 457 // into IDs and pass them to On... methods. | |
| 458 void SetServerCertificate(const std::vector<uint8_t>& certificate, | |
| 459 std::unique_ptr<SimpleCdmPromise> promise) override; | |
| 460 MOCK_METHOD2(OnSetServerCertificate, | |
| 461 void(const std::vector<uint8_t>& certificate, | |
| 462 uint32_t promise_id)); | |
| 463 | |
| 464 void CreateSessionAndGenerateRequest( | |
| 465 CdmSessionType session_type, | |
| 466 EmeInitDataType init_data_type, | |
| 467 const std::vector<uint8_t>& init_data, | |
| 468 std::unique_ptr<NewSessionCdmPromise> promise) override; | |
| 469 MOCK_METHOD4(OnCreateSessionAndGenerateRequest, | |
| 470 void(CdmSessionType session_type, | |
| 471 EmeInitDataType init_data_type, | |
| 472 const std::vector<uint8_t>& init_data, | |
| 473 uint32_t promise_id)); | |
|
xhwang
2017/01/05 06:59:53
Instead of using the promise adapter to convert th
jrummell
2017/01/05 23:47:22
Done.
| |
| 474 | |
| 475 void LoadSession(CdmSessionType session_type, | |
| 476 const std::string& session_id, | |
| 477 std::unique_ptr<NewSessionCdmPromise> promise) override; | |
| 478 MOCK_METHOD3(OnLoadSession, | |
| 479 void(CdmSessionType session_type, | |
| 480 const std::string& session_id, | |
| 481 uint32_t promise_id)); | |
| 482 | |
| 483 void UpdateSession(const std::string& session_id, | |
| 484 const std::vector<uint8_t>& response, | |
| 485 std::unique_ptr<SimpleCdmPromise> promise) override; | |
| 486 MOCK_METHOD3(OnUpdateSession, | |
| 487 void(const std::string& session_id, | |
| 488 const std::vector<uint8_t>& response, | |
| 489 uint32_t promise_id)); | |
| 490 | |
| 491 void CloseSession(const std::string& session_id, | |
| 492 std::unique_ptr<SimpleCdmPromise> promise) override; | |
| 493 MOCK_METHOD2(OnCloseSession, | |
| 494 void(const std::string& session_id, uint32_t promise_id)); | |
| 495 | |
| 496 void RemoveSession(const std::string& session_id, | |
| 497 std::unique_ptr<SimpleCdmPromise> promise) override; | |
| 498 MOCK_METHOD2(OnRemoveSession, | |
| 499 void(const std::string& session_id, uint32_t promise_id)); | |
| 500 | |
| 501 MOCK_METHOD0(GetCdmContext, CdmContext*()); | |
| 502 | |
| 503 // As the promises are saved to |cdm_promise_adapter_|, these methods | |
| 504 // provide a way for the mock methods to fulfill the promise as necessary | |
| 505 // for the test. | |
| 506 void ResolvePromise(uint32_t promise_id); | |
| 507 void RejectPromise(uint32_t promise_id); | |
| 508 void ResolvePromiseWithSession(uint32_t promise_id, | |
| 509 const std::string& session_id); | |
| 510 | |
| 511 // As MockCdmFactory returns the MockCdm provided to it, this sets the | |
| 512 // actual callbacks used when MockCdmFactory::Create() is called. | |
| 513 void SetCallbacks( | |
| 514 const SessionMessageCB& session_message_cb, | |
| 515 const SessionClosedCB& session_closed_cb, | |
| 516 const SessionKeysChangeCB& session_keys_change_cb, | |
| 517 const SessionExpirationUpdateCB& session_expiration_update_cb); | |
| 518 void CallSessionMessageCB(const std::string& session_id, | |
| 519 ContentDecryptionModule::MessageType message_type, | |
| 520 const std::vector<uint8_t>& message); | |
| 521 void CallSessionClosedCB(const std::string& session_id); | |
| 522 void CallSessionKeysChangeCB(const std::string& session_id, | |
| 523 bool has_additional_usable_key, | |
| 524 CdmKeysInfo keys_info); | |
| 525 void CallSessionExpirationUpdateCB(const std::string& session_id, | |
| 526 base::Time new_expiry_time); | |
| 527 | |
| 528 protected: | |
| 529 ~MockCdm() override; | |
| 530 | |
| 531 private: | |
| 532 // Callbacks. | |
| 533 SessionMessageCB session_message_cb_; | |
| 534 SessionClosedCB session_closed_cb_; | |
| 535 SessionKeysChangeCB session_keys_change_cb_; | |
| 536 SessionExpirationUpdateCB session_expiration_update_cb_; | |
| 537 | |
| 538 // Keep track of the promises so that ResolvePromise(), etc. can be called | |
| 539 // by the mock methods. | |
| 540 CdmPromiseAdapter cdm_promise_adapter_; | |
| 541 | |
| 542 DISALLOW_COPY_AND_ASSIGN(MockCdm); | |
| 543 }; | |
| 544 | |
| 545 class MockCdmFactory : public CdmFactory { | |
| 546 public: | |
| 547 MockCdmFactory(); | |
| 548 ~MockCdmFactory() override; | |
| 549 | |
| 550 // CdmFactory implementation. | |
| 551 MOCK_METHOD8( | |
| 552 Create, | |
| 553 void(const std::string& key_system, | |
| 554 const GURL& security_origin, | |
| 555 const CdmConfig& cdm_config, | |
| 556 const SessionMessageCB& session_message_cb, | |
| 557 const SessionClosedCB& session_closed_cb, | |
| 558 const SessionKeysChangeCB& session_keys_change_cb, | |
| 559 const SessionExpirationUpdateCB& session_expiration_update_cb, | |
| 560 const CdmCreatedCB& cdm_created_cb)); | |
| 561 | |
| 562 private: | |
| 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 |