Add additional properties to display system info on ChromeOS
[chromium-blink-merge.git] / content / test / webrtc_audio_device_test.h
blobf15e3bb2d46a08d48fd6e2f611a650907d5115e7
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_TEST_WEBRTC_AUDIO_DEVICE_TEST_H_
6 #define CONTENT_TEST_WEBRTC_AUDIO_DEVICE_TEST_H_
8 #include <string>
10 #include "base/files/file_path.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop.h"
14 #include "content/browser/renderer_host/media/mock_media_observer.h"
15 #include "content/public/renderer/content_renderer_client.h"
16 #include "ipc/ipc_listener.h"
17 #include "media/base/audio_hardware_config.h"
18 #include "media/base/channel_layout.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "third_party/webrtc/common_types.h"
22 namespace IPC {
23 class Channel;
26 namespace media {
27 class AudioManager;
30 namespace net {
31 class URLRequestContext;
34 namespace webrtc {
35 class VoENetwork;
38 #if defined(OS_WIN)
39 namespace base {
40 namespace win {
41 class ScopedCOMInitializer;
44 #endif
46 namespace content {
48 class AudioInputRendererHost;
49 class AudioMirroringManager;
50 class AudioRendererHost;
51 class ContentRendererClient;
52 class MediaStreamManager;
53 class MockResourceContext;
54 class RenderThreadImpl;
55 class ResourceContext;
56 class TestBrowserThread;
57 class WebRTCMockRenderProcess;
59 // Scoped class for WebRTC interfaces. Fetches the wrapped interface
60 // in the constructor via WebRTC's GetInterface mechanism and then releases
61 // the reference in the destructor.
62 template<typename T>
63 class ScopedWebRTCPtr {
64 public:
65 template<typename Engine>
66 explicit ScopedWebRTCPtr(Engine* e)
67 : ptr_(T::GetInterface(e)) {}
68 explicit ScopedWebRTCPtr(T* p) : ptr_(p) {}
69 ~ScopedWebRTCPtr() { reset(); }
70 T* operator->() const { return ptr_; }
71 T* get() const { return ptr_; }
73 // Releases the current pointer.
74 void reset() {
75 if (ptr_) {
76 ptr_->Release();
77 ptr_ = NULL;
81 bool valid() const { return ptr_ != NULL; }
83 private:
84 T* ptr_;
87 // Wrapper to automatically calling T::Delete in the destructor.
88 // This is useful for some WebRTC objects that have their own Create/Delete
89 // methods and we can't use our our scoped_* classes.
90 template <typename T>
91 class WebRTCAutoDelete {
92 public:
93 WebRTCAutoDelete() : ptr_(NULL) {}
94 explicit WebRTCAutoDelete(T* ptr) : ptr_(ptr) {}
95 ~WebRTCAutoDelete() { reset(); }
97 void reset() {
98 if (ptr_) {
99 T::Delete(ptr_);
100 ptr_ = NULL;
104 T* operator->() { return ptr_; }
105 T* get() const { return ptr_; }
107 bool valid() const { return ptr_ != NULL; }
109 protected:
110 T* ptr_;
113 // Implemented and defined in the cc file.
114 class ReplaceContentClientRenderer;
116 class WebRTCAudioDeviceTest : public ::testing::Test, public IPC::Listener {
117 public:
118 WebRTCAudioDeviceTest();
119 virtual ~WebRTCAudioDeviceTest();
121 virtual void SetUp() OVERRIDE;
122 virtual void TearDown() OVERRIDE;
124 // Sends an IPC message to the IO thread channel.
125 bool Send(IPC::Message* message);
127 void SetAudioHardwareConfig(media::AudioHardwareConfig* hardware_config);
129 protected:
130 void InitializeIOThread(const char* thread_name);
131 void UninitializeIOThread();
132 void CreateChannel(const char* name);
133 void DestroyChannel();
135 void OnGetAudioHardwareConfig(media::AudioParameters* input_params,
136 media::AudioParameters* output_params);
138 // IPC::Listener implementation.
139 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
141 // Posts a final task to the IO message loop and waits for completion.
142 void WaitForIOThreadCompletion();
143 void WaitForAudioManagerCompletion();
144 void WaitForMessageLoopCompletion(base::MessageLoopProxy* loop);
146 // Convenience getter for gmock.
147 MockMediaInternals& media_observer() const {
148 return *media_internals_.get();
151 std::string GetTestDataPath(const base::FilePath::StringType& file_name);
153 scoped_ptr<ReplaceContentClientRenderer> saved_content_renderer_;
154 base::MessageLoopForUI message_loop_;
155 ContentRendererClient content_renderer_client_;
156 RenderThreadImpl* render_thread_; // Owned by mock_process_.
157 scoped_ptr<WebRTCMockRenderProcess> mock_process_;
158 scoped_ptr<MockMediaInternals> media_internals_;
159 scoped_ptr<MediaStreamManager> media_stream_manager_;
160 scoped_ptr<media::AudioManager> audio_manager_;
161 scoped_ptr<AudioMirroringManager> mirroring_manager_;
162 scoped_ptr<net::URLRequestContext> test_request_context_;
163 scoped_ptr<ResourceContext> resource_context_;
164 scoped_ptr<IPC::Channel> channel_;
165 scoped_refptr<AudioRendererHost> audio_render_host_;
166 scoped_refptr<AudioInputRendererHost> audio_input_renderer_host_;
168 media::AudioHardwareConfig* audio_hardware_config_; // Weak reference.
170 // Initialized on the main test thread that we mark as the UI thread.
171 scoped_ptr<TestBrowserThread> ui_thread_;
172 // Initialized on our IO thread to satisfy BrowserThread::IO checks.
173 scoped_ptr<TestBrowserThread> io_thread_;
175 #if defined(OS_WIN)
176 // COM initialization on the IO thread.
177 scoped_ptr<base::win::ScopedCOMInitializer> initialize_com_;
178 #endif
180 // These are initialized when we set up our IO thread.
181 bool has_input_devices_;
182 bool has_output_devices_;
184 // The previous state for whether sandbox support was enabled in
185 // RenderViewWebKitPlatformSupportImpl.
186 bool sandbox_was_enabled_;
189 // A very basic implementation of webrtc::Transport that acts as a transport
190 // but just forwards all calls to a local webrtc::VoENetwork implementation.
191 // Ownership of the VoENetwork object lies outside the class.
192 class WebRTCTransportImpl : public webrtc::Transport {
193 public:
194 explicit WebRTCTransportImpl(webrtc::VoENetwork* network);
195 virtual ~WebRTCTransportImpl();
197 virtual int SendPacket(int channel, const void* data, int len) OVERRIDE;
198 virtual int SendRTCPPacket(int channel, const void* data, int len) OVERRIDE;
200 private:
201 webrtc::VoENetwork* network_;
204 } // namespace content
206 #endif // CONTENT_TEST_WEBRTC_AUDIO_DEVICE_TEST_H_