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

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

Issue 10662049: Move the device enumerate/open/close work to device thread from IO thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed Magnus' comments. Created 8 years, 5 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
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.h" 10 #include "base/message_loop.h"
11 #include "content/browser/browser_main_loop.h"
11 #include "content/browser/browser_thread_impl.h" 12 #include "content/browser/browser_thread_impl.h"
12 #include "content/browser/renderer_host/media/audio_input_device_manager.h" 13 #include "content/browser/renderer_host/media/audio_input_device_manager.h"
13 #include "content/browser/renderer_host/media/audio_input_device_manager_event_h andler.h" 14 #include "content/browser/renderer_host/media/audio_input_device_manager_event_h andler.h"
15 #include "content/public/common/content_switches.h"
16 #include "content/public/common/main_function_params.h"
14 #include "media/audio/audio_manager_base.h" 17 #include "media/audio/audio_manager_base.h"
15 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
17 20
21 using content::BrowserMainLoop;
18 using content::BrowserThread; 22 using content::BrowserThread;
19 using content::BrowserThreadImpl; 23 using content::BrowserThreadImpl;
20 using media_stream::AudioInputDeviceManager; 24 using media_stream::AudioInputDeviceManager;
21 using testing::_; 25 using testing::_;
22 using testing::AnyNumber; 26 using testing::AnyNumber;
23 using testing::InSequence; 27 using testing::InSequence;
24 using testing::Return; 28 using testing::Return;
25 29
26 namespace media_stream { 30 namespace media_stream {
27 31
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 DISALLOW_COPY_AND_ASSIGN(MockAudioInputDeviceManagerEventHandler); 85 DISALLOW_COPY_AND_ASSIGN(MockAudioInputDeviceManagerEventHandler);
82 }; 86 };
83 87
84 ACTION_P(ExitMessageLoop, message_loop) { 88 ACTION_P(ExitMessageLoop, message_loop) {
85 message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 89 message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure());
86 } 90 }
87 91
88 class AudioInputDeviceManagerTest : public testing::Test { 92 class AudioInputDeviceManagerTest : public testing::Test {
89 public: 93 public:
90 AudioInputDeviceManagerTest() 94 AudioInputDeviceManagerTest()
91 : message_loop_(), 95 : io_thread_(),
92 io_thread_(),
93 manager_(), 96 manager_(),
94 audio_input_listener_() { 97 audio_input_listener_() {
95 } 98 }
96 99
97 // Returns true iff machine has an audio input device. 100 // Returns true if machine has an audio input device.
tommi (sloooow) - chröme 2012/07/02 13:36:36 I don't think that 'iff' was a typo if that's what
no longer working on chromium 2012/07/04 12:35:25 Good to know, thanks. Done.
98 bool CanRunAudioInputDeviceTests() { 101 bool CanRunAudioInputDeviceTests() {
99 return audio_manager_->HasAudioInputDevices(); 102 return BrowserMainLoop::GetAudioManager()->HasAudioInputDevices();
100 } 103 }
101 104
102 protected: 105 protected:
103 virtual void SetUp() { 106 virtual void SetUp() {
tommi (sloooow) - chröme 2012/07/02 13:36:36 OVERRIDE?
no longer working on chromium 2012/07/04 12:35:25 Done.
107 CommandLine command_line = CommandLine(CommandLine::NO_PROGRAM);
108 content::MainFunctionParams params_=
109 content::MainFunctionParams(command_line);
110 main_loop_.reset(new content::BrowserMainLoop(params_));
111 main_loop_->Init();
112 main_loop_->MainMessageLoopStart();
113
104 // The test must run on Browser::IO. 114 // The test must run on Browser::IO.
105 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO));
106 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO, 115 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO,
107 message_loop_.get())); 116 MessageLoop::current()));
108 audio_manager_.reset(media::AudioManager::Create());
109 117
110 manager_ = new AudioInputDeviceManager(audio_manager_.get()); 118 manager_ = new AudioInputDeviceManager(
119 MessageLoop::current()->message_loop_proxy());
111 audio_input_listener_.reset(new MockAudioInputDeviceManagerListener()); 120 audio_input_listener_.reset(new MockAudioInputDeviceManagerListener());
112 manager_->Register(audio_input_listener_.get()); 121 manager_->Register(audio_input_listener_.get());
113 122
114 // Gets the enumerated device list from the AudioInputDeviceManager. 123 // Gets the enumerated device list from the AudioInputDeviceManager.
115 manager_->EnumerateDevices(); 124 manager_->EnumerateDevices();
116 EXPECT_CALL(*audio_input_listener_, DevicesEnumerated(_)) 125 EXPECT_CALL(*audio_input_listener_, DevicesEnumerated(_))
117 .Times(1); 126 .Times(1);
118 127
119 // Waits for the callback. 128 // Wait until we get the list.
120 message_loop_->RunAllPending(); 129 MessageLoop::current()->RunAllPending();
121 } 130 }
122 131
123 virtual void TearDown() { 132 virtual void TearDown() {
124 manager_->Unregister(); 133 manager_->Unregister();
125 io_thread_.reset(); 134 io_thread_.reset();
126 } 135 }
127 136
128 scoped_ptr<MessageLoop> message_loop_;
129 scoped_ptr<BrowserThreadImpl> io_thread_; 137 scoped_ptr<BrowserThreadImpl> io_thread_;
130 scoped_refptr<AudioInputDeviceManager> manager_; 138 scoped_refptr<AudioInputDeviceManager> manager_;
131 scoped_ptr<MockAudioInputDeviceManagerListener> audio_input_listener_; 139 scoped_ptr<MockAudioInputDeviceManagerListener> audio_input_listener_;
132 scoped_ptr<media::AudioManager> audio_manager_; 140 scoped_ptr<media::AudioManager> audio_manager_;
141 scoped_ptr<content::BrowserMainLoop> main_loop_;
133 142
134 private: 143 private:
135 DISALLOW_COPY_AND_ASSIGN(AudioInputDeviceManagerTest); 144 DISALLOW_COPY_AND_ASSIGN(AudioInputDeviceManagerTest);
136 }; 145 };
137 146
138 // Opens and closes the devices. 147 // Opens and closes the devices.
139 TEST_F(AudioInputDeviceManagerTest, OpenAndCloseDevice) { 148 TEST_F(AudioInputDeviceManagerTest, OpenAndCloseDevice) {
140 if (!CanRunAudioInputDeviceTests()) 149 if (!CanRunAudioInputDeviceTests())
141 return; 150 return;
142 151
(...skipping 11 matching lines...) Expand all
154 // Expected mock call with expected return value. 163 // Expected mock call with expected return value.
155 EXPECT_CALL(*audio_input_listener_, 164 EXPECT_CALL(*audio_input_listener_,
156 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 165 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
157 session_id)) 166 session_id))
158 .Times(1); 167 .Times(1);
159 EXPECT_CALL(*audio_input_listener_, 168 EXPECT_CALL(*audio_input_listener_,
160 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 169 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
161 session_id)) 170 session_id))
162 .Times(1); 171 .Times(1);
163 172
164 // Waits for the callback. 173 MessageLoop::current()->RunAllPending();
165 message_loop_->RunAllPending();
166 } 174 }
167 } 175 }
168 176
169 // Opens multiple devices at one time and closes them later. 177 // Opens multiple devices at one time and closes them later.
170 TEST_F(AudioInputDeviceManagerTest, OpenMultipleDevices) { 178 TEST_F(AudioInputDeviceManagerTest, OpenMultipleDevices) {
171 if (!CanRunAudioInputDeviceTests()) 179 if (!CanRunAudioInputDeviceTests())
172 return; 180 return;
173 181
174 ASSERT_FALSE(audio_input_listener_->devices_.empty()); 182 ASSERT_FALSE(audio_input_listener_->devices_.empty());
175 183
176 InSequence s; 184 InSequence s;
177 185
178 int index = 0; 186 int index = 0;
179 const int kDeviceSize = audio_input_listener_->devices_.size(); 187 const int kDeviceSize = audio_input_listener_->devices_.size();
180 scoped_array<int> session_id(new int[kDeviceSize]); 188 scoped_array<int> session_id(new int[kDeviceSize]);
181 189
182 // Opens the devices in a loop. 190 // Opens the devices in a loop.
183 for (StreamDeviceInfoArray::const_iterator iter = 191 for (StreamDeviceInfoArray::const_iterator iter =
184 audio_input_listener_->devices_.begin(); 192 audio_input_listener_->devices_.begin();
185 iter != audio_input_listener_->devices_.end(); ++iter, ++index) { 193 iter != audio_input_listener_->devices_.end(); ++iter, ++index) {
186 // Opens the devices. 194 // Opens the devices.
187 session_id[index] = manager_->Open(*iter); 195 session_id[index] = manager_->Open(*iter);
188 196
189 // Expected mock call with expected returned value. 197 // Expected mock call with expected returned value.
190 EXPECT_CALL(*audio_input_listener_, 198 EXPECT_CALL(*audio_input_listener_,
191 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 199 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
192 session_id[index])) 200 session_id[index]))
193 .Times(1); 201 .Times(1);
194 202
195 // Waits for the callback. 203 MessageLoop::current()->RunAllPending();
196 message_loop_->RunAllPending();
197 } 204 }
198 205
199 // Checks if the session_ids are unique. 206 // Checks if the session_ids are unique.
200 for (int i = 0; i < kDeviceSize - 1; ++i) { 207 for (int i = 0; i < kDeviceSize - 1; ++i) {
201 for (int k = i+1; k < kDeviceSize; ++k) { 208 for (int k = i+1; k < kDeviceSize; ++k) {
202 EXPECT_TRUE(session_id[i] != session_id[k]); 209 EXPECT_TRUE(session_id[i] != session_id[k]);
203 } 210 }
204 } 211 }
205 212
206 for (int i = 0; i < kDeviceSize; ++i) { 213 for (int i = 0; i < kDeviceSize; ++i) {
207 // Closes the devices. 214 // Closes the devices.
208 manager_->Close(session_id[i]); 215 manager_->Close(session_id[i]);
209 EXPECT_CALL(*audio_input_listener_, 216 EXPECT_CALL(*audio_input_listener_,
210 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 217 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
211 session_id[i])) 218 session_id[i]))
212 .Times(1); 219 .Times(1);
213 220
214 // Waits for the callback. 221 MessageLoop::current()->RunAllPending();
215 message_loop_->RunAllPending();
216 } 222 }
217 } 223 }
218 224
219 // Opens a non-existing device. 225 // Opens a non-existing device.
220 TEST_F(AudioInputDeviceManagerTest, OpenNotExistingDevice) { 226 TEST_F(AudioInputDeviceManagerTest, OpenNotExistingDevice) {
221 if (!CanRunAudioInputDeviceTests()) 227 if (!CanRunAudioInputDeviceTests())
222 return; 228 return;
223 InSequence s; 229 InSequence s;
224 230
225 MediaStreamType stream_type = content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE; 231 MediaStreamType stream_type = content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE;
226 std::string device_name("device_doesnt_exist"); 232 std::string device_name("device_doesnt_exist");
227 std::string device_id("id_doesnt_exist"); 233 std::string device_id("id_doesnt_exist");
228 StreamDeviceInfo dummy_device(stream_type, device_name, device_id, false); 234 StreamDeviceInfo dummy_device(stream_type, device_name, device_id, false);
229 235
230 int session_id = manager_->Open(dummy_device); 236 int session_id = manager_->Open(dummy_device);
231 EXPECT_CALL(*audio_input_listener_, 237 EXPECT_CALL(*audio_input_listener_,
232 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 238 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
233 session_id)) 239 session_id))
234 .Times(1); 240 .Times(1);
235 241
236 // Waits for the callback. 242 MessageLoop::current()->RunAllPending();
237 message_loop_->RunAllPending();
238 } 243 }
239 244
240 // Opens default device twice. 245 // Opens default device twice.
241 TEST_F(AudioInputDeviceManagerTest, OpenDeviceTwice) { 246 TEST_F(AudioInputDeviceManagerTest, OpenDeviceTwice) {
242 if (!CanRunAudioInputDeviceTests()) 247 if (!CanRunAudioInputDeviceTests())
243 return; 248 return;
244 249
245 ASSERT_FALSE(audio_input_listener_->devices_.empty()); 250 ASSERT_FALSE(audio_input_listener_->devices_.empty());
246 251
247 InSequence s; 252 InSequence s;
(...skipping 18 matching lines...) Expand all
266 .Times(1); 271 .Times(1);
267 EXPECT_CALL(*audio_input_listener_, 272 EXPECT_CALL(*audio_input_listener_,
268 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 273 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
269 first_session_id)) 274 first_session_id))
270 .Times(1); 275 .Times(1);
271 EXPECT_CALL(*audio_input_listener_, 276 EXPECT_CALL(*audio_input_listener_,
272 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 277 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
273 second_session_id)) 278 second_session_id))
274 .Times(1); 279 .Times(1);
275 280
276 // Waits for the callback. 281 MessageLoop::current()->RunAllPending();
277 message_loop_->RunAllPending();
278 } 282 }
279 283
280 // Starts and closes the sessions after opening the devices. 284 // Starts and closes the sessions after opening the devices.
281 TEST_F(AudioInputDeviceManagerTest, StartAndStopSession) { 285 TEST_F(AudioInputDeviceManagerTest, StartAndStopSession) {
282 if (!CanRunAudioInputDeviceTests()) 286 if (!CanRunAudioInputDeviceTests())
283 return; 287 return;
284 288
285 ASSERT_FALSE(audio_input_listener_->devices_.empty()); 289 ASSERT_FALSE(audio_input_listener_->devices_.empty());
286 290
287 InSequence s; 291 InSequence s;
288 292
289 int index = 0; 293 int index = 0;
290 const int kDeviceSize = audio_input_listener_->devices_.size(); 294 const int kDeviceSize = audio_input_listener_->devices_.size();
291 scoped_array<int> session_id(new int[kDeviceSize]); 295 scoped_array<int> session_id(new int[kDeviceSize]);
292 296
293 // Creates the EventHandler for the sessions. 297 // Creates the EventHandler for the sessions.
294 scoped_ptr<MockAudioInputDeviceManagerEventHandler> 298 scoped_ptr<MockAudioInputDeviceManagerEventHandler>
295 audio_input_event_handler( 299 audio_input_event_handler(
296 new MockAudioInputDeviceManagerEventHandler(message_loop_.get())); 300 new MockAudioInputDeviceManagerEventHandler(MessageLoop::current()));
297 301
298 // Loops through the devices and calls Open()/Start()/Stop()/Close() for 302 // Loops through the devices and calls Open()/Start()/Stop()/Close() for
299 // each device. 303 // each device.
300 for (StreamDeviceInfoArray::const_iterator iter = 304 for (StreamDeviceInfoArray::const_iterator iter =
301 audio_input_listener_->devices_.begin(); 305 audio_input_listener_->devices_.begin();
302 iter != audio_input_listener_->devices_.end(); ++iter, ++index) { 306 iter != audio_input_listener_->devices_.end(); ++iter, ++index) {
303 // Note that no DeviceStopped() notification for Event Handler as we have 307 // Note that no DeviceStopped() notification for Event Handler as we have
304 // stopped the device before calling close. 308 // stopped the device before calling close.
305 session_id[index] = manager_->Open(*iter); 309 session_id[index] = manager_->Open(*iter);
306 EXPECT_CALL(*audio_input_listener_, 310 EXPECT_CALL(*audio_input_listener_,
307 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 311 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
308 session_id[index])) 312 session_id[index]))
309 .Times(1); 313 .Times(1);
310 message_loop_->RunAllPending(); 314 MessageLoop::current()->RunAllPending();
311 315
312 manager_->Start(session_id[index], audio_input_event_handler.get()); 316 manager_->Start(session_id[index], audio_input_event_handler.get());
313 EXPECT_CALL(*audio_input_event_handler, 317 EXPECT_CALL(*audio_input_event_handler,
314 DeviceStarted(session_id[index], iter->device_id)) 318 DeviceStarted(session_id[index], iter->device_id))
315 .Times(1); 319 .Times(1);
316 message_loop_->RunAllPending(); 320 MessageLoop::current()->RunAllPending();
317 321
318 manager_->Stop(session_id[index]); 322 manager_->Stop(session_id[index]);
319 manager_->Close(session_id[index]); 323 manager_->Close(session_id[index]);
320 EXPECT_CALL(*audio_input_listener_, 324 EXPECT_CALL(*audio_input_listener_,
321 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 325 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
322 session_id[index])) 326 session_id[index]))
323 .Times(1); 327 .Times(1);
324 message_loop_->RunAllPending(); 328 MessageLoop::current()->RunAllPending();
325 } 329 }
326 } 330 }
327 331
328 // Tests the behavior of calling Close() without calling Stop(). 332 // Tests the behavior of calling Close() without calling Stop().
329 TEST_F(AudioInputDeviceManagerTest, CloseWithoutStopSession) { 333 TEST_F(AudioInputDeviceManagerTest, CloseWithoutStopSession) {
330 if (!CanRunAudioInputDeviceTests()) 334 if (!CanRunAudioInputDeviceTests())
331 return; 335 return;
332 336
333 ASSERT_FALSE(audio_input_listener_->devices_.empty()); 337 ASSERT_FALSE(audio_input_listener_->devices_.empty());
334 338
335 InSequence s; 339 InSequence s;
336 340
337 int index = 0; 341 int index = 0;
338 const int kDeviceSize = audio_input_listener_->devices_.size(); 342 const int kDeviceSize = audio_input_listener_->devices_.size();
339 scoped_array<int> session_id(new int[kDeviceSize]); 343 scoped_array<int> session_id(new int[kDeviceSize]);
340 344
341 // Creates the EventHandlers for the sessions. 345 // Creates the EventHandlers for the sessions.
342 scoped_ptr<MockAudioInputDeviceManagerEventHandler> 346 scoped_ptr<MockAudioInputDeviceManagerEventHandler>
343 audio_input_event_handler( 347 audio_input_event_handler(
344 new MockAudioInputDeviceManagerEventHandler(message_loop_.get())); 348 new MockAudioInputDeviceManagerEventHandler(MessageLoop::current()));
345 349
346 // Loop through the devices, and calls Open()/Start()/Close() for the devices. 350 // Loop through the devices, and calls Open()/Start()/Close() for the devices.
347 // Note that we do not call stop. 351 // Note that we do not call stop.
348 for (StreamDeviceInfoArray::const_iterator iter = 352 for (StreamDeviceInfoArray::const_iterator iter =
349 audio_input_listener_->devices_.begin(); 353 audio_input_listener_->devices_.begin();
350 iter != audio_input_listener_->devices_.end(); ++iter, ++index) { 354 iter != audio_input_listener_->devices_.end(); ++iter, ++index) {
351 // Calls Open()/Start()/Close() for each device. 355 // Calls Open()/Start()/Close() for each device.
352 session_id[index] = manager_->Open(*iter); 356 session_id[index] = manager_->Open(*iter);
353 EXPECT_CALL(*audio_input_listener_, 357 EXPECT_CALL(*audio_input_listener_,
354 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 358 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
355 session_id[index])) 359 session_id[index]))
356 .Times(1); 360 .Times(1);
357 message_loop_->RunAllPending(); 361 MessageLoop::current()->RunAllPending();
358 362
359 manager_->Start(session_id[index], audio_input_event_handler.get()); 363 manager_->Start(session_id[index], audio_input_event_handler.get());
360 EXPECT_CALL(*audio_input_event_handler, 364 EXPECT_CALL(*audio_input_event_handler,
361 DeviceStarted(session_id[index], iter->device_id)) 365 DeviceStarted(session_id[index], iter->device_id))
362 .Times(1); 366 .Times(1);
363 message_loop_->RunAllPending(); 367 MessageLoop::current()->RunAllPending();
364 368
365 // Event Handler should get a stop device notification as no stop is called 369 // Event Handler should get a stop device notification as no stop is called
366 // before closing the device. 370 // before closing the device.
367 manager_->Close(session_id[index]); 371 manager_->Close(session_id[index]);
368 EXPECT_CALL(*audio_input_event_handler, 372 EXPECT_CALL(*audio_input_event_handler,
369 DeviceStopped(session_id[index])) 373 DeviceStopped(session_id[index]))
370 .Times(1); 374 .Times(1);
371 EXPECT_CALL(*audio_input_listener_, 375 EXPECT_CALL(*audio_input_listener_,
372 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 376 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
373 session_id[index])) 377 session_id[index]))
374 .Times(1); 378 .Times(1);
375 message_loop_->RunAllPending(); 379 MessageLoop::current()->RunAllPending();
376 } 380 }
377 } 381 }
378 382
379 // Starts the same device twice. 383 // Starts the same device twice.
380 TEST_F(AudioInputDeviceManagerTest, StartDeviceTwice) { 384 TEST_F(AudioInputDeviceManagerTest, StartDeviceTwice) {
381 if (!CanRunAudioInputDeviceTests()) 385 if (!CanRunAudioInputDeviceTests())
382 return; 386 return;
383 387
384 ASSERT_FALSE(audio_input_listener_->devices_.empty()); 388 ASSERT_FALSE(audio_input_listener_->devices_.empty());
385 389
386 InSequence s; 390 InSequence s;
387 391
388 // Create one EventHandler for each session. 392 // Create one EventHandler for each session.
389 scoped_ptr<MockAudioInputDeviceManagerEventHandler> 393 scoped_ptr<MockAudioInputDeviceManagerEventHandler>
390 first_event_handler( 394 first_event_handler(
391 new MockAudioInputDeviceManagerEventHandler(message_loop_.get())); 395 new MockAudioInputDeviceManagerEventHandler(MessageLoop::current()));
392 scoped_ptr<MockAudioInputDeviceManagerEventHandler> 396 scoped_ptr<MockAudioInputDeviceManagerEventHandler>
393 second_event_handler( 397 second_event_handler(
394 new MockAudioInputDeviceManagerEventHandler(message_loop_.get())); 398 new MockAudioInputDeviceManagerEventHandler(MessageLoop::current()));
395 399
396 // Open the default device twice. 400 // Open the default device twice.
397 StreamDeviceInfoArray::const_iterator iter = 401 StreamDeviceInfoArray::const_iterator iter =
398 audio_input_listener_->devices_.begin(); 402 audio_input_listener_->devices_.begin();
399 int first_session_id = manager_->Open(*iter); 403 int first_session_id = manager_->Open(*iter);
400 int second_session_id = manager_->Open(*iter); 404 int second_session_id = manager_->Open(*iter);
401 EXPECT_NE(first_session_id, second_session_id); 405 EXPECT_NE(first_session_id, second_session_id);
402 EXPECT_CALL(*audio_input_listener_, 406 EXPECT_CALL(*audio_input_listener_,
403 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 407 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
404 first_session_id)) 408 first_session_id))
405 .Times(1); 409 .Times(1);
406 EXPECT_CALL(*audio_input_listener_, 410 EXPECT_CALL(*audio_input_listener_,
407 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 411 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
408 second_session_id)) 412 second_session_id))
409 .Times(1); 413 .Times(1);
410 message_loop_->RunAllPending(); 414 MessageLoop::current()->RunAllPending();
411 415
412 // Calls Start()/Stop()/Close() for the default device twice. 416 // Calls Start()/Stop()/Close() for the default device twice.
413 manager_->Start(first_session_id, first_event_handler.get()); 417 manager_->Start(first_session_id, first_event_handler.get());
414 manager_->Start(second_session_id, second_event_handler.get()); 418 manager_->Start(second_session_id, second_event_handler.get());
415 EXPECT_CALL(*first_event_handler, 419 EXPECT_CALL(*first_event_handler,
416 DeviceStarted(first_session_id, 420 DeviceStarted(first_session_id,
417 media::AudioManagerBase::kDefaultDeviceId)) 421 media::AudioManagerBase::kDefaultDeviceId))
418 .Times(1); 422 .Times(1);
419 EXPECT_CALL(*second_event_handler, 423 EXPECT_CALL(*second_event_handler,
420 DeviceStarted(second_session_id, 424 DeviceStarted(second_session_id,
421 media::AudioManagerBase::kDefaultDeviceId)) 425 media::AudioManagerBase::kDefaultDeviceId))
422 .Times(1); 426 .Times(1);
423 message_loop_->RunAllPending(); 427 MessageLoop::current()->RunAllPending();
424 428
425 manager_->Stop(first_session_id); 429 manager_->Stop(first_session_id);
426 manager_->Stop(second_session_id); 430 manager_->Stop(second_session_id);
427 manager_->Close(first_session_id); 431 manager_->Close(first_session_id);
428 manager_->Close(second_session_id); 432 manager_->Close(second_session_id);
429 EXPECT_CALL(*audio_input_listener_, 433 EXPECT_CALL(*audio_input_listener_,
430 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 434 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
431 first_session_id)) 435 first_session_id))
432 .Times(1); 436 .Times(1);
433 EXPECT_CALL(*audio_input_listener_, 437 EXPECT_CALL(*audio_input_listener_,
434 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 438 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
435 second_session_id)) 439 second_session_id))
436 .Times(1); 440 .Times(1);
437 message_loop_->RunAllPending(); 441 MessageLoop::current()->RunAllPending();
438 } 442 }
439 443
440 // Starts an invalid session. 444 // Starts an invalid session.
441 TEST_F(AudioInputDeviceManagerTest, StartInvalidSession) { 445 TEST_F(AudioInputDeviceManagerTest, StartInvalidSession) {
442 if (!CanRunAudioInputDeviceTests()) 446 if (!CanRunAudioInputDeviceTests())
443 return; 447 return;
444 InSequence s; 448 InSequence s;
445 449
446 // Creates the EventHandlers for the sessions. 450 // Creates the EventHandlers for the sessions.
447 scoped_ptr<MockAudioInputDeviceManagerEventHandler> 451 scoped_ptr<MockAudioInputDeviceManagerEventHandler>
448 audio_input_event_handler( 452 audio_input_event_handler(
449 new MockAudioInputDeviceManagerEventHandler(message_loop_.get())); 453 new MockAudioInputDeviceManagerEventHandler(MessageLoop::current()));
450 454
451 // Opens the first device. 455 // Opens the first device.
452 StreamDeviceInfoArray::const_iterator iter = 456 StreamDeviceInfoArray::const_iterator iter =
453 audio_input_listener_->devices_.begin(); 457 audio_input_listener_->devices_.begin();
454 int session_id = manager_->Open(*iter); 458 int session_id = manager_->Open(*iter);
455 EXPECT_CALL(*audio_input_listener_, 459 EXPECT_CALL(*audio_input_listener_,
456 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 460 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
457 session_id)) 461 session_id))
458 .Times(1); 462 .Times(1);
459 message_loop_->RunAllPending(); 463 MessageLoop::current()->RunAllPending();
460 464
461 // Starts a non-opened device. 465 // Starts a non-opened device.
462 // This should fail and trigger error code 'kDeviceNotAvailable'. 466 // This should fail and trigger error code 'kDeviceNotAvailable'.
463 int invalid_session_id = session_id + 1; 467 int invalid_session_id = session_id + 1;
464 manager_->Start(invalid_session_id, audio_input_event_handler.get()); 468 manager_->Start(invalid_session_id, audio_input_event_handler.get());
465 EXPECT_CALL(*audio_input_event_handler, 469 EXPECT_CALL(*audio_input_event_handler,
466 DeviceStarted(invalid_session_id, 470 DeviceStarted(invalid_session_id,
467 AudioInputDeviceManager::kInvalidDeviceId)) 471 AudioInputDeviceManager::kInvalidDeviceId))
468 .Times(1); 472 .Times(1);
469 message_loop_->RunAllPending(); 473 MessageLoop::current()->RunAllPending();
470 474
471 manager_->Close(session_id); 475 manager_->Close(session_id);
472 EXPECT_CALL(*audio_input_listener_, 476 EXPECT_CALL(*audio_input_listener_,
473 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 477 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
474 session_id)) 478 session_id))
475 .Times(1); 479 .Times(1);
476 message_loop_->RunAllPending(); 480 MessageLoop::current()->RunAllPending();
477 } 481 }
478 482
479 // Starts a session twice, the first time should succeed, while the second 483 // Starts a session twice, the first time should succeed, while the second
480 // time should fail. 484 // time should fail.
481 TEST_F(AudioInputDeviceManagerTest, StartSessionTwice) { 485 TEST_F(AudioInputDeviceManagerTest, StartSessionTwice) {
482 if (!CanRunAudioInputDeviceTests()) 486 if (!CanRunAudioInputDeviceTests())
483 return; 487 return;
484 InSequence s; 488 InSequence s;
485 489
486 // Creates the EventHandlers for the sessions. 490 // Creates the EventHandlers for the sessions.
487 scoped_ptr<MockAudioInputDeviceManagerEventHandler> 491 scoped_ptr<MockAudioInputDeviceManagerEventHandler>
488 audio_input_event_handler( 492 audio_input_event_handler(
489 new MockAudioInputDeviceManagerEventHandler(message_loop_.get())); 493 new MockAudioInputDeviceManagerEventHandler(MessageLoop::current()));
490 494
491 // Opens the first device. 495 // Opens the first device.
492 StreamDeviceInfoArray::const_iterator iter = 496 StreamDeviceInfoArray::const_iterator iter =
493 audio_input_listener_->devices_.begin(); 497 audio_input_listener_->devices_.begin();
494 int session_id = manager_->Open(*iter); 498 int session_id = manager_->Open(*iter);
495 EXPECT_CALL(*audio_input_listener_, 499 EXPECT_CALL(*audio_input_listener_,
496 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 500 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
497 session_id)) 501 session_id))
498 .Times(1); 502 .Times(1);
499 message_loop_->RunAllPending(); 503 MessageLoop::current()->RunAllPending();
500 504
501 // Starts the session, it should succeed. 505 // Starts the session, it should succeed.
502 manager_->Start(session_id, audio_input_event_handler.get()); 506 manager_->Start(session_id, audio_input_event_handler.get());
503 EXPECT_CALL(*audio_input_event_handler, 507 EXPECT_CALL(*audio_input_event_handler,
504 DeviceStarted(session_id, 508 DeviceStarted(session_id,
505 media::AudioManagerBase::kDefaultDeviceId)) 509 media::AudioManagerBase::kDefaultDeviceId))
506 .Times(1); 510 .Times(1);
507 message_loop_->RunAllPending(); 511 MessageLoop::current()->RunAllPending();
508 512
509 // Starts the session for the second time, it should fail. 513 // Starts the session for the second time, it should fail.
510 manager_->Start(session_id, audio_input_event_handler.get()); 514 manager_->Start(session_id, audio_input_event_handler.get());
511 EXPECT_CALL(*audio_input_event_handler, 515 EXPECT_CALL(*audio_input_event_handler,
512 DeviceStarted(session_id, 516 DeviceStarted(session_id,
513 AudioInputDeviceManager::kInvalidDeviceId)) 517 AudioInputDeviceManager::kInvalidDeviceId))
514 .Times(1); 518 .Times(1);
515 519
516 manager_->Stop(session_id); 520 manager_->Stop(session_id);
517 manager_->Close(session_id); 521 manager_->Close(session_id);
518 EXPECT_CALL(*audio_input_listener_, 522 EXPECT_CALL(*audio_input_listener_,
519 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 523 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
520 session_id)) 524 session_id))
521 .Times(1); 525 .Times(1);
522 message_loop_->RunAllPending(); 526 MessageLoop::current()->RunAllPending();
523 } 527 }
524 528
525 } // namespace media_stream 529 } // namespace media_stream
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698