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

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 // Implemented and defined in the cc file.
101 class ReplaceContentClientRenderer;
102
103 class WebRTCAudioDeviceTest
104 : public ::testing::Test,
105 public IPC::Channel::Listener {
106 public:
107 class SetupTask : public base::RefCountedThreadSafe<SetupTask> {
108 public:
109 explicit SetupTask(WebRTCAudioDeviceTest* test) : test_(test) {
110 DCHECK(test); // Catch this early since we dereference much later.
111 }
112 void InitializeIOThread(const char* thread_name) {
113 test_->InitializeIOThread(thread_name);
114 }
115 void UninitializeIOThread() { test_->UninitializeIOThread(); }
116 protected:
117 WebRTCAudioDeviceTest* test_;
118 };
119
120 WebRTCAudioDeviceTest();
121 virtual ~WebRTCAudioDeviceTest();
122
123 virtual void SetUp();
124 virtual void TearDown();
125
126 // Sends an IPC message to the IO thread channel.
127 bool Send(IPC::Message* message);
128
129 void set_audio_util_callback(AudioUtilInterface* callback) {
130 audio_util_callback_ = callback;
131 }
132
133 protected:
134 void InitializeIOThread(const char* thread_name);
135 void UninitializeIOThread();
136 void CreateChannel(const char* name,
137 content::ResourceContext* resource_context);
138 void DestroyChannel();
139
140 void OnGetHardwareSampleRate(double* sample_rate);
141 void OnGetHardwareInputSampleRate(double* sample_rate);
142
143 // IPC::Channel::Listener implementation.
144 virtual bool OnMessageReceived(const IPC::Message& message);
145
146 // Posts a final task to the IO message loop and waits for completion.
147 void WaitForIOThreadCompletion();
148
149 // Convenience getter for gmock.
150 MockMediaObserver& media_observer() const {
151 return *media_observer_.get();
152 }
153
154 std::string GetTestDataPath(const FilePath::StringType& file_name);
155
156 scoped_ptr<ReplaceContentClientRenderer> saved_content_renderer_;
157 MessageLoopForUI message_loop_;
158 content::MockContentRendererClient mock_content_renderer_client_;
159 RenderThreadImpl* render_thread_; // Owned by mock_process_.
160 scoped_ptr<WebRTCMockRenderProcess> mock_process_;
161 base::WaitableEvent event_;
162 scoped_ptr<MockMediaObserver> media_observer_;
163 scoped_ptr<content::ResourceContext> resource_context_;
164 scoped_refptr<net::URLRequestContext> test_request_context_;
165 scoped_ptr<IPC::Channel> channel_;
166 scoped_refptr<AudioRendererHost> audio_render_host_;
167 AudioUtilInterface* audio_util_callback_; // Weak reference.
168
169 // Initialized on the main test thread that we mark as the UI thread.
170 scoped_ptr<content::TestBrowserThread> ui_thread_;
171 // Initialized on our IO thread to satisfy BrowserThread::IO checks.
172 scoped_ptr<content::TestBrowserThread> io_thread_;
173 };
174
175 // A very basic implementation of webrtc::Transport that acts as a transport
176 // but just forwards all calls to a local webrtc::VoENetwork implementation.
177 // Ownership of the VoENetwork object lies outside the class.
178 class WebRTCTransportImpl : public webrtc::Transport {
179 public:
180 explicit WebRTCTransportImpl(webrtc::VoENetwork* network);
181 virtual ~WebRTCTransportImpl();
182
183 virtual int SendPacket(int channel, const void* data, int len);
184 virtual int SendRTCPPacket(int channel, const void* data, int len);
185
186 private:
187 webrtc::VoENetwork* network_;
188 };
189
190 #endif // CONTENT_TEST_WEBRTC_AUDIO_DEVICE_TEST_H_
OLDNEW
« no previous file with comments | « content/renderer/media/webrtc_audio_device_unittest.cc ('k') | content/test/webrtc_audio_device_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698