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

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

Issue 2344123002: ImageCapture: Implement TakePhoto() for Linux/CrOs (Closed)
Patch Set: v4l2_capture_delegate.cc l.152: Added back '&0xf0' 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 #define MAYBE_AllocateBadSize AllocateBadSize 57 #define MAYBE_AllocateBadSize AllocateBadSize
58 #define MAYBE_CaptureMjpeg CaptureMjpeg 58 #define MAYBE_CaptureMjpeg CaptureMjpeg
59 #define MAYBE_TakePhoto TakePhoto 59 #define MAYBE_TakePhoto TakePhoto
60 #elif defined(OS_LINUX) 60 #elif defined(OS_LINUX)
61 // AllocateBadSize will hang when a real camera is attached and if more than one 61 // 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 62 // test is trying to use the camera (even across processes). Do NOT renable
63 // this test without fixing the many bugs associated with it: 63 // this test without fixing the many bugs associated with it:
64 // http://crbug.com/94134 http://crbug.com/137260 http://crbug.com/417824 64 // http://crbug.com/94134 http://crbug.com/137260 http://crbug.com/417824
65 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize 65 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize
66 #define MAYBE_CaptureMjpeg CaptureMjpeg 66 #define MAYBE_CaptureMjpeg CaptureMjpeg
67 #define MAYBE_TakePhoto DISABLED_TakePhoto 67 #define MAYBE_TakePhoto TakePhoto
68 #else 68 #else
69 #define MAYBE_AllocateBadSize AllocateBadSize 69 #define MAYBE_AllocateBadSize AllocateBadSize
70 #define MAYBE_CaptureMjpeg CaptureMjpeg 70 #define MAYBE_CaptureMjpeg CaptureMjpeg
71 #define MAYBE_TakePhoto DISABLED_TakePhoto 71 #define MAYBE_TakePhoto DISABLED_TakePhoto
72 #endif 72 #endif
73 73
74 using ::testing::_; 74 using ::testing::_;
75 using ::testing::SaveArg; 75 using ::testing::SaveArg;
76 76
77 namespace media { 77 namespace media {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 135
136 private: 136 private:
137 scoped_refptr<base::SingleThreadTaskRunner> main_thread_; 137 scoped_refptr<base::SingleThreadTaskRunner> main_thread_;
138 base::Callback<void(const VideoCaptureFormat&)> frame_cb_; 138 base::Callback<void(const VideoCaptureFormat&)> frame_cb_;
139 }; 139 };
140 140
141 class MockImageCaptureClient : public base::RefCounted<MockImageCaptureClient> { 141 class MockImageCaptureClient : public base::RefCounted<MockImageCaptureClient> {
142 public: 142 public:
143 // 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.
144 void DoOnPhotoTaken(mojom::BlobPtr blob) { 144 void DoOnPhotoTaken(mojom::BlobPtr blob) {
145 EXPECT_STREQ("image/jpeg", blob->mime_type.c_str()); 145 if (strcmp("image/jpeg", blob->mime_type.c_str()) == 0) {
146 ASSERT_GT(blob->data.size(), 4u); 146 ASSERT_GT(blob->data.size(), 4u);
147 // Check some bytes that univocally identify |data| as a JPEG File. 147 // Check some bytes that univocally identify |data| as a JPEG File.
148 // 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
149 EXPECT_EQ(0xFF, blob->data[0]); // First SOI byte 149 EXPECT_EQ(0xFF, blob->data[0]); // First SOI byte
150 EXPECT_EQ(0xD8, blob->data[1]); // Second SOI byte 150 EXPECT_EQ(0xD8, blob->data[1]); // Second SOI byte
151 EXPECT_EQ(0xFF, blob->data[2]); // First JFIF-APP0 byte 151 EXPECT_EQ(0xFF, blob->data[2]); // First JFIF-APP0 byte
152 EXPECT_EQ(0xE0, blob->data[3] & 0xF0); // Second JFIF-APP0/APP1 byte 152 EXPECT_EQ(0xE0, blob->data[3] & 0xF0); // Second JFIF-APP0 byte
153 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 ADD_FAILURE() << "Photo format should be jpeg or png";
162 }
154 } 163 }
155 MOCK_METHOD0(OnCorrectPhotoTaken, void(void)); 164 MOCK_METHOD0(OnCorrectPhotoTaken, void(void));
156 MOCK_METHOD1(OnTakePhotoFailure, 165 MOCK_METHOD1(OnTakePhotoFailure,
157 void(const base::Callback<void(mojom::BlobPtr)>&)); 166 void(const base::Callback<void(mojom::BlobPtr)>&));
158 167
159 private: 168 private:
160 friend class base::RefCounted<MockImageCaptureClient>; 169 friend class base::RefCounted<MockImageCaptureClient>;
161 virtual ~MockImageCaptureClient() {} 170 virtual ~MockImageCaptureClient() {}
162 }; 171 };
163 172
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 &MockImageCaptureClient::OnTakePhotoFailure, image_capture_client_))); 548 &MockImageCaptureClient::OnTakePhotoFailure, image_capture_client_)));
540 549
541 EXPECT_CALL(*image_capture_client_.get(), OnCorrectPhotoTaken()).Times(1); 550 EXPECT_CALL(*image_capture_client_.get(), OnCorrectPhotoTaken()).Times(1);
542 device->TakePhoto(std::move(scoped_callback)); 551 device->TakePhoto(std::move(scoped_callback));
543 WaitForCapturedFrame(); 552 WaitForCapturedFrame();
544 553
545 device->StopAndDeAllocate(); 554 device->StopAndDeAllocate();
546 } 555 }
547 556
548 }; // namespace media 557 }; // 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