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

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

Issue 2344123002: ImageCapture: Implement TakePhoto() for Linux/CrOs (Closed)
Patch Set: 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
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 #define MAYBE_AllocateBadSize AllocateBadSize 56 #define MAYBE_AllocateBadSize AllocateBadSize
57 #define MAYBE_CaptureMjpeg CaptureMjpeg 57 #define MAYBE_CaptureMjpeg CaptureMjpeg
58 #define MAYBE_TakePhoto DISABLED_TakePhoto 58 #define MAYBE_TakePhoto DISABLED_TakePhoto
59 #elif defined(OS_LINUX) 59 #elif defined(OS_LINUX)
60 // AllocateBadSize will hang when a real camera is attached and if more than one 60 // AllocateBadSize will hang when a real camera is attached and if more than one
61 // test is trying to use the camera (even across processes). Do NOT renable 61 // test is trying to use the camera (even across processes). Do NOT renable
62 // this test without fixing the many bugs associated with it: 62 // this test without fixing the many bugs associated with it:
63 // http://crbug.com/94134 http://crbug.com/137260 http://crbug.com/417824 63 // http://crbug.com/94134 http://crbug.com/137260 http://crbug.com/417824
64 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize 64 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize
65 #define MAYBE_CaptureMjpeg CaptureMjpeg 65 #define MAYBE_CaptureMjpeg CaptureMjpeg
66 #define MAYBE_TakePhoto DISABLED_TakePhoto 66 #define MAYBE_TakePhoto TakePhoto
67 #else 67 #else
68 #define MAYBE_AllocateBadSize AllocateBadSize 68 #define MAYBE_AllocateBadSize AllocateBadSize
69 #define MAYBE_CaptureMjpeg CaptureMjpeg 69 #define MAYBE_CaptureMjpeg CaptureMjpeg
70 #define MAYBE_TakePhoto DISABLED_TakePhoto 70 #define MAYBE_TakePhoto DISABLED_TakePhoto
71 #endif 71 #endif
72 72
73 using ::testing::_; 73 using ::testing::_;
74 using ::testing::AnyOf;
mcasas 2016/09/16 03:50:37 Not used, remove.
xianglu 2016/09/16 18:22:34 Done.
74 using ::testing::SaveArg; 75 using ::testing::SaveArg;
75 76
76 namespace media { 77 namespace media {
77 namespace { 78 namespace {
78 79
79 class MockVideoCaptureClient : public VideoCaptureDevice::Client { 80 class MockVideoCaptureClient : public VideoCaptureDevice::Client {
80 public: 81 public:
81 MOCK_METHOD0(DoReserveOutputBuffer, void(void)); 82 MOCK_METHOD0(DoReserveOutputBuffer, void(void));
82 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void)); 83 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void));
83 MOCK_METHOD0(DoOnIncomingCapturedVideoFrame, void(void)); 84 MOCK_METHOD0(DoOnIncomingCapturedVideoFrame, void(void));
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 135
135 private: 136 private:
136 scoped_refptr<base::SingleThreadTaskRunner> main_thread_; 137 scoped_refptr<base::SingleThreadTaskRunner> main_thread_;
137 base::Callback<void(const VideoCaptureFormat&)> frame_cb_; 138 base::Callback<void(const VideoCaptureFormat&)> frame_cb_;
138 }; 139 };
139 140
140 class MockImageCaptureClient : public base::RefCounted<MockImageCaptureClient> { 141 class MockImageCaptureClient : public base::RefCounted<MockImageCaptureClient> {
141 public: 142 public:
142 // GMock doesn't support move-only arguments, so we use this forward method. 143 // GMock doesn't support move-only arguments, so we use this forward method.
143 void DoOnPhotoTaken(mojom::BlobPtr blob) { 144 void DoOnPhotoTaken(mojom::BlobPtr blob) {
144 EXPECT_STREQ("image/jpeg", blob->mime_type.c_str()); 145 if (strcmp("image/jpeg", blob->mime_type.c_str()) == 0) {
145 ASSERT_GT(blob->data.size(), 4u); 146 ASSERT_GT(blob->data.size(), 4u);
146 // Check some bytes that univocally identify |data| as a JPEG File. 147 // Check some bytes that univocally identify |data| as a JPEG File.
147 // https://en.wikipedia.org/wiki/JPEG_File_Interchange_Format#File_format_st ructure 148 // https://en.wikipedia.org/wiki/JPEG_File_Interchange_Format#File_format_ structure
148 EXPECT_EQ(0xFF, blob->data[0]); // First SOI byte 149 EXPECT_EQ(0xFF, blob->data[0]); // First SOI byte
149 EXPECT_EQ(0xD8, blob->data[1]); // Second SOI byte 150 EXPECT_EQ(0xD8, blob->data[1]); // Second SOI byte
150 EXPECT_EQ(0xFF, blob->data[2]); // First JFIF-APP0 byte 151 EXPECT_EQ(0xFF, blob->data[2]); // First JFIF-APP0 byte
151 EXPECT_EQ(0xE0, blob->data[3]); // Second JFIF-APP0 byte 152 EXPECT_EQ(0xE0, blob->data[3]); // Second JFIF-APP0 byte
152 OnCorrectPhotoTaken(); 153 OnCorrectPhotoTaken();
154 } else if (strcmp("image/png", blob->mime_type.c_str()) == 0) {
155 ASSERT_GT(blob->data.size(), 4u);
156 EXPECT_EQ('P', blob->data[1]);
157 EXPECT_EQ('N', blob->data[2]);
158 EXPECT_EQ('G', blob->data[3]);
159 OnCorrectPhotoTaken();
160 } else {
161 NOTREACHED() << "Photo format should be jpeg or png";
mcasas 2016/09/16 03:50:37 NOTREACHED() would crash the test executable and p
xianglu 2016/09/16 18:22:34 Done.
162 }
153 } 163 }
154 MOCK_METHOD0(OnCorrectPhotoTaken, void(void)); 164 MOCK_METHOD0(OnCorrectPhotoTaken, void(void));
155 MOCK_METHOD1(OnTakePhotoFailure, 165 MOCK_METHOD1(OnTakePhotoFailure,
156 void(const base::Callback<void(mojom::BlobPtr)>&)); 166 void(const base::Callback<void(mojom::BlobPtr)>&));
157 167
158 private: 168 private:
159 friend class base::RefCounted<MockImageCaptureClient>; 169 friend class base::RefCounted<MockImageCaptureClient>;
160 virtual ~MockImageCaptureClient() {} 170 virtual ~MockImageCaptureClient() {}
161 }; 171 };
162 172
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 &MockImageCaptureClient::OnTakePhotoFailure, image_capture_client_))); 540 &MockImageCaptureClient::OnTakePhotoFailure, image_capture_client_)));
531 541
532 EXPECT_CALL(*image_capture_client_.get(), OnCorrectPhotoTaken()).Times(1); 542 EXPECT_CALL(*image_capture_client_.get(), OnCorrectPhotoTaken()).Times(1);
533 device->TakePhoto(std::move(scoped_callback)); 543 device->TakePhoto(std::move(scoped_callback));
534 WaitForCapturedFrame(); 544 WaitForCapturedFrame();
535 545
536 device->StopAndDeAllocate(); 546 device->StopAndDeAllocate();
537 } 547 }
538 548
539 }; // namespace media 549 }; // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698