morrita@chromium.org | 15996aa | 2014-08-05 08:44:17 +0900 | [diff] [blame] | 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. |
| 4 | |
| 5 | #ifndef IPC_IPC_TEST_CHANNEL_LISTENER_H_ |
| 6 | #define IPC_IPC_TEST_CHANNEL_LISTENER_H_ |
| 7 | |
tfarina | 1cbfa08 | 2015-09-05 03:47:57 +0900 | [diff] [blame] | 8 | #include <stddef.h> |
| 9 | |
morrita@chromium.org | 15996aa | 2014-08-05 08:44:17 +0900 | [diff] [blame] | 10 | #include "ipc/ipc_listener.h" |
| 11 | |
| 12 | namespace IPC { |
| 13 | |
| 14 | class Sender; |
| 15 | |
| 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); |
| 23 | |
| 24 | TestChannelListener() : sender_(NULL), messages_left_(50) {} |
dcheng | ef7721a | 2014-10-22 11:29:52 +0900 | [diff] [blame] | 25 | ~TestChannelListener() override {} |
morrita@chromium.org | 15996aa | 2014-08-05 08:44:17 +0900 | [diff] [blame] | 26 | |
dcheng | ef7721a | 2014-10-22 11:29:52 +0900 | [diff] [blame] | 27 | bool OnMessageReceived(const Message& message) override; |
| 28 | void OnChannelError() override; |
morrita@chromium.org | 15996aa | 2014-08-05 08:44:17 +0900 | [diff] [blame] | 29 | |
| 30 | void Init(Sender* s) { |
| 31 | sender_ = s; |
| 32 | } |
| 33 | |
| 34 | bool HasSentAll() const { return 0 == messages_left_; } |
| 35 | |
| 36 | protected: |
| 37 | void SendNextMessage(); |
| 38 | |
| 39 | private: |
| 40 | Sender* sender_; |
| 41 | int messages_left_; |
| 42 | }; |
| 43 | |
| 44 | } |
| 45 | |
| 46 | #endif // IPC_IPC_TEST_CHANNEL_LISTENER_H_ |