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 "chrome/test/base/chrome_test_launcher.h"
7 #include "base/command_line.h"
8 #include "base/debug/leak_annotations.h"
9 #include "base/files/file_path.h"
10 #include "base/files/file_util.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_launcher.h"
24 #include "content/public/test/test_utils.h"
25 #include "ui/base/test/ui_controls.h"
27 #if defined(OS_MACOSX)
28 #include "chrome/browser/chrome_browser_application_mac.h"
29 #endif // defined(OS_MACOSX)
32 #include "ui/aura/test/ui_controls_factory_aura.h"
33 #include "ui/base/test/ui_controls_aura.h"
34 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
35 #include "ui/views/test/ui_controls_factory_desktop_aurax11.h"
39 #if defined(OS_CHROMEOS)
40 #include "ash/test/ui_controls_factory_ash.h"
43 #if defined(OS_LINUX) || defined(OS_ANDROID)
44 #include "chrome/app/chrome_crash_reporter_client.h"
49 class ChromeTestLauncherDelegate : public content::TestLauncherDelegate {
51 explicit ChromeTestLauncherDelegate(ChromeTestSuiteRunner* runner)
53 virtual ~ChromeTestLauncherDelegate() {}
55 virtual int RunTestSuite(int argc, char** argv) OVERRIDE {
56 return runner_->RunTestSuite(argc, argv);
59 virtual bool AdjustChildProcessCommandLine(
60 CommandLine* command_line, const base::FilePath& temp_data_dir) OVERRIDE {
61 CommandLine new_command_line(command_line->GetProgram());
62 CommandLine::SwitchMap switches = command_line->GetSwitches();
64 // Strip out user-data-dir if present. We will add it back in again later.
65 switches.erase(switches::kUserDataDir);
67 for (CommandLine::SwitchMap::const_iterator iter = switches.begin();
68 iter != switches.end(); ++iter) {
69 new_command_line.AppendSwitchNative((*iter).first, (*iter).second);
72 new_command_line.AppendSwitchPath(switches::kUserDataDir, temp_data_dir);
74 // file:// access for ChromeOS.
75 new_command_line.AppendSwitch(switches::kAllowFileAccess);
77 *command_line = new_command_line;
82 virtual content::ContentMainDelegate* CreateContentMainDelegate() OVERRIDE {
83 return new ChromeMainDelegate();
86 virtual void AdjustDefaultParallelJobs(int* default_jobs) OVERRIDE {
88 if (CommandLine::ForCurrentProcess()->HasSwitch(
89 switches::kAshBrowserTests)) {
92 "Disabling test parallelization for --ash-browsertests.\n");
95 #endif // defined(OS_WIN)
99 ChromeTestSuiteRunner* runner_;
101 DISALLOW_COPY_AND_ASSIGN(ChromeTestLauncherDelegate);
106 int LaunchChromeTests(int default_jobs,
107 ChromeTestSuiteRunner* runner,
110 #if defined(OS_MACOSX)
111 chrome_browser_application_mac::RegisterBrowserCrApp();
114 #if defined(OS_LINUX) || defined(OS_ANDROID)
115 // We leak this pointer intentionally. The breakpad client needs to outlive
117 chrome::ChromeCrashReporterClient* crash_client =
118 new chrome::ChromeCrashReporterClient();
119 ANNOTATE_LEAKING_OBJECT_PTR(crash_client);
120 crash_reporter::SetCrashReporterClient(crash_client);
123 ChromeTestLauncherDelegate launcher_delegate(runner);
124 return content::LaunchTests(&launcher_delegate, default_jobs, argc, argv);