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

Side by Side Diff: content/browser/renderer_host/media/audio_input_device_manager_unittest.cc

Issue 131503006: Initialization of audio manager for Android is now done on the audio thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: now compiles Created 6 years, 10 months 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
« no previous file with comments | « no previous file | content/browser/renderer_host/render_message_filter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 #include <string> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 23 matching lines...) Expand all
34 MOCK_METHOD2(DevicesEnumerated, void(MediaStreamType, 34 MOCK_METHOD2(DevicesEnumerated, void(MediaStreamType,
35 const StreamDeviceInfoArray&)); 35 const StreamDeviceInfoArray&));
36 MOCK_METHOD3(Error, void(MediaStreamType, int, MediaStreamProviderError)); 36 MOCK_METHOD3(Error, void(MediaStreamType, int, MediaStreamProviderError));
37 37
38 StreamDeviceInfoArray devices_; 38 StreamDeviceInfoArray devices_;
39 39
40 private: 40 private:
41 DISALLOW_COPY_AND_ASSIGN(MockAudioInputDeviceManagerListener); 41 DISALLOW_COPY_AND_ASSIGN(MockAudioInputDeviceManagerListener);
42 }; 42 };
43 43
44 class AudioInputDeviceManagerTest : public testing::Test { 44 // TODO(henrika): there are special restrictions for Android since
45 // AudioInputDeviceManager::Open() must be called on the audio thread.
46 // This test suite must be modified to run on Android.
47 #if defined(OS_ANDROID)
48 #define MAYBE_AudioInputDeviceManagerTest DISABLED_AudioInputDeviceManagerTest
49 #else
50 #define MAYBE_AudioInputDeviceManagerTest AudioInputDeviceManagerTest
51 #endif
52
53 class MAYBE_AudioInputDeviceManagerTest : public testing::Test {
45 public: 54 public:
46 AudioInputDeviceManagerTest() {} 55 MAYBE_AudioInputDeviceManagerTest() {}
47 56
48 // Returns true iff machine has an audio input device. 57 // Returns true iff machine has an audio input device.
49 bool CanRunAudioInputDeviceTests() { 58 bool CanRunAudioInputDeviceTests() {
50 return audio_manager_->HasAudioInputDevices(); 59 return audio_manager_->HasAudioInputDevices();
51 } 60 }
52 61
53 protected: 62 protected:
54 virtual void SetUp() OVERRIDE { 63 virtual void SetUp() OVERRIDE {
55 // The test must run on Browser::IO. 64 // The test must run on Browser::IO.
56 message_loop_.reset(new base::MessageLoopForIO); 65 message_loop_.reset(new base::MessageLoopForIO);
(...skipping 28 matching lines...) Expand all
85 } 94 }
86 95
87 scoped_ptr<base::MessageLoop> message_loop_; 96 scoped_ptr<base::MessageLoop> message_loop_;
88 scoped_ptr<BrowserThreadImpl> io_thread_; 97 scoped_ptr<BrowserThreadImpl> io_thread_;
89 scoped_refptr<AudioInputDeviceManager> manager_; 98 scoped_refptr<AudioInputDeviceManager> manager_;
90 scoped_ptr<MockAudioInputDeviceManagerListener> audio_input_listener_; 99 scoped_ptr<MockAudioInputDeviceManagerListener> audio_input_listener_;
91 scoped_ptr<media::AudioManager> audio_manager_; 100 scoped_ptr<media::AudioManager> audio_manager_;
92 StreamDeviceInfoArray devices_; 101 StreamDeviceInfoArray devices_;
93 102
94 private: 103 private:
95 DISALLOW_COPY_AND_ASSIGN(AudioInputDeviceManagerTest); 104 DISALLOW_COPY_AND_ASSIGN(MAYBE_AudioInputDeviceManagerTest);
96 }; 105 };
97 106
98 // Opens and closes the devices. 107 // Opens and closes the devices.
99 TEST_F(AudioInputDeviceManagerTest, OpenAndCloseDevice) { 108 TEST_F(MAYBE_AudioInputDeviceManagerTest, OpenAndCloseDevice) {
100 if (!CanRunAudioInputDeviceTests()) 109 if (!CanRunAudioInputDeviceTests())
101 return; 110 return;
102 111
103 ASSERT_FALSE(devices_.empty()); 112 ASSERT_FALSE(devices_.empty());
104 113
105 InSequence s; 114 InSequence s;
106 115
107 for (StreamDeviceInfoArray::const_iterator iter = devices_.begin(); 116 for (StreamDeviceInfoArray::const_iterator iter = devices_.begin();
108 iter != devices_.end(); ++iter) { 117 iter != devices_.end(); ++iter) {
109 // Opens/closes the devices. 118 // Opens/closes the devices.
(...skipping 10 matching lines...) Expand all
120 EXPECT_CALL(*audio_input_listener_, 129 EXPECT_CALL(*audio_input_listener_,
121 Closed(MEDIA_DEVICE_AUDIO_CAPTURE, session_id)) 130 Closed(MEDIA_DEVICE_AUDIO_CAPTURE, session_id))
122 .Times(1); 131 .Times(1);
123 132
124 // Waits for the callback. 133 // Waits for the callback.
125 message_loop_->RunUntilIdle(); 134 message_loop_->RunUntilIdle();
126 } 135 }
127 } 136 }
128 137
129 // Opens multiple devices at one time and closes them later. 138 // Opens multiple devices at one time and closes them later.
130 TEST_F(AudioInputDeviceManagerTest, OpenMultipleDevices) { 139 TEST_F(MAYBE_AudioInputDeviceManagerTest, OpenMultipleDevices) {
131 if (!CanRunAudioInputDeviceTests()) 140 if (!CanRunAudioInputDeviceTests())
132 return; 141 return;
133 142
134 ASSERT_FALSE(devices_.empty()); 143 ASSERT_FALSE(devices_.empty());
135 144
136 InSequence s; 145 InSequence s;
137 146
138 int index = 0; 147 int index = 0;
139 scoped_ptr<int[]> session_id(new int[devices_.size()]); 148 scoped_ptr<int[]> session_id(new int[devices_.size()]);
140 149
(...skipping 25 matching lines...) Expand all
166 EXPECT_CALL(*audio_input_listener_, 175 EXPECT_CALL(*audio_input_listener_,
167 Closed(MEDIA_DEVICE_AUDIO_CAPTURE, session_id[i])) 176 Closed(MEDIA_DEVICE_AUDIO_CAPTURE, session_id[i]))
168 .Times(1); 177 .Times(1);
169 178
170 // Waits for the callback. 179 // Waits for the callback.
171 message_loop_->RunUntilIdle(); 180 message_loop_->RunUntilIdle();
172 } 181 }
173 } 182 }
174 183
175 // Opens a non-existing device. 184 // Opens a non-existing device.
176 TEST_F(AudioInputDeviceManagerTest, OpenNotExistingDevice) { 185 TEST_F(MAYBE_AudioInputDeviceManagerTest, OpenNotExistingDevice) {
177 if (!CanRunAudioInputDeviceTests()) 186 if (!CanRunAudioInputDeviceTests())
178 return; 187 return;
179 InSequence s; 188 InSequence s;
180 189
181 MediaStreamType stream_type = MEDIA_DEVICE_AUDIO_CAPTURE; 190 MediaStreamType stream_type = MEDIA_DEVICE_AUDIO_CAPTURE;
182 std::string device_name("device_doesnt_exist"); 191 std::string device_name("device_doesnt_exist");
183 std::string device_id("id_doesnt_exist"); 192 std::string device_id("id_doesnt_exist");
184 int sample_rate(0); 193 int sample_rate(0);
185 int channel_config(0); 194 int channel_config(0);
186 StreamDeviceInfo dummy_device( 195 StreamDeviceInfo dummy_device(
187 stream_type, device_name, device_id, sample_rate, channel_config, 2048); 196 stream_type, device_name, device_id, sample_rate, channel_config, 2048);
188 197
189 int session_id = manager_->Open(dummy_device); 198 int session_id = manager_->Open(dummy_device);
190 EXPECT_CALL(*audio_input_listener_, 199 EXPECT_CALL(*audio_input_listener_,
191 Opened(MEDIA_DEVICE_AUDIO_CAPTURE, session_id)) 200 Opened(MEDIA_DEVICE_AUDIO_CAPTURE, session_id))
192 .Times(1); 201 .Times(1);
193 202
194 // Waits for the callback. 203 // Waits for the callback.
195 message_loop_->RunUntilIdle(); 204 message_loop_->RunUntilIdle();
196 } 205 }
197 206
198 // Opens default device twice. 207 // Opens default device twice.
199 TEST_F(AudioInputDeviceManagerTest, OpenDeviceTwice) { 208 TEST_F(MAYBE_AudioInputDeviceManagerTest, OpenDeviceTwice) {
200 if (!CanRunAudioInputDeviceTests()) 209 if (!CanRunAudioInputDeviceTests())
201 return; 210 return;
202 211
203 ASSERT_FALSE(devices_.empty()); 212 ASSERT_FALSE(devices_.empty());
204 213
205 InSequence s; 214 InSequence s;
206 215
207 // Opens and closes the default device twice. 216 // Opens and closes the default device twice.
208 int first_session_id = manager_->Open(devices_.front()); 217 int first_session_id = manager_->Open(devices_.front());
209 int second_session_id = manager_->Open(devices_.front()); 218 int second_session_id = manager_->Open(devices_.front());
(...skipping 15 matching lines...) Expand all
225 Closed(MEDIA_DEVICE_AUDIO_CAPTURE, first_session_id)) 234 Closed(MEDIA_DEVICE_AUDIO_CAPTURE, first_session_id))
226 .Times(1); 235 .Times(1);
227 EXPECT_CALL(*audio_input_listener_, 236 EXPECT_CALL(*audio_input_listener_,
228 Closed(MEDIA_DEVICE_AUDIO_CAPTURE, second_session_id)) 237 Closed(MEDIA_DEVICE_AUDIO_CAPTURE, second_session_id))
229 .Times(1); 238 .Times(1);
230 // Waits for the callback. 239 // Waits for the callback.
231 message_loop_->RunUntilIdle(); 240 message_loop_->RunUntilIdle();
232 } 241 }
233 242
234 // Accesses then closes the sessions after opening the devices. 243 // Accesses then closes the sessions after opening the devices.
235 TEST_F(AudioInputDeviceManagerTest, AccessAndCloseSession) { 244 TEST_F(MAYBE_AudioInputDeviceManagerTest, AccessAndCloseSession) {
236 if (!CanRunAudioInputDeviceTests()) 245 if (!CanRunAudioInputDeviceTests())
237 return; 246 return;
238 247
239 ASSERT_FALSE(devices_.empty()); 248 ASSERT_FALSE(devices_.empty());
240 249
241 InSequence s; 250 InSequence s;
242 251
243 int index = 0; 252 int index = 0;
244 scoped_ptr<int[]> session_id(new int[devices_.size()]); 253 scoped_ptr<int[]> session_id(new int[devices_.size()]);
245 254
(...skipping 15 matching lines...) Expand all
261 EXPECT_EQ(iter->device.id, info->device.id); 270 EXPECT_EQ(iter->device.id, info->device.id);
262 manager_->Close(session_id[index]); 271 manager_->Close(session_id[index]);
263 EXPECT_CALL(*audio_input_listener_, 272 EXPECT_CALL(*audio_input_listener_,
264 Closed(MEDIA_DEVICE_AUDIO_CAPTURE, session_id[index])) 273 Closed(MEDIA_DEVICE_AUDIO_CAPTURE, session_id[index]))
265 .Times(1); 274 .Times(1);
266 message_loop_->RunUntilIdle(); 275 message_loop_->RunUntilIdle();
267 } 276 }
268 } 277 }
269 278
270 // Access an invalid session. 279 // Access an invalid session.
271 TEST_F(AudioInputDeviceManagerTest, AccessInvalidSession) { 280 TEST_F(MAYBE_AudioInputDeviceManagerTest, AccessInvalidSession) {
272 if (!CanRunAudioInputDeviceTests()) 281 if (!CanRunAudioInputDeviceTests())
273 return; 282 return;
274 InSequence s; 283 InSequence s;
275 284
276 // Opens the first device. 285 // Opens the first device.
277 StreamDeviceInfoArray::const_iterator iter = devices_.begin(); 286 StreamDeviceInfoArray::const_iterator iter = devices_.begin();
278 int session_id = manager_->Open(*iter); 287 int session_id = manager_->Open(*iter);
279 EXPECT_CALL(*audio_input_listener_, 288 EXPECT_CALL(*audio_input_listener_,
280 Opened(MEDIA_DEVICE_AUDIO_CAPTURE, session_id)) 289 Opened(MEDIA_DEVICE_AUDIO_CAPTURE, session_id))
281 .Times(1); 290 .Times(1);
282 message_loop_->RunUntilIdle(); 291 message_loop_->RunUntilIdle();
283 292
284 // Access a non-opened device. 293 // Access a non-opened device.
285 // This should fail and return an empty StreamDeviceInfo. 294 // This should fail and return an empty StreamDeviceInfo.
286 int invalid_session_id = session_id + 1; 295 int invalid_session_id = session_id + 1;
287 const StreamDeviceInfo* info = 296 const StreamDeviceInfo* info =
288 manager_->GetOpenedDeviceInfoById(invalid_session_id); 297 manager_->GetOpenedDeviceInfoById(invalid_session_id);
289 DCHECK(!info); 298 DCHECK(!info);
290 299
291 manager_->Close(session_id); 300 manager_->Close(session_id);
292 EXPECT_CALL(*audio_input_listener_, 301 EXPECT_CALL(*audio_input_listener_,
293 Closed(MEDIA_DEVICE_AUDIO_CAPTURE, session_id)) 302 Closed(MEDIA_DEVICE_AUDIO_CAPTURE, session_id))
294 .Times(1); 303 .Times(1);
295 message_loop_->RunUntilIdle(); 304 message_loop_->RunUntilIdle();
296 } 305 }
297 306
298 } // namespace content 307 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/render_message_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698