| 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 } | 138 } |
| 139 | 139 |
| 140 private: | 140 private: |
| 141 scoped_refptr<base::SingleThreadTaskRunner> main_thread_; | 141 scoped_refptr<base::SingleThreadTaskRunner> main_thread_; |
| 142 base::Callback<void(const VideoCaptureFormat&)> frame_cb_; | 142 base::Callback<void(const VideoCaptureFormat&)> frame_cb_; |
| 143 }; | 143 }; |
| 144 | 144 |
| 145 class MockImageCaptureClient : public base::RefCounted<MockImageCaptureClient> { | 145 class MockImageCaptureClient : public base::RefCounted<MockImageCaptureClient> { |
| 146 public: | 146 public: |
| 147 // GMock doesn't support move-only arguments, so we use this forward method. | 147 // GMock doesn't support move-only arguments, so we use this forward method. |
| 148 void DoOnPhotoTaken(mojo::String mime_type, mojo::Array<uint8_t> data) { | 148 void DoOnPhotoTaken(const std::string& mime_type, |
| 149 EXPECT_STREQ("image/jpeg", mime_type.storage().c_str()); | 149 const std::vector<uint8_t>& data) { |
| 150 EXPECT_STREQ("image/jpeg", mime_type.c_str()); |
| 150 ASSERT_GT(data.size(), 4u); | 151 ASSERT_GT(data.size(), 4u); |
| 151 // Check some bytes that univocally identify |data| as a JPEG File. | 152 // Check some bytes that univocally identify |data| as a JPEG File. |
| 152 // https://en.wikipedia.org/wiki/JPEG_File_Interchange_Format#File_format_st
ructure | 153 // https://en.wikipedia.org/wiki/JPEG_File_Interchange_Format#File_format_st
ructure |
| 153 EXPECT_EQ(0xFF, data[0]); // First SOI byte | 154 EXPECT_EQ(0xFF, data[0]); // First SOI byte |
| 154 EXPECT_EQ(0xD8, data[1]); // Second SOI byte | 155 EXPECT_EQ(0xD8, data[1]); // Second SOI byte |
| 155 EXPECT_EQ(0xFF, data[2]); // First JFIF-APP0 byte | 156 EXPECT_EQ(0xFF, data[2]); // First JFIF-APP0 byte |
| 156 EXPECT_EQ(0xE0, data[3]); // Second JFIF-APP0 byte | 157 EXPECT_EQ(0xE0, data[3]); // Second JFIF-APP0 byte |
| 157 OnCorrectPhotoTaken(); | 158 OnCorrectPhotoTaken(); |
| 158 } | 159 } |
| 159 MOCK_METHOD0(OnCorrectPhotoTaken, void(void)); | 160 MOCK_METHOD0(OnCorrectPhotoTaken, void(void)); |
| 160 MOCK_METHOD1( | 161 MOCK_METHOD1(OnTakePhotoFailure, |
| 161 OnTakePhotoFailure, | 162 void(const base::Callback<void(const std::string&, |
| 162 void(const base::Callback<void(mojo::String, mojo::Array<uint8_t>)>&)); | 163 const std::vector<uint8_t>&)>&)); |
| 163 | 164 |
| 164 private: | 165 private: |
| 165 friend class base::RefCounted<MockImageCaptureClient>; | 166 friend class base::RefCounted<MockImageCaptureClient>; |
| 166 virtual ~MockImageCaptureClient() {} | 167 virtual ~MockImageCaptureClient() {} |
| 167 }; | 168 }; |
| 168 | 169 |
| 169 class DeviceEnumerationListener | 170 class DeviceEnumerationListener |
| 170 : public base::RefCounted<DeviceEnumerationListener> { | 171 : public base::RefCounted<DeviceEnumerationListener> { |
| 171 public: | 172 public: |
| 172 MOCK_METHOD1(OnEnumeratedDevicesCallbackPtr, | 173 MOCK_METHOD1(OnEnumeratedDevicesCallbackPtr, |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 &MockImageCaptureClient::OnTakePhotoFailure, image_capture_client_))); | 547 &MockImageCaptureClient::OnTakePhotoFailure, image_capture_client_))); |
| 547 | 548 |
| 548 EXPECT_CALL(*image_capture_client_.get(), OnCorrectPhotoTaken()).Times(1); | 549 EXPECT_CALL(*image_capture_client_.get(), OnCorrectPhotoTaken()).Times(1); |
| 549 device->TakePhoto(std::move(scoped_callback)); | 550 device->TakePhoto(std::move(scoped_callback)); |
| 550 WaitForCapturedFrame(); | 551 WaitForCapturedFrame(); |
| 551 | 552 |
| 552 device->StopAndDeAllocate(); | 553 device->StopAndDeAllocate(); |
| 553 } | 554 } |
| 554 | 555 |
| 555 }; // namespace media | 556 }; // namespace media |
| OLD | NEW |