Fixed last bookmark button hiding behavior.
[chromium-blink-merge.git] / base / test / multiprocess_test.h
blob7c3af3395dd458ffda07b3774562a6d968d46493
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 #ifndef BASE_TEST_MULTIPROCESS_TEST_H_
6 #define BASE_TEST_MULTIPROCESS_TEST_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/process.h"
12 #include "base/process_util.h"
13 #include "build/build_config.h"
14 #include "testing/platform_test.h"
16 class CommandLine;
18 namespace base {
20 // A MultiProcessTest is a test class which makes it easier to
21 // write a test which requires code running out of process.
23 // To create a multiprocess test simply follow these steps:
25 // 1) Derive your test from MultiProcessTest. Example:
27 // class MyTest : public MultiProcessTest {
28 // };
30 // TEST_F(MyTest, TestCaseName) {
31 // ...
32 // }
34 // 2) Create a mainline function for the child processes and include
35 // testing/multiprocess_func_list.h.
36 // See the declaration of the MULTIPROCESS_TEST_MAIN macro
37 // in that file for an example.
38 // 3) Call SpawnChild("foo"), where "foo" is the name of
39 // the function you wish to run in the child processes.
40 // That's it!
41 class MultiProcessTest : public PlatformTest {
42 public:
43 MultiProcessTest();
45 protected:
46 // Run a child process.
47 // 'procname' is the name of a function which the child will
48 // execute. It must be exported from this library in order to
49 // run.
51 // Example signature:
52 // extern "C" int __declspec(dllexport) FooBar() {
53 // // do client work here
54 // }
56 // Returns the handle to the child, or NULL on failure
57 ProcessHandle SpawnChild(const std::string& procname, bool debug_on_start);
59 #if defined(OS_POSIX)
60 // TODO(evan): see if we can delete this via more refactoring.
61 // SpawnChild() should just take a base::LaunchOptions so that we don't
62 // need multiple versions of it.
63 ProcessHandle SpawnChild(const std::string& procname,
64 const FileHandleMappingVector& fds_to_map,
65 bool debug_on_start);
66 #endif
68 // Set up the command line used to spawn the child process.
69 virtual CommandLine MakeCmdLine(const std::string& procname,
70 bool debug_on_start);
72 private:
73 // Shared implementation of SpawnChild.
74 // TODO: |fds_to_map| is unused on Windows; see above TODO about
75 // further refactoring.
76 ProcessHandle SpawnChildImpl(const std::string& procname,
77 const FileHandleMappingVector& fds_to_map,
78 bool debug_on_start);
80 DISALLOW_COPY_AND_ASSIGN(MultiProcessTest);
83 } // namespace base
85 #endif // BASE_TEST_MULTIPROCESS_TEST_H_