| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "net/base/test_completion_callback.h" | 8 #include "net/base/test_completion_callback.h" |
| 9 #include "net/cert/mock_cert_verifier.h" | 9 #include "net/cert/mock_cert_verifier.h" |
| 10 #include "net/dns/mock_host_resolver.h" | 10 #include "net/dns/mock_host_resolver.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 56 |
| 57 namespace net { | 57 namespace net { |
| 58 namespace test { | 58 namespace test { |
| 59 | 59 |
| 60 class QuicNetworkTransactionTest : public PlatformTest { | 60 class QuicNetworkTransactionTest : public PlatformTest { |
| 61 protected: | 61 protected: |
| 62 QuicNetworkTransactionTest() | 62 QuicNetworkTransactionTest() |
| 63 : clock_(new MockClock), | 63 : clock_(new MockClock), |
| 64 ssl_config_service_(new SSLConfigServiceDefaults), | 64 ssl_config_service_(new SSLConfigServiceDefaults), |
| 65 proxy_service_(ProxyService::CreateDirect()), | 65 proxy_service_(ProxyService::CreateDirect()), |
| 66 compressor_(new QuicSpdyCompressor()), | |
| 67 auth_handler_factory_( | 66 auth_handler_factory_( |
| 68 HttpAuthHandlerFactory::CreateDefault(&host_resolver_)) { | 67 HttpAuthHandlerFactory::CreateDefault(&host_resolver_)) { |
| 69 } | 68 } |
| 70 | 69 |
| 71 virtual void SetUp() { | 70 virtual void SetUp() { |
| 72 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 71 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
| 73 MessageLoop::current()->RunUntilIdle(); | 72 MessageLoop::current()->RunUntilIdle(); |
| 74 } | 73 } |
| 75 | 74 |
| 76 virtual void TearDown() { | 75 virtual void TearDown() { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 headers[":version"] = "HTTP/1.1"; | 162 headers[":version"] = "HTTP/1.1"; |
| 164 return SerializeHeaderBlock(headers); | 163 return SerializeHeaderBlock(headers); |
| 165 } | 164 } |
| 166 | 165 |
| 167 std::string GetResponseString(const std::string& status, | 166 std::string GetResponseString(const std::string& status, |
| 168 const std::string& body) { | 167 const std::string& body) { |
| 169 SpdyHeaderBlock headers; | 168 SpdyHeaderBlock headers; |
| 170 headers[":status"] = status; | 169 headers[":status"] = status; |
| 171 headers[":version"] = "HTTP/1.1"; | 170 headers[":version"] = "HTTP/1.1"; |
| 172 headers["content-type"] = "text/plain"; | 171 headers["content-type"] = "text/plain"; |
| 173 return compressor_->CompressHeaders(headers) + body; | 172 return SerializeHeaderBlock(headers) + body; |
| 174 } | 173 } |
| 175 | 174 |
| 176 std::string SerializeHeaderBlock(const SpdyHeaderBlock& headers) { | 175 std::string SerializeHeaderBlock(const SpdyHeaderBlock& headers) { |
| 177 size_t len = SpdyFramer::GetSerializedLength(3, &headers); | 176 size_t len = SpdyFramer::GetSerializedLength(3, &headers); |
| 178 SpdyFrameBuilder builder(len); | 177 SpdyFrameBuilder builder(len); |
| 179 SpdyFramer::WriteHeaderBlock(&builder, 3, &headers); | 178 SpdyFramer::WriteHeaderBlock(&builder, 3, &headers); |
| 180 scoped_ptr<SpdyFrame> frame(builder.take()); | 179 scoped_ptr<SpdyFrame> frame(builder.take()); |
| 181 return std::string(frame->data(), len); | 180 return std::string(frame->data(), len); |
| 182 } | 181 } |
| 183 | 182 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 | 234 |
| 236 QuicPacketHeader header_; | 235 QuicPacketHeader header_; |
| 237 scoped_refptr<HttpNetworkSession> session_; | 236 scoped_refptr<HttpNetworkSession> session_; |
| 238 MockClientSocketFactory socket_factory_; | 237 MockClientSocketFactory socket_factory_; |
| 239 MockCryptoClientStreamFactory crypto_client_stream_factory_; | 238 MockCryptoClientStreamFactory crypto_client_stream_factory_; |
| 240 MockClock* clock_; // Owned by QuicStreamFactory after CreateSession. | 239 MockClock* clock_; // Owned by QuicStreamFactory after CreateSession. |
| 241 MockHostResolver host_resolver_; | 240 MockHostResolver host_resolver_; |
| 242 MockCertVerifier cert_verifier_; | 241 MockCertVerifier cert_verifier_; |
| 243 scoped_refptr<SSLConfigServiceDefaults> ssl_config_service_; | 242 scoped_refptr<SSLConfigServiceDefaults> ssl_config_service_; |
| 244 scoped_ptr<ProxyService> proxy_service_; | 243 scoped_ptr<ProxyService> proxy_service_; |
| 245 scoped_ptr<QuicSpdyCompressor> compressor_; | |
| 246 scoped_ptr<HttpAuthHandlerFactory> auth_handler_factory_; | 244 scoped_ptr<HttpAuthHandlerFactory> auth_handler_factory_; |
| 247 MockRandom random_generator_; | 245 MockRandom random_generator_; |
| 248 HttpServerPropertiesImpl http_server_properties; | 246 HttpServerPropertiesImpl http_server_properties; |
| 249 HttpNetworkSession::Params params_; | 247 HttpNetworkSession::Params params_; |
| 250 }; | 248 }; |
| 251 | 249 |
| 252 TEST_F(QuicNetworkTransactionTest, ForceQuic) { | 250 TEST_F(QuicNetworkTransactionTest, ForceQuic) { |
| 253 params_.origin_port_to_force_quic_on = 80; | 251 params_.origin_port_to_force_quic_on = 80; |
| 254 | 252 |
| 255 HttpRequestInfo request; | 253 HttpRequestInfo request; |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 ASSERT_TRUE(session_->http_server_properties()->HasAlternateProtocol( | 704 ASSERT_TRUE(session_->http_server_properties()->HasAlternateProtocol( |
| 707 HostPortPair::FromURL(request.url))); | 705 HostPortPair::FromURL(request.url))); |
| 708 const PortAlternateProtocolPair alternate = | 706 const PortAlternateProtocolPair alternate = |
| 709 session_->http_server_properties()->GetAlternateProtocol( | 707 session_->http_server_properties()->GetAlternateProtocol( |
| 710 HostPortPair::FromURL(request.url)); | 708 HostPortPair::FromURL(request.url)); |
| 711 EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, alternate.protocol); | 709 EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, alternate.protocol); |
| 712 } | 710 } |
| 713 | 711 |
| 714 } // namespace test | 712 } // namespace test |
| 715 } // namespace net | 713 } // namespace net |
| OLD | NEW |