Roll WebRTC 9745:9761, Libjingle 9742:9761
[chromium-blink-merge.git] / cc / output / renderer_unittest.cc
blob48545587759588146d1c5b65c7018b080f359630
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"
16 namespace cc {
17 namespace {
19 class TestOutputSurface : public OutputSurface {
20 public:
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 {
43 public:
44 explicit MockContextProvider(scoped_ptr<TestWebGraphicsContext3D> context)
45 : TestContextProvider(context.Pass()) {}
46 MOCK_METHOD0(DeleteCachedResources, void());
48 protected:
49 ~MockContextProvider() {}
52 template <class T>
53 scoped_ptr<Renderer> CreateRenderer(RendererClient* client,
54 const RendererSettings* settings,
55 OutputSurface* output_surface,
56 ResourceProvider* resource_provider);
58 template <>
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);
68 template <>
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);
78 template <typename T>
79 class RendererTest : public ::testing::Test {
80 protected:
81 virtual void SetUp() {
82 context_provider_ =
83 new MockContextProvider(TestWebGraphicsContext3D::Create());
84 output_surface_.reset(new TestOutputSurface(context_provider_));
85 output_surface_->BindToClient(&output_surface_client_);
86 resource_provider_ =
87 FakeResourceProvider::Create(output_surface_.get(), nullptr);
88 renderer_ = CreateRenderer<T>(&renderer_client_,
89 &tree_settings_,
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())
108 .Times(1);
110 EXPECT_TRUE(this->renderer_->visible());
111 this->renderer_->SetVisible(false);
112 EXPECT_FALSE(this->renderer_->visible());
115 } // namespace
116 } // namespace cc