| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 QUIT_MESSAGE, // message type | 311 QUIT_MESSAGE, // message type |
| 312 IPC::Message::PRIORITY_NORMAL); | 312 IPC::Message::PRIORITY_NORMAL); |
| 313 channel.Send(message); | 313 channel.Send(message); |
| 314 SpinRunLoop(TestTimeouts::action_timeout_ms()); | 314 SpinRunLoop(TestTimeouts::action_timeout_ms()); |
| 315 EXPECT_TRUE(base::WaitForExitCode(handle, &exit_code)); | 315 EXPECT_TRUE(base::WaitForExitCode(handle, &exit_code)); |
| 316 EXPECT_EQ(exit_code, 0); | 316 EXPECT_EQ(exit_code, 0); |
| 317 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); | 317 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); |
| 318 ASSERT_FALSE(channel.HasAcceptedConnection()); | 318 ASSERT_FALSE(channel.HasAcceptedConnection()); |
| 319 } | 319 } |
| 320 | 320 |
| 321 TEST_F(IPCChannelPosixTest, DoubleServer) { |
| 322 // Test setting up two servers with the same name. |
| 323 IPCChannelPosixTestListener listener(false); |
| 324 IPCChannelPosixTestListener listener2(false); |
| 325 IPC::ChannelHandle chan_handle(kConnectionSocketTestName); |
| 326 IPC::Channel channel(chan_handle, IPC::Channel::MODE_SERVER, &listener); |
| 327 IPC::Channel channel2(chan_handle, IPC::Channel::MODE_SERVER, &listener2); |
| 328 ASSERT_TRUE(channel.Connect()); |
| 329 ASSERT_FALSE(channel2.Connect()); |
| 330 } |
| 331 |
| 332 TEST_F(IPCChannelPosixTest, BadMode) { |
| 333 // Test setting up two servers with a bad mode. |
| 334 IPCChannelPosixTestListener listener(false); |
| 335 IPC::ChannelHandle chan_handle(kConnectionSocketTestName); |
| 336 IPC::Channel channel(chan_handle, IPC::Channel::MODE_NONE, &listener); |
| 337 ASSERT_FALSE(channel.Connect()); |
| 338 } |
| 339 |
| 321 // A long running process that connects to us | 340 // A long running process that connects to us |
| 322 MULTIPROCESS_TEST_MAIN(IPCChannelPosixTestConnectionProc) { | 341 MULTIPROCESS_TEST_MAIN(IPCChannelPosixTestConnectionProc) { |
| 323 MessageLoopForIO message_loop; | 342 MessageLoopForIO message_loop; |
| 324 IPCChannelPosixTestListener listener(true); | 343 IPCChannelPosixTestListener listener(true); |
| 325 IPC::ChannelHandle handle(IPCChannelPosixTest::kConnectionSocketTestName); | 344 IPC::ChannelHandle handle(IPCChannelPosixTest::kConnectionSocketTestName); |
| 326 IPCChannelPosixTest::SetUpSocket(&handle, IPC::Channel::MODE_NAMED_CLIENT); | 345 IPCChannelPosixTest::SetUpSocket(&handle, IPC::Channel::MODE_NAMED_CLIENT); |
| 327 IPC::Channel channel(handle, IPC::Channel::MODE_NAMED_CLIENT, &listener); | 346 IPC::Channel channel(handle, IPC::Channel::MODE_NAMED_CLIENT, &listener); |
| 328 EXPECT_TRUE(channel.Connect()); | 347 EXPECT_TRUE(channel.Connect()); |
| 329 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout_ms()); | 348 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout_ms()); |
| 330 EXPECT_EQ(IPCChannelPosixTestListener::MESSAGE_RECEIVED, listener.status()); | 349 EXPECT_EQ(IPCChannelPosixTestListener::MESSAGE_RECEIVED, listener.status()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 347 bool connected = channel.Connect(); | 366 bool connected = channel.Connect(); |
| 348 if (connected) { | 367 if (connected) { |
| 349 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout_ms()); | 368 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout_ms()); |
| 350 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); | 369 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); |
| 351 } else { | 370 } else { |
| 352 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); | 371 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); |
| 353 } | 372 } |
| 354 return 0; | 373 return 0; |
| 355 } | 374 } |
| 356 | 375 |
| OLD | NEW |