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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 | 239 |
240 // If a connection closes right before a Send() call, we may end up closing | 240 // If a connection closes right before a Send() call, we may end up closing |
241 // the connection without notifying the listener, which can cause hangs in | 241 // the connection without notifying the listener, which can cause hangs in |
242 // sync_message_filter and others. Make sure the listener is notified. | 242 // sync_message_filter and others. Make sure the listener is notified. |
243 TEST_F(IPCChannelPosixTest, SendHangTest) { | 243 TEST_F(IPCChannelPosixTest, SendHangTest) { |
244 IPCChannelPosixTestListener out_listener(true); | 244 IPCChannelPosixTestListener out_listener(true); |
245 IPCChannelPosixTestListener in_listener(true); | 245 IPCChannelPosixTestListener in_listener(true); |
246 IPC::ChannelHandle in_handle("IN"); | 246 IPC::ChannelHandle in_handle("IN"); |
247 scoped_ptr<IPC::ChannelPosix> in_chan(new IPC::ChannelPosix( | 247 scoped_ptr<IPC::ChannelPosix> in_chan(new IPC::ChannelPosix( |
248 in_handle, IPC::Channel::MODE_SERVER, &in_listener)); | 248 in_handle, IPC::Channel::MODE_SERVER, &in_listener)); |
249 base::FileDescriptor out_fd( | 249 IPC::ChannelHandle out_handle( |
250 in_chan->TakeClientFileDescriptor(), false); | 250 "OUT", base::FileDescriptor(in_chan->TakeClientFileDescriptor())); |
251 IPC::ChannelHandle out_handle("OUT", out_fd); | |
252 scoped_ptr<IPC::ChannelPosix> out_chan(new IPC::ChannelPosix( | 251 scoped_ptr<IPC::ChannelPosix> out_chan(new IPC::ChannelPosix( |
253 out_handle, IPC::Channel::MODE_CLIENT, &out_listener)); | 252 out_handle, IPC::Channel::MODE_CLIENT, &out_listener)); |
254 ASSERT_TRUE(in_chan->Connect()); | 253 ASSERT_TRUE(in_chan->Connect()); |
255 ASSERT_TRUE(out_chan->Connect()); | 254 ASSERT_TRUE(out_chan->Connect()); |
256 in_chan->Close(); // simulate remote process dying at an unfortunate time. | 255 in_chan->Close(); // simulate remote process dying at an unfortunate time. |
257 // Send will fail, because it cannot write the message. | 256 // Send will fail, because it cannot write the message. |
258 ASSERT_FALSE(out_chan->Send(new IPC::Message( | 257 ASSERT_FALSE(out_chan->Send(new IPC::Message( |
259 0, // routing_id | 258 0, // routing_id |
260 kQuitMessage, // message type | 259 kQuitMessage, // message type |
261 IPC::Message::PRIORITY_NORMAL))); | 260 IPC::Message::PRIORITY_NORMAL))); |
262 SpinRunLoop(TestTimeouts::action_max_timeout()); | 261 SpinRunLoop(TestTimeouts::action_max_timeout()); |
263 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, out_listener.status()); | 262 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, out_listener.status()); |
264 } | 263 } |
265 | 264 |
266 // If a connection closes right before a Connect() call, we may end up closing | 265 // If a connection closes right before a Connect() call, we may end up closing |
267 // the connection without notifying the listener, which can cause hangs in | 266 // the connection without notifying the listener, which can cause hangs in |
268 // sync_message_filter and others. Make sure the listener is notified. | 267 // sync_message_filter and others. Make sure the listener is notified. |
269 TEST_F(IPCChannelPosixTest, AcceptHangTest) { | 268 TEST_F(IPCChannelPosixTest, AcceptHangTest) { |
270 IPCChannelPosixTestListener out_listener(true); | 269 IPCChannelPosixTestListener out_listener(true); |
271 IPCChannelPosixTestListener in_listener(true); | 270 IPCChannelPosixTestListener in_listener(true); |
272 IPC::ChannelHandle in_handle("IN"); | 271 IPC::ChannelHandle in_handle("IN"); |
273 scoped_ptr<IPC::ChannelPosix> in_chan(new IPC::ChannelPosix( | 272 scoped_ptr<IPC::ChannelPosix> in_chan(new IPC::ChannelPosix( |
274 in_handle, IPC::Channel::MODE_SERVER, &in_listener)); | 273 in_handle, IPC::Channel::MODE_SERVER, &in_listener)); |
275 base::FileDescriptor out_fd( | 274 IPC::ChannelHandle out_handle( |
276 in_chan->TakeClientFileDescriptor(), false); | 275 "OUT", base::FileDescriptor(in_chan->TakeClientFileDescriptor())); |
277 IPC::ChannelHandle out_handle("OUT", out_fd); | |
278 scoped_ptr<IPC::ChannelPosix> out_chan(new IPC::ChannelPosix( | 276 scoped_ptr<IPC::ChannelPosix> out_chan(new IPC::ChannelPosix( |
279 out_handle, IPC::Channel::MODE_CLIENT, &out_listener)); | 277 out_handle, IPC::Channel::MODE_CLIENT, &out_listener)); |
280 ASSERT_TRUE(in_chan->Connect()); | 278 ASSERT_TRUE(in_chan->Connect()); |
281 in_chan->Close(); // simulate remote process dying at an unfortunate time. | 279 in_chan->Close(); // simulate remote process dying at an unfortunate time. |
282 ASSERT_FALSE(out_chan->Connect()); | 280 ASSERT_FALSE(out_chan->Connect()); |
283 SpinRunLoop(TestTimeouts::action_max_timeout()); | 281 SpinRunLoop(TestTimeouts::action_max_timeout()); |
284 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, out_listener.status()); | 282 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, out_listener.status()); |
285 } | 283 } |
286 | 284 |
287 TEST_F(IPCChannelPosixTest, AdvancedConnected) { | 285 TEST_F(IPCChannelPosixTest, AdvancedConnected) { |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 if (connected) { | 477 if (connected) { |
480 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); | 478 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); |
481 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); | 479 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); |
482 } else { | 480 } else { |
483 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); | 481 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); |
484 } | 482 } |
485 return 0; | 483 return 0; |
486 } | 484 } |
487 | 485 |
488 } // namespace | 486 } // namespace |
OLD | NEW |