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

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

Powered by Google App Engine
This is Rietveld 408576698