[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / content / browser / compositor / software_browser_compositor_output_surface_unittest.cc
blob68534f0cacd15ce32f74f8aeb1625bc827581725
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 "base/message_loop/message_loop.h"
6 #include "cc/output/compositor_frame.h"
7 #include "cc/test/fake_output_surface_client.h"
8 #include "content/browser/compositor/software_browser_compositor_output_surface.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/compositor/compositor.h"
11 #include "ui/compositor/test/context_factories_for_test.h"
12 #include "ui/gfx/vsync_provider.h"
14 namespace {
16 class FakeVSyncProvider : public gfx::VSyncProvider {
17 public:
18 FakeVSyncProvider() : call_count_(0) {}
19 ~FakeVSyncProvider() override {}
21 void GetVSyncParameters(const UpdateVSyncCallback& callback) override {
22 callback.Run(timebase_, interval_);
23 call_count_++;
26 int call_count() const { return call_count_; }
28 void set_timebase(base::TimeTicks timebase) { timebase_ = timebase; }
29 void set_interval(base::TimeDelta interval) { interval_ = interval; }
31 private:
32 base::TimeTicks timebase_;
33 base::TimeDelta interval_;
35 int call_count_;
37 DISALLOW_COPY_AND_ASSIGN(FakeVSyncProvider);
40 class FakeSoftwareOutputDevice : public cc::SoftwareOutputDevice {
41 public:
42 FakeSoftwareOutputDevice() : vsync_provider_(new FakeVSyncProvider()) {}
43 ~FakeSoftwareOutputDevice() override {}
45 gfx::VSyncProvider* GetVSyncProvider() override {
46 return vsync_provider_.get();
49 private:
50 scoped_ptr<gfx::VSyncProvider> vsync_provider_;
52 DISALLOW_COPY_AND_ASSIGN(FakeSoftwareOutputDevice);
55 } // namespace
57 class SoftwareBrowserCompositorOutputSurfaceTest : public testing::Test {
58 public:
59 SoftwareBrowserCompositorOutputSurfaceTest();
60 ~SoftwareBrowserCompositorOutputSurfaceTest() override;
62 void SetUp() override;
63 void TearDown() override;
65 scoped_ptr<content::BrowserCompositorOutputSurface> CreateSurface(
66 scoped_ptr<cc::SoftwareOutputDevice> device);
68 protected:
69 scoped_ptr<content::BrowserCompositorOutputSurface> output_surface_;
71 scoped_ptr<base::MessageLoop> message_loop_;
72 scoped_ptr<ui::Compositor> compositor_;
74 DISALLOW_COPY_AND_ASSIGN(SoftwareBrowserCompositorOutputSurfaceTest);
77 SoftwareBrowserCompositorOutputSurfaceTest::
78 SoftwareBrowserCompositorOutputSurfaceTest() {
79 // |message_loop_| is not used, but the main thread still has to exist for the
80 // compositor to use.
81 message_loop_.reset(new base::MessageLoopForUI);
84 SoftwareBrowserCompositorOutputSurfaceTest::
85 ~SoftwareBrowserCompositorOutputSurfaceTest() {}
87 void SoftwareBrowserCompositorOutputSurfaceTest::SetUp() {
88 bool enable_pixel_output = false;
89 ui::ContextFactory* context_factory =
90 ui::InitializeContextFactoryForTests(enable_pixel_output);
92 compositor_.reset(new ui::Compositor(gfx::kNullAcceleratedWidget,
93 context_factory,
94 base::MessageLoopProxy::current()));
97 void SoftwareBrowserCompositorOutputSurfaceTest::TearDown() {
98 output_surface_.reset();
99 compositor_.reset();
100 ui::TerminateContextFactoryForTests();
103 scoped_ptr<content::BrowserCompositorOutputSurface>
104 SoftwareBrowserCompositorOutputSurfaceTest::CreateSurface(
105 scoped_ptr<cc::SoftwareOutputDevice> device) {
106 return scoped_ptr<content::BrowserCompositorOutputSurface>(
107 new content::SoftwareBrowserCompositorOutputSurface(
108 device.Pass(),
109 compositor_->vsync_manager()));
112 TEST_F(SoftwareBrowserCompositorOutputSurfaceTest, NoVSyncProvider) {
113 cc::FakeOutputSurfaceClient output_surface_client;
114 scoped_ptr<cc::SoftwareOutputDevice> software_device(
115 new cc::SoftwareOutputDevice());
116 output_surface_ = CreateSurface(software_device.Pass());
117 CHECK(output_surface_->BindToClient(&output_surface_client));
119 cc::CompositorFrame frame;
120 output_surface_->SwapBuffers(&frame);
122 EXPECT_EQ(1, output_surface_client.swap_count());
123 EXPECT_EQ(NULL, output_surface_->software_device()->GetVSyncProvider());
126 TEST_F(SoftwareBrowserCompositorOutputSurfaceTest, VSyncProviderUpdates) {
127 cc::FakeOutputSurfaceClient output_surface_client;
128 scoped_ptr<cc::SoftwareOutputDevice> software_device(
129 new FakeSoftwareOutputDevice());
130 output_surface_ = CreateSurface(software_device.Pass());
131 CHECK(output_surface_->BindToClient(&output_surface_client));
133 FakeVSyncProvider* vsync_provider = static_cast<FakeVSyncProvider*>(
134 output_surface_->software_device()->GetVSyncProvider());
135 EXPECT_EQ(0, vsync_provider->call_count());
137 cc::CompositorFrame frame;
138 output_surface_->SwapBuffers(&frame);
140 EXPECT_EQ(1, output_surface_client.swap_count());
141 EXPECT_EQ(1, vsync_provider->call_count());