OLD | NEW |
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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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> { | 135 class PhotoTakenListener : public base::RefCounted<PhotoTakenListener> { |
136 public: | 136 public: |
137 MOCK_METHOD0(OnCorrectPhotoTaken, void(void)); | 137 MOCK_METHOD0(OnCorrectPhotoTaken, void(void)); |
138 // GMock doesn't support move-only arguments, so we use this forward method. | 138 // GMock doesn't support move-only arguments, so we use this forward method. |
139 void DoOnPhotoTaken(const std::string& mime_type, | 139 void DoOnPhotoTaken(const mojo::String& mime_type, |
140 std::unique_ptr<std::vector<uint8_t>> data) { | 140 mojo::Array<uint8_t> data) { |
141 // Only PNG images are supported right now. | 141 // Only PNG images are supported right now. |
142 EXPECT_STREQ("image/png", mime_type.c_str()); | 142 EXPECT_STREQ("image/png", mime_type.storage().c_str()); |
143 // Not worth decoding the incoming data. Just check that the header is PNG. | 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 | 144 // http://www.libpng.org/pub/png/spec/1.2/PNG-Rationale.html#R.PNG-file-sign
ature |
145 ASSERT_GT(data->size(), 4u); | 145 ASSERT_GT(data.size(), 4u); |
146 EXPECT_EQ('P', data->data()[1]); | 146 EXPECT_EQ('P', data[1]); |
147 EXPECT_EQ('N', data->data()[2]); | 147 EXPECT_EQ('N', data[2]); |
148 EXPECT_EQ('G', data->data()[3]); | 148 EXPECT_EQ('G', data[3]); |
149 OnCorrectPhotoTaken(); | 149 OnCorrectPhotoTaken(); |
150 } | 150 } |
| 151 MOCK_METHOD1(OnTakePhotoFailure, |
| 152 void(const VideoCaptureDevice::TakePhotoCallback&)); |
151 | 153 |
152 private: | 154 private: |
153 friend class base::RefCounted<PhotoTakenListener>; | 155 friend class base::RefCounted<PhotoTakenListener>; |
154 virtual ~PhotoTakenListener() {} | 156 virtual ~PhotoTakenListener() {} |
155 }; | 157 }; |
156 | 158 |
157 } // namespace | 159 } // namespace |
158 | 160 |
159 class FakeVideoCaptureDeviceBase : public ::testing::Test { | 161 class FakeVideoCaptureDeviceBase : public ::testing::Test { |
160 protected: | 162 protected: |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 TEST_F(FakeVideoCaptureDeviceTest, TakePhoto) { | 280 TEST_F(FakeVideoCaptureDeviceTest, TakePhoto) { |
279 std::unique_ptr<VideoCaptureDevice> device(new FakeVideoCaptureDevice( | 281 std::unique_ptr<VideoCaptureDevice> device(new FakeVideoCaptureDevice( |
280 FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS, 30.0)); | 282 FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS, 30.0)); |
281 ASSERT_TRUE(device); | 283 ASSERT_TRUE(device); |
282 | 284 |
283 VideoCaptureParams capture_params; | 285 VideoCaptureParams capture_params; |
284 capture_params.requested_format.frame_size.SetSize(640, 480); | 286 capture_params.requested_format.frame_size.SetSize(640, 480); |
285 capture_params.requested_format.frame_rate = 30.0; | 287 capture_params.requested_format.frame_rate = 30.0; |
286 device->AllocateAndStart(capture_params, std::move(client_)); | 288 device->AllocateAndStart(capture_params, std::move(client_)); |
287 | 289 |
288 const VideoCaptureDevice::TakePhotoCallback photo_callback = | 290 ScopedCallback<VideoCaptureDevice::TakePhotoCallback> scoped_callback( |
289 base::Bind(&PhotoTakenListener::DoOnPhotoTaken, photo_taken_listener_); | 291 base::Bind(&PhotoTakenListener::DoOnPhotoTaken, photo_taken_listener_), |
| 292 base::Bind(&PhotoTakenListener::OnTakePhotoFailure, |
| 293 photo_taken_listener_)); |
| 294 |
290 EXPECT_CALL(*photo_taken_listener_.get(), OnCorrectPhotoTaken()).Times(1); | 295 EXPECT_CALL(*photo_taken_listener_.get(), OnCorrectPhotoTaken()).Times(1); |
291 ASSERT_TRUE(device->TakePhoto(photo_callback)); | 296 device->TakePhoto(std::move(scoped_callback)); |
292 | 297 |
293 run_loop_.reset(new base::RunLoop()); | 298 run_loop_.reset(new base::RunLoop()); |
294 run_loop_->Run(); | 299 run_loop_->Run(); |
295 device->StopAndDeAllocate(); | 300 device->StopAndDeAllocate(); |
296 } | 301 } |
297 | 302 |
298 TEST_P(FakeVideoCaptureDeviceCommandLineTest, FrameRate) { | 303 TEST_P(FakeVideoCaptureDeviceCommandLineTest, FrameRate) { |
299 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 304 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
300 switches::kUseFakeDeviceForMediaStream, GetParam().argument); | 305 switches::kUseFakeDeviceForMediaStream, GetParam().argument); |
301 const std::unique_ptr<VideoCaptureDevice::Names> names(EnumerateDevices()); | 306 const std::unique_ptr<VideoCaptureDevice::Names> names(EnumerateDevices()); |
(...skipping 17 matching lines...) Expand all Loading... |
319 } | 324 } |
320 } | 325 } |
321 | 326 |
322 INSTANTIATE_TEST_CASE_P(, | 327 INSTANTIATE_TEST_CASE_P(, |
323 FakeVideoCaptureDeviceCommandLineTest, | 328 FakeVideoCaptureDeviceCommandLineTest, |
324 Values(CommandLineTestData{"fps=-1", 5}, | 329 Values(CommandLineTestData{"fps=-1", 5}, |
325 CommandLineTestData{"fps=29.97", 29.97f}, | 330 CommandLineTestData{"fps=29.97", 29.97f}, |
326 CommandLineTestData{"fps=60", 60}, | 331 CommandLineTestData{"fps=60", 60}, |
327 CommandLineTestData{"fps=1000", 60})); | 332 CommandLineTestData{"fps=1000", 60})); |
328 }; // namespace media | 333 }; // namespace media |
OLD | NEW |