Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1313)

Side by Side Diff: ipc/ipc_channel_posix_unittest.cc

Issue 12386010: Implement IPC::ChannelFactory, a class that accept()s on a UNIX socket. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: un-revert fix to tests Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ipc/ipc_channel_posix.cc ('k') | ipc/ipc_channel_proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
24 #include "testing/multiprocess_func_list.h" 25 #include "testing/multiprocess_func_list.h"
25 26
26 namespace { 27 namespace {
27 28
28 static const uint32 kQuitMessage = 47; 29 static const uint32 kQuitMessage = 47;
29 30
30 class IPCChannelPosixTestListener : public IPC::Listener { 31 class IPCChannelPosixTestListener : public IPC::Listener {
31 public: 32 public:
32 enum STATUS { 33 enum STATUS {
33 DISCONNECTED, 34 DISCONNECTED,
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 void IPCChannelPosixTest::SetUpSocket(IPC::ChannelHandle *handle, 139 void IPCChannelPosixTest::SetUpSocket(IPC::ChannelHandle *handle,
139 IPC::Channel::Mode mode) { 140 IPC::Channel::Mode mode) {
140 const std::string& name = handle->name; 141 const std::string& name = handle->name;
141 142
142 int socket_fd = socket(PF_UNIX, SOCK_STREAM, 0); 143 int socket_fd = socket(PF_UNIX, SOCK_STREAM, 0);
143 ASSERT_GE(socket_fd, 0) << name; 144 ASSERT_GE(socket_fd, 0) << name;
144 ASSERT_GE(fcntl(socket_fd, F_SETFL, O_NONBLOCK), 0); 145 ASSERT_GE(fcntl(socket_fd, F_SETFL, O_NONBLOCK), 0);
145 struct sockaddr_un server_address = { 0 }; 146 struct sockaddr_un server_address = { 0 };
146 memset(&server_address, 0, sizeof(server_address)); 147 memset(&server_address, 0, sizeof(server_address));
147 server_address.sun_family = AF_UNIX; 148 server_address.sun_family = AF_UNIX;
148 int path_len = snprintf(server_address.sun_path, IPC::kMaxPipeNameLength, 149 int path_len = snprintf(server_address.sun_path, IPC::kMaxSocketNameLength,
149 "%s", name.c_str()); 150 "%s", name.c_str());
150 DCHECK_EQ(static_cast<int>(name.length()), path_len); 151 DCHECK_EQ(static_cast<int>(name.length()), path_len);
151 size_t server_address_len = offsetof(struct sockaddr_un, 152 size_t server_address_len = offsetof(struct sockaddr_un,
152 sun_path) + path_len + 1; 153 sun_path) + path_len + 1;
153 154
154 if (mode == IPC::Channel::MODE_NAMED_SERVER) { 155 if (mode == IPC::Channel::MODE_NAMED_SERVER) {
155 // Only one server at a time. Cleanup garbage if it exists. 156 // Only one server at a time. Cleanup garbage if it exists.
156 unlink(name.c_str()); 157 unlink(name.c_str());
157 // Make sure the path we need exists. 158 // Make sure the path we need exists.
158 base::FilePath path(name); 159 base::FilePath path(name);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 ASSERT_FALSE(channel.Connect()); 305 ASSERT_FALSE(channel.Connect());
305 306
306 // Test name that is too long. 307 // Test name that is too long.
307 const char *kTooLongName = "This_is_a_very_long_name_to_proactively_implement" 308 const char *kTooLongName = "This_is_a_very_long_name_to_proactively_implement"
308 "client-centered_synergy_through_top-line" 309 "client-centered_synergy_through_top-line"
309 "platforms_Phosfluorescently_disintermediate_" 310 "platforms_Phosfluorescently_disintermediate_"
310 "clicks-and-mortar_best_practices_without_" 311 "clicks-and-mortar_best_practices_without_"
311 "future-proof_growth_strategies_Continually" 312 "future-proof_growth_strategies_Continually"
312 "pontificate_proactive_potentialities_before" 313 "pontificate_proactive_potentialities_before"
313 "leading-edge_processes"; 314 "leading-edge_processes";
314 EXPECT_GE(strlen(kTooLongName), IPC::kMaxPipeNameLength); 315 EXPECT_GE(strlen(kTooLongName), IPC::kMaxSocketNameLength);
315 IPC::ChannelHandle handle2(kTooLongName); 316 IPC::ChannelHandle handle2(kTooLongName);
316 IPC::Channel channel2(handle2, IPC::Channel::MODE_NAMED_SERVER, NULL); 317 IPC::Channel channel2(handle2, IPC::Channel::MODE_NAMED_SERVER, NULL);
317 EXPECT_FALSE(channel2.Connect()); 318 EXPECT_FALSE(channel2.Connect());
318 } 319 }
319 320
320 TEST_F(IPCChannelPosixTest, MultiConnection) { 321 TEST_F(IPCChannelPosixTest, MultiConnection) {
321 // 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
322 // another external process attempt to connect to us. 323 // another external process attempt to connect to us.
323 IPCChannelPosixTestListener listener(false); 324 IPCChannelPosixTestListener listener(false);
324 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); 325 IPC::ChannelHandle chan_handle(GetConnectionSocketName());
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 if (connected) { 419 if (connected) {
419 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); 420 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout());
420 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); 421 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status());
421 } else { 422 } else {
422 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); 423 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status());
423 } 424 }
424 return 0; 425 return 0;
425 } 426 }
426 427
427 } // namespace 428 } // namespace
OLDNEW
« no previous file with comments | « ipc/ipc_channel_posix.cc ('k') | ipc/ipc_channel_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698