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