diff options
author | dalecurtis <dalecurtis@chromium.org> | 2015-06-09 11:38:14 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-09 18:39:03 +0000 |
commit | b839664368dfd6985422123e98fcbea4562b838f (patch) | |
tree | cec289c428aaeecd004e29976aa6a989a1117956 | |
parent | 4b518e9671a8de323a808a0bfccc57f3c2d4c115 (diff) | |
download | chromium_src-b839664368dfd6985422123e98fcbea4562b838f.zip chromium_src-b839664368dfd6985422123e98fcbea4562b838f.tar.gz chromium_src-b839664368dfd6985422123e98fcbea4562b838f.tar.bz2 |
Add unittest for VideoFrameProviderClientImpl.
Class was woefully lacking in tests, coverage added! \o/
BUG=none
TEST=new unittest!
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel
Review URL: https://codereview.chromium.org/1161513009
Cr-Commit-Position: refs/heads/master@{#333539}
-rw-r--r-- | cc/BUILD.gn | 1 | ||||
-rw-r--r-- | cc/cc_tests.gyp | 1 | ||||
-rw-r--r-- | cc/layers/video_frame_provider_client_impl.h | 4 | ||||
-rw-r--r-- | cc/layers/video_frame_provider_client_impl_unittest.cc | 167 | ||||
-rw-r--r-- | cc/test/fake_video_frame_provider.cc | 9 | ||||
-rw-r--r-- | cc/test/fake_video_frame_provider.h | 5 |
6 files changed, 184 insertions, 3 deletions
diff --git a/cc/BUILD.gn b/cc/BUILD.gn index 22df7d0..4f0a5ca5 100644 --- a/cc/BUILD.gn +++ b/cc/BUILD.gn @@ -791,6 +791,7 @@ test("cc_unittests") { "layers/tiled_layer_unittest.cc", "layers/ui_resource_layer_impl_unittest.cc", "layers/ui_resource_layer_unittest.cc", + "layers/video_frame_provider_client_impl_unittest.cc", "layers/video_layer_impl_unittest.cc", "output/begin_frame_args_unittest.cc", "output/delegating_renderer_unittest.cc", diff --git a/cc/cc_tests.gyp b/cc/cc_tests.gyp index c1e456a..5d013f4 100644 --- a/cc/cc_tests.gyp +++ b/cc/cc_tests.gyp @@ -62,6 +62,7 @@ 'layers/tiled_layer_unittest.cc', 'layers/ui_resource_layer_impl_unittest.cc', 'layers/ui_resource_layer_unittest.cc', + 'layers/video_frame_provider_client_impl_unittest.cc', 'layers/video_layer_impl_unittest.cc', 'output/begin_frame_args_unittest.cc', 'output/bsp_tree_unittest.cc', diff --git a/cc/layers/video_frame_provider_client_impl.h b/cc/layers/video_frame_provider_client_impl.h index 5429228..e626b54 100644 --- a/cc/layers/video_frame_provider_client_impl.h +++ b/cc/layers/video_frame_provider_client_impl.h @@ -59,6 +59,10 @@ class CC_EXPORT VideoFrameProviderClientImpl void DidReceiveFrame() override; void DidUpdateMatrix(const float* matrix) override; + const VideoFrameProvider* get_provider_for_testing() const { + return provider_; + } + private: friend class base::RefCounted<VideoFrameProviderClientImpl>; diff --git a/cc/layers/video_frame_provider_client_impl_unittest.cc b/cc/layers/video_frame_provider_client_impl_unittest.cc new file mode 100644 index 0000000..f2f2c0d --- /dev/null +++ b/cc/layers/video_frame_provider_client_impl_unittest.cc @@ -0,0 +1,167 @@ +// Copyright 2015 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 "cc/layers/video_frame_provider_client_impl.h" +#include "cc/layers/video_layer_impl.h" +#include "cc/output/begin_frame_args.h" +#include "cc/test/fake_video_frame_provider.h" +#include "cc/test/layer_test_common.h" +#include "media/base/video_frame.h" +#include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" + +using testing::_; + +namespace cc { + +// NOTE: We cannot use DebugScopedSetImplThreadAndMainThreadBlocked in these +// tests because it gets destroyed before the VideoLayerImpl is destroyed. This +// causes a DCHECK in VideoLayerImpl's destructor to fail. +static void DebugSetImplThreadAndMainThreadBlocked(Proxy* proxy) { +#if DCHECK_IS_ON() + proxy->SetCurrentThreadIsImplThread(true); + proxy->SetMainThreadBlocked(true); +#endif +} + +class VideoFrameProviderClientImplTest : public testing::Test, + public VideoFrameControllerClient { + public: + VideoFrameProviderClientImplTest() + : client_impl_(VideoFrameProviderClientImpl::Create(&provider_, this)), + video_layer_impl_(nullptr), + test_frame_(media::VideoFrame::CreateFrame(media::VideoFrame::YV12, + gfx::Size(10, 10), + gfx::Rect(10, 10), + gfx::Size(10, 10), + base::TimeDelta())) { + DebugSetImplThreadAndMainThreadBlocked(impl_.proxy()); + } + + ~VideoFrameProviderClientImplTest() { + if (!client_impl_->Stopped()) { + client_impl_->Stop(); + DCHECK(client_impl_->Stopped()); + DCHECK(!client_impl_->ActiveVideoLayer()); + } + + provider_.SetVideoFrameProviderClient(nullptr); + } + + void StartRendering() { + EXPECT_CALL(*this, AddVideoFrameController(_)); + client_impl_->StartRendering(); + } + + void StopRendering() { + EXPECT_CALL(*this, RemoveVideoFrameController(_)); + client_impl_->StopRendering(); + } + + void StartRenderingAndRenderFrame() { + EXPECT_FALSE(client_impl_->HasCurrentFrame()); + provider_.set_frame(test_frame_); + EXPECT_TRUE(client_impl_->HasCurrentFrame()); + + // Start rendering and verify SetNeedsRedraw() was called for the new frame. + StartRendering(); + EXPECT_EQ(gfx::Rect(), video_layer_impl_->update_rect()); + client_impl_->OnBeginFrame(BeginFrameArgs()); + EXPECT_NE(gfx::Rect(), video_layer_impl_->update_rect()); + } + + void CreateActiveVideoLayer() { + gfx::Size layer_size(100, 100); + video_layer_impl_ = impl_.AddChildToRoot<VideoLayerImpl>( + &provider_, media::VIDEO_ROTATION_0); + video_layer_impl_->SetBounds(layer_size); + video_layer_impl_->SetContentBounds(layer_size); + video_layer_impl_->SetDrawsContent(true); + client_impl_->SetActiveVideoLayer(video_layer_impl_); + ASSERT_TRUE(client_impl_->ActiveVideoLayer()); + } + + MOCK_METHOD1(AddVideoFrameController, void(VideoFrameController*)); + MOCK_METHOD1(RemoveVideoFrameController, void(VideoFrameController*)); + + protected: + FakeVideoFrameProvider provider_; + LayerTestCommon::LayerImplTest impl_; + scoped_refptr<VideoFrameProviderClientImpl> client_impl_; + VideoLayerImpl* video_layer_impl_; + scoped_refptr<media::VideoFrame> test_frame_; + + private: + DISALLOW_COPY_AND_ASSIGN(VideoFrameProviderClientImplTest); +}; + +TEST_F(VideoFrameProviderClientImplTest, StartStopRendering) { + StartRendering(); + StopRendering(); +} + +TEST_F(VideoFrameProviderClientImplTest, StopUsingProvider) { + ASSERT_TRUE(client_impl_->get_provider_for_testing()); + StartRendering(); + EXPECT_CALL(*this, RemoveVideoFrameController(_)); + client_impl_->StopUsingProvider(); + ASSERT_FALSE(client_impl_->get_provider_for_testing()); +} + +TEST_F(VideoFrameProviderClientImplTest, FrameAcquisition) { + CreateActiveVideoLayer(); + StartRenderingAndRenderFrame(); + + // Verify GetCurrentFrame() and PutCurrentFrame() work correctly. + EXPECT_EQ(test_frame_, client_impl_->AcquireLockAndCurrentFrame()); + EXPECT_EQ(0, provider_.put_current_frame_count()); + client_impl_->PutCurrentFrame(); + EXPECT_EQ(1, provider_.put_current_frame_count()); + + client_impl_->ReleaseLock(); + StopRendering(); +} + +TEST_F(VideoFrameProviderClientImplTest, DidReceiveFrame) { + CreateActiveVideoLayer(); + EXPECT_EQ(gfx::Rect(), video_layer_impl_->update_rect()); + client_impl_->DidReceiveFrame(); + EXPECT_NE(gfx::Rect(), video_layer_impl_->update_rect()); +} + +TEST_F(VideoFrameProviderClientImplTest, DidDrawFrameIssuesPutCurrentFrame) { + CreateActiveVideoLayer(); + StartRenderingAndRenderFrame(); + EXPECT_EQ(0, provider_.put_current_frame_count()); + client_impl_->DidDrawFrame(); + EXPECT_EQ(1, provider_.put_current_frame_count()); + StopRendering(); +} + +TEST_F(VideoFrameProviderClientImplTest, StreamTextureMatrix) { + const float kIdentityMatrix[] = { + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + }; + + EXPECT_FALSE(client_impl_->StreamTextureMatrix().IsIdentity()); + client_impl_->DidUpdateMatrix(kIdentityMatrix); + EXPECT_TRUE(client_impl_->StreamTextureMatrix().IsIdentity()); +} + +} // namespace cc diff --git a/cc/test/fake_video_frame_provider.cc b/cc/test/fake_video_frame_provider.cc index b979b0c..0145544 100644 --- a/cc/test/fake_video_frame_provider.cc +++ b/cc/test/fake_video_frame_provider.cc @@ -7,7 +7,8 @@ namespace cc { FakeVideoFrameProvider::FakeVideoFrameProvider() - : frame_(NULL), client_(NULL) {} + : frame_(NULL), client_(NULL), put_current_frame_count_(0) { +} FakeVideoFrameProvider::~FakeVideoFrameProvider() { if (client_) @@ -16,7 +17,7 @@ FakeVideoFrameProvider::~FakeVideoFrameProvider() { bool FakeVideoFrameProvider::UpdateCurrentFrame(base::TimeTicks deadline_min, base::TimeTicks deadline_max) { - return false; + return HasCurrentFrame(); } void FakeVideoFrameProvider::SetVideoFrameProviderClient(Client* client) { @@ -31,4 +32,8 @@ scoped_refptr<media::VideoFrame> FakeVideoFrameProvider::GetCurrentFrame() { return frame_; } +void FakeVideoFrameProvider::PutCurrentFrame() { + ++put_current_frame_count_; +} + } // namespace cc diff --git a/cc/test/fake_video_frame_provider.h b/cc/test/fake_video_frame_provider.h index da68d5b..4cbd80a 100644 --- a/cc/test/fake_video_frame_provider.h +++ b/cc/test/fake_video_frame_provider.h @@ -21,7 +21,7 @@ class FakeVideoFrameProvider : public VideoFrameProvider { base::TimeTicks deadline_max) override; bool HasCurrentFrame() override; scoped_refptr<media::VideoFrame> GetCurrentFrame() override; - void PutCurrentFrame() override {} + void PutCurrentFrame() override; Client* client() { return client_; } @@ -29,9 +29,12 @@ class FakeVideoFrameProvider : public VideoFrameProvider { frame_ = frame; } + int put_current_frame_count() const { return put_current_frame_count_; } + private: scoped_refptr<media::VideoFrame> frame_; Client* client_; + int put_current_frame_count_; }; } // namespace cc |