| Index: media/capture/service/video_capture_stream_impl_unittest.cc
|
| diff --git a/media/capture/service/video_capture_stream_impl_unittest.cc b/media/capture/service/video_capture_stream_impl_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e67dacf7dabd09d413aa7aac42e6b63bcc9f534b
|
| --- /dev/null
|
| +++ b/media/capture/service/video_capture_stream_impl_unittest.cc
|
| @@ -0,0 +1,143 @@
|
| +// 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 "media/capture/service/mock_video_capture_stream_client.h"
|
| +#include "media/capture/service/video_capture_stream_impl.h"
|
| +#include "media/mojo/common/mojo_shared_buffer_video_frame.h"
|
| +#include "mojo/public/cpp/system/buffer.h"
|
| +#include "testing/gmock/include/gmock/gmock.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +using ::testing::_;
|
| +using ::testing::AllOf;
|
| +using ::testing::InSequence;
|
| +using ::testing::Field;
|
| +using ::testing::Property;
|
| +
|
| +namespace media {
|
| +
|
| +namespace {
|
| +
|
| +ACTION_P(RunClosure, closure) {
|
| + closure.Run();
|
| +}
|
| +
|
| +} // anonymous namespace
|
| +
|
| +class VideoCaptureStreamImplTest : public testing::Test {
|
| + public:
|
| + VideoCaptureStreamImplTest()
|
| + : video_capture_stream_impl_(new VideoCaptureStreamImpl(
|
| + mojo::GetProxy(&stream_ptr_),
|
| + base::Bind(&VideoCaptureStreamImplTest::StopCallback,
|
| + base::Unretained(this)),
|
| + base::Bind(&VideoCaptureStreamImplTest::ErrorCallback,
|
| + base::Unretained(this)))) {}
|
| +
|
| + void SetUp() override {}
|
| + void TearDown() override {}
|
| +
|
| + MOCK_METHOD0(StopCallback, void());
|
| + MOCK_METHOD0(ErrorCallback, void());
|
| + MOCK_METHOD0(OnRelease, void());
|
| +
|
| + void OnFrame(const scoped_refptr<MojoSharedBufferVideoFrame>& frame,
|
| + const base::TimeTicks& timestamp) {
|
| + video_capture_stream_impl_->OnFrame(frame, timestamp);
|
| + }
|
| + void OnError(const std::string& reason) {
|
| + video_capture_stream_impl_->OnError(reason);
|
| + }
|
| +
|
| + void CreateClientAndStart() {
|
| + mojom::VideoCaptureStreamClientPtr le_client =
|
| + stream_client_impl_.CreateProxy();
|
| + video_capture_stream_impl_->Start(std::move(le_client));
|
| + }
|
| +
|
| + protected:
|
| + // This is needed for the Binding's Router's HandleWatcher :)
|
| + const base::MessageLoop loop_;
|
| +
|
| + mojom::VideoCaptureStreamPtr stream_ptr_;
|
| + // The class under test.
|
| + const scoped_ptr<VideoCaptureStreamImpl> video_capture_stream_impl_;
|
| +
|
| + // The mock of the (remote) video capture client.
|
| + MockVideoCaptureStreamClient stream_client_impl_;
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(VideoCaptureStreamImplTest);
|
| +};
|
| +
|
| +TEST_F(VideoCaptureStreamImplTest, CreateAndStartAndDestroy) {
|
| + CreateClientAndStart();
|
| +}
|
| +
|
| +// Tests the connection
|
| +// OnFrame() --> (NotifyOnFrameAvailable()) --> client's FrameAvailable().
|
| +TEST_F(VideoCaptureStreamImplTest, OnFramePingsOnFrameAvailable) {
|
| + InSequence s;
|
| + CreateClientAndStart();
|
| +
|
| + const gfx::Size kFrameSize(10, 10);
|
| + const scoped_refptr<MojoSharedBufferVideoFrame> le_frame =
|
| + MojoSharedBufferVideoFrame::CreateDefaultI420(kFrameSize,
|
| + base::TimeDelta());
|
| + le_frame->AddDestructionObserver(base::Bind(
|
| + &VideoCaptureStreamImplTest::OnRelease, base::Unretained(this)));
|
| + const base::TimeTicks now = base::TimeTicks::Now();
|
| +
|
| + base::RunLoop run_loop;
|
| + base::Closure quit_closure = run_loop.QuitClosure();
|
| + EXPECT_CALL(
|
| + stream_client_impl_,
|
| + DoOnFrameAvailable(
|
| + AllOf(Field(&mojom::FrameInfo::storage_size, le_frame->mapped_size()),
|
| + Field(&mojom::FrameInfo::pixel_format,
|
| + static_cast<media::interfaces::VideoFormat>(
|
| + le_frame->format())),
|
| + Field(&mojom::FrameInfo::timestamp, now.ToInternalValue())),
|
| + _))
|
| + .Times(1)
|
| + .WillOnce(RunClosure(quit_closure));
|
| + EXPECT_CALL(*this, OnRelease()).Times(1);
|
| +
|
| + OnFrame(le_frame, now);
|
| + run_loop.Run();
|
| +}
|
| +
|
| +// Tests the connection
|
| +// OnError() --> (NotifyError()) --> client's and owners' Error().
|
| +TEST_F(VideoCaptureStreamImplTest, OnErrorPingsError) {
|
| + InSequence s;
|
| + CreateClientAndStart();
|
| +
|
| + const std::string kErrorMessage("big error!");
|
| + base::RunLoop run_loop;
|
| + base::Closure quit_closure = run_loop.QuitClosure();
|
| +
|
| + EXPECT_CALL(*this, ErrorCallback()).Times(1);
|
| + EXPECT_CALL(
|
| + stream_client_impl_,
|
| + OnError(Property(&mojo::String::To<std::string>, kErrorMessage.c_str())))
|
| + .Times(1)
|
| + .WillOnce(RunClosure(quit_closure));
|
| + OnError(kErrorMessage);
|
| + run_loop.Run();
|
| +}
|
| +
|
| +// Tests the connection Stop() --> Stop Callback.
|
| +TEST_F(VideoCaptureStreamImplTest, StopPingsStopCallback) {
|
| + CreateClientAndStart();
|
| +
|
| + EXPECT_CALL(*this, ErrorCallback()).Times(0);
|
| + EXPECT_CALL(*this, StopCallback()).Times(1);
|
| + video_capture_stream_impl_->Stop();
|
| + base::RunLoop().RunUntilIdle();
|
| +}
|
| +
|
| +} // namespace media
|
|
|