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 1691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1702 // Http POST Content-Length is using UploadDataStream::size(). | 1702 // Http POST Content-Length is using UploadDataStream::size(). |
1703 // It is the same as request.upload_data->GetContentLengthSync(). | 1703 // It is the same as request.upload_data->GetContentLengthSync(). |
1704 scoped_ptr<UploadDataStream> stream( | 1704 scoped_ptr<UploadDataStream> stream( |
1705 new UploadDataStream(request.upload_data)); | 1705 new UploadDataStream(request.upload_data)); |
1706 ASSERT_EQ(OK, stream->Init()); | 1706 ASSERT_EQ(OK, stream->Init()); |
1707 ASSERT_EQ(request.upload_data->GetContentLengthSync(), | 1707 ASSERT_EQ(request.upload_data->GetContentLengthSync(), |
1708 stream->size()); | 1708 stream->size()); |
1709 scoped_ptr<SpdyFrame> stream_reply(ConstructSpdyPostSynReply(NULL, 0)); | 1709 scoped_ptr<SpdyFrame> stream_reply(ConstructSpdyPostSynReply(NULL, 0)); |
1710 scoped_ptr<SpdyFrame> stream_body(ConstructSpdyBodyFrame(1, true)); | 1710 scoped_ptr<SpdyFrame> stream_body(ConstructSpdyBodyFrame(1, true)); |
1711 MockRead reads[] = { | 1711 MockRead reads[] = { |
1712 CreateMockRead(*stream_reply, 2), | 1712 CreateMockRead(*stream_reply, 1), |
1713 CreateMockRead(*stream_body, 3), | 1713 MockRead(ASYNC, 0, 3) // EOF |
1714 MockRead(SYNCHRONOUS, 0, 0) // EOF | |
1715 }; | 1714 }; |
1716 | 1715 |
1717 DelayedSocketData data(0, reads, arraysize(reads), NULL, 0); | 1716 scoped_ptr<SpdyFrame> req(ConstructSpdyPost(kUploadDataSize, NULL, 0)); |
1718 NormalSpdyTransactionHelper helper(request, | 1717 scoped_ptr<SpdyFrame> body(ConstructSpdyBodyFrame(1, true)); |
| 1718 MockRead writes[] = { |
| 1719 CreateMockWrite(*req, 0), |
| 1720 CreateMockWrite(*body, 2), |
| 1721 }; |
| 1722 |
| 1723 DeterministicSocketData data(reads, arraysize(reads), |
| 1724 writes, arraysize(writes)); |
| 1725 NormalSpdyTransactionHelper helper(CreatePostRequest(), |
1719 BoundNetLog(), GetParam(), NULL); | 1726 BoundNetLog(), GetParam(), NULL); |
| 1727 helper.SetDeterministic(); |
1720 helper.RunPreTestSetup(); | 1728 helper.RunPreTestSetup(); |
1721 helper.AddData(&data); | 1729 helper.AddDeterministicData(&data); |
1722 helper.RunDefaultTest(); | 1730 HttpNetworkTransaction* trans = helper.trans(); |
1723 helper.VerifyDataConsumed(); | |
1724 | 1731 |
1725 TransactionHelperResult out = helper.output(); | 1732 TestCompletionCallback callback; |
1726 EXPECT_EQ(ERR_SYN_REPLY_NOT_RECEIVED, out.rv); | 1733 int rv = trans->Start( |
| 1734 &CreatePostRequest(), callback.callback(), BoundNetLog()); |
| 1735 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1736 |
| 1737 data.RunFor(2); |
| 1738 rv = callback.WaitForResult(); |
| 1739 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, rv); |
| 1740 data.RunFor(1); |
1727 } | 1741 } |
1728 | 1742 |
1729 // The client upon cancellation tries to send a RST_STREAM frame. The mock | 1743 // The client upon cancellation tries to send a RST_STREAM frame. The mock |
1730 // socket causes the TCP write to return zero. This test checks that the client | 1744 // socket causes the TCP write to return zero. This test checks that the client |
1731 // tries to queue up the RST_STREAM frame again. | 1745 // tries to queue up the RST_STREAM frame again. |
1732 TEST_P(SpdyNetworkTransactionSpdy2Test, SocketWriteReturnsZero) { | 1746 TEST_P(SpdyNetworkTransactionSpdy2Test, SocketWriteReturnsZero) { |
1733 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 1747 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
1734 scoped_ptr<SpdyFrame> rst( | 1748 scoped_ptr<SpdyFrame> rst( |
1735 ConstructSpdyRstStream(1, CANCEL)); | 1749 ConstructSpdyRstStream(1, CANCEL)); |
1736 MockWrite writes[] = { | 1750 MockWrite writes[] = { |
(...skipping 3713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5450 // Verify the SYN_REPLY. | 5464 // Verify the SYN_REPLY. |
5451 HttpResponseInfo response = *trans->GetResponseInfo(); | 5465 HttpResponseInfo response = *trans->GetResponseInfo(); |
5452 EXPECT_TRUE(response.headers != NULL); | 5466 EXPECT_TRUE(response.headers != NULL); |
5453 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 5467 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
5454 } | 5468 } |
5455 | 5469 |
5456 TEST_P(SpdyNetworkTransactionSpdy2Test, OutOfOrderSynStream) { | 5470 TEST_P(SpdyNetworkTransactionSpdy2Test, OutOfOrderSynStream) { |
5457 // This first request will start to establish the SpdySession. | 5471 // This first request will start to establish the SpdySession. |
5458 // Then we will start the second (MEDIUM priority) and then third | 5472 // Then we will start the second (MEDIUM priority) and then third |
5459 // (HIGHEST priority) request in such a way that the third will actually | 5473 // (HIGHEST priority) request in such a way that the third will actually |
5460 // start before the second, causing the second to be re-numbered. | 5474 // start before the second, causing the second to be numbered differently |
| 5475 // than the order they were created. |
5461 scoped_ptr<SpdyFrame> req1(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 5476 scoped_ptr<SpdyFrame> req1(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
5462 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 3, MEDIUM)); | 5477 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 3, HIGHEST)); |
5463 scoped_ptr<SpdyFrame> req3(ConstructSpdyGet(NULL, 0, false, 5, HIGHEST)); | 5478 scoped_ptr<SpdyFrame> req3(ConstructSpdyGet(NULL, 0, false, 5, MEDIUM)); |
5464 MockWrite writes[] = { | 5479 MockWrite writes[] = { |
5465 CreateMockWrite(*req1, 0), | 5480 CreateMockWrite(*req1, 0), |
5466 CreateMockWrite(*req2, 3), | 5481 CreateMockWrite(*req2, 3), |
5467 CreateMockWrite(*req3, 4), | 5482 CreateMockWrite(*req3, 4), |
5468 }; | 5483 }; |
5469 | 5484 |
5470 scoped_ptr<SpdyFrame> resp1(ConstructSpdyGetSynReply(NULL, 0, 1)); | 5485 scoped_ptr<SpdyFrame> resp1(ConstructSpdyGetSynReply(NULL, 0, 1)); |
5471 scoped_ptr<SpdyFrame> body1(ConstructSpdyBodyFrame(1, true)); | 5486 scoped_ptr<SpdyFrame> body1(ConstructSpdyBodyFrame(1, true)); |
5472 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 3)); | 5487 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 3)); |
5473 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(3, true)); | 5488 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(3, true)); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5532 // And now we can allow everything else to run to completion. | 5547 // And now we can allow everything else to run to completion. |
5533 data.SetStop(10); | 5548 data.SetStop(10); |
5534 data.Run(); | 5549 data.Run(); |
5535 EXPECT_EQ(OK, callback2.WaitForResult()); | 5550 EXPECT_EQ(OK, callback2.WaitForResult()); |
5536 EXPECT_EQ(OK, callback3.WaitForResult()); | 5551 EXPECT_EQ(OK, callback3.WaitForResult()); |
5537 | 5552 |
5538 helper.VerifyDataConsumed(); | 5553 helper.VerifyDataConsumed(); |
5539 } | 5554 } |
5540 | 5555 |
5541 } // namespace net | 5556 } // namespace net |
OLD | NEW |