Chromium Code Reviews| Index: media/video/capture/video_capture_device_unittest.cc |
| diff --git a/media/video/capture/video_capture_device_unittest.cc b/media/video/capture/video_capture_device_unittest.cc |
| index 1742b9fb51eea638ff43b4fc7faf3b6f93aba613..4023a503160c66b049e84c62f896f87a53b1b165 100644 |
| --- a/media/video/capture/video_capture_device_unittest.cc |
| +++ b/media/video/capture/video_capture_device_unittest.cc |
| @@ -128,6 +128,32 @@ class VideoCaptureDeviceTest : public testing::Test { |
| const VideoCaptureFormat& last_format() const { return last_format_; } |
| + scoped_ptr<VideoCaptureDevice::Name> GetFirstDeviceNameSupportingPixelFormat( |
| + const VideoPixelFormat& pixel_format) { |
| + VideoCaptureDevice::GetDeviceNames(&names_); |
| + if (!names_.size()) { |
| + DVLOG(1) << "No camera available."; |
| + return scoped_ptr<VideoCaptureDevice::Name>(); |
| + } |
| + VideoCaptureDevice::Names::iterator names_iterator; |
| + for (names_iterator = names_.begin(); names_iterator != names_.end(); |
| + ++names_iterator) { |
| + VideoCaptureFormats supported_formats; |
| + VideoCaptureDevice::GetDeviceSupportedFormats(*names_iterator, |
| + &supported_formats); |
| + VideoCaptureFormats::iterator formats_iterator; |
| + for (formats_iterator = supported_formats.begin(); |
| + formats_iterator != supported_formats.end(); ++formats_iterator) { |
| + if (formats_iterator->pixel_format == pixel_format) { |
| + return scoped_ptr<VideoCaptureDevice::Name>( |
| + new VideoCaptureDevice::Name(*names_iterator)); |
| + } |
| + } |
| + } |
| + DVLOG(1) << "No camera can capture the format: " << pixel_format; |
| + return scoped_ptr<VideoCaptureDevice::Name>(); |
| + } |
| + |
| #if defined(OS_WIN) |
| base::win::ScopedCOMInitializer initialize_com_; |
| #endif |
| @@ -332,13 +358,13 @@ TEST_F(VideoCaptureDeviceTest, FakeCapture) { |
| // Start the camera in 720p to capture MJPEG instead of a raw format. |
| TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { |
| - VideoCaptureDevice::GetDeviceNames(&names_); |
| - if (!names_.size()) { |
| - DVLOG(1) << "No camera available. Exiting test."; |
| + scoped_ptr<VideoCaptureDevice::Name> name = |
| + GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MJPEG); |
| + if (name.get() == NULL) { |
|
Ami GONE FROM CHROMIUM
2014/04/08 16:39:47
nit: FYI
if (name.get() == NULL) {
is equiv to the
yuli
2014/04/09 05:08:28
Done.
|
| + DVLOG(1) << "No camera supports MJPEG format. Exiting test."; |
| return; |
| } |
| - scoped_ptr<VideoCaptureDevice> device( |
| - VideoCaptureDevice::Create(names_.front())); |
| + scoped_ptr<VideoCaptureDevice> device(VideoCaptureDevice::Create(*name)); |
| ASSERT_TRUE(device.get() != NULL); |
| EXPECT_CALL(*client_, OnErr()) |
| @@ -359,19 +385,13 @@ TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { |
| } |
| TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) { |
| - VideoCaptureDevice::GetDeviceNames(&names_); |
| - if (!names_.size()) { |
| - DVLOG(1) << "No camera available. Exiting test."; |
| - return; |
| - } |
| - VideoCaptureFormats supported_formats; |
| - VideoCaptureDevice::Names::iterator names_iterator; |
| - for (names_iterator = names_.begin(); names_iterator != names_.end(); |
| - ++names_iterator) { |
| - VideoCaptureDevice::GetDeviceSupportedFormats(*names_iterator, |
| - &supported_formats); |
| - // Nothing to test here since we cannot forecast the hardware capabilities. |
| - } |
| + // Use PIXEL_FORMAT_MAX to iterate all device names for testing |
| + // GetDeviceSupportedFormats(). |
| + scoped_ptr<VideoCaptureDevice::Name> name = |
| + GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); |
| + // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here |
| + // since we cannot forecast the hardware capabilities. |
| + ASSERT_TRUE(name.get() == NULL); |
|
Ami GONE FROM CHROMIUM
2014/04/08 16:39:47
ditto ASSERT_FALSE(name);
yuli
2014/04/09 05:08:28
Done.
|
| } |
| TEST_F(VideoCaptureDeviceTest, FakeCaptureVariableResolution) { |