Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: content/test/webrtc_audio_device_test.h

Issue 8427031: First unit tests for WebRTCAudioDevice. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
## -0,0 +1 ##
+LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_TEST_WEBRTC_AUDIO_DEVICE_TEST_H_
6 #define CONTENT_TEST_WEBRTC_AUDIO_DEVICE_TEST_H_
7 #pragma once
8
9 #include "base/file_path.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "content/browser/renderer_host/media/mock_media_observer.h"
13 #include "content/renderer/media/audio_renderer_impl.h"
14 #include "content/renderer/mock_content_renderer_client.h"
15 #include "ipc/ipc_channel.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "third_party/webrtc/common_types.h"
18
19 class AudioInputRendererHost;
20 class AudioRendererHost;
21 class RenderThreadImpl;
22 class WebRTCMockRenderProcess;
23
24 namespace content {
25 class ContentRendererClient;
26 class ResourceContext;
27 class TestBrowserThread;
28 }
29
30 namespace net {
31 class URLRequestContext;
32 }
33
34 namespace webrtc {
35 class VoENetwork;
36 }
37
38 // Scoped class for WebRTC interfaces. Fetches the wrapped interface
39 // in the constructor via WebRTC's GetInterface mechanism and then releases
40 // the reference in the destructor.
41 template<typename T>
42 class ScopedWebRTCPtr {
43 public:
44 template<typename Engine>
45 explicit ScopedWebRTCPtr(Engine* e)
46 : ptr_(T::GetInterface(e)) {}
47 explicit ScopedWebRTCPtr(T* p) : ptr_(p) {}
48 ~ScopedWebRTCPtr() { reset(); }
49 T* operator->() const { return ptr_; }
50 T* get() const { return ptr_; }
51
52 // Releases the current pointer.
53 void reset() {
54 if (ptr_) {
55 ptr_->Release();
56 ptr_ = NULL;
57 }
58 }
59
60 bool valid() const { return ptr_ != NULL; }
61
62 private:
63 T* ptr_;
64 };
65
66 // Wrapper to automatically calling T::Delete in the destructor.
67 // This is useful for some WebRTC objects that have their own Create/Delete
68 // methods and we can't use our our scoped_* classes.
69 template <typename T>
70 class WebRTCAutoDelete {
71 public:
72 WebRTCAutoDelete() : ptr_(NULL) {}
73 explicit WebRTCAutoDelete(T* ptr) : ptr_(ptr) {}
74 ~WebRTCAutoDelete() { reset(); }
75
76 void reset() {
77 if (ptr_) {
78 T::Delete(ptr_);
79 ptr_ = NULL;
80 }
81 }
82
83 T* operator->() { return ptr_; }
84 T* get() const { return ptr_; }
85
86 bool valid() const { return ptr_ != NULL; }
87
88 protected:
89 T* ptr_;
90 };
91
92 // Individual tests can provide an implementation (or mock) of this interface
93 // when the audio code queries for hardware capabilities on the IO thread.
94 class AudioUtilInterface {
95 public:
96 virtual double GetAudioHardwareSampleRate() = 0;
97 virtual double GetAudioInputHardwareSampleRate() = 0;
98 };
99
100 class WebRTCAudioDeviceTest
101 : public ::testing::Test,
102 public IPC::Channel::Listener {
103 public:
104 class SetupTask : public base::RefCountedThreadSafe<SetupTask> {
105 public:
106 explicit SetupTask(WebRTCAudioDeviceTest* test) : test_(test) {}
Paweł Hajdan Jr. 2011/11/02 18:00:24 nit: Ah, it's probably useful to DCHECK here (if t
tommi (sloooow) - chröme 2011/11/04 08:59:00 Done.
107 void InitializeIOThread(const char* thread_name) {
108 test_->InitializeIOThread(thread_name);
109 }
110 void UninitializeIOThread() { test_->UninitializeIOThread(); }
111 protected:
112 WebRTCAudioDeviceTest* test_;
113 };
114
115 WebRTCAudioDeviceTest();
116 virtual ~WebRTCAudioDeviceTest();
117
118 virtual void SetUp();
119 virtual void TearDown();
120
121 // Sends an IPC message to the IO thread channel.
122 bool Send(IPC::Message* message);
123
124 void set_audio_util_callback(AudioUtilInterface* callback) {
125 audio_util_callback_ = callback;
126 }
127
128 protected:
129 void InitializeIOThread(const char* thread_name);
130 void UninitializeIOThread();
131 void CreateChannel(const char* name,
132 content::ResourceContext* resource_context);
133 void DestroyChannel();
134
135 void OnGetHardwareSampleRate(double* sample_rate);
136 void OnGetHardwareInputSampleRate(double* sample_rate);
137
138 // IPC::Channel::Listener implementation.
139 virtual bool OnMessageReceived(const IPC::Message& message);
140
141 // Posts a final task to the IO message loop and waits for completion.
142 void WaitForIOThreadCompletion();
143
144 // Convenience getter for gmock.
145 MockMediaObserver& media_observer() const {
146 return *media_observer_.get();
147 }
148
149 std::string GetTestDataPath(const FilePath::StringType& file_name);
150
151 // Actual implementation of the short and long PlayFile tests.
152 // If the |duration| parameter is 0, then the function determines the length
153 // of the audio file and plays the entire file. Otherwise, |duration|
154 // specifies the number of milliseconds to allow the file to play.
155 void PlayLocalFile(int duration);
156
157 content::ContentRendererClient* saved_content_renderer_;
158 MessageLoopForUI message_loop_;
159 content::MockContentRendererClient mock_content_renderer_client_;
160 RenderThreadImpl* render_thread_; // owned by mock_process_
161 scoped_ptr<WebRTCMockRenderProcess> mock_process_;
162 //media::MockFilterHost host_;
163 base::WaitableEvent event_;
164 scoped_ptr<MockMediaObserver> media_observer_;
165 scoped_ptr<content::ResourceContext> resource_context_;
166 scoped_refptr<net::URLRequestContext> test_request_context_;
167 scoped_ptr<IPC::Channel> channel_;
168 scoped_refptr<AudioRendererHost> audio_render_host_;
169 AudioUtilInterface* audio_util_callback_; // Weak reference.
170
171 // Initialized on the main test thread that we mark as the UI thread.
172 scoped_ptr<content::TestBrowserThread> ui_thread_;
173 // Initialized on our IO thread to satisfy BrowserThread::IO checks.
174 scoped_ptr<content::TestBrowserThread> io_thread_;
175 };
176
177 // A very basic implementation of webrtc::Transport that acts as a transport
178 // but just forwards all calls to a local webrtc::VoENetwork implementation.
179 // Ownership of the VoENetwork object lies outside the class.
180 class WebRTCTransportImpl : public webrtc::Transport {
181 public:
182 explicit WebRTCTransportImpl(webrtc::VoENetwork* network);
183 virtual ~WebRTCTransportImpl();
184
185 virtual int SendPacket(int channel, const void* data, int len);
186 virtual int SendRTCPPacket(int channel, const void* data, int len);
187
188 private:
189 webrtc::VoENetwork* network_;
190 };
191
192 #endif // CONTENT_TEST_WEBRTC_AUDIO_DEVICE_TEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698