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/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 "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 //----------------------------------------------------------------------------- | 29 //----------------------------------------------------------------------------- |
30 | 30 |
31 namespace net { | 31 namespace net { |
32 | 32 |
33 enum SpdyNetworkTransactionSpdy2TestTypes { | 33 enum SpdyNetworkTransactionSpdy2TestTypes { |
34 SPDYNPN, | 34 SPDYNPN, |
35 SPDYNOSSL, | 35 SPDYNOSSL, |
36 SPDYSSL, | 36 SPDYSSL, |
37 }; | 37 }; |
| 38 |
38 class SpdyNetworkTransactionSpdy2Test | 39 class SpdyNetworkTransactionSpdy2Test |
39 : public ::testing::TestWithParam<SpdyNetworkTransactionSpdy2TestTypes> { | 40 : public ::testing::TestWithParam<SpdyNetworkTransactionSpdy2TestTypes> { |
40 protected: | 41 protected: |
41 | 42 |
42 virtual void SetUp() { | 43 virtual void SetUp() { |
43 SpdySession::set_default_protocol(kProtoSPDY2); | 44 SpdySession::set_default_protocol(kProtoSPDY2); |
44 google_get_request_initialized_ = false; | 45 google_get_request_initialized_ = false; |
45 google_post_request_initialized_ = false; | 46 google_post_request_initialized_ = false; |
46 google_chunked_post_request_initialized_ = false; | 47 google_chunked_post_request_initialized_ = false; |
47 } | 48 } |
48 | 49 |
49 virtual void TearDown() { | 50 virtual void TearDown() { |
| 51 UploadDataStream::ResetMergeChunks(); |
50 // Empty the current queue. | 52 // Empty the current queue. |
51 MessageLoop::current()->RunAllPending(); | 53 MessageLoop::current()->RunAllPending(); |
52 } | 54 } |
53 | 55 |
| 56 void set_merge_chunks(bool merge) { |
| 57 UploadDataStream::set_merge_chunks(merge); |
| 58 } |
| 59 |
54 struct TransactionHelperResult { | 60 struct TransactionHelperResult { |
55 int rv; | 61 int rv; |
56 std::string status_line; | 62 std::string status_line; |
57 std::string response_data; | 63 std::string response_data; |
58 HttpResponseInfo response_info; | 64 HttpResponseInfo response_info; |
59 }; | 65 }; |
60 | 66 |
61 // A helper class that handles all the initial npn/ssl setup. | 67 // A helper class that handles all the initial npn/ssl setup. |
62 class NormalSpdyTransactionHelper { | 68 class NormalSpdyTransactionHelper { |
63 public: | 69 public: |
(...skipping 1516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1580 BoundNetLog(), GetParam(), NULL); | 1586 BoundNetLog(), GetParam(), NULL); |
1581 helper.RunToCompletion(data.get()); | 1587 helper.RunToCompletion(data.get()); |
1582 TransactionHelperResult out = helper.output(); | 1588 TransactionHelperResult out = helper.output(); |
1583 EXPECT_EQ(OK, out.rv); | 1589 EXPECT_EQ(OK, out.rv); |
1584 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 1590 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
1585 EXPECT_EQ("hello!", out.response_data); | 1591 EXPECT_EQ("hello!", out.response_data); |
1586 } | 1592 } |
1587 | 1593 |
1588 // Test that a chunked POST works. | 1594 // Test that a chunked POST works. |
1589 TEST_P(SpdyNetworkTransactionSpdy2Test, ChunkedPost) { | 1595 TEST_P(SpdyNetworkTransactionSpdy2Test, ChunkedPost) { |
1590 UploadDataStream::set_merge_chunks(false); | 1596 // Disable merging of chunks until we have a better way to unit test POST |
| 1597 // requests with chunked uploads. |
| 1598 set_merge_chunks(false); |
| 1599 |
1591 scoped_ptr<SpdyFrame> req(ConstructChunkedSpdyPost(NULL, 0)); | 1600 scoped_ptr<SpdyFrame> req(ConstructChunkedSpdyPost(NULL, 0)); |
1592 scoped_ptr<SpdyFrame> chunk1(ConstructSpdyBodyFrame(1, false)); | 1601 scoped_ptr<SpdyFrame> chunk1(ConstructSpdyBodyFrame(1, false)); |
1593 scoped_ptr<SpdyFrame> chunk2(ConstructSpdyBodyFrame(1, true)); | 1602 scoped_ptr<SpdyFrame> chunk2(ConstructSpdyBodyFrame(1, true)); |
1594 MockWrite writes[] = { | 1603 MockWrite writes[] = { |
1595 CreateMockWrite(*req), | 1604 CreateMockWrite(*req), |
1596 CreateMockWrite(*chunk1), | 1605 CreateMockWrite(*chunk1), |
1597 CreateMockWrite(*chunk2), | 1606 CreateMockWrite(*chunk2), |
1598 }; | 1607 }; |
1599 | 1608 |
1600 scoped_ptr<SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0)); | 1609 scoped_ptr<SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0)); |
(...skipping 4024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5625 // And now we can allow everything else to run to completion. | 5634 // And now we can allow everything else to run to completion. |
5626 data->SetStop(10); | 5635 data->SetStop(10); |
5627 data->Run(); | 5636 data->Run(); |
5628 EXPECT_EQ(OK, callback2.WaitForResult()); | 5637 EXPECT_EQ(OK, callback2.WaitForResult()); |
5629 EXPECT_EQ(OK, callback3.WaitForResult()); | 5638 EXPECT_EQ(OK, callback3.WaitForResult()); |
5630 | 5639 |
5631 helper.VerifyDataConsumed(); | 5640 helper.VerifyDataConsumed(); |
5632 } | 5641 } |
5633 | 5642 |
5634 } // namespace net | 5643 } // namespace net |
OLD | NEW |