| 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 <errno.h> | 9 #include <errno.h> |
| 10 #include <fcntl.h> | 10 #include <fcntl.h> |
| 11 #include <stddef.h> | 11 #include <stddef.h> |
| 12 #include <stdint.h> | 12 #include <stdint.h> |
| 13 #include <string.h> | 13 #include <string.h> |
| 14 #include <sys/socket.h> | 14 #include <sys/socket.h> |
| 15 #include <sys/un.h> | 15 #include <sys/un.h> |
| 16 #include <unistd.h> | 16 #include <unistd.h> |
| 17 | 17 |
| 18 #include <memory> | 18 #include <memory> |
| 19 | 19 |
| 20 #include "base/files/file_path.h" | 20 #include "base/files/file_path.h" |
| 21 #include "base/files/file_util.h" | 21 #include "base/files/file_util.h" |
| 22 #include "base/location.h" | 22 #include "base/location.h" |
| 23 #include "base/path_service.h" | 23 #include "base/path_service.h" |
| 24 #include "base/posix/eintr_wrapper.h" | 24 #include "base/posix/eintr_wrapper.h" |
| 25 #include "base/process/process.h" | 25 #include "base/process/process.h" |
| 26 #include "base/run_loop.h" |
| 26 #include "base/single_thread_task_runner.h" | 27 #include "base/single_thread_task_runner.h" |
| 27 #include "base/test/multiprocess_test.h" | 28 #include "base/test/multiprocess_test.h" |
| 28 #include "base/test/test_timeouts.h" | 29 #include "base/test/test_timeouts.h" |
| 29 #include "build/build_config.h" | 30 #include "build/build_config.h" |
| 30 #include "ipc/ipc_listener.h" | 31 #include "ipc/ipc_listener.h" |
| 31 #include "ipc/unix_domain_socket_util.h" | 32 #include "ipc/unix_domain_socket_util.h" |
| 32 #include "testing/multiprocess_func_list.h" | 33 #include "testing/multiprocess_func_list.h" |
| 33 | 34 |
| 34 namespace { | 35 namespace { |
| 35 | 36 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 } | 171 } |
| 171 | 172 |
| 172 void IPCChannelPosixTest::SpinRunLoop(base::TimeDelta delay) { | 173 void IPCChannelPosixTest::SpinRunLoop(base::TimeDelta delay) { |
| 173 base::MessageLoopForIO* loop = base::MessageLoopForIO::current(); | 174 base::MessageLoopForIO* loop = base::MessageLoopForIO::current(); |
| 174 // Post a quit task so that this loop eventually ends and we don't hang | 175 // Post a quit task so that this loop eventually ends and we don't hang |
| 175 // in the case of a bad test. Usually, the run loop will quit sooner than | 176 // in the case of a bad test. Usually, the run loop will quit sooner than |
| 176 // that because all tests use a IPCChannelPosixTestListener which quits the | 177 // that because all tests use a IPCChannelPosixTestListener which quits the |
| 177 // current run loop on any channel activity. | 178 // current run loop on any channel activity. |
| 178 loop->task_runner()->PostDelayedTask(FROM_HERE, loop->QuitWhenIdleClosure(), | 179 loop->task_runner()->PostDelayedTask(FROM_HERE, loop->QuitWhenIdleClosure(), |
| 179 delay); | 180 delay); |
| 180 loop->Run(); | 181 base::RunLoop().Run(); |
| 181 } | 182 } |
| 182 | 183 |
| 183 TEST_F(IPCChannelPosixTest, BasicListen) { | 184 TEST_F(IPCChannelPosixTest, BasicListen) { |
| 184 const std::string kChannelName = | 185 const std::string kChannelName = |
| 185 GetChannelDirName() + "/IPCChannelPosixTest_BasicListen"; | 186 GetChannelDirName() + "/IPCChannelPosixTest_BasicListen"; |
| 186 | 187 |
| 187 // Test creating a socket that is listening. | 188 // Test creating a socket that is listening. |
| 188 IPC::ChannelHandle handle(kChannelName); | 189 IPC::ChannelHandle handle(kChannelName); |
| 189 SetUpSocket(&handle, IPC::Channel::MODE_NAMED_SERVER); | 190 SetUpSocket(&handle, IPC::Channel::MODE_NAMED_SERVER); |
| 190 unlink(handle.name.c_str()); | 191 unlink(handle.name.c_str()); |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 if (connected) { | 467 if (connected) { |
| 467 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); | 468 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); |
| 468 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); | 469 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); |
| 469 } else { | 470 } else { |
| 470 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); | 471 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); |
| 471 } | 472 } |
| 472 return 0; | 473 return 0; |
| 473 } | 474 } |
| 474 | 475 |
| 475 } // namespace | 476 } // namespace |
| OLD | NEW |