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> |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 195 |
196 TEST_F(IPCChannelPosixTest, BasicListen) { | 196 TEST_F(IPCChannelPosixTest, BasicListen) { |
197 const std::string kChannelName = | 197 const std::string kChannelName = |
198 GetChannelDirName() + "/IPCChannelPosixTest_BasicListen"; | 198 GetChannelDirName() + "/IPCChannelPosixTest_BasicListen"; |
199 | 199 |
200 // Test creating a socket that is listening. | 200 // Test creating a socket that is listening. |
201 IPC::ChannelHandle handle(kChannelName); | 201 IPC::ChannelHandle handle(kChannelName); |
202 SetUpSocket(&handle, IPC::Channel::MODE_NAMED_SERVER); | 202 SetUpSocket(&handle, IPC::Channel::MODE_NAMED_SERVER); |
203 unlink(handle.name.c_str()); | 203 unlink(handle.name.c_str()); |
204 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( | 204 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( |
205 handle, IPC::Channel::MODE_NAMED_SERVER, NULL, nullptr)); | 205 handle, IPC::Channel::MODE_NAMED_SERVER, NULL)); |
206 ASSERT_TRUE(channel->Connect()); | 206 ASSERT_TRUE(channel->Connect()); |
207 ASSERT_TRUE(channel->AcceptsConnections()); | 207 ASSERT_TRUE(channel->AcceptsConnections()); |
208 ASSERT_FALSE(channel->HasAcceptedConnection()); | 208 ASSERT_FALSE(channel->HasAcceptedConnection()); |
209 channel->ResetToAcceptingConnectionState(); | 209 channel->ResetToAcceptingConnectionState(); |
210 ASSERT_FALSE(channel->HasAcceptedConnection()); | 210 ASSERT_FALSE(channel->HasAcceptedConnection()); |
211 unlink(handle.name.c_str()); | 211 unlink(handle.name.c_str()); |
212 } | 212 } |
213 | 213 |
214 TEST_F(IPCChannelPosixTest, BasicConnected) { | 214 TEST_F(IPCChannelPosixTest, BasicConnected) { |
215 // Test creating a socket that is connected. | 215 // Test creating a socket that is connected. |
216 int pipe_fds[2]; | 216 int pipe_fds[2]; |
217 ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, pipe_fds)); | 217 ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, pipe_fds)); |
218 std::string socket_name("/var/tmp/IPCChannelPosixTest_BasicConnected"); | 218 std::string socket_name("/var/tmp/IPCChannelPosixTest_BasicConnected"); |
219 ASSERT_GE(fcntl(pipe_fds[0], F_SETFL, O_NONBLOCK), 0); | 219 ASSERT_GE(fcntl(pipe_fds[0], F_SETFL, O_NONBLOCK), 0); |
220 | 220 |
221 base::FileDescriptor fd(pipe_fds[0], false); | 221 base::FileDescriptor fd(pipe_fds[0], false); |
222 IPC::ChannelHandle handle(socket_name, fd); | 222 IPC::ChannelHandle handle(socket_name, fd); |
223 scoped_ptr<IPC::ChannelPosix> channel( | 223 scoped_ptr<IPC::ChannelPosix> channel( |
224 new IPC::ChannelPosix(handle, IPC::Channel::MODE_SERVER, NULL, nullptr)); | 224 new IPC::ChannelPosix(handle, IPC::Channel::MODE_SERVER, NULL)); |
225 ASSERT_TRUE(channel->Connect()); | 225 ASSERT_TRUE(channel->Connect()); |
226 ASSERT_FALSE(channel->AcceptsConnections()); | 226 ASSERT_FALSE(channel->AcceptsConnections()); |
227 channel->Close(); | 227 channel->Close(); |
228 ASSERT_TRUE(IGNORE_EINTR(close(pipe_fds[1])) == 0); | 228 ASSERT_TRUE(IGNORE_EINTR(close(pipe_fds[1])) == 0); |
229 | 229 |
230 // Make sure that we can use the socket that is created for us by | 230 // Make sure that we can use the socket that is created for us by |
231 // a standard channel. | 231 // a standard channel. |
232 scoped_ptr<IPC::ChannelPosix> channel2(new IPC::ChannelPosix( | 232 scoped_ptr<IPC::ChannelPosix> channel2(new IPC::ChannelPosix( |
233 socket_name, IPC::Channel::MODE_SERVER, NULL, nullptr)); | 233 socket_name, IPC::Channel::MODE_SERVER, NULL)); |
234 ASSERT_TRUE(channel2->Connect()); | 234 ASSERT_TRUE(channel2->Connect()); |
235 ASSERT_FALSE(channel2->AcceptsConnections()); | 235 ASSERT_FALSE(channel2->AcceptsConnections()); |
236 } | 236 } |
237 | 237 |
238 // If a connection closes right before a Send() call, we may end up closing | 238 // If a connection closes right before a Send() call, we may end up closing |
239 // the connection without notifying the listener, which can cause hangs in | 239 // the connection without notifying the listener, which can cause hangs in |
240 // sync_message_filter and others. Make sure the listener is notified. | 240 // sync_message_filter and others. Make sure the listener is notified. |
241 TEST_F(IPCChannelPosixTest, SendHangTest) { | 241 TEST_F(IPCChannelPosixTest, SendHangTest) { |
242 IPCChannelPosixTestListener out_listener(true); | 242 IPCChannelPosixTestListener out_listener(true); |
243 IPCChannelPosixTestListener in_listener(true); | 243 IPCChannelPosixTestListener in_listener(true); |
244 IPC::ChannelHandle in_handle("IN"); | 244 IPC::ChannelHandle in_handle("IN"); |
245 scoped_ptr<IPC::ChannelPosix> in_chan(new IPC::ChannelPosix( | 245 scoped_ptr<IPC::ChannelPosix> in_chan(new IPC::ChannelPosix( |
246 in_handle, IPC::Channel::MODE_SERVER, &in_listener, nullptr)); | 246 in_handle, IPC::Channel::MODE_SERVER, &in_listener)); |
247 IPC::ChannelHandle out_handle( | 247 IPC::ChannelHandle out_handle( |
248 "OUT", base::FileDescriptor(in_chan->TakeClientFileDescriptor())); | 248 "OUT", base::FileDescriptor(in_chan->TakeClientFileDescriptor())); |
249 scoped_ptr<IPC::ChannelPosix> out_chan(new IPC::ChannelPosix( | 249 scoped_ptr<IPC::ChannelPosix> out_chan(new IPC::ChannelPosix( |
250 out_handle, IPC::Channel::MODE_CLIENT, &out_listener, nullptr)); | 250 out_handle, IPC::Channel::MODE_CLIENT, &out_listener)); |
251 ASSERT_TRUE(in_chan->Connect()); | 251 ASSERT_TRUE(in_chan->Connect()); |
252 ASSERT_TRUE(out_chan->Connect()); | 252 ASSERT_TRUE(out_chan->Connect()); |
253 in_chan->Close(); // simulate remote process dying at an unfortunate time. | 253 in_chan->Close(); // simulate remote process dying at an unfortunate time. |
254 // Send will fail, because it cannot write the message. | 254 // Send will fail, because it cannot write the message. |
255 ASSERT_FALSE(out_chan->Send(new IPC::Message( | 255 ASSERT_FALSE(out_chan->Send(new IPC::Message( |
256 0, // routing_id | 256 0, // routing_id |
257 kQuitMessage, // message type | 257 kQuitMessage, // message type |
258 IPC::Message::PRIORITY_NORMAL))); | 258 IPC::Message::PRIORITY_NORMAL))); |
259 SpinRunLoop(TestTimeouts::action_max_timeout()); | 259 SpinRunLoop(TestTimeouts::action_max_timeout()); |
260 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, out_listener.status()); | 260 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, out_listener.status()); |
261 } | 261 } |
262 | 262 |
263 // If a connection closes right before a Connect() call, we may end up closing | 263 // If a connection closes right before a Connect() call, we may end up closing |
264 // the connection without notifying the listener, which can cause hangs in | 264 // the connection without notifying the listener, which can cause hangs in |
265 // sync_message_filter and others. Make sure the listener is notified. | 265 // sync_message_filter and others. Make sure the listener is notified. |
266 TEST_F(IPCChannelPosixTest, AcceptHangTest) { | 266 TEST_F(IPCChannelPosixTest, AcceptHangTest) { |
267 IPCChannelPosixTestListener out_listener(true); | 267 IPCChannelPosixTestListener out_listener(true); |
268 IPCChannelPosixTestListener in_listener(true); | 268 IPCChannelPosixTestListener in_listener(true); |
269 IPC::ChannelHandle in_handle("IN"); | 269 IPC::ChannelHandle in_handle("IN"); |
270 scoped_ptr<IPC::ChannelPosix> in_chan(new IPC::ChannelPosix( | 270 scoped_ptr<IPC::ChannelPosix> in_chan(new IPC::ChannelPosix( |
271 in_handle, IPC::Channel::MODE_SERVER, &in_listener, nullptr)); | 271 in_handle, IPC::Channel::MODE_SERVER, &in_listener)); |
272 IPC::ChannelHandle out_handle( | 272 IPC::ChannelHandle out_handle( |
273 "OUT", base::FileDescriptor(in_chan->TakeClientFileDescriptor())); | 273 "OUT", base::FileDescriptor(in_chan->TakeClientFileDescriptor())); |
274 scoped_ptr<IPC::ChannelPosix> out_chan(new IPC::ChannelPosix( | 274 scoped_ptr<IPC::ChannelPosix> out_chan(new IPC::ChannelPosix( |
275 out_handle, IPC::Channel::MODE_CLIENT, &out_listener, nullptr)); | 275 out_handle, IPC::Channel::MODE_CLIENT, &out_listener)); |
276 ASSERT_TRUE(in_chan->Connect()); | 276 ASSERT_TRUE(in_chan->Connect()); |
277 in_chan->Close(); // simulate remote process dying at an unfortunate time. | 277 in_chan->Close(); // simulate remote process dying at an unfortunate time. |
278 ASSERT_FALSE(out_chan->Connect()); | 278 ASSERT_FALSE(out_chan->Connect()); |
279 SpinRunLoop(TestTimeouts::action_max_timeout()); | 279 SpinRunLoop(TestTimeouts::action_max_timeout()); |
280 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, out_listener.status()); | 280 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, out_listener.status()); |
281 } | 281 } |
282 | 282 |
283 #if defined(OS_ANDROID) | 283 #if defined(OS_ANDROID) |
284 #define MAYBE_AdvancedConnected DISABLED_AdvancedConnected | 284 #define MAYBE_AdvancedConnected DISABLED_AdvancedConnected |
285 #else | 285 #else |
286 #define MAYBE_AdvancedConnected AdvancedConnected | 286 #define MAYBE_AdvancedConnected AdvancedConnected |
287 #endif | 287 #endif |
288 TEST_F(IPCChannelPosixTest, MAYBE_AdvancedConnected) { | 288 TEST_F(IPCChannelPosixTest, MAYBE_AdvancedConnected) { |
289 // Test creating a connection to an external process. | 289 // Test creating a connection to an external process. |
290 IPCChannelPosixTestListener listener(false); | 290 IPCChannelPosixTestListener listener(false); |
291 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); | 291 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); |
292 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER); | 292 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER); |
293 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( | 293 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( |
294 chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener, nullptr)); | 294 chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener)); |
295 ASSERT_TRUE(channel->Connect()); | 295 ASSERT_TRUE(channel->Connect()); |
296 ASSERT_TRUE(channel->AcceptsConnections()); | 296 ASSERT_TRUE(channel->AcceptsConnections()); |
297 ASSERT_FALSE(channel->HasAcceptedConnection()); | 297 ASSERT_FALSE(channel->HasAcceptedConnection()); |
298 | 298 |
299 base::Process process = SpawnChild("IPCChannelPosixTestConnectionProc"); | 299 base::Process process = SpawnChild("IPCChannelPosixTestConnectionProc"); |
300 ASSERT_TRUE(process.IsValid()); | 300 ASSERT_TRUE(process.IsValid()); |
301 SpinRunLoop(TestTimeouts::action_max_timeout()); | 301 SpinRunLoop(TestTimeouts::action_max_timeout()); |
302 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); | 302 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); |
303 ASSERT_TRUE(channel->HasAcceptedConnection()); | 303 ASSERT_TRUE(channel->HasAcceptedConnection()); |
304 IPC::Message* message = new IPC::Message(0, // routing_id | 304 IPC::Message* message = new IPC::Message(0, // routing_id |
(...skipping 15 matching lines...) Expand all Loading... |
320 #define MAYBE_ResetState ResetState | 320 #define MAYBE_ResetState ResetState |
321 #endif | 321 #endif |
322 TEST_F(IPCChannelPosixTest, MAYBE_ResetState) { | 322 TEST_F(IPCChannelPosixTest, MAYBE_ResetState) { |
323 // Test creating a connection to an external process. Close the connection, | 323 // Test creating a connection to an external process. Close the connection, |
324 // but continue to listen and make sure another external process can connect | 324 // but continue to listen and make sure another external process can connect |
325 // to us. | 325 // to us. |
326 IPCChannelPosixTestListener listener(false); | 326 IPCChannelPosixTestListener listener(false); |
327 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); | 327 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); |
328 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER); | 328 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER); |
329 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( | 329 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( |
330 chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener, nullptr)); | 330 chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener)); |
331 ASSERT_TRUE(channel->Connect()); | 331 ASSERT_TRUE(channel->Connect()); |
332 ASSERT_TRUE(channel->AcceptsConnections()); | 332 ASSERT_TRUE(channel->AcceptsConnections()); |
333 ASSERT_FALSE(channel->HasAcceptedConnection()); | 333 ASSERT_FALSE(channel->HasAcceptedConnection()); |
334 | 334 |
335 base::Process process = SpawnChild("IPCChannelPosixTestConnectionProc"); | 335 base::Process process = SpawnChild("IPCChannelPosixTestConnectionProc"); |
336 ASSERT_TRUE(process.IsValid()); | 336 ASSERT_TRUE(process.IsValid()); |
337 SpinRunLoop(TestTimeouts::action_max_timeout()); | 337 SpinRunLoop(TestTimeouts::action_max_timeout()); |
338 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); | 338 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); |
339 ASSERT_TRUE(channel->HasAcceptedConnection()); | 339 ASSERT_TRUE(channel->HasAcceptedConnection()); |
340 channel->ResetToAcceptingConnectionState(); | 340 channel->ResetToAcceptingConnectionState(); |
(...skipping 15 matching lines...) Expand all Loading... |
356 EXPECT_EQ(0, exit_code); | 356 EXPECT_EQ(0, exit_code); |
357 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); | 357 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); |
358 ASSERT_FALSE(channel->HasAcceptedConnection()); | 358 ASSERT_FALSE(channel->HasAcceptedConnection()); |
359 unlink(chan_handle.name.c_str()); | 359 unlink(chan_handle.name.c_str()); |
360 } | 360 } |
361 | 361 |
362 TEST_F(IPCChannelPosixTest, BadChannelName) { | 362 TEST_F(IPCChannelPosixTest, BadChannelName) { |
363 // Test empty name | 363 // Test empty name |
364 IPC::ChannelHandle handle(""); | 364 IPC::ChannelHandle handle(""); |
365 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( | 365 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( |
366 handle, IPC::Channel::MODE_NAMED_SERVER, NULL, nullptr)); | 366 handle, IPC::Channel::MODE_NAMED_SERVER, NULL)); |
367 ASSERT_FALSE(channel->Connect()); | 367 ASSERT_FALSE(channel->Connect()); |
368 | 368 |
369 // Test name that is too long. | 369 // Test name that is too long. |
370 const char *kTooLongName = "This_is_a_very_long_name_to_proactively_implement" | 370 const char *kTooLongName = "This_is_a_very_long_name_to_proactively_implement" |
371 "client-centered_synergy_through_top-line" | 371 "client-centered_synergy_through_top-line" |
372 "platforms_Phosfluorescently_disintermediate_" | 372 "platforms_Phosfluorescently_disintermediate_" |
373 "clicks-and-mortar_best_practices_without_" | 373 "clicks-and-mortar_best_practices_without_" |
374 "future-proof_growth_strategies_Continually" | 374 "future-proof_growth_strategies_Continually" |
375 "pontificate_proactive_potentialities_before" | 375 "pontificate_proactive_potentialities_before" |
376 "leading-edge_processes"; | 376 "leading-edge_processes"; |
377 EXPECT_GE(strlen(kTooLongName), IPC::kMaxSocketNameLength); | 377 EXPECT_GE(strlen(kTooLongName), IPC::kMaxSocketNameLength); |
378 IPC::ChannelHandle handle2(kTooLongName); | 378 IPC::ChannelHandle handle2(kTooLongName); |
379 scoped_ptr<IPC::ChannelPosix> channel2(new IPC::ChannelPosix( | 379 scoped_ptr<IPC::ChannelPosix> channel2(new IPC::ChannelPosix( |
380 handle2, IPC::Channel::MODE_NAMED_SERVER, NULL, nullptr)); | 380 handle2, IPC::Channel::MODE_NAMED_SERVER, NULL)); |
381 EXPECT_FALSE(channel2->Connect()); | 381 EXPECT_FALSE(channel2->Connect()); |
382 } | 382 } |
383 | 383 |
384 #if defined(OS_ANDROID) | 384 #if defined(OS_ANDROID) |
385 #define MAYBE_MultiConnection DISABLED_MultiConnection | 385 #define MAYBE_MultiConnection DISABLED_MultiConnection |
386 #else | 386 #else |
387 #define MAYBE_MultiConnection MultiConnection | 387 #define MAYBE_MultiConnection MultiConnection |
388 #endif | 388 #endif |
389 TEST_F(IPCChannelPosixTest, MAYBE_MultiConnection) { | 389 TEST_F(IPCChannelPosixTest, MAYBE_MultiConnection) { |
390 // Test setting up a connection to an external process, and then have | 390 // Test setting up a connection to an external process, and then have |
391 // another external process attempt to connect to us. | 391 // another external process attempt to connect to us. |
392 IPCChannelPosixTestListener listener(false); | 392 IPCChannelPosixTestListener listener(false); |
393 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); | 393 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); |
394 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER); | 394 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER); |
395 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( | 395 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( |
396 chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener, nullptr)); | 396 chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener)); |
397 ASSERT_TRUE(channel->Connect()); | 397 ASSERT_TRUE(channel->Connect()); |
398 ASSERT_TRUE(channel->AcceptsConnections()); | 398 ASSERT_TRUE(channel->AcceptsConnections()); |
399 ASSERT_FALSE(channel->HasAcceptedConnection()); | 399 ASSERT_FALSE(channel->HasAcceptedConnection()); |
400 | 400 |
401 base::Process process = SpawnChild("IPCChannelPosixTestConnectionProc"); | 401 base::Process process = SpawnChild("IPCChannelPosixTestConnectionProc"); |
402 ASSERT_TRUE(process.IsValid()); | 402 ASSERT_TRUE(process.IsValid()); |
403 SpinRunLoop(TestTimeouts::action_max_timeout()); | 403 SpinRunLoop(TestTimeouts::action_max_timeout()); |
404 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); | 404 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); |
405 ASSERT_TRUE(channel->HasAcceptedConnection()); | 405 ASSERT_TRUE(channel->HasAcceptedConnection()); |
406 base::Process process2 = SpawnChild("IPCChannelPosixFailConnectionProc"); | 406 base::Process process2 = SpawnChild("IPCChannelPosixFailConnectionProc"); |
(...skipping 15 matching lines...) Expand all Loading... |
422 ASSERT_FALSE(channel->HasAcceptedConnection()); | 422 ASSERT_FALSE(channel->HasAcceptedConnection()); |
423 unlink(chan_handle.name.c_str()); | 423 unlink(chan_handle.name.c_str()); |
424 } | 424 } |
425 | 425 |
426 TEST_F(IPCChannelPosixTest, DoubleServer) { | 426 TEST_F(IPCChannelPosixTest, DoubleServer) { |
427 // Test setting up two servers with the same name. | 427 // Test setting up two servers with the same name. |
428 IPCChannelPosixTestListener listener(false); | 428 IPCChannelPosixTestListener listener(false); |
429 IPCChannelPosixTestListener listener2(false); | 429 IPCChannelPosixTestListener listener2(false); |
430 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); | 430 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); |
431 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( | 431 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( |
432 chan_handle, IPC::Channel::MODE_SERVER, &listener, nullptr)); | 432 chan_handle, IPC::Channel::MODE_SERVER, &listener)); |
433 scoped_ptr<IPC::ChannelPosix> channel2(new IPC::ChannelPosix( | 433 scoped_ptr<IPC::ChannelPosix> channel2(new IPC::ChannelPosix( |
434 chan_handle, IPC::Channel::MODE_SERVER, &listener2, nullptr)); | 434 chan_handle, IPC::Channel::MODE_SERVER, &listener2)); |
435 ASSERT_TRUE(channel->Connect()); | 435 ASSERT_TRUE(channel->Connect()); |
436 ASSERT_FALSE(channel2->Connect()); | 436 ASSERT_FALSE(channel2->Connect()); |
437 } | 437 } |
438 | 438 |
439 TEST_F(IPCChannelPosixTest, BadMode) { | 439 TEST_F(IPCChannelPosixTest, BadMode) { |
440 // Test setting up two servers with a bad mode. | 440 // Test setting up two servers with a bad mode. |
441 IPCChannelPosixTestListener listener(false); | 441 IPCChannelPosixTestListener listener(false); |
442 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); | 442 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); |
443 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( | 443 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( |
444 chan_handle, IPC::Channel::MODE_NONE, &listener, nullptr)); | 444 chan_handle, IPC::Channel::MODE_NONE, &listener)); |
445 ASSERT_FALSE(channel->Connect()); | 445 ASSERT_FALSE(channel->Connect()); |
446 } | 446 } |
447 | 447 |
448 TEST_F(IPCChannelPosixTest, IsNamedServerInitialized) { | 448 TEST_F(IPCChannelPosixTest, IsNamedServerInitialized) { |
449 const std::string& connection_socket_name = GetConnectionSocketName(); | 449 const std::string& connection_socket_name = GetConnectionSocketName(); |
450 IPCChannelPosixTestListener listener(false); | 450 IPCChannelPosixTestListener listener(false); |
451 IPC::ChannelHandle chan_handle(connection_socket_name); | 451 IPC::ChannelHandle chan_handle(connection_socket_name); |
452 ASSERT_TRUE(base::DeleteFile(base::FilePath(connection_socket_name), false)); | 452 ASSERT_TRUE(base::DeleteFile(base::FilePath(connection_socket_name), false)); |
453 ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized( | 453 ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized( |
454 connection_socket_name)); | 454 connection_socket_name)); |
455 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( | 455 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( |
456 chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener, nullptr)); | 456 chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener)); |
457 ASSERT_TRUE(IPC::Channel::IsNamedServerInitialized( | 457 ASSERT_TRUE(IPC::Channel::IsNamedServerInitialized( |
458 connection_socket_name)); | 458 connection_socket_name)); |
459 channel->Close(); | 459 channel->Close(); |
460 ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized( | 460 ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized( |
461 connection_socket_name)); | 461 connection_socket_name)); |
462 unlink(chan_handle.name.c_str()); | 462 unlink(chan_handle.name.c_str()); |
463 } | 463 } |
464 | 464 |
465 // A long running process that connects to us | 465 // A long running process that connects to us |
466 MULTIPROCESS_TEST_MAIN(IPCChannelPosixTestConnectionProc) { | 466 MULTIPROCESS_TEST_MAIN(IPCChannelPosixTestConnectionProc) { |
467 base::MessageLoopForIO message_loop; | 467 base::MessageLoopForIO message_loop; |
468 IPCChannelPosixTestListener listener(true); | 468 IPCChannelPosixTestListener listener(true); |
469 IPC::ChannelHandle handle(IPCChannelPosixTest::GetConnectionSocketName()); | 469 IPC::ChannelHandle handle(IPCChannelPosixTest::GetConnectionSocketName()); |
470 IPCChannelPosixTest::SetUpSocket(&handle, IPC::Channel::MODE_NAMED_CLIENT); | 470 IPCChannelPosixTest::SetUpSocket(&handle, IPC::Channel::MODE_NAMED_CLIENT); |
471 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( | 471 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( |
472 handle, IPC::Channel::MODE_NAMED_CLIENT, &listener, nullptr)); | 472 handle, IPC::Channel::MODE_NAMED_CLIENT, &listener)); |
473 EXPECT_TRUE(channel->Connect()); | 473 EXPECT_TRUE(channel->Connect()); |
474 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); | 474 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); |
475 EXPECT_EQ(IPCChannelPosixTestListener::MESSAGE_RECEIVED, listener.status()); | 475 EXPECT_EQ(IPCChannelPosixTestListener::MESSAGE_RECEIVED, listener.status()); |
476 return 0; | 476 return 0; |
477 } | 477 } |
478 | 478 |
479 // Simple external process that shouldn't be able to connect to us. | 479 // Simple external process that shouldn't be able to connect to us. |
480 MULTIPROCESS_TEST_MAIN(IPCChannelPosixFailConnectionProc) { | 480 MULTIPROCESS_TEST_MAIN(IPCChannelPosixFailConnectionProc) { |
481 base::MessageLoopForIO message_loop; | 481 base::MessageLoopForIO message_loop; |
482 IPCChannelPosixTestListener listener(false); | 482 IPCChannelPosixTestListener listener(false); |
483 IPC::ChannelHandle handle(IPCChannelPosixTest::GetConnectionSocketName()); | 483 IPC::ChannelHandle handle(IPCChannelPosixTest::GetConnectionSocketName()); |
484 IPCChannelPosixTest::SetUpSocket(&handle, IPC::Channel::MODE_NAMED_CLIENT); | 484 IPCChannelPosixTest::SetUpSocket(&handle, IPC::Channel::MODE_NAMED_CLIENT); |
485 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( | 485 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( |
486 handle, IPC::Channel::MODE_NAMED_CLIENT, &listener, nullptr)); | 486 handle, IPC::Channel::MODE_NAMED_CLIENT, &listener)); |
487 | 487 |
488 // In this case connect may succeed or fail depending on if the packet | 488 // In this case connect may succeed or fail depending on if the packet |
489 // actually gets sent at sendmsg. Since we never delay on send, we may not | 489 // actually gets sent at sendmsg. Since we never delay on send, we may not |
490 // see the error. However even if connect succeeds, eventually we will get an | 490 // see the error. However even if connect succeeds, eventually we will get an |
491 // error back since the channel will be closed when we attempt to read from | 491 // error back since the channel will be closed when we attempt to read from |
492 // it. | 492 // it. |
493 bool connected = channel->Connect(); | 493 bool connected = channel->Connect(); |
494 if (connected) { | 494 if (connected) { |
495 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); | 495 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); |
496 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); | 496 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); |
497 } else { | 497 } else { |
498 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); | 498 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); |
499 } | 499 } |
500 return 0; | 500 return 0; |
501 } | 501 } |
502 | 502 |
503 } // namespace | 503 } // namespace |
OLD | NEW |