Roll src/third_party/WebKit f298044:aa8346d (svn 202628:202629)
[chromium-blink-merge.git] / ipc / ipc_test_channel_listener.h
blob75635f7db390ae6fb02290c9f9317135183821e9
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 #ifndef IPC_IPC_TEST_CHANNEL_LISTENER_H_
6 #define IPC_IPC_TEST_CHANNEL_LISTENER_H_
8 #include <stddef.h>
10 #include "ipc/ipc_listener.h"
12 namespace IPC {
14 class Sender;
16 // A generic listener that expects messages of a certain type (see
17 // OnMessageReceived()), and either sends a generic response or quits after the
18 // 50th message (or on channel error).
19 class TestChannelListener : public Listener {
20 public:
21 static const size_t kLongMessageStringNumBytes = 50000;
22 static void SendOneMessage(Sender* sender, const char* text);
24 TestChannelListener() : sender_(NULL), messages_left_(50) {}
25 ~TestChannelListener() override {}
27 bool OnMessageReceived(const Message& message) override;
28 void OnChannelError() override;
30 void Init(Sender* s) {
31 sender_ = s;
34 bool HasSentAll() const { return 0 == messages_left_; }
36 protected:
37 void SendNextMessage();
39 private:
40 Sender* sender_;
41 int messages_left_;
46 #endif // IPC_IPC_TEST_CHANNEL_LISTENER_H_