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

Side by Side Diff: media/capture/video/video_capture_device_unittest.cc

Issue 2349693003: Image Capture Linux/CrOs: wire some capabilities set/get (Closed)
Patch Set: rebase Created 4 years, 3 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
« no previous file with comments | « media/capture/video/linux/video_capture_device_linux.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/video_capture_device.h" 5 #include "media/capture/video/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>
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "media/capture/video/android/video_capture_device_android.h" 42 #include "media/capture/video/android/video_capture_device_android.h"
43 #include "media/capture/video/android/video_capture_device_factory_android.h" 43 #include "media/capture/video/android/video_capture_device_factory_android.h"
44 #endif 44 #endif
45 45
46 #if defined(OS_MACOSX) 46 #if defined(OS_MACOSX)
47 // Mac will always give you the size you ask for and this case will fail. 47 // Mac will always give you the size you ask for and this case will fail.
48 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize 48 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize
49 // We will always get YUYV from the Mac AVFoundation implementations. 49 // We will always get YUYV from the Mac AVFoundation implementations.
50 #define MAYBE_CaptureMjpeg DISABLED_CaptureMjpeg 50 #define MAYBE_CaptureMjpeg DISABLED_CaptureMjpeg
51 #define MAYBE_TakePhoto TakePhoto 51 #define MAYBE_TakePhoto TakePhoto
52 #define MAYBE_GetPhotoCapabilities DISABLED_GetPhotoCapabilities
52 #elif defined(OS_WIN) 53 #elif defined(OS_WIN)
53 #define MAYBE_AllocateBadSize AllocateBadSize 54 #define MAYBE_AllocateBadSize AllocateBadSize
54 #define MAYBE_CaptureMjpeg CaptureMjpeg 55 #define MAYBE_CaptureMjpeg CaptureMjpeg
55 #define MAYBE_TakePhoto TakePhoto 56 #define MAYBE_TakePhoto TakePhoto
57 #define MAYBE_GetPhotoCapabilities DISABLED_GetPhotoCapabilities
56 #elif defined(OS_ANDROID) 58 #elif defined(OS_ANDROID)
57 #define MAYBE_AllocateBadSize AllocateBadSize 59 #define MAYBE_AllocateBadSize AllocateBadSize
58 #define MAYBE_CaptureMjpeg CaptureMjpeg 60 #define MAYBE_CaptureMjpeg CaptureMjpeg
59 #define MAYBE_TakePhoto TakePhoto 61 #define MAYBE_TakePhoto TakePhoto
62 #define MAYBE_GetPhotoCapabilities GetPhotoCapabilities
60 #elif defined(OS_LINUX) 63 #elif defined(OS_LINUX)
61 // AllocateBadSize will hang when a real camera is attached and if more than one 64 // AllocateBadSize will hang when a real camera is attached and if more than one
62 // test is trying to use the camera (even across processes). Do NOT renable 65 // test is trying to use the camera (even across processes). Do NOT renable
63 // this test without fixing the many bugs associated with it: 66 // this test without fixing the many bugs associated with it:
64 // http://crbug.com/94134 http://crbug.com/137260 http://crbug.com/417824 67 // http://crbug.com/94134 http://crbug.com/137260 http://crbug.com/417824
65 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize 68 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize
66 #define MAYBE_CaptureMjpeg CaptureMjpeg 69 #define MAYBE_CaptureMjpeg CaptureMjpeg
67 #define MAYBE_TakePhoto TakePhoto 70 #define MAYBE_TakePhoto TakePhoto
71 #define MAYBE_GetPhotoCapabilities GetPhotoCapabilities
68 #else 72 #else
69 #define MAYBE_AllocateBadSize AllocateBadSize 73 #define MAYBE_AllocateBadSize AllocateBadSize
70 #define MAYBE_CaptureMjpeg CaptureMjpeg 74 #define MAYBE_CaptureMjpeg CaptureMjpeg
71 #define MAYBE_TakePhoto DISABLED_TakePhoto 75 #define MAYBE_TakePhoto DISABLED_TakePhoto
76 #define MAYBE_GetPhotoCapabilities DISABLED_GetPhotoCapabilities
72 #endif 77 #endif
73 78
74 using ::testing::_; 79 using ::testing::_;
75 using ::testing::SaveArg; 80 using ::testing::SaveArg;
76 81
77 namespace media { 82 namespace media {
78 namespace { 83 namespace {
79 84
80 class MockVideoCaptureClient : public VideoCaptureDevice::Client { 85 class MockVideoCaptureClient : public VideoCaptureDevice::Client {
81 public: 86 public:
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 EXPECT_EQ('G', blob->data[3]); 163 EXPECT_EQ('G', blob->data[3]);
159 OnCorrectPhotoTaken(); 164 OnCorrectPhotoTaken();
160 } else { 165 } else {
161 ADD_FAILURE() << "Photo format should be jpeg or png"; 166 ADD_FAILURE() << "Photo format should be jpeg or png";
162 } 167 }
163 } 168 }
164 MOCK_METHOD0(OnCorrectPhotoTaken, void(void)); 169 MOCK_METHOD0(OnCorrectPhotoTaken, void(void));
165 MOCK_METHOD1(OnTakePhotoFailure, 170 MOCK_METHOD1(OnTakePhotoFailure,
166 void(const base::Callback<void(mojom::BlobPtr)>&)); 171 void(const base::Callback<void(mojom::BlobPtr)>&));
167 172
173 // GMock doesn't support move-only arguments, so we use this forward method.
174 void DoOnGetPhotoCapabilities(mojom::PhotoCapabilitiesPtr capabilities) {
175 capabilities_ = std::move(capabilities);
176 OnCorrectGetPhotoCapabilities();
177 }
178 MOCK_METHOD0(OnCorrectGetPhotoCapabilities, void(void));
179 MOCK_METHOD1(OnGetPhotoCapabilitiesFailure,
180 void(const base::Callback<void(mojom::PhotoCapabilitiesPtr)>&));
181
182 const mojom::PhotoCapabilities* capabilities() { return capabilities_.get(); }
183
168 private: 184 private:
169 friend class base::RefCounted<MockImageCaptureClient>; 185 friend class base::RefCounted<MockImageCaptureClient>;
170 virtual ~MockImageCaptureClient() {} 186 virtual ~MockImageCaptureClient() {}
187
188 mojom::PhotoCapabilitiesPtr capabilities_;
171 }; 189 };
172 190
173 class DeviceEnumerationListener 191 class DeviceEnumerationListener
174 : public base::RefCounted<DeviceEnumerationListener> { 192 : public base::RefCounted<DeviceEnumerationListener> {
175 public: 193 public:
176 MOCK_METHOD1(DoOnEnumerateDeviceDescriptors, 194 MOCK_METHOD1(DoOnEnumerateDeviceDescriptors,
177 void(VideoCaptureDeviceDescriptors* device_descriptors)); 195 void(VideoCaptureDeviceDescriptors* device_descriptors));
178 // GMock doesn't support move-only arguments, so we use this forward method. 196 // GMock doesn't support move-only arguments, so we use this forward method.
179 void OnEnumerateDeviceDescriptors( 197 void OnEnumerateDeviceDescriptors(
180 std::unique_ptr<VideoCaptureDeviceDescriptors> device_descriptors) { 198 std::unique_ptr<VideoCaptureDeviceDescriptors> device_descriptors) {
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 TEST_F(VideoCaptureDeviceTest, NoCameraSupportsPixelFormatMax) { 525 TEST_F(VideoCaptureDeviceTest, NoCameraSupportsPixelFormatMax) {
508 // Use PIXEL_FORMAT_MAX to iterate all device names for testing 526 // Use PIXEL_FORMAT_MAX to iterate all device names for testing
509 // GetDeviceSupportedFormats(). 527 // GetDeviceSupportedFormats().
510 std::unique_ptr<VideoCaptureDeviceDescriptor> device_descriptor = 528 std::unique_ptr<VideoCaptureDeviceDescriptor> device_descriptor =
511 GetFirstDeviceDescriptorSupportingPixelFormat(PIXEL_FORMAT_MAX); 529 GetFirstDeviceDescriptorSupportingPixelFormat(PIXEL_FORMAT_MAX);
512 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here 530 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here
513 // since we cannot forecast the hardware capabilities. 531 // since we cannot forecast the hardware capabilities.
514 ASSERT_FALSE(device_descriptor); 532 ASSERT_FALSE(device_descriptor);
515 } 533 }
516 534
517 // Starts the camera and take a photo. 535 // Starts the camera and takes a photo.
518 TEST_F(VideoCaptureDeviceTest, MAYBE_TakePhoto) { 536 TEST_F(VideoCaptureDeviceTest, MAYBE_TakePhoto) {
519 if (!EnumerateAndFindUsableDevices()) 537 if (!EnumerateAndFindUsableDevices())
520 return; 538 return;
521 539
522 #if defined(OS_ANDROID) 540 #if defined(OS_ANDROID)
523 // TODO(mcasas): fails on Lollipop devices, reconnect https://crbug.com/646840 541 // TODO(mcasas): fails on Lollipop devices, reconnect https://crbug.com/646840
524 if (base::android::BuildInfo::GetInstance()->sdk_int() < 542 if (base::android::BuildInfo::GetInstance()->sdk_int() <
525 base::android::SDK_VERSION_MARSHMALLOW) { 543 base::android::SDK_VERSION_MARSHMALLOW) {
526 return; 544 return;
527 } 545 }
(...skipping 19 matching lines...) Expand all
547 media::BindToCurrentLoop(base::Bind( 565 media::BindToCurrentLoop(base::Bind(
548 &MockImageCaptureClient::OnTakePhotoFailure, image_capture_client_))); 566 &MockImageCaptureClient::OnTakePhotoFailure, image_capture_client_)));
549 567
550 EXPECT_CALL(*image_capture_client_.get(), OnCorrectPhotoTaken()).Times(1); 568 EXPECT_CALL(*image_capture_client_.get(), OnCorrectPhotoTaken()).Times(1);
551 device->TakePhoto(std::move(scoped_callback)); 569 device->TakePhoto(std::move(scoped_callback));
552 WaitForCapturedFrame(); 570 WaitForCapturedFrame();
553 571
554 device->StopAndDeAllocate(); 572 device->StopAndDeAllocate();
555 } 573 }
556 574
575 // Starts the camera and tries to get the Photo capabilities.
576 TEST_F(VideoCaptureDeviceTest, MAYBE_GetPhotoCapabilities) {
577 if (!EnumerateAndFindUsableDevices())
578 return;
579
580 #if defined(OS_ANDROID)
581 // TODO(mcasas): fails on Lollipop devices, reconnect https://crbug.com/646840
582 if (base::android::BuildInfo::GetInstance()->sdk_int() <
583 base::android::SDK_VERSION_MARSHMALLOW) {
584 return;
585 }
586 #endif
587
588 std::unique_ptr<VideoCaptureDevice> device(
589 video_capture_device_factory_->CreateDevice(
590 device_descriptors_->front()));
591 ASSERT_TRUE(device);
592
593 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0);
594
595 VideoCaptureParams capture_params;
596 capture_params.requested_format.frame_size.SetSize(320, 240);
597 capture_params.requested_format.frame_rate = 30;
598 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
599 device->AllocateAndStart(capture_params, std::move(video_capture_client_));
600 WaitForCapturedFrame();
601
602 VideoCaptureDevice::GetPhotoCapabilitiesCallback scoped_get_callback(
603 base::Bind(&MockImageCaptureClient::DoOnGetPhotoCapabilities,
604 image_capture_client_),
605 media::BindToCurrentLoop(
606 base::Bind(&MockImageCaptureClient::OnGetPhotoCapabilitiesFailure,
607 image_capture_client_)));
608
609 EXPECT_CALL(*image_capture_client_.get(), OnCorrectGetPhotoCapabilities())
610 .Times(1);
611
612 device->GetPhotoCapabilities(std::move(scoped_get_callback));
613 WaitForCapturedFrame();
614
615 auto* capabilities = image_capture_client_->capabilities();
616 ASSERT_TRUE(capabilities);
617
618 device->StopAndDeAllocate();
619 }
620
557 }; // namespace media 621 }; // namespace media
OLDNEW
« no previous file with comments | « media/capture/video/linux/video_capture_device_linux.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698