OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include <string> | |
6 | |
7 #include "base/memory/ref_counted.h" | |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "net/base/net_util.h" | |
10 #include "net/base/request_priority.h" | |
11 #include "net/dns/mock_host_resolver.h" | |
12 #include "net/http/http_auth_handler_mock.h" | |
13 #include "net/http/http_network_session.h" | |
14 #include "net/http/http_network_transaction.h" | |
15 #include "net/http/http_request_info.h" | |
16 #include "net/http/http_server_properties_impl.h" | |
17 #include "net/http/transport_security_state.h" | |
18 #include "net/proxy/proxy_config_service.h" | |
19 #include "net/proxy/proxy_service.h" | |
20 #include "net/socket/socket_test_util.h" | |
21 #include "net/ssl/ssl_config_service_defaults.h" | |
22 #include "testing/gtest/include/gtest/gtest.h" | |
23 | |
24 namespace net { | |
25 | |
26 namespace { | |
27 | |
28 class SimpleProxyConfigService : public ProxyConfigService { | |
agl
2013/04/15 15:23:51
Looks like this is the third copy of this. Probabl
thaidn_google
2013/04/16 00:38:16
Done.
| |
29 public: | |
30 virtual void AddObserver(Observer* observer) OVERRIDE { | |
31 observer_ = observer; | |
32 } | |
33 | |
34 virtual void RemoveObserver(Observer* observer) OVERRIDE { | |
35 if (observer_ == observer) { | |
36 observer_ = NULL; | |
37 } | |
38 } | |
39 | |
40 virtual ConfigAvailability GetLatestProxyConfig( | |
41 ProxyConfig* config) OVERRIDE { | |
42 *config = config_; | |
43 return CONFIG_VALID; | |
44 } | |
45 | |
46 void IncrementConfigId() { | |
47 config_.set_id(config_.id() + 1); | |
48 observer_->OnProxyConfigChanged(config_, ProxyConfigService::CONFIG_VALID); | |
49 } | |
50 | |
51 private: | |
52 ProxyConfig config_; | |
53 Observer* observer_; | |
54 }; | |
55 | |
56 class HttpNetworkTransactionSSLTest : public testing::Test { | |
57 public: | |
agl
2013/04/15 15:23:51
indentation of this class is incorrect.
thaidn_google
2013/04/16 00:38:16
Done.
| |
58 virtual void SetUp() { | |
59 proxy_config_service_ = new SimpleProxyConfigService(); | |
60 proxy_service_.reset(new ProxyService(proxy_config_service_, | |
61 NULL, NULL)); | |
62 ssl_config_ = new SSLConfigServiceDefaults; | |
63 auth_handler_factory_.reset(new HttpAuthHandlerMock::Factory()); | |
64 | |
65 transport_security_state_.reset(new TransportSecurityState()); | |
66 | |
67 HttpNetworkSession::Params session_params; | |
68 session_params.client_socket_factory = &factory_; | |
69 session_params.proxy_service = proxy_service_.get(); | |
70 session_params.host_resolver = &mock_resolver_; | |
71 session_params.ssl_config_service = ssl_config_.get(); | |
72 session_params.http_auth_handler_factory = auth_handler_factory_.get(); | |
73 session_params.http_server_properties = &http_server_properties_; | |
74 session_params.transport_security_state = | |
75 transport_security_state_.get(); | |
76 session_ = new HttpNetworkSession(session_params); | |
77 } | |
78 | |
79 HttpRequestInfo* GetRequestInfo(std::string url) { | |
80 HttpRequestInfo* request_info = new HttpRequestInfo; | |
81 request_info->url = GURL(url); | |
82 request_info->method = "GET"; | |
83 return request_info; | |
84 } | |
85 | |
86 DeterministicMockClientSocketFactory factory_; | |
87 TestCompletionCallback callback_; | |
88 | |
89 SimpleProxyConfigService* proxy_config_service_; | |
90 scoped_ptr<ProxyService> proxy_service_; | |
91 MockHostResolver mock_resolver_; | |
92 scoped_refptr<SSLConfigService> ssl_config_; | |
93 scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory_; | |
94 HttpServerPropertiesImpl http_server_properties_; | |
95 scoped_ptr<TransportSecurityState> transport_security_state_; | |
96 scoped_refptr<HttpNetworkSession> session_; | |
97 }; | |
98 | |
99 TEST_F(HttpNetworkTransactionSSLTest, Google_Preloaded) { | |
100 scoped_ptr<HttpNetworkTransaction> trans( | |
101 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); | |
102 SSLConfig& ssl_config = trans->server_ssl_config(); | |
103 EXPECT_EQ(ssl_config.version_min, | |
104 SSL_PROTOCOL_VERSION_SSL3); | |
105 TestCompletionCallback callback; | |
106 EXPECT_EQ(ERR_IO_PENDING, | |
107 trans->Start(GetRequestInfo("https://www.google.com/"), | |
108 callback.callback(), BoundNetLog())); | |
109 EXPECT_EQ(ssl_config.version_min, | |
110 SSL_PROTOCOL_VERSION_TLS1); | |
Ryan Sleevi
2013/04/15 18:03:28
style: EXPECT_* macros follow the EXPECT_*(expecte
| |
111 } | |
112 | |
113 TEST_F(HttpNetworkTransactionSSLTest, Google_PreloadedDisabled) { | |
114 scoped_ptr<HttpNetworkTransaction> trans( | |
115 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); | |
116 SSLConfig& ssl_config = trans->server_ssl_config(); | |
117 EXPECT_EQ(ssl_config.version_min, | |
118 SSL_PROTOCOL_VERSION_SSL3); | |
119 TestCompletionCallback callback; | |
120 ssl_config.ssl_version_min_preloaded_disabled = true; | |
121 EXPECT_EQ(ERR_IO_PENDING, | |
122 trans->Start(GetRequestInfo("https://www.google.com/"), | |
123 callback.callback(), BoundNetLog())); | |
124 EXPECT_EQ(ssl_config.version_min, | |
125 SSL_PROTOCOL_VERSION_SSL3); | |
126 } | |
127 | |
128 TEST_F(HttpNetworkTransactionSSLTest, NonGoogle_Preloaded) { | |
129 scoped_ptr<HttpNetworkTransaction> trans( | |
130 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); | |
131 SSLConfig& ssl_config = trans->server_ssl_config(); | |
132 EXPECT_EQ(ssl_config.version_min, | |
133 SSL_PROTOCOL_VERSION_SSL3); | |
134 TestCompletionCallback callback; | |
135 EXPECT_EQ(ERR_IO_PENDING, | |
136 trans->Start(GetRequestInfo("https://www.paypal.com/"), | |
137 callback.callback(), BoundNetLog())); | |
138 EXPECT_EQ(ssl_config.version_min, | |
139 SSL_PROTOCOL_VERSION_SSL3); | |
140 } | |
141 | |
142 } // namespace | |
143 } // namespace net | |
144 | |
OLD | NEW |