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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 MockClock clock_; | 76 MockClock clock_; |
77 QuicCongestionFeedbackFrame* feedback_; | 77 QuicCongestionFeedbackFrame* feedback_; |
78 | 78 |
79 DISALLOW_COPY_AND_ASSIGN(TestReceiveAlgorithm); | 79 DISALLOW_COPY_AND_ASSIGN(TestReceiveAlgorithm); |
80 }; | 80 }; |
81 | 81 |
82 // Subclass of QuicHttpStream that closes itself when the first piece of data | 82 // Subclass of QuicHttpStream that closes itself when the first piece of data |
83 // is received. | 83 // is received. |
84 class AutoClosingStream : public QuicHttpStream { | 84 class AutoClosingStream : public QuicHttpStream { |
85 public: | 85 public: |
86 AutoClosingStream(QuicReliableClientStream* stream, bool use_spdy) | 86 explicit AutoClosingStream(QuicReliableClientStream* stream) |
87 : QuicHttpStream(stream, use_spdy) { | 87 : QuicHttpStream(stream) { |
88 } | 88 } |
89 | 89 |
90 virtual int OnDataReceived(const char* data, int length) OVERRIDE { | 90 virtual int OnDataReceived(const char* data, int length) OVERRIDE { |
91 Close(false); | 91 Close(false); |
92 return OK; | 92 return OK; |
93 } | 93 } |
94 }; | 94 }; |
95 | 95 |
96 } // namespace | 96 } // namespace |
97 | 97 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 connection_->SetReceiveAlgorithm(receive_algorithm_); | 176 connection_->SetReceiveAlgorithm(receive_algorithm_); |
177 session_.reset(new QuicClientSession(connection_, helper_, NULL, | 177 session_.reset(new QuicClientSession(connection_, helper_, NULL, |
178 "www.google.com", NULL)); | 178 "www.google.com", NULL)); |
179 CryptoHandshakeMessage message; | 179 CryptoHandshakeMessage message; |
180 message.tag = kSHLO; | 180 message.tag = kSHLO; |
181 session_->GetCryptoStream()->OnHandshakeMessage(message); | 181 session_->GetCryptoStream()->OnHandshakeMessage(message); |
182 EXPECT_TRUE(session_->IsCryptoHandshakeComplete()); | 182 EXPECT_TRUE(session_->IsCryptoHandshakeComplete()); |
183 QuicReliableClientStream* stream = | 183 QuicReliableClientStream* stream = |
184 session_->CreateOutgoingReliableStream(); | 184 session_->CreateOutgoingReliableStream(); |
185 stream_.reset(use_closing_stream_ ? | 185 stream_.reset(use_closing_stream_ ? |
186 new AutoClosingStream(stream, GetParam()) : | 186 new AutoClosingStream(stream) : |
187 new QuicHttpStream(stream, GetParam())); | 187 new QuicHttpStream(stream)); |
188 } | 188 } |
189 | 189 |
190 void SetRequestString(const std::string& method, const std::string& path) { | 190 void SetRequestString(const std::string& method, const std::string& path) { |
191 if (GetParam() == true) { | 191 SpdyHeaderBlock headers; |
192 SpdyHeaderBlock headers; | 192 headers[":method"] = method; |
193 headers[":method"] = method; | 193 headers[":host"] = "www.google.com"; |
194 headers[":host"] = "www.google.com"; | 194 headers[":path"] = path; |
195 headers[":path"] = path; | 195 headers[":scheme"] = "http"; |
196 headers[":scheme"] = "http"; | 196 headers[":version"] = "HTTP/1.1"; |
197 headers[":version"] = "HTTP/1.1"; | 197 request_data_ = SerializeHeaderBlock(headers); |
198 request_data_ = SerializeHeaderBlock(headers); | |
199 } else { | |
200 request_data_ = method + " " + path + " HTTP/1.1\r\n\r\n"; | |
201 } | |
202 } | 198 } |
203 | 199 |
204 void SetResponseString(const std::string& status, const std::string& body) { | 200 void SetResponseString(const std::string& status, const std::string& body) { |
205 if (GetParam() == true) { | 201 SpdyHeaderBlock headers; |
206 SpdyHeaderBlock headers; | 202 headers[":status"] = status; |
207 headers[":status"] = status; | 203 headers[":version"] = "HTTP/1.1"; |
208 headers[":version"] = "HTTP/1.1"; | 204 headers["content-type"] = "text/plain"; |
209 headers["content-type"] = "text/plain"; | 205 response_data_ = SerializeHeaderBlock(headers) + body; |
210 response_data_ = SerializeHeaderBlock(headers) + body; | |
211 } else { | |
212 response_data_ = "HTTP/1.1 " + status + " \r\n" | |
213 "Content-Type: text/plain\r\n\r\n" + body; | |
214 } | |
215 } | 206 } |
216 | 207 |
217 std::string SerializeHeaderBlock(const SpdyHeaderBlock& headers) { | 208 std::string SerializeHeaderBlock(const SpdyHeaderBlock& headers) { |
218 size_t len = SpdyFramer::GetSerializedLength(3, &headers); | 209 size_t len = SpdyFramer::GetSerializedLength(3, &headers); |
219 SpdyFrameBuilder builder(len); | 210 SpdyFrameBuilder builder(len); |
220 SpdyFramer::WriteHeaderBlock(&builder, 3, &headers); | 211 SpdyFramer::WriteHeaderBlock(&builder, 3, &headers); |
221 scoped_ptr<SpdyFrame> frame(builder.take()); | 212 scoped_ptr<SpdyFrame> frame(builder.take()); |
222 return std::string(frame->data(), len); | 213 return std::string(frame->data(), len); |
223 } | 214 } |
224 | 215 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 QuicFramer framer_; | 294 QuicFramer framer_; |
304 IPEndPoint self_addr_; | 295 IPEndPoint self_addr_; |
305 IPEndPoint peer_addr_; | 296 IPEndPoint peer_addr_; |
306 MockRandom random_; | 297 MockRandom random_; |
307 QuicPacketCreator creator_; | 298 QuicPacketCreator creator_; |
308 QuicPacketHeader header_; | 299 QuicPacketHeader header_; |
309 scoped_ptr<StaticSocketDataProvider> socket_data_; | 300 scoped_ptr<StaticSocketDataProvider> socket_data_; |
310 std::vector<PacketToWrite> writes_; | 301 std::vector<PacketToWrite> writes_; |
311 }; | 302 }; |
312 | 303 |
313 // All tests are run with two different serializations, HTTP/SPDY | 304 TEST_F(QuicHttpStreamTest, RenewStreamForAuth) { |
314 INSTANTIATE_TEST_CASE_P(QuicHttpStreamTests, | |
315 QuicHttpStreamTest, | |
316 ::testing::Values(true, false)); | |
317 | |
318 TEST_P(QuicHttpStreamTest, RenewStreamForAuth) { | |
319 EXPECT_EQ(NULL, stream_->RenewStreamForAuth()); | 305 EXPECT_EQ(NULL, stream_->RenewStreamForAuth()); |
320 } | 306 } |
321 | 307 |
322 TEST_P(QuicHttpStreamTest, CanFindEndOfResponse) { | 308 TEST_F(QuicHttpStreamTest, CanFindEndOfResponse) { |
323 EXPECT_TRUE(stream_->CanFindEndOfResponse()); | 309 EXPECT_TRUE(stream_->CanFindEndOfResponse()); |
324 } | 310 } |
325 | 311 |
326 TEST_P(QuicHttpStreamTest, IsMoreDataBuffered) { | 312 TEST_F(QuicHttpStreamTest, IsMoreDataBuffered) { |
327 EXPECT_FALSE(stream_->IsMoreDataBuffered()); | 313 EXPECT_FALSE(stream_->IsMoreDataBuffered()); |
328 } | 314 } |
329 | 315 |
330 TEST_P(QuicHttpStreamTest, IsConnectionReusable) { | 316 TEST_F(QuicHttpStreamTest, IsConnectionReusable) { |
331 EXPECT_FALSE(stream_->IsConnectionReusable()); | 317 EXPECT_FALSE(stream_->IsConnectionReusable()); |
332 } | 318 } |
333 | 319 |
334 TEST_P(QuicHttpStreamTest, GetRequest) { | 320 TEST_F(QuicHttpStreamTest, GetRequest) { |
335 SetRequestString("GET", "/"); | 321 SetRequestString("GET", "/"); |
336 AddWrite(SYNCHRONOUS, ConstructDataPacket(1, kFin, 0, | 322 AddWrite(SYNCHRONOUS, ConstructDataPacket(1, kFin, 0, |
337 request_data_)); | 323 request_data_)); |
338 AddWrite(SYNCHRONOUS, ConstructAckPacket(2, 2, 2)); | 324 AddWrite(SYNCHRONOUS, ConstructAckPacket(2, 2, 2)); |
339 Initialize(); | 325 Initialize(); |
340 | 326 |
341 request_.method = "GET"; | 327 request_.method = "GET"; |
342 request_.url = GURL("http://www.google.com/"); | 328 request_.url = GURL("http://www.google.com/"); |
343 | 329 |
344 EXPECT_EQ(OK, stream_->InitializeStream(&request_, net_log_, | 330 EXPECT_EQ(OK, stream_->InitializeStream(&request_, net_log_, |
(...skipping 22 matching lines...) Expand all Loading... |
367 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); | 353 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
368 | 354 |
369 // There is no body, so this should return immediately. | 355 // There is no body, so this should return immediately. |
370 EXPECT_EQ(0, stream_->ReadResponseBody(read_buffer_.get(), | 356 EXPECT_EQ(0, stream_->ReadResponseBody(read_buffer_.get(), |
371 read_buffer_->size(), | 357 read_buffer_->size(), |
372 callback_.callback())); | 358 callback_.callback())); |
373 EXPECT_TRUE(stream_->IsResponseBodyComplete()); | 359 EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
374 EXPECT_TRUE(AtEof()); | 360 EXPECT_TRUE(AtEof()); |
375 } | 361 } |
376 | 362 |
377 TEST_P(QuicHttpStreamTest, GetRequestFullResponseInSinglePacket) { | 363 TEST_F(QuicHttpStreamTest, GetRequestFullResponseInSinglePacket) { |
378 SetRequestString("GET", "/"); | 364 SetRequestString("GET", "/"); |
379 AddWrite(SYNCHRONOUS, ConstructDataPacket(1, kFin, 0, request_data_)); | 365 AddWrite(SYNCHRONOUS, ConstructDataPacket(1, kFin, 0, request_data_)); |
380 AddWrite(SYNCHRONOUS, ConstructAckPacket(2, 2, 2)); | 366 AddWrite(SYNCHRONOUS, ConstructAckPacket(2, 2, 2)); |
381 Initialize(); | 367 Initialize(); |
382 | 368 |
383 request_.method = "GET"; | 369 request_.method = "GET"; |
384 request_.url = GURL("http://www.google.com/"); | 370 request_.url = GURL("http://www.google.com/"); |
385 | 371 |
386 EXPECT_EQ(OK, stream_->InitializeStream(&request_, net_log_, | 372 EXPECT_EQ(OK, stream_->InitializeStream(&request_, net_log_, |
387 callback_.callback())); | 373 callback_.callback())); |
(...skipping 22 matching lines...) Expand all Loading... |
410 | 396 |
411 // There is no body, so this should return immediately. | 397 // There is no body, so this should return immediately. |
412 // Since the body has already arrived, this should return immediately. | 398 // Since the body has already arrived, this should return immediately. |
413 EXPECT_EQ(12, stream_->ReadResponseBody(read_buffer_.get(), | 399 EXPECT_EQ(12, stream_->ReadResponseBody(read_buffer_.get(), |
414 read_buffer_->size(), | 400 read_buffer_->size(), |
415 callback_.callback())); | 401 callback_.callback())); |
416 EXPECT_TRUE(stream_->IsResponseBodyComplete()); | 402 EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
417 EXPECT_TRUE(AtEof()); | 403 EXPECT_TRUE(AtEof()); |
418 } | 404 } |
419 | 405 |
420 TEST_P(QuicHttpStreamTest, SendPostRequest) { | 406 TEST_F(QuicHttpStreamTest, SendPostRequest) { |
421 SetRequestString("POST", "/"); | 407 SetRequestString("POST", "/"); |
422 AddWrite(SYNCHRONOUS, ConstructDataPacket(1, !kFin, 0, request_data_)); | 408 AddWrite(SYNCHRONOUS, ConstructDataPacket(1, !kFin, 0, request_data_)); |
423 AddWrite(SYNCHRONOUS, ConstructDataPacket(2, kFin, request_data_.length(), | 409 AddWrite(SYNCHRONOUS, ConstructDataPacket(2, kFin, request_data_.length(), |
424 kUploadData)); | 410 kUploadData)); |
425 AddWrite(SYNCHRONOUS, ConstructAckPacket(3, 2, 3)); | 411 AddWrite(SYNCHRONOUS, ConstructAckPacket(3, 2, 3)); |
426 | 412 |
427 Initialize(); | 413 Initialize(); |
428 | 414 |
429 ScopedVector<UploadElementReader> element_readers; | 415 ScopedVector<UploadElementReader> element_readers; |
430 element_readers.push_back( | 416 element_readers.push_back( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 | 451 |
466 // Since the body has already arrived, this should return immediately. | 452 // Since the body has already arrived, this should return immediately. |
467 EXPECT_EQ(static_cast<int>(strlen(kResponseBody)), | 453 EXPECT_EQ(static_cast<int>(strlen(kResponseBody)), |
468 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), | 454 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), |
469 callback_.callback())); | 455 callback_.callback())); |
470 | 456 |
471 EXPECT_TRUE(stream_->IsResponseBodyComplete()); | 457 EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
472 EXPECT_TRUE(AtEof()); | 458 EXPECT_TRUE(AtEof()); |
473 } | 459 } |
474 | 460 |
475 TEST_P(QuicHttpStreamTest, DestroyedEarly) { | 461 TEST_F(QuicHttpStreamTest, DestroyedEarly) { |
476 SetRequestString("GET", "/"); | 462 SetRequestString("GET", "/"); |
477 AddWrite(SYNCHRONOUS, ConstructDataPacket(1, kFin, 0, request_data_)); | 463 AddWrite(SYNCHRONOUS, ConstructDataPacket(1, kFin, 0, request_data_)); |
478 AddWrite(SYNCHRONOUS, ConstructRstPacket(2, 3)); | 464 AddWrite(SYNCHRONOUS, ConstructRstPacket(2, 3)); |
479 AddWrite(SYNCHRONOUS, ConstructAckPacket(3, 2, 2)); | 465 AddWrite(SYNCHRONOUS, ConstructAckPacket(3, 2, 2)); |
480 use_closing_stream_ = true; | 466 use_closing_stream_ = true; |
481 Initialize(); | 467 Initialize(); |
482 | 468 |
483 request_.method = "GET"; | 469 request_.method = "GET"; |
484 request_.url = GURL("http://www.google.com/"); | 470 request_.url = GURL("http://www.google.com/"); |
485 | 471 |
(...skipping 17 matching lines...) Expand all Loading... |
503 | 489 |
504 // In the course of processing this packet, the QuicHttpStream close itself. | 490 // In the course of processing this packet, the QuicHttpStream close itself. |
505 ProcessPacket(*resp); | 491 ProcessPacket(*resp); |
506 | 492 |
507 EXPECT_TRUE(AtEof()); | 493 EXPECT_TRUE(AtEof()); |
508 } | 494 } |
509 | 495 |
510 } // namespace test | 496 } // namespace test |
511 | 497 |
512 } // namespace net | 498 } // namespace net |
OLD | NEW |