OLD | NEW |
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 Loading... |
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::SaveArg; | 74 using ::testing::SaveArg; |
75 | 75 |
76 namespace media { | 76 namespace media { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 134 |
135 private: | 135 private: |
136 scoped_refptr<base::SingleThreadTaskRunner> main_thread_; | 136 scoped_refptr<base::SingleThreadTaskRunner> main_thread_; |
137 base::Callback<void(const VideoCaptureFormat&)> frame_cb_; | 137 base::Callback<void(const VideoCaptureFormat&)> frame_cb_; |
138 }; | 138 }; |
139 | 139 |
140 class MockImageCaptureClient : public base::RefCounted<MockImageCaptureClient> { | 140 class MockImageCaptureClient : public base::RefCounted<MockImageCaptureClient> { |
141 public: | 141 public: |
142 // GMock doesn't support move-only arguments, so we use this forward method. | 142 // GMock doesn't support move-only arguments, so we use this forward method. |
143 void DoOnPhotoTaken(mojom::BlobPtr blob) { | 143 void DoOnPhotoTaken(mojom::BlobPtr blob) { |
144 EXPECT_STREQ("image/jpeg", blob->mime_type.c_str()); | 144 if (strcmp("image/jpeg", blob->mime_type.c_str()) == 0) { |
145 ASSERT_GT(blob->data.size(), 4u); | 145 ASSERT_GT(blob->data.size(), 4u); |
146 // Check some bytes that univocally identify |data| as a JPEG File. | 146 // 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 | 147 // https://en.wikipedia.org/wiki/JPEG_File_Interchange_Format#File_format_
structure |
148 EXPECT_EQ(0xFF, blob->data[0]); // First SOI byte | 148 EXPECT_EQ(0xFF, blob->data[0]); // First SOI byte |
149 EXPECT_EQ(0xD8, blob->data[1]); // Second SOI byte | 149 EXPECT_EQ(0xD8, blob->data[1]); // Second SOI byte |
150 EXPECT_EQ(0xFF, blob->data[2]); // First JFIF-APP0 byte | 150 EXPECT_EQ(0xFF, blob->data[2]); // First JFIF-APP0 byte |
151 EXPECT_EQ(0xE0, blob->data[3]); // Second JFIF-APP0 byte | 151 EXPECT_EQ(0xE0, blob->data[3]); // Second JFIF-APP0 byte |
152 OnCorrectPhotoTaken(); | 152 OnCorrectPhotoTaken(); |
| 153 } else if (strcmp("image/png", blob->mime_type.c_str()) == 0) { |
| 154 ASSERT_GT(blob->data.size(), 4u); |
| 155 EXPECT_EQ('P', blob->data[1]); |
| 156 EXPECT_EQ('N', blob->data[2]); |
| 157 EXPECT_EQ('G', blob->data[3]); |
| 158 OnCorrectPhotoTaken(); |
| 159 } else { |
| 160 ADD_FAILURE() << "Photo format should be jpeg or png"; |
| 161 } |
153 } | 162 } |
154 MOCK_METHOD0(OnCorrectPhotoTaken, void(void)); | 163 MOCK_METHOD0(OnCorrectPhotoTaken, void(void)); |
155 MOCK_METHOD1(OnTakePhotoFailure, | 164 MOCK_METHOD1(OnTakePhotoFailure, |
156 void(const base::Callback<void(mojom::BlobPtr)>&)); | 165 void(const base::Callback<void(mojom::BlobPtr)>&)); |
157 | 166 |
158 private: | 167 private: |
159 friend class base::RefCounted<MockImageCaptureClient>; | 168 friend class base::RefCounted<MockImageCaptureClient>; |
160 virtual ~MockImageCaptureClient() {} | 169 virtual ~MockImageCaptureClient() {} |
161 }; | 170 }; |
162 | 171 |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 &MockImageCaptureClient::OnTakePhotoFailure, image_capture_client_))); | 539 &MockImageCaptureClient::OnTakePhotoFailure, image_capture_client_))); |
531 | 540 |
532 EXPECT_CALL(*image_capture_client_.get(), OnCorrectPhotoTaken()).Times(1); | 541 EXPECT_CALL(*image_capture_client_.get(), OnCorrectPhotoTaken()).Times(1); |
533 device->TakePhoto(std::move(scoped_callback)); | 542 device->TakePhoto(std::move(scoped_callback)); |
534 WaitForCapturedFrame(); | 543 WaitForCapturedFrame(); |
535 | 544 |
536 device->StopAndDeAllocate(); | 545 device->StopAndDeAllocate(); |
537 } | 546 } |
538 | 547 |
539 }; // namespace media | 548 }; // namespace media |
OLD | NEW |