OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/base/net_log_unittest.h" | 5 #include "net/base/net_log_unittest.h" |
6 #include "net/http/http_transaction_unittest.h" | 6 #include "net/http/http_transaction_unittest.h" |
7 #include "net/spdy/spdy_http_stream.h" | 7 #include "net/spdy/spdy_http_stream.h" |
8 #include "net/spdy/spdy_network_transaction.h" | 8 #include "net/spdy/spdy_network_transaction.h" |
9 #include "net/spdy/spdy_test_util.h" | 9 #include "net/spdy/spdy_test_util.h" |
10 #include "testing/platform_test.h" | 10 #include "testing/platform_test.h" |
(...skipping 1110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1121 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); | 1121 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); |
1122 EXPECT_EQ(ERR_IO_PENDING, rv); | 1122 EXPECT_EQ(ERR_IO_PENDING, rv); |
1123 helper.ResetTrans(); // Cancel the transaction. | 1123 helper.ResetTrans(); // Cancel the transaction. |
1124 | 1124 |
1125 // Flush the MessageLoop while the SpdySessionDependencies (in particular, the | 1125 // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
1126 // MockClientSocketFactory) are still alive. | 1126 // MockClientSocketFactory) are still alive. |
1127 MessageLoop::current()->RunAllPending(); | 1127 MessageLoop::current()->RunAllPending(); |
1128 helper.VerifyDataNotConsumed(); | 1128 helper.VerifyDataNotConsumed(); |
1129 } | 1129 } |
1130 | 1130 |
| 1131 // Verify that the client sends a Rst Frame upon cancelling the stream. |
| 1132 TEST_P(SpdyNetworkTransactionTest, CancelledTransactionSendRst) { |
| 1133 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
| 1134 scoped_ptr<spdy::SpdyFrame> rst( |
| 1135 ConstructSpdyRstStream(1, spdy::CANCEL)); |
| 1136 MockWrite writes[] = { |
| 1137 CreateMockWrite(*req, 1), |
| 1138 CreateMockWrite(*rst, 3), |
| 1139 }; |
| 1140 |
| 1141 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1142 MockRead reads[] = { |
| 1143 CreateMockRead(*resp, 2), |
| 1144 MockRead(true, 0, 0, 4) // EOF |
| 1145 }; |
| 1146 |
| 1147 scoped_refptr<OrderedSocketData> data( |
| 1148 new OrderedSocketData(reads, arraysize(reads), |
| 1149 writes, arraysize(writes))); |
| 1150 |
| 1151 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
| 1152 BoundNetLog(), |
| 1153 GetParam()); |
| 1154 helper.AddData(data.get()); |
| 1155 helper.RunPreTestSetup(); |
| 1156 HttpNetworkTransaction* trans = helper.trans(); |
| 1157 |
| 1158 TestCompletionCallback callback; |
| 1159 |
| 1160 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); |
| 1161 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1162 rv = callback.WaitForResult(); |
| 1163 helper.ResetTrans(); // Cancel the transaction. |
| 1164 |
| 1165 // Finish running rest of tasks. |
| 1166 MessageLoop::current()->RunAllPending(); |
| 1167 data->CompleteRead(); |
| 1168 helper.VerifyDataConsumed(); |
| 1169 } |
| 1170 |
1131 class SpdyNetworkTransactionTest::StartTransactionCallback | 1171 class SpdyNetworkTransactionTest::StartTransactionCallback |
1132 : public CallbackRunner< Tuple1<int> > { | 1172 : public CallbackRunner< Tuple1<int> > { |
1133 public: | 1173 public: |
1134 explicit StartTransactionCallback( | 1174 explicit StartTransactionCallback( |
1135 scoped_refptr<HttpNetworkSession>& session, | 1175 scoped_refptr<HttpNetworkSession>& session, |
1136 NormalSpdyTransactionHelper& helper) | 1176 NormalSpdyTransactionHelper& helper) |
1137 : session_(session), helper_(helper) {} | 1177 : session_(session), helper_(helper) {} |
1138 | 1178 |
1139 // We try to start another transaction, which should succeed. | 1179 // We try to start another transaction, which should succeed. |
1140 virtual void RunWithParams(const Tuple1<int>& params) { | 1180 virtual void RunWithParams(const Tuple1<int>& params) { |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1689 } | 1729 } |
1690 | 1730 |
1691 // In this test, we enable compression, but get a uncompressed SynReply from | 1731 // In this test, we enable compression, but get a uncompressed SynReply from |
1692 // the server. Verify that teardown is all clean. | 1732 // the server. Verify that teardown is all clean. |
1693 TEST_P(SpdyNetworkTransactionTest, DecompressFailureOnSynReply) { | 1733 TEST_P(SpdyNetworkTransactionTest, DecompressFailureOnSynReply) { |
1694 // For this test, we turn on the normal compression. | 1734 // For this test, we turn on the normal compression. |
1695 EnableCompression(true); | 1735 EnableCompression(true); |
1696 | 1736 |
1697 scoped_ptr<spdy::SpdyFrame> compressed( | 1737 scoped_ptr<spdy::SpdyFrame> compressed( |
1698 ConstructSpdyGet(NULL, 0, true, 1, LOWEST)); | 1738 ConstructSpdyGet(NULL, 0, true, 1, LOWEST)); |
| 1739 scoped_ptr<spdy::SpdyFrame> rst( |
| 1740 ConstructSpdyRstStream(1, spdy::PROTOCOL_ERROR)); |
1699 MockWrite writes[] = { | 1741 MockWrite writes[] = { |
1700 CreateMockWrite(*compressed), | 1742 CreateMockWrite(*compressed), |
| 1743 CreateMockWrite(*rst), |
1701 }; | 1744 }; |
1702 | 1745 |
1703 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | 1746 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
1704 scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame(1, true)); | 1747 scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame(1, true)); |
1705 MockRead reads[] = { | 1748 MockRead reads[] = { |
1706 CreateMockRead(*resp), | 1749 CreateMockRead(*resp), |
1707 CreateMockRead(*body), | 1750 CreateMockRead(*body), |
1708 MockRead(true, 0, 0) // EOF | |
1709 }; | 1751 }; |
1710 | 1752 |
1711 scoped_refptr<DelayedSocketData> data( | 1753 scoped_refptr<DelayedSocketData> data( |
1712 new DelayedSocketData(1, reads, arraysize(reads), | 1754 new DelayedSocketData(1, reads, arraysize(reads), |
1713 writes, arraysize(writes))); | 1755 writes, arraysize(writes))); |
1714 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 1756 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
1715 BoundNetLog(), GetParam()); | 1757 BoundNetLog(), GetParam()); |
1716 helper.RunToCompletion(data.get()); | 1758 helper.RunToCompletion(data.get()); |
1717 TransactionHelperResult out = helper.output(); | 1759 TransactionHelperResult out = helper.output(); |
1718 EXPECT_EQ(ERR_SYN_REPLY_NOT_RECEIVED, out.rv); | 1760 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
1719 data->Reset(); | 1761 data->Reset(); |
1720 | 1762 |
1721 EnableCompression(false); | 1763 EnableCompression(false); |
1722 } | 1764 } |
1723 | 1765 |
1724 // Test that the NetLog contains good data for a simple GET request. | 1766 // Test that the NetLog contains good data for a simple GET request. |
1725 TEST_P(SpdyNetworkTransactionTest, NetLog) { | 1767 TEST_P(SpdyNetworkTransactionTest, NetLog) { |
1726 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 1768 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
1727 MockWrite writes[] = { CreateMockWrite(*req) }; | 1769 MockWrite writes[] = { CreateMockWrite(*req) }; |
1728 | 1770 |
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2552 const HttpResponseInfo* response = trans->GetResponseInfo(); | 2594 const HttpResponseInfo* response = trans->GetResponseInfo(); |
2553 EXPECT_TRUE(response->headers != NULL); | 2595 EXPECT_TRUE(response->headers != NULL); |
2554 EXPECT_TRUE(response->was_fetched_via_spdy); | 2596 EXPECT_TRUE(response->was_fetched_via_spdy); |
2555 out.rv = ReadTransaction(trans, &out.response_data); | 2597 out.rv = ReadTransaction(trans, &out.response_data); |
2556 EXPECT_EQ(ERR_CONNECTION_CLOSED, out.rv); | 2598 EXPECT_EQ(ERR_CONNECTION_CLOSED, out.rv); |
2557 | 2599 |
2558 // Verify that we consumed all test data. | 2600 // Verify that we consumed all test data. |
2559 helper.VerifyDataConsumed(); | 2601 helper.VerifyDataConsumed(); |
2560 } | 2602 } |
2561 } // namespace net | 2603 } // namespace net |
OLD | NEW |