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/location.h" |
17 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.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/process.h" | 21 #include "base/process/process.h" |
| 22 #include "base/single_thread_task_runner.h" |
22 #include "base/test/multiprocess_test.h" | 23 #include "base/test/multiprocess_test.h" |
23 #include "base/test/test_timeouts.h" | 24 #include "base/test/test_timeouts.h" |
24 #include "ipc/ipc_listener.h" | 25 #include "ipc/ipc_listener.h" |
25 #include "ipc/unix_domain_socket_util.h" | 26 #include "ipc/unix_domain_socket_util.h" |
26 #include "testing/multiprocess_func_list.h" | 27 #include "testing/multiprocess_func_list.h" |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 static const uint32 kQuitMessage = 47; | 31 static const uint32 kQuitMessage = 47; |
31 | 32 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 } | 82 } |
82 | 83 |
83 STATUS status() { return status_; } | 84 STATUS status() { return status_; } |
84 | 85 |
85 void QuitRunLoop() { | 86 void QuitRunLoop() { |
86 base::MessageLoopForIO* loop = base::MessageLoopForIO::current(); | 87 base::MessageLoopForIO* loop = base::MessageLoopForIO::current(); |
87 if (loop->is_running()) { | 88 if (loop->is_running()) { |
88 loop->QuitNow(); | 89 loop->QuitNow(); |
89 } else { | 90 } else { |
90 // Die as soon as Run is called. | 91 // Die as soon as Run is called. |
91 loop->PostTask(FROM_HERE, loop->QuitClosure()); | 92 loop->task_runner()->PostTask(FROM_HERE, loop->QuitClosure()); |
92 } | 93 } |
93 } | 94 } |
94 | 95 |
95 private: | 96 private: |
96 // The current status of the listener. | 97 // The current status of the listener. |
97 STATUS status_; | 98 STATUS status_; |
98 // If |quit_only_on_message_| then the listener will only break out of | 99 // If |quit_only_on_message_| then the listener will only break out of |
99 // the run loop when kQuitMessage is received. | 100 // the run loop when kQuitMessage is received. |
100 bool quit_only_on_message_; | 101 bool quit_only_on_message_; |
101 }; | 102 }; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 } | 182 } |
182 handle->socket.fd = socket_fd; | 183 handle->socket.fd = socket_fd; |
183 } | 184 } |
184 | 185 |
185 void IPCChannelPosixTest::SpinRunLoop(base::TimeDelta delay) { | 186 void IPCChannelPosixTest::SpinRunLoop(base::TimeDelta delay) { |
186 base::MessageLoopForIO* loop = base::MessageLoopForIO::current(); | 187 base::MessageLoopForIO* loop = base::MessageLoopForIO::current(); |
187 // Post a quit task so that this loop eventually ends and we don't hang | 188 // Post a quit task so that this loop eventually ends and we don't hang |
188 // in the case of a bad test. Usually, the run loop will quit sooner than | 189 // in the case of a bad test. Usually, the run loop will quit sooner than |
189 // that because all tests use a IPCChannelPosixTestListener which quits the | 190 // that because all tests use a IPCChannelPosixTestListener which quits the |
190 // current run loop on any channel activity. | 191 // current run loop on any channel activity. |
191 loop->PostDelayedTask(FROM_HERE, loop->QuitClosure(), delay); | 192 loop->task_runner()->PostDelayedTask(FROM_HERE, loop->QuitClosure(), delay); |
192 loop->Run(); | 193 loop->Run(); |
193 } | 194 } |
194 | 195 |
195 TEST_F(IPCChannelPosixTest, BasicListen) { | 196 TEST_F(IPCChannelPosixTest, BasicListen) { |
196 const std::string kChannelName = | 197 const std::string kChannelName = |
197 GetChannelDirName() + "/IPCChannelPosixTest_BasicListen"; | 198 GetChannelDirName() + "/IPCChannelPosixTest_BasicListen"; |
198 | 199 |
199 // Test creating a socket that is listening. | 200 // Test creating a socket that is listening. |
200 IPC::ChannelHandle handle(kChannelName); | 201 IPC::ChannelHandle handle(kChannelName); |
201 SetUpSocket(&handle, IPC::Channel::MODE_NAMED_SERVER); | 202 SetUpSocket(&handle, IPC::Channel::MODE_NAMED_SERVER); |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 if (connected) { | 479 if (connected) { |
479 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); | 480 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); |
480 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); | 481 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); |
481 } else { | 482 } else { |
482 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); | 483 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); |
483 } | 484 } |
484 return 0; | 485 return 0; |
485 } | 486 } |
486 | 487 |
487 } // namespace | 488 } // namespace |
OLD | NEW |