Chromium Code Reviews| Index: media/video/capture/fake_video_capture_device_unittest.cc |
| diff --git a/media/video/capture/fake_video_capture_device_unittest.cc b/media/video/capture/fake_video_capture_device_unittest.cc |
| index 929f5ecddbf3e24984703c64587b32b8e9a915ff..e1e13db997a0313500313ce42112c65dccd58000 100644 |
| --- a/media/video/capture/fake_video_capture_device_unittest.cc |
| +++ b/media/video/capture/fake_video_capture_device_unittest.cc |
| @@ -15,6 +15,7 @@ |
| #include "testing/gtest/include/gtest/gtest.h" |
| using ::testing::_; |
| +using ::testing::SaveArg; |
| namespace media { |
| @@ -53,6 +54,20 @@ class MockClient : public media::VideoCaptureDevice::Client { |
| base::Callback<void(const VideoCaptureFormat&)> frame_cb_; |
| }; |
| +class DeviceEnumerationListener : |
| + public base::RefCounted<DeviceEnumerationListener>{ |
|
tommi (sloooow) - chröme
2014/05/30 12:37:51
space before {
mcasas
2014/05/30 14:08:50
Done.
|
| + public: |
| + MOCK_METHOD1(OnEnumeratedDevicesCallback, |
| + void(media::VideoCaptureDevice::Names& names)); |
| + |
| + void EnumeratedDevicesCallback(media::VideoCaptureDevice::Names& names) { |
|
tommi (sloooow) - chröme
2014/05/30 12:37:51
const
tommi (sloooow) - chröme
2014/05/30 12:37:51
why is this method needed? (add a comment?)
should
mcasas
2014/05/30 14:08:50
It isn't, so removed.
mcasas
2014/05/30 14:08:50
const& in the previous MOCK_METHOD.
|
| + OnEnumeratedDevicesCallback(names); |
| + } |
| + private: |
| + friend class base::RefCounted<DeviceEnumerationListener>; |
| + ~DeviceEnumerationListener() {} |
|
tommi (sloooow) - chröme
2014/05/30 12:37:51
virtual?
mcasas
2014/05/30 14:08:50
Done.
|
| +}; |
| + |
| class FakeVideoCaptureDeviceTest : public testing::Test { |
| protected: |
| typedef media::VideoCaptureDevice::Client Client; |
| @@ -62,7 +77,9 @@ class FakeVideoCaptureDeviceTest : public testing::Test { |
| client_(new MockClient( |
| base::Bind(&FakeVideoCaptureDeviceTest::OnFrameCaptured, |
| base::Unretained(this)))), |
| - video_capture_device_factory_(new FakeVideoCaptureDeviceFactory()) {} |
| + video_capture_device_factory_(new FakeVideoCaptureDeviceFactory()) { |
| + device_enumeration_listener_ = new DeviceEnumerationListener(); |
| + } |
| virtual void SetUp() { |
| } |
| @@ -77,12 +94,23 @@ class FakeVideoCaptureDeviceTest : public testing::Test { |
| run_loop_->Run(); |
| } |
| + void EnumerateDevices(VideoCaptureDevice::Names* device_names) { |
| + EXPECT_CALL(*device_enumeration_listener_, OnEnumeratedDevicesCallback(_)) |
| + .WillOnce(SaveArg<0>(device_names)); |
|
tommi (sloooow) - chröme
2014/05/30 12:37:51
indent
mcasas
2014/05/30 14:08:50
Done.
|
| + |
| + video_capture_device_factory_->EnumerateDeviceNames( |
| + base::Bind(&DeviceEnumerationListener::EnumeratedDevicesCallback, |
| + device_enumeration_listener_)); |
| + base::MessageLoop::current()->RunUntilIdle(); |
| + } |
| + |
| const VideoCaptureFormat& last_format() const { return last_format_; } |
| VideoCaptureDevice::Names names_; |
| scoped_ptr<base::MessageLoop> loop_; |
| scoped_ptr<base::RunLoop> run_loop_; |
| scoped_ptr<MockClient> client_; |
| + scoped_refptr<DeviceEnumerationListener> device_enumeration_listener_; |
| VideoCaptureFormat last_format_; |
| scoped_ptr<VideoCaptureDeviceFactory> video_capture_device_factory_; |
| }; |
| @@ -90,13 +118,12 @@ class FakeVideoCaptureDeviceTest : public testing::Test { |
| TEST_F(FakeVideoCaptureDeviceTest, Capture) { |
| VideoCaptureDevice::Names names; |
| - video_capture_device_factory_->GetDeviceNames(&names); |
| + EnumerateDevices(&names); |
| ASSERT_GT(static_cast<int>(names.size()), 0); |
| scoped_ptr<VideoCaptureDevice> device( |
| - video_capture_device_factory_->Create( |
| - base::MessageLoopProxy::current(), names.front())); |
| + video_capture_device_factory_->Create(names.front())); |
| ASSERT_TRUE(device); |
| EXPECT_CALL(*client_, OnErr()).Times(0); |
| @@ -116,7 +143,7 @@ TEST_F(FakeVideoCaptureDeviceTest, Capture) { |
| TEST_F(FakeVideoCaptureDeviceTest, GetDeviceSupportedFormats) { |
| VideoCaptureDevice::Names names; |
| - video_capture_device_factory_->GetDeviceNames(&names); |
| + EnumerateDevices(&names); |
| VideoCaptureFormats supported_formats; |
| VideoCaptureDevice::Names::iterator names_iterator; |
| @@ -144,7 +171,7 @@ TEST_F(FakeVideoCaptureDeviceTest, GetDeviceSupportedFormats) { |
| TEST_F(FakeVideoCaptureDeviceTest, CaptureVariableResolution) { |
| VideoCaptureDevice::Names names; |
| - video_capture_device_factory_->GetDeviceNames(&names); |
| + EnumerateDevices(&names); |
| VideoCaptureParams capture_params; |
| capture_params.requested_format.frame_size.SetSize(640, 480); |
| capture_params.requested_format.frame_rate = 30; |
| @@ -154,8 +181,7 @@ TEST_F(FakeVideoCaptureDeviceTest, CaptureVariableResolution) { |
| ASSERT_GT(static_cast<int>(names.size()), 0); |
| scoped_ptr<VideoCaptureDevice> device( |
| - video_capture_device_factory_->Create( |
| - base::MessageLoopProxy::current(), names.front())); |
| + video_capture_device_factory_->Create(names.front())); |
| ASSERT_TRUE(device); |
| // Configure the FakeVideoCaptureDevice to use all its formats as roster. |