OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_QUIC_TEST_TOOLS_QUIC_TEST_CLIENT_H_ | 5 #ifndef NET_QUIC_TEST_TOOLS_QUIC_TEST_CLIENT_H_ |
6 #define NET_QUIC_TEST_TOOLS_QUIC_TEST_CLIENT_H_ | 6 #define NET_QUIC_TEST_TOOLS_QUIC_TEST_CLIENT_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "net/quic/quic_framer.h" | 12 #include "net/quic/quic_framer.h" |
13 #include "net/quic/quic_packet_creator.h" | 13 #include "net/quic/quic_packet_creator.h" |
14 #include "net/quic/quic_protocol.h" | 14 #include "net/quic/quic_protocol.h" |
15 #include "net/quic/test_tools/quic_test_writer.h" | 15 #include "net/quic/test_tools/quic_test_writer.h" |
16 #include "net/tools/quic/quic_client.h" | 16 #include "net/tools/quic/quic_client.h" |
17 | 17 |
18 namespace net { | 18 namespace net { |
19 | 19 |
20 class ProofVerifier; | 20 class ProofVerifier; |
21 | 21 |
22 namespace tools { | 22 namespace tools { |
23 | 23 |
24 namespace test { | 24 namespace test { |
25 | 25 |
26 class HTTPMessage; | 26 class HTTPMessage; |
27 | 27 |
28 // A toy QUIC client used for testing. | 28 // A toy QUIC client used for testing. |
29 class QuicTestClient : public ReliableQuicStream::Visitor { | 29 class QuicTestClient : public QuicDataStream::Visitor { |
30 public: | 30 public: |
31 QuicTestClient(IPEndPoint server_address, const string& server_hostname, | 31 QuicTestClient(IPEndPoint server_address, const string& server_hostname, |
32 const QuicVersionVector& supported_versions); | 32 const QuicVersionVector& supported_versions); |
33 QuicTestClient(IPEndPoint server_address, | 33 QuicTestClient(IPEndPoint server_address, |
34 const string& server_hostname, | 34 const string& server_hostname, |
35 bool secure, | 35 bool secure, |
36 const QuicVersionVector& supported_versions); | 36 const QuicVersionVector& supported_versions); |
37 QuicTestClient(IPEndPoint server_address, | 37 QuicTestClient(IPEndPoint server_address, |
38 const string& server_hostname, | 38 const string& server_hostname, |
39 bool secure, | 39 bool secure, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 bool response_headers_complete() const; | 74 bool response_headers_complete() const; |
75 const BalsaHeaders* response_headers() const; | 75 const BalsaHeaders* response_headers() const; |
76 int response_size() const; | 76 int response_size() const; |
77 int response_header_size() const { return response_header_size_; } | 77 int response_header_size() const { return response_header_size_; } |
78 int response_body_size() const { return response_body_size_; } | 78 int response_body_size() const { return response_body_size_; } |
79 size_t bytes_read() const; | 79 size_t bytes_read() const; |
80 size_t bytes_written() const; | 80 size_t bytes_written() const; |
81 bool buffer_body() const { return buffer_body_; } | 81 bool buffer_body() const { return buffer_body_; } |
82 void set_buffer_body(bool buffer_body) { buffer_body_ = buffer_body; } | 82 void set_buffer_body(bool buffer_body) { buffer_body_ = buffer_body; } |
83 | 83 |
84 // From ReliableQuicStream::Visitor | 84 // From QuicDataStream::Visitor |
85 virtual void OnClose(ReliableQuicStream* stream) OVERRIDE; | 85 virtual void OnClose(QuicDataStream* stream) OVERRIDE; |
86 | 86 |
87 // Configures client_ to take ownership of and use the writer. | 87 // Configures client_ to take ownership of and use the writer. |
88 // Must be called before initial connect. | 88 // Must be called before initial connect. |
89 void UseWriter(net::test::QuicTestWriter* writer); | 89 void UseWriter(net::test::QuicTestWriter* writer); |
90 // If the given GUID is nonzero, configures client_ to use a specific GUID | 90 // If the given GUID is nonzero, configures client_ to use a specific GUID |
91 // instead of a random one. | 91 // instead of a random one. |
92 void UseGuid(QuicGuid guid); | 92 void UseGuid(QuicGuid guid); |
93 | 93 |
94 // Returns NULL if the maximum number of streams have already been created. | 94 // Returns NULL if the maximum number of streams have already been created. |
95 QuicReliableClientStream* GetOrCreateStream(); | 95 QuicSpdyClientStream* GetOrCreateStream(); |
96 | 96 |
97 QuicRstStreamErrorCode stream_error() { return stream_error_; } | 97 QuicRstStreamErrorCode stream_error() { return stream_error_; } |
98 QuicErrorCode connection_error() { return client()->session()->error(); } | 98 QuicErrorCode connection_error() { return client()->session()->error(); } |
99 | 99 |
100 QuicClient* client() { return client_.get(); } | 100 QuicClient* client() { return client_.get(); } |
101 | 101 |
102 // cert_common_name returns the common name value of the server's certificate, | 102 // cert_common_name returns the common name value of the server's certificate, |
103 // or the empty string if no certificate was presented. | 103 // or the empty string if no certificate was presented. |
104 const string& cert_common_name() const; | 104 const string& cert_common_name() const; |
105 | 105 |
106 const string& response_body() {return response_;} | 106 const string& response_body() {return response_;} |
107 bool connected() const; | 107 bool connected() const; |
108 | 108 |
109 void set_auto_reconnect(bool reconnect) { auto_reconnect_ = reconnect; } | 109 void set_auto_reconnect(bool reconnect) { auto_reconnect_ = reconnect; } |
110 | 110 |
111 void set_priority(QuicPriority priority) { priority_ = priority; } | 111 void set_priority(QuicPriority priority) { priority_ = priority; } |
112 | 112 |
113 void WaitForWriteToFlush(); | 113 void WaitForWriteToFlush(); |
114 | 114 |
115 private: | 115 private: |
116 void Initialize(IPEndPoint address, const string& hostname, bool secure); | 116 void Initialize(IPEndPoint address, const string& hostname, bool secure); |
117 | 117 |
118 IPEndPoint server_address_; | 118 IPEndPoint server_address_; |
119 IPEndPoint client_address_; | 119 IPEndPoint client_address_; |
120 scoped_ptr<QuicClient> client_; // The actual client | 120 scoped_ptr<QuicClient> client_; // The actual client |
121 QuicReliableClientStream* stream_; | 121 QuicSpdyClientStream* stream_; |
122 | 122 |
123 QuicRstStreamErrorCode stream_error_; | 123 QuicRstStreamErrorCode stream_error_; |
124 | 124 |
125 bool response_complete_; | 125 bool response_complete_; |
126 bool response_headers_complete_; | 126 bool response_headers_complete_; |
127 BalsaHeaders headers_; | 127 BalsaHeaders headers_; |
128 QuicPriority priority_; | 128 QuicPriority priority_; |
129 string response_; | 129 string response_; |
130 uint64 bytes_read_; | 130 uint64 bytes_read_; |
131 uint64 bytes_written_; | 131 uint64 bytes_written_; |
(...skipping 15 matching lines...) Expand all Loading... |
147 // client_. | 147 // client_. |
148 ProofVerifier* proof_verifier_; | 148 ProofVerifier* proof_verifier_; |
149 }; | 149 }; |
150 | 150 |
151 } // namespace test | 151 } // namespace test |
152 | 152 |
153 } // namespace tools | 153 } // namespace tools |
154 } // namespace net | 154 } // namespace net |
155 | 155 |
156 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_CLIENT_H_ | 156 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_CLIENT_H_ |
OLD | NEW |