OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
7 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 7 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
8 #include "content/browser/gpu/gpu_process_host_ui_shim.h" | 8 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
9 #include "content/common/gpu/client/context_provider_command_buffer.h" | 9 #include "content/common/gpu/client/context_provider_command_buffer.h" |
10 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 10 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
11 #include "content/common/gpu/gpu_process_launch_causes.h" | 11 #include "content/common/gpu/gpu_process_launch_causes.h" |
12 #include "content/public/browser/browser_thread.h" | |
13 #include "content/public/browser/gpu_data_manager.h" | 12 #include "content/public/browser/gpu_data_manager.h" |
14 #include "content/public/common/content_switches.h" | 13 #include "content/public/common/content_switches.h" |
15 #include "content/test/content_browser_test.h" | 14 #include "content/test/content_browser_test.h" |
16 #include "ui/gl/gl_switches.h" | 15 #include "ui/gl/gl_switches.h" |
17 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.
h" | 16 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.
h" |
18 | 17 |
19 namespace { | 18 namespace { |
20 | 19 |
21 using content::WebGraphicsContext3DCommandBufferImpl; | 20 using content::WebGraphicsContext3DCommandBufferImpl; |
22 | 21 |
| 22 const content::CauseForGpuLaunch kInitCause = |
| 23 content:: |
| 24 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; |
| 25 |
23 class ContextTestBase : public content::ContentBrowserTest { | 26 class ContextTestBase : public content::ContentBrowserTest { |
24 public: | 27 public: |
25 virtual void SetUpOnMainThread() OVERRIDE { | 28 virtual void SetUpOnMainThread() OVERRIDE { |
26 if (!content::BrowserGpuChannelHostFactory::CanUseForTesting()) | 29 if (!content::BrowserGpuChannelHostFactory::CanUseForTesting()) |
27 return; | 30 return; |
28 | 31 |
29 if (!content::BrowserGpuChannelHostFactory::instance()) | 32 if (!content::BrowserGpuChannelHostFactory::instance()) |
30 content::BrowserGpuChannelHostFactory::Initialize(true); | 33 content::BrowserGpuChannelHostFactory::Initialize(true); |
31 | 34 |
32 content::BrowserGpuChannelHostFactory* factory = | 35 content::BrowserGpuChannelHostFactory* factory = |
33 content::BrowserGpuChannelHostFactory::instance(); | 36 content::BrowserGpuChannelHostFactory::instance(); |
34 CHECK(factory); | 37 CHECK(factory); |
35 scoped_refptr<content::GpuChannelHost> gpu_channel_host( | 38 scoped_refptr<content::GpuChannelHost> gpu_channel_host( |
36 factory->EstablishGpuChannelSync( | 39 factory->EstablishGpuChannelSync(kInitCause)); |
37 content:: | |
38 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITI
ALIZE)); | |
39 context_.reset( | 40 context_.reset( |
40 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext( | 41 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext( |
41 gpu_channel_host.get(), | 42 gpu_channel_host.get(), |
42 blink::WebGraphicsContext3D::Attributes(), | 43 blink::WebGraphicsContext3D::Attributes(), |
43 GURL(), | 44 GURL(), |
44 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits())); | 45 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits())); |
45 CHECK(context_.get()); | 46 CHECK(context_.get()); |
46 context_->makeContextCurrent(); | 47 context_->makeContextCurrent(); |
47 context_support_ = context_->GetContextSupport(); | 48 context_support_ = context_->GetContextSupport(); |
48 ContentBrowserTest::SetUpOnMainThread(); | 49 ContentBrowserTest::SetUpOnMainThread(); |
49 } | 50 } |
50 | 51 |
51 virtual void TearDownOnMainThread() OVERRIDE { | 52 virtual void TearDownOnMainThread() OVERRIDE { |
52 // Must delete the context first. | 53 // Must delete the context first. |
53 context_.reset(NULL); | 54 context_.reset(NULL); |
54 ContentBrowserTest::TearDownOnMainThread(); | 55 ContentBrowserTest::TearDownOnMainThread(); |
55 } | 56 } |
56 | 57 |
57 protected: | 58 protected: |
58 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context_; | 59 scoped_ptr<content::WebGraphicsContext3DCommandBufferImpl> context_; |
59 gpu::ContextSupport* context_support_; | 60 gpu::ContextSupport* context_support_; |
60 }; | 61 }; |
61 | 62 |
62 } // namespace | 63 } // namespace |
63 | 64 |
64 // Include the shared tests. | 65 // Include the shared tests. |
65 #define CONTEXT_TEST_F IN_PROC_BROWSER_TEST_F | 66 #define CONTEXT_TEST_F IN_PROC_BROWSER_TEST_F |
66 #include "content/common/gpu/client/gpu_context_tests.h" | 67 #include "content/common/gpu/client/gpu_context_tests.h" |
67 | 68 |
68 namespace content { | 69 namespace content { |
69 | 70 |
70 class BrowserGpuChannelHostFactoryTest : public ContextTestBase { | 71 class BrowserGpuChannelHostFactoryTest : public ContextTestBase { |
71 public: | 72 public: |
72 virtual void SetUpOnMainThread() OVERRIDE { | 73 virtual void SetUpOnMainThread() OVERRIDE { |
73 if (!content::BrowserGpuChannelHostFactory::CanUseForTesting()) | 74 if (!BrowserGpuChannelHostFactory::CanUseForTesting()) |
74 return; | 75 return; |
75 | 76 |
76 // Start all tests without a gpu channel so that the tests exercise a | 77 // Start all tests without a gpu channel so that the tests exercise a |
77 // consistent codepath. | 78 // consistent codepath. |
78 if (!content::BrowserGpuChannelHostFactory::instance()) | 79 if (!BrowserGpuChannelHostFactory::instance()) |
79 content::BrowserGpuChannelHostFactory::Initialize(false); | 80 BrowserGpuChannelHostFactory::Initialize(false); |
80 | 81 |
81 CHECK(GetFactory()); | 82 CHECK(GetFactory()); |
82 | 83 |
83 ContentBrowserTest::SetUpOnMainThread(); | 84 ContentBrowserTest::SetUpOnMainThread(); |
84 } | 85 } |
85 | 86 |
86 virtual void TearDownOnMainThread() OVERRIDE { | 87 virtual void TearDownOnMainThread() OVERRIDE { |
87 ContextTestBase::TearDownOnMainThread(); | 88 ContextTestBase::TearDownOnMainThread(); |
88 } | 89 } |
89 | 90 |
(...skipping 12 matching lines...) Expand all Loading... |
102 BrowserGpuChannelHostFactory* GetFactory() { | 103 BrowserGpuChannelHostFactory* GetFactory() { |
103 return BrowserGpuChannelHostFactory::instance(); | 104 return BrowserGpuChannelHostFactory::instance(); |
104 } | 105 } |
105 | 106 |
106 bool IsChannelEstablished() { | 107 bool IsChannelEstablished() { |
107 return GetFactory()->GetGpuChannel() != NULL; | 108 return GetFactory()->GetGpuChannel() != NULL; |
108 } | 109 } |
109 | 110 |
110 void EstablishAndWait() { | 111 void EstablishAndWait() { |
111 base::RunLoop run_loop; | 112 base::RunLoop run_loop; |
112 GetFactory()->EstablishGpuChannel( | 113 GetFactory()->EstablishGpuChannel(kInitCause, run_loop.QuitClosure()); |
113 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE, | |
114 run_loop.QuitClosure()); | |
115 run_loop.Run(); | 114 run_loop.Run(); |
116 } | 115 } |
117 | 116 |
118 GpuChannelHost* GetGpuChannel() { | 117 GpuChannelHost* GetGpuChannel() { |
119 return GetFactory()->GetGpuChannel(); | 118 return GetFactory()->GetGpuChannel(); |
120 } | 119 } |
121 | 120 |
122 static void Signal(bool *event) { | 121 static void Signal(bool *event) { |
123 CHECK_EQ(*event, false); | 122 CHECK_EQ(*event, false); |
124 *event = true; | 123 *event = true; |
(...skipping 18 matching lines...) Expand all Loading... |
143 EXPECT_TRUE(GetGpuChannel() != NULL); | 142 EXPECT_TRUE(GetGpuChannel() != NULL); |
144 } | 143 } |
145 | 144 |
146 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, | 145 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, |
147 EstablishAndTerminate) { | 146 EstablishAndTerminate) { |
148 if (!context_) | 147 if (!context_) |
149 return; | 148 return; |
150 | 149 |
151 DCHECK(!IsChannelEstablished()); | 150 DCHECK(!IsChannelEstablished()); |
152 base::RunLoop run_loop; | 151 base::RunLoop run_loop; |
153 GetFactory()->EstablishGpuChannel( | 152 GetFactory()->EstablishGpuChannel(kInitCause, run_loop.QuitClosure()); |
154 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE, | |
155 run_loop.QuitClosure()); | |
156 GetFactory()->Terminate(); | 153 GetFactory()->Terminate(); |
157 | 154 |
158 // The callback should still trigger. | 155 // The callback should still trigger. |
159 run_loop.Run(); | 156 run_loop.Run(); |
160 } | 157 } |
161 | 158 |
162 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, AlreadyEstablished) { | 159 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, AlreadyEstablished) { |
163 if (!context_) | 160 if (!context_) |
164 return; | 161 return; |
165 | 162 |
166 DCHECK(!IsChannelEstablished()); | 163 DCHECK(!IsChannelEstablished()); |
167 scoped_refptr<GpuChannelHost> gpu_channel = | 164 scoped_refptr<GpuChannelHost> gpu_channel = |
168 GetFactory()->EstablishGpuChannelSync( | 165 GetFactory()->EstablishGpuChannelSync(kInitCause); |
169 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE)
; | |
170 | 166 |
171 // Expect established callback immediately. | 167 // Expect established callback immediately. |
172 bool event = false; | 168 bool event = false; |
173 GetFactory()->EstablishGpuChannel( | 169 GetFactory()->EstablishGpuChannel( |
174 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE, | 170 kInitCause, |
175 base::Bind(&BrowserGpuChannelHostFactoryTest::Signal, &event)); | 171 base::Bind(&BrowserGpuChannelHostFactoryTest::Signal, &event)); |
176 EXPECT_TRUE(event); | 172 EXPECT_TRUE(event); |
177 EXPECT_EQ(gpu_channel, GetGpuChannel()); | 173 EXPECT_EQ(gpu_channel, GetGpuChannel()); |
178 } | 174 } |
179 | 175 |
180 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, CrashAndRecover) { | 176 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, CrashAndRecover) { |
181 if (!context_) | 177 if (!context_) |
182 return; | 178 return; |
183 | 179 |
184 DCHECK(!IsChannelEstablished()); | 180 DCHECK(!IsChannelEstablished()); |
(...skipping 15 matching lines...) Expand all Loading... |
200 shim->SimulateCrash(); | 196 shim->SimulateCrash(); |
201 run_loop.Run(); | 197 run_loop.Run(); |
202 | 198 |
203 EXPECT_EQ(1, counter); | 199 EXPECT_EQ(1, counter); |
204 EXPECT_FALSE(IsChannelEstablished()); | 200 EXPECT_FALSE(IsChannelEstablished()); |
205 EstablishAndWait(); | 201 EstablishAndWait(); |
206 EXPECT_TRUE(IsChannelEstablished()); | 202 EXPECT_TRUE(IsChannelEstablished()); |
207 } | 203 } |
208 | 204 |
209 } // namespace content | 205 } // namespace content |
OLD | NEW |