OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "ipc/ipc_test_base.h" | 5 #include "ipc/ipc_test_base.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/process/kill.h" | 11 #include "base/process/kill.h" |
| 12 #include "base/run_loop.h" |
12 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
13 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 #include "ipc/ipc_channel_mojo.h" |
16 #include "ipc/ipc_descriptors.h" | 18 #include "ipc/ipc_descriptors.h" |
17 | 19 |
18 #if defined(OS_POSIX) | 20 #if defined(OS_POSIX) |
19 #include "base/posix/global_descriptors.h" | 21 #include "base/posix/global_descriptors.h" |
20 #endif | 22 #endif |
21 | 23 |
22 // static | 24 // static |
23 std::string IPCTestBase::GetChannelName(const std::string& test_client_name) { | 25 std::string IPCTestBase::GetChannelName(const std::string& test_client_name) { |
24 DCHECK(!test_client_name.empty()); | 26 DCHECK(!test_client_name.empty()); |
25 return test_client_name + "__Channel"; | 27 return test_client_name + "__Channel"; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 | 163 |
162 scoped_refptr<base::SingleThreadTaskRunner> IPCTestBase::task_runner() { | 164 scoped_refptr<base::SingleThreadTaskRunner> IPCTestBase::task_runner() { |
163 return message_loop_->task_runner(); | 165 return message_loop_->task_runner(); |
164 } | 166 } |
165 | 167 |
166 std::unique_ptr<IPC::ChannelFactory> IPCTestBase::CreateChannelFactory( | 168 std::unique_ptr<IPC::ChannelFactory> IPCTestBase::CreateChannelFactory( |
167 const IPC::ChannelHandle& handle, | 169 const IPC::ChannelHandle& handle, |
168 base::SingleThreadTaskRunner* runner) { | 170 base::SingleThreadTaskRunner* runner) { |
169 return IPC::ChannelFactory::Create(handle, IPC::Channel::MODE_SERVER, runner); | 171 return IPC::ChannelFactory::Create(handle, IPC::Channel::MODE_SERVER, runner); |
170 } | 172 } |
| 173 IPCChannelMojoTestBase::IPCChannelMojoTestBase() = default; |
| 174 IPCChannelMojoTestBase::~IPCChannelMojoTestBase() = default; |
| 175 |
| 176 void IPCChannelMojoTestBase::Init(const std::string& test_client_name) { |
| 177 handle_ = helper_.StartChild(test_client_name); |
| 178 } |
| 179 |
| 180 bool IPCChannelMojoTestBase::WaitForClientShutdown() { |
| 181 return helper_.WaitForChildTestShutdown(); |
| 182 } |
| 183 |
| 184 void IPCChannelMojoTestBase::TearDown() { |
| 185 base::RunLoop().RunUntilIdle(); |
| 186 } |
| 187 |
| 188 void IPCChannelMojoTestBase::CreateChannel(IPC::Listener* listener) { |
| 189 channel_ = |
| 190 IPC::ChannelMojo::Create(TakeHandle(), IPC::Channel::MODE_SERVER, |
| 191 listener, base::ThreadTaskRunnerHandle::Get()); |
| 192 } |
| 193 |
| 194 bool IPCChannelMojoTestBase::ConnectChannel() { |
| 195 return channel_->Connect(); |
| 196 } |
| 197 |
| 198 void IPCChannelMojoTestBase::DestroyChannel() { |
| 199 channel_.reset(); |
| 200 } |
| 201 |
| 202 mojo::ScopedMessagePipeHandle IPCChannelMojoTestBase::TakeHandle() { |
| 203 return std::move(handle_); |
| 204 } |
| 205 |
| 206 IpcChannelMojoTestClient::IpcChannelMojoTestClient() = default; |
| 207 |
| 208 IpcChannelMojoTestClient::~IpcChannelMojoTestClient() = default; |
| 209 |
| 210 void IpcChannelMojoTestClient::Init(mojo::ScopedMessagePipeHandle handle) { |
| 211 handle_ = std::move(handle); |
| 212 } |
| 213 |
| 214 void IpcChannelMojoTestClient::Connect(IPC::Listener* listener) { |
| 215 channel_ = |
| 216 IPC::ChannelMojo::Create(std::move(handle_), IPC::Channel::MODE_CLIENT, |
| 217 listener, base::ThreadTaskRunnerHandle::Get()); |
| 218 CHECK(channel_->Connect()); |
| 219 } |
| 220 |
| 221 void IpcChannelMojoTestClient::Close() { |
| 222 channel_->Close(); |
| 223 |
| 224 base::RunLoop run_loop; |
| 225 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 226 run_loop.QuitClosure()); |
| 227 run_loop.Run(); |
| 228 } |
OLD | NEW |