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

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: ready for review. Created 8 years, 6 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"
14 #include "media/audio/audio_manager_base.h" 15 #include "media/audio/audio_manager_base.h"
15 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
19 using content::BrowserMainLoop;
18 using content::BrowserThread; 20 using content::BrowserThread;
19 using content::BrowserThreadImpl; 21 using content::BrowserThreadImpl;
20 using media_stream::AudioInputDeviceManager; 22 using media_stream::AudioInputDeviceManager;
21 using testing::_; 23 using testing::_;
22 using testing::AnyNumber; 24 using testing::AnyNumber;
23 using testing::InSequence; 25 using testing::InSequence;
24 using testing::Return; 26 using testing::Return;
25 27
26 namespace media_stream { 28 namespace media_stream {
27 29
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 bool CanRunAudioInputDeviceTests() { 100 bool CanRunAudioInputDeviceTests() {
99 return audio_manager_->HasAudioInputDevices(); 101 return audio_manager_->HasAudioInputDevices();
100 } 102 }
101 103
102 protected: 104 protected:
103 virtual void SetUp() { 105 virtual void SetUp() {
104 // The test must run on Browser::IO. 106 // The test must run on Browser::IO.
105 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); 107 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO));
106 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO, 108 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO,
107 message_loop_.get())); 109 message_loop_.get()));
108 audio_manager_.reset(media::AudioManager::Create());
109 110
110 manager_ = new AudioInputDeviceManager(audio_manager_.get()); 111 device_thread_.reset(new base::Thread("AudioInputDeviceManagerTestThread"));
scherkus (not reviewing) 2012/06/27 00:52:31 given that you can inject message loops I'm curiou
no longer working on chromium 2012/06/27 14:07:16 True, I did not do this simply because I was not s
112 CHECK(device_thread_->Start());
113
114 manager_ = new AudioInputDeviceManager(
115 device_thread_->message_loop_proxy());
111 audio_input_listener_.reset(new MockAudioInputDeviceManagerListener()); 116 audio_input_listener_.reset(new MockAudioInputDeviceManagerListener());
112 manager_->Register(audio_input_listener_.get()); 117 manager_->Register(audio_input_listener_.get());
113 118
119 audio_manager_.reset(media::AudioManager::Create());
120 manager_->SetAudioManagerForTesting(audio_manager_.get());
scherkus (not reviewing) 2012/06/27 00:52:31 can't we recreate a BrowserMainLoop for each test
no longer working on chromium 2012/06/27 14:07:16 Good idea, done.
121
114 // Gets the enumerated device list from the AudioInputDeviceManager. 122 // Gets the enumerated device list from the AudioInputDeviceManager.
115 manager_->EnumerateDevices(); 123 manager_->EnumerateDevices();
116 EXPECT_CALL(*audio_input_listener_, DevicesEnumerated(_)) 124 EXPECT_CALL(*audio_input_listener_, DevicesEnumerated(_))
117 .Times(1); 125 .Times(1);
118 126
119 // Waits for the callback. 127 // Sync up the threads to make sure we get the list.
120 message_loop_->RunAllPending(); 128 SyncWithAudioInputDeviceManagerThread();
121 } 129 }
122 130
123 virtual void TearDown() { 131 virtual void TearDown() {
124 manager_->Unregister(); 132 manager_->Unregister();
125 io_thread_.reset(); 133 io_thread_.reset();
134 device_thread_->Stop();
135 }
136
137 // Called on the device thread.
138 static void PostQuitMessageLoop(MessageLoop* message_loop) {
139 message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure());
140 }
141
142 // Called on the main thread.
143 static void PostQuitOnAudioInputDeviceManagerThread(
144 MessageLoop* message_loop, MessageLoop* device_message_loop) {
145 device_message_loop->PostTask(
146 FROM_HERE, base::Bind(&PostQuitMessageLoop, message_loop));
147 }
148
149 // SyncWithAudioInputDeviceManagerThread() waits until all pending tasks on
150 // the audio_input_device_manager thread are executed while also processing
151 // pending task in message_loop_ on the current thread.
152 void SyncWithAudioInputDeviceManagerThread() {
153 message_loop_->PostTask(
154 FROM_HERE,
155 base::Bind(&PostQuitOnAudioInputDeviceManagerThread,
156 message_loop_.get(),
157 device_thread_->message_loop()));
158 message_loop_->Run();
126 } 159 }
127 160
128 scoped_ptr<MessageLoop> message_loop_; 161 scoped_ptr<MessageLoop> message_loop_;
129 scoped_ptr<BrowserThreadImpl> io_thread_; 162 scoped_ptr<BrowserThreadImpl> io_thread_;
163 scoped_ptr<base::Thread> device_thread_;
130 scoped_refptr<AudioInputDeviceManager> manager_; 164 scoped_refptr<AudioInputDeviceManager> manager_;
131 scoped_ptr<MockAudioInputDeviceManagerListener> audio_input_listener_; 165 scoped_ptr<MockAudioInputDeviceManagerListener> audio_input_listener_;
132 scoped_ptr<media::AudioManager> audio_manager_; 166 scoped_ptr<media::AudioManager> audio_manager_;
133 167
134 private: 168 private:
135 DISALLOW_COPY_AND_ASSIGN(AudioInputDeviceManagerTest); 169 DISALLOW_COPY_AND_ASSIGN(AudioInputDeviceManagerTest);
136 }; 170 };
137 171
138 // Opens and closes the devices. 172 // Opens and closes the devices.
139 TEST_F(AudioInputDeviceManagerTest, OpenAndCloseDevice) { 173 TEST_F(AudioInputDeviceManagerTest, OpenAndCloseDevice) {
(...skipping 14 matching lines...) Expand all
154 // Expected mock call with expected return value. 188 // Expected mock call with expected return value.
155 EXPECT_CALL(*audio_input_listener_, 189 EXPECT_CALL(*audio_input_listener_,
156 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 190 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
157 session_id)) 191 session_id))
158 .Times(1); 192 .Times(1);
159 EXPECT_CALL(*audio_input_listener_, 193 EXPECT_CALL(*audio_input_listener_,
160 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 194 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
161 session_id)) 195 session_id))
162 .Times(1); 196 .Times(1);
163 197
164 // Waits for the callback. 198 SyncWithAudioInputDeviceManagerThread();
165 message_loop_->RunAllPending();
166 } 199 }
167 } 200 }
168 201
169 // Opens multiple devices at one time and closes them later. 202 // Opens multiple devices at one time and closes them later.
170 TEST_F(AudioInputDeviceManagerTest, OpenMultipleDevices) { 203 TEST_F(AudioInputDeviceManagerTest, OpenMultipleDevices) {
171 if (!CanRunAudioInputDeviceTests()) 204 if (!CanRunAudioInputDeviceTests())
172 return; 205 return;
173 206
174 ASSERT_FALSE(audio_input_listener_->devices_.empty()); 207 ASSERT_FALSE(audio_input_listener_->devices_.empty());
175 208
176 InSequence s; 209 InSequence s;
177 210
178 int index = 0; 211 int index = 0;
179 const int kDeviceSize = audio_input_listener_->devices_.size(); 212 const int kDeviceSize = audio_input_listener_->devices_.size();
180 scoped_array<int> session_id(new int[kDeviceSize]); 213 scoped_array<int> session_id(new int[kDeviceSize]);
181 214
182 // Opens the devices in a loop. 215 // Opens the devices in a loop.
183 for (StreamDeviceInfoArray::const_iterator iter = 216 for (StreamDeviceInfoArray::const_iterator iter =
184 audio_input_listener_->devices_.begin(); 217 audio_input_listener_->devices_.begin();
185 iter != audio_input_listener_->devices_.end(); ++iter, ++index) { 218 iter != audio_input_listener_->devices_.end(); ++iter, ++index) {
186 // Opens the devices. 219 // Opens the devices.
187 session_id[index] = manager_->Open(*iter); 220 session_id[index] = manager_->Open(*iter);
188 221
189 // Expected mock call with expected returned value. 222 // Expected mock call with expected returned value.
190 EXPECT_CALL(*audio_input_listener_, 223 EXPECT_CALL(*audio_input_listener_,
191 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 224 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
192 session_id[index])) 225 session_id[index]))
193 .Times(1); 226 .Times(1);
194 227
195 // Waits for the callback. 228 SyncWithAudioInputDeviceManagerThread();
196 message_loop_->RunAllPending();
197 } 229 }
198 230
199 // Checks if the session_ids are unique. 231 // Checks if the session_ids are unique.
200 for (int i = 0; i < kDeviceSize - 1; ++i) { 232 for (int i = 0; i < kDeviceSize - 1; ++i) {
201 for (int k = i+1; k < kDeviceSize; ++k) { 233 for (int k = i+1; k < kDeviceSize; ++k) {
202 EXPECT_TRUE(session_id[i] != session_id[k]); 234 EXPECT_TRUE(session_id[i] != session_id[k]);
203 } 235 }
204 } 236 }
205 237
206 for (int i = 0; i < kDeviceSize; ++i) { 238 for (int i = 0; i < kDeviceSize; ++i) {
207 // Closes the devices. 239 // Closes the devices.
208 manager_->Close(session_id[i]); 240 manager_->Close(session_id[i]);
209 EXPECT_CALL(*audio_input_listener_, 241 EXPECT_CALL(*audio_input_listener_,
210 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 242 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
211 session_id[i])) 243 session_id[i]))
212 .Times(1); 244 .Times(1);
213 245
214 // Waits for the callback. 246 SyncWithAudioInputDeviceManagerThread();
215 message_loop_->RunAllPending();
216 } 247 }
217 } 248 }
218 249
219 // Opens a non-existing device. 250 // Opens a non-existing device.
220 TEST_F(AudioInputDeviceManagerTest, OpenNotExistingDevice) { 251 TEST_F(AudioInputDeviceManagerTest, OpenNotExistingDevice) {
221 if (!CanRunAudioInputDeviceTests()) 252 if (!CanRunAudioInputDeviceTests())
222 return; 253 return;
223 InSequence s; 254 InSequence s;
224 255
225 MediaStreamType stream_type = content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE; 256 MediaStreamType stream_type = content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE;
226 std::string device_name("device_doesnt_exist"); 257 std::string device_name("device_doesnt_exist");
227 std::string device_id("id_doesnt_exist"); 258 std::string device_id("id_doesnt_exist");
228 StreamDeviceInfo dummy_device(stream_type, device_name, device_id, false); 259 StreamDeviceInfo dummy_device(stream_type, device_name, device_id, false);
229 260
230 int session_id = manager_->Open(dummy_device); 261 int session_id = manager_->Open(dummy_device);
231 EXPECT_CALL(*audio_input_listener_, 262 EXPECT_CALL(*audio_input_listener_,
232 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 263 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
233 session_id)) 264 session_id))
234 .Times(1); 265 .Times(1);
235 266
236 // Waits for the callback. 267 SyncWithAudioInputDeviceManagerThread();
237 message_loop_->RunAllPending();
238 } 268 }
239 269
240 // Opens default device twice. 270 // Opens default device twice.
241 TEST_F(AudioInputDeviceManagerTest, OpenDeviceTwice) { 271 TEST_F(AudioInputDeviceManagerTest, OpenDeviceTwice) {
242 if (!CanRunAudioInputDeviceTests()) 272 if (!CanRunAudioInputDeviceTests())
243 return; 273 return;
244 274
245 ASSERT_FALSE(audio_input_listener_->devices_.empty()); 275 ASSERT_FALSE(audio_input_listener_->devices_.empty());
246 276
247 InSequence s; 277 InSequence s;
(...skipping 18 matching lines...) Expand all
266 .Times(1); 296 .Times(1);
267 EXPECT_CALL(*audio_input_listener_, 297 EXPECT_CALL(*audio_input_listener_,
268 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 298 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
269 first_session_id)) 299 first_session_id))
270 .Times(1); 300 .Times(1);
271 EXPECT_CALL(*audio_input_listener_, 301 EXPECT_CALL(*audio_input_listener_,
272 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 302 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
273 second_session_id)) 303 second_session_id))
274 .Times(1); 304 .Times(1);
275 305
276 // Waits for the callback. 306 SyncWithAudioInputDeviceManagerThread();
277 message_loop_->RunAllPending();
278 } 307 }
279 308
280 // Starts and closes the sessions after opening the devices. 309 // Starts and closes the sessions after opening the devices.
281 TEST_F(AudioInputDeviceManagerTest, StartAndStopSession) { 310 TEST_F(AudioInputDeviceManagerTest, StartAndStopSession) {
282 if (!CanRunAudioInputDeviceTests()) 311 if (!CanRunAudioInputDeviceTests())
283 return; 312 return;
284 313
285 ASSERT_FALSE(audio_input_listener_->devices_.empty()); 314 ASSERT_FALSE(audio_input_listener_->devices_.empty());
286 315
287 InSequence s; 316 InSequence s;
(...skipping 12 matching lines...) Expand all
300 for (StreamDeviceInfoArray::const_iterator iter = 329 for (StreamDeviceInfoArray::const_iterator iter =
301 audio_input_listener_->devices_.begin(); 330 audio_input_listener_->devices_.begin();
302 iter != audio_input_listener_->devices_.end(); ++iter, ++index) { 331 iter != audio_input_listener_->devices_.end(); ++iter, ++index) {
303 // Note that no DeviceStopped() notification for Event Handler as we have 332 // Note that no DeviceStopped() notification for Event Handler as we have
304 // stopped the device before calling close. 333 // stopped the device before calling close.
305 session_id[index] = manager_->Open(*iter); 334 session_id[index] = manager_->Open(*iter);
306 EXPECT_CALL(*audio_input_listener_, 335 EXPECT_CALL(*audio_input_listener_,
307 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 336 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
308 session_id[index])) 337 session_id[index]))
309 .Times(1); 338 .Times(1);
310 message_loop_->RunAllPending(); 339 SyncWithAudioInputDeviceManagerThread();
311 340
312 manager_->Start(session_id[index], audio_input_event_handler.get()); 341 manager_->Start(session_id[index], audio_input_event_handler.get());
313 EXPECT_CALL(*audio_input_event_handler, 342 EXPECT_CALL(*audio_input_event_handler,
314 DeviceStarted(session_id[index], iter->device_id)) 343 DeviceStarted(session_id[index], iter->device_id))
315 .Times(1); 344 .Times(1);
316 message_loop_->RunAllPending(); 345 message_loop_->RunAllPending();
317 346
318 manager_->Stop(session_id[index]); 347 manager_->Stop(session_id[index]);
319 manager_->Close(session_id[index]); 348 manager_->Close(session_id[index]);
320 EXPECT_CALL(*audio_input_listener_, 349 EXPECT_CALL(*audio_input_listener_,
321 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 350 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
322 session_id[index])) 351 session_id[index]))
323 .Times(1); 352 .Times(1);
324 message_loop_->RunAllPending(); 353 SyncWithAudioInputDeviceManagerThread();
325 } 354 }
326 } 355 }
327 356
328 // Tests the behavior of calling Close() without calling Stop(). 357 // Tests the behavior of calling Close() without calling Stop().
329 TEST_F(AudioInputDeviceManagerTest, CloseWithoutStopSession) { 358 TEST_F(AudioInputDeviceManagerTest, CloseWithoutStopSession) {
330 if (!CanRunAudioInputDeviceTests()) 359 if (!CanRunAudioInputDeviceTests())
331 return; 360 return;
332 361
333 ASSERT_FALSE(audio_input_listener_->devices_.empty()); 362 ASSERT_FALSE(audio_input_listener_->devices_.empty());
334 363
(...skipping 12 matching lines...) Expand all
347 // Note that we do not call stop. 376 // Note that we do not call stop.
348 for (StreamDeviceInfoArray::const_iterator iter = 377 for (StreamDeviceInfoArray::const_iterator iter =
349 audio_input_listener_->devices_.begin(); 378 audio_input_listener_->devices_.begin();
350 iter != audio_input_listener_->devices_.end(); ++iter, ++index) { 379 iter != audio_input_listener_->devices_.end(); ++iter, ++index) {
351 // Calls Open()/Start()/Close() for each device. 380 // Calls Open()/Start()/Close() for each device.
352 session_id[index] = manager_->Open(*iter); 381 session_id[index] = manager_->Open(*iter);
353 EXPECT_CALL(*audio_input_listener_, 382 EXPECT_CALL(*audio_input_listener_,
354 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 383 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
355 session_id[index])) 384 session_id[index]))
356 .Times(1); 385 .Times(1);
357 message_loop_->RunAllPending(); 386 SyncWithAudioInputDeviceManagerThread();
358 387
359 manager_->Start(session_id[index], audio_input_event_handler.get()); 388 manager_->Start(session_id[index], audio_input_event_handler.get());
360 EXPECT_CALL(*audio_input_event_handler, 389 EXPECT_CALL(*audio_input_event_handler,
361 DeviceStarted(session_id[index], iter->device_id)) 390 DeviceStarted(session_id[index], iter->device_id))
362 .Times(1); 391 .Times(1);
363 message_loop_->RunAllPending(); 392 message_loop_->RunAllPending();
364 393
365 // Event Handler should get a stop device notification as no stop is called 394 // Event Handler should get a stop device notification as no stop is called
366 // before closing the device. 395 // before closing the device.
367 manager_->Close(session_id[index]); 396 manager_->Close(session_id[index]);
368 EXPECT_CALL(*audio_input_event_handler, 397 EXPECT_CALL(*audio_input_event_handler,
369 DeviceStopped(session_id[index])) 398 DeviceStopped(session_id[index]))
370 .Times(1); 399 .Times(1);
371 EXPECT_CALL(*audio_input_listener_, 400 EXPECT_CALL(*audio_input_listener_,
372 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 401 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
373 session_id[index])) 402 session_id[index]))
374 .Times(1); 403 .Times(1);
375 message_loop_->RunAllPending(); 404 SyncWithAudioInputDeviceManagerThread();
376 } 405 }
377 } 406 }
378 407
379 // Starts the same device twice. 408 // Starts the same device twice.
380 TEST_F(AudioInputDeviceManagerTest, StartDeviceTwice) { 409 TEST_F(AudioInputDeviceManagerTest, StartDeviceTwice) {
381 if (!CanRunAudioInputDeviceTests()) 410 if (!CanRunAudioInputDeviceTests())
382 return; 411 return;
383 412
384 ASSERT_FALSE(audio_input_listener_->devices_.empty()); 413 ASSERT_FALSE(audio_input_listener_->devices_.empty());
385 414
(...skipping 14 matching lines...) Expand all
400 int second_session_id = manager_->Open(*iter); 429 int second_session_id = manager_->Open(*iter);
401 EXPECT_NE(first_session_id, second_session_id); 430 EXPECT_NE(first_session_id, second_session_id);
402 EXPECT_CALL(*audio_input_listener_, 431 EXPECT_CALL(*audio_input_listener_,
403 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 432 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
404 first_session_id)) 433 first_session_id))
405 .Times(1); 434 .Times(1);
406 EXPECT_CALL(*audio_input_listener_, 435 EXPECT_CALL(*audio_input_listener_,
407 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 436 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
408 second_session_id)) 437 second_session_id))
409 .Times(1); 438 .Times(1);
410 message_loop_->RunAllPending(); 439 SyncWithAudioInputDeviceManagerThread();
411 440
412 // Calls Start()/Stop()/Close() for the default device twice. 441 // Calls Start()/Stop()/Close() for the default device twice.
413 manager_->Start(first_session_id, first_event_handler.get()); 442 manager_->Start(first_session_id, first_event_handler.get());
414 manager_->Start(second_session_id, second_event_handler.get()); 443 manager_->Start(second_session_id, second_event_handler.get());
415 EXPECT_CALL(*first_event_handler, 444 EXPECT_CALL(*first_event_handler,
416 DeviceStarted(first_session_id, 445 DeviceStarted(first_session_id,
417 media::AudioManagerBase::kDefaultDeviceId)) 446 media::AudioManagerBase::kDefaultDeviceId))
418 .Times(1); 447 .Times(1);
419 EXPECT_CALL(*second_event_handler, 448 EXPECT_CALL(*second_event_handler,
420 DeviceStarted(second_session_id, 449 DeviceStarted(second_session_id,
421 media::AudioManagerBase::kDefaultDeviceId)) 450 media::AudioManagerBase::kDefaultDeviceId))
422 .Times(1); 451 .Times(1);
423 message_loop_->RunAllPending(); 452 message_loop_->RunAllPending();
424 453
425 manager_->Stop(first_session_id); 454 manager_->Stop(first_session_id);
426 manager_->Stop(second_session_id); 455 manager_->Stop(second_session_id);
427 manager_->Close(first_session_id); 456 manager_->Close(first_session_id);
428 manager_->Close(second_session_id); 457 manager_->Close(second_session_id);
429 EXPECT_CALL(*audio_input_listener_, 458 EXPECT_CALL(*audio_input_listener_,
430 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 459 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
431 first_session_id)) 460 first_session_id))
432 .Times(1); 461 .Times(1);
433 EXPECT_CALL(*audio_input_listener_, 462 EXPECT_CALL(*audio_input_listener_,
434 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 463 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
435 second_session_id)) 464 second_session_id))
436 .Times(1); 465 .Times(1);
437 message_loop_->RunAllPending(); 466 SyncWithAudioInputDeviceManagerThread();
438 } 467 }
439 468
440 // Starts an invalid session. 469 // Starts an invalid session.
441 TEST_F(AudioInputDeviceManagerTest, StartInvalidSession) { 470 TEST_F(AudioInputDeviceManagerTest, StartInvalidSession) {
442 if (!CanRunAudioInputDeviceTests()) 471 if (!CanRunAudioInputDeviceTests())
443 return; 472 return;
444 InSequence s; 473 InSequence s;
445 474
446 // Creates the EventHandlers for the sessions. 475 // Creates the EventHandlers for the sessions.
447 scoped_ptr<MockAudioInputDeviceManagerEventHandler> 476 scoped_ptr<MockAudioInputDeviceManagerEventHandler>
448 audio_input_event_handler( 477 audio_input_event_handler(
449 new MockAudioInputDeviceManagerEventHandler(message_loop_.get())); 478 new MockAudioInputDeviceManagerEventHandler(message_loop_.get()));
450 479
451 // Opens the first device. 480 // Opens the first device.
452 StreamDeviceInfoArray::const_iterator iter = 481 StreamDeviceInfoArray::const_iterator iter =
453 audio_input_listener_->devices_.begin(); 482 audio_input_listener_->devices_.begin();
454 int session_id = manager_->Open(*iter); 483 int session_id = manager_->Open(*iter);
455 EXPECT_CALL(*audio_input_listener_, 484 EXPECT_CALL(*audio_input_listener_,
456 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 485 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
457 session_id)) 486 session_id))
458 .Times(1); 487 .Times(1);
459 message_loop_->RunAllPending(); 488 SyncWithAudioInputDeviceManagerThread();
460 489
461 // Starts a non-opened device. 490 // Starts a non-opened device.
462 // This should fail and trigger error code 'kDeviceNotAvailable'. 491 // This should fail and trigger error code 'kDeviceNotAvailable'.
463 int invalid_session_id = session_id + 1; 492 int invalid_session_id = session_id + 1;
464 manager_->Start(invalid_session_id, audio_input_event_handler.get()); 493 manager_->Start(invalid_session_id, audio_input_event_handler.get());
465 EXPECT_CALL(*audio_input_event_handler, 494 EXPECT_CALL(*audio_input_event_handler,
466 DeviceStarted(invalid_session_id, 495 DeviceStarted(invalid_session_id,
467 AudioInputDeviceManager::kInvalidDeviceId)) 496 AudioInputDeviceManager::kInvalidDeviceId))
468 .Times(1); 497 .Times(1);
469 message_loop_->RunAllPending(); 498 message_loop_->RunAllPending();
470 499
471 manager_->Close(session_id); 500 manager_->Close(session_id);
472 EXPECT_CALL(*audio_input_listener_, 501 EXPECT_CALL(*audio_input_listener_,
473 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 502 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
474 session_id)) 503 session_id))
475 .Times(1); 504 .Times(1);
476 message_loop_->RunAllPending(); 505 SyncWithAudioInputDeviceManagerThread();
477 } 506 }
478 507
479 // Starts a session twice, the first time should succeed, while the second 508 // Starts a session twice, the first time should succeed, while the second
480 // time should fail. 509 // time should fail.
481 TEST_F(AudioInputDeviceManagerTest, StartSessionTwice) { 510 TEST_F(AudioInputDeviceManagerTest, StartSessionTwice) {
482 if (!CanRunAudioInputDeviceTests()) 511 if (!CanRunAudioInputDeviceTests())
483 return; 512 return;
484 InSequence s; 513 InSequence s;
485 514
486 // Creates the EventHandlers for the sessions. 515 // Creates the EventHandlers for the sessions.
487 scoped_ptr<MockAudioInputDeviceManagerEventHandler> 516 scoped_ptr<MockAudioInputDeviceManagerEventHandler>
488 audio_input_event_handler( 517 audio_input_event_handler(
489 new MockAudioInputDeviceManagerEventHandler(message_loop_.get())); 518 new MockAudioInputDeviceManagerEventHandler(message_loop_.get()));
490 519
491 // Opens the first device. 520 // Opens the first device.
492 StreamDeviceInfoArray::const_iterator iter = 521 StreamDeviceInfoArray::const_iterator iter =
493 audio_input_listener_->devices_.begin(); 522 audio_input_listener_->devices_.begin();
494 int session_id = manager_->Open(*iter); 523 int session_id = manager_->Open(*iter);
495 EXPECT_CALL(*audio_input_listener_, 524 EXPECT_CALL(*audio_input_listener_,
496 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 525 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
497 session_id)) 526 session_id))
498 .Times(1); 527 .Times(1);
499 message_loop_->RunAllPending(); 528 SyncWithAudioInputDeviceManagerThread();
500 529
501 // Starts the session, it should succeed. 530 // Starts the session, it should succeed.
502 manager_->Start(session_id, audio_input_event_handler.get()); 531 manager_->Start(session_id, audio_input_event_handler.get());
503 EXPECT_CALL(*audio_input_event_handler, 532 EXPECT_CALL(*audio_input_event_handler,
504 DeviceStarted(session_id, 533 DeviceStarted(session_id,
505 media::AudioManagerBase::kDefaultDeviceId)) 534 media::AudioManagerBase::kDefaultDeviceId))
506 .Times(1); 535 .Times(1);
507 message_loop_->RunAllPending(); 536 message_loop_->RunAllPending();
508 537
509 // Starts the session for the second time, it should fail. 538 // Starts the session for the second time, it should fail.
510 manager_->Start(session_id, audio_input_event_handler.get()); 539 manager_->Start(session_id, audio_input_event_handler.get());
511 EXPECT_CALL(*audio_input_event_handler, 540 EXPECT_CALL(*audio_input_event_handler,
512 DeviceStarted(session_id, 541 DeviceStarted(session_id,
513 AudioInputDeviceManager::kInvalidDeviceId)) 542 AudioInputDeviceManager::kInvalidDeviceId))
514 .Times(1); 543 .Times(1);
515 544
516 manager_->Stop(session_id); 545 manager_->Stop(session_id);
517 manager_->Close(session_id); 546 manager_->Close(session_id);
518 EXPECT_CALL(*audio_input_listener_, 547 EXPECT_CALL(*audio_input_listener_,
519 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 548 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
520 session_id)) 549 session_id))
521 .Times(1); 550 .Times(1);
522 message_loop_->RunAllPending(); 551 SyncWithAudioInputDeviceManagerThread();
523 } 552 }
524 553
525 } // namespace media_stream 554 } // namespace media_stream
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698