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