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/files/file_path.h" | 15 #include "base/files/file_path.h" |
16 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/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/process/kill.h" | 21 #include "base/process/process.h" |
22 #include "base/test/multiprocess_test.h" | 22 #include "base/test/multiprocess_test.h" |
23 #include "base/test/test_timeouts.h" | 23 #include "base/test/test_timeouts.h" |
24 #include "ipc/ipc_listener.h" | 24 #include "ipc/ipc_listener.h" |
25 #include "ipc/unix_domain_socket_util.h" | 25 #include "ipc/unix_domain_socket_util.h" |
26 #include "testing/multiprocess_func_list.h" | 26 #include "testing/multiprocess_func_list.h" |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 static const uint32 kQuitMessage = 47; | 30 static const uint32 kQuitMessage = 47; |
31 | 31 |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 base::Process process2 = SpawnChild("IPCChannelPosixTestConnectionProc"); | 332 base::Process process2 = SpawnChild("IPCChannelPosixTestConnectionProc"); |
333 ASSERT_TRUE(process2.IsValid()); | 333 ASSERT_TRUE(process2.IsValid()); |
334 SpinRunLoop(TestTimeouts::action_max_timeout()); | 334 SpinRunLoop(TestTimeouts::action_max_timeout()); |
335 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); | 335 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); |
336 ASSERT_TRUE(channel->HasAcceptedConnection()); | 336 ASSERT_TRUE(channel->HasAcceptedConnection()); |
337 IPC::Message* message = new IPC::Message(0, // routing_id | 337 IPC::Message* message = new IPC::Message(0, // routing_id |
338 kQuitMessage, // message type | 338 kQuitMessage, // message type |
339 IPC::Message::PRIORITY_NORMAL); | 339 IPC::Message::PRIORITY_NORMAL); |
340 channel->Send(message); | 340 channel->Send(message); |
341 SpinRunLoop(TestTimeouts::action_timeout()); | 341 SpinRunLoop(TestTimeouts::action_timeout()); |
342 EXPECT_TRUE(base::KillProcess(process.Handle(), 0, false)); | 342 EXPECT_TRUE(process.Terminate(0, false)); |
343 int exit_code = 0; | 343 int exit_code = 0; |
344 EXPECT_TRUE(process2.WaitForExit(&exit_code)); | 344 EXPECT_TRUE(process2.WaitForExit(&exit_code)); |
345 EXPECT_EQ(0, exit_code); | 345 EXPECT_EQ(0, exit_code); |
346 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); | 346 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); |
347 ASSERT_FALSE(channel->HasAcceptedConnection()); | 347 ASSERT_FALSE(channel->HasAcceptedConnection()); |
348 unlink(chan_handle.name.c_str()); | 348 unlink(chan_handle.name.c_str()); |
349 } | 349 } |
350 | 350 |
351 TEST_F(IPCChannelPosixTest, BadChannelName) { | 351 TEST_F(IPCChannelPosixTest, BadChannelName) { |
352 // Test empty name | 352 // Test empty name |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 if (connected) { | 478 if (connected) { |
479 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); | 479 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); |
480 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); | 480 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); |
481 } else { | 481 } else { |
482 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); | 482 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); |
483 } | 483 } |
484 return 0; | 484 return 0; |
485 } | 485 } |
486 | 486 |
487 } // namespace | 487 } // namespace |
OLD | NEW |