Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(671)

Side by Side Diff: content/public/test/browser_test_base.cc

Issue 22293003: Clean up compositor initialization/destruction. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanupcompositor: UseRealGLBindings in NetInternalsTest Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/public/test/browser_test_base.h ('k') | content/public/test/content_test_suite_base.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "content/public/test/browser_test_base.h" 5 #include "content/public/test/browser_test_base.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/debug/stack_trace.h" 9 #include "base/debug/stack_trace.h"
10 #include "content/browser/renderer_host/render_process_host_impl.h" 10 #include "content/browser/renderer_host/render_process_host_impl.h"
11 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/common/content_switches.h" 12 #include "content/public/common/content_switches.h"
13 #include "content/public/common/main_function_params.h" 13 #include "content/public/common/main_function_params.h"
14 #include "content/public/test/test_utils.h" 14 #include "content/public/test/test_utils.h"
15 #include "net/test/embedded_test_server/embedded_test_server.h" 15 #include "net/test/embedded_test_server/embedded_test_server.h"
16 #include "ui/compositor/compositor_switches.h"
17 #include "ui/gl/gl_implementation.h"
18 #include "ui/gl/gl_switches.h"
16 19
17 #if defined(OS_POSIX) 20 #if defined(OS_POSIX)
18 #include "base/process/process_handle.h" 21 #include "base/process/process_handle.h"
19 #endif 22 #endif
20 23
21 #if defined(OS_MACOSX) 24 #if defined(OS_MACOSX)
22 #include "base/mac/mac_util.h" 25 #include "base/mac/mac_util.h"
23 #include "base/power_monitor/power_monitor_device_source.h" 26 #include "base/power_monitor/power_monitor_device_source.h"
24 #endif 27 #endif
25 28
26 #if defined(OS_ANDROID) 29 #if defined(OS_ANDROID)
27 #include "base/threading/thread_restrictions.h" 30 #include "base/threading/thread_restrictions.h"
28 #include "content/public/browser/browser_main_runner.h" 31 #include "content/public/browser/browser_main_runner.h"
29 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
30 #endif 33 #endif
31 34
35 #if defined(OS_CHROMEOS)
36 #include "base/chromeos/chromeos_version.h"
37 #endif
38
32 namespace content { 39 namespace content {
33 namespace { 40 namespace {
34 41
35 #if defined(OS_POSIX) 42 #if defined(OS_POSIX)
36 // On SIGTERM (sent by the runner on timeouts), dump a stack trace (to make 43 // On SIGTERM (sent by the runner on timeouts), dump a stack trace (to make
37 // debugging easier) and also exit with a known error code (so that the test 44 // debugging easier) and also exit with a known error code (so that the test
38 // framework considers this a failure -- http://crbug.com/57578). 45 // framework considers this a failure -- http://crbug.com/57578).
39 // Note: We only want to do this in the browser process, and not forked 46 // Note: We only want to do this in the browser process, and not forked
40 // processes. That might lead to hangs because of locks inside tcmalloc or the 47 // processes. That might lead to hangs because of locks inside tcmalloc or the
41 // OS. See http://crbug.com/141302. 48 // OS. See http://crbug.com/141302.
(...skipping 15 matching lines...) Expand all
57 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, quit_task); 64 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, quit_task);
58 } 65 }
59 66
60 } // namespace 67 } // namespace
61 68
62 extern int BrowserMain(const MainFunctionParams&); 69 extern int BrowserMain(const MainFunctionParams&);
63 70
64 BrowserTestBase::BrowserTestBase() 71 BrowserTestBase::BrowserTestBase()
65 : embedded_test_server_( 72 : embedded_test_server_(
66 new net::test_server::EmbeddedTestServer( 73 new net::test_server::EmbeddedTestServer(
67 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))) { 74 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))),
75 allow_test_contexts_(true),
76 allow_osmesa_(true) {
68 #if defined(OS_MACOSX) 77 #if defined(OS_MACOSX)
69 base::mac::SetOverrideAmIBundled(true); 78 base::mac::SetOverrideAmIBundled(true);
70 base::PowerMonitorDeviceSource::AllocateSystemIOPorts(); 79 base::PowerMonitorDeviceSource::AllocateSystemIOPorts();
71 #endif 80 #endif
72 81
73 #if defined(OS_POSIX) 82 #if defined(OS_POSIX)
74 handle_sigterm_ = true; 83 handle_sigterm_ = true;
75 #endif 84 #endif
76 } 85 }
77 86
78 BrowserTestBase::~BrowserTestBase() { 87 BrowserTestBase::~BrowserTestBase() {
79 #if defined(OS_ANDROID) 88 #if defined(OS_ANDROID)
80 // RemoteTestServer can cause wait on the UI thread. 89 // RemoteTestServer can cause wait on the UI thread.
81 base::ThreadRestrictions::ScopedAllowWait allow_wait; 90 base::ThreadRestrictions::ScopedAllowWait allow_wait;
82 test_server_.reset(NULL); 91 test_server_.reset(NULL);
83 #endif 92 #endif
84 } 93 }
85 94
86 void BrowserTestBase::SetUp() { 95 void BrowserTestBase::SetUp() {
87 CommandLine* command_line = CommandLine::ForCurrentProcess(); 96 CommandLine* command_line = CommandLine::ForCurrentProcess();
88 97
89 // The tests assume that file:// URIs can freely access other file:// URIs. 98 // The tests assume that file:// URIs can freely access other file:// URIs.
90 command_line->AppendSwitch(switches::kAllowFileAccessFromFiles); 99 command_line->AppendSwitch(switches::kAllowFileAccessFromFiles);
91 100
92 command_line->AppendSwitch(switches::kDomAutomationController); 101 command_line->AppendSwitch(switches::kDomAutomationController);
93 102
94 command_line->AppendSwitch(switches::kSkipGpuDataLoading); 103 command_line->AppendSwitch(switches::kSkipGpuDataLoading);
95 104
96 MainFunctionParams params(*command_line); 105 MainFunctionParams params(*command_line);
gab 2013/08/15 19:40:46 Looks like the |command_line| is used here to laun
danakj 2013/08/15 20:15:13 Hm, it seems to work fine in practice for these sw
gab 2013/08/15 20:18:46 Ah, just noticed that it seems MainFunctionParams
97 params.ui_task = 106 params.ui_task =
98 new base::Closure( 107 new base::Closure(
99 base::Bind(&BrowserTestBase::ProxyRunTestOnMainThreadLoop, this)); 108 base::Bind(&BrowserTestBase::ProxyRunTestOnMainThreadLoop, this));
100 109
110 #if defined(USE_AURA)
111 // Use test contexts for browser tests unless they override and force us to
112 // use a real context.
113 if (allow_test_contexts_)
114 command_line->AppendSwitch(switches::kTestCompositor);
115 #endif
116
117 // When using real GL contexts, we usually use OSMesa as this works on all
118 // bots. The command line can override this behaviour to use a real GPU.
119 if (command_line->HasSwitch(switches::kUseGpuInTests))
120 allow_osmesa_ = false;
121
122 // Some bots pass this flag when they want to use a real GPU.
123 if (command_line->HasSwitch("enable-gpu"))
124 allow_osmesa_ = false;
125
126 #if defined(OS_MACOSX)
127 // On Mac we always use a real GPU.
128 allow_osmesa_ = false;
129 #endif
130
131 #if defined(OS_ANDROID)
132 // On Android we always use a real GPU.
133 allow_osmesa_ = false;
134 #endif
135
136 #if defined(OS_CHROMEOS)
137 // If the test is running on the chromeos envrionment (such as
138 // device or vm bots), the compositor will use real GL contexts, and
139 // we should use real GL bindings with it.
140 if (base::chromeos::IsRunningOnChromeOS())
141 allow_osmesa_ = false;
142 #endif
143
144 if (command_line->HasSwitch(switches::kUseGL)) {
145 NOTREACHED() <<
146 "kUseGL should not be used with tests. Try kUseGpuInTests instead.";
147 }
148
149 if (allow_osmesa_) {
150 command_line->AppendSwitchASCII(
151 switches::kUseGL, gfx::kGLImplementationOSMesaName);
152 }
153
101 SetUpInProcessBrowserTestFixture(); 154 SetUpInProcessBrowserTestFixture();
102 #if defined(OS_ANDROID) 155 #if defined(OS_ANDROID)
103 BrowserMainRunner::Create()->Initialize(params); 156 BrowserMainRunner::Create()->Initialize(params);
104 // We are done running the test by now. During teardown we 157 // We are done running the test by now. During teardown we
105 // need to be able to perform IO. 158 // need to be able to perform IO.
106 base::ThreadRestrictions::SetIOAllowed(true); 159 base::ThreadRestrictions::SetIOAllowed(true);
107 BrowserThread::PostTask( 160 BrowserThread::PostTask(
108 BrowserThread::IO, FROM_HERE, 161 BrowserThread::IO, FROM_HERE,
109 base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed), 162 base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed),
110 true)); 163 true));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 RenderProcessHostImpl::GetInProcessRendererThreadForTesting(); 199 RenderProcessHostImpl::GetInProcessRendererThreadForTesting();
147 CHECK(renderer_loop); 200 CHECK(renderer_loop);
148 201
149 renderer_loop->PostTask( 202 renderer_loop->PostTask(
150 FROM_HERE, 203 FROM_HERE,
151 base::Bind(&RunTaskOnRendererThread, task, runner->QuitClosure())); 204 base::Bind(&RunTaskOnRendererThread, task, runner->QuitClosure()));
152 runner->Run(); 205 runner->Run();
153 } 206 }
154 207
155 } // namespace content 208 } // namespace content
OLDNEW
« no previous file with comments | « content/public/test/browser_test_base.h ('k') | content/public/test/content_test_suite_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698