| 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| 11 #include <stdint.h> | 11 #include <stdint.h> |
| 12 | 12 |
| 13 #include <memory> | 13 #include <memory> |
| 14 #include <string> | 14 #include <string> |
| 15 | 15 |
| 16 #include "base/pickle.h" | 16 #include "base/pickle.h" |
| 17 #include "base/run_loop.h" |
| 17 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
| 20 #include "ipc/ipc_test_base.h" | 21 #include "ipc/ipc_test_base.h" |
| 21 #include "ipc/ipc_test_channel_listener.h" | 22 #include "ipc/ipc_test_channel_listener.h" |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 class IPCChannelTest : public IPCTestBase { | 26 class IPCChannelTest : public IPCTestBase { |
| 26 }; | 27 }; |
| 27 | 28 |
| 28 TEST_F(IPCChannelTest, ChannelTest) { | 29 TEST_F(IPCChannelTest, ChannelTest) { |
| 29 Init("GenericClient"); | 30 Init("GenericClient"); |
| 30 | 31 |
| 31 // Set up IPC channel and start client. | 32 // Set up IPC channel and start client. |
| 32 IPC::TestChannelListener listener; | 33 IPC::TestChannelListener listener; |
| 33 CreateChannel(&listener); | 34 CreateChannel(&listener); |
| 34 listener.Init(sender()); | 35 listener.Init(sender()); |
| 35 ASSERT_TRUE(ConnectChannel()); | 36 ASSERT_TRUE(ConnectChannel()); |
| 36 ASSERT_TRUE(StartClient()); | 37 ASSERT_TRUE(StartClient()); |
| 37 | 38 |
| 38 IPC::TestChannelListener::SendOneMessage(sender(), "hello from parent"); | 39 IPC::TestChannelListener::SendOneMessage(sender(), "hello from parent"); |
| 39 | 40 |
| 40 // Run message loop. | 41 // Run message loop. |
| 41 base::MessageLoop::current()->Run(); | 42 base::RunLoop().Run(); |
| 42 | 43 |
| 43 // Close the channel so the client's OnChannelError() gets fired. | 44 // Close the channel so the client's OnChannelError() gets fired. |
| 44 channel()->Close(); | 45 channel()->Close(); |
| 45 | 46 |
| 46 EXPECT_TRUE(WaitForClientShutdown()); | 47 EXPECT_TRUE(WaitForClientShutdown()); |
| 47 DestroyChannel(); | 48 DestroyChannel(); |
| 48 } | 49 } |
| 49 | 50 |
| 50 // TODO(viettrungluu): Move to a separate IPCChannelWinTest. | 51 // TODO(viettrungluu): Move to a separate IPCChannelWinTest. |
| 51 #if defined(OS_WIN) | 52 #if defined(OS_WIN) |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 // Set up IPC channel proxy. | 99 // Set up IPC channel proxy. |
| 99 IPC::TestChannelListener listener; | 100 IPC::TestChannelListener listener; |
| 100 CreateChannelProxy(&listener, thread.task_runner().get()); | 101 CreateChannelProxy(&listener, thread.task_runner().get()); |
| 101 listener.Init(sender()); | 102 listener.Init(sender()); |
| 102 | 103 |
| 103 ASSERT_TRUE(StartClient()); | 104 ASSERT_TRUE(StartClient()); |
| 104 | 105 |
| 105 IPC::TestChannelListener::SendOneMessage(sender(), "hello from parent"); | 106 IPC::TestChannelListener::SendOneMessage(sender(), "hello from parent"); |
| 106 | 107 |
| 107 // Run message loop. | 108 // Run message loop. |
| 108 base::MessageLoop::current()->Run(); | 109 base::RunLoop().Run(); |
| 109 | 110 |
| 110 EXPECT_TRUE(WaitForClientShutdown()); | 111 EXPECT_TRUE(WaitForClientShutdown()); |
| 111 | 112 |
| 112 // Destroy the channel proxy before shutting down the thread. | 113 // Destroy the channel proxy before shutting down the thread. |
| 113 DestroyChannelProxy(); | 114 DestroyChannelProxy(); |
| 114 thread.Stop(); | 115 thread.Stop(); |
| 115 } | 116 } |
| 116 | 117 |
| 117 class ChannelListenerWithOnConnectedSend : public IPC::TestChannelListener { | 118 class ChannelListenerWithOnConnectedSend : public IPC::TestChannelListener { |
| 118 public: | 119 public: |
| (...skipping 19 matching lines...) Expand all Loading... |
| 138 // Set up IPC channel and start client. | 139 // Set up IPC channel and start client. |
| 139 ChannelListenerWithOnConnectedSend listener; | 140 ChannelListenerWithOnConnectedSend listener; |
| 140 CreateChannel(&listener); | 141 CreateChannel(&listener); |
| 141 listener.Init(sender()); | 142 listener.Init(sender()); |
| 142 ASSERT_TRUE(ConnectChannel()); | 143 ASSERT_TRUE(ConnectChannel()); |
| 143 ASSERT_TRUE(StartClient()); | 144 ASSERT_TRUE(StartClient()); |
| 144 | 145 |
| 145 IPC::TestChannelListener::SendOneMessage(sender(), "hello from parent"); | 146 IPC::TestChannelListener::SendOneMessage(sender(), "hello from parent"); |
| 146 | 147 |
| 147 // Run message loop. | 148 // Run message loop. |
| 148 base::MessageLoop::current()->Run(); | 149 base::RunLoop().Run(); |
| 149 | 150 |
| 150 // Close the channel so the client's OnChannelError() gets fired. | 151 // Close the channel so the client's OnChannelError() gets fired. |
| 151 channel()->Close(); | 152 channel()->Close(); |
| 152 | 153 |
| 153 EXPECT_TRUE(WaitForClientShutdown()); | 154 EXPECT_TRUE(WaitForClientShutdown()); |
| 154 DestroyChannel(); | 155 DestroyChannel(); |
| 155 } | 156 } |
| 156 | 157 |
| 157 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(GenericClient) { | 158 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(GenericClient) { |
| 158 base::MessageLoopForIO main_message_loop; | 159 base::MessageLoopForIO main_message_loop; |
| 159 IPC::TestChannelListener listener; | 160 IPC::TestChannelListener listener; |
| 160 | 161 |
| 161 // Set up IPC channel. | 162 // Set up IPC channel. |
| 162 std::unique_ptr<IPC::Channel> channel(IPC::Channel::CreateClient( | 163 std::unique_ptr<IPC::Channel> channel(IPC::Channel::CreateClient( |
| 163 IPCTestBase::GetChannelName("GenericClient"), &listener)); | 164 IPCTestBase::GetChannelName("GenericClient"), &listener)); |
| 164 CHECK(channel->Connect()); | 165 CHECK(channel->Connect()); |
| 165 listener.Init(channel.get()); | 166 listener.Init(channel.get()); |
| 166 IPC::TestChannelListener::SendOneMessage(channel.get(), "hello from child"); | 167 IPC::TestChannelListener::SendOneMessage(channel.get(), "hello from child"); |
| 167 | 168 |
| 168 base::MessageLoop::current()->Run(); | 169 base::RunLoop().Run(); |
| 169 return 0; | 170 return 0; |
| 170 } | 171 } |
| 171 | 172 |
| 172 } // namespace | 173 } // namespace |
| OLD | NEW |