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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 | 238 |
239 // If a connection closes right before a Send() call, we may end up closing | 239 // If a connection closes right before a Send() call, we may end up closing |
240 // the connection without notifying the listener, which can cause hangs in | 240 // the connection without notifying the listener, which can cause hangs in |
241 // sync_message_filter and others. Make sure the listener is notified. | 241 // sync_message_filter and others. Make sure the listener is notified. |
242 TEST_F(IPCChannelPosixTest, SendHangTest) { | 242 TEST_F(IPCChannelPosixTest, SendHangTest) { |
243 IPCChannelPosixTestListener out_listener(true); | 243 IPCChannelPosixTestListener out_listener(true); |
244 IPCChannelPosixTestListener in_listener(true); | 244 IPCChannelPosixTestListener in_listener(true); |
245 IPC::ChannelHandle in_handle("IN"); | 245 IPC::ChannelHandle in_handle("IN"); |
246 scoped_ptr<IPC::Channel> in_chan( | 246 scoped_ptr<IPC::Channel> in_chan( |
247 IPC::Channel::CreateServer(in_handle, &in_listener)); | 247 IPC::Channel::CreateServer(in_handle, &in_listener)); |
248 base::FileDescriptor out_fd(in_chan->TakeClientFileDescriptor(), false); | 248 base::FileDescriptor out_fd( |
| 249 in_chan->TakeClientFileDescriptor(), false); |
249 IPC::ChannelHandle out_handle("OUT", out_fd); | 250 IPC::ChannelHandle out_handle("OUT", out_fd); |
250 scoped_ptr<IPC::Channel> out_chan( | 251 scoped_ptr<IPC::Channel> out_chan( |
251 IPC::Channel::CreateClient(out_handle, &out_listener)); | 252 IPC::Channel::CreateClient(out_handle, &out_listener)); |
252 ASSERT_TRUE(in_chan->Connect()); | 253 ASSERT_TRUE(in_chan->Connect()); |
253 ASSERT_TRUE(out_chan->Connect()); | 254 ASSERT_TRUE(out_chan->Connect()); |
254 in_chan->Close(); // simulate remote process dying at an unfortunate time. | 255 in_chan->Close(); // simulate remote process dying at an unfortunate time. |
255 // Send will fail, because it cannot write the message. | 256 // Send will fail, because it cannot write the message. |
256 ASSERT_FALSE(out_chan->Send(new IPC::Message( | 257 ASSERT_FALSE(out_chan->Send(new IPC::Message( |
257 0, // routing_id | 258 0, // routing_id |
258 kQuitMessage, // message type | 259 kQuitMessage, // message type |
259 IPC::Message::PRIORITY_NORMAL))); | 260 IPC::Message::PRIORITY_NORMAL))); |
260 SpinRunLoop(TestTimeouts::action_max_timeout()); | 261 SpinRunLoop(TestTimeouts::action_max_timeout()); |
261 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, out_listener.status()); | 262 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, out_listener.status()); |
262 } | 263 } |
263 | 264 |
264 // 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 |
265 // the connection without notifying the listener, which can cause hangs in | 266 // the connection without notifying the listener, which can cause hangs in |
266 // sync_message_filter and others. Make sure the listener is notified. | 267 // sync_message_filter and others. Make sure the listener is notified. |
267 TEST_F(IPCChannelPosixTest, AcceptHangTest) { | 268 TEST_F(IPCChannelPosixTest, AcceptHangTest) { |
268 IPCChannelPosixTestListener out_listener(true); | 269 IPCChannelPosixTestListener out_listener(true); |
269 IPCChannelPosixTestListener in_listener(true); | 270 IPCChannelPosixTestListener in_listener(true); |
270 IPC::ChannelHandle in_handle("IN"); | 271 IPC::ChannelHandle in_handle("IN"); |
271 scoped_ptr<IPC::Channel> in_chan( | 272 scoped_ptr<IPC::Channel> in_chan( |
272 IPC::Channel::CreateServer(in_handle, &in_listener)); | 273 IPC::Channel::CreateServer(in_handle, &in_listener)); |
273 base::FileDescriptor out_fd(in_chan->TakeClientFileDescriptor(), false); | 274 base::FileDescriptor out_fd( |
| 275 in_chan->TakeClientFileDescriptor(), false); |
274 IPC::ChannelHandle out_handle("OUT", out_fd); | 276 IPC::ChannelHandle out_handle("OUT", out_fd); |
275 scoped_ptr<IPC::Channel> out_chan( | 277 scoped_ptr<IPC::Channel> out_chan( |
276 IPC::Channel::CreateClient(out_handle, &out_listener)); | 278 IPC::Channel::CreateClient(out_handle, &out_listener)); |
277 ASSERT_TRUE(in_chan->Connect()); | 279 ASSERT_TRUE(in_chan->Connect()); |
278 in_chan->Close(); // simulate remote process dying at an unfortunate time. | 280 in_chan->Close(); // simulate remote process dying at an unfortunate time. |
279 ASSERT_FALSE(out_chan->Connect()); | 281 ASSERT_FALSE(out_chan->Connect()); |
280 SpinRunLoop(TestTimeouts::action_max_timeout()); | 282 SpinRunLoop(TestTimeouts::action_max_timeout()); |
281 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, out_listener.status()); | 283 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, out_listener.status()); |
282 } | 284 } |
283 | 285 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 scoped_ptr<IPC::Channel> channel2( | 418 scoped_ptr<IPC::Channel> channel2( |
417 IPC::Channel::CreateServer(chan_handle, &listener2)); | 419 IPC::Channel::CreateServer(chan_handle, &listener2)); |
418 ASSERT_TRUE(channel->Connect()); | 420 ASSERT_TRUE(channel->Connect()); |
419 ASSERT_FALSE(channel2->Connect()); | 421 ASSERT_FALSE(channel2->Connect()); |
420 } | 422 } |
421 | 423 |
422 TEST_F(IPCChannelPosixTest, BadMode) { | 424 TEST_F(IPCChannelPosixTest, BadMode) { |
423 // Test setting up two servers with a bad mode. | 425 // Test setting up two servers with a bad mode. |
424 IPCChannelPosixTestListener listener(false); | 426 IPCChannelPosixTestListener listener(false); |
425 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); | 427 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); |
426 scoped_ptr<IPC::Channel> channel(IPC::Channel::CreateByModeForProxy( | 428 scoped_ptr<IPC::Channel> channel(IPC::Channel::Create( |
427 chan_handle, IPC::Channel::MODE_NONE, &listener)); | 429 chan_handle, IPC::Channel::MODE_NONE, &listener)); |
428 ASSERT_FALSE(channel->Connect()); | 430 ASSERT_FALSE(channel->Connect()); |
429 } | 431 } |
430 | 432 |
431 TEST_F(IPCChannelPosixTest, IsNamedServerInitialized) { | 433 TEST_F(IPCChannelPosixTest, IsNamedServerInitialized) { |
432 const std::string& connection_socket_name = GetConnectionSocketName(); | 434 const std::string& connection_socket_name = GetConnectionSocketName(); |
433 IPCChannelPosixTestListener listener(false); | 435 IPCChannelPosixTestListener listener(false); |
434 IPC::ChannelHandle chan_handle(connection_socket_name); | 436 IPC::ChannelHandle chan_handle(connection_socket_name); |
435 ASSERT_TRUE(base::DeleteFile(base::FilePath(connection_socket_name), false)); | 437 ASSERT_TRUE(base::DeleteFile(base::FilePath(connection_socket_name), false)); |
436 ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized( | 438 ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 if (connected) { | 478 if (connected) { |
477 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); | 479 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); |
478 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); | 480 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); |
479 } else { | 481 } else { |
480 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); | 482 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); |
481 } | 483 } |
482 return 0; | 484 return 0; |
483 } | 485 } |
484 | 486 |
485 } // namespace | 487 } // namespace |
OLD | NEW |