Index: media/capture/video/fake_video_capture_device_unittest.cc |
diff --git a/media/capture/video/fake_video_capture_device_unittest.cc b/media/capture/video/fake_video_capture_device_unittest.cc |
index 417a6be580cebdb3e9b34c584e07ff2ec0314a81..b0694cbdaa2818a3e06f59794f6c78fb318f3dce 100644 |
--- a/media/capture/video/fake_video_capture_device_unittest.cc |
+++ b/media/capture/video/fake_video_capture_device_unittest.cc |
@@ -23,6 +23,7 @@ |
#include "media/capture/video/video_capture_device.h" |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+#include "ui/gfx/codec/png_codec.h" |
using ::testing::_; |
using ::testing::Bool; |
@@ -132,6 +133,32 @@ class DeviceEnumerationListener |
virtual ~DeviceEnumerationListener() {} |
}; |
+class PhotoTakenListener : public base::RefCounted<PhotoTakenListener> { |
+ public: |
+ MOCK_METHOD0(OnCorrectPhotoTaken, void(void)); |
+ // GMock doesn't support move-only arguments, so we use this forward method. |
+ void DoOnPhotoTaken(const std::string& mime_type, |
+ std::unique_ptr<std::vector<uint8_t>> data) { |
+ // Only PNG images are supported right now. |
+ EXPECT_STREQ("image/png", mime_type.c_str()); |
+ |
+ std::vector<unsigned char> decoded; |
+ int width, height; |
+ ASSERT_TRUE(gfx::PNGCodec::Decode(data->data(), data->size(), |
miu
2016/05/05 22:04:24
Your call, but it feels a bit heavyweight for the
mcasas
2016/05/05 23:05:50
Done.
|
+ gfx::PNGCodec::FORMAT_RGB, &decoded, |
+ &width, &height)); |
+ |
+ EXPECT_GT(decoded.size(), 0u); |
+ EXPECT_GT(width, 0); |
+ EXPECT_GT(height, 0); |
+ OnCorrectPhotoTaken(); |
+ } |
+ |
+ private: |
+ friend class base::RefCounted<PhotoTakenListener>; |
+ virtual ~PhotoTakenListener() {} |
+}; |
+ |
} // namespace |
class FakeVideoCaptureDeviceBase : public ::testing::Test { |
@@ -141,9 +168,9 @@ class FakeVideoCaptureDeviceBase : public ::testing::Test { |
client_(new MockClient( |
base::Bind(&FakeVideoCaptureDeviceBase::OnFrameCaptured, |
base::Unretained(this)))), |
- video_capture_device_factory_(new FakeVideoCaptureDeviceFactory()) { |
- device_enumeration_listener_ = new DeviceEnumerationListener(); |
- } |
+ device_enumeration_listener_(new DeviceEnumerationListener()), |
+ photo_taken_listener_(new PhotoTakenListener()), |
+ video_capture_device_factory_(new FakeVideoCaptureDeviceFactory()) {} |
void SetUp() override { EXPECT_CALL(*client_, OnError(_, _)).Times(0); } |
@@ -175,7 +202,8 @@ class FakeVideoCaptureDeviceBase : public ::testing::Test { |
const std::unique_ptr<base::MessageLoop> loop_; |
std::unique_ptr<base::RunLoop> run_loop_; |
std::unique_ptr<MockClient> client_; |
- scoped_refptr<DeviceEnumerationListener> device_enumeration_listener_; |
+ const scoped_refptr<DeviceEnumerationListener> device_enumeration_listener_; |
+ const scoped_refptr<PhotoTakenListener> photo_taken_listener_; |
VideoCaptureFormat last_format_; |
const std::unique_ptr<VideoCaptureDeviceFactory> |
video_capture_device_factory_; |
@@ -252,6 +280,26 @@ TEST_F(FakeVideoCaptureDeviceTest, GetDeviceSupportedFormats) { |
} |
} |
+TEST_F(FakeVideoCaptureDeviceTest, TakePhoto) { |
+ std::unique_ptr<VideoCaptureDevice> device(new FakeVideoCaptureDevice( |
+ FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS, 30.0)); |
+ ASSERT_TRUE(device); |
+ |
+ VideoCaptureParams capture_params; |
+ capture_params.requested_format.frame_size.SetSize(640, 480); |
+ capture_params.requested_format.frame_rate = 30.0; |
+ device->AllocateAndStart(capture_params, std::move(client_)); |
+ |
+ const VideoCaptureDevice::TakePhotoCallback photo_callback = |
+ base::Bind(&PhotoTakenListener::DoOnPhotoTaken, photo_taken_listener_); |
+ EXPECT_CALL(*photo_taken_listener_.get(), OnCorrectPhotoTaken()).Times(1); |
+ ASSERT_TRUE(device->TakePhoto(photo_callback)); |
+ |
+ run_loop_.reset(new base::RunLoop()); |
+ run_loop_->Run(); |
+ device->StopAndDeAllocate(); |
+} |
+ |
TEST_P(FakeVideoCaptureDeviceCommandLineTest, FrameRate) { |
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
switches::kUseFakeDeviceForMediaStream, GetParam().argument); |