summaryrefslogtreecommitdiffstats
path: root/ipc/sync_socket_unittest.cc
diff options
context:
space:
mode:
authorviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-25 21:51:35 +0000
committerviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-25 21:51:35 +0000
commit3c78858906d3d0d7f5319d7c993240284b4503b5 (patch)
tree1abeaac1ec6d16e96c05ef5f534681979d1f4ef6 /ipc/sync_socket_unittest.cc
parentcdf594b2db94ff9c66d3f552a063706c16015c2b (diff)
downloadchromium_src-3c78858906d3d0d7f5319d7c993240284b4503b5.zip
chromium_src-3c78858906d3d0d7f5319d7c993240284b4503b5.tar.gz
chromium_src-3c78858906d3d0d7f5319d7c993240284b4503b5.tar.bz2
Refactor (many) IPC tests, notably most of the multiprocess tests.
This factors out common code and, more importantly/usefully, makes test-specific code more local, and thus easier to add new tests and maintain existing ones. In particular, this allows you to add a new test "client" (running in another process) without modifying ipc_test_base.*. Review URL: https://codereview.chromium.org/12051048 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@178901 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ipc/sync_socket_unittest.cc')
-rw-r--r--ipc/sync_socket_unittest.cc38
1 files changed, 18 insertions, 20 deletions
diff --git a/ipc/sync_socket_unittest.cc b/ipc/sync_socket_unittest.cc
index 4dba55d..57ba326 100644
--- a/ipc/sync_socket_unittest.cc
+++ b/ipc/sync_socket_unittest.cc
@@ -12,8 +12,6 @@
#include "base/message_loop.h"
#include "base/process_util.h"
#include "base/threading/thread.h"
-#include "ipc/ipc_channel_proxy.h"
-#include "ipc/ipc_multiprocess_test.h"
#include "ipc/ipc_test_base.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -106,14 +104,16 @@ class SyncSocketServerListener : public IPC::Listener {
DISALLOW_COPY_AND_ASSIGN(SyncSocketServerListener);
};
-// Runs the fuzzing server child mode. Returns when the preset number
-// of messages have been received.
-MULTIPROCESS_IPC_TEST_MAIN(RunSyncSocketServer) {
+// Runs the fuzzing server child mode. Returns when the preset number of
+// messages have been received.
+MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SyncSocketServerClient) {
MessageLoopForIO main_message_loop;
SyncSocketServerListener listener;
- IPC::Channel chan(kSyncSocketChannel, IPC::Channel::MODE_CLIENT, &listener);
- EXPECT_TRUE(chan.Connect());
- listener.Init(&chan);
+ IPC::Channel channel(IPCTestBase::GetChannelName("SyncSocketServerClient"),
+ IPC::Channel::MODE_CLIENT,
+ &listener);
+ EXPECT_TRUE(channel.Connect());
+ listener.Init(&channel);
MessageLoop::current()->Run();
return 0;
}
@@ -167,11 +167,11 @@ class SyncSocketTest : public IPCTestBase {
};
TEST_F(SyncSocketTest, SanityTest) {
+ Init("SyncSocketServerClient");
+
SyncSocketClientListener listener;
- IPC::Channel chan(kSyncSocketChannel, IPC::Channel::MODE_SERVER,
- &listener);
- base::ProcessHandle server_process = SpawnChild(SYNC_SOCKET_SERVER, &chan);
- ASSERT_TRUE(server_process);
+ CreateChannel(&listener);
+ ASSERT_TRUE(StartClient());
// Create a pair of SyncSockets.
base::SyncSocket pair[2];
base::SyncSocket::CreatePair(&pair[0], &pair[1]);
@@ -180,12 +180,12 @@ TEST_F(SyncSocketTest, SanityTest) {
EXPECT_EQ(0U, pair[1].Peek());
base::SyncSocket::Handle target_handle;
// Connect the channel and listener.
- ASSERT_TRUE(chan.Connect());
- listener.Init(&pair[0], &chan);
+ ASSERT_TRUE(ConnectChannel());
+ listener.Init(&pair[0], channel());
#if defined(OS_WIN)
// On windows we need to duplicate the handle into the server process.
BOOL retval = DuplicateHandle(GetCurrentProcess(), pair[1].handle(),
- server_process, &target_handle,
+ client_process(), &target_handle,
0, FALSE, DUPLICATE_SAME_ACCESS);
EXPECT_TRUE(retval);
// Set up a message to pass the handle to the server.
@@ -196,18 +196,16 @@ TEST_F(SyncSocketTest, SanityTest) {
base::FileDescriptor filedesc(target_handle, false);
IPC::Message* msg = new MsgClassSetHandle(filedesc);
#endif // defined(OS_WIN)
- EXPECT_TRUE(chan.Send(msg));
+ EXPECT_TRUE(sender()->Send(msg));
// Use the current thread as the I/O thread.
MessageLoop::current()->Run();
// Shut down.
pair[0].Close();
pair[1].Close();
- EXPECT_TRUE(base::WaitForSingleProcess(
- server_process, base::TimeDelta::FromSeconds(5)));
- base::CloseProcessHandle(server_process);
+ EXPECT_TRUE(WaitForClientShutdown());
+ DestroyChannel();
}
-
// A blocking read operation that will block the thread until it receives
// |length| bytes of packets or Shutdown() is called on another thread.
static void BlockingRead(base::SyncSocket* socket, char* buf,