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" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 // (manually) destroy the channel proxy before the task runner's thread is | 69 // (manually) destroy the channel proxy before the task runner's thread is |
70 // destroyed. | 70 // destroyed. |
71 void CreateChannelProxy( | 71 void CreateChannelProxy( |
72 IPC::Listener* listener, | 72 IPC::Listener* listener, |
73 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner); | 73 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner); |
74 void DestroyChannelProxy(); | 74 void DestroyChannelProxy(); |
75 | 75 |
76 // Starts the client process, returning true if successful; this should be | 76 // Starts the client process, returning true if successful; this should be |
77 // done after connecting to the channel. | 77 // done after connecting to the channel. |
78 bool StartClient(); | 78 bool StartClient(); |
| 79 // A StartClient() variant that allows caller to pass the FD of IPC pipe |
| 80 bool StartClientWithFD(int ipcfd); |
79 | 81 |
80 // Waits for the client to shut down, returning true if successful. Note that | 82 // Waits for the client to shut down, returning true if successful. Note that |
81 // this does not initiate client shutdown; that must be done by the test | 83 // this does not initiate client shutdown; that must be done by the test |
82 // (somehow). This must be called before the end of the test whenever | 84 // (somehow). This must be called before the end of the test whenever |
83 // StartClient() was called successfully. | 85 // StartClient() was called successfully. |
84 bool WaitForClientShutdown(); | 86 bool WaitForClientShutdown(); |
85 | 87 |
| 88 IPC::ChannelHandle GetTestChannelHandle(); |
| 89 |
86 // Use this to send IPC messages (when you don't care if you're using a | 90 // Use this to send IPC messages (when you don't care if you're using a |
87 // channel or a proxy). | 91 // channel or a proxy). |
88 IPC::Sender* sender() { | 92 IPC::Sender* sender() { |
89 return channel_.get() ? static_cast<IPC::Sender*>(channel_.get()) : | 93 return channel_.get() ? static_cast<IPC::Sender*>(channel_.get()) : |
90 static_cast<IPC::Sender*>(channel_proxy_.get()); | 94 static_cast<IPC::Sender*>(channel_proxy_.get()); |
91 } | 95 } |
92 | 96 |
93 IPC::Channel* channel() { return channel_.get(); } | 97 IPC::Channel* channel() { return channel_.get(); } |
94 IPC::ChannelProxy* channel_proxy() { return channel_proxy_.get(); } | 98 IPC::ChannelProxy* channel_proxy() { return channel_proxy_.get(); } |
95 | 99 |
96 const base::ProcessHandle& client_process() const { return client_process_; } | 100 const base::ProcessHandle& client_process() const { return client_process_; } |
97 scoped_refptr<base::TaskRunner> task_runner(); | 101 scoped_refptr<base::TaskRunner> task_runner(); |
98 | 102 |
99 virtual scoped_ptr<IPC::ChannelFactory> CreateChannelFactory( | 103 virtual scoped_ptr<IPC::ChannelFactory> CreateChannelFactory( |
100 const IPC::ChannelHandle& handle, base::TaskRunner* runner); | 104 const IPC::ChannelHandle& handle, base::TaskRunner* runner); |
101 | 105 |
102 private: | 106 private: |
| 107 bool StartClientInternal(int ipcfd); |
| 108 |
103 std::string test_client_name_; | 109 std::string test_client_name_; |
104 scoped_ptr<base::MessageLoop> message_loop_; | 110 scoped_ptr<base::MessageLoop> message_loop_; |
105 | 111 |
106 scoped_ptr<IPC::Channel> channel_; | 112 scoped_ptr<IPC::Channel> channel_; |
107 scoped_ptr<IPC::ChannelProxy> channel_proxy_; | 113 scoped_ptr<IPC::ChannelProxy> channel_proxy_; |
108 | 114 |
109 base::ProcessHandle client_process_; | 115 base::ProcessHandle client_process_; |
110 | 116 |
111 DISALLOW_COPY_AND_ASSIGN(IPCTestBase); | 117 DISALLOW_COPY_AND_ASSIGN(IPCTestBase); |
112 }; | 118 }; |
113 | 119 |
114 // Use this to declare the client side for tests using IPCTestBase. | 120 // Use this to declare the client side for tests using IPCTestBase. |
115 #define MULTIPROCESS_IPC_TEST_CLIENT_MAIN(test_client_name) \ | 121 #define MULTIPROCESS_IPC_TEST_CLIENT_MAIN(test_client_name) \ |
116 MULTIPROCESS_IPC_TEST_MAIN(test_client_name ## TestClientMain) | 122 MULTIPROCESS_IPC_TEST_MAIN(test_client_name ## TestClientMain) |
117 | 123 |
118 #endif // IPC_IPC_TEST_BASE_H_ | 124 #endif // IPC_IPC_TEST_BASE_H_ |
OLD | NEW |