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

Side by Side Diff: ipc/ipc_channel_posix_unittest.cc

Issue 1292263003: ipc: Use a global for the process's attachment broker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ipc_message2
Patch Set: Comments from avi. Created 5 years, 3 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
« no previous file with comments | « ipc/ipc_channel_posix.cc ('k') | ipc/ipc_channel_win.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 <stdint.h> 10 #include <stdint.h>
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 196
197 TEST_F(IPCChannelPosixTest, BasicListen) { 197 TEST_F(IPCChannelPosixTest, BasicListen) {
198 const std::string kChannelName = 198 const std::string kChannelName =
199 GetChannelDirName() + "/IPCChannelPosixTest_BasicListen"; 199 GetChannelDirName() + "/IPCChannelPosixTest_BasicListen";
200 200
201 // Test creating a socket that is listening. 201 // Test creating a socket that is listening.
202 IPC::ChannelHandle handle(kChannelName); 202 IPC::ChannelHandle handle(kChannelName);
203 SetUpSocket(&handle, IPC::Channel::MODE_NAMED_SERVER); 203 SetUpSocket(&handle, IPC::Channel::MODE_NAMED_SERVER);
204 unlink(handle.name.c_str()); 204 unlink(handle.name.c_str());
205 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( 205 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix(
206 handle, IPC::Channel::MODE_NAMED_SERVER, NULL, nullptr)); 206 handle, IPC::Channel::MODE_NAMED_SERVER, NULL));
207 ASSERT_TRUE(channel->Connect()); 207 ASSERT_TRUE(channel->Connect());
208 ASSERT_TRUE(channel->AcceptsConnections()); 208 ASSERT_TRUE(channel->AcceptsConnections());
209 ASSERT_FALSE(channel->HasAcceptedConnection()); 209 ASSERT_FALSE(channel->HasAcceptedConnection());
210 channel->ResetToAcceptingConnectionState(); 210 channel->ResetToAcceptingConnectionState();
211 ASSERT_FALSE(channel->HasAcceptedConnection()); 211 ASSERT_FALSE(channel->HasAcceptedConnection());
212 unlink(handle.name.c_str()); 212 unlink(handle.name.c_str());
213 } 213 }
214 214
215 TEST_F(IPCChannelPosixTest, BasicConnected) { 215 TEST_F(IPCChannelPosixTest, BasicConnected) {
216 // Test creating a socket that is connected. 216 // Test creating a socket that is connected.
217 int pipe_fds[2]; 217 int pipe_fds[2];
218 ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, pipe_fds)); 218 ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, pipe_fds));
219 std::string socket_name("/var/tmp/IPCChannelPosixTest_BasicConnected"); 219 std::string socket_name("/var/tmp/IPCChannelPosixTest_BasicConnected");
220 ASSERT_GE(fcntl(pipe_fds[0], F_SETFL, O_NONBLOCK), 0); 220 ASSERT_GE(fcntl(pipe_fds[0], F_SETFL, O_NONBLOCK), 0);
221 221
222 base::FileDescriptor fd(pipe_fds[0], false); 222 base::FileDescriptor fd(pipe_fds[0], false);
223 IPC::ChannelHandle handle(socket_name, fd); 223 IPC::ChannelHandle handle(socket_name, fd);
224 scoped_ptr<IPC::ChannelPosix> channel( 224 scoped_ptr<IPC::ChannelPosix> channel(
225 new IPC::ChannelPosix(handle, IPC::Channel::MODE_SERVER, NULL, nullptr)); 225 new IPC::ChannelPosix(handle, IPC::Channel::MODE_SERVER, NULL));
226 ASSERT_TRUE(channel->Connect()); 226 ASSERT_TRUE(channel->Connect());
227 ASSERT_FALSE(channel->AcceptsConnections()); 227 ASSERT_FALSE(channel->AcceptsConnections());
228 channel->Close(); 228 channel->Close();
229 ASSERT_TRUE(IGNORE_EINTR(close(pipe_fds[1])) == 0); 229 ASSERT_TRUE(IGNORE_EINTR(close(pipe_fds[1])) == 0);
230 230
231 // Make sure that we can use the socket that is created for us by 231 // Make sure that we can use the socket that is created for us by
232 // a standard channel. 232 // a standard channel.
233 scoped_ptr<IPC::ChannelPosix> channel2(new IPC::ChannelPosix( 233 scoped_ptr<IPC::ChannelPosix> channel2(new IPC::ChannelPosix(
234 socket_name, IPC::Channel::MODE_SERVER, NULL, nullptr)); 234 socket_name, IPC::Channel::MODE_SERVER, NULL));
235 ASSERT_TRUE(channel2->Connect()); 235 ASSERT_TRUE(channel2->Connect());
236 ASSERT_FALSE(channel2->AcceptsConnections()); 236 ASSERT_FALSE(channel2->AcceptsConnections());
237 } 237 }
238 238
239 // If a connection closes right before a Send() call, we may end up closing 239 // If a connection closes right before a Send() call, we may end up closing
240 // the connection without notifying the listener, which can cause hangs in 240 // the connection without notifying the listener, which can cause hangs in
241 // sync_message_filter and others. Make sure the listener is notified. 241 // sync_message_filter and others. Make sure the listener is notified.
242 TEST_F(IPCChannelPosixTest, SendHangTest) { 242 TEST_F(IPCChannelPosixTest, SendHangTest) {
243 IPCChannelPosixTestListener out_listener(true); 243 IPCChannelPosixTestListener out_listener(true);
244 IPCChannelPosixTestListener in_listener(true); 244 IPCChannelPosixTestListener in_listener(true);
245 IPC::ChannelHandle in_handle("IN"); 245 IPC::ChannelHandle in_handle("IN");
246 scoped_ptr<IPC::ChannelPosix> in_chan(new IPC::ChannelPosix( 246 scoped_ptr<IPC::ChannelPosix> in_chan(new IPC::ChannelPosix(
247 in_handle, IPC::Channel::MODE_SERVER, &in_listener, nullptr)); 247 in_handle, IPC::Channel::MODE_SERVER, &in_listener));
248 IPC::ChannelHandle out_handle( 248 IPC::ChannelHandle out_handle(
249 "OUT", base::FileDescriptor(in_chan->TakeClientFileDescriptor())); 249 "OUT", base::FileDescriptor(in_chan->TakeClientFileDescriptor()));
250 scoped_ptr<IPC::ChannelPosix> out_chan(new IPC::ChannelPosix( 250 scoped_ptr<IPC::ChannelPosix> out_chan(new IPC::ChannelPosix(
251 out_handle, IPC::Channel::MODE_CLIENT, &out_listener, nullptr)); 251 out_handle, IPC::Channel::MODE_CLIENT, &out_listener));
252 ASSERT_TRUE(in_chan->Connect()); 252 ASSERT_TRUE(in_chan->Connect());
253 ASSERT_TRUE(out_chan->Connect()); 253 ASSERT_TRUE(out_chan->Connect());
254 in_chan->Close(); // simulate remote process dying at an unfortunate time. 254 in_chan->Close(); // simulate remote process dying at an unfortunate time.
255 // Send will fail, because it cannot write the message. 255 // Send will fail, because it cannot write the message.
256 ASSERT_FALSE(out_chan->Send(new IPC::Message( 256 ASSERT_FALSE(out_chan->Send(new IPC::Message(
257 0, // routing_id 257 0, // routing_id
258 kQuitMessage, // message type 258 kQuitMessage, // message type
259 IPC::Message::PRIORITY_NORMAL))); 259 IPC::Message::PRIORITY_NORMAL)));
260 SpinRunLoop(TestTimeouts::action_max_timeout()); 260 SpinRunLoop(TestTimeouts::action_max_timeout());
261 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, out_listener.status()); 261 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, out_listener.status());
262 } 262 }
263 263
264 // If a connection closes right before a Connect() call, we may end up closing 264 // If a connection closes right before a Connect() call, we may end up closing
265 // the connection without notifying the listener, which can cause hangs in 265 // the connection without notifying the listener, which can cause hangs in
266 // sync_message_filter and others. Make sure the listener is notified. 266 // sync_message_filter and others. Make sure the listener is notified.
267 TEST_F(IPCChannelPosixTest, AcceptHangTest) { 267 TEST_F(IPCChannelPosixTest, AcceptHangTest) {
268 IPCChannelPosixTestListener out_listener(true); 268 IPCChannelPosixTestListener out_listener(true);
269 IPCChannelPosixTestListener in_listener(true); 269 IPCChannelPosixTestListener in_listener(true);
270 IPC::ChannelHandle in_handle("IN"); 270 IPC::ChannelHandle in_handle("IN");
271 scoped_ptr<IPC::ChannelPosix> in_chan(new IPC::ChannelPosix( 271 scoped_ptr<IPC::ChannelPosix> in_chan(new IPC::ChannelPosix(
272 in_handle, IPC::Channel::MODE_SERVER, &in_listener, nullptr)); 272 in_handle, IPC::Channel::MODE_SERVER, &in_listener));
273 IPC::ChannelHandle out_handle( 273 IPC::ChannelHandle out_handle(
274 "OUT", base::FileDescriptor(in_chan->TakeClientFileDescriptor())); 274 "OUT", base::FileDescriptor(in_chan->TakeClientFileDescriptor()));
275 scoped_ptr<IPC::ChannelPosix> out_chan(new IPC::ChannelPosix( 275 scoped_ptr<IPC::ChannelPosix> out_chan(new IPC::ChannelPosix(
276 out_handle, IPC::Channel::MODE_CLIENT, &out_listener, nullptr)); 276 out_handle, IPC::Channel::MODE_CLIENT, &out_listener));
277 ASSERT_TRUE(in_chan->Connect()); 277 ASSERT_TRUE(in_chan->Connect());
278 in_chan->Close(); // simulate remote process dying at an unfortunate time. 278 in_chan->Close(); // simulate remote process dying at an unfortunate time.
279 ASSERT_FALSE(out_chan->Connect()); 279 ASSERT_FALSE(out_chan->Connect());
280 SpinRunLoop(TestTimeouts::action_max_timeout()); 280 SpinRunLoop(TestTimeouts::action_max_timeout());
281 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, out_listener.status()); 281 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, out_listener.status());
282 } 282 }
283 283
284 #if defined(OS_ANDROID) 284 #if defined(OS_ANDROID)
285 #define MAYBE_AdvancedConnected DISABLED_AdvancedConnected 285 #define MAYBE_AdvancedConnected DISABLED_AdvancedConnected
286 #else 286 #else
287 #define MAYBE_AdvancedConnected AdvancedConnected 287 #define MAYBE_AdvancedConnected AdvancedConnected
288 #endif 288 #endif
289 TEST_F(IPCChannelPosixTest, MAYBE_AdvancedConnected) { 289 TEST_F(IPCChannelPosixTest, MAYBE_AdvancedConnected) {
290 // Test creating a connection to an external process. 290 // Test creating a connection to an external process.
291 IPCChannelPosixTestListener listener(false); 291 IPCChannelPosixTestListener listener(false);
292 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); 292 IPC::ChannelHandle chan_handle(GetConnectionSocketName());
293 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER); 293 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER);
294 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( 294 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix(
295 chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener, nullptr)); 295 chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener));
296 ASSERT_TRUE(channel->Connect()); 296 ASSERT_TRUE(channel->Connect());
297 ASSERT_TRUE(channel->AcceptsConnections()); 297 ASSERT_TRUE(channel->AcceptsConnections());
298 ASSERT_FALSE(channel->HasAcceptedConnection()); 298 ASSERT_FALSE(channel->HasAcceptedConnection());
299 299
300 base::Process process = SpawnChild("IPCChannelPosixTestConnectionProc"); 300 base::Process process = SpawnChild("IPCChannelPosixTestConnectionProc");
301 ASSERT_TRUE(process.IsValid()); 301 ASSERT_TRUE(process.IsValid());
302 SpinRunLoop(TestTimeouts::action_max_timeout()); 302 SpinRunLoop(TestTimeouts::action_max_timeout());
303 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); 303 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status());
304 ASSERT_TRUE(channel->HasAcceptedConnection()); 304 ASSERT_TRUE(channel->HasAcceptedConnection());
305 IPC::Message* message = new IPC::Message(0, // routing_id 305 IPC::Message* message = new IPC::Message(0, // routing_id
(...skipping 15 matching lines...) Expand all
321 #define MAYBE_ResetState ResetState 321 #define MAYBE_ResetState ResetState
322 #endif 322 #endif
323 TEST_F(IPCChannelPosixTest, MAYBE_ResetState) { 323 TEST_F(IPCChannelPosixTest, MAYBE_ResetState) {
324 // Test creating a connection to an external process. Close the connection, 324 // Test creating a connection to an external process. Close the connection,
325 // but continue to listen and make sure another external process can connect 325 // but continue to listen and make sure another external process can connect
326 // to us. 326 // to us.
327 IPCChannelPosixTestListener listener(false); 327 IPCChannelPosixTestListener listener(false);
328 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); 328 IPC::ChannelHandle chan_handle(GetConnectionSocketName());
329 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER); 329 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER);
330 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( 330 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix(
331 chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener, nullptr)); 331 chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener));
332 ASSERT_TRUE(channel->Connect()); 332 ASSERT_TRUE(channel->Connect());
333 ASSERT_TRUE(channel->AcceptsConnections()); 333 ASSERT_TRUE(channel->AcceptsConnections());
334 ASSERT_FALSE(channel->HasAcceptedConnection()); 334 ASSERT_FALSE(channel->HasAcceptedConnection());
335 335
336 base::Process process = SpawnChild("IPCChannelPosixTestConnectionProc"); 336 base::Process process = SpawnChild("IPCChannelPosixTestConnectionProc");
337 ASSERT_TRUE(process.IsValid()); 337 ASSERT_TRUE(process.IsValid());
338 SpinRunLoop(TestTimeouts::action_max_timeout()); 338 SpinRunLoop(TestTimeouts::action_max_timeout());
339 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); 339 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status());
340 ASSERT_TRUE(channel->HasAcceptedConnection()); 340 ASSERT_TRUE(channel->HasAcceptedConnection());
341 channel->ResetToAcceptingConnectionState(); 341 channel->ResetToAcceptingConnectionState();
(...skipping 15 matching lines...) Expand all
357 EXPECT_EQ(0, exit_code); 357 EXPECT_EQ(0, exit_code);
358 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); 358 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status());
359 ASSERT_FALSE(channel->HasAcceptedConnection()); 359 ASSERT_FALSE(channel->HasAcceptedConnection());
360 unlink(chan_handle.name.c_str()); 360 unlink(chan_handle.name.c_str());
361 } 361 }
362 362
363 TEST_F(IPCChannelPosixTest, BadChannelName) { 363 TEST_F(IPCChannelPosixTest, BadChannelName) {
364 // Test empty name 364 // Test empty name
365 IPC::ChannelHandle handle(""); 365 IPC::ChannelHandle handle("");
366 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( 366 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix(
367 handle, IPC::Channel::MODE_NAMED_SERVER, NULL, nullptr)); 367 handle, IPC::Channel::MODE_NAMED_SERVER, NULL));
368 ASSERT_FALSE(channel->Connect()); 368 ASSERT_FALSE(channel->Connect());
369 369
370 // Test name that is too long. 370 // Test name that is too long.
371 const char *kTooLongName = "This_is_a_very_long_name_to_proactively_implement" 371 const char *kTooLongName = "This_is_a_very_long_name_to_proactively_implement"
372 "client-centered_synergy_through_top-line" 372 "client-centered_synergy_through_top-line"
373 "platforms_Phosfluorescently_disintermediate_" 373 "platforms_Phosfluorescently_disintermediate_"
374 "clicks-and-mortar_best_practices_without_" 374 "clicks-and-mortar_best_practices_without_"
375 "future-proof_growth_strategies_Continually" 375 "future-proof_growth_strategies_Continually"
376 "pontificate_proactive_potentialities_before" 376 "pontificate_proactive_potentialities_before"
377 "leading-edge_processes"; 377 "leading-edge_processes";
378 EXPECT_GE(strlen(kTooLongName), IPC::kMaxSocketNameLength); 378 EXPECT_GE(strlen(kTooLongName), IPC::kMaxSocketNameLength);
379 IPC::ChannelHandle handle2(kTooLongName); 379 IPC::ChannelHandle handle2(kTooLongName);
380 scoped_ptr<IPC::ChannelPosix> channel2(new IPC::ChannelPosix( 380 scoped_ptr<IPC::ChannelPosix> channel2(new IPC::ChannelPosix(
381 handle2, IPC::Channel::MODE_NAMED_SERVER, NULL, nullptr)); 381 handle2, IPC::Channel::MODE_NAMED_SERVER, NULL));
382 EXPECT_FALSE(channel2->Connect()); 382 EXPECT_FALSE(channel2->Connect());
383 } 383 }
384 384
385 #if defined(OS_ANDROID) 385 #if defined(OS_ANDROID)
386 #define MAYBE_MultiConnection DISABLED_MultiConnection 386 #define MAYBE_MultiConnection DISABLED_MultiConnection
387 #else 387 #else
388 #define MAYBE_MultiConnection MultiConnection 388 #define MAYBE_MultiConnection MultiConnection
389 #endif 389 #endif
390 TEST_F(IPCChannelPosixTest, MAYBE_MultiConnection) { 390 TEST_F(IPCChannelPosixTest, MAYBE_MultiConnection) {
391 // Test setting up a connection to an external process, and then have 391 // Test setting up a connection to an external process, and then have
392 // another external process attempt to connect to us. 392 // another external process attempt to connect to us.
393 IPCChannelPosixTestListener listener(false); 393 IPCChannelPosixTestListener listener(false);
394 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); 394 IPC::ChannelHandle chan_handle(GetConnectionSocketName());
395 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER); 395 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER);
396 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( 396 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix(
397 chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener, nullptr)); 397 chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener));
398 ASSERT_TRUE(channel->Connect()); 398 ASSERT_TRUE(channel->Connect());
399 ASSERT_TRUE(channel->AcceptsConnections()); 399 ASSERT_TRUE(channel->AcceptsConnections());
400 ASSERT_FALSE(channel->HasAcceptedConnection()); 400 ASSERT_FALSE(channel->HasAcceptedConnection());
401 401
402 base::Process process = SpawnChild("IPCChannelPosixTestConnectionProc"); 402 base::Process process = SpawnChild("IPCChannelPosixTestConnectionProc");
403 ASSERT_TRUE(process.IsValid()); 403 ASSERT_TRUE(process.IsValid());
404 SpinRunLoop(TestTimeouts::action_max_timeout()); 404 SpinRunLoop(TestTimeouts::action_max_timeout());
405 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); 405 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status());
406 ASSERT_TRUE(channel->HasAcceptedConnection()); 406 ASSERT_TRUE(channel->HasAcceptedConnection());
407 base::Process process2 = SpawnChild("IPCChannelPosixFailConnectionProc"); 407 base::Process process2 = SpawnChild("IPCChannelPosixFailConnectionProc");
(...skipping 15 matching lines...) Expand all
423 ASSERT_FALSE(channel->HasAcceptedConnection()); 423 ASSERT_FALSE(channel->HasAcceptedConnection());
424 unlink(chan_handle.name.c_str()); 424 unlink(chan_handle.name.c_str());
425 } 425 }
426 426
427 TEST_F(IPCChannelPosixTest, DoubleServer) { 427 TEST_F(IPCChannelPosixTest, DoubleServer) {
428 // Test setting up two servers with the same name. 428 // Test setting up two servers with the same name.
429 IPCChannelPosixTestListener listener(false); 429 IPCChannelPosixTestListener listener(false);
430 IPCChannelPosixTestListener listener2(false); 430 IPCChannelPosixTestListener listener2(false);
431 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); 431 IPC::ChannelHandle chan_handle(GetConnectionSocketName());
432 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( 432 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix(
433 chan_handle, IPC::Channel::MODE_SERVER, &listener, nullptr)); 433 chan_handle, IPC::Channel::MODE_SERVER, &listener));
434 scoped_ptr<IPC::ChannelPosix> channel2(new IPC::ChannelPosix( 434 scoped_ptr<IPC::ChannelPosix> channel2(new IPC::ChannelPosix(
435 chan_handle, IPC::Channel::MODE_SERVER, &listener2, nullptr)); 435 chan_handle, IPC::Channel::MODE_SERVER, &listener2));
436 ASSERT_TRUE(channel->Connect()); 436 ASSERT_TRUE(channel->Connect());
437 ASSERT_FALSE(channel2->Connect()); 437 ASSERT_FALSE(channel2->Connect());
438 } 438 }
439 439
440 TEST_F(IPCChannelPosixTest, BadMode) { 440 TEST_F(IPCChannelPosixTest, BadMode) {
441 // Test setting up two servers with a bad mode. 441 // Test setting up two servers with a bad mode.
442 IPCChannelPosixTestListener listener(false); 442 IPCChannelPosixTestListener listener(false);
443 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); 443 IPC::ChannelHandle chan_handle(GetConnectionSocketName());
444 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( 444 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix(
445 chan_handle, IPC::Channel::MODE_NONE, &listener, nullptr)); 445 chan_handle, IPC::Channel::MODE_NONE, &listener));
446 ASSERT_FALSE(channel->Connect()); 446 ASSERT_FALSE(channel->Connect());
447 } 447 }
448 448
449 TEST_F(IPCChannelPosixTest, IsNamedServerInitialized) { 449 TEST_F(IPCChannelPosixTest, IsNamedServerInitialized) {
450 const std::string& connection_socket_name = GetConnectionSocketName(); 450 const std::string& connection_socket_name = GetConnectionSocketName();
451 IPCChannelPosixTestListener listener(false); 451 IPCChannelPosixTestListener listener(false);
452 IPC::ChannelHandle chan_handle(connection_socket_name); 452 IPC::ChannelHandle chan_handle(connection_socket_name);
453 ASSERT_TRUE(base::DeleteFile(base::FilePath(connection_socket_name), false)); 453 ASSERT_TRUE(base::DeleteFile(base::FilePath(connection_socket_name), false));
454 ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized( 454 ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized(
455 connection_socket_name)); 455 connection_socket_name));
456 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( 456 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix(
457 chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener, nullptr)); 457 chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener));
458 ASSERT_TRUE(IPC::Channel::IsNamedServerInitialized( 458 ASSERT_TRUE(IPC::Channel::IsNamedServerInitialized(
459 connection_socket_name)); 459 connection_socket_name));
460 channel->Close(); 460 channel->Close();
461 ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized( 461 ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized(
462 connection_socket_name)); 462 connection_socket_name));
463 unlink(chan_handle.name.c_str()); 463 unlink(chan_handle.name.c_str());
464 } 464 }
465 465
466 // A long running process that connects to us 466 // A long running process that connects to us
467 MULTIPROCESS_TEST_MAIN(IPCChannelPosixTestConnectionProc) { 467 MULTIPROCESS_TEST_MAIN(IPCChannelPosixTestConnectionProc) {
468 base::MessageLoopForIO message_loop; 468 base::MessageLoopForIO message_loop;
469 IPCChannelPosixTestListener listener(true); 469 IPCChannelPosixTestListener listener(true);
470 IPC::ChannelHandle handle(IPCChannelPosixTest::GetConnectionSocketName()); 470 IPC::ChannelHandle handle(IPCChannelPosixTest::GetConnectionSocketName());
471 IPCChannelPosixTest::SetUpSocket(&handle, IPC::Channel::MODE_NAMED_CLIENT); 471 IPCChannelPosixTest::SetUpSocket(&handle, IPC::Channel::MODE_NAMED_CLIENT);
472 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( 472 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix(
473 handle, IPC::Channel::MODE_NAMED_CLIENT, &listener, nullptr)); 473 handle, IPC::Channel::MODE_NAMED_CLIENT, &listener));
474 EXPECT_TRUE(channel->Connect()); 474 EXPECT_TRUE(channel->Connect());
475 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); 475 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout());
476 EXPECT_EQ(IPCChannelPosixTestListener::MESSAGE_RECEIVED, listener.status()); 476 EXPECT_EQ(IPCChannelPosixTestListener::MESSAGE_RECEIVED, listener.status());
477 return 0; 477 return 0;
478 } 478 }
479 479
480 // Simple external process that shouldn't be able to connect to us. 480 // Simple external process that shouldn't be able to connect to us.
481 MULTIPROCESS_TEST_MAIN(IPCChannelPosixFailConnectionProc) { 481 MULTIPROCESS_TEST_MAIN(IPCChannelPosixFailConnectionProc) {
482 base::MessageLoopForIO message_loop; 482 base::MessageLoopForIO message_loop;
483 IPCChannelPosixTestListener listener(false); 483 IPCChannelPosixTestListener listener(false);
484 IPC::ChannelHandle handle(IPCChannelPosixTest::GetConnectionSocketName()); 484 IPC::ChannelHandle handle(IPCChannelPosixTest::GetConnectionSocketName());
485 IPCChannelPosixTest::SetUpSocket(&handle, IPC::Channel::MODE_NAMED_CLIENT); 485 IPCChannelPosixTest::SetUpSocket(&handle, IPC::Channel::MODE_NAMED_CLIENT);
486 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( 486 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix(
487 handle, IPC::Channel::MODE_NAMED_CLIENT, &listener, nullptr)); 487 handle, IPC::Channel::MODE_NAMED_CLIENT, &listener));
488 488
489 // In this case connect may succeed or fail depending on if the packet 489 // In this case connect may succeed or fail depending on if the packet
490 // actually gets sent at sendmsg. Since we never delay on send, we may not 490 // actually gets sent at sendmsg. Since we never delay on send, we may not
491 // see the error. However even if connect succeeds, eventually we will get an 491 // see the error. However even if connect succeeds, eventually we will get an
492 // error back since the channel will be closed when we attempt to read from 492 // error back since the channel will be closed when we attempt to read from
493 // it. 493 // it.
494 bool connected = channel->Connect(); 494 bool connected = channel->Connect();
495 if (connected) { 495 if (connected) {
496 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); 496 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout());
497 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); 497 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status());
498 } else { 498 } else {
499 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); 499 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status());
500 } 500 }
501 return 0; 501 return 0;
502 } 502 }
503 503
504 } // namespace 504 } // namespace
OLDNEW
« no previous file with comments | « ipc/ipc_channel_posix.cc ('k') | ipc/ipc_channel_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698