MD Downloads: prevent search text from overlapping with the cancel search (X)
[chromium-blink-merge.git] / remoting / protocol / connection_tester.h
blobde63a62da50cfc900f77749efd6f5ddc87d9c711
1 // Copyright (c) 2012 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 REMOTING_PROTOCOL_CONNECTION_TESTER_H_
6 #define REMOTING_PROTOCOL_CONNECTION_TESTER_H_
8 #include <vector>
10 #include "base/memory/ref_counted.h"
12 namespace base {
13 class MessageLoop;
16 namespace net {
17 class DrainableIOBuffer;
18 class GrowableIOBuffer;
19 class IOBuffer;
20 } // namespace net
22 namespace remoting {
23 namespace protocol {
25 class P2PDatagramSocket;
26 class P2PStreamSocket;
28 // This class is used by unit tests to verify that a connection
29 // between two sockets works properly, i.e. data is delivered from one
30 // end to the other.
31 class StreamConnectionTester {
32 public:
33 StreamConnectionTester(P2PStreamSocket* client_socket,
34 P2PStreamSocket* host_socket,
35 int message_size,
36 int message_count);
37 ~StreamConnectionTester();
39 void Start();
40 bool done() { return done_; }
41 void CheckResults();
43 protected:
44 void Done();
45 void InitBuffers();
46 void DoWrite();
47 void OnWritten(int result);
48 void HandleWriteResult(int result);
49 void DoRead();
50 void OnRead(int result);
51 void HandleReadResult(int result);
53 private:
54 base::MessageLoop* message_loop_;
55 P2PStreamSocket* host_socket_;
56 P2PStreamSocket* client_socket_;
57 int message_size_;
58 int test_data_size_;
59 bool done_;
61 scoped_refptr<net::DrainableIOBuffer> output_buffer_;
62 scoped_refptr<net::GrowableIOBuffer> input_buffer_;
64 int write_errors_;
65 int read_errors_;
68 class DatagramConnectionTester {
69 public:
70 DatagramConnectionTester(P2PDatagramSocket* client_socket,
71 P2PDatagramSocket* host_socket,
72 int message_size,
73 int message_count,
74 int delay_ms);
75 ~DatagramConnectionTester() ;
77 void Start();
78 void CheckResults();
80 private:
81 void Done();
82 void DoWrite();
83 void OnWritten(int result);
84 void HandleWriteResult(int result);
85 void DoRead();
86 void OnRead(int result);
87 void HandleReadResult(int result);
89 base::MessageLoop* message_loop_;
90 P2PDatagramSocket* host_socket_;
91 P2PDatagramSocket* client_socket_;
92 int message_size_;
93 int message_count_;
94 int delay_ms_;
95 bool done_;
97 std::vector<scoped_refptr<net::IOBuffer> > sent_packets_;
98 scoped_refptr<net::IOBuffer> read_buffer_;
100 int write_errors_;
101 int read_errors_;
102 int packets_sent_;
103 int packets_received_;
104 int bad_packets_received_;
107 } // namespace protocol
108 } // namespace remoting
110 #endif // REMOTING_PROTOCOL_CONNECTION_TESTER_H_