Disable LoginInterstitialShouldReplaceExistingInterstitial
[chromium-blink-merge.git] / ipc / ipc_test_channel_listener.cc
blobe98f6b7ee156cc12c979321711493f32f40c76d0
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ipc/ipc_test_channel_listener.h"
7 #include "ipc/ipc_message.h"
8 #include "ipc/ipc_sender.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace IPC {
13 // static
14 void TestChannelListener::SendOneMessage(IPC::Sender* sender,
15 const char* text) {
16 static int message_index = 0;
18 IPC::Message* message = new IPC::Message(0,
20 IPC::Message::PRIORITY_NORMAL);
21 message->WriteInt(message_index++);
22 message->WriteString(std::string(text));
24 // Make sure we can handle large messages.
25 char junk[kLongMessageStringNumBytes];
26 memset(junk, 'a', sizeof(junk)-1);
27 junk[sizeof(junk)-1] = 0;
28 message->WriteString(std::string(junk));
30 sender->Send(message);
34 bool TestChannelListener::OnMessageReceived(const IPC::Message& message) {
35 PickleIterator iter(message);
37 int ignored;
38 EXPECT_TRUE(iter.ReadInt(&ignored));
39 std::string data;
40 EXPECT_TRUE(iter.ReadString(&data));
41 std::string big_string;
42 EXPECT_TRUE(iter.ReadString(&big_string));
43 EXPECT_EQ(kLongMessageStringNumBytes - 1, big_string.length());
45 SendNextMessage();
46 return true;
49 void TestChannelListener::OnChannelError() {
50 // There is a race when closing the channel so the last message may be lost.
51 EXPECT_LE(messages_left_, 1);
52 base::MessageLoop::current()->Quit();
55 void TestChannelListener::SendNextMessage() {
56 if (--messages_left_ <= 0)
57 base::MessageLoop::current()->Quit();
58 else
59 SendOneMessage(sender_, "Foo");