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