| 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 21 matching lines...) Expand all Loading... |
| 32 enum SpdyNetworkTransactionSpdy3TestTypes { | 32 enum SpdyNetworkTransactionSpdy3TestTypes { |
| 33 SPDYNPN, | 33 SPDYNPN, |
| 34 SPDYNOSSL, | 34 SPDYNOSSL, |
| 35 SPDYSSL, | 35 SPDYSSL, |
| 36 }; | 36 }; |
| 37 class SpdyNetworkTransactionSpdy3Test | 37 class SpdyNetworkTransactionSpdy3Test |
| 38 : public ::testing::TestWithParam<SpdyNetworkTransactionSpdy3TestTypes> { | 38 : public ::testing::TestWithParam<SpdyNetworkTransactionSpdy3TestTypes> { |
| 39 protected: | 39 protected: |
| 40 | 40 |
| 41 virtual void SetUp() { | 41 virtual void SetUp() { |
| 42 // By default, all tests turn off compression. | |
| 43 EnableCompression(false); | |
| 44 SpdySession::set_default_protocol(SSLClientSocket::kProtoSPDY3); | 42 SpdySession::set_default_protocol(SSLClientSocket::kProtoSPDY3); |
| 45 google_get_request_initialized_ = false; | 43 google_get_request_initialized_ = false; |
| 46 google_post_request_initialized_ = false; | 44 google_post_request_initialized_ = false; |
| 47 google_chunked_post_request_initialized_ = false; | 45 google_chunked_post_request_initialized_ = false; |
| 48 } | 46 } |
| 49 | 47 |
| 50 virtual void TearDown() { | 48 virtual void TearDown() { |
| 51 // Empty the current queue. | 49 // Empty the current queue. |
| 52 MessageLoop::current()->RunAllPending(); | 50 MessageLoop::current()->RunAllPending(); |
| 53 } | 51 } |
| 54 | 52 |
| 55 struct TransactionHelperResult { | 53 struct TransactionHelperResult { |
| 56 int rv; | 54 int rv; |
| 57 std::string status_line; | 55 std::string status_line; |
| 58 std::string response_data; | 56 std::string response_data; |
| 59 HttpResponseInfo response_info; | 57 HttpResponseInfo response_info; |
| 60 }; | 58 }; |
| 61 | 59 |
| 62 void EnableCompression(bool enabled) { | |
| 63 spdy::SpdyFramer::set_enable_compression_default(enabled); | |
| 64 } | |
| 65 | |
| 66 // A helper class that handles all the initial npn/ssl setup. | 60 // A helper class that handles all the initial npn/ssl setup. |
| 67 class NormalSpdyTransactionHelper { | 61 class NormalSpdyTransactionHelper { |
| 68 public: | 62 public: |
| 69 NormalSpdyTransactionHelper(const HttpRequestInfo& request, | 63 NormalSpdyTransactionHelper(const HttpRequestInfo& request, |
| 70 const BoundNetLog& log, | 64 const BoundNetLog& log, |
| 71 SpdyNetworkTransactionSpdy3TestTypes test_type) | 65 SpdyNetworkTransactionSpdy3TestTypes test_type) |
| 72 : request_(request), | 66 : request_(request), |
| 73 session_deps_(new SpdySessionDependencies()), | 67 session_deps_(new SpdySessionDependencies()), |
| 74 session_(SpdySessionDependencies::SpdyCreateSession( | 68 session_(SpdySessionDependencies::SpdyCreateSession( |
| 75 session_deps_.get())), | 69 session_deps_.get())), |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 } | 517 } |
| 524 | 518 |
| 525 private: | 519 private: |
| 526 bool google_get_request_initialized_; | 520 bool google_get_request_initialized_; |
| 527 bool google_post_request_initialized_; | 521 bool google_post_request_initialized_; |
| 528 bool google_chunked_post_request_initialized_; | 522 bool google_chunked_post_request_initialized_; |
| 529 HttpRequestInfo google_get_request_; | 523 HttpRequestInfo google_get_request_; |
| 530 HttpRequestInfo google_post_request_; | 524 HttpRequestInfo google_post_request_; |
| 531 HttpRequestInfo google_chunked_post_request_; | 525 HttpRequestInfo google_chunked_post_request_; |
| 532 HttpRequestInfo google_get_push_request_; | 526 HttpRequestInfo google_get_push_request_; |
| 527 SpdyTestStateHelper spdy_state_; |
| 533 }; | 528 }; |
| 534 | 529 |
| 535 //----------------------------------------------------------------------------- | 530 //----------------------------------------------------------------------------- |
| 536 // All tests are run with three different connection types: SPDY after NPN | 531 // All tests are run with three different connection types: SPDY after NPN |
| 537 // negotiation, SPDY without SSL, and SPDY with SSL. | 532 // negotiation, SPDY without SSL, and SPDY with SSL. |
| 538 INSTANTIATE_TEST_CASE_P(Spdy, | 533 INSTANTIATE_TEST_CASE_P(Spdy, |
| 539 SpdyNetworkTransactionSpdy3Test, | 534 SpdyNetworkTransactionSpdy3Test, |
| 540 ::testing::Values(SPDYNOSSL, SPDYSSL, SPDYNPN)); | 535 ::testing::Values(SPDYNOSSL, SPDYSSL, SPDYNPN)); |
| 541 | 536 |
| 542 | 537 |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 } | 1044 } |
| 1050 EXPECT_EQ(OK, out.rv); | 1045 EXPECT_EQ(OK, out.rv); |
| 1051 } | 1046 } |
| 1052 | 1047 |
| 1053 // Similar to ThreeGetsWithMaxConcurrent above, however this test adds | 1048 // Similar to ThreeGetsWithMaxConcurrent above, however this test adds |
| 1054 // a fourth transaction. The third and fourth transactions have | 1049 // a fourth transaction. The third and fourth transactions have |
| 1055 // different data ("hello!" vs "hello!hello!") and because of the | 1050 // different data ("hello!" vs "hello!hello!") and because of the |
| 1056 // user specified priority, we expect to see them inverted in | 1051 // user specified priority, we expect to see them inverted in |
| 1057 // the response from the server. | 1052 // the response from the server. |
| 1058 TEST_P(SpdyNetworkTransactionSpdy3Test, FourGetsWithMaxConcurrentPriority) { | 1053 TEST_P(SpdyNetworkTransactionSpdy3Test, FourGetsWithMaxConcurrentPriority) { |
| 1059 SpdySession::set_enable_ping_based_connection_checking(false); | |
| 1060 | |
| 1061 // Construct the request. | 1054 // Construct the request. |
| 1062 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 1055 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
| 1063 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | 1056 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1064 scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame(1, false)); | 1057 scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame(1, false)); |
| 1065 scoped_ptr<spdy::SpdyFrame> fbody(ConstructSpdyBodyFrame(1, true)); | 1058 scoped_ptr<spdy::SpdyFrame> fbody(ConstructSpdyBodyFrame(1, true)); |
| 1066 | 1059 |
| 1067 scoped_ptr<spdy::SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 3, LOWEST)); | 1060 scoped_ptr<spdy::SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 3, LOWEST)); |
| 1068 scoped_ptr<spdy::SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 3)); | 1061 scoped_ptr<spdy::SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 1069 scoped_ptr<spdy::SpdyFrame> body2(ConstructSpdyBodyFrame(3, false)); | 1062 scoped_ptr<spdy::SpdyFrame> body2(ConstructSpdyBodyFrame(3, false)); |
| 1070 scoped_ptr<spdy::SpdyFrame> fbody2(ConstructSpdyBodyFrame(3, true)); | 1063 scoped_ptr<spdy::SpdyFrame> fbody2(ConstructSpdyBodyFrame(3, true)); |
| (...skipping 2730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3801 TransactionHelperResult out = helper.output(); | 3794 TransactionHelperResult out = helper.output(); |
| 3802 EXPECT_EQ(OK, out.rv); | 3795 EXPECT_EQ(OK, out.rv); |
| 3803 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 3796 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 3804 EXPECT_EQ("hello!", out.response_data); | 3797 EXPECT_EQ("hello!", out.response_data); |
| 3805 } | 3798 } |
| 3806 | 3799 |
| 3807 // In this test, we enable compression, but get a uncompressed SynReply from | 3800 // In this test, we enable compression, but get a uncompressed SynReply from |
| 3808 // the server. Verify that teardown is all clean. | 3801 // the server. Verify that teardown is all clean. |
| 3809 TEST_P(SpdyNetworkTransactionSpdy3Test, DecompressFailureOnSynReply) { | 3802 TEST_P(SpdyNetworkTransactionSpdy3Test, DecompressFailureOnSynReply) { |
| 3810 // For this test, we turn on the normal compression. | 3803 // For this test, we turn on the normal compression. |
| 3811 EnableCompression(true); | 3804 spdy::SpdyFramer::set_enable_compression_default(true); |
| 3812 | 3805 |
| 3813 scoped_ptr<spdy::SpdyFrame> compressed( | 3806 scoped_ptr<spdy::SpdyFrame> compressed( |
| 3814 ConstructSpdyGet(NULL, 0, true, 1, LOWEST)); | 3807 ConstructSpdyGet(NULL, 0, true, 1, LOWEST)); |
| 3815 scoped_ptr<spdy::SpdyFrame> rst( | 3808 scoped_ptr<spdy::SpdyFrame> rst( |
| 3816 ConstructSpdyRstStream(1, spdy::PROTOCOL_ERROR)); | 3809 ConstructSpdyRstStream(1, spdy::PROTOCOL_ERROR)); |
| 3817 MockWrite writes[] = { | 3810 MockWrite writes[] = { |
| 3818 CreateMockWrite(*compressed), | 3811 CreateMockWrite(*compressed), |
| 3819 }; | 3812 }; |
| 3820 | 3813 |
| 3821 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | 3814 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3822 scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame(1, true)); | 3815 scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame(1, true)); |
| 3823 MockRead reads[] = { | 3816 MockRead reads[] = { |
| 3824 CreateMockRead(*resp), | 3817 CreateMockRead(*resp), |
| 3825 }; | 3818 }; |
| 3826 | 3819 |
| 3827 scoped_ptr<DelayedSocketData> data( | 3820 scoped_ptr<DelayedSocketData> data( |
| 3828 new DelayedSocketData(1, reads, arraysize(reads), | 3821 new DelayedSocketData(1, reads, arraysize(reads), |
| 3829 writes, arraysize(writes))); | 3822 writes, arraysize(writes))); |
| 3830 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 3823 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
| 3831 BoundNetLog(), GetParam()); | 3824 BoundNetLog(), GetParam()); |
| 3832 helper.RunToCompletion(data.get()); | 3825 helper.RunToCompletion(data.get()); |
| 3833 TransactionHelperResult out = helper.output(); | 3826 TransactionHelperResult out = helper.output(); |
| 3834 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); | 3827 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
| 3835 data->Reset(); | 3828 data->Reset(); |
| 3836 | |
| 3837 EnableCompression(false); | |
| 3838 } | 3829 } |
| 3839 | 3830 |
| 3840 // Test that the NetLog contains good data for a simple GET request. | 3831 // Test that the NetLog contains good data for a simple GET request. |
| 3841 TEST_P(SpdyNetworkTransactionSpdy3Test, NetLog) { | 3832 TEST_P(SpdyNetworkTransactionSpdy3Test, NetLog) { |
| 3842 static const char* const kExtraHeaders[] = { | 3833 static const char* const kExtraHeaders[] = { |
| 3843 "user-agent", "Chrome", | 3834 "user-agent", "Chrome", |
| 3844 }; | 3835 }; |
| 3845 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(kExtraHeaders, 1, false, 1, | 3836 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(kExtraHeaders, 1, false, 1, |
| 3846 LOWEST)); | 3837 LOWEST)); |
| 3847 MockWrite writes[] = { CreateMockWrite(*req) }; | 3838 MockWrite writes[] = { CreateMockWrite(*req) }; |
| (...skipping 2019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5867 << " Write index: " | 5858 << " Write index: " |
| 5868 << data->write_index(); | 5859 << data->write_index(); |
| 5869 | 5860 |
| 5870 // Verify the SYN_REPLY. | 5861 // Verify the SYN_REPLY. |
| 5871 HttpResponseInfo response = *trans->GetResponseInfo(); | 5862 HttpResponseInfo response = *trans->GetResponseInfo(); |
| 5872 EXPECT_TRUE(response.headers != NULL); | 5863 EXPECT_TRUE(response.headers != NULL); |
| 5873 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 5864 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 5874 } | 5865 } |
| 5875 | 5866 |
| 5876 } // namespace net | 5867 } // namespace net |
| OLD | NEW |