Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: services/video_capture/test/mock_device_test.cc

Issue 2818513003: [Mojo Video Capture] Adapt video_capture service to refactored video capture stack (Closed)
Patch Set: Fix compile errors Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "services/video_capture/test/mock_device_test.h" 5 #include "services/video_capture/test/mock_device_test.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "media/capture/video/video_capture_jpeg_decoder.h" 9 #include "media/capture/video/video_capture_jpeg_decoder.h"
10 #include "media/capture/video/video_capture_system_impl.h"
11
12 using testing::_;
13 using testing::Invoke;
14 using testing::InvokeWithoutArgs;
10 15
11 namespace { 16 namespace {
12 17
13 std::unique_ptr<media::VideoCaptureJpegDecoder> CreateJpegDecoder() { 18 std::unique_ptr<media::VideoCaptureJpegDecoder> CreateJpegDecoder() {
14 return nullptr; 19 return nullptr;
15 } 20 }
16 21
17 } // anonymous namespace 22 } // anonymous namespace
18 23
19 namespace video_capture { 24 namespace video_capture {
20 25
21 MockDevice::MockDevice() = default; 26 MockDevice::MockDevice() = default;
22 27
23 MockDevice::~MockDevice() = default; 28 MockDevice::~MockDevice() = default;
24 29
30 void MockDevice::SendStubFrame(const media::VideoCaptureFormat& format,
31 int rotation,
32 int frame_id) {
33 auto stub_frame = media::VideoFrame::CreateZeroInitializedFrame(
34 format.pixel_format, format.frame_size,
35 gfx::Rect(format.frame_size.width(), format.frame_size.height()),
36 format.frame_size, base::TimeDelta());
37 client_->OnIncomingCapturedData(
38 stub_frame->data(0),
39 static_cast<int>(media::VideoFrame::AllocationSize(
40 stub_frame->format(), stub_frame->coded_size())),
41 format, rotation, base::TimeTicks(), base::TimeDelta(), frame_id);
42 }
43
25 void MockDevice::AllocateAndStart(const media::VideoCaptureParams& params, 44 void MockDevice::AllocateAndStart(const media::VideoCaptureParams& params,
26 std::unique_ptr<Client> client) { 45 std::unique_ptr<Client> client) {
46 client_ = std::move(client);
27 DoAllocateAndStart(params, &client); 47 DoAllocateAndStart(params, &client);
28 } 48 }
29 49
50 void MockDevice::StopAndDeAllocate() {
51 DoStopAndDeAllocate();
52 client_.reset();
53 }
54
30 void MockDevice::GetPhotoCapabilities(GetPhotoCapabilitiesCallback callback) { 55 void MockDevice::GetPhotoCapabilities(GetPhotoCapabilitiesCallback callback) {
31 DoGetPhotoCapabilities(&callback); 56 DoGetPhotoCapabilities(&callback);
32 } 57 }
33 58
34 void MockDevice::SetPhotoOptions(media::mojom::PhotoSettingsPtr settings, 59 void MockDevice::SetPhotoOptions(media::mojom::PhotoSettingsPtr settings,
35 SetPhotoOptionsCallback callback) { 60 SetPhotoOptionsCallback callback) {
36 DoSetPhotoOptions(&settings, &callback); 61 DoSetPhotoOptions(&settings, &callback);
37 } 62 }
38 63
39 void MockDevice::TakePhoto(TakePhotoCallback callback) { 64 void MockDevice::TakePhoto(TakePhotoCallback callback) {
40 DoTakePhoto(&callback); 65 DoTakePhoto(&callback);
41 } 66 }
42 67
43 MockDeviceTest::MockDeviceTest() = default; 68 MockDeviceTest::MockDeviceTest() = default;
44 69
45 MockDeviceTest::~MockDeviceTest() = default; 70 MockDeviceTest::~MockDeviceTest() = default;
46 71
47 void MockDeviceTest::SetUp() { 72 void MockDeviceTest::SetUp() {
48 message_loop_ = base::MakeUnique<base::MessageLoop>(); 73 message_loop_ = base::MakeUnique<base::MessageLoop>();
49 auto mock_device_factory = base::MakeUnique<MockDeviceFactory>(); 74 auto mock_device_factory = base::MakeUnique<MockDeviceFactory>();
50 // We keep a pointer to the MockDeviceFactory as a member so that we can 75 // We keep a pointer to the MockDeviceFactory as a member so that we can
51 // invoke its AddMockDevice(). Ownership of the MockDeviceFactory is moved 76 // invoke its AddMockDevice(). Ownership of the MockDeviceFactory is moved
52 // to the DeviceFactoryMediaToMojoAdapter. 77 // to the DeviceFactoryMediaToMojoAdapter.
53 mock_device_factory_ = mock_device_factory.get(); 78 mock_device_factory_ = mock_device_factory.get();
79 auto video_capture_system = base::MakeUnique<media::VideoCaptureSystemImpl>(
80 std::move(mock_device_factory));
54 mock_device_factory_adapter_ = 81 mock_device_factory_adapter_ =
55 base::MakeUnique<DeviceFactoryMediaToMojoAdapter>( 82 base::MakeUnique<DeviceFactoryMediaToMojoAdapter>(
56 std::move(mock_device_factory), base::Bind(CreateJpegDecoder)); 83 std::move(video_capture_system), base::Bind(CreateJpegDecoder));
57 84
58 mock_factory_binding_ = base::MakeUnique<mojo::Binding<mojom::DeviceFactory>>( 85 mock_factory_binding_ = base::MakeUnique<mojo::Binding<mojom::DeviceFactory>>(
59 mock_device_factory_adapter_.get(), mojo::MakeRequest(&factory_)); 86 mock_device_factory_adapter_.get(), mojo::MakeRequest(&factory_));
60 87
61 media::VideoCaptureDeviceDescriptor mock_descriptor; 88 media::VideoCaptureDeviceDescriptor mock_descriptor;
62 mock_descriptor.device_id = "MockDeviceId"; 89 mock_descriptor.device_id = "MockDeviceId";
63 mock_device_factory_->AddMockDevice(&mock_device_, mock_descriptor); 90 mock_device_factory_->AddMockDevice(&mock_device_, mock_descriptor);
64 91
65 // Obtain the mock device from the factory 92 // Obtain the mock device from the factory
93 base::RunLoop wait_loop;
94 EXPECT_CALL(device_infos_receiver_, Run(_))
95 .WillOnce(InvokeWithoutArgs([&wait_loop]() { wait_loop.Quit(); }));
96 factory_->GetDeviceInfos(device_infos_receiver_.Get());
97 // We must wait for the response to GetDeviceInfos before calling
98 // CreateDevice.
99 wait_loop.Run();
66 factory_->CreateDevice( 100 factory_->CreateDevice(
67 mock_descriptor.device_id, mojo::MakeRequest(&device_proxy_), 101 mock_descriptor.device_id, mojo::MakeRequest(&device_proxy_),
68 base::Bind([](mojom::DeviceAccessResultCode result_code) {})); 102 base::Bind([](mojom::DeviceAccessResultCode result_code) {}));
69 103
70 requested_settings_.requested_format.frame_size = gfx::Size(800, 600); 104 requested_settings_.requested_format.frame_size = gfx::Size(800, 600);
71 requested_settings_.requested_format.frame_rate = 15; 105 requested_settings_.requested_format.frame_rate = 15;
72 requested_settings_.resolution_change_policy = 106 requested_settings_.resolution_change_policy =
73 media::RESOLUTION_POLICY_FIXED_RESOLUTION; 107 media::RESOLUTION_POLICY_FIXED_RESOLUTION;
74 requested_settings_.power_line_frequency = 108 requested_settings_.power_line_frequency =
75 media::PowerLineFrequency::FREQUENCY_DEFAULT; 109 media::PowerLineFrequency::FREQUENCY_DEFAULT;
76 110
77 mock_receiver_ = 111 mock_receiver_ =
78 base::MakeUnique<MockReceiver>(mojo::MakeRequest(&mock_receiver_proxy_)); 112 base::MakeUnique<MockReceiver>(mojo::MakeRequest(&mock_receiver_proxy_));
79 } 113 }
80 114
81 } // namespace video_capture 115 } // namespace video_capture
OLDNEW
« no previous file with comments | « services/video_capture/test/mock_device_test.h ('k') | services/video_capture/test/mock_device_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698