13551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved.
23551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
33551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// found in the LICENSE file.
43551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
53551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "net/http/http_stream_factory_impl_request.h"
63551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
73551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "net/http/http_stream_factory_impl_job.h"
83551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "net/proxy/proxy_info.h"
93551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "net/proxy/proxy_service.h"
103551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "net/spdy/spdy_test_util_common.h"
113551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
123551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
133551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)namespace net {
143551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
153551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class HttpStreamFactoryImplRequestTest
163551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    : public ::testing::Test,
173551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      public ::testing::WithParamInterface<NextProto> {};
183551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)INSTANTIATE_TEST_CASE_P(
203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    NextProto,
213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    HttpStreamFactoryImplRequestTest,
224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    testing::Values(kProtoDeprecatedSPDY2,
23a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch                    kProtoSPDY3, kProtoSPDY31, kProtoSPDY4));
243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)namespace {
263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
273551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class DoNothingRequestDelegate : public HttpStreamRequest::Delegate {
283551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) public:
293551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  DoNothingRequestDelegate() {}
303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
313551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual ~DoNothingRequestDelegate() {}
323551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // HttpStreamRequest::Delegate
343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual void OnStreamReady(
353551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      const SSLConfig& used_ssl_config,
363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      const ProxyInfo& used_proxy_info,
373551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      HttpStreamBase* stream) OVERRIDE {}
381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void OnWebSocketHandshakeStreamReady(
393551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      const SSLConfig& used_ssl_config,
403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      const ProxyInfo& used_proxy_info,
411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      WebSocketHandshakeStreamBase* stream) OVERRIDE {}
423551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual void OnStreamFailed(
433551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      int status,
443551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      const SSLConfig& used_ssl_config) OVERRIDE {}
453551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual void OnCertificateError(
463551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      int status,
473551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      const SSLConfig& used_ssl_config,
483551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      const SSLInfo& ssl_info) OVERRIDE {}
493551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual void OnNeedsProxyAuth(const HttpResponseInfo& proxy_response,
503551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)                                const SSLConfig& used_ssl_config,
513551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)                                const ProxyInfo& used_proxy_info,
523551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)                                HttpAuthController* auth_controller) OVERRIDE {}
533551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual void OnNeedsClientAuth(const SSLConfig& used_ssl_config,
543551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)                                 SSLCertRequestInfo* cert_info) OVERRIDE {}
553551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual void OnHttpsProxyTunnelResponse(const HttpResponseInfo& response_info,
563551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)                                          const SSLConfig& used_ssl_config,
573551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)                                          const ProxyInfo& used_proxy_info,
583551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)                                          HttpStreamBase* stream) OVERRIDE {}
593551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)};
603551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
613551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}  // namespace
623551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
633551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Make sure that Request passes on its priority updates to its jobs.
643551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)TEST_P(HttpStreamFactoryImplRequestTest, SetPriority) {
653551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  SpdySessionDependencies session_deps(GetParam(),
663551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)                                       ProxyService::CreateDirect());
673551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
683551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  scoped_refptr<HttpNetworkSession>
693551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      session(SpdySessionDependencies::SpdyCreateSession(&session_deps));
703551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  HttpStreamFactoryImpl* factory =
713551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      static_cast<HttpStreamFactoryImpl*>(session->http_stream_factory());
723551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
733551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  DoNothingRequestDelegate request_delegate;
743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  HttpStreamFactoryImpl::Request request(
753551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      GURL(), factory, &request_delegate, NULL, BoundNetLog());
763551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
773551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  HttpStreamFactoryImpl::Job* job =
783551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      new HttpStreamFactoryImpl::Job(factory,
791320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                     session.get(),
803551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)                                     HttpRequestInfo(),
813551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)                                     DEFAULT_PRIORITY,
823551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)                                     SSLConfig(),
833551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)                                     SSLConfig(),
843551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)                                     NULL);
853551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  request.AttachJob(job);
863551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_EQ(DEFAULT_PRIORITY, job->priority());
873551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
883551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  request.SetPriority(MEDIUM);
893551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_EQ(MEDIUM, job->priority());
903551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
913551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Make |job| the bound job.
923551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  request.OnStreamFailed(job, ERR_FAILED, SSLConfig());
933551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
943551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  request.SetPriority(IDLE);
953551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_EQ(IDLE, job->priority());
963551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}
973551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
983551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}  // namespace net
99