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

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

Issue 1952463002: Media Stream Image Capture (4): wire takePhoto and implement in FakeVCDevice (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: forgotten "!" and rebase Created 4 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/fake_video_capture_device.h" 5 #include "media/capture/video/fake_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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 void OnEnumeratedDevicesCallback( 125 void OnEnumeratedDevicesCallback(
126 std::unique_ptr<VideoCaptureDevice::Names> names) { 126 std::unique_ptr<VideoCaptureDevice::Names> names) {
127 OnEnumeratedDevicesCallbackPtr(names.release()); 127 OnEnumeratedDevicesCallbackPtr(names.release());
128 } 128 }
129 129
130 private: 130 private:
131 friend class base::RefCounted<DeviceEnumerationListener>; 131 friend class base::RefCounted<DeviceEnumerationListener>;
132 virtual ~DeviceEnumerationListener() {} 132 virtual ~DeviceEnumerationListener() {}
133 }; 133 };
134 134
135 class PhotoTakenListener : public base::RefCounted<PhotoTakenListener> {
136 public:
137 MOCK_METHOD0(OnCorrectPhotoTaken, void(void));
138 // GMock doesn't support move-only arguments, so we use this forward method.
139 void DoOnPhotoTaken(const std::string& mime_type,
140 std::unique_ptr<std::vector<uint8_t>> data) {
141 // Only PNG images are supported right now.
142 EXPECT_STREQ("image/png", mime_type.c_str());
143 // Not worth decoding the incoming data. Just check that the header is PNG.
144 // http://www.libpng.org/pub/png/spec/1.2/PNG-Rationale.html#R.PNG-file-sign ature
145 EXPECT_GT(data->size(), 4u);
tommi (sloooow) - chröme 2016/05/09 11:17:33 ASSERT_GT?
mcasas 2016/05/09 16:48:40 Done.
146 EXPECT_EQ('P', data->data()[1]);
147 EXPECT_EQ('N', data->data()[2]);
148 EXPECT_EQ('G', data->data()[3]);
149 OnCorrectPhotoTaken();
150 }
151
152 private:
153 friend class base::RefCounted<PhotoTakenListener>;
154 virtual ~PhotoTakenListener() {}
155 };
156
135 } // namespace 157 } // namespace
136 158
137 class FakeVideoCaptureDeviceBase : public ::testing::Test { 159 class FakeVideoCaptureDeviceBase : public ::testing::Test {
138 protected: 160 protected:
139 FakeVideoCaptureDeviceBase() 161 FakeVideoCaptureDeviceBase()
140 : loop_(new base::MessageLoop()), 162 : loop_(new base::MessageLoop()),
141 client_(new MockClient( 163 client_(new MockClient(
142 base::Bind(&FakeVideoCaptureDeviceBase::OnFrameCaptured, 164 base::Bind(&FakeVideoCaptureDeviceBase::OnFrameCaptured,
143 base::Unretained(this)))), 165 base::Unretained(this)))),
144 video_capture_device_factory_(new FakeVideoCaptureDeviceFactory()) { 166 device_enumeration_listener_(new DeviceEnumerationListener()),
145 device_enumeration_listener_ = new DeviceEnumerationListener(); 167 photo_taken_listener_(new PhotoTakenListener()),
146 } 168 video_capture_device_factory_(new FakeVideoCaptureDeviceFactory()) {}
147 169
148 void SetUp() override { EXPECT_CALL(*client_, OnError(_, _)).Times(0); } 170 void SetUp() override { EXPECT_CALL(*client_, OnError(_, _)).Times(0); }
149 171
150 void OnFrameCaptured(const VideoCaptureFormat& format) { 172 void OnFrameCaptured(const VideoCaptureFormat& format) {
151 last_format_ = format; 173 last_format_ = format;
152 run_loop_->QuitClosure().Run(); 174 run_loop_->QuitClosure().Run();
153 } 175 }
154 176
155 void WaitForCapturedFrame() { 177 void WaitForCapturedFrame() {
156 run_loop_.reset(new base::RunLoop()); 178 run_loop_.reset(new base::RunLoop());
(...skipping 11 matching lines...) Expand all
168 base::MessageLoop::current()->RunUntilIdle(); 190 base::MessageLoop::current()->RunUntilIdle();
169 return std::unique_ptr<VideoCaptureDevice::Names>(names); 191 return std::unique_ptr<VideoCaptureDevice::Names>(names);
170 } 192 }
171 193
172 const VideoCaptureFormat& last_format() const { return last_format_; } 194 const VideoCaptureFormat& last_format() const { return last_format_; }
173 195
174 VideoCaptureDevice::Names names_; 196 VideoCaptureDevice::Names names_;
175 const std::unique_ptr<base::MessageLoop> loop_; 197 const std::unique_ptr<base::MessageLoop> loop_;
176 std::unique_ptr<base::RunLoop> run_loop_; 198 std::unique_ptr<base::RunLoop> run_loop_;
177 std::unique_ptr<MockClient> client_; 199 std::unique_ptr<MockClient> client_;
178 scoped_refptr<DeviceEnumerationListener> device_enumeration_listener_; 200 const scoped_refptr<DeviceEnumerationListener> device_enumeration_listener_;
201 const scoped_refptr<PhotoTakenListener> photo_taken_listener_;
179 VideoCaptureFormat last_format_; 202 VideoCaptureFormat last_format_;
180 const std::unique_ptr<VideoCaptureDeviceFactory> 203 const std::unique_ptr<VideoCaptureDeviceFactory>
181 video_capture_device_factory_; 204 video_capture_device_factory_;
182 }; 205 };
183 206
184 class FakeVideoCaptureDeviceTest 207 class FakeVideoCaptureDeviceTest
185 : public FakeVideoCaptureDeviceBase, 208 : public FakeVideoCaptureDeviceBase,
186 public ::testing::WithParamInterface< 209 public ::testing::WithParamInterface<
187 ::testing::tuple<FakeVideoCaptureDevice::BufferOwnership, float>> {}; 210 ::testing::tuple<FakeVideoCaptureDevice::BufferOwnership, float>> {};
188 211
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 EXPECT_EQ(supported_formats[2].frame_size.height(), 720); 268 EXPECT_EQ(supported_formats[2].frame_size.height(), 720);
246 EXPECT_EQ(supported_formats[2].pixel_format, PIXEL_FORMAT_I420); 269 EXPECT_EQ(supported_formats[2].pixel_format, PIXEL_FORMAT_I420);
247 EXPECT_GE(supported_formats[2].frame_rate, 20.0); 270 EXPECT_GE(supported_formats[2].frame_rate, 20.0);
248 EXPECT_EQ(supported_formats[3].frame_size.width(), 1920); 271 EXPECT_EQ(supported_formats[3].frame_size.width(), 1920);
249 EXPECT_EQ(supported_formats[3].frame_size.height(), 1080); 272 EXPECT_EQ(supported_formats[3].frame_size.height(), 1080);
250 EXPECT_EQ(supported_formats[3].pixel_format, PIXEL_FORMAT_I420); 273 EXPECT_EQ(supported_formats[3].pixel_format, PIXEL_FORMAT_I420);
251 EXPECT_GE(supported_formats[3].frame_rate, 20.0); 274 EXPECT_GE(supported_formats[3].frame_rate, 20.0);
252 } 275 }
253 } 276 }
254 277
278 TEST_F(FakeVideoCaptureDeviceTest, TakePhoto) {
279 std::unique_ptr<VideoCaptureDevice> device(new FakeVideoCaptureDevice(
280 FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS, 30.0));
281 ASSERT_TRUE(device);
282
283 VideoCaptureParams capture_params;
284 capture_params.requested_format.frame_size.SetSize(640, 480);
285 capture_params.requested_format.frame_rate = 30.0;
286 device->AllocateAndStart(capture_params, std::move(client_));
287
288 const VideoCaptureDevice::TakePhotoCallback photo_callback =
289 base::Bind(&PhotoTakenListener::DoOnPhotoTaken, photo_taken_listener_);
290 EXPECT_CALL(*photo_taken_listener_.get(), OnCorrectPhotoTaken()).Times(1);
291 ASSERT_TRUE(device->TakePhoto(photo_callback));
292
293 run_loop_.reset(new base::RunLoop());
294 run_loop_->Run();
295 device->StopAndDeAllocate();
296 }
297
255 TEST_P(FakeVideoCaptureDeviceCommandLineTest, FrameRate) { 298 TEST_P(FakeVideoCaptureDeviceCommandLineTest, FrameRate) {
256 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 299 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
257 switches::kUseFakeDeviceForMediaStream, GetParam().argument); 300 switches::kUseFakeDeviceForMediaStream, GetParam().argument);
258 const std::unique_ptr<VideoCaptureDevice::Names> names(EnumerateDevices()); 301 const std::unique_ptr<VideoCaptureDevice::Names> names(EnumerateDevices());
259 ASSERT_FALSE(names->empty()); 302 ASSERT_FALSE(names->empty());
260 303
261 for (const auto& names_iterator : *names) { 304 for (const auto& names_iterator : *names) {
262 std::unique_ptr<VideoCaptureDevice> device = 305 std::unique_ptr<VideoCaptureDevice> device =
263 video_capture_device_factory_->Create(names_iterator); 306 video_capture_device_factory_->Create(names_iterator);
264 ASSERT_TRUE(device); 307 ASSERT_TRUE(device);
(...skipping 11 matching lines...) Expand all
276 } 319 }
277 } 320 }
278 321
279 INSTANTIATE_TEST_CASE_P(, 322 INSTANTIATE_TEST_CASE_P(,
280 FakeVideoCaptureDeviceCommandLineTest, 323 FakeVideoCaptureDeviceCommandLineTest,
281 Values(CommandLineTestData{"fps=-1", 5}, 324 Values(CommandLineTestData{"fps=-1", 5},
282 CommandLineTestData{"fps=29.97", 29.97f}, 325 CommandLineTestData{"fps=29.97", 29.97f},
283 CommandLineTestData{"fps=60", 60}, 326 CommandLineTestData{"fps=60", 60},
284 CommandLineTestData{"fps=1000", 60})); 327 CommandLineTestData{"fps=1000", 60}));
285 }; // namespace media 328 }; // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698