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"
7 #include "base/command_line.h"
8 #include "base/debug/leak_annotations.h"
9 #include "base/file_util.h"
10 #include "base/files/file_path.h"
11 #include "base/logging.h"
12 #include "base/memory/linked_ptr.h"
13 #include "base/process/process_metrics.h"
14 #include "base/run_loop.h"
15 #include "base/strings/string_util.h"
16 #include "base/test/test_file_util.h"
17 #include "chrome/app/chrome_main_delegate.h"
18 #include "chrome/common/chrome_constants.h"
19 #include "chrome/common/chrome_switches.h"
20 #include "chrome/test/base/chrome_test_suite.h"
21 #include "chrome/test/base/test_switches.h"
22 #include "content/public/app/content_main.h"
23 #include "content/public/test/test_utils.h"
24 #include "ui/base/test/ui_controls.h"
26 #if defined(OS_MACOSX)
27 #include "chrome/browser/chrome_browser_application_mac.h"
28 #endif // defined(OS_MACOSX)
31 #include "content/public/app/startup_helper_win.h"
32 #include "sandbox/win/src/sandbox_types.h"
33 #endif // defined(OS_WIN)
36 #include "ui/aura/test/ui_controls_factory_aura.h"
37 #include "ui/base/test/ui_controls_aura.h"
38 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
39 #include "ui/views/test/ui_controls_factory_desktop_aurax11.h"
43 #if defined(OS_CHROMEOS)
44 #include "ash/test/ui_controls_factory_ash.h"
47 #if defined(OS_LINUX) || defined(OS_ANDROID)
48 #include "chrome/app/chrome_breakpad_client.h"
53 class ChromeTestLauncherDelegate : public content::TestLauncherDelegate {
55 ChromeTestLauncherDelegate() {}
56 virtual ~ChromeTestLauncherDelegate() {}
58 virtual int RunTestSuite(int argc, char** argv) OVERRIDE {
59 return ChromeTestSuite(argc, argv).Run();
62 virtual bool AdjustChildProcessCommandLine(
63 CommandLine* command_line, const base::FilePath& temp_data_dir) OVERRIDE {
64 CommandLine new_command_line(command_line->GetProgram());
65 CommandLine::SwitchMap switches = command_line->GetSwitches();
67 // Strip out user-data-dir if present. We will add it back in again later.
68 switches.erase(switches::kUserDataDir);
70 for (CommandLine::SwitchMap::const_iterator iter = switches.begin();
71 iter != switches.end(); ++iter) {
72 new_command_line.AppendSwitchNative((*iter).first, (*iter).second);
75 new_command_line.AppendSwitchPath(switches::kUserDataDir, temp_data_dir);
77 // file:// access for ChromeOS.
78 new_command_line.AppendSwitch(switches::kAllowFileAccess);
80 *command_line = new_command_line;
85 virtual content::ContentMainDelegate* CreateContentMainDelegate() OVERRIDE {
86 #if defined(OS_WIN) || defined (OS_LINUX)
87 return new ChromeMainDelegate();
89 // This delegate is only guaranteed to link on linux and windows, so just
90 // bail out if we are on any other platform.
96 virtual void AdjustDefaultParallelJobs(int* default_jobs) OVERRIDE {
98 if (CommandLine::ForCurrentProcess()->HasSwitch(
99 switches::kAshBrowserTests)) {
102 "Disabling test parallelization for --ash-browsertests.\n");
105 #endif // defined(OS_WIN)
109 DISALLOW_COPY_AND_ASSIGN(ChromeTestLauncherDelegate);
114 int LaunchChromeTests(int default_jobs, int argc, char** argv) {
115 #if defined(OS_MACOSX)
116 chrome_browser_application_mac::RegisterBrowserCrApp();
119 #if defined(OS_LINUX) || defined(OS_ANDROID)
120 // We leak this pointer intentionally. The breakpad client needs to outlive
122 chrome::ChromeBreakpadClient* breakpad_client =
123 new chrome::ChromeBreakpadClient();
124 ANNOTATE_LEAKING_OBJECT_PTR(breakpad_client);
125 breakpad::SetBreakpadClient(breakpad_client);
128 ChromeTestLauncherDelegate launcher_delegate;
129 return content::LaunchTests(&launcher_delegate, default_jobs, argc, argv);