Remove PlatformFile from profile_browsertest
[chromium-blink-merge.git] / content / browser / gpu / gpu_ipc_browsertests.cc
blobebeceff357a1607f37c68c9e22f6f97673e1cca9
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 "base/command_line.h"
6 #include "base/run_loop.h"
7 #include "content/browser/gpu/browser_gpu_channel_host_factory.h"
8 #include "content/browser/gpu/gpu_process_host_ui_shim.h"
9 #include "content/common/gpu/client/context_provider_command_buffer.h"
10 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
11 #include "content/common/gpu/gpu_process_launch_causes.h"
12 #include "content/public/browser/gpu_data_manager.h"
13 #include "content/public/common/content_switches.h"
14 #include "content/public/test/content_browser_test.h"
15 #include "ui/gl/gl_switches.h"
16 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
18 namespace {
20 using content::WebGraphicsContext3DCommandBufferImpl;
22 const content::CauseForGpuLaunch kInitCause =
23 content::
24 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
26 class ContextTestBase : public content::ContentBrowserTest {
27 public:
28 virtual void SetUpOnMainThread() OVERRIDE {
29 if (!content::BrowserGpuChannelHostFactory::CanUseForTesting())
30 return;
32 if (!content::BrowserGpuChannelHostFactory::instance())
33 content::BrowserGpuChannelHostFactory::Initialize(true);
35 content::BrowserGpuChannelHostFactory* factory =
36 content::BrowserGpuChannelHostFactory::instance();
37 CHECK(factory);
38 scoped_refptr<content::GpuChannelHost> gpu_channel_host(
39 factory->EstablishGpuChannelSync(kInitCause));
40 context_.reset(
41 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext(
42 gpu_channel_host.get(),
43 blink::WebGraphicsContext3D::Attributes(),
44 GURL(),
45 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits(),
46 NULL));
47 CHECK(context_.get());
48 context_->makeContextCurrent();
49 context_support_ = context_->GetContextSupport();
50 ContentBrowserTest::SetUpOnMainThread();
53 virtual void TearDownOnMainThread() OVERRIDE {
54 // Must delete the context first.
55 context_.reset(NULL);
56 ContentBrowserTest::TearDownOnMainThread();
59 protected:
60 scoped_ptr<content::WebGraphicsContext3DCommandBufferImpl> context_;
61 gpu::ContextSupport* context_support_;
64 } // namespace
66 // Include the shared tests.
67 #define CONTEXT_TEST_F IN_PROC_BROWSER_TEST_F
68 #include "content/common/gpu/client/gpu_context_tests.h"
70 namespace content {
72 class BrowserGpuChannelHostFactoryTest : public ContentBrowserTest {
73 public:
74 virtual void SetUpOnMainThread() OVERRIDE {
75 if (!BrowserGpuChannelHostFactory::CanUseForTesting())
76 return;
78 // Start all tests without a gpu channel so that the tests exercise a
79 // consistent codepath.
80 if (!BrowserGpuChannelHostFactory::instance())
81 BrowserGpuChannelHostFactory::Initialize(false);
83 CHECK(GetFactory());
85 ContentBrowserTest::SetUpOnMainThread();
88 void OnContextLost(const base::Closure callback, int* counter) {
89 (*counter)++;
90 callback.Run();
93 protected:
94 BrowserGpuChannelHostFactory* GetFactory() {
95 return BrowserGpuChannelHostFactory::instance();
98 bool IsChannelEstablished() {
99 return GetFactory()->GetGpuChannel() != NULL;
102 void EstablishAndWait() {
103 base::RunLoop run_loop;
104 GetFactory()->EstablishGpuChannel(kInitCause, run_loop.QuitClosure());
105 run_loop.Run();
108 GpuChannelHost* GetGpuChannel() {
109 return GetFactory()->GetGpuChannel();
112 static void Signal(bool *event) {
113 CHECK_EQ(*event, false);
114 *event = true;
117 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> CreateContext() {
118 return make_scoped_ptr(
119 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext(
120 GetGpuChannel(),
121 blink::WebGraphicsContext3D::Attributes(),
122 GURL(),
123 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits(),
124 NULL));
128 // Fails since UI Compositor establishes a GpuChannel.
129 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, DISABLED_Basic) {
130 DCHECK(!IsChannelEstablished());
131 EstablishAndWait();
132 EXPECT_TRUE(GetGpuChannel() != NULL);
135 // Fails since UI Compositor establishes a GpuChannel.
136 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest,
137 DISABLED_EstablishAndTerminate) {
138 DCHECK(!IsChannelEstablished());
139 base::RunLoop run_loop;
140 GetFactory()->EstablishGpuChannel(kInitCause, run_loop.QuitClosure());
141 GetFactory()->Terminate();
143 // The callback should still trigger.
144 run_loop.Run();
147 // Fails since UI Compositor establishes a GpuChannel.
148 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest,
149 DISABLED_AlreadyEstablished) {
150 DCHECK(!IsChannelEstablished());
151 scoped_refptr<GpuChannelHost> gpu_channel =
152 GetFactory()->EstablishGpuChannelSync(kInitCause);
154 // Expect established callback immediately.
155 bool event = false;
156 GetFactory()->EstablishGpuChannel(
157 kInitCause,
158 base::Bind(&BrowserGpuChannelHostFactoryTest::Signal, &event));
159 EXPECT_TRUE(event);
160 EXPECT_EQ(gpu_channel, GetGpuChannel());
163 // Fails since UI Compositor establishes a GpuChannel.
164 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest,
165 DISABLED_CrashAndRecover) {
166 DCHECK(!IsChannelEstablished());
167 EstablishAndWait();
168 scoped_refptr<GpuChannelHost> host = GetGpuChannel();
170 scoped_refptr<ContextProviderCommandBuffer> provider =
171 ContextProviderCommandBuffer::Create(CreateContext(),
172 "BrowserGpuChannelHostFactoryTest");
173 base::RunLoop run_loop;
174 int counter = 0;
175 provider->SetLostContextCallback(
176 base::Bind(&BrowserGpuChannelHostFactoryTest::OnContextLost,
177 base::Unretained(this), run_loop.QuitClosure(), &counter));
178 EXPECT_TRUE(provider->BindToCurrentThread());
179 GpuProcessHostUIShim* shim =
180 GpuProcessHostUIShim::FromID(GetFactory()->GpuProcessHostId());
181 EXPECT_TRUE(shim != NULL);
182 shim->SimulateCrash();
183 run_loop.Run();
185 EXPECT_EQ(1, counter);
186 EXPECT_FALSE(IsChannelEstablished());
187 EstablishAndWait();
188 EXPECT_TRUE(IsChannelEstablished());
191 } // namespace content