| Index: ipc/ipc_channel_unittest.cc
|
| diff --git a/ipc/ipc_channel_unittest.cc b/ipc/ipc_channel_unittest.cc
|
| index b9665dbed7304ee3c4fa893ee10879aa6eac4d65..1f8531170b95b468f5f8132cac3381735b72f43b 100644
|
| --- a/ipc/ipc_channel_unittest.cc
|
| +++ b/ipc/ipc_channel_unittest.cc
|
| @@ -15,76 +15,10 @@
|
| #include "base/threading/thread.h"
|
| #include "ipc/ipc_message.h"
|
| #include "ipc/ipc_test_base.h"
|
| +#include "ipc/ipc_test_channel_listener.h"
|
|
|
| namespace {
|
|
|
| -const size_t kLongMessageStringNumBytes = 50000;
|
| -
|
| -static void Send(IPC::Sender* sender, const char* text) {
|
| - static int message_index = 0;
|
| -
|
| - IPC::Message* message = new IPC::Message(0,
|
| - 2,
|
| - IPC::Message::PRIORITY_NORMAL);
|
| - message->WriteInt(message_index++);
|
| - message->WriteString(std::string(text));
|
| -
|
| - // Make sure we can handle large messages.
|
| - char junk[kLongMessageStringNumBytes];
|
| - memset(junk, 'a', sizeof(junk)-1);
|
| - junk[sizeof(junk)-1] = 0;
|
| - message->WriteString(std::string(junk));
|
| -
|
| - // DEBUG: printf("[%u] sending message [%s]\n", GetCurrentProcessId(), text);
|
| - sender->Send(message);
|
| -}
|
| -
|
| -// A generic listener that expects messages of a certain type (see
|
| -// OnMessageReceived()), and either sends a generic response or quits after the
|
| -// 50th message (or on channel error).
|
| -class GenericChannelListener : public IPC::Listener {
|
| - public:
|
| - GenericChannelListener() : sender_(NULL), messages_left_(50) {}
|
| - virtual ~GenericChannelListener() {}
|
| -
|
| - virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE {
|
| - PickleIterator iter(message);
|
| -
|
| - int ignored;
|
| - EXPECT_TRUE(iter.ReadInt(&ignored));
|
| - std::string data;
|
| - EXPECT_TRUE(iter.ReadString(&data));
|
| - std::string big_string;
|
| - EXPECT_TRUE(iter.ReadString(&big_string));
|
| - EXPECT_EQ(kLongMessageStringNumBytes - 1, big_string.length());
|
| -
|
| - SendNextMessage();
|
| - return true;
|
| - }
|
| -
|
| - virtual void OnChannelError() OVERRIDE {
|
| - // There is a race when closing the channel so the last message may be lost.
|
| - EXPECT_LE(messages_left_, 1);
|
| - base::MessageLoop::current()->Quit();
|
| - }
|
| -
|
| - void Init(IPC::Sender* s) {
|
| - sender_ = s;
|
| - }
|
| -
|
| - protected:
|
| - void SendNextMessage() {
|
| - if (--messages_left_ <= 0)
|
| - base::MessageLoop::current()->Quit();
|
| - else
|
| - Send(sender_, "Foo");
|
| - }
|
| -
|
| - private:
|
| - IPC::Sender* sender_;
|
| - int messages_left_;
|
| -};
|
| -
|
| class IPCChannelTest : public IPCTestBase {
|
| };
|
|
|
| @@ -124,13 +58,13 @@ TEST_F(IPCChannelTest, ChannelTest) {
|
| Init("GenericClient");
|
|
|
| // Set up IPC channel and start client.
|
| - GenericChannelListener listener;
|
| + IPC::TestChannelListener listener;
|
| CreateChannel(&listener);
|
| listener.Init(sender());
|
| ASSERT_TRUE(ConnectChannel());
|
| ASSERT_TRUE(StartClient());
|
|
|
| - Send(sender(), "hello from parent");
|
| + IPC::TestChannelListener::SendOneMessage(sender(), "hello from parent");
|
|
|
| // Run message loop.
|
| base::MessageLoop::current()->Run();
|
| @@ -149,7 +83,7 @@ TEST_F(IPCChannelTest, ChannelTestExistingPipe) {
|
|
|
| // Create pipe manually using the standard Chromium name and set up IPC
|
| // channel.
|
| - GenericChannelListener listener;
|
| + IPC::TestChannelListener listener;
|
| std::string name("\\\\.\\pipe\\chrome.");
|
| name.append(GetChannelName("GenericClient"));
|
| HANDLE pipe = CreateNamedPipeA(name.c_str(),
|
| @@ -169,7 +103,7 @@ TEST_F(IPCChannelTest, ChannelTestExistingPipe) {
|
| ASSERT_TRUE(ConnectChannel());
|
| ASSERT_TRUE(StartClient());
|
|
|
| - Send(sender(), "hello from parent");
|
| + IPC::TestChannelListener::SendOneMessage(sender(), "hello from parent");
|
|
|
| // Run message loop.
|
| base::MessageLoop::current()->Run();
|
| @@ -191,13 +125,13 @@ TEST_F(IPCChannelTest, ChannelProxyTest) {
|
| thread.StartWithOptions(options);
|
|
|
| // Set up IPC channel proxy.
|
| - GenericChannelListener listener;
|
| + IPC::TestChannelListener listener;
|
| CreateChannelProxy(&listener, thread.message_loop_proxy().get());
|
| listener.Init(sender());
|
|
|
| ASSERT_TRUE(StartClient());
|
|
|
| - Send(sender(), "hello from parent");
|
| + IPC::TestChannelListener::SendOneMessage(sender(), "hello from parent");
|
|
|
| // Run message loop.
|
| base::MessageLoop::current()->Run();
|
| @@ -209,7 +143,7 @@ TEST_F(IPCChannelTest, ChannelProxyTest) {
|
| thread.Stop();
|
| }
|
|
|
| -class ChannelListenerWithOnConnectedSend : public GenericChannelListener {
|
| +class ChannelListenerWithOnConnectedSend : public IPC::TestChannelListener {
|
| public:
|
| ChannelListenerWithOnConnectedSend() {}
|
| virtual ~ChannelListenerWithOnConnectedSend() {}
|
| @@ -237,7 +171,7 @@ TEST_F(IPCChannelTest, MAYBE_SendMessageInChannelConnected) {
|
| ASSERT_TRUE(ConnectChannel());
|
| ASSERT_TRUE(StartClient());
|
|
|
| - Send(sender(), "hello from parent");
|
| + IPC::TestChannelListener::SendOneMessage(sender(), "hello from parent");
|
|
|
| // Run message loop.
|
| base::MessageLoop::current()->Run();
|
| @@ -251,7 +185,7 @@ TEST_F(IPCChannelTest, MAYBE_SendMessageInChannelConnected) {
|
|
|
| MULTIPROCESS_IPC_TEST_CLIENT_MAIN(GenericClient) {
|
| base::MessageLoopForIO main_message_loop;
|
| - GenericChannelListener listener;
|
| + IPC::TestChannelListener listener;
|
|
|
| // Set up IPC channel.
|
| scoped_ptr<IPC::Channel> channel(IPC::Channel::CreateClient(
|
| @@ -259,7 +193,7 @@ MULTIPROCESS_IPC_TEST_CLIENT_MAIN(GenericClient) {
|
| &listener));
|
| CHECK(channel->Connect());
|
| listener.Init(channel.get());
|
| - Send(channel.get(), "hello from child");
|
| + IPC::TestChannelListener::SendOneMessage(channel.get(), "hello from child");
|
|
|
| base::MessageLoop::current()->Run();
|
| return 0;
|
|
|