| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 protected: | 103 protected: |
| 104 virtual void SetUp(); | 104 virtual void SetUp(); |
| 105 virtual void TearDown(); | 105 virtual void TearDown(); |
| 106 | 106 |
| 107 private: | 107 private: |
| 108 scoped_ptr<MessageLoopForIO> message_loop_; | 108 scoped_ptr<MessageLoopForIO> message_loop_; |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 const std::string IPCChannelPosixTest::GetChannelDirName() { | 111 const std::string IPCChannelPosixTest::GetChannelDirName() { |
| 112 #if defined(OS_ANDROID) | 112 #if defined(OS_ANDROID) |
| 113 FilePath tmp_dir; | 113 base::FilePath tmp_dir; |
| 114 PathService::Get(base::DIR_CACHE, &tmp_dir); | 114 PathService::Get(base::DIR_CACHE, &tmp_dir); |
| 115 return tmp_dir.value(); | 115 return tmp_dir.value(); |
| 116 #else | 116 #else |
| 117 return "/var/tmp"; | 117 return "/var/tmp"; |
| 118 #endif | 118 #endif |
| 119 } | 119 } |
| 120 | 120 |
| 121 const std::string IPCChannelPosixTest::GetConnectionSocketName() { | 121 const std::string IPCChannelPosixTest::GetConnectionSocketName() { |
| 122 return GetChannelDirName() + "/chrome_IPCChannelPosixTest__ConnectionSocket"; | 122 return GetChannelDirName() + "/chrome_IPCChannelPosixTest__ConnectionSocket"; |
| 123 } | 123 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 148 int path_len = snprintf(server_address.sun_path, IPC::kMaxPipeNameLength, | 148 int path_len = snprintf(server_address.sun_path, IPC::kMaxPipeNameLength, |
| 149 "%s", name.c_str()); | 149 "%s", name.c_str()); |
| 150 DCHECK_EQ(static_cast<int>(name.length()), path_len); | 150 DCHECK_EQ(static_cast<int>(name.length()), path_len); |
| 151 size_t server_address_len = offsetof(struct sockaddr_un, | 151 size_t server_address_len = offsetof(struct sockaddr_un, |
| 152 sun_path) + path_len + 1; | 152 sun_path) + path_len + 1; |
| 153 | 153 |
| 154 if (mode == IPC::Channel::MODE_NAMED_SERVER) { | 154 if (mode == IPC::Channel::MODE_NAMED_SERVER) { |
| 155 // Only one server at a time. Cleanup garbage if it exists. | 155 // Only one server at a time. Cleanup garbage if it exists. |
| 156 unlink(name.c_str()); | 156 unlink(name.c_str()); |
| 157 // Make sure the path we need exists. | 157 // Make sure the path we need exists. |
| 158 FilePath path(name); | 158 base::FilePath path(name); |
| 159 FilePath dir_path = path.DirName(); | 159 base::FilePath dir_path = path.DirName(); |
| 160 ASSERT_TRUE(file_util::CreateDirectory(dir_path)); | 160 ASSERT_TRUE(file_util::CreateDirectory(dir_path)); |
| 161 ASSERT_GE(bind(socket_fd, | 161 ASSERT_GE(bind(socket_fd, |
| 162 reinterpret_cast<struct sockaddr *>(&server_address), | 162 reinterpret_cast<struct sockaddr *>(&server_address), |
| 163 server_address_len), 0) << server_address.sun_path | 163 server_address_len), 0) << server_address.sun_path |
| 164 << ": " << strerror(errno) | 164 << ": " << strerror(errno) |
| 165 << "(" << errno << ")"; | 165 << "(" << errno << ")"; |
| 166 ASSERT_GE(listen(socket_fd, SOMAXCONN), 0) << server_address.sun_path | 166 ASSERT_GE(listen(socket_fd, SOMAXCONN), 0) << server_address.sun_path |
| 167 << ": " << strerror(errno) | 167 << ": " << strerror(errno) |
| 168 << "(" << errno << ")"; | 168 << "(" << errno << ")"; |
| 169 } else if (mode == IPC::Channel::MODE_NAMED_CLIENT) { | 169 } else if (mode == IPC::Channel::MODE_NAMED_CLIENT) { |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 IPCChannelPosixTestListener listener(false); | 370 IPCChannelPosixTestListener listener(false); |
| 371 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); | 371 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); |
| 372 IPC::Channel channel(chan_handle, IPC::Channel::MODE_NONE, &listener); | 372 IPC::Channel channel(chan_handle, IPC::Channel::MODE_NONE, &listener); |
| 373 ASSERT_FALSE(channel.Connect()); | 373 ASSERT_FALSE(channel.Connect()); |
| 374 } | 374 } |
| 375 | 375 |
| 376 TEST_F(IPCChannelPosixTest, IsNamedServerInitialized) { | 376 TEST_F(IPCChannelPosixTest, IsNamedServerInitialized) { |
| 377 const std::string& connection_socket_name = GetConnectionSocketName(); | 377 const std::string& connection_socket_name = GetConnectionSocketName(); |
| 378 IPCChannelPosixTestListener listener(false); | 378 IPCChannelPosixTestListener listener(false); |
| 379 IPC::ChannelHandle chan_handle(connection_socket_name); | 379 IPC::ChannelHandle chan_handle(connection_socket_name); |
| 380 ASSERT_TRUE(file_util::Delete(FilePath(connection_socket_name), false)); | 380 ASSERT_TRUE(file_util::Delete(base::FilePath(connection_socket_name), false)); |
| 381 ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized( | 381 ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized( |
| 382 connection_socket_name)); | 382 connection_socket_name)); |
| 383 IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener); | 383 IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener); |
| 384 ASSERT_TRUE(IPC::Channel::IsNamedServerInitialized( | 384 ASSERT_TRUE(IPC::Channel::IsNamedServerInitialized( |
| 385 connection_socket_name)); | 385 connection_socket_name)); |
| 386 channel.Close(); | 386 channel.Close(); |
| 387 ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized( | 387 ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized( |
| 388 connection_socket_name)); | 388 connection_socket_name)); |
| 389 } | 389 } |
| 390 | 390 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 418 if (connected) { | 418 if (connected) { |
| 419 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); | 419 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); |
| 420 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); | 420 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); |
| 421 } else { | 421 } else { |
| 422 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); | 422 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); |
| 423 } | 423 } |
| 424 return 0; | 424 return 0; |
| 425 } | 425 } |
| 426 | 426 |
| 427 } // namespace | 427 } // namespace |
| OLD | NEW |