OLD | NEW |
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 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, quit_task); | 60 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, quit_task); |
58 } | 61 } |
59 | 62 |
60 } // namespace | 63 } // namespace |
61 | 64 |
62 extern int BrowserMain(const MainFunctionParams&); | 65 extern int BrowserMain(const MainFunctionParams&); |
63 | 66 |
64 BrowserTestBase::BrowserTestBase() | 67 BrowserTestBase::BrowserTestBase() |
65 : embedded_test_server_( | 68 : embedded_test_server_( |
66 new net::test_server::EmbeddedTestServer( | 69 new net::test_server::EmbeddedTestServer( |
67 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))) { | 70 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))), |
| 71 allow_test_contexts_(true), |
| 72 allow_osmesa_(true) { |
68 #if defined(OS_MACOSX) | 73 #if defined(OS_MACOSX) |
69 base::mac::SetOverrideAmIBundled(true); | 74 base::mac::SetOverrideAmIBundled(true); |
70 base::PowerMonitorDeviceSource::AllocateSystemIOPorts(); | 75 base::PowerMonitorDeviceSource::AllocateSystemIOPorts(); |
71 #endif | 76 #endif |
72 | 77 |
73 #if defined(OS_POSIX) | 78 #if defined(OS_POSIX) |
74 handle_sigterm_ = true; | 79 handle_sigterm_ = true; |
75 #endif | 80 #endif |
76 } | 81 } |
77 | 82 |
(...skipping 13 matching lines...) Expand all Loading... |
91 | 96 |
92 command_line->AppendSwitch(switches::kDomAutomationController); | 97 command_line->AppendSwitch(switches::kDomAutomationController); |
93 | 98 |
94 command_line->AppendSwitch(switches::kSkipGpuDataLoading); | 99 command_line->AppendSwitch(switches::kSkipGpuDataLoading); |
95 | 100 |
96 MainFunctionParams params(*command_line); | 101 MainFunctionParams params(*command_line); |
97 params.ui_task = | 102 params.ui_task = |
98 new base::Closure( | 103 new base::Closure( |
99 base::Bind(&BrowserTestBase::ProxyRunTestOnMainThreadLoop, this)); | 104 base::Bind(&BrowserTestBase::ProxyRunTestOnMainThreadLoop, this)); |
100 | 105 |
| 106 #if defined(USE_AURA) |
| 107 // Use test contexts for browser tests unless they override and force us to |
| 108 // use a real context. |
| 109 if (allow_test_contexts_) |
| 110 command_line->AppendSwitch(switches::kTestCompositor); |
| 111 #endif |
| 112 |
| 113 // When using real GL contexts, we usually use OSMesa as this works on all |
| 114 // bots. The command line can override this behaviour to use a real GPU. |
| 115 if (command_line->HasSwitch(switches::kUseGpuInTests)) |
| 116 allow_osmesa_ = false; |
| 117 |
| 118 #if defined(OS_MACOSX) |
| 119 // On Mac we always use a real GPU. |
| 120 allow_osmesa_ = false; |
| 121 #endif |
| 122 |
| 123 if (command_line->HasSwitch(switches::kUseGL)) { |
| 124 NOTREACHED() << |
| 125 "kUseGL should not be used with tests. Try kUseGpuInTests instead."; |
| 126 } |
| 127 |
| 128 if (allow_osmesa_) { |
| 129 command_line->AppendSwitchASCII( |
| 130 switches::kUseGL, gfx::kGLImplementationOSMesaName); |
| 131 } |
| 132 |
101 SetUpInProcessBrowserTestFixture(); | 133 SetUpInProcessBrowserTestFixture(); |
102 #if defined(OS_ANDROID) | 134 #if defined(OS_ANDROID) |
103 BrowserMainRunner::Create()->Initialize(params); | 135 BrowserMainRunner::Create()->Initialize(params); |
104 // We are done running the test by now. During teardown we | 136 // We are done running the test by now. During teardown we |
105 // need to be able to perform IO. | 137 // need to be able to perform IO. |
106 base::ThreadRestrictions::SetIOAllowed(true); | 138 base::ThreadRestrictions::SetIOAllowed(true); |
107 BrowserThread::PostTask( | 139 BrowserThread::PostTask( |
108 BrowserThread::IO, FROM_HERE, | 140 BrowserThread::IO, FROM_HERE, |
109 base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed), | 141 base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed), |
110 true)); | 142 true)); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 RenderProcessHostImpl::GetInProcessRendererThreadForTesting(); | 178 RenderProcessHostImpl::GetInProcessRendererThreadForTesting(); |
147 CHECK(renderer_loop); | 179 CHECK(renderer_loop); |
148 | 180 |
149 renderer_loop->PostTask( | 181 renderer_loop->PostTask( |
150 FROM_HERE, | 182 FROM_HERE, |
151 base::Bind(&RunTaskOnRendererThread, task, runner->QuitClosure())); | 183 base::Bind(&RunTaskOnRendererThread, task, runner->QuitClosure())); |
152 runner->Run(); | 184 runner->Run(); |
153 } | 185 } |
154 | 186 |
155 } // namespace content | 187 } // namespace content |
OLD | NEW |