Index: content/browser/renderer_host/media/video_capture_manager_unittest.cc |
diff --git a/content/browser/renderer_host/media/video_capture_manager_unittest.cc b/content/browser/renderer_host/media/video_capture_manager_unittest.cc |
index e4d3bb227d5770495d3d3a5877fc8df9c196f884..6dcc5bc576f459029d5fa0f45343f031c1046000 100644 |
--- a/content/browser/renderer_host/media/video_capture_manager_unittest.cc |
+++ b/content/browser/renderer_host/media/video_capture_manager_unittest.cc |
@@ -16,6 +16,7 @@ |
#include "content/browser/renderer_host/media/video_capture_controller_event_handler.h" |
#include "content/browser/renderer_host/media/video_capture_manager.h" |
#include "content/common/media/media_stream_options.h" |
+#include "media/video/capture/fake_video_capture_device.h" |
#include "media/video/capture/video_capture_device.h" |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -196,6 +197,101 @@ TEST_F(VideoCaptureManagerTest, OpenTwice) { |
vcm_->Unregister(); |
} |
+// Connect and disconnect devices. |
+TEST_F(VideoCaptureManagerTest, ConnectAndDisconnectDevices) { |
+ StreamDeviceInfoArray devices; |
+ int number_of_devices_keep = |
+ media::FakeVideoCaptureDevice::NumberOfFakeDevices(); |
+ |
+ InSequence s; |
+ EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
+ .Times(1).WillOnce(SaveArg<1>(&devices)); |
+ vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
+ message_loop_->RunUntilIdle(); |
+ ASSERT_EQ(devices.size(), 2u); |
+ |
+ // Simulate we remove 1 fake device. |
+ media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(1); |
+ EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
+ .Times(1).WillOnce(SaveArg<1>(&devices)); |
+ vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
+ message_loop_->RunUntilIdle(); |
+ ASSERT_EQ(devices.size(), 1u); |
+ |
+ // Simulate we add 2 fake devices. |
+ media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(3); |
+ EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
+ .Times(1).WillOnce(SaveArg<1>(&devices)); |
+ vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
+ message_loop_->RunUntilIdle(); |
+ ASSERT_EQ(devices.size(), 3u); |
+ |
+ vcm_->Unregister(); |
+ media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(number_of_devices_keep); |
+} |
+ |
+// Enumerate devices and open the first, then check the list of supported |
+// formats. Then start the opened device. The capability list should be reduced |
+// to just one format, and this should be the one used when configuring-starting |
+// the device. Finally stop the device and check that the capabilities have been |
+// restored. |
+// |
+// Underlying FakeVCD hits a SIGSEGV at the end of this test in Mac Valgrind |
+// bot, see http://crbug.com/319955. Possibly associated to FakeVCD races, |
+// check this test after http://crbug.com/323893. |
perkj_chrome
2013/12/10 12:27:14
looks like this is fixed. Remove the comments and
mcasas
2013/12/12 10:38:05
Done.
|
+TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) { |
+ StreamDeviceInfoArray devices; |
+ |
+ InSequence s; |
+ EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
+ .Times(1).WillOnce(SaveArg<1>(&devices)); |
+ vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
+ message_loop_->RunUntilIdle(); |
+ |
+ EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(1); |
+ int video_session_id = vcm_->Open(devices.front()); |
+ message_loop_->RunUntilIdle(); |
+ |
+ // When the device has been opened, we should see all the devices' |
+ // supported formats. |
+ media::VideoCaptureFormats supported_formats; |
+ vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats); |
+ ASSERT_EQ(devices.size(), 2u); |
+ ASSERT_GT(supported_formats.size(), 1u); |
+ EXPECT_GT(supported_formats[0].frame_size.width(), 1); |
+ EXPECT_GT(supported_formats[0].frame_size.height(), 1); |
+ EXPECT_GT(supported_formats[0].frame_rate, 1); |
+ EXPECT_GT(supported_formats[1].frame_size.width(), 1); |
+ EXPECT_GT(supported_formats[1].frame_size.height(), 1); |
+ EXPECT_GT(supported_formats[1].frame_rate, 1); |
+ |
+ VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
+ message_loop_->RunUntilIdle(); |
+ // After StartClient(), device's supported formats should be reduced to one. |
+ vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats); |
+ ASSERT_EQ(supported_formats.size(), 1u); |
perkj_chrome
2013/12/10 12:27:14
nit: This can be EXPECT_EQ
mcasas
2013/12/12 10:38:05
I prefer the test to fail and not continue if the
|
+ EXPECT_GT(supported_formats[0].frame_size.width(), 1); |
+ EXPECT_GT(supported_formats[0].frame_size.height(), 1); |
+ EXPECT_GT(supported_formats[0].frame_rate, 1); |
+ |
+ EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(1); |
+ StopClient(client_id); |
+ // After StopClient(), the device's list of supported formats should be |
+ // restored to the original one. |
+ vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats); |
+ ASSERT_GT(supported_formats.size(), 1u); |
+ EXPECT_GT(supported_formats[0].frame_size.width(), 1); |
+ EXPECT_GT(supported_formats[0].frame_size.height(), 1); |
+ EXPECT_GT(supported_formats[0].frame_rate, 1); |
+ EXPECT_GT(supported_formats[1].frame_size.width(), 1); |
+ EXPECT_GT(supported_formats[1].frame_size.height(), 1); |
+ EXPECT_GT(supported_formats[1].frame_rate, 1); |
+ |
+ vcm_->Close(video_session_id); |
+ message_loop_->RunUntilIdle(); |
+ vcm_->Unregister(); |
+} |
+ |
// Open two different devices. |
TEST_F(VideoCaptureManagerTest, OpenTwo) { |
StreamDeviceInfoArray devices; |