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 1640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1651 // Test that a simple POST works. | 1651 // Test that a simple POST works. |
1652 TEST_P(SpdyNetworkTransactionSpdy3Test, EmptyPost) { | 1652 TEST_P(SpdyNetworkTransactionSpdy3Test, EmptyPost) { |
1653 // Setup the request | 1653 // Setup the request |
1654 HttpRequestInfo request; | 1654 HttpRequestInfo request; |
1655 request.method = "POST"; | 1655 request.method = "POST"; |
1656 request.url = GURL("http://www.google.com/"); | 1656 request.url = GURL("http://www.google.com/"); |
1657 // Create an empty UploadData. | 1657 // Create an empty UploadData. |
1658 request.upload_data = new UploadData(); | 1658 request.upload_data = new UploadData(); |
1659 | 1659 |
1660 // Http POST Content-Length is using UploadDataStream::size(). | 1660 // Http POST Content-Length is using UploadDataStream::size(). |
1661 // It is the same as request.upload_data->GetContentLengthSync(). | 1661 const uint64 kContentLength = 0; |
1662 scoped_ptr<UploadDataStream> stream( | 1662 scoped_ptr<UploadDataStream> stream( |
1663 new UploadDataStream(request.upload_data)); | 1663 new UploadDataStream(request.upload_data)); |
1664 ASSERT_EQ(OK, stream->Init()); | 1664 ASSERT_EQ(OK, stream->Init()); |
1665 ASSERT_EQ(request.upload_data->GetContentLengthSync(), | 1665 ASSERT_EQ(kContentLength, stream->size()); |
1666 stream->size()); | |
1667 | 1666 |
1668 scoped_ptr<SpdyFrame> | 1667 scoped_ptr<SpdyFrame> req(ConstructSpdyPost(kContentLength, NULL, 0)); |
1669 req(ConstructSpdyPost( | |
1670 request.upload_data->GetContentLengthSync(), NULL, 0)); | |
1671 // Set the FIN bit since there will be no body. | 1668 // Set the FIN bit since there will be no body. |
1672 req->set_flags(CONTROL_FLAG_FIN); | 1669 req->set_flags(CONTROL_FLAG_FIN); |
1673 MockWrite writes[] = { | 1670 MockWrite writes[] = { |
1674 CreateMockWrite(*req), | 1671 CreateMockWrite(*req), |
1675 }; | 1672 }; |
1676 | 1673 |
1677 scoped_ptr<SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0)); | 1674 scoped_ptr<SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0)); |
1678 scoped_ptr<SpdyFrame> body(ConstructSpdyBodyFrame(1, true)); | 1675 scoped_ptr<SpdyFrame> body(ConstructSpdyBodyFrame(1, true)); |
1679 MockRead reads[] = { | 1676 MockRead reads[] = { |
1680 CreateMockRead(*resp), | 1677 CreateMockRead(*resp), |
(...skipping 18 matching lines...) Expand all Loading... |
1699 static const char upload[] = { "hello!" }; | 1696 static const char upload[] = { "hello!" }; |
1700 | 1697 |
1701 // Setup the request | 1698 // Setup the request |
1702 HttpRequestInfo request; | 1699 HttpRequestInfo request; |
1703 request.method = "POST"; | 1700 request.method = "POST"; |
1704 request.url = GURL("http://www.google.com/"); | 1701 request.url = GURL("http://www.google.com/"); |
1705 request.upload_data = new UploadData(); | 1702 request.upload_data = new UploadData(); |
1706 request.upload_data->AppendBytes(upload, sizeof(upload)); | 1703 request.upload_data->AppendBytes(upload, sizeof(upload)); |
1707 | 1704 |
1708 // Http POST Content-Length is using UploadDataStream::size(). | 1705 // Http POST Content-Length is using UploadDataStream::size(). |
1709 // It is the same as request.upload_data->GetContentLengthSync(). | 1706 const uint64 kContentLength = sizeof(upload); |
1710 scoped_ptr<UploadDataStream> stream( | 1707 scoped_ptr<UploadDataStream> stream( |
1711 new UploadDataStream(request.upload_data)); | 1708 new UploadDataStream(request.upload_data)); |
1712 ASSERT_EQ(OK, stream->Init()); | 1709 ASSERT_EQ(OK, stream->Init()); |
1713 ASSERT_EQ(request.upload_data->GetContentLengthSync(), | 1710 ASSERT_EQ(kContentLength, stream->size()); |
1714 stream->size()); | |
1715 scoped_ptr<SpdyFrame> stream_reply(ConstructSpdyPostSynReply(NULL, 0)); | 1711 scoped_ptr<SpdyFrame> stream_reply(ConstructSpdyPostSynReply(NULL, 0)); |
1716 scoped_ptr<SpdyFrame> stream_body(ConstructSpdyBodyFrame(1, true)); | 1712 scoped_ptr<SpdyFrame> stream_body(ConstructSpdyBodyFrame(1, true)); |
1717 MockRead reads[] = { | 1713 MockRead reads[] = { |
1718 CreateMockRead(*stream_reply, 1), | 1714 CreateMockRead(*stream_reply, 1), |
1719 MockRead(ASYNC, 0, 3) // EOF | 1715 MockRead(ASYNC, 0, 3) // EOF |
1720 }; | 1716 }; |
1721 | 1717 |
1722 scoped_ptr<SpdyFrame> req(ConstructSpdyPost(kUploadDataSize, NULL, 0)); | 1718 scoped_ptr<SpdyFrame> req(ConstructSpdyPost(kUploadDataSize, NULL, 0)); |
1723 scoped_ptr<SpdyFrame> body(ConstructSpdyBodyFrame(1, true)); | 1719 scoped_ptr<SpdyFrame> body(ConstructSpdyBodyFrame(1, true)); |
1724 MockWrite writes[] = { | 1720 MockWrite writes[] = { |
(...skipping 4505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6230 // And now we can allow everything else to run to completion. | 6226 // And now we can allow everything else to run to completion. |
6231 data.SetStop(10); | 6227 data.SetStop(10); |
6232 data.Run(); | 6228 data.Run(); |
6233 EXPECT_EQ(OK, callback2.WaitForResult()); | 6229 EXPECT_EQ(OK, callback2.WaitForResult()); |
6234 EXPECT_EQ(OK, callback3.WaitForResult()); | 6230 EXPECT_EQ(OK, callback3.WaitForResult()); |
6235 | 6231 |
6236 helper.VerifyDataConsumed(); | 6232 helper.VerifyDataConsumed(); |
6237 } | 6233 } |
6238 | 6234 |
6239 } // namespace net | 6235 } // namespace net |
OLD | NEW |