1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/public/test/test_launcher.h"
9 #include "base/command_line.h"
10 #include "base/debug/leak_annotations.h"
11 #include "base/file_util.h"
12 #include "base/files/file_path.h"
13 #include "base/logging.h"
14 #include "base/memory/linked_ptr.h"
15 #include "base/process/process_metrics.h"
16 #include "base/run_loop.h"
17 #include "base/strings/string_util.h"
18 #include "base/test/test_file_util.h"
19 #include "chrome/app/chrome_main_delegate.h"
20 #include "chrome/common/chrome_constants.h"
21 #include "chrome/common/chrome_switches.h"
22 #include "chrome/common/chrome_switches.h"
23 #include "chrome/test/base/chrome_test_suite.h"
24 #include "content/public/app/content_main.h"
25 #include "content/public/browser/browser_thread.h"
26 #include "content/public/test/test_utils.h"
27 #include "ui/base/test/ui_controls.h"
29 #if defined(OS_MACOSX)
30 #include "chrome/browser/chrome_browser_application_mac.h"
31 #endif // defined(OS_MACOSX)
34 #include "content/public/app/startup_helper_win.h"
35 #include "sandbox/win/src/sandbox_types.h"
36 #endif // defined(OS_WIN)
38 #if defined(TOOLKIT_VIEWS)
39 #include "ui/views/focus/accelerator_handler.h"
43 #include "ui/aura/test/ui_controls_factory_aura.h"
44 #include "ui/base/test/ui_controls_aura.h"
45 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
46 #include "ui/views/test/ui_controls_factory_desktop_aurax11.h"
50 #if defined(OS_CHROMEOS)
51 #include "ash/test/ui_controls_factory_ash.h"
54 #if defined(OS_LINUX) || defined(OS_ANDROID)
55 #include "chrome/app/chrome_breakpad_client.h"
60 class ChromeTestLauncherDelegate : public content::TestLauncherDelegate {
62 ChromeTestLauncherDelegate() {}
63 virtual ~ChromeTestLauncherDelegate() {}
65 virtual int RunTestSuite(int argc, char** argv) OVERRIDE {
66 return ChromeTestSuite(argc, argv).Run();
69 virtual bool AdjustChildProcessCommandLine(
70 CommandLine* command_line, const base::FilePath& temp_data_dir) OVERRIDE {
71 CommandLine new_command_line(command_line->GetProgram());
72 CommandLine::SwitchMap switches = command_line->GetSwitches();
74 // Strip out user-data-dir if present. We will add it back in again later.
75 switches.erase(switches::kUserDataDir);
77 for (CommandLine::SwitchMap::const_iterator iter = switches.begin();
78 iter != switches.end(); ++iter) {
79 new_command_line.AppendSwitchNative((*iter).first, (*iter).second);
82 new_command_line.AppendSwitchPath(switches::kUserDataDir, temp_data_dir);
84 // file:// access for ChromeOS.
85 new_command_line.AppendSwitch(switches::kAllowFileAccess);
87 *command_line = new_command_line;
91 virtual void PreRunMessageLoop(base::RunLoop* run_loop) OVERRIDE {
92 #if !defined(USE_AURA) && defined(TOOLKIT_VIEWS)
93 if (content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
94 linked_ptr<views::AcceleratorHandler> handler(
95 new views::AcceleratorHandler);
96 handlers_.push(handler);
97 run_loop->set_dispatcher(handler.get());
102 virtual void PostRunMessageLoop() OVERRIDE {
103 #if !defined(USE_AURA) && defined(TOOLKIT_VIEWS)
104 if (content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
105 DCHECK_EQ(handlers_.empty(), false);
112 virtual content::ContentMainDelegate* CreateContentMainDelegate() OVERRIDE {
113 #if defined(OS_WIN) || defined (OS_LINUX)
114 return new ChromeMainDelegate();
116 // This delegate is only guaranteed to link on linux and windows, so just
117 // bail out if we are on any other platform.
124 #if !defined(USE_AURA) && defined(TOOLKIT_VIEWS)
125 std::stack<linked_ptr<views::AcceleratorHandler> > handlers_;
128 DISALLOW_COPY_AND_ASSIGN(ChromeTestLauncherDelegate);
133 int LaunchChromeTests(int default_jobs, int argc, char** argv) {
134 #if defined(OS_MACOSX)
135 chrome_browser_application_mac::RegisterBrowserCrApp();
138 #if defined(OS_LINUX) || defined(OS_ANDROID)
139 // We leak this pointer intentionally. The breakpad client needs to outlive
141 chrome::ChromeBreakpadClient* breakpad_client =
142 new chrome::ChromeBreakpadClient();
143 ANNOTATE_LEAKING_OBJECT_PTR(breakpad_client);
144 breakpad::SetBreakpadClient(breakpad_client);
147 ChromeTestLauncherDelegate launcher_delegate;
148 return content::LaunchTests(&launcher_delegate, default_jobs, argc, argv);