Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / net / http / http_stream_factory_impl_request_unittest.cc
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, kProtoSPDY4));
24
25 namespace {
26
27 class DoNothingRequestDelegate : public HttpStreamRequest::Delegate {
28  public:
29   DoNothingRequestDelegate() {}
30
31   ~DoNothingRequestDelegate() override {}
32
33   // HttpStreamRequest::Delegate
34   void OnStreamReady(const SSLConfig& used_ssl_config,
35                      const ProxyInfo& used_proxy_info,
36                      HttpStream* stream) override {}
37   void OnWebSocketHandshakeStreamReady(
38       const SSLConfig& used_ssl_config,
39       const ProxyInfo& used_proxy_info,
40       WebSocketHandshakeStreamBase* stream) override {}
41   void OnStreamFailed(int status, const SSLConfig& used_ssl_config) override {}
42   void OnCertificateError(int status,
43                           const SSLConfig& used_ssl_config,
44                           const SSLInfo& ssl_info) override {}
45   void OnNeedsProxyAuth(const HttpResponseInfo& proxy_response,
46                         const SSLConfig& used_ssl_config,
47                         const ProxyInfo& used_proxy_info,
48                         HttpAuthController* auth_controller) override {}
49   void OnNeedsClientAuth(const SSLConfig& used_ssl_config,
50                          SSLCertRequestInfo* cert_info) override {}
51   void OnHttpsProxyTunnelResponse(const HttpResponseInfo& response_info,
52                                   const SSLConfig& used_ssl_config,
53                                   const ProxyInfo& used_proxy_info,
54                                   HttpStream* stream) override {}
55 };
56
57 }  // namespace
58
59 // Make sure that Request passes on its priority updates to its jobs.
60 TEST_P(HttpStreamFactoryImplRequestTest, SetPriority) {
61   SpdySessionDependencies session_deps(GetParam(),
62                                        ProxyService::CreateDirect());
63
64   scoped_refptr<HttpNetworkSession>
65       session(SpdySessionDependencies::SpdyCreateSession(&session_deps));
66   HttpStreamFactoryImpl* factory =
67       static_cast<HttpStreamFactoryImpl*>(session->http_stream_factory());
68
69   DoNothingRequestDelegate request_delegate;
70   HttpStreamFactoryImpl::Request request(
71       GURL(), factory, &request_delegate, NULL, BoundNetLog());
72
73   HttpStreamFactoryImpl::Job* job =
74       new HttpStreamFactoryImpl::Job(factory,
75                                      session.get(),
76                                      HttpRequestInfo(),
77                                      DEFAULT_PRIORITY,
78                                      SSLConfig(),
79                                      SSLConfig(),
80                                      NULL);
81   request.AttachJob(job);
82   EXPECT_EQ(DEFAULT_PRIORITY, job->priority());
83
84   request.SetPriority(MEDIUM);
85   EXPECT_EQ(MEDIUM, job->priority());
86
87   // Make |job| the bound job.
88   request.OnStreamFailed(job, ERR_FAILED, SSLConfig());
89
90   request.SetPriority(IDLE);
91   EXPECT_EQ(IDLE, job->priority());
92 }
93
94 }  // namespace net