| Index: components/video_capture/device_client_impl_unittest.cc
|
| diff --git a/components/video_capture/device_client_impl_unittest.cc b/components/video_capture/device_client_impl_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..93602e23e688a310d7352f4dc99e8b40ff1f4a7e
|
| --- /dev/null
|
| +++ b/components/video_capture/device_client_impl_unittest.cc
|
| @@ -0,0 +1,161 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/run_loop.h"
|
| +#include "components/video_capture/device_client_impl.h"
|
| +#include "media/base/video_frame.h"
|
| +#include "testing/gmock/include/gmock/gmock.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +using ::testing::_;
|
| +using ::testing::InSequence;
|
| +using ::testing::SaveArg;
|
| +
|
| +namespace video_capture {
|
| +
|
| +class DeviceClientImplTest : public testing::Test,
|
| + public DeviceClientImpl::Delegate {
|
| + public:
|
| + DeviceClientImplTest() : device_client_impl_(this) {}
|
| +
|
| + void SetUp() override {}
|
| + void TearDown() override {}
|
| +
|
| + // DeviceClientImpl::Delegate
|
| + MOCK_METHOD3(OnFrame,
|
| + void(const scoped_refptr<media::VideoFrame>& frame,
|
| + const base::TimeTicks& timestamp,
|
| + const base::Closure& release_callback));
|
| + MOCK_METHOD1(OnError, void(const std::string& reason));
|
| +
|
| + void OnIncomingCapturedData(const uint8_t* data,
|
| + int length,
|
| + const media::VideoCaptureFormat& frame_format,
|
| + int clockwise_rotation,
|
| + const base::TimeTicks& timestamp) {
|
| + device_client_impl_.OnIncomingCapturedData(data, length, frame_format,
|
| + clockwise_rotation, timestamp);
|
| + }
|
| + void OnError(const tracked_objects::Location& from_here,
|
| + const std::string& reason) {
|
| + device_client_impl_.OnError(from_here, reason);
|
| + }
|
| + protected:
|
| + base::MessageLoop loop_;
|
| +
|
| + // The mock of the (remote) video capture client.
|
| + DeviceClientImpl device_client_impl_;
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(DeviceClientImplTest);
|
| +};
|
| +
|
| +TEST_F(DeviceClientImplTest, CreateAndDestroy) {
|
| +}
|
| +
|
| +// Tests that OnError is correctly forwarded.
|
| +TEST_F(DeviceClientImplTest, OnError) {
|
| + const std::string kBigError("Kaiju-size error");
|
| + EXPECT_CALL(*this, OnError(kBigError)).Times(1);
|
| + OnError(FROM_HERE, kBigError);
|
| + base::RunLoop().RunUntilIdle();
|
| +}
|
| +
|
| +// Tests that buffer-based capture API accepts all memory-backed pixel formats.
|
| +// Same as VideoCaptureDeviceClientTest's homonym test case.
|
| +TEST_F(DeviceClientImplTest, DataCaptureInEachVideoFormatInSequence) {
|
| + // The usual ReserveOutputBuffer() -> OnIncomingCapturedVideoFrame() cannot
|
| + // be used since it does not accept all pixel formats. The memory backed
|
| + // buffer OnIncomingCapturedData() is used instead, with a dummy scratchpad
|
| + // buffer.
|
| + const size_t kScratchpadSizeInBytes = 400;
|
| + unsigned char data[kScratchpadSizeInBytes] = {};
|
| + const gfx::Size capture_resolution(10, 10);
|
| + ASSERT_GE(kScratchpadSizeInBytes, capture_resolution.GetArea() * 4u)
|
| + << "Scratchpad is too small to hold the largest pixel format (ARGB).";
|
| +
|
| + for (int format = 0; format < media::PIXEL_FORMAT_MAX; ++format) {
|
| + // Conversion from some formats are unsupported.
|
| + if (format == media::PIXEL_FORMAT_UNKNOWN ||
|
| + format == media::PIXEL_FORMAT_YV16 ||
|
| + format == media::PIXEL_FORMAT_YV12A ||
|
| + format == media::PIXEL_FORMAT_YV24 ||
|
| + format == media::PIXEL_FORMAT_ARGB ||
|
| + format == media::PIXEL_FORMAT_XRGB ||
|
| + format == media::PIXEL_FORMAT_MJPEG ||
|
| + format == media::PIXEL_FORMAT_MT21) {
|
| + continue;
|
| + }
|
| +#if !defined(OS_LINUX) && !defined(OS_WIN)
|
| + if (format == media::PIXEL_FORMAT_RGB24){
|
| + continue;
|
| + }
|
| +#endif
|
| + media::VideoCaptureParams params;
|
| + params.requested_format = media::VideoCaptureFormat(
|
| + capture_resolution, 30.0f, media::VideoPixelFormat(format));
|
| +
|
| + EXPECT_CALL(*this, OnFrame(_, _, _)).Times(1);
|
| + OnIncomingCapturedData(data, params.requested_format.ImageAllocationSize(),
|
| + params.requested_format, 0 /* clockwise_rotation */,
|
| + base::TimeTicks());
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| + }
|
| +}
|
| +
|
| +// Test that we receive the expected resolution for a given captured frame
|
| +// resolution and rotation. Odd resolutions are also cropped.
|
| +// Same as VideoCaptureDeviceClientTest's homonym test case.
|
| +TEST_F(DeviceClientImplTest, CheckRotationsAndCrops) {
|
| + const struct SizeAndRotation {
|
| + gfx::Size input_resolution;
|
| + int rotation;
|
| + gfx::Size output_resolution;
|
| + } kSizeAndRotations[] = {{{6, 4}, 0, {6, 4}},
|
| + {{6, 4}, 90, {4, 6}},
|
| + {{6, 4}, 180, {6, 4}},
|
| + {{6, 4}, 270, {4, 6}},
|
| + {{7, 4}, 0, {6, 4}},
|
| + {{7, 4}, 90, {4, 6}},
|
| + {{7, 4}, 180, {6, 4}},
|
| + {{7, 4}, 270, {4, 6}}};
|
| +
|
| + // The usual ReserveOutputBuffer() -> OnIncomingCapturedVideoFrame() cannot
|
| + // be used since it does not resolve rotations or crops. The memory backed
|
| + // buffer OnIncomingCapturedData() is used instead, with a dummy scratchpad
|
| + // buffer.
|
| + const size_t kScratchpadSizeInBytes = 400;
|
| + unsigned char data[kScratchpadSizeInBytes] = {};
|
| +
|
| + media::VideoCaptureParams params;
|
| + for (const auto& size_and_rotation : kSizeAndRotations) {
|
| + ASSERT_GE(kScratchpadSizeInBytes,
|
| + size_and_rotation.input_resolution.GetArea() * 4u)
|
| + << "Scratchpad is too small to hold the largest pixel format (ARGB).";
|
| + params.requested_format =
|
| + media::VideoCaptureFormat(size_and_rotation.input_resolution, 30.0f,
|
| + media::PIXEL_FORMAT_ARGB);
|
| +
|
| + scoped_refptr<media::VideoFrame> frame;
|
| + const base::TimeTicks now = base::TimeTicks::Now();
|
| + EXPECT_CALL(*this, OnFrame(_, now, _))
|
| + .Times(1)
|
| + .WillOnce(SaveArg<0>(&frame));
|
| + OnIncomingCapturedData(data, params.requested_format.ImageAllocationSize(),
|
| + params.requested_format, size_and_rotation.rotation,
|
| + now);
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| + EXPECT_EQ(frame->coded_size().width(),
|
| + size_and_rotation.output_resolution.width());
|
| + EXPECT_EQ(frame->coded_size().height(),
|
| + size_and_rotation.output_resolution.height());
|
| +
|
| + }
|
| +}
|
| +
|
| +
|
| +} // namespace video_capture
|
|
|