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 c3e2876252312169d1b28736f7702f341fd8c46b..f037843df5c807d9b662f6c5726cf463247a426a 100644 |
| --- a/media/capture/video/fake_video_capture_device_unittest.cc |
| +++ b/media/capture/video/fake_video_capture_device_unittest.cc |
| @@ -177,15 +177,20 @@ class FakeVideoCaptureDeviceBase : public ::testing::Test { |
| protected: |
| FakeVideoCaptureDeviceBase() |
| : loop_(new base::MessageLoop()), |
| - client_(new MockClient( |
| - base::Bind(&FakeVideoCaptureDeviceBase::OnFrameCaptured, |
| - base::Unretained(this)))), |
| + client_(CreateClient()), |
| device_enumeration_listener_(new DeviceEnumerationListener()), |
| image_capture_client_(new ImageCaptureClient()), |
| video_capture_device_factory_(new FakeVideoCaptureDeviceFactory()) {} |
| void SetUp() override { EXPECT_CALL(*client_, OnError(_, _)).Times(0); } |
| + std::unique_ptr<MockClient> CreateClient() { |
| + std::unique_ptr<MockClient> client = std::unique_ptr<MockClient>( |
| + new MockClient(base::Bind(&FakeVideoCaptureDeviceBase::OnFrameCaptured, |
| + base::Unretained(this)))); |
| + return client; |
|
mcasas
2016/10/25 22:13:13
Suggestion:
return base::MakeUnique<MockClien
aleksandar.stojiljkovic
2016/10/25 23:20:40
Done.
|
| + } |
| + |
| void OnFrameCaptured(const VideoCaptureFormat& format) { |
| last_format_ = format; |
| run_loop_->QuitClosure().Run(); |
| @@ -232,6 +237,7 @@ struct CommandLineTestData { |
| std::string argument; |
| // Expected values |
| float fps; |
| + size_t device_count; |
| }; |
| class FakeVideoCaptureDeviceCommandLineTest |
| @@ -267,30 +273,40 @@ INSTANTIATE_TEST_CASE_P( |
| Values(20, 29.97, 30, 50, 60))); |
| TEST_F(FakeVideoCaptureDeviceTest, GetDeviceSupportedFormats) { |
| + base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| + switches::kUseFakeDeviceForMediaStream, "device-count=3"); |
| std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( |
| EnumerateDevices()); |
| + ASSERT_EQ(descriptors->size(), 3u); |
|
mcasas
2016/10/25 22:13:12
ASSERT_EQ(expected, actual), so here:
ASSERT_EQ(3u
aleksandar.stojiljkovic
2016/10/25 23:20:40
Done.
I did it only in this method - will do the r
|
| for (const auto& descriptors_iterator : *descriptors) { |
| VideoCaptureFormats supported_formats; |
| video_capture_device_factory_->GetSupportedFormats(descriptors_iterator, |
| &supported_formats); |
| - ASSERT_EQ(supported_formats.size(), 4u); |
| - EXPECT_EQ(supported_formats[0].frame_size.width(), 320); |
| - EXPECT_EQ(supported_formats[0].frame_size.height(), 240); |
| - EXPECT_EQ(supported_formats[0].pixel_format, PIXEL_FORMAT_I420); |
| + ASSERT_EQ(supported_formats.size(), 5u); |
| + const std::string device_id = descriptors_iterator.device_id; |
| + VideoPixelFormat expected_format = |
| + (device_id == "/dev/video1") ? PIXEL_FORMAT_Y16 : PIXEL_FORMAT_I420; |
| + EXPECT_EQ(supported_formats[0].frame_size.width(), 96); |
| + EXPECT_EQ(supported_formats[0].frame_size.height(), 96); |
| + EXPECT_EQ(supported_formats[0].pixel_format, expected_format); |
| EXPECT_GE(supported_formats[0].frame_rate, 20.0); |
| - EXPECT_EQ(supported_formats[1].frame_size.width(), 640); |
| - EXPECT_EQ(supported_formats[1].frame_size.height(), 480); |
| - EXPECT_EQ(supported_formats[1].pixel_format, PIXEL_FORMAT_I420); |
| + EXPECT_EQ(supported_formats[1].frame_size.width(), 320); |
| + EXPECT_EQ(supported_formats[1].frame_size.height(), 240); |
| + EXPECT_EQ(supported_formats[1].pixel_format, expected_format); |
| EXPECT_GE(supported_formats[1].frame_rate, 20.0); |
| - EXPECT_EQ(supported_formats[2].frame_size.width(), 1280); |
| - EXPECT_EQ(supported_formats[2].frame_size.height(), 720); |
| - EXPECT_EQ(supported_formats[2].pixel_format, PIXEL_FORMAT_I420); |
| + EXPECT_EQ(supported_formats[2].frame_size.width(), 640); |
| + EXPECT_EQ(supported_formats[2].frame_size.height(), 480); |
| + EXPECT_EQ(supported_formats[2].pixel_format, expected_format); |
| EXPECT_GE(supported_formats[2].frame_rate, 20.0); |
| - EXPECT_EQ(supported_formats[3].frame_size.width(), 1920); |
| - EXPECT_EQ(supported_formats[3].frame_size.height(), 1080); |
| - EXPECT_EQ(supported_formats[3].pixel_format, PIXEL_FORMAT_I420); |
| + EXPECT_EQ(supported_formats[3].frame_size.width(), 1280); |
| + EXPECT_EQ(supported_formats[3].frame_size.height(), 720); |
| + EXPECT_EQ(supported_formats[3].pixel_format, expected_format); |
| EXPECT_GE(supported_formats[3].frame_rate, 20.0); |
| + EXPECT_EQ(supported_formats[4].frame_size.width(), 1920); |
| + EXPECT_EQ(supported_formats[4].frame_size.height(), 1080); |
| + EXPECT_EQ(supported_formats[4].pixel_format, expected_format); |
| + EXPECT_GE(supported_formats[4].frame_rate, 20.0); |
| } |
| } |
| @@ -426,11 +442,12 @@ TEST_F(FakeVideoCaptureDeviceTest, TakePhoto) { |
| device->StopAndDeAllocate(); |
| } |
| -TEST_P(FakeVideoCaptureDeviceCommandLineTest, FrameRate) { |
| +TEST_P(FakeVideoCaptureDeviceCommandLineTest, FrameRateAndDeviceCount) { |
| base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| switches::kUseFakeDeviceForMediaStream, GetParam().argument); |
| const std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( |
| EnumerateDevices()); |
| + EXPECT_EQ(descriptors->size(), GetParam().device_count); |
| ASSERT_FALSE(descriptors->empty()); |
| for (const auto& descriptors_iterator : *descriptors) { |
| @@ -441,8 +458,7 @@ TEST_P(FakeVideoCaptureDeviceCommandLineTest, FrameRate) { |
| VideoCaptureParams capture_params; |
| capture_params.requested_format.frame_size.SetSize(1280, 720); |
| capture_params.requested_format.frame_rate = GetParam().fps; |
| - device->AllocateAndStart(capture_params, std::move(client_)); |
| - |
| + device->AllocateAndStart(capture_params, CreateClient()); |
| WaitForCapturedFrame(); |
| EXPECT_EQ(last_format().frame_size.width(), 1280); |
| EXPECT_EQ(last_format().frame_size.height(), 720); |
| @@ -451,10 +467,13 @@ TEST_P(FakeVideoCaptureDeviceCommandLineTest, FrameRate) { |
| } |
| } |
| -INSTANTIATE_TEST_CASE_P(, |
| - FakeVideoCaptureDeviceCommandLineTest, |
| - Values(CommandLineTestData{"fps=-1", 5}, |
| - CommandLineTestData{"fps=29.97", 29.97f}, |
| - CommandLineTestData{"fps=60", 60}, |
| - CommandLineTestData{"fps=1000", 60})); |
| +INSTANTIATE_TEST_CASE_P( |
| + , |
| + FakeVideoCaptureDeviceCommandLineTest, |
| + Values(CommandLineTestData{"fps=-1", 5, 1u}, |
| + CommandLineTestData{"fps=29.97, device-count=1", 29.97f, 1u}, |
| + CommandLineTestData{"fps=60, device-count=2", 60, 2u}, |
| + CommandLineTestData{"fps=1000, device-count=-1", 60, 1u}, |
| + CommandLineTestData{"device-count=2", 20, 2u}, |
| + CommandLineTestData{"device-count=0", 20, 1u})); |
| }; // namespace media |