OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "media/capture/video/fake_video_capture_device.h" | 5 #include "media/capture/video/fake_video_capture_device.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 17 #include "base/test/scoped_task_environment.h" |
17 #include "base/test/test_timeouts.h" | 18 #include "base/test/test_timeouts.h" |
18 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
19 #include "build/build_config.h" | 20 #include "build/build_config.h" |
20 #include "media/base/media_switches.h" | 21 #include "media/base/media_switches.h" |
21 #include "media/capture/video/fake_video_capture_device_factory.h" | 22 #include "media/capture/video/fake_video_capture_device_factory.h" |
22 #include "media/capture/video/video_capture_device.h" | 23 #include "media/capture/video/video_capture_device.h" |
23 #include "media/capture/video_capture_types.h" | 24 #include "media/capture/video_capture_types.h" |
24 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
26 | 27 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 virtual ~ImageCaptureClient() {} | 193 virtual ~ImageCaptureClient() {} |
193 | 194 |
194 mojom::PhotoCapabilitiesPtr capabilities_; | 195 mojom::PhotoCapabilitiesPtr capabilities_; |
195 }; | 196 }; |
196 | 197 |
197 } // namespace | 198 } // namespace |
198 | 199 |
199 class FakeVideoCaptureDeviceBase : public ::testing::Test { | 200 class FakeVideoCaptureDeviceBase : public ::testing::Test { |
200 protected: | 201 protected: |
201 FakeVideoCaptureDeviceBase() | 202 FakeVideoCaptureDeviceBase() |
202 : loop_(new base::MessageLoop()), | 203 : descriptors_(new VideoCaptureDeviceDescriptors()), |
203 descriptors_(new VideoCaptureDeviceDescriptors()), | |
204 client_(CreateClient()), | 204 client_(CreateClient()), |
205 image_capture_client_(new ImageCaptureClient()), | 205 image_capture_client_(new ImageCaptureClient()), |
206 video_capture_device_factory_(new FakeVideoCaptureDeviceFactory()) {} | 206 video_capture_device_factory_(new FakeVideoCaptureDeviceFactory()) {} |
207 | 207 |
208 void SetUp() override { EXPECT_CALL(*client_, OnError(_, _)).Times(0); } | 208 void SetUp() override { EXPECT_CALL(*client_, OnError(_, _)).Times(0); } |
209 | 209 |
210 std::unique_ptr<MockClient> CreateClient() { | 210 std::unique_ptr<MockClient> CreateClient() { |
211 return std::unique_ptr<MockClient>(new MockClient(base::Bind( | 211 return std::unique_ptr<MockClient>(new MockClient(base::Bind( |
212 &FakeVideoCaptureDeviceBase::OnFrameCaptured, base::Unretained(this)))); | 212 &FakeVideoCaptureDeviceBase::OnFrameCaptured, base::Unretained(this)))); |
213 } | 213 } |
214 | 214 |
215 void OnFrameCaptured(const VideoCaptureFormat& format) { | 215 void OnFrameCaptured(const VideoCaptureFormat& format) { |
216 last_format_ = format; | 216 last_format_ = format; |
217 run_loop_->QuitClosure().Run(); | 217 run_loop_->QuitClosure().Run(); |
218 } | 218 } |
219 | 219 |
220 void WaitForCapturedFrame() { | 220 void WaitForCapturedFrame() { |
221 run_loop_.reset(new base::RunLoop()); | 221 run_loop_.reset(new base::RunLoop()); |
222 run_loop_->Run(); | 222 run_loop_->Run(); |
223 } | 223 } |
224 | 224 |
225 const VideoCaptureFormat& last_format() const { return last_format_; } | 225 const VideoCaptureFormat& last_format() const { return last_format_; } |
226 | 226 |
227 const std::unique_ptr<base::MessageLoop> loop_; | 227 base::test::ScopedTaskEnvironment scoped_task_environment_; |
228 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors_; | 228 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors_; |
229 std::unique_ptr<base::RunLoop> run_loop_; | 229 std::unique_ptr<base::RunLoop> run_loop_; |
230 std::unique_ptr<MockClient> client_; | 230 std::unique_ptr<MockClient> client_; |
231 const scoped_refptr<ImageCaptureClient> image_capture_client_; | 231 const scoped_refptr<ImageCaptureClient> image_capture_client_; |
232 VideoCaptureFormat last_format_; | 232 VideoCaptureFormat last_format_; |
233 const std::unique_ptr<FakeVideoCaptureDeviceFactory> | 233 const std::unique_ptr<FakeVideoCaptureDeviceFactory> |
234 video_capture_device_factory_; | 234 video_capture_device_factory_; |
235 }; | 235 }; |
236 | 236 |
237 class FakeVideoCaptureDeviceTest | 237 class FakeVideoCaptureDeviceTest |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 4u, | 610 4u, |
611 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, | 611 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, |
612 PIXEL_FORMAT_MJPEG, PIXEL_FORMAT_I420}}, | 612 PIXEL_FORMAT_MJPEG, PIXEL_FORMAT_I420}}, |
613 CommandLineTestData{"device-count=4,ownership=client", | 613 CommandLineTestData{"device-count=4,ownership=client", |
614 20, | 614 20, |
615 4u, | 615 4u, |
616 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, | 616 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, |
617 PIXEL_FORMAT_MJPEG, PIXEL_FORMAT_I420}}, | 617 PIXEL_FORMAT_MJPEG, PIXEL_FORMAT_I420}}, |
618 CommandLineTestData{"device-count=0", 20, 0u, {PIXEL_FORMAT_I420}})); | 618 CommandLineTestData{"device-count=0", 20, 0u, {PIXEL_FORMAT_I420}})); |
619 }; // namespace media | 619 }; // namespace media |
OLD | NEW |