Windows should animate when they are about to get docked at screen edges.
[chromium-blink-merge.git] / net / tools / quic / test_tools / quic_test_client.h
blob74bfc24646aed23db8f147cbed2fa558dc1bdf93
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 NET_QUIC_TEST_TOOLS_QUIC_CLIENT_H_
6 #define NET_QUIC_TEST_TOOLS_QUIC_CLIENT_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "net/quic/quic_framer.h"
13 #include "net/quic/quic_packet_creator.h"
14 #include "net/quic/quic_protocol.h"
15 #include "net/tools/quic/quic_client.h"
16 #include "net/tools/quic/quic_packet_writer.h"
18 namespace net {
20 class ProofVerifier;
22 namespace tools {
24 namespace test {
26 // Allows setting a writer for the client's QuicConnectionHelper, to allow
27 // fine-grained control of writes.
28 class QuicTestWriter : public QuicPacketWriter {
29 public:
30 virtual ~QuicTestWriter() {}
31 virtual void set_fd(int fd) = 0;
34 class HTTPMessage;
36 // A toy QUIC client used for testing.
37 class QuicTestClient : public ReliableQuicStream::Visitor {
38 public:
39 QuicTestClient(IPEndPoint server_address, const string& server_hostname,
40 const QuicVersion version);
41 QuicTestClient(IPEndPoint server_address,
42 const string& server_hostname,
43 bool secure,
44 const QuicVersion version);
45 QuicTestClient(IPEndPoint server_address,
46 const string& server_hostname,
47 bool secure,
48 const QuicConfig& config,
49 const QuicVersion version);
51 virtual ~QuicTestClient();
53 // ExpectCertificates controls whether the server is expected to provide
54 // certificates. The certificates, if any, are not verified, but the common
55 // name is recorded and available with |cert_common_name()|.
56 void ExpectCertificates(bool on);
58 // Clears any outstanding state and sends a simple GET of 'uri' to the
59 // server. Returns 0 if the request failed and no bytes were written.
60 ssize_t SendRequest(const string& uri);
61 ssize_t SendMessage(const HTTPMessage& message);
63 string SendCustomSynchronousRequest(const HTTPMessage& message);
64 string SendSynchronousRequest(const string& uri);
66 // Wraps data in a quic packet and sends it.
67 ssize_t SendData(string data, bool last_data);
69 QuicPacketCreator::Options* options() { return client_->options(); }
71 const BalsaHeaders *response_headers() const {return &headers_;}
73 void WaitForResponse();
75 void Connect();
76 void ResetConnection();
77 void Disconnect();
78 IPEndPoint LocalSocketAddress() const;
79 void ClearPerRequestState();
80 void WaitForInitialResponse();
81 ssize_t Send(const void *buffer, size_t size);
82 int response_size() const;
83 size_t bytes_read() const;
84 size_t bytes_written() const;
86 // From ReliableQuicStream::Visitor
87 virtual void OnClose(ReliableQuicStream* stream) OVERRIDE;
89 // Configures client_ to take ownership of and use the writer.
90 // Must be called before initial connect.
91 void UseWriter(QuicTestWriter* writer);
93 // Returns NULL if the maximum number of streams have already been created.
94 QuicReliableClientStream* GetOrCreateStream();
96 QuicRstStreamErrorCode stream_error() { return stream_error_; }
97 QuicErrorCode connection_error() { return client()->session()->error(); }
99 QuicClient* client() { return client_.get(); }
101 // cert_common_name returns the common name value of the server's certificate,
102 // or the empty string if no certificate was presented.
103 const string& cert_common_name() const;
105 const string& response_body() {return response_;}
106 bool connected() const;
108 void set_auto_reconnect(bool reconnect) { auto_reconnect_ = reconnect; }
110 private:
111 void Initialize(IPEndPoint address, const string& hostname, bool secure);
113 IPEndPoint server_address_;
114 IPEndPoint client_address_;
115 scoped_ptr<QuicClient> client_; // The actual client
116 QuicReliableClientStream* stream_;
118 QuicRstStreamErrorCode stream_error_;
120 BalsaHeaders headers_;
121 string response_;
122 uint64 bytes_read_;
123 uint64 bytes_written_;
124 // True if the client has never connected before. The client will
125 // auto-connect exactly once before sending data. If something causes a
126 // connection reset, it will not automatically reconnect.
127 bool never_connected_;
128 bool secure_;
129 // If true, the client will always reconnect if necessary before creating a
130 // stream.
131 bool auto_reconnect_;
133 // proof_verifier_ points to a RecordingProofVerifier that is owned by
134 // client_.
135 ProofVerifier* proof_verifier_;
138 } // namespace test
140 } // namespace tools
141 } // namespace net
143 #endif // NET_QUIC_TEST_TOOLS_QUIC_CLIENT_H_