Fix mistake in crrev.com/650223005.
[chromium-blink-merge.git] / cc / output / renderer_unittest.cc
blob8f0a0ef0aa01bcf5c40844b5b4f0d6745b078a27
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"
15 namespace cc {
16 namespace {
18 class TestOutputSurface : public OutputSurface {
19 public:
20 explicit TestOutputSurface(
21 const scoped_refptr<ContextProvider>& context_provider);
22 virtual ~TestOutputSurface() override;
24 // OutputSurface implementation
25 virtual 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 {
42 public:
43 explicit MockContextProvider(scoped_ptr<TestWebGraphicsContext3D> context)
44 : TestContextProvider(context.Pass()) {}
45 MOCK_METHOD0(DeleteCachedResources, void());
47 protected:
48 ~MockContextProvider() {}
51 template <class T>
52 scoped_ptr<Renderer> CreateRenderer(RendererClient* client,
53 const LayerTreeSettings* settings,
54 OutputSurface* output_surface,
55 ResourceProvider* resource_provider);
57 template <>
58 scoped_ptr<Renderer> CreateRenderer<DelegatingRenderer>(
59 RendererClient* client,
60 const LayerTreeSettings* settings,
61 OutputSurface* output_surface,
62 ResourceProvider* resource_provider) {
63 return DelegatingRenderer::Create(
64 client, settings, output_surface, resource_provider);
67 template <>
68 scoped_ptr<Renderer> CreateRenderer<GLRenderer>(
69 RendererClient* client,
70 const LayerTreeSettings* settings,
71 OutputSurface* output_surface,
72 ResourceProvider* resource_provider) {
73 return GLRenderer::Create(
74 client, settings, output_surface, resource_provider, NULL, 0);
77 template <typename T>
78 class RendererTest : public ::testing::Test {
79 protected:
80 virtual void SetUp() {
81 context_provider_ =
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, false);
87 renderer_ = CreateRenderer<T>(&renderer_client_,
88 &tree_settings_,
89 output_surface_.get(),
90 resource_provider_.get());
93 FakeRendererClient renderer_client_;
94 LayerTreeSettings 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())
107 .Times(1);
109 EXPECT_TRUE(this->renderer_->visible());
110 this->renderer_->SetVisible(false);
111 EXPECT_FALSE(this->renderer_->visible());
114 } // namespace
115 } // namespace cc