| 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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 stream_->ReadResponseHeaders(callback_.callback())); | 344 stream_->ReadResponseHeaders(callback_.callback())); |
| 345 | 345 |
| 346 // Send the response without a body. | 346 // Send the response without a body. |
| 347 SetResponseString("404 Not Found", std::string()); | 347 SetResponseString("404 Not Found", std::string()); |
| 348 scoped_ptr<QuicEncryptedPacket> resp( | 348 scoped_ptr<QuicEncryptedPacket> resp( |
| 349 ConstructDataPacket(2, false, kFin, 0, response_data_)); | 349 ConstructDataPacket(2, false, kFin, 0, response_data_)); |
| 350 ProcessPacket(*resp); | 350 ProcessPacket(*resp); |
| 351 | 351 |
| 352 // Now that the headers have been processed, the callback will return. | 352 // Now that the headers have been processed, the callback will return. |
| 353 EXPECT_EQ(OK, callback_.WaitForResult()); | 353 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 354 ASSERT_TRUE(response_.headers.get() != NULL); | 354 ASSERT_TRUE(response_.headers); |
| 355 EXPECT_EQ(404, response_.headers->response_code()); | 355 EXPECT_EQ(404, response_.headers->response_code()); |
| 356 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); | 356 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
| 357 | 357 |
| 358 // There is no body, so this should return immediately. | 358 // There is no body, so this should return immediately. |
| 359 EXPECT_EQ(0, stream_->ReadResponseBody(read_buffer_.get(), | 359 EXPECT_EQ(0, stream_->ReadResponseBody(read_buffer_.get(), |
| 360 read_buffer_->size(), | 360 read_buffer_->size(), |
| 361 callback_.callback())); | 361 callback_.callback())); |
| 362 EXPECT_TRUE(stream_->IsResponseBodyComplete()); | 362 EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
| 363 EXPECT_TRUE(AtEof()); | 363 EXPECT_TRUE(AtEof()); |
| 364 } | 364 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 386 stream_->ReadResponseHeaders(callback_.callback())); | 386 stream_->ReadResponseHeaders(callback_.callback())); |
| 387 | 387 |
| 388 // Send the response with a body. | 388 // Send the response with a body. |
| 389 SetResponseString("200 OK", "hello world!"); | 389 SetResponseString("200 OK", "hello world!"); |
| 390 scoped_ptr<QuicEncryptedPacket> resp( | 390 scoped_ptr<QuicEncryptedPacket> resp( |
| 391 ConstructDataPacket(2, false, kFin, 0, response_data_)); | 391 ConstructDataPacket(2, false, kFin, 0, response_data_)); |
| 392 ProcessPacket(*resp); | 392 ProcessPacket(*resp); |
| 393 | 393 |
| 394 // Now that the headers have been processed, the callback will return. | 394 // Now that the headers have been processed, the callback will return. |
| 395 EXPECT_EQ(OK, callback_.WaitForResult()); | 395 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 396 ASSERT_TRUE(response_.headers.get() != NULL); | 396 ASSERT_TRUE(response_.headers); |
| 397 EXPECT_EQ(200, response_.headers->response_code()); | 397 EXPECT_EQ(200, response_.headers->response_code()); |
| 398 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); | 398 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
| 399 | 399 |
| 400 // There is no body, so this should return immediately. | 400 // There is no body, so this should return immediately. |
| 401 // Since the body has already arrived, this should return immediately. | 401 // Since the body has already arrived, this should return immediately. |
| 402 EXPECT_EQ(12, stream_->ReadResponseBody(read_buffer_.get(), | 402 EXPECT_EQ(12, stream_->ReadResponseBody(read_buffer_.get(), |
| 403 read_buffer_->size(), | 403 read_buffer_->size(), |
| 404 callback_.callback())); | 404 callback_.callback())); |
| 405 EXPECT_TRUE(stream_->IsResponseBodyComplete()); | 405 EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
| 406 EXPECT_TRUE(AtEof()); | 406 EXPECT_TRUE(AtEof()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 436 ProcessPacket(*ack); | 436 ProcessPacket(*ack); |
| 437 | 437 |
| 438 // Send the response headers (but not the body). | 438 // Send the response headers (but not the body). |
| 439 SetResponseString("200 OK", std::string()); | 439 SetResponseString("200 OK", std::string()); |
| 440 scoped_ptr<QuicEncryptedPacket> resp( | 440 scoped_ptr<QuicEncryptedPacket> resp( |
| 441 ConstructDataPacket(2, false, !kFin, 0, response_data_)); | 441 ConstructDataPacket(2, false, !kFin, 0, response_data_)); |
| 442 ProcessPacket(*resp); | 442 ProcessPacket(*resp); |
| 443 | 443 |
| 444 // Since the headers have already arrived, this should return immediately. | 444 // Since the headers have already arrived, this should return immediately. |
| 445 EXPECT_EQ(OK, stream_->ReadResponseHeaders(callback_.callback())); | 445 EXPECT_EQ(OK, stream_->ReadResponseHeaders(callback_.callback())); |
| 446 ASSERT_TRUE(response_.headers.get() != NULL); | 446 ASSERT_TRUE(response_.headers); |
| 447 EXPECT_EQ(200, response_.headers->response_code()); | 447 EXPECT_EQ(200, response_.headers->response_code()); |
| 448 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); | 448 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
| 449 | 449 |
| 450 // Send the response body. | 450 // Send the response body. |
| 451 const char kResponseBody[] = "Hello world!"; | 451 const char kResponseBody[] = "Hello world!"; |
| 452 scoped_ptr<QuicEncryptedPacket> resp_body( | 452 scoped_ptr<QuicEncryptedPacket> resp_body( |
| 453 ConstructDataPacket(3, false, kFin, response_data_.length(), | 453 ConstructDataPacket(3, false, kFin, response_data_.length(), |
| 454 kResponseBody)); | 454 kResponseBody)); |
| 455 ProcessPacket(*resp_body); | 455 ProcessPacket(*resp_body); |
| 456 | 456 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 ProcessPacket(*ack); | 498 ProcessPacket(*ack); |
| 499 | 499 |
| 500 // Send the response headers (but not the body). | 500 // Send the response headers (but not the body). |
| 501 SetResponseString("200 OK", std::string()); | 501 SetResponseString("200 OK", std::string()); |
| 502 scoped_ptr<QuicEncryptedPacket> resp( | 502 scoped_ptr<QuicEncryptedPacket> resp( |
| 503 ConstructDataPacket(2, false, !kFin, 0, response_data_)); | 503 ConstructDataPacket(2, false, !kFin, 0, response_data_)); |
| 504 ProcessPacket(*resp); | 504 ProcessPacket(*resp); |
| 505 | 505 |
| 506 // Since the headers have already arrived, this should return immediately. | 506 // Since the headers have already arrived, this should return immediately. |
| 507 ASSERT_EQ(OK, stream_->ReadResponseHeaders(callback_.callback())); | 507 ASSERT_EQ(OK, stream_->ReadResponseHeaders(callback_.callback())); |
| 508 ASSERT_TRUE(response_.headers.get() != NULL); | 508 ASSERT_TRUE(response_.headers); |
| 509 EXPECT_EQ(200, response_.headers->response_code()); | 509 EXPECT_EQ(200, response_.headers->response_code()); |
| 510 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); | 510 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
| 511 | 511 |
| 512 // Send the response body. | 512 // Send the response body. |
| 513 const char kResponseBody[] = "Hello world!"; | 513 const char kResponseBody[] = "Hello world!"; |
| 514 scoped_ptr<QuicEncryptedPacket> resp_body( | 514 scoped_ptr<QuicEncryptedPacket> resp_body( |
| 515 ConstructDataPacket(3, false, kFin, response_data_.length(), | 515 ConstructDataPacket(3, false, kFin, response_data_.length(), |
| 516 kResponseBody)); | 516 kResponseBody)); |
| 517 ProcessPacket(*resp_body); | 517 ProcessPacket(*resp_body); |
| 518 | 518 |
| 519 // Since the body has already arrived, this should return immediately. | 519 // Since the body has already arrived, this should return immediately. |
| 520 ASSERT_EQ(static_cast<int>(strlen(kResponseBody)), | 520 ASSERT_EQ(static_cast<int>(strlen(kResponseBody)), |
| 521 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), | 521 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), |
| 522 callback_.callback())); | 522 callback_.callback())); |
| 523 | 523 |
| 524 EXPECT_TRUE(stream_->IsResponseBodyComplete()); | 524 EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
| 525 EXPECT_TRUE(AtEof()); | 525 EXPECT_TRUE(AtEof()); |
| 526 } | 526 } |
| 527 | 527 |
| 528 TEST_F(QuicHttpStreamTest, DestroyedEarly) { | 528 TEST_F(QuicHttpStreamTest, DestroyedEarly) { |
| 529 SetRequestString("GET", "/"); | 529 SetRequestString("GET", "/"); |
| 530 AddWrite(SYNCHRONOUS, ConstructDataPacket(1, true, kFin, 0, request_data_)); | 530 AddWrite(SYNCHRONOUS, ConstructDataPacket(1, true, kFin, 0, request_data_)); |
| 531 AddWrite(SYNCHRONOUS, ConstructRstPacket(2, 3)); | 531 AddWrite(SYNCHRONOUS, ConstructAckPacket(2, 2, 1)); |
| 532 AddWrite(SYNCHRONOUS, ConstructAckPacket(3, 2, 1)); | |
| 533 use_closing_stream_ = true; | 532 use_closing_stream_ = true; |
| 534 Initialize(); | 533 Initialize(); |
| 535 | 534 |
| 536 request_.method = "GET"; | 535 request_.method = "GET"; |
| 537 request_.url = GURL("http://www.google.com/"); | 536 request_.url = GURL("http://www.google.com/"); |
| 538 | 537 |
| 539 EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, | 538 EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 540 net_log_, callback_.callback())); | 539 net_log_, callback_.callback())); |
| 541 EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_, | 540 EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_, |
| 542 callback_.callback())); | 541 callback_.callback())); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 555 | 554 |
| 556 // In the course of processing this packet, the QuicHttpStream close itself. | 555 // In the course of processing this packet, the QuicHttpStream close itself. |
| 557 ProcessPacket(*resp); | 556 ProcessPacket(*resp); |
| 558 | 557 |
| 559 EXPECT_TRUE(AtEof()); | 558 EXPECT_TRUE(AtEof()); |
| 560 } | 559 } |
| 561 | 560 |
| 562 } // namespace test | 561 } // namespace test |
| 563 | 562 |
| 564 } // namespace net | 563 } // namespace net |
| OLD | NEW |