Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(257)

Side by Side Diff: net/quic/quic_http_stream_test.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 QuicPacketWriter* writer)
62 : QuicConnection(connection_id, address, helper, writer, false, 62 : QuicConnection(connection_id,
63 versions, kInitialFlowControlWindowForTest) { 63 address,
64 } 64 helper,
65 writer,
66 false,
67 versions,
68 kInitialFlowControlWindowForTest) {}
65 69
66 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { 70 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) {
67 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); 71 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm);
68 } 72 }
69 73
70 void SetReceiveAlgorithm(ReceiveAlgorithmInterface* receive_algorithm) { 74 void SetReceiveAlgorithm(ReceiveAlgorithmInterface* receive_algorithm) {
71 QuicConnectionPeer::SetReceiveAlgorithm(this, receive_algorithm); 75 QuicConnectionPeer::SetReceiveAlgorithm(this, receive_algorithm);
72 } 76 }
73 }; 77 };
74 78
75 class TestReceiveAlgorithm : public ReceiveAlgorithmInterface { 79 class TestReceiveAlgorithm : public ReceiveAlgorithmInterface {
76 public: 80 public:
77 virtual bool GenerateCongestionFeedback( 81 virtual bool GenerateCongestionFeedback(
78 QuicCongestionFeedbackFrame* /*congestion_feedback*/) { 82 QuicCongestionFeedbackFrame* /*congestion_feedback*/) {
79 return false; 83 return false;
80 } 84 }
81 85
82 MOCK_METHOD3(RecordIncomingPacket, 86 MOCK_METHOD3(RecordIncomingPacket,
83 void(QuicByteCount, QuicPacketSequenceNumber, QuicTime)); 87 void(QuicByteCount, QuicPacketSequenceNumber, QuicTime));
84 }; 88 };
85 89
86 // Subclass of QuicHttpStream that closes itself when the first piece of data 90 // Subclass of QuicHttpStream that closes itself when the first piece of data
87 // is received. 91 // is received.
88 class AutoClosingStream : public QuicHttpStream { 92 class AutoClosingStream : public QuicHttpStream {
89 public: 93 public:
90 explicit AutoClosingStream(const base::WeakPtr<QuicClientSession>& session) 94 explicit AutoClosingStream(const base::WeakPtr<QuicClientSession>& session)
91 : QuicHttpStream(session) { 95 : QuicHttpStream(session) {}
92 }
93 96
94 virtual int OnDataReceived(const char* data, int length) OVERRIDE { 97 virtual int OnDataReceived(const char* data, int length) OVERRIDE {
95 Close(false); 98 Close(false);
96 return OK; 99 return OK;
97 } 100 }
98 }; 101 };
99 102
100 } // namespace 103 } // namespace
101 104
102 class QuicHttpStreamPeer { 105 class QuicHttpStreamPeer {
103 public: 106 public:
104 static QuicReliableClientStream* GetQuicReliableClientStream( 107 static QuicReliableClientStream* GetQuicReliableClientStream(
105 QuicHttpStream* stream) { 108 QuicHttpStream* stream) {
106 return stream->stream_; 109 return stream->stream_;
107 } 110 }
108 }; 111 };
109 112
110 class QuicHttpStreamTest : public ::testing::TestWithParam<QuicVersion> { 113 class QuicHttpStreamTest : public ::testing::TestWithParam<QuicVersion> {
111 protected: 114 protected:
112 static const bool kFin = true; 115 static const bool kFin = true;
113 static const bool kIncludeVersion = true; 116 static const bool kIncludeVersion = true;
114 static const bool kIncludeCongestionFeedback = true; 117 static const bool kIncludeCongestionFeedback = true;
115 118
116 // Holds a packet to be written to the wire, and the IO mode that should 119 // Holds a packet to be written to the wire, and the IO mode that should
117 // be used by the mock socket when performing the write. 120 // be used by the mock socket when performing the write.
118 struct PacketToWrite { 121 struct PacketToWrite {
119 PacketToWrite(IoMode mode, QuicEncryptedPacket* packet) 122 PacketToWrite(IoMode mode, QuicEncryptedPacket* packet)
120 : mode(mode), 123 : mode(mode), packet(packet) {}
121 packet(packet) {
122 }
123 IoMode mode; 124 IoMode mode;
124 QuicEncryptedPacket* packet; 125 QuicEncryptedPacket* packet;
125 }; 126 };
126 127
127 QuicHttpStreamTest() 128 QuicHttpStreamTest()
128 : net_log_(BoundNetLog()), 129 : net_log_(BoundNetLog()),
129 use_closing_stream_(false), 130 use_closing_stream_(false),
130 read_buffer_(new IOBufferWithSize(4096)), 131 read_buffer_(new IOBufferWithSize(4096)),
131 connection_id_(2), 132 connection_id_(2),
132 stream_id_(5), 133 stream_id_(5),
(...skipping 11 matching lines...) Expand all
144 delete writes_[i].packet; 145 delete writes_[i].packet;
145 } 146 }
146 } 147 }
147 148
148 // Adds a packet to the list of expected writes. 149 // Adds a packet to the list of expected writes.
149 void AddWrite(scoped_ptr<QuicEncryptedPacket> packet) { 150 void AddWrite(scoped_ptr<QuicEncryptedPacket> packet) {
150 writes_.push_back(PacketToWrite(SYNCHRONOUS, packet.release())); 151 writes_.push_back(PacketToWrite(SYNCHRONOUS, packet.release()));
151 } 152 }
152 153
153 // Returns the packet to be written at position |pos|. 154 // Returns the packet to be written at position |pos|.
154 QuicEncryptedPacket* GetWrite(size_t pos) { 155 QuicEncryptedPacket* GetWrite(size_t pos) { return writes_[pos].packet; }
155 return writes_[pos].packet;
156 }
157 156
158 bool AtEof() { 157 bool AtEof() {
159 return socket_data_->at_read_eof() && socket_data_->at_write_eof(); 158 return socket_data_->at_read_eof() && socket_data_->at_write_eof();
160 } 159 }
161 160
162 void ProcessPacket(scoped_ptr<QuicEncryptedPacket> packet) { 161 void ProcessPacket(scoped_ptr<QuicEncryptedPacket> packet) {
163 connection_->ProcessUdpPacket(self_addr_, peer_addr_, *packet); 162 connection_->ProcessUdpPacket(self_addr_, peer_addr_, *packet);
164 } 163 }
165 164
166 // Configures the test fixture to use the list of expected writes. 165 // Configures the test fixture to use the list of expected writes.
167 void Initialize() { 166 void Initialize() {
168 mock_writes_.reset(new MockWrite[writes_.size()]); 167 mock_writes_.reset(new MockWrite[writes_.size()]);
169 for (size_t i = 0; i < writes_.size(); i++) { 168 for (size_t i = 0; i < writes_.size(); i++) {
170 mock_writes_[i] = MockWrite(writes_[i].mode, 169 mock_writes_[i] = MockWrite(writes_[i].mode,
171 writes_[i].packet->data(), 170 writes_[i].packet->data(),
172 writes_[i].packet->length()); 171 writes_[i].packet->length());
173 }; 172 };
174 173
175 socket_data_.reset(new StaticSocketDataProvider(NULL, 0, mock_writes_.get(), 174 socket_data_.reset(new StaticSocketDataProvider(
176 writes_.size())); 175 NULL, 0, mock_writes_.get(), writes_.size()));
177 176
178 MockUDPClientSocket* socket = new MockUDPClientSocket(socket_data_.get(), 177 MockUDPClientSocket* socket =
179 net_log_.net_log()); 178 new MockUDPClientSocket(socket_data_.get(), net_log_.net_log());
180 socket->Connect(peer_addr_); 179 socket->Connect(peer_addr_);
181 runner_ = new TestTaskRunner(&clock_); 180 runner_ = new TestTaskRunner(&clock_);
182 send_algorithm_ = new MockSendAlgorithm(); 181 send_algorithm_ = new MockSendAlgorithm();
183 receive_algorithm_ = new TestReceiveAlgorithm(); 182 receive_algorithm_ = new TestReceiveAlgorithm();
184 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _)). 183 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _))
185 Times(AnyNumber()); 184 .Times(AnyNumber());
186 EXPECT_CALL(*send_algorithm_, 185 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _))
187 OnPacketSent(_, _, _, _)).WillRepeatedly(Return(true)); 186 .WillRepeatedly(Return(true));
188 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly( 187 EXPECT_CALL(*send_algorithm_, RetransmissionDelay())
189 Return(QuicTime::Delta::Zero())); 188 .WillRepeatedly(Return(QuicTime::Delta::Zero()));
190 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( 189 EXPECT_CALL(*send_algorithm_, GetCongestionWindow())
191 Return(kMaxPacketSize)); 190 .WillRepeatedly(Return(kMaxPacketSize));
192 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)). 191 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _))
193 WillRepeatedly(Return(QuicTime::Delta::Zero())); 192 .WillRepeatedly(Return(QuicTime::Delta::Zero()));
194 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillRepeatedly( 193 EXPECT_CALL(*send_algorithm_, BandwidthEstimate())
195 Return(QuicBandwidth::Zero())); 194 .WillRepeatedly(Return(QuicBandwidth::Zero()));
196 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)).Times(AnyNumber()); 195 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)).Times(AnyNumber());
197 helper_.reset(new QuicConnectionHelper(runner_.get(), &clock_, 196 helper_.reset(
198 &random_generator_)); 197 new QuicConnectionHelper(runner_.get(), &clock_, &random_generator_));
199 writer_.reset(new QuicDefaultPacketWriter(socket)); 198 writer_.reset(new QuicDefaultPacketWriter(socket));
200 connection_ = new TestQuicConnection(SupportedVersions(GetParam()), 199 connection_ = new TestQuicConnection(SupportedVersions(GetParam()),
201 connection_id_, peer_addr_, 200 connection_id_,
202 helper_.get(), writer_.get()); 201 peer_addr_,
202 helper_.get(),
203 writer_.get());
203 connection_->set_visitor(&visitor_); 204 connection_->set_visitor(&visitor_);
204 connection_->SetSendAlgorithm(send_algorithm_); 205 connection_->SetSendAlgorithm(send_algorithm_);
205 connection_->SetReceiveAlgorithm(receive_algorithm_); 206 connection_->SetReceiveAlgorithm(receive_algorithm_);
206 crypto_config_.SetDefaults(); 207 crypto_config_.SetDefaults();
207 session_.reset( 208 session_.reset(new QuicClientSession(
208 new QuicClientSession(connection_, 209 connection_,
209 scoped_ptr<DatagramClientSocket>(socket), 210 scoped_ptr<DatagramClientSocket>(socket),
210 writer_.Pass(), NULL, 211 writer_.Pass(),
211 &crypto_client_stream_factory_, 212 NULL,
212 make_scoped_ptr((QuicServerInfo*)NULL), 213 &crypto_client_stream_factory_,
213 QuicServerId(kServerHostname, kServerPort, 214 make_scoped_ptr((QuicServerInfo*)NULL),
214 false, PRIVACY_MODE_DISABLED), 215 QuicServerId(
215 DefaultQuicConfig(), &crypto_config_, NULL)); 216 kServerHostname, kServerPort, false, PRIVACY_MODE_DISABLED),
217 DefaultQuicConfig(),
218 &crypto_config_,
219 NULL));
216 session_->GetCryptoStream()->CryptoConnect(); 220 session_->GetCryptoStream()->CryptoConnect();
217 EXPECT_TRUE(session_->IsCryptoHandshakeConfirmed()); 221 EXPECT_TRUE(session_->IsCryptoHandshakeConfirmed());
218 stream_.reset(use_closing_stream_ ? 222 stream_.reset(use_closing_stream_
219 new AutoClosingStream(session_->GetWeakPtr()) : 223 ? new AutoClosingStream(session_->GetWeakPtr())
220 new QuicHttpStream(session_->GetWeakPtr())); 224 : new QuicHttpStream(session_->GetWeakPtr()));
221 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(20)); 225 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(20));
222 } 226 }
223 227
224 void SetRequest(const std::string& method, 228 void SetRequest(const std::string& method,
225 const std::string& path, 229 const std::string& path,
226 RequestPriority priority) { 230 RequestPriority priority) {
227 request_headers_ = maker_.GetRequestHeaders(method, "http", path); 231 request_headers_ = maker_.GetRequestHeaders(method, "http", path);
228 } 232 }
229 233
230 void SetResponse(const std::string& status, const std::string& body) { 234 void SetResponse(const std::string& status, const std::string& body) {
(...skipping 21 matching lines...) Expand all
252 scoped_ptr<QuicEncryptedPacket> ConstructResponseHeadersPacket( 256 scoped_ptr<QuicEncryptedPacket> ConstructResponseHeadersPacket(
253 QuicPacketSequenceNumber sequence_number, 257 QuicPacketSequenceNumber sequence_number,
254 bool fin) { 258 bool fin) {
255 return maker_.MakeResponseHeadersPacket( 259 return maker_.MakeResponseHeadersPacket(
256 sequence_number, stream_id_, !kIncludeVersion, fin, response_headers_); 260 sequence_number, stream_id_, !kIncludeVersion, fin, response_headers_);
257 } 261 }
258 262
259 scoped_ptr<QuicEncryptedPacket> ConstructRstStreamPacket( 263 scoped_ptr<QuicEncryptedPacket> ConstructRstStreamPacket(
260 QuicPacketSequenceNumber sequence_number) { 264 QuicPacketSequenceNumber sequence_number) {
261 return maker_.MakeRstPacket( 265 return maker_.MakeRstPacket(
262 sequence_number, true, stream_id_, 266 sequence_number,
267 true,
268 stream_id_,
263 AdjustErrorForVersion(QUIC_RST_FLOW_CONTROL_ACCOUNTING, GetParam())); 269 AdjustErrorForVersion(QUIC_RST_FLOW_CONTROL_ACCOUNTING, GetParam()));
264 } 270 }
265 271
266 scoped_ptr<QuicEncryptedPacket> ConstructAckAndRstStreamPacket( 272 scoped_ptr<QuicEncryptedPacket> ConstructAckAndRstStreamPacket(
267 QuicPacketSequenceNumber sequence_number) { 273 QuicPacketSequenceNumber sequence_number) {
268 return maker_.MakeAckAndRstPacket( 274 return maker_.MakeAckAndRstPacket(sequence_number,
269 sequence_number, !kIncludeVersion, stream_id_, QUIC_STREAM_CANCELLED, 275 !kIncludeVersion,
270 2, 1, !kIncludeCongestionFeedback); 276 stream_id_,
277 QUIC_STREAM_CANCELLED,
278 2,
279 1,
280 !kIncludeCongestionFeedback);
271 } 281 }
272 282
273 scoped_ptr<QuicEncryptedPacket> ConstructAckPacket( 283 scoped_ptr<QuicEncryptedPacket> ConstructAckPacket(
274 QuicPacketSequenceNumber sequence_number, 284 QuicPacketSequenceNumber sequence_number,
275 QuicPacketSequenceNumber largest_received, 285 QuicPacketSequenceNumber largest_received,
276 QuicPacketSequenceNumber least_unacked) { 286 QuicPacketSequenceNumber least_unacked) {
277 return maker_.MakeAckPacket(sequence_number, largest_received, 287 return maker_.MakeAckPacket(sequence_number,
278 least_unacked, !kIncludeCongestionFeedback); 288 largest_received,
289 least_unacked,
290 !kIncludeCongestionFeedback);
279 } 291 }
280 292
281 BoundNetLog net_log_; 293 BoundNetLog net_log_;
282 bool use_closing_stream_; 294 bool use_closing_stream_;
283 MockSendAlgorithm* send_algorithm_; 295 MockSendAlgorithm* send_algorithm_;
284 TestReceiveAlgorithm* receive_algorithm_; 296 TestReceiveAlgorithm* receive_algorithm_;
285 scoped_refptr<TestTaskRunner> runner_; 297 scoped_refptr<TestTaskRunner> runner_;
286 scoped_ptr<MockWrite[]> mock_writes_; 298 scoped_ptr<MockWrite[]> mock_writes_;
287 MockClock clock_; 299 MockClock clock_;
288 TestQuicConnection* connection_; 300 TestQuicConnection* connection_;
(...skipping 18 matching lines...) Expand all
307 const QuicStreamId stream_id_; 319 const QuicStreamId stream_id_;
308 QuicTestPacketMaker maker_; 320 QuicTestPacketMaker maker_;
309 IPEndPoint self_addr_; 321 IPEndPoint self_addr_;
310 IPEndPoint peer_addr_; 322 IPEndPoint peer_addr_;
311 MockRandom random_generator_; 323 MockRandom random_generator_;
312 MockCryptoClientStreamFactory crypto_client_stream_factory_; 324 MockCryptoClientStreamFactory crypto_client_stream_factory_;
313 scoped_ptr<StaticSocketDataProvider> socket_data_; 325 scoped_ptr<StaticSocketDataProvider> socket_data_;
314 std::vector<PacketToWrite> writes_; 326 std::vector<PacketToWrite> writes_;
315 }; 327 };
316 328
317 INSTANTIATE_TEST_CASE_P(Version, QuicHttpStreamTest, 329 INSTANTIATE_TEST_CASE_P(Version,
330 QuicHttpStreamTest,
318 ::testing::ValuesIn(QuicSupportedVersions())); 331 ::testing::ValuesIn(QuicSupportedVersions()));
319 332
320 TEST_P(QuicHttpStreamTest, RenewStreamForAuth) { 333 TEST_P(QuicHttpStreamTest, RenewStreamForAuth) {
321 Initialize(); 334 Initialize();
322 EXPECT_EQ(NULL, stream_->RenewStreamForAuth()); 335 EXPECT_EQ(NULL, stream_->RenewStreamForAuth());
323 } 336 }
324 337
325 TEST_P(QuicHttpStreamTest, CanFindEndOfResponse) { 338 TEST_P(QuicHttpStreamTest, CanFindEndOfResponse) {
326 Initialize(); 339 Initialize();
327 EXPECT_TRUE(stream_->CanFindEndOfResponse()); 340 EXPECT_TRUE(stream_->CanFindEndOfResponse());
328 } 341 }
329 342
330 TEST_P(QuicHttpStreamTest, IsConnectionReusable) { 343 TEST_P(QuicHttpStreamTest, IsConnectionReusable) {
331 Initialize(); 344 Initialize();
332 EXPECT_FALSE(stream_->IsConnectionReusable()); 345 EXPECT_FALSE(stream_->IsConnectionReusable());
333 } 346 }
334 347
335 TEST_P(QuicHttpStreamTest, GetRequest) { 348 TEST_P(QuicHttpStreamTest, GetRequest) {
336 SetRequest("GET", "/", DEFAULT_PRIORITY); 349 SetRequest("GET", "/", DEFAULT_PRIORITY);
337 AddWrite(ConstructRequestHeadersPacket(1, kFin)); 350 AddWrite(ConstructRequestHeadersPacket(1, kFin));
338 Initialize(); 351 Initialize();
339 352
340 request_.method = "GET"; 353 request_.method = "GET";
341 request_.url = GURL("http://www.google.com/"); 354 request_.url = GURL("http://www.google.com/");
342 355
343 EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, 356 EXPECT_EQ(OK,
344 net_log_, callback_.callback())); 357 stream_->InitializeStream(
345 EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_, 358 &request_, DEFAULT_PRIORITY, net_log_, callback_.callback()));
346 callback_.callback())); 359 EXPECT_EQ(OK,
360 stream_->SendRequest(headers_, &response_, callback_.callback()));
347 EXPECT_EQ(&response_, stream_->GetResponseInfo()); 361 EXPECT_EQ(&response_, stream_->GetResponseInfo());
348 362
349 // Ack the request. 363 // Ack the request.
350 ProcessPacket(ConstructAckPacket(1, 0, 0)); 364 ProcessPacket(ConstructAckPacket(1, 0, 0));
351 365
352 EXPECT_EQ(ERR_IO_PENDING, 366 EXPECT_EQ(ERR_IO_PENDING, stream_->ReadResponseHeaders(callback_.callback()));
353 stream_->ReadResponseHeaders(callback_.callback()));
354 367
355 SetResponse("404 Not Found", std::string()); 368 SetResponse("404 Not Found", std::string());
356 ProcessPacket(ConstructResponseHeadersPacket(2, kFin)); 369 ProcessPacket(ConstructResponseHeadersPacket(2, kFin));
357 370
358 // Now that the headers have been processed, the callback will return. 371 // Now that the headers have been processed, the callback will return.
359 EXPECT_EQ(OK, callback_.WaitForResult()); 372 EXPECT_EQ(OK, callback_.WaitForResult());
360 ASSERT_TRUE(response_.headers.get()); 373 ASSERT_TRUE(response_.headers.get());
361 EXPECT_EQ(404, response_.headers->response_code()); 374 EXPECT_EQ(404, response_.headers->response_code());
362 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); 375 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain"));
363 376
364 // There is no body, so this should return immediately. 377 // There is no body, so this should return immediately.
365 EXPECT_EQ(0, stream_->ReadResponseBody(read_buffer_.get(), 378 EXPECT_EQ(
366 read_buffer_->size(), 379 0,
367 callback_.callback())); 380 stream_->ReadResponseBody(
381 read_buffer_.get(), read_buffer_->size(), callback_.callback()));
368 EXPECT_TRUE(stream_->IsResponseBodyComplete()); 382 EXPECT_TRUE(stream_->IsResponseBodyComplete());
369 EXPECT_TRUE(AtEof()); 383 EXPECT_TRUE(AtEof());
370 } 384 }
371 385
372 // Regression test for http://crbug.com/288128 386 // Regression test for http://crbug.com/288128
373 TEST_P(QuicHttpStreamTest, GetRequestLargeResponse) { 387 TEST_P(QuicHttpStreamTest, GetRequestLargeResponse) {
374 SetRequest("GET", "/", DEFAULT_PRIORITY); 388 SetRequest("GET", "/", DEFAULT_PRIORITY);
375 AddWrite(ConstructRequestHeadersPacket(1, kFin)); 389 AddWrite(ConstructRequestHeadersPacket(1, kFin));
376 Initialize(); 390 Initialize();
377 391
378 request_.method = "GET"; 392 request_.method = "GET";
379 request_.url = GURL("http://www.google.com/"); 393 request_.url = GURL("http://www.google.com/");
380 394
381 EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, 395 EXPECT_EQ(OK,
382 net_log_, callback_.callback())); 396 stream_->InitializeStream(
383 EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_, 397 &request_, DEFAULT_PRIORITY, net_log_, callback_.callback()));
384 callback_.callback())); 398 EXPECT_EQ(OK,
399 stream_->SendRequest(headers_, &response_, callback_.callback()));
385 EXPECT_EQ(&response_, stream_->GetResponseInfo()); 400 EXPECT_EQ(&response_, stream_->GetResponseInfo());
386 401
387 // Ack the request. 402 // Ack the request.
388 ProcessPacket(ConstructAckPacket(1, 0, 0)); 403 ProcessPacket(ConstructAckPacket(1, 0, 0));
389 404
390 EXPECT_EQ(ERR_IO_PENDING, 405 EXPECT_EQ(ERR_IO_PENDING, stream_->ReadResponseHeaders(callback_.callback()));
391 stream_->ReadResponseHeaders(callback_.callback()));
392 406
393 SpdyHeaderBlock headers; 407 SpdyHeaderBlock headers;
394 headers[":status"] = "200 OK"; 408 headers[":status"] = "200 OK";
395 headers[":version"] = "HTTP/1.1"; 409 headers[":version"] = "HTTP/1.1";
396 headers["content-type"] = "text/plain"; 410 headers["content-type"] = "text/plain";
397 headers["big6"] = std::string(10000, 'x'); // Lots of x's. 411 headers["big6"] = std::string(10000, 'x'); // Lots of x's.
398 412
399 std::string response = SpdyUtils::SerializeUncompressedHeaders(headers); 413 std::string response = SpdyUtils::SerializeUncompressedHeaders(headers);
400 EXPECT_LT(4096u, response.length()); 414 EXPECT_LT(4096u, response.length());
401 stream_->OnDataReceived(response.data(), response.length()); 415 stream_->OnDataReceived(response.data(), response.length());
402 stream_->OnClose(QUIC_NO_ERROR); 416 stream_->OnClose(QUIC_NO_ERROR);
403 417
404 // Now that the headers have been processed, the callback will return. 418 // Now that the headers have been processed, the callback will return.
405 EXPECT_EQ(OK, callback_.WaitForResult()); 419 EXPECT_EQ(OK, callback_.WaitForResult());
406 ASSERT_TRUE(response_.headers.get()); 420 ASSERT_TRUE(response_.headers.get());
407 EXPECT_EQ(200, response_.headers->response_code()); 421 EXPECT_EQ(200, response_.headers->response_code());
408 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); 422 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain"));
409 423
410 // There is no body, so this should return immediately. 424 // There is no body, so this should return immediately.
411 EXPECT_EQ(0, stream_->ReadResponseBody(read_buffer_.get(), 425 EXPECT_EQ(
412 read_buffer_->size(), 426 0,
413 callback_.callback())); 427 stream_->ReadResponseBody(
428 read_buffer_.get(), read_buffer_->size(), callback_.callback()));
414 EXPECT_TRUE(stream_->IsResponseBodyComplete()); 429 EXPECT_TRUE(stream_->IsResponseBodyComplete());
415 EXPECT_TRUE(AtEof()); 430 EXPECT_TRUE(AtEof());
416 } 431 }
417 432
418 TEST_P(QuicHttpStreamTest, SendPostRequest) { 433 TEST_P(QuicHttpStreamTest, SendPostRequest) {
419 SetRequest("POST", "/", DEFAULT_PRIORITY); 434 SetRequest("POST", "/", DEFAULT_PRIORITY);
420 AddWrite(ConstructRequestHeadersPacket(1, !kFin)); 435 AddWrite(ConstructRequestHeadersPacket(1, !kFin));
421 AddWrite(ConstructDataPacket(2, kIncludeVersion, kFin, 0, kUploadData)); 436 AddWrite(ConstructDataPacket(2, kIncludeVersion, kFin, 0, kUploadData));
422 AddWrite(ConstructAckPacket(3, 3, 1)); 437 AddWrite(ConstructAckPacket(3, 3, 1));
423 438
424 Initialize(); 439 Initialize();
425 440
426 ScopedVector<UploadElementReader> element_readers; 441 ScopedVector<UploadElementReader> element_readers;
427 element_readers.push_back( 442 element_readers.push_back(
428 new UploadBytesElementReader(kUploadData, strlen(kUploadData))); 443 new UploadBytesElementReader(kUploadData, strlen(kUploadData)));
429 UploadDataStream upload_data_stream(element_readers.Pass(), 0); 444 UploadDataStream upload_data_stream(element_readers.Pass(), 0);
430 request_.method = "POST"; 445 request_.method = "POST";
431 request_.url = GURL("http://www.google.com/"); 446 request_.url = GURL("http://www.google.com/");
432 request_.upload_data_stream = &upload_data_stream; 447 request_.upload_data_stream = &upload_data_stream;
433 ASSERT_EQ(OK, request_.upload_data_stream->Init(CompletionCallback())); 448 ASSERT_EQ(OK, request_.upload_data_stream->Init(CompletionCallback()));
434 449
435 EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, 450 EXPECT_EQ(OK,
436 net_log_, callback_.callback())); 451 stream_->InitializeStream(
437 EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_, 452 &request_, DEFAULT_PRIORITY, net_log_, callback_.callback()));
438 callback_.callback())); 453 EXPECT_EQ(OK,
454 stream_->SendRequest(headers_, &response_, callback_.callback()));
439 EXPECT_EQ(&response_, stream_->GetResponseInfo()); 455 EXPECT_EQ(&response_, stream_->GetResponseInfo());
440 456
441 // Ack both packets in the request. 457 // Ack both packets in the request.
442 ProcessPacket(ConstructAckPacket(1, 0, 0)); 458 ProcessPacket(ConstructAckPacket(1, 0, 0));
443 459
444 // Send the response headers (but not the body). 460 // Send the response headers (but not the body).
445 SetResponse("200 OK", std::string()); 461 SetResponse("200 OK", std::string());
446 ProcessPacket(ConstructResponseHeadersPacket(2, !kFin)); 462 ProcessPacket(ConstructResponseHeadersPacket(2, !kFin));
447 463
448 // Since the headers have already arrived, this should return immediately. 464 // Since the headers have already arrived, this should return immediately.
449 EXPECT_EQ(OK, stream_->ReadResponseHeaders(callback_.callback())); 465 EXPECT_EQ(OK, stream_->ReadResponseHeaders(callback_.callback()));
450 ASSERT_TRUE(response_.headers.get()); 466 ASSERT_TRUE(response_.headers.get());
451 EXPECT_EQ(200, response_.headers->response_code()); 467 EXPECT_EQ(200, response_.headers->response_code());
452 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); 468 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain"));
453 469
454 // Send the response body. 470 // Send the response body.
455 const char kResponseBody[] = "Hello world!"; 471 const char kResponseBody[] = "Hello world!";
456 ProcessPacket(ConstructDataPacket(3, false, kFin, 0, kResponseBody)); 472 ProcessPacket(ConstructDataPacket(3, false, kFin, 0, kResponseBody));
457 // Since the body has already arrived, this should return immediately. 473 // Since the body has already arrived, this should return immediately.
458 EXPECT_EQ(static_cast<int>(strlen(kResponseBody)), 474 EXPECT_EQ(
459 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), 475 static_cast<int>(strlen(kResponseBody)),
460 callback_.callback())); 476 stream_->ReadResponseBody(
477 read_buffer_.get(), read_buffer_->size(), callback_.callback()));
461 478
462 EXPECT_TRUE(stream_->IsResponseBodyComplete()); 479 EXPECT_TRUE(stream_->IsResponseBodyComplete());
463 EXPECT_TRUE(AtEof()); 480 EXPECT_TRUE(AtEof());
464 } 481 }
465 482
466 TEST_P(QuicHttpStreamTest, SendChunkedPostRequest) { 483 TEST_P(QuicHttpStreamTest, SendChunkedPostRequest) {
467 SetRequest("POST", "/", DEFAULT_PRIORITY); 484 SetRequest("POST", "/", DEFAULT_PRIORITY);
468 size_t chunk_size = strlen(kUploadData); 485 size_t chunk_size = strlen(kUploadData);
469 AddWrite(ConstructRequestHeadersPacket(1, !kFin)); 486 AddWrite(ConstructRequestHeadersPacket(1, !kFin));
470 AddWrite(ConstructDataPacket(2, kIncludeVersion, !kFin, 0, kUploadData)); 487 AddWrite(ConstructDataPacket(2, kIncludeVersion, !kFin, 0, kUploadData));
471 AddWrite(ConstructDataPacket(3, kIncludeVersion, kFin, chunk_size, 488 AddWrite(
472 kUploadData)); 489 ConstructDataPacket(3, kIncludeVersion, kFin, chunk_size, kUploadData));
473 AddWrite(ConstructAckPacket(4, 3, 1)); 490 AddWrite(ConstructAckPacket(4, 3, 1));
474 Initialize(); 491 Initialize();
475 492
476 UploadDataStream upload_data_stream(UploadDataStream::CHUNKED, 0); 493 UploadDataStream upload_data_stream(UploadDataStream::CHUNKED, 0);
477 upload_data_stream.AppendChunk(kUploadData, chunk_size, false); 494 upload_data_stream.AppendChunk(kUploadData, chunk_size, false);
478 495
479 request_.method = "POST"; 496 request_.method = "POST";
480 request_.url = GURL("http://www.google.com/"); 497 request_.url = GURL("http://www.google.com/");
481 request_.upload_data_stream = &upload_data_stream; 498 request_.upload_data_stream = &upload_data_stream;
482 ASSERT_EQ(OK, request_.upload_data_stream->Init(CompletionCallback())); 499 ASSERT_EQ(OK, request_.upload_data_stream->Init(CompletionCallback()));
483 500
484 ASSERT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, 501 ASSERT_EQ(OK,
485 net_log_, callback_.callback())); 502 stream_->InitializeStream(
486 ASSERT_EQ(ERR_IO_PENDING, stream_->SendRequest(headers_, &response_, 503 &request_, DEFAULT_PRIORITY, net_log_, callback_.callback()));
487 callback_.callback())); 504 ASSERT_EQ(ERR_IO_PENDING,
505 stream_->SendRequest(headers_, &response_, callback_.callback()));
488 EXPECT_EQ(&response_, stream_->GetResponseInfo()); 506 EXPECT_EQ(&response_, stream_->GetResponseInfo());
489 507
490 upload_data_stream.AppendChunk(kUploadData, chunk_size, true); 508 upload_data_stream.AppendChunk(kUploadData, chunk_size, true);
491 509
492 // Ack both packets in the request. 510 // Ack both packets in the request.
493 ProcessPacket(ConstructAckPacket(1, 0, 0)); 511 ProcessPacket(ConstructAckPacket(1, 0, 0));
494 512
495 // Send the response headers (but not the body). 513 // Send the response headers (but not the body).
496 SetResponse("200 OK", std::string()); 514 SetResponse("200 OK", std::string());
497 ProcessPacket(ConstructResponseHeadersPacket(2, !kFin)); 515 ProcessPacket(ConstructResponseHeadersPacket(2, !kFin));
498 516
499 // Since the headers have already arrived, this should return immediately. 517 // Since the headers have already arrived, this should return immediately.
500 ASSERT_EQ(OK, stream_->ReadResponseHeaders(callback_.callback())); 518 ASSERT_EQ(OK, stream_->ReadResponseHeaders(callback_.callback()));
501 ASSERT_TRUE(response_.headers.get()); 519 ASSERT_TRUE(response_.headers.get());
502 EXPECT_EQ(200, response_.headers->response_code()); 520 EXPECT_EQ(200, response_.headers->response_code());
503 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); 521 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain"));
504 522
505 // Send the response body. 523 // Send the response body.
506 const char kResponseBody[] = "Hello world!"; 524 const char kResponseBody[] = "Hello world!";
507 ProcessPacket(ConstructDataPacket(3, false, kFin, response_data_.length(), 525 ProcessPacket(ConstructDataPacket(
508 kResponseBody)); 526 3, false, kFin, response_data_.length(), kResponseBody));
509 527
510 // Since the body has already arrived, this should return immediately. 528 // Since the body has already arrived, this should return immediately.
511 ASSERT_EQ(static_cast<int>(strlen(kResponseBody)), 529 ASSERT_EQ(
512 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), 530 static_cast<int>(strlen(kResponseBody)),
513 callback_.callback())); 531 stream_->ReadResponseBody(
532 read_buffer_.get(), read_buffer_->size(), callback_.callback()));
514 533
515 EXPECT_TRUE(stream_->IsResponseBodyComplete()); 534 EXPECT_TRUE(stream_->IsResponseBodyComplete());
516 EXPECT_TRUE(AtEof()); 535 EXPECT_TRUE(AtEof());
517 } 536 }
518 537
519 TEST_P(QuicHttpStreamTest, DestroyedEarly) { 538 TEST_P(QuicHttpStreamTest, DestroyedEarly) {
520 SetRequest("GET", "/", DEFAULT_PRIORITY); 539 SetRequest("GET", "/", DEFAULT_PRIORITY);
521 AddWrite(ConstructRequestHeadersPacket(1, kFin)); 540 AddWrite(ConstructRequestHeadersPacket(1, kFin));
522 AddWrite(ConstructAckAndRstStreamPacket(2)); 541 AddWrite(ConstructAckAndRstStreamPacket(2));
523 use_closing_stream_ = true; 542 use_closing_stream_ = true;
524 Initialize(); 543 Initialize();
525 544
526 request_.method = "GET"; 545 request_.method = "GET";
527 request_.url = GURL("http://www.google.com/"); 546 request_.url = GURL("http://www.google.com/");
528 547
529 EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, 548 EXPECT_EQ(OK,
530 net_log_, callback_.callback())); 549 stream_->InitializeStream(
531 EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_, 550 &request_, DEFAULT_PRIORITY, net_log_, callback_.callback()));
532 callback_.callback())); 551 EXPECT_EQ(OK,
552 stream_->SendRequest(headers_, &response_, callback_.callback()));
533 EXPECT_EQ(&response_, stream_->GetResponseInfo()); 553 EXPECT_EQ(&response_, stream_->GetResponseInfo());
534 554
535 // Ack the request. 555 // Ack the request.
536 ProcessPacket(ConstructAckPacket(1, 0, 0)); 556 ProcessPacket(ConstructAckPacket(1, 0, 0));
537 EXPECT_EQ(ERR_IO_PENDING, 557 EXPECT_EQ(ERR_IO_PENDING, stream_->ReadResponseHeaders(callback_.callback()));
538 stream_->ReadResponseHeaders(callback_.callback()));
539 558
540 // Send the response with a body. 559 // Send the response with a body.
541 SetResponse("404 OK", "hello world!"); 560 SetResponse("404 OK", "hello world!");
542 // In the course of processing this packet, the QuicHttpStream close itself. 561 // In the course of processing this packet, the QuicHttpStream close itself.
543 ProcessPacket(ConstructResponseHeadersPacket(2, kFin)); 562 ProcessPacket(ConstructResponseHeadersPacket(2, kFin));
544 563
545 EXPECT_TRUE(AtEof()); 564 EXPECT_TRUE(AtEof());
546 } 565 }
547 566
548 TEST_P(QuicHttpStreamTest, Priority) { 567 TEST_P(QuicHttpStreamTest, Priority) {
549 SetRequest("GET", "/", MEDIUM); 568 SetRequest("GET", "/", MEDIUM);
550 AddWrite(ConstructRequestHeadersPacket(1, kFin)); 569 AddWrite(ConstructRequestHeadersPacket(1, kFin));
551 AddWrite(ConstructAckAndRstStreamPacket(2)); 570 AddWrite(ConstructAckAndRstStreamPacket(2));
552 use_closing_stream_ = true; 571 use_closing_stream_ = true;
553 Initialize(); 572 Initialize();
554 573
555 request_.method = "GET"; 574 request_.method = "GET";
556 request_.url = GURL("http://www.google.com/"); 575 request_.url = GURL("http://www.google.com/");
557 576
558 EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, 577 EXPECT_EQ(OK,
559 net_log_, callback_.callback())); 578 stream_->InitializeStream(
579 &request_, MEDIUM, net_log_, callback_.callback()));
560 580
561 // Check that priority is highest. 581 // Check that priority is highest.
562 QuicReliableClientStream* reliable_stream = 582 QuicReliableClientStream* reliable_stream =
563 QuicHttpStreamPeer::GetQuicReliableClientStream(stream_.get()); 583 QuicHttpStreamPeer::GetQuicReliableClientStream(stream_.get());
564 DCHECK(reliable_stream); 584 DCHECK(reliable_stream);
565 DCHECK_EQ(QuicWriteBlockedList::kHighestPriority, 585 DCHECK_EQ(QuicWriteBlockedList::kHighestPriority,
566 reliable_stream->EffectivePriority()); 586 reliable_stream->EffectivePriority());
567 587
568 EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_, 588 EXPECT_EQ(OK,
569 callback_.callback())); 589 stream_->SendRequest(headers_, &response_, callback_.callback()));
570 EXPECT_EQ(&response_, stream_->GetResponseInfo()); 590 EXPECT_EQ(&response_, stream_->GetResponseInfo());
571 591
572 // Check that priority has now dropped back to MEDIUM. 592 // Check that priority has now dropped back to MEDIUM.
573 DCHECK_EQ(MEDIUM, ConvertQuicPriorityToRequestPriority( 593 DCHECK_EQ(MEDIUM,
574 reliable_stream->EffectivePriority())); 594 ConvertQuicPriorityToRequestPriority(
595 reliable_stream->EffectivePriority()));
575 596
576 // Ack the request. 597 // Ack the request.
577 ProcessPacket(ConstructAckPacket(1, 0, 0)); 598 ProcessPacket(ConstructAckPacket(1, 0, 0));
578 EXPECT_EQ(ERR_IO_PENDING, 599 EXPECT_EQ(ERR_IO_PENDING, stream_->ReadResponseHeaders(callback_.callback()));
579 stream_->ReadResponseHeaders(callback_.callback()));
580 600
581 // Send the response with a body. 601 // Send the response with a body.
582 SetResponse("404 OK", "hello world!"); 602 SetResponse("404 OK", "hello world!");
583 // In the course of processing this packet, the QuicHttpStream close itself. 603 // In the course of processing this packet, the QuicHttpStream close itself.
584 ProcessPacket(ConstructResponseHeadersPacket(2, kFin)); 604 ProcessPacket(ConstructResponseHeadersPacket(2, kFin));
585 605
586 EXPECT_TRUE(AtEof()); 606 EXPECT_TRUE(AtEof());
587 } 607 }
588 608
589 // Regression test for http://crbug.com/294870 609 // Regression test for http://crbug.com/294870
590 TEST_P(QuicHttpStreamTest, CheckPriorityWithNoDelegate) { 610 TEST_P(QuicHttpStreamTest, CheckPriorityWithNoDelegate) {
591 SetRequest("GET", "/", MEDIUM); 611 SetRequest("GET", "/", MEDIUM);
592 use_closing_stream_ = true; 612 use_closing_stream_ = true;
593 613
594 AddWrite(ConstructRstStreamPacket(1)); 614 AddWrite(ConstructRstStreamPacket(1));
595 615
596 Initialize(); 616 Initialize();
597 617
598 request_.method = "GET"; 618 request_.method = "GET";
599 request_.url = GURL("http://www.google.com/"); 619 request_.url = GURL("http://www.google.com/");
600 620
601 EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, 621 EXPECT_EQ(OK,
602 net_log_, callback_.callback())); 622 stream_->InitializeStream(
623 &request_, MEDIUM, net_log_, callback_.callback()));
603 624
604 // Check that priority is highest. 625 // Check that priority is highest.
605 QuicReliableClientStream* reliable_stream = 626 QuicReliableClientStream* reliable_stream =
606 QuicHttpStreamPeer::GetQuicReliableClientStream(stream_.get()); 627 QuicHttpStreamPeer::GetQuicReliableClientStream(stream_.get());
607 DCHECK(reliable_stream); 628 DCHECK(reliable_stream);
608 QuicReliableClientStream::Delegate* delegate = reliable_stream->GetDelegate(); 629 QuicReliableClientStream::Delegate* delegate = reliable_stream->GetDelegate();
609 DCHECK(delegate); 630 DCHECK(delegate);
610 DCHECK_EQ(QuicWriteBlockedList::kHighestPriority, 631 DCHECK_EQ(QuicWriteBlockedList::kHighestPriority,
611 reliable_stream->EffectivePriority()); 632 reliable_stream->EffectivePriority());
612 633
613 // Set Delegate to NULL and make sure EffectivePriority returns highest 634 // Set Delegate to NULL and make sure EffectivePriority returns highest
614 // priority. 635 // priority.
615 reliable_stream->SetDelegate(NULL); 636 reliable_stream->SetDelegate(NULL);
616 DCHECK_EQ(QuicWriteBlockedList::kHighestPriority, 637 DCHECK_EQ(QuicWriteBlockedList::kHighestPriority,
617 reliable_stream->EffectivePriority()); 638 reliable_stream->EffectivePriority());
618 reliable_stream->SetDelegate(delegate); 639 reliable_stream->SetDelegate(delegate);
619 } 640 }
620 641
621 } // namespace test 642 } // namespace test
622 } // namespace net 643 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698