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

Side by Side Diff: ipc/ipc_channel_posix_unittest.cc

Issue 10387218: Make GlobalDescriptors::MaybeGet return -1 when the key is not found. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Applied Jeremy's suggestions + sync. Created 8 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 | Annotate | Revision Log
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>
11 #include <sys/un.h> 11 #include <sys/un.h>
12 #include <unistd.h> 12 #include <unistd.h>
13 13
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "base/eintr_wrapper.h" 15 #include "base/eintr_wrapper.h"
16 #include "base/file_path.h" 16 #include "base/file_path.h"
17 #include "base/file_util.h" 17 #include "base/file_util.h"
18 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
19 #include "base/message_loop.h" 19 #include "base/message_loop.h"
20 #include "base/path_service.h" 20 #include "base/path_service.h"
21 #include "base/test/multiprocess_test.h" 21 #include "base/test/multiprocess_test.h"
22 #include "base/test/test_timeouts.h" 22 #include "base/test/test_timeouts.h"
23 #include "ipc/ipc_listener.h" 23 #include "ipc/ipc_listener.h"
24 #include "ipc/ipc_tests.h"
24 #include "testing/multiprocess_func_list.h" 25 #include "testing/multiprocess_func_list.h"
25 26
26 namespace { 27 namespace {
27 28
28 static const uint32 kQuitMessage = 47; 29 static const uint32 kQuitMessage = 47;
29 30
30 class IPCChannelPosixTestListener : public IPC::Listener { 31 class IPCChannelPosixTestListener : public IPC::Listener {
31 public: 32 public:
32 enum STATUS { 33 enum STATUS {
33 DISCONNECTED, 34 DISCONNECTED,
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 connection_socket_name)); 385 connection_socket_name));
385 IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener); 386 IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener);
386 ASSERT_TRUE(IPC::Channel::IsNamedServerInitialized( 387 ASSERT_TRUE(IPC::Channel::IsNamedServerInitialized(
387 connection_socket_name)); 388 connection_socket_name));
388 channel.Close(); 389 channel.Close();
389 ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized( 390 ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized(
390 connection_socket_name)); 391 connection_socket_name));
391 } 392 }
392 393
393 // A long running process that connects to us 394 // A long running process that connects to us
394 MULTIPROCESS_TEST_MAIN(IPCChannelPosixTestConnectionProc) { 395 MULTIPROCESS_IPC_TEST_MAIN(IPCChannelPosixTestConnectionProc) {
395 MessageLoopForIO message_loop; 396 MessageLoopForIO message_loop;
396 IPCChannelPosixTestListener listener(true); 397 IPCChannelPosixTestListener listener(true);
397 IPC::ChannelHandle handle(IPCChannelPosixTest::GetConnectionSocketName()); 398 IPC::ChannelHandle handle(IPCChannelPosixTest::GetConnectionSocketName());
398 IPCChannelPosixTest::SetUpSocket(&handle, IPC::Channel::MODE_NAMED_CLIENT); 399 IPCChannelPosixTest::SetUpSocket(&handle, IPC::Channel::MODE_NAMED_CLIENT);
399 IPC::Channel channel(handle, IPC::Channel::MODE_NAMED_CLIENT, &listener); 400 IPC::Channel channel(handle, IPC::Channel::MODE_NAMED_CLIENT, &listener);
400 EXPECT_TRUE(channel.Connect()); 401 EXPECT_TRUE(channel.Connect());
401 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout_ms()); 402 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout_ms());
402 EXPECT_EQ(IPCChannelPosixTestListener::MESSAGE_RECEIVED, listener.status()); 403 EXPECT_EQ(IPCChannelPosixTestListener::MESSAGE_RECEIVED, listener.status());
403 return 0; 404 return 0;
404 } 405 }
405 406
406 // Simple external process that shouldn't be able to connect to us. 407 // Simple external process that shouldn't be able to connect to us.
407 MULTIPROCESS_TEST_MAIN(IPCChannelPosixFailConnectionProc) { 408 MULTIPROCESS_IPC_TEST_MAIN(IPCChannelPosixFailConnectionProc) {
408 MessageLoopForIO message_loop; 409 MessageLoopForIO message_loop;
409 IPCChannelPosixTestListener listener(false); 410 IPCChannelPosixTestListener listener(false);
410 IPC::ChannelHandle handle(IPCChannelPosixTest::GetConnectionSocketName()); 411 IPC::ChannelHandle handle(IPCChannelPosixTest::GetConnectionSocketName());
411 IPCChannelPosixTest::SetUpSocket(&handle, IPC::Channel::MODE_NAMED_CLIENT); 412 IPCChannelPosixTest::SetUpSocket(&handle, IPC::Channel::MODE_NAMED_CLIENT);
412 IPC::Channel channel(handle, IPC::Channel::MODE_NAMED_CLIENT, &listener); 413 IPC::Channel channel(handle, IPC::Channel::MODE_NAMED_CLIENT, &listener);
413 414
414 // In this case connect may succeed or fail depending on if the packet 415 // In this case connect may succeed or fail depending on if the packet
415 // actually gets sent at sendmsg. Since we never delay on send, we may not 416 // actually gets sent at sendmsg. Since we never delay on send, we may not
416 // see the error. However even if connect succeeds, eventually we will get an 417 // see the error. However even if connect succeeds, eventually we will get an
417 // error back since the channel will be closed when we attempt to read from 418 // error back since the channel will be closed when we attempt to read from
418 // it. 419 // it.
419 bool connected = channel.Connect(); 420 bool connected = channel.Connect();
420 if (connected) { 421 if (connected) {
421 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout_ms()); 422 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout_ms());
422 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); 423 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status());
423 } else { 424 } else {
424 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); 425 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status());
425 } 426 }
426 return 0; 427 return 0;
427 } 428 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698