| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/http/http_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "net/base/auth.h" | 10 #include "net/base/auth.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 SPDYSSL, | 33 SPDYSSL, |
| 34 }; | 34 }; |
| 35 class SpdyNetworkTransactionTest | 35 class SpdyNetworkTransactionTest |
| 36 : public ::testing::TestWithParam<SpdyNetworkTransactionTestTypes> { | 36 : public ::testing::TestWithParam<SpdyNetworkTransactionTestTypes> { |
| 37 protected: | 37 protected: |
| 38 virtual void SetUp() { | 38 virtual void SetUp() { |
| 39 // By default, all tests turn off compression. | 39 // By default, all tests turn off compression. |
| 40 EnableCompression(false); | 40 EnableCompression(false); |
| 41 google_get_request_initialized_ = false; | 41 google_get_request_initialized_ = false; |
| 42 google_post_request_initialized_ = false; | 42 google_post_request_initialized_ = false; |
| 43 google_chunked_post_request_initialized_ = false; |
| 43 } | 44 } |
| 44 | 45 |
| 45 virtual void TearDown() { | 46 virtual void TearDown() { |
| 46 // Empty the current queue. | 47 // Empty the current queue. |
| 47 MessageLoop::current()->RunAllPending(); | 48 MessageLoop::current()->RunAllPending(); |
| 48 } | 49 } |
| 49 | 50 |
| 50 struct TransactionHelperResult { | 51 struct TransactionHelperResult { |
| 51 int rv; | 52 int rv; |
| 52 std::string status_line; | 53 std::string status_line; |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 google_post_request_.method = "POST"; | 344 google_post_request_.method = "POST"; |
| 344 google_post_request_.url = GURL(kDefaultURL); | 345 google_post_request_.url = GURL(kDefaultURL); |
| 345 google_post_request_.upload_data = new UploadData(); | 346 google_post_request_.upload_data = new UploadData(); |
| 346 google_post_request_.upload_data->AppendBytes(kUploadData, | 347 google_post_request_.upload_data->AppendBytes(kUploadData, |
| 347 kUploadDataSize); | 348 kUploadDataSize); |
| 348 google_post_request_initialized_ = true; | 349 google_post_request_initialized_ = true; |
| 349 } | 350 } |
| 350 return google_post_request_; | 351 return google_post_request_; |
| 351 } | 352 } |
| 352 | 353 |
| 354 const HttpRequestInfo& CreateChunkedPostRequest() { |
| 355 if (!google_chunked_post_request_initialized_) { |
| 356 google_chunked_post_request_.method = "POST"; |
| 357 google_chunked_post_request_.url = GURL(kDefaultURL); |
| 358 google_chunked_post_request_.upload_data = new UploadData(); |
| 359 google_chunked_post_request_.upload_data->set_is_chunked(true); |
| 360 google_chunked_post_request_.upload_data->AppendChunk( |
| 361 kUploadData, kUploadDataSize, false); |
| 362 google_chunked_post_request_.upload_data->AppendChunk( |
| 363 kUploadData, kUploadDataSize, true); |
| 364 google_chunked_post_request_initialized_ = true; |
| 365 } |
| 366 return google_chunked_post_request_; |
| 367 } |
| 368 |
| 353 // Read the result of a particular transaction, knowing that we've got | 369 // Read the result of a particular transaction, knowing that we've got |
| 354 // multiple transactions in the read pipeline; so as we read, we may have | 370 // multiple transactions in the read pipeline; so as we read, we may have |
| 355 // to skip over data destined for other transactions while we consume | 371 // to skip over data destined for other transactions while we consume |
| 356 // the data for |trans|. | 372 // the data for |trans|. |
| 357 int ReadResult(HttpNetworkTransaction* trans, | 373 int ReadResult(HttpNetworkTransaction* trans, |
| 358 StaticSocketDataProvider* data, | 374 StaticSocketDataProvider* data, |
| 359 std::string* result) { | 375 std::string* result) { |
| 360 const int kSize = 3000; | 376 const int kSize = 3000; |
| 361 | 377 |
| 362 int bytes_read = 0; | 378 int bytes_read = 0; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 // Copy the response info, because trans goes away. | 463 // Copy the response info, because trans goes away. |
| 448 *response = *trans->GetResponseInfo(); | 464 *response = *trans->GetResponseInfo(); |
| 449 *push_response = *trans2->GetResponseInfo(); | 465 *push_response = *trans2->GetResponseInfo(); |
| 450 | 466 |
| 451 VerifyStreamsClosed(helper); | 467 VerifyStreamsClosed(helper); |
| 452 } | 468 } |
| 453 | 469 |
| 454 private: | 470 private: |
| 455 bool google_get_request_initialized_; | 471 bool google_get_request_initialized_; |
| 456 bool google_post_request_initialized_; | 472 bool google_post_request_initialized_; |
| 473 bool google_chunked_post_request_initialized_; |
| 457 HttpRequestInfo google_get_request_; | 474 HttpRequestInfo google_get_request_; |
| 458 HttpRequestInfo google_post_request_; | 475 HttpRequestInfo google_post_request_; |
| 476 HttpRequestInfo google_chunked_post_request_; |
| 459 HttpRequestInfo google_get_push_request_; | 477 HttpRequestInfo google_get_push_request_; |
| 460 }; | 478 }; |
| 461 | 479 |
| 462 //----------------------------------------------------------------------------- | 480 //----------------------------------------------------------------------------- |
| 463 // All tests are run with three different connection types: SPDY after NPN | 481 // All tests are run with three different connection types: SPDY after NPN |
| 464 // negotiation, SPDY without SSL, and SPDY with SSL. | 482 // negotiation, SPDY without SSL, and SPDY with SSL. |
| 465 INSTANTIATE_TEST_CASE_P(Spdy, | 483 INSTANTIATE_TEST_CASE_P(Spdy, |
| 466 SpdyNetworkTransactionTest, | 484 SpdyNetworkTransactionTest, |
| 467 ::testing::Values(SPDYNOSSL, SPDYSSL, SPDYNPN)); | 485 ::testing::Values(SPDYNOSSL, SPDYSSL, SPDYNPN)); |
| 468 | 486 |
| (...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1518 writes, arraysize(writes))); | 1536 writes, arraysize(writes))); |
| 1519 NormalSpdyTransactionHelper helper(CreatePostRequest(), | 1537 NormalSpdyTransactionHelper helper(CreatePostRequest(), |
| 1520 BoundNetLog(), GetParam()); | 1538 BoundNetLog(), GetParam()); |
| 1521 helper.RunToCompletion(data.get()); | 1539 helper.RunToCompletion(data.get()); |
| 1522 TransactionHelperResult out = helper.output(); | 1540 TransactionHelperResult out = helper.output(); |
| 1523 EXPECT_EQ(OK, out.rv); | 1541 EXPECT_EQ(OK, out.rv); |
| 1524 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 1542 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1525 EXPECT_EQ("hello!", out.response_data); | 1543 EXPECT_EQ("hello!", out.response_data); |
| 1526 } | 1544 } |
| 1527 | 1545 |
| 1546 // Test that a chunked POST works. |
| 1547 TEST_P(SpdyNetworkTransactionTest, ChunkedPost) { |
| 1548 UploadDataStream::set_merge_chunks(false); |
| 1549 scoped_ptr<spdy::SpdyFrame> req(ConstructChunkedSpdyPost(NULL, 0)); |
| 1550 scoped_ptr<spdy::SpdyFrame> chunk1(ConstructSpdyBodyFrame(1, false)); |
| 1551 scoped_ptr<spdy::SpdyFrame> chunk2(ConstructSpdyBodyFrame(1, true)); |
| 1552 MockWrite writes[] = { |
| 1553 CreateMockWrite(*req), |
| 1554 CreateMockWrite(*chunk1), |
| 1555 CreateMockWrite(*chunk2), |
| 1556 }; |
| 1557 |
| 1558 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0)); |
| 1559 MockRead reads[] = { |
| 1560 CreateMockRead(*resp), |
| 1561 CreateMockRead(*chunk1), |
| 1562 CreateMockRead(*chunk2), |
| 1563 MockRead(true, 0, 0) // EOF |
| 1564 }; |
| 1565 |
| 1566 scoped_refptr<DelayedSocketData> data( |
| 1567 new DelayedSocketData(2, reads, arraysize(reads), |
| 1568 writes, arraysize(writes))); |
| 1569 NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), |
| 1570 BoundNetLog(), GetParam()); |
| 1571 helper.RunToCompletion(data.get()); |
| 1572 TransactionHelperResult out = helper.output(); |
| 1573 EXPECT_EQ(OK, out.rv); |
| 1574 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1575 EXPECT_EQ("hello!hello!", out.response_data); |
| 1576 } |
| 1577 |
| 1528 // Test that a POST without any post data works. | 1578 // Test that a POST without any post data works. |
| 1529 TEST_P(SpdyNetworkTransactionTest, NullPost) { | 1579 TEST_P(SpdyNetworkTransactionTest, NullPost) { |
| 1530 // Setup the request | 1580 // Setup the request |
| 1531 HttpRequestInfo request; | 1581 HttpRequestInfo request; |
| 1532 request.method = "POST"; | 1582 request.method = "POST"; |
| 1533 request.url = GURL("http://www.google.com/"); | 1583 request.url = GURL("http://www.google.com/"); |
| 1534 // Create an empty UploadData. | 1584 // Create an empty UploadData. |
| 1535 request.upload_data = NULL; | 1585 request.upload_data = NULL; |
| 1536 | 1586 |
| 1537 // When request.upload_data is NULL for post, content-length is | 1587 // When request.upload_data is NULL for post, content-length is |
| (...skipping 4060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5598 | 5648 |
| 5599 VerifyStreamsClosed(helper); | 5649 VerifyStreamsClosed(helper); |
| 5600 | 5650 |
| 5601 // Verify the SYN_REPLY. | 5651 // Verify the SYN_REPLY. |
| 5602 EXPECT_TRUE(response.headers != NULL); | 5652 EXPECT_TRUE(response.headers != NULL); |
| 5603 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 5653 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 5604 } | 5654 } |
| 5605 } | 5655 } |
| 5606 | 5656 |
| 5607 } // namespace net | 5657 } // namespace net |
| OLD | NEW |