Delete unused downloads page asset.
[chromium-blink-merge.git] / cc / layers / video_frame_provider_client_impl_unittest.cc
blob4cbd493e0d54aa316e6c478c3ef8312489f6630e
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/layers/video_frame_provider_client_impl.h"
6 #include "cc/layers/video_layer_impl.h"
7 #include "cc/output/begin_frame_args.h"
8 #include "cc/test/fake_video_frame_provider.h"
9 #include "cc/test/layer_test_common.h"
10 #include "media/base/video_frame.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 using testing::_;
16 namespace cc {
18 // NOTE: We cannot use DebugScopedSetImplThreadAndMainThreadBlocked in these
19 // tests because it gets destroyed before the VideoLayerImpl is destroyed. This
20 // causes a DCHECK in VideoLayerImpl's destructor to fail.
21 static void DebugSetImplThreadAndMainThreadBlocked(Proxy* proxy) {
22 #if DCHECK_IS_ON()
23 proxy->SetCurrentThreadIsImplThread(true);
24 proxy->SetMainThreadBlocked(true);
25 #endif
28 class VideoFrameProviderClientImplTest : public testing::Test,
29 public VideoFrameControllerClient {
30 public:
31 VideoFrameProviderClientImplTest()
32 : client_impl_(VideoFrameProviderClientImpl::Create(&provider_, this)),
33 video_layer_impl_(nullptr),
34 test_frame_(media::VideoFrame::CreateFrame(media::PIXEL_FORMAT_YV12,
35 gfx::Size(10, 10),
36 gfx::Rect(10, 10),
37 gfx::Size(10, 10),
38 base::TimeDelta())) {
39 DebugSetImplThreadAndMainThreadBlocked(impl_.proxy());
42 ~VideoFrameProviderClientImplTest() {
43 if (!client_impl_->Stopped()) {
44 client_impl_->Stop();
45 DCHECK(client_impl_->Stopped());
46 DCHECK(!client_impl_->ActiveVideoLayer());
49 provider_.SetVideoFrameProviderClient(nullptr);
52 void StartRendering() {
53 EXPECT_CALL(*this, AddVideoFrameController(_));
54 client_impl_->StartRendering();
57 void StopRendering() {
58 EXPECT_CALL(*this, RemoveVideoFrameController(_));
59 client_impl_->StopRendering();
62 void StartRenderingAndRenderFrame() {
63 EXPECT_FALSE(client_impl_->HasCurrentFrame());
64 provider_.set_frame(test_frame_);
65 EXPECT_TRUE(client_impl_->HasCurrentFrame());
67 // Start rendering and verify SetNeedsRedraw() was called for the new frame.
68 StartRendering();
69 EXPECT_EQ(gfx::Rect(), video_layer_impl_->update_rect());
70 client_impl_->OnBeginFrame(BeginFrameArgs());
71 EXPECT_NE(gfx::Rect(), video_layer_impl_->update_rect());
74 void CreateActiveVideoLayer() {
75 gfx::Size layer_size(100, 100);
76 video_layer_impl_ = impl_.AddChildToRoot<VideoLayerImpl>(
77 &provider_, media::VIDEO_ROTATION_0);
78 video_layer_impl_->SetBounds(layer_size);
79 video_layer_impl_->SetDrawsContent(true);
80 client_impl_->SetActiveVideoLayer(video_layer_impl_);
81 ASSERT_TRUE(client_impl_->ActiveVideoLayer());
84 MOCK_METHOD1(AddVideoFrameController, void(VideoFrameController*));
85 MOCK_METHOD1(RemoveVideoFrameController, void(VideoFrameController*));
87 protected:
88 FakeVideoFrameProvider provider_;
89 LayerTestCommon::LayerImplTest impl_;
90 scoped_refptr<VideoFrameProviderClientImpl> client_impl_;
91 VideoLayerImpl* video_layer_impl_;
92 scoped_refptr<media::VideoFrame> test_frame_;
94 private:
95 DISALLOW_COPY_AND_ASSIGN(VideoFrameProviderClientImplTest);
98 TEST_F(VideoFrameProviderClientImplTest, StartStopRendering) {
99 StartRendering();
100 StopRendering();
103 TEST_F(VideoFrameProviderClientImplTest, StopUsingProvider) {
104 ASSERT_TRUE(client_impl_->get_provider_for_testing());
105 StartRendering();
106 EXPECT_CALL(*this, RemoveVideoFrameController(_));
107 client_impl_->StopUsingProvider();
108 ASSERT_FALSE(client_impl_->get_provider_for_testing());
111 TEST_F(VideoFrameProviderClientImplTest, FrameAcquisition) {
112 CreateActiveVideoLayer();
113 StartRenderingAndRenderFrame();
115 // Verify GetCurrentFrame() and PutCurrentFrame() work correctly.
116 EXPECT_EQ(test_frame_, client_impl_->AcquireLockAndCurrentFrame());
117 EXPECT_EQ(0, provider_.put_current_frame_count());
118 client_impl_->PutCurrentFrame();
119 EXPECT_EQ(1, provider_.put_current_frame_count());
121 client_impl_->ReleaseLock();
122 StopRendering();
125 TEST_F(VideoFrameProviderClientImplTest, DidReceiveFrame) {
126 CreateActiveVideoLayer();
127 EXPECT_EQ(gfx::Rect(), video_layer_impl_->update_rect());
128 client_impl_->DidReceiveFrame();
129 EXPECT_NE(gfx::Rect(), video_layer_impl_->update_rect());
132 TEST_F(VideoFrameProviderClientImplTest, DidDrawFrameIssuesPutCurrentFrame) {
133 CreateActiveVideoLayer();
134 StartRenderingAndRenderFrame();
135 EXPECT_EQ(0, provider_.put_current_frame_count());
136 client_impl_->DidDrawFrame();
137 EXPECT_EQ(1, provider_.put_current_frame_count());
138 StopRendering();
141 TEST_F(VideoFrameProviderClientImplTest, StreamTextureMatrix) {
142 const float kIdentityMatrix[] = {
143 1.0,
144 0.0,
145 0.0,
146 0.0,
147 0.0,
148 1.0,
149 0.0,
150 0.0,
151 0.0,
152 0.0,
153 1.0,
154 0.0,
155 0.0,
156 0.0,
157 0.0,
158 1.0,
161 EXPECT_FALSE(client_impl_->StreamTextureMatrix().IsIdentity());
162 client_impl_->DidUpdateMatrix(kIdentityMatrix);
163 EXPECT_TRUE(client_impl_->StreamTextureMatrix().IsIdentity());
166 } // namespace cc