| 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 "content/browser/renderer_host/media/audio_input_device_manager.h" | 5 #include "content/browser/renderer_host/media/audio_input_device_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 // Use fake devices. | 76 // Use fake devices. |
| 77 devices_.emplace_back(MEDIA_DEVICE_AUDIO_CAPTURE, "Fake Device 1", | 77 devices_.emplace_back(MEDIA_DEVICE_AUDIO_CAPTURE, "Fake Device 1", |
| 78 "fake_device_1"); | 78 "fake_device_1"); |
| 79 devices_.emplace_back(MEDIA_DEVICE_AUDIO_CAPTURE, "Fake Device 2", | 79 devices_.emplace_back(MEDIA_DEVICE_AUDIO_CAPTURE, "Fake Device 2", |
| 80 "fake_device_2"); | 80 "fake_device_2"); |
| 81 | 81 |
| 82 // Wait until we get the list. | 82 // Wait until we get the list. |
| 83 base::RunLoop().RunUntilIdle(); | 83 base::RunLoop().RunUntilIdle(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void TearDown() override { manager_->UnregisterListener(); } | 86 void TearDown() override { |
| 87 manager_->UnregisterListener(audio_input_listener_.get()); |
| 88 } |
| 87 | 89 |
| 88 TestBrowserThreadBundle thread_bundle_; | 90 TestBrowserThreadBundle thread_bundle_; |
| 89 scoped_refptr<AudioInputDeviceManager> manager_; | 91 scoped_refptr<AudioInputDeviceManager> manager_; |
| 90 std::unique_ptr<MockAudioInputDeviceManagerListener> audio_input_listener_; | 92 std::unique_ptr<MockAudioInputDeviceManagerListener> audio_input_listener_; |
| 91 media::ScopedAudioManagerPtr audio_manager_; | 93 media::ScopedAudioManagerPtr audio_manager_; |
| 92 StreamDeviceInfoArray devices_; | 94 StreamDeviceInfoArray devices_; |
| 93 | 95 |
| 94 private: | 96 private: |
| 95 DISALLOW_COPY_AND_ASSIGN(MAYBE_AudioInputDeviceManagerTest); | 97 DISALLOW_COPY_AND_ASSIGN(MAYBE_AudioInputDeviceManagerTest); |
| 96 }; | 98 }; |
| 97 | 99 |
| 98 // Opens and closes the devices. | 100 // Opens and closes the devices. |
| 99 TEST_F(MAYBE_AudioInputDeviceManagerTest, OpenAndCloseDevice) { | 101 TEST_F(MAYBE_AudioInputDeviceManagerTest, OpenAndCloseDevice) { |
| 100 ASSERT_FALSE(devices_.empty()); | 102 ASSERT_FALSE(devices_.empty()); |
| 101 | 103 |
| 102 InSequence s; | 104 InSequence s; |
| 103 | 105 |
| 104 for (StreamDeviceInfoArray::const_iterator iter = devices_.begin(); | 106 for (StreamDeviceInfoArray::const_iterator iter = devices_.begin(); |
| 105 iter != devices_.end(); ++iter) { | 107 iter != devices_.end(); ++iter) { |
| 106 // Opens/closes the devices. | 108 // Opens/closes the devices. |
| 107 int session_id = manager_->Open(*iter); | 109 int session_id = manager_->Open(iter->device); |
| 108 | 110 |
| 109 // Expected mock call with expected return value. | 111 // Expected mock call with expected return value. |
| 110 EXPECT_CALL(*audio_input_listener_, | 112 EXPECT_CALL(*audio_input_listener_, |
| 111 Opened(MEDIA_DEVICE_AUDIO_CAPTURE, session_id)) | 113 Opened(MEDIA_DEVICE_AUDIO_CAPTURE, session_id)) |
| 112 .Times(1); | 114 .Times(1); |
| 113 // Waits for the callback. | 115 // Waits for the callback. |
| 114 base::RunLoop().RunUntilIdle(); | 116 base::RunLoop().RunUntilIdle(); |
| 115 | 117 |
| 116 manager_->Close(session_id); | 118 manager_->Close(session_id); |
| 117 EXPECT_CALL(*audio_input_listener_, | 119 EXPECT_CALL(*audio_input_listener_, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 129 | 131 |
| 130 InSequence s; | 132 InSequence s; |
| 131 | 133 |
| 132 int index = 0; | 134 int index = 0; |
| 133 std::unique_ptr<int[]> session_id(new int[devices_.size()]); | 135 std::unique_ptr<int[]> session_id(new int[devices_.size()]); |
| 134 | 136 |
| 135 // Opens the devices in a loop. | 137 // Opens the devices in a loop. |
| 136 for (StreamDeviceInfoArray::const_iterator iter = devices_.begin(); | 138 for (StreamDeviceInfoArray::const_iterator iter = devices_.begin(); |
| 137 iter != devices_.end(); ++iter, ++index) { | 139 iter != devices_.end(); ++iter, ++index) { |
| 138 // Opens the devices. | 140 // Opens the devices. |
| 139 session_id[index] = manager_->Open(*iter); | 141 session_id[index] = manager_->Open(iter->device); |
| 140 | 142 |
| 141 // Expected mock call with expected returned value. | 143 // Expected mock call with expected returned value. |
| 142 EXPECT_CALL(*audio_input_listener_, | 144 EXPECT_CALL(*audio_input_listener_, |
| 143 Opened(MEDIA_DEVICE_AUDIO_CAPTURE, session_id[index])) | 145 Opened(MEDIA_DEVICE_AUDIO_CAPTURE, session_id[index])) |
| 144 .Times(1); | 146 .Times(1); |
| 145 | 147 |
| 146 // Waits for the callback. | 148 // Waits for the callback. |
| 147 base::RunLoop().RunUntilIdle(); | 149 base::RunLoop().RunUntilIdle(); |
| 148 } | 150 } |
| 149 | 151 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 166 } | 168 } |
| 167 } | 169 } |
| 168 | 170 |
| 169 // Opens a non-existing device. | 171 // Opens a non-existing device. |
| 170 TEST_F(MAYBE_AudioInputDeviceManagerTest, OpenNotExistingDevice) { | 172 TEST_F(MAYBE_AudioInputDeviceManagerTest, OpenNotExistingDevice) { |
| 171 InSequence s; | 173 InSequence s; |
| 172 | 174 |
| 173 MediaStreamType stream_type = MEDIA_DEVICE_AUDIO_CAPTURE; | 175 MediaStreamType stream_type = MEDIA_DEVICE_AUDIO_CAPTURE; |
| 174 std::string device_name("device_doesnt_exist"); | 176 std::string device_name("device_doesnt_exist"); |
| 175 std::string device_id("id_doesnt_exist"); | 177 std::string device_id("id_doesnt_exist"); |
| 176 int sample_rate(0); | 178 MediaStreamDevice dummy_device(stream_type, device_id, device_name); |
| 177 int channel_config(0); | |
| 178 StreamDeviceInfo dummy_device(stream_type, device_name, device_id, | |
| 179 sample_rate, channel_config, 2048); | |
| 180 | 179 |
| 181 int session_id = manager_->Open(dummy_device); | 180 int session_id = manager_->Open(dummy_device); |
| 182 EXPECT_CALL(*audio_input_listener_, | 181 EXPECT_CALL(*audio_input_listener_, |
| 183 Opened(MEDIA_DEVICE_AUDIO_CAPTURE, session_id)) | 182 Opened(MEDIA_DEVICE_AUDIO_CAPTURE, session_id)) |
| 184 .Times(1); | 183 .Times(1); |
| 185 | 184 |
| 186 // Waits for the callback. | 185 // Waits for the callback. |
| 187 base::RunLoop().RunUntilIdle(); | 186 base::RunLoop().RunUntilIdle(); |
| 188 } | 187 } |
| 189 | 188 |
| 190 // Opens default device twice. | 189 // Opens default device twice. |
| 191 TEST_F(MAYBE_AudioInputDeviceManagerTest, OpenDeviceTwice) { | 190 TEST_F(MAYBE_AudioInputDeviceManagerTest, OpenDeviceTwice) { |
| 192 ASSERT_FALSE(devices_.empty()); | 191 ASSERT_FALSE(devices_.empty()); |
| 193 | 192 |
| 194 InSequence s; | 193 InSequence s; |
| 195 | 194 |
| 196 // Opens and closes the default device twice. | 195 // Opens and closes the default device twice. |
| 197 int first_session_id = manager_->Open(devices_.front()); | 196 int first_session_id = manager_->Open(devices_.front().device); |
| 198 int second_session_id = manager_->Open(devices_.front()); | 197 int second_session_id = manager_->Open(devices_.front().device); |
| 199 | 198 |
| 200 // Expected mock calls with expected returned values. | 199 // Expected mock calls with expected returned values. |
| 201 EXPECT_NE(first_session_id, second_session_id); | 200 EXPECT_NE(first_session_id, second_session_id); |
| 202 EXPECT_CALL(*audio_input_listener_, | 201 EXPECT_CALL(*audio_input_listener_, |
| 203 Opened(MEDIA_DEVICE_AUDIO_CAPTURE, first_session_id)) | 202 Opened(MEDIA_DEVICE_AUDIO_CAPTURE, first_session_id)) |
| 204 .Times(1); | 203 .Times(1); |
| 205 EXPECT_CALL(*audio_input_listener_, | 204 EXPECT_CALL(*audio_input_listener_, |
| 206 Opened(MEDIA_DEVICE_AUDIO_CAPTURE, second_session_id)) | 205 Opened(MEDIA_DEVICE_AUDIO_CAPTURE, second_session_id)) |
| 207 .Times(1); | 206 .Times(1); |
| 208 // Waits for the callback. | 207 // Waits for the callback. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 228 | 227 |
| 229 int index = 0; | 228 int index = 0; |
| 230 std::unique_ptr<int[]> session_id(new int[devices_.size()]); | 229 std::unique_ptr<int[]> session_id(new int[devices_.size()]); |
| 231 | 230 |
| 232 // Loops through the devices and calls Open()/Close()/GetOpenedDeviceInfoById | 231 // Loops through the devices and calls Open()/Close()/GetOpenedDeviceInfoById |
| 233 // for each device. | 232 // for each device. |
| 234 for (StreamDeviceInfoArray::const_iterator iter = devices_.begin(); | 233 for (StreamDeviceInfoArray::const_iterator iter = devices_.begin(); |
| 235 iter != devices_.end(); ++iter, ++index) { | 234 iter != devices_.end(); ++iter, ++index) { |
| 236 // Note that no DeviceStopped() notification for Event Handler as we have | 235 // Note that no DeviceStopped() notification for Event Handler as we have |
| 237 // stopped the device before calling close. | 236 // stopped the device before calling close. |
| 238 session_id[index] = manager_->Open(*iter); | 237 session_id[index] = manager_->Open(iter->device); |
| 239 EXPECT_CALL(*audio_input_listener_, | 238 EXPECT_CALL(*audio_input_listener_, |
| 240 Opened(MEDIA_DEVICE_AUDIO_CAPTURE, session_id[index])) | 239 Opened(MEDIA_DEVICE_AUDIO_CAPTURE, session_id[index])) |
| 241 .Times(1); | 240 .Times(1); |
| 242 base::RunLoop().RunUntilIdle(); | 241 base::RunLoop().RunUntilIdle(); |
| 243 | 242 |
| 244 const StreamDeviceInfo* info = manager_->GetOpenedDeviceInfoById( | 243 const StreamDeviceInfo* info = manager_->GetOpenedDeviceInfoById( |
| 245 session_id[index]); | 244 session_id[index]); |
| 246 DCHECK(info); | 245 DCHECK(info); |
| 247 EXPECT_EQ(iter->device.id, info->device.id); | 246 EXPECT_EQ(iter->device.id, info->device.id); |
| 248 manager_->Close(session_id[index]); | 247 manager_->Close(session_id[index]); |
| 249 EXPECT_CALL(*audio_input_listener_, | 248 EXPECT_CALL(*audio_input_listener_, |
| 250 Closed(MEDIA_DEVICE_AUDIO_CAPTURE, session_id[index])) | 249 Closed(MEDIA_DEVICE_AUDIO_CAPTURE, session_id[index])) |
| 251 .Times(1); | 250 .Times(1); |
| 252 base::RunLoop().RunUntilIdle(); | 251 base::RunLoop().RunUntilIdle(); |
| 253 } | 252 } |
| 254 } | 253 } |
| 255 | 254 |
| 256 // Access an invalid session. | 255 // Access an invalid session. |
| 257 TEST_F(MAYBE_AudioInputDeviceManagerTest, AccessInvalidSession) { | 256 TEST_F(MAYBE_AudioInputDeviceManagerTest, AccessInvalidSession) { |
| 258 InSequence s; | 257 InSequence s; |
| 259 | 258 |
| 260 // Opens the first device. | 259 // Opens the first device. |
| 261 StreamDeviceInfoArray::const_iterator iter = devices_.begin(); | 260 StreamDeviceInfoArray::const_iterator iter = devices_.begin(); |
| 262 int session_id = manager_->Open(*iter); | 261 int session_id = manager_->Open(iter->device); |
| 263 EXPECT_CALL(*audio_input_listener_, | 262 EXPECT_CALL(*audio_input_listener_, |
| 264 Opened(MEDIA_DEVICE_AUDIO_CAPTURE, session_id)) | 263 Opened(MEDIA_DEVICE_AUDIO_CAPTURE, session_id)) |
| 265 .Times(1); | 264 .Times(1); |
| 266 base::RunLoop().RunUntilIdle(); | 265 base::RunLoop().RunUntilIdle(); |
| 267 | 266 |
| 268 // Access a non-opened device. | 267 // Access a non-opened device. |
| 269 // This should fail and return an empty StreamDeviceInfo. | 268 // This should fail and return an empty StreamDeviceInfo. |
| 270 int invalid_session_id = session_id + 1; | 269 int invalid_session_id = session_id + 1; |
| 271 const StreamDeviceInfo* info = | 270 const StreamDeviceInfo* info = |
| 272 manager_->GetOpenedDeviceInfoById(invalid_session_id); | 271 manager_->GetOpenedDeviceInfoById(invalid_session_id); |
| 273 DCHECK(!info); | 272 DCHECK(!info); |
| 274 | 273 |
| 275 manager_->Close(session_id); | 274 manager_->Close(session_id); |
| 276 EXPECT_CALL(*audio_input_listener_, | 275 EXPECT_CALL(*audio_input_listener_, |
| 277 Closed(MEDIA_DEVICE_AUDIO_CAPTURE, session_id)) | 276 Closed(MEDIA_DEVICE_AUDIO_CAPTURE, session_id)) |
| 278 .Times(1); | 277 .Times(1); |
| 279 base::RunLoop().RunUntilIdle(); | 278 base::RunLoop().RunUntilIdle(); |
| 280 } | 279 } |
| 281 | 280 |
| 282 } // namespace content | 281 } // namespace content |
| OLD | NEW |