summaryrefslogtreecommitdiffstats
path: root/cc/output/renderer_unittest.cc
blob: 1d54608ee7a446e02e0bc3b646e7ced5757b0f7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cc/output/delegating_renderer.h"
#include "cc/output/gl_renderer.h"
#include "cc/output/output_surface.h"
#include "cc/test/fake_output_surface_client.h"
#include "cc/test/fake_renderer_client.h"
#include "cc/test/test_context_provider.h"
#include "cc/test/test_web_graphics_context_3d.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace cc {
namespace {

class MockContextProvider : public TestContextProvider {
 public:
  explicit MockContextProvider(scoped_ptr<TestWebGraphicsContext3D> context)
      : TestContextProvider(context.Pass()) {}
  MOCK_METHOD0(DeleteCachedResources, void());

 protected:
  ~MockContextProvider() {}
};

template <class T>
scoped_ptr<Renderer> CreateRenderer(RendererClient* client,
                                    const LayerTreeSettings* settings,
                                    OutputSurface* output_surface,
                                    ResourceProvider* resource_provider);

template <>
scoped_ptr<Renderer> CreateRenderer<DelegatingRenderer>(
    RendererClient* client,
    const LayerTreeSettings* settings,
    OutputSurface* output_surface,
    ResourceProvider* resource_provider) {
  return DelegatingRenderer::Create(
             client, settings, output_surface, resource_provider)
      .PassAs<Renderer>();
}

template <>
scoped_ptr<Renderer> CreateRenderer<GLRenderer>(
    RendererClient* client,
    const LayerTreeSettings* settings,
    OutputSurface* output_surface,
    ResourceProvider* resource_provider) {
  return GLRenderer::Create(
             client, settings, output_surface, resource_provider, NULL, 0)
      .PassAs<Renderer>();
}

template <typename T>
class RendererTest : public ::testing::Test {
 protected:
  virtual void SetUp() {
    context_provider_ =
        new MockContextProvider(TestWebGraphicsContext3D::Create());
    output_surface_.reset(new OutputSurface(context_provider_));
    output_surface_->BindToClient(&output_surface_client_);
    resource_provider_ = ResourceProvider::Create(
        output_surface_.get(), NULL, NULL, 0, false, 1, false);
    renderer_ = CreateRenderer<T>(&renderer_client_,
                                  &tree_settings_,
                                  output_surface_.get(),
                                  resource_provider_.get());
  }

  FakeRendererClient renderer_client_;
  LayerTreeSettings tree_settings_;
  FakeOutputSurfaceClient output_surface_client_;
  scoped_refptr<MockContextProvider> context_provider_;
  scoped_ptr<OutputSurface> output_surface_;
  scoped_ptr<ResourceProvider> resource_provider_;
  scoped_ptr<Renderer> renderer_;
};

typedef ::testing::Types<DelegatingRenderer, GLRenderer> RendererTypes;
TYPED_TEST_CASE(RendererTest, RendererTypes);

TYPED_TEST(RendererTest, ContextPurgedWhenRendererBecomesInvisible) {
  EXPECT_CALL(*(this->context_provider_.get()), DeleteCachedResources())
      .Times(1);

  EXPECT_TRUE(this->renderer_->visible());
  this->renderer_->SetVisible(false);
  EXPECT_FALSE(this->renderer_->visible());
}

}  // namespace
}  // namespace cc