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

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

Issue 14304004: Convert a bunch of test_shell_tests to content_browsertests. These are tests that depend on loading… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync Created 7 years, 8 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/renderer/DEPS » ('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 "base/process_util.h" 10 #include "base/process_util.h"
11 #include "content/browser/renderer_host/render_process_host_impl.h"
12 #include "content/public/browser/browser_thread.h"
11 #include "content/public/common/content_switches.h" 13 #include "content/public/common/content_switches.h"
12 #include "content/public/common/main_function_params.h" 14 #include "content/public/common/main_function_params.h"
15 #include "content/public/test/test_utils.h"
13 16
14 #if defined(OS_MACOSX) 17 #if defined(OS_MACOSX)
15 #include "base/mac/mac_util.h" 18 #include "base/mac/mac_util.h"
16 #include "base/power_monitor/power_monitor.h" 19 #include "base/power_monitor/power_monitor.h"
17 #endif 20 #endif
18 21
19 #if defined(OS_ANDROID) 22 #if defined(OS_ANDROID)
20 #include "base/threading/thread_restrictions.h" 23 #include "base/threading/thread_restrictions.h"
21 #include "content/public/browser/browser_main_runner.h" 24 #include "content/public/browser/browser_main_runner.h"
22 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
23 #endif 26 #endif
24 27
28 namespace content {
25 namespace { 29 namespace {
26 30
27 #if defined(OS_POSIX) 31 #if defined(OS_POSIX)
28 // On SIGTERM (sent by the runner on timeouts), dump a stack trace (to make 32 // On SIGTERM (sent by the runner on timeouts), dump a stack trace (to make
29 // debugging easier) and also exit with a known error code (so that the test 33 // debugging easier) and also exit with a known error code (so that the test
30 // framework considers this a failure -- http://crbug.com/57578). 34 // framework considers this a failure -- http://crbug.com/57578).
31 // Note: We only want to do this in the browser process, and not forked 35 // Note: We only want to do this in the browser process, and not forked
32 // processes. That might lead to hangs because of locks inside tcmalloc or the 36 // processes. That might lead to hangs because of locks inside tcmalloc or the
33 // OS. See http://crbug.com/141302. 37 // OS. See http://crbug.com/141302.
34 static int g_browser_process_pid; 38 static int g_browser_process_pid;
35 static void DumpStackTraceSignalHandler(int signal) { 39 static void DumpStackTraceSignalHandler(int signal) {
36 if (g_browser_process_pid == base::GetCurrentProcId()) { 40 if (g_browser_process_pid == base::GetCurrentProcId()) {
37 logging::RawLog(logging::LOG_ERROR, 41 logging::RawLog(logging::LOG_ERROR,
38 "BrowserTestBase signal handler received SIGTERM. " 42 "BrowserTestBase signal handler received SIGTERM. "
39 "Backtrace:\n"); 43 "Backtrace:\n");
40 base::debug::StackTrace().PrintBacktrace(); 44 base::debug::StackTrace().PrintBacktrace();
41 } 45 }
42 _exit(128 + signal); 46 _exit(128 + signal);
43 } 47 }
44 #endif // defined(OS_POSIX) 48 #endif // defined(OS_POSIX)
45 49
50 void RunTaskOnRendererThread(const base::Closure& task,
51 const base::Closure& quit_task) {
52 task.Run();
53 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, quit_task);
54 }
55
46 } // namespace 56 } // namespace
47 57
48 namespace content { 58 extern int BrowserMain(const MainFunctionParams&);
49
50 extern int BrowserMain(const content::MainFunctionParams&);
51 59
52 BrowserTestBase::BrowserTestBase() { 60 BrowserTestBase::BrowserTestBase() {
53 #if defined(OS_MACOSX) 61 #if defined(OS_MACOSX)
54 base::mac::SetOverrideAmIBundled(true); 62 base::mac::SetOverrideAmIBundled(true);
55 base::PowerMonitor::AllocateSystemIOPorts(); 63 base::PowerMonitor::AllocateSystemIOPorts();
56 #endif 64 #endif
57 65
58 #if defined(OS_POSIX) 66 #if defined(OS_POSIX)
59 handle_sigterm_ = true; 67 handle_sigterm_ = true;
60 #endif 68 #endif
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } 121 }
114 122
115 void BrowserTestBase::CreateTestServer(const base::FilePath& test_server_base) { 123 void BrowserTestBase::CreateTestServer(const base::FilePath& test_server_base) {
116 CHECK(!test_server_.get()); 124 CHECK(!test_server_.get());
117 test_server_.reset(new net::TestServer( 125 test_server_.reset(new net::TestServer(
118 net::TestServer::TYPE_HTTP, 126 net::TestServer::TYPE_HTTP,
119 net::TestServer::kLocalhost, 127 net::TestServer::kLocalhost,
120 test_server_base)); 128 test_server_base));
121 } 129 }
122 130
131 void BrowserTestBase::PostTaskToInProcessRendererAndWait(
132 const base::Closure& task) {
133 CHECK(CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess));
134
135 scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner;
136
137 base::MessageLoop* renderer_loop =
138 RenderProcessHostImpl::GetInProcessRendererThreadForTesting();
139 CHECK(renderer_loop);
140
141 renderer_loop->PostTask(
142 FROM_HERE,
143 base::Bind(&RunTaskOnRendererThread, task, runner->QuitClosure()));
144 runner->Run();
145 }
146
123 } // namespace content 147 } // namespace content
OLDNEW
« no previous file with comments | « content/public/test/browser_test_base.h ('k') | content/renderer/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698