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 MockContextProvider
: public TestContextProvider
{
20 explicit MockContextProvider(scoped_ptr
<TestWebGraphicsContext3D
> context
)
21 : TestContextProvider(context
.Pass()) {}
22 MOCK_METHOD0(DeleteCachedResources
, void());
25 ~MockContextProvider() {}
29 scoped_ptr
<Renderer
> CreateRenderer(RendererClient
* client
,
30 const LayerTreeSettings
* settings
,
31 OutputSurface
* output_surface
,
32 ResourceProvider
* resource_provider
);
35 scoped_ptr
<Renderer
> CreateRenderer
<DelegatingRenderer
>(
36 RendererClient
* client
,
37 const LayerTreeSettings
* settings
,
38 OutputSurface
* output_surface
,
39 ResourceProvider
* resource_provider
) {
40 return DelegatingRenderer::Create(
41 client
, settings
, output_surface
, resource_provider
)
46 scoped_ptr
<Renderer
> CreateRenderer
<GLRenderer
>(
47 RendererClient
* client
,
48 const LayerTreeSettings
* settings
,
49 OutputSurface
* output_surface
,
50 ResourceProvider
* resource_provider
) {
51 return GLRenderer::Create(
52 client
, settings
, output_surface
, resource_provider
, NULL
, 0)
57 class RendererTest
: public ::testing::Test
{
59 virtual void SetUp() {
61 new MockContextProvider(TestWebGraphicsContext3D::Create());
62 output_surface_
.reset(new OutputSurface(context_provider_
));
63 output_surface_
->BindToClient(&output_surface_client_
);
65 ResourceProvider::Create(output_surface_
.get(), NULL
, 0, false, 1,
67 renderer_
= CreateRenderer
<T
>(&renderer_client_
,
69 output_surface_
.get(),
70 resource_provider_
.get());
73 FakeRendererClient renderer_client_
;
74 LayerTreeSettings tree_settings_
;
75 FakeOutputSurfaceClient output_surface_client_
;
76 scoped_refptr
<MockContextProvider
> context_provider_
;
77 scoped_ptr
<OutputSurface
> output_surface_
;
78 scoped_ptr
<ResourceProvider
> resource_provider_
;
79 scoped_ptr
<Renderer
> renderer_
;
82 typedef ::testing::Types
<DelegatingRenderer
, GLRenderer
> RendererTypes
;
83 TYPED_TEST_CASE(RendererTest
, RendererTypes
);
85 TYPED_TEST(RendererTest
, ContextPurgedWhenRendererBecomesInvisible
) {
86 EXPECT_CALL(*(this->context_provider_
), DeleteCachedResources()).Times(1);
88 EXPECT_TRUE(this->renderer_
->visible());
89 this->renderer_
->SetVisible(false);
90 EXPECT_FALSE(this->renderer_
->visible());