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/fake_resource_provider.h"
11 #include "cc/test/test_context_provider.h"
12 #include "cc/test/test_web_graphics_context_3d.h"
13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h"
19 class TestOutputSurface
: public OutputSurface
{
21 explicit TestOutputSurface(
22 const scoped_refptr
<ContextProvider
>& context_provider
);
23 ~TestOutputSurface() override
;
25 // OutputSurface implementation
26 void SwapBuffers(CompositorFrame
* frame
) override
;
29 TestOutputSurface::TestOutputSurface(
30 const scoped_refptr
<ContextProvider
>& context_provider
)
31 : OutputSurface(context_provider
) {
34 TestOutputSurface::~TestOutputSurface() {
37 void TestOutputSurface::SwapBuffers(CompositorFrame
* frame
) {
38 client_
->DidSwapBuffers();
39 client_
->DidSwapBuffersComplete();
42 class MockContextProvider
: public TestContextProvider
{
44 explicit MockContextProvider(scoped_ptr
<TestWebGraphicsContext3D
> context
)
45 : TestContextProvider(context
.Pass()) {}
46 MOCK_METHOD0(DeleteCachedResources
, void());
49 ~MockContextProvider() {}
53 scoped_ptr
<Renderer
> CreateRenderer(RendererClient
* client
,
54 const RendererSettings
* settings
,
55 OutputSurface
* output_surface
,
56 ResourceProvider
* resource_provider
);
59 scoped_ptr
<Renderer
> CreateRenderer
<DelegatingRenderer
>(
60 RendererClient
* client
,
61 const RendererSettings
* settings
,
62 OutputSurface
* output_surface
,
63 ResourceProvider
* resource_provider
) {
64 return DelegatingRenderer::Create(
65 client
, settings
, output_surface
, resource_provider
);
69 scoped_ptr
<Renderer
> CreateRenderer
<GLRenderer
>(
70 RendererClient
* client
,
71 const RendererSettings
* settings
,
72 OutputSurface
* output_surface
,
73 ResourceProvider
* resource_provider
) {
74 return GLRenderer::Create(
75 client
, settings
, output_surface
, resource_provider
, NULL
, 0);
79 class RendererTest
: public ::testing::Test
{
81 virtual void SetUp() {
83 new MockContextProvider(TestWebGraphicsContext3D::Create());
84 output_surface_
.reset(new TestOutputSurface(context_provider_
));
85 output_surface_
->BindToClient(&output_surface_client_
);
87 FakeResourceProvider::Create(output_surface_
.get(), nullptr);
88 renderer_
= CreateRenderer
<T
>(&renderer_client_
,
90 output_surface_
.get(),
91 resource_provider_
.get());
94 FakeRendererClient renderer_client_
;
95 RendererSettings tree_settings_
;
96 FakeOutputSurfaceClient output_surface_client_
;
97 scoped_refptr
<MockContextProvider
> context_provider_
;
98 scoped_ptr
<OutputSurface
> output_surface_
;
99 scoped_ptr
<ResourceProvider
> resource_provider_
;
100 scoped_ptr
<Renderer
> renderer_
;
103 typedef ::testing::Types
<DelegatingRenderer
, GLRenderer
> RendererTypes
;
104 TYPED_TEST_CASE(RendererTest
, RendererTypes
);
106 TYPED_TEST(RendererTest
, ContextPurgedWhenRendererBecomesInvisible
) {
107 EXPECT_CALL(*(this->context_provider_
.get()), DeleteCachedResources())
110 EXPECT_TRUE(this->renderer_
->visible());
111 this->renderer_
->SetVisible(false);
112 EXPECT_FALSE(this->renderer_
->visible());