| 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 1634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1645 // Test that a simple POST works. | 1645 // Test that a simple POST works. |
| 1646 TEST_P(SpdyNetworkTransactionSpdy2Test, EmptyPost) { | 1646 TEST_P(SpdyNetworkTransactionSpdy2Test, EmptyPost) { |
| 1647 // Setup the request | 1647 // Setup the request |
| 1648 HttpRequestInfo request; | 1648 HttpRequestInfo request; |
| 1649 request.method = "POST"; | 1649 request.method = "POST"; |
| 1650 request.url = GURL("http://www.google.com/"); | 1650 request.url = GURL("http://www.google.com/"); |
| 1651 // Create an empty UploadData. | 1651 // Create an empty UploadData. |
| 1652 request.upload_data = new UploadData(); | 1652 request.upload_data = new UploadData(); |
| 1653 | 1653 |
| 1654 // Http POST Content-Length is using UploadDataStream::size(). | 1654 // Http POST Content-Length is using UploadDataStream::size(). |
| 1655 // It is the same as request.upload_data->GetContentLengthSync(). | 1655 const uint64 kContentLength = 0; |
| 1656 scoped_ptr<UploadDataStream> stream( | 1656 scoped_ptr<UploadDataStream> stream( |
| 1657 new UploadDataStream(request.upload_data)); | 1657 new UploadDataStream(request.upload_data)); |
| 1658 ASSERT_EQ(OK, stream->Init()); | 1658 ASSERT_EQ(OK, stream->Init()); |
| 1659 ASSERT_EQ(request.upload_data->GetContentLengthSync(), | 1659 ASSERT_EQ(kContentLength, stream->size()); |
| 1660 stream->size()); | |
| 1661 | 1660 |
| 1662 scoped_ptr<SpdyFrame> | 1661 scoped_ptr<SpdyFrame> req(ConstructSpdyPost(kContentLength, NULL, 0)); |
| 1663 req(ConstructSpdyPost( | |
| 1664 request.upload_data->GetContentLengthSync(), NULL, 0)); | |
| 1665 // Set the FIN bit since there will be no body. | 1662 // Set the FIN bit since there will be no body. |
| 1666 req->set_flags(CONTROL_FLAG_FIN); | 1663 req->set_flags(CONTROL_FLAG_FIN); |
| 1667 MockWrite writes[] = { | 1664 MockWrite writes[] = { |
| 1668 CreateMockWrite(*req), | 1665 CreateMockWrite(*req), |
| 1669 }; | 1666 }; |
| 1670 | 1667 |
| 1671 scoped_ptr<SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0)); | 1668 scoped_ptr<SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0)); |
| 1672 scoped_ptr<SpdyFrame> body(ConstructSpdyBodyFrame(1, true)); | 1669 scoped_ptr<SpdyFrame> body(ConstructSpdyBodyFrame(1, true)); |
| 1673 MockRead reads[] = { | 1670 MockRead reads[] = { |
| 1674 CreateMockRead(*resp), | 1671 CreateMockRead(*resp), |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1693 static const char upload[] = { "hello!" }; | 1690 static const char upload[] = { "hello!" }; |
| 1694 | 1691 |
| 1695 // Setup the request | 1692 // Setup the request |
| 1696 HttpRequestInfo request; | 1693 HttpRequestInfo request; |
| 1697 request.method = "POST"; | 1694 request.method = "POST"; |
| 1698 request.url = GURL("http://www.google.com/"); | 1695 request.url = GURL("http://www.google.com/"); |
| 1699 request.upload_data = new UploadData(); | 1696 request.upload_data = new UploadData(); |
| 1700 request.upload_data->AppendBytes(upload, sizeof(upload)); | 1697 request.upload_data->AppendBytes(upload, sizeof(upload)); |
| 1701 | 1698 |
| 1702 // Http POST Content-Length is using UploadDataStream::size(). | 1699 // Http POST Content-Length is using UploadDataStream::size(). |
| 1703 // It is the same as request.upload_data->GetContentLengthSync(). | 1700 const uint64 kContentLength = sizeof(upload); |
| 1704 scoped_ptr<UploadDataStream> stream( | 1701 scoped_ptr<UploadDataStream> stream( |
| 1705 new UploadDataStream(request.upload_data)); | 1702 new UploadDataStream(request.upload_data)); |
| 1706 ASSERT_EQ(OK, stream->Init()); | 1703 ASSERT_EQ(OK, stream->Init()); |
| 1707 ASSERT_EQ(request.upload_data->GetContentLengthSync(), | 1704 ASSERT_EQ(kContentLength, stream->size()); |
| 1708 stream->size()); | |
| 1709 scoped_ptr<SpdyFrame> stream_reply(ConstructSpdyPostSynReply(NULL, 0)); | 1705 scoped_ptr<SpdyFrame> stream_reply(ConstructSpdyPostSynReply(NULL, 0)); |
| 1710 scoped_ptr<SpdyFrame> stream_body(ConstructSpdyBodyFrame(1, true)); | 1706 scoped_ptr<SpdyFrame> stream_body(ConstructSpdyBodyFrame(1, true)); |
| 1711 MockRead reads[] = { | 1707 MockRead reads[] = { |
| 1712 CreateMockRead(*stream_reply, 1), | 1708 CreateMockRead(*stream_reply, 1), |
| 1713 MockRead(ASYNC, 0, 3) // EOF | 1709 MockRead(ASYNC, 0, 3) // EOF |
| 1714 }; | 1710 }; |
| 1715 | 1711 |
| 1716 scoped_ptr<SpdyFrame> req(ConstructSpdyPost(kUploadDataSize, NULL, 0)); | 1712 scoped_ptr<SpdyFrame> req(ConstructSpdyPost(kUploadDataSize, NULL, 0)); |
| 1717 scoped_ptr<SpdyFrame> body(ConstructSpdyBodyFrame(1, true)); | 1713 scoped_ptr<SpdyFrame> body(ConstructSpdyBodyFrame(1, true)); |
| 1718 MockWrite writes[] = { | 1714 MockWrite writes[] = { |
| (...skipping 3951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5670 // And now we can allow everything else to run to completion. | 5666 // And now we can allow everything else to run to completion. |
| 5671 data.SetStop(10); | 5667 data.SetStop(10); |
| 5672 data.Run(); | 5668 data.Run(); |
| 5673 EXPECT_EQ(OK, callback2.WaitForResult()); | 5669 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 5674 EXPECT_EQ(OK, callback3.WaitForResult()); | 5670 EXPECT_EQ(OK, callback3.WaitForResult()); |
| 5675 | 5671 |
| 5676 helper.VerifyDataConsumed(); | 5672 helper.VerifyDataConsumed(); |
| 5677 } | 5673 } |
| 5678 | 5674 |
| 5679 } // namespace net | 5675 } // namespace net |
| OLD | NEW |