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

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: Simplify: Use only one AudioInputDeviceManager and VideoCaptureManager, like before. 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"
11 #include "content/browser/browser_thread_impl.h" 11 #include "content/browser/browser_thread_impl.h"
12 #include "content/browser/renderer_host/media/audio_input_device_manager.h" 12 #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" 13 #include "content/browser/renderer_host/media/audio_input_device_manager_event_h andler.h"
14 #include "content/public/common/media_stream_request.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
18 using content::BrowserThread; 19 using content::BrowserThread;
19 using content::BrowserThreadImpl; 20 using content::BrowserThreadImpl;
20 using media_stream::AudioInputDeviceManager; 21 using media_stream::AudioInputDeviceManager;
21 using testing::_; 22 using testing::_;
22 using testing::AnyNumber; 23 using testing::AnyNumber;
23 using testing::InSequence; 24 using testing::InSequence;
24 using testing::Return; 25 using testing::Return;
25 26
26 namespace media_stream { 27 namespace media_stream {
27 28
28 class MockAudioInputDeviceManagerListener 29 class MockAudioInputDeviceManagerListener
29 : public MediaStreamProviderListener { 30 : public MediaStreamProviderListener {
30 public: 31 public:
31 MockAudioInputDeviceManagerListener() {} 32 MockAudioInputDeviceManagerListener() {}
32 virtual ~MockAudioInputDeviceManagerListener() {} 33 virtual ~MockAudioInputDeviceManagerListener() {}
33 34
34 MOCK_METHOD2(Opened, void(MediaStreamType, const int)); 35 MOCK_METHOD2(Opened, void(MediaStreamType, const int));
35 MOCK_METHOD2(Closed, void(MediaStreamType, const int)); 36 MOCK_METHOD2(Closed, void(MediaStreamType, const int));
36 MOCK_METHOD1(DevicesEnumerated, void(const StreamDeviceInfoArray&)); 37 MOCK_METHOD1(DevicesEnumerated, void(const StreamDeviceInfoArray&));
37 MOCK_METHOD3(Error, void(MediaStreamType, int, MediaStreamProviderError)); 38 MOCK_METHOD3(Error, void(MediaStreamType, int, MediaStreamProviderError));
38 39
39 virtual void DevicesEnumerated(MediaStreamType service_type, 40 virtual void DevicesEnumerated(MediaStreamType service_type,
40 const StreamDeviceInfoArray& devices) { 41 const StreamDeviceInfoArray& devices) {
41 if (service_type != content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) 42 if (service_type != content::MEDIA_DEVICE_AUDIO_CAPTURE)
42 return; 43 return;
43 44
44 devices_ = devices; 45 devices_ = devices;
45 DevicesEnumerated(devices); 46 DevicesEnumerated(devices);
46 } 47 }
47 48
48 StreamDeviceInfoArray devices_; 49 StreamDeviceInfoArray devices_;
49 50
50 private: 51 private:
51 DISALLOW_COPY_AND_ASSIGN(MockAudioInputDeviceManagerListener); 52 DISALLOW_COPY_AND_ASSIGN(MockAudioInputDeviceManagerListener);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 139
139 for (StreamDeviceInfoArray::const_iterator iter = 140 for (StreamDeviceInfoArray::const_iterator iter =
140 audio_input_listener_->devices_.begin(); 141 audio_input_listener_->devices_.begin();
141 iter != audio_input_listener_->devices_.end(); ++iter) { 142 iter != audio_input_listener_->devices_.end(); ++iter) {
142 // Opens/closes the devices. 143 // Opens/closes the devices.
143 int session_id = manager_->Open(*iter); 144 int session_id = manager_->Open(*iter);
144 manager_->Close(session_id); 145 manager_->Close(session_id);
145 146
146 // Expected mock call with expected return value. 147 // Expected mock call with expected return value.
147 EXPECT_CALL(*audio_input_listener_, 148 EXPECT_CALL(*audio_input_listener_,
148 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 149 Opened(content::MEDIA_DEVICE_AUDIO_CAPTURE, session_id))
149 session_id))
150 .Times(1); 150 .Times(1);
151 EXPECT_CALL(*audio_input_listener_, 151 EXPECT_CALL(*audio_input_listener_,
152 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 152 Closed(content::MEDIA_DEVICE_AUDIO_CAPTURE, session_id))
153 session_id))
154 .Times(1); 153 .Times(1);
155 154
156 // Waits for the callback. 155 // Waits for the callback.
157 message_loop_->RunAllPending(); 156 message_loop_->RunAllPending();
158 } 157 }
159 } 158 }
160 159
161 // Opens multiple devices at one time and closes them later. 160 // Opens multiple devices at one time and closes them later.
162 TEST_F(AudioInputDeviceManagerTest, OpenMultipleDevices) { 161 TEST_F(AudioInputDeviceManagerTest, OpenMultipleDevices) {
163 if (!CanRunAudioInputDeviceTests()) 162 if (!CanRunAudioInputDeviceTests())
164 return; 163 return;
165 164
166 ASSERT_FALSE(audio_input_listener_->devices_.empty()); 165 ASSERT_FALSE(audio_input_listener_->devices_.empty());
167 166
168 InSequence s; 167 InSequence s;
169 168
170 int index = 0; 169 int index = 0;
171 const int kDeviceSize = audio_input_listener_->devices_.size(); 170 const int kDeviceSize = audio_input_listener_->devices_.size();
172 scoped_array<int> session_id(new int[kDeviceSize]); 171 scoped_array<int> session_id(new int[kDeviceSize]);
173 172
174 // Opens the devices in a loop. 173 // Opens the devices in a loop.
175 for (StreamDeviceInfoArray::const_iterator iter = 174 for (StreamDeviceInfoArray::const_iterator iter =
176 audio_input_listener_->devices_.begin(); 175 audio_input_listener_->devices_.begin();
177 iter != audio_input_listener_->devices_.end(); ++iter, ++index) { 176 iter != audio_input_listener_->devices_.end(); ++iter, ++index) {
178 // Opens the devices. 177 // Opens the devices.
179 session_id[index] = manager_->Open(*iter); 178 session_id[index] = manager_->Open(*iter);
180 179
181 // Expected mock call with expected returned value. 180 // Expected mock call with expected returned value.
182 EXPECT_CALL(*audio_input_listener_, 181 EXPECT_CALL(*audio_input_listener_,
183 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 182 Opened(content::MEDIA_DEVICE_AUDIO_CAPTURE, session_id[index]))
184 session_id[index]))
185 .Times(1); 183 .Times(1);
186 184
187 // Waits for the callback. 185 // Waits for the callback.
188 message_loop_->RunAllPending(); 186 message_loop_->RunAllPending();
189 } 187 }
190 188
191 // Checks if the session_ids are unique. 189 // Checks if the session_ids are unique.
192 for (int i = 0; i < kDeviceSize - 1; ++i) { 190 for (int i = 0; i < kDeviceSize - 1; ++i) {
193 for (int k = i+1; k < kDeviceSize; ++k) { 191 for (int k = i+1; k < kDeviceSize; ++k) {
194 EXPECT_TRUE(session_id[i] != session_id[k]); 192 EXPECT_TRUE(session_id[i] != session_id[k]);
195 } 193 }
196 } 194 }
197 195
198 for (int i = 0; i < kDeviceSize; ++i) { 196 for (int i = 0; i < kDeviceSize; ++i) {
199 // Closes the devices. 197 // Closes the devices.
200 manager_->Close(session_id[i]); 198 manager_->Close(session_id[i]);
201 EXPECT_CALL(*audio_input_listener_, 199 EXPECT_CALL(*audio_input_listener_,
202 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 200 Closed(content::MEDIA_DEVICE_AUDIO_CAPTURE, session_id[i]))
203 session_id[i]))
204 .Times(1); 201 .Times(1);
205 202
206 // Waits for the callback. 203 // Waits for the callback.
207 message_loop_->RunAllPending(); 204 message_loop_->RunAllPending();
208 } 205 }
209 } 206 }
210 207
211 // Opens a non-existing device. 208 // Opens a non-existing device.
212 TEST_F(AudioInputDeviceManagerTest, OpenNotExistingDevice) { 209 TEST_F(AudioInputDeviceManagerTest, OpenNotExistingDevice) {
213 if (!CanRunAudioInputDeviceTests()) 210 if (!CanRunAudioInputDeviceTests())
214 return; 211 return;
215 InSequence s; 212 InSequence s;
216 213
217 MediaStreamType stream_type = content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE; 214 MediaStreamType stream_type = content::MEDIA_DEVICE_AUDIO_CAPTURE;
218 std::string device_name("device_doesnt_exist"); 215 std::string device_name("device_doesnt_exist");
219 std::string device_id("id_doesnt_exist"); 216 std::string device_id("id_doesnt_exist");
220 StreamDeviceInfo dummy_device(stream_type, device_name, device_id, false); 217 StreamDeviceInfo dummy_device(stream_type, device_name, device_id, false);
221 218
222 int session_id = manager_->Open(dummy_device); 219 int session_id = manager_->Open(dummy_device);
223 EXPECT_CALL(*audio_input_listener_, 220 EXPECT_CALL(*audio_input_listener_,
224 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 221 Opened(content::MEDIA_DEVICE_AUDIO_CAPTURE, session_id))
225 session_id))
226 .Times(1); 222 .Times(1);
227 223
228 // Waits for the callback. 224 // Waits for the callback.
229 message_loop_->RunAllPending(); 225 message_loop_->RunAllPending();
230 } 226 }
231 227
232 // Opens default device twice. 228 // Opens default device twice.
233 TEST_F(AudioInputDeviceManagerTest, OpenDeviceTwice) { 229 TEST_F(AudioInputDeviceManagerTest, OpenDeviceTwice) {
234 if (!CanRunAudioInputDeviceTests()) 230 if (!CanRunAudioInputDeviceTests())
235 return; 231 return;
236 232
237 ASSERT_FALSE(audio_input_listener_->devices_.empty()); 233 ASSERT_FALSE(audio_input_listener_->devices_.empty());
238 234
239 InSequence s; 235 InSequence s;
240 236
241 // Opens and closes the default device twice. 237 // Opens and closes the default device twice.
242 int first_session_id = manager_->Open( 238 int first_session_id = manager_->Open(
243 audio_input_listener_->devices_.front()); 239 audio_input_listener_->devices_.front());
244 int second_session_id = manager_->Open( 240 int second_session_id = manager_->Open(
245 audio_input_listener_->devices_.front()); 241 audio_input_listener_->devices_.front());
246 manager_->Close(first_session_id); 242 manager_->Close(first_session_id);
247 manager_->Close(second_session_id); 243 manager_->Close(second_session_id);
248 244
249 // Expected mock calls with expected returned values. 245 // Expected mock calls with expected returned values.
250 EXPECT_NE(first_session_id, second_session_id); 246 EXPECT_NE(first_session_id, second_session_id);
251 EXPECT_CALL(*audio_input_listener_, 247 EXPECT_CALL(*audio_input_listener_,
252 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 248 Opened(content::MEDIA_DEVICE_AUDIO_CAPTURE, first_session_id))
253 first_session_id))
254 .Times(1); 249 .Times(1);
255 EXPECT_CALL(*audio_input_listener_, 250 EXPECT_CALL(*audio_input_listener_,
256 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 251 Opened(content::MEDIA_DEVICE_AUDIO_CAPTURE, second_session_id))
257 second_session_id))
258 .Times(1); 252 .Times(1);
259 EXPECT_CALL(*audio_input_listener_, 253 EXPECT_CALL(*audio_input_listener_,
260 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 254 Closed(content::MEDIA_DEVICE_AUDIO_CAPTURE, first_session_id))
261 first_session_id))
262 .Times(1); 255 .Times(1);
263 EXPECT_CALL(*audio_input_listener_, 256 EXPECT_CALL(*audio_input_listener_,
264 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 257 Closed(content::MEDIA_DEVICE_AUDIO_CAPTURE, second_session_id))
265 second_session_id))
266 .Times(1); 258 .Times(1);
267 259
268 // Waits for the callback. 260 // Waits for the callback.
269 message_loop_->RunAllPending(); 261 message_loop_->RunAllPending();
270 } 262 }
271 263
272 // Starts and closes the sessions after opening the devices. 264 // Starts and closes the sessions after opening the devices.
273 TEST_F(AudioInputDeviceManagerTest, StartAndStopSession) { 265 TEST_F(AudioInputDeviceManagerTest, StartAndStopSession) {
274 if (!CanRunAudioInputDeviceTests()) 266 if (!CanRunAudioInputDeviceTests())
275 return; 267 return;
(...skipping 13 matching lines...) Expand all
289 281
290 // Loops through the devices and calls Open()/Start()/Stop()/Close() for 282 // Loops through the devices and calls Open()/Start()/Stop()/Close() for
291 // each device. 283 // each device.
292 for (StreamDeviceInfoArray::const_iterator iter = 284 for (StreamDeviceInfoArray::const_iterator iter =
293 audio_input_listener_->devices_.begin(); 285 audio_input_listener_->devices_.begin();
294 iter != audio_input_listener_->devices_.end(); ++iter, ++index) { 286 iter != audio_input_listener_->devices_.end(); ++iter, ++index) {
295 // Note that no DeviceStopped() notification for Event Handler as we have 287 // Note that no DeviceStopped() notification for Event Handler as we have
296 // stopped the device before calling close. 288 // stopped the device before calling close.
297 session_id[index] = manager_->Open(*iter); 289 session_id[index] = manager_->Open(*iter);
298 EXPECT_CALL(*audio_input_listener_, 290 EXPECT_CALL(*audio_input_listener_,
299 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 291 Opened(content::MEDIA_DEVICE_AUDIO_CAPTURE, session_id[index]))
300 session_id[index]))
301 .Times(1); 292 .Times(1);
302 message_loop_->RunAllPending(); 293 message_loop_->RunAllPending();
303 294
304 manager_->Start(session_id[index], audio_input_event_handler.get()); 295 manager_->Start(session_id[index], audio_input_event_handler.get());
305 EXPECT_CALL(*audio_input_event_handler, 296 EXPECT_CALL(*audio_input_event_handler,
306 DeviceStarted(session_id[index], iter->device_id)) 297 DeviceStarted(session_id[index], iter->device_id))
307 .Times(1); 298 .Times(1);
308 message_loop_->RunAllPending(); 299 message_loop_->RunAllPending();
309 300
310 manager_->Stop(session_id[index]); 301 manager_->Stop(session_id[index]);
311 manager_->Close(session_id[index]); 302 manager_->Close(session_id[index]);
312 EXPECT_CALL(*audio_input_listener_, 303 EXPECT_CALL(*audio_input_listener_,
313 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 304 Closed(content::MEDIA_DEVICE_AUDIO_CAPTURE, session_id[index]))
314 session_id[index]))
315 .Times(1); 305 .Times(1);
316 message_loop_->RunAllPending(); 306 message_loop_->RunAllPending();
317 } 307 }
318 } 308 }
319 309
320 // Tests the behavior of calling Close() without calling Stop(). 310 // Tests the behavior of calling Close() without calling Stop().
321 TEST_F(AudioInputDeviceManagerTest, CloseWithoutStopSession) { 311 TEST_F(AudioInputDeviceManagerTest, CloseWithoutStopSession) {
322 if (!CanRunAudioInputDeviceTests()) 312 if (!CanRunAudioInputDeviceTests())
323 return; 313 return;
324 314
(...skipping 11 matching lines...) Expand all
336 new MockAudioInputDeviceManagerEventHandler(message_loop_.get())); 326 new MockAudioInputDeviceManagerEventHandler(message_loop_.get()));
337 327
338 // Loop through the devices, and calls Open()/Start()/Close() for the devices. 328 // Loop through the devices, and calls Open()/Start()/Close() for the devices.
339 // Note that we do not call stop. 329 // Note that we do not call stop.
340 for (StreamDeviceInfoArray::const_iterator iter = 330 for (StreamDeviceInfoArray::const_iterator iter =
341 audio_input_listener_->devices_.begin(); 331 audio_input_listener_->devices_.begin();
342 iter != audio_input_listener_->devices_.end(); ++iter, ++index) { 332 iter != audio_input_listener_->devices_.end(); ++iter, ++index) {
343 // Calls Open()/Start()/Close() for each device. 333 // Calls Open()/Start()/Close() for each device.
344 session_id[index] = manager_->Open(*iter); 334 session_id[index] = manager_->Open(*iter);
345 EXPECT_CALL(*audio_input_listener_, 335 EXPECT_CALL(*audio_input_listener_,
346 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 336 Opened(content::MEDIA_DEVICE_AUDIO_CAPTURE, session_id[index]))
347 session_id[index]))
348 .Times(1); 337 .Times(1);
349 message_loop_->RunAllPending(); 338 message_loop_->RunAllPending();
350 339
351 manager_->Start(session_id[index], audio_input_event_handler.get()); 340 manager_->Start(session_id[index], audio_input_event_handler.get());
352 EXPECT_CALL(*audio_input_event_handler, 341 EXPECT_CALL(*audio_input_event_handler,
353 DeviceStarted(session_id[index], iter->device_id)) 342 DeviceStarted(session_id[index], iter->device_id))
354 .Times(1); 343 .Times(1);
355 message_loop_->RunAllPending(); 344 message_loop_->RunAllPending();
356 345
357 // Event Handler should get a stop device notification as no stop is called 346 // Event Handler should get a stop device notification as no stop is called
358 // before closing the device. 347 // before closing the device.
359 manager_->Close(session_id[index]); 348 manager_->Close(session_id[index]);
360 EXPECT_CALL(*audio_input_event_handler, 349 EXPECT_CALL(*audio_input_event_handler,
361 DeviceStopped(session_id[index])) 350 DeviceStopped(session_id[index]))
362 .Times(1); 351 .Times(1);
363 EXPECT_CALL(*audio_input_listener_, 352 EXPECT_CALL(*audio_input_listener_,
364 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 353 Closed(content::MEDIA_DEVICE_AUDIO_CAPTURE, session_id[index]))
365 session_id[index]))
366 .Times(1); 354 .Times(1);
367 message_loop_->RunAllPending(); 355 message_loop_->RunAllPending();
368 } 356 }
369 } 357 }
370 358
371 // Starts the same device twice. 359 // Starts the same device twice.
372 TEST_F(AudioInputDeviceManagerTest, StartDeviceTwice) { 360 TEST_F(AudioInputDeviceManagerTest, StartDeviceTwice) {
373 if (!CanRunAudioInputDeviceTests()) 361 if (!CanRunAudioInputDeviceTests())
374 return; 362 return;
375 363
376 ASSERT_FALSE(audio_input_listener_->devices_.empty()); 364 ASSERT_FALSE(audio_input_listener_->devices_.empty());
377 365
378 InSequence s; 366 InSequence s;
379 367
380 // Create one EventHandler for each session. 368 // Create one EventHandler for each session.
381 scoped_ptr<MockAudioInputDeviceManagerEventHandler> 369 scoped_ptr<MockAudioInputDeviceManagerEventHandler>
382 first_event_handler( 370 first_event_handler(
383 new MockAudioInputDeviceManagerEventHandler(message_loop_.get())); 371 new MockAudioInputDeviceManagerEventHandler(message_loop_.get()));
384 scoped_ptr<MockAudioInputDeviceManagerEventHandler> 372 scoped_ptr<MockAudioInputDeviceManagerEventHandler>
385 second_event_handler( 373 second_event_handler(
386 new MockAudioInputDeviceManagerEventHandler(message_loop_.get())); 374 new MockAudioInputDeviceManagerEventHandler(message_loop_.get()));
387 375
388 // Open the default device twice. 376 // Open the default device twice.
389 StreamDeviceInfoArray::const_iterator iter = 377 StreamDeviceInfoArray::const_iterator iter =
390 audio_input_listener_->devices_.begin(); 378 audio_input_listener_->devices_.begin();
391 int first_session_id = manager_->Open(*iter); 379 int first_session_id = manager_->Open(*iter);
392 int second_session_id = manager_->Open(*iter); 380 int second_session_id = manager_->Open(*iter);
393 EXPECT_NE(first_session_id, second_session_id); 381 EXPECT_NE(first_session_id, second_session_id);
394 EXPECT_CALL(*audio_input_listener_, 382 EXPECT_CALL(*audio_input_listener_,
395 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 383 Opened(content::MEDIA_DEVICE_AUDIO_CAPTURE, first_session_id))
396 first_session_id))
397 .Times(1); 384 .Times(1);
398 EXPECT_CALL(*audio_input_listener_, 385 EXPECT_CALL(*audio_input_listener_,
399 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 386 Opened(content::MEDIA_DEVICE_AUDIO_CAPTURE, second_session_id))
400 second_session_id))
401 .Times(1); 387 .Times(1);
402 message_loop_->RunAllPending(); 388 message_loop_->RunAllPending();
403 389
404 // Calls Start()/Stop()/Close() for the default device twice. 390 // Calls Start()/Stop()/Close() for the default device twice.
405 manager_->Start(first_session_id, first_event_handler.get()); 391 manager_->Start(first_session_id, first_event_handler.get());
406 manager_->Start(second_session_id, second_event_handler.get()); 392 manager_->Start(second_session_id, second_event_handler.get());
407 EXPECT_CALL(*first_event_handler, 393 EXPECT_CALL(*first_event_handler,
408 DeviceStarted(first_session_id, 394 DeviceStarted(first_session_id,
409 media::AudioManagerBase::kDefaultDeviceId)) 395 media::AudioManagerBase::kDefaultDeviceId))
410 .Times(1); 396 .Times(1);
411 EXPECT_CALL(*second_event_handler, 397 EXPECT_CALL(*second_event_handler,
412 DeviceStarted(second_session_id, 398 DeviceStarted(second_session_id,
413 media::AudioManagerBase::kDefaultDeviceId)) 399 media::AudioManagerBase::kDefaultDeviceId))
414 .Times(1); 400 .Times(1);
415 message_loop_->RunAllPending(); 401 message_loop_->RunAllPending();
416 402
417 manager_->Stop(first_session_id); 403 manager_->Stop(first_session_id);
418 manager_->Stop(second_session_id); 404 manager_->Stop(second_session_id);
419 manager_->Close(first_session_id); 405 manager_->Close(first_session_id);
420 manager_->Close(second_session_id); 406 manager_->Close(second_session_id);
421 EXPECT_CALL(*audio_input_listener_, 407 EXPECT_CALL(*audio_input_listener_,
422 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 408 Closed(content::MEDIA_DEVICE_AUDIO_CAPTURE, first_session_id))
423 first_session_id))
424 .Times(1); 409 .Times(1);
425 EXPECT_CALL(*audio_input_listener_, 410 EXPECT_CALL(*audio_input_listener_,
426 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 411 Closed(content::MEDIA_DEVICE_AUDIO_CAPTURE, second_session_id))
427 second_session_id))
428 .Times(1); 412 .Times(1);
429 message_loop_->RunAllPending(); 413 message_loop_->RunAllPending();
430 } 414 }
431 415
432 // Starts an invalid session. 416 // Starts an invalid session.
433 TEST_F(AudioInputDeviceManagerTest, StartInvalidSession) { 417 TEST_F(AudioInputDeviceManagerTest, StartInvalidSession) {
434 if (!CanRunAudioInputDeviceTests()) 418 if (!CanRunAudioInputDeviceTests())
435 return; 419 return;
436 InSequence s; 420 InSequence s;
437 421
438 // Creates the EventHandlers for the sessions. 422 // Creates the EventHandlers for the sessions.
439 scoped_ptr<MockAudioInputDeviceManagerEventHandler> 423 scoped_ptr<MockAudioInputDeviceManagerEventHandler>
440 audio_input_event_handler( 424 audio_input_event_handler(
441 new MockAudioInputDeviceManagerEventHandler(message_loop_.get())); 425 new MockAudioInputDeviceManagerEventHandler(message_loop_.get()));
442 426
443 // Opens the first device. 427 // Opens the first device.
444 StreamDeviceInfoArray::const_iterator iter = 428 StreamDeviceInfoArray::const_iterator iter =
445 audio_input_listener_->devices_.begin(); 429 audio_input_listener_->devices_.begin();
446 int session_id = manager_->Open(*iter); 430 int session_id = manager_->Open(*iter);
447 EXPECT_CALL(*audio_input_listener_, 431 EXPECT_CALL(*audio_input_listener_,
448 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 432 Opened(content::MEDIA_DEVICE_AUDIO_CAPTURE, session_id))
449 session_id))
450 .Times(1); 433 .Times(1);
451 message_loop_->RunAllPending(); 434 message_loop_->RunAllPending();
452 435
453 // Starts a non-opened device. 436 // Starts a non-opened device.
454 // This should fail and trigger error code 'kDeviceNotAvailable'. 437 // This should fail and trigger error code 'kDeviceNotAvailable'.
455 int invalid_session_id = session_id + 1; 438 int invalid_session_id = session_id + 1;
456 manager_->Start(invalid_session_id, audio_input_event_handler.get()); 439 manager_->Start(invalid_session_id, audio_input_event_handler.get());
457 EXPECT_CALL(*audio_input_event_handler, 440 EXPECT_CALL(*audio_input_event_handler,
458 DeviceStarted(invalid_session_id, std::string())) 441 DeviceStarted(invalid_session_id, std::string()))
459 .Times(1); 442 .Times(1);
460 message_loop_->RunAllPending(); 443 message_loop_->RunAllPending();
461 444
462 manager_->Close(session_id); 445 manager_->Close(session_id);
463 EXPECT_CALL(*audio_input_listener_, 446 EXPECT_CALL(*audio_input_listener_,
464 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 447 Closed(content::MEDIA_DEVICE_AUDIO_CAPTURE, session_id))
465 session_id))
466 .Times(1); 448 .Times(1);
467 message_loop_->RunAllPending(); 449 message_loop_->RunAllPending();
468 } 450 }
469 451
470 // Starts a session twice, the first time should succeed, while the second 452 // Starts a session twice, the first time should succeed, while the second
471 // time should fail. 453 // time should fail.
472 TEST_F(AudioInputDeviceManagerTest, StartSessionTwice) { 454 TEST_F(AudioInputDeviceManagerTest, StartSessionTwice) {
473 if (!CanRunAudioInputDeviceTests()) 455 if (!CanRunAudioInputDeviceTests())
474 return; 456 return;
475 InSequence s; 457 InSequence s;
476 458
477 // Creates the EventHandlers for the sessions. 459 // Creates the EventHandlers for the sessions.
478 scoped_ptr<MockAudioInputDeviceManagerEventHandler> 460 scoped_ptr<MockAudioInputDeviceManagerEventHandler>
479 audio_input_event_handler( 461 audio_input_event_handler(
480 new MockAudioInputDeviceManagerEventHandler(message_loop_.get())); 462 new MockAudioInputDeviceManagerEventHandler(message_loop_.get()));
481 463
482 // Opens the first device. 464 // Opens the first device.
483 StreamDeviceInfoArray::const_iterator iter = 465 StreamDeviceInfoArray::const_iterator iter =
484 audio_input_listener_->devices_.begin(); 466 audio_input_listener_->devices_.begin();
485 int session_id = manager_->Open(*iter); 467 int session_id = manager_->Open(*iter);
486 EXPECT_CALL(*audio_input_listener_, 468 EXPECT_CALL(*audio_input_listener_,
487 Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 469 Opened(content::MEDIA_DEVICE_AUDIO_CAPTURE, session_id))
488 session_id))
489 .Times(1); 470 .Times(1);
490 message_loop_->RunAllPending(); 471 message_loop_->RunAllPending();
491 472
492 // Starts the session, it should succeed. 473 // Starts the session, it should succeed.
493 manager_->Start(session_id, audio_input_event_handler.get()); 474 manager_->Start(session_id, audio_input_event_handler.get());
494 EXPECT_CALL(*audio_input_event_handler, 475 EXPECT_CALL(*audio_input_event_handler,
495 DeviceStarted(session_id, 476 DeviceStarted(session_id,
496 media::AudioManagerBase::kDefaultDeviceId)) 477 media::AudioManagerBase::kDefaultDeviceId))
497 .Times(1); 478 .Times(1);
498 message_loop_->RunAllPending(); 479 message_loop_->RunAllPending();
499 480
500 // Starts the session for the second time, it should fail. 481 // Starts the session for the second time, it should fail.
501 manager_->Start(session_id, audio_input_event_handler.get()); 482 manager_->Start(session_id, audio_input_event_handler.get());
502 EXPECT_CALL(*audio_input_event_handler, 483 EXPECT_CALL(*audio_input_event_handler,
503 DeviceStarted(session_id, std::string())) 484 DeviceStarted(session_id, std::string()))
504 .Times(1); 485 .Times(1);
505 486
506 manager_->Stop(session_id); 487 manager_->Stop(session_id);
507 manager_->Close(session_id); 488 manager_->Close(session_id);
508 EXPECT_CALL(*audio_input_listener_, 489 EXPECT_CALL(*audio_input_listener_,
509 Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 490 Closed(content::MEDIA_DEVICE_AUDIO_CAPTURE, session_id))
510 session_id))
511 .Times(1); 491 .Times(1);
512 message_loop_->RunAllPending(); 492 message_loop_->RunAllPending();
513 } 493 }
514 494
515 } // namespace media_stream 495 } // namespace media_stream
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698