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