OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_RENDERER_MEDIA_MOCK_AUDIO_DEVICE_FACTORY_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_MOCK_AUDIO_DEVICE_FACTORY_H_ |
| 7 |
| 8 #include "content/renderer/media/audio_device_factory.h" |
| 9 |
| 10 #include "media/base/audio_capturer_source.h" |
| 11 #include "media/base/audio_renderer_sink.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" |
| 13 |
| 14 namespace content { |
| 15 |
| 16 // MockAudioDeviceFactory creates an instance of this. |
| 17 class MockCapturerSource : public media::AudioCapturerSource { |
| 18 public: |
| 19 MockCapturerSource(); |
| 20 MOCK_METHOD3(Initialize, void(const media::AudioParameters& params, |
| 21 CaptureCallback* callback, |
| 22 int session_id)); |
| 23 MOCK_METHOD0(Start, void()); |
| 24 MOCK_METHOD0(Stop, void()); |
| 25 MOCK_METHOD1(SetAutomaticGainControl, void(bool enable)); |
| 26 void SetVolume(double volume) override; |
| 27 |
| 28 protected: |
| 29 ~MockCapturerSource() override; |
| 30 }; |
| 31 |
| 32 // Creates one MockCapturerSource instance for unit testing. This replaces the |
| 33 // need for unit tests to open a real platform audio output. Instantiating this |
| 34 // class sets the global content::AudioDeviceFactory implementation to |this|. |
| 35 class MockAudioDeviceFactory : public AudioDeviceFactory { |
| 36 public: |
| 37 MockAudioDeviceFactory(); |
| 38 ~MockAudioDeviceFactory() override; |
| 39 |
| 40 // Returns the MockCapturerSource created by this factory. |
| 41 const scoped_refptr<MockCapturerSource>& mock_capturer_source() const { |
| 42 return mock_capturer_source_; |
| 43 } |
| 44 |
| 45 // Returns nullptr. |
| 46 scoped_refptr<media::AudioRendererSink> CreateFinalAudioRendererSink( |
| 47 int render_frame_id, |
| 48 int sesssion_id, |
| 49 const std::string& device_id, |
| 50 const url::Origin& security_origin) override; |
| 51 |
| 52 // Returns nullptr. |
| 53 scoped_refptr<media::AudioRendererSink> CreateAudioRendererSink( |
| 54 SourceType source_type, |
| 55 int render_frame_id, |
| 56 int sesssion_id, |
| 57 const std::string& device_id, |
| 58 const url::Origin& security_origin) override; |
| 59 |
| 60 // Returns nullptr. |
| 61 scoped_refptr<media::SwitchableAudioRendererSink> |
| 62 CreateSwitchableAudioRendererSink( |
| 63 SourceType source_type, |
| 64 int render_frame_id, |
| 65 int sesssion_id, |
| 66 const std::string& device_id, |
| 67 const url::Origin& security_origin) override; |
| 68 |
| 69 // Returns mock_capturer_source_ once. If called a second time, the process |
| 70 // will crash. |
| 71 scoped_refptr<media::AudioCapturerSource> CreateAudioCapturerSource( |
| 72 int render_frame_id) override; |
| 73 |
| 74 private: |
| 75 scoped_refptr<MockCapturerSource> mock_capturer_source_; |
| 76 bool did_create_once_; |
| 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(MockAudioDeviceFactory); |
| 79 }; |
| 80 |
| 81 } // namespace content |
| 82 |
| 83 #endif // CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_FACTORY_H_ |
OLD | NEW |