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> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
17 #include "base/test/test_timeouts.h" | 17 #include "base/test/test_timeouts.h" |
18 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
20 #include "media/base/media_switches.h" | 20 #include "media/base/media_switches.h" |
21 #include "media/base/video_capture_types.h" | 21 #include "media/base/video_capture_types.h" |
22 #include "media/capture/video/fake_video_capture_device_factory.h" | 22 #include "media/capture/video/fake_video_capture_device_factory.h" |
23 #include "media/capture/video/video_capture_device.h" | 23 #include "media/capture/video/video_capture_device.h" |
| 24 #include "mojo/public/cpp/bindings/string.h" |
24 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
26 | 27 |
27 using ::testing::_; | 28 using ::testing::_; |
28 using ::testing::Bool; | 29 using ::testing::Bool; |
29 using ::testing::Combine; | 30 using ::testing::Combine; |
30 using ::testing::SaveArg; | 31 using ::testing::SaveArg; |
31 using ::testing::Values; | 32 using ::testing::Values; |
32 | 33 |
33 namespace media { | 34 namespace media { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 | 132 |
132 private: | 133 private: |
133 friend class base::RefCounted<DeviceEnumerationListener>; | 134 friend class base::RefCounted<DeviceEnumerationListener>; |
134 virtual ~DeviceEnumerationListener() {} | 135 virtual ~DeviceEnumerationListener() {} |
135 }; | 136 }; |
136 | 137 |
137 class PhotoTakenListener : public base::RefCounted<PhotoTakenListener> { | 138 class PhotoTakenListener : public base::RefCounted<PhotoTakenListener> { |
138 public: | 139 public: |
139 MOCK_METHOD0(OnCorrectPhotoTaken, void(void)); | 140 MOCK_METHOD0(OnCorrectPhotoTaken, void(void)); |
140 // GMock doesn't support move-only arguments, so we use this forward method. | 141 // GMock doesn't support move-only arguments, so we use this forward method. |
141 void DoOnPhotoTaken(const std::string& mime_type, | 142 void DoOnPhotoTaken(const mojo::String& mime_type, |
142 std::unique_ptr<std::vector<uint8_t>> data) { | 143 mojo::Array<uint8_t> data) { |
143 // Only PNG images are supported right now. | 144 // Only PNG images are supported right now. |
144 EXPECT_STREQ("image/png", mime_type.c_str()); | 145 EXPECT_STREQ("image/png", mime_type.storage().c_str()); |
145 // Not worth decoding the incoming data. Just check that the header is PNG. | 146 // Not worth decoding the incoming data. Just check that the header is PNG. |
146 // http://www.libpng.org/pub/png/spec/1.2/PNG-Rationale.html#R.PNG-file-sign
ature | 147 // http://www.libpng.org/pub/png/spec/1.2/PNG-Rationale.html#R.PNG-file-sign
ature |
147 ASSERT_GT(data->size(), 4u); | 148 ASSERT_GT(data.size(), 4u); |
148 EXPECT_EQ('P', data->data()[1]); | 149 EXPECT_EQ('P', data[1]); |
149 EXPECT_EQ('N', data->data()[2]); | 150 EXPECT_EQ('N', data[2]); |
150 EXPECT_EQ('G', data->data()[3]); | 151 EXPECT_EQ('G', data[3]); |
151 OnCorrectPhotoTaken(); | 152 OnCorrectPhotoTaken(); |
152 } | 153 } |
| 154 MOCK_METHOD1(OnTakePhotoFailure, |
| 155 void(const VideoCaptureDevice::TakePhotoCallback&)); |
153 | 156 |
154 private: | 157 private: |
155 friend class base::RefCounted<PhotoTakenListener>; | 158 friend class base::RefCounted<PhotoTakenListener>; |
156 virtual ~PhotoTakenListener() {} | 159 virtual ~PhotoTakenListener() {} |
157 }; | 160 }; |
158 | 161 |
159 } // namespace | 162 } // namespace |
160 | 163 |
161 class FakeVideoCaptureDeviceBase : public ::testing::Test { | 164 class FakeVideoCaptureDeviceBase : public ::testing::Test { |
162 protected: | 165 protected: |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 TEST_F(FakeVideoCaptureDeviceTest, TakePhoto) { | 283 TEST_F(FakeVideoCaptureDeviceTest, TakePhoto) { |
281 std::unique_ptr<VideoCaptureDevice> device(new FakeVideoCaptureDevice( | 284 std::unique_ptr<VideoCaptureDevice> device(new FakeVideoCaptureDevice( |
282 FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS, 30.0)); | 285 FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS, 30.0)); |
283 ASSERT_TRUE(device); | 286 ASSERT_TRUE(device); |
284 | 287 |
285 VideoCaptureParams capture_params; | 288 VideoCaptureParams capture_params; |
286 capture_params.requested_format.frame_size.SetSize(640, 480); | 289 capture_params.requested_format.frame_size.SetSize(640, 480); |
287 capture_params.requested_format.frame_rate = 30.0; | 290 capture_params.requested_format.frame_rate = 30.0; |
288 device->AllocateAndStart(capture_params, std::move(client_)); | 291 device->AllocateAndStart(capture_params, std::move(client_)); |
289 | 292 |
290 const VideoCaptureDevice::TakePhotoCallback photo_callback = | 293 ScopedResultCallback<VideoCaptureDevice::TakePhotoCallback> scoped_callback( |
291 base::Bind(&PhotoTakenListener::DoOnPhotoTaken, photo_taken_listener_); | 294 base::Bind(&PhotoTakenListener::DoOnPhotoTaken, photo_taken_listener_), |
| 295 base::Bind(&PhotoTakenListener::OnTakePhotoFailure, |
| 296 photo_taken_listener_)); |
| 297 |
292 EXPECT_CALL(*photo_taken_listener_.get(), OnCorrectPhotoTaken()).Times(1); | 298 EXPECT_CALL(*photo_taken_listener_.get(), OnCorrectPhotoTaken()).Times(1); |
293 ASSERT_TRUE(device->TakePhoto(photo_callback)); | 299 device->TakePhoto(std::move(scoped_callback)); |
294 | 300 |
295 run_loop_.reset(new base::RunLoop()); | 301 run_loop_.reset(new base::RunLoop()); |
296 run_loop_->Run(); | 302 run_loop_->Run(); |
297 device->StopAndDeAllocate(); | 303 device->StopAndDeAllocate(); |
298 } | 304 } |
299 | 305 |
300 TEST_P(FakeVideoCaptureDeviceCommandLineTest, FrameRate) { | 306 TEST_P(FakeVideoCaptureDeviceCommandLineTest, FrameRate) { |
301 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 307 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
302 switches::kUseFakeDeviceForMediaStream, GetParam().argument); | 308 switches::kUseFakeDeviceForMediaStream, GetParam().argument); |
303 const std::unique_ptr<VideoCaptureDevice::Names> names(EnumerateDevices()); | 309 const std::unique_ptr<VideoCaptureDevice::Names> names(EnumerateDevices()); |
(...skipping 17 matching lines...) Expand all Loading... |
321 } | 327 } |
322 } | 328 } |
323 | 329 |
324 INSTANTIATE_TEST_CASE_P(, | 330 INSTANTIATE_TEST_CASE_P(, |
325 FakeVideoCaptureDeviceCommandLineTest, | 331 FakeVideoCaptureDeviceCommandLineTest, |
326 Values(CommandLineTestData{"fps=-1", 5}, | 332 Values(CommandLineTestData{"fps=-1", 5}, |
327 CommandLineTestData{"fps=29.97", 29.97f}, | 333 CommandLineTestData{"fps=29.97", 29.97f}, |
328 CommandLineTestData{"fps=60", 60}, | 334 CommandLineTestData{"fps=60", 60}, |
329 CommandLineTestData{"fps=1000", 60})); | 335 CommandLineTestData{"fps=1000", 60})); |
330 }; // namespace media | 336 }; // namespace media |
OLD | NEW |