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