Chromium Code Reviews| 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 #include "net/socket/client_socket_factory.h" | 37 #include "net/socket/client_socket_factory.h" |
| 38 #include "net/socket/mock_client_socket_pool_manager.h" | 38 #include "net/socket/mock_client_socket_pool_manager.h" |
| 39 #include "net/socket/socket_test_util.h" | 39 #include "net/socket/socket_test_util.h" |
| 40 #include "net/socket/ssl_client_socket.h" | 40 #include "net/socket/ssl_client_socket.h" |
| 41 #include "net/spdy/spdy_frame_builder.h" | 41 #include "net/spdy/spdy_frame_builder.h" |
| 42 #include "net/spdy/spdy_framer.h" | 42 #include "net/spdy/spdy_framer.h" |
| 43 #include "net/ssl/ssl_config_service_defaults.h" | 43 #include "net/ssl/ssl_config_service_defaults.h" |
| 44 #include "testing/gtest/include/gtest/gtest.h" | 44 #include "testing/gtest/include/gtest/gtest.h" |
| 45 #include "testing/platform_test.h" | 45 #include "testing/platform_test.h" |
| 46 | 46 |
| 47 using std::ostream; | |
| 48 using std::vector; | |
| 49 | |
| 47 //----------------------------------------------------------------------------- | 50 //----------------------------------------------------------------------------- |
| 48 | 51 |
| 49 namespace { | 52 namespace { |
| 50 | 53 |
| 51 // This is the expected return from a current server advertising QUIC. | 54 // This is the expected return from a current server advertising QUIC. |
| 52 static const char kQuicAlternateProtocolHttpHeader[] = | 55 static const char kQuicAlternateProtocolHttpHeader[] = |
| 53 "Alternate-Protocol: 80:quic\r\n\r\n"; | 56 "Alternate-Protocol: 80:quic\r\n\r\n"; |
| 54 static const char kQuicAlternateProtocol50pctHttpHeader[] = | 57 static const char kQuicAlternateProtocol50pctHttpHeader[] = |
| 55 "Alternate-Protocol: 80:quic,p=.5\r\n\r\n"; | 58 "Alternate-Protocol: 80:quic,p=.5\r\n\r\n"; |
| 56 static const char kQuicAlternateProtocolHttpsHeader[] = | 59 static const char kQuicAlternateProtocolHttpsHeader[] = |
| 57 "Alternate-Protocol: 443:quic\r\n\r\n"; | 60 "Alternate-Protocol: 443:quic\r\n\r\n"; |
| 58 | 61 |
| 59 } // namespace | 62 } // namespace |
| 60 | 63 |
| 61 namespace net { | 64 namespace net { |
| 62 namespace test { | 65 namespace test { |
| 63 | 66 |
| 67 namespace { | |
| 68 | |
| 69 // Run all tests with all the combinations of versions and | |
| 70 // enable_connection_racing. | |
| 71 struct TestParams { | |
| 72 TestParams(const QuicVersion version, bool enable_connection_racing) | |
| 73 : version(version), enable_connection_racing(enable_connection_racing) {} | |
| 74 | |
| 75 friend ostream& operator<<(ostream& os, const TestParams& p) { | |
| 76 os << "{ version: " << QuicVersionToString(p.version); | |
| 77 os << " enable_connection_racing: " << p.enable_connection_racing << " }"; | |
| 78 return os; | |
| 79 } | |
| 80 | |
| 81 QuicVersion version; | |
| 82 bool enable_connection_racing; | |
| 83 }; | |
| 84 | |
| 85 // Constructs various test permutations. | |
| 86 vector<TestParams> GetTestParams() { | |
| 87 vector<TestParams> params; | |
| 88 QuicVersionVector all_supported_versions = QuicSupportedVersions(); | |
| 89 for (const QuicVersion version : all_supported_versions) { | |
| 90 params.push_back(TestParams(version, false)); | |
| 91 params.push_back(TestParams(version, true)); | |
| 92 } | |
| 93 return params; | |
| 94 } | |
| 95 | |
| 96 } // namespace anonymous | |
| 97 | |
| 64 // Helper class to encapsulate MockReads and MockWrites for QUIC. | 98 // Helper class to encapsulate MockReads and MockWrites for QUIC. |
| 65 // Simplify ownership issues and the interaction with the MockSocketFactory. | 99 // Simplify ownership issues and the interaction with the MockSocketFactory. |
| 66 class MockQuicData { | 100 class MockQuicData { |
| 67 public: | 101 public: |
| 68 ~MockQuicData() { | 102 ~MockQuicData() { |
| 69 STLDeleteElements(&packets_); | 103 STLDeleteElements(&packets_); |
| 70 } | 104 } |
| 71 | 105 |
| 72 void AddRead(scoped_ptr<QuicEncryptedPacket> packet) { | 106 void AddRead(scoped_ptr<QuicEncryptedPacket> packet) { |
| 73 reads_.push_back(MockRead(SYNCHRONOUS, packet->data(), packet->length(), | 107 reads_.push_back(MockRead(SYNCHRONOUS, packet->data(), packet->length(), |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 97 private: | 131 private: |
| 98 std::vector<QuicEncryptedPacket*> packets_; | 132 std::vector<QuicEncryptedPacket*> packets_; |
| 99 std::vector<MockWrite> writes_; | 133 std::vector<MockWrite> writes_; |
| 100 std::vector<MockRead> reads_; | 134 std::vector<MockRead> reads_; |
| 101 size_t sequence_number_; | 135 size_t sequence_number_; |
| 102 scoped_ptr<SocketDataProvider> socket_data_; | 136 scoped_ptr<SocketDataProvider> socket_data_; |
| 103 }; | 137 }; |
| 104 | 138 |
| 105 class QuicNetworkTransactionTest | 139 class QuicNetworkTransactionTest |
| 106 : public PlatformTest, | 140 : public PlatformTest, |
| 107 public ::testing::WithParamInterface<QuicVersion> { | 141 public ::testing::WithParamInterface<TestParams> { |
| 108 protected: | 142 protected: |
| 109 QuicNetworkTransactionTest() | 143 QuicNetworkTransactionTest() |
| 110 : clock_(new MockClock), | 144 : clock_(new MockClock), |
| 111 maker_(GetParam(), 0, clock_), | 145 maker_(GetParam().version, 0, clock_), |
| 112 ssl_config_service_(new SSLConfigServiceDefaults), | 146 ssl_config_service_(new SSLConfigServiceDefaults), |
| 113 proxy_service_(ProxyService::CreateDirect()), | 147 proxy_service_(ProxyService::CreateDirect()), |
| 114 auth_handler_factory_( | 148 auth_handler_factory_( |
| 115 HttpAuthHandlerFactory::CreateDefault(&host_resolver_)), | 149 HttpAuthHandlerFactory::CreateDefault(&host_resolver_)), |
| 116 random_generator_(0), | 150 random_generator_(0), |
| 117 hanging_data_(nullptr, 0, nullptr, 0) { | 151 hanging_data_(nullptr, 0, nullptr, 0) { |
| 118 request_.method = "GET"; | 152 request_.method = "GET"; |
| 119 request_.url = GURL("http://www.google.com/"); | 153 request_.url = GURL("http://www.google.com/"); |
| 120 request_.load_flags = 0; | 154 request_.load_flags = 0; |
| 121 clock_->AdvanceTime(QuicTime::Delta::FromMilliseconds(20)); | 155 clock_->AdvanceTime(QuicTime::Delta::FromMilliseconds(20)); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 params_.quic_random = &random_generator_; | 240 params_.quic_random = &random_generator_; |
| 207 params_.client_socket_factory = socket_factory; | 241 params_.client_socket_factory = socket_factory; |
| 208 params_.quic_crypto_client_stream_factory = &crypto_client_stream_factory_; | 242 params_.quic_crypto_client_stream_factory = &crypto_client_stream_factory_; |
| 209 params_.host_resolver = &host_resolver_; | 243 params_.host_resolver = &host_resolver_; |
| 210 params_.cert_verifier = &cert_verifier_; | 244 params_.cert_verifier = &cert_verifier_; |
| 211 params_.transport_security_state = &transport_security_state_; | 245 params_.transport_security_state = &transport_security_state_; |
| 212 params_.proxy_service = proxy_service_.get(); | 246 params_.proxy_service = proxy_service_.get(); |
| 213 params_.ssl_config_service = ssl_config_service_.get(); | 247 params_.ssl_config_service = ssl_config_service_.get(); |
| 214 params_.http_auth_handler_factory = auth_handler_factory_.get(); | 248 params_.http_auth_handler_factory = auth_handler_factory_.get(); |
| 215 params_.http_server_properties = http_server_properties.GetWeakPtr(); | 249 params_.http_server_properties = http_server_properties.GetWeakPtr(); |
| 216 params_.quic_supported_versions = SupportedVersions(GetParam()); | 250 params_.quic_supported_versions = SupportedVersions(GetParam().version); |
| 217 | 251 |
| 218 if (use_next_protos) { | 252 if (use_next_protos) { |
| 219 params_.use_alternate_protocols = true; | 253 params_.use_alternate_protocols = true; |
| 220 params_.next_protos = NextProtosWithSpdyAndQuic(true, true); | 254 params_.next_protos = NextProtosWithSpdyAndQuic(true, true); |
| 221 } | 255 } |
| 222 | 256 |
| 223 session_ = new HttpNetworkSession(params_); | 257 session_ = new HttpNetworkSession(params_); |
| 224 session_->quic_stream_factory()->set_require_confirmation(false); | 258 session_->quic_stream_factory()->set_require_confirmation(false); |
| 259 session_->quic_stream_factory()->set_enable_connection_racing( | |
| 260 GetParam().enable_connection_racing); | |
|
Ryan Hamilton
2015/02/04 20:10:29
I'm a bit surprised that these tests pass with con
ramant (doing other things)
2015/02/05 03:39:41
Acknowledged.
ramant (doing other things)
2015/02/05 20:06:28
Undid the changes to this file.
| |
| 225 } | 261 } |
| 226 | 262 |
| 227 void CheckWasQuicResponse(const scoped_ptr<HttpNetworkTransaction>& trans) { | 263 void CheckWasQuicResponse(const scoped_ptr<HttpNetworkTransaction>& trans) { |
| 228 const HttpResponseInfo* response = trans->GetResponseInfo(); | 264 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 229 ASSERT_TRUE(response != nullptr); | 265 ASSERT_TRUE(response != nullptr); |
| 230 ASSERT_TRUE(response->headers.get() != nullptr); | 266 ASSERT_TRUE(response->headers.get() != nullptr); |
| 231 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 267 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 232 EXPECT_TRUE(response->was_fetched_via_spdy); | 268 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 233 EXPECT_TRUE(response->was_npn_negotiated); | 269 EXPECT_TRUE(response->was_npn_negotiated); |
| 234 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_QUIC1_SPDY3, | 270 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_QUIC1_SPDY3, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 scoped_ptr<ProxyService> proxy_service_; | 355 scoped_ptr<ProxyService> proxy_service_; |
| 320 scoped_ptr<HttpAuthHandlerFactory> auth_handler_factory_; | 356 scoped_ptr<HttpAuthHandlerFactory> auth_handler_factory_; |
| 321 MockRandom random_generator_; | 357 MockRandom random_generator_; |
| 322 HttpServerPropertiesImpl http_server_properties; | 358 HttpServerPropertiesImpl http_server_properties; |
| 323 HttpNetworkSession::Params params_; | 359 HttpNetworkSession::Params params_; |
| 324 HttpRequestInfo request_; | 360 HttpRequestInfo request_; |
| 325 CapturingBoundNetLog net_log_; | 361 CapturingBoundNetLog net_log_; |
| 326 StaticSocketDataProvider hanging_data_; | 362 StaticSocketDataProvider hanging_data_; |
| 327 }; | 363 }; |
| 328 | 364 |
| 329 INSTANTIATE_TEST_CASE_P(Version, QuicNetworkTransactionTest, | 365 INSTANTIATE_TEST_CASE_P(Version, |
| 330 ::testing::ValuesIn(QuicSupportedVersions())); | 366 QuicNetworkTransactionTest, |
| 367 ::testing::ValuesIn(GetTestParams())); | |
| 331 | 368 |
| 332 TEST_P(QuicNetworkTransactionTest, ForceQuic) { | 369 TEST_P(QuicNetworkTransactionTest, ForceQuic) { |
| 333 params_.origin_to_force_quic_on = | 370 params_.origin_to_force_quic_on = |
| 334 HostPortPair::FromString("www.google.com:80"); | 371 HostPortPair::FromString("www.google.com:80"); |
| 335 | 372 |
| 336 MockQuicData mock_quic_data; | 373 MockQuicData mock_quic_data; |
| 337 mock_quic_data.AddWrite( | 374 mock_quic_data.AddWrite( |
| 338 ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, | 375 ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
| 339 GetRequestHeaders("GET", "http", "/"))); | 376 GetRequestHeaders("GET", "http", "/"))); |
| 340 mock_quic_data.AddRead( | 377 mock_quic_data.AddRead( |
| (...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1035 nullptr, | 1072 nullptr, |
| 1036 net_log_.bound()); | 1073 net_log_.bound()); |
| 1037 | 1074 |
| 1038 CreateSessionWithNextProtos(); | 1075 CreateSessionWithNextProtos(); |
| 1039 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); | 1076 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 1040 SendRequestAndExpectHttpResponse("hello world"); | 1077 SendRequestAndExpectHttpResponse("hello world"); |
| 1041 } | 1078 } |
| 1042 | 1079 |
| 1043 } // namespace test | 1080 } // namespace test |
| 1044 } // namespace net | 1081 } // namespace net |
| OLD | NEW |