OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef IPC_IPC_TEST_BASE_H_ | 5 #ifndef IPC_IPC_TEST_BASE_H_ |
6 #define IPC_IPC_TEST_BASE_H_ | 6 #define IPC_IPC_TEST_BASE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/process.h" | 12 #include "base/process.h" |
13 #include "base/test/multiprocess_test.h" | 13 #include "base/test/multiprocess_test.h" |
14 #include "ipc/ipc_channel.h" | 14 #include "ipc/ipc_channel.h" |
15 #include "ipc/ipc_channel_proxy.h" | 15 #include "ipc/ipc_channel_proxy.h" |
16 #include "ipc/ipc_multiprocess_test.h" | 16 #include "ipc/ipc_multiprocess_test.h" |
17 | 17 |
| 18 namespace base { |
18 class MessageLoopForIO; | 19 class MessageLoopForIO; |
| 20 } |
19 | 21 |
20 // A test fixture for multiprocess IPC tests. Such tests include a "client" side | 22 // A test fixture for multiprocess IPC tests. Such tests include a "client" side |
21 // (running in a separate process). The same client may be shared between | 23 // (running in a separate process). The same client may be shared between |
22 // several different tests. | 24 // several different tests. |
23 class IPCTestBase : public base::MultiProcessTest { | 25 class IPCTestBase : public base::MultiProcessTest { |
24 public: | 26 public: |
25 // The channel name is based on the client's name. This is a public static | 27 // The channel name is based on the client's name. This is a public static |
26 // helper to be used by the client-side code; server-side test code should | 28 // helper to be used by the client-side code; server-side test code should |
27 // usually not use this (directly). | 29 // usually not use this (directly). |
28 static std::string GetChannelName(const std::string& test_client_name); | 30 static std::string GetChannelName(const std::string& test_client_name); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 static_cast<IPC::Sender*>(channel_proxy_.get()); | 77 static_cast<IPC::Sender*>(channel_proxy_.get()); |
76 } | 78 } |
77 | 79 |
78 IPC::Channel* channel() { return channel_.get(); } | 80 IPC::Channel* channel() { return channel_.get(); } |
79 IPC::ChannelProxy* channel_proxy() { return channel_proxy_.get(); } | 81 IPC::ChannelProxy* channel_proxy() { return channel_proxy_.get(); } |
80 | 82 |
81 const base::ProcessHandle& client_process() const { return client_process_; } | 83 const base::ProcessHandle& client_process() const { return client_process_; } |
82 | 84 |
83 private: | 85 private: |
84 std::string test_client_name_; | 86 std::string test_client_name_; |
85 scoped_ptr<MessageLoopForIO> message_loop_; | 87 scoped_ptr<base::MessageLoopForIO> message_loop_; |
86 | 88 |
87 scoped_ptr<IPC::Channel> channel_; | 89 scoped_ptr<IPC::Channel> channel_; |
88 scoped_ptr<IPC::ChannelProxy> channel_proxy_; | 90 scoped_ptr<IPC::ChannelProxy> channel_proxy_; |
89 | 91 |
90 base::ProcessHandle client_process_; | 92 base::ProcessHandle client_process_; |
91 | 93 |
92 DISALLOW_COPY_AND_ASSIGN(IPCTestBase); | 94 DISALLOW_COPY_AND_ASSIGN(IPCTestBase); |
93 }; | 95 }; |
94 | 96 |
95 // Use this to declare the client side for tests using IPCTestBase. | 97 // Use this to declare the client side for tests using IPCTestBase. |
96 #define MULTIPROCESS_IPC_TEST_CLIENT_MAIN(test_client_name) \ | 98 #define MULTIPROCESS_IPC_TEST_CLIENT_MAIN(test_client_name) \ |
97 MULTIPROCESS_IPC_TEST_MAIN(test_client_name ## TestClientMain) | 99 MULTIPROCESS_IPC_TEST_MAIN(test_client_name ## TestClientMain) |
98 | 100 |
99 #endif // IPC_IPC_TEST_BASE_H_ | 101 #endif // IPC_IPC_TEST_BASE_H_ |
OLD | NEW |