Chromium Code Reviews| Index: media/capture/video/fake_video_capture_device_unittest.cc |
| diff --git a/media/capture/video/fake_video_capture_device_unittest.cc b/media/capture/video/fake_video_capture_device_unittest.cc |
| index fd52e19b54e3d65aad3c5ffbfd241cde6a969948..8cc1c3cd15f1ddf49b237be50d37ad6685ae1bb1 100644 |
| --- a/media/capture/video/fake_video_capture_device_unittest.cc |
| +++ b/media/capture/video/fake_video_capture_device_unittest.cc |
| @@ -154,22 +154,6 @@ class MockClient : public VideoCaptureDevice::Client { |
| base::Callback<void(const VideoCaptureFormat&)> frame_cb_; |
| }; |
| -class DeviceEnumerationListener |
| - : public base::RefCounted<DeviceEnumerationListener> { |
| - public: |
| - MOCK_METHOD1(OnEnumeratedDevicesCallbackPtr, |
| - void(VideoCaptureDeviceDescriptors* descriptors)); |
| - // GMock doesn't support move-only arguments, so we use this forward method. |
| - void OnEnumeratedDevicesCallback( |
| - std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors) { |
| - OnEnumeratedDevicesCallbackPtr(descriptors.release()); |
| - } |
| - |
| - private: |
| - friend class base::RefCounted<DeviceEnumerationListener>; |
| - virtual ~DeviceEnumerationListener() {} |
| -}; |
| - |
| class ImageCaptureClient : public base::RefCounted<ImageCaptureClient> { |
| public: |
| // GMock doesn't support move-only arguments, so we use this forward method. |
| @@ -216,8 +200,8 @@ class FakeVideoCaptureDeviceBase : public ::testing::Test { |
| protected: |
| FakeVideoCaptureDeviceBase() |
| : loop_(new base::MessageLoop()), |
| + descriptors_(new VideoCaptureDeviceDescriptors()), |
| client_(CreateClient()), |
| - device_enumeration_listener_(new DeviceEnumerationListener()), |
| image_capture_client_(new ImageCaptureClient()), |
| video_capture_device_factory_(new FakeVideoCaptureDeviceFactory()) {} |
| @@ -238,26 +222,12 @@ class FakeVideoCaptureDeviceBase : public ::testing::Test { |
| run_loop_->Run(); |
| } |
| - std::unique_ptr<VideoCaptureDeviceDescriptors> EnumerateDevices() { |
| - VideoCaptureDeviceDescriptors* descriptors; |
| - EXPECT_CALL(*device_enumeration_listener_.get(), |
| - OnEnumeratedDevicesCallbackPtr(_)) |
| - .WillOnce(SaveArg<0>(&descriptors)); |
| - |
| - video_capture_device_factory_->EnumerateDeviceDescriptors( |
| - base::Bind(&DeviceEnumerationListener::OnEnumeratedDevicesCallback, |
| - device_enumeration_listener_)); |
| - base::RunLoop().RunUntilIdle(); |
| - return std::unique_ptr<VideoCaptureDeviceDescriptors>(descriptors); |
| - } |
| - |
| const VideoCaptureFormat& last_format() const { return last_format_; } |
| - VideoCaptureDeviceDescriptors descriptors_; |
| const std::unique_ptr<base::MessageLoop> loop_; |
| + std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors_; |
|
chfremer
2017/04/07 16:34:21
Does this need to be a std::unique_ptr<> or can we
Chandan
2017/04/10 09:18:24
VideoCaptureDeviceDescriptors descriptors_ was unu
|
| std::unique_ptr<base::RunLoop> run_loop_; |
| std::unique_ptr<MockClient> client_; |
| - const scoped_refptr<DeviceEnumerationListener> device_enumeration_listener_; |
| const scoped_refptr<ImageCaptureClient> image_capture_client_; |
| VideoCaptureFormat last_format_; |
| const std::unique_ptr<FakeVideoCaptureDeviceFactory> |
| @@ -281,9 +251,9 @@ TEST_P(FakeVideoCaptureDeviceTest, CaptureUsing) { |
| return; |
| } |
| - const std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( |
| - EnumerateDevices()); |
| - ASSERT_FALSE(descriptors->empty()); |
| + descriptors_->clear(); |
|
chfremer
2017/04/07 16:34:21
I believe that the gtest framework will create a n
Chandan
2017/04/10 09:18:24
Done.
|
| + video_capture_device_factory_->GetDeviceDescriptors(descriptors_.get()); |
| + ASSERT_FALSE(descriptors_->empty()); |
| std::unique_ptr<VideoCaptureDevice> device = |
| FakeVideoCaptureDeviceFactory::CreateDeviceWithDefaultResolutions( |
| @@ -330,16 +300,16 @@ INSTANTIATE_TEST_CASE_P( |
| Values(20, 29.97, 30, 50, 60))); |
| TEST_F(FakeVideoCaptureDeviceTest, GetDeviceSupportedFormats) { |
| + descriptors_->clear(); |
| video_capture_device_factory_->SetToDefaultDevicesConfig(4); |
| - std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( |
| - EnumerateDevices()); |
| - ASSERT_EQ(4u, descriptors->size()); |
| + video_capture_device_factory_->GetDeviceDescriptors(descriptors_.get()); |
| + ASSERT_EQ(4u, descriptors_->size()); |
| const VideoPixelFormat expected_format_by_device_index[] = { |
| PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, PIXEL_FORMAT_MJPEG, |
| PIXEL_FORMAT_I420}; |
| int device_index = 0; |
| - for (const auto& descriptors_iterator : *descriptors) { |
| + for (const auto& descriptors_iterator : *descriptors_) { |
| VideoCaptureFormats supported_formats; |
| video_capture_device_factory_->GetSupportedFormats(descriptors_iterator, |
| &supported_formats); |
| @@ -371,13 +341,14 @@ TEST_F(FakeVideoCaptureDeviceTest, GetDeviceSupportedFormats) { |
| } |
| TEST_F(FakeVideoCaptureDeviceTest, GetCameraCalibration) { |
| + descriptors_->clear(); |
| const size_t device_count = 2; |
| video_capture_device_factory_->SetToDefaultDevicesConfig(device_count); |
| - std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( |
| - EnumerateDevices()); |
| - ASSERT_EQ(device_count, descriptors->size()); |
| - ASSERT_FALSE(descriptors->at(0).camera_calibration); |
| - const VideoCaptureDeviceDescriptor& depth_device = descriptors->at(1); |
| + |
| + video_capture_device_factory_->GetDeviceDescriptors(descriptors_.get()); |
| + ASSERT_EQ(device_count, descriptors_->size()); |
| + ASSERT_FALSE(descriptors_->at(0).camera_calibration); |
| + const VideoCaptureDeviceDescriptor& depth_device = descriptors_->at(1); |
| EXPECT_EQ("/dev/video1", depth_device.device_id); |
| ASSERT_TRUE(depth_device.camera_calibration); |
| EXPECT_EQ(135.0, depth_device.camera_calibration->focal_length_x); |
| @@ -554,20 +525,21 @@ class FakeVideoCaptureDeviceFactoryTest |
| public ::testing::WithParamInterface<CommandLineTestData> {}; |
| TEST_F(FakeVideoCaptureDeviceFactoryTest, DeviceWithNoSupportedFormats) { |
| + descriptors_->clear(); |
| std::vector<FakeVideoCaptureDeviceSettings> config; |
| FakeVideoCaptureDeviceSettings device_setting; |
| device_setting.device_id = "Device with no supported formats"; |
| config.emplace_back(device_setting); |
| video_capture_device_factory_->SetToCustomDevicesConfig(config); |
| - const std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( |
| - EnumerateDevices()); |
| - EXPECT_EQ(1u, descriptors->size()); |
| + video_capture_device_factory_->GetDeviceDescriptors(descriptors_.get()); |
| + EXPECT_EQ(1u, descriptors_->size()); |
| media::VideoCaptureFormats supported_formats; |
| - video_capture_device_factory_->GetSupportedFormats(descriptors->at(0), |
| + video_capture_device_factory_->GetSupportedFormats(descriptors_->at(0), |
| &supported_formats); |
| EXPECT_EQ(0u, supported_formats.size()); |
| - auto device = video_capture_device_factory_->CreateDevice(descriptors->at(0)); |
| + auto device = |
| + video_capture_device_factory_->CreateDevice(descriptors_->at(0)); |
| EXPECT_TRUE(device.get()); |
| auto client = CreateClient(); |
| @@ -580,17 +552,17 @@ TEST_F(FakeVideoCaptureDeviceFactoryTest, DeviceWithNoSupportedFormats) { |
| // Tests that the FakeVideoCaptureDeviceFactory delivers the expected number |
| // of devices and formats when being configured using command-line switches. |
| TEST_P(FakeVideoCaptureDeviceFactoryTest, FrameRateAndDeviceCount) { |
| + descriptors_->clear(); |
| std::vector<FakeVideoCaptureDeviceSettings> config; |
| FakeVideoCaptureDeviceFactory::ParseFakeDevicesConfigFromOptionsString( |
| GetParam().switch_value_string, &config); |
| video_capture_device_factory_->SetToCustomDevicesConfig(config); |
| - const std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( |
| - EnumerateDevices()); |
| - EXPECT_EQ(GetParam().expected_device_count, descriptors->size()); |
| + video_capture_device_factory_->GetDeviceDescriptors(descriptors_.get()); |
| + EXPECT_EQ(GetParam().expected_device_count, descriptors_->size()); |
| int device_index = 0; |
| - for (const auto& descriptors_iterator : *descriptors) { |
| + for (const auto& descriptors_iterator : *descriptors_) { |
| media::VideoCaptureFormats supported_formats; |
| video_capture_device_factory_->GetSupportedFormats(descriptors_iterator, |
| &supported_formats); |