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