1 // Copyright 2014 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/output/delegating_renderer.h"
6 #include "cc/output/gl_renderer.h"
7 #include "cc/output/output_surface.h"
8 #include "cc/test/fake_output_surface_client.h"
9 #include "cc/test/fake_renderer_client.h"
10 #include "cc/test/test_context_provider.h"
11 #include "cc/test/test_web_graphics_context_3d.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h"
18 class TestOutputSurface
: public OutputSurface
{
20 explicit TestOutputSurface(
21 const scoped_refptr
<ContextProvider
>& context_provider
);
22 ~TestOutputSurface() override
;
24 // OutputSurface implementation
25 void SwapBuffers(CompositorFrame
* frame
) override
;
28 TestOutputSurface::TestOutputSurface(
29 const scoped_refptr
<ContextProvider
>& context_provider
)
30 : OutputSurface(context_provider
) {
33 TestOutputSurface::~TestOutputSurface() {
36 void TestOutputSurface::SwapBuffers(CompositorFrame
* frame
) {
37 client_
->DidSwapBuffers();
38 client_
->DidSwapBuffersComplete();
41 class MockContextProvider
: public TestContextProvider
{
43 explicit MockContextProvider(scoped_ptr
<TestWebGraphicsContext3D
> context
)
44 : TestContextProvider(context
.Pass()) {}
45 MOCK_METHOD0(DeleteCachedResources
, void());
48 ~MockContextProvider() {}
52 scoped_ptr
<Renderer
> CreateRenderer(RendererClient
* client
,
53 const RendererSettings
* settings
,
54 OutputSurface
* output_surface
,
55 ResourceProvider
* resource_provider
);
58 scoped_ptr
<Renderer
> CreateRenderer
<DelegatingRenderer
>(
59 RendererClient
* client
,
60 const RendererSettings
* settings
,
61 OutputSurface
* output_surface
,
62 ResourceProvider
* resource_provider
) {
63 return DelegatingRenderer::Create(
64 client
, settings
, output_surface
, resource_provider
);
68 scoped_ptr
<Renderer
> CreateRenderer
<GLRenderer
>(
69 RendererClient
* client
,
70 const RendererSettings
* settings
,
71 OutputSurface
* output_surface
,
72 ResourceProvider
* resource_provider
) {
73 return GLRenderer::Create(
74 client
, settings
, output_surface
, resource_provider
, NULL
, 0);
78 class RendererTest
: public ::testing::Test
{
80 virtual void SetUp() {
82 new MockContextProvider(TestWebGraphicsContext3D::Create());
83 output_surface_
.reset(new TestOutputSurface(context_provider_
));
84 output_surface_
->BindToClient(&output_surface_client_
);
85 resource_provider_
= ResourceProvider::Create(
86 output_surface_
.get(), NULL
, NULL
, NULL
, 0, false, 1);
87 renderer_
= CreateRenderer
<T
>(&renderer_client_
,
89 output_surface_
.get(),
90 resource_provider_
.get());
93 FakeRendererClient renderer_client_
;
94 RendererSettings tree_settings_
;
95 FakeOutputSurfaceClient output_surface_client_
;
96 scoped_refptr
<MockContextProvider
> context_provider_
;
97 scoped_ptr
<OutputSurface
> output_surface_
;
98 scoped_ptr
<ResourceProvider
> resource_provider_
;
99 scoped_ptr
<Renderer
> renderer_
;
102 typedef ::testing::Types
<DelegatingRenderer
, GLRenderer
> RendererTypes
;
103 TYPED_TEST_CASE(RendererTest
, RendererTypes
);
105 TYPED_TEST(RendererTest
, ContextPurgedWhenRendererBecomesInvisible
) {
106 EXPECT_CALL(*(this->context_provider_
.get()), DeleteCachedResources())
109 EXPECT_TRUE(this->renderer_
->visible());
110 this->renderer_
->SetVisible(false);
111 EXPECT_FALSE(this->renderer_
->visible());