| 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/run_loop.h" | 5 #include "base/command_line.h" |
| 6 #include "cc/resources/sync_point_helper.h" | |
| 7 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 6 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
| 8 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 7 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
| 8 #include "content/public/common/content_switches.h" |
| 9 #include "content/test/content_browser_test.h" | 9 #include "content/test/content_browser_test.h" |
| 10 #include "gpu/GLES2/gl2extchromium.h" | 10 #include "ui/gl/gl_switches.h" |
| 11 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.
h" | 11 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.
h" |
| 12 | 12 |
| 13 namespace content { | |
| 14 namespace { | 13 namespace { |
| 15 | 14 |
| 16 enum ContextType { | 15 class ContextTestBase : public content::ContentBrowserTest { |
| 17 GPU_SERVICE_CONTEXT, | 16 public: |
| 18 IN_PROCESS_CONTEXT, | 17 virtual void SetUpOnMainThread() OVERRIDE { |
| 19 }; | 18 CHECK(content::BrowserGpuChannelHostFactory::instance()); |
| 19 context_.reset( |
| 20 content::WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext( |
| 21 content::BrowserGpuChannelHostFactory::instance(), |
| 22 WebKit::WebGraphicsContext3D::Attributes(), |
| 23 GURL())); |
| 24 CHECK(context_.get()); |
| 25 context_->makeContextCurrent(); |
| 26 ContentBrowserTest::SetUpOnMainThread(); |
| 27 } |
| 20 | 28 |
| 21 class SignalBrowserTest | 29 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 22 : public ContentBrowserTest, | 30 // TODO(Hubbe): This code is very similar to some code in |
| 23 public ::testing::WithParamInterface<ContextType> { | 31 // test/gpu/gpu_feature_browsertest.cc, and should really be |
| 24 public: | 32 // shared in a common location. |
| 25 virtual void SetUp() { | 33 if (!command_line->HasSwitch(switches::kUseGpuInTests)) { |
| 26 switch (GetParam()) { | 34 CHECK(!command_line->HasSwitch(switches::kUseGL)) |
| 27 case GPU_SERVICE_CONTEXT: | 35 << "kUseGL must not be set by test framework code!"; |
| 28 context_.reset( | 36 command_line->AppendSwitchASCII(switches::kUseGL, |
| 29 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext( | 37 gfx::kGLImplementationOSMesaName); |
| 30 BrowserGpuChannelHostFactory::instance(), | |
| 31 WebKit::WebGraphicsContext3D::Attributes(), | |
| 32 GURL())); | |
| 33 break; | |
| 34 case IN_PROCESS_CONTEXT: | |
| 35 context_ = | |
| 36 webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl:: | |
| 37 CreateOffscreenContext(WebKit::WebGraphicsContext3D::Attributes()); | |
| 38 break; | |
| 39 } | 38 } |
| 40 } | 39 } |
| 41 | 40 |
| 42 // These tests should time out if the callback doesn't get called. | 41 virtual void TearDownOnMainThread() OVERRIDE { |
| 43 void testSignalSyncPoint(unsigned sync_point) { | 42 // Must delete the context first. |
| 44 base::RunLoop run_loop; | 43 context_.reset(NULL); |
| 45 cc::SyncPointHelper::SignalSyncPoint( | 44 ContentBrowserTest::TearDownOnMainThread(); |
| 46 context_.get(), sync_point, run_loop.QuitClosure()); | |
| 47 run_loop.Run(); | |
| 48 } | |
| 49 | |
| 50 // These tests should time out if the callback doesn't get called. | |
| 51 void testSignalQuery(WebKit::WebGLId query) { | |
| 52 base::RunLoop run_loop; | |
| 53 cc::SyncPointHelper::SignalQuery( | |
| 54 context_.get(), query, run_loop.QuitClosure()); | |
| 55 run_loop.Run(); | |
| 56 } | 45 } |
| 57 | 46 |
| 58 protected: | 47 protected: |
| 59 scoped_ptr<WebKit::WebGraphicsContext3D> context_; | 48 scoped_ptr<WebKit::WebGraphicsContext3D> context_; |
| 60 }; | 49 }; |
| 61 | 50 |
| 62 IN_PROC_BROWSER_TEST_P(SignalBrowserTest, BasicSignalSyncPointTest) { | 51 } // namespace |
| 63 testSignalSyncPoint(context_->insertSyncPoint()); | |
| 64 }; | |
| 65 | 52 |
| 66 IN_PROC_BROWSER_TEST_P(SignalBrowserTest, InvalidSignalSyncPointTest) { | 53 // Include the actual tests. |
| 67 // Signalling something that doesn't exist should run the callback | 54 #define CONTEXT_TEST_F IN_PROC_BROWSER_TEST_F |
| 68 // immediately. | 55 #include "content/common/gpu/client/gpu_context_tests.h" |
| 69 testSignalSyncPoint(1297824234); | |
| 70 }; | |
| 71 | |
| 72 IN_PROC_BROWSER_TEST_P(SignalBrowserTest, BasicSignalQueryTest) { | |
| 73 unsigned query = context_->createQueryEXT(); | |
| 74 context_->beginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, query); | |
| 75 context_->finish(); | |
| 76 context_->endQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); | |
| 77 testSignalQuery(query); | |
| 78 context_->deleteQueryEXT(query); | |
| 79 }; | |
| 80 | |
| 81 IN_PROC_BROWSER_TEST_P(SignalBrowserTest, SignalQueryUnboundTest) { | |
| 82 WebKit::WebGLId query = context_->createQueryEXT(); | |
| 83 testSignalQuery(query); | |
| 84 context_->deleteQueryEXT(query); | |
| 85 }; | |
| 86 | |
| 87 IN_PROC_BROWSER_TEST_P(SignalBrowserTest, InvalidSignalQueryUnboundTest) { | |
| 88 // Signalling something that doesn't exist should run the callback | |
| 89 // immediately. | |
| 90 testSignalQuery(928729087); | |
| 91 }; | |
| 92 | |
| 93 INSTANTIATE_TEST_CASE_P(, SignalBrowserTest, | |
| 94 ::testing::Values(GPU_SERVICE_CONTEXT, | |
| 95 IN_PROCESS_CONTEXT)); | |
| 96 | |
| 97 } // namespace | |
| 98 } // namespace content | |
| OLD | NEW |