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 #include "net/quic/quic_http_stream.h" | 5 #include "net/quic/quic_http_stream.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 #include "net/base/test_completion_callback.h" | 10 #include "net/base/test_completion_callback.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 const char kUploadData[] = "hello world!"; | 51 const char kUploadData[] = "hello world!"; |
52 const char kServerHostname[] = "www.google.com"; | 52 const char kServerHostname[] = "www.google.com"; |
53 const uint16 kServerPort = 80; | 53 const uint16 kServerPort = 80; |
54 | 54 |
55 class TestQuicConnection : public QuicConnection { | 55 class TestQuicConnection : public QuicConnection { |
56 public: | 56 public: |
57 TestQuicConnection(const QuicVersionVector& versions, | 57 TestQuicConnection(const QuicVersionVector& versions, |
58 QuicConnectionId connection_id, | 58 QuicConnectionId connection_id, |
59 IPEndPoint address, | 59 IPEndPoint address, |
60 QuicConnectionHelper* helper, | 60 QuicConnectionHelper* helper, |
61 QuicPacketWriter* writer) | 61 const QuicConnection::PacketWriterFactory& writer_factory) |
62 : QuicConnection(connection_id, | 62 : QuicConnection(connection_id, |
63 address, | 63 address, |
64 helper, | 64 helper, |
65 writer, | 65 writer_factory, |
66 false /* owns_writer */, | 66 true /* owns_writer */, |
67 false /* is_server */, | 67 false /* is_server */, |
68 versions) { | 68 versions) { |
69 } | 69 } |
70 | 70 |
71 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { | 71 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { |
72 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); | 72 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); |
73 } | 73 } |
74 | 74 |
75 void SetReceiveAlgorithm(ReceiveAlgorithmInterface* receive_algorithm) { | 75 void SetReceiveAlgorithm(ReceiveAlgorithmInterface* receive_algorithm) { |
76 QuicConnectionPeer::SetReceiveAlgorithm(this, receive_algorithm); | 76 QuicConnectionPeer::SetReceiveAlgorithm(this, receive_algorithm); |
(...skipping 18 matching lines...) Expand all Loading... |
95 explicit AutoClosingStream(const base::WeakPtr<QuicClientSession>& session) | 95 explicit AutoClosingStream(const base::WeakPtr<QuicClientSession>& session) |
96 : QuicHttpStream(session) { | 96 : QuicHttpStream(session) { |
97 } | 97 } |
98 | 98 |
99 virtual int OnDataReceived(const char* data, int length) OVERRIDE { | 99 virtual int OnDataReceived(const char* data, int length) OVERRIDE { |
100 Close(false); | 100 Close(false); |
101 return OK; | 101 return OK; |
102 } | 102 } |
103 }; | 103 }; |
104 | 104 |
| 105 class TestPacketWriterFactory : public QuicConnection::PacketWriterFactory { |
| 106 public: |
| 107 explicit TestPacketWriterFactory(DatagramClientSocket* socket) |
| 108 : socket_(socket) {} |
| 109 virtual ~TestPacketWriterFactory() {} |
| 110 |
| 111 virtual QuicPacketWriter* Create(QuicConnection* connection) const OVERRIDE { |
| 112 return new QuicDefaultPacketWriter(socket_); |
| 113 } |
| 114 |
| 115 private: |
| 116 DatagramClientSocket* socket_; |
| 117 }; |
| 118 |
105 } // namespace | 119 } // namespace |
106 | 120 |
107 class QuicHttpStreamPeer { | 121 class QuicHttpStreamPeer { |
108 public: | 122 public: |
109 static QuicReliableClientStream* GetQuicReliableClientStream( | 123 static QuicReliableClientStream* GetQuicReliableClientStream( |
110 QuicHttpStream* stream) { | 124 QuicHttpStream* stream) { |
111 return stream->stream_; | 125 return stream->stream_; |
112 } | 126 } |
113 }; | 127 }; |
114 | 128 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 Return(QuicTime::Delta::Zero())); | 208 Return(QuicTime::Delta::Zero())); |
195 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( | 209 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( |
196 Return(kMaxPacketSize)); | 210 Return(kMaxPacketSize)); |
197 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)). | 211 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)). |
198 WillRepeatedly(Return(QuicTime::Delta::Zero())); | 212 WillRepeatedly(Return(QuicTime::Delta::Zero())); |
199 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillRepeatedly( | 213 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillRepeatedly( |
200 Return(QuicBandwidth::Zero())); | 214 Return(QuicBandwidth::Zero())); |
201 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)).Times(AnyNumber()); | 215 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)).Times(AnyNumber()); |
202 helper_.reset(new QuicConnectionHelper(runner_.get(), &clock_, | 216 helper_.reset(new QuicConnectionHelper(runner_.get(), &clock_, |
203 &random_generator_)); | 217 &random_generator_)); |
204 writer_.reset(new QuicDefaultPacketWriter(socket)); | 218 TestPacketWriterFactory writer_factory(socket); |
205 connection_ = new TestQuicConnection(SupportedVersions(GetParam()), | 219 connection_ = new TestQuicConnection(SupportedVersions(GetParam()), |
206 connection_id_, peer_addr_, | 220 connection_id_, peer_addr_, |
207 helper_.get(), writer_.get()); | 221 helper_.get(), writer_factory); |
208 connection_->set_visitor(&visitor_); | 222 connection_->set_visitor(&visitor_); |
209 connection_->SetSendAlgorithm(send_algorithm_); | 223 connection_->SetSendAlgorithm(send_algorithm_); |
210 connection_->SetReceiveAlgorithm(receive_algorithm_); | 224 connection_->SetReceiveAlgorithm(receive_algorithm_); |
211 crypto_config_.SetDefaults(); | 225 crypto_config_.SetDefaults(); |
212 session_.reset( | 226 session_.reset( |
213 new QuicClientSession(connection_, | 227 new QuicClientSession(connection_, |
214 scoped_ptr<DatagramClientSocket>(socket), | 228 scoped_ptr<DatagramClientSocket>(socket), |
215 writer_.Pass(), NULL, | 229 NULL, |
216 &crypto_client_stream_factory_, | 230 &crypto_client_stream_factory_, |
217 make_scoped_ptr((QuicServerInfo*)NULL), | 231 make_scoped_ptr((QuicServerInfo*)NULL), |
218 QuicServerId(kServerHostname, kServerPort, | 232 QuicServerId(kServerHostname, kServerPort, |
219 false, PRIVACY_MODE_DISABLED), | 233 false, PRIVACY_MODE_DISABLED), |
220 DefaultQuicConfig(), &crypto_config_, | 234 DefaultQuicConfig(), &crypto_config_, |
221 base::MessageLoop::current()-> | 235 base::MessageLoop::current()-> |
222 message_loop_proxy().get(), | 236 message_loop_proxy().get(), |
223 NULL)); | 237 NULL)); |
224 session_->InitializeSession(); | 238 session_->InitializeSession(); |
225 session_->GetCryptoStream()->CryptoConnect(); | 239 session_->GetCryptoStream()->CryptoConnect(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 bool use_closing_stream_; | 305 bool use_closing_stream_; |
292 MockSendAlgorithm* send_algorithm_; | 306 MockSendAlgorithm* send_algorithm_; |
293 TestReceiveAlgorithm* receive_algorithm_; | 307 TestReceiveAlgorithm* receive_algorithm_; |
294 scoped_refptr<TestTaskRunner> runner_; | 308 scoped_refptr<TestTaskRunner> runner_; |
295 scoped_ptr<MockWrite[]> mock_writes_; | 309 scoped_ptr<MockWrite[]> mock_writes_; |
296 MockClock clock_; | 310 MockClock clock_; |
297 TestQuicConnection* connection_; | 311 TestQuicConnection* connection_; |
298 scoped_ptr<QuicConnectionHelper> helper_; | 312 scoped_ptr<QuicConnectionHelper> helper_; |
299 testing::StrictMock<MockConnectionVisitor> visitor_; | 313 testing::StrictMock<MockConnectionVisitor> visitor_; |
300 scoped_ptr<QuicHttpStream> stream_; | 314 scoped_ptr<QuicHttpStream> stream_; |
301 scoped_ptr<QuicDefaultPacketWriter> writer_; | |
302 scoped_ptr<QuicClientSession> session_; | 315 scoped_ptr<QuicClientSession> session_; |
303 QuicCryptoClientConfig crypto_config_; | 316 QuicCryptoClientConfig crypto_config_; |
304 TestCompletionCallback callback_; | 317 TestCompletionCallback callback_; |
305 HttpRequestInfo request_; | 318 HttpRequestInfo request_; |
306 HttpRequestHeaders headers_; | 319 HttpRequestHeaders headers_; |
307 HttpResponseInfo response_; | 320 HttpResponseInfo response_; |
308 scoped_refptr<IOBufferWithSize> read_buffer_; | 321 scoped_refptr<IOBufferWithSize> read_buffer_; |
309 SpdyHeaderBlock request_headers_; | 322 SpdyHeaderBlock request_headers_; |
310 SpdyHeaderBlock response_headers_; | 323 SpdyHeaderBlock response_headers_; |
311 std::string request_data_; | 324 std::string request_data_; |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 // Set Delegate to NULL and make sure EffectivePriority returns highest | 631 // Set Delegate to NULL and make sure EffectivePriority returns highest |
619 // priority. | 632 // priority. |
620 reliable_stream->SetDelegate(NULL); | 633 reliable_stream->SetDelegate(NULL); |
621 DCHECK_EQ(QuicWriteBlockedList::kHighestPriority, | 634 DCHECK_EQ(QuicWriteBlockedList::kHighestPriority, |
622 reliable_stream->EffectivePriority()); | 635 reliable_stream->EffectivePriority()); |
623 reliable_stream->SetDelegate(delegate); | 636 reliable_stream->SetDelegate(delegate); |
624 } | 637 } |
625 | 638 |
626 } // namespace test | 639 } // namespace test |
627 } // namespace net | 640 } // namespace net |
OLD | NEW |