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(kUploadData, |
| 361 kUploadDataSize); |
| 362 google_chunked_post_request_.upload_data->AppendChunk(NULL, 0); |
| 363 google_chunked_post_request_initialized_ = true; |
| 364 } |
| 365 return google_chunked_post_request_; |
| 366 } |
| 367 |
353 // Read the result of a particular transaction, knowing that we've got | 368 // 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 | 369 // 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 | 370 // to skip over data destined for other transactions while we consume |
356 // the data for |trans|. | 371 // the data for |trans|. |
357 int ReadResult(HttpNetworkTransaction* trans, | 372 int ReadResult(HttpNetworkTransaction* trans, |
358 StaticSocketDataProvider* data, | 373 StaticSocketDataProvider* data, |
359 std::string* result) { | 374 std::string* result) { |
360 const int kSize = 3000; | 375 const int kSize = 3000; |
361 | 376 |
362 int bytes_read = 0; | 377 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. | 462 // Copy the response info, because trans goes away. |
448 *response = *trans->GetResponseInfo(); | 463 *response = *trans->GetResponseInfo(); |
449 *push_response = *trans2->GetResponseInfo(); | 464 *push_response = *trans2->GetResponseInfo(); |
450 | 465 |
451 VerifyStreamsClosed(helper); | 466 VerifyStreamsClosed(helper); |
452 } | 467 } |
453 | 468 |
454 private: | 469 private: |
455 bool google_get_request_initialized_; | 470 bool google_get_request_initialized_; |
456 bool google_post_request_initialized_; | 471 bool google_post_request_initialized_; |
| 472 bool google_chunked_post_request_initialized_; |
457 HttpRequestInfo google_get_request_; | 473 HttpRequestInfo google_get_request_; |
458 HttpRequestInfo google_post_request_; | 474 HttpRequestInfo google_post_request_; |
| 475 HttpRequestInfo google_chunked_post_request_; |
459 HttpRequestInfo google_get_push_request_; | 476 HttpRequestInfo google_get_push_request_; |
460 }; | 477 }; |
461 | 478 |
462 //----------------------------------------------------------------------------- | 479 //----------------------------------------------------------------------------- |
463 // All tests are run with three different connection types: SPDY after NPN | 480 // All tests are run with three different connection types: SPDY after NPN |
464 // negotiation, SPDY without SSL, and SPDY with SSL. | 481 // negotiation, SPDY without SSL, and SPDY with SSL. |
465 INSTANTIATE_TEST_CASE_P(Spdy, | 482 INSTANTIATE_TEST_CASE_P(Spdy, |
466 SpdyNetworkTransactionTest, | 483 SpdyNetworkTransactionTest, |
467 ::testing::Values(SPDYNOSSL, SPDYSSL, SPDYNPN)); | 484 ::testing::Values(SPDYNOSSL, SPDYSSL, SPDYNPN)); |
468 | 485 |
(...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1518 writes, arraysize(writes))); | 1535 writes, arraysize(writes))); |
1519 NormalSpdyTransactionHelper helper(CreatePostRequest(), | 1536 NormalSpdyTransactionHelper helper(CreatePostRequest(), |
1520 BoundNetLog(), GetParam()); | 1537 BoundNetLog(), GetParam()); |
1521 helper.RunToCompletion(data.get()); | 1538 helper.RunToCompletion(data.get()); |
1522 TransactionHelperResult out = helper.output(); | 1539 TransactionHelperResult out = helper.output(); |
1523 EXPECT_EQ(OK, out.rv); | 1540 EXPECT_EQ(OK, out.rv); |
1524 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 1541 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
1525 EXPECT_EQ("hello!", out.response_data); | 1542 EXPECT_EQ("hello!", out.response_data); |
1526 } | 1543 } |
1527 | 1544 |
| 1545 // Test that a chunked POST works. |
| 1546 TEST_P(SpdyNetworkTransactionTest, ChunkedPost) { |
| 1547 scoped_ptr<spdy::SpdyFrame> req(ConstructChunkedSpdyPost(NULL, 0)); |
| 1548 scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame(1, false)); |
| 1549 scoped_ptr<spdy::SpdyFrame> lastchunk(ConstructSpdyBodyFrame(1, NULL, 0, |
| 1550 true)); |
| 1551 MockWrite writes[] = { |
| 1552 CreateMockWrite(*req), |
| 1553 CreateMockWrite(*body), // POST upload frame |
| 1554 CreateMockWrite(*lastchunk), |
| 1555 }; |
| 1556 |
| 1557 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0)); |
| 1558 MockRead reads[] = { |
| 1559 CreateMockRead(*resp), |
| 1560 CreateMockRead(*body), |
| 1561 CreateMockRead(*lastchunk), |
| 1562 MockRead(true, 0, 0) // EOF |
| 1563 }; |
| 1564 |
| 1565 scoped_refptr<DelayedSocketData> data( |
| 1566 new DelayedSocketData(3, reads, arraysize(reads), |
| 1567 writes, arraysize(writes))); |
| 1568 NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), |
| 1569 BoundNetLog(), GetParam()); |
| 1570 helper.RunToCompletion(data.get()); |
| 1571 TransactionHelperResult out = helper.output(); |
| 1572 EXPECT_EQ(OK, out.rv); |
| 1573 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1574 EXPECT_EQ("hello!", out.response_data); |
| 1575 } |
| 1576 |
1528 // Test that a POST without any post data works. | 1577 // Test that a POST without any post data works. |
1529 TEST_P(SpdyNetworkTransactionTest, NullPost) { | 1578 TEST_P(SpdyNetworkTransactionTest, NullPost) { |
1530 // Setup the request | 1579 // Setup the request |
1531 HttpRequestInfo request; | 1580 HttpRequestInfo request; |
1532 request.method = "POST"; | 1581 request.method = "POST"; |
1533 request.url = GURL("http://www.google.com/"); | 1582 request.url = GURL("http://www.google.com/"); |
1534 // Create an empty UploadData. | 1583 // Create an empty UploadData. |
1535 request.upload_data = NULL; | 1584 request.upload_data = NULL; |
1536 | 1585 |
1537 // When request.upload_data is NULL for post, content-length is | 1586 // 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 | 5647 |
5599 VerifyStreamsClosed(helper); | 5648 VerifyStreamsClosed(helper); |
5600 | 5649 |
5601 // Verify the SYN_REPLY. | 5650 // Verify the SYN_REPLY. |
5602 EXPECT_TRUE(response.headers != NULL); | 5651 EXPECT_TRUE(response.headers != NULL); |
5603 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 5652 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
5604 } | 5653 } |
5605 } | 5654 } |
5606 | 5655 |
5607 } // namespace net | 5656 } // namespace net |
OLD | NEW |