1 // Copyright 2013 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 "content/browser/gpu/browser_gpu_channel_host_factory.h"
6 #include "content/common/gpu/client/context_provider_command_buffer.h"
7 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
8 #include "content/public/test/content_browser_test.h"
9 #include "testing/gtest/include/gtest/gtest.h"
14 class ContextProviderCommandBufferBrowserTest : public ContentBrowserTest {
16 virtual void SetUpOnMainThread() OVERRIDE {
17 if (!BrowserGpuChannelHostFactory::CanUseForTesting())
21 BrowserGpuChannelHostFactory::Initialize(true);
24 ContentBrowserTest::SetUpOnMainThread();
28 BrowserGpuChannelHostFactory* GetFactory() {
29 return BrowserGpuChannelHostFactory::instance();
32 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> CreateContext3d() {
33 bool lose_context_when_out_of_memory = false;
34 scoped_refptr<GpuChannelHost> gpu_channel_host(
35 GetFactory()->EstablishGpuChannelSync(
36 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE));
37 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
38 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext(
39 gpu_channel_host.get(),
40 blink::WebGraphicsContext3D::Attributes(),
41 lose_context_when_out_of_memory,
42 GURL("chrome://gpu/ContextProviderCommandBufferTest"),
43 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits(),
45 return context.Pass();
49 IN_PROC_BROWSER_TEST_F(ContextProviderCommandBufferBrowserTest, LeakOnDestroy) {
50 if (!BrowserGpuChannelHostFactory::CanUseForTesting())
53 scoped_refptr<ContextProviderCommandBuffer> provider =
54 ContextProviderCommandBuffer::Create(CreateContext3d(), "TestContext");
55 provider->set_leak_on_destroy();
56 EXPECT_TRUE(provider->BindToCurrentThread());
57 // This should not crash.
62 } // namespace content