Chromium Code Reviews| Index: chrome/service/service_ipc_server_unittest.cc |
| diff --git a/chrome/service/service_ipc_server_unittest.cc b/chrome/service/service_ipc_server_unittest.cc |
| index f05d719f583dbe9049ab010139816eec446a43ae..a99dd247ae80917004b080b98df88b38da42bdd1 100644 |
| --- a/chrome/service/service_ipc_server_unittest.cc |
| +++ b/chrome/service/service_ipc_server_unittest.cc |
| @@ -4,6 +4,8 @@ |
| #include "chrome/service/service_ipc_server.h" |
| +#include <utility> |
| + |
| #include "base/bind.h" |
| #include "base/bind_helpers.h" |
| #include "base/memory/ptr_util.h" |
| @@ -16,6 +18,8 @@ |
| #include "chrome/common/service_messages.h" |
| #include "ipc/ipc_channel.h" |
| #include "ipc/ipc_channel_handle.h" |
| +#include "ipc/ipc_channel_mojo.h" |
| +#include "mojo/public/cpp/system/message_pipe.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| namespace { |
| @@ -32,11 +36,14 @@ class FakeServiceIPCServerClient : public ServiceIPCServer::Client { |
| ~FakeServiceIPCServerClient() override {} |
| void OnShutdown() override; |
| void OnUpdateAvailable() override; |
| + void OnStayAliveForTesting() override; |
| bool OnIPCClientDisconnect() override; |
| + mojo::ScopedMessagePipeHandle CreateChannelMessagePipe() override; |
| int shutdown_calls = 0; |
| int update_available_calls = 0; |
| int ipc_client_disconnect_calls = 0; |
| + mojo::ScopedMessagePipeHandle channel_handle; |
|
Lei Zhang
2016/09/01 06:12:01
channel_handle_ ? Fix the over variables if you'd
Sam McNally
2016/09/01 06:58:45
Done.
|
| }; |
| void FakeServiceIPCServerClient::OnShutdown() { |
| @@ -47,6 +54,8 @@ void FakeServiceIPCServerClient::OnUpdateAvailable() { |
| update_available_calls++; |
| } |
| +void FakeServiceIPCServerClient::OnStayAliveForTesting() {} |
| + |
| bool FakeServiceIPCServerClient::OnIPCClientDisconnect() { |
| ipc_client_disconnect_calls++; |
| @@ -55,6 +64,13 @@ bool FakeServiceIPCServerClient::OnIPCClientDisconnect() { |
| return true; |
| } |
| +mojo::ScopedMessagePipeHandle |
| +FakeServiceIPCServerClient::CreateChannelMessagePipe() { |
| + mojo::MessagePipe channel; |
| + channel_handle = std::move(channel.handle0); |
| + return std::move(channel.handle1); |
| +} |
| + |
| class FakeChannelListener : public IPC::Listener { |
| public: |
| FakeChannelListener() {} |
| @@ -104,7 +120,6 @@ class ServiceIPCServerTest : public ::testing::Test { |
| protected: |
| FakeServiceIPCServerClient service_process_client_; |
| - IPC::ChannelHandle channel_handle_; |
| base::MessageLoopForUI main_message_loop_; |
| base::Thread io_thread_; |
| base::WaitableEvent shutdown_event_; |
| @@ -114,19 +129,18 @@ class ServiceIPCServerTest : public ::testing::Test { |
| }; |
| ServiceIPCServerTest::ServiceIPCServerTest() |
| - : channel_handle_(IPC::Channel::GenerateUniqueRandomChannelID()), |
| - io_thread_("ServiceIPCServerTest IO"), |
| + : io_thread_("ServiceIPCServerTest IO"), |
| shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, |
| base::WaitableEvent::InitialState::NOT_SIGNALED) {} |
| void ServiceIPCServerTest::SetUp() { |
| base::Thread::Options options; |
| + mojo::MessagePipe channel; |
| options.message_loop_type = base::MessageLoop::TYPE_IO; |
| ASSERT_TRUE(io_thread_.StartWithOptions(options)); |
| server_.reset(new ServiceIPCServer(&service_process_client_, |
| io_thread_.task_runner(), |
| - channel_handle_, |
| &shutdown_event_)); |
| server_->Init(); |
| } |
| @@ -155,12 +169,11 @@ void ServiceIPCServerTest::PumpLoops() { |
| void ServiceIPCServerTest::ConnectClientChannel() { |
| client_process_channel_ = IPC::SyncChannel::Create( |
| - channel_handle_, |
| - IPC::Channel::MODE_NAMED_CLIENT, |
| - &client_process_channel_listener_, |
| - io_thread_.task_runner(), |
| - true /* create_pipe_now */, |
| - &shutdown_event_); |
| + IPC::ChannelMojo::CreateClientFactory( |
| + std::move(service_process_client_.channel_handle), |
| + io_thread_.task_runner()), |
| + &client_process_channel_listener_, io_thread_.task_runner(), |
| + true /* create_pipe_now */, &shutdown_event_); |
| PumpLoops(); |
| } |
| @@ -188,17 +201,8 @@ TEST_F(ServiceIPCServerTest, ConnectDisconnectReconnect) { |
| ASSERT_FALSE(server_->is_ipc_client_connected()); |
| ASSERT_EQ(1, service_process_client_.ipc_client_disconnect_calls); |
| - // On Windows only, the server recreates its channel in OnChannelError, if the |
| - // service process client tells it to continue listening. On other platforms |
| - // the channel is reused for subsequent reconnects by the client process. This |
| - // means however that OnChannelConnected is not called again and the server is |
| - // only aware of being connected once an IPC message is received. |
| ConnectClientChannel(); |
| -#if defined(OS_WIN) |
| ASSERT_TRUE(server_->is_ipc_client_connected()); |
| -#else |
| - ASSERT_FALSE(server_->is_ipc_client_connected()); |
| -#endif |
| SendToServiceProcess(new ServiceMsg_UpdateAvailable()); |
| ASSERT_TRUE(server_->is_ipc_client_connected()); |