| 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_AUDIO_MOCK_AUDIO_MANAGER_H_ | 5 #ifndef MEDIA_AUDIO_MOCK_AUDIO_MANAGER_H_ |
| 6 #define MEDIA_AUDIO_MOCK_AUDIO_MANAGER_H_ | 6 #define MEDIA_AUDIO_MOCK_AUDIO_MANAGER_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/sequenced_task_runner_helpers.h" |
| 9 #include "media/audio/audio_manager.h" | 10 #include "media/audio/audio_manager.h" |
| 10 | 11 |
| 11 namespace media { | 12 namespace media { |
| 12 | 13 |
| 13 // This class is a simple mock around AudioManager, used exclusively for tests, | 14 // This class is a simple mock around AudioManager, used exclusively for tests, |
| 14 // which avoids to use the actual (system and platform dependent) AudioManager. | 15 // which avoids to use the actual (system and platform dependent) AudioManager. |
| 15 // Some bots does not have input devices, thus using the actual AudioManager | 16 // Some bots does not have input devices, thus using the actual AudioManager |
| 16 // would causing failures on classes which expect that. | 17 // would causing failures on classes which expect that. |
| 17 class MockAudioManager : public media::AudioManager { | 18 class MockAudioManager : public AudioManager { |
| 18 public: | 19 public: |
| 20 class Deleter { |
| 21 public: |
| 22 void operator()(const MockAudioManager* instance) const; |
| 23 }; |
| 24 |
| 25 using UniquePtr = std::unique_ptr<MockAudioManager, Deleter>; |
| 26 |
| 19 explicit MockAudioManager( | 27 explicit MockAudioManager( |
| 20 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 28 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 21 | 29 |
| 22 bool HasAudioOutputDevices() override; | 30 bool HasAudioOutputDevices() override; |
| 23 | 31 |
| 24 bool HasAudioInputDevices() override; | 32 bool HasAudioInputDevices() override; |
| 25 | 33 |
| 26 base::string16 GetAudioInputDeviceModel() override; | 34 base::string16 GetAudioInputDeviceModel() override; |
| 27 | 35 |
| 28 void ShowAudioInputSettings() override; | 36 void ShowAudioInputSettings() override; |
| 29 | 37 |
| 30 void GetAudioInputDeviceDescriptions( | 38 void GetAudioInputDeviceDescriptions( |
| 31 media::AudioDeviceDescriptions* device_descriptions) override; | 39 media::AudioDeviceDescriptions* device_descriptions) override; |
| 32 | 40 |
| 33 void GetAudioOutputDeviceDescriptions( | 41 void GetAudioOutputDeviceDescriptions( |
| 34 media::AudioDeviceDescriptions* device_descriptions) override; | 42 media::AudioDeviceDescriptions* device_descriptions) override; |
| 35 | 43 |
| 36 media::AudioOutputStream* MakeAudioOutputStream( | 44 AudioOutputStream* MakeAudioOutputStream( |
| 37 const media::AudioParameters& params, | 45 const media::AudioParameters& params, |
| 38 const std::string& device_id, | 46 const std::string& device_id, |
| 39 const LogCallback& log_callback) override; | 47 const LogCallback& log_callback) override; |
| 40 | 48 |
| 41 media::AudioOutputStream* MakeAudioOutputStreamProxy( | 49 AudioOutputStream* MakeAudioOutputStreamProxy( |
| 42 const media::AudioParameters& params, | 50 const media::AudioParameters& params, |
| 43 const std::string& device_id) override; | 51 const std::string& device_id) override; |
| 44 | 52 |
| 45 media::AudioInputStream* MakeAudioInputStream( | 53 AudioInputStream* MakeAudioInputStream( |
| 46 const media::AudioParameters& params, | 54 const media::AudioParameters& params, |
| 47 const std::string& device_id, | 55 const std::string& device_id, |
| 48 const LogCallback& log_callback) override; | 56 const LogCallback& log_callback) override; |
| 49 | 57 |
| 50 void AddOutputDeviceChangeListener(AudioDeviceListener* listener) override; | 58 void AddOutputDeviceChangeListener(AudioDeviceListener* listener) override; |
| 51 void RemoveOutputDeviceChangeListener(AudioDeviceListener* listener) override; | 59 void RemoveOutputDeviceChangeListener(AudioDeviceListener* listener) override; |
| 52 | 60 |
| 53 AudioParameters GetDefaultOutputStreamParameters() override; | 61 AudioParameters GetDefaultOutputStreamParameters() override; |
| 54 AudioParameters GetOutputStreamParameters( | 62 AudioParameters GetOutputStreamParameters( |
| 55 const std::string& device_id) override; | 63 const std::string& device_id) override; |
| 56 AudioParameters GetInputStreamParameters( | 64 AudioParameters GetInputStreamParameters( |
| 57 const std::string& device_id) override; | 65 const std::string& device_id) override; |
| 58 std::string GetAssociatedOutputDeviceID( | 66 std::string GetAssociatedOutputDeviceID( |
| 59 const std::string& input_device_id) override; | 67 const std::string& input_device_id) override; |
| 60 | 68 |
| 61 std::unique_ptr<AudioLog> CreateAudioLog( | 69 std::unique_ptr<AudioLog> CreateAudioLog( |
| 62 AudioLogFactory::AudioComponent component) override; | 70 AudioLogFactory::AudioComponent component) override; |
| 63 | 71 |
| 64 const char* GetName() override; | 72 const char* GetName() override; |
| 65 | 73 |
| 74 // Setters to emulate desired in-test behavior. |
| 75 void SetInputStreamParameters(const AudioParameters& input_params); |
| 76 void SetHasInputDevices(bool has_input_devices); |
| 77 |
| 66 protected: | 78 protected: |
| 67 ~MockAudioManager() override; | 79 ~MockAudioManager() override; |
| 68 | 80 |
| 69 private: | 81 private: |
| 82 friend class base::DeleteHelper<MockAudioManager>; |
| 83 AudioParameters input_params_; |
| 84 bool has_input_devices_ = true; |
| 85 |
| 70 DISALLOW_COPY_AND_ASSIGN(MockAudioManager); | 86 DISALLOW_COPY_AND_ASSIGN(MockAudioManager); |
| 71 }; | 87 }; |
| 72 | 88 |
| 73 } // namespace media. | 89 } // namespace media. |
| 74 | 90 |
| 75 #endif // MEDIA_AUDIO_MOCK_AUDIO_MANAGER_H_ | 91 #endif // MEDIA_AUDIO_MOCK_AUDIO_MANAGER_H_ |
| OLD | NEW |