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 // These tests are POSIX only. | 5 // These tests are POSIX only. |
6 | 6 |
7 #include "ipc/ipc_channel_posix.h" | 7 #include "ipc/ipc_channel_posix.h" |
8 | 8 |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 channel.Close(); | 221 channel.Close(); |
222 ASSERT_TRUE(HANDLE_EINTR(close(pipe_fds[1])) == 0); | 222 ASSERT_TRUE(HANDLE_EINTR(close(pipe_fds[1])) == 0); |
223 | 223 |
224 // Make sure that we can use the socket that is created for us by | 224 // Make sure that we can use the socket that is created for us by |
225 // a standard channel. | 225 // a standard channel. |
226 IPC::Channel channel2(socket_name, IPC::Channel::MODE_SERVER, NULL); | 226 IPC::Channel channel2(socket_name, IPC::Channel::MODE_SERVER, NULL); |
227 ASSERT_TRUE(channel2.Connect()); | 227 ASSERT_TRUE(channel2.Connect()); |
228 ASSERT_FALSE(channel2.AcceptsConnections()); | 228 ASSERT_FALSE(channel2.AcceptsConnections()); |
229 } | 229 } |
230 | 230 |
| 231 // If a connection closes right before a Send() call, we may end up closing |
| 232 // the connection without notifying the listener, which can cause hangs in |
| 233 // sync_message_filter and others. Make sure the listener is notified. |
| 234 TEST_F(IPCChannelPosixTest, SendHangTest) { |
| 235 IPCChannelPosixTestListener out_listener(true); |
| 236 IPCChannelPosixTestListener in_listener(true); |
| 237 IPC::ChannelHandle in_handle("IN"); |
| 238 IPC::Channel in_chan(in_handle, IPC::Channel::MODE_SERVER, &in_listener); |
| 239 base::FileDescriptor out_fd(in_chan.TakeClientFileDescriptor(), false); |
| 240 IPC::ChannelHandle out_handle("OUT", out_fd); |
| 241 IPC::Channel out_chan(out_handle, IPC::Channel::MODE_CLIENT, &out_listener); |
| 242 ASSERT_TRUE(in_chan.Connect()); |
| 243 ASSERT_TRUE(out_chan.Connect()); |
| 244 in_chan.Close(); // simulate remote process dying at an unforunate time. |
| 245 // Send will fail, because it cannot write the message. |
| 246 ASSERT_FALSE(out_chan.Send(new IPC::Message( |
| 247 0, // routing_id |
| 248 kQuitMessage, // message type |
| 249 IPC::Message::PRIORITY_NORMAL))); |
| 250 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, out_listener.status()); |
| 251 } |
| 252 |
231 TEST_F(IPCChannelPosixTest, AdvancedConnected) { | 253 TEST_F(IPCChannelPosixTest, AdvancedConnected) { |
232 // Test creating a connection to an external process. | 254 // Test creating a connection to an external process. |
233 IPCChannelPosixTestListener listener(false); | 255 IPCChannelPosixTestListener listener(false); |
234 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); | 256 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); |
235 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER); | 257 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER); |
236 IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener); | 258 IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener); |
237 ASSERT_TRUE(channel.Connect()); | 259 ASSERT_TRUE(channel.Connect()); |
238 ASSERT_TRUE(channel.AcceptsConnections()); | 260 ASSERT_TRUE(channel.AcceptsConnections()); |
239 ASSERT_FALSE(channel.HasAcceptedConnection()); | 261 ASSERT_FALSE(channel.HasAcceptedConnection()); |
240 | 262 |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 if (connected) { | 439 if (connected) { |
418 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); | 440 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); |
419 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); | 441 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); |
420 } else { | 442 } else { |
421 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); | 443 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); |
422 } | 444 } |
423 return 0; | 445 return 0; |
424 } | 446 } |
425 | 447 |
426 } // namespace | 448 } // namespace |
OLD | NEW |