1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "net/http/http_stream_factory_impl_request.h" 6 7 #include "net/http/http_stream_factory_impl_job.h" 8 #include "net/proxy/proxy_info.h" 9 #include "net/proxy/proxy_service.h" 10 #include "net/spdy/spdy_test_util_common.h" 11 #include "testing/gtest/include/gtest/gtest.h" 12 13 namespace net { 14 15 class HttpStreamFactoryImplRequestTest 16 : public ::testing::Test, 17 public ::testing::WithParamInterface<NextProto> {}; 18 19 INSTANTIATE_TEST_CASE_P( 20 NextProto, 21 HttpStreamFactoryImplRequestTest, 22 testing::Values(kProtoDeprecatedSPDY2, 23 kProtoSPDY3, kProtoSPDY31, kProtoSPDY4a2, 24 kProtoHTTP2Draft04)); 25 26 namespace { 27 28 class DoNothingRequestDelegate : public HttpStreamRequest::Delegate { 29 public: 30 DoNothingRequestDelegate() {} 31 32 virtual ~DoNothingRequestDelegate() {} 33 34 // HttpStreamRequest::Delegate 35 virtual void OnStreamReady( 36 const SSLConfig& used_ssl_config, 37 const ProxyInfo& used_proxy_info, 38 HttpStreamBase* stream) OVERRIDE {} 39 virtual void OnWebSocketHandshakeStreamReady( 40 const SSLConfig& used_ssl_config, 41 const ProxyInfo& used_proxy_info, 42 WebSocketHandshakeStreamBase* stream) OVERRIDE {} 43 virtual void OnStreamFailed( 44 int status, 45 const SSLConfig& used_ssl_config) OVERRIDE {} 46 virtual void OnCertificateError( 47 int status, 48 const SSLConfig& used_ssl_config, 49 const SSLInfo& ssl_info) OVERRIDE {} 50 virtual void OnNeedsProxyAuth(const HttpResponseInfo& proxy_response, 51 const SSLConfig& used_ssl_config, 52 const ProxyInfo& used_proxy_info, 53 HttpAuthController* auth_controller) OVERRIDE {} 54 virtual void OnNeedsClientAuth(const SSLConfig& used_ssl_config, 55 SSLCertRequestInfo* cert_info) OVERRIDE {} 56 virtual void OnHttpsProxyTunnelResponse(const HttpResponseInfo& response_info, 57 const SSLConfig& used_ssl_config, 58 const ProxyInfo& used_proxy_info, 59 HttpStreamBase* stream) OVERRIDE {} 60 }; 61 62 } // namespace 63 64 // Make sure that Request passes on its priority updates to its jobs. 65 TEST_P(HttpStreamFactoryImplRequestTest, SetPriority) { 66 SpdySessionDependencies session_deps(GetParam(), 67 ProxyService::CreateDirect()); 68 69 scoped_refptr<HttpNetworkSession> 70 session(SpdySessionDependencies::SpdyCreateSession(&session_deps)); 71 HttpStreamFactoryImpl* factory = 72 static_cast<HttpStreamFactoryImpl*>(session->http_stream_factory()); 73 74 DoNothingRequestDelegate request_delegate; 75 HttpStreamFactoryImpl::Request request( 76 GURL(), factory, &request_delegate, NULL, BoundNetLog()); 77 78 HttpStreamFactoryImpl::Job* job = 79 new HttpStreamFactoryImpl::Job(factory, 80 session, 81 HttpRequestInfo(), 82 DEFAULT_PRIORITY, 83 SSLConfig(), 84 SSLConfig(), 85 NULL); 86 request.AttachJob(job); 87 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); 88 89 request.SetPriority(MEDIUM); 90 EXPECT_EQ(MEDIUM, job->priority()); 91 92 // Make |job| the bound job. 93 request.OnStreamFailed(job, ERR_FAILED, SSLConfig()); 94 95 request.SetPriority(IDLE); 96 EXPECT_EQ(IDLE, job->priority()); 97 } 98 99 } // namespace net 100