| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 static void SpinRunLoop(int milliseconds); | 100 static void SpinRunLoop(int milliseconds); |
| 101 | 101 |
| 102 protected: | 102 protected: |
| 103 virtual void SetUp(); | 103 virtual void SetUp(); |
| 104 virtual void TearDown(); | 104 virtual void TearDown(); |
| 105 | 105 |
| 106 private: | 106 private: |
| 107 scoped_ptr<MessageLoopForIO> message_loop_; | 107 scoped_ptr<MessageLoopForIO> message_loop_; |
| 108 }; | 108 }; |
| 109 | 109 |
| 110 #if defined(OS_ANDROID) |
| 111 const char IPCChannelPosixTest::kConnectionSocketTestName[] = |
| 112 "/data/local/chrome_IPCChannelPosixTest__ConnectionSocket"; |
| 113 #else |
| 110 const char IPCChannelPosixTest::kConnectionSocketTestName[] = | 114 const char IPCChannelPosixTest::kConnectionSocketTestName[] = |
| 111 "/var/tmp/chrome_IPCChannelPosixTest__ConnectionSocket"; | 115 "/var/tmp/chrome_IPCChannelPosixTest__ConnectionSocket"; |
| 116 #endif |
| 112 | 117 |
| 113 void IPCChannelPosixTest::SetUp() { | 118 void IPCChannelPosixTest::SetUp() { |
| 114 MultiProcessTest::SetUp(); | 119 MultiProcessTest::SetUp(); |
| 115 // Construct a fresh IO Message loop for the duration of each test. | 120 // Construct a fresh IO Message loop for the duration of each test. |
| 116 message_loop_.reset(new MessageLoopForIO()); | 121 message_loop_.reset(new MessageLoopForIO()); |
| 117 } | 122 } |
| 118 | 123 |
| 119 void IPCChannelPosixTest::TearDown() { | 124 void IPCChannelPosixTest::TearDown() { |
| 120 message_loop_.reset(NULL); | 125 message_loop_.reset(NULL); |
| 121 MultiProcessTest::TearDown(); | 126 MultiProcessTest::TearDown(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 MessageLoopForIO *loop = MessageLoopForIO::current(); | 175 MessageLoopForIO *loop = MessageLoopForIO::current(); |
| 171 // Post a quit task so that this loop eventually ends and we don't hang | 176 // Post a quit task so that this loop eventually ends and we don't hang |
| 172 // in the case of a bad test. Usually, the run loop will quit sooner than | 177 // in the case of a bad test. Usually, the run loop will quit sooner than |
| 173 // that because all tests use a IPCChannelPosixTestListener which quits the | 178 // that because all tests use a IPCChannelPosixTestListener which quits the |
| 174 // current run loop on any channel activity. | 179 // current run loop on any channel activity. |
| 175 loop->PostDelayedTask(FROM_HERE, new MessageLoop::QuitTask(), milliseconds); | 180 loop->PostDelayedTask(FROM_HERE, new MessageLoop::QuitTask(), milliseconds); |
| 176 loop->Run(); | 181 loop->Run(); |
| 177 } | 182 } |
| 178 | 183 |
| 179 TEST_F(IPCChannelPosixTest, BasicListen) { | 184 TEST_F(IPCChannelPosixTest, BasicListen) { |
| 185 |
| 186 #if defined(OS_ANDROID) |
| 187 const char* kChannelName = "/data/local/IPCChannelPosixTest_BasicListen"; |
| 188 #else |
| 189 const char* kChannelName = "/var/tmp/IPCChannelPosixTest_BasicListen"; |
| 190 #endif |
| 180 // Test creating a socket that is listening. | 191 // Test creating a socket that is listening. |
| 181 IPC::ChannelHandle handle("/var/tmp/IPCChannelPosixTest_BasicListen"); | 192 IPC::ChannelHandle handle(kChannelName); |
| 182 SetUpSocket(&handle, IPC::Channel::MODE_NAMED_SERVER); | 193 SetUpSocket(&handle, IPC::Channel::MODE_NAMED_SERVER); |
| 183 unlink(handle.name.c_str()); | 194 unlink(handle.name.c_str()); |
| 184 IPC::Channel channel(handle, IPC::Channel::MODE_NAMED_SERVER, NULL); | 195 IPC::Channel channel(handle, IPC::Channel::MODE_NAMED_SERVER, NULL); |
| 185 ASSERT_TRUE(channel.Connect()); | 196 ASSERT_TRUE(channel.Connect()); |
| 186 ASSERT_TRUE(channel.AcceptsConnections()); | 197 ASSERT_TRUE(channel.AcceptsConnections()); |
| 187 ASSERT_FALSE(channel.HasAcceptedConnection()); | 198 ASSERT_FALSE(channel.HasAcceptedConnection()); |
| 188 channel.ResetToAcceptingConnectionState(); | 199 channel.ResetToAcceptingConnectionState(); |
| 189 ASSERT_FALSE(channel.HasAcceptedConnection()); | 200 ASSERT_FALSE(channel.HasAcceptedConnection()); |
| 190 } | 201 } |
| 191 | 202 |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 // it. | 408 // it. |
| 398 bool connected = channel.Connect(); | 409 bool connected = channel.Connect(); |
| 399 if (connected) { | 410 if (connected) { |
| 400 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout_ms()); | 411 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout_ms()); |
| 401 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); | 412 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); |
| 402 } else { | 413 } else { |
| 403 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); | 414 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); |
| 404 } | 415 } |
| 405 return 0; | 416 return 0; |
| 406 } | 417 } |
| 407 | |
| OLD | NEW |