Index: content/renderer/media/mock_audio_device_factory.h |
diff --git a/content/renderer/media/mock_audio_device_factory.h b/content/renderer/media/mock_audio_device_factory.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e31293caf5efa3d1e4b3f99dd2676ab819682bfe |
--- /dev/null |
+++ b/content/renderer/media/mock_audio_device_factory.h |
@@ -0,0 +1,83 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CONTENT_RENDERER_MEDIA_MOCK_AUDIO_DEVICE_FACTORY_H_ |
+#define CONTENT_RENDERER_MEDIA_MOCK_AUDIO_DEVICE_FACTORY_H_ |
+ |
+#include "content/renderer/media/audio_device_factory.h" |
+ |
+#include "media/base/audio_capturer_source.h" |
+#include "media/base/audio_renderer_sink.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
+ |
+namespace content { |
+ |
+// MockAudioDeviceFactory creates an instance of this. |
+class MockCapturerSource : public media::AudioCapturerSource { |
+ public: |
+ MockCapturerSource(); |
+ MOCK_METHOD3(Initialize, void(const media::AudioParameters& params, |
+ CaptureCallback* callback, |
+ int session_id)); |
+ MOCK_METHOD0(Start, void()); |
+ MOCK_METHOD0(Stop, void()); |
+ MOCK_METHOD1(SetAutomaticGainControl, void(bool enable)); |
+ void SetVolume(double volume) override; |
+ |
+ protected: |
+ ~MockCapturerSource() override; |
+}; |
+ |
+// Creates one MockCapturerSource instance for unit testing. This replaces the |
+// need for unit tests to open a real platform audio output. Instantiating this |
+// class sets the global content::AudioDeviceFactory implementation to |this|. |
+class MockAudioDeviceFactory : public AudioDeviceFactory { |
+ public: |
+ MockAudioDeviceFactory(); |
+ ~MockAudioDeviceFactory() override; |
+ |
+ // Returns the MockCapturerSource created by this factory. |
+ const scoped_refptr<MockCapturerSource>& mock_capturer_source() const { |
+ return mock_capturer_source_; |
+ } |
+ |
+ // Returns nullptr. |
+ scoped_refptr<media::AudioRendererSink> CreateFinalAudioRendererSink( |
+ int render_frame_id, |
+ int sesssion_id, |
+ const std::string& device_id, |
+ const url::Origin& security_origin) override; |
+ |
+ // Returns nullptr. |
+ scoped_refptr<media::AudioRendererSink> CreateAudioRendererSink( |
+ SourceType source_type, |
+ int render_frame_id, |
+ int sesssion_id, |
+ const std::string& device_id, |
+ const url::Origin& security_origin) override; |
+ |
+ // Returns nullptr. |
+ scoped_refptr<media::SwitchableAudioRendererSink> |
+ CreateSwitchableAudioRendererSink( |
+ SourceType source_type, |
+ int render_frame_id, |
+ int sesssion_id, |
+ const std::string& device_id, |
+ const url::Origin& security_origin) override; |
+ |
+ // Returns mock_capturer_source_ once. If called a second time, the process |
+ // will crash. |
+ scoped_refptr<media::AudioCapturerSource> CreateAudioCapturerSource( |
+ int render_frame_id) override; |
+ |
+ private: |
+ scoped_refptr<MockCapturerSource> mock_capturer_source_; |
+ bool did_create_once_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(MockAudioDeviceFactory); |
+}; |
+ |
+} // namespace content |
+ |
+#endif // CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_FACTORY_H_ |