Fix FullScreen crash in Webapp
[platform/framework/web/chromium-efl.git] / ipc / ipc_test_channel_listener.cc
1 // Copyright 2014 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ipc/ipc_test_channel_listener.h"
6
7 #include "base/run_loop.h"
8 #include "ipc/ipc_message.h"
9 #include "ipc/ipc_sender.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace IPC {
13
14 // static
15 void TestChannelListener::SendOneMessage(IPC::Sender* sender,
16                                          const char* text) {
17   static int message_index = 0;
18
19   IPC::Message* message = new IPC::Message(0,
20                                            2,
21                                            IPC::Message::PRIORITY_NORMAL);
22   message->WriteInt(message_index++);
23   message->WriteString(std::string(text));
24
25   // Make sure we can handle large messages.
26   char junk[kLongMessageStringNumBytes];
27   memset(junk, 'a', sizeof(junk)-1);
28   junk[sizeof(junk)-1] = 0;
29   message->WriteString(std::string(junk));
30
31   sender->Send(message);
32 }
33
34
35 bool TestChannelListener::OnMessageReceived(const IPC::Message& message) {
36   base::PickleIterator iter(message);
37
38   int ignored;
39   EXPECT_TRUE(iter.ReadInt(&ignored));
40   std::string data;
41   EXPECT_TRUE(iter.ReadString(&data));
42   std::string big_string;
43   EXPECT_TRUE(iter.ReadString(&big_string));
44   EXPECT_EQ(kLongMessageStringNumBytes - 1, big_string.length());
45
46   SendNextMessage();
47   return true;
48 }
49
50 void TestChannelListener::OnChannelError() {
51   // There is a race when closing the channel so the last message may be lost.
52   EXPECT_LE(messages_left_, 1);
53   base::RunLoop::QuitCurrentWhenIdleDeprecated();
54 }
55
56 void TestChannelListener::SendNextMessage() {
57   if (--messages_left_ <= 0)
58     base::RunLoop::QuitCurrentWhenIdleDeprecated();
59   else
60     SendOneMessage(sender_, "Foo");
61 }
62
63 }