Chromium Code Reviews| 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 // Unit test for VideoCaptureManager. | 5 // Unit test for VideoCaptureManager. |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "content/browser/browser_thread_impl.h" | 14 #include "content/browser/browser_thread_impl.h" |
| 15 #include "content/browser/renderer_host/media/media_stream_provider.h" | 15 #include "content/browser/renderer_host/media/media_stream_provider.h" |
| 16 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" | 16 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" |
| 17 #include "content/browser/renderer_host/media/video_capture_manager.h" | 17 #include "content/browser/renderer_host/media/video_capture_manager.h" |
| 18 #include "content/common/media/media_stream_options.h" | 18 #include "content/common/media/media_stream_options.h" |
| 19 #include "media/video/capture/fake_video_capture_device.h" | |
| 19 #include "media/video/capture/video_capture_device.h" | 20 #include "media/video/capture/video_capture_device.h" |
| 20 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 23 |
| 23 using ::testing::_; | 24 using ::testing::_; |
| 24 using ::testing::AnyNumber; | 25 using ::testing::AnyNumber; |
| 25 using ::testing::InSequence; | 26 using ::testing::InSequence; |
| 26 using ::testing::Return; | 27 using ::testing::Return; |
| 27 using ::testing::SaveArg; | 28 using ::testing::SaveArg; |
| 28 | 29 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 message_loop_->RunUntilIdle(); | 166 message_loop_->RunUntilIdle(); |
| 166 vcm_->Unregister(); | 167 vcm_->Unregister(); |
| 167 } | 168 } |
| 168 | 169 |
| 169 // Open the same device twice. | 170 // Open the same device twice. |
| 170 TEST_F(VideoCaptureManagerTest, OpenTwice) { | 171 TEST_F(VideoCaptureManagerTest, OpenTwice) { |
| 171 StreamDeviceInfoArray devices; | 172 StreamDeviceInfoArray devices; |
| 172 | 173 |
| 173 InSequence s; | 174 InSequence s; |
| 174 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | 175 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
| 175 .Times(1).WillOnce(SaveArg<1>(&devices)); | 176 .Times(1) |
| 177 .WillOnce(SaveArg<1>(&devices)); | |
| 176 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 178 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
| 177 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 179 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
| 178 | 180 |
| 179 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | 181 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
| 180 | 182 |
| 181 // Wait to get device callback. | 183 // Wait to get device callback. |
| 182 message_loop_->RunUntilIdle(); | 184 message_loop_->RunUntilIdle(); |
| 183 | 185 |
| 184 int video_session_id_first = vcm_->Open(devices.front()); | 186 int video_session_id_first = vcm_->Open(devices.front()); |
| 185 | 187 |
| 186 // This should trigger an error callback with error code | 188 // This should trigger an error callback with error code |
| 187 // 'kDeviceAlreadyInUse'. | 189 // 'kDeviceAlreadyInUse'. |
| 188 int video_session_id_second = vcm_->Open(devices.front()); | 190 int video_session_id_second = vcm_->Open(devices.front()); |
| 189 EXPECT_NE(video_session_id_first, video_session_id_second); | 191 EXPECT_NE(video_session_id_first, video_session_id_second); |
| 190 | 192 |
| 191 vcm_->Close(video_session_id_first); | 193 vcm_->Close(video_session_id_first); |
| 192 vcm_->Close(video_session_id_second); | 194 vcm_->Close(video_session_id_second); |
| 193 | 195 |
| 194 // Wait to check callbacks before removing the listener. | 196 // Wait to check callbacks before removing the listener. |
| 195 message_loop_->RunUntilIdle(); | 197 message_loop_->RunUntilIdle(); |
| 196 vcm_->Unregister(); | 198 vcm_->Unregister(); |
| 197 } | 199 } |
| 198 | 200 |
| 201 // Connect and disconnect devices. | |
| 202 TEST_F(VideoCaptureManagerTest, ConnectAndDisconnectDevices) { | |
| 203 StreamDeviceInfoArray devices; | |
| 204 int number_of_devices_keep = | |
| 205 media::FakeVideoCaptureDevice::NumberOfFakeDevices(); | |
| 206 | |
| 207 InSequence s; | |
| 208 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | |
| 209 .Times(1) | |
| 210 .WillOnce(SaveArg<1>(&devices)); | |
| 211 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | |
| 212 message_loop_->RunUntilIdle(); | |
| 213 ASSERT_EQ(devices.size(), 2u); | |
| 214 | |
| 215 // Simulate we remove 1 fake device. | |
| 216 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(1); | |
| 217 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | |
| 218 .Times(1) | |
| 219 .WillOnce(SaveArg<1>(&devices)); | |
| 220 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | |
| 221 message_loop_->RunUntilIdle(); | |
| 222 ASSERT_EQ(devices.size(), 1u); | |
| 223 | |
| 224 // Simulate we add 2 fake devices. | |
| 225 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(3); | |
| 226 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | |
| 227 .Times(1) | |
| 228 .WillOnce(SaveArg<1>(&devices)); | |
| 229 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | |
| 230 message_loop_->RunUntilIdle(); | |
| 231 ASSERT_EQ(devices.size(), 3u); | |
| 232 | |
| 233 vcm_->Unregister(); | |
| 234 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(number_of_devices_keep); | |
| 235 } | |
| 236 | |
| 237 // Enumerate devices and open the first, then check the list of supported | |
| 238 // formats. Then start the opened device. The capability list should be reduced | |
| 239 // to just one format, and this should be the one used when configuring-starting | |
| 240 // the device. Finally stop the device and check that the capabilities have been | |
| 241 // restored. | |
| 242 | |
| 243 // Possibly | |
| 244 #if defined(OS_MACOSX) | |
| 245 // Underlying FakeVCD hits a SIGSEGV at the end of this test in Mac Valgrind | |
| 246 // bot, see http://crbug.com/319955. Possibly associated to FakeVCD races, | |
| 247 // re-enable this test after http://crbug.com/323893. | |
| 248 TEST_F(VideoCaptureManagerTest, DISABLED_ManipulateDeviceAndCheckCapabilities) { | |
| 249 #else | |
| 250 TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) { | |
|
perkj_chrome
2013/11/27 17:53:12
Right- But as I said- the same code is used on all
mcasas
2013/12/03 14:28:41
We'll review that first then.
| |
| 251 #endif | |
| 252 StreamDeviceInfoArray devices; | |
| 253 | |
| 254 InSequence s; | |
| 255 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | |
| 256 .Times(1) | |
| 257 .WillOnce(SaveArg<1>(&devices)); | |
| 258 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | |
| 259 message_loop_->RunUntilIdle(); | |
| 260 | |
| 261 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(1); | |
| 262 int video_session_id = vcm_->Open(devices.front()); | |
| 263 message_loop_->RunUntilIdle(); | |
| 264 | |
| 265 // When the device has been opened, we should see all the devices' | |
| 266 // supported formats. | |
| 267 media::VideoCaptureFormats supported_formats; | |
| 268 vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats); | |
| 269 ASSERT_EQ(devices.size(), 2u); | |
| 270 ASSERT_GT(supported_formats.size(), 1u); | |
| 271 EXPECT_GT(supported_formats[0].frame_size.width(), 1); | |
| 272 EXPECT_GT(supported_formats[0].frame_size.height(), 1); | |
| 273 EXPECT_GT(supported_formats[0].frame_rate, 1); | |
| 274 EXPECT_GT(supported_formats[1].frame_size.width(), 1); | |
| 275 EXPECT_GT(supported_formats[1].frame_size.height(), 1); | |
| 276 EXPECT_GT(supported_formats[1].frame_rate, 1); | |
| 277 | |
| 278 VideoCaptureControllerID client_id = StartClient(video_session_id, true); | |
| 279 message_loop_->RunUntilIdle(); | |
| 280 // After StartClient(), device's supported formats should be reduced to one. | |
| 281 vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats); | |
| 282 ASSERT_EQ(supported_formats.size(), 1u); | |
| 283 EXPECT_GT(supported_formats[0].frame_size.width(), 1); | |
| 284 EXPECT_GT(supported_formats[0].frame_size.height(), 1); | |
| 285 EXPECT_GT(supported_formats[0].frame_rate, 1); | |
| 286 | |
| 287 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(1); | |
| 288 StopClient(client_id); | |
| 289 // After StopClient(), the device's list of supported formats should be | |
| 290 // restored to the original one. | |
| 291 vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats); | |
| 292 ASSERT_GT(supported_formats.size(), 1u); | |
| 293 EXPECT_GT(supported_formats[0].frame_size.width(), 1); | |
| 294 EXPECT_GT(supported_formats[0].frame_size.height(), 1); | |
| 295 EXPECT_GT(supported_formats[0].frame_rate, 1); | |
| 296 EXPECT_GT(supported_formats[1].frame_size.width(), 1); | |
| 297 EXPECT_GT(supported_formats[1].frame_size.height(), 1); | |
| 298 EXPECT_GT(supported_formats[1].frame_rate, 1); | |
| 299 | |
| 300 vcm_->Close(video_session_id); | |
| 301 message_loop_->RunUntilIdle(); | |
| 302 vcm_->Unregister(); | |
| 303 } | |
| 304 | |
| 199 // Open two different devices. | 305 // Open two different devices. |
| 200 TEST_F(VideoCaptureManagerTest, OpenTwo) { | 306 TEST_F(VideoCaptureManagerTest, OpenTwo) { |
| 201 StreamDeviceInfoArray devices; | 307 StreamDeviceInfoArray devices; |
| 202 | 308 |
| 203 InSequence s; | 309 InSequence s; |
| 204 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | 310 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
| 205 .Times(1).WillOnce(SaveArg<1>(&devices)); | 311 .Times(1).WillOnce(SaveArg<1>(&devices)); |
| 206 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 312 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
| 207 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 313 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
| 208 | 314 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 // VideoCaptureManager destructor otherwise. | 396 // VideoCaptureManager destructor otherwise. |
| 291 vcm_->Close(video_session_id); | 397 vcm_->Close(video_session_id); |
| 292 StopClient(client_id); | 398 StopClient(client_id); |
| 293 | 399 |
| 294 // Wait to check callbacks before removing the listener | 400 // Wait to check callbacks before removing the listener |
| 295 message_loop_->RunUntilIdle(); | 401 message_loop_->RunUntilIdle(); |
| 296 vcm_->Unregister(); | 402 vcm_->Unregister(); |
| 297 } | 403 } |
| 298 | 404 |
| 299 } // namespace content | 405 } // namespace content |
| OLD | NEW |