| Index: content/browser/aura/software_browser_compositor_output_surface_unittest.cc
|
| diff --git a/content/browser/aura/software_browser_compositor_output_surface_unittest.cc b/content/browser/aura/software_browser_compositor_output_surface_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a1c813b87d9d2e2ebdaa0a1daf3882f0e4a80a52
|
| --- /dev/null
|
| +++ b/content/browser/aura/software_browser_compositor_output_surface_unittest.cc
|
| @@ -0,0 +1,126 @@
|
| +// Copyright 2013 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 "base/message_loop/message_loop.h"
|
| +#include "cc/output/compositor_frame.h"
|
| +#include "content/browser/aura/software_browser_compositor_output_surface.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "ui/compositor/test/context_factories_for_test.h"
|
| +#include "ui/gl/gl_implementation.h"
|
| +#include "ui/gl/vsync_provider.h"
|
| +
|
| +namespace {
|
| +
|
| +class FakeVSyncProvider : public gfx::VSyncProvider {
|
| + public:
|
| + FakeVSyncProvider() : call_count_(0) {}
|
| + virtual ~FakeVSyncProvider() {}
|
| +
|
| + virtual void GetVSyncParameters(
|
| + const UpdateVSyncCallback& callback) OVERRIDE {
|
| + callback.Run(timebase_, interval_);
|
| + call_count_++;
|
| + }
|
| +
|
| + int get_call_count() const { return call_count_; }
|
| +
|
| + void set_timebase(base::TimeTicks timebase) { timebase_ = timebase; }
|
| + void set_interval(base::TimeDelta interval) { interval_ = interval; }
|
| +
|
| + private:
|
| + base::TimeTicks timebase_;
|
| + base::TimeDelta interval_;
|
| +
|
| + int call_count_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(FakeVSyncProvider);
|
| +};
|
| +
|
| +class FakeSoftwareOutputDevice : public cc::SoftwareOutputDevice {
|
| + public:
|
| + FakeSoftwareOutputDevice() : vsync_provider_(new FakeVSyncProvider()) {}
|
| + virtual ~FakeSoftwareOutputDevice() {}
|
| +
|
| + virtual gfx::VSyncProvider* GetVSyncProvider() OVERRIDE {
|
| + return vsync_provider_.get();
|
| + }
|
| + private:
|
| + scoped_ptr<gfx::VSyncProvider> vsync_provider_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(FakeSoftwareOutputDevice);
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +class SoftwareBrowserCompositorOutputSurfaceTest : public testing::Test {
|
| + public:
|
| + SoftwareBrowserCompositorOutputSurfaceTest();
|
| + virtual ~SoftwareBrowserCompositorOutputSurfaceTest();
|
| +
|
| + virtual void SetUp() OVERRIDE;
|
| + virtual void TearDown() OVERRIDE;
|
| +
|
| + protected:
|
| + scoped_ptr<content::SoftwareBrowserCompositorOutputSurface> output_surface_;
|
| +
|
| + scoped_ptr<base::MessageLoop> message_loop_;
|
| + scoped_ptr<ui::Compositor> compositor_;
|
| +};
|
| +
|
| +SoftwareBrowserCompositorOutputSurfaceTest::
|
| +SoftwareBrowserCompositorOutputSurfaceTest() {
|
| + CHECK(gfx::InitializeGLBindings(gfx::kGLImplementationOSMesaGL));
|
| + message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_UI));
|
| +}
|
| +
|
| +SoftwareBrowserCompositorOutputSurfaceTest::
|
| +~SoftwareBrowserCompositorOutputSurfaceTest() {
|
| +}
|
| +
|
| +void SoftwareBrowserCompositorOutputSurfaceTest::SetUp() {
|
| + ui::InitializeContextFactoryForTests(false);
|
| + ui::Compositor::Initialize();
|
| +
|
| + compositor_.reset(new ui::Compositor(true, 1));
|
| +}
|
| +
|
| +void SoftwareBrowserCompositorOutputSurfaceTest::TearDown() {
|
| + output_surface_.reset();
|
| + compositor_.reset();
|
| +
|
| + ui::TerminateContextFactoryForTests();
|
| + ui::Compositor::Terminate();
|
| +}
|
| +
|
| +TEST_F(SoftwareBrowserCompositorOutputSurfaceTest, NoVSyncProvider) {
|
| + scoped_ptr<cc::SoftwareOutputDevice> software_device(
|
| + new cc::SoftwareOutputDevice());
|
| + output_surface_ = content::SoftwareBrowserCompositorOutputSurface::Create(
|
| + software_device.Pass(),
|
| + compositor_->GetCompositorMessageLoop(),
|
| + compositor_->AsWeakPtr());
|
| +
|
| + cc::CompositorFrame frame;
|
| + static_cast<cc::OutputSurface*>(output_surface_.get())->SwapBuffers(&frame);
|
| +
|
| + EXPECT_EQ(NULL, output_surface_->software_device()->GetVSyncProvider());
|
| +}
|
| +
|
| +TEST_F(SoftwareBrowserCompositorOutputSurfaceTest, VSyncProviderUpdates) {
|
| + scoped_ptr<cc::SoftwareOutputDevice> software_device(
|
| + new FakeSoftwareOutputDevice());
|
| + output_surface_ = content::SoftwareBrowserCompositorOutputSurface::Create(
|
| + software_device.Pass(),
|
| + compositor_->GetCompositorMessageLoop(),
|
| + compositor_->AsWeakPtr());
|
| +
|
| + FakeVSyncProvider* vsync_provider = static_cast<FakeVSyncProvider*>(
|
| + output_surface_->software_device()->GetVSyncProvider());
|
| + EXPECT_EQ(0, vsync_provider->get_call_count());
|
| +
|
| + cc::CompositorFrame frame;
|
| + static_cast<cc::OutputSurface*>(output_surface_.get())->SwapBuffers(&frame);
|
| +
|
| + EXPECT_EQ(1, vsync_provider->get_call_count());
|
| +}
|
|
|