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/file_util.h" | 15 #include "base/file_util.h" |
16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
19 #include "base/path_service.h" | 19 #include "base/path_service.h" |
20 #include "base/posix/eintr_wrapper.h" | 20 #include "base/posix/eintr_wrapper.h" |
21 #include "base/test/multiprocess_test.h" | 21 #include "base/test/multiprocess_test.h" |
22 #include "base/test/test_timeouts.h" | 22 #include "base/test/test_timeouts.h" |
23 #include "ipc/ipc_listener.h" | 23 #include "ipc/ipc_listener.h" |
24 #include "ipc/unix_domain_socket_util.h" | |
25 #include "testing/multiprocess_func_list.h" | 24 #include "testing/multiprocess_func_list.h" |
26 | 25 |
27 namespace { | 26 namespace { |
28 | 27 |
29 static const uint32 kQuitMessage = 47; | 28 static const uint32 kQuitMessage = 47; |
30 | 29 |
31 class IPCChannelPosixTestListener : public IPC::Listener { | 30 class IPCChannelPosixTestListener : public IPC::Listener { |
32 public: | 31 public: |
33 enum STATUS { | 32 enum STATUS { |
34 DISCONNECTED, | 33 DISCONNECTED, |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 void IPCChannelPosixTest::SetUpSocket(IPC::ChannelHandle *handle, | 138 void IPCChannelPosixTest::SetUpSocket(IPC::ChannelHandle *handle, |
140 IPC::Channel::Mode mode) { | 139 IPC::Channel::Mode mode) { |
141 const std::string& name = handle->name; | 140 const std::string& name = handle->name; |
142 | 141 |
143 int socket_fd = socket(PF_UNIX, SOCK_STREAM, 0); | 142 int socket_fd = socket(PF_UNIX, SOCK_STREAM, 0); |
144 ASSERT_GE(socket_fd, 0) << name; | 143 ASSERT_GE(socket_fd, 0) << name; |
145 ASSERT_GE(fcntl(socket_fd, F_SETFL, O_NONBLOCK), 0); | 144 ASSERT_GE(fcntl(socket_fd, F_SETFL, O_NONBLOCK), 0); |
146 struct sockaddr_un server_address = { 0 }; | 145 struct sockaddr_un server_address = { 0 }; |
147 memset(&server_address, 0, sizeof(server_address)); | 146 memset(&server_address, 0, sizeof(server_address)); |
148 server_address.sun_family = AF_UNIX; | 147 server_address.sun_family = AF_UNIX; |
149 int path_len = snprintf(server_address.sun_path, IPC::kMaxSocketNameLength, | 148 int path_len = snprintf(server_address.sun_path, IPC::kMaxPipeNameLength, |
150 "%s", name.c_str()); | 149 "%s", name.c_str()); |
151 DCHECK_EQ(static_cast<int>(name.length()), path_len); | 150 DCHECK_EQ(static_cast<int>(name.length()), path_len); |
152 size_t server_address_len = offsetof(struct sockaddr_un, | 151 size_t server_address_len = offsetof(struct sockaddr_un, |
153 sun_path) + path_len + 1; | 152 sun_path) + path_len + 1; |
154 | 153 |
155 if (mode == IPC::Channel::MODE_NAMED_SERVER) { | 154 if (mode == IPC::Channel::MODE_NAMED_SERVER) { |
156 // Only one server at a time. Cleanup garbage if it exists. | 155 // Only one server at a time. Cleanup garbage if it exists. |
157 unlink(name.c_str()); | 156 unlink(name.c_str()); |
158 // Make sure the path we need exists. | 157 // Make sure the path we need exists. |
159 base::FilePath path(name); | 158 base::FilePath path(name); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 ASSERT_FALSE(channel.Connect()); | 304 ASSERT_FALSE(channel.Connect()); |
306 | 305 |
307 // Test name that is too long. | 306 // Test name that is too long. |
308 const char *kTooLongName = "This_is_a_very_long_name_to_proactively_implement" | 307 const char *kTooLongName = "This_is_a_very_long_name_to_proactively_implement" |
309 "client-centered_synergy_through_top-line" | 308 "client-centered_synergy_through_top-line" |
310 "platforms_Phosfluorescently_disintermediate_" | 309 "platforms_Phosfluorescently_disintermediate_" |
311 "clicks-and-mortar_best_practices_without_" | 310 "clicks-and-mortar_best_practices_without_" |
312 "future-proof_growth_strategies_Continually" | 311 "future-proof_growth_strategies_Continually" |
313 "pontificate_proactive_potentialities_before" | 312 "pontificate_proactive_potentialities_before" |
314 "leading-edge_processes"; | 313 "leading-edge_processes"; |
315 EXPECT_GE(strlen(kTooLongName), IPC::kMaxSocketNameLength); | 314 EXPECT_GE(strlen(kTooLongName), IPC::kMaxPipeNameLength); |
316 IPC::ChannelHandle handle2(kTooLongName); | 315 IPC::ChannelHandle handle2(kTooLongName); |
317 IPC::Channel channel2(handle2, IPC::Channel::MODE_NAMED_SERVER, NULL); | 316 IPC::Channel channel2(handle2, IPC::Channel::MODE_NAMED_SERVER, NULL); |
318 EXPECT_FALSE(channel2.Connect()); | 317 EXPECT_FALSE(channel2.Connect()); |
319 } | 318 } |
320 | 319 |
321 TEST_F(IPCChannelPosixTest, MultiConnection) { | 320 TEST_F(IPCChannelPosixTest, MultiConnection) { |
322 // Test setting up a connection to an external process, and then have | 321 // Test setting up a connection to an external process, and then have |
323 // another external process attempt to connect to us. | 322 // another external process attempt to connect to us. |
324 IPCChannelPosixTestListener listener(false); | 323 IPCChannelPosixTestListener listener(false); |
325 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); | 324 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 if (connected) { | 418 if (connected) { |
420 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); | 419 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); |
421 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); | 420 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); |
422 } else { | 421 } else { |
423 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); | 422 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); |
424 } | 423 } |
425 return 0; | 424 return 0; |
426 } | 425 } |
427 | 426 |
428 } // namespace | 427 } // namespace |
OLD | NEW |