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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 TEST_F(IPCChannelPosixTest, AdvancedConnected) { | 278 TEST_F(IPCChannelPosixTest, AdvancedConnected) { |
279 // Test creating a connection to an external process. | 279 // Test creating a connection to an external process. |
280 IPCChannelPosixTestListener listener(false); | 280 IPCChannelPosixTestListener listener(false); |
281 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); | 281 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); |
282 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER); | 282 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER); |
283 IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener); | 283 IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener); |
284 ASSERT_TRUE(channel.Connect()); | 284 ASSERT_TRUE(channel.Connect()); |
285 ASSERT_TRUE(channel.AcceptsConnections()); | 285 ASSERT_TRUE(channel.AcceptsConnections()); |
286 ASSERT_FALSE(channel.HasAcceptedConnection()); | 286 ASSERT_FALSE(channel.HasAcceptedConnection()); |
287 | 287 |
288 base::ProcessHandle handle = SpawnChild("IPCChannelPosixTestConnectionProc", | 288 base::ProcessHandle handle = SpawnChild("IPCChannelPosixTestConnectionProc"); |
289 false); | |
290 ASSERT_TRUE(handle); | 289 ASSERT_TRUE(handle); |
291 SpinRunLoop(TestTimeouts::action_max_timeout()); | 290 SpinRunLoop(TestTimeouts::action_max_timeout()); |
292 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); | 291 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); |
293 ASSERT_TRUE(channel.HasAcceptedConnection()); | 292 ASSERT_TRUE(channel.HasAcceptedConnection()); |
294 IPC::Message* message = new IPC::Message(0, // routing_id | 293 IPC::Message* message = new IPC::Message(0, // routing_id |
295 kQuitMessage, // message type | 294 kQuitMessage, // message type |
296 IPC::Message::PRIORITY_NORMAL); | 295 IPC::Message::PRIORITY_NORMAL); |
297 channel.Send(message); | 296 channel.Send(message); |
298 SpinRunLoop(TestTimeouts::action_timeout()); | 297 SpinRunLoop(TestTimeouts::action_timeout()); |
299 int exit_code = 0; | 298 int exit_code = 0; |
300 EXPECT_TRUE(base::WaitForExitCode(handle, &exit_code)); | 299 EXPECT_TRUE(base::WaitForExitCode(handle, &exit_code)); |
301 EXPECT_EQ(0, exit_code); | 300 EXPECT_EQ(0, exit_code); |
302 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); | 301 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); |
303 ASSERT_FALSE(channel.HasAcceptedConnection()); | 302 ASSERT_FALSE(channel.HasAcceptedConnection()); |
304 } | 303 } |
305 | 304 |
306 TEST_F(IPCChannelPosixTest, ResetState) { | 305 TEST_F(IPCChannelPosixTest, ResetState) { |
307 // Test creating a connection to an external process. Close the connection, | 306 // Test creating a connection to an external process. Close the connection, |
308 // but continue to listen and make sure another external process can connect | 307 // but continue to listen and make sure another external process can connect |
309 // to us. | 308 // to us. |
310 IPCChannelPosixTestListener listener(false); | 309 IPCChannelPosixTestListener listener(false); |
311 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); | 310 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); |
312 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER); | 311 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER); |
313 IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener); | 312 IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener); |
314 ASSERT_TRUE(channel.Connect()); | 313 ASSERT_TRUE(channel.Connect()); |
315 ASSERT_TRUE(channel.AcceptsConnections()); | 314 ASSERT_TRUE(channel.AcceptsConnections()); |
316 ASSERT_FALSE(channel.HasAcceptedConnection()); | 315 ASSERT_FALSE(channel.HasAcceptedConnection()); |
317 | 316 |
318 base::ProcessHandle handle = SpawnChild("IPCChannelPosixTestConnectionProc", | 317 base::ProcessHandle handle = SpawnChild("IPCChannelPosixTestConnectionProc"); |
319 false); | |
320 ASSERT_TRUE(handle); | 318 ASSERT_TRUE(handle); |
321 SpinRunLoop(TestTimeouts::action_max_timeout()); | 319 SpinRunLoop(TestTimeouts::action_max_timeout()); |
322 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); | 320 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); |
323 ASSERT_TRUE(channel.HasAcceptedConnection()); | 321 ASSERT_TRUE(channel.HasAcceptedConnection()); |
324 channel.ResetToAcceptingConnectionState(); | 322 channel.ResetToAcceptingConnectionState(); |
325 ASSERT_FALSE(channel.HasAcceptedConnection()); | 323 ASSERT_FALSE(channel.HasAcceptedConnection()); |
326 | 324 |
327 base::ProcessHandle handle2 = SpawnChild("IPCChannelPosixTestConnectionProc", | 325 base::ProcessHandle handle2 = SpawnChild("IPCChannelPosixTestConnectionProc"); |
328 false); | |
329 ASSERT_TRUE(handle2); | 326 ASSERT_TRUE(handle2); |
330 SpinRunLoop(TestTimeouts::action_max_timeout()); | 327 SpinRunLoop(TestTimeouts::action_max_timeout()); |
331 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); | 328 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); |
332 ASSERT_TRUE(channel.HasAcceptedConnection()); | 329 ASSERT_TRUE(channel.HasAcceptedConnection()); |
333 IPC::Message* message = new IPC::Message(0, // routing_id | 330 IPC::Message* message = new IPC::Message(0, // routing_id |
334 kQuitMessage, // message type | 331 kQuitMessage, // message type |
335 IPC::Message::PRIORITY_NORMAL); | 332 IPC::Message::PRIORITY_NORMAL); |
336 channel.Send(message); | 333 channel.Send(message); |
337 SpinRunLoop(TestTimeouts::action_timeout()); | 334 SpinRunLoop(TestTimeouts::action_timeout()); |
338 EXPECT_TRUE(base::KillProcess(handle, 0, false)); | 335 EXPECT_TRUE(base::KillProcess(handle, 0, false)); |
(...skipping 28 matching lines...) Expand all Loading... |
367 // Test setting up a connection to an external process, and then have | 364 // Test setting up a connection to an external process, and then have |
368 // another external process attempt to connect to us. | 365 // another external process attempt to connect to us. |
369 IPCChannelPosixTestListener listener(false); | 366 IPCChannelPosixTestListener listener(false); |
370 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); | 367 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); |
371 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER); | 368 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER); |
372 IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener); | 369 IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener); |
373 ASSERT_TRUE(channel.Connect()); | 370 ASSERT_TRUE(channel.Connect()); |
374 ASSERT_TRUE(channel.AcceptsConnections()); | 371 ASSERT_TRUE(channel.AcceptsConnections()); |
375 ASSERT_FALSE(channel.HasAcceptedConnection()); | 372 ASSERT_FALSE(channel.HasAcceptedConnection()); |
376 | 373 |
377 base::ProcessHandle handle = SpawnChild("IPCChannelPosixTestConnectionProc", | 374 base::ProcessHandle handle = SpawnChild("IPCChannelPosixTestConnectionProc"); |
378 false); | |
379 ASSERT_TRUE(handle); | 375 ASSERT_TRUE(handle); |
380 SpinRunLoop(TestTimeouts::action_max_timeout()); | 376 SpinRunLoop(TestTimeouts::action_max_timeout()); |
381 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); | 377 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); |
382 ASSERT_TRUE(channel.HasAcceptedConnection()); | 378 ASSERT_TRUE(channel.HasAcceptedConnection()); |
383 base::ProcessHandle handle2 = SpawnChild("IPCChannelPosixFailConnectionProc", | 379 base::ProcessHandle handle2 = SpawnChild("IPCChannelPosixFailConnectionProc"); |
384 false); | |
385 ASSERT_TRUE(handle2); | 380 ASSERT_TRUE(handle2); |
386 SpinRunLoop(TestTimeouts::action_max_timeout()); | 381 SpinRunLoop(TestTimeouts::action_max_timeout()); |
387 int exit_code = 0; | 382 int exit_code = 0; |
388 EXPECT_TRUE(base::WaitForExitCode(handle2, &exit_code)); | 383 EXPECT_TRUE(base::WaitForExitCode(handle2, &exit_code)); |
389 EXPECT_EQ(exit_code, 0); | 384 EXPECT_EQ(exit_code, 0); |
390 ASSERT_EQ(IPCChannelPosixTestListener::DENIED, listener.status()); | 385 ASSERT_EQ(IPCChannelPosixTestListener::DENIED, listener.status()); |
391 ASSERT_TRUE(channel.HasAcceptedConnection()); | 386 ASSERT_TRUE(channel.HasAcceptedConnection()); |
392 IPC::Message* message = new IPC::Message(0, // routing_id | 387 IPC::Message* message = new IPC::Message(0, // routing_id |
393 kQuitMessage, // message type | 388 kQuitMessage, // message type |
394 IPC::Message::PRIORITY_NORMAL); | 389 IPC::Message::PRIORITY_NORMAL); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 if (connected) { | 459 if (connected) { |
465 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); | 460 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); |
466 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); | 461 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); |
467 } else { | 462 } else { |
468 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); | 463 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); |
469 } | 464 } |
470 return 0; | 465 return 0; |
471 } | 466 } |
472 | 467 |
473 } // namespace | 468 } // namespace |
OLD | NEW |