Index: services/video_capture/test/mock_device_test.cc |
diff --git a/services/video_capture/test/mock_device_test.cc b/services/video_capture/test/mock_device_test.cc |
index 9b976347c8012c0a736465a0d8039fd5ffa4adeb..8b526503c50fd0013ab4bbf547fdf63bc6741a8d 100644 |
--- a/services/video_capture/test/mock_device_test.cc |
+++ b/services/video_capture/test/mock_device_test.cc |
@@ -7,6 +7,11 @@ |
#include "base/memory/ptr_util.h" |
#include "base/run_loop.h" |
#include "media/capture/video/video_capture_jpeg_decoder.h" |
+#include "media/capture/video/video_capture_system_impl.h" |
+ |
+using testing::_; |
+using testing::Invoke; |
+using testing::InvokeWithoutArgs; |
namespace { |
@@ -22,11 +27,31 @@ MockDevice::MockDevice() = default; |
MockDevice::~MockDevice() = default; |
+void MockDevice::SendStubFrame(const media::VideoCaptureFormat& format, |
+ int rotation, |
+ int frame_id) { |
+ auto stub_frame = media::VideoFrame::CreateZeroInitializedFrame( |
+ format.pixel_format, format.frame_size, |
+ gfx::Rect(format.frame_size.width(), format.frame_size.height()), |
+ format.frame_size, base::TimeDelta()); |
+ client_->OnIncomingCapturedData( |
+ stub_frame->data(0), |
+ static_cast<int>(media::VideoFrame::AllocationSize( |
+ stub_frame->format(), stub_frame->coded_size())), |
+ format, rotation, base::TimeTicks(), base::TimeDelta(), frame_id); |
+} |
+ |
void MockDevice::AllocateAndStart(const media::VideoCaptureParams& params, |
std::unique_ptr<Client> client) { |
+ client_ = std::move(client); |
DoAllocateAndStart(params, &client); |
} |
+void MockDevice::StopAndDeAllocate() { |
+ DoStopAndDeAllocate(); |
+ client_.reset(); |
+} |
+ |
void MockDevice::GetPhotoCapabilities(GetPhotoCapabilitiesCallback callback) { |
DoGetPhotoCapabilities(&callback); |
} |
@@ -51,9 +76,11 @@ void MockDeviceTest::SetUp() { |
// invoke its AddMockDevice(). Ownership of the MockDeviceFactory is moved |
// to the DeviceFactoryMediaToMojoAdapter. |
mock_device_factory_ = mock_device_factory.get(); |
+ auto video_capture_system = base::MakeUnique<media::VideoCaptureSystemImpl>( |
+ std::move(mock_device_factory)); |
mock_device_factory_adapter_ = |
base::MakeUnique<DeviceFactoryMediaToMojoAdapter>( |
- std::move(mock_device_factory), base::Bind(CreateJpegDecoder)); |
+ std::move(video_capture_system), base::Bind(CreateJpegDecoder)); |
mock_factory_binding_ = base::MakeUnique<mojo::Binding<mojom::DeviceFactory>>( |
mock_device_factory_adapter_.get(), mojo::MakeRequest(&factory_)); |
@@ -63,6 +90,13 @@ void MockDeviceTest::SetUp() { |
mock_device_factory_->AddMockDevice(&mock_device_, mock_descriptor); |
// Obtain the mock device from the factory |
+ base::RunLoop wait_loop; |
+ EXPECT_CALL(device_infos_receiver_, Run(_)) |
+ .WillOnce(InvokeWithoutArgs([&wait_loop]() { wait_loop.Quit(); })); |
+ factory_->GetDeviceInfos(device_infos_receiver_.Get()); |
+ // We must wait for the response to GetDeviceInfos before calling |
+ // CreateDevice. |
+ wait_loop.Run(); |
factory_->CreateDevice( |
mock_descriptor.device_id, mojo::MakeRequest(&device_proxy_), |
base::Bind([](mojom::DeviceAccessResultCode result_code) {})); |