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

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

Issue 10912004: Begin adding support for tab mirroring via the MediaStream audio/video capturing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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"
(...skipping 20 matching lines...) Expand all
31 MockAudioInputDeviceManagerListener() {} 31 MockAudioInputDeviceManagerListener() {}
32 virtual ~MockAudioInputDeviceManagerListener() {} 32 virtual ~MockAudioInputDeviceManagerListener() {}
33 33
34 MOCK_METHOD2(Opened, void(MediaStreamType, const int)); 34 MOCK_METHOD2(Opened, void(MediaStreamType, const int));
35 MOCK_METHOD2(Closed, void(MediaStreamType, const int)); 35 MOCK_METHOD2(Closed, void(MediaStreamType, const int));
36 MOCK_METHOD1(DevicesEnumerated, void(const StreamDeviceInfoArray&)); 36 MOCK_METHOD1(DevicesEnumerated, void(const StreamDeviceInfoArray&));
37 MOCK_METHOD3(Error, void(MediaStreamType, int, MediaStreamProviderError)); 37 MOCK_METHOD3(Error, void(MediaStreamType, int, MediaStreamProviderError));
38 38
39 virtual void DevicesEnumerated(MediaStreamType service_type, 39 virtual void DevicesEnumerated(MediaStreamType service_type,
40 const StreamDeviceInfoArray& devices) { 40 const StreamDeviceInfoArray& devices) {
41 if (service_type != content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) 41 if (!content::IsAudioMediaStreamDeviceType(service_type))
42 return; 42 return;
43 43
44 devices_ = devices; 44 devices_ = devices;
45 DevicesEnumerated(devices); 45 DevicesEnumerated(devices);
46 } 46 }
47 47
48 StreamDeviceInfoArray devices_; 48 StreamDeviceInfoArray devices_;
49 49
50 private: 50 private:
51 DISALLOW_COPY_AND_ASSIGN(MockAudioInputDeviceManagerListener); 51 DISALLOW_COPY_AND_ASSIGN(MockAudioInputDeviceManagerListener);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 } 91 }
92 92
93 protected: 93 protected:
94 virtual void SetUp() OVERRIDE { 94 virtual void SetUp() OVERRIDE {
95 // The test must run on Browser::IO. 95 // The test must run on Browser::IO.
96 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); 96 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO));
97 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO, 97 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO,
98 message_loop_.get())); 98 message_loop_.get()));
99 99
100 audio_manager_.reset(media::AudioManager::Create()); 100 audio_manager_.reset(media::AudioManager::Create());
101 manager_ = new AudioInputDeviceManager(audio_manager_.get()); 101 manager_ = new AudioInputDeviceManager(
102 audio_manager_.get(),
103 content::MEDIA_STREAM_DEVICE_TYPE_USER_AUDIO_CAPTURE);
102 audio_input_listener_.reset(new MockAudioInputDeviceManagerListener()); 104 audio_input_listener_.reset(new MockAudioInputDeviceManagerListener());
103 manager_->Register(audio_input_listener_.get(), 105 manager_->Register(audio_input_listener_.get(),
104 message_loop_->message_loop_proxy()); 106 message_loop_->message_loop_proxy());
105 107
106 // Gets the enumerated device list from the AudioInputDeviceManager. 108 // Gets the enumerated device list from the AudioInputDeviceManager.
107 manager_->EnumerateDevices(); 109 manager_->EnumerateDevices();
108 EXPECT_CALL(*audio_input_listener_, DevicesEnumerated(_)) 110 EXPECT_CALL(*audio_input_listener_, DevicesEnumerated(_))
109 .Times(1); 111 .Times(1);
110 112
111 // Wait until we get the list. 113 // Wait until we get the list.
(...skipping 26 matching lines...) Expand all
138 140
139 for (StreamDeviceInfoArray::const_iterator iter = 141 for (StreamDeviceInfoArray::const_iterator iter =
140 audio_input_listener_->devices_.begin(); 142 audio_input_listener_->devices_.begin();
141 iter != audio_input_listener_->devices_.end(); ++iter) { 143 iter != audio_input_listener_->devices_.end(); ++iter) {
142 // Opens/closes the devices. 144 // Opens/closes the devices.
143 int session_id = manager_->Open(*iter); 145 int session_id = manager_->Open(*iter);
144 manager_->Close(session_id); 146 manager_->Close(session_id);
145 147
146 // Expected mock call with expected return value. 148 // Expected mock call with expected return value.
147 EXPECT_CALL(*audio_input_listener_, 149 EXPECT_CALL(*audio_input_listener_,
148 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 150 Opened(content::MEDIA_STREAM_DEVICE_TYPE_USER_AUDIO_CAPTURE,
149 session_id)) 151 session_id))
150 .Times(1); 152 .Times(1);
151 EXPECT_CALL(*audio_input_listener_, 153 EXPECT_CALL(*audio_input_listener_,
152 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 154 Closed(content::MEDIA_STREAM_DEVICE_TYPE_USER_AUDIO_CAPTURE,
153 session_id)) 155 session_id))
154 .Times(1); 156 .Times(1);
155 157
156 // Waits for the callback. 158 // Waits for the callback.
157 message_loop_->RunAllPending(); 159 message_loop_->RunAllPending();
158 } 160 }
159 } 161 }
160 162
161 // Opens multiple devices at one time and closes them later. 163 // Opens multiple devices at one time and closes them later.
162 TEST_F(AudioInputDeviceManagerTest, OpenMultipleDevices) { 164 TEST_F(AudioInputDeviceManagerTest, OpenMultipleDevices) {
(...skipping 10 matching lines...) Expand all
173 175
174 // Opens the devices in a loop. 176 // Opens the devices in a loop.
175 for (StreamDeviceInfoArray::const_iterator iter = 177 for (StreamDeviceInfoArray::const_iterator iter =
176 audio_input_listener_->devices_.begin(); 178 audio_input_listener_->devices_.begin();
177 iter != audio_input_listener_->devices_.end(); ++iter, ++index) { 179 iter != audio_input_listener_->devices_.end(); ++iter, ++index) {
178 // Opens the devices. 180 // Opens the devices.
179 session_id[index] = manager_->Open(*iter); 181 session_id[index] = manager_->Open(*iter);
180 182
181 // Expected mock call with expected returned value. 183 // Expected mock call with expected returned value.
182 EXPECT_CALL(*audio_input_listener_, 184 EXPECT_CALL(*audio_input_listener_,
183 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 185 Opened(content::MEDIA_STREAM_DEVICE_TYPE_USER_AUDIO_CAPTURE,
184 session_id[index])) 186 session_id[index]))
185 .Times(1); 187 .Times(1);
186 188
187 // Waits for the callback. 189 // Waits for the callback.
188 message_loop_->RunAllPending(); 190 message_loop_->RunAllPending();
189 } 191 }
190 192
191 // Checks if the session_ids are unique. 193 // Checks if the session_ids are unique.
192 for (int i = 0; i < kDeviceSize - 1; ++i) { 194 for (int i = 0; i < kDeviceSize - 1; ++i) {
193 for (int k = i+1; k < kDeviceSize; ++k) { 195 for (int k = i+1; k < kDeviceSize; ++k) {
194 EXPECT_TRUE(session_id[i] != session_id[k]); 196 EXPECT_TRUE(session_id[i] != session_id[k]);
195 } 197 }
196 } 198 }
197 199
198 for (int i = 0; i < kDeviceSize; ++i) { 200 for (int i = 0; i < kDeviceSize; ++i) {
199 // Closes the devices. 201 // Closes the devices.
200 manager_->Close(session_id[i]); 202 manager_->Close(session_id[i]);
201 EXPECT_CALL(*audio_input_listener_, 203 EXPECT_CALL(*audio_input_listener_,
202 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 204 Closed(content::MEDIA_STREAM_DEVICE_TYPE_USER_AUDIO_CAPTURE,
203 session_id[i])) 205 session_id[i]))
204 .Times(1); 206 .Times(1);
205 207
206 // Waits for the callback. 208 // Waits for the callback.
207 message_loop_->RunAllPending(); 209 message_loop_->RunAllPending();
208 } 210 }
209 } 211 }
210 212
211 // Opens a non-existing device. 213 // Opens a non-existing device.
212 TEST_F(AudioInputDeviceManagerTest, OpenNotExistingDevice) { 214 TEST_F(AudioInputDeviceManagerTest, OpenNotExistingDevice) {
213 if (!CanRunAudioInputDeviceTests()) 215 if (!CanRunAudioInputDeviceTests())
214 return; 216 return;
215 InSequence s; 217 InSequence s;
216 218
217 MediaStreamType stream_type = content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE; 219 MediaStreamType stream_type =
220 content::MEDIA_STREAM_DEVICE_TYPE_USER_AUDIO_CAPTURE;
218 std::string device_name("device_doesnt_exist"); 221 std::string device_name("device_doesnt_exist");
219 std::string device_id("id_doesnt_exist"); 222 std::string device_id("id_doesnt_exist");
220 StreamDeviceInfo dummy_device(stream_type, device_name, device_id, false); 223 StreamDeviceInfo dummy_device(stream_type, device_name, device_id, false);
221 224
222 int session_id = manager_->Open(dummy_device); 225 int session_id = manager_->Open(dummy_device);
223 EXPECT_CALL(*audio_input_listener_, 226 EXPECT_CALL(*audio_input_listener_,
224 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 227 Opened(content::MEDIA_STREAM_DEVICE_TYPE_USER_AUDIO_CAPTURE,
225 session_id)) 228 session_id))
226 .Times(1); 229 .Times(1);
227 230
228 // Waits for the callback. 231 // Waits for the callback.
229 message_loop_->RunAllPending(); 232 message_loop_->RunAllPending();
230 } 233 }
231 234
232 // Opens default device twice. 235 // Opens default device twice.
233 TEST_F(AudioInputDeviceManagerTest, OpenDeviceTwice) { 236 TEST_F(AudioInputDeviceManagerTest, OpenDeviceTwice) {
234 if (!CanRunAudioInputDeviceTests()) 237 if (!CanRunAudioInputDeviceTests())
235 return; 238 return;
236 239
237 ASSERT_FALSE(audio_input_listener_->devices_.empty()); 240 ASSERT_FALSE(audio_input_listener_->devices_.empty());
238 241
239 InSequence s; 242 InSequence s;
240 243
241 // Opens and closes the default device twice. 244 // Opens and closes the default device twice.
242 int first_session_id = manager_->Open( 245 int first_session_id = manager_->Open(
243 audio_input_listener_->devices_.front()); 246 audio_input_listener_->devices_.front());
244 int second_session_id = manager_->Open( 247 int second_session_id = manager_->Open(
245 audio_input_listener_->devices_.front()); 248 audio_input_listener_->devices_.front());
246 manager_->Close(first_session_id); 249 manager_->Close(first_session_id);
247 manager_->Close(second_session_id); 250 manager_->Close(second_session_id);
248 251
249 // Expected mock calls with expected returned values. 252 // Expected mock calls with expected returned values.
250 EXPECT_NE(first_session_id, second_session_id); 253 EXPECT_NE(first_session_id, second_session_id);
251 EXPECT_CALL(*audio_input_listener_, 254 EXPECT_CALL(*audio_input_listener_,
252 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 255 Opened(content::MEDIA_STREAM_DEVICE_TYPE_USER_AUDIO_CAPTURE,
253 first_session_id)) 256 first_session_id))
254 .Times(1); 257 .Times(1);
255 EXPECT_CALL(*audio_input_listener_, 258 EXPECT_CALL(*audio_input_listener_,
256 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 259 Opened(content::MEDIA_STREAM_DEVICE_TYPE_USER_AUDIO_CAPTURE,
257 second_session_id)) 260 second_session_id))
258 .Times(1); 261 .Times(1);
259 EXPECT_CALL(*audio_input_listener_, 262 EXPECT_CALL(*audio_input_listener_,
260 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 263 Closed(content::MEDIA_STREAM_DEVICE_TYPE_USER_AUDIO_CAPTURE,
261 first_session_id)) 264 first_session_id))
262 .Times(1); 265 .Times(1);
263 EXPECT_CALL(*audio_input_listener_, 266 EXPECT_CALL(*audio_input_listener_,
264 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 267 Closed(content::MEDIA_STREAM_DEVICE_TYPE_USER_AUDIO_CAPTURE,
265 second_session_id)) 268 second_session_id))
266 .Times(1); 269 .Times(1);
267 270
268 // Waits for the callback. 271 // Waits for the callback.
269 message_loop_->RunAllPending(); 272 message_loop_->RunAllPending();
270 } 273 }
271 274
272 // Starts and closes the sessions after opening the devices. 275 // Starts and closes the sessions after opening the devices.
273 TEST_F(AudioInputDeviceManagerTest, StartAndStopSession) { 276 TEST_F(AudioInputDeviceManagerTest, StartAndStopSession) {
274 if (!CanRunAudioInputDeviceTests()) 277 if (!CanRunAudioInputDeviceTests())
(...skipping 14 matching lines...) Expand all
289 292
290 // Loops through the devices and calls Open()/Start()/Stop()/Close() for 293 // Loops through the devices and calls Open()/Start()/Stop()/Close() for
291 // each device. 294 // each device.
292 for (StreamDeviceInfoArray::const_iterator iter = 295 for (StreamDeviceInfoArray::const_iterator iter =
293 audio_input_listener_->devices_.begin(); 296 audio_input_listener_->devices_.begin();
294 iter != audio_input_listener_->devices_.end(); ++iter, ++index) { 297 iter != audio_input_listener_->devices_.end(); ++iter, ++index) {
295 // Note that no DeviceStopped() notification for Event Handler as we have 298 // Note that no DeviceStopped() notification for Event Handler as we have
296 // stopped the device before calling close. 299 // stopped the device before calling close.
297 session_id[index] = manager_->Open(*iter); 300 session_id[index] = manager_->Open(*iter);
298 EXPECT_CALL(*audio_input_listener_, 301 EXPECT_CALL(*audio_input_listener_,
299 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 302 Opened(content::MEDIA_STREAM_DEVICE_TYPE_USER_AUDIO_CAPTURE,
300 session_id[index])) 303 session_id[index]))
301 .Times(1); 304 .Times(1);
302 message_loop_->RunAllPending(); 305 message_loop_->RunAllPending();
303 306
304 manager_->Start(session_id[index], audio_input_event_handler.get()); 307 manager_->Start(session_id[index], audio_input_event_handler.get());
305 EXPECT_CALL(*audio_input_event_handler, 308 EXPECT_CALL(*audio_input_event_handler,
306 DeviceStarted(session_id[index], iter->device_id)) 309 DeviceStarted(session_id[index], iter->device_id))
307 .Times(1); 310 .Times(1);
308 message_loop_->RunAllPending(); 311 message_loop_->RunAllPending();
309 312
310 manager_->Stop(session_id[index]); 313 manager_->Stop(session_id[index]);
311 manager_->Close(session_id[index]); 314 manager_->Close(session_id[index]);
312 EXPECT_CALL(*audio_input_listener_, 315 EXPECT_CALL(*audio_input_listener_,
313 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 316 Closed(content::MEDIA_STREAM_DEVICE_TYPE_USER_AUDIO_CAPTURE,
314 session_id[index])) 317 session_id[index]))
315 .Times(1); 318 .Times(1);
316 message_loop_->RunAllPending(); 319 message_loop_->RunAllPending();
317 } 320 }
318 } 321 }
319 322
320 // Tests the behavior of calling Close() without calling Stop(). 323 // Tests the behavior of calling Close() without calling Stop().
321 TEST_F(AudioInputDeviceManagerTest, CloseWithoutStopSession) { 324 TEST_F(AudioInputDeviceManagerTest, CloseWithoutStopSession) {
322 if (!CanRunAudioInputDeviceTests()) 325 if (!CanRunAudioInputDeviceTests())
323 return; 326 return;
(...skipping 12 matching lines...) Expand all
336 new MockAudioInputDeviceManagerEventHandler(message_loop_.get())); 339 new MockAudioInputDeviceManagerEventHandler(message_loop_.get()));
337 340
338 // Loop through the devices, and calls Open()/Start()/Close() for the devices. 341 // Loop through the devices, and calls Open()/Start()/Close() for the devices.
339 // Note that we do not call stop. 342 // Note that we do not call stop.
340 for (StreamDeviceInfoArray::const_iterator iter = 343 for (StreamDeviceInfoArray::const_iterator iter =
341 audio_input_listener_->devices_.begin(); 344 audio_input_listener_->devices_.begin();
342 iter != audio_input_listener_->devices_.end(); ++iter, ++index) { 345 iter != audio_input_listener_->devices_.end(); ++iter, ++index) {
343 // Calls Open()/Start()/Close() for each device. 346 // Calls Open()/Start()/Close() for each device.
344 session_id[index] = manager_->Open(*iter); 347 session_id[index] = manager_->Open(*iter);
345 EXPECT_CALL(*audio_input_listener_, 348 EXPECT_CALL(*audio_input_listener_,
346 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 349 Opened(content::MEDIA_STREAM_DEVICE_TYPE_USER_AUDIO_CAPTURE,
347 session_id[index])) 350 session_id[index]))
348 .Times(1); 351 .Times(1);
349 message_loop_->RunAllPending(); 352 message_loop_->RunAllPending();
350 353
351 manager_->Start(session_id[index], audio_input_event_handler.get()); 354 manager_->Start(session_id[index], audio_input_event_handler.get());
352 EXPECT_CALL(*audio_input_event_handler, 355 EXPECT_CALL(*audio_input_event_handler,
353 DeviceStarted(session_id[index], iter->device_id)) 356 DeviceStarted(session_id[index], iter->device_id))
354 .Times(1); 357 .Times(1);
355 message_loop_->RunAllPending(); 358 message_loop_->RunAllPending();
356 359
357 // Event Handler should get a stop device notification as no stop is called 360 // Event Handler should get a stop device notification as no stop is called
358 // before closing the device. 361 // before closing the device.
359 manager_->Close(session_id[index]); 362 manager_->Close(session_id[index]);
360 EXPECT_CALL(*audio_input_event_handler, 363 EXPECT_CALL(*audio_input_event_handler,
361 DeviceStopped(session_id[index])) 364 DeviceStopped(session_id[index]))
362 .Times(1); 365 .Times(1);
363 EXPECT_CALL(*audio_input_listener_, 366 EXPECT_CALL(*audio_input_listener_,
364 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 367 Closed(content::MEDIA_STREAM_DEVICE_TYPE_USER_AUDIO_CAPTURE,
365 session_id[index])) 368 session_id[index]))
366 .Times(1); 369 .Times(1);
367 message_loop_->RunAllPending(); 370 message_loop_->RunAllPending();
368 } 371 }
369 } 372 }
370 373
371 // Starts the same device twice. 374 // Starts the same device twice.
372 TEST_F(AudioInputDeviceManagerTest, StartDeviceTwice) { 375 TEST_F(AudioInputDeviceManagerTest, StartDeviceTwice) {
373 if (!CanRunAudioInputDeviceTests()) 376 if (!CanRunAudioInputDeviceTests())
374 return; 377 return;
(...skipping 10 matching lines...) Expand all
385 second_event_handler( 388 second_event_handler(
386 new MockAudioInputDeviceManagerEventHandler(message_loop_.get())); 389 new MockAudioInputDeviceManagerEventHandler(message_loop_.get()));
387 390
388 // Open the default device twice. 391 // Open the default device twice.
389 StreamDeviceInfoArray::const_iterator iter = 392 StreamDeviceInfoArray::const_iterator iter =
390 audio_input_listener_->devices_.begin(); 393 audio_input_listener_->devices_.begin();
391 int first_session_id = manager_->Open(*iter); 394 int first_session_id = manager_->Open(*iter);
392 int second_session_id = manager_->Open(*iter); 395 int second_session_id = manager_->Open(*iter);
393 EXPECT_NE(first_session_id, second_session_id); 396 EXPECT_NE(first_session_id, second_session_id);
394 EXPECT_CALL(*audio_input_listener_, 397 EXPECT_CALL(*audio_input_listener_,
395 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 398 Opened(content::MEDIA_STREAM_DEVICE_TYPE_USER_AUDIO_CAPTURE,
396 first_session_id)) 399 first_session_id))
397 .Times(1); 400 .Times(1);
398 EXPECT_CALL(*audio_input_listener_, 401 EXPECT_CALL(*audio_input_listener_,
399 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 402 Opened(content::MEDIA_STREAM_DEVICE_TYPE_USER_AUDIO_CAPTURE,
400 second_session_id)) 403 second_session_id))
401 .Times(1); 404 .Times(1);
402 message_loop_->RunAllPending(); 405 message_loop_->RunAllPending();
403 406
404 // Calls Start()/Stop()/Close() for the default device twice. 407 // Calls Start()/Stop()/Close() for the default device twice.
405 manager_->Start(first_session_id, first_event_handler.get()); 408 manager_->Start(first_session_id, first_event_handler.get());
406 manager_->Start(second_session_id, second_event_handler.get()); 409 manager_->Start(second_session_id, second_event_handler.get());
407 EXPECT_CALL(*first_event_handler, 410 EXPECT_CALL(*first_event_handler,
408 DeviceStarted(first_session_id, 411 DeviceStarted(first_session_id,
409 media::AudioManagerBase::kDefaultDeviceId)) 412 media::AudioManagerBase::kDefaultDeviceId))
410 .Times(1); 413 .Times(1);
411 EXPECT_CALL(*second_event_handler, 414 EXPECT_CALL(*second_event_handler,
412 DeviceStarted(second_session_id, 415 DeviceStarted(second_session_id,
413 media::AudioManagerBase::kDefaultDeviceId)) 416 media::AudioManagerBase::kDefaultDeviceId))
414 .Times(1); 417 .Times(1);
415 message_loop_->RunAllPending(); 418 message_loop_->RunAllPending();
416 419
417 manager_->Stop(first_session_id); 420 manager_->Stop(first_session_id);
418 manager_->Stop(second_session_id); 421 manager_->Stop(second_session_id);
419 manager_->Close(first_session_id); 422 manager_->Close(first_session_id);
420 manager_->Close(second_session_id); 423 manager_->Close(second_session_id);
421 EXPECT_CALL(*audio_input_listener_, 424 EXPECT_CALL(*audio_input_listener_,
422 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 425 Closed(content::MEDIA_STREAM_DEVICE_TYPE_USER_AUDIO_CAPTURE,
423 first_session_id)) 426 first_session_id))
424 .Times(1); 427 .Times(1);
425 EXPECT_CALL(*audio_input_listener_, 428 EXPECT_CALL(*audio_input_listener_,
426 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 429 Closed(content::MEDIA_STREAM_DEVICE_TYPE_USER_AUDIO_CAPTURE,
427 second_session_id)) 430 second_session_id))
428 .Times(1); 431 .Times(1);
429 message_loop_->RunAllPending(); 432 message_loop_->RunAllPending();
430 } 433 }
431 434
432 // Starts an invalid session. 435 // Starts an invalid session.
433 TEST_F(AudioInputDeviceManagerTest, StartInvalidSession) { 436 TEST_F(AudioInputDeviceManagerTest, StartInvalidSession) {
434 if (!CanRunAudioInputDeviceTests()) 437 if (!CanRunAudioInputDeviceTests())
435 return; 438 return;
436 InSequence s; 439 InSequence s;
437 440
438 // Creates the EventHandlers for the sessions. 441 // Creates the EventHandlers for the sessions.
439 scoped_ptr<MockAudioInputDeviceManagerEventHandler> 442 scoped_ptr<MockAudioInputDeviceManagerEventHandler>
440 audio_input_event_handler( 443 audio_input_event_handler(
441 new MockAudioInputDeviceManagerEventHandler(message_loop_.get())); 444 new MockAudioInputDeviceManagerEventHandler(message_loop_.get()));
442 445
443 // Opens the first device. 446 // Opens the first device.
444 StreamDeviceInfoArray::const_iterator iter = 447 StreamDeviceInfoArray::const_iterator iter =
445 audio_input_listener_->devices_.begin(); 448 audio_input_listener_->devices_.begin();
446 int session_id = manager_->Open(*iter); 449 int session_id = manager_->Open(*iter);
447 EXPECT_CALL(*audio_input_listener_, 450 EXPECT_CALL(*audio_input_listener_,
448 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 451 Opened(content::MEDIA_STREAM_DEVICE_TYPE_USER_AUDIO_CAPTURE,
449 session_id)) 452 session_id))
450 .Times(1); 453 .Times(1);
451 message_loop_->RunAllPending(); 454 message_loop_->RunAllPending();
452 455
453 // Starts a non-opened device. 456 // Starts a non-opened device.
454 // This should fail and trigger error code 'kDeviceNotAvailable'. 457 // This should fail and trigger error code 'kDeviceNotAvailable'.
455 int invalid_session_id = session_id + 1; 458 int invalid_session_id = session_id + 1;
456 manager_->Start(invalid_session_id, audio_input_event_handler.get()); 459 manager_->Start(invalid_session_id, audio_input_event_handler.get());
457 EXPECT_CALL(*audio_input_event_handler, 460 EXPECT_CALL(*audio_input_event_handler,
458 DeviceStarted(invalid_session_id, std::string())) 461 DeviceStarted(invalid_session_id, std::string()))
459 .Times(1); 462 .Times(1);
460 message_loop_->RunAllPending(); 463 message_loop_->RunAllPending();
461 464
462 manager_->Close(session_id); 465 manager_->Close(session_id);
463 EXPECT_CALL(*audio_input_listener_, 466 EXPECT_CALL(*audio_input_listener_,
464 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 467 Closed(content::MEDIA_STREAM_DEVICE_TYPE_USER_AUDIO_CAPTURE,
465 session_id)) 468 session_id))
466 .Times(1); 469 .Times(1);
467 message_loop_->RunAllPending(); 470 message_loop_->RunAllPending();
468 } 471 }
469 472
470 // Starts a session twice, the first time should succeed, while the second 473 // Starts a session twice, the first time should succeed, while the second
471 // time should fail. 474 // time should fail.
472 TEST_F(AudioInputDeviceManagerTest, StartSessionTwice) { 475 TEST_F(AudioInputDeviceManagerTest, StartSessionTwice) {
473 if (!CanRunAudioInputDeviceTests()) 476 if (!CanRunAudioInputDeviceTests())
474 return; 477 return;
475 InSequence s; 478 InSequence s;
476 479
477 // Creates the EventHandlers for the sessions. 480 // Creates the EventHandlers for the sessions.
478 scoped_ptr<MockAudioInputDeviceManagerEventHandler> 481 scoped_ptr<MockAudioInputDeviceManagerEventHandler>
479 audio_input_event_handler( 482 audio_input_event_handler(
480 new MockAudioInputDeviceManagerEventHandler(message_loop_.get())); 483 new MockAudioInputDeviceManagerEventHandler(message_loop_.get()));
481 484
482 // Opens the first device. 485 // Opens the first device.
483 StreamDeviceInfoArray::const_iterator iter = 486 StreamDeviceInfoArray::const_iterator iter =
484 audio_input_listener_->devices_.begin(); 487 audio_input_listener_->devices_.begin();
485 int session_id = manager_->Open(*iter); 488 int session_id = manager_->Open(*iter);
486 EXPECT_CALL(*audio_input_listener_, 489 EXPECT_CALL(*audio_input_listener_,
487 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 490 Opened(content::MEDIA_STREAM_DEVICE_TYPE_USER_AUDIO_CAPTURE,
488 session_id)) 491 session_id))
489 .Times(1); 492 .Times(1);
490 message_loop_->RunAllPending(); 493 message_loop_->RunAllPending();
491 494
492 // Starts the session, it should succeed. 495 // Starts the session, it should succeed.
493 manager_->Start(session_id, audio_input_event_handler.get()); 496 manager_->Start(session_id, audio_input_event_handler.get());
494 EXPECT_CALL(*audio_input_event_handler, 497 EXPECT_CALL(*audio_input_event_handler,
495 DeviceStarted(session_id, 498 DeviceStarted(session_id,
496 media::AudioManagerBase::kDefaultDeviceId)) 499 media::AudioManagerBase::kDefaultDeviceId))
497 .Times(1); 500 .Times(1);
498 message_loop_->RunAllPending(); 501 message_loop_->RunAllPending();
499 502
500 // Starts the session for the second time, it should fail. 503 // Starts the session for the second time, it should fail.
501 manager_->Start(session_id, audio_input_event_handler.get()); 504 manager_->Start(session_id, audio_input_event_handler.get());
502 EXPECT_CALL(*audio_input_event_handler, 505 EXPECT_CALL(*audio_input_event_handler,
503 DeviceStarted(session_id, std::string())) 506 DeviceStarted(session_id, std::string()))
504 .Times(1); 507 .Times(1);
505 508
506 manager_->Stop(session_id); 509 manager_->Stop(session_id);
507 manager_->Close(session_id); 510 manager_->Close(session_id);
508 EXPECT_CALL(*audio_input_listener_, 511 EXPECT_CALL(*audio_input_listener_,
509 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 512 Closed(content::MEDIA_STREAM_DEVICE_TYPE_USER_AUDIO_CAPTURE,
510 session_id)) 513 session_id))
511 .Times(1); 514 .Times(1);
512 message_loop_->RunAllPending(); 515 message_loop_->RunAllPending();
513 } 516 }
514 517
515 } // namespace media_stream 518 } // namespace media_stream
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698