OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CONTENT_TEST_WEBRTC_AUDIO_DEVICE_TEST_H_ | 5 #ifndef CONTENT_TEST_WEBRTC_AUDIO_DEVICE_TEST_H_ |
6 #define CONTENT_TEST_WEBRTC_AUDIO_DEVICE_TEST_H_ | 6 #define CONTENT_TEST_WEBRTC_AUDIO_DEVICE_TEST_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
15 #include "base/synchronization/waitable_event.h" | |
16 #include "content/browser/renderer_host/media/mock_media_observer.h" | 15 #include "content/browser/renderer_host/media/mock_media_observer.h" |
17 #include "content/renderer/mock_content_renderer_client.h" | 16 #include "content/renderer/mock_content_renderer_client.h" |
18 #include "ipc/ipc_channel.h" | 17 #include "ipc/ipc_channel.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
20 #include "third_party/webrtc/common_types.h" | 19 #include "third_party/webrtc/common_types.h" |
21 | 20 |
22 class AudioInputRendererHost; | 21 class AudioInputRendererHost; |
| 22 class AudioManager; |
23 class AudioRendererHost; | 23 class AudioRendererHost; |
24 class RenderThreadImpl; | 24 class RenderThreadImpl; |
25 class WebRTCMockRenderProcess; | 25 class WebRTCMockRenderProcess; |
26 | 26 |
27 namespace base { | 27 namespace base { |
28 namespace win { | 28 namespace win { |
29 class ScopedCOMInitializer; | 29 class ScopedCOMInitializer; |
30 } | 30 } |
31 } | 31 } |
32 | 32 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 virtual double GetAudioInputHardwareSampleRate() = 0; | 111 virtual double GetAudioInputHardwareSampleRate() = 0; |
112 }; | 112 }; |
113 | 113 |
114 // Implemented and defined in the cc file. | 114 // Implemented and defined in the cc file. |
115 class ReplaceContentClientRenderer; | 115 class ReplaceContentClientRenderer; |
116 | 116 |
117 class WebRTCAudioDeviceTest | 117 class WebRTCAudioDeviceTest |
118 : public ::testing::Test, | 118 : public ::testing::Test, |
119 public IPC::Channel::Listener { | 119 public IPC::Channel::Listener { |
120 public: | 120 public: |
121 class SetupTask : public base::RefCountedThreadSafe<SetupTask> { | |
122 public: | |
123 explicit SetupTask(WebRTCAudioDeviceTest* test) : test_(test) { | |
124 DCHECK(test); // Catch this early since we dereference much later. | |
125 } | |
126 void InitializeIOThread(const char* thread_name) { | |
127 test_->InitializeIOThread(thread_name); | |
128 } | |
129 void UninitializeIOThread() { test_->UninitializeIOThread(); } | |
130 protected: | |
131 WebRTCAudioDeviceTest* test_; | |
132 }; | |
133 | |
134 WebRTCAudioDeviceTest(); | 121 WebRTCAudioDeviceTest(); |
135 virtual ~WebRTCAudioDeviceTest(); | 122 virtual ~WebRTCAudioDeviceTest(); |
136 | 123 |
137 virtual void SetUp() OVERRIDE; | 124 virtual void SetUp() OVERRIDE; |
138 virtual void TearDown() OVERRIDE; | 125 virtual void TearDown() OVERRIDE; |
139 | 126 |
140 // Sends an IPC message to the IO thread channel. | 127 // Sends an IPC message to the IO thread channel. |
141 bool Send(IPC::Message* message); | 128 bool Send(IPC::Message* message); |
142 | 129 |
143 void SetAudioUtilCallback(AudioUtilInterface* callback); | 130 void SetAudioUtilCallback(AudioUtilInterface* callback); |
144 | 131 |
145 protected: | 132 protected: |
146 void InitializeIOThread(const char* thread_name); | 133 void InitializeIOThread(const char* thread_name); |
147 void UninitializeIOThread(); | 134 void UninitializeIOThread(); |
148 void CreateChannel(const char* name, | 135 void CreateChannel(const char* name); |
149 content::ResourceContext* resource_context); | |
150 void DestroyChannel(); | 136 void DestroyChannel(); |
151 | 137 |
152 void OnGetHardwareSampleRate(double* sample_rate); | 138 void OnGetHardwareSampleRate(double* sample_rate); |
153 void OnGetHardwareInputSampleRate(double* sample_rate); | 139 void OnGetHardwareInputSampleRate(double* sample_rate); |
154 | 140 |
155 // IPC::Channel::Listener implementation. | 141 // IPC::Channel::Listener implementation. |
156 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 142 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
157 | 143 |
158 // Posts a final task to the IO message loop and waits for completion. | 144 // Posts a final task to the IO message loop and waits for completion. |
159 void WaitForIOThreadCompletion(); | 145 void WaitForIOThreadCompletion(); |
| 146 void WaitForAudioManagerCompletion(); |
| 147 void WaitForMessageLoopCompletion(MessageLoop* loop); |
160 | 148 |
161 // Convenience getter for gmock. | 149 // Convenience getter for gmock. |
162 MockMediaObserver& media_observer() const { | 150 MockMediaObserver& media_observer() const { |
163 return *media_observer_.get(); | 151 return *media_observer_.get(); |
164 } | 152 } |
165 | 153 |
166 std::string GetTestDataPath(const FilePath::StringType& file_name); | 154 std::string GetTestDataPath(const FilePath::StringType& file_name); |
167 | 155 |
168 scoped_ptr<ReplaceContentClientRenderer> saved_content_renderer_; | 156 scoped_ptr<ReplaceContentClientRenderer> saved_content_renderer_; |
169 MessageLoopForUI message_loop_; | 157 MessageLoopForUI message_loop_; |
170 content::MockContentRendererClient mock_content_renderer_client_; | 158 content::MockContentRendererClient mock_content_renderer_client_; |
171 RenderThreadImpl* render_thread_; // Owned by mock_process_. | 159 RenderThreadImpl* render_thread_; // Owned by mock_process_. |
172 scoped_ptr<WebRTCMockRenderProcess> mock_process_; | 160 scoped_ptr<WebRTCMockRenderProcess> mock_process_; |
173 base::WaitableEvent event_; | |
174 scoped_ptr<MockMediaObserver> media_observer_; | 161 scoped_ptr<MockMediaObserver> media_observer_; |
175 scoped_ptr<media_stream::MediaStreamManager> media_stream_manager_; | 162 scoped_ptr<media_stream::MediaStreamManager> media_stream_manager_; |
| 163 scoped_refptr<AudioManager> audio_manager_; |
176 scoped_ptr<content::ResourceContext> resource_context_; | 164 scoped_ptr<content::ResourceContext> resource_context_; |
177 scoped_refptr<net::URLRequestContext> test_request_context_; | 165 scoped_refptr<net::URLRequestContext> test_request_context_; |
178 scoped_ptr<IPC::Channel> channel_; | 166 scoped_ptr<IPC::Channel> channel_; |
179 scoped_refptr<AudioRendererHost> audio_render_host_; | 167 scoped_refptr<AudioRendererHost> audio_render_host_; |
180 scoped_refptr<AudioInputRendererHost> audio_input_renderer_host_; | 168 scoped_refptr<AudioInputRendererHost> audio_input_renderer_host_; |
181 | 169 |
182 AudioUtilInterface* audio_util_callback_; // Weak reference. | 170 AudioUtilInterface* audio_util_callback_; // Weak reference. |
183 | 171 |
184 // Initialized on the main test thread that we mark as the UI thread. | 172 // Initialized on the main test thread that we mark as the UI thread. |
185 scoped_ptr<content::TestBrowserThread> ui_thread_; | 173 scoped_ptr<content::TestBrowserThread> ui_thread_; |
(...skipping 12 matching lines...) Expand all Loading... |
198 virtual ~WebRTCTransportImpl(); | 186 virtual ~WebRTCTransportImpl(); |
199 | 187 |
200 virtual int SendPacket(int channel, const void* data, int len) OVERRIDE; | 188 virtual int SendPacket(int channel, const void* data, int len) OVERRIDE; |
201 virtual int SendRTCPPacket(int channel, const void* data, int len) OVERRIDE; | 189 virtual int SendRTCPPacket(int channel, const void* data, int len) OVERRIDE; |
202 | 190 |
203 private: | 191 private: |
204 webrtc::VoENetwork* network_; | 192 webrtc::VoENetwork* network_; |
205 }; | 193 }; |
206 | 194 |
207 #endif // CONTENT_TEST_WEBRTC_AUDIO_DEVICE_TEST_H_ | 195 #endif // CONTENT_TEST_WEBRTC_AUDIO_DEVICE_TEST_H_ |
OLD | NEW |