| 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 <stdint.h> | 10 #include <stdint.h> |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 } | 82 } |
| 83 | 83 |
| 84 STATUS status() { return status_; } | 84 STATUS status() { return status_; } |
| 85 | 85 |
| 86 void QuitRunLoop() { | 86 void QuitRunLoop() { |
| 87 base::MessageLoopForIO* loop = base::MessageLoopForIO::current(); | 87 base::MessageLoopForIO* loop = base::MessageLoopForIO::current(); |
| 88 if (loop->is_running()) { | 88 if (loop->is_running()) { |
| 89 loop->QuitNow(); | 89 loop->QuitNow(); |
| 90 } else { | 90 } else { |
| 91 // Die as soon as Run is called. | 91 // Die as soon as Run is called. |
| 92 loop->task_runner()->PostTask(FROM_HERE, loop->QuitClosure()); | 92 loop->task_runner()->PostTask(FROM_HERE, loop->QuitWhenIdleClosure()); |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 | 95 |
| 96 private: | 96 private: |
| 97 // The current status of the listener. | 97 // The current status of the listener. |
| 98 STATUS status_; | 98 STATUS status_; |
| 99 // 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 |
| 100 // the run loop when kQuitMessage is received. | 100 // the run loop when kQuitMessage is received. |
| 101 bool quit_only_on_message_; | 101 bool quit_only_on_message_; |
| 102 }; | 102 }; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 } | 182 } |
| 183 handle->socket.fd = socket_fd; | 183 handle->socket.fd = socket_fd; |
| 184 } | 184 } |
| 185 | 185 |
| 186 void IPCChannelPosixTest::SpinRunLoop(base::TimeDelta delay) { | 186 void IPCChannelPosixTest::SpinRunLoop(base::TimeDelta delay) { |
| 187 base::MessageLoopForIO* loop = base::MessageLoopForIO::current(); | 187 base::MessageLoopForIO* loop = base::MessageLoopForIO::current(); |
| 188 // 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 |
| 189 // 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 |
| 190 // that because all tests use a IPCChannelPosixTestListener which quits the | 190 // that because all tests use a IPCChannelPosixTestListener which quits the |
| 191 // current run loop on any channel activity. | 191 // current run loop on any channel activity. |
| 192 loop->task_runner()->PostDelayedTask(FROM_HERE, loop->QuitClosure(), delay); | 192 loop->task_runner()->PostDelayedTask(FROM_HERE, loop->QuitWhenIdleClosure(), |
| 193 delay); |
| 193 loop->Run(); | 194 loop->Run(); |
| 194 } | 195 } |
| 195 | 196 |
| 196 TEST_F(IPCChannelPosixTest, BasicListen) { | 197 TEST_F(IPCChannelPosixTest, BasicListen) { |
| 197 const std::string kChannelName = | 198 const std::string kChannelName = |
| 198 GetChannelDirName() + "/IPCChannelPosixTest_BasicListen"; | 199 GetChannelDirName() + "/IPCChannelPosixTest_BasicListen"; |
| 199 | 200 |
| 200 // Test creating a socket that is listening. | 201 // Test creating a socket that is listening. |
| 201 IPC::ChannelHandle handle(kChannelName); | 202 IPC::ChannelHandle handle(kChannelName); |
| 202 SetUpSocket(&handle, IPC::Channel::MODE_NAMED_SERVER); | 203 SetUpSocket(&handle, IPC::Channel::MODE_NAMED_SERVER); |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 if (connected) { | 495 if (connected) { |
| 495 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); | 496 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); |
| 496 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); | 497 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); |
| 497 } else { | 498 } else { |
| 498 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); | 499 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); |
| 499 } | 500 } |
| 500 return 0; | 501 return 0; |
| 501 } | 502 } |
| 502 | 503 |
| 503 } // namespace | 504 } // namespace |
| OLD | NEW |