| 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> |
| 11 #include <sys/un.h> | 11 #include <sys/un.h> |
| 12 #include <unistd.h> | 12 #include <unistd.h> |
| 13 | 13 |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/eintr_wrapper.h" | 15 #include "base/eintr_wrapper.h" |
| 16 #include "base/file_path.h" | 16 #include "base/file_path.h" |
| 17 #include "base/file_util.h" | 17 #include "base/file_util.h" |
| 18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/message_loop.h" | 19 #include "base/message_loop.h" |
| 20 #include "base/path_service.h" |
| 20 #include "base/test/multiprocess_test.h" | 21 #include "base/test/multiprocess_test.h" |
| 21 #include "base/test/test_timeouts.h" | 22 #include "base/test/test_timeouts.h" |
| 22 #include "testing/multiprocess_func_list.h" | 23 #include "testing/multiprocess_func_list.h" |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 static const uint32 kQuitMessage = 47; | 27 static const uint32 kQuitMessage = 47; |
| 27 | 28 |
| 28 class IPCChannelPosixTestListener : public IPC::Channel::Listener { | 29 class IPCChannelPosixTestListener : public IPC::Channel::Listener { |
| 29 public: | 30 public: |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 STATUS status_; | 88 STATUS status_; |
| 88 // If |quit_only_on_message_| then the listener will only break out of | 89 // If |quit_only_on_message_| then the listener will only break out of |
| 89 // the run loop when kQuitMessage is received. | 90 // the run loop when kQuitMessage is received. |
| 90 bool quit_only_on_message_; | 91 bool quit_only_on_message_; |
| 91 }; | 92 }; |
| 92 | 93 |
| 93 } // namespace | 94 } // namespace |
| 94 | 95 |
| 95 class IPCChannelPosixTest : public base::MultiProcessTest { | 96 class IPCChannelPosixTest : public base::MultiProcessTest { |
| 96 public: | 97 public: |
| 97 static const char kConnectionSocketTestName[]; | |
| 98 static void SetUpSocket(IPC::ChannelHandle *handle, | 98 static void SetUpSocket(IPC::ChannelHandle *handle, |
| 99 IPC::Channel::Mode mode); | 99 IPC::Channel::Mode mode); |
| 100 static void SpinRunLoop(int milliseconds); | 100 static void SpinRunLoop(int milliseconds); |
| 101 static const std::string GetConnectionSocketName(); |
| 102 static const std::string GetChannelDirName(); |
| 101 | 103 |
| 102 protected: | 104 protected: |
| 103 virtual void SetUp(); | 105 virtual void SetUp(); |
| 104 virtual void TearDown(); | 106 virtual void TearDown(); |
| 105 | 107 |
| 106 private: | 108 private: |
| 107 scoped_ptr<MessageLoopForIO> message_loop_; | 109 scoped_ptr<MessageLoopForIO> message_loop_; |
| 108 }; | 110 }; |
| 109 | 111 |
| 112 const std::string IPCChannelPosixTest::GetChannelDirName() { |
| 110 #if defined(OS_ANDROID) | 113 #if defined(OS_ANDROID) |
| 111 const char IPCChannelPosixTest::kConnectionSocketTestName[] = | 114 FilePath tmp_dir; |
| 112 "/data/local/chrome_IPCChannelPosixTest__ConnectionSocket"; | 115 PathService::Get(base::DIR_CACHE, &tmp_dir); |
| 116 return tmp_dir.value(); |
| 113 #else | 117 #else |
| 114 const char IPCChannelPosixTest::kConnectionSocketTestName[] = | 118 return "/var/tmp"; |
| 115 "/var/tmp/chrome_IPCChannelPosixTest__ConnectionSocket"; | |
| 116 #endif | 119 #endif |
| 120 } |
| 121 |
| 122 const std::string IPCChannelPosixTest::GetConnectionSocketName() { |
| 123 return GetChannelDirName() + "/chrome_IPCChannelPosixTest__ConnectionSocket"; |
| 124 } |
| 117 | 125 |
| 118 void IPCChannelPosixTest::SetUp() { | 126 void IPCChannelPosixTest::SetUp() { |
| 119 MultiProcessTest::SetUp(); | 127 MultiProcessTest::SetUp(); |
| 120 // Construct a fresh IO Message loop for the duration of each test. | 128 // Construct a fresh IO Message loop for the duration of each test. |
| 121 message_loop_.reset(new MessageLoopForIO()); | 129 message_loop_.reset(new MessageLoopForIO()); |
| 122 } | 130 } |
| 123 | 131 |
| 124 void IPCChannelPosixTest::TearDown() { | 132 void IPCChannelPosixTest::TearDown() { |
| 125 message_loop_.reset(NULL); | 133 message_loop_.reset(NULL); |
| 126 MultiProcessTest::TearDown(); | 134 MultiProcessTest::TearDown(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 // that because all tests use a IPCChannelPosixTestListener which quits the | 186 // that because all tests use a IPCChannelPosixTestListener which quits the |
| 179 // current run loop on any channel activity. | 187 // current run loop on any channel activity. |
| 180 loop->PostDelayedTask( | 188 loop->PostDelayedTask( |
| 181 FROM_HERE, | 189 FROM_HERE, |
| 182 MessageLoop::QuitClosure(), | 190 MessageLoop::QuitClosure(), |
| 183 base::TimeDelta::FromMilliseconds(milliseconds)); | 191 base::TimeDelta::FromMilliseconds(milliseconds)); |
| 184 loop->Run(); | 192 loop->Run(); |
| 185 } | 193 } |
| 186 | 194 |
| 187 TEST_F(IPCChannelPosixTest, BasicListen) { | 195 TEST_F(IPCChannelPosixTest, BasicListen) { |
| 196 const std::string kChannelName = |
| 197 GetChannelDirName() + "/IPCChannelPosixTest_BasicListen"; |
| 188 | 198 |
| 189 #if defined(OS_ANDROID) | |
| 190 const char* kChannelName = "/data/local/IPCChannelPosixTest_BasicListen"; | |
| 191 #else | |
| 192 const char* kChannelName = "/var/tmp/IPCChannelPosixTest_BasicListen"; | |
| 193 #endif | |
| 194 // Test creating a socket that is listening. | 199 // Test creating a socket that is listening. |
| 195 IPC::ChannelHandle handle(kChannelName); | 200 IPC::ChannelHandle handle(kChannelName); |
| 196 SetUpSocket(&handle, IPC::Channel::MODE_NAMED_SERVER); | 201 SetUpSocket(&handle, IPC::Channel::MODE_NAMED_SERVER); |
| 197 unlink(handle.name.c_str()); | 202 unlink(handle.name.c_str()); |
| 198 IPC::Channel channel(handle, IPC::Channel::MODE_NAMED_SERVER, NULL); | 203 IPC::Channel channel(handle, IPC::Channel::MODE_NAMED_SERVER, NULL); |
| 199 ASSERT_TRUE(channel.Connect()); | 204 ASSERT_TRUE(channel.Connect()); |
| 200 ASSERT_TRUE(channel.AcceptsConnections()); | 205 ASSERT_TRUE(channel.AcceptsConnections()); |
| 201 ASSERT_FALSE(channel.HasAcceptedConnection()); | 206 ASSERT_FALSE(channel.HasAcceptedConnection()); |
| 202 channel.ResetToAcceptingConnectionState(); | 207 channel.ResetToAcceptingConnectionState(); |
| 203 ASSERT_FALSE(channel.HasAcceptedConnection()); | 208 ASSERT_FALSE(channel.HasAcceptedConnection()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 221 // Make sure that we can use the socket that is created for us by | 226 // Make sure that we can use the socket that is created for us by |
| 222 // a standard channel. | 227 // a standard channel. |
| 223 IPC::Channel channel2(socket_name, IPC::Channel::MODE_SERVER, NULL); | 228 IPC::Channel channel2(socket_name, IPC::Channel::MODE_SERVER, NULL); |
| 224 ASSERT_TRUE(channel2.Connect()); | 229 ASSERT_TRUE(channel2.Connect()); |
| 225 ASSERT_FALSE(channel2.AcceptsConnections()); | 230 ASSERT_FALSE(channel2.AcceptsConnections()); |
| 226 } | 231 } |
| 227 | 232 |
| 228 TEST_F(IPCChannelPosixTest, AdvancedConnected) { | 233 TEST_F(IPCChannelPosixTest, AdvancedConnected) { |
| 229 // Test creating a connection to an external process. | 234 // Test creating a connection to an external process. |
| 230 IPCChannelPosixTestListener listener(false); | 235 IPCChannelPosixTestListener listener(false); |
| 231 IPC::ChannelHandle chan_handle(kConnectionSocketTestName); | 236 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); |
| 232 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER); | 237 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER); |
| 233 IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener); | 238 IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener); |
| 234 ASSERT_TRUE(channel.Connect()); | 239 ASSERT_TRUE(channel.Connect()); |
| 235 ASSERT_TRUE(channel.AcceptsConnections()); | 240 ASSERT_TRUE(channel.AcceptsConnections()); |
| 236 ASSERT_FALSE(channel.HasAcceptedConnection()); | 241 ASSERT_FALSE(channel.HasAcceptedConnection()); |
| 237 | 242 |
| 238 base::ProcessHandle handle = SpawnChild("IPCChannelPosixTestConnectionProc", | 243 base::ProcessHandle handle = SpawnChild("IPCChannelPosixTestConnectionProc", |
| 239 false); | 244 false); |
| 240 ASSERT_TRUE(handle); | 245 ASSERT_TRUE(handle); |
| 241 SpinRunLoop(TestTimeouts::action_max_timeout_ms()); | 246 SpinRunLoop(TestTimeouts::action_max_timeout_ms()); |
| 242 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); | 247 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); |
| 243 ASSERT_TRUE(channel.HasAcceptedConnection()); | 248 ASSERT_TRUE(channel.HasAcceptedConnection()); |
| 244 IPC::Message* message = new IPC::Message(0, // routing_id | 249 IPC::Message* message = new IPC::Message(0, // routing_id |
| 245 kQuitMessage, // message type | 250 kQuitMessage, // message type |
| 246 IPC::Message::PRIORITY_NORMAL); | 251 IPC::Message::PRIORITY_NORMAL); |
| 247 channel.Send(message); | 252 channel.Send(message); |
| 248 SpinRunLoop(TestTimeouts::action_timeout_ms()); | 253 SpinRunLoop(TestTimeouts::action_timeout_ms()); |
| 249 int exit_code = 0; | 254 int exit_code = 0; |
| 250 EXPECT_TRUE(base::WaitForExitCode(handle, &exit_code)); | 255 EXPECT_TRUE(base::WaitForExitCode(handle, &exit_code)); |
| 251 EXPECT_EQ(0, exit_code); | 256 EXPECT_EQ(0, exit_code); |
| 252 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); | 257 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); |
| 253 ASSERT_FALSE(channel.HasAcceptedConnection()); | 258 ASSERT_FALSE(channel.HasAcceptedConnection()); |
| 254 } | 259 } |
| 255 | 260 |
| 256 TEST_F(IPCChannelPosixTest, ResetState) { | 261 TEST_F(IPCChannelPosixTest, ResetState) { |
| 257 // Test creating a connection to an external process. Close the connection, | 262 // Test creating a connection to an external process. Close the connection, |
| 258 // but continue to listen and make sure another external process can connect | 263 // but continue to listen and make sure another external process can connect |
| 259 // to us. | 264 // to us. |
| 260 IPCChannelPosixTestListener listener(false); | 265 IPCChannelPosixTestListener listener(false); |
| 261 IPC::ChannelHandle chan_handle(kConnectionSocketTestName); | 266 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); |
| 262 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER); | 267 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER); |
| 263 IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener); | 268 IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener); |
| 264 ASSERT_TRUE(channel.Connect()); | 269 ASSERT_TRUE(channel.Connect()); |
| 265 ASSERT_TRUE(channel.AcceptsConnections()); | 270 ASSERT_TRUE(channel.AcceptsConnections()); |
| 266 ASSERT_FALSE(channel.HasAcceptedConnection()); | 271 ASSERT_FALSE(channel.HasAcceptedConnection()); |
| 267 | 272 |
| 268 base::ProcessHandle handle = SpawnChild("IPCChannelPosixTestConnectionProc", | 273 base::ProcessHandle handle = SpawnChild("IPCChannelPosixTestConnectionProc", |
| 269 false); | 274 false); |
| 270 ASSERT_TRUE(handle); | 275 ASSERT_TRUE(handle); |
| 271 SpinRunLoop(TestTimeouts::action_max_timeout_ms()); | 276 SpinRunLoop(TestTimeouts::action_max_timeout_ms()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 EXPECT_GE(strlen(kTooLongName), IPC::kMaxPipeNameLength); | 315 EXPECT_GE(strlen(kTooLongName), IPC::kMaxPipeNameLength); |
| 311 IPC::ChannelHandle handle2(kTooLongName); | 316 IPC::ChannelHandle handle2(kTooLongName); |
| 312 IPC::Channel channel2(handle2, IPC::Channel::MODE_NAMED_SERVER, NULL); | 317 IPC::Channel channel2(handle2, IPC::Channel::MODE_NAMED_SERVER, NULL); |
| 313 EXPECT_FALSE(channel2.Connect()); | 318 EXPECT_FALSE(channel2.Connect()); |
| 314 } | 319 } |
| 315 | 320 |
| 316 TEST_F(IPCChannelPosixTest, MultiConnection) { | 321 TEST_F(IPCChannelPosixTest, MultiConnection) { |
| 317 // Test setting up a connection to an external process, and then have | 322 // Test setting up a connection to an external process, and then have |
| 318 // another external process attempt to connect to us. | 323 // another external process attempt to connect to us. |
| 319 IPCChannelPosixTestListener listener(false); | 324 IPCChannelPosixTestListener listener(false); |
| 320 IPC::ChannelHandle chan_handle(kConnectionSocketTestName); | 325 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); |
| 321 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER); | 326 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER); |
| 322 IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener); | 327 IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener); |
| 323 ASSERT_TRUE(channel.Connect()); | 328 ASSERT_TRUE(channel.Connect()); |
| 324 ASSERT_TRUE(channel.AcceptsConnections()); | 329 ASSERT_TRUE(channel.AcceptsConnections()); |
| 325 ASSERT_FALSE(channel.HasAcceptedConnection()); | 330 ASSERT_FALSE(channel.HasAcceptedConnection()); |
| 326 | 331 |
| 327 base::ProcessHandle handle = SpawnChild("IPCChannelPosixTestConnectionProc", | 332 base::ProcessHandle handle = SpawnChild("IPCChannelPosixTestConnectionProc", |
| 328 false); | 333 false); |
| 329 ASSERT_TRUE(handle); | 334 ASSERT_TRUE(handle); |
| 330 SpinRunLoop(TestTimeouts::action_max_timeout_ms()); | 335 SpinRunLoop(TestTimeouts::action_max_timeout_ms()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 347 EXPECT_TRUE(base::WaitForExitCode(handle, &exit_code)); | 352 EXPECT_TRUE(base::WaitForExitCode(handle, &exit_code)); |
| 348 EXPECT_EQ(exit_code, 0); | 353 EXPECT_EQ(exit_code, 0); |
| 349 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); | 354 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); |
| 350 ASSERT_FALSE(channel.HasAcceptedConnection()); | 355 ASSERT_FALSE(channel.HasAcceptedConnection()); |
| 351 } | 356 } |
| 352 | 357 |
| 353 TEST_F(IPCChannelPosixTest, DoubleServer) { | 358 TEST_F(IPCChannelPosixTest, DoubleServer) { |
| 354 // Test setting up two servers with the same name. | 359 // Test setting up two servers with the same name. |
| 355 IPCChannelPosixTestListener listener(false); | 360 IPCChannelPosixTestListener listener(false); |
| 356 IPCChannelPosixTestListener listener2(false); | 361 IPCChannelPosixTestListener listener2(false); |
| 357 IPC::ChannelHandle chan_handle(kConnectionSocketTestName); | 362 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); |
| 358 IPC::Channel channel(chan_handle, IPC::Channel::MODE_SERVER, &listener); | 363 IPC::Channel channel(chan_handle, IPC::Channel::MODE_SERVER, &listener); |
| 359 IPC::Channel channel2(chan_handle, IPC::Channel::MODE_SERVER, &listener2); | 364 IPC::Channel channel2(chan_handle, IPC::Channel::MODE_SERVER, &listener2); |
| 360 ASSERT_TRUE(channel.Connect()); | 365 ASSERT_TRUE(channel.Connect()); |
| 361 ASSERT_FALSE(channel2.Connect()); | 366 ASSERT_FALSE(channel2.Connect()); |
| 362 } | 367 } |
| 363 | 368 |
| 364 TEST_F(IPCChannelPosixTest, BadMode) { | 369 TEST_F(IPCChannelPosixTest, BadMode) { |
| 365 // Test setting up two servers with a bad mode. | 370 // Test setting up two servers with a bad mode. |
| 366 IPCChannelPosixTestListener listener(false); | 371 IPCChannelPosixTestListener listener(false); |
| 367 IPC::ChannelHandle chan_handle(kConnectionSocketTestName); | 372 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); |
| 368 IPC::Channel channel(chan_handle, IPC::Channel::MODE_NONE, &listener); | 373 IPC::Channel channel(chan_handle, IPC::Channel::MODE_NONE, &listener); |
| 369 ASSERT_FALSE(channel.Connect()); | 374 ASSERT_FALSE(channel.Connect()); |
| 370 } | 375 } |
| 371 | 376 |
| 372 TEST_F(IPCChannelPosixTest, IsNamedServerInitialized) { | 377 TEST_F(IPCChannelPosixTest, IsNamedServerInitialized) { |
| 378 const std::string& connection_socket_name = GetConnectionSocketName(); |
| 373 IPCChannelPosixTestListener listener(false); | 379 IPCChannelPosixTestListener listener(false); |
| 374 IPC::ChannelHandle chan_handle(kConnectionSocketTestName); | 380 IPC::ChannelHandle chan_handle(connection_socket_name); |
| 375 ASSERT_TRUE(file_util::Delete(FilePath(kConnectionSocketTestName), false)); | 381 ASSERT_TRUE(file_util::Delete(FilePath(connection_socket_name), false)); |
| 376 ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized( | 382 ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized( |
| 377 kConnectionSocketTestName)); | 383 connection_socket_name)); |
| 378 IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener); | 384 IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener); |
| 379 ASSERT_TRUE(IPC::Channel::IsNamedServerInitialized( | 385 ASSERT_TRUE(IPC::Channel::IsNamedServerInitialized( |
| 380 kConnectionSocketTestName)); | 386 connection_socket_name)); |
| 381 channel.Close(); | 387 channel.Close(); |
| 382 ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized( | 388 ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized( |
| 383 kConnectionSocketTestName)); | 389 connection_socket_name)); |
| 384 } | 390 } |
| 385 | 391 |
| 386 // A long running process that connects to us | 392 // A long running process that connects to us |
| 387 MULTIPROCESS_TEST_MAIN(IPCChannelPosixTestConnectionProc) { | 393 MULTIPROCESS_TEST_MAIN(IPCChannelPosixTestConnectionProc) { |
| 388 MessageLoopForIO message_loop; | 394 MessageLoopForIO message_loop; |
| 389 IPCChannelPosixTestListener listener(true); | 395 IPCChannelPosixTestListener listener(true); |
| 390 IPC::ChannelHandle handle(IPCChannelPosixTest::kConnectionSocketTestName); | 396 IPC::ChannelHandle handle(IPCChannelPosixTest::GetConnectionSocketName()); |
| 391 IPCChannelPosixTest::SetUpSocket(&handle, IPC::Channel::MODE_NAMED_CLIENT); | 397 IPCChannelPosixTest::SetUpSocket(&handle, IPC::Channel::MODE_NAMED_CLIENT); |
| 392 IPC::Channel channel(handle, IPC::Channel::MODE_NAMED_CLIENT, &listener); | 398 IPC::Channel channel(handle, IPC::Channel::MODE_NAMED_CLIENT, &listener); |
| 393 EXPECT_TRUE(channel.Connect()); | 399 EXPECT_TRUE(channel.Connect()); |
| 394 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout_ms()); | 400 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout_ms()); |
| 395 EXPECT_EQ(IPCChannelPosixTestListener::MESSAGE_RECEIVED, listener.status()); | 401 EXPECT_EQ(IPCChannelPosixTestListener::MESSAGE_RECEIVED, listener.status()); |
| 396 return 0; | 402 return 0; |
| 397 } | 403 } |
| 398 | 404 |
| 399 // Simple external process that shouldn't be able to connect to us. | 405 // Simple external process that shouldn't be able to connect to us. |
| 400 MULTIPROCESS_TEST_MAIN(IPCChannelPosixFailConnectionProc) { | 406 MULTIPROCESS_TEST_MAIN(IPCChannelPosixFailConnectionProc) { |
| 401 MessageLoopForIO message_loop; | 407 MessageLoopForIO message_loop; |
| 402 IPCChannelPosixTestListener listener(false); | 408 IPCChannelPosixTestListener listener(false); |
| 403 IPC::ChannelHandle handle(IPCChannelPosixTest::kConnectionSocketTestName); | 409 IPC::ChannelHandle handle(IPCChannelPosixTest::GetConnectionSocketName()); |
| 404 IPCChannelPosixTest::SetUpSocket(&handle, IPC::Channel::MODE_NAMED_CLIENT); | 410 IPCChannelPosixTest::SetUpSocket(&handle, IPC::Channel::MODE_NAMED_CLIENT); |
| 405 IPC::Channel channel(handle, IPC::Channel::MODE_NAMED_CLIENT, &listener); | 411 IPC::Channel channel(handle, IPC::Channel::MODE_NAMED_CLIENT, &listener); |
| 406 | 412 |
| 407 // In this case connect may succeed or fail depending on if the packet | 413 // In this case connect may succeed or fail depending on if the packet |
| 408 // actually gets sent at sendmsg. Since we never delay on send, we may not | 414 // actually gets sent at sendmsg. Since we never delay on send, we may not |
| 409 // see the error. However even if connect succeeds, eventually we will get an | 415 // see the error. However even if connect succeeds, eventually we will get an |
| 410 // error back since the channel will be closed when we attempt to read from | 416 // error back since the channel will be closed when we attempt to read from |
| 411 // it. | 417 // it. |
| 412 bool connected = channel.Connect(); | 418 bool connected = channel.Connect(); |
| 413 if (connected) { | 419 if (connected) { |
| 414 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout_ms()); | 420 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout_ms()); |
| 415 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); | 421 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); |
| 416 } else { | 422 } else { |
| 417 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); | 423 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); |
| 418 } | 424 } |
| 419 return 0; | 425 return 0; |
| 420 } | 426 } |
| OLD | NEW |