Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / test / base / chrome_test_launcher.cc
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.
4
5 #include "chrome/test/base/chrome_test_launcher.h"
6
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"
26
27 #if defined(OS_MACOSX)
28 #include "chrome/browser/chrome_browser_application_mac.h"
29 #endif  // defined(OS_MACOSX)
30
31 #if defined(USE_AURA)
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"
36 #endif
37 #endif
38
39 #if defined(OS_CHROMEOS)
40 #include "ash/test/ui_controls_factory_ash.h"
41 #endif
42
43 #if defined(OS_LINUX) || defined(OS_ANDROID)
44 #include "chrome/app/chrome_crash_reporter_client.h"
45 #endif
46
47 namespace {
48
49 class ChromeTestLauncherDelegate : public content::TestLauncherDelegate {
50  public:
51   explicit ChromeTestLauncherDelegate(ChromeTestSuiteRunner* runner)
52       : runner_(runner) {}
53   virtual ~ChromeTestLauncherDelegate() {}
54
55   virtual int RunTestSuite(int argc, char** argv) OVERRIDE {
56     return runner_->RunTestSuite(argc, argv);
57   }
58
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();
63
64     // Strip out user-data-dir if present.  We will add it back in again later.
65     switches.erase(switches::kUserDataDir);
66
67     for (CommandLine::SwitchMap::const_iterator iter = switches.begin();
68          iter != switches.end(); ++iter) {
69       new_command_line.AppendSwitchNative((*iter).first, (*iter).second);
70     }
71
72     new_command_line.AppendSwitchPath(switches::kUserDataDir, temp_data_dir);
73
74     // file:// access for ChromeOS.
75     new_command_line.AppendSwitch(switches::kAllowFileAccess);
76
77     *command_line = new_command_line;
78     return true;
79   }
80
81  protected:
82   virtual content::ContentMainDelegate* CreateContentMainDelegate() OVERRIDE {
83     return new ChromeMainDelegate();
84   }
85
86   virtual void AdjustDefaultParallelJobs(int* default_jobs) OVERRIDE {
87 #if defined(OS_WIN)
88     if (CommandLine::ForCurrentProcess()->HasSwitch(
89             switches::kAshBrowserTests)) {
90       *default_jobs = 1;
91       fprintf(stdout,
92               "Disabling test parallelization for --ash-browsertests.\n");
93       fflush(stdout);
94     }
95 #endif  // defined(OS_WIN)
96   }
97
98  private:
99   ChromeTestSuiteRunner* runner_;
100
101   DISALLOW_COPY_AND_ASSIGN(ChromeTestLauncherDelegate);
102 };
103
104 }  // namespace
105
106 int LaunchChromeTests(int default_jobs,
107                       ChromeTestSuiteRunner* runner,
108                       int argc,
109                       char** argv) {
110 #if defined(OS_MACOSX)
111   chrome_browser_application_mac::RegisterBrowserCrApp();
112 #endif
113
114 #if defined(OS_LINUX) || defined(OS_ANDROID)
115   // We leak this pointer intentionally. The breakpad client needs to outlive
116   // all other code.
117   chrome::ChromeCrashReporterClient* crash_client =
118       new chrome::ChromeCrashReporterClient();
119   ANNOTATE_LEAKING_OBJECT_PTR(crash_client);
120   crash_reporter::SetCrashReporterClient(crash_client);
121 #endif
122
123   ChromeTestLauncherDelegate launcher_delegate(runner);
124   return content::LaunchTests(&launcher_delegate, default_jobs, argc, argv);
125 }