Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(688)

Side by Side Diff: ipc/ipc_channel_posix_unittest.cc

Issue 1185133006: IPC: Make ChannelReader inherit from SupportsAttachmentBrokering. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments from tsepez. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ipc/ipc_channel_posix.cc ('k') | ipc/ipc_channel_proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 } 194 }
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( 204 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix(
205 new IPC::ChannelPosix(handle, IPC::Channel::MODE_NAMED_SERVER, NULL)); 205 handle, IPC::Channel::MODE_NAMED_SERVER, NULL, nullptr));
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(new IPC::ChannelPosix( 223 scoped_ptr<IPC::ChannelPosix> channel(
224 handle, IPC::Channel::MODE_SERVER, NULL)); 224 new IPC::ChannelPosix(handle, IPC::Channel::MODE_SERVER, NULL, nullptr));
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)); 233 socket_name, IPC::Channel::MODE_SERVER, NULL, nullptr));
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)); 246 in_handle, IPC::Channel::MODE_SERVER, &in_listener, nullptr));
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)); 250 out_handle, IPC::Channel::MODE_CLIENT, &out_listener, nullptr));
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)); 271 in_handle, IPC::Channel::MODE_SERVER, &in_listener, nullptr));
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)); 275 out_handle, IPC::Channel::MODE_CLIENT, &out_listener, nullptr));
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 TEST_F(IPCChannelPosixTest, AdvancedConnected) { 283 TEST_F(IPCChannelPosixTest, AdvancedConnected) {
284 // Test creating a connection to an external process. 284 // Test creating a connection to an external process.
285 IPCChannelPosixTestListener listener(false); 285 IPCChannelPosixTestListener listener(false);
286 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); 286 IPC::ChannelHandle chan_handle(GetConnectionSocketName());
287 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER); 287 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER);
288 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( 288 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix(
289 chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener)); 289 chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener, nullptr));
290 ASSERT_TRUE(channel->Connect()); 290 ASSERT_TRUE(channel->Connect());
291 ASSERT_TRUE(channel->AcceptsConnections()); 291 ASSERT_TRUE(channel->AcceptsConnections());
292 ASSERT_FALSE(channel->HasAcceptedConnection()); 292 ASSERT_FALSE(channel->HasAcceptedConnection());
293 293
294 base::Process process = SpawnChild("IPCChannelPosixTestConnectionProc"); 294 base::Process process = SpawnChild("IPCChannelPosixTestConnectionProc");
295 ASSERT_TRUE(process.IsValid()); 295 ASSERT_TRUE(process.IsValid());
296 SpinRunLoop(TestTimeouts::action_max_timeout()); 296 SpinRunLoop(TestTimeouts::action_max_timeout());
297 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); 297 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status());
298 ASSERT_TRUE(channel->HasAcceptedConnection()); 298 ASSERT_TRUE(channel->HasAcceptedConnection());
299 IPC::Message* message = new IPC::Message(0, // routing_id 299 IPC::Message* message = new IPC::Message(0, // routing_id
(...skipping 10 matching lines...) Expand all
310 } 310 }
311 311
312 TEST_F(IPCChannelPosixTest, ResetState) { 312 TEST_F(IPCChannelPosixTest, ResetState) {
313 // Test creating a connection to an external process. Close the connection, 313 // Test creating a connection to an external process. Close the connection,
314 // but continue to listen and make sure another external process can connect 314 // but continue to listen and make sure another external process can connect
315 // to us. 315 // to us.
316 IPCChannelPosixTestListener listener(false); 316 IPCChannelPosixTestListener listener(false);
317 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); 317 IPC::ChannelHandle chan_handle(GetConnectionSocketName());
318 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER); 318 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER);
319 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( 319 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix(
320 chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener)); 320 chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener, nullptr));
321 ASSERT_TRUE(channel->Connect()); 321 ASSERT_TRUE(channel->Connect());
322 ASSERT_TRUE(channel->AcceptsConnections()); 322 ASSERT_TRUE(channel->AcceptsConnections());
323 ASSERT_FALSE(channel->HasAcceptedConnection()); 323 ASSERT_FALSE(channel->HasAcceptedConnection());
324 324
325 base::Process process = SpawnChild("IPCChannelPosixTestConnectionProc"); 325 base::Process process = SpawnChild("IPCChannelPosixTestConnectionProc");
326 ASSERT_TRUE(process.IsValid()); 326 ASSERT_TRUE(process.IsValid());
327 SpinRunLoop(TestTimeouts::action_max_timeout()); 327 SpinRunLoop(TestTimeouts::action_max_timeout());
328 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); 328 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status());
329 ASSERT_TRUE(channel->HasAcceptedConnection()); 329 ASSERT_TRUE(channel->HasAcceptedConnection());
330 channel->ResetToAcceptingConnectionState(); 330 channel->ResetToAcceptingConnectionState();
(...skipping 15 matching lines...) Expand all
346 EXPECT_EQ(0, exit_code); 346 EXPECT_EQ(0, exit_code);
347 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); 347 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status());
348 ASSERT_FALSE(channel->HasAcceptedConnection()); 348 ASSERT_FALSE(channel->HasAcceptedConnection());
349 unlink(chan_handle.name.c_str()); 349 unlink(chan_handle.name.c_str());
350 } 350 }
351 351
352 TEST_F(IPCChannelPosixTest, BadChannelName) { 352 TEST_F(IPCChannelPosixTest, BadChannelName) {
353 // Test empty name 353 // Test empty name
354 IPC::ChannelHandle handle(""); 354 IPC::ChannelHandle handle("");
355 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( 355 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix(
356 handle, IPC::Channel::MODE_NAMED_SERVER, NULL)); 356 handle, IPC::Channel::MODE_NAMED_SERVER, NULL, nullptr));
357 ASSERT_FALSE(channel->Connect()); 357 ASSERT_FALSE(channel->Connect());
358 358
359 // Test name that is too long. 359 // Test name that is too long.
360 const char *kTooLongName = "This_is_a_very_long_name_to_proactively_implement" 360 const char *kTooLongName = "This_is_a_very_long_name_to_proactively_implement"
361 "client-centered_synergy_through_top-line" 361 "client-centered_synergy_through_top-line"
362 "platforms_Phosfluorescently_disintermediate_" 362 "platforms_Phosfluorescently_disintermediate_"
363 "clicks-and-mortar_best_practices_without_" 363 "clicks-and-mortar_best_practices_without_"
364 "future-proof_growth_strategies_Continually" 364 "future-proof_growth_strategies_Continually"
365 "pontificate_proactive_potentialities_before" 365 "pontificate_proactive_potentialities_before"
366 "leading-edge_processes"; 366 "leading-edge_processes";
367 EXPECT_GE(strlen(kTooLongName), IPC::kMaxSocketNameLength); 367 EXPECT_GE(strlen(kTooLongName), IPC::kMaxSocketNameLength);
368 IPC::ChannelHandle handle2(kTooLongName); 368 IPC::ChannelHandle handle2(kTooLongName);
369 scoped_ptr<IPC::ChannelPosix> channel2(new IPC::ChannelPosix( 369 scoped_ptr<IPC::ChannelPosix> channel2(new IPC::ChannelPosix(
370 handle2, IPC::Channel::MODE_NAMED_SERVER, NULL)); 370 handle2, IPC::Channel::MODE_NAMED_SERVER, NULL, nullptr));
371 EXPECT_FALSE(channel2->Connect()); 371 EXPECT_FALSE(channel2->Connect());
372 } 372 }
373 373
374 TEST_F(IPCChannelPosixTest, MultiConnection) { 374 TEST_F(IPCChannelPosixTest, MultiConnection) {
375 // Test setting up a connection to an external process, and then have 375 // Test setting up a connection to an external process, and then have
376 // another external process attempt to connect to us. 376 // another external process attempt to connect to us.
377 IPCChannelPosixTestListener listener(false); 377 IPCChannelPosixTestListener listener(false);
378 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); 378 IPC::ChannelHandle chan_handle(GetConnectionSocketName());
379 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER); 379 SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER);
380 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( 380 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix(
381 chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener)); 381 chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener, nullptr));
382 ASSERT_TRUE(channel->Connect()); 382 ASSERT_TRUE(channel->Connect());
383 ASSERT_TRUE(channel->AcceptsConnections()); 383 ASSERT_TRUE(channel->AcceptsConnections());
384 ASSERT_FALSE(channel->HasAcceptedConnection()); 384 ASSERT_FALSE(channel->HasAcceptedConnection());
385 385
386 base::Process process = SpawnChild("IPCChannelPosixTestConnectionProc"); 386 base::Process process = SpawnChild("IPCChannelPosixTestConnectionProc");
387 ASSERT_TRUE(process.IsValid()); 387 ASSERT_TRUE(process.IsValid());
388 SpinRunLoop(TestTimeouts::action_max_timeout()); 388 SpinRunLoop(TestTimeouts::action_max_timeout());
389 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); 389 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status());
390 ASSERT_TRUE(channel->HasAcceptedConnection()); 390 ASSERT_TRUE(channel->HasAcceptedConnection());
391 base::Process process2 = SpawnChild("IPCChannelPosixFailConnectionProc"); 391 base::Process process2 = SpawnChild("IPCChannelPosixFailConnectionProc");
(...skipping 15 matching lines...) Expand all
407 ASSERT_FALSE(channel->HasAcceptedConnection()); 407 ASSERT_FALSE(channel->HasAcceptedConnection());
408 unlink(chan_handle.name.c_str()); 408 unlink(chan_handle.name.c_str());
409 } 409 }
410 410
411 TEST_F(IPCChannelPosixTest, DoubleServer) { 411 TEST_F(IPCChannelPosixTest, DoubleServer) {
412 // Test setting up two servers with the same name. 412 // Test setting up two servers with the same name.
413 IPCChannelPosixTestListener listener(false); 413 IPCChannelPosixTestListener listener(false);
414 IPCChannelPosixTestListener listener2(false); 414 IPCChannelPosixTestListener listener2(false);
415 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); 415 IPC::ChannelHandle chan_handle(GetConnectionSocketName());
416 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( 416 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix(
417 chan_handle, IPC::Channel::MODE_SERVER, &listener)); 417 chan_handle, IPC::Channel::MODE_SERVER, &listener, nullptr));
418 scoped_ptr<IPC::ChannelPosix> channel2(new IPC::ChannelPosix( 418 scoped_ptr<IPC::ChannelPosix> channel2(new IPC::ChannelPosix(
419 chan_handle, IPC::Channel::MODE_SERVER, &listener2)); 419 chan_handle, IPC::Channel::MODE_SERVER, &listener2, nullptr));
420 ASSERT_TRUE(channel->Connect()); 420 ASSERT_TRUE(channel->Connect());
421 ASSERT_FALSE(channel2->Connect()); 421 ASSERT_FALSE(channel2->Connect());
422 } 422 }
423 423
424 TEST_F(IPCChannelPosixTest, BadMode) { 424 TEST_F(IPCChannelPosixTest, BadMode) {
425 // Test setting up two servers with a bad mode. 425 // Test setting up two servers with a bad mode.
426 IPCChannelPosixTestListener listener(false); 426 IPCChannelPosixTestListener listener(false);
427 IPC::ChannelHandle chan_handle(GetConnectionSocketName()); 427 IPC::ChannelHandle chan_handle(GetConnectionSocketName());
428 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( 428 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix(
429 chan_handle, IPC::Channel::MODE_NONE, &listener)); 429 chan_handle, IPC::Channel::MODE_NONE, &listener, nullptr));
430 ASSERT_FALSE(channel->Connect()); 430 ASSERT_FALSE(channel->Connect());
431 } 431 }
432 432
433 TEST_F(IPCChannelPosixTest, IsNamedServerInitialized) { 433 TEST_F(IPCChannelPosixTest, IsNamedServerInitialized) {
434 const std::string& connection_socket_name = GetConnectionSocketName(); 434 const std::string& connection_socket_name = GetConnectionSocketName();
435 IPCChannelPosixTestListener listener(false); 435 IPCChannelPosixTestListener listener(false);
436 IPC::ChannelHandle chan_handle(connection_socket_name); 436 IPC::ChannelHandle chan_handle(connection_socket_name);
437 ASSERT_TRUE(base::DeleteFile(base::FilePath(connection_socket_name), false)); 437 ASSERT_TRUE(base::DeleteFile(base::FilePath(connection_socket_name), false));
438 ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized( 438 ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized(
439 connection_socket_name)); 439 connection_socket_name));
440 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( 440 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix(
441 chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener)); 441 chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener, nullptr));
442 ASSERT_TRUE(IPC::Channel::IsNamedServerInitialized( 442 ASSERT_TRUE(IPC::Channel::IsNamedServerInitialized(
443 connection_socket_name)); 443 connection_socket_name));
444 channel->Close(); 444 channel->Close();
445 ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized( 445 ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized(
446 connection_socket_name)); 446 connection_socket_name));
447 unlink(chan_handle.name.c_str()); 447 unlink(chan_handle.name.c_str());
448 } 448 }
449 449
450 // A long running process that connects to us 450 // A long running process that connects to us
451 MULTIPROCESS_TEST_MAIN(IPCChannelPosixTestConnectionProc) { 451 MULTIPROCESS_TEST_MAIN(IPCChannelPosixTestConnectionProc) {
452 base::MessageLoopForIO message_loop; 452 base::MessageLoopForIO message_loop;
453 IPCChannelPosixTestListener listener(true); 453 IPCChannelPosixTestListener listener(true);
454 IPC::ChannelHandle handle(IPCChannelPosixTest::GetConnectionSocketName()); 454 IPC::ChannelHandle handle(IPCChannelPosixTest::GetConnectionSocketName());
455 IPCChannelPosixTest::SetUpSocket(&handle, IPC::Channel::MODE_NAMED_CLIENT); 455 IPCChannelPosixTest::SetUpSocket(&handle, IPC::Channel::MODE_NAMED_CLIENT);
456 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( 456 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix(
457 handle, IPC::Channel::MODE_NAMED_CLIENT, &listener)); 457 handle, IPC::Channel::MODE_NAMED_CLIENT, &listener, nullptr));
458 EXPECT_TRUE(channel->Connect()); 458 EXPECT_TRUE(channel->Connect());
459 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); 459 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout());
460 EXPECT_EQ(IPCChannelPosixTestListener::MESSAGE_RECEIVED, listener.status()); 460 EXPECT_EQ(IPCChannelPosixTestListener::MESSAGE_RECEIVED, listener.status());
461 return 0; 461 return 0;
462 } 462 }
463 463
464 // 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.
465 MULTIPROCESS_TEST_MAIN(IPCChannelPosixFailConnectionProc) { 465 MULTIPROCESS_TEST_MAIN(IPCChannelPosixFailConnectionProc) {
466 base::MessageLoopForIO message_loop; 466 base::MessageLoopForIO message_loop;
467 IPCChannelPosixTestListener listener(false); 467 IPCChannelPosixTestListener listener(false);
468 IPC::ChannelHandle handle(IPCChannelPosixTest::GetConnectionSocketName()); 468 IPC::ChannelHandle handle(IPCChannelPosixTest::GetConnectionSocketName());
469 IPCChannelPosixTest::SetUpSocket(&handle, IPC::Channel::MODE_NAMED_CLIENT); 469 IPCChannelPosixTest::SetUpSocket(&handle, IPC::Channel::MODE_NAMED_CLIENT);
470 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix( 470 scoped_ptr<IPC::ChannelPosix> channel(new IPC::ChannelPosix(
471 handle, IPC::Channel::MODE_NAMED_CLIENT, &listener)); 471 handle, IPC::Channel::MODE_NAMED_CLIENT, &listener, nullptr));
472 472
473 // 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
474 // 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
475 // 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
476 // 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
477 // it. 477 // it.
478 bool connected = channel->Connect(); 478 bool connected = channel->Connect();
479 if (connected) { 479 if (connected) {
480 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); 480 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout());
481 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); 481 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status());
482 } else { 482 } else {
483 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); 483 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status());
484 } 484 }
485 return 0; 485 return 0;
486 } 486 }
487 487
488 } // namespace 488 } // namespace
OLDNEW
« no previous file with comments | « ipc/ipc_channel_posix.cc ('k') | ipc/ipc_channel_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698