| 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 <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 std::unique_ptr<IPC::Channel> channel_; | 130 std::unique_ptr<IPC::Channel> channel_; |
| 131 std::unique_ptr<IPC::ChannelProxy> channel_proxy_; | 131 std::unique_ptr<IPC::ChannelProxy> channel_proxy_; |
| 132 | 132 |
| 133 base::Process client_process_; | 133 base::Process client_process_; |
| 134 | 134 |
| 135 DISALLOW_COPY_AND_ASSIGN(IPCTestBase); | 135 DISALLOW_COPY_AND_ASSIGN(IPCTestBase); |
| 136 }; | 136 }; |
| 137 | 137 |
| 138 class IPCChannelMojoTestBase : public testing::Test { | 138 class IPCChannelMojoTestBase : public testing::Test { |
| 139 public: | 139 public: |
| 140 class ClientHandle { |
| 141 public: |
| 142 ClientHandle(); |
| 143 ~ClientHandle(); |
| 144 |
| 145 void Init(const std::string& test_client_name); |
| 146 void CreateChannel(IPC::Listener* listener); |
| 147 bool ConnectChannel(); |
| 148 void DestroyChannel(); |
| 149 bool WaitForShutdown(); |
| 150 |
| 151 mojo::ScopedMessagePipeHandle TakeHandle(); |
| 152 |
| 153 IPC::Channel* channel() { return channel_.get(); } |
| 154 const base::Process& process() const { return helper_.test_child(); } |
| 155 |
| 156 private: |
| 157 mojo::ScopedMessagePipeHandle pipe_; |
| 158 mojo::edk::test::MultiprocessTestHelper helper_; |
| 159 std::unique_ptr<IPC::Channel> channel_; |
| 160 |
| 161 DISALLOW_COPY_AND_ASSIGN(ClientHandle); |
| 162 }; |
| 163 |
| 140 IPCChannelMojoTestBase(); | 164 IPCChannelMojoTestBase(); |
| 141 ~IPCChannelMojoTestBase() override; | 165 ~IPCChannelMojoTestBase() override; |
| 142 | 166 |
| 143 void Init(const std::string& test_client_name); | 167 void Init(const std::string& test_client_name); |
| 144 | 168 |
| 145 bool WaitForClientShutdown(); | 169 bool WaitForClientShutdown(); |
| 146 | 170 |
| 147 void TearDown() override; | 171 void TearDown() override; |
| 148 | 172 |
| 149 void CreateChannel(IPC::Listener* listener); | 173 void CreateChannel(IPC::Listener* listener); |
| 150 | 174 |
| 151 bool ConnectChannel(); | 175 bool ConnectChannel(); |
| 152 | 176 |
| 153 void DestroyChannel(); | 177 void DestroyChannel(); |
| 154 | 178 |
| 155 IPC::Sender* sender() { return channel(); } | 179 IPC::Sender* sender() { return channel(); } |
| 156 IPC::Channel* channel() { return channel_.get(); } | 180 IPC::Channel* channel() { return primary_client_.channel(); } |
| 157 const base::Process& client_process() const { return helper_.test_child(); } | 181 const base::Process& client_process() const { |
| 182 return primary_client_.process(); |
| 183 } |
| 158 | 184 |
| 159 protected: | 185 protected: |
| 160 mojo::ScopedMessagePipeHandle TakeHandle(); | 186 mojo::ScopedMessagePipeHandle TakeHandle(); |
| 161 | 187 |
| 162 private: | 188 private: |
| 163 base::MessageLoop message_loop_; | 189 base::MessageLoop message_loop_; |
| 164 | 190 ClientHandle primary_client_; |
| 165 mojo::ScopedMessagePipeHandle handle_; | |
| 166 mojo::edk::test::MultiprocessTestHelper helper_; | |
| 167 | |
| 168 std::unique_ptr<IPC::Channel> channel_; | |
| 169 | 191 |
| 170 DISALLOW_COPY_AND_ASSIGN(IPCChannelMojoTestBase); | 192 DISALLOW_COPY_AND_ASSIGN(IPCChannelMojoTestBase); |
| 171 }; | 193 }; |
| 172 | 194 |
| 173 class IpcChannelMojoTestClient { | 195 class IpcChannelMojoTestClient { |
| 174 public: | 196 public: |
| 175 IpcChannelMojoTestClient(); | 197 IpcChannelMojoTestClient(); |
| 176 ~IpcChannelMojoTestClient(); | 198 ~IpcChannelMojoTestClient(); |
| 177 | 199 |
| 178 void Init(mojo::ScopedMessagePipeHandle handle); | 200 void Init(mojo::ScopedMessagePipeHandle handle); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 : 0; \ | 237 : 0; \ |
| 216 } \ | 238 } \ |
| 217 void client_name##_MainFixture::Main() | 239 void client_name##_MainFixture::Main() |
| 218 | 240 |
| 219 // Use this to declare the client side for tests using IPCChannelMojoTestBase. | 241 // Use this to declare the client side for tests using IPCChannelMojoTestBase. |
| 220 #define DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(client_name) \ | 242 #define DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(client_name) \ |
| 221 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT_WITH_CUSTOM_FIXTURE( \ | 243 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT_WITH_CUSTOM_FIXTURE( \ |
| 222 client_name, IpcChannelMojoTestClient) | 244 client_name, IpcChannelMojoTestClient) |
| 223 | 245 |
| 224 #endif // IPC_IPC_TEST_BASE_H_ | 246 #endif // IPC_IPC_TEST_BASE_H_ |
| OLD | NEW |