Upstream version 5.34.104.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 "content/public/test/test_launcher.h"
6
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"
25
26 #if defined(OS_MACOSX)
27 #include "chrome/browser/chrome_browser_application_mac.h"
28 #endif  // defined(OS_MACOSX)
29
30 #if defined(OS_WIN)
31 #include "content/public/app/startup_helper_win.h"
32 #include "sandbox/win/src/sandbox_types.h"
33 #endif  // defined(OS_WIN)
34
35 #if defined(USE_AURA)
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"
40 #endif
41 #endif
42
43 #if defined(OS_CHROMEOS)
44 #include "ash/test/ui_controls_factory_ash.h"
45 #endif
46
47 #if defined(OS_LINUX) || defined(OS_ANDROID)
48 #include "chrome/app/chrome_breakpad_client.h"
49 #endif
50
51 namespace {
52
53 class ChromeTestLauncherDelegate : public content::TestLauncherDelegate {
54  public:
55   ChromeTestLauncherDelegate() {}
56   virtual ~ChromeTestLauncherDelegate() {}
57
58   virtual int RunTestSuite(int argc, char** argv) OVERRIDE {
59     return ChromeTestSuite(argc, argv).Run();
60   }
61
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();
66
67     // Strip out user-data-dir if present.  We will add it back in again later.
68     switches.erase(switches::kUserDataDir);
69
70     for (CommandLine::SwitchMap::const_iterator iter = switches.begin();
71          iter != switches.end(); ++iter) {
72       new_command_line.AppendSwitchNative((*iter).first, (*iter).second);
73     }
74
75     new_command_line.AppendSwitchPath(switches::kUserDataDir, temp_data_dir);
76
77     // file:// access for ChromeOS.
78     new_command_line.AppendSwitch(switches::kAllowFileAccess);
79
80     *command_line = new_command_line;
81     return true;
82   }
83
84  protected:
85   virtual content::ContentMainDelegate* CreateContentMainDelegate() OVERRIDE {
86 #if defined(OS_WIN) || defined (OS_LINUX)
87     return new ChromeMainDelegate();
88 #else
89     // This delegate is only guaranteed to link on linux and windows, so just
90     // bail out if we are on any other platform.
91     NOTREACHED();
92     return NULL;
93 #endif
94   }
95
96   virtual void AdjustDefaultParallelJobs(int* default_jobs) OVERRIDE {
97 #if defined(OS_WIN)
98     if (CommandLine::ForCurrentProcess()->HasSwitch(
99             switches::kAshBrowserTests)) {
100       *default_jobs = 1;
101       fprintf(stdout,
102               "Disabling test parallelization for --ash-browsertests.\n");
103       fflush(stdout);
104     }
105 #endif  // defined(OS_WIN)
106   }
107
108  private:
109   DISALLOW_COPY_AND_ASSIGN(ChromeTestLauncherDelegate);
110 };
111
112 }  // namespace
113
114 int LaunchChromeTests(int default_jobs, int argc, char** argv) {
115 #if defined(OS_MACOSX)
116   chrome_browser_application_mac::RegisterBrowserCrApp();
117 #endif
118
119 #if defined(OS_LINUX) || defined(OS_ANDROID)
120   // We leak this pointer intentionally. The breakpad client needs to outlive
121   // all other code.
122   chrome::ChromeBreakpadClient* breakpad_client =
123       new chrome::ChromeBreakpadClient();
124   ANNOTATE_LEAKING_OBJECT_PTR(breakpad_client);
125   breakpad::SetBreakpadClient(breakpad_client);
126 #endif
127
128   ChromeTestLauncherDelegate launcher_delegate;
129   return content::LaunchTests(&launcher_delegate, default_jobs, argc, argv);
130 }