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 "base/test/multiprocess_test.h"
6
7 #include "base/base_switches.h"
8 #include "base/command_line.h"
9
10 namespace base {
11
12 #if !defined(OS_ANDROID)
SpawnMultiProcessTestChild(const std::string & procname,const CommandLine & base_command_line,const LaunchOptions & options)13 ProcessHandle SpawnMultiProcessTestChild(
14 const std::string& procname,
15 const CommandLine& base_command_line,
16 const LaunchOptions& options) {
17 CommandLine command_line(base_command_line);
18 // TODO(viettrungluu): See comment above |MakeCmdLine()| in the header file.
19 // This is a temporary hack, since |MakeCmdLine()| has to provide a full
20 // command line.
21 if (!command_line.HasSwitch(switches::kTestChildProcess))
22 command_line.AppendSwitchASCII(switches::kTestChildProcess, procname);
23
24 ProcessHandle handle = kNullProcessHandle;
25 LaunchProcess(command_line, options, &handle);
26 return handle;
27 }
28 #endif // !defined(OS_ANDROID)
29
GetMultiProcessTestChildBaseCommandLine()30 CommandLine GetMultiProcessTestChildBaseCommandLine() {
31 return *CommandLine::ForCurrentProcess();
32 }
33
34 // MultiProcessTest ------------------------------------------------------------
35
MultiProcessTest()36 MultiProcessTest::MultiProcessTest() {
37 }
38
SpawnChild(const std::string & procname)39 ProcessHandle MultiProcessTest::SpawnChild(const std::string& procname) {
40 LaunchOptions options;
41 #if defined(OS_WIN)
42 options.start_hidden = true;
43 #endif
44 return SpawnChildWithOptions(procname, options);
45 }
46
SpawnChildWithOptions(const std::string & procname,const LaunchOptions & options)47 ProcessHandle MultiProcessTest::SpawnChildWithOptions(
48 const std::string& procname,
49 const LaunchOptions& options) {
50 return SpawnMultiProcessTestChild(procname, MakeCmdLine(procname), options);
51 }
52
MakeCmdLine(const std::string & procname)53 CommandLine MultiProcessTest::MakeCmdLine(const std::string& procname) {
54 CommandLine command_line = GetMultiProcessTestChildBaseCommandLine();
55 command_line.AppendSwitchASCII(switches::kTestChildProcess, procname);
56 return command_line;
57 }
58
59 } // namespace base
60