blob: 878406e6c75748a4e0ec3a22082c12f0fad114af [file] [log] [blame]
[email protected]23e482282013-06-14 16:08:021// Copyright 2013 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit586acc5fe2008-07-26 22:42:524
[email protected]2d731a32010-04-29 01:04:065#include "net/http/http_network_transaction.h"
6
[email protected]77848d12008-11-14 00:00:227#include <math.h> // ceil
[email protected]5285d972011-10-18 18:56:348#include <stdarg.h>
9#include <string>
[email protected]95d88ffe2010-02-04 21:25:3310#include <vector>
[email protected]77848d12008-11-14 00:00:2211
[email protected]2d731a32010-04-29 01:04:0612#include "base/basictypes.h"
[email protected]68bf9152008-09-25 19:47:3013#include "base/compiler_specific.h"
[email protected]57999812013-02-24 05:40:5214#include "base/files/file_path.h"
thestigd8df0332014-09-04 06:33:2915#include "base/files/file_util.h"
[email protected]f3da152d2012-06-02 01:00:5716#include "base/json/json_writer.h"
[email protected]3b63f8f42011-03-28 01:54:1517#include "base/memory/scoped_ptr.h"
[email protected]bf828982013-08-14 18:01:4718#include "base/memory/weak_ptr.h"
[email protected]a34f61ee2014-03-18 20:59:4919#include "base/run_loop.h"
[email protected]125ef482013-06-11 18:32:4720#include "base/strings/string_util.h"
[email protected]750b2f3c2013-06-07 18:41:0521#include "base/strings/utf_string_conversions.h"
[email protected]f36a8132011-09-02 18:36:3322#include "base/test/test_file_util.h"
[email protected]277d5942010-08-11 21:02:3523#include "net/base/auth.h"
[email protected]169d0012010-05-10 23:20:1224#include "net/base/capturing_net_log.h"
mmenkecbc2b712014-10-09 20:29:0725#include "net/base/chunked_upload_data_stream.h"
[email protected]bacff652009-03-31 17:50:3326#include "net/base/completion_callback.h"
mmenkecbc2b712014-10-09 20:29:0727#include "net/base/elements_upload_data_stream.h"
[email protected]58e32bb2013-01-21 18:23:2528#include "net/base/load_timing_info.h"
29#include "net/base/load_timing_info_test_util.h"
[email protected]169d0012010-05-10 23:20:1230#include "net/base/net_log.h"
31#include "net/base/net_log_unittest.h"
[email protected]ac790b42009-12-02 04:31:3132#include "net/base/request_priority.h"
initial.commit586acc5fe2008-07-26 22:42:5233#include "net/base/test_completion_callback.h"
[email protected]42fdb452012-11-01 12:44:4034#include "net/base/test_data_directory.h"
[email protected]b2d26cfd2012-12-11 10:36:0635#include "net/base/upload_bytes_element_reader.h"
[email protected]d98961652012-09-11 20:27:2136#include "net/base/upload_file_element_reader.h"
[email protected]6e7845ae2013-03-29 21:48:1137#include "net/cert/mock_cert_verifier.h"
[email protected]bc71b8772013-04-10 20:55:1638#include "net/dns/host_cache.h"
[email protected]f2cb3cf2013-03-21 01:40:5339#include "net/dns/mock_host_resolver.h"
[email protected]df41d0d82014-03-13 00:43:2440#include "net/http/http_auth_challenge_tokenizer.h"
[email protected]3c32c5f2010-05-18 15:18:1241#include "net/http/http_auth_handler_digest.h"
[email protected]3fd9dae2010-06-21 11:39:0042#include "net/http/http_auth_handler_mock.h"
[email protected]385a4672009-03-11 22:21:2943#include "net/http/http_auth_handler_ntlm.h"
[email protected]0877e3d2009-10-17 22:29:5744#include "net/http/http_basic_stream.h"
initial.commit586acc5fe2008-07-26 22:42:5245#include "net/http/http_network_session.h"
[email protected]87bfa3f2010-09-30 14:54:5646#include "net/http/http_network_session_peer.h"
[email protected]17291a022011-10-10 07:32:5347#include "net/http/http_server_properties_impl.h"
[email protected]0877e3d2009-10-17 22:29:5748#include "net/http/http_stream.h"
[email protected]8e6441ca2010-08-19 05:56:3849#include "net/http/http_stream_factory.h"
[email protected]c41737d2014-05-14 07:47:1950#include "net/http/http_transaction_test_util.h"
[email protected]51fff29d2008-12-19 22:17:5351#include "net/proxy/proxy_config_service_fixed.h"
[email protected]e86839fd2013-08-14 18:29:0352#include "net/proxy/proxy_info.h"
[email protected]631f1322010-04-30 17:59:1153#include "net/proxy/proxy_resolver.h"
54#include "net/proxy/proxy_service.h"
[email protected]f7984fc62009-06-22 23:26:4455#include "net/socket/client_socket_factory.h"
[email protected]483fa202013-05-14 01:07:0356#include "net/socket/client_socket_pool_manager.h"
[email protected]a42dbd142011-11-17 16:42:0257#include "net/socket/mock_client_socket_pool_manager.h"
[email protected]bb88e1d32013-05-03 23:11:0758#include "net/socket/next_proto.h"
[email protected]f7984fc62009-06-22 23:26:4459#include "net/socket/socket_test_util.h"
60#include "net/socket/ssl_client_socket.h"
[email protected]2ff8b312010-04-26 22:20:5461#include "net/spdy/spdy_framer.h"
62#include "net/spdy/spdy_session.h"
63#include "net/spdy/spdy_session_pool.h"
[email protected]23e482282013-06-14 16:08:0264#include "net/spdy/spdy_test_util_common.h"
[email protected]536fd0b2013-03-14 17:41:5765#include "net/ssl/ssl_cert_request_info.h"
[email protected]e86839fd2013-08-14 18:29:0366#include "net/ssl/ssl_config_service.h"
[email protected]536fd0b2013-03-14 17:41:5767#include "net/ssl/ssl_config_service_defaults.h"
68#include "net/ssl/ssl_info.h"
[email protected]6e7845ae2013-03-29 21:48:1169#include "net/test/cert_test_util.h"
[email protected]831e4a32013-11-14 02:14:4470#include "net/websockets/websocket_handshake_stream_base.h"
initial.commit586acc5fe2008-07-26 22:42:5271#include "testing/gtest/include/gtest/gtest.h"
[email protected]23887f04f2008-12-02 19:20:1572#include "testing/platform_test.h"
[email protected]795cbf82013-07-22 09:37:2773#include "url/gurl.h"
initial.commit586acc5fe2008-07-26 22:42:5274
[email protected]ad65a3e2013-12-25 18:18:0175using base::ASCIIToUTF16;
76
initial.commit586acc5fe2008-07-26 22:42:5277//-----------------------------------------------------------------------------
78
[email protected]13c8a092010-07-29 06:15:4479namespace {
80
[email protected]42cba2fb2013-03-29 19:58:5781const base::string16 kBar(ASCIIToUTF16("bar"));
82const base::string16 kBar2(ASCIIToUTF16("bar2"));
83const base::string16 kBar3(ASCIIToUTF16("bar3"));
84const base::string16 kBaz(ASCIIToUTF16("baz"));
85const base::string16 kFirst(ASCIIToUTF16("first"));
86const base::string16 kFoo(ASCIIToUTF16("foo"));
87const base::string16 kFoo2(ASCIIToUTF16("foo2"));
88const base::string16 kFoo3(ASCIIToUTF16("foo3"));
89const base::string16 kFou(ASCIIToUTF16("fou"));
90const base::string16 kSecond(ASCIIToUTF16("second"));
91const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm"));
92const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword"));
[email protected]13c8a092010-07-29 06:15:4493
[email protected]e5c026642012-03-17 00:14:0294int GetIdleSocketCountInTransportSocketPool(net::HttpNetworkSession* session) {
95 return session->GetTransportSocketPool(
96 net::HttpNetworkSession::NORMAL_SOCKET_POOL)->IdleSocketCount();
97}
98
99int GetIdleSocketCountInSSLSocketPool(net::HttpNetworkSession* session) {
100 return session->GetSSLSocketPool(
101 net::HttpNetworkSession::NORMAL_SOCKET_POOL)->IdleSocketCount();
102}
103
[email protected]043b68c82013-08-22 23:41:52104bool IsTransportSocketPoolStalled(net::HttpNetworkSession* session) {
105 return session->GetTransportSocketPool(
106 net::HttpNetworkSession::NORMAL_SOCKET_POOL)->IsStalled();
107}
108
[email protected]f3da152d2012-06-02 01:00:57109// Takes in a Value created from a NetLogHttpResponseParameter, and returns
110// a JSONified list of headers as a single string. Uses single quotes instead
111// of double quotes for easier comparison. Returns false on failure.
[email protected]ea5ef4c2013-06-13 22:50:27112bool GetHeaders(base::DictionaryValue* params, std::string* headers) {
[email protected]f3da152d2012-06-02 01:00:57113 if (!params)
114 return false;
[email protected]ea5ef4c2013-06-13 22:50:27115 base::ListValue* header_list;
[email protected]f3da152d2012-06-02 01:00:57116 if (!params->GetList("headers", &header_list))
117 return false;
118 std::string double_quote_headers;
119 base::JSONWriter::Write(header_list, &double_quote_headers);
[email protected]466c9862013-12-03 22:05:28120 base::ReplaceChars(double_quote_headers, "\"", "'", headers);
[email protected]f3da152d2012-06-02 01:00:57121 return true;
122}
123
[email protected]029c83b62013-01-24 05:28:20124// Tests LoadTimingInfo in the case a socket is reused and no PAC script is
125// used.
126void TestLoadTimingReused(const net::LoadTimingInfo& load_timing_info) {
127 EXPECT_TRUE(load_timing_info.socket_reused);
[email protected]58e32bb2013-01-21 18:23:25128 EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id);
129
[email protected]029c83b62013-01-24 05:28:20130 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null());
131 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null());
132
133 net::ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing);
134 EXPECT_FALSE(load_timing_info.send_start.is_null());
[email protected]58e32bb2013-01-21 18:23:25135
136 EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end);
[email protected]58e32bb2013-01-21 18:23:25137
[email protected]3b23a222013-05-15 21:33:25138 // Set at a higher level.
[email protected]58e32bb2013-01-21 18:23:25139 EXPECT_TRUE(load_timing_info.request_start_time.is_null());
140 EXPECT_TRUE(load_timing_info.request_start.is_null());
[email protected]3b23a222013-05-15 21:33:25141 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null());
[email protected]58e32bb2013-01-21 18:23:25142}
143
[email protected]029c83b62013-01-24 05:28:20144// Tests LoadTimingInfo in the case a new socket is used and no PAC script is
145// used.
[email protected]58e32bb2013-01-21 18:23:25146void TestLoadTimingNotReused(const net::LoadTimingInfo& load_timing_info,
147 int connect_timing_flags) {
[email protected]029c83b62013-01-24 05:28:20148 EXPECT_FALSE(load_timing_info.socket_reused);
149 EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id);
150
151 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null());
152 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null());
153
154 net::ExpectConnectTimingHasTimes(load_timing_info.connect_timing,
[email protected]3b23a222013-05-15 21:33:25155 connect_timing_flags);
[email protected]029c83b62013-01-24 05:28:20156 EXPECT_LE(load_timing_info.connect_timing.connect_end,
157 load_timing_info.send_start);
158
159 EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end);
[email protected]029c83b62013-01-24 05:28:20160
[email protected]3b23a222013-05-15 21:33:25161 // Set at a higher level.
[email protected]029c83b62013-01-24 05:28:20162 EXPECT_TRUE(load_timing_info.request_start_time.is_null());
163 EXPECT_TRUE(load_timing_info.request_start.is_null());
[email protected]3b23a222013-05-15 21:33:25164 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null());
[email protected]029c83b62013-01-24 05:28:20165}
166
167// Tests LoadTimingInfo in the case a socket is reused and a PAC script is
168// used.
169void TestLoadTimingReusedWithPac(const net::LoadTimingInfo& load_timing_info) {
170 EXPECT_TRUE(load_timing_info.socket_reused);
171 EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id);
172
173 net::ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing);
174
175 EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null());
176 EXPECT_LE(load_timing_info.proxy_resolve_start,
177 load_timing_info.proxy_resolve_end);
178 EXPECT_LE(load_timing_info.proxy_resolve_end,
179 load_timing_info.send_start);
180 EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end);
[email protected]029c83b62013-01-24 05:28:20181
[email protected]3b23a222013-05-15 21:33:25182 // Set at a higher level.
[email protected]029c83b62013-01-24 05:28:20183 EXPECT_TRUE(load_timing_info.request_start_time.is_null());
184 EXPECT_TRUE(load_timing_info.request_start.is_null());
[email protected]3b23a222013-05-15 21:33:25185 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null());
[email protected]029c83b62013-01-24 05:28:20186}
187
188// Tests LoadTimingInfo in the case a new socket is used and a PAC script is
189// used.
190void TestLoadTimingNotReusedWithPac(const net::LoadTimingInfo& load_timing_info,
191 int connect_timing_flags) {
192 EXPECT_FALSE(load_timing_info.socket_reused);
193 EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id);
194
195 EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null());
196 EXPECT_LE(load_timing_info.proxy_resolve_start,
197 load_timing_info.proxy_resolve_end);
198 EXPECT_LE(load_timing_info.proxy_resolve_end,
199 load_timing_info.connect_timing.connect_start);
200 net::ExpectConnectTimingHasTimes(load_timing_info.connect_timing,
201 connect_timing_flags);
202 EXPECT_LE(load_timing_info.connect_timing.connect_end,
203 load_timing_info.send_start);
204
205 EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end);
[email protected]029c83b62013-01-24 05:28:20206
[email protected]3b23a222013-05-15 21:33:25207 // Set at a higher level.
[email protected]029c83b62013-01-24 05:28:20208 EXPECT_TRUE(load_timing_info.request_start_time.is_null());
209 EXPECT_TRUE(load_timing_info.request_start.is_null());
[email protected]3b23a222013-05-15 21:33:25210 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null());
[email protected]58e32bb2013-01-21 18:23:25211}
212
[email protected]13c8a092010-07-29 06:15:44213} // namespace
214
[email protected]89ceba9a2009-03-21 03:46:06215namespace net {
216
[email protected]448d4ca52012-03-04 04:12:23217namespace {
218
[email protected]c6bf8152012-12-02 07:43:34219HttpNetworkSession* CreateSession(SpdySessionDependencies* session_deps) {
220 return SpdySessionDependencies::SpdyCreateSession(session_deps);
[email protected]e8d536192008-10-17 22:21:14221}
222
[email protected]448d4ca52012-03-04 04:12:23223} // namespace
224
[email protected]23e482282013-06-14 16:08:02225class HttpNetworkTransactionTest
226 : public PlatformTest,
227 public ::testing::WithParamInterface<NextProto> {
[email protected]483fa202013-05-14 01:07:03228 public:
[email protected]23e482282013-06-14 16:08:02229 virtual ~HttpNetworkTransactionTest() {
[email protected]483fa202013-05-14 01:07:03230 // Important to restore the per-pool limit first, since the pool limit must
231 // always be greater than group limit, and the tests reduce both limits.
232 ClientSocketPoolManager::set_max_sockets_per_pool(
233 HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_);
234 ClientSocketPoolManager::set_max_sockets_per_group(
235 HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_);
236 }
237
[email protected]e3ceb682011-06-28 23:55:46238 protected:
[email protected]23e482282013-06-14 16:08:02239 HttpNetworkTransactionTest()
240 : spdy_util_(GetParam()),
241 session_deps_(GetParam()),
[email protected]483fa202013-05-14 01:07:03242 old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group(
243 HttpNetworkSession::NORMAL_SOCKET_POOL)),
244 old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool(
245 HttpNetworkSession::NORMAL_SOCKET_POOL)) {
246 }
[email protected]bb88e1d32013-05-03 23:11:07247
[email protected]e3ceb682011-06-28 23:55:46248 struct SimpleGetHelperResult {
249 int rv;
250 std::string status_line;
251 std::string response_data;
[email protected]b8015c42013-12-24 15:18:19252 int64 totalReceivedBytes;
[email protected]58e32bb2013-01-21 18:23:25253 LoadTimingInfo load_timing_info;
[email protected]e3ceb682011-06-28 23:55:46254 };
255
dcheng67be2b1f2014-10-27 21:47:29256 void SetUp() override {
[email protected]0b0bf032010-09-21 18:08:50257 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests();
[email protected]2da659e2013-05-23 20:51:34258 base::MessageLoop::current()->RunUntilIdle();
[email protected]2ff8b312010-04-26 22:20:54259 }
260
dcheng67be2b1f2014-10-27 21:47:29261 void TearDown() override {
[email protected]0b0bf032010-09-21 18:08:50262 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests();
[email protected]2da659e2013-05-23 20:51:34263 base::MessageLoop::current()->RunUntilIdle();
[email protected]0e75a732008-10-16 20:36:09264 // Empty the current queue.
[email protected]2da659e2013-05-23 20:51:34265 base::MessageLoop::current()->RunUntilIdle();
[email protected]0e75a732008-10-16 20:36:09266 PlatformTest::TearDown();
[email protected]0b0bf032010-09-21 18:08:50267 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests();
[email protected]2da659e2013-05-23 20:51:34268 base::MessageLoop::current()->RunUntilIdle();
[email protected]0e75a732008-10-16 20:36:09269 }
270
bnc33b8cef42014-11-19 17:30:38271 const char* GetAlternateProtocolFromParam() {
272 return
273 AlternateProtocolToString(AlternateProtocolFromNextProto(GetParam()));
274 }
275
[email protected]8a0fc822013-06-27 20:52:43276 // This is the expected return from a current server advertising SPDY.
277 std::string GetAlternateProtocolHttpHeader() {
bnc33b8cef42014-11-19 17:30:38278 return std::string("Alternate-Protocol: 443:") +
279 GetAlternateProtocolFromParam() + "\r\n\r\n";
[email protected]8a0fc822013-06-27 20:52:43280 }
281
[email protected]202965992011-12-07 23:04:51282 // Either |write_failure| specifies a write failure or |read_failure|
283 // specifies a read failure when using a reused socket. In either case, the
284 // failure should cause the network transaction to resend the request, and the
285 // other argument should be NULL.
286 void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure,
287 const MockRead* read_failure);
initial.commit586acc5fe2008-07-26 22:42:52288
[email protected]a34f61ee2014-03-18 20:59:49289 // Either |write_failure| specifies a write failure or |read_failure|
290 // specifies a read failure when using a reused socket. In either case, the
291 // failure should cause the network transaction to resend the request, and the
292 // other argument should be NULL.
293 void PreconnectErrorResendRequestTest(const MockWrite* write_failure,
[email protected]09356c652014-03-25 15:36:10294 const MockRead* read_failure,
295 bool use_spdy);
[email protected]a34f61ee2014-03-18 20:59:49296
[email protected]5a60c8b2011-10-19 20:14:29297 SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[],
298 size_t data_count) {
[email protected]ff007e162009-05-23 09:13:15299 SimpleGetHelperResult out;
initial.commit586acc5fe2008-07-26 22:42:52300
[email protected]ff007e162009-05-23 09:13:15301 HttpRequestInfo request;
302 request.method = "GET";
303 request.url = GURL("http://www.google.com/");
304 request.load_flags = 0;
initial.commit586acc5fe2008-07-26 22:42:52305
[email protected]58e32bb2013-01-21 18:23:25306 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:07307 session_deps_.net_log = log.bound().net_log();
[email protected]3fe8d2f82013-10-17 08:56:07308 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:27309 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:41310 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:27311
[email protected]5a60c8b2011-10-19 20:14:29312 for (size_t i = 0; i < data_count; ++i) {
[email protected]bb88e1d32013-05-03 23:11:07313 session_deps_.socket_factory->AddSocketDataProvider(data[i]);
[email protected]5a60c8b2011-10-19 20:14:29314 }
initial.commit586acc5fe2008-07-26 22:42:52315
[email protected]49639fa2011-12-20 23:22:41316 TestCompletionCallback callback;
initial.commit586acc5fe2008-07-26 22:42:52317
[email protected]c47c0372014-03-12 23:07:02318 EXPECT_TRUE(log.bound().IsLogging());
[email protected]49639fa2011-12-20 23:22:41319 int rv = trans->Start(&request, callback.callback(), log.bound());
[email protected]ff007e162009-05-23 09:13:15320 EXPECT_EQ(ERR_IO_PENDING, rv);
initial.commit586acc5fe2008-07-26 22:42:52321
[email protected]ff007e162009-05-23 09:13:15322 out.rv = callback.WaitForResult();
[email protected]58e32bb2013-01-21 18:23:25323
324 // Even in the failure cases that use this function, connections are always
325 // successfully established before the error.
326 EXPECT_TRUE(trans->GetLoadTimingInfo(&out.load_timing_info));
327 TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES);
328
[email protected]ff007e162009-05-23 09:13:15329 if (out.rv != OK)
330 return out;
331
332 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:50333 // Can't use ASSERT_* inside helper functions like this, so
334 // return an error.
[email protected]90499482013-06-01 00:39:50335 if (response == NULL || response->headers.get() == NULL) {
[email protected]fe2255a2011-09-20 19:37:50336 out.rv = ERR_UNEXPECTED;
337 return out;
338 }
[email protected]ff007e162009-05-23 09:13:15339 out.status_line = response->headers->GetStatusLine();
340
[email protected]80a09a82012-11-16 17:40:06341 EXPECT_EQ("127.0.0.1", response->socket_address.host());
342 EXPECT_EQ(80, response->socket_address.port());
[email protected]6d81b482011-02-22 19:47:19343
[email protected]ff007e162009-05-23 09:13:15344 rv = ReadTransaction(trans.get(), &out.response_data);
345 EXPECT_EQ(OK, rv);
[email protected]b2fcd0e2010-12-01 15:19:40346
[email protected]f3da152d2012-06-02 01:00:57347 net::CapturingNetLog::CapturedEntryList entries;
[email protected]b2fcd0e2010-12-01 15:19:40348 log.GetEntries(&entries);
[email protected]dbb83db2010-05-11 18:13:39349 size_t pos = ExpectLogContainsSomewhere(
[email protected]b2fcd0e2010-12-01 15:19:40350 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS,
[email protected]169d0012010-05-10 23:20:12351 NetLog::PHASE_NONE);
[email protected]dbb83db2010-05-11 18:13:39352 ExpectLogContainsSomewhere(
[email protected]b2fcd0e2010-12-01 15:19:40353 entries, pos,
[email protected]dbb83db2010-05-11 18:13:39354 NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS,
355 NetLog::PHASE_NONE);
[email protected]ff007e162009-05-23 09:13:15356
[email protected]f3da152d2012-06-02 01:00:57357 std::string line;
358 EXPECT_TRUE(entries[pos].GetStringValue("line", &line));
359 EXPECT_EQ("GET / HTTP/1.1\r\n", line);
360
[email protected]79e1fd62013-06-20 06:50:04361 HttpRequestHeaders request_headers;
362 EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers));
363 std::string value;
364 EXPECT_TRUE(request_headers.GetHeader("Host", &value));
365 EXPECT_EQ("www.google.com", value);
366 EXPECT_TRUE(request_headers.GetHeader("Connection", &value));
367 EXPECT_EQ("keep-alive", value);
368
369 std::string response_headers;
370 EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers));
371 EXPECT_EQ("['Host: www.google.com','Connection: keep-alive']",
372 response_headers);
[email protected]3deb9a52010-11-11 00:24:40373
[email protected]b8015c42013-12-24 15:18:19374 out.totalReceivedBytes = trans->GetTotalReceivedBytes();
[email protected]aecfbf22008-10-16 02:02:47375 return out;
[email protected]ff007e162009-05-23 09:13:15376 }
initial.commit586acc5fe2008-07-26 22:42:52377
[email protected]5a60c8b2011-10-19 20:14:29378 SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[],
379 size_t reads_count) {
380 StaticSocketDataProvider reads(data_reads, reads_count, NULL, 0);
381 StaticSocketDataProvider* data[] = { &reads };
382 return SimpleGetHelperForData(data, 1);
383 }
384
[email protected]b8015c42013-12-24 15:18:19385 int64 ReadsSize(MockRead data_reads[], size_t reads_count) {
386 int64 size = 0;
387 for (size_t i = 0; i < reads_count; ++i)
388 size += data_reads[i].data_len;
389 return size;
390 }
391
[email protected]ff007e162009-05-23 09:13:15392 void ConnectStatusHelperWithExpectedStatus(const MockRead& status,
393 int expected_status);
initial.commit586acc5fe2008-07-26 22:42:52394
[email protected]ff007e162009-05-23 09:13:15395 void ConnectStatusHelper(const MockRead& status);
[email protected]bb88e1d32013-05-03 23:11:07396
397 void BypassHostCacheOnRefreshHelper(int load_flags);
398
399 void CheckErrorIsPassedBack(int error, IoMode mode);
400
[email protected]4bd46222013-05-14 19:32:23401 SpdyTestUtil spdy_util_;
[email protected]bb88e1d32013-05-03 23:11:07402 SpdySessionDependencies session_deps_;
[email protected]483fa202013-05-14 01:07:03403
404 // Original socket limits. Some tests set these. Safest to always restore
405 // them once each test has been run.
406 int old_max_group_sockets_;
407 int old_max_pool_sockets_;
[email protected]ff007e162009-05-23 09:13:15408};
[email protected]231d5a32008-09-13 00:45:27409
[email protected]23e482282013-06-14 16:08:02410INSTANTIATE_TEST_CASE_P(
411 NextProto,
412 HttpNetworkTransactionTest,
bnc33b8cef42014-11-19 17:30:38413 testing::Values(kProtoSPDY31, kProtoSPDY4_14, kProtoSPDY4_15));
[email protected]23e482282013-06-14 16:08:02414
[email protected]448d4ca52012-03-04 04:12:23415namespace {
416
[email protected]1826a402014-01-08 15:40:48417class BeforeNetworkStartHandler {
418 public:
419 explicit BeforeNetworkStartHandler(bool defer)
420 : defer_on_before_network_start_(defer),
421 observed_before_network_start_(false) {}
422
423 void OnBeforeNetworkStart(bool* defer) {
424 *defer = defer_on_before_network_start_;
425 observed_before_network_start_ = true;
426 }
427
428 bool observed_before_network_start() const {
429 return observed_before_network_start_;
430 }
431
432 private:
433 const bool defer_on_before_network_start_;
434 bool observed_before_network_start_;
435
436 DISALLOW_COPY_AND_ASSIGN(BeforeNetworkStartHandler);
437};
438
[email protected]597a1ab2014-06-26 08:12:27439class BeforeProxyHeadersSentHandler {
440 public:
441 BeforeProxyHeadersSentHandler()
442 : observed_before_proxy_headers_sent_(false) {}
443
[email protected]1252d42f2014-07-01 21:20:20444 void OnBeforeProxyHeadersSent(const ProxyInfo& proxy_info,
445 HttpRequestHeaders* request_headers) {
[email protected]597a1ab2014-06-26 08:12:27446 observed_before_proxy_headers_sent_ = true;
447 observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI();
448 }
449
450 bool observed_before_proxy_headers_sent() const {
451 return observed_before_proxy_headers_sent_;
452 }
453
454 std::string observed_proxy_server_uri() const {
455 return observed_proxy_server_uri_;
456 }
457
458 private:
459 bool observed_before_proxy_headers_sent_;
460 std::string observed_proxy_server_uri_;
461
462 DISALLOW_COPY_AND_ASSIGN(BeforeProxyHeadersSentHandler);
463};
464
[email protected]15a5ccf82008-10-23 19:57:43465// Fill |str| with a long header list that consumes >= |size| bytes.
466void FillLargeHeadersString(std::string* str, int size) {
[email protected]4ddaf2502008-10-23 18:26:19467 const char* row =
468 "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n";
469 const int sizeof_row = strlen(row);
470 const int num_rows = static_cast<int>(
471 ceil(static_cast<float>(size) / sizeof_row));
472 const int sizeof_data = num_rows * sizeof_row;
473 DCHECK(sizeof_data >= size);
[email protected]15a5ccf82008-10-23 19:57:43474 str->reserve(sizeof_data);
[email protected]372d34a2008-11-05 21:30:51475
[email protected]4ddaf2502008-10-23 18:26:19476 for (int i = 0; i < num_rows; ++i)
[email protected]15a5ccf82008-10-23 19:57:43477 str->append(row, sizeof_row);
[email protected]4ddaf2502008-10-23 18:26:19478}
479
[email protected]385a4672009-03-11 22:21:29480// Alternative functions that eliminate randomness and dependency on the local
481// host name so that the generated NTLM messages are reproducible.
[email protected]fe2bc6a2009-03-23 16:52:20482void MockGenerateRandom1(uint8* output, size_t n) {
[email protected]385a4672009-03-11 22:21:29483 static const uint8 bytes[] = {
484 0x55, 0x29, 0x66, 0x26, 0x6b, 0x9c, 0x73, 0x54
485 };
486 static size_t current_byte = 0;
487 for (size_t i = 0; i < n; ++i) {
488 output[i] = bytes[current_byte++];
489 current_byte %= arraysize(bytes);
490 }
491}
492
[email protected]fe2bc6a2009-03-23 16:52:20493void MockGenerateRandom2(uint8* output, size_t n) {
[email protected]385a4672009-03-11 22:21:29494 static const uint8 bytes[] = {
495 0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, 0x70, 0xa1,
496 0x4e, 0xe7, 0x87, 0x45, 0x31, 0x5b, 0xd3, 0x1f
497 };
498 static size_t current_byte = 0;
499 for (size_t i = 0; i < n; ++i) {
500 output[i] = bytes[current_byte++];
501 current_byte %= arraysize(bytes);
502 }
503}
504
[email protected]fe2bc6a2009-03-23 16:52:20505std::string MockGetHostName() {
506 return "WTC-WIN7";
[email protected]385a4672009-03-11 22:21:29507}
508
[email protected]e60e47a2010-07-14 03:37:18509template<typename ParentPool>
510class CaptureGroupNameSocketPool : public ParentPool {
[email protected]04e5be32009-06-26 20:00:31511 public:
[email protected]9e1bdd32011-02-03 21:48:34512 CaptureGroupNameSocketPool(HostResolver* host_resolver,
513 CertVerifier* cert_verifier);
[email protected]e60e47a2010-07-14 03:37:18514
[email protected]d80a4322009-08-14 07:07:49515 const std::string last_group_name_received() const {
516 return last_group_name_;
517 }
518
[email protected]684970b2009-08-14 04:54:46519 virtual int RequestSocket(const std::string& group_name,
[email protected]d80a4322009-08-14 07:07:49520 const void* socket_params,
[email protected]ac790b42009-12-02 04:31:31521 RequestPriority priority,
[email protected]04e5be32009-06-26 20:00:31522 ClientSocketHandle* handle,
[email protected]49639fa2011-12-20 23:22:41523 const CompletionCallback& callback,
[email protected]9e743cd2010-03-16 07:03:53524 const BoundNetLog& net_log) {
[email protected]04e5be32009-06-26 20:00:31525 last_group_name_ = group_name;
526 return ERR_IO_PENDING;
527 }
[email protected]04e5be32009-06-26 20:00:31528 virtual void CancelRequest(const std::string& group_name,
[email protected]05ea9ff2010-07-15 19:08:21529 ClientSocketHandle* handle) {}
[email protected]04e5be32009-06-26 20:00:31530 virtual void ReleaseSocket(const std::string& group_name,
[email protected]18ccfdb2013-08-15 00:13:44531 scoped_ptr<StreamSocket> socket,
[email protected]9f95c692011-02-11 19:20:19532 int id) {}
[email protected]04e5be32009-06-26 20:00:31533 virtual void CloseIdleSockets() {}
[email protected]04e5be32009-06-26 20:00:31534 virtual int IdleSocketCount() const {
535 return 0;
536 }
537 virtual int IdleSocketCountInGroup(const std::string& group_name) const {
538 return 0;
539 }
540 virtual LoadState GetLoadState(const std::string& group_name,
541 const ClientSocketHandle* handle) const {
542 return LOAD_STATE_IDLE;
543 }
[email protected]a796bcec2010-03-22 17:17:26544 virtual base::TimeDelta ConnectionTimeout() const {
545 return base::TimeDelta();
546 }
[email protected]d80a4322009-08-14 07:07:49547
548 private:
[email protected]04e5be32009-06-26 20:00:31549 std::string last_group_name_;
550};
551
[email protected]ab739042011-04-07 15:22:28552typedef CaptureGroupNameSocketPool<TransportClientSocketPool>
553CaptureGroupNameTransportSocketPool;
[email protected]e772db3f2010-07-12 18:11:13554typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool>
555CaptureGroupNameHttpProxySocketPool;
[email protected]2d731a32010-04-29 01:04:06556typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool>
[email protected]2227c692010-05-04 15:36:11557CaptureGroupNameSOCKSSocketPool;
[email protected]e60e47a2010-07-14 03:37:18558typedef CaptureGroupNameSocketPool<SSLClientSocketPool>
559CaptureGroupNameSSLSocketPool;
560
561template<typename ParentPool>
562CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool(
[email protected]9e1bdd32011-02-03 21:48:34563 HostResolver* host_resolver,
564 CertVerifier* /* cert_verifier */)
565 : ParentPool(0, 0, NULL, host_resolver, NULL, NULL) {}
[email protected]e60e47a2010-07-14 03:37:18566
567template<>
[email protected]2df19bb2010-08-25 20:13:46568CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool(
[email protected]9e1bdd32011-02-03 21:48:34569 HostResolver* host_resolver,
570 CertVerifier* /* cert_verifier */)
bengr39e406102014-09-10 23:04:46571 : HttpProxyClientSocketPool(
572 0, 0, NULL, host_resolver, NULL, NULL, NULL, NULL) {}
[email protected]2df19bb2010-08-25 20:13:46573
[email protected]007b3f82013-04-09 08:46:45574template <>
[email protected]e60e47a2010-07-14 03:37:18575CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool(
[email protected]9e1bdd32011-02-03 21:48:34576 HostResolver* host_resolver,
577 CertVerifier* cert_verifier)
[email protected]007b3f82013-04-09 08:46:45578 : SSLClientSocketPool(0,
579 0,
580 NULL,
581 host_resolver,
582 cert_verifier,
583 NULL,
584 NULL,
[email protected]284303b62013-11-28 15:11:54585 NULL,
[email protected]007b3f82013-04-09 08:46:45586 std::string(),
587 NULL,
588 NULL,
589 NULL,
590 NULL,
591 NULL,
[email protected]8e458552014-08-05 00:02:15592 false,
593 NULL) {
594}
[email protected]2227c692010-05-04 15:36:11595
[email protected]231d5a32008-09-13 00:45:27596//-----------------------------------------------------------------------------
597
[email protected]79cb5c12011-09-12 13:12:04598// Helper functions for validating that AuthChallengeInfo's are correctly
599// configured for common cases.
600bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) {
601 if (!auth_challenge)
602 return false;
603 EXPECT_FALSE(auth_challenge->is_proxy);
604 EXPECT_EQ("www.google.com:80", auth_challenge->challenger.ToString());
605 EXPECT_EQ("MyRealm1", auth_challenge->realm);
606 EXPECT_EQ("basic", auth_challenge->scheme);
607 return true;
608}
609
610bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) {
611 if (!auth_challenge)
612 return false;
613 EXPECT_TRUE(auth_challenge->is_proxy);
614 EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString());
615 EXPECT_EQ("MyRealm1", auth_challenge->realm);
616 EXPECT_EQ("basic", auth_challenge->scheme);
617 return true;
618}
619
620bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) {
621 if (!auth_challenge)
622 return false;
623 EXPECT_FALSE(auth_challenge->is_proxy);
624 EXPECT_EQ("www.google.com:80", auth_challenge->challenger.ToString());
625 EXPECT_EQ("digestive", auth_challenge->realm);
626 EXPECT_EQ("digest", auth_challenge->scheme);
627 return true;
628}
629
630bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) {
631 if (!auth_challenge)
632 return false;
633 EXPECT_FALSE(auth_challenge->is_proxy);
634 EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString());
635 EXPECT_EQ(std::string(), auth_challenge->realm);
636 EXPECT_EQ("ntlm", auth_challenge->scheme);
637 return true;
638}
639
[email protected]448d4ca52012-03-04 04:12:23640} // namespace
641
[email protected]23e482282013-06-14 16:08:02642TEST_P(HttpNetworkTransactionTest, Basic) {
[email protected]3fe8d2f82013-10-17 08:56:07643 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]d207a5f2009-06-04 05:28:40644 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:41645 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]231d5a32008-09-13 00:45:27646}
647
[email protected]23e482282013-06-14 16:08:02648TEST_P(HttpNetworkTransactionTest, SimpleGET) {
[email protected]231d5a32008-09-13 00:45:27649 MockRead data_reads[] = {
[email protected]217e6022008-09-29 18:18:35650 MockRead("HTTP/1.0 200 OK\r\n\r\n"),
651 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:06652 MockRead(SYNCHRONOUS, OK),
[email protected]231d5a32008-09-13 00:45:27653 };
[email protected]31a2bfe2010-02-09 08:03:39654 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
655 arraysize(data_reads));
[email protected]1c773ea12009-04-28 19:58:42656 EXPECT_EQ(OK, out.rv);
[email protected]231d5a32008-09-13 00:45:27657 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line);
658 EXPECT_EQ("hello world", out.response_data);
[email protected]b8015c42013-12-24 15:18:19659 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads));
660 EXPECT_EQ(reads_size, out.totalReceivedBytes);
[email protected]231d5a32008-09-13 00:45:27661}
662
663// Response with no status line.
[email protected]23e482282013-06-14 16:08:02664TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) {
[email protected]231d5a32008-09-13 00:45:27665 MockRead data_reads[] = {
[email protected]217e6022008-09-29 18:18:35666 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:06667 MockRead(SYNCHRONOUS, OK),
[email protected]231d5a32008-09-13 00:45:27668 };
[email protected]31a2bfe2010-02-09 08:03:39669 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
670 arraysize(data_reads));
[email protected]1c773ea12009-04-28 19:58:42671 EXPECT_EQ(OK, out.rv);
[email protected]231d5a32008-09-13 00:45:27672 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line);
673 EXPECT_EQ("hello world", out.response_data);
[email protected]b8015c42013-12-24 15:18:19674 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads));
675 EXPECT_EQ(reads_size, out.totalReceivedBytes);
[email protected]231d5a32008-09-13 00:45:27676}
677
678// Allow up to 4 bytes of junk to precede status line.
[email protected]23e482282013-06-14 16:08:02679TEST_P(HttpNetworkTransactionTest, StatusLineJunk3Bytes) {
[email protected]231d5a32008-09-13 00:45:27680 MockRead data_reads[] = {
[email protected]217e6022008-09-29 18:18:35681 MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"),
[email protected]8ddf8322012-02-23 18:08:06682 MockRead(SYNCHRONOUS, OK),
[email protected]231d5a32008-09-13 00:45:27683 };
[email protected]31a2bfe2010-02-09 08:03:39684 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
685 arraysize(data_reads));
[email protected]1c773ea12009-04-28 19:58:42686 EXPECT_EQ(OK, out.rv);
[email protected]231d5a32008-09-13 00:45:27687 EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line);
688 EXPECT_EQ("DATA", out.response_data);
[email protected]b8015c42013-12-24 15:18:19689 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads));
690 EXPECT_EQ(reads_size, out.totalReceivedBytes);
[email protected]231d5a32008-09-13 00:45:27691}
692
693// Allow up to 4 bytes of junk to precede status line.
[email protected]23e482282013-06-14 16:08:02694TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes) {
[email protected]231d5a32008-09-13 00:45:27695 MockRead data_reads[] = {
[email protected]217e6022008-09-29 18:18:35696 MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"),
[email protected]8ddf8322012-02-23 18:08:06697 MockRead(SYNCHRONOUS, OK),
[email protected]231d5a32008-09-13 00:45:27698 };
[email protected]31a2bfe2010-02-09 08:03:39699 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
700 arraysize(data_reads));
[email protected]1c773ea12009-04-28 19:58:42701 EXPECT_EQ(OK, out.rv);
[email protected]231d5a32008-09-13 00:45:27702 EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line);
703 EXPECT_EQ("DATA", out.response_data);
[email protected]b8015c42013-12-24 15:18:19704 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads));
705 EXPECT_EQ(reads_size, out.totalReceivedBytes);
[email protected]231d5a32008-09-13 00:45:27706}
707
708// Beyond 4 bytes of slop and it should fail to find a status line.
[email protected]23e482282013-06-14 16:08:02709TEST_P(HttpNetworkTransactionTest, StatusLineJunk5Bytes) {
[email protected]231d5a32008-09-13 00:45:27710 MockRead data_reads[] = {
[email protected]217e6022008-09-29 18:18:35711 MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"),
[email protected]8ddf8322012-02-23 18:08:06712 MockRead(SYNCHRONOUS, OK),
[email protected]231d5a32008-09-13 00:45:27713 };
[email protected]31a2bfe2010-02-09 08:03:39714 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
715 arraysize(data_reads));
[email protected]1c773ea12009-04-28 19:58:42716 EXPECT_EQ(OK, out.rv);
[email protected]3d2a59b2008-09-26 19:44:25717 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line);
718 EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data);
[email protected]b8015c42013-12-24 15:18:19719 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads));
720 EXPECT_EQ(reads_size, out.totalReceivedBytes);
[email protected]231d5a32008-09-13 00:45:27721}
722
723// Same as StatusLineJunk4Bytes, except the read chunks are smaller.
[email protected]23e482282013-06-14 16:08:02724TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) {
[email protected]231d5a32008-09-13 00:45:27725 MockRead data_reads[] = {
[email protected]217e6022008-09-29 18:18:35726 MockRead("\n"),
727 MockRead("\n"),
728 MockRead("Q"),
729 MockRead("J"),
730 MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"),
[email protected]8ddf8322012-02-23 18:08:06731 MockRead(SYNCHRONOUS, OK),
[email protected]231d5a32008-09-13 00:45:27732 };
[email protected]31a2bfe2010-02-09 08:03:39733 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
734 arraysize(data_reads));
[email protected]1c773ea12009-04-28 19:58:42735 EXPECT_EQ(OK, out.rv);
[email protected]231d5a32008-09-13 00:45:27736 EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line);
737 EXPECT_EQ("DATA", out.response_data);
[email protected]b8015c42013-12-24 15:18:19738 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads));
739 EXPECT_EQ(reads_size, out.totalReceivedBytes);
[email protected]231d5a32008-09-13 00:45:27740}
741
742// Close the connection before enough bytes to have a status line.
[email protected]23e482282013-06-14 16:08:02743TEST_P(HttpNetworkTransactionTest, StatusLinePartial) {
[email protected]231d5a32008-09-13 00:45:27744 MockRead data_reads[] = {
[email protected]217e6022008-09-29 18:18:35745 MockRead("HTT"),
[email protected]8ddf8322012-02-23 18:08:06746 MockRead(SYNCHRONOUS, OK),
[email protected]231d5a32008-09-13 00:45:27747 };
[email protected]31a2bfe2010-02-09 08:03:39748 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
749 arraysize(data_reads));
[email protected]1c773ea12009-04-28 19:58:42750 EXPECT_EQ(OK, out.rv);
[email protected]231d5a32008-09-13 00:45:27751 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line);
752 EXPECT_EQ("HTT", out.response_data);
[email protected]b8015c42013-12-24 15:18:19753 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads));
754 EXPECT_EQ(reads_size, out.totalReceivedBytes);
initial.commit586acc5fe2008-07-26 22:42:52755}
756
[email protected]f9d44aa2008-09-23 23:57:17757// Simulate a 204 response, lacking a Content-Length header, sent over a
758// persistent connection. The response should still terminate since a 204
759// cannot have a response body.
[email protected]23e482282013-06-14 16:08:02760TEST_P(HttpNetworkTransactionTest, StopsReading204) {
[email protected]b8015c42013-12-24 15:18:19761 char junk[] = "junk";
[email protected]f9d44aa2008-09-23 23:57:17762 MockRead data_reads[] = {
[email protected]217e6022008-09-29 18:18:35763 MockRead("HTTP/1.1 204 No Content\r\n\r\n"),
[email protected]b8015c42013-12-24 15:18:19764 MockRead(junk), // Should not be read!!
[email protected]8ddf8322012-02-23 18:08:06765 MockRead(SYNCHRONOUS, OK),
[email protected]f9d44aa2008-09-23 23:57:17766 };
[email protected]31a2bfe2010-02-09 08:03:39767 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
768 arraysize(data_reads));
[email protected]1c773ea12009-04-28 19:58:42769 EXPECT_EQ(OK, out.rv);
[email protected]f9d44aa2008-09-23 23:57:17770 EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line);
771 EXPECT_EQ("", out.response_data);
[email protected]b8015c42013-12-24 15:18:19772 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads));
773 int64 response_size = reads_size - strlen(junk);
774 EXPECT_EQ(response_size, out.totalReceivedBytes);
[email protected]f9d44aa2008-09-23 23:57:17775}
776
[email protected]0877e3d2009-10-17 22:29:57777// A simple request using chunked encoding with some extra data after.
[email protected]23e482282013-06-14 16:08:02778TEST_P(HttpNetworkTransactionTest, ChunkedEncoding) {
[email protected]b8015c42013-12-24 15:18:19779 std::string final_chunk = "0\r\n\r\n";
780 std::string extra_data = "HTTP/1.1 200 OK\r\n";
781 std::string last_read = final_chunk + extra_data;
[email protected]0877e3d2009-10-17 22:29:57782 MockRead data_reads[] = {
783 MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"),
784 MockRead("5\r\nHello\r\n"),
785 MockRead("1\r\n"),
786 MockRead(" \r\n"),
787 MockRead("5\r\nworld\r\n"),
[email protected]b8015c42013-12-24 15:18:19788 MockRead(last_read.data()),
[email protected]8ddf8322012-02-23 18:08:06789 MockRead(SYNCHRONOUS, OK),
[email protected]0877e3d2009-10-17 22:29:57790 };
[email protected]31a2bfe2010-02-09 08:03:39791 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
792 arraysize(data_reads));
[email protected]0877e3d2009-10-17 22:29:57793 EXPECT_EQ(OK, out.rv);
794 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
795 EXPECT_EQ("Hello world", out.response_data);
[email protected]b8015c42013-12-24 15:18:19796 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads));
797 int64 response_size = reads_size - extra_data.size();
798 EXPECT_EQ(response_size, out.totalReceivedBytes);
[email protected]0877e3d2009-10-17 22:29:57799}
800
[email protected]9fe44f52010-09-23 18:36:00801// Next tests deal with http://crbug.com/56344.
802
[email protected]23e482282013-06-14 16:08:02803TEST_P(HttpNetworkTransactionTest,
[email protected]9fe44f52010-09-23 18:36:00804 MultipleContentLengthHeadersNoTransferEncoding) {
805 MockRead data_reads[] = {
806 MockRead("HTTP/1.1 200 OK\r\n"),
807 MockRead("Content-Length: 10\r\n"),
808 MockRead("Content-Length: 5\r\n\r\n"),
809 };
810 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
811 arraysize(data_reads));
812 EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv);
813}
814
[email protected]23e482282013-06-14 16:08:02815TEST_P(HttpNetworkTransactionTest,
[email protected]44b52042010-10-29 22:48:04816 DuplicateContentLengthHeadersNoTransferEncoding) {
817 MockRead data_reads[] = {
818 MockRead("HTTP/1.1 200 OK\r\n"),
819 MockRead("Content-Length: 5\r\n"),
820 MockRead("Content-Length: 5\r\n\r\n"),
821 MockRead("Hello"),
822 };
823 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
824 arraysize(data_reads));
825 EXPECT_EQ(OK, out.rv);
826 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
827 EXPECT_EQ("Hello", out.response_data);
828}
829
[email protected]23e482282013-06-14 16:08:02830TEST_P(HttpNetworkTransactionTest,
[email protected]44b52042010-10-29 22:48:04831 ComplexContentLengthHeadersNoTransferEncoding) {
832 // More than 2 dupes.
833 {
834 MockRead data_reads[] = {
835 MockRead("HTTP/1.1 200 OK\r\n"),
836 MockRead("Content-Length: 5\r\n"),
837 MockRead("Content-Length: 5\r\n"),
838 MockRead("Content-Length: 5\r\n\r\n"),
839 MockRead("Hello"),
840 };
841 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
842 arraysize(data_reads));
843 EXPECT_EQ(OK, out.rv);
844 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
845 EXPECT_EQ("Hello", out.response_data);
846 }
847 // HTTP/1.0
848 {
849 MockRead data_reads[] = {
850 MockRead("HTTP/1.0 200 OK\r\n"),
851 MockRead("Content-Length: 5\r\n"),
852 MockRead("Content-Length: 5\r\n"),
853 MockRead("Content-Length: 5\r\n\r\n"),
854 MockRead("Hello"),
855 };
856 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
857 arraysize(data_reads));
858 EXPECT_EQ(OK, out.rv);
859 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line);
860 EXPECT_EQ("Hello", out.response_data);
861 }
862 // 2 dupes and one mismatched.
863 {
864 MockRead data_reads[] = {
865 MockRead("HTTP/1.1 200 OK\r\n"),
866 MockRead("Content-Length: 10\r\n"),
867 MockRead("Content-Length: 10\r\n"),
868 MockRead("Content-Length: 5\r\n\r\n"),
869 };
870 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
871 arraysize(data_reads));
872 EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv);
873 }
874}
875
[email protected]23e482282013-06-14 16:08:02876TEST_P(HttpNetworkTransactionTest,
[email protected]9fe44f52010-09-23 18:36:00877 MultipleContentLengthHeadersTransferEncoding) {
878 MockRead data_reads[] = {
879 MockRead("HTTP/1.1 200 OK\r\n"),
880 MockRead("Content-Length: 666\r\n"),
881 MockRead("Content-Length: 1337\r\n"),
882 MockRead("Transfer-Encoding: chunked\r\n\r\n"),
883 MockRead("5\r\nHello\r\n"),
884 MockRead("1\r\n"),
885 MockRead(" \r\n"),
886 MockRead("5\r\nworld\r\n"),
887 MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"),
[email protected]8ddf8322012-02-23 18:08:06888 MockRead(SYNCHRONOUS, OK),
[email protected]9fe44f52010-09-23 18:36:00889 };
890 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
891 arraysize(data_reads));
892 EXPECT_EQ(OK, out.rv);
893 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
894 EXPECT_EQ("Hello world", out.response_data);
895}
896
[email protected]1628fe92011-10-04 23:04:55897// Next tests deal with http://crbug.com/98895.
898
899// Checks that a single Content-Disposition header results in no error.
[email protected]23e482282013-06-14 16:08:02900TEST_P(HttpNetworkTransactionTest, SingleContentDispositionHeader) {
[email protected]1628fe92011-10-04 23:04:55901 MockRead data_reads[] = {
902 MockRead("HTTP/1.1 200 OK\r\n"),
903 MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"),
904 MockRead("Content-Length: 5\r\n\r\n"),
905 MockRead("Hello"),
906 };
907 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
908 arraysize(data_reads));
909 EXPECT_EQ(OK, out.rv);
910 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
911 EXPECT_EQ("Hello", out.response_data);
912}
913
[email protected]54a9c6e52012-03-21 20:10:59914// Checks that two identical Content-Disposition headers result in no error.
[email protected]23e482282013-06-14 16:08:02915TEST_P(HttpNetworkTransactionTest,
[email protected]54a9c6e52012-03-21 20:10:59916 TwoIdenticalContentDispositionHeaders) {
[email protected]1628fe92011-10-04 23:04:55917 MockRead data_reads[] = {
918 MockRead("HTTP/1.1 200 OK\r\n"),
919 MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"),
920 MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"),
921 MockRead("Content-Length: 5\r\n\r\n"),
922 MockRead("Hello"),
923 };
924 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
925 arraysize(data_reads));
[email protected]54a9c6e52012-03-21 20:10:59926 EXPECT_EQ(OK, out.rv);
927 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
928 EXPECT_EQ("Hello", out.response_data);
[email protected]1628fe92011-10-04 23:04:55929}
930
931// Checks that two distinct Content-Disposition headers result in an error.
[email protected]23e482282013-06-14 16:08:02932TEST_P(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) {
[email protected]1628fe92011-10-04 23:04:55933 MockRead data_reads[] = {
934 MockRead("HTTP/1.1 200 OK\r\n"),
935 MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"),
936 MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"),
937 MockRead("Content-Length: 5\r\n\r\n"),
938 MockRead("Hello"),
939 };
940 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
941 arraysize(data_reads));
942 EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION, out.rv);
943}
944
[email protected]54a9c6e52012-03-21 20:10:59945// Checks that two identical Location headers result in no error.
946// Also tests Location header behavior.
[email protected]23e482282013-06-14 16:08:02947TEST_P(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) {
[email protected]1628fe92011-10-04 23:04:55948 MockRead data_reads[] = {
949 MockRead("HTTP/1.1 302 Redirect\r\n"),
950 MockRead("Location: http://good.com/\r\n"),
[email protected]54a9c6e52012-03-21 20:10:59951 MockRead("Location: http://good.com/\r\n"),
[email protected]1628fe92011-10-04 23:04:55952 MockRead("Content-Length: 0\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:06953 MockRead(SYNCHRONOUS, OK),
[email protected]1628fe92011-10-04 23:04:55954 };
955
956 HttpRequestInfo request;
957 request.method = "GET";
958 request.url = GURL("http://redirect.com/");
959 request.load_flags = 0;
960
[email protected]3fe8d2f82013-10-17 08:56:07961 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]1628fe92011-10-04 23:04:55962 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:41963 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]1628fe92011-10-04 23:04:55964
965 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:07966 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]1628fe92011-10-04 23:04:55967
[email protected]49639fa2011-12-20 23:22:41968 TestCompletionCallback callback;
[email protected]1628fe92011-10-04 23:04:55969
[email protected]49639fa2011-12-20 23:22:41970 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1628fe92011-10-04 23:04:55971 EXPECT_EQ(ERR_IO_PENDING, rv);
972
973 EXPECT_EQ(OK, callback.WaitForResult());
974
975 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]90499482013-06-01 00:39:50976 ASSERT_TRUE(response != NULL && response->headers.get() != NULL);
[email protected]1628fe92011-10-04 23:04:55977 EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine());
978 std::string url;
979 EXPECT_TRUE(response->headers->IsRedirect(&url));
980 EXPECT_EQ("http://good.com/", url);
[email protected]d8fc4722014-06-13 13:17:15981 EXPECT_TRUE(response->proxy_server.IsEmpty());
[email protected]1628fe92011-10-04 23:04:55982}
983
[email protected]1628fe92011-10-04 23:04:55984// Checks that two distinct Location headers result in an error.
[email protected]23e482282013-06-14 16:08:02985TEST_P(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) {
[email protected]1628fe92011-10-04 23:04:55986 MockRead data_reads[] = {
987 MockRead("HTTP/1.1 302 Redirect\r\n"),
988 MockRead("Location: http://good.com/\r\n"),
989 MockRead("Location: http://evil.com/\r\n"),
990 MockRead("Content-Length: 0\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:06991 MockRead(SYNCHRONOUS, OK),
[email protected]1628fe92011-10-04 23:04:55992 };
993 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
994 arraysize(data_reads));
995 EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION, out.rv);
996}
997
[email protected]ef0faf2e72009-03-05 23:27:23998// Do a request using the HEAD method. Verify that we don't try to read the
999// message body (since HEAD has none).
[email protected]23e482282013-06-14 16:08:021000TEST_P(HttpNetworkTransactionTest, Head) {
[email protected]1c773ea12009-04-28 19:58:421001 HttpRequestInfo request;
[email protected]ef0faf2e72009-03-05 23:27:231002 request.method = "HEAD";
1003 request.url = GURL("http://www.google.com/");
1004 request.load_flags = 0;
1005
[email protected]3fe8d2f82013-10-17 08:56:071006 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:271007 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:411008 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]597a1ab2014-06-26 08:12:271009 BeforeProxyHeadersSentHandler proxy_headers_handler;
1010 trans->SetBeforeProxyHeadersSentCallback(
1011 base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent,
1012 base::Unretained(&proxy_headers_handler)));
[email protected]cb9bf6ca2011-01-28 13:15:271013
[email protected]ef0faf2e72009-03-05 23:27:231014 MockWrite data_writes1[] = {
1015 MockWrite("HEAD / HTTP/1.1\r\n"
1016 "Host: www.google.com\r\n"
1017 "Connection: keep-alive\r\n"
1018 "Content-Length: 0\r\n\r\n"),
1019 };
1020 MockRead data_reads1[] = {
1021 MockRead("HTTP/1.1 404 Not Found\r\n"),
1022 MockRead("Server: Blah\r\n"),
1023 MockRead("Content-Length: 1234\r\n\r\n"),
1024
1025 // No response body because the test stops reading here.
[email protected]8ddf8322012-02-23 18:08:061026 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached.
[email protected]ef0faf2e72009-03-05 23:27:231027 };
1028
[email protected]31a2bfe2010-02-09 08:03:391029 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
1030 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:071031 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]ef0faf2e72009-03-05 23:27:231032
[email protected]49639fa2011-12-20 23:22:411033 TestCompletionCallback callback1;
[email protected]ef0faf2e72009-03-05 23:27:231034
[email protected]49639fa2011-12-20 23:22:411035 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:421036 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]ef0faf2e72009-03-05 23:27:231037
1038 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:421039 EXPECT_EQ(OK, rv);
[email protected]ef0faf2e72009-03-05 23:27:231040
[email protected]1c773ea12009-04-28 19:58:421041 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:501042 ASSERT_TRUE(response != NULL);
[email protected]ef0faf2e72009-03-05 23:27:231043
1044 // Check that the headers got parsed.
[email protected]90499482013-06-01 00:39:501045 EXPECT_TRUE(response->headers.get() != NULL);
[email protected]ef0faf2e72009-03-05 23:27:231046 EXPECT_EQ(1234, response->headers->GetContentLength());
1047 EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine());
[email protected]d8fc4722014-06-13 13:17:151048 EXPECT_TRUE(response->proxy_server.IsEmpty());
[email protected]597a1ab2014-06-26 08:12:271049 EXPECT_FALSE(proxy_headers_handler.observed_before_proxy_headers_sent());
[email protected]ef0faf2e72009-03-05 23:27:231050
1051 std::string server_header;
1052 void* iter = NULL;
1053 bool has_server_header = response->headers->EnumerateHeader(
1054 &iter, "Server", &server_header);
1055 EXPECT_TRUE(has_server_header);
1056 EXPECT_EQ("Blah", server_header);
1057
1058 // Reading should give EOF right away, since there is no message body
1059 // (despite non-zero content-length).
1060 std::string response_data;
1061 rv = ReadTransaction(trans.get(), &response_data);
[email protected]1c773ea12009-04-28 19:58:421062 EXPECT_EQ(OK, rv);
[email protected]ef0faf2e72009-03-05 23:27:231063 EXPECT_EQ("", response_data);
1064}
1065
[email protected]23e482282013-06-14 16:08:021066TEST_P(HttpNetworkTransactionTest, ReuseConnection) {
[email protected]bb88e1d32013-05-03 23:11:071067 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
initial.commit586acc5fe2008-07-26 22:42:521068
1069 MockRead data_reads[] = {
[email protected]217e6022008-09-29 18:18:351070 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"),
1071 MockRead("hello"),
1072 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"),
1073 MockRead("world"),
[email protected]8ddf8322012-02-23 18:08:061074 MockRead(SYNCHRONOUS, OK),
initial.commit586acc5fe2008-07-26 22:42:521075 };
[email protected]31a2bfe2010-02-09 08:03:391076 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:071077 session_deps_.socket_factory->AddSocketDataProvider(&data);
initial.commit586acc5fe2008-07-26 22:42:521078
[email protected]0b0bf032010-09-21 18:08:501079 const char* const kExpectedResponseData[] = {
initial.commit586acc5fe2008-07-26 22:42:521080 "hello", "world"
1081 };
1082
1083 for (int i = 0; i < 2; ++i) {
[email protected]1c773ea12009-04-28 19:58:421084 HttpRequestInfo request;
initial.commit586acc5fe2008-07-26 22:42:521085 request.method = "GET";
1086 request.url = GURL("http://www.google.com/");
1087 request.load_flags = 0;
1088
[email protected]262eec82013-03-19 21:01:361089 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:501090 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:271091
[email protected]49639fa2011-12-20 23:22:411092 TestCompletionCallback callback;
initial.commit586acc5fe2008-07-26 22:42:521093
[email protected]49639fa2011-12-20 23:22:411094 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:421095 EXPECT_EQ(ERR_IO_PENDING, rv);
initial.commit586acc5fe2008-07-26 22:42:521096
1097 rv = callback.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:421098 EXPECT_EQ(OK, rv);
initial.commit586acc5fe2008-07-26 22:42:521099
[email protected]1c773ea12009-04-28 19:58:421100 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:501101 ASSERT_TRUE(response != NULL);
initial.commit586acc5fe2008-07-26 22:42:521102
[email protected]90499482013-06-01 00:39:501103 EXPECT_TRUE(response->headers.get() != NULL);
[email protected]3d2a59b2008-09-26 19:44:251104 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
[email protected]d8fc4722014-06-13 13:17:151105 EXPECT_TRUE(response->proxy_server.IsEmpty());
initial.commit586acc5fe2008-07-26 22:42:521106
1107 std::string response_data;
[email protected]af4876d2008-10-21 23:10:571108 rv = ReadTransaction(trans.get(), &response_data);
[email protected]1c773ea12009-04-28 19:58:421109 EXPECT_EQ(OK, rv);
[email protected]3d2a59b2008-09-26 19:44:251110 EXPECT_EQ(kExpectedResponseData[i], response_data);
initial.commit586acc5fe2008-07-26 22:42:521111 }
1112}
1113
[email protected]23e482282013-06-14 16:08:021114TEST_P(HttpNetworkTransactionTest, Ignores100) {
[email protected]b2d26cfd2012-12-11 10:36:061115 ScopedVector<UploadElementReader> element_readers;
1116 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:071117 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]329b68b2012-11-14 17:54:271118
[email protected]1c773ea12009-04-28 19:58:421119 HttpRequestInfo request;
initial.commit586acc5fe2008-07-26 22:42:521120 request.method = "POST";
1121 request.url = GURL("http://www.foo.com/");
[email protected]329b68b2012-11-14 17:54:271122 request.upload_data_stream = &upload_data_stream;
initial.commit586acc5fe2008-07-26 22:42:521123 request.load_flags = 0;
1124
[email protected]3fe8d2f82013-10-17 08:56:071125 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:271126 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:411127 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:271128
initial.commit586acc5fe2008-07-26 22:42:521129 MockRead data_reads[] = {
[email protected]217e6022008-09-29 18:18:351130 MockRead("HTTP/1.0 100 Continue\r\n\r\n"),
1131 MockRead("HTTP/1.0 200 OK\r\n\r\n"),
1132 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:061133 MockRead(SYNCHRONOUS, OK),
initial.commit586acc5fe2008-07-26 22:42:521134 };
[email protected]31a2bfe2010-02-09 08:03:391135 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:071136 session_deps_.socket_factory->AddSocketDataProvider(&data);
initial.commit586acc5fe2008-07-26 22:42:521137
[email protected]49639fa2011-12-20 23:22:411138 TestCompletionCallback callback;
initial.commit586acc5fe2008-07-26 22:42:521139
[email protected]49639fa2011-12-20 23:22:411140 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:421141 EXPECT_EQ(ERR_IO_PENDING, rv);
initial.commit586acc5fe2008-07-26 22:42:521142
1143 rv = callback.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:421144 EXPECT_EQ(OK, rv);
initial.commit586acc5fe2008-07-26 22:42:521145
[email protected]1c773ea12009-04-28 19:58:421146 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:501147 ASSERT_TRUE(response != NULL);
initial.commit586acc5fe2008-07-26 22:42:521148
[email protected]90499482013-06-01 00:39:501149 EXPECT_TRUE(response->headers.get() != NULL);
[email protected]3d2a59b2008-09-26 19:44:251150 EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine());
initial.commit586acc5fe2008-07-26 22:42:521151
1152 std::string response_data;
[email protected]af4876d2008-10-21 23:10:571153 rv = ReadTransaction(trans.get(), &response_data);
[email protected]1c773ea12009-04-28 19:58:421154 EXPECT_EQ(OK, rv);
[email protected]3d2a59b2008-09-26 19:44:251155 EXPECT_EQ("hello world", response_data);
initial.commit586acc5fe2008-07-26 22:42:521156}
1157
[email protected]3a2d3662009-03-27 03:49:141158// This test is almost the same as Ignores100 above, but the response contains
1159// a 102 instead of a 100. Also, instead of HTTP/1.0 the response is
[email protected]0877e3d2009-10-17 22:29:571160// HTTP/1.1 and the two status headers are read in one read.
[email protected]23e482282013-06-14 16:08:021161TEST_P(HttpNetworkTransactionTest, Ignores1xx) {
[email protected]1c773ea12009-04-28 19:58:421162 HttpRequestInfo request;
[email protected]3a2d3662009-03-27 03:49:141163 request.method = "GET";
1164 request.url = GURL("http://www.foo.com/");
1165 request.load_flags = 0;
1166
[email protected]3fe8d2f82013-10-17 08:56:071167 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:271168 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:411169 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:271170
[email protected]3a2d3662009-03-27 03:49:141171 MockRead data_reads[] = {
[email protected]0877e3d2009-10-17 22:29:571172 MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n"
1173 "HTTP/1.1 200 OK\r\n\r\n"),
[email protected]3a2d3662009-03-27 03:49:141174 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:061175 MockRead(SYNCHRONOUS, OK),
[email protected]3a2d3662009-03-27 03:49:141176 };
[email protected]31a2bfe2010-02-09 08:03:391177 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:071178 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]3a2d3662009-03-27 03:49:141179
[email protected]49639fa2011-12-20 23:22:411180 TestCompletionCallback callback;
[email protected]3a2d3662009-03-27 03:49:141181
[email protected]49639fa2011-12-20 23:22:411182 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:421183 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]3a2d3662009-03-27 03:49:141184
1185 rv = callback.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:421186 EXPECT_EQ(OK, rv);
[email protected]3a2d3662009-03-27 03:49:141187
[email protected]1c773ea12009-04-28 19:58:421188 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:501189 ASSERT_TRUE(response != NULL);
[email protected]3a2d3662009-03-27 03:49:141190
[email protected]90499482013-06-01 00:39:501191 EXPECT_TRUE(response->headers.get() != NULL);
[email protected]3a2d3662009-03-27 03:49:141192 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
1193
1194 std::string response_data;
1195 rv = ReadTransaction(trans.get(), &response_data);
[email protected]1c773ea12009-04-28 19:58:421196 EXPECT_EQ(OK, rv);
[email protected]3a2d3662009-03-27 03:49:141197 EXPECT_EQ("hello world", response_data);
1198}
1199
[email protected]23e482282013-06-14 16:08:021200TEST_P(HttpNetworkTransactionTest, Incomplete100ThenEOF) {
[email protected]ee9410e72010-01-07 01:42:381201 HttpRequestInfo request;
1202 request.method = "POST";
1203 request.url = GURL("http://www.foo.com/");
1204 request.load_flags = 0;
1205
[email protected]3fe8d2f82013-10-17 08:56:071206 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:271207 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:411208 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:271209
[email protected]ee9410e72010-01-07 01:42:381210 MockRead data_reads[] = {
[email protected]8ddf8322012-02-23 18:08:061211 MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"),
1212 MockRead(ASYNC, 0),
[email protected]ee9410e72010-01-07 01:42:381213 };
[email protected]31a2bfe2010-02-09 08:03:391214 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:071215 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]ee9410e72010-01-07 01:42:381216
[email protected]49639fa2011-12-20 23:22:411217 TestCompletionCallback callback;
[email protected]ee9410e72010-01-07 01:42:381218
[email protected]49639fa2011-12-20 23:22:411219 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]ee9410e72010-01-07 01:42:381220 EXPECT_EQ(ERR_IO_PENDING, rv);
1221
1222 rv = callback.WaitForResult();
1223 EXPECT_EQ(OK, rv);
1224
1225 std::string response_data;
1226 rv = ReadTransaction(trans.get(), &response_data);
1227 EXPECT_EQ(OK, rv);
1228 EXPECT_EQ("", response_data);
1229}
1230
[email protected]23e482282013-06-14 16:08:021231TEST_P(HttpNetworkTransactionTest, EmptyResponse) {
[email protected]ee9410e72010-01-07 01:42:381232 HttpRequestInfo request;
1233 request.method = "POST";
1234 request.url = GURL("http://www.foo.com/");
1235 request.load_flags = 0;
1236
[email protected]3fe8d2f82013-10-17 08:56:071237 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:271238 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:411239 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:271240
[email protected]ee9410e72010-01-07 01:42:381241 MockRead data_reads[] = {
[email protected]8ddf8322012-02-23 18:08:061242 MockRead(ASYNC, 0),
[email protected]ee9410e72010-01-07 01:42:381243 };
[email protected]31a2bfe2010-02-09 08:03:391244 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:071245 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]ee9410e72010-01-07 01:42:381246
[email protected]49639fa2011-12-20 23:22:411247 TestCompletionCallback callback;
[email protected]ee9410e72010-01-07 01:42:381248
[email protected]49639fa2011-12-20 23:22:411249 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]ee9410e72010-01-07 01:42:381250 EXPECT_EQ(ERR_IO_PENDING, rv);
1251
1252 rv = callback.WaitForResult();
1253 EXPECT_EQ(ERR_EMPTY_RESPONSE, rv);
1254}
1255
[email protected]23e482282013-06-14 16:08:021256void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest(
[email protected]202965992011-12-07 23:04:511257 const MockWrite* write_failure,
1258 const MockRead* read_failure) {
[email protected]1c773ea12009-04-28 19:58:421259 HttpRequestInfo request;
initial.commit586acc5fe2008-07-26 22:42:521260 request.method = "GET";
1261 request.url = GURL("http://www.foo.com/");
1262 request.load_flags = 0;
1263
[email protected]58e32bb2013-01-21 18:23:251264 CapturingNetLog net_log;
[email protected]bb88e1d32013-05-03 23:11:071265 session_deps_.net_log = &net_log;
1266 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:271267
[email protected]202965992011-12-07 23:04:511268 // Written data for successfully sending both requests.
1269 MockWrite data1_writes[] = {
1270 MockWrite("GET / HTTP/1.1\r\n"
1271 "Host: www.foo.com\r\n"
1272 "Connection: keep-alive\r\n\r\n"),
1273 MockWrite("GET / HTTP/1.1\r\n"
1274 "Host: www.foo.com\r\n"
1275 "Connection: keep-alive\r\n\r\n")
1276 };
1277
1278 // Read results for the first request.
initial.commit586acc5fe2008-07-26 22:42:521279 MockRead data1_reads[] = {
[email protected]217e6022008-09-29 18:18:351280 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"),
1281 MockRead("hello"),
[email protected]8ddf8322012-02-23 18:08:061282 MockRead(ASYNC, OK),
initial.commit586acc5fe2008-07-26 22:42:521283 };
[email protected]202965992011-12-07 23:04:511284
1285 if (write_failure) {
[email protected]a34f61ee2014-03-18 20:59:491286 ASSERT_FALSE(read_failure);
[email protected]202965992011-12-07 23:04:511287 data1_writes[1] = *write_failure;
1288 } else {
1289 ASSERT_TRUE(read_failure);
1290 data1_reads[2] = *read_failure;
1291 }
1292
1293 StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads),
1294 data1_writes, arraysize(data1_writes));
[email protected]bb88e1d32013-05-03 23:11:071295 session_deps_.socket_factory->AddSocketDataProvider(&data1);
initial.commit586acc5fe2008-07-26 22:42:521296
1297 MockRead data2_reads[] = {
[email protected]217e6022008-09-29 18:18:351298 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"),
1299 MockRead("world"),
[email protected]8ddf8322012-02-23 18:08:061300 MockRead(ASYNC, OK),
initial.commit586acc5fe2008-07-26 22:42:521301 };
[email protected]31a2bfe2010-02-09 08:03:391302 StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:071303 session_deps_.socket_factory->AddSocketDataProvider(&data2);
initial.commit586acc5fe2008-07-26 22:42:521304
1305 const char* kExpectedResponseData[] = {
1306 "hello", "world"
1307 };
1308
[email protected]58e32bb2013-01-21 18:23:251309 uint32 first_socket_log_id = NetLog::Source::kInvalidId;
initial.commit586acc5fe2008-07-26 22:42:521310 for (int i = 0; i < 2; ++i) {
[email protected]49639fa2011-12-20 23:22:411311 TestCompletionCallback callback;
initial.commit586acc5fe2008-07-26 22:42:521312
[email protected]262eec82013-03-19 21:01:361313 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:501314 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
initial.commit586acc5fe2008-07-26 22:42:521315
[email protected]49639fa2011-12-20 23:22:411316 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:421317 EXPECT_EQ(ERR_IO_PENDING, rv);
initial.commit586acc5fe2008-07-26 22:42:521318
1319 rv = callback.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:421320 EXPECT_EQ(OK, rv);
initial.commit586acc5fe2008-07-26 22:42:521321
[email protected]58e32bb2013-01-21 18:23:251322 LoadTimingInfo load_timing_info;
1323 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
1324 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES);
1325 if (i == 0) {
1326 first_socket_log_id = load_timing_info.socket_log_id;
1327 } else {
1328 // The second request should be using a new socket.
1329 EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id);
1330 }
1331
[email protected]1c773ea12009-04-28 19:58:421332 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:501333 ASSERT_TRUE(response != NULL);
initial.commit586acc5fe2008-07-26 22:42:521334
[email protected]90499482013-06-01 00:39:501335 EXPECT_TRUE(response->headers.get() != NULL);
[email protected]3d2a59b2008-09-26 19:44:251336 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
initial.commit586acc5fe2008-07-26 22:42:521337
1338 std::string response_data;
[email protected]af4876d2008-10-21 23:10:571339 rv = ReadTransaction(trans.get(), &response_data);
[email protected]1c773ea12009-04-28 19:58:421340 EXPECT_EQ(OK, rv);
[email protected]3d2a59b2008-09-26 19:44:251341 EXPECT_EQ(kExpectedResponseData[i], response_data);
initial.commit586acc5fe2008-07-26 22:42:521342 }
1343}
[email protected]3d2a59b2008-09-26 19:44:251344
[email protected]a34f61ee2014-03-18 20:59:491345void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest(
1346 const MockWrite* write_failure,
[email protected]09356c652014-03-25 15:36:101347 const MockRead* read_failure,
1348 bool use_spdy) {
[email protected]a34f61ee2014-03-18 20:59:491349 HttpRequestInfo request;
1350 request.method = "GET";
[email protected]09356c652014-03-25 15:36:101351 request.url = GURL("https://www.foo.com/");
[email protected]a34f61ee2014-03-18 20:59:491352 request.load_flags = 0;
1353
1354 CapturingNetLog net_log;
1355 session_deps_.net_log = &net_log;
1356 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
1357
[email protected]09356c652014-03-25 15:36:101358 SSLSocketDataProvider ssl1(ASYNC, OK);
1359 SSLSocketDataProvider ssl2(ASYNC, OK);
1360 if (use_spdy) {
1361 ssl1.SetNextProto(GetParam());
1362 ssl2.SetNextProto(GetParam());
1363 }
1364 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1);
1365 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2);
[email protected]a34f61ee2014-03-18 20:59:491366
[email protected]09356c652014-03-25 15:36:101367 // SPDY versions of the request and response.
1368 scoped_ptr<SpdyFrame> spdy_request(spdy_util_.ConstructSpdyGet(
1369 request.url.spec().c_str(), false, 1, DEFAULT_PRIORITY));
1370 scoped_ptr<SpdyFrame> spdy_response(
1371 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
1372 scoped_ptr<SpdyFrame> spdy_data(
1373 spdy_util_.ConstructSpdyBodyFrame(1, "hello", 5, true));
[email protected]a34f61ee2014-03-18 20:59:491374
[email protected]09356c652014-03-25 15:36:101375 // HTTP/1.1 versions of the request and response.
1376 const char kHttpRequest[] = "GET / HTTP/1.1\r\n"
1377 "Host: www.foo.com\r\n"
1378 "Connection: keep-alive\r\n\r\n";
1379 const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n";
1380 const char kHttpData[] = "hello";
1381
1382 std::vector<MockRead> data1_reads;
1383 std::vector<MockWrite> data1_writes;
[email protected]a34f61ee2014-03-18 20:59:491384 if (write_failure) {
1385 ASSERT_FALSE(read_failure);
[email protected]09356c652014-03-25 15:36:101386 data1_writes.push_back(*write_failure);
1387 data1_reads.push_back(MockRead(ASYNC, OK));
[email protected]a34f61ee2014-03-18 20:59:491388 } else {
1389 ASSERT_TRUE(read_failure);
[email protected]09356c652014-03-25 15:36:101390 if (use_spdy) {
1391 data1_writes.push_back(CreateMockWrite(*spdy_request));
1392 } else {
1393 data1_writes.push_back(MockWrite(kHttpRequest));
1394 }
1395 data1_reads.push_back(*read_failure);
[email protected]a34f61ee2014-03-18 20:59:491396 }
1397
[email protected]09356c652014-03-25 15:36:101398 StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(),
1399 &data1_writes[0], data1_writes.size());
[email protected]a34f61ee2014-03-18 20:59:491400 session_deps_.socket_factory->AddSocketDataProvider(&data1);
1401
[email protected]09356c652014-03-25 15:36:101402 std::vector<MockRead> data2_reads;
1403 std::vector<MockWrite> data2_writes;
1404
1405 if (use_spdy) {
1406 data2_writes.push_back(CreateMockWrite(*spdy_request, 0, ASYNC));
1407
1408 data2_reads.push_back(CreateMockRead(*spdy_response, 1, ASYNC));
1409 data2_reads.push_back(CreateMockRead(*spdy_data, 2, ASYNC));
1410 data2_reads.push_back(MockRead(ASYNC, OK, 3));
1411 } else {
1412 data2_writes.push_back(
1413 MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0));
1414
1415 data2_reads.push_back(
1416 MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1));
1417 data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2));
1418 data2_reads.push_back(MockRead(ASYNC, OK, 3));
1419 }
1420 OrderedSocketData data2(&data2_reads[0], data2_reads.size(),
1421 &data2_writes[0], data2_writes.size());
[email protected]a34f61ee2014-03-18 20:59:491422 session_deps_.socket_factory->AddSocketDataProvider(&data2);
1423
1424 // Preconnect a socket.
1425 net::SSLConfig ssl_config;
1426 session->ssl_config_service()->GetSSLConfig(&ssl_config);
[email protected]d7599122014-05-24 03:37:231427 session->GetNextProtos(&ssl_config.next_protos);
[email protected]a34f61ee2014-03-18 20:59:491428 session->http_stream_factory()->PreconnectStreams(
1429 1, request, DEFAULT_PRIORITY, ssl_config, ssl_config);
1430 // Wait for the preconnect to complete.
1431 // TODO(davidben): Some way to wait for an idle socket count might be handy.
1432 base::RunLoop().RunUntilIdle();
[email protected]09356c652014-03-25 15:36:101433 EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get()));
[email protected]a34f61ee2014-03-18 20:59:491434
1435 // Make the request.
1436 TestCompletionCallback callback;
1437
1438 scoped_ptr<HttpTransaction> trans(
1439 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
1440
1441 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
1442 EXPECT_EQ(ERR_IO_PENDING, rv);
1443
1444 rv = callback.WaitForResult();
1445 EXPECT_EQ(OK, rv);
1446
1447 LoadTimingInfo load_timing_info;
1448 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
[email protected]09356c652014-03-25 15:36:101449 TestLoadTimingNotReused(
1450 load_timing_info,
1451 CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES);
[email protected]a34f61ee2014-03-18 20:59:491452
1453 const HttpResponseInfo* response = trans->GetResponseInfo();
1454 ASSERT_TRUE(response != NULL);
1455
1456 EXPECT_TRUE(response->headers.get() != NULL);
1457 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
1458
1459 std::string response_data;
1460 rv = ReadTransaction(trans.get(), &response_data);
1461 EXPECT_EQ(OK, rv);
[email protected]09356c652014-03-25 15:36:101462 EXPECT_EQ(kHttpData, response_data);
[email protected]a34f61ee2014-03-18 20:59:491463}
1464
[email protected]23e482282013-06-14 16:08:021465TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:231466 KeepAliveConnectionNotConnectedOnWrite) {
[email protected]8ddf8322012-02-23 18:08:061467 MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED);
[email protected]202965992011-12-07 23:04:511468 KeepAliveConnectionResendRequestTest(&write_failure, NULL);
1469}
1470
[email protected]23e482282013-06-14 16:08:021471TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionReset) {
[email protected]8ddf8322012-02-23 18:08:061472 MockRead read_failure(ASYNC, ERR_CONNECTION_RESET);
[email protected]202965992011-12-07 23:04:511473 KeepAliveConnectionResendRequestTest(NULL, &read_failure);
[email protected]3d2a59b2008-09-26 19:44:251474}
1475
[email protected]23e482282013-06-14 16:08:021476TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionEOF) {
[email protected]8ddf8322012-02-23 18:08:061477 MockRead read_failure(SYNCHRONOUS, OK); // EOF
[email protected]202965992011-12-07 23:04:511478 KeepAliveConnectionResendRequestTest(NULL, &read_failure);
[email protected]3d2a59b2008-09-26 19:44:251479}
1480
[email protected]d58ceea82014-06-04 10:55:541481// Make sure that on a 408 response (Request Timeout), the request is retried,
1482// if the socket was a reused keep alive socket.
1483TEST_P(HttpNetworkTransactionTest, KeepAlive408) {
1484 MockRead read_failure(SYNCHRONOUS,
1485 "HTTP/1.1 408 Request Timeout\r\n"
1486 "Connection: Keep-Alive\r\n"
1487 "Content-Length: 6\r\n\r\n"
1488 "Pickle");
1489 KeepAliveConnectionResendRequestTest(NULL, &read_failure);
1490}
1491
[email protected]a34f61ee2014-03-18 20:59:491492TEST_P(HttpNetworkTransactionTest,
1493 PreconnectErrorNotConnectedOnWrite) {
1494 MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED);
[email protected]09356c652014-03-25 15:36:101495 PreconnectErrorResendRequestTest(&write_failure, NULL, false);
[email protected]a34f61ee2014-03-18 20:59:491496}
1497
1498TEST_P(HttpNetworkTransactionTest, PreconnectErrorReset) {
1499 MockRead read_failure(ASYNC, ERR_CONNECTION_RESET);
[email protected]09356c652014-03-25 15:36:101500 PreconnectErrorResendRequestTest(NULL, &read_failure, false);
[email protected]a34f61ee2014-03-18 20:59:491501}
1502
1503TEST_P(HttpNetworkTransactionTest, PreconnectErrorEOF) {
1504 MockRead read_failure(SYNCHRONOUS, OK); // EOF
[email protected]09356c652014-03-25 15:36:101505 PreconnectErrorResendRequestTest(NULL, &read_failure, false);
1506}
1507
1508TEST_P(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) {
1509 MockRead read_failure(ASYNC, OK); // EOF
1510 PreconnectErrorResendRequestTest(NULL, &read_failure, false);
1511}
1512
[email protected]d58ceea82014-06-04 10:55:541513// Make sure that on a 408 response (Request Timeout), the request is retried,
1514// if the socket was a preconnected (UNUSED_IDLE) socket.
1515TEST_P(HttpNetworkTransactionTest, RetryOnIdle408) {
1516 MockRead read_failure(SYNCHRONOUS,
1517 "HTTP/1.1 408 Request Timeout\r\n"
1518 "Connection: Keep-Alive\r\n"
1519 "Content-Length: 6\r\n\r\n"
1520 "Pickle");
1521 KeepAliveConnectionResendRequestTest(NULL, &read_failure);
1522 PreconnectErrorResendRequestTest(NULL, &read_failure, false);
1523}
1524
[email protected]09356c652014-03-25 15:36:101525TEST_P(HttpNetworkTransactionTest,
1526 SpdyPreconnectErrorNotConnectedOnWrite) {
1527 MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED);
1528 PreconnectErrorResendRequestTest(&write_failure, NULL, true);
1529}
1530
1531TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) {
1532 MockRead read_failure(ASYNC, ERR_CONNECTION_RESET);
1533 PreconnectErrorResendRequestTest(NULL, &read_failure, true);
1534}
1535
1536TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) {
1537 MockRead read_failure(SYNCHRONOUS, OK); // EOF
1538 PreconnectErrorResendRequestTest(NULL, &read_failure, true);
1539}
1540
1541TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) {
1542 MockRead read_failure(ASYNC, OK); // EOF
1543 PreconnectErrorResendRequestTest(NULL, &read_failure, true);
[email protected]a34f61ee2014-03-18 20:59:491544}
1545
[email protected]23e482282013-06-14 16:08:021546TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) {
[email protected]1c773ea12009-04-28 19:58:421547 HttpRequestInfo request;
[email protected]3d2a59b2008-09-26 19:44:251548 request.method = "GET";
1549 request.url = GURL("http://www.google.com/");
1550 request.load_flags = 0;
1551
[email protected]3fe8d2f82013-10-17 08:56:071552 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:271553 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:411554 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:271555
[email protected]3d2a59b2008-09-26 19:44:251556 MockRead data_reads[] = {
[email protected]8ddf8322012-02-23 18:08:061557 MockRead(ASYNC, ERR_CONNECTION_RESET),
[email protected]217e6022008-09-29 18:18:351558 MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used
1559 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:061560 MockRead(SYNCHRONOUS, OK),
[email protected]3d2a59b2008-09-26 19:44:251561 };
[email protected]31a2bfe2010-02-09 08:03:391562 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:071563 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]3d2a59b2008-09-26 19:44:251564
[email protected]49639fa2011-12-20 23:22:411565 TestCompletionCallback callback;
[email protected]3d2a59b2008-09-26 19:44:251566
[email protected]49639fa2011-12-20 23:22:411567 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:421568 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]3d2a59b2008-09-26 19:44:251569
1570 rv = callback.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:421571 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
[email protected]3d2a59b2008-09-26 19:44:251572
[email protected]1c773ea12009-04-28 19:58:421573 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]3d2a59b2008-09-26 19:44:251574 EXPECT_TRUE(response == NULL);
[email protected]3d2a59b2008-09-26 19:44:251575}
1576
1577// What do various browsers do when the server closes a non-keepalive
1578// connection without sending any response header or body?
1579//
1580// IE7: error page
1581// Safari 3.1.2 (Windows): error page
1582// Firefox 3.0.1: blank page
1583// Opera 9.52: after five attempts, blank page
[email protected]1c773ea12009-04-28 19:58:421584// Us with WinHTTP: error page (ERR_INVALID_RESPONSE)
1585// Us: error page (EMPTY_RESPONSE)
[email protected]23e482282013-06-14 16:08:021586TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) {
[email protected]3d2a59b2008-09-26 19:44:251587 MockRead data_reads[] = {
[email protected]8ddf8322012-02-23 18:08:061588 MockRead(SYNCHRONOUS, OK), // EOF
[email protected]217e6022008-09-29 18:18:351589 MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used
1590 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:061591 MockRead(SYNCHRONOUS, OK),
[email protected]3d2a59b2008-09-26 19:44:251592 };
[email protected]31a2bfe2010-02-09 08:03:391593 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
1594 arraysize(data_reads));
[email protected]1c773ea12009-04-28 19:58:421595 EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv);
[email protected]3d2a59b2008-09-26 19:44:251596}
[email protected]038e9a32008-10-08 22:40:161597
[email protected]1826a402014-01-08 15:40:481598// Test that network access can be deferred and resumed.
1599TEST_P(HttpNetworkTransactionTest, ThrottleBeforeNetworkStart) {
1600 HttpRequestInfo request;
1601 request.method = "GET";
1602 request.url = GURL("http://www.google.com/");
1603 request.load_flags = 0;
1604
1605 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
1606 scoped_ptr<HttpTransaction> trans(
1607 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
1608
1609 // Defer on OnBeforeNetworkStart.
1610 BeforeNetworkStartHandler net_start_handler(true); // defer
1611 trans->SetBeforeNetworkStartCallback(
1612 base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart,
1613 base::Unretained(&net_start_handler)));
1614
1615 MockRead data_reads[] = {
1616 MockRead("HTTP/1.0 200 OK\r\n"),
1617 MockRead("Content-Length: 5\r\n\r\n"),
1618 MockRead("hello"),
1619 MockRead(SYNCHRONOUS, 0),
1620 };
1621 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
1622 session_deps_.socket_factory->AddSocketDataProvider(&data);
1623
1624 TestCompletionCallback callback;
1625
1626 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
1627 EXPECT_EQ(ERR_IO_PENDING, rv);
1628 base::MessageLoop::current()->RunUntilIdle();
1629
1630 // Should have deferred for network start.
1631 EXPECT_TRUE(net_start_handler.observed_before_network_start());
1632 EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState());
1633 EXPECT_TRUE(trans->GetResponseInfo() == NULL);
1634
1635 trans->ResumeNetworkStart();
1636 rv = callback.WaitForResult();
1637 EXPECT_EQ(OK, rv);
1638 EXPECT_TRUE(trans->GetResponseInfo() != NULL);
1639
1640 scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100));
1641 rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback());
1642 if (rv == ERR_IO_PENDING)
1643 rv = callback.WaitForResult();
1644 EXPECT_EQ(5, rv);
1645 trans.reset();
1646}
1647
1648// Test that network use can be deferred and canceled.
1649TEST_P(HttpNetworkTransactionTest, ThrottleAndCancelBeforeNetworkStart) {
1650 HttpRequestInfo request;
1651 request.method = "GET";
1652 request.url = GURL("http://www.google.com/");
1653 request.load_flags = 0;
1654
1655 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
1656 scoped_ptr<HttpTransaction> trans(
1657 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
1658
1659 // Defer on OnBeforeNetworkStart.
1660 BeforeNetworkStartHandler net_start_handler(true); // defer
1661 trans->SetBeforeNetworkStartCallback(
1662 base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart,
1663 base::Unretained(&net_start_handler)));
1664
1665 TestCompletionCallback callback;
1666
1667 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
1668 EXPECT_EQ(ERR_IO_PENDING, rv);
1669 base::MessageLoop::current()->RunUntilIdle();
1670
1671 // Should have deferred for network start.
1672 EXPECT_TRUE(net_start_handler.observed_before_network_start());
1673 EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState());
1674 EXPECT_TRUE(trans->GetResponseInfo() == NULL);
1675}
1676
[email protected]7a5378b2012-11-04 03:25:171677// Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression
1678// tests. There was a bug causing HttpNetworkTransaction to hang in the
1679// destructor in such situations.
1680// See http://crbug.com/154712 and http://crbug.com/156609.
[email protected]23e482282013-06-14 16:08:021681TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose) {
[email protected]7a5378b2012-11-04 03:25:171682 HttpRequestInfo request;
1683 request.method = "GET";
1684 request.url = GURL("http://www.google.com/");
1685 request.load_flags = 0;
1686
[email protected]bb88e1d32013-05-03 23:11:071687 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:361688 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:501689 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]7a5378b2012-11-04 03:25:171690
1691 MockRead data_reads[] = {
1692 MockRead("HTTP/1.0 200 OK\r\n"),
1693 MockRead("Connection: keep-alive\r\n"),
1694 MockRead("Content-Length: 100\r\n\r\n"),
1695 MockRead("hello"),
1696 MockRead(SYNCHRONOUS, 0),
1697 };
1698 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:071699 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]7a5378b2012-11-04 03:25:171700
1701 TestCompletionCallback callback;
1702
1703 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
1704 EXPECT_EQ(ERR_IO_PENDING, rv);
1705
1706 rv = callback.WaitForResult();
1707 EXPECT_EQ(OK, rv);
1708
1709 scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100));
[email protected]90499482013-06-01 00:39:501710 rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback());
[email protected]7a5378b2012-11-04 03:25:171711 if (rv == ERR_IO_PENDING)
1712 rv = callback.WaitForResult();
1713 EXPECT_EQ(5, rv);
[email protected]90499482013-06-01 00:39:501714 rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback());
[email protected]7a5378b2012-11-04 03:25:171715 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv);
1716
1717 trans.reset();
[email protected]2da659e2013-05-23 20:51:341718 base::MessageLoop::current()->RunUntilIdle();
[email protected]7a5378b2012-11-04 03:25:171719 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get()));
1720}
1721
[email protected]23e482282013-06-14 16:08:021722TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose2) {
[email protected]7a5378b2012-11-04 03:25:171723 HttpRequestInfo request;
1724 request.method = "GET";
1725 request.url = GURL("http://www.google.com/");
1726 request.load_flags = 0;
1727
[email protected]bb88e1d32013-05-03 23:11:071728 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:361729 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:501730 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]7a5378b2012-11-04 03:25:171731
1732 MockRead data_reads[] = {
1733 MockRead("HTTP/1.0 200 OK\r\n"),
1734 MockRead("Connection: keep-alive\r\n"),
1735 MockRead("Content-Length: 100\r\n\r\n"),
1736 MockRead(SYNCHRONOUS, 0),
1737 };
1738 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:071739 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]7a5378b2012-11-04 03:25:171740
1741 TestCompletionCallback callback;
1742
1743 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
1744 EXPECT_EQ(ERR_IO_PENDING, rv);
1745
1746 rv = callback.WaitForResult();
1747 EXPECT_EQ(OK, rv);
1748
1749 scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100));
[email protected]90499482013-06-01 00:39:501750 rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback());
[email protected]7a5378b2012-11-04 03:25:171751 if (rv == ERR_IO_PENDING)
1752 rv = callback.WaitForResult();
1753 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv);
1754
1755 trans.reset();
[email protected]2da659e2013-05-23 20:51:341756 base::MessageLoop::current()->RunUntilIdle();
[email protected]7a5378b2012-11-04 03:25:171757 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get()));
1758}
1759
[email protected]0b0bf032010-09-21 18:08:501760// Test that we correctly reuse a keep-alive connection after not explicitly
1761// reading the body.
[email protected]23e482282013-06-14 16:08:021762TEST_P(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) {
[email protected]fc31d6a42010-06-24 18:05:131763 HttpRequestInfo request;
1764 request.method = "GET";
1765 request.url = GURL("http://www.foo.com/");
1766 request.load_flags = 0;
1767
[email protected]58e32bb2013-01-21 18:23:251768 CapturingNetLog net_log;
[email protected]bb88e1d32013-05-03 23:11:071769 session_deps_.net_log = &net_log;
1770 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:271771
[email protected]0b0bf032010-09-21 18:08:501772 // Note that because all these reads happen in the same
1773 // StaticSocketDataProvider, it shows that the same socket is being reused for
1774 // all transactions.
[email protected]fc31d6a42010-06-24 18:05:131775 MockRead data1_reads[] = {
[email protected]0b0bf032010-09-21 18:08:501776 MockRead("HTTP/1.1 204 No Content\r\n\r\n"),
1777 MockRead("HTTP/1.1 205 Reset Content\r\n\r\n"),
[email protected]fc31d6a42010-06-24 18:05:131778 MockRead("HTTP/1.1 304 Not Modified\r\n\r\n"),
[email protected]0b0bf032010-09-21 18:08:501779 MockRead("HTTP/1.1 302 Found\r\n"
1780 "Content-Length: 0\r\n\r\n"),
1781 MockRead("HTTP/1.1 302 Found\r\n"
1782 "Content-Length: 5\r\n\r\n"
1783 "hello"),
1784 MockRead("HTTP/1.1 301 Moved Permanently\r\n"
1785 "Content-Length: 0\r\n\r\n"),
1786 MockRead("HTTP/1.1 301 Moved Permanently\r\n"
1787 "Content-Length: 5\r\n\r\n"
1788 "hello"),
[email protected]fc31d6a42010-06-24 18:05:131789 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"),
1790 MockRead("hello"),
1791 };
1792 StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:071793 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]fc31d6a42010-06-24 18:05:131794
1795 MockRead data2_reads[] = {
[email protected]8ddf8322012-02-23 18:08:061796 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached.
[email protected]fc31d6a42010-06-24 18:05:131797 };
1798 StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:071799 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]fc31d6a42010-06-24 18:05:131800
[email protected]0b0bf032010-09-21 18:08:501801 const int kNumUnreadBodies = arraysize(data1_reads) - 2;
1802 std::string response_lines[kNumUnreadBodies];
1803
[email protected]58e32bb2013-01-21 18:23:251804 uint32 first_socket_log_id = NetLog::Source::kInvalidId;
[email protected]0b0bf032010-09-21 18:08:501805 for (size_t i = 0; i < arraysize(data1_reads) - 2; ++i) {
[email protected]49639fa2011-12-20 23:22:411806 TestCompletionCallback callback;
[email protected]fc31d6a42010-06-24 18:05:131807
[email protected]262eec82013-03-19 21:01:361808 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:501809 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]fc31d6a42010-06-24 18:05:131810
[email protected]49639fa2011-12-20 23:22:411811 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]fc31d6a42010-06-24 18:05:131812 EXPECT_EQ(ERR_IO_PENDING, rv);
1813
1814 rv = callback.WaitForResult();
1815 EXPECT_EQ(OK, rv);
1816
[email protected]58e32bb2013-01-21 18:23:251817 LoadTimingInfo load_timing_info;
1818 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
1819 if (i == 0) {
1820 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES);
1821 first_socket_log_id = load_timing_info.socket_log_id;
1822 } else {
1823 TestLoadTimingReused(load_timing_info);
1824 EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id);
1825 }
1826
[email protected]fc31d6a42010-06-24 18:05:131827 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]0b0bf032010-09-21 18:08:501828 ASSERT_TRUE(response != NULL);
[email protected]fc31d6a42010-06-24 18:05:131829
[email protected]90499482013-06-01 00:39:501830 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]0b0bf032010-09-21 18:08:501831 response_lines[i] = response->headers->GetStatusLine();
1832
1833 // We intentionally don't read the response bodies.
[email protected]fc31d6a42010-06-24 18:05:131834 }
[email protected]0b0bf032010-09-21 18:08:501835
1836 const char* const kStatusLines[] = {
1837 "HTTP/1.1 204 No Content",
1838 "HTTP/1.1 205 Reset Content",
1839 "HTTP/1.1 304 Not Modified",
1840 "HTTP/1.1 302 Found",
1841 "HTTP/1.1 302 Found",
1842 "HTTP/1.1 301 Moved Permanently",
1843 "HTTP/1.1 301 Moved Permanently",
1844 };
1845
1846 COMPILE_ASSERT(kNumUnreadBodies == arraysize(kStatusLines),
1847 forgot_to_update_kStatusLines);
1848
1849 for (int i = 0; i < kNumUnreadBodies; ++i)
1850 EXPECT_EQ(kStatusLines[i], response_lines[i]);
1851
[email protected]49639fa2011-12-20 23:22:411852 TestCompletionCallback callback;
[email protected]262eec82013-03-19 21:01:361853 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:501854 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:411855 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]0b0bf032010-09-21 18:08:501856 EXPECT_EQ(ERR_IO_PENDING, rv);
1857 rv = callback.WaitForResult();
1858 EXPECT_EQ(OK, rv);
1859 const HttpResponseInfo* response = trans->GetResponseInfo();
1860 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:501861 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]0b0bf032010-09-21 18:08:501862 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
1863 std::string response_data;
1864 rv = ReadTransaction(trans.get(), &response_data);
1865 EXPECT_EQ(OK, rv);
1866 EXPECT_EQ("hello", response_data);
[email protected]fc31d6a42010-06-24 18:05:131867}
1868
[email protected]038e9a32008-10-08 22:40:161869// Test the request-challenge-retry sequence for basic auth.
1870// (basic auth is the easiest to mock, because it has no randomness).
[email protected]23e482282013-06-14 16:08:021871TEST_P(HttpNetworkTransactionTest, BasicAuth) {
[email protected]1c773ea12009-04-28 19:58:421872 HttpRequestInfo request;
[email protected]038e9a32008-10-08 22:40:161873 request.method = "GET";
1874 request.url = GURL("http://www.google.com/");
1875 request.load_flags = 0;
1876
[email protected]58e32bb2013-01-21 18:23:251877 CapturingNetLog log;
[email protected]bb88e1d32013-05-03 23:11:071878 session_deps_.net_log = &log;
[email protected]3fe8d2f82013-10-17 08:56:071879 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:271880 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:411881 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:271882
[email protected]f9ee6b52008-11-08 06:46:231883 MockWrite data_writes1[] = {
1884 MockWrite("GET / HTTP/1.1\r\n"
1885 "Host: www.google.com\r\n"
1886 "Connection: keep-alive\r\n\r\n"),
1887 };
1888
[email protected]038e9a32008-10-08 22:40:161889 MockRead data_reads1[] = {
1890 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
1891 // Give a couple authenticate options (only the middle one is actually
1892 // supported).
[email protected]22927ad2009-09-21 19:56:191893 MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed.
[email protected]038e9a32008-10-08 22:40:161894 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
1895 MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"),
1896 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
1897 // Large content-length -- won't matter, as connection will be reset.
1898 MockRead("Content-Length: 10000\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:061899 MockRead(SYNCHRONOUS, ERR_FAILED),
[email protected]038e9a32008-10-08 22:40:161900 };
1901
1902 // After calling trans->RestartWithAuth(), this is the request we should
1903 // be issuing -- the final header line contains the credentials.
1904 MockWrite data_writes2[] = {
1905 MockWrite("GET / HTTP/1.1\r\n"
1906 "Host: www.google.com\r\n"
1907 "Connection: keep-alive\r\n"
1908 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
1909 };
1910
1911 // Lastly, the server responds with the actual content.
1912 MockRead data_reads2[] = {
1913 MockRead("HTTP/1.0 200 OK\r\n"),
1914 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
1915 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:061916 MockRead(SYNCHRONOUS, OK),
[email protected]038e9a32008-10-08 22:40:161917 };
1918
[email protected]31a2bfe2010-02-09 08:03:391919 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
1920 data_writes1, arraysize(data_writes1));
1921 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
1922 data_writes2, arraysize(data_writes2));
[email protected]bb88e1d32013-05-03 23:11:071923 session_deps_.socket_factory->AddSocketDataProvider(&data1);
1924 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]038e9a32008-10-08 22:40:161925
[email protected]49639fa2011-12-20 23:22:411926 TestCompletionCallback callback1;
[email protected]038e9a32008-10-08 22:40:161927
[email protected]49639fa2011-12-20 23:22:411928 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:421929 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]038e9a32008-10-08 22:40:161930
1931 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:421932 EXPECT_EQ(OK, rv);
[email protected]038e9a32008-10-08 22:40:161933
[email protected]58e32bb2013-01-21 18:23:251934 LoadTimingInfo load_timing_info1;
1935 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1));
1936 TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES);
1937
[email protected]b8015c42013-12-24 15:18:191938 int64 reads_size1 = ReadsSize(data_reads1, arraysize(data_reads1));
1939 EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes());
1940
[email protected]1c773ea12009-04-28 19:58:421941 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:501942 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:041943 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
[email protected]038e9a32008-10-08 22:40:161944
[email protected]49639fa2011-12-20 23:22:411945 TestCompletionCallback callback2;
[email protected]038e9a32008-10-08 22:40:161946
[email protected]49639fa2011-12-20 23:22:411947 rv = trans->RestartWithAuth(
1948 AuthCredentials(kFoo, kBar), callback2.callback());
[email protected]1c773ea12009-04-28 19:58:421949 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]038e9a32008-10-08 22:40:161950
1951 rv = callback2.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:421952 EXPECT_EQ(OK, rv);
[email protected]038e9a32008-10-08 22:40:161953
[email protected]58e32bb2013-01-21 18:23:251954 LoadTimingInfo load_timing_info2;
1955 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2));
1956 TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES);
1957 // The load timing after restart should have a new socket ID, and times after
1958 // those of the first load timing.
1959 EXPECT_LE(load_timing_info1.receive_headers_end,
1960 load_timing_info2.connect_timing.connect_start);
1961 EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id);
1962
[email protected]b8015c42013-12-24 15:18:191963 int64 reads_size2 = ReadsSize(data_reads2, arraysize(data_reads2));
1964 EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes());
1965
[email protected]038e9a32008-10-08 22:40:161966 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:501967 ASSERT_TRUE(response != NULL);
[email protected]038e9a32008-10-08 22:40:161968 EXPECT_TRUE(response->auth_challenge.get() == NULL);
1969 EXPECT_EQ(100, response->headers->GetContentLength());
[email protected]038e9a32008-10-08 22:40:161970}
1971
[email protected]23e482282013-06-14 16:08:021972TEST_P(HttpNetworkTransactionTest, DoNotSendAuth) {
[email protected]861fcd52009-08-26 02:33:461973 HttpRequestInfo request;
1974 request.method = "GET";
1975 request.url = GURL("http://www.google.com/");
1976 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA;
1977
[email protected]3fe8d2f82013-10-17 08:56:071978 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:271979 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:411980 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:271981
[email protected]861fcd52009-08-26 02:33:461982 MockWrite data_writes[] = {
1983 MockWrite("GET / HTTP/1.1\r\n"
1984 "Host: www.google.com\r\n"
1985 "Connection: keep-alive\r\n\r\n"),
1986 };
1987
1988 MockRead data_reads[] = {
1989 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
1990 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
1991 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
1992 // Large content-length -- won't matter, as connection will be reset.
1993 MockRead("Content-Length: 10000\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:061994 MockRead(SYNCHRONOUS, ERR_FAILED),
[email protected]861fcd52009-08-26 02:33:461995 };
1996
[email protected]31a2bfe2010-02-09 08:03:391997 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
1998 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:071999 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]49639fa2011-12-20 23:22:412000 TestCompletionCallback callback;
[email protected]861fcd52009-08-26 02:33:462001
[email protected]49639fa2011-12-20 23:22:412002 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]861fcd52009-08-26 02:33:462003 EXPECT_EQ(ERR_IO_PENDING, rv);
2004
2005 rv = callback.WaitForResult();
2006 EXPECT_EQ(0, rv);
2007
[email protected]b8015c42013-12-24 15:18:192008 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads));
2009 EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes());
2010
[email protected]861fcd52009-08-26 02:33:462011 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:502012 ASSERT_TRUE(response != NULL);
[email protected]861fcd52009-08-26 02:33:462013 EXPECT_TRUE(response->auth_challenge.get() == NULL);
2014}
2015
[email protected]2d2697f92009-02-18 21:00:322016// Test the request-challenge-retry sequence for basic auth, over a keep-alive
2017// connection.
[email protected]23e482282013-06-14 16:08:022018TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAlive) {
[email protected]1c773ea12009-04-28 19:58:422019 HttpRequestInfo request;
[email protected]2d2697f92009-02-18 21:00:322020 request.method = "GET";
2021 request.url = GURL("http://www.google.com/");
2022 request.load_flags = 0;
2023
[email protected]58e32bb2013-01-21 18:23:252024 CapturingNetLog log;
[email protected]bb88e1d32013-05-03 23:11:072025 session_deps_.net_log = &log;
2026 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:272027
[email protected]2d2697f92009-02-18 21:00:322028 MockWrite data_writes1[] = {
2029 MockWrite("GET / HTTP/1.1\r\n"
2030 "Host: www.google.com\r\n"
2031 "Connection: keep-alive\r\n\r\n"),
2032
2033 // After calling trans->RestartWithAuth(), this is the request we should
2034 // be issuing -- the final header line contains the credentials.
2035 MockWrite("GET / HTTP/1.1\r\n"
2036 "Host: www.google.com\r\n"
2037 "Connection: keep-alive\r\n"
2038 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
2039 };
2040
2041 MockRead data_reads1[] = {
2042 MockRead("HTTP/1.1 401 Unauthorized\r\n"),
2043 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2044 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
2045 MockRead("Content-Length: 14\r\n\r\n"),
2046 MockRead("Unauthorized\r\n"),
2047
2048 // Lastly, the server responds with the actual content.
2049 MockRead("HTTP/1.1 200 OK\r\n"),
2050 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
[email protected]0b0bf032010-09-21 18:08:502051 MockRead("Content-Length: 5\r\n\r\n"),
2052 MockRead("Hello"),
[email protected]2d2697f92009-02-18 21:00:322053 };
2054
[email protected]2d0a4f92011-05-05 16:38:462055 // If there is a regression where we disconnect a Keep-Alive
2056 // connection during an auth roundtrip, we'll end up reading this.
2057 MockRead data_reads2[] = {
[email protected]8ddf8322012-02-23 18:08:062058 MockRead(SYNCHRONOUS, ERR_FAILED),
[email protected]2d0a4f92011-05-05 16:38:462059 };
2060
[email protected]31a2bfe2010-02-09 08:03:392061 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
2062 data_writes1, arraysize(data_writes1));
[email protected]2d0a4f92011-05-05 16:38:462063 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
2064 NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:072065 session_deps_.socket_factory->AddSocketDataProvider(&data1);
2066 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]2d2697f92009-02-18 21:00:322067
[email protected]49639fa2011-12-20 23:22:412068 TestCompletionCallback callback1;
[email protected]2d2697f92009-02-18 21:00:322069
[email protected]262eec82013-03-19 21:01:362070 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:502071 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:412072 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:422073 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]2d2697f92009-02-18 21:00:322074
2075 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:422076 EXPECT_EQ(OK, rv);
[email protected]2d2697f92009-02-18 21:00:322077
[email protected]58e32bb2013-01-21 18:23:252078 LoadTimingInfo load_timing_info1;
2079 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1));
2080 TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES);
2081
[email protected]1c773ea12009-04-28 19:58:422082 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:502083 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:042084 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
[email protected]2d2697f92009-02-18 21:00:322085
[email protected]49639fa2011-12-20 23:22:412086 TestCompletionCallback callback2;
[email protected]2d2697f92009-02-18 21:00:322087
[email protected]49639fa2011-12-20 23:22:412088 rv = trans->RestartWithAuth(
2089 AuthCredentials(kFoo, kBar), callback2.callback());
[email protected]1c773ea12009-04-28 19:58:422090 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]2d2697f92009-02-18 21:00:322091
2092 rv = callback2.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:422093 EXPECT_EQ(OK, rv);
[email protected]2d2697f92009-02-18 21:00:322094
[email protected]58e32bb2013-01-21 18:23:252095 LoadTimingInfo load_timing_info2;
2096 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2));
2097 TestLoadTimingReused(load_timing_info2);
2098 // The load timing after restart should have the same socket ID, and times
2099 // those of the first load timing.
2100 EXPECT_LE(load_timing_info1.receive_headers_end,
2101 load_timing_info2.send_start);
2102 EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id);
2103
[email protected]2d2697f92009-02-18 21:00:322104 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:502105 ASSERT_TRUE(response != NULL);
[email protected]2d2697f92009-02-18 21:00:322106 EXPECT_TRUE(response->auth_challenge.get() == NULL);
[email protected]0b0bf032010-09-21 18:08:502107 EXPECT_EQ(5, response->headers->GetContentLength());
[email protected]b8015c42013-12-24 15:18:192108
2109 std::string response_data;
2110 rv = ReadTransaction(trans.get(), &response_data);
2111 EXPECT_EQ(OK, rv);
2112 int64 reads_size1 = ReadsSize(data_reads1, arraysize(data_reads1));
2113 EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes());
[email protected]2d2697f92009-02-18 21:00:322114}
2115
2116// Test the request-challenge-retry sequence for basic auth, over a keep-alive
2117// connection and with no response body to drain.
[email protected]23e482282013-06-14 16:08:022118TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) {
[email protected]1c773ea12009-04-28 19:58:422119 HttpRequestInfo request;
[email protected]2d2697f92009-02-18 21:00:322120 request.method = "GET";
2121 request.url = GURL("http://www.google.com/");
2122 request.load_flags = 0;
2123
[email protected]bb88e1d32013-05-03 23:11:072124 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:272125
[email protected]2d2697f92009-02-18 21:00:322126 MockWrite data_writes1[] = {
2127 MockWrite("GET / HTTP/1.1\r\n"
2128 "Host: www.google.com\r\n"
2129 "Connection: keep-alive\r\n\r\n"),
2130
2131 // After calling trans->RestartWithAuth(), this is the request we should
2132 // be issuing -- the final header line contains the credentials.
2133 MockWrite("GET / HTTP/1.1\r\n"
2134 "Host: www.google.com\r\n"
2135 "Connection: keep-alive\r\n"
2136 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
2137 };
2138
[email protected]2d2697f92009-02-18 21:00:322139 MockRead data_reads1[] = {
2140 MockRead("HTTP/1.1 401 Unauthorized\r\n"),
2141 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
[email protected]11203f012009-11-12 23:02:312142 MockRead("Content-Length: 0\r\n\r\n"), // No response body.
[email protected]2d2697f92009-02-18 21:00:322143
2144 // Lastly, the server responds with the actual content.
2145 MockRead("HTTP/1.1 200 OK\r\n"),
2146 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
[email protected]0b0bf032010-09-21 18:08:502147 MockRead("Content-Length: 5\r\n\r\n"),
2148 MockRead("hello"),
[email protected]2d2697f92009-02-18 21:00:322149 };
2150
[email protected]2d0a4f92011-05-05 16:38:462151 // An incorrect reconnect would cause this to be read.
2152 MockRead data_reads2[] = {
[email protected]8ddf8322012-02-23 18:08:062153 MockRead(SYNCHRONOUS, ERR_FAILED),
[email protected]2d0a4f92011-05-05 16:38:462154 };
2155
[email protected]31a2bfe2010-02-09 08:03:392156 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
2157 data_writes1, arraysize(data_writes1));
[email protected]2d0a4f92011-05-05 16:38:462158 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
2159 NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:072160 session_deps_.socket_factory->AddSocketDataProvider(&data1);
2161 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]2d2697f92009-02-18 21:00:322162
[email protected]49639fa2011-12-20 23:22:412163 TestCompletionCallback callback1;
[email protected]2d2697f92009-02-18 21:00:322164
[email protected]262eec82013-03-19 21:01:362165 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:502166 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:412167 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:422168 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]2d2697f92009-02-18 21:00:322169
2170 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:422171 EXPECT_EQ(OK, rv);
[email protected]2d2697f92009-02-18 21:00:322172
[email protected]1c773ea12009-04-28 19:58:422173 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:502174 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:042175 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
[email protected]2d2697f92009-02-18 21:00:322176
[email protected]49639fa2011-12-20 23:22:412177 TestCompletionCallback callback2;
[email protected]2d2697f92009-02-18 21:00:322178
[email protected]49639fa2011-12-20 23:22:412179 rv = trans->RestartWithAuth(
2180 AuthCredentials(kFoo, kBar), callback2.callback());
[email protected]1c773ea12009-04-28 19:58:422181 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]2d2697f92009-02-18 21:00:322182
2183 rv = callback2.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:422184 EXPECT_EQ(OK, rv);
[email protected]2d2697f92009-02-18 21:00:322185
2186 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:502187 ASSERT_TRUE(response != NULL);
[email protected]2d2697f92009-02-18 21:00:322188 EXPECT_TRUE(response->auth_challenge.get() == NULL);
[email protected]0b0bf032010-09-21 18:08:502189 EXPECT_EQ(5, response->headers->GetContentLength());
[email protected]2d2697f92009-02-18 21:00:322190}
2191
2192// Test the request-challenge-retry sequence for basic auth, over a keep-alive
2193// connection and with a large response body to drain.
[email protected]23e482282013-06-14 16:08:022194TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) {
[email protected]1c773ea12009-04-28 19:58:422195 HttpRequestInfo request;
[email protected]2d2697f92009-02-18 21:00:322196 request.method = "GET";
2197 request.url = GURL("http://www.google.com/");
2198 request.load_flags = 0;
2199
[email protected]bb88e1d32013-05-03 23:11:072200 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:272201
[email protected]2d2697f92009-02-18 21:00:322202 MockWrite data_writes1[] = {
2203 MockWrite("GET / HTTP/1.1\r\n"
2204 "Host: www.google.com\r\n"
2205 "Connection: keep-alive\r\n\r\n"),
2206
2207 // After calling trans->RestartWithAuth(), this is the request we should
2208 // be issuing -- the final header line contains the credentials.
2209 MockWrite("GET / HTTP/1.1\r\n"
2210 "Host: www.google.com\r\n"
2211 "Connection: keep-alive\r\n"
2212 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
2213 };
2214
2215 // Respond with 5 kb of response body.
2216 std::string large_body_string("Unauthorized");
2217 large_body_string.append(5 * 1024, ' ');
2218 large_body_string.append("\r\n");
2219
2220 MockRead data_reads1[] = {
2221 MockRead("HTTP/1.1 401 Unauthorized\r\n"),
2222 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2223 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
2224 // 5134 = 12 + 5 * 1024 + 2
2225 MockRead("Content-Length: 5134\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:062226 MockRead(ASYNC, large_body_string.data(), large_body_string.size()),
[email protected]2d2697f92009-02-18 21:00:322227
2228 // Lastly, the server responds with the actual content.
2229 MockRead("HTTP/1.1 200 OK\r\n"),
2230 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
[email protected]0b0bf032010-09-21 18:08:502231 MockRead("Content-Length: 5\r\n\r\n"),
2232 MockRead("hello"),
[email protected]2d2697f92009-02-18 21:00:322233 };
2234
[email protected]2d0a4f92011-05-05 16:38:462235 // An incorrect reconnect would cause this to be read.
2236 MockRead data_reads2[] = {
[email protected]8ddf8322012-02-23 18:08:062237 MockRead(SYNCHRONOUS, ERR_FAILED),
[email protected]2d0a4f92011-05-05 16:38:462238 };
2239
[email protected]31a2bfe2010-02-09 08:03:392240 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
2241 data_writes1, arraysize(data_writes1));
[email protected]2d0a4f92011-05-05 16:38:462242 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
2243 NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:072244 session_deps_.socket_factory->AddSocketDataProvider(&data1);
2245 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]2d2697f92009-02-18 21:00:322246
[email protected]49639fa2011-12-20 23:22:412247 TestCompletionCallback callback1;
[email protected]2d2697f92009-02-18 21:00:322248
[email protected]262eec82013-03-19 21:01:362249 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:502250 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:412251 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:422252 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]2d2697f92009-02-18 21:00:322253
2254 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:422255 EXPECT_EQ(OK, rv);
[email protected]2d2697f92009-02-18 21:00:322256
[email protected]1c773ea12009-04-28 19:58:422257 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:502258 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:042259 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
[email protected]2d2697f92009-02-18 21:00:322260
[email protected]49639fa2011-12-20 23:22:412261 TestCompletionCallback callback2;
[email protected]2d2697f92009-02-18 21:00:322262
[email protected]49639fa2011-12-20 23:22:412263 rv = trans->RestartWithAuth(
2264 AuthCredentials(kFoo, kBar), callback2.callback());
[email protected]1c773ea12009-04-28 19:58:422265 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]2d2697f92009-02-18 21:00:322266
2267 rv = callback2.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:422268 EXPECT_EQ(OK, rv);
[email protected]2d2697f92009-02-18 21:00:322269
2270 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:502271 ASSERT_TRUE(response != NULL);
[email protected]2d2697f92009-02-18 21:00:322272 EXPECT_TRUE(response->auth_challenge.get() == NULL);
[email protected]0b0bf032010-09-21 18:08:502273 EXPECT_EQ(5, response->headers->GetContentLength());
[email protected]2d2697f92009-02-18 21:00:322274}
2275
2276// Test the request-challenge-retry sequence for basic auth, over a keep-alive
[email protected]11203f012009-11-12 23:02:312277// connection, but the server gets impatient and closes the connection.
[email protected]23e482282013-06-14 16:08:022278TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) {
[email protected]11203f012009-11-12 23:02:312279 HttpRequestInfo request;
2280 request.method = "GET";
2281 request.url = GURL("http://www.google.com/");
2282 request.load_flags = 0;
2283
[email protected]bb88e1d32013-05-03 23:11:072284 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:272285
[email protected]11203f012009-11-12 23:02:312286 MockWrite data_writes1[] = {
2287 MockWrite("GET / HTTP/1.1\r\n"
2288 "Host: www.google.com\r\n"
2289 "Connection: keep-alive\r\n\r\n"),
2290 // This simulates the seemingly successful write to a closed connection
2291 // if the bug is not fixed.
2292 MockWrite("GET / HTTP/1.1\r\n"
2293 "Host: www.google.com\r\n"
2294 "Connection: keep-alive\r\n"
2295 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
2296 };
2297
2298 MockRead data_reads1[] = {
2299 MockRead("HTTP/1.1 401 Unauthorized\r\n"),
2300 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2301 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
2302 MockRead("Content-Length: 14\r\n\r\n"),
2303 // Tell MockTCPClientSocket to simulate the server closing the connection.
[email protected]8ddf8322012-02-23 18:08:062304 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
[email protected]11203f012009-11-12 23:02:312305 MockRead("Unauthorized\r\n"),
[email protected]8ddf8322012-02-23 18:08:062306 MockRead(SYNCHRONOUS, OK), // The server closes the connection.
[email protected]11203f012009-11-12 23:02:312307 };
2308
2309 // After calling trans->RestartWithAuth(), this is the request we should
2310 // be issuing -- the final header line contains the credentials.
2311 MockWrite data_writes2[] = {
2312 MockWrite("GET / HTTP/1.1\r\n"
2313 "Host: www.google.com\r\n"
2314 "Connection: keep-alive\r\n"
2315 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
2316 };
2317
2318 // Lastly, the server responds with the actual content.
2319 MockRead data_reads2[] = {
2320 MockRead("HTTP/1.1 200 OK\r\n"),
2321 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
[email protected]0b0bf032010-09-21 18:08:502322 MockRead("Content-Length: 5\r\n\r\n"),
2323 MockRead("hello"),
[email protected]11203f012009-11-12 23:02:312324 };
2325
[email protected]31a2bfe2010-02-09 08:03:392326 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
2327 data_writes1, arraysize(data_writes1));
2328 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
2329 data_writes2, arraysize(data_writes2));
[email protected]bb88e1d32013-05-03 23:11:072330 session_deps_.socket_factory->AddSocketDataProvider(&data1);
2331 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]11203f012009-11-12 23:02:312332
[email protected]49639fa2011-12-20 23:22:412333 TestCompletionCallback callback1;
[email protected]11203f012009-11-12 23:02:312334
[email protected]262eec82013-03-19 21:01:362335 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:502336 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:412337 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]11203f012009-11-12 23:02:312338 EXPECT_EQ(ERR_IO_PENDING, rv);
2339
2340 rv = callback1.WaitForResult();
2341 EXPECT_EQ(OK, rv);
2342
2343 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:502344 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:042345 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
[email protected]11203f012009-11-12 23:02:312346
[email protected]49639fa2011-12-20 23:22:412347 TestCompletionCallback callback2;
[email protected]11203f012009-11-12 23:02:312348
[email protected]49639fa2011-12-20 23:22:412349 rv = trans->RestartWithAuth(
2350 AuthCredentials(kFoo, kBar), callback2.callback());
[email protected]11203f012009-11-12 23:02:312351 EXPECT_EQ(ERR_IO_PENDING, rv);
2352
2353 rv = callback2.WaitForResult();
2354 EXPECT_EQ(OK, rv);
2355
2356 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:502357 ASSERT_TRUE(response != NULL);
[email protected]11203f012009-11-12 23:02:312358 EXPECT_TRUE(response->auth_challenge.get() == NULL);
[email protected]0b0bf032010-09-21 18:08:502359 EXPECT_EQ(5, response->headers->GetContentLength());
[email protected]11203f012009-11-12 23:02:312360}
2361
[email protected]394816e92010-08-03 07:38:592362// Test the request-challenge-retry sequence for basic auth, over a connection
2363// that requires a restart when setting up an SSL tunnel.
[email protected]23e482282013-06-14 16:08:022364TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAlive) {
[email protected]394816e92010-08-03 07:38:592365 HttpRequestInfo request;
2366 request.method = "GET";
2367 request.url = GURL("https://www.google.com/");
2368 // when the no authentication data flag is set.
2369 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA;
2370
[email protected]cb9bf6ca2011-01-28 13:15:272371 // Configure against proxy server "myproxy:70".
[email protected]bb88e1d32013-05-03 23:11:072372 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:202373 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"));
[email protected]333bdf62012-06-08 22:57:292374 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:072375 session_deps_.net_log = log.bound().net_log();
2376 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:272377
[email protected]394816e92010-08-03 07:38:592378 // Since we have proxy, should try to establish tunnel.
2379 MockWrite data_writes1[] = {
2380 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
2381 "Host: www.google.com\r\n"
2382 "Proxy-Connection: keep-alive\r\n\r\n"),
2383
2384 // After calling trans->RestartWithAuth(), this is the request we should
2385 // be issuing -- the final header line contains the credentials.
2386 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
2387 "Host: www.google.com\r\n"
2388 "Proxy-Connection: keep-alive\r\n"
2389 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
2390
2391 MockWrite("GET / HTTP/1.1\r\n"
2392 "Host: www.google.com\r\n"
2393 "Connection: keep-alive\r\n\r\n"),
2394 };
2395
2396 // The proxy responds to the connect with a 407, using a persistent
2397 // connection.
2398 MockRead data_reads1[] = {
2399 // No credentials.
2400 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
2401 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2402 MockRead("Proxy-Connection: close\r\n\r\n"),
2403
2404 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"),
2405
2406 MockRead("HTTP/1.1 200 OK\r\n"),
2407 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
[email protected]0b0bf032010-09-21 18:08:502408 MockRead("Content-Length: 5\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:062409 MockRead(SYNCHRONOUS, "hello"),
[email protected]394816e92010-08-03 07:38:592410 };
2411
2412 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
2413 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:072414 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]8ddf8322012-02-23 18:08:062415 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]bb88e1d32013-05-03 23:11:072416 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]394816e92010-08-03 07:38:592417
[email protected]49639fa2011-12-20 23:22:412418 TestCompletionCallback callback1;
[email protected]394816e92010-08-03 07:38:592419
[email protected]262eec82013-03-19 21:01:362420 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:502421 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0b0bf032010-09-21 18:08:502422
[email protected]49639fa2011-12-20 23:22:412423 int rv = trans->Start(&request, callback1.callback(), log.bound());
[email protected]394816e92010-08-03 07:38:592424 EXPECT_EQ(ERR_IO_PENDING, rv);
2425
2426 rv = callback1.WaitForResult();
2427 EXPECT_EQ(OK, rv);
[email protected]f3da152d2012-06-02 01:00:572428 net::CapturingNetLog::CapturedEntryList entries;
[email protected]b2fcd0e2010-12-01 15:19:402429 log.GetEntries(&entries);
[email protected]394816e92010-08-03 07:38:592430 size_t pos = ExpectLogContainsSomewhere(
[email protected]b2fcd0e2010-12-01 15:19:402431 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
[email protected]394816e92010-08-03 07:38:592432 NetLog::PHASE_NONE);
2433 ExpectLogContainsSomewhere(
[email protected]b2fcd0e2010-12-01 15:19:402434 entries, pos,
[email protected]394816e92010-08-03 07:38:592435 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
2436 NetLog::PHASE_NONE);
2437
2438 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:502439 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:502440 ASSERT_FALSE(response->headers.get() == NULL);
[email protected]394816e92010-08-03 07:38:592441 EXPECT_EQ(407, response->headers->response_code());
2442 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
[email protected]79cb5c12011-09-12 13:12:042443 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
[email protected]394816e92010-08-03 07:38:592444
[email protected]029c83b62013-01-24 05:28:202445 LoadTimingInfo load_timing_info;
2446 // CONNECT requests and responses are handled at the connect job level, so
2447 // the transaction does not yet have a connection.
2448 EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info));
2449
[email protected]49639fa2011-12-20 23:22:412450 TestCompletionCallback callback2;
[email protected]394816e92010-08-03 07:38:592451
[email protected]49639fa2011-12-20 23:22:412452 rv = trans->RestartWithAuth(
2453 AuthCredentials(kFoo, kBar), callback2.callback());
[email protected]394816e92010-08-03 07:38:592454 EXPECT_EQ(ERR_IO_PENDING, rv);
2455
2456 rv = callback2.WaitForResult();
2457 EXPECT_EQ(OK, rv);
2458
2459 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:502460 ASSERT_TRUE(response != NULL);
[email protected]394816e92010-08-03 07:38:592461
2462 EXPECT_TRUE(response->headers->IsKeepAlive());
2463 EXPECT_EQ(200, response->headers->response_code());
[email protected]0b0bf032010-09-21 18:08:502464 EXPECT_EQ(5, response->headers->GetContentLength());
[email protected]394816e92010-08-03 07:38:592465 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
2466
2467 // The password prompt info should not be set.
2468 EXPECT_TRUE(response->auth_challenge.get() == NULL);
[email protected]0b0bf032010-09-21 18:08:502469
[email protected]029c83b62013-01-24 05:28:202470 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
2471 TestLoadTimingNotReusedWithPac(load_timing_info,
2472 CONNECT_TIMING_HAS_SSL_TIMES);
2473
[email protected]0b0bf032010-09-21 18:08:502474 trans.reset();
[email protected]102e27c2011-02-23 01:01:312475 session->CloseAllConnections();
[email protected]394816e92010-08-03 07:38:592476}
2477
[email protected]11203f012009-11-12 23:02:312478// Test the request-challenge-retry sequence for basic auth, over a keep-alive
[email protected]2d2697f92009-02-18 21:00:322479// proxy connection, when setting up an SSL tunnel.
[email protected]23e482282013-06-14 16:08:022480TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAlive) {
[email protected]cb9bf6ca2011-01-28 13:15:272481 HttpRequestInfo request;
2482 request.method = "GET";
2483 request.url = GURL("https://www.google.com/");
2484 // Ensure that proxy authentication is attempted even
2485 // when the no authentication data flag is set.
2486 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA;
2487
[email protected]2d2697f92009-02-18 21:00:322488 // Configure against proxy server "myproxy:70".
[email protected]bb88e1d32013-05-03 23:11:072489 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70"));
[email protected]333bdf62012-06-08 22:57:292490 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:072491 session_deps_.net_log = log.bound().net_log();
2492 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]2d2697f92009-02-18 21:00:322493
[email protected]262eec82013-03-19 21:01:362494 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:502495 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]2d2697f92009-02-18 21:00:322496
[email protected]2d2697f92009-02-18 21:00:322497 // Since we have proxy, should try to establish tunnel.
2498 MockWrite data_writes1[] = {
2499 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
[email protected]e44de5d2009-06-05 20:12:452500 "Host: www.google.com\r\n"
2501 "Proxy-Connection: keep-alive\r\n\r\n"),
[email protected]2d2697f92009-02-18 21:00:322502
2503 // After calling trans->RestartWithAuth(), this is the request we should
2504 // be issuing -- the final header line contains the credentials.
2505 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
2506 "Host: www.google.com\r\n"
[email protected]e44de5d2009-06-05 20:12:452507 "Proxy-Connection: keep-alive\r\n"
[email protected]2d2697f92009-02-18 21:00:322508 "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"),
2509 };
2510
2511 // The proxy responds to the connect with a 407, using a persistent
2512 // connection.
2513 MockRead data_reads1[] = {
2514 // No credentials.
2515 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
2516 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2517 MockRead("Content-Length: 10\r\n\r\n"),
2518 MockRead("0123456789"),
2519
2520 // Wrong credentials (wrong password).
2521 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
2522 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2523 MockRead("Content-Length: 10\r\n\r\n"),
2524 // No response body because the test stops reading here.
[email protected]8ddf8322012-02-23 18:08:062525 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached.
[email protected]2d2697f92009-02-18 21:00:322526 };
2527
[email protected]31a2bfe2010-02-09 08:03:392528 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
2529 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:072530 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]2d2697f92009-02-18 21:00:322531
[email protected]49639fa2011-12-20 23:22:412532 TestCompletionCallback callback1;
[email protected]2d2697f92009-02-18 21:00:322533
[email protected]49639fa2011-12-20 23:22:412534 int rv = trans->Start(&request, callback1.callback(), log.bound());
[email protected]1c773ea12009-04-28 19:58:422535 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]2d2697f92009-02-18 21:00:322536
2537 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:422538 EXPECT_EQ(OK, rv);
[email protected]f3da152d2012-06-02 01:00:572539 net::CapturingNetLog::CapturedEntryList entries;
[email protected]b2fcd0e2010-12-01 15:19:402540 log.GetEntries(&entries);
[email protected]dbb83db2010-05-11 18:13:392541 size_t pos = ExpectLogContainsSomewhere(
[email protected]b2fcd0e2010-12-01 15:19:402542 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
[email protected]dbb83db2010-05-11 18:13:392543 NetLog::PHASE_NONE);
2544 ExpectLogContainsSomewhere(
[email protected]b2fcd0e2010-12-01 15:19:402545 entries, pos,
[email protected]dbb83db2010-05-11 18:13:392546 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
2547 NetLog::PHASE_NONE);
[email protected]2d2697f92009-02-18 21:00:322548
[email protected]1c773ea12009-04-28 19:58:422549 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:502550 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:502551 ASSERT_FALSE(response->headers.get() == NULL);
[email protected]2d2697f92009-02-18 21:00:322552 EXPECT_TRUE(response->headers->IsKeepAlive());
2553 EXPECT_EQ(407, response->headers->response_code());
2554 EXPECT_EQ(10, response->headers->GetContentLength());
[email protected]1c773ea12009-04-28 19:58:422555 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
[email protected]79cb5c12011-09-12 13:12:042556 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
[email protected]2d2697f92009-02-18 21:00:322557
[email protected]49639fa2011-12-20 23:22:412558 TestCompletionCallback callback2;
[email protected]2d2697f92009-02-18 21:00:322559
2560 // Wrong password (should be "bar").
[email protected]49639fa2011-12-20 23:22:412561 rv = trans->RestartWithAuth(
2562 AuthCredentials(kFoo, kBaz), callback2.callback());
[email protected]1c773ea12009-04-28 19:58:422563 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]2d2697f92009-02-18 21:00:322564
2565 rv = callback2.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:422566 EXPECT_EQ(OK, rv);
[email protected]2d2697f92009-02-18 21:00:322567
2568 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:502569 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:502570 ASSERT_FALSE(response->headers.get() == NULL);
[email protected]2d2697f92009-02-18 21:00:322571 EXPECT_TRUE(response->headers->IsKeepAlive());
2572 EXPECT_EQ(407, response->headers->response_code());
2573 EXPECT_EQ(10, response->headers->GetContentLength());
[email protected]1c773ea12009-04-28 19:58:422574 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
[email protected]79cb5c12011-09-12 13:12:042575 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
[email protected]e772db3f2010-07-12 18:11:132576
[email protected]e60e47a2010-07-14 03:37:182577 // Flush the idle socket before the NetLog and HttpNetworkTransaction go
2578 // out of scope.
[email protected]102e27c2011-02-23 01:01:312579 session->CloseAllConnections();
[email protected]2d2697f92009-02-18 21:00:322580}
2581
[email protected]a8e9b162009-03-12 00:06:442582// Test that we don't read the response body when we fail to establish a tunnel,
2583// even if the user cancels the proxy's auth attempt.
[email protected]23e482282013-06-14 16:08:022584TEST_P(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) {
[email protected]cb9bf6ca2011-01-28 13:15:272585 HttpRequestInfo request;
2586 request.method = "GET";
2587 request.url = GURL("https://www.google.com/");
2588 request.load_flags = 0;
2589
[email protected]a8e9b162009-03-12 00:06:442590 // Configure against proxy server "myproxy:70".
[email protected]bb88e1d32013-05-03 23:11:072591 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70"));
[email protected]a8e9b162009-03-12 00:06:442592
[email protected]bb88e1d32013-05-03 23:11:072593 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]a8e9b162009-03-12 00:06:442594
[email protected]262eec82013-03-19 21:01:362595 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:502596 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]a8e9b162009-03-12 00:06:442597
[email protected]a8e9b162009-03-12 00:06:442598 // Since we have proxy, should try to establish tunnel.
2599 MockWrite data_writes[] = {
2600 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
[email protected]e44de5d2009-06-05 20:12:452601 "Host: www.google.com\r\n"
2602 "Proxy-Connection: keep-alive\r\n\r\n"),
[email protected]a8e9b162009-03-12 00:06:442603 };
2604
2605 // The proxy responds to the connect with a 407.
2606 MockRead data_reads[] = {
2607 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
2608 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2609 MockRead("Content-Length: 10\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:062610 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached.
[email protected]a8e9b162009-03-12 00:06:442611 };
2612
[email protected]31a2bfe2010-02-09 08:03:392613 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
2614 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:072615 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]a8e9b162009-03-12 00:06:442616
[email protected]49639fa2011-12-20 23:22:412617 TestCompletionCallback callback;
[email protected]a8e9b162009-03-12 00:06:442618
[email protected]49639fa2011-12-20 23:22:412619 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:422620 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]a8e9b162009-03-12 00:06:442621
2622 rv = callback.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:422623 EXPECT_EQ(OK, rv);
[email protected]a8e9b162009-03-12 00:06:442624
[email protected]1c773ea12009-04-28 19:58:422625 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:502626 ASSERT_TRUE(response != NULL);
[email protected]a8e9b162009-03-12 00:06:442627
2628 EXPECT_TRUE(response->headers->IsKeepAlive());
2629 EXPECT_EQ(407, response->headers->response_code());
2630 EXPECT_EQ(10, response->headers->GetContentLength());
[email protected]1c773ea12009-04-28 19:58:422631 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
[email protected]a8e9b162009-03-12 00:06:442632
2633 std::string response_data;
2634 rv = ReadTransaction(trans.get(), &response_data);
[email protected]1c773ea12009-04-28 19:58:422635 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv);
[email protected]e60e47a2010-07-14 03:37:182636
2637 // Flush the idle socket before the HttpNetworkTransaction goes out of scope.
[email protected]102e27c2011-02-23 01:01:312638 session->CloseAllConnections();
[email protected]a8e9b162009-03-12 00:06:442639}
2640
[email protected]8fdbcd22010-05-05 02:54:522641// Test when a server (non-proxy) returns a 407 (proxy-authenticate).
2642// The request should fail with ERR_UNEXPECTED_PROXY_AUTH.
[email protected]23e482282013-06-14 16:08:022643TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) {
[email protected]8fdbcd22010-05-05 02:54:522644 HttpRequestInfo request;
2645 request.method = "GET";
2646 request.url = GURL("http://www.google.com/");
2647 request.load_flags = 0;
2648
[email protected]cb9bf6ca2011-01-28 13:15:272649 // We are using a DIRECT connection (i.e. no proxy) for this session.
[email protected]3fe8d2f82013-10-17 08:56:072650 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:272651 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:412652 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:272653
[email protected]8fdbcd22010-05-05 02:54:522654 MockWrite data_writes1[] = {
2655 MockWrite("GET / HTTP/1.1\r\n"
2656 "Host: www.google.com\r\n"
2657 "Connection: keep-alive\r\n\r\n"),
2658 };
2659
2660 MockRead data_reads1[] = {
2661 MockRead("HTTP/1.0 407 Proxy Auth required\r\n"),
2662 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2663 // Large content-length -- won't matter, as connection will be reset.
2664 MockRead("Content-Length: 10000\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:062665 MockRead(SYNCHRONOUS, ERR_FAILED),
[email protected]8fdbcd22010-05-05 02:54:522666 };
2667
2668 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
2669 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:072670 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]8fdbcd22010-05-05 02:54:522671
[email protected]49639fa2011-12-20 23:22:412672 TestCompletionCallback callback;
[email protected]8fdbcd22010-05-05 02:54:522673
[email protected]49639fa2011-12-20 23:22:412674 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]8fdbcd22010-05-05 02:54:522675 EXPECT_EQ(ERR_IO_PENDING, rv);
2676
2677 rv = callback.WaitForResult();
2678 EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv);
2679}
2680
[email protected]7a67a8152010-11-05 18:31:102681// Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication)
2682// through a non-authenticating proxy. The request should fail with
2683// ERR_UNEXPECTED_PROXY_AUTH.
2684// Note that it is impossible to detect if an HTTP server returns a 407 through
2685// a non-authenticating proxy - there is nothing to indicate whether the
2686// response came from the proxy or the server, so it is treated as if the proxy
2687// issued the challenge.
[email protected]23e482282013-06-14 16:08:022688TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:232689 HttpsServerRequestsProxyAuthThroughProxy) {
[email protected]cb9bf6ca2011-01-28 13:15:272690 HttpRequestInfo request;
2691 request.method = "GET";
2692 request.url = GURL("https://www.google.com/");
2693
[email protected]bb88e1d32013-05-03 23:11:072694 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70"));
[email protected]333bdf62012-06-08 22:57:292695 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:072696 session_deps_.net_log = log.bound().net_log();
2697 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]7a67a8152010-11-05 18:31:102698
[email protected]7a67a8152010-11-05 18:31:102699 // Since we have proxy, should try to establish tunnel.
2700 MockWrite data_writes1[] = {
2701 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
2702 "Host: www.google.com\r\n"
2703 "Proxy-Connection: keep-alive\r\n\r\n"),
2704
2705 MockWrite("GET / HTTP/1.1\r\n"
2706 "Host: www.google.com\r\n"
2707 "Connection: keep-alive\r\n\r\n"),
2708 };
2709
2710 MockRead data_reads1[] = {
2711 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"),
2712
2713 MockRead("HTTP/1.1 407 Unauthorized\r\n"),
2714 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2715 MockRead("\r\n"),
[email protected]8ddf8322012-02-23 18:08:062716 MockRead(SYNCHRONOUS, OK),
[email protected]7a67a8152010-11-05 18:31:102717 };
2718
2719 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
2720 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:072721 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]8ddf8322012-02-23 18:08:062722 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]bb88e1d32013-05-03 23:11:072723 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]7a67a8152010-11-05 18:31:102724
[email protected]49639fa2011-12-20 23:22:412725 TestCompletionCallback callback1;
[email protected]7a67a8152010-11-05 18:31:102726
[email protected]262eec82013-03-19 21:01:362727 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:502728 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]7a67a8152010-11-05 18:31:102729
[email protected]49639fa2011-12-20 23:22:412730 int rv = trans->Start(&request, callback1.callback(), log.bound());
[email protected]7a67a8152010-11-05 18:31:102731 EXPECT_EQ(ERR_IO_PENDING, rv);
2732
2733 rv = callback1.WaitForResult();
2734 EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv);
[email protected]f3da152d2012-06-02 01:00:572735 net::CapturingNetLog::CapturedEntryList entries;
[email protected]b2fcd0e2010-12-01 15:19:402736 log.GetEntries(&entries);
[email protected]7a67a8152010-11-05 18:31:102737 size_t pos = ExpectLogContainsSomewhere(
[email protected]b2fcd0e2010-12-01 15:19:402738 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
[email protected]7a67a8152010-11-05 18:31:102739 NetLog::PHASE_NONE);
2740 ExpectLogContainsSomewhere(
[email protected]b2fcd0e2010-12-01 15:19:402741 entries, pos,
[email protected]7a67a8152010-11-05 18:31:102742 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
2743 NetLog::PHASE_NONE);
2744}
[email protected]2df19bb2010-08-25 20:13:462745
[email protected]029c83b62013-01-24 05:28:202746// Test the load timing for HTTPS requests with an HTTP proxy.
[email protected]23e482282013-06-14 16:08:022747TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) {
[email protected]029c83b62013-01-24 05:28:202748 HttpRequestInfo request1;
2749 request1.method = "GET";
2750 request1.url = GURL("https://www.google.com/1");
2751
2752 HttpRequestInfo request2;
2753 request2.method = "GET";
2754 request2.url = GURL("https://www.google.com/2");
2755
2756 // Configure against proxy server "myproxy:70".
[email protected]bb88e1d32013-05-03 23:11:072757 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:202758 ProxyService::CreateFixed("PROXY myproxy:70"));
2759 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:072760 session_deps_.net_log = log.bound().net_log();
2761 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]029c83b62013-01-24 05:28:202762
2763 // Since we have proxy, should try to establish tunnel.
2764 MockWrite data_writes1[] = {
2765 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
2766 "Host: www.google.com\r\n"
2767 "Proxy-Connection: keep-alive\r\n\r\n"),
2768
2769 MockWrite("GET /1 HTTP/1.1\r\n"
2770 "Host: www.google.com\r\n"
2771 "Connection: keep-alive\r\n\r\n"),
2772
2773 MockWrite("GET /2 HTTP/1.1\r\n"
2774 "Host: www.google.com\r\n"
2775 "Connection: keep-alive\r\n\r\n"),
2776 };
2777
2778 // The proxy responds to the connect with a 407, using a persistent
2779 // connection.
2780 MockRead data_reads1[] = {
2781 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"),
2782
2783 MockRead("HTTP/1.1 200 OK\r\n"),
2784 MockRead("Content-Length: 1\r\n\r\n"),
2785 MockRead(SYNCHRONOUS, "1"),
2786
2787 MockRead("HTTP/1.1 200 OK\r\n"),
2788 MockRead("Content-Length: 2\r\n\r\n"),
2789 MockRead(SYNCHRONOUS, "22"),
2790 };
2791
2792 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
2793 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:072794 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]029c83b62013-01-24 05:28:202795 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]bb88e1d32013-05-03 23:11:072796 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]029c83b62013-01-24 05:28:202797
2798 TestCompletionCallback callback1;
[email protected]262eec82013-03-19 21:01:362799 scoped_ptr<HttpTransaction> trans1(
[email protected]90499482013-06-01 00:39:502800 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]029c83b62013-01-24 05:28:202801
2802 int rv = trans1->Start(&request1, callback1.callback(), log.bound());
2803 EXPECT_EQ(ERR_IO_PENDING, rv);
2804
2805 rv = callback1.WaitForResult();
2806 EXPECT_EQ(OK, rv);
2807
2808 const HttpResponseInfo* response1 = trans1->GetResponseInfo();
2809 ASSERT_TRUE(response1 != NULL);
[email protected]90499482013-06-01 00:39:502810 ASSERT_TRUE(response1->headers.get() != NULL);
[email protected]029c83b62013-01-24 05:28:202811 EXPECT_EQ(1, response1->headers->GetContentLength());
2812
2813 LoadTimingInfo load_timing_info1;
2814 EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1));
2815 TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES);
2816
2817 trans1.reset();
2818
2819 TestCompletionCallback callback2;
[email protected]262eec82013-03-19 21:01:362820 scoped_ptr<HttpTransaction> trans2(
[email protected]90499482013-06-01 00:39:502821 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]029c83b62013-01-24 05:28:202822
2823 rv = trans2->Start(&request2, callback2.callback(), log.bound());
2824 EXPECT_EQ(ERR_IO_PENDING, rv);
2825
2826 rv = callback2.WaitForResult();
2827 EXPECT_EQ(OK, rv);
2828
2829 const HttpResponseInfo* response2 = trans2->GetResponseInfo();
2830 ASSERT_TRUE(response2 != NULL);
[email protected]90499482013-06-01 00:39:502831 ASSERT_TRUE(response2->headers.get() != NULL);
[email protected]029c83b62013-01-24 05:28:202832 EXPECT_EQ(2, response2->headers->GetContentLength());
2833
2834 LoadTimingInfo load_timing_info2;
2835 EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2));
2836 TestLoadTimingReused(load_timing_info2);
2837
2838 EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id);
2839
2840 trans2.reset();
2841 session->CloseAllConnections();
2842}
2843
2844// Test the load timing for HTTPS requests with an HTTP proxy and a PAC script.
[email protected]23e482282013-06-14 16:08:022845TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) {
[email protected]029c83b62013-01-24 05:28:202846 HttpRequestInfo request1;
2847 request1.method = "GET";
2848 request1.url = GURL("https://www.google.com/1");
2849
2850 HttpRequestInfo request2;
2851 request2.method = "GET";
2852 request2.url = GURL("https://www.google.com/2");
2853
2854 // Configure against proxy server "myproxy:70".
[email protected]bb88e1d32013-05-03 23:11:072855 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:202856 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"));
2857 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:072858 session_deps_.net_log = log.bound().net_log();
2859 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]029c83b62013-01-24 05:28:202860
2861 // Since we have proxy, should try to establish tunnel.
2862 MockWrite data_writes1[] = {
2863 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
2864 "Host: www.google.com\r\n"
2865 "Proxy-Connection: keep-alive\r\n\r\n"),
2866
2867 MockWrite("GET /1 HTTP/1.1\r\n"
2868 "Host: www.google.com\r\n"
2869 "Connection: keep-alive\r\n\r\n"),
2870
2871 MockWrite("GET /2 HTTP/1.1\r\n"
2872 "Host: www.google.com\r\n"
2873 "Connection: keep-alive\r\n\r\n"),
2874 };
2875
2876 // The proxy responds to the connect with a 407, using a persistent
2877 // connection.
2878 MockRead data_reads1[] = {
2879 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"),
2880
2881 MockRead("HTTP/1.1 200 OK\r\n"),
2882 MockRead("Content-Length: 1\r\n\r\n"),
2883 MockRead(SYNCHRONOUS, "1"),
2884
2885 MockRead("HTTP/1.1 200 OK\r\n"),
2886 MockRead("Content-Length: 2\r\n\r\n"),
2887 MockRead(SYNCHRONOUS, "22"),
2888 };
2889
2890 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
2891 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:072892 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]029c83b62013-01-24 05:28:202893 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]bb88e1d32013-05-03 23:11:072894 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]029c83b62013-01-24 05:28:202895
2896 TestCompletionCallback callback1;
[email protected]262eec82013-03-19 21:01:362897 scoped_ptr<HttpTransaction> trans1(
[email protected]90499482013-06-01 00:39:502898 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]029c83b62013-01-24 05:28:202899
2900 int rv = trans1->Start(&request1, callback1.callback(), log.bound());
2901 EXPECT_EQ(ERR_IO_PENDING, rv);
2902
2903 rv = callback1.WaitForResult();
2904 EXPECT_EQ(OK, rv);
2905
2906 const HttpResponseInfo* response1 = trans1->GetResponseInfo();
2907 ASSERT_TRUE(response1 != NULL);
[email protected]90499482013-06-01 00:39:502908 ASSERT_TRUE(response1->headers.get() != NULL);
[email protected]029c83b62013-01-24 05:28:202909 EXPECT_EQ(1, response1->headers->GetContentLength());
2910
2911 LoadTimingInfo load_timing_info1;
2912 EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1));
2913 TestLoadTimingNotReusedWithPac(load_timing_info1,
2914 CONNECT_TIMING_HAS_SSL_TIMES);
2915
2916 trans1.reset();
2917
2918 TestCompletionCallback callback2;
[email protected]262eec82013-03-19 21:01:362919 scoped_ptr<HttpTransaction> trans2(
[email protected]90499482013-06-01 00:39:502920 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]029c83b62013-01-24 05:28:202921
2922 rv = trans2->Start(&request2, callback2.callback(), log.bound());
2923 EXPECT_EQ(ERR_IO_PENDING, rv);
2924
2925 rv = callback2.WaitForResult();
2926 EXPECT_EQ(OK, rv);
2927
2928 const HttpResponseInfo* response2 = trans2->GetResponseInfo();
2929 ASSERT_TRUE(response2 != NULL);
[email protected]90499482013-06-01 00:39:502930 ASSERT_TRUE(response2->headers.get() != NULL);
[email protected]029c83b62013-01-24 05:28:202931 EXPECT_EQ(2, response2->headers->GetContentLength());
2932
2933 LoadTimingInfo load_timing_info2;
2934 EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2));
2935 TestLoadTimingReusedWithPac(load_timing_info2);
2936
2937 EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id);
2938
2939 trans2.reset();
2940 session->CloseAllConnections();
2941}
2942
[email protected]2df19bb2010-08-25 20:13:462943// Test a simple get through an HTTPS Proxy.
[email protected]23e482282013-06-14 16:08:022944TEST_P(HttpNetworkTransactionTest, HttpsProxyGet) {
[email protected]cb9bf6ca2011-01-28 13:15:272945 HttpRequestInfo request;
2946 request.method = "GET";
2947 request.url = GURL("http://www.google.com/");
2948
[email protected]2df19bb2010-08-25 20:13:462949 // Configure against https proxy server "proxy:70".
[email protected]bb88e1d32013-05-03 23:11:072950 session_deps_.proxy_service.reset(ProxyService::CreateFixed(
[email protected]3912662a32011-10-04 00:51:112951 "https://proxy:70"));
[email protected]333bdf62012-06-08 22:57:292952 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:072953 session_deps_.net_log = log.bound().net_log();
2954 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]2df19bb2010-08-25 20:13:462955
[email protected]2df19bb2010-08-25 20:13:462956 // Since we have proxy, should use full url
2957 MockWrite data_writes1[] = {
2958 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
2959 "Host: www.google.com\r\n"
2960 "Proxy-Connection: keep-alive\r\n\r\n"),
2961 };
2962
2963 MockRead data_reads1[] = {
2964 MockRead("HTTP/1.1 200 OK\r\n"),
2965 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
2966 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:062967 MockRead(SYNCHRONOUS, OK),
[email protected]2df19bb2010-08-25 20:13:462968 };
2969
2970 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
2971 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:072972 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]8ddf8322012-02-23 18:08:062973 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]bb88e1d32013-05-03 23:11:072974 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]2df19bb2010-08-25 20:13:462975
[email protected]49639fa2011-12-20 23:22:412976 TestCompletionCallback callback1;
[email protected]2df19bb2010-08-25 20:13:462977
[email protected]262eec82013-03-19 21:01:362978 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:502979 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0b0bf032010-09-21 18:08:502980
[email protected]49639fa2011-12-20 23:22:412981 int rv = trans->Start(&request, callback1.callback(), log.bound());
[email protected]2df19bb2010-08-25 20:13:462982 EXPECT_EQ(ERR_IO_PENDING, rv);
2983
2984 rv = callback1.WaitForResult();
2985 EXPECT_EQ(OK, rv);
2986
[email protected]58e32bb2013-01-21 18:23:252987 LoadTimingInfo load_timing_info;
2988 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
2989 TestLoadTimingNotReused(load_timing_info,
2990 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY);
2991
[email protected]2df19bb2010-08-25 20:13:462992 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:502993 ASSERT_TRUE(response != NULL);
[email protected]2df19bb2010-08-25 20:13:462994
2995 EXPECT_TRUE(response->headers->IsKeepAlive());
2996 EXPECT_EQ(200, response->headers->response_code());
2997 EXPECT_EQ(100, response->headers->GetContentLength());
2998 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
2999
3000 // The password prompt info should not be set.
3001 EXPECT_TRUE(response->auth_challenge.get() == NULL);
3002}
3003
[email protected]7642b5ae2010-09-01 20:55:173004// Test a SPDY get through an HTTPS Proxy.
[email protected]23e482282013-06-14 16:08:023005TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGet) {
[email protected]cb9bf6ca2011-01-28 13:15:273006 HttpRequestInfo request;
3007 request.method = "GET";
3008 request.url = GURL("http://www.google.com/");
3009 request.load_flags = 0;
3010
[email protected]7642b5ae2010-09-01 20:55:173011 // Configure against https proxy server "proxy:70".
[email protected]bb88e1d32013-05-03 23:11:073012 session_deps_.proxy_service.reset(ProxyService::CreateFixed(
[email protected]3912662a32011-10-04 00:51:113013 "https://proxy:70"));
[email protected]333bdf62012-06-08 22:57:293014 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:073015 session_deps_.net_log = log.bound().net_log();
3016 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]7642b5ae2010-09-01 20:55:173017
[email protected]7642b5ae2010-09-01 20:55:173018 // fetch http://www.google.com/ via SPDY
[email protected]cdf8f7e72013-05-23 10:56:463019 scoped_ptr<SpdyFrame> req(
3020 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false));
[email protected]7642b5ae2010-09-01 20:55:173021 MockWrite spdy_writes[] = { CreateMockWrite(*req) };
3022
[email protected]23e482282013-06-14 16:08:023023 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
3024 scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]7642b5ae2010-09-01 20:55:173025 MockRead spdy_reads[] = {
3026 CreateMockRead(*resp),
3027 CreateMockRead(*data),
[email protected]8ddf8322012-02-23 18:08:063028 MockRead(ASYNC, 0, 0),
[email protected]7642b5ae2010-09-01 20:55:173029 };
3030
[email protected]dd54bd82012-07-19 23:44:573031 DelayedSocketData spdy_data(
3032 1, // wait for one write to finish before reading.
3033 spdy_reads, arraysize(spdy_reads),
3034 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:073035 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]7642b5ae2010-09-01 20:55:173036
[email protected]8ddf8322012-02-23 18:08:063037 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:023038 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:073039 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]7642b5ae2010-09-01 20:55:173040
[email protected]49639fa2011-12-20 23:22:413041 TestCompletionCallback callback1;
[email protected]7642b5ae2010-09-01 20:55:173042
[email protected]262eec82013-03-19 21:01:363043 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:503044 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0b0bf032010-09-21 18:08:503045
[email protected]49639fa2011-12-20 23:22:413046 int rv = trans->Start(&request, callback1.callback(), log.bound());
[email protected]7642b5ae2010-09-01 20:55:173047 EXPECT_EQ(ERR_IO_PENDING, rv);
3048
3049 rv = callback1.WaitForResult();
3050 EXPECT_EQ(OK, rv);
3051
[email protected]58e32bb2013-01-21 18:23:253052 LoadTimingInfo load_timing_info;
3053 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
3054 TestLoadTimingNotReused(load_timing_info,
3055 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY);
3056
[email protected]7642b5ae2010-09-01 20:55:173057 const HttpResponseInfo* response = trans->GetResponseInfo();
3058 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:503059 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]7642b5ae2010-09-01 20:55:173060 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
3061
3062 std::string response_data;
3063 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
[email protected]448d4ca52012-03-04 04:12:233064 EXPECT_EQ(kUploadData, response_data);
[email protected]7642b5ae2010-09-01 20:55:173065}
3066
[email protected]1c173852014-06-19 12:51:503067// Verifies that a session which races and wins against the owning transaction
3068// (completing prior to host resolution), doesn't fail the transaction.
3069// Regression test for crbug.com/334413.
3070TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) {
3071 HttpRequestInfo request;
3072 request.method = "GET";
3073 request.url = GURL("http://www.google.com/");
3074 request.load_flags = 0;
3075
3076 // Configure SPDY proxy server "proxy:70".
3077 session_deps_.proxy_service.reset(
3078 ProxyService::CreateFixed("https://proxy:70"));
3079 CapturingBoundNetLog log;
3080 session_deps_.net_log = log.bound().net_log();
3081 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
3082
3083 // Fetch http://www.google.com/ through the SPDY proxy.
3084 scoped_ptr<SpdyFrame> req(
3085 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false));
3086 MockWrite spdy_writes[] = {CreateMockWrite(*req)};
3087
3088 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
3089 scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true));
3090 MockRead spdy_reads[] = {
3091 CreateMockRead(*resp), CreateMockRead(*data), MockRead(ASYNC, 0, 0),
3092 };
3093
3094 DelayedSocketData spdy_data(
3095 1, // wait for one write to finish before reading.
3096 spdy_reads,
3097 arraysize(spdy_reads),
3098 spdy_writes,
3099 arraysize(spdy_writes));
3100 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
3101
3102 SSLSocketDataProvider ssl(ASYNC, OK);
3103 ssl.SetNextProto(GetParam());
3104 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
3105
3106 TestCompletionCallback callback1;
3107
3108 scoped_ptr<HttpTransaction> trans(
3109 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
3110
3111 // Stall the hostname resolution begun by the transaction.
3112 session_deps_.host_resolver->set_synchronous_mode(false);
3113 session_deps_.host_resolver->set_ondemand_mode(true);
3114
3115 int rv = trans->Start(&request, callback1.callback(), log.bound());
3116 EXPECT_EQ(ERR_IO_PENDING, rv);
3117
3118 // Race a session to the proxy, which completes first.
3119 session_deps_.host_resolver->set_ondemand_mode(false);
3120 SpdySessionKey key(
3121 HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED);
3122 base::WeakPtr<SpdySession> spdy_session =
3123 CreateSecureSpdySession(session, key, log.bound());
3124
3125 // Unstall the resolution begun by the transaction.
3126 session_deps_.host_resolver->set_ondemand_mode(true);
3127 session_deps_.host_resolver->ResolveAllPending();
3128
3129 EXPECT_FALSE(callback1.have_result());
3130 rv = callback1.WaitForResult();
3131 EXPECT_EQ(OK, rv);
3132
3133 const HttpResponseInfo* response = trans->GetResponseInfo();
3134 ASSERT_TRUE(response != NULL);
3135 ASSERT_TRUE(response->headers.get() != NULL);
3136 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
3137
3138 std::string response_data;
3139 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
3140 EXPECT_EQ(kUploadData, response_data);
3141}
3142
[email protected]dc7bd1c52010-11-12 00:01:133143// Test a SPDY get through an HTTPS Proxy.
[email protected]23e482282013-06-14 16:08:023144TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) {
[email protected]cb9bf6ca2011-01-28 13:15:273145 HttpRequestInfo request;
3146 request.method = "GET";
3147 request.url = GURL("http://www.google.com/");
3148 request.load_flags = 0;
3149
[email protected]79cb5c12011-09-12 13:12:043150 // Configure against https proxy server "myproxy:70".
[email protected]bb88e1d32013-05-03 23:11:073151 session_deps_.proxy_service.reset(
[email protected]79cb5c12011-09-12 13:12:043152 ProxyService::CreateFixed("https://myproxy:70"));
[email protected]333bdf62012-06-08 22:57:293153 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:073154 session_deps_.net_log = log.bound().net_log();
3155 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]dc7bd1c52010-11-12 00:01:133156
[email protected]dc7bd1c52010-11-12 00:01:133157 // The first request will be a bare GET, the second request will be a
3158 // GET with a Proxy-Authorization header.
[email protected]ff98d7f02012-03-22 21:44:193159 scoped_ptr<SpdyFrame> req_get(
[email protected]cdf8f7e72013-05-23 10:56:463160 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false));
[email protected]dc7bd1c52010-11-12 00:01:133161 const char* const kExtraAuthorizationHeaders[] = {
[email protected]cdf8f7e72013-05-23 10:56:463162 "proxy-authorization", "Basic Zm9vOmJhcg=="
[email protected]dc7bd1c52010-11-12 00:01:133163 };
[email protected]ff98d7f02012-03-22 21:44:193164 scoped_ptr<SpdyFrame> req_get_authorization(
[email protected]cdf8f7e72013-05-23 10:56:463165 spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders,
3166 arraysize(kExtraAuthorizationHeaders) / 2,
3167 false,
3168 3,
3169 LOWEST,
3170 false));
[email protected]dc7bd1c52010-11-12 00:01:133171 MockWrite spdy_writes[] = {
3172 CreateMockWrite(*req_get, 1),
3173 CreateMockWrite(*req_get_authorization, 4),
3174 };
3175
3176 // The first response is a 407 proxy authentication challenge, and the second
3177 // response will be a 200 response since the second request includes a valid
3178 // Authorization header.
3179 const char* const kExtraAuthenticationHeaders[] = {
[email protected]cdf8f7e72013-05-23 10:56:463180 "proxy-authenticate", "Basic realm=\"MyRealm1\""
[email protected]dc7bd1c52010-11-12 00:01:133181 };
[email protected]ff98d7f02012-03-22 21:44:193182 scoped_ptr<SpdyFrame> resp_authentication(
[email protected]23e482282013-06-14 16:08:023183 spdy_util_.ConstructSpdySynReplyError(
[email protected]dc7bd1c52010-11-12 00:01:133184 "407 Proxy Authentication Required",
3185 kExtraAuthenticationHeaders, arraysize(kExtraAuthenticationHeaders)/2,
3186 1));
[email protected]ff98d7f02012-03-22 21:44:193187 scoped_ptr<SpdyFrame> body_authentication(
[email protected]23e482282013-06-14 16:08:023188 spdy_util_.ConstructSpdyBodyFrame(1, true));
3189 scoped_ptr<SpdyFrame> resp_data(
3190 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
3191 scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true));
[email protected]dc7bd1c52010-11-12 00:01:133192 MockRead spdy_reads[] = {
3193 CreateMockRead(*resp_authentication, 2),
3194 CreateMockRead(*body_authentication, 3),
3195 CreateMockRead(*resp_data, 5),
3196 CreateMockRead(*body_data, 6),
[email protected]8ddf8322012-02-23 18:08:063197 MockRead(ASYNC, 0, 7),
[email protected]dc7bd1c52010-11-12 00:01:133198 };
3199
[email protected]dd54bd82012-07-19 23:44:573200 OrderedSocketData data(
3201 spdy_reads, arraysize(spdy_reads),
3202 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:073203 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]dc7bd1c52010-11-12 00:01:133204
[email protected]8ddf8322012-02-23 18:08:063205 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:023206 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:073207 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]dc7bd1c52010-11-12 00:01:133208
[email protected]49639fa2011-12-20 23:22:413209 TestCompletionCallback callback1;
[email protected]dc7bd1c52010-11-12 00:01:133210
[email protected]262eec82013-03-19 21:01:363211 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:503212 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]dc7bd1c52010-11-12 00:01:133213
[email protected]49639fa2011-12-20 23:22:413214 int rv = trans->Start(&request, callback1.callback(), log.bound());
[email protected]dc7bd1c52010-11-12 00:01:133215 EXPECT_EQ(ERR_IO_PENDING, rv);
3216
3217 rv = callback1.WaitForResult();
3218 EXPECT_EQ(OK, rv);
3219
3220 const HttpResponseInfo* const response = trans->GetResponseInfo();
3221
3222 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:503223 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]dc7bd1c52010-11-12 00:01:133224 EXPECT_EQ(407, response->headers->response_code());
3225 EXPECT_TRUE(response->was_fetched_via_spdy);
[email protected]79cb5c12011-09-12 13:12:043226 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
[email protected]dc7bd1c52010-11-12 00:01:133227
[email protected]49639fa2011-12-20 23:22:413228 TestCompletionCallback callback2;
[email protected]dc7bd1c52010-11-12 00:01:133229
[email protected]49639fa2011-12-20 23:22:413230 rv = trans->RestartWithAuth(
3231 AuthCredentials(kFoo, kBar), callback2.callback());
[email protected]dc7bd1c52010-11-12 00:01:133232 EXPECT_EQ(ERR_IO_PENDING, rv);
3233
3234 rv = callback2.WaitForResult();
3235 EXPECT_EQ(OK, rv);
3236
3237 const HttpResponseInfo* const response_restart = trans->GetResponseInfo();
3238
3239 ASSERT_TRUE(response_restart != NULL);
[email protected]90499482013-06-01 00:39:503240 ASSERT_TRUE(response_restart->headers.get() != NULL);
[email protected]dc7bd1c52010-11-12 00:01:133241 EXPECT_EQ(200, response_restart->headers->response_code());
3242 // The password prompt info should not be set.
3243 EXPECT_TRUE(response_restart->auth_challenge.get() == NULL);
3244}
3245
[email protected]d9da5fe2010-10-13 22:37:163246// Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server.
[email protected]23e482282013-06-14 16:08:023247TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) {
[email protected]cb9bf6ca2011-01-28 13:15:273248 HttpRequestInfo request;
3249 request.method = "GET";
3250 request.url = GURL("https://www.google.com/");
3251 request.load_flags = 0;
3252
[email protected]d9da5fe2010-10-13 22:37:163253 // Configure against https proxy server "proxy:70".
[email protected]bb88e1d32013-05-03 23:11:073254 session_deps_.proxy_service.reset(ProxyService::CreateFixed(
[email protected]3912662a32011-10-04 00:51:113255 "https://proxy:70"));
[email protected]333bdf62012-06-08 22:57:293256 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:073257 session_deps_.net_log = log.bound().net_log();
3258 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]d9da5fe2010-10-13 22:37:163259
[email protected]262eec82013-03-19 21:01:363260 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:503261 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]d9da5fe2010-10-13 22:37:163262
[email protected]d9da5fe2010-10-13 22:37:163263 // CONNECT to www.google.com:443 via SPDY
[email protected]9075f51c2013-08-15 17:53:543264 scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(NULL, 0, 1,
3265 LOWEST));
[email protected]d9da5fe2010-10-13 22:37:163266 // fetch https://www.google.com/ via HTTP
3267
3268 const char get[] = "GET / HTTP/1.1\r\n"
3269 "Host: www.google.com\r\n"
3270 "Connection: keep-alive\r\n\r\n";
[email protected]ff98d7f02012-03-22 21:44:193271 scoped_ptr<SpdyFrame> wrapped_get(
[email protected]23e482282013-06-14 16:08:023272 spdy_util_.ConstructSpdyBodyFrame(1, get, strlen(get), false));
3273 scoped_ptr<SpdyFrame> conn_resp(
3274 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
[email protected]d9da5fe2010-10-13 22:37:163275 const char resp[] = "HTTP/1.1 200 OK\r\n"
3276 "Content-Length: 10\r\n\r\n";
[email protected]ff98d7f02012-03-22 21:44:193277 scoped_ptr<SpdyFrame> wrapped_get_resp(
[email protected]23e482282013-06-14 16:08:023278 spdy_util_.ConstructSpdyBodyFrame(1, resp, strlen(resp), false));
[email protected]ff98d7f02012-03-22 21:44:193279 scoped_ptr<SpdyFrame> wrapped_body(
[email protected]23e482282013-06-14 16:08:023280 spdy_util_.ConstructSpdyBodyFrame(1, "1234567890", 10, false));
[email protected]ff98d7f02012-03-22 21:44:193281 scoped_ptr<SpdyFrame> window_update(
[email protected]c10b20852013-05-15 21:29:203282 spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size()));
[email protected]8d2f7012012-02-16 00:08:043283
3284 MockWrite spdy_writes[] = {
3285 CreateMockWrite(*connect, 1),
3286 CreateMockWrite(*wrapped_get, 3),
[email protected]cdf8f7e72013-05-23 10:56:463287 CreateMockWrite(*window_update, 5),
[email protected]8d2f7012012-02-16 00:08:043288 };
3289
[email protected]d9da5fe2010-10-13 22:37:163290 MockRead spdy_reads[] = {
[email protected]8ddf8322012-02-23 18:08:063291 CreateMockRead(*conn_resp, 2, ASYNC),
3292 CreateMockRead(*wrapped_get_resp, 4, ASYNC),
3293 CreateMockRead(*wrapped_body, 6, ASYNC),
3294 CreateMockRead(*wrapped_body, 7, ASYNC),
3295 MockRead(ASYNC, 0, 8),
[email protected]d9da5fe2010-10-13 22:37:163296 };
3297
[email protected]dd54bd82012-07-19 23:44:573298 OrderedSocketData spdy_data(
3299 spdy_reads, arraysize(spdy_reads),
3300 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:073301 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]d9da5fe2010-10-13 22:37:163302
[email protected]8ddf8322012-02-23 18:08:063303 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:023304 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:073305 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]8ddf8322012-02-23 18:08:063306 SSLSocketDataProvider ssl2(ASYNC, OK);
[email protected]d9da5fe2010-10-13 22:37:163307 ssl2.was_npn_negotiated = false;
[email protected]8e3c78cb2012-03-31 03:58:463308 ssl2.protocol_negotiated = kProtoUnknown;
[email protected]bb88e1d32013-05-03 23:11:073309 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2);
[email protected]d9da5fe2010-10-13 22:37:163310
[email protected]49639fa2011-12-20 23:22:413311 TestCompletionCallback callback1;
[email protected]d9da5fe2010-10-13 22:37:163312
[email protected]49639fa2011-12-20 23:22:413313 int rv = trans->Start(&request, callback1.callback(), log.bound());
[email protected]d9da5fe2010-10-13 22:37:163314 EXPECT_EQ(ERR_IO_PENDING, rv);
3315
3316 rv = callback1.WaitForResult();
3317 EXPECT_EQ(OK, rv);
3318
[email protected]58e32bb2013-01-21 18:23:253319 LoadTimingInfo load_timing_info;
3320 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
3321 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES);
3322
[email protected]d9da5fe2010-10-13 22:37:163323 const HttpResponseInfo* response = trans->GetResponseInfo();
3324 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:503325 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]d9da5fe2010-10-13 22:37:163326 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
3327
3328 std::string response_data;
3329 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
3330 EXPECT_EQ("1234567890", response_data);
3331}
3332
3333// Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server.
[email protected]23e482282013-06-14 16:08:023334TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) {
[email protected]cb9bf6ca2011-01-28 13:15:273335 HttpRequestInfo request;
3336 request.method = "GET";
3337 request.url = GURL("https://www.google.com/");
3338 request.load_flags = 0;
3339
[email protected]d9da5fe2010-10-13 22:37:163340 // Configure against https proxy server "proxy:70".
[email protected]bb88e1d32013-05-03 23:11:073341 session_deps_.proxy_service.reset(ProxyService::CreateFixed(
[email protected]3912662a32011-10-04 00:51:113342 "https://proxy:70"));
[email protected]333bdf62012-06-08 22:57:293343 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:073344 session_deps_.net_log = log.bound().net_log();
3345 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]d9da5fe2010-10-13 22:37:163346
[email protected]262eec82013-03-19 21:01:363347 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:503348 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]d9da5fe2010-10-13 22:37:163349
[email protected]d9da5fe2010-10-13 22:37:163350 // CONNECT to www.google.com:443 via SPDY
[email protected]9075f51c2013-08-15 17:53:543351 scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(NULL, 0, 1,
3352 LOWEST));
[email protected]d9da5fe2010-10-13 22:37:163353 // fetch https://www.google.com/ via SPDY
3354 const char* const kMyUrl = "https://www.google.com/";
[email protected]cdf8f7e72013-05-23 10:56:463355 scoped_ptr<SpdyFrame> get(
3356 spdy_util_.ConstructSpdyGet(kMyUrl, false, 1, LOWEST));
[email protected]23e482282013-06-14 16:08:023357 scoped_ptr<SpdyFrame> wrapped_get(
3358 spdy_util_.ConstructWrappedSpdyFrame(get, 1));
3359 scoped_ptr<SpdyFrame> conn_resp(
3360 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
3361 scoped_ptr<SpdyFrame> get_resp(
3362 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
[email protected]ff98d7f02012-03-22 21:44:193363 scoped_ptr<SpdyFrame> wrapped_get_resp(
[email protected]23e482282013-06-14 16:08:023364 spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1));
3365 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
3366 scoped_ptr<SpdyFrame> wrapped_body(
3367 spdy_util_.ConstructWrappedSpdyFrame(body, 1));
[email protected]ff98d7f02012-03-22 21:44:193368 scoped_ptr<SpdyFrame> window_update_get_resp(
[email protected]c10b20852013-05-15 21:29:203369 spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size()));
[email protected]ff98d7f02012-03-22 21:44:193370 scoped_ptr<SpdyFrame> window_update_body(
[email protected]c10b20852013-05-15 21:29:203371 spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body->size()));
[email protected]8d2f7012012-02-16 00:08:043372
3373 MockWrite spdy_writes[] = {
3374 CreateMockWrite(*connect, 1),
3375 CreateMockWrite(*wrapped_get, 3),
3376 CreateMockWrite(*window_update_get_resp, 5),
3377 CreateMockWrite(*window_update_body, 7),
3378 };
3379
[email protected]d9da5fe2010-10-13 22:37:163380 MockRead spdy_reads[] = {
[email protected]8ddf8322012-02-23 18:08:063381 CreateMockRead(*conn_resp, 2, ASYNC),
3382 CreateMockRead(*wrapped_get_resp, 4, ASYNC),
3383 CreateMockRead(*wrapped_body, 6, ASYNC),
3384 MockRead(ASYNC, 0, 8),
[email protected]d9da5fe2010-10-13 22:37:163385 };
3386
[email protected]dd54bd82012-07-19 23:44:573387 OrderedSocketData spdy_data(
3388 spdy_reads, arraysize(spdy_reads),
3389 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:073390 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]d9da5fe2010-10-13 22:37:163391
[email protected]8ddf8322012-02-23 18:08:063392 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:023393 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:073394 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]8ddf8322012-02-23 18:08:063395 SSLSocketDataProvider ssl2(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:023396 ssl2.SetNextProto(GetParam());
3397 ssl2.protocol_negotiated = GetParam();
[email protected]bb88e1d32013-05-03 23:11:073398 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2);
[email protected]d9da5fe2010-10-13 22:37:163399
[email protected]49639fa2011-12-20 23:22:413400 TestCompletionCallback callback1;
[email protected]d9da5fe2010-10-13 22:37:163401
[email protected]49639fa2011-12-20 23:22:413402 int rv = trans->Start(&request, callback1.callback(), log.bound());
[email protected]d9da5fe2010-10-13 22:37:163403 EXPECT_EQ(ERR_IO_PENDING, rv);
3404
3405 rv = callback1.WaitForResult();
3406 EXPECT_EQ(OK, rv);
3407
[email protected]58e32bb2013-01-21 18:23:253408 LoadTimingInfo load_timing_info;
3409 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
3410 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES);
3411
[email protected]d9da5fe2010-10-13 22:37:163412 const HttpResponseInfo* response = trans->GetResponseInfo();
3413 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:503414 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]d9da5fe2010-10-13 22:37:163415 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
3416
3417 std::string response_data;
3418 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
[email protected]448d4ca52012-03-04 04:12:233419 EXPECT_EQ(kUploadData, response_data);
[email protected]d9da5fe2010-10-13 22:37:163420}
3421
3422// Test a SPDY CONNECT failure through an HTTPS Proxy.
[email protected]23e482282013-06-14 16:08:023423TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) {
[email protected]cb9bf6ca2011-01-28 13:15:273424 HttpRequestInfo request;
3425 request.method = "GET";
3426 request.url = GURL("https://www.google.com/");
3427 request.load_flags = 0;
3428
[email protected]d9da5fe2010-10-13 22:37:163429 // Configure against https proxy server "proxy:70".
[email protected]bb88e1d32013-05-03 23:11:073430 session_deps_.proxy_service.reset(ProxyService::CreateFixed(
[email protected]3912662a32011-10-04 00:51:113431 "https://proxy:70"));
[email protected]333bdf62012-06-08 22:57:293432 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:073433 session_deps_.net_log = log.bound().net_log();
3434 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]d9da5fe2010-10-13 22:37:163435
[email protected]262eec82013-03-19 21:01:363436 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:503437 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]d9da5fe2010-10-13 22:37:163438
[email protected]d9da5fe2010-10-13 22:37:163439 // CONNECT to www.google.com:443 via SPDY
[email protected]9075f51c2013-08-15 17:53:543440 scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(NULL, 0, 1,
3441 LOWEST));
[email protected]c10b20852013-05-15 21:29:203442 scoped_ptr<SpdyFrame> get(
3443 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL));
[email protected]d9da5fe2010-10-13 22:37:163444
3445 MockWrite spdy_writes[] = {
3446 CreateMockWrite(*connect, 1),
3447 CreateMockWrite(*get, 3),
3448 };
3449
[email protected]23e482282013-06-14 16:08:023450 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdySynReplyError(1));
3451 scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]d9da5fe2010-10-13 22:37:163452 MockRead spdy_reads[] = {
[email protected]8ddf8322012-02-23 18:08:063453 CreateMockRead(*resp, 2, ASYNC),
3454 MockRead(ASYNC, 0, 4),
[email protected]d9da5fe2010-10-13 22:37:163455 };
3456
[email protected]dd54bd82012-07-19 23:44:573457 OrderedSocketData spdy_data(
3458 spdy_reads, arraysize(spdy_reads),
3459 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:073460 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]d9da5fe2010-10-13 22:37:163461
[email protected]8ddf8322012-02-23 18:08:063462 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:023463 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:073464 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]8ddf8322012-02-23 18:08:063465 SSLSocketDataProvider ssl2(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:023466 ssl2.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:073467 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2);
[email protected]d9da5fe2010-10-13 22:37:163468
[email protected]49639fa2011-12-20 23:22:413469 TestCompletionCallback callback1;
[email protected]d9da5fe2010-10-13 22:37:163470
[email protected]49639fa2011-12-20 23:22:413471 int rv = trans->Start(&request, callback1.callback(), log.bound());
[email protected]d9da5fe2010-10-13 22:37:163472 EXPECT_EQ(ERR_IO_PENDING, rv);
3473
3474 rv = callback1.WaitForResult();
[email protected]4eddbc732012-08-09 05:40:173475 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv);
[email protected]d9da5fe2010-10-13 22:37:163476
[email protected]4eddbc732012-08-09 05:40:173477 // TODO(ttuttle): Anything else to check here?
[email protected]d9da5fe2010-10-13 22:37:163478}
3479
[email protected]f6c63db52013-02-02 00:35:223480// Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY
3481// HTTPS Proxy to different servers.
[email protected]23e482282013-06-14 16:08:023482TEST_P(HttpNetworkTransactionTest,
[email protected]f6c63db52013-02-02 00:35:223483 HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) {
3484 // Configure against https proxy server "proxy:70".
[email protected]bb88e1d32013-05-03 23:11:073485 session_deps_.proxy_service.reset(ProxyService::CreateFixed(
[email protected]f6c63db52013-02-02 00:35:223486 "https://proxy:70"));
3487 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:073488 session_deps_.net_log = log.bound().net_log();
[email protected]f6c63db52013-02-02 00:35:223489 scoped_refptr<HttpNetworkSession> session(
[email protected]bb88e1d32013-05-03 23:11:073490 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_));
[email protected]f6c63db52013-02-02 00:35:223491
3492 HttpRequestInfo request1;
3493 request1.method = "GET";
3494 request1.url = GURL("https://www.google.com/");
3495 request1.load_flags = 0;
3496
3497 HttpRequestInfo request2;
3498 request2.method = "GET";
3499 request2.url = GURL("https://news.google.com/");
3500 request2.load_flags = 0;
3501
3502 // CONNECT to www.google.com:443 via SPDY.
[email protected]9075f51c2013-08-15 17:53:543503 scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect(NULL, 0, 1,
3504 LOWEST));
[email protected]23e482282013-06-14 16:08:023505 scoped_ptr<SpdyFrame> conn_resp1(
3506 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
[email protected]f6c63db52013-02-02 00:35:223507
3508 // Fetch https://www.google.com/ via HTTP.
3509 const char get1[] = "GET / HTTP/1.1\r\n"
3510 "Host: www.google.com\r\n"
3511 "Connection: keep-alive\r\n\r\n";
3512 scoped_ptr<SpdyFrame> wrapped_get1(
[email protected]23e482282013-06-14 16:08:023513 spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false));
[email protected]f6c63db52013-02-02 00:35:223514 const char resp1[] = "HTTP/1.1 200 OK\r\n"
3515 "Content-Length: 1\r\n\r\n";
3516 scoped_ptr<SpdyFrame> wrapped_get_resp1(
[email protected]23e482282013-06-14 16:08:023517 spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false));
3518 scoped_ptr<SpdyFrame> wrapped_body1(
3519 spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false));
[email protected]f6c63db52013-02-02 00:35:223520 scoped_ptr<SpdyFrame> window_update(
[email protected]c10b20852013-05-15 21:29:203521 spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size()));
[email protected]f6c63db52013-02-02 00:35:223522
3523 // CONNECT to news.google.com:443 via SPDY.
[email protected]745aa9c2014-06-27 02:21:293524 SpdyHeaderBlock connect2_block;
3525 connect2_block[spdy_util_.GetMethodKey()] = "CONNECT";
3526 connect2_block[spdy_util_.GetPathKey()] = "news.google.com:443";
3527 connect2_block[spdy_util_.GetHostKey()] = "news.google.com";
3528 spdy_util_.MaybeAddVersionHeader(&connect2_block);
[email protected]f6c63db52013-02-02 00:35:223529 scoped_ptr<SpdyFrame> connect2(
[email protected]745aa9c2014-06-27 02:21:293530 spdy_util_.ConstructSpdySyn(3, connect2_block, LOWEST, false, false));
[email protected]601e03f12014-04-06 16:26:393531
[email protected]23e482282013-06-14 16:08:023532 scoped_ptr<SpdyFrame> conn_resp2(
3533 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
[email protected]f6c63db52013-02-02 00:35:223534
3535 // Fetch https://news.google.com/ via HTTP.
3536 const char get2[] = "GET / HTTP/1.1\r\n"
3537 "Host: news.google.com\r\n"
3538 "Connection: keep-alive\r\n\r\n";
3539 scoped_ptr<SpdyFrame> wrapped_get2(
[email protected]23e482282013-06-14 16:08:023540 spdy_util_.ConstructSpdyBodyFrame(3, get2, strlen(get2), false));
[email protected]f6c63db52013-02-02 00:35:223541 const char resp2[] = "HTTP/1.1 200 OK\r\n"
3542 "Content-Length: 2\r\n\r\n";
3543 scoped_ptr<SpdyFrame> wrapped_get_resp2(
[email protected]23e482282013-06-14 16:08:023544 spdy_util_.ConstructSpdyBodyFrame(3, resp2, strlen(resp2), false));
[email protected]f6c63db52013-02-02 00:35:223545 scoped_ptr<SpdyFrame> wrapped_body2(
[email protected]23e482282013-06-14 16:08:023546 spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, false));
[email protected]f6c63db52013-02-02 00:35:223547
3548 MockWrite spdy_writes[] = {
3549 CreateMockWrite(*connect1, 0),
3550 CreateMockWrite(*wrapped_get1, 2),
3551 CreateMockWrite(*connect2, 5),
3552 CreateMockWrite(*wrapped_get2, 7),
3553 };
3554
3555 MockRead spdy_reads[] = {
3556 CreateMockRead(*conn_resp1, 1, ASYNC),
3557 CreateMockRead(*wrapped_get_resp1, 3, ASYNC),
3558 CreateMockRead(*wrapped_body1, 4, ASYNC),
3559 CreateMockRead(*conn_resp2, 6, ASYNC),
3560 CreateMockRead(*wrapped_get_resp2, 8, ASYNC),
3561 CreateMockRead(*wrapped_body2, 9, ASYNC),
3562 MockRead(ASYNC, 0, 10),
3563 };
3564
3565 DeterministicSocketData spdy_data(
3566 spdy_reads, arraysize(spdy_reads),
3567 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:073568 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]f6c63db52013-02-02 00:35:223569
3570 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:023571 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:073572 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]f6c63db52013-02-02 00:35:223573 SSLSocketDataProvider ssl2(ASYNC, OK);
3574 ssl2.was_npn_negotiated = false;
3575 ssl2.protocol_negotiated = kProtoUnknown;
[email protected]bb88e1d32013-05-03 23:11:073576 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2);
[email protected]f6c63db52013-02-02 00:35:223577 SSLSocketDataProvider ssl3(ASYNC, OK);
3578 ssl3.was_npn_negotiated = false;
3579 ssl3.protocol_negotiated = kProtoUnknown;
[email protected]bb88e1d32013-05-03 23:11:073580 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl3);
[email protected]f6c63db52013-02-02 00:35:223581
3582 TestCompletionCallback callback;
3583
[email protected]262eec82013-03-19 21:01:363584 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:503585 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]f6c63db52013-02-02 00:35:223586 int rv = trans->Start(&request1, callback.callback(), BoundNetLog());
3587 EXPECT_EQ(ERR_IO_PENDING, rv);
3588 // The first connect and request, each of their responses, and the body.
3589 spdy_data.RunFor(5);
3590
3591 rv = callback.WaitForResult();
3592 EXPECT_EQ(OK, rv);
3593
3594 LoadTimingInfo load_timing_info;
3595 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
3596 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES);
3597
3598 const HttpResponseInfo* response = trans->GetResponseInfo();
3599 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:503600 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]f6c63db52013-02-02 00:35:223601 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
3602
3603 std::string response_data;
3604 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256));
[email protected]90499482013-06-01 00:39:503605 EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback()));
[email protected]f6c63db52013-02-02 00:35:223606
[email protected]262eec82013-03-19 21:01:363607 scoped_ptr<HttpTransaction> trans2(
[email protected]90499482013-06-01 00:39:503608 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]f6c63db52013-02-02 00:35:223609 rv = trans2->Start(&request2, callback.callback(), BoundNetLog());
3610 EXPECT_EQ(ERR_IO_PENDING, rv);
3611
3612 // The second connect and request, each of their responses, and the body.
3613 spdy_data.RunFor(5);
3614 rv = callback.WaitForResult();
3615 EXPECT_EQ(OK, rv);
3616
3617 LoadTimingInfo load_timing_info2;
3618 EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2));
3619 // Even though the SPDY connection is reused, a new tunnelled connection has
3620 // to be created, so the socket's load timing looks like a fresh connection.
3621 TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES);
3622
3623 // The requests should have different IDs, since they each are using their own
3624 // separate stream.
3625 EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id);
3626
[email protected]90499482013-06-01 00:39:503627 EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback()));
[email protected]f6c63db52013-02-02 00:35:223628}
3629
3630// Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY
3631// HTTPS Proxy to the same server.
[email protected]23e482282013-06-14 16:08:023632TEST_P(HttpNetworkTransactionTest,
[email protected]f6c63db52013-02-02 00:35:223633 HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) {
3634 // Configure against https proxy server "proxy:70".
[email protected]bb88e1d32013-05-03 23:11:073635 session_deps_.proxy_service.reset(ProxyService::CreateFixed(
[email protected]f6c63db52013-02-02 00:35:223636 "https://proxy:70"));
3637 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:073638 session_deps_.net_log = log.bound().net_log();
[email protected]f6c63db52013-02-02 00:35:223639 scoped_refptr<HttpNetworkSession> session(
[email protected]bb88e1d32013-05-03 23:11:073640 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_));
[email protected]f6c63db52013-02-02 00:35:223641
3642 HttpRequestInfo request1;
3643 request1.method = "GET";
3644 request1.url = GURL("https://www.google.com/");
3645 request1.load_flags = 0;
3646
3647 HttpRequestInfo request2;
3648 request2.method = "GET";
3649 request2.url = GURL("https://www.google.com/2");
3650 request2.load_flags = 0;
3651
3652 // CONNECT to www.google.com:443 via SPDY.
[email protected]9075f51c2013-08-15 17:53:543653 scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect(NULL, 0, 1,
3654 LOWEST));
[email protected]23e482282013-06-14 16:08:023655 scoped_ptr<SpdyFrame> conn_resp1(
3656 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
[email protected]f6c63db52013-02-02 00:35:223657
3658 // Fetch https://www.google.com/ via HTTP.
3659 const char get1[] = "GET / HTTP/1.1\r\n"
3660 "Host: www.google.com\r\n"
3661 "Connection: keep-alive\r\n\r\n";
3662 scoped_ptr<SpdyFrame> wrapped_get1(
[email protected]23e482282013-06-14 16:08:023663 spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false));
[email protected]f6c63db52013-02-02 00:35:223664 const char resp1[] = "HTTP/1.1 200 OK\r\n"
3665 "Content-Length: 1\r\n\r\n";
3666 scoped_ptr<SpdyFrame> wrapped_get_resp1(
[email protected]23e482282013-06-14 16:08:023667 spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false));
3668 scoped_ptr<SpdyFrame> wrapped_body1(
3669 spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false));
[email protected]f6c63db52013-02-02 00:35:223670 scoped_ptr<SpdyFrame> window_update(
[email protected]c10b20852013-05-15 21:29:203671 spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size()));
[email protected]f6c63db52013-02-02 00:35:223672
3673 // Fetch https://www.google.com/2 via HTTP.
3674 const char get2[] = "GET /2 HTTP/1.1\r\n"
3675 "Host: www.google.com\r\n"
3676 "Connection: keep-alive\r\n\r\n";
3677 scoped_ptr<SpdyFrame> wrapped_get2(
[email protected]23e482282013-06-14 16:08:023678 spdy_util_.ConstructSpdyBodyFrame(1, get2, strlen(get2), false));
[email protected]f6c63db52013-02-02 00:35:223679 const char resp2[] = "HTTP/1.1 200 OK\r\n"
3680 "Content-Length: 2\r\n\r\n";
3681 scoped_ptr<SpdyFrame> wrapped_get_resp2(
[email protected]23e482282013-06-14 16:08:023682 spdy_util_.ConstructSpdyBodyFrame(1, resp2, strlen(resp2), false));
[email protected]f6c63db52013-02-02 00:35:223683 scoped_ptr<SpdyFrame> wrapped_body2(
[email protected]23e482282013-06-14 16:08:023684 spdy_util_.ConstructSpdyBodyFrame(1, "22", 2, false));
[email protected]f6c63db52013-02-02 00:35:223685
3686 MockWrite spdy_writes[] = {
3687 CreateMockWrite(*connect1, 0),
3688 CreateMockWrite(*wrapped_get1, 2),
3689 CreateMockWrite(*wrapped_get2, 5),
3690 };
3691
3692 MockRead spdy_reads[] = {
3693 CreateMockRead(*conn_resp1, 1, ASYNC),
3694 CreateMockRead(*wrapped_get_resp1, 3, ASYNC),
3695 CreateMockRead(*wrapped_body1, 4, ASYNC),
3696 CreateMockRead(*wrapped_get_resp2, 6, ASYNC),
3697 CreateMockRead(*wrapped_body2, 7, ASYNC),
3698 MockRead(ASYNC, 0, 8),
3699 };
3700
3701 DeterministicSocketData spdy_data(
3702 spdy_reads, arraysize(spdy_reads),
3703 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:073704 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]f6c63db52013-02-02 00:35:223705
3706 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:023707 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:073708 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]f6c63db52013-02-02 00:35:223709 SSLSocketDataProvider ssl2(ASYNC, OK);
3710 ssl2.was_npn_negotiated = false;
3711 ssl2.protocol_negotiated = kProtoUnknown;
[email protected]bb88e1d32013-05-03 23:11:073712 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2);
[email protected]f6c63db52013-02-02 00:35:223713
3714 TestCompletionCallback callback;
3715
[email protected]262eec82013-03-19 21:01:363716 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:503717 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]f6c63db52013-02-02 00:35:223718 int rv = trans->Start(&request1, callback.callback(), BoundNetLog());
3719 EXPECT_EQ(ERR_IO_PENDING, rv);
3720 // The first connect and request, each of their responses, and the body.
3721 spdy_data.RunFor(5);
3722
3723 rv = callback.WaitForResult();
3724 EXPECT_EQ(OK, rv);
3725
3726 LoadTimingInfo load_timing_info;
3727 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
3728 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES);
3729
3730 const HttpResponseInfo* response = trans->GetResponseInfo();
3731 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:503732 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]f6c63db52013-02-02 00:35:223733 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
3734
3735 std::string response_data;
3736 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256));
[email protected]90499482013-06-01 00:39:503737 EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback()));
[email protected]f6c63db52013-02-02 00:35:223738 trans.reset();
3739
[email protected]262eec82013-03-19 21:01:363740 scoped_ptr<HttpTransaction> trans2(
[email protected]90499482013-06-01 00:39:503741 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]f6c63db52013-02-02 00:35:223742 rv = trans2->Start(&request2, callback.callback(), BoundNetLog());
3743 EXPECT_EQ(ERR_IO_PENDING, rv);
3744
3745 // The second request, response, and body. There should not be a second
3746 // connect.
3747 spdy_data.RunFor(3);
3748 rv = callback.WaitForResult();
3749 EXPECT_EQ(OK, rv);
3750
3751 LoadTimingInfo load_timing_info2;
3752 EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2));
3753 TestLoadTimingReused(load_timing_info2);
3754
3755 // The requests should have the same ID.
3756 EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id);
3757
[email protected]90499482013-06-01 00:39:503758 EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback()));
[email protected]f6c63db52013-02-02 00:35:223759}
3760
3761// Test load timing in the case of of two HTTP requests through a SPDY HTTPS
3762// Proxy to different servers.
[email protected]23e482282013-06-14 16:08:023763TEST_P(HttpNetworkTransactionTest,
[email protected]f6c63db52013-02-02 00:35:223764 HttpsProxySpdyLoadTimingTwoHttpRequests) {
3765 // Configure against https proxy server "proxy:70".
[email protected]bb88e1d32013-05-03 23:11:073766 session_deps_.proxy_service.reset(ProxyService::CreateFixed(
[email protected]f6c63db52013-02-02 00:35:223767 "https://proxy:70"));
3768 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:073769 session_deps_.net_log = log.bound().net_log();
[email protected]f6c63db52013-02-02 00:35:223770 scoped_refptr<HttpNetworkSession> session(
[email protected]bb88e1d32013-05-03 23:11:073771 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_));
[email protected]f6c63db52013-02-02 00:35:223772
3773 HttpRequestInfo request1;
3774 request1.method = "GET";
3775 request1.url = GURL("http://www.google.com/");
3776 request1.load_flags = 0;
3777
3778 HttpRequestInfo request2;
3779 request2.method = "GET";
3780 request2.url = GURL("http://news.google.com/");
3781 request2.load_flags = 0;
3782
3783 // http://www.google.com/
[email protected]23e482282013-06-14 16:08:023784 scoped_ptr<SpdyHeaderBlock> headers(
3785 spdy_util_.ConstructGetHeaderBlockForProxy("http://www.google.com/"));
[email protected]745aa9c2014-06-27 02:21:293786 scoped_ptr<SpdyFrame> get1(
3787 spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true));
[email protected]23e482282013-06-14 16:08:023788 scoped_ptr<SpdyFrame> get_resp1(
3789 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
3790 scoped_ptr<SpdyFrame> body1(
3791 spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, true));
[email protected]f6c63db52013-02-02 00:35:223792
3793 // http://news.google.com/
[email protected]23e482282013-06-14 16:08:023794 scoped_ptr<SpdyHeaderBlock> headers2(
3795 spdy_util_.ConstructGetHeaderBlockForProxy("http://news.google.com/"));
[email protected]745aa9c2014-06-27 02:21:293796 scoped_ptr<SpdyFrame> get2(
3797 spdy_util_.ConstructSpdySyn(3, *headers2, LOWEST, false, true));
[email protected]23e482282013-06-14 16:08:023798 scoped_ptr<SpdyFrame> get_resp2(
3799 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
3800 scoped_ptr<SpdyFrame> body2(
3801 spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, true));
[email protected]f6c63db52013-02-02 00:35:223802
3803 MockWrite spdy_writes[] = {
3804 CreateMockWrite(*get1, 0),
3805 CreateMockWrite(*get2, 3),
3806 };
3807
3808 MockRead spdy_reads[] = {
3809 CreateMockRead(*get_resp1, 1, ASYNC),
3810 CreateMockRead(*body1, 2, ASYNC),
3811 CreateMockRead(*get_resp2, 4, ASYNC),
3812 CreateMockRead(*body2, 5, ASYNC),
3813 MockRead(ASYNC, 0, 6),
3814 };
3815
3816 DeterministicSocketData spdy_data(
3817 spdy_reads, arraysize(spdy_reads),
3818 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:073819 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]f6c63db52013-02-02 00:35:223820
3821 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:023822 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:073823 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]f6c63db52013-02-02 00:35:223824
3825 TestCompletionCallback callback;
3826
[email protected]262eec82013-03-19 21:01:363827 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:503828 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]f6c63db52013-02-02 00:35:223829 int rv = trans->Start(&request1, callback.callback(), BoundNetLog());
3830 EXPECT_EQ(ERR_IO_PENDING, rv);
3831 spdy_data.RunFor(2);
3832
3833 rv = callback.WaitForResult();
3834 EXPECT_EQ(OK, rv);
3835
3836 LoadTimingInfo load_timing_info;
3837 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
3838 TestLoadTimingNotReused(load_timing_info,
3839 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY);
3840
3841 const HttpResponseInfo* response = trans->GetResponseInfo();
3842 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:503843 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]f6c63db52013-02-02 00:35:223844 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
3845
3846 std::string response_data;
3847 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256));
[email protected]90499482013-06-01 00:39:503848 EXPECT_EQ(ERR_IO_PENDING, trans->Read(buf.get(), 256, callback.callback()));
[email protected]f6c63db52013-02-02 00:35:223849 spdy_data.RunFor(1);
3850 EXPECT_EQ(1, callback.WaitForResult());
3851 // Delete the first request, so the second one can reuse the socket.
3852 trans.reset();
3853
[email protected]262eec82013-03-19 21:01:363854 scoped_ptr<HttpTransaction> trans2(
[email protected]90499482013-06-01 00:39:503855 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]f6c63db52013-02-02 00:35:223856 rv = trans2->Start(&request2, callback.callback(), BoundNetLog());
3857 EXPECT_EQ(ERR_IO_PENDING, rv);
3858
3859 spdy_data.RunFor(2);
3860 rv = callback.WaitForResult();
3861 EXPECT_EQ(OK, rv);
3862
3863 LoadTimingInfo load_timing_info2;
3864 EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2));
3865 TestLoadTimingReused(load_timing_info2);
3866
3867 // The requests should have the same ID.
3868 EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id);
3869
[email protected]90499482013-06-01 00:39:503870 EXPECT_EQ(ERR_IO_PENDING, trans2->Read(buf.get(), 256, callback.callback()));
[email protected]f6c63db52013-02-02 00:35:223871 spdy_data.RunFor(1);
3872 EXPECT_EQ(2, callback.WaitForResult());
3873}
3874
[email protected]2df19bb2010-08-25 20:13:463875// Test the challenge-response-retry sequence through an HTTPS Proxy
[email protected]23e482282013-06-14 16:08:023876TEST_P(HttpNetworkTransactionTest, HttpsProxyAuthRetry) {
[email protected]2df19bb2010-08-25 20:13:463877 HttpRequestInfo request;
3878 request.method = "GET";
3879 request.url = GURL("http://www.google.com/");
3880 // when the no authentication data flag is set.
3881 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA;
3882
[email protected]79cb5c12011-09-12 13:12:043883 // Configure against https proxy server "myproxy:70".
[email protected]bb88e1d32013-05-03 23:11:073884 session_deps_.proxy_service.reset(
[email protected]79cb5c12011-09-12 13:12:043885 ProxyService::CreateFixed("https://myproxy:70"));
[email protected]333bdf62012-06-08 22:57:293886 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:073887 session_deps_.net_log = log.bound().net_log();
3888 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:273889
[email protected]2df19bb2010-08-25 20:13:463890 // Since we have proxy, should use full url
3891 MockWrite data_writes1[] = {
3892 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
3893 "Host: www.google.com\r\n"
3894 "Proxy-Connection: keep-alive\r\n\r\n"),
3895
3896 // After calling trans->RestartWithAuth(), this is the request we should
3897 // be issuing -- the final header line contains the credentials.
3898 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
3899 "Host: www.google.com\r\n"
3900 "Proxy-Connection: keep-alive\r\n"
3901 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
3902 };
3903
3904 // The proxy responds to the GET with a 407, using a persistent
3905 // connection.
3906 MockRead data_reads1[] = {
3907 // No credentials.
3908 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
3909 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
3910 MockRead("Proxy-Connection: keep-alive\r\n"),
3911 MockRead("Content-Length: 0\r\n\r\n"),
3912
3913 MockRead("HTTP/1.1 200 OK\r\n"),
3914 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
3915 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:063916 MockRead(SYNCHRONOUS, OK),
[email protected]2df19bb2010-08-25 20:13:463917 };
3918
3919 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
3920 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:073921 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]8ddf8322012-02-23 18:08:063922 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]bb88e1d32013-05-03 23:11:073923 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]2df19bb2010-08-25 20:13:463924
[email protected]49639fa2011-12-20 23:22:413925 TestCompletionCallback callback1;
[email protected]2df19bb2010-08-25 20:13:463926
[email protected]262eec82013-03-19 21:01:363927 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:503928 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0b0bf032010-09-21 18:08:503929
[email protected]49639fa2011-12-20 23:22:413930 int rv = trans->Start(&request, callback1.callback(), log.bound());
[email protected]2df19bb2010-08-25 20:13:463931 EXPECT_EQ(ERR_IO_PENDING, rv);
3932
3933 rv = callback1.WaitForResult();
3934 EXPECT_EQ(OK, rv);
3935
[email protected]58e32bb2013-01-21 18:23:253936 LoadTimingInfo load_timing_info;
3937 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
3938 TestLoadTimingNotReused(load_timing_info,
3939 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY);
3940
[email protected]2df19bb2010-08-25 20:13:463941 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:503942 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:503943 ASSERT_FALSE(response->headers.get() == NULL);
[email protected]2df19bb2010-08-25 20:13:463944 EXPECT_EQ(407, response->headers->response_code());
3945 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
[email protected]79cb5c12011-09-12 13:12:043946 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
[email protected]2df19bb2010-08-25 20:13:463947
[email protected]49639fa2011-12-20 23:22:413948 TestCompletionCallback callback2;
[email protected]2df19bb2010-08-25 20:13:463949
[email protected]49639fa2011-12-20 23:22:413950 rv = trans->RestartWithAuth(
3951 AuthCredentials(kFoo, kBar), callback2.callback());
[email protected]2df19bb2010-08-25 20:13:463952 EXPECT_EQ(ERR_IO_PENDING, rv);
3953
3954 rv = callback2.WaitForResult();
3955 EXPECT_EQ(OK, rv);
3956
[email protected]58e32bb2013-01-21 18:23:253957 load_timing_info = LoadTimingInfo();
3958 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
3959 // Retrying with HTTP AUTH is considered to be reusing a socket.
3960 TestLoadTimingReused(load_timing_info);
3961
[email protected]2df19bb2010-08-25 20:13:463962 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:503963 ASSERT_TRUE(response != NULL);
[email protected]2df19bb2010-08-25 20:13:463964
3965 EXPECT_TRUE(response->headers->IsKeepAlive());
3966 EXPECT_EQ(200, response->headers->response_code());
3967 EXPECT_EQ(100, response->headers->GetContentLength());
3968 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
3969
3970 // The password prompt info should not be set.
3971 EXPECT_TRUE(response->auth_challenge.get() == NULL);
3972}
3973
[email protected]23e482282013-06-14 16:08:023974void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus(
[email protected]c744cf22009-02-27 07:28:083975 const MockRead& status, int expected_status) {
[email protected]1c773ea12009-04-28 19:58:423976 HttpRequestInfo request;
[email protected]c744cf22009-02-27 07:28:083977 request.method = "GET";
3978 request.url = GURL("https://www.google.com/");
3979 request.load_flags = 0;
3980
[email protected]cb9bf6ca2011-01-28 13:15:273981 // Configure against proxy server "myproxy:70".
[email protected]bb88e1d32013-05-03 23:11:073982 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70"));
[email protected]bb88e1d32013-05-03 23:11:073983 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:273984
[email protected]c744cf22009-02-27 07:28:083985 // Since we have proxy, should try to establish tunnel.
3986 MockWrite data_writes[] = {
3987 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
[email protected]e44de5d2009-06-05 20:12:453988 "Host: www.google.com\r\n"
3989 "Proxy-Connection: keep-alive\r\n\r\n"),
[email protected]c744cf22009-02-27 07:28:083990 };
3991
3992 MockRead data_reads[] = {
3993 status,
3994 MockRead("Content-Length: 10\r\n\r\n"),
3995 // No response body because the test stops reading here.
[email protected]8ddf8322012-02-23 18:08:063996 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached.
[email protected]c744cf22009-02-27 07:28:083997 };
3998
[email protected]31a2bfe2010-02-09 08:03:393999 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
4000 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:074001 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]c744cf22009-02-27 07:28:084002
[email protected]49639fa2011-12-20 23:22:414003 TestCompletionCallback callback;
[email protected]c744cf22009-02-27 07:28:084004
[email protected]262eec82013-03-19 21:01:364005 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:504006 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0b0bf032010-09-21 18:08:504007
[email protected]49639fa2011-12-20 23:22:414008 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:424009 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]c744cf22009-02-27 07:28:084010
4011 rv = callback.WaitForResult();
4012 EXPECT_EQ(expected_status, rv);
4013}
4014
[email protected]23e482282013-06-14 16:08:024015void HttpNetworkTransactionTest::ConnectStatusHelper(
[email protected]448d4ca52012-03-04 04:12:234016 const MockRead& status) {
[email protected]c744cf22009-02-27 07:28:084017 ConnectStatusHelperWithExpectedStatus(
[email protected]1c773ea12009-04-28 19:58:424018 status, ERR_TUNNEL_CONNECTION_FAILED);
[email protected]c744cf22009-02-27 07:28:084019}
4020
[email protected]23e482282013-06-14 16:08:024021TEST_P(HttpNetworkTransactionTest, ConnectStatus100) {
[email protected]c744cf22009-02-27 07:28:084022 ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n"));
4023}
4024
[email protected]23e482282013-06-14 16:08:024025TEST_P(HttpNetworkTransactionTest, ConnectStatus101) {
[email protected]c744cf22009-02-27 07:28:084026 ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n"));
4027}
4028
[email protected]23e482282013-06-14 16:08:024029TEST_P(HttpNetworkTransactionTest, ConnectStatus201) {
[email protected]c744cf22009-02-27 07:28:084030 ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n"));
4031}
4032
[email protected]23e482282013-06-14 16:08:024033TEST_P(HttpNetworkTransactionTest, ConnectStatus202) {
[email protected]c744cf22009-02-27 07:28:084034 ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n"));
4035}
4036
[email protected]23e482282013-06-14 16:08:024037TEST_P(HttpNetworkTransactionTest, ConnectStatus203) {
[email protected]c744cf22009-02-27 07:28:084038 ConnectStatusHelper(
4039 MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n"));
4040}
4041
[email protected]23e482282013-06-14 16:08:024042TEST_P(HttpNetworkTransactionTest, ConnectStatus204) {
[email protected]c744cf22009-02-27 07:28:084043 ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n"));
4044}
4045
[email protected]23e482282013-06-14 16:08:024046TEST_P(HttpNetworkTransactionTest, ConnectStatus205) {
[email protected]c744cf22009-02-27 07:28:084047 ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n"));
4048}
4049
[email protected]23e482282013-06-14 16:08:024050TEST_P(HttpNetworkTransactionTest, ConnectStatus206) {
[email protected]c744cf22009-02-27 07:28:084051 ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n"));
4052}
4053
[email protected]23e482282013-06-14 16:08:024054TEST_P(HttpNetworkTransactionTest, ConnectStatus300) {
[email protected]c744cf22009-02-27 07:28:084055 ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n"));
4056}
4057
[email protected]23e482282013-06-14 16:08:024058TEST_P(HttpNetworkTransactionTest, ConnectStatus301) {
[email protected]c744cf22009-02-27 07:28:084059 ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n"));
4060}
4061
[email protected]23e482282013-06-14 16:08:024062TEST_P(HttpNetworkTransactionTest, ConnectStatus302) {
[email protected]c744cf22009-02-27 07:28:084063 ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n"));
4064}
4065
[email protected]23e482282013-06-14 16:08:024066TEST_P(HttpNetworkTransactionTest, ConnectStatus303) {
[email protected]c744cf22009-02-27 07:28:084067 ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n"));
4068}
4069
[email protected]23e482282013-06-14 16:08:024070TEST_P(HttpNetworkTransactionTest, ConnectStatus304) {
[email protected]c744cf22009-02-27 07:28:084071 ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n"));
4072}
4073
[email protected]23e482282013-06-14 16:08:024074TEST_P(HttpNetworkTransactionTest, ConnectStatus305) {
[email protected]c744cf22009-02-27 07:28:084075 ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n"));
4076}
4077
[email protected]23e482282013-06-14 16:08:024078TEST_P(HttpNetworkTransactionTest, ConnectStatus306) {
[email protected]c744cf22009-02-27 07:28:084079 ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n"));
4080}
4081
[email protected]23e482282013-06-14 16:08:024082TEST_P(HttpNetworkTransactionTest, ConnectStatus307) {
[email protected]c744cf22009-02-27 07:28:084083 ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n"));
4084}
4085
[email protected]0a17aab32014-04-24 03:32:374086TEST_P(HttpNetworkTransactionTest, ConnectStatus308) {
4087 ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n"));
4088}
4089
[email protected]23e482282013-06-14 16:08:024090TEST_P(HttpNetworkTransactionTest, ConnectStatus400) {
[email protected]c744cf22009-02-27 07:28:084091 ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n"));
4092}
4093
[email protected]23e482282013-06-14 16:08:024094TEST_P(HttpNetworkTransactionTest, ConnectStatus401) {
[email protected]c744cf22009-02-27 07:28:084095 ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n"));
4096}
4097
[email protected]23e482282013-06-14 16:08:024098TEST_P(HttpNetworkTransactionTest, ConnectStatus402) {
[email protected]c744cf22009-02-27 07:28:084099 ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n"));
4100}
4101
[email protected]23e482282013-06-14 16:08:024102TEST_P(HttpNetworkTransactionTest, ConnectStatus403) {
[email protected]c744cf22009-02-27 07:28:084103 ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n"));
4104}
4105
[email protected]23e482282013-06-14 16:08:024106TEST_P(HttpNetworkTransactionTest, ConnectStatus404) {
[email protected]c744cf22009-02-27 07:28:084107 ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n"));
4108}
4109
[email protected]23e482282013-06-14 16:08:024110TEST_P(HttpNetworkTransactionTest, ConnectStatus405) {
[email protected]c744cf22009-02-27 07:28:084111 ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n"));
4112}
4113
[email protected]23e482282013-06-14 16:08:024114TEST_P(HttpNetworkTransactionTest, ConnectStatus406) {
[email protected]c744cf22009-02-27 07:28:084115 ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n"));
4116}
4117
[email protected]23e482282013-06-14 16:08:024118TEST_P(HttpNetworkTransactionTest, ConnectStatus407) {
[email protected]c744cf22009-02-27 07:28:084119 ConnectStatusHelperWithExpectedStatus(
4120 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
[email protected]a7ea8832010-07-12 17:54:544121 ERR_PROXY_AUTH_UNSUPPORTED);
[email protected]c744cf22009-02-27 07:28:084122}
4123
[email protected]23e482282013-06-14 16:08:024124TEST_P(HttpNetworkTransactionTest, ConnectStatus408) {
[email protected]c744cf22009-02-27 07:28:084125 ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n"));
4126}
4127
[email protected]23e482282013-06-14 16:08:024128TEST_P(HttpNetworkTransactionTest, ConnectStatus409) {
[email protected]c744cf22009-02-27 07:28:084129 ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n"));
4130}
4131
[email protected]23e482282013-06-14 16:08:024132TEST_P(HttpNetworkTransactionTest, ConnectStatus410) {
[email protected]c744cf22009-02-27 07:28:084133 ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n"));
4134}
4135
[email protected]23e482282013-06-14 16:08:024136TEST_P(HttpNetworkTransactionTest, ConnectStatus411) {
[email protected]c744cf22009-02-27 07:28:084137 ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n"));
4138}
4139
[email protected]23e482282013-06-14 16:08:024140TEST_P(HttpNetworkTransactionTest, ConnectStatus412) {
[email protected]c744cf22009-02-27 07:28:084141 ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n"));
4142}
4143
[email protected]23e482282013-06-14 16:08:024144TEST_P(HttpNetworkTransactionTest, ConnectStatus413) {
[email protected]c744cf22009-02-27 07:28:084145 ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n"));
4146}
4147
[email protected]23e482282013-06-14 16:08:024148TEST_P(HttpNetworkTransactionTest, ConnectStatus414) {
[email protected]c744cf22009-02-27 07:28:084149 ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n"));
4150}
4151
[email protected]23e482282013-06-14 16:08:024152TEST_P(HttpNetworkTransactionTest, ConnectStatus415) {
[email protected]c744cf22009-02-27 07:28:084153 ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n"));
4154}
4155
[email protected]23e482282013-06-14 16:08:024156TEST_P(HttpNetworkTransactionTest, ConnectStatus416) {
[email protected]c744cf22009-02-27 07:28:084157 ConnectStatusHelper(
4158 MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n"));
4159}
4160
[email protected]23e482282013-06-14 16:08:024161TEST_P(HttpNetworkTransactionTest, ConnectStatus417) {
[email protected]c744cf22009-02-27 07:28:084162 ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n"));
4163}
4164
[email protected]23e482282013-06-14 16:08:024165TEST_P(HttpNetworkTransactionTest, ConnectStatus500) {
[email protected]c744cf22009-02-27 07:28:084166 ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n"));
4167}
4168
[email protected]23e482282013-06-14 16:08:024169TEST_P(HttpNetworkTransactionTest, ConnectStatus501) {
[email protected]c744cf22009-02-27 07:28:084170 ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n"));
4171}
4172
[email protected]23e482282013-06-14 16:08:024173TEST_P(HttpNetworkTransactionTest, ConnectStatus502) {
[email protected]c744cf22009-02-27 07:28:084174 ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n"));
4175}
4176
[email protected]23e482282013-06-14 16:08:024177TEST_P(HttpNetworkTransactionTest, ConnectStatus503) {
[email protected]c744cf22009-02-27 07:28:084178 ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n"));
4179}
4180
[email protected]23e482282013-06-14 16:08:024181TEST_P(HttpNetworkTransactionTest, ConnectStatus504) {
[email protected]c744cf22009-02-27 07:28:084182 ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n"));
4183}
4184
[email protected]23e482282013-06-14 16:08:024185TEST_P(HttpNetworkTransactionTest, ConnectStatus505) {
[email protected]c744cf22009-02-27 07:28:084186 ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n"));
4187}
4188
[email protected]038e9a32008-10-08 22:40:164189// Test the flow when both the proxy server AND origin server require
4190// authentication. Again, this uses basic auth for both since that is
4191// the simplest to mock.
[email protected]23e482282013-06-14 16:08:024192TEST_P(HttpNetworkTransactionTest, BasicAuthProxyThenServer) {
[email protected]cb9bf6ca2011-01-28 13:15:274193 HttpRequestInfo request;
4194 request.method = "GET";
4195 request.url = GURL("http://www.google.com/");
4196 request.load_flags = 0;
4197
[email protected]038e9a32008-10-08 22:40:164198 // Configure against proxy server "myproxy:70".
[email protected]3fe8d2f82013-10-17 08:56:074199 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70"));
4200 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
4201
4202 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:414203 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]038e9a32008-10-08 22:40:164204
[email protected]f9ee6b52008-11-08 06:46:234205 MockWrite data_writes1[] = {
4206 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
4207 "Host: www.google.com\r\n"
4208 "Proxy-Connection: keep-alive\r\n\r\n"),
4209 };
4210
[email protected]038e9a32008-10-08 22:40:164211 MockRead data_reads1[] = {
4212 MockRead("HTTP/1.0 407 Unauthorized\r\n"),
4213 // Give a couple authenticate options (only the middle one is actually
4214 // supported).
[email protected]22927ad2009-09-21 19:56:194215 MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed.
[email protected]038e9a32008-10-08 22:40:164216 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
4217 MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"),
4218 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
4219 // Large content-length -- won't matter, as connection will be reset.
4220 MockRead("Content-Length: 10000\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:064221 MockRead(SYNCHRONOUS, ERR_FAILED),
[email protected]038e9a32008-10-08 22:40:164222 };
4223
4224 // After calling trans->RestartWithAuth() the first time, this is the
4225 // request we should be issuing -- the final header line contains the
4226 // proxy's credentials.
4227 MockWrite data_writes2[] = {
4228 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
4229 "Host: www.google.com\r\n"
4230 "Proxy-Connection: keep-alive\r\n"
4231 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
4232 };
4233
4234 // Now the proxy server lets the request pass through to origin server.
4235 // The origin server responds with a 401.
4236 MockRead data_reads2[] = {
4237 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
4238 // Note: We are using the same realm-name as the proxy server. This is
4239 // completely valid, as realms are unique across hosts.
4240 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
4241 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
4242 MockRead("Content-Length: 2000\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:064243 MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached.
[email protected]038e9a32008-10-08 22:40:164244 };
4245
4246 // After calling trans->RestartWithAuth() the second time, we should send
4247 // the credentials for both the proxy and origin server.
4248 MockWrite data_writes3[] = {
4249 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
4250 "Host: www.google.com\r\n"
4251 "Proxy-Connection: keep-alive\r\n"
4252 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n"
4253 "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"),
4254 };
4255
4256 // Lastly we get the desired content.
4257 MockRead data_reads3[] = {
4258 MockRead("HTTP/1.0 200 OK\r\n"),
4259 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
4260 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:064261 MockRead(SYNCHRONOUS, OK),
[email protected]038e9a32008-10-08 22:40:164262 };
4263
[email protected]31a2bfe2010-02-09 08:03:394264 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
4265 data_writes1, arraysize(data_writes1));
4266 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
4267 data_writes2, arraysize(data_writes2));
4268 StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3),
4269 data_writes3, arraysize(data_writes3));
[email protected]bb88e1d32013-05-03 23:11:074270 session_deps_.socket_factory->AddSocketDataProvider(&data1);
4271 session_deps_.socket_factory->AddSocketDataProvider(&data2);
4272 session_deps_.socket_factory->AddSocketDataProvider(&data3);
[email protected]038e9a32008-10-08 22:40:164273
[email protected]49639fa2011-12-20 23:22:414274 TestCompletionCallback callback1;
[email protected]038e9a32008-10-08 22:40:164275
[email protected]49639fa2011-12-20 23:22:414276 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:424277 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]038e9a32008-10-08 22:40:164278
4279 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:424280 EXPECT_EQ(OK, rv);
[email protected]038e9a32008-10-08 22:40:164281
[email protected]1c773ea12009-04-28 19:58:424282 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:504283 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:044284 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
[email protected]038e9a32008-10-08 22:40:164285
[email protected]49639fa2011-12-20 23:22:414286 TestCompletionCallback callback2;
[email protected]038e9a32008-10-08 22:40:164287
[email protected]49639fa2011-12-20 23:22:414288 rv = trans->RestartWithAuth(
4289 AuthCredentials(kFoo, kBar), callback2.callback());
[email protected]1c773ea12009-04-28 19:58:424290 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]038e9a32008-10-08 22:40:164291
4292 rv = callback2.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:424293 EXPECT_EQ(OK, rv);
[email protected]038e9a32008-10-08 22:40:164294
4295 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:504296 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:044297 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
[email protected]038e9a32008-10-08 22:40:164298
[email protected]49639fa2011-12-20 23:22:414299 TestCompletionCallback callback3;
[email protected]038e9a32008-10-08 22:40:164300
[email protected]49639fa2011-12-20 23:22:414301 rv = trans->RestartWithAuth(
4302 AuthCredentials(kFoo2, kBar2), callback3.callback());
[email protected]1c773ea12009-04-28 19:58:424303 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]038e9a32008-10-08 22:40:164304
4305 rv = callback3.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:424306 EXPECT_EQ(OK, rv);
[email protected]038e9a32008-10-08 22:40:164307
4308 response = trans->GetResponseInfo();
4309 EXPECT_TRUE(response->auth_challenge.get() == NULL);
4310 EXPECT_EQ(100, response->headers->GetContentLength());
[email protected]038e9a32008-10-08 22:40:164311}
[email protected]4ddaf2502008-10-23 18:26:194312
[email protected]ea9dc9a2009-09-05 00:43:324313// For the NTLM implementation using SSPI, we skip the NTLM tests since we
4314// can't hook into its internals to cause it to generate predictable NTLM
4315// authorization headers.
4316#if defined(NTLM_PORTABLE)
[email protected]385a4672009-03-11 22:21:294317// The NTLM authentication unit tests were generated by capturing the HTTP
4318// requests and responses using Fiddler 2 and inspecting the generated random
4319// bytes in the debugger.
4320
4321// Enter the correct password and authenticate successfully.
[email protected]23e482282013-06-14 16:08:024322TEST_P(HttpNetworkTransactionTest, NTLMAuth1) {
[email protected]1c773ea12009-04-28 19:58:424323 HttpRequestInfo request;
[email protected]3f918782009-02-28 01:29:244324 request.method = "GET";
4325 request.url = GURL("http://172.22.68.17/kids/login.aspx");
[email protected]2217aa22013-10-11 03:03:544326
4327 // Ensure load is not disrupted by flags which suppress behaviour specific
4328 // to other auth schemes.
4329 request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY;
[email protected]3f918782009-02-28 01:29:244330
[email protected]cb9bf6ca2011-01-28 13:15:274331 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1,
4332 MockGetHostName);
[email protected]bb88e1d32013-05-03 23:11:074333 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:274334
[email protected]3f918782009-02-28 01:29:244335 MockWrite data_writes1[] = {
4336 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n"
4337 "Host: 172.22.68.17\r\n"
4338 "Connection: keep-alive\r\n\r\n"),
4339 };
4340
4341 MockRead data_reads1[] = {
4342 MockRead("HTTP/1.1 401 Access Denied\r\n"),
[email protected]aef04272010-06-28 18:03:044343 // Negotiate and NTLM are often requested together. However, we only want
4344 // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip
4345 // the header that requests Negotiate for this test.
[email protected]3f918782009-02-28 01:29:244346 MockRead("WWW-Authenticate: NTLM\r\n"),
4347 MockRead("Connection: close\r\n"),
4348 MockRead("Content-Length: 42\r\n"),
[email protected]076c85082009-04-10 23:21:364349 MockRead("Content-Type: text/html\r\n\r\n"),
[email protected]3f918782009-02-28 01:29:244350 // Missing content -- won't matter, as connection will be reset.
[email protected]8ddf8322012-02-23 18:08:064351 MockRead(SYNCHRONOUS, ERR_UNEXPECTED),
[email protected]3f918782009-02-28 01:29:244352 };
4353
4354 MockWrite data_writes2[] = {
[email protected]0757e7702009-03-27 04:00:224355 // After restarting with a null identity, this is the
[email protected]3f918782009-02-28 01:29:244356 // request we should be issuing -- the final header line contains a Type
4357 // 1 message.
4358 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n"
4359 "Host: 172.22.68.17\r\n"
4360 "Connection: keep-alive\r\n"
4361 "Authorization: NTLM "
4362 "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"),
4363
4364 // After calling trans->RestartWithAuth(), we should send a Type 3 message
4365 // (the credentials for the origin server). The second request continues
4366 // on the same connection.
4367 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n"
4368 "Host: 172.22.68.17\r\n"
4369 "Connection: keep-alive\r\n"
[email protected]385a4672009-03-11 22:21:294370 "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA"
4371 "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA"
4372 "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW"
4373 "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX"
4374 "ahlhx5I=\r\n\r\n"),
[email protected]3f918782009-02-28 01:29:244375 };
4376
4377 MockRead data_reads2[] = {
4378 // The origin server responds with a Type 2 message.
4379 MockRead("HTTP/1.1 401 Access Denied\r\n"),
4380 MockRead("WWW-Authenticate: NTLM "
[email protected]385a4672009-03-11 22:21:294381 "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo"
[email protected]3f918782009-02-28 01:29:244382 "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE"
4383 "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA"
4384 "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy"
4385 "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB"
4386 "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw"
4387 "BtAAAAAAA=\r\n"),
4388 MockRead("Content-Length: 42\r\n"),
[email protected]076c85082009-04-10 23:21:364389 MockRead("Content-Type: text/html\r\n\r\n"),
[email protected]3f918782009-02-28 01:29:244390 MockRead("You are not authorized to view this page\r\n"),
4391
4392 // Lastly we get the desired content.
4393 MockRead("HTTP/1.1 200 OK\r\n"),
4394 MockRead("Content-Type: text/html; charset=utf-8\r\n"),
4395 MockRead("Content-Length: 13\r\n\r\n"),
4396 MockRead("Please Login\r\n"),
[email protected]8ddf8322012-02-23 18:08:064397 MockRead(SYNCHRONOUS, OK),
[email protected]3f918782009-02-28 01:29:244398 };
4399
[email protected]31a2bfe2010-02-09 08:03:394400 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
4401 data_writes1, arraysize(data_writes1));
4402 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
4403 data_writes2, arraysize(data_writes2));
[email protected]bb88e1d32013-05-03 23:11:074404 session_deps_.socket_factory->AddSocketDataProvider(&data1);
4405 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]3f918782009-02-28 01:29:244406
[email protected]49639fa2011-12-20 23:22:414407 TestCompletionCallback callback1;
[email protected]3f918782009-02-28 01:29:244408
[email protected]262eec82013-03-19 21:01:364409 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:504410 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0b0bf032010-09-21 18:08:504411
[email protected]49639fa2011-12-20 23:22:414412 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:424413 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]3f918782009-02-28 01:29:244414
4415 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:424416 EXPECT_EQ(OK, rv);
[email protected]3f918782009-02-28 01:29:244417
[email protected]0757e7702009-03-27 04:00:224418 EXPECT_FALSE(trans->IsReadyToRestartForAuth());
4419
[email protected]1c773ea12009-04-28 19:58:424420 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]79cb5c12011-09-12 13:12:044421 ASSERT_FALSE(response == NULL);
4422 EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get()));
[email protected]3f918782009-02-28 01:29:244423
[email protected]49639fa2011-12-20 23:22:414424 TestCompletionCallback callback2;
[email protected]10af5fe72011-01-31 16:17:254425
[email protected]f3cf9802011-10-28 18:44:584426 rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM),
[email protected]49639fa2011-12-20 23:22:414427 callback2.callback());
[email protected]10af5fe72011-01-31 16:17:254428 EXPECT_EQ(ERR_IO_PENDING, rv);
4429
4430 rv = callback2.WaitForResult();
4431 EXPECT_EQ(OK, rv);
4432
4433 EXPECT_TRUE(trans->IsReadyToRestartForAuth());
4434
4435 response = trans->GetResponseInfo();
4436 ASSERT_TRUE(response != NULL);
[email protected]10af5fe72011-01-31 16:17:254437 EXPECT_TRUE(response->auth_challenge.get() == NULL);
4438
[email protected]49639fa2011-12-20 23:22:414439 TestCompletionCallback callback3;
[email protected]3f918782009-02-28 01:29:244440
[email protected]49639fa2011-12-20 23:22:414441 rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback());
[email protected]1c773ea12009-04-28 19:58:424442 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]3f918782009-02-28 01:29:244443
[email protected]0757e7702009-03-27 04:00:224444 rv = callback3.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:424445 EXPECT_EQ(OK, rv);
[email protected]3f918782009-02-28 01:29:244446
4447 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:504448 ASSERT_TRUE(response != NULL);
[email protected]3f918782009-02-28 01:29:244449 EXPECT_TRUE(response->auth_challenge.get() == NULL);
4450 EXPECT_EQ(13, response->headers->GetContentLength());
4451}
4452
[email protected]385a4672009-03-11 22:21:294453// Enter a wrong password, and then the correct one.
[email protected]23e482282013-06-14 16:08:024454TEST_P(HttpNetworkTransactionTest, NTLMAuth2) {
[email protected]1c773ea12009-04-28 19:58:424455 HttpRequestInfo request;
[email protected]385a4672009-03-11 22:21:294456 request.method = "GET";
4457 request.url = GURL("http://172.22.68.17/kids/login.aspx");
4458 request.load_flags = 0;
4459
[email protected]cb9bf6ca2011-01-28 13:15:274460 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2,
4461 MockGetHostName);
[email protected]bb88e1d32013-05-03 23:11:074462 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:274463
[email protected]385a4672009-03-11 22:21:294464 MockWrite data_writes1[] = {
4465 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n"
4466 "Host: 172.22.68.17\r\n"
4467 "Connection: keep-alive\r\n\r\n"),
4468 };
4469
4470 MockRead data_reads1[] = {
4471 MockRead("HTTP/1.1 401 Access Denied\r\n"),
[email protected]aef04272010-06-28 18:03:044472 // Negotiate and NTLM are often requested together. However, we only want
4473 // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip
4474 // the header that requests Negotiate for this test.
[email protected]385a4672009-03-11 22:21:294475 MockRead("WWW-Authenticate: NTLM\r\n"),
4476 MockRead("Connection: close\r\n"),
4477 MockRead("Content-Length: 42\r\n"),
[email protected]076c85082009-04-10 23:21:364478 MockRead("Content-Type: text/html\r\n\r\n"),
[email protected]385a4672009-03-11 22:21:294479 // Missing content -- won't matter, as connection will be reset.
[email protected]8ddf8322012-02-23 18:08:064480 MockRead(SYNCHRONOUS, ERR_UNEXPECTED),
[email protected]385a4672009-03-11 22:21:294481 };
4482
4483 MockWrite data_writes2[] = {
[email protected]0757e7702009-03-27 04:00:224484 // After restarting with a null identity, this is the
[email protected]385a4672009-03-11 22:21:294485 // request we should be issuing -- the final header line contains a Type
4486 // 1 message.
4487 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n"
4488 "Host: 172.22.68.17\r\n"
4489 "Connection: keep-alive\r\n"
4490 "Authorization: NTLM "
4491 "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"),
4492
4493 // After calling trans->RestartWithAuth(), we should send a Type 3 message
4494 // (the credentials for the origin server). The second request continues
4495 // on the same connection.
4496 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n"
4497 "Host: 172.22.68.17\r\n"
4498 "Connection: keep-alive\r\n"
4499 "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA"
4500 "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA"
4501 "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY"
4502 "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj"
4503 "4Ww7b7E=\r\n\r\n"),
4504 };
4505
4506 MockRead data_reads2[] = {
4507 // The origin server responds with a Type 2 message.
4508 MockRead("HTTP/1.1 401 Access Denied\r\n"),
4509 MockRead("WWW-Authenticate: NTLM "
4510 "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo"
4511 "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE"
4512 "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA"
4513 "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy"
4514 "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB"
4515 "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw"
4516 "BtAAAAAAA=\r\n"),
4517 MockRead("Content-Length: 42\r\n"),
[email protected]076c85082009-04-10 23:21:364518 MockRead("Content-Type: text/html\r\n\r\n"),
[email protected]385a4672009-03-11 22:21:294519 MockRead("You are not authorized to view this page\r\n"),
4520
4521 // Wrong password.
4522 MockRead("HTTP/1.1 401 Access Denied\r\n"),
[email protected]385a4672009-03-11 22:21:294523 MockRead("WWW-Authenticate: NTLM\r\n"),
4524 MockRead("Connection: close\r\n"),
4525 MockRead("Content-Length: 42\r\n"),
[email protected]076c85082009-04-10 23:21:364526 MockRead("Content-Type: text/html\r\n\r\n"),
[email protected]385a4672009-03-11 22:21:294527 // Missing content -- won't matter, as connection will be reset.
[email protected]8ddf8322012-02-23 18:08:064528 MockRead(SYNCHRONOUS, ERR_UNEXPECTED),
[email protected]385a4672009-03-11 22:21:294529 };
4530
4531 MockWrite data_writes3[] = {
[email protected]0757e7702009-03-27 04:00:224532 // After restarting with a null identity, this is the
[email protected]385a4672009-03-11 22:21:294533 // request we should be issuing -- the final header line contains a Type
4534 // 1 message.
4535 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n"
4536 "Host: 172.22.68.17\r\n"
4537 "Connection: keep-alive\r\n"
4538 "Authorization: NTLM "
4539 "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"),
4540
4541 // After calling trans->RestartWithAuth(), we should send a Type 3 message
4542 // (the credentials for the origin server). The second request continues
4543 // on the same connection.
4544 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n"
4545 "Host: 172.22.68.17\r\n"
4546 "Connection: keep-alive\r\n"
4547 "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA"
4548 "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA"
4549 "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54"
4550 "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI"
4551 "+4MUm7c=\r\n\r\n"),
4552 };
4553
4554 MockRead data_reads3[] = {
4555 // The origin server responds with a Type 2 message.
4556 MockRead("HTTP/1.1 401 Access Denied\r\n"),
4557 MockRead("WWW-Authenticate: NTLM "
4558 "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo"
4559 "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE"
4560 "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA"
4561 "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy"
4562 "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB"
4563 "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw"
4564 "BtAAAAAAA=\r\n"),
4565 MockRead("Content-Length: 42\r\n"),
[email protected]076c85082009-04-10 23:21:364566 MockRead("Content-Type: text/html\r\n\r\n"),
[email protected]385a4672009-03-11 22:21:294567 MockRead("You are not authorized to view this page\r\n"),
4568
4569 // Lastly we get the desired content.
4570 MockRead("HTTP/1.1 200 OK\r\n"),
4571 MockRead("Content-Type: text/html; charset=utf-8\r\n"),
4572 MockRead("Content-Length: 13\r\n\r\n"),
4573 MockRead("Please Login\r\n"),
[email protected]8ddf8322012-02-23 18:08:064574 MockRead(SYNCHRONOUS, OK),
[email protected]385a4672009-03-11 22:21:294575 };
4576
[email protected]31a2bfe2010-02-09 08:03:394577 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
4578 data_writes1, arraysize(data_writes1));
4579 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
4580 data_writes2, arraysize(data_writes2));
4581 StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3),
4582 data_writes3, arraysize(data_writes3));
[email protected]bb88e1d32013-05-03 23:11:074583 session_deps_.socket_factory->AddSocketDataProvider(&data1);
4584 session_deps_.socket_factory->AddSocketDataProvider(&data2);
4585 session_deps_.socket_factory->AddSocketDataProvider(&data3);
[email protected]385a4672009-03-11 22:21:294586
[email protected]49639fa2011-12-20 23:22:414587 TestCompletionCallback callback1;
[email protected]385a4672009-03-11 22:21:294588
[email protected]262eec82013-03-19 21:01:364589 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:504590 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0b0bf032010-09-21 18:08:504591
[email protected]49639fa2011-12-20 23:22:414592 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:424593 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]385a4672009-03-11 22:21:294594
4595 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:424596 EXPECT_EQ(OK, rv);
[email protected]385a4672009-03-11 22:21:294597
[email protected]0757e7702009-03-27 04:00:224598 EXPECT_FALSE(trans->IsReadyToRestartForAuth());
[email protected]385a4672009-03-11 22:21:294599
[email protected]1c773ea12009-04-28 19:58:424600 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:504601 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:044602 EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get()));
[email protected]385a4672009-03-11 22:21:294603
[email protected]49639fa2011-12-20 23:22:414604 TestCompletionCallback callback2;
[email protected]385a4672009-03-11 22:21:294605
[email protected]0757e7702009-03-27 04:00:224606 // Enter the wrong password.
[email protected]f3cf9802011-10-28 18:44:584607 rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword),
[email protected]49639fa2011-12-20 23:22:414608 callback2.callback());
[email protected]1c773ea12009-04-28 19:58:424609 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]385a4672009-03-11 22:21:294610
[email protected]10af5fe72011-01-31 16:17:254611 rv = callback2.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:424612 EXPECT_EQ(OK, rv);
[email protected]385a4672009-03-11 22:21:294613
[email protected]0757e7702009-03-27 04:00:224614 EXPECT_TRUE(trans->IsReadyToRestartForAuth());
[email protected]49639fa2011-12-20 23:22:414615 TestCompletionCallback callback3;
4616 rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback());
[email protected]1c773ea12009-04-28 19:58:424617 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]10af5fe72011-01-31 16:17:254618 rv = callback3.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:424619 EXPECT_EQ(OK, rv);
[email protected]0757e7702009-03-27 04:00:224620 EXPECT_FALSE(trans->IsReadyToRestartForAuth());
4621
4622 response = trans->GetResponseInfo();
[email protected]79cb5c12011-09-12 13:12:044623 ASSERT_FALSE(response == NULL);
4624 EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get()));
[email protected]0757e7702009-03-27 04:00:224625
[email protected]49639fa2011-12-20 23:22:414626 TestCompletionCallback callback4;
[email protected]0757e7702009-03-27 04:00:224627
4628 // Now enter the right password.
[email protected]f3cf9802011-10-28 18:44:584629 rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM),
[email protected]49639fa2011-12-20 23:22:414630 callback4.callback());
[email protected]10af5fe72011-01-31 16:17:254631 EXPECT_EQ(ERR_IO_PENDING, rv);
4632
4633 rv = callback4.WaitForResult();
4634 EXPECT_EQ(OK, rv);
4635
4636 EXPECT_TRUE(trans->IsReadyToRestartForAuth());
4637
[email protected]49639fa2011-12-20 23:22:414638 TestCompletionCallback callback5;
[email protected]10af5fe72011-01-31 16:17:254639
4640 // One more roundtrip
[email protected]49639fa2011-12-20 23:22:414641 rv = trans->RestartWithAuth(AuthCredentials(), callback5.callback());
[email protected]1c773ea12009-04-28 19:58:424642 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]0757e7702009-03-27 04:00:224643
4644 rv = callback5.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:424645 EXPECT_EQ(OK, rv);
[email protected]0757e7702009-03-27 04:00:224646
[email protected]385a4672009-03-11 22:21:294647 response = trans->GetResponseInfo();
4648 EXPECT_TRUE(response->auth_challenge.get() == NULL);
4649 EXPECT_EQ(13, response->headers->GetContentLength());
4650}
[email protected]ea9dc9a2009-09-05 00:43:324651#endif // NTLM_PORTABLE
[email protected]385a4672009-03-11 22:21:294652
[email protected]4ddaf2502008-10-23 18:26:194653// Test reading a server response which has only headers, and no body.
4654// After some maximum number of bytes is consumed, the transaction should
4655// fail with ERR_RESPONSE_HEADERS_TOO_BIG.
[email protected]23e482282013-06-14 16:08:024656TEST_P(HttpNetworkTransactionTest, LargeHeadersNoBody) {
[email protected]1c773ea12009-04-28 19:58:424657 HttpRequestInfo request;
[email protected]4ddaf2502008-10-23 18:26:194658 request.method = "GET";
4659 request.url = GURL("http://www.google.com/");
4660 request.load_flags = 0;
4661
[email protected]3fe8d2f82013-10-17 08:56:074662 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:274663 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:414664 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:274665
[email protected]b75b7b2f2009-10-06 00:54:534666 // Respond with 300 kb of headers (we should fail after 256 kb).
[email protected]15a5ccf82008-10-23 19:57:434667 std::string large_headers_string;
[email protected]b75b7b2f2009-10-06 00:54:534668 FillLargeHeadersString(&large_headers_string, 300 * 1024);
[email protected]4ddaf2502008-10-23 18:26:194669
4670 MockRead data_reads[] = {
4671 MockRead("HTTP/1.0 200 OK\r\n"),
[email protected]8ddf8322012-02-23 18:08:064672 MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()),
[email protected]4ddaf2502008-10-23 18:26:194673 MockRead("\r\nBODY"),
[email protected]8ddf8322012-02-23 18:08:064674 MockRead(SYNCHRONOUS, OK),
[email protected]4ddaf2502008-10-23 18:26:194675 };
[email protected]31a2bfe2010-02-09 08:03:394676 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:074677 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]4ddaf2502008-10-23 18:26:194678
[email protected]49639fa2011-12-20 23:22:414679 TestCompletionCallback callback;
[email protected]4ddaf2502008-10-23 18:26:194680
[email protected]49639fa2011-12-20 23:22:414681 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:424682 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]4ddaf2502008-10-23 18:26:194683
4684 rv = callback.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:424685 EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, rv);
[email protected]4ddaf2502008-10-23 18:26:194686
[email protected]1c773ea12009-04-28 19:58:424687 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]4ddaf2502008-10-23 18:26:194688 EXPECT_TRUE(response == NULL);
4689}
[email protected]f4e426b2008-11-05 00:24:494690
4691// Make sure that we don't try to reuse a TCPClientSocket when failing to
4692// establish tunnel.
4693// http://code.google.com/p/chromium/issues/detail?id=3772
[email protected]23e482282013-06-14 16:08:024694TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:234695 DontRecycleTransportSocketForSSLTunnel) {
[email protected]cb9bf6ca2011-01-28 13:15:274696 HttpRequestInfo request;
4697 request.method = "GET";
4698 request.url = GURL("https://www.google.com/");
4699 request.load_flags = 0;
4700
[email protected]f4e426b2008-11-05 00:24:494701 // Configure against proxy server "myproxy:70".
[email protected]bb88e1d32013-05-03 23:11:074702 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70"));
[email protected]db8f44c2008-12-13 04:52:014703
[email protected]bb88e1d32013-05-03 23:11:074704 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]f4e426b2008-11-05 00:24:494705
[email protected]262eec82013-03-19 21:01:364706 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:504707 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]f4e426b2008-11-05 00:24:494708
[email protected]f4e426b2008-11-05 00:24:494709 // Since we have proxy, should try to establish tunnel.
4710 MockWrite data_writes1[] = {
4711 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
[email protected]e44de5d2009-06-05 20:12:454712 "Host: www.google.com\r\n"
4713 "Proxy-Connection: keep-alive\r\n\r\n"),
[email protected]f4e426b2008-11-05 00:24:494714 };
4715
[email protected]77848d12008-11-14 00:00:224716 // The proxy responds to the connect with a 404, using a persistent
[email protected]f4e426b2008-11-05 00:24:494717 // connection. Usually a proxy would return 501 (not implemented),
4718 // or 200 (tunnel established).
4719 MockRead data_reads1[] = {
4720 MockRead("HTTP/1.1 404 Not Found\r\n"),
4721 MockRead("Content-Length: 10\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:064722 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached.
[email protected]f4e426b2008-11-05 00:24:494723 };
4724
[email protected]31a2bfe2010-02-09 08:03:394725 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
4726 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:074727 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]f4e426b2008-11-05 00:24:494728
[email protected]49639fa2011-12-20 23:22:414729 TestCompletionCallback callback1;
[email protected]f4e426b2008-11-05 00:24:494730
[email protected]49639fa2011-12-20 23:22:414731 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:424732 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]f4e426b2008-11-05 00:24:494733
4734 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:424735 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv);
[email protected]f4e426b2008-11-05 00:24:494736
[email protected]1c773ea12009-04-28 19:58:424737 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]c744cf22009-02-27 07:28:084738 EXPECT_TRUE(response == NULL);
[email protected]f4e426b2008-11-05 00:24:494739
[email protected]b4404c02009-04-10 16:38:524740 // Empty the current queue. This is necessary because idle sockets are
4741 // added to the connection pool asynchronously with a PostTask.
[email protected]2da659e2013-05-23 20:51:344742 base::MessageLoop::current()->RunUntilIdle();
[email protected]b4404c02009-04-10 16:38:524743
[email protected]f4e426b2008-11-05 00:24:494744 // We now check to make sure the TCPClientSocket was not added back to
4745 // the pool.
[email protected]90499482013-06-01 00:39:504746 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get()));
[email protected]f4e426b2008-11-05 00:24:494747 trans.reset();
[email protected]2da659e2013-05-23 20:51:344748 base::MessageLoop::current()->RunUntilIdle();
[email protected]f4e426b2008-11-05 00:24:494749 // Make sure that the socket didn't get recycled after calling the destructor.
[email protected]90499482013-06-01 00:39:504750 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get()));
[email protected]f4e426b2008-11-05 00:24:494751}
[email protected]372d34a2008-11-05 21:30:514752
[email protected]1b157c02009-04-21 01:55:404753// Make sure that we recycle a socket after reading all of the response body.
[email protected]23e482282013-06-14 16:08:024754TEST_P(HttpNetworkTransactionTest, RecycleSocket) {
[email protected]1c773ea12009-04-28 19:58:424755 HttpRequestInfo request;
[email protected]1b157c02009-04-21 01:55:404756 request.method = "GET";
4757 request.url = GURL("http://www.google.com/");
4758 request.load_flags = 0;
4759
[email protected]bb88e1d32013-05-03 23:11:074760 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:274761
[email protected]262eec82013-03-19 21:01:364762 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:504763 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:274764
[email protected]1b157c02009-04-21 01:55:404765 MockRead data_reads[] = {
4766 // A part of the response body is received with the response headers.
4767 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"),
4768 // The rest of the response body is received in two parts.
4769 MockRead("lo"),
4770 MockRead(" world"),
4771 MockRead("junk"), // Should not be read!!
[email protected]8ddf8322012-02-23 18:08:064772 MockRead(SYNCHRONOUS, OK),
[email protected]1b157c02009-04-21 01:55:404773 };
4774
[email protected]31a2bfe2010-02-09 08:03:394775 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:074776 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]1b157c02009-04-21 01:55:404777
[email protected]49639fa2011-12-20 23:22:414778 TestCompletionCallback callback;
[email protected]1b157c02009-04-21 01:55:404779
[email protected]49639fa2011-12-20 23:22:414780 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:424781 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]1b157c02009-04-21 01:55:404782
4783 rv = callback.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:424784 EXPECT_EQ(OK, rv);
[email protected]1b157c02009-04-21 01:55:404785
[email protected]1c773ea12009-04-28 19:58:424786 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:504787 ASSERT_TRUE(response != NULL);
[email protected]1b157c02009-04-21 01:55:404788
[email protected]90499482013-06-01 00:39:504789 EXPECT_TRUE(response->headers.get() != NULL);
[email protected]1b157c02009-04-21 01:55:404790 std::string status_line = response->headers->GetStatusLine();
4791 EXPECT_EQ("HTTP/1.1 200 OK", status_line);
4792
[email protected]90499482013-06-01 00:39:504793 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get()));
[email protected]1b157c02009-04-21 01:55:404794
4795 std::string response_data;
4796 rv = ReadTransaction(trans.get(), &response_data);
[email protected]1c773ea12009-04-28 19:58:424797 EXPECT_EQ(OK, rv);
[email protected]1b157c02009-04-21 01:55:404798 EXPECT_EQ("hello world", response_data);
4799
4800 // Empty the current queue. This is necessary because idle sockets are
4801 // added to the connection pool asynchronously with a PostTask.
[email protected]2da659e2013-05-23 20:51:344802 base::MessageLoop::current()->RunUntilIdle();
[email protected]1b157c02009-04-21 01:55:404803
4804 // We now check to make sure the socket was added back to the pool.
[email protected]90499482013-06-01 00:39:504805 EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get()));
[email protected]1b157c02009-04-21 01:55:404806}
4807
[email protected]76a505b2010-08-25 06:23:004808// Make sure that we recycle a SSL socket after reading all of the response
4809// body.
[email protected]23e482282013-06-14 16:08:024810TEST_P(HttpNetworkTransactionTest, RecycleSSLSocket) {
[email protected]76a505b2010-08-25 06:23:004811 HttpRequestInfo request;
4812 request.method = "GET";
4813 request.url = GURL("https://www.google.com/");
4814 request.load_flags = 0;
4815
4816 MockWrite data_writes[] = {
4817 MockWrite("GET / HTTP/1.1\r\n"
4818 "Host: www.google.com\r\n"
4819 "Connection: keep-alive\r\n\r\n"),
4820 };
4821
4822 MockRead data_reads[] = {
4823 MockRead("HTTP/1.1 200 OK\r\n"),
4824 MockRead("Content-Length: 11\r\n\r\n"),
4825 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:064826 MockRead(SYNCHRONOUS, OK),
[email protected]76a505b2010-08-25 06:23:004827 };
4828
[email protected]8ddf8322012-02-23 18:08:064829 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]bb88e1d32013-05-03 23:11:074830 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]76a505b2010-08-25 06:23:004831
4832 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
4833 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:074834 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]76a505b2010-08-25 06:23:004835
[email protected]49639fa2011-12-20 23:22:414836 TestCompletionCallback callback;
[email protected]76a505b2010-08-25 06:23:004837
[email protected]bb88e1d32013-05-03 23:11:074838 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:364839 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:504840 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]76a505b2010-08-25 06:23:004841
[email protected]49639fa2011-12-20 23:22:414842 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]76a505b2010-08-25 06:23:004843
4844 EXPECT_EQ(ERR_IO_PENDING, rv);
4845 EXPECT_EQ(OK, callback.WaitForResult());
4846
4847 const HttpResponseInfo* response = trans->GetResponseInfo();
4848 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:504849 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]76a505b2010-08-25 06:23:004850 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
4851
[email protected]90499482013-06-01 00:39:504852 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get()));
[email protected]76a505b2010-08-25 06:23:004853
4854 std::string response_data;
4855 rv = ReadTransaction(trans.get(), &response_data);
4856 EXPECT_EQ(OK, rv);
4857 EXPECT_EQ("hello world", response_data);
4858
4859 // Empty the current queue. This is necessary because idle sockets are
4860 // added to the connection pool asynchronously with a PostTask.
[email protected]2da659e2013-05-23 20:51:344861 base::MessageLoop::current()->RunUntilIdle();
[email protected]76a505b2010-08-25 06:23:004862
4863 // We now check to make sure the socket was added back to the pool.
[email protected]90499482013-06-01 00:39:504864 EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get()));
[email protected]76a505b2010-08-25 06:23:004865}
4866
4867// Grab a SSL socket, use it, and put it back into the pool. Then, reuse it
4868// from the pool and make sure that we recover okay.
[email protected]23e482282013-06-14 16:08:024869TEST_P(HttpNetworkTransactionTest, RecycleDeadSSLSocket) {
[email protected]76a505b2010-08-25 06:23:004870 HttpRequestInfo request;
4871 request.method = "GET";
4872 request.url = GURL("https://www.google.com/");
4873 request.load_flags = 0;
4874
4875 MockWrite data_writes[] = {
4876 MockWrite("GET / HTTP/1.1\r\n"
4877 "Host: www.google.com\r\n"
4878 "Connection: keep-alive\r\n\r\n"),
4879 MockWrite("GET / HTTP/1.1\r\n"
4880 "Host: www.google.com\r\n"
4881 "Connection: keep-alive\r\n\r\n"),
4882 };
4883
4884 MockRead data_reads[] = {
4885 MockRead("HTTP/1.1 200 OK\r\n"),
4886 MockRead("Content-Length: 11\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:064887 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
[email protected]76a505b2010-08-25 06:23:004888 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:064889 MockRead(ASYNC, 0, 0) // EOF
[email protected]76a505b2010-08-25 06:23:004890 };
4891
[email protected]8ddf8322012-02-23 18:08:064892 SSLSocketDataProvider ssl(ASYNC, OK);
4893 SSLSocketDataProvider ssl2(ASYNC, OK);
[email protected]bb88e1d32013-05-03 23:11:074894 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
4895 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2);
[email protected]76a505b2010-08-25 06:23:004896
4897 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
4898 data_writes, arraysize(data_writes));
4899 StaticSocketDataProvider data2(data_reads, arraysize(data_reads),
4900 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:074901 session_deps_.socket_factory->AddSocketDataProvider(&data);
4902 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]76a505b2010-08-25 06:23:004903
[email protected]49639fa2011-12-20 23:22:414904 TestCompletionCallback callback;
[email protected]76a505b2010-08-25 06:23:004905
[email protected]bb88e1d32013-05-03 23:11:074906 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:364907 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:504908 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]76a505b2010-08-25 06:23:004909
[email protected]49639fa2011-12-20 23:22:414910 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]76a505b2010-08-25 06:23:004911
4912 EXPECT_EQ(ERR_IO_PENDING, rv);
4913 EXPECT_EQ(OK, callback.WaitForResult());
4914
4915 const HttpResponseInfo* response = trans->GetResponseInfo();
4916 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:504917 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]76a505b2010-08-25 06:23:004918 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
4919
[email protected]90499482013-06-01 00:39:504920 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get()));
[email protected]76a505b2010-08-25 06:23:004921
4922 std::string response_data;
4923 rv = ReadTransaction(trans.get(), &response_data);
4924 EXPECT_EQ(OK, rv);
4925 EXPECT_EQ("hello world", response_data);
4926
4927 // Empty the current queue. This is necessary because idle sockets are
4928 // added to the connection pool asynchronously with a PostTask.
[email protected]2da659e2013-05-23 20:51:344929 base::MessageLoop::current()->RunUntilIdle();
[email protected]76a505b2010-08-25 06:23:004930
4931 // We now check to make sure the socket was added back to the pool.
[email protected]90499482013-06-01 00:39:504932 EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get()));
[email protected]76a505b2010-08-25 06:23:004933
4934 // Now start the second transaction, which should reuse the previous socket.
4935
[email protected]90499482013-06-01 00:39:504936 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]76a505b2010-08-25 06:23:004937
[email protected]49639fa2011-12-20 23:22:414938 rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]76a505b2010-08-25 06:23:004939
4940 EXPECT_EQ(ERR_IO_PENDING, rv);
4941 EXPECT_EQ(OK, callback.WaitForResult());
4942
4943 response = trans->GetResponseInfo();
4944 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:504945 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]76a505b2010-08-25 06:23:004946 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
4947
[email protected]90499482013-06-01 00:39:504948 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get()));
[email protected]76a505b2010-08-25 06:23:004949
4950 rv = ReadTransaction(trans.get(), &response_data);
4951 EXPECT_EQ(OK, rv);
4952 EXPECT_EQ("hello world", response_data);
4953
4954 // Empty the current queue. This is necessary because idle sockets are
4955 // added to the connection pool asynchronously with a PostTask.
[email protected]2da659e2013-05-23 20:51:344956 base::MessageLoop::current()->RunUntilIdle();
[email protected]76a505b2010-08-25 06:23:004957
4958 // We now check to make sure the socket was added back to the pool.
[email protected]90499482013-06-01 00:39:504959 EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get()));
[email protected]76a505b2010-08-25 06:23:004960}
4961
[email protected]b4404c02009-04-10 16:38:524962// Make sure that we recycle a socket after a zero-length response.
4963// http://crbug.com/9880
[email protected]23e482282013-06-14 16:08:024964TEST_P(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) {
[email protected]1c773ea12009-04-28 19:58:424965 HttpRequestInfo request;
[email protected]b4404c02009-04-10 16:38:524966 request.method = "GET";
4967 request.url = GURL("http://www.google.com/csi?v=3&s=web&action=&"
4968 "tran=undefined&ei=mAXcSeegAo-SMurloeUN&"
4969 "e=17259,18167,19592,19773,19981,20133,20173,20233&"
4970 "rt=prt.2642,ol.2649,xjs.2951");
4971 request.load_flags = 0;
4972
[email protected]bb88e1d32013-05-03 23:11:074973 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:274974
[email protected]262eec82013-03-19 21:01:364975 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:504976 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:274977
[email protected]b4404c02009-04-10 16:38:524978 MockRead data_reads[] = {
4979 MockRead("HTTP/1.1 204 No Content\r\n"
4980 "Content-Length: 0\r\n"
4981 "Content-Type: text/html\r\n\r\n"),
4982 MockRead("junk"), // Should not be read!!
[email protected]8ddf8322012-02-23 18:08:064983 MockRead(SYNCHRONOUS, OK),
[email protected]b4404c02009-04-10 16:38:524984 };
4985
[email protected]31a2bfe2010-02-09 08:03:394986 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:074987 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]b4404c02009-04-10 16:38:524988
[email protected]49639fa2011-12-20 23:22:414989 TestCompletionCallback callback;
[email protected]b4404c02009-04-10 16:38:524990
[email protected]49639fa2011-12-20 23:22:414991 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:424992 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]b4404c02009-04-10 16:38:524993
4994 rv = callback.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:424995 EXPECT_EQ(OK, rv);
[email protected]b4404c02009-04-10 16:38:524996
[email protected]1c773ea12009-04-28 19:58:424997 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:504998 ASSERT_TRUE(response != NULL);
[email protected]b4404c02009-04-10 16:38:524999
[email protected]90499482013-06-01 00:39:505000 EXPECT_TRUE(response->headers.get() != NULL);
[email protected]b4404c02009-04-10 16:38:525001 std::string status_line = response->headers->GetStatusLine();
5002 EXPECT_EQ("HTTP/1.1 204 No Content", status_line);
5003
[email protected]90499482013-06-01 00:39:505004 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get()));
[email protected]b4404c02009-04-10 16:38:525005
5006 std::string response_data;
5007 rv = ReadTransaction(trans.get(), &response_data);
[email protected]1c773ea12009-04-28 19:58:425008 EXPECT_EQ(OK, rv);
[email protected]b4404c02009-04-10 16:38:525009 EXPECT_EQ("", response_data);
5010
5011 // Empty the current queue. This is necessary because idle sockets are
5012 // added to the connection pool asynchronously with a PostTask.
[email protected]2da659e2013-05-23 20:51:345013 base::MessageLoop::current()->RunUntilIdle();
[email protected]b4404c02009-04-10 16:38:525014
5015 // We now check to make sure the socket was added back to the pool.
[email protected]90499482013-06-01 00:39:505016 EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get()));
[email protected]b4404c02009-04-10 16:38:525017}
5018
[email protected]23e482282013-06-14 16:08:025019TEST_P(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) {
[email protected]b2d26cfd2012-12-11 10:36:065020 ScopedVector<UploadElementReader> element_readers;
5021 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:075022 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]329b68b2012-11-14 17:54:275023
[email protected]1c773ea12009-04-28 19:58:425024 HttpRequestInfo request[2];
[email protected]372d34a2008-11-05 21:30:515025 // Transaction 1: a GET request that succeeds. The socket is recycled
5026 // after use.
5027 request[0].method = "GET";
5028 request[0].url = GURL("http://www.google.com/");
5029 request[0].load_flags = 0;
5030 // Transaction 2: a POST request. Reuses the socket kept alive from
5031 // transaction 1. The first attempts fails when writing the POST data.
5032 // This causes the transaction to retry with a new socket. The second
5033 // attempt succeeds.
5034 request[1].method = "POST";
5035 request[1].url = GURL("http://www.google.com/login.cgi");
[email protected]329b68b2012-11-14 17:54:275036 request[1].upload_data_stream = &upload_data_stream;
[email protected]372d34a2008-11-05 21:30:515037 request[1].load_flags = 0;
5038
[email protected]bb88e1d32013-05-03 23:11:075039 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]372d34a2008-11-05 21:30:515040
5041 // The first socket is used for transaction 1 and the first attempt of
5042 // transaction 2.
5043
5044 // The response of transaction 1.
5045 MockRead data_reads1[] = {
5046 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"),
5047 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:065048 MockRead(SYNCHRONOUS, OK),
[email protected]372d34a2008-11-05 21:30:515049 };
5050 // The mock write results of transaction 1 and the first attempt of
5051 // transaction 2.
5052 MockWrite data_writes1[] = {
[email protected]8ddf8322012-02-23 18:08:065053 MockWrite(SYNCHRONOUS, 64), // GET
5054 MockWrite(SYNCHRONOUS, 93), // POST
5055 MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data
[email protected]372d34a2008-11-05 21:30:515056 };
[email protected]31a2bfe2010-02-09 08:03:395057 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
5058 data_writes1, arraysize(data_writes1));
[email protected]372d34a2008-11-05 21:30:515059
5060 // The second socket is used for the second attempt of transaction 2.
5061
5062 // The response of transaction 2.
5063 MockRead data_reads2[] = {
5064 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"),
5065 MockRead("welcome"),
[email protected]8ddf8322012-02-23 18:08:065066 MockRead(SYNCHRONOUS, OK),
[email protected]372d34a2008-11-05 21:30:515067 };
5068 // The mock write results of the second attempt of transaction 2.
5069 MockWrite data_writes2[] = {
[email protected]8ddf8322012-02-23 18:08:065070 MockWrite(SYNCHRONOUS, 93), // POST
5071 MockWrite(SYNCHRONOUS, 3), // POST data
[email protected]372d34a2008-11-05 21:30:515072 };
[email protected]31a2bfe2010-02-09 08:03:395073 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
5074 data_writes2, arraysize(data_writes2));
[email protected]372d34a2008-11-05 21:30:515075
[email protected]bb88e1d32013-05-03 23:11:075076 session_deps_.socket_factory->AddSocketDataProvider(&data1);
5077 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]372d34a2008-11-05 21:30:515078
5079 const char* kExpectedResponseData[] = {
5080 "hello world", "welcome"
5081 };
5082
5083 for (int i = 0; i < 2; ++i) {
[email protected]1c773ea12009-04-28 19:58:425084 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:505085 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]372d34a2008-11-05 21:30:515086
[email protected]49639fa2011-12-20 23:22:415087 TestCompletionCallback callback;
[email protected]372d34a2008-11-05 21:30:515088
[email protected]49639fa2011-12-20 23:22:415089 int rv = trans->Start(&request[i], callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:425090 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]372d34a2008-11-05 21:30:515091
5092 rv = callback.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:425093 EXPECT_EQ(OK, rv);
[email protected]372d34a2008-11-05 21:30:515094
[email protected]1c773ea12009-04-28 19:58:425095 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:505096 ASSERT_TRUE(response != NULL);
[email protected]372d34a2008-11-05 21:30:515097
[email protected]90499482013-06-01 00:39:505098 EXPECT_TRUE(response->headers.get() != NULL);
[email protected]372d34a2008-11-05 21:30:515099 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
5100
5101 std::string response_data;
5102 rv = ReadTransaction(trans.get(), &response_data);
[email protected]1c773ea12009-04-28 19:58:425103 EXPECT_EQ(OK, rv);
[email protected]372d34a2008-11-05 21:30:515104 EXPECT_EQ(kExpectedResponseData[i], response_data);
5105 }
5106}
[email protected]f9ee6b52008-11-08 06:46:235107
5108// Test the request-challenge-retry sequence for basic auth when there is
5109// an identity in the URL. The request should be sent as normal, but when
[email protected]2262e3a2012-05-22 16:08:165110// it fails the identity from the URL is used to answer the challenge.
[email protected]23e482282013-06-14 16:08:025111TEST_P(HttpNetworkTransactionTest, AuthIdentityInURL) {
[email protected]1c773ea12009-04-28 19:58:425112 HttpRequestInfo request;
[email protected]f9ee6b52008-11-08 06:46:235113 request.method = "GET";
[email protected]a97cca42009-08-14 01:00:295114 request.url = GURL("http://foo:b@[email protected]/");
[email protected]7b08ba62012-02-10 20:19:415115 request.load_flags = LOAD_NORMAL;
[email protected]a97cca42009-08-14 01:00:295116
[email protected]3fe8d2f82013-10-17 08:56:075117 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:275118 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:415119 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:275120
[email protected]a97cca42009-08-14 01:00:295121 // The password contains an escaped character -- for this test to pass it
5122 // will need to be unescaped by HttpNetworkTransaction.
5123 EXPECT_EQ("b%40r", request.url.password());
5124
[email protected]f9ee6b52008-11-08 06:46:235125 MockWrite data_writes1[] = {
5126 MockWrite("GET / HTTP/1.1\r\n"
5127 "Host: www.google.com\r\n"
5128 "Connection: keep-alive\r\n\r\n"),
5129 };
5130
5131 MockRead data_reads1[] = {
5132 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
5133 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
5134 MockRead("Content-Length: 10\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:065135 MockRead(SYNCHRONOUS, ERR_FAILED),
[email protected]f9ee6b52008-11-08 06:46:235136 };
5137
[email protected]2262e3a2012-05-22 16:08:165138 // After the challenge above, the transaction will be restarted using the
5139 // identity from the url (foo, b@r) to answer the challenge.
5140 MockWrite data_writes2[] = {
5141 MockWrite("GET / HTTP/1.1\r\n"
5142 "Host: www.google.com\r\n"
5143 "Connection: keep-alive\r\n"
5144 "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"),
5145 };
5146
5147 MockRead data_reads2[] = {
5148 MockRead("HTTP/1.0 200 OK\r\n"),
5149 MockRead("Content-Length: 100\r\n\r\n"),
5150 MockRead(SYNCHRONOUS, OK),
5151 };
5152
[email protected]31a2bfe2010-02-09 08:03:395153 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
5154 data_writes1, arraysize(data_writes1));
[email protected]2262e3a2012-05-22 16:08:165155 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
5156 data_writes2, arraysize(data_writes2));
[email protected]bb88e1d32013-05-03 23:11:075157 session_deps_.socket_factory->AddSocketDataProvider(&data1);
5158 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]f9ee6b52008-11-08 06:46:235159
[email protected]49639fa2011-12-20 23:22:415160 TestCompletionCallback callback1;
[email protected]49639fa2011-12-20 23:22:415161 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:425162 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]f9ee6b52008-11-08 06:46:235163 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:425164 EXPECT_EQ(OK, rv);
[email protected]2262e3a2012-05-22 16:08:165165 EXPECT_TRUE(trans->IsReadyToRestartForAuth());
5166
5167 TestCompletionCallback callback2;
5168 rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback());
5169 EXPECT_EQ(ERR_IO_PENDING, rv);
5170 rv = callback2.WaitForResult();
5171 EXPECT_EQ(OK, rv);
[email protected]0757e7702009-03-27 04:00:225172 EXPECT_FALSE(trans->IsReadyToRestartForAuth());
5173
[email protected]2262e3a2012-05-22 16:08:165174 const HttpResponseInfo* response = trans->GetResponseInfo();
5175 ASSERT_TRUE(response != NULL);
5176
5177 // There is no challenge info, since the identity in URL worked.
5178 EXPECT_TRUE(response->auth_challenge.get() == NULL);
5179
5180 EXPECT_EQ(100, response->headers->GetContentLength());
5181
5182 // Empty the current queue.
[email protected]2da659e2013-05-23 20:51:345183 base::MessageLoop::current()->RunUntilIdle();
[email protected]2262e3a2012-05-22 16:08:165184}
5185
5186// Test the request-challenge-retry sequence for basic auth when there is an
5187// incorrect identity in the URL. The identity from the URL should be used only
5188// once.
[email protected]23e482282013-06-14 16:08:025189TEST_P(HttpNetworkTransactionTest, WrongAuthIdentityInURL) {
[email protected]2262e3a2012-05-22 16:08:165190 HttpRequestInfo request;
5191 request.method = "GET";
5192 // Note: the URL has a username:password in it. The password "baz" is
5193 // wrong (should be "bar").
5194 request.url = GURL("http://foo:[email protected]/");
5195
5196 request.load_flags = LOAD_NORMAL;
5197
[email protected]3fe8d2f82013-10-17 08:56:075198 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]2262e3a2012-05-22 16:08:165199 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:415200 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]2262e3a2012-05-22 16:08:165201
5202 MockWrite data_writes1[] = {
5203 MockWrite("GET / HTTP/1.1\r\n"
5204 "Host: www.google.com\r\n"
5205 "Connection: keep-alive\r\n\r\n"),
5206 };
5207
5208 MockRead data_reads1[] = {
5209 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
5210 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
5211 MockRead("Content-Length: 10\r\n\r\n"),
5212 MockRead(SYNCHRONOUS, ERR_FAILED),
5213 };
5214
5215 // After the challenge above, the transaction will be restarted using the
5216 // identity from the url (foo, baz) to answer the challenge.
5217 MockWrite data_writes2[] = {
5218 MockWrite("GET / HTTP/1.1\r\n"
5219 "Host: www.google.com\r\n"
5220 "Connection: keep-alive\r\n"
5221 "Authorization: Basic Zm9vOmJheg==\r\n\r\n"),
5222 };
5223
5224 MockRead data_reads2[] = {
5225 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
5226 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
5227 MockRead("Content-Length: 10\r\n\r\n"),
5228 MockRead(SYNCHRONOUS, ERR_FAILED),
5229 };
5230
5231 // After the challenge above, the transaction will be restarted using the
5232 // identity supplied by the user (foo, bar) to answer the challenge.
5233 MockWrite data_writes3[] = {
5234 MockWrite("GET / HTTP/1.1\r\n"
5235 "Host: www.google.com\r\n"
5236 "Connection: keep-alive\r\n"
5237 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
5238 };
5239
5240 MockRead data_reads3[] = {
5241 MockRead("HTTP/1.0 200 OK\r\n"),
5242 MockRead("Content-Length: 100\r\n\r\n"),
5243 MockRead(SYNCHRONOUS, OK),
5244 };
5245
5246 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
5247 data_writes1, arraysize(data_writes1));
5248 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
5249 data_writes2, arraysize(data_writes2));
5250 StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3),
5251 data_writes3, arraysize(data_writes3));
[email protected]bb88e1d32013-05-03 23:11:075252 session_deps_.socket_factory->AddSocketDataProvider(&data1);
5253 session_deps_.socket_factory->AddSocketDataProvider(&data2);
5254 session_deps_.socket_factory->AddSocketDataProvider(&data3);
[email protected]2262e3a2012-05-22 16:08:165255
5256 TestCompletionCallback callback1;
5257
5258 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
5259 EXPECT_EQ(ERR_IO_PENDING, rv);
5260
5261 rv = callback1.WaitForResult();
5262 EXPECT_EQ(OK, rv);
5263
5264 EXPECT_TRUE(trans->IsReadyToRestartForAuth());
5265 TestCompletionCallback callback2;
5266 rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback());
5267 EXPECT_EQ(ERR_IO_PENDING, rv);
5268 rv = callback2.WaitForResult();
5269 EXPECT_EQ(OK, rv);
5270 EXPECT_FALSE(trans->IsReadyToRestartForAuth());
5271
5272 const HttpResponseInfo* response = trans->GetResponseInfo();
5273 ASSERT_TRUE(response != NULL);
5274 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
5275
5276 TestCompletionCallback callback3;
5277 rv = trans->RestartWithAuth(
5278 AuthCredentials(kFoo, kBar), callback3.callback());
5279 EXPECT_EQ(ERR_IO_PENDING, rv);
5280 rv = callback3.WaitForResult();
5281 EXPECT_EQ(OK, rv);
5282 EXPECT_FALSE(trans->IsReadyToRestartForAuth());
5283
5284 response = trans->GetResponseInfo();
5285 ASSERT_TRUE(response != NULL);
5286
5287 // There is no challenge info, since the identity worked.
5288 EXPECT_TRUE(response->auth_challenge.get() == NULL);
5289
5290 EXPECT_EQ(100, response->headers->GetContentLength());
5291
[email protected]ea9dc9a2009-09-05 00:43:325292 // Empty the current queue.
[email protected]2da659e2013-05-23 20:51:345293 base::MessageLoop::current()->RunUntilIdle();
[email protected]ea9dc9a2009-09-05 00:43:325294}
5295
[email protected]2217aa22013-10-11 03:03:545296
5297// Test the request-challenge-retry sequence for basic auth when there is a
5298// correct identity in the URL, but its use is being suppressed. The identity
5299// from the URL should never be used.
5300TEST_P(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) {
5301 HttpRequestInfo request;
5302 request.method = "GET";
5303 request.url = GURL("http://foo:[email protected]/");
5304 request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY;
5305
[email protected]3fe8d2f82013-10-17 08:56:075306 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]2217aa22013-10-11 03:03:545307 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:415308 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]2217aa22013-10-11 03:03:545309
5310 MockWrite data_writes1[] = {
5311 MockWrite("GET / HTTP/1.1\r\n"
5312 "Host: www.google.com\r\n"
5313 "Connection: keep-alive\r\n\r\n"),
5314 };
5315
5316 MockRead data_reads1[] = {
5317 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
5318 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
5319 MockRead("Content-Length: 10\r\n\r\n"),
5320 MockRead(SYNCHRONOUS, ERR_FAILED),
5321 };
5322
5323 // After the challenge above, the transaction will be restarted using the
5324 // identity supplied by the user, not the one in the URL, to answer the
5325 // challenge.
5326 MockWrite data_writes3[] = {
5327 MockWrite("GET / HTTP/1.1\r\n"
5328 "Host: www.google.com\r\n"
5329 "Connection: keep-alive\r\n"
5330 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
5331 };
5332
5333 MockRead data_reads3[] = {
5334 MockRead("HTTP/1.0 200 OK\r\n"),
5335 MockRead("Content-Length: 100\r\n\r\n"),
5336 MockRead(SYNCHRONOUS, OK),
5337 };
5338
5339 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
5340 data_writes1, arraysize(data_writes1));
5341 StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3),
5342 data_writes3, arraysize(data_writes3));
5343 session_deps_.socket_factory->AddSocketDataProvider(&data1);
5344 session_deps_.socket_factory->AddSocketDataProvider(&data3);
5345
5346 TestCompletionCallback callback1;
5347 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
5348 EXPECT_EQ(ERR_IO_PENDING, rv);
5349 rv = callback1.WaitForResult();
5350 EXPECT_EQ(OK, rv);
5351 EXPECT_FALSE(trans->IsReadyToRestartForAuth());
5352
5353 const HttpResponseInfo* response = trans->GetResponseInfo();
5354 ASSERT_TRUE(response != NULL);
5355 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
5356
5357 TestCompletionCallback callback3;
5358 rv = trans->RestartWithAuth(
5359 AuthCredentials(kFoo, kBar), callback3.callback());
5360 EXPECT_EQ(ERR_IO_PENDING, rv);
5361 rv = callback3.WaitForResult();
5362 EXPECT_EQ(OK, rv);
5363 EXPECT_FALSE(trans->IsReadyToRestartForAuth());
5364
5365 response = trans->GetResponseInfo();
5366 ASSERT_TRUE(response != NULL);
5367
5368 // There is no challenge info, since the identity worked.
5369 EXPECT_TRUE(response->auth_challenge.get() == NULL);
5370 EXPECT_EQ(100, response->headers->GetContentLength());
5371
5372 // Empty the current queue.
5373 base::MessageLoop::current()->RunUntilIdle();
5374}
5375
[email protected]f9ee6b52008-11-08 06:46:235376// Test that previously tried username/passwords for a realm get re-used.
[email protected]23e482282013-06-14 16:08:025377TEST_P(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) {
[email protected]bb88e1d32013-05-03 23:11:075378 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]f9ee6b52008-11-08 06:46:235379
5380 // Transaction 1: authenticate (foo, bar) on MyRealm1
5381 {
[email protected]1c773ea12009-04-28 19:58:425382 HttpRequestInfo request;
[email protected]f9ee6b52008-11-08 06:46:235383 request.method = "GET";
5384 request.url = GURL("http://www.google.com/x/y/z");
5385 request.load_flags = 0;
5386
[email protected]262eec82013-03-19 21:01:365387 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:505388 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:275389
[email protected]f9ee6b52008-11-08 06:46:235390 MockWrite data_writes1[] = {
5391 MockWrite("GET /x/y/z HTTP/1.1\r\n"
5392 "Host: www.google.com\r\n"
5393 "Connection: keep-alive\r\n\r\n"),
5394 };
5395
5396 MockRead data_reads1[] = {
5397 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
5398 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
5399 MockRead("Content-Length: 10000\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:065400 MockRead(SYNCHRONOUS, ERR_FAILED),
[email protected]f9ee6b52008-11-08 06:46:235401 };
5402
5403 // Resend with authorization (username=foo, password=bar)
5404 MockWrite data_writes2[] = {
5405 MockWrite("GET /x/y/z HTTP/1.1\r\n"
5406 "Host: www.google.com\r\n"
5407 "Connection: keep-alive\r\n"
5408 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
5409 };
5410
5411 // Sever accepts the authorization.
5412 MockRead data_reads2[] = {
5413 MockRead("HTTP/1.0 200 OK\r\n"),
5414 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:065415 MockRead(SYNCHRONOUS, OK),
[email protected]f9ee6b52008-11-08 06:46:235416 };
5417
[email protected]31a2bfe2010-02-09 08:03:395418 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
5419 data_writes1, arraysize(data_writes1));
5420 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
5421 data_writes2, arraysize(data_writes2));
[email protected]bb88e1d32013-05-03 23:11:075422 session_deps_.socket_factory->AddSocketDataProvider(&data1);
5423 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]f9ee6b52008-11-08 06:46:235424
[email protected]49639fa2011-12-20 23:22:415425 TestCompletionCallback callback1;
[email protected]f9ee6b52008-11-08 06:46:235426
[email protected]49639fa2011-12-20 23:22:415427 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:425428 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]f9ee6b52008-11-08 06:46:235429
5430 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:425431 EXPECT_EQ(OK, rv);
[email protected]f9ee6b52008-11-08 06:46:235432
[email protected]1c773ea12009-04-28 19:58:425433 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:505434 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:045435 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
[email protected]f9ee6b52008-11-08 06:46:235436
[email protected]49639fa2011-12-20 23:22:415437 TestCompletionCallback callback2;
[email protected]f9ee6b52008-11-08 06:46:235438
[email protected]49639fa2011-12-20 23:22:415439 rv = trans->RestartWithAuth(
5440 AuthCredentials(kFoo, kBar), callback2.callback());
[email protected]1c773ea12009-04-28 19:58:425441 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]f9ee6b52008-11-08 06:46:235442
5443 rv = callback2.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:425444 EXPECT_EQ(OK, rv);
[email protected]f9ee6b52008-11-08 06:46:235445
5446 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:505447 ASSERT_TRUE(response != NULL);
[email protected]f9ee6b52008-11-08 06:46:235448 EXPECT_TRUE(response->auth_challenge.get() == NULL);
5449 EXPECT_EQ(100, response->headers->GetContentLength());
5450 }
5451
5452 // ------------------------------------------------------------------------
5453
5454 // Transaction 2: authenticate (foo2, bar2) on MyRealm2
5455 {
[email protected]1c773ea12009-04-28 19:58:425456 HttpRequestInfo request;
[email protected]f9ee6b52008-11-08 06:46:235457 request.method = "GET";
5458 // Note that Transaction 1 was at /x/y/z, so this is in the same
5459 // protection space as MyRealm1.
5460 request.url = GURL("http://www.google.com/x/y/a/b");
5461 request.load_flags = 0;
5462
[email protected]262eec82013-03-19 21:01:365463 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:505464 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:275465
[email protected]f9ee6b52008-11-08 06:46:235466 MockWrite data_writes1[] = {
5467 MockWrite("GET /x/y/a/b HTTP/1.1\r\n"
5468 "Host: www.google.com\r\n"
5469 "Connection: keep-alive\r\n"
5470 // Send preemptive authorization for MyRealm1
5471 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
5472 };
5473
5474 // The server didn't like the preemptive authorization, and
5475 // challenges us for a different realm (MyRealm2).
5476 MockRead data_reads1[] = {
5477 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
5478 MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"),
5479 MockRead("Content-Length: 10000\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:065480 MockRead(SYNCHRONOUS, ERR_FAILED),
[email protected]f9ee6b52008-11-08 06:46:235481 };
5482
5483 // Resend with authorization for MyRealm2 (username=foo2, password=bar2)
5484 MockWrite data_writes2[] = {
5485 MockWrite("GET /x/y/a/b HTTP/1.1\r\n"
5486 "Host: www.google.com\r\n"
5487 "Connection: keep-alive\r\n"
5488 "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"),
5489 };
5490
5491 // Sever accepts the authorization.
5492 MockRead data_reads2[] = {
5493 MockRead("HTTP/1.0 200 OK\r\n"),
5494 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:065495 MockRead(SYNCHRONOUS, OK),
[email protected]f9ee6b52008-11-08 06:46:235496 };
5497
[email protected]31a2bfe2010-02-09 08:03:395498 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
5499 data_writes1, arraysize(data_writes1));
5500 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
5501 data_writes2, arraysize(data_writes2));
[email protected]bb88e1d32013-05-03 23:11:075502 session_deps_.socket_factory->AddSocketDataProvider(&data1);
5503 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]f9ee6b52008-11-08 06:46:235504
[email protected]49639fa2011-12-20 23:22:415505 TestCompletionCallback callback1;
[email protected]f9ee6b52008-11-08 06:46:235506
[email protected]49639fa2011-12-20 23:22:415507 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:425508 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]f9ee6b52008-11-08 06:46:235509
5510 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:425511 EXPECT_EQ(OK, rv);
[email protected]f9ee6b52008-11-08 06:46:235512
[email protected]1c773ea12009-04-28 19:58:425513 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:505514 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:045515 ASSERT_TRUE(response->auth_challenge.get());
5516 EXPECT_FALSE(response->auth_challenge->is_proxy);
5517 EXPECT_EQ("www.google.com:80",
5518 response->auth_challenge->challenger.ToString());
5519 EXPECT_EQ("MyRealm2", response->auth_challenge->realm);
5520 EXPECT_EQ("basic", response->auth_challenge->scheme);
[email protected]f9ee6b52008-11-08 06:46:235521
[email protected]49639fa2011-12-20 23:22:415522 TestCompletionCallback callback2;
[email protected]f9ee6b52008-11-08 06:46:235523
[email protected]49639fa2011-12-20 23:22:415524 rv = trans->RestartWithAuth(
5525 AuthCredentials(kFoo2, kBar2), callback2.callback());
[email protected]1c773ea12009-04-28 19:58:425526 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]f9ee6b52008-11-08 06:46:235527
5528 rv = callback2.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:425529 EXPECT_EQ(OK, rv);
[email protected]f9ee6b52008-11-08 06:46:235530
5531 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:505532 ASSERT_TRUE(response != NULL);
[email protected]f9ee6b52008-11-08 06:46:235533 EXPECT_TRUE(response->auth_challenge.get() == NULL);
5534 EXPECT_EQ(100, response->headers->GetContentLength());
5535 }
5536
5537 // ------------------------------------------------------------------------
5538
5539 // Transaction 3: Resend a request in MyRealm's protection space --
5540 // succeed with preemptive authorization.
5541 {
[email protected]1c773ea12009-04-28 19:58:425542 HttpRequestInfo request;
[email protected]f9ee6b52008-11-08 06:46:235543 request.method = "GET";
5544 request.url = GURL("http://www.google.com/x/y/z2");
5545 request.load_flags = 0;
5546
[email protected]262eec82013-03-19 21:01:365547 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:505548 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:275549
[email protected]f9ee6b52008-11-08 06:46:235550 MockWrite data_writes1[] = {
5551 MockWrite("GET /x/y/z2 HTTP/1.1\r\n"
5552 "Host: www.google.com\r\n"
5553 "Connection: keep-alive\r\n"
5554 // The authorization for MyRealm1 gets sent preemptively
5555 // (since the url is in the same protection space)
5556 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
5557 };
5558
5559 // Sever accepts the preemptive authorization
5560 MockRead data_reads1[] = {
5561 MockRead("HTTP/1.0 200 OK\r\n"),
5562 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:065563 MockRead(SYNCHRONOUS, OK),
[email protected]f9ee6b52008-11-08 06:46:235564 };
5565
[email protected]31a2bfe2010-02-09 08:03:395566 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
5567 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:075568 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]f9ee6b52008-11-08 06:46:235569
[email protected]49639fa2011-12-20 23:22:415570 TestCompletionCallback callback1;
[email protected]f9ee6b52008-11-08 06:46:235571
[email protected]49639fa2011-12-20 23:22:415572 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:425573 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]f9ee6b52008-11-08 06:46:235574
5575 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:425576 EXPECT_EQ(OK, rv);
[email protected]f9ee6b52008-11-08 06:46:235577
[email protected]1c773ea12009-04-28 19:58:425578 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:505579 ASSERT_TRUE(response != NULL);
[email protected]f9ee6b52008-11-08 06:46:235580
5581 EXPECT_TRUE(response->auth_challenge.get() == NULL);
5582 EXPECT_EQ(100, response->headers->GetContentLength());
5583 }
5584
5585 // ------------------------------------------------------------------------
5586
5587 // Transaction 4: request another URL in MyRealm (however the
5588 // url is not known to belong to the protection space, so no pre-auth).
5589 {
[email protected]1c773ea12009-04-28 19:58:425590 HttpRequestInfo request;
[email protected]f9ee6b52008-11-08 06:46:235591 request.method = "GET";
5592 request.url = GURL("http://www.google.com/x/1");
5593 request.load_flags = 0;
5594
[email protected]262eec82013-03-19 21:01:365595 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:505596 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:275597
[email protected]f9ee6b52008-11-08 06:46:235598 MockWrite data_writes1[] = {
5599 MockWrite("GET /x/1 HTTP/1.1\r\n"
5600 "Host: www.google.com\r\n"
5601 "Connection: keep-alive\r\n\r\n"),
5602 };
5603
5604 MockRead data_reads1[] = {
5605 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
5606 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
5607 MockRead("Content-Length: 10000\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:065608 MockRead(SYNCHRONOUS, ERR_FAILED),
[email protected]f9ee6b52008-11-08 06:46:235609 };
5610
5611 // Resend with authorization from MyRealm's cache.
5612 MockWrite data_writes2[] = {
5613 MockWrite("GET /x/1 HTTP/1.1\r\n"
5614 "Host: www.google.com\r\n"
5615 "Connection: keep-alive\r\n"
5616 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
5617 };
5618
5619 // Sever accepts the authorization.
5620 MockRead data_reads2[] = {
5621 MockRead("HTTP/1.0 200 OK\r\n"),
5622 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:065623 MockRead(SYNCHRONOUS, OK),
[email protected]f9ee6b52008-11-08 06:46:235624 };
5625
[email protected]31a2bfe2010-02-09 08:03:395626 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
5627 data_writes1, arraysize(data_writes1));
5628 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
5629 data_writes2, arraysize(data_writes2));
[email protected]bb88e1d32013-05-03 23:11:075630 session_deps_.socket_factory->AddSocketDataProvider(&data1);
5631 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]f9ee6b52008-11-08 06:46:235632
[email protected]49639fa2011-12-20 23:22:415633 TestCompletionCallback callback1;
[email protected]f9ee6b52008-11-08 06:46:235634
[email protected]49639fa2011-12-20 23:22:415635 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:425636 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]f9ee6b52008-11-08 06:46:235637
5638 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:425639 EXPECT_EQ(OK, rv);
[email protected]f9ee6b52008-11-08 06:46:235640
[email protected]0757e7702009-03-27 04:00:225641 EXPECT_TRUE(trans->IsReadyToRestartForAuth());
[email protected]49639fa2011-12-20 23:22:415642 TestCompletionCallback callback2;
5643 rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback());
[email protected]1c773ea12009-04-28 19:58:425644 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]0757e7702009-03-27 04:00:225645 rv = callback2.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:425646 EXPECT_EQ(OK, rv);
[email protected]0757e7702009-03-27 04:00:225647 EXPECT_FALSE(trans->IsReadyToRestartForAuth());
5648
[email protected]1c773ea12009-04-28 19:58:425649 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:505650 ASSERT_TRUE(response != NULL);
[email protected]f9ee6b52008-11-08 06:46:235651 EXPECT_TRUE(response->auth_challenge.get() == NULL);
5652 EXPECT_EQ(100, response->headers->GetContentLength());
5653 }
5654
5655 // ------------------------------------------------------------------------
5656
5657 // Transaction 5: request a URL in MyRealm, but the server rejects the
5658 // cached identity. Should invalidate and re-prompt.
5659 {
[email protected]1c773ea12009-04-28 19:58:425660 HttpRequestInfo request;
[email protected]f9ee6b52008-11-08 06:46:235661 request.method = "GET";
5662 request.url = GURL("http://www.google.com/p/q/t");
5663 request.load_flags = 0;
5664
[email protected]262eec82013-03-19 21:01:365665 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:505666 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:275667
[email protected]f9ee6b52008-11-08 06:46:235668 MockWrite data_writes1[] = {
5669 MockWrite("GET /p/q/t HTTP/1.1\r\n"
5670 "Host: www.google.com\r\n"
5671 "Connection: keep-alive\r\n\r\n"),
5672 };
5673
5674 MockRead data_reads1[] = {
5675 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
5676 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
5677 MockRead("Content-Length: 10000\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:065678 MockRead(SYNCHRONOUS, ERR_FAILED),
[email protected]f9ee6b52008-11-08 06:46:235679 };
5680
5681 // Resend with authorization from cache for MyRealm.
5682 MockWrite data_writes2[] = {
5683 MockWrite("GET /p/q/t HTTP/1.1\r\n"
5684 "Host: www.google.com\r\n"
5685 "Connection: keep-alive\r\n"
5686 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
5687 };
5688
5689 // Sever rejects the authorization.
5690 MockRead data_reads2[] = {
5691 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
5692 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
5693 MockRead("Content-Length: 10000\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:065694 MockRead(SYNCHRONOUS, ERR_FAILED),
[email protected]f9ee6b52008-11-08 06:46:235695 };
5696
5697 // At this point we should prompt for new credentials for MyRealm.
5698 // Restart with username=foo3, password=foo4.
5699 MockWrite data_writes3[] = {
5700 MockWrite("GET /p/q/t HTTP/1.1\r\n"
5701 "Host: www.google.com\r\n"
5702 "Connection: keep-alive\r\n"
5703 "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"),
5704 };
5705
5706 // Sever accepts the authorization.
5707 MockRead data_reads3[] = {
5708 MockRead("HTTP/1.0 200 OK\r\n"),
5709 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:065710 MockRead(SYNCHRONOUS, OK),
[email protected]f9ee6b52008-11-08 06:46:235711 };
5712
[email protected]31a2bfe2010-02-09 08:03:395713 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
5714 data_writes1, arraysize(data_writes1));
5715 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
5716 data_writes2, arraysize(data_writes2));
5717 StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3),
5718 data_writes3, arraysize(data_writes3));
[email protected]bb88e1d32013-05-03 23:11:075719 session_deps_.socket_factory->AddSocketDataProvider(&data1);
5720 session_deps_.socket_factory->AddSocketDataProvider(&data2);
5721 session_deps_.socket_factory->AddSocketDataProvider(&data3);
[email protected]f9ee6b52008-11-08 06:46:235722
[email protected]49639fa2011-12-20 23:22:415723 TestCompletionCallback callback1;
[email protected]f9ee6b52008-11-08 06:46:235724
[email protected]49639fa2011-12-20 23:22:415725 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:425726 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]f9ee6b52008-11-08 06:46:235727
5728 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:425729 EXPECT_EQ(OK, rv);
[email protected]f9ee6b52008-11-08 06:46:235730
[email protected]0757e7702009-03-27 04:00:225731 EXPECT_TRUE(trans->IsReadyToRestartForAuth());
[email protected]49639fa2011-12-20 23:22:415732 TestCompletionCallback callback2;
5733 rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback());
[email protected]1c773ea12009-04-28 19:58:425734 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]0757e7702009-03-27 04:00:225735 rv = callback2.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:425736 EXPECT_EQ(OK, rv);
[email protected]0757e7702009-03-27 04:00:225737 EXPECT_FALSE(trans->IsReadyToRestartForAuth());
5738
[email protected]1c773ea12009-04-28 19:58:425739 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:505740 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:045741 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
[email protected]f9ee6b52008-11-08 06:46:235742
[email protected]49639fa2011-12-20 23:22:415743 TestCompletionCallback callback3;
[email protected]f9ee6b52008-11-08 06:46:235744
[email protected]49639fa2011-12-20 23:22:415745 rv = trans->RestartWithAuth(
5746 AuthCredentials(kFoo3, kBar3), callback3.callback());
[email protected]1c773ea12009-04-28 19:58:425747 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]f9ee6b52008-11-08 06:46:235748
[email protected]0757e7702009-03-27 04:00:225749 rv = callback3.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:425750 EXPECT_EQ(OK, rv);
[email protected]f9ee6b52008-11-08 06:46:235751
5752 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:505753 ASSERT_TRUE(response != NULL);
[email protected]f9ee6b52008-11-08 06:46:235754 EXPECT_TRUE(response->auth_challenge.get() == NULL);
5755 EXPECT_EQ(100, response->headers->GetContentLength());
5756 }
5757}
[email protected]89ceba9a2009-03-21 03:46:065758
[email protected]3c32c5f2010-05-18 15:18:125759// Tests that nonce count increments when multiple auth attempts
5760// are started with the same nonce.
[email protected]23e482282013-06-14 16:08:025761TEST_P(HttpNetworkTransactionTest, DigestPreAuthNonceCount) {
[email protected]54fea2562010-11-17 14:40:445762 HttpAuthHandlerDigest::Factory* digest_factory =
5763 new HttpAuthHandlerDigest::Factory();
5764 HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator =
5765 new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef");
5766 digest_factory->set_nonce_generator(nonce_generator);
[email protected]bb88e1d32013-05-03 23:11:075767 session_deps_.http_auth_handler_factory.reset(digest_factory);
5768 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]3c32c5f2010-05-18 15:18:125769
5770 // Transaction 1: authenticate (foo, bar) on MyRealm1
5771 {
[email protected]3c32c5f2010-05-18 15:18:125772 HttpRequestInfo request;
5773 request.method = "GET";
5774 request.url = GURL("http://www.google.com/x/y/z");
5775 request.load_flags = 0;
5776
[email protected]262eec82013-03-19 21:01:365777 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:505778 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:275779
[email protected]3c32c5f2010-05-18 15:18:125780 MockWrite data_writes1[] = {
5781 MockWrite("GET /x/y/z HTTP/1.1\r\n"
5782 "Host: www.google.com\r\n"
5783 "Connection: keep-alive\r\n\r\n"),
5784 };
5785
5786 MockRead data_reads1[] = {
5787 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
5788 MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", "
5789 "algorithm=MD5, qop=\"auth\"\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:065790 MockRead(SYNCHRONOUS, OK),
[email protected]3c32c5f2010-05-18 15:18:125791 };
5792
5793 // Resend with authorization (username=foo, password=bar)
5794 MockWrite data_writes2[] = {
5795 MockWrite("GET /x/y/z HTTP/1.1\r\n"
5796 "Host: www.google.com\r\n"
5797 "Connection: keep-alive\r\n"
5798 "Authorization: Digest username=\"foo\", realm=\"digestive\", "
5799 "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, "
5800 "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, "
5801 "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"),
5802 };
5803
5804 // Sever accepts the authorization.
5805 MockRead data_reads2[] = {
5806 MockRead("HTTP/1.0 200 OK\r\n"),
[email protected]8ddf8322012-02-23 18:08:065807 MockRead(SYNCHRONOUS, OK),
[email protected]3c32c5f2010-05-18 15:18:125808 };
5809
5810 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
5811 data_writes1, arraysize(data_writes1));
5812 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
5813 data_writes2, arraysize(data_writes2));
[email protected]bb88e1d32013-05-03 23:11:075814 session_deps_.socket_factory->AddSocketDataProvider(&data1);
5815 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]3c32c5f2010-05-18 15:18:125816
[email protected]49639fa2011-12-20 23:22:415817 TestCompletionCallback callback1;
[email protected]3c32c5f2010-05-18 15:18:125818
[email protected]49639fa2011-12-20 23:22:415819 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]3c32c5f2010-05-18 15:18:125820 EXPECT_EQ(ERR_IO_PENDING, rv);
5821
5822 rv = callback1.WaitForResult();
5823 EXPECT_EQ(OK, rv);
5824
5825 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:505826 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:045827 EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get()));
[email protected]3c32c5f2010-05-18 15:18:125828
[email protected]49639fa2011-12-20 23:22:415829 TestCompletionCallback callback2;
[email protected]3c32c5f2010-05-18 15:18:125830
[email protected]49639fa2011-12-20 23:22:415831 rv = trans->RestartWithAuth(
5832 AuthCredentials(kFoo, kBar), callback2.callback());
[email protected]3c32c5f2010-05-18 15:18:125833 EXPECT_EQ(ERR_IO_PENDING, rv);
5834
5835 rv = callback2.WaitForResult();
5836 EXPECT_EQ(OK, rv);
5837
5838 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:505839 ASSERT_TRUE(response != NULL);
[email protected]3c32c5f2010-05-18 15:18:125840 EXPECT_TRUE(response->auth_challenge.get() == NULL);
5841 }
5842
5843 // ------------------------------------------------------------------------
5844
5845 // Transaction 2: Request another resource in digestive's protection space.
5846 // This will preemptively add an Authorization header which should have an
5847 // "nc" value of 2 (as compared to 1 in the first use.
5848 {
[email protected]3c32c5f2010-05-18 15:18:125849 HttpRequestInfo request;
5850 request.method = "GET";
5851 // Note that Transaction 1 was at /x/y/z, so this is in the same
5852 // protection space as digest.
5853 request.url = GURL("http://www.google.com/x/y/a/b");
5854 request.load_flags = 0;
5855
[email protected]262eec82013-03-19 21:01:365856 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:505857 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:275858
[email protected]3c32c5f2010-05-18 15:18:125859 MockWrite data_writes1[] = {
5860 MockWrite("GET /x/y/a/b HTTP/1.1\r\n"
5861 "Host: www.google.com\r\n"
5862 "Connection: keep-alive\r\n"
5863 "Authorization: Digest username=\"foo\", realm=\"digestive\", "
5864 "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, "
5865 "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, "
5866 "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"),
5867 };
5868
5869 // Sever accepts the authorization.
5870 MockRead data_reads1[] = {
5871 MockRead("HTTP/1.0 200 OK\r\n"),
5872 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:065873 MockRead(SYNCHRONOUS, OK),
[email protected]3c32c5f2010-05-18 15:18:125874 };
5875
5876 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
5877 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:075878 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]3c32c5f2010-05-18 15:18:125879
[email protected]49639fa2011-12-20 23:22:415880 TestCompletionCallback callback1;
[email protected]3c32c5f2010-05-18 15:18:125881
[email protected]49639fa2011-12-20 23:22:415882 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]3c32c5f2010-05-18 15:18:125883 EXPECT_EQ(ERR_IO_PENDING, rv);
5884
5885 rv = callback1.WaitForResult();
5886 EXPECT_EQ(OK, rv);
5887
5888 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:505889 ASSERT_TRUE(response != NULL);
[email protected]3c32c5f2010-05-18 15:18:125890 EXPECT_TRUE(response->auth_challenge.get() == NULL);
5891 }
5892}
5893
[email protected]89ceba9a2009-03-21 03:46:065894// Test the ResetStateForRestart() private method.
[email protected]23e482282013-06-14 16:08:025895TEST_P(HttpNetworkTransactionTest, ResetStateForRestart) {
[email protected]89ceba9a2009-03-21 03:46:065896 // Create a transaction (the dependencies aren't important).
[email protected]3fe8d2f82013-10-17 08:56:075897 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]d207a5f2009-06-04 05:28:405898 scoped_ptr<HttpNetworkTransaction> trans(
dcheng48459ac22014-08-26 00:46:415899 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]89ceba9a2009-03-21 03:46:065900
5901 // Setup some state (which we expect ResetStateForRestart() will clear).
[email protected]89ceba9a2009-03-21 03:46:065902 trans->read_buf_ = new IOBuffer(15);
5903 trans->read_buf_len_ = 15;
[email protected]b94f92d2010-10-27 16:45:205904 trans->request_headers_.SetHeader("Authorization", "NTLM");
[email protected]89ceba9a2009-03-21 03:46:065905
5906 // Setup state in response_
[email protected]a7e41312009-12-16 23:18:145907 HttpResponseInfo* response = &trans->response_;
[email protected]0877e3d2009-10-17 22:29:575908 response->auth_challenge = new AuthChallengeInfo();
[email protected]70d66502011-09-23 00:55:085909 response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical.
[email protected]0877e3d2009-10-17 22:29:575910 response->response_time = base::Time::Now();
5911 response->was_cached = true; // (Wouldn't ever actually be true...)
[email protected]89ceba9a2009-03-21 03:46:065912
5913 { // Setup state for response_.vary_data
5914 HttpRequestInfo request;
5915 std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n");
5916 std::replace(temp.begin(), temp.end(), '\n', '\0');
[email protected]ad8e04a2010-11-01 04:16:275917 scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp));
[email protected]8c76ae22010-04-20 22:15:435918 request.extra_headers.SetHeader("Foo", "1");
5919 request.extra_headers.SetHeader("bar", "23");
[email protected]90499482013-06-01 00:39:505920 EXPECT_TRUE(response->vary_data.Init(request, *headers.get()));
[email protected]89ceba9a2009-03-21 03:46:065921 }
5922
5923 // Cause the above state to be reset.
5924 trans->ResetStateForRestart();
5925
5926 // Verify that the state that needed to be reset, has been reset.
[email protected]9b6fee12009-09-29 18:13:075927 EXPECT_TRUE(trans->read_buf_.get() == NULL);
[email protected]89ceba9a2009-03-21 03:46:065928 EXPECT_EQ(0, trans->read_buf_len_);
[email protected]b94f92d2010-10-27 16:45:205929 EXPECT_TRUE(trans->request_headers_.IsEmpty());
[email protected]0877e3d2009-10-17 22:29:575930 EXPECT_TRUE(response->auth_challenge.get() == NULL);
5931 EXPECT_TRUE(response->headers.get() == NULL);
[email protected]34f40942010-10-04 00:34:045932 EXPECT_FALSE(response->was_cached);
[email protected]70d66502011-09-23 00:55:085933 EXPECT_EQ(0U, response->ssl_info.cert_status);
[email protected]0877e3d2009-10-17 22:29:575934 EXPECT_FALSE(response->vary_data.is_valid());
[email protected]89ceba9a2009-03-21 03:46:065935}
5936
[email protected]bacff652009-03-31 17:50:335937// Test HTTPS connections to a site with a bad certificate
[email protected]23e482282013-06-14 16:08:025938TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificate) {
[email protected]bacff652009-03-31 17:50:335939 HttpRequestInfo request;
5940 request.method = "GET";
5941 request.url = GURL("https://www.google.com/");
5942 request.load_flags = 0;
5943
[email protected]3fe8d2f82013-10-17 08:56:075944 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:275945 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:415946 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:275947
[email protected]bacff652009-03-31 17:50:335948 MockWrite data_writes[] = {
5949 MockWrite("GET / HTTP/1.1\r\n"
5950 "Host: www.google.com\r\n"
5951 "Connection: keep-alive\r\n\r\n"),
5952 };
5953
5954 MockRead data_reads[] = {
5955 MockRead("HTTP/1.0 200 OK\r\n"),
5956 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
5957 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:065958 MockRead(SYNCHRONOUS, OK),
[email protected]bacff652009-03-31 17:50:335959 };
5960
[email protected]5ecc992a42009-11-11 01:41:595961 StaticSocketDataProvider ssl_bad_certificate;
[email protected]31a2bfe2010-02-09 08:03:395962 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
5963 data_writes, arraysize(data_writes));
[email protected]8ddf8322012-02-23 18:08:065964 SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID);
5965 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]bacff652009-03-31 17:50:335966
[email protected]bb88e1d32013-05-03 23:11:075967 session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate);
5968 session_deps_.socket_factory->AddSocketDataProvider(&data);
5969 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad);
5970 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]bacff652009-03-31 17:50:335971
[email protected]49639fa2011-12-20 23:22:415972 TestCompletionCallback callback;
[email protected]bacff652009-03-31 17:50:335973
[email protected]49639fa2011-12-20 23:22:415974 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]bacff652009-03-31 17:50:335975 EXPECT_EQ(ERR_IO_PENDING, rv);
5976
5977 rv = callback.WaitForResult();
5978 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv);
5979
[email protected]49639fa2011-12-20 23:22:415980 rv = trans->RestartIgnoringLastError(callback.callback());
[email protected]bacff652009-03-31 17:50:335981 EXPECT_EQ(ERR_IO_PENDING, rv);
5982
5983 rv = callback.WaitForResult();
5984 EXPECT_EQ(OK, rv);
5985
5986 const HttpResponseInfo* response = trans->GetResponseInfo();
5987
[email protected]fe2255a2011-09-20 19:37:505988 ASSERT_TRUE(response != NULL);
[email protected]bacff652009-03-31 17:50:335989 EXPECT_EQ(100, response->headers->GetContentLength());
5990}
5991
5992// Test HTTPS connections to a site with a bad certificate, going through a
5993// proxy
[email protected]23e482282013-06-14 16:08:025994TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) {
[email protected]bb88e1d32013-05-03 23:11:075995 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70"));
[email protected]bacff652009-03-31 17:50:335996
5997 HttpRequestInfo request;
5998 request.method = "GET";
5999 request.url = GURL("https://www.google.com/");
6000 request.load_flags = 0;
6001
6002 MockWrite proxy_writes[] = {
6003 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
[email protected]e44de5d2009-06-05 20:12:456004 "Host: www.google.com\r\n"
6005 "Proxy-Connection: keep-alive\r\n\r\n"),
[email protected]bacff652009-03-31 17:50:336006 };
6007
6008 MockRead proxy_reads[] = {
6009 MockRead("HTTP/1.0 200 Connected\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:066010 MockRead(SYNCHRONOUS, OK)
[email protected]bacff652009-03-31 17:50:336011 };
6012
6013 MockWrite data_writes[] = {
6014 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
[email protected]e44de5d2009-06-05 20:12:456015 "Host: www.google.com\r\n"
6016 "Proxy-Connection: keep-alive\r\n\r\n"),
[email protected]bacff652009-03-31 17:50:336017 MockWrite("GET / HTTP/1.1\r\n"
6018 "Host: www.google.com\r\n"
6019 "Connection: keep-alive\r\n\r\n"),
6020 };
6021
6022 MockRead data_reads[] = {
6023 MockRead("HTTP/1.0 200 Connected\r\n\r\n"),
6024 MockRead("HTTP/1.0 200 OK\r\n"),
6025 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
6026 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:066027 MockRead(SYNCHRONOUS, OK),
[email protected]bacff652009-03-31 17:50:336028 };
6029
[email protected]31a2bfe2010-02-09 08:03:396030 StaticSocketDataProvider ssl_bad_certificate(
6031 proxy_reads, arraysize(proxy_reads),
6032 proxy_writes, arraysize(proxy_writes));
6033 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
6034 data_writes, arraysize(data_writes));
[email protected]8ddf8322012-02-23 18:08:066035 SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID);
6036 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]bacff652009-03-31 17:50:336037
[email protected]bb88e1d32013-05-03 23:11:076038 session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate);
6039 session_deps_.socket_factory->AddSocketDataProvider(&data);
6040 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad);
6041 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]bacff652009-03-31 17:50:336042
[email protected]49639fa2011-12-20 23:22:416043 TestCompletionCallback callback;
[email protected]bacff652009-03-31 17:50:336044
6045 for (int i = 0; i < 2; i++) {
[email protected]bb88e1d32013-05-03 23:11:076046 session_deps_.socket_factory->ResetNextMockIndexes();
[email protected]bacff652009-03-31 17:50:336047
[email protected]3fe8d2f82013-10-17 08:56:076048 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]d207a5f2009-06-04 05:28:406049 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:416050 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]bacff652009-03-31 17:50:336051
[email protected]49639fa2011-12-20 23:22:416052 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]bacff652009-03-31 17:50:336053 EXPECT_EQ(ERR_IO_PENDING, rv);
6054
6055 rv = callback.WaitForResult();
6056 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv);
6057
[email protected]49639fa2011-12-20 23:22:416058 rv = trans->RestartIgnoringLastError(callback.callback());
[email protected]bacff652009-03-31 17:50:336059 EXPECT_EQ(ERR_IO_PENDING, rv);
6060
6061 rv = callback.WaitForResult();
6062 EXPECT_EQ(OK, rv);
6063
6064 const HttpResponseInfo* response = trans->GetResponseInfo();
6065
[email protected]fe2255a2011-09-20 19:37:506066 ASSERT_TRUE(response != NULL);
[email protected]bacff652009-03-31 17:50:336067 EXPECT_EQ(100, response->headers->GetContentLength());
6068 }
6069}
6070
[email protected]2df19bb2010-08-25 20:13:466071
6072// Test HTTPS connections to a site, going through an HTTPS proxy
[email protected]23e482282013-06-14 16:08:026073TEST_P(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) {
[email protected]bb88e1d32013-05-03 23:11:076074 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:206075 ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"));
6076 CapturingNetLog net_log;
[email protected]bb88e1d32013-05-03 23:11:076077 session_deps_.net_log = &net_log;
[email protected]2df19bb2010-08-25 20:13:466078
6079 HttpRequestInfo request;
6080 request.method = "GET";
6081 request.url = GURL("https://www.google.com/");
6082 request.load_flags = 0;
6083
6084 MockWrite data_writes[] = {
6085 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
6086 "Host: www.google.com\r\n"
6087 "Proxy-Connection: keep-alive\r\n\r\n"),
6088 MockWrite("GET / HTTP/1.1\r\n"
6089 "Host: www.google.com\r\n"
6090 "Connection: keep-alive\r\n\r\n"),
6091 };
6092
6093 MockRead data_reads[] = {
6094 MockRead("HTTP/1.0 200 Connected\r\n\r\n"),
6095 MockRead("HTTP/1.1 200 OK\r\n"),
6096 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
6097 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:066098 MockRead(SYNCHRONOUS, OK),
[email protected]2df19bb2010-08-25 20:13:466099 };
6100
6101 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
6102 data_writes, arraysize(data_writes));
[email protected]8ddf8322012-02-23 18:08:066103 SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy
6104 SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel
[email protected]2df19bb2010-08-25 20:13:466105
[email protected]bb88e1d32013-05-03 23:11:076106 session_deps_.socket_factory->AddSocketDataProvider(&data);
6107 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl);
6108 session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl);
[email protected]2df19bb2010-08-25 20:13:466109
[email protected]49639fa2011-12-20 23:22:416110 TestCompletionCallback callback;
[email protected]2df19bb2010-08-25 20:13:466111
[email protected]3fe8d2f82013-10-17 08:56:076112 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]2df19bb2010-08-25 20:13:466113 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:416114 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]2df19bb2010-08-25 20:13:466115
[email protected]49639fa2011-12-20 23:22:416116 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]2df19bb2010-08-25 20:13:466117 EXPECT_EQ(ERR_IO_PENDING, rv);
6118
6119 rv = callback.WaitForResult();
6120 EXPECT_EQ(OK, rv);
6121 const HttpResponseInfo* response = trans->GetResponseInfo();
6122
[email protected]fe2255a2011-09-20 19:37:506123 ASSERT_TRUE(response != NULL);
[email protected]2df19bb2010-08-25 20:13:466124
6125 EXPECT_TRUE(response->headers->IsKeepAlive());
6126 EXPECT_EQ(200, response->headers->response_code());
6127 EXPECT_EQ(100, response->headers->GetContentLength());
6128 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
[email protected]029c83b62013-01-24 05:28:206129
6130 LoadTimingInfo load_timing_info;
6131 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
6132 TestLoadTimingNotReusedWithPac(load_timing_info,
6133 CONNECT_TIMING_HAS_SSL_TIMES);
[email protected]2df19bb2010-08-25 20:13:466134}
6135
[email protected]511f6f52010-12-17 03:58:296136// Test an HTTPS Proxy's ability to redirect a CONNECT request
[email protected]23e482282013-06-14 16:08:026137TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) {
[email protected]bb88e1d32013-05-03 23:11:076138 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:206139 ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"));
6140 CapturingNetLog net_log;
[email protected]bb88e1d32013-05-03 23:11:076141 session_deps_.net_log = &net_log;
[email protected]511f6f52010-12-17 03:58:296142
6143 HttpRequestInfo request;
6144 request.method = "GET";
6145 request.url = GURL("https://www.google.com/");
6146 request.load_flags = 0;
6147
6148 MockWrite data_writes[] = {
6149 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
6150 "Host: www.google.com\r\n"
6151 "Proxy-Connection: keep-alive\r\n\r\n"),
6152 };
6153
6154 MockRead data_reads[] = {
6155 MockRead("HTTP/1.1 302 Redirect\r\n"),
6156 MockRead("Location: http://login.example.com/\r\n"),
6157 MockRead("Content-Length: 0\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:066158 MockRead(SYNCHRONOUS, OK),
[email protected]511f6f52010-12-17 03:58:296159 };
6160
6161 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
6162 data_writes, arraysize(data_writes));
[email protected]8ddf8322012-02-23 18:08:066163 SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy
[email protected]511f6f52010-12-17 03:58:296164
[email protected]bb88e1d32013-05-03 23:11:076165 session_deps_.socket_factory->AddSocketDataProvider(&data);
6166 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl);
[email protected]511f6f52010-12-17 03:58:296167
[email protected]49639fa2011-12-20 23:22:416168 TestCompletionCallback callback;
[email protected]511f6f52010-12-17 03:58:296169
[email protected]3fe8d2f82013-10-17 08:56:076170 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]511f6f52010-12-17 03:58:296171 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:416172 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]511f6f52010-12-17 03:58:296173
[email protected]49639fa2011-12-20 23:22:416174 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]511f6f52010-12-17 03:58:296175 EXPECT_EQ(ERR_IO_PENDING, rv);
6176
6177 rv = callback.WaitForResult();
6178 EXPECT_EQ(OK, rv);
6179 const HttpResponseInfo* response = trans->GetResponseInfo();
6180
[email protected]fe2255a2011-09-20 19:37:506181 ASSERT_TRUE(response != NULL);
[email protected]511f6f52010-12-17 03:58:296182
6183 EXPECT_EQ(302, response->headers->response_code());
6184 std::string url;
6185 EXPECT_TRUE(response->headers->IsRedirect(&url));
6186 EXPECT_EQ("http://login.example.com/", url);
[email protected]029c83b62013-01-24 05:28:206187
6188 // In the case of redirects from proxies, HttpNetworkTransaction returns
6189 // timing for the proxy connection instead of the connection to the host,
6190 // and no send / receive times.
6191 // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse.
6192 LoadTimingInfo load_timing_info;
6193 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
6194
6195 EXPECT_FALSE(load_timing_info.socket_reused);
6196 EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id);
6197
6198 EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null());
6199 EXPECT_LE(load_timing_info.proxy_resolve_start,
6200 load_timing_info.proxy_resolve_end);
6201 EXPECT_LE(load_timing_info.proxy_resolve_end,
6202 load_timing_info.connect_timing.connect_start);
6203 ExpectConnectTimingHasTimes(
6204 load_timing_info.connect_timing,
6205 CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES);
6206
6207 EXPECT_TRUE(load_timing_info.send_start.is_null());
6208 EXPECT_TRUE(load_timing_info.send_end.is_null());
6209 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null());
[email protected]511f6f52010-12-17 03:58:296210}
6211
6212// Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request
[email protected]23e482282013-06-14 16:08:026213TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) {
[email protected]bb88e1d32013-05-03 23:11:076214 session_deps_.proxy_service.reset(
[email protected]511f6f52010-12-17 03:58:296215 ProxyService::CreateFixed("https://proxy:70"));
6216
6217 HttpRequestInfo request;
6218 request.method = "GET";
6219 request.url = GURL("https://www.google.com/");
6220 request.load_flags = 0;
6221
[email protected]9075f51c2013-08-15 17:53:546222 scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect(NULL, 0, 1,
6223 LOWEST));
[email protected]c10b20852013-05-15 21:29:206224 scoped_ptr<SpdyFrame> goaway(
6225 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL));
[email protected]511f6f52010-12-17 03:58:296226 MockWrite data_writes[] = {
[email protected]8ddf8322012-02-23 18:08:066227 CreateMockWrite(*conn.get(), 0, SYNCHRONOUS),
[email protected]57d2dfa2013-06-24 06:04:126228 CreateMockWrite(*goaway.get(), 3, SYNCHRONOUS),
[email protected]511f6f52010-12-17 03:58:296229 };
6230
6231 static const char* const kExtraHeaders[] = {
6232 "location",
6233 "http://login.example.com/",
6234 };
[email protected]ff98d7f02012-03-22 21:44:196235 scoped_ptr<SpdyFrame> resp(
[email protected]23e482282013-06-14 16:08:026236 spdy_util_.ConstructSpdySynReplyError("302 Redirect", kExtraHeaders,
[email protected]511f6f52010-12-17 03:58:296237 arraysize(kExtraHeaders)/2, 1));
6238 MockRead data_reads[] = {
[email protected]8ddf8322012-02-23 18:08:066239 CreateMockRead(*resp.get(), 1, SYNCHRONOUS),
6240 MockRead(ASYNC, 0, 2), // EOF
[email protected]511f6f52010-12-17 03:58:296241 };
6242
[email protected]dd54bd82012-07-19 23:44:576243 DelayedSocketData data(
6244 1, // wait for one write to finish before reading.
6245 data_reads, arraysize(data_reads),
6246 data_writes, arraysize(data_writes));
[email protected]8ddf8322012-02-23 18:08:066247 SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy
[email protected]23e482282013-06-14 16:08:026248 proxy_ssl.SetNextProto(GetParam());
[email protected]511f6f52010-12-17 03:58:296249
[email protected]bb88e1d32013-05-03 23:11:076250 session_deps_.socket_factory->AddSocketDataProvider(&data);
6251 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl);
[email protected]511f6f52010-12-17 03:58:296252
[email protected]49639fa2011-12-20 23:22:416253 TestCompletionCallback callback;
[email protected]511f6f52010-12-17 03:58:296254
[email protected]3fe8d2f82013-10-17 08:56:076255 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]511f6f52010-12-17 03:58:296256 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:416257 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]511f6f52010-12-17 03:58:296258
[email protected]49639fa2011-12-20 23:22:416259 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]511f6f52010-12-17 03:58:296260 EXPECT_EQ(ERR_IO_PENDING, rv);
6261
6262 rv = callback.WaitForResult();
6263 EXPECT_EQ(OK, rv);
6264 const HttpResponseInfo* response = trans->GetResponseInfo();
6265
[email protected]fe2255a2011-09-20 19:37:506266 ASSERT_TRUE(response != NULL);
[email protected]511f6f52010-12-17 03:58:296267
6268 EXPECT_EQ(302, response->headers->response_code());
6269 std::string url;
6270 EXPECT_TRUE(response->headers->IsRedirect(&url));
6271 EXPECT_EQ("http://login.example.com/", url);
6272}
6273
[email protected]4eddbc732012-08-09 05:40:176274// Test that an HTTPS proxy's response to a CONNECT request is filtered.
[email protected]23e482282013-06-14 16:08:026275TEST_P(HttpNetworkTransactionTest,
[email protected]4eddbc732012-08-09 05:40:176276 ErrorResponseToHttpsConnectViaHttpsProxy) {
[email protected]bb88e1d32013-05-03 23:11:076277 session_deps_.proxy_service.reset(
[email protected]511f6f52010-12-17 03:58:296278 ProxyService::CreateFixed("https://proxy:70"));
6279
6280 HttpRequestInfo request;
6281 request.method = "GET";
6282 request.url = GURL("https://www.google.com/");
6283 request.load_flags = 0;
6284
6285 MockWrite data_writes[] = {
6286 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
6287 "Host: www.google.com\r\n"
6288 "Proxy-Connection: keep-alive\r\n\r\n"),
6289 };
6290
6291 MockRead data_reads[] = {
6292 MockRead("HTTP/1.1 404 Not Found\r\n"),
6293 MockRead("Content-Length: 23\r\n\r\n"),
6294 MockRead("The host does not exist"),
[email protected]8ddf8322012-02-23 18:08:066295 MockRead(SYNCHRONOUS, OK),
[email protected]511f6f52010-12-17 03:58:296296 };
6297
6298 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
6299 data_writes, arraysize(data_writes));
[email protected]8ddf8322012-02-23 18:08:066300 SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy
[email protected]511f6f52010-12-17 03:58:296301
[email protected]bb88e1d32013-05-03 23:11:076302 session_deps_.socket_factory->AddSocketDataProvider(&data);
6303 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl);
[email protected]511f6f52010-12-17 03:58:296304
[email protected]49639fa2011-12-20 23:22:416305 TestCompletionCallback callback;
[email protected]511f6f52010-12-17 03:58:296306
[email protected]3fe8d2f82013-10-17 08:56:076307 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]511f6f52010-12-17 03:58:296308 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:416309 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]511f6f52010-12-17 03:58:296310
[email protected]49639fa2011-12-20 23:22:416311 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]511f6f52010-12-17 03:58:296312 EXPECT_EQ(ERR_IO_PENDING, rv);
6313
6314 rv = callback.WaitForResult();
[email protected]4eddbc732012-08-09 05:40:176315 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv);
[email protected]511f6f52010-12-17 03:58:296316
[email protected]4eddbc732012-08-09 05:40:176317 // TODO(ttuttle): Anything else to check here?
[email protected]511f6f52010-12-17 03:58:296318}
6319
[email protected]4eddbc732012-08-09 05:40:176320// Test that a SPDY proxy's response to a CONNECT request is filtered.
[email protected]23e482282013-06-14 16:08:026321TEST_P(HttpNetworkTransactionTest,
[email protected]4eddbc732012-08-09 05:40:176322 ErrorResponseToHttpsConnectViaSpdyProxy) {
[email protected]bb88e1d32013-05-03 23:11:076323 session_deps_.proxy_service.reset(
6324 ProxyService::CreateFixed("https://proxy:70"));
[email protected]511f6f52010-12-17 03:58:296325
6326 HttpRequestInfo request;
6327 request.method = "GET";
6328 request.url = GURL("https://www.google.com/");
6329 request.load_flags = 0;
6330
[email protected]9075f51c2013-08-15 17:53:546331 scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect(NULL, 0, 1,
6332 LOWEST));
[email protected]c10b20852013-05-15 21:29:206333 scoped_ptr<SpdyFrame> rst(
6334 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL));
[email protected]511f6f52010-12-17 03:58:296335 MockWrite data_writes[] = {
[email protected]8ddf8322012-02-23 18:08:066336 CreateMockWrite(*conn.get(), 0, SYNCHRONOUS),
[email protected]4eddbc732012-08-09 05:40:176337 CreateMockWrite(*rst.get(), 3, SYNCHRONOUS),
[email protected]511f6f52010-12-17 03:58:296338 };
6339
6340 static const char* const kExtraHeaders[] = {
6341 "location",
6342 "http://login.example.com/",
6343 };
[email protected]ff98d7f02012-03-22 21:44:196344 scoped_ptr<SpdyFrame> resp(
[email protected]23e482282013-06-14 16:08:026345 spdy_util_.ConstructSpdySynReplyError("404 Not Found", kExtraHeaders,
[email protected]511f6f52010-12-17 03:58:296346 arraysize(kExtraHeaders)/2, 1));
[email protected]ff98d7f02012-03-22 21:44:196347 scoped_ptr<SpdyFrame> body(
[email protected]23e482282013-06-14 16:08:026348 spdy_util_.ConstructSpdyBodyFrame(
6349 1, "The host does not exist", 23, true));
[email protected]511f6f52010-12-17 03:58:296350 MockRead data_reads[] = {
[email protected]8ddf8322012-02-23 18:08:066351 CreateMockRead(*resp.get(), 1, SYNCHRONOUS),
6352 CreateMockRead(*body.get(), 2, SYNCHRONOUS),
[email protected]4eddbc732012-08-09 05:40:176353 MockRead(ASYNC, 0, 4), // EOF
[email protected]511f6f52010-12-17 03:58:296354 };
6355
[email protected]dd54bd82012-07-19 23:44:576356 DelayedSocketData data(
6357 1, // wait for one write to finish before reading.
6358 data_reads, arraysize(data_reads),
6359 data_writes, arraysize(data_writes));
[email protected]8ddf8322012-02-23 18:08:066360 SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy
[email protected]23e482282013-06-14 16:08:026361 proxy_ssl.SetNextProto(GetParam());
[email protected]511f6f52010-12-17 03:58:296362
[email protected]bb88e1d32013-05-03 23:11:076363 session_deps_.socket_factory->AddSocketDataProvider(&data);
6364 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl);
[email protected]511f6f52010-12-17 03:58:296365
[email protected]49639fa2011-12-20 23:22:416366 TestCompletionCallback callback;
[email protected]511f6f52010-12-17 03:58:296367
[email protected]3fe8d2f82013-10-17 08:56:076368 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]511f6f52010-12-17 03:58:296369 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:416370 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]511f6f52010-12-17 03:58:296371
[email protected]49639fa2011-12-20 23:22:416372 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]511f6f52010-12-17 03:58:296373 EXPECT_EQ(ERR_IO_PENDING, rv);
6374
6375 rv = callback.WaitForResult();
[email protected]4eddbc732012-08-09 05:40:176376 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv);
[email protected]511f6f52010-12-17 03:58:296377
[email protected]4eddbc732012-08-09 05:40:176378 // TODO(ttuttle): Anything else to check here?
[email protected]511f6f52010-12-17 03:58:296379}
6380
[email protected]0c5fb722012-02-28 11:50:356381// Test the request-challenge-retry sequence for basic auth, through
6382// a SPDY proxy over a single SPDY session.
[email protected]23e482282013-06-14 16:08:026383TEST_P(HttpNetworkTransactionTest, BasicAuthSpdyProxy) {
[email protected]0c5fb722012-02-28 11:50:356384 HttpRequestInfo request;
6385 request.method = "GET";
6386 request.url = GURL("https://www.google.com/");
6387 // when the no authentication data flag is set.
6388 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA;
6389
6390 // Configure against https proxy server "myproxy:70".
[email protected]bb88e1d32013-05-03 23:11:076391 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:206392 ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"));
[email protected]333bdf62012-06-08 22:57:296393 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:076394 session_deps_.net_log = log.bound().net_log();
6395 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]0c5fb722012-02-28 11:50:356396
6397 // Since we have proxy, should try to establish tunnel.
[email protected]9075f51c2013-08-15 17:53:546398 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyConnect(NULL, 0, 1,
6399 LOWEST));
[email protected]c10b20852013-05-15 21:29:206400 scoped_ptr<SpdyFrame> rst(
6401 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL));
[email protected]0c5fb722012-02-28 11:50:356402
6403 // After calling trans->RestartWithAuth(), this is the request we should
6404 // be issuing -- the final header line contains the credentials.
6405 const char* const kAuthCredentials[] = {
6406 "proxy-authorization", "Basic Zm9vOmJhcg==",
6407 };
[email protected]fba2dbde2013-05-24 16:09:016408 scoped_ptr<SpdyFrame> connect2(spdy_util_.ConstructSpdyConnect(
[email protected]9075f51c2013-08-15 17:53:546409 kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST));
[email protected]0c5fb722012-02-28 11:50:356410 // fetch https://www.google.com/ via HTTP
6411 const char get[] = "GET / HTTP/1.1\r\n"
6412 "Host: www.google.com\r\n"
6413 "Connection: keep-alive\r\n\r\n";
[email protected]ff98d7f02012-03-22 21:44:196414 scoped_ptr<SpdyFrame> wrapped_get(
[email protected]23e482282013-06-14 16:08:026415 spdy_util_.ConstructSpdyBodyFrame(3, get, strlen(get), false));
[email protected]0c5fb722012-02-28 11:50:356416
6417 MockWrite spdy_writes[] = {
[email protected]3d7c43f2012-07-10 21:26:206418 CreateMockWrite(*req, 1, ASYNC),
[email protected]c92f4b4542012-07-26 23:53:216419 CreateMockWrite(*rst, 4, ASYNC),
6420 CreateMockWrite(*connect2, 5),
[email protected]3d7c43f2012-07-10 21:26:206421 CreateMockWrite(*wrapped_get, 8),
[email protected]0c5fb722012-02-28 11:50:356422 };
6423
6424 // The proxy responds to the connect with a 407, using a persistent
6425 // connection.
[email protected]745aa9c2014-06-27 02:21:296426 const char* const kAuthStatus = "407";
[email protected]0c5fb722012-02-28 11:50:356427 const char* const kAuthChallenge[] = {
[email protected]0c5fb722012-02-28 11:50:356428 "proxy-authenticate", "Basic realm=\"MyRealm1\"",
6429 };
[email protected]745aa9c2014-06-27 02:21:296430 scoped_ptr<SpdyFrame> conn_auth_resp(spdy_util_.ConstructSpdySynReplyError(
6431 kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1));
[email protected]0c5fb722012-02-28 11:50:356432
[email protected]23e482282013-06-14 16:08:026433 scoped_ptr<SpdyFrame> conn_resp(
6434 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
[email protected]0c5fb722012-02-28 11:50:356435 const char resp[] = "HTTP/1.1 200 OK\r\n"
6436 "Content-Length: 5\r\n\r\n";
6437
[email protected]ff98d7f02012-03-22 21:44:196438 scoped_ptr<SpdyFrame> wrapped_get_resp(
[email protected]23e482282013-06-14 16:08:026439 spdy_util_.ConstructSpdyBodyFrame(3, resp, strlen(resp), false));
[email protected]ff98d7f02012-03-22 21:44:196440 scoped_ptr<SpdyFrame> wrapped_body(
[email protected]23e482282013-06-14 16:08:026441 spdy_util_.ConstructSpdyBodyFrame(3, "hello", 5, false));
[email protected]0c5fb722012-02-28 11:50:356442 MockRead spdy_reads[] = {
[email protected]3d7c43f2012-07-10 21:26:206443 CreateMockRead(*conn_auth_resp, 2, ASYNC),
6444 CreateMockRead(*conn_resp, 6, ASYNC),
6445 CreateMockRead(*wrapped_get_resp, 9, ASYNC),
6446 CreateMockRead(*wrapped_body, 10, ASYNC),
6447 MockRead(ASYNC, OK, 11), // EOF. May or may not be read.
[email protected]0c5fb722012-02-28 11:50:356448 };
6449
[email protected]dd54bd82012-07-19 23:44:576450 OrderedSocketData spdy_data(
6451 spdy_reads, arraysize(spdy_reads),
6452 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:076453 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]0c5fb722012-02-28 11:50:356454 // Negotiate SPDY to the proxy
6455 SSLSocketDataProvider proxy(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:026456 proxy.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:076457 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy);
[email protected]0c5fb722012-02-28 11:50:356458 // Vanilla SSL to the server
6459 SSLSocketDataProvider server(ASYNC, OK);
[email protected]bb88e1d32013-05-03 23:11:076460 session_deps_.socket_factory->AddSSLSocketDataProvider(&server);
[email protected]0c5fb722012-02-28 11:50:356461
6462 TestCompletionCallback callback1;
6463
[email protected]262eec82013-03-19 21:01:366464 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:506465 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0c5fb722012-02-28 11:50:356466
6467 int rv = trans->Start(&request, callback1.callback(), log.bound());
6468 EXPECT_EQ(ERR_IO_PENDING, rv);
6469
6470 rv = callback1.WaitForResult();
6471 EXPECT_EQ(OK, rv);
[email protected]f3da152d2012-06-02 01:00:576472 net::CapturingNetLog::CapturedEntryList entries;
[email protected]0c5fb722012-02-28 11:50:356473 log.GetEntries(&entries);
6474 size_t pos = ExpectLogContainsSomewhere(
6475 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
6476 NetLog::PHASE_NONE);
6477 ExpectLogContainsSomewhere(
6478 entries, pos,
6479 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
6480 NetLog::PHASE_NONE);
6481
6482 const HttpResponseInfo* response = trans->GetResponseInfo();
6483 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:506484 ASSERT_FALSE(response->headers.get() == NULL);
[email protected]0c5fb722012-02-28 11:50:356485 EXPECT_EQ(407, response->headers->response_code());
6486 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
6487 EXPECT_TRUE(response->auth_challenge.get() != NULL);
6488 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
6489
6490 TestCompletionCallback callback2;
6491
6492 rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar),
6493 callback2.callback());
6494 EXPECT_EQ(ERR_IO_PENDING, rv);
6495
6496 rv = callback2.WaitForResult();
6497 EXPECT_EQ(OK, rv);
6498
6499 response = trans->GetResponseInfo();
6500 ASSERT_TRUE(response != NULL);
6501
6502 EXPECT_TRUE(response->headers->IsKeepAlive());
6503 EXPECT_EQ(200, response->headers->response_code());
6504 EXPECT_EQ(5, response->headers->GetContentLength());
6505 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
6506
6507 // The password prompt info should not be set.
6508 EXPECT_TRUE(response->auth_challenge.get() == NULL);
6509
[email protected]029c83b62013-01-24 05:28:206510 LoadTimingInfo load_timing_info;
6511 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
6512 TestLoadTimingNotReusedWithPac(load_timing_info,
6513 CONNECT_TIMING_HAS_SSL_TIMES);
6514
[email protected]0c5fb722012-02-28 11:50:356515 trans.reset();
6516 session->CloseAllConnections();
6517}
6518
[email protected]7c6f7ba2012-04-03 04:09:296519// Test that an explicitly trusted SPDY proxy can push a resource from an
6520// origin that is different from that of its associated resource.
[email protected]23e482282013-06-14 16:08:026521TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPush) {
[email protected]7c6f7ba2012-04-03 04:09:296522 HttpRequestInfo request;
6523 HttpRequestInfo push_request;
6524
[email protected]7c6f7ba2012-04-03 04:09:296525 request.method = "GET";
6526 request.url = GURL("http://www.google.com/");
6527 push_request.method = "GET";
6528 push_request.url = GURL("http://www.another-origin.com/foo.dat");
6529
[email protected]7c6f7ba2012-04-03 04:09:296530 // Configure against https proxy server "myproxy:70".
[email protected]bb88e1d32013-05-03 23:11:076531 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:206532 ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"));
[email protected]333bdf62012-06-08 22:57:296533 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:076534 session_deps_.net_log = log.bound().net_log();
[email protected]61b4efc2012-04-27 18:12:506535
6536 // Enable cross-origin push.
[email protected]bb88e1d32013-05-03 23:11:076537 session_deps_.trusted_spdy_proxy = "myproxy:70";
[email protected]61b4efc2012-04-27 18:12:506538
[email protected]bb88e1d32013-05-03 23:11:076539 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]7c6f7ba2012-04-03 04:09:296540
[email protected]cdf8f7e72013-05-23 10:56:466541 scoped_ptr<SpdyFrame> stream1_syn(
6542 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false));
[email protected]7c6f7ba2012-04-03 04:09:296543
6544 MockWrite spdy_writes[] = {
[email protected]cdf8f7e72013-05-23 10:56:466545 CreateMockWrite(*stream1_syn, 1, ASYNC),
[email protected]7c6f7ba2012-04-03 04:09:296546 };
6547
6548 scoped_ptr<SpdyFrame>
[email protected]23e482282013-06-14 16:08:026549 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
[email protected]7c6f7ba2012-04-03 04:09:296550
6551 scoped_ptr<SpdyFrame>
[email protected]23e482282013-06-14 16:08:026552 stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]7c6f7ba2012-04-03 04:09:296553
6554 scoped_ptr<SpdyFrame>
[email protected]23e482282013-06-14 16:08:026555 stream2_syn(spdy_util_.ConstructSpdyPush(NULL,
[email protected]7c6f7ba2012-04-03 04:09:296556 0,
6557 2,
6558 1,
6559 "http://www.another-origin.com/foo.dat"));
[email protected]8a0fc822013-06-27 20:52:436560 const char kPushedData[] = "pushed";
6561 scoped_ptr<SpdyFrame> stream2_body(
6562 spdy_util_.ConstructSpdyBodyFrame(
6563 2, kPushedData, strlen(kPushedData), true));
[email protected]7c6f7ba2012-04-03 04:09:296564
6565 MockRead spdy_reads[] = {
6566 CreateMockRead(*stream1_reply, 2, ASYNC),
6567 CreateMockRead(*stream2_syn, 3, ASYNC),
6568 CreateMockRead(*stream1_body, 4, ASYNC),
[email protected]8a0fc822013-06-27 20:52:436569 CreateMockRead(*stream2_body, 5, ASYNC),
[email protected]7c6f7ba2012-04-03 04:09:296570 MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause
6571 };
6572
[email protected]dd54bd82012-07-19 23:44:576573 OrderedSocketData spdy_data(
6574 spdy_reads, arraysize(spdy_reads),
6575 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:076576 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]7c6f7ba2012-04-03 04:09:296577 // Negotiate SPDY to the proxy
6578 SSLSocketDataProvider proxy(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:026579 proxy.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:076580 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy);
[email protected]7c6f7ba2012-04-03 04:09:296581
[email protected]262eec82013-03-19 21:01:366582 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:506583 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]7c6f7ba2012-04-03 04:09:296584 TestCompletionCallback callback;
6585 int rv = trans->Start(&request, callback.callback(), log.bound());
6586 EXPECT_EQ(ERR_IO_PENDING, rv);
6587
6588 rv = callback.WaitForResult();
6589 EXPECT_EQ(OK, rv);
6590 const HttpResponseInfo* response = trans->GetResponseInfo();
6591
[email protected]262eec82013-03-19 21:01:366592 scoped_ptr<HttpTransaction> push_trans(
[email protected]90499482013-06-01 00:39:506593 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
6594 rv = push_trans->Start(&push_request, callback.callback(), log.bound());
[email protected]7c6f7ba2012-04-03 04:09:296595 EXPECT_EQ(ERR_IO_PENDING, rv);
6596
6597 rv = callback.WaitForResult();
6598 EXPECT_EQ(OK, rv);
6599 const HttpResponseInfo* push_response = push_trans->GetResponseInfo();
6600
6601 ASSERT_TRUE(response != NULL);
6602 EXPECT_TRUE(response->headers->IsKeepAlive());
6603
6604 EXPECT_EQ(200, response->headers->response_code());
6605 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
6606
6607 std::string response_data;
6608 rv = ReadTransaction(trans.get(), &response_data);
6609 EXPECT_EQ(OK, rv);
6610 EXPECT_EQ("hello!", response_data);
6611
[email protected]029c83b62013-01-24 05:28:206612 LoadTimingInfo load_timing_info;
6613 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
6614 TestLoadTimingNotReusedWithPac(load_timing_info,
6615 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY);
6616
[email protected]7c6f7ba2012-04-03 04:09:296617 // Verify the pushed stream.
[email protected]90499482013-06-01 00:39:506618 EXPECT_TRUE(push_response->headers.get() != NULL);
[email protected]7c6f7ba2012-04-03 04:09:296619 EXPECT_EQ(200, push_response->headers->response_code());
6620
6621 rv = ReadTransaction(push_trans.get(), &response_data);
6622 EXPECT_EQ(OK, rv);
6623 EXPECT_EQ("pushed", response_data);
6624
[email protected]029c83b62013-01-24 05:28:206625 LoadTimingInfo push_load_timing_info;
6626 EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info));
6627 TestLoadTimingReusedWithPac(push_load_timing_info);
6628 // The transactions should share a socket ID, despite being for different
6629 // origins.
6630 EXPECT_EQ(load_timing_info.socket_log_id,
6631 push_load_timing_info.socket_log_id);
6632
[email protected]7c6f7ba2012-04-03 04:09:296633 trans.reset();
6634 push_trans.reset();
6635 session->CloseAllConnections();
6636}
6637
[email protected]8c843192012-04-05 07:15:006638// Test that an explicitly trusted SPDY proxy cannot push HTTPS content.
[email protected]23e482282013-06-14 16:08:026639TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) {
[email protected]8c843192012-04-05 07:15:006640 HttpRequestInfo request;
6641
6642 request.method = "GET";
6643 request.url = GURL("http://www.google.com/");
6644
[email protected]8c843192012-04-05 07:15:006645 // Configure against https proxy server "myproxy:70".
[email protected]bb88e1d32013-05-03 23:11:076646 session_deps_.proxy_service.reset(
[email protected]8c843192012-04-05 07:15:006647 ProxyService::CreateFixed("https://myproxy:70"));
[email protected]333bdf62012-06-08 22:57:296648 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:076649 session_deps_.net_log = log.bound().net_log();
[email protected]61b4efc2012-04-27 18:12:506650
6651 // Enable cross-origin push.
[email protected]bb88e1d32013-05-03 23:11:076652 session_deps_.trusted_spdy_proxy = "myproxy:70";
[email protected]61b4efc2012-04-27 18:12:506653
[email protected]bb88e1d32013-05-03 23:11:076654 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]8c843192012-04-05 07:15:006655
[email protected]cdf8f7e72013-05-23 10:56:466656 scoped_ptr<SpdyFrame> stream1_syn(
6657 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false));
[email protected]8c843192012-04-05 07:15:006658
6659 scoped_ptr<SpdyFrame> push_rst(
[email protected]c10b20852013-05-15 21:29:206660 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM));
[email protected]8c843192012-04-05 07:15:006661
6662 MockWrite spdy_writes[] = {
6663 CreateMockWrite(*stream1_syn, 1, ASYNC),
6664 CreateMockWrite(*push_rst, 4),
6665 };
6666
6667 scoped_ptr<SpdyFrame>
[email protected]23e482282013-06-14 16:08:026668 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
[email protected]8c843192012-04-05 07:15:006669
6670 scoped_ptr<SpdyFrame>
[email protected]23e482282013-06-14 16:08:026671 stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]8c843192012-04-05 07:15:006672
6673 scoped_ptr<SpdyFrame>
[email protected]23e482282013-06-14 16:08:026674 stream2_syn(spdy_util_.ConstructSpdyPush(NULL,
[email protected]8c843192012-04-05 07:15:006675 0,
6676 2,
6677 1,
6678 "https://www.another-origin.com/foo.dat"));
6679
6680 MockRead spdy_reads[] = {
6681 CreateMockRead(*stream1_reply, 2, ASYNC),
6682 CreateMockRead(*stream2_syn, 3, ASYNC),
6683 CreateMockRead(*stream1_body, 5, ASYNC),
6684 MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause
6685 };
6686
[email protected]dd54bd82012-07-19 23:44:576687 OrderedSocketData spdy_data(
6688 spdy_reads, arraysize(spdy_reads),
6689 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:076690 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]8c843192012-04-05 07:15:006691 // Negotiate SPDY to the proxy
6692 SSLSocketDataProvider proxy(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:026693 proxy.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:076694 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy);
[email protected]8c843192012-04-05 07:15:006695
[email protected]262eec82013-03-19 21:01:366696 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:506697 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]8c843192012-04-05 07:15:006698 TestCompletionCallback callback;
6699 int rv = trans->Start(&request, callback.callback(), log.bound());
6700 EXPECT_EQ(ERR_IO_PENDING, rv);
6701
6702 rv = callback.WaitForResult();
6703 EXPECT_EQ(OK, rv);
6704 const HttpResponseInfo* response = trans->GetResponseInfo();
6705
6706 ASSERT_TRUE(response != NULL);
6707 EXPECT_TRUE(response->headers->IsKeepAlive());
6708
6709 EXPECT_EQ(200, response->headers->response_code());
6710 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
6711
6712 std::string response_data;
6713 rv = ReadTransaction(trans.get(), &response_data);
6714 EXPECT_EQ(OK, rv);
6715 EXPECT_EQ("hello!", response_data);
6716
6717 trans.reset();
6718 session->CloseAllConnections();
6719}
6720
[email protected]2df19bb2010-08-25 20:13:466721// Test HTTPS connections to a site with a bad certificate, going through an
6722// HTTPS proxy
[email protected]23e482282013-06-14 16:08:026723TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) {
[email protected]bb88e1d32013-05-03 23:11:076724 session_deps_.proxy_service.reset(ProxyService::CreateFixed(
[email protected]3912662a32011-10-04 00:51:116725 "https://proxy:70"));
[email protected]2df19bb2010-08-25 20:13:466726
6727 HttpRequestInfo request;
6728 request.method = "GET";
6729 request.url = GURL("https://www.google.com/");
6730 request.load_flags = 0;
6731
6732 // Attempt to fetch the URL from a server with a bad cert
6733 MockWrite bad_cert_writes[] = {
6734 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
6735 "Host: www.google.com\r\n"
6736 "Proxy-Connection: keep-alive\r\n\r\n"),
6737 };
6738
6739 MockRead bad_cert_reads[] = {
6740 MockRead("HTTP/1.0 200 Connected\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:066741 MockRead(SYNCHRONOUS, OK)
[email protected]2df19bb2010-08-25 20:13:466742 };
6743
6744 // Attempt to fetch the URL with a good cert
6745 MockWrite good_data_writes[] = {
6746 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
6747 "Host: www.google.com\r\n"
6748 "Proxy-Connection: keep-alive\r\n\r\n"),
6749 MockWrite("GET / HTTP/1.1\r\n"
6750 "Host: www.google.com\r\n"
6751 "Connection: keep-alive\r\n\r\n"),
6752 };
6753
6754 MockRead good_cert_reads[] = {
6755 MockRead("HTTP/1.0 200 Connected\r\n\r\n"),
6756 MockRead("HTTP/1.0 200 OK\r\n"),
6757 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
6758 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:066759 MockRead(SYNCHRONOUS, OK),
[email protected]2df19bb2010-08-25 20:13:466760 };
6761
6762 StaticSocketDataProvider ssl_bad_certificate(
6763 bad_cert_reads, arraysize(bad_cert_reads),
6764 bad_cert_writes, arraysize(bad_cert_writes));
6765 StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads),
6766 good_data_writes, arraysize(good_data_writes));
[email protected]8ddf8322012-02-23 18:08:066767 SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID);
6768 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]2df19bb2010-08-25 20:13:466769
6770 // SSL to the proxy, then CONNECT request, then SSL with bad certificate
[email protected]bb88e1d32013-05-03 23:11:076771 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
6772 session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate);
6773 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad);
[email protected]2df19bb2010-08-25 20:13:466774
6775 // SSL to the proxy, then CONNECT request, then valid SSL certificate
[email protected]bb88e1d32013-05-03 23:11:076776 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
6777 session_deps_.socket_factory->AddSocketDataProvider(&data);
6778 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]2df19bb2010-08-25 20:13:466779
[email protected]49639fa2011-12-20 23:22:416780 TestCompletionCallback callback;
[email protected]2df19bb2010-08-25 20:13:466781
[email protected]3fe8d2f82013-10-17 08:56:076782 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]2df19bb2010-08-25 20:13:466783 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:416784 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]2df19bb2010-08-25 20:13:466785
[email protected]49639fa2011-12-20 23:22:416786 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]2df19bb2010-08-25 20:13:466787 EXPECT_EQ(ERR_IO_PENDING, rv);
6788
6789 rv = callback.WaitForResult();
6790 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv);
6791
[email protected]49639fa2011-12-20 23:22:416792 rv = trans->RestartIgnoringLastError(callback.callback());
[email protected]2df19bb2010-08-25 20:13:466793 EXPECT_EQ(ERR_IO_PENDING, rv);
6794
6795 rv = callback.WaitForResult();
6796 EXPECT_EQ(OK, rv);
6797
6798 const HttpResponseInfo* response = trans->GetResponseInfo();
6799
[email protected]fe2255a2011-09-20 19:37:506800 ASSERT_TRUE(response != NULL);
[email protected]2df19bb2010-08-25 20:13:466801 EXPECT_EQ(100, response->headers->GetContentLength());
6802}
6803
[email protected]23e482282013-06-14 16:08:026804TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgent) {
[email protected]1c773ea12009-04-28 19:58:426805 HttpRequestInfo request;
6806 request.method = "GET";
6807 request.url = GURL("http://www.google.com/");
[email protected]8c76ae22010-04-20 22:15:436808 request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent,
6809 "Chromium Ultra Awesome X Edition");
[email protected]1c773ea12009-04-28 19:58:426810
[email protected]3fe8d2f82013-10-17 08:56:076811 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:276812 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:416813 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:276814
[email protected]1c773ea12009-04-28 19:58:426815 MockWrite data_writes[] = {
6816 MockWrite("GET / HTTP/1.1\r\n"
6817 "Host: www.google.com\r\n"
6818 "Connection: keep-alive\r\n"
6819 "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"),
6820 };
6821
6822 // Lastly, the server responds with the actual content.
6823 MockRead data_reads[] = {
6824 MockRead("HTTP/1.0 200 OK\r\n"),
6825 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
6826 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:066827 MockRead(SYNCHRONOUS, OK),
[email protected]1c773ea12009-04-28 19:58:426828 };
6829
[email protected]31a2bfe2010-02-09 08:03:396830 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
6831 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:076832 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]1c773ea12009-04-28 19:58:426833
[email protected]49639fa2011-12-20 23:22:416834 TestCompletionCallback callback;
[email protected]1c773ea12009-04-28 19:58:426835
[email protected]49639fa2011-12-20 23:22:416836 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:426837 EXPECT_EQ(ERR_IO_PENDING, rv);
6838
6839 rv = callback.WaitForResult();
6840 EXPECT_EQ(OK, rv);
6841}
6842
[email protected]23e482282013-06-14 16:08:026843TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) {
[email protected]da81f132010-08-18 23:39:296844 HttpRequestInfo request;
6845 request.method = "GET";
6846 request.url = GURL("https://www.google.com/");
6847 request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent,
6848 "Chromium Ultra Awesome X Edition");
6849
[email protected]bb88e1d32013-05-03 23:11:076850 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70"));
[email protected]3fe8d2f82013-10-17 08:56:076851 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:276852 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:416853 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:276854
[email protected]da81f132010-08-18 23:39:296855 MockWrite data_writes[] = {
6856 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
6857 "Host: www.google.com\r\n"
6858 "Proxy-Connection: keep-alive\r\n"
6859 "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"),
6860 };
6861 MockRead data_reads[] = {
6862 // Return an error, so the transaction stops here (this test isn't
6863 // interested in the rest).
6864 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
6865 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
6866 MockRead("Proxy-Connection: close\r\n\r\n"),
6867 };
6868
6869 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
6870 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:076871 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]da81f132010-08-18 23:39:296872
[email protected]49639fa2011-12-20 23:22:416873 TestCompletionCallback callback;
[email protected]da81f132010-08-18 23:39:296874
[email protected]49639fa2011-12-20 23:22:416875 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]da81f132010-08-18 23:39:296876 EXPECT_EQ(ERR_IO_PENDING, rv);
6877
6878 rv = callback.WaitForResult();
6879 EXPECT_EQ(OK, rv);
6880}
6881
[email protected]23e482282013-06-14 16:08:026882TEST_P(HttpNetworkTransactionTest, BuildRequest_Referer) {
[email protected]1c773ea12009-04-28 19:58:426883 HttpRequestInfo request;
6884 request.method = "GET";
6885 request.url = GURL("http://www.google.com/");
6886 request.load_flags = 0;
[email protected]c10450102011-06-27 09:06:166887 request.extra_headers.SetHeader(HttpRequestHeaders::kReferer,
6888 "http://the.previous.site.com/");
[email protected]1c773ea12009-04-28 19:58:426889
[email protected]3fe8d2f82013-10-17 08:56:076890 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:276891 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:416892 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:276893
[email protected]1c773ea12009-04-28 19:58:426894 MockWrite data_writes[] = {
6895 MockWrite("GET / HTTP/1.1\r\n"
6896 "Host: www.google.com\r\n"
6897 "Connection: keep-alive\r\n"
6898 "Referer: http://the.previous.site.com/\r\n\r\n"),
6899 };
6900
6901 // Lastly, the server responds with the actual content.
6902 MockRead data_reads[] = {
6903 MockRead("HTTP/1.0 200 OK\r\n"),
6904 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
6905 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:066906 MockRead(SYNCHRONOUS, OK),
[email protected]1c773ea12009-04-28 19:58:426907 };
6908
[email protected]31a2bfe2010-02-09 08:03:396909 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
6910 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:076911 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]1c773ea12009-04-28 19:58:426912
[email protected]49639fa2011-12-20 23:22:416913 TestCompletionCallback callback;
[email protected]1c773ea12009-04-28 19:58:426914
[email protected]49639fa2011-12-20 23:22:416915 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:426916 EXPECT_EQ(ERR_IO_PENDING, rv);
6917
6918 rv = callback.WaitForResult();
6919 EXPECT_EQ(OK, rv);
6920}
6921
[email protected]23e482282013-06-14 16:08:026922TEST_P(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) {
[email protected]1c773ea12009-04-28 19:58:426923 HttpRequestInfo request;
6924 request.method = "POST";
6925 request.url = GURL("http://www.google.com/");
6926
[email protected]3fe8d2f82013-10-17 08:56:076927 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:276928 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:416929 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:276930
[email protected]1c773ea12009-04-28 19:58:426931 MockWrite data_writes[] = {
6932 MockWrite("POST / HTTP/1.1\r\n"
6933 "Host: www.google.com\r\n"
6934 "Connection: keep-alive\r\n"
6935 "Content-Length: 0\r\n\r\n"),
6936 };
6937
6938 // Lastly, the server responds with the actual content.
6939 MockRead data_reads[] = {
6940 MockRead("HTTP/1.0 200 OK\r\n"),
6941 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
6942 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:066943 MockRead(SYNCHRONOUS, OK),
[email protected]1c773ea12009-04-28 19:58:426944 };
6945
[email protected]31a2bfe2010-02-09 08:03:396946 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
6947 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:076948 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]1c773ea12009-04-28 19:58:426949
[email protected]49639fa2011-12-20 23:22:416950 TestCompletionCallback callback;
[email protected]1c773ea12009-04-28 19:58:426951
[email protected]49639fa2011-12-20 23:22:416952 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:426953 EXPECT_EQ(ERR_IO_PENDING, rv);
6954
6955 rv = callback.WaitForResult();
6956 EXPECT_EQ(OK, rv);
6957}
6958
[email protected]23e482282013-06-14 16:08:026959TEST_P(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) {
[email protected]1c773ea12009-04-28 19:58:426960 HttpRequestInfo request;
6961 request.method = "PUT";
6962 request.url = GURL("http://www.google.com/");
6963
[email protected]3fe8d2f82013-10-17 08:56:076964 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:276965 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:416966 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:276967
[email protected]1c773ea12009-04-28 19:58:426968 MockWrite data_writes[] = {
6969 MockWrite("PUT / HTTP/1.1\r\n"
6970 "Host: www.google.com\r\n"
6971 "Connection: keep-alive\r\n"
6972 "Content-Length: 0\r\n\r\n"),
6973 };
6974
6975 // Lastly, the server responds with the actual content.
6976 MockRead data_reads[] = {
6977 MockRead("HTTP/1.0 200 OK\r\n"),
6978 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
6979 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:066980 MockRead(SYNCHRONOUS, OK),
[email protected]1c773ea12009-04-28 19:58:426981 };
6982
[email protected]31a2bfe2010-02-09 08:03:396983 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
6984 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:076985 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]1c773ea12009-04-28 19:58:426986
[email protected]49639fa2011-12-20 23:22:416987 TestCompletionCallback callback;
[email protected]1c773ea12009-04-28 19:58:426988
[email protected]49639fa2011-12-20 23:22:416989 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:426990 EXPECT_EQ(ERR_IO_PENDING, rv);
6991
6992 rv = callback.WaitForResult();
6993 EXPECT_EQ(OK, rv);
6994}
6995
[email protected]23e482282013-06-14 16:08:026996TEST_P(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) {
[email protected]1c773ea12009-04-28 19:58:426997 HttpRequestInfo request;
6998 request.method = "HEAD";
6999 request.url = GURL("http://www.google.com/");
7000
[email protected]3fe8d2f82013-10-17 08:56:077001 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:277002 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417003 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:277004
[email protected]1c773ea12009-04-28 19:58:427005 MockWrite data_writes[] = {
7006 MockWrite("HEAD / HTTP/1.1\r\n"
7007 "Host: www.google.com\r\n"
7008 "Connection: keep-alive\r\n"
7009 "Content-Length: 0\r\n\r\n"),
7010 };
7011
7012 // Lastly, the server responds with the actual content.
7013 MockRead data_reads[] = {
7014 MockRead("HTTP/1.0 200 OK\r\n"),
7015 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
7016 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:067017 MockRead(SYNCHRONOUS, OK),
[email protected]1c773ea12009-04-28 19:58:427018 };
7019
[email protected]31a2bfe2010-02-09 08:03:397020 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
7021 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:077022 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]1c773ea12009-04-28 19:58:427023
[email protected]49639fa2011-12-20 23:22:417024 TestCompletionCallback callback;
[email protected]1c773ea12009-04-28 19:58:427025
[email protected]49639fa2011-12-20 23:22:417026 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:427027 EXPECT_EQ(ERR_IO_PENDING, rv);
7028
7029 rv = callback.WaitForResult();
7030 EXPECT_EQ(OK, rv);
7031}
7032
[email protected]23e482282013-06-14 16:08:027033TEST_P(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) {
[email protected]1c773ea12009-04-28 19:58:427034 HttpRequestInfo request;
7035 request.method = "GET";
7036 request.url = GURL("http://www.google.com/");
7037 request.load_flags = LOAD_BYPASS_CACHE;
7038
[email protected]3fe8d2f82013-10-17 08:56:077039 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:277040 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417041 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:277042
[email protected]1c773ea12009-04-28 19:58:427043 MockWrite data_writes[] = {
7044 MockWrite("GET / HTTP/1.1\r\n"
7045 "Host: www.google.com\r\n"
7046 "Connection: keep-alive\r\n"
7047 "Pragma: no-cache\r\n"
7048 "Cache-Control: no-cache\r\n\r\n"),
7049 };
7050
7051 // Lastly, the server responds with the actual content.
7052 MockRead data_reads[] = {
7053 MockRead("HTTP/1.0 200 OK\r\n"),
7054 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
7055 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:067056 MockRead(SYNCHRONOUS, OK),
[email protected]1c773ea12009-04-28 19:58:427057 };
7058
[email protected]31a2bfe2010-02-09 08:03:397059 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
7060 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:077061 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]1c773ea12009-04-28 19:58:427062
[email protected]49639fa2011-12-20 23:22:417063 TestCompletionCallback callback;
[email protected]1c773ea12009-04-28 19:58:427064
[email protected]49639fa2011-12-20 23:22:417065 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:427066 EXPECT_EQ(ERR_IO_PENDING, rv);
7067
7068 rv = callback.WaitForResult();
7069 EXPECT_EQ(OK, rv);
7070}
7071
[email protected]23e482282013-06-14 16:08:027072TEST_P(HttpNetworkTransactionTest,
[email protected]1c773ea12009-04-28 19:58:427073 BuildRequest_CacheControlValidateCache) {
[email protected]1c773ea12009-04-28 19:58:427074 HttpRequestInfo request;
7075 request.method = "GET";
7076 request.url = GURL("http://www.google.com/");
7077 request.load_flags = LOAD_VALIDATE_CACHE;
7078
[email protected]3fe8d2f82013-10-17 08:56:077079 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:277080 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417081 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:277082
[email protected]1c773ea12009-04-28 19:58:427083 MockWrite data_writes[] = {
7084 MockWrite("GET / HTTP/1.1\r\n"
7085 "Host: www.google.com\r\n"
7086 "Connection: keep-alive\r\n"
7087 "Cache-Control: max-age=0\r\n\r\n"),
7088 };
7089
7090 // Lastly, the server responds with the actual content.
7091 MockRead data_reads[] = {
7092 MockRead("HTTP/1.0 200 OK\r\n"),
7093 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
7094 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:067095 MockRead(SYNCHRONOUS, OK),
[email protected]1c773ea12009-04-28 19:58:427096 };
7097
[email protected]31a2bfe2010-02-09 08:03:397098 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
7099 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:077100 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]1c773ea12009-04-28 19:58:427101
[email protected]49639fa2011-12-20 23:22:417102 TestCompletionCallback callback;
[email protected]1c773ea12009-04-28 19:58:427103
[email protected]49639fa2011-12-20 23:22:417104 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:427105 EXPECT_EQ(ERR_IO_PENDING, rv);
7106
7107 rv = callback.WaitForResult();
7108 EXPECT_EQ(OK, rv);
7109}
7110
[email protected]23e482282013-06-14 16:08:027111TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) {
[email protected]1c773ea12009-04-28 19:58:427112 HttpRequestInfo request;
7113 request.method = "GET";
7114 request.url = GURL("http://www.google.com/");
[email protected]8c76ae22010-04-20 22:15:437115 request.extra_headers.SetHeader("FooHeader", "Bar");
[email protected]1c773ea12009-04-28 19:58:427116
[email protected]3fe8d2f82013-10-17 08:56:077117 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:277118 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417119 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:277120
[email protected]1c773ea12009-04-28 19:58:427121 MockWrite data_writes[] = {
7122 MockWrite("GET / HTTP/1.1\r\n"
7123 "Host: www.google.com\r\n"
7124 "Connection: keep-alive\r\n"
7125 "FooHeader: Bar\r\n\r\n"),
7126 };
7127
7128 // Lastly, the server responds with the actual content.
7129 MockRead data_reads[] = {
7130 MockRead("HTTP/1.0 200 OK\r\n"),
7131 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
7132 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:067133 MockRead(SYNCHRONOUS, OK),
[email protected]1c773ea12009-04-28 19:58:427134 };
7135
[email protected]31a2bfe2010-02-09 08:03:397136 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
7137 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:077138 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]1c773ea12009-04-28 19:58:427139
[email protected]49639fa2011-12-20 23:22:417140 TestCompletionCallback callback;
[email protected]1c773ea12009-04-28 19:58:427141
[email protected]49639fa2011-12-20 23:22:417142 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:427143 EXPECT_EQ(ERR_IO_PENDING, rv);
7144
7145 rv = callback.WaitForResult();
7146 EXPECT_EQ(OK, rv);
7147}
7148
[email protected]23e482282013-06-14 16:08:027149TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) {
[email protected]270c6412010-03-29 22:02:477150 HttpRequestInfo request;
7151 request.method = "GET";
7152 request.url = GURL("http://www.google.com/");
[email protected]8c76ae22010-04-20 22:15:437153 request.extra_headers.SetHeader("referer", "www.foo.com");
7154 request.extra_headers.SetHeader("hEllo", "Kitty");
7155 request.extra_headers.SetHeader("FoO", "bar");
[email protected]270c6412010-03-29 22:02:477156
[email protected]3fe8d2f82013-10-17 08:56:077157 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:277158 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417159 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:277160
[email protected]270c6412010-03-29 22:02:477161 MockWrite data_writes[] = {
7162 MockWrite("GET / HTTP/1.1\r\n"
7163 "Host: www.google.com\r\n"
7164 "Connection: keep-alive\r\n"
[email protected]c10450102011-06-27 09:06:167165 "referer: www.foo.com\r\n"
[email protected]270c6412010-03-29 22:02:477166 "hEllo: Kitty\r\n"
7167 "FoO: bar\r\n\r\n"),
7168 };
7169
7170 // Lastly, the server responds with the actual content.
7171 MockRead data_reads[] = {
7172 MockRead("HTTP/1.0 200 OK\r\n"),
7173 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
7174 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:067175 MockRead(SYNCHRONOUS, OK),
[email protected]270c6412010-03-29 22:02:477176 };
7177
7178 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
7179 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:077180 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]270c6412010-03-29 22:02:477181
[email protected]49639fa2011-12-20 23:22:417182 TestCompletionCallback callback;
[email protected]270c6412010-03-29 22:02:477183
[email protected]49639fa2011-12-20 23:22:417184 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]270c6412010-03-29 22:02:477185 EXPECT_EQ(ERR_IO_PENDING, rv);
7186
7187 rv = callback.WaitForResult();
7188 EXPECT_EQ(OK, rv);
7189}
7190
[email protected]23e482282013-06-14 16:08:027191TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) {
[email protected]cb9bf6ca2011-01-28 13:15:277192 HttpRequestInfo request;
7193 request.method = "GET";
7194 request.url = GURL("http://www.google.com/");
7195 request.load_flags = 0;
7196
[email protected]bb88e1d32013-05-03 23:11:077197 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:207198 ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"));
7199 CapturingNetLog net_log;
[email protected]bb88e1d32013-05-03 23:11:077200 session_deps_.net_log = &net_log;
[email protected]3cd17242009-06-23 02:59:027201
[email protected]3fe8d2f82013-10-17 08:56:077202 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]3cd17242009-06-23 02:59:027203 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417204 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]3cd17242009-06-23 02:59:027205
[email protected]3cd17242009-06-23 02:59:027206 char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 };
7207 char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 };
7208
7209 MockWrite data_writes[] = {
[email protected]8ddf8322012-02-23 18:08:067210 MockWrite(ASYNC, write_buffer, arraysize(write_buffer)),
[email protected]3cd17242009-06-23 02:59:027211 MockWrite("GET / HTTP/1.1\r\n"
7212 "Host: www.google.com\r\n"
7213 "Connection: keep-alive\r\n\r\n")
7214 };
7215
7216 MockRead data_reads[] = {
[email protected]8ddf8322012-02-23 18:08:067217 MockRead(ASYNC, read_buffer, arraysize(read_buffer)),
[email protected]3cd17242009-06-23 02:59:027218 MockRead("HTTP/1.0 200 OK\r\n"),
7219 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"),
7220 MockRead("Payload"),
[email protected]8ddf8322012-02-23 18:08:067221 MockRead(SYNCHRONOUS, OK)
[email protected]3cd17242009-06-23 02:59:027222 };
7223
[email protected]31a2bfe2010-02-09 08:03:397224 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
7225 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:077226 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]3cd17242009-06-23 02:59:027227
[email protected]49639fa2011-12-20 23:22:417228 TestCompletionCallback callback;
[email protected]3cd17242009-06-23 02:59:027229
[email protected]49639fa2011-12-20 23:22:417230 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]3cd17242009-06-23 02:59:027231 EXPECT_EQ(ERR_IO_PENDING, rv);
7232
7233 rv = callback.WaitForResult();
7234 EXPECT_EQ(OK, rv);
7235
7236 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:507237 ASSERT_TRUE(response != NULL);
[email protected]3cd17242009-06-23 02:59:027238
[email protected]029c83b62013-01-24 05:28:207239 LoadTimingInfo load_timing_info;
7240 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
7241 TestLoadTimingNotReusedWithPac(load_timing_info,
7242 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY);
7243
[email protected]3cd17242009-06-23 02:59:027244 std::string response_text;
7245 rv = ReadTransaction(trans.get(), &response_text);
7246 EXPECT_EQ(OK, rv);
7247 EXPECT_EQ("Payload", response_text);
7248}
7249
[email protected]23e482282013-06-14 16:08:027250TEST_P(HttpNetworkTransactionTest, SOCKS4_SSL_GET) {
[email protected]cb9bf6ca2011-01-28 13:15:277251 HttpRequestInfo request;
7252 request.method = "GET";
7253 request.url = GURL("https://www.google.com/");
7254 request.load_flags = 0;
7255
[email protected]bb88e1d32013-05-03 23:11:077256 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:207257 ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"));
7258 CapturingNetLog net_log;
[email protected]bb88e1d32013-05-03 23:11:077259 session_deps_.net_log = &net_log;
[email protected]3cd17242009-06-23 02:59:027260
[email protected]3fe8d2f82013-10-17 08:56:077261 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]3cd17242009-06-23 02:59:027262 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417263 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]3cd17242009-06-23 02:59:027264
[email protected]3cd17242009-06-23 02:59:027265 unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 };
7266 unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 };
7267
7268 MockWrite data_writes[] = {
[email protected]8ddf8322012-02-23 18:08:067269 MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer),
[email protected]e0c27be2009-07-15 13:09:357270 arraysize(write_buffer)),
[email protected]3cd17242009-06-23 02:59:027271 MockWrite("GET / HTTP/1.1\r\n"
7272 "Host: www.google.com\r\n"
7273 "Connection: keep-alive\r\n\r\n")
7274 };
7275
7276 MockRead data_reads[] = {
[email protected]f871ee152012-07-27 19:02:017277 MockRead(ASYNC, reinterpret_cast<char*>(read_buffer),
7278 arraysize(read_buffer)),
[email protected]e0c27be2009-07-15 13:09:357279 MockRead("HTTP/1.0 200 OK\r\n"),
7280 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"),
7281 MockRead("Payload"),
[email protected]8ddf8322012-02-23 18:08:067282 MockRead(SYNCHRONOUS, OK)
[email protected]e0c27be2009-07-15 13:09:357283 };
7284
[email protected]31a2bfe2010-02-09 08:03:397285 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
7286 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:077287 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]e0c27be2009-07-15 13:09:357288
[email protected]8ddf8322012-02-23 18:08:067289 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]bb88e1d32013-05-03 23:11:077290 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]e0c27be2009-07-15 13:09:357291
[email protected]49639fa2011-12-20 23:22:417292 TestCompletionCallback callback;
[email protected]e0c27be2009-07-15 13:09:357293
[email protected]49639fa2011-12-20 23:22:417294 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]e0c27be2009-07-15 13:09:357295 EXPECT_EQ(ERR_IO_PENDING, rv);
7296
7297 rv = callback.WaitForResult();
7298 EXPECT_EQ(OK, rv);
7299
[email protected]029c83b62013-01-24 05:28:207300 LoadTimingInfo load_timing_info;
7301 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
7302 TestLoadTimingNotReusedWithPac(load_timing_info,
7303 CONNECT_TIMING_HAS_SSL_TIMES);
7304
[email protected]e0c27be2009-07-15 13:09:357305 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:507306 ASSERT_TRUE(response != NULL);
[email protected]e0c27be2009-07-15 13:09:357307
7308 std::string response_text;
7309 rv = ReadTransaction(trans.get(), &response_text);
7310 EXPECT_EQ(OK, rv);
7311 EXPECT_EQ("Payload", response_text);
7312}
7313
[email protected]23e482282013-06-14 16:08:027314TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) {
[email protected]029c83b62013-01-24 05:28:207315 HttpRequestInfo request;
7316 request.method = "GET";
7317 request.url = GURL("http://www.google.com/");
7318 request.load_flags = 0;
7319
[email protected]bb88e1d32013-05-03 23:11:077320 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:207321 ProxyService::CreateFixed("socks4://myproxy:1080"));
7322 CapturingNetLog net_log;
[email protected]bb88e1d32013-05-03 23:11:077323 session_deps_.net_log = &net_log;
[email protected]029c83b62013-01-24 05:28:207324
[email protected]3fe8d2f82013-10-17 08:56:077325 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]029c83b62013-01-24 05:28:207326 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417327 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]029c83b62013-01-24 05:28:207328
7329 char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 };
7330 char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 };
7331
7332 MockWrite data_writes[] = {
7333 MockWrite(ASYNC, write_buffer, arraysize(write_buffer)),
7334 MockWrite("GET / HTTP/1.1\r\n"
7335 "Host: www.google.com\r\n"
7336 "Connection: keep-alive\r\n\r\n")
7337 };
7338
7339 MockRead data_reads[] = {
7340 MockRead(ASYNC, read_buffer, arraysize(read_buffer)),
7341 MockRead("HTTP/1.0 200 OK\r\n"),
7342 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"),
7343 MockRead("Payload"),
7344 MockRead(SYNCHRONOUS, OK)
7345 };
7346
7347 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
7348 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:077349 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]029c83b62013-01-24 05:28:207350
7351 TestCompletionCallback callback;
7352
7353 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
7354 EXPECT_EQ(ERR_IO_PENDING, rv);
7355
7356 rv = callback.WaitForResult();
7357 EXPECT_EQ(OK, rv);
7358
7359 const HttpResponseInfo* response = trans->GetResponseInfo();
7360 ASSERT_TRUE(response != NULL);
7361
7362 LoadTimingInfo load_timing_info;
7363 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
7364 TestLoadTimingNotReused(load_timing_info,
7365 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY);
7366
7367 std::string response_text;
7368 rv = ReadTransaction(trans.get(), &response_text);
7369 EXPECT_EQ(OK, rv);
7370 EXPECT_EQ("Payload", response_text);
7371}
7372
[email protected]23e482282013-06-14 16:08:027373TEST_P(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) {
[email protected]cb9bf6ca2011-01-28 13:15:277374 HttpRequestInfo request;
7375 request.method = "GET";
7376 request.url = GURL("http://www.google.com/");
7377 request.load_flags = 0;
7378
[email protected]bb88e1d32013-05-03 23:11:077379 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:207380 ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"));
7381 CapturingNetLog net_log;
[email protected]bb88e1d32013-05-03 23:11:077382 session_deps_.net_log = &net_log;
[email protected]e0c27be2009-07-15 13:09:357383
[email protected]3fe8d2f82013-10-17 08:56:077384 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]e0c27be2009-07-15 13:09:357385 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417386 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]e0c27be2009-07-15 13:09:357387
[email protected]e0c27be2009-07-15 13:09:357388 const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 };
7389 const char kSOCKS5GreetResponse[] = { 0x05, 0x00 };
[email protected]f209dba2009-12-18 00:24:377390 const char kSOCKS5OkRequest[] = {
7391 0x05, // Version
7392 0x01, // Command (CONNECT)
7393 0x00, // Reserved.
7394 0x03, // Address type (DOMAINNAME).
7395 0x0E, // Length of domain (14)
7396 // Domain string:
7397 'w', 'w', 'w', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'c', 'o', 'm',
7398 0x00, 0x50, // 16-bit port (80)
7399 };
[email protected]e0c27be2009-07-15 13:09:357400 const char kSOCKS5OkResponse[] =
7401 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 };
7402
7403 MockWrite data_writes[] = {
[email protected]8ddf8322012-02-23 18:08:067404 MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)),
7405 MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)),
[email protected]e0c27be2009-07-15 13:09:357406 MockWrite("GET / HTTP/1.1\r\n"
7407 "Host: www.google.com\r\n"
7408 "Connection: keep-alive\r\n\r\n")
7409 };
7410
7411 MockRead data_reads[] = {
[email protected]f871ee152012-07-27 19:02:017412 MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)),
7413 MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)),
[email protected]e0c27be2009-07-15 13:09:357414 MockRead("HTTP/1.0 200 OK\r\n"),
7415 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"),
7416 MockRead("Payload"),
[email protected]8ddf8322012-02-23 18:08:067417 MockRead(SYNCHRONOUS, OK)
[email protected]e0c27be2009-07-15 13:09:357418 };
7419
[email protected]31a2bfe2010-02-09 08:03:397420 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
7421 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:077422 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]e0c27be2009-07-15 13:09:357423
[email protected]49639fa2011-12-20 23:22:417424 TestCompletionCallback callback;
[email protected]e0c27be2009-07-15 13:09:357425
[email protected]49639fa2011-12-20 23:22:417426 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]e0c27be2009-07-15 13:09:357427 EXPECT_EQ(ERR_IO_PENDING, rv);
7428
7429 rv = callback.WaitForResult();
7430 EXPECT_EQ(OK, rv);
7431
7432 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:507433 ASSERT_TRUE(response != NULL);
[email protected]e0c27be2009-07-15 13:09:357434
[email protected]029c83b62013-01-24 05:28:207435 LoadTimingInfo load_timing_info;
7436 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
7437 TestLoadTimingNotReusedWithPac(load_timing_info,
7438 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY);
7439
[email protected]e0c27be2009-07-15 13:09:357440 std::string response_text;
7441 rv = ReadTransaction(trans.get(), &response_text);
7442 EXPECT_EQ(OK, rv);
7443 EXPECT_EQ("Payload", response_text);
7444}
7445
[email protected]23e482282013-06-14 16:08:027446TEST_P(HttpNetworkTransactionTest, SOCKS5_SSL_GET) {
[email protected]cb9bf6ca2011-01-28 13:15:277447 HttpRequestInfo request;
7448 request.method = "GET";
7449 request.url = GURL("https://www.google.com/");
7450 request.load_flags = 0;
7451
[email protected]bb88e1d32013-05-03 23:11:077452 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:207453 ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"));
7454 CapturingNetLog net_log;
[email protected]bb88e1d32013-05-03 23:11:077455 session_deps_.net_log = &net_log;
[email protected]e0c27be2009-07-15 13:09:357456
[email protected]3fe8d2f82013-10-17 08:56:077457 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]e0c27be2009-07-15 13:09:357458 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417459 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]e0c27be2009-07-15 13:09:357460
[email protected]e0c27be2009-07-15 13:09:357461 const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 };
7462 const char kSOCKS5GreetResponse[] = { 0x05, 0x00 };
[email protected]f209dba2009-12-18 00:24:377463 const unsigned char kSOCKS5OkRequest[] = {
7464 0x05, // Version
7465 0x01, // Command (CONNECT)
7466 0x00, // Reserved.
7467 0x03, // Address type (DOMAINNAME).
7468 0x0E, // Length of domain (14)
7469 // Domain string:
7470 'w', 'w', 'w', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'c', 'o', 'm',
7471 0x01, 0xBB, // 16-bit port (443)
7472 };
7473
[email protected]e0c27be2009-07-15 13:09:357474 const char kSOCKS5OkResponse[] =
7475 { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 };
7476
7477 MockWrite data_writes[] = {
[email protected]8ddf8322012-02-23 18:08:067478 MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)),
7479 MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest),
[email protected]e0c27be2009-07-15 13:09:357480 arraysize(kSOCKS5OkRequest)),
7481 MockWrite("GET / HTTP/1.1\r\n"
7482 "Host: www.google.com\r\n"
7483 "Connection: keep-alive\r\n\r\n")
7484 };
7485
7486 MockRead data_reads[] = {
[email protected]f871ee152012-07-27 19:02:017487 MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)),
7488 MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)),
[email protected]3cd17242009-06-23 02:59:027489 MockRead("HTTP/1.0 200 OK\r\n"),
7490 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"),
7491 MockRead("Payload"),
[email protected]8ddf8322012-02-23 18:08:067492 MockRead(SYNCHRONOUS, OK)
[email protected]3cd17242009-06-23 02:59:027493 };
7494
[email protected]31a2bfe2010-02-09 08:03:397495 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
7496 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:077497 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]3cd17242009-06-23 02:59:027498
[email protected]8ddf8322012-02-23 18:08:067499 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]bb88e1d32013-05-03 23:11:077500 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]3cd17242009-06-23 02:59:027501
[email protected]49639fa2011-12-20 23:22:417502 TestCompletionCallback callback;
[email protected]3cd17242009-06-23 02:59:027503
[email protected]49639fa2011-12-20 23:22:417504 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]3cd17242009-06-23 02:59:027505 EXPECT_EQ(ERR_IO_PENDING, rv);
7506
7507 rv = callback.WaitForResult();
7508 EXPECT_EQ(OK, rv);
7509
7510 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:507511 ASSERT_TRUE(response != NULL);
[email protected]3cd17242009-06-23 02:59:027512
[email protected]029c83b62013-01-24 05:28:207513 LoadTimingInfo load_timing_info;
7514 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
7515 TestLoadTimingNotReusedWithPac(load_timing_info,
7516 CONNECT_TIMING_HAS_SSL_TIMES);
7517
[email protected]3cd17242009-06-23 02:59:027518 std::string response_text;
7519 rv = ReadTransaction(trans.get(), &response_text);
7520 EXPECT_EQ(OK, rv);
7521 EXPECT_EQ("Payload", response_text);
7522}
7523
[email protected]448d4ca52012-03-04 04:12:237524namespace {
7525
[email protected]04e5be32009-06-26 20:00:317526// Tests that for connection endpoints the group names are correctly set.
[email protected]2d731a32010-04-29 01:04:067527
7528struct GroupNameTest {
7529 std::string proxy_server;
7530 std::string url;
7531 std::string expected_group_name;
[email protected]e60e47a2010-07-14 03:37:187532 bool ssl;
[email protected]2d731a32010-04-29 01:04:067533};
7534
7535scoped_refptr<HttpNetworkSession> SetupSessionForGroupNameTests(
[email protected]8a0fc822013-06-27 20:52:437536 NextProto next_proto,
[email protected]bb88e1d32013-05-03 23:11:077537 SpdySessionDependencies* session_deps_) {
7538 scoped_refptr<HttpNetworkSession> session(CreateSession(session_deps_));
[email protected]2d731a32010-04-29 01:04:067539
[email protected]30d4c022013-07-18 22:58:167540 base::WeakPtr<HttpServerProperties> http_server_properties =
[email protected]17291a022011-10-10 07:32:537541 session->http_server_properties();
7542 http_server_properties->SetAlternateProtocol(
[email protected]2d731a32010-04-29 01:04:067543 HostPortPair("host.with.alternate", 80), 443,
[email protected]287d9412014-07-08 23:01:007544 AlternateProtocolFromNextProto(next_proto), 1);
[email protected]2d731a32010-04-29 01:04:067545
7546 return session;
7547}
7548
7549int GroupNameTransactionHelper(
7550 const std::string& url,
7551 const scoped_refptr<HttpNetworkSession>& session) {
[email protected]2d731a32010-04-29 01:04:067552 HttpRequestInfo request;
7553 request.method = "GET";
7554 request.url = GURL(url);
7555 request.load_flags = 0;
7556
[email protected]262eec82013-03-19 21:01:367557 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:507558 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:277559
[email protected]49639fa2011-12-20 23:22:417560 TestCompletionCallback callback;
[email protected]2d731a32010-04-29 01:04:067561
7562 // We do not complete this request, the dtor will clean the transaction up.
[email protected]49639fa2011-12-20 23:22:417563 return trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]2d731a32010-04-29 01:04:067564}
7565
[email protected]448d4ca52012-03-04 04:12:237566} // namespace
7567
[email protected]23e482282013-06-14 16:08:027568TEST_P(HttpNetworkTransactionTest, GroupNameForDirectConnections) {
[email protected]2d731a32010-04-29 01:04:067569 const GroupNameTest tests[] = {
[email protected]04e5be32009-06-26 20:00:317570 {
[email protected]2d731a32010-04-29 01:04:067571 "", // unused
[email protected]04e5be32009-06-26 20:00:317572 "http://www.google.com/direct",
[email protected]2ff8b312010-04-26 22:20:547573 "www.google.com:80",
[email protected]e60e47a2010-07-14 03:37:187574 false,
[email protected]2ff8b312010-04-26 22:20:547575 },
7576 {
[email protected]2d731a32010-04-29 01:04:067577 "", // unused
[email protected]2ff8b312010-04-26 22:20:547578 "http://[2001:1418:13:1::25]/direct",
7579 "[2001:1418:13:1::25]:80",
[email protected]e60e47a2010-07-14 03:37:187580 false,
[email protected]04e5be32009-06-26 20:00:317581 },
[email protected]04e5be32009-06-26 20:00:317582
7583 // SSL Tests
7584 {
[email protected]2d731a32010-04-29 01:04:067585 "", // unused
[email protected]04e5be32009-06-26 20:00:317586 "https://www.google.com/direct_ssl",
[email protected]0e88ad602010-05-04 23:47:027587 "ssl/www.google.com:443",
[email protected]e60e47a2010-07-14 03:37:187588 true,
[email protected]04e5be32009-06-26 20:00:317589 },
7590 {
[email protected]2d731a32010-04-29 01:04:067591 "", // unused
7592 "https://[2001:1418:13:1::25]/direct",
[email protected]0e88ad602010-05-04 23:47:027593 "ssl/[2001:1418:13:1::25]:443",
[email protected]e60e47a2010-07-14 03:37:187594 true,
[email protected]04e5be32009-06-26 20:00:317595 },
7596 {
[email protected]2d731a32010-04-29 01:04:067597 "", // unused
[email protected]2ff8b312010-04-26 22:20:547598 "http://host.with.alternate/direct",
[email protected]0e88ad602010-05-04 23:47:027599 "ssl/host.with.alternate:443",
[email protected]e60e47a2010-07-14 03:37:187600 true,
[email protected]2ff8b312010-04-26 22:20:547601 },
[email protected]2d731a32010-04-29 01:04:067602 };
[email protected]2ff8b312010-04-26 22:20:547603
[email protected]d7599122014-05-24 03:37:237604 session_deps_.use_alternate_protocols = true;
[email protected]2d731a32010-04-29 01:04:067605
viettrungluue4a8b882014-10-16 06:17:387606 for (size_t i = 0; i < arraysize(tests); ++i) {
[email protected]bb88e1d32013-05-03 23:11:077607 session_deps_.proxy_service.reset(
[email protected]8b114dd72011-03-25 05:33:027608 ProxyService::CreateFixed(tests[i].proxy_server));
[email protected]2d731a32010-04-29 01:04:067609 scoped_refptr<HttpNetworkSession> session(
[email protected]8a0fc822013-06-27 20:52:437610 SetupSessionForGroupNameTests(GetParam(), &session_deps_));
[email protected]2d731a32010-04-29 01:04:067611
7612 HttpNetworkSessionPeer peer(session);
[email protected]ab739042011-04-07 15:22:287613 CaptureGroupNameTransportSocketPool* transport_conn_pool =
7614 new CaptureGroupNameTransportSocketPool(NULL, NULL);
[email protected]2431756e2010-09-29 20:26:137615 CaptureGroupNameSSLSocketPool* ssl_conn_pool =
[email protected]9e1bdd32011-02-03 21:48:347616 new CaptureGroupNameSSLSocketPool(NULL, NULL);
[email protected]831e4a32013-11-14 02:14:447617 scoped_ptr<MockClientSocketPoolManager> mock_pool_manager(
7618 new MockClientSocketPoolManager);
[email protected]a42dbd142011-11-17 16:42:027619 mock_pool_manager->SetTransportSocketPool(transport_conn_pool);
7620 mock_pool_manager->SetSSLSocketPool(ssl_conn_pool);
dchenge3d1ddc2014-10-15 19:30:517621 peer.SetClientSocketPoolManager(mock_pool_manager.Pass());
[email protected]2d731a32010-04-29 01:04:067622
7623 EXPECT_EQ(ERR_IO_PENDING,
7624 GroupNameTransactionHelper(tests[i].url, session));
[email protected]e60e47a2010-07-14 03:37:187625 if (tests[i].ssl)
7626 EXPECT_EQ(tests[i].expected_group_name,
7627 ssl_conn_pool->last_group_name_received());
7628 else
7629 EXPECT_EQ(tests[i].expected_group_name,
[email protected]ab739042011-04-07 15:22:287630 transport_conn_pool->last_group_name_received());
[email protected]2d731a32010-04-29 01:04:067631 }
7632
[email protected]2d731a32010-04-29 01:04:067633}
7634
[email protected]23e482282013-06-14 16:08:027635TEST_P(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) {
[email protected]2d731a32010-04-29 01:04:067636 const GroupNameTest tests[] = {
7637 {
7638 "http_proxy",
7639 "http://www.google.com/http_proxy_normal",
7640 "www.google.com:80",
[email protected]e60e47a2010-07-14 03:37:187641 false,
[email protected]2d731a32010-04-29 01:04:067642 },
7643
7644 // SSL Tests
7645 {
7646 "http_proxy",
7647 "https://www.google.com/http_connect_ssl",
[email protected]0e88ad602010-05-04 23:47:027648 "ssl/www.google.com:443",
[email protected]e60e47a2010-07-14 03:37:187649 true,
[email protected]2d731a32010-04-29 01:04:067650 },
[email protected]af3490e2010-10-16 21:02:297651
[email protected]9faeded92010-04-29 20:03:057652 {
7653 "http_proxy",
7654 "http://host.with.alternate/direct",
[email protected]0e88ad602010-05-04 23:47:027655 "ssl/host.with.alternate:443",
[email protected]e60e47a2010-07-14 03:37:187656 true,
[email protected]9faeded92010-04-29 20:03:057657 },
[email protected]45499252013-01-23 17:12:567658
7659 {
7660 "http_proxy",
7661 "ftp://ftp.google.com/http_proxy_normal",
7662 "ftp/ftp.google.com:21",
7663 false,
7664 },
[email protected]2d731a32010-04-29 01:04:067665 };
7666
[email protected]d7599122014-05-24 03:37:237667 session_deps_.use_alternate_protocols = true;
[email protected]2d731a32010-04-29 01:04:067668
viettrungluue4a8b882014-10-16 06:17:387669 for (size_t i = 0; i < arraysize(tests); ++i) {
[email protected]bb88e1d32013-05-03 23:11:077670 session_deps_.proxy_service.reset(
[email protected]8b114dd72011-03-25 05:33:027671 ProxyService::CreateFixed(tests[i].proxy_server));
[email protected]2d731a32010-04-29 01:04:067672 scoped_refptr<HttpNetworkSession> session(
[email protected]8a0fc822013-06-27 20:52:437673 SetupSessionForGroupNameTests(GetParam(), &session_deps_));
[email protected]2d731a32010-04-29 01:04:067674
7675 HttpNetworkSessionPeer peer(session);
7676
[email protected]e60e47a2010-07-14 03:37:187677 HostPortPair proxy_host("http_proxy", 80);
[email protected]2431756e2010-09-29 20:26:137678 CaptureGroupNameHttpProxySocketPool* http_proxy_pool =
[email protected]9e1bdd32011-02-03 21:48:347679 new CaptureGroupNameHttpProxySocketPool(NULL, NULL);
[email protected]2431756e2010-09-29 20:26:137680 CaptureGroupNameSSLSocketPool* ssl_conn_pool =
[email protected]9e1bdd32011-02-03 21:48:347681 new CaptureGroupNameSSLSocketPool(NULL, NULL);
[email protected]a42dbd142011-11-17 16:42:027682
[email protected]831e4a32013-11-14 02:14:447683 scoped_ptr<MockClientSocketPoolManager> mock_pool_manager(
7684 new MockClientSocketPoolManager);
[email protected]a42dbd142011-11-17 16:42:027685 mock_pool_manager->SetSocketPoolForHTTPProxy(proxy_host, http_proxy_pool);
7686 mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool);
dchenge3d1ddc2014-10-15 19:30:517687 peer.SetClientSocketPoolManager(mock_pool_manager.Pass());
[email protected]2d731a32010-04-29 01:04:067688
7689 EXPECT_EQ(ERR_IO_PENDING,
7690 GroupNameTransactionHelper(tests[i].url, session));
[email protected]e60e47a2010-07-14 03:37:187691 if (tests[i].ssl)
7692 EXPECT_EQ(tests[i].expected_group_name,
7693 ssl_conn_pool->last_group_name_received());
7694 else
7695 EXPECT_EQ(tests[i].expected_group_name,
7696 http_proxy_pool->last_group_name_received());
[email protected]2d731a32010-04-29 01:04:067697 }
[email protected]2d731a32010-04-29 01:04:067698}
7699
[email protected]23e482282013-06-14 16:08:027700TEST_P(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) {
[email protected]2d731a32010-04-29 01:04:067701 const GroupNameTest tests[] = {
7702 {
7703 "socks4://socks_proxy:1080",
7704 "http://www.google.com/socks4_direct",
7705 "socks4/www.google.com:80",
[email protected]e60e47a2010-07-14 03:37:187706 false,
[email protected]2d731a32010-04-29 01:04:067707 },
7708 {
7709 "socks5://socks_proxy:1080",
7710 "http://www.google.com/socks5_direct",
7711 "socks5/www.google.com:80",
[email protected]e60e47a2010-07-14 03:37:187712 false,
[email protected]2d731a32010-04-29 01:04:067713 },
7714
7715 // SSL Tests
7716 {
7717 "socks4://socks_proxy:1080",
7718 "https://www.google.com/socks4_ssl",
[email protected]0e88ad602010-05-04 23:47:027719 "socks4/ssl/www.google.com:443",
[email protected]e60e47a2010-07-14 03:37:187720 true,
[email protected]2d731a32010-04-29 01:04:067721 },
7722 {
7723 "socks5://socks_proxy:1080",
7724 "https://www.google.com/socks5_ssl",
[email protected]0e88ad602010-05-04 23:47:027725 "socks5/ssl/www.google.com:443",
[email protected]e60e47a2010-07-14 03:37:187726 true,
[email protected]2d731a32010-04-29 01:04:067727 },
[email protected]af3490e2010-10-16 21:02:297728
[email protected]9faeded92010-04-29 20:03:057729 {
7730 "socks4://socks_proxy:1080",
7731 "http://host.with.alternate/direct",
[email protected]0e88ad602010-05-04 23:47:027732 "socks4/ssl/host.with.alternate:443",
[email protected]e60e47a2010-07-14 03:37:187733 true,
[email protected]9faeded92010-04-29 20:03:057734 },
[email protected]04e5be32009-06-26 20:00:317735 };
7736
[email protected]d7599122014-05-24 03:37:237737 session_deps_.use_alternate_protocols = true;
[email protected]2ff8b312010-04-26 22:20:547738
viettrungluue4a8b882014-10-16 06:17:387739 for (size_t i = 0; i < arraysize(tests); ++i) {
[email protected]bb88e1d32013-05-03 23:11:077740 session_deps_.proxy_service.reset(
[email protected]8b114dd72011-03-25 05:33:027741 ProxyService::CreateFixed(tests[i].proxy_server));
[email protected]2d731a32010-04-29 01:04:067742 scoped_refptr<HttpNetworkSession> session(
[email protected]8a0fc822013-06-27 20:52:437743 SetupSessionForGroupNameTests(GetParam(), &session_deps_));
[email protected]8b114dd72011-03-25 05:33:027744
[email protected]2d731a32010-04-29 01:04:067745 HttpNetworkSessionPeer peer(session);
[email protected]04e5be32009-06-26 20:00:317746
[email protected]e60e47a2010-07-14 03:37:187747 HostPortPair proxy_host("socks_proxy", 1080);
[email protected]2431756e2010-09-29 20:26:137748 CaptureGroupNameSOCKSSocketPool* socks_conn_pool =
[email protected]9e1bdd32011-02-03 21:48:347749 new CaptureGroupNameSOCKSSocketPool(NULL, NULL);
[email protected]2431756e2010-09-29 20:26:137750 CaptureGroupNameSSLSocketPool* ssl_conn_pool =
[email protected]9e1bdd32011-02-03 21:48:347751 new CaptureGroupNameSSLSocketPool(NULL, NULL);
[email protected]a42dbd142011-11-17 16:42:027752
[email protected]831e4a32013-11-14 02:14:447753 scoped_ptr<MockClientSocketPoolManager> mock_pool_manager(
7754 new MockClientSocketPoolManager);
[email protected]a42dbd142011-11-17 16:42:027755 mock_pool_manager->SetSocketPoolForSOCKSProxy(proxy_host, socks_conn_pool);
7756 mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool);
dchenge3d1ddc2014-10-15 19:30:517757 peer.SetClientSocketPoolManager(mock_pool_manager.Pass());
[email protected]04e5be32009-06-26 20:00:317758
[email protected]262eec82013-03-19 21:01:367759 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:507760 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]04e5be32009-06-26 20:00:317761
[email protected]2d731a32010-04-29 01:04:067762 EXPECT_EQ(ERR_IO_PENDING,
7763 GroupNameTransactionHelper(tests[i].url, session));
[email protected]e60e47a2010-07-14 03:37:187764 if (tests[i].ssl)
7765 EXPECT_EQ(tests[i].expected_group_name,
7766 ssl_conn_pool->last_group_name_received());
7767 else
7768 EXPECT_EQ(tests[i].expected_group_name,
7769 socks_conn_pool->last_group_name_received());
[email protected]04e5be32009-06-26 20:00:317770 }
7771}
7772
[email protected]23e482282013-06-14 16:08:027773TEST_P(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) {
[email protected]cb9bf6ca2011-01-28 13:15:277774 HttpRequestInfo request;
7775 request.method = "GET";
7776 request.url = GURL("http://www.google.com/");
7777
[email protected]bb88e1d32013-05-03 23:11:077778 session_deps_.proxy_service.reset(
[email protected]81cdfcd2010-10-16 00:49:007779 ProxyService::CreateFixed("myproxy:70;foobar:80"));
[email protected]b59ff372009-07-15 22:04:327780
[email protected]69719062010-01-05 20:09:217781 // This simulates failure resolving all hostnames; that means we will fail
7782 // connecting to both proxies (myproxy:70 and foobar:80).
[email protected]bb88e1d32013-05-03 23:11:077783 session_deps_.host_resolver->rules()->AddSimulatedFailure("*");
[email protected]b59ff372009-07-15 22:04:327784
[email protected]3fe8d2f82013-10-17 08:56:077785 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]9172a982009-06-06 00:30:257786 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417787 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]9172a982009-06-06 00:30:257788
[email protected]49639fa2011-12-20 23:22:417789 TestCompletionCallback callback;
[email protected]9172a982009-06-06 00:30:257790
[email protected]49639fa2011-12-20 23:22:417791 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]9172a982009-06-06 00:30:257792 EXPECT_EQ(ERR_IO_PENDING, rv);
7793
[email protected]9172a982009-06-06 00:30:257794 rv = callback.WaitForResult();
[email protected]f7fccee2010-09-16 20:53:017795 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv);
[email protected]9172a982009-06-06 00:30:257796}
7797
[email protected]685af592010-05-11 19:31:247798// Base test to make sure that when the load flags for a request specify to
7799// bypass the cache, the DNS cache is not used.
[email protected]23e482282013-06-14 16:08:027800void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper(
[email protected]bb88e1d32013-05-03 23:11:077801 int load_flags) {
[email protected]cb9bf6ca2011-01-28 13:15:277802 // Issue a request, asking to bypass the cache(s).
7803 HttpRequestInfo request;
7804 request.method = "GET";
7805 request.load_flags = load_flags;
7806 request.url = GURL("http://www.google.com/");
7807
[email protected]a2c2fb92009-07-18 07:31:047808 // Select a host resolver that does caching.
[email protected]bb88e1d32013-05-03 23:11:077809 session_deps_.host_resolver.reset(new MockCachingHostResolver);
[email protected]b59ff372009-07-15 22:04:327810
[email protected]3fe8d2f82013-10-17 08:56:077811 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
7812 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417813 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]3b9cca42009-06-16 01:08:287814
[email protected]6e78dfb2011-07-28 21:34:477815 // Warm up the host cache so it has an entry for "www.google.com".
[email protected]3b9cca42009-06-16 01:08:287816 AddressList addrlist;
[email protected]aa22b242011-11-16 18:58:297817 TestCompletionCallback callback;
[email protected]bb88e1d32013-05-03 23:11:077818 int rv = session_deps_.host_resolver->Resolve(
[email protected]5109c1952013-08-20 18:44:107819 HostResolver::RequestInfo(HostPortPair("www.google.com", 80)),
7820 DEFAULT_PRIORITY,
[email protected]b9823c02013-08-16 21:24:417821 &addrlist,
7822 callback.callback(),
7823 NULL,
7824 BoundNetLog());
[email protected]6e78dfb2011-07-28 21:34:477825 EXPECT_EQ(ERR_IO_PENDING, rv);
7826 rv = callback.WaitForResult();
[email protected]3b9cca42009-06-16 01:08:287827 EXPECT_EQ(OK, rv);
7828
7829 // Verify that it was added to host cache, by doing a subsequent async lookup
7830 // and confirming it completes synchronously.
[email protected]bb88e1d32013-05-03 23:11:077831 rv = session_deps_.host_resolver->Resolve(
[email protected]5109c1952013-08-20 18:44:107832 HostResolver::RequestInfo(HostPortPair("www.google.com", 80)),
7833 DEFAULT_PRIORITY,
[email protected]b9823c02013-08-16 21:24:417834 &addrlist,
7835 callback.callback(),
7836 NULL,
7837 BoundNetLog());
[email protected]b59ff372009-07-15 22:04:327838 ASSERT_EQ(OK, rv);
[email protected]3b9cca42009-06-16 01:08:287839
7840 // Inject a failure the next time that "www.google.com" is resolved. This way
7841 // we can tell if the next lookup hit the cache, or the "network".
7842 // (cache --> success, "network" --> failure).
[email protected]bb88e1d32013-05-03 23:11:077843 session_deps_.host_resolver->rules()->AddSimulatedFailure("www.google.com");
[email protected]3b9cca42009-06-16 01:08:287844
7845 // Connect up a mock socket which will fail with ERR_UNEXPECTED during the
7846 // first read -- this won't be reached as the host resolution will fail first.
[email protected]8ddf8322012-02-23 18:08:067847 MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) };
[email protected]31a2bfe2010-02-09 08:03:397848 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:077849 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]3b9cca42009-06-16 01:08:287850
[email protected]3b9cca42009-06-16 01:08:287851 // Run the request.
[email protected]49639fa2011-12-20 23:22:417852 rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]3b9cca42009-06-16 01:08:287853 ASSERT_EQ(ERR_IO_PENDING, rv);
[email protected]49639fa2011-12-20 23:22:417854 rv = callback.WaitForResult();
[email protected]3b9cca42009-06-16 01:08:287855
7856 // If we bypassed the cache, we would have gotten a failure while resolving
7857 // "www.google.com".
7858 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv);
7859}
7860
[email protected]685af592010-05-11 19:31:247861// There are multiple load flags that should trigger the host cache bypass.
7862// Test each in isolation:
[email protected]23e482282013-06-14 16:08:027863TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) {
[email protected]685af592010-05-11 19:31:247864 BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE);
7865}
7866
[email protected]23e482282013-06-14 16:08:027867TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) {
[email protected]685af592010-05-11 19:31:247868 BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE);
7869}
7870
[email protected]23e482282013-06-14 16:08:027871TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) {
[email protected]685af592010-05-11 19:31:247872 BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE);
7873}
7874
[email protected]0877e3d2009-10-17 22:29:577875// Make sure we can handle an error when writing the request.
[email protected]23e482282013-06-14 16:08:027876TEST_P(HttpNetworkTransactionTest, RequestWriteError) {
[email protected]0877e3d2009-10-17 22:29:577877 HttpRequestInfo request;
7878 request.method = "GET";
7879 request.url = GURL("http://www.foo.com/");
7880 request.load_flags = 0;
7881
7882 MockWrite write_failure[] = {
[email protected]8ddf8322012-02-23 18:08:067883 MockWrite(ASYNC, ERR_CONNECTION_RESET),
[email protected]0877e3d2009-10-17 22:29:577884 };
[email protected]31a2bfe2010-02-09 08:03:397885 StaticSocketDataProvider data(NULL, 0,
7886 write_failure, arraysize(write_failure));
[email protected]bb88e1d32013-05-03 23:11:077887 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]3fe8d2f82013-10-17 08:56:077888 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]0877e3d2009-10-17 22:29:577889
[email protected]49639fa2011-12-20 23:22:417890 TestCompletionCallback callback;
[email protected]0877e3d2009-10-17 22:29:577891
7892 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417893 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0877e3d2009-10-17 22:29:577894
[email protected]49639fa2011-12-20 23:22:417895 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]0877e3d2009-10-17 22:29:577896 EXPECT_EQ(ERR_IO_PENDING, rv);
7897
7898 rv = callback.WaitForResult();
7899 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
7900}
7901
7902// Check that a connection closed after the start of the headers finishes ok.
[email protected]23e482282013-06-14 16:08:027903TEST_P(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) {
[email protected]0877e3d2009-10-17 22:29:577904 HttpRequestInfo request;
7905 request.method = "GET";
7906 request.url = GURL("http://www.foo.com/");
7907 request.load_flags = 0;
7908
7909 MockRead data_reads[] = {
7910 MockRead("HTTP/1."),
[email protected]8ddf8322012-02-23 18:08:067911 MockRead(SYNCHRONOUS, OK),
[email protected]0877e3d2009-10-17 22:29:577912 };
7913
[email protected]31a2bfe2010-02-09 08:03:397914 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:077915 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]3fe8d2f82013-10-17 08:56:077916 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]0877e3d2009-10-17 22:29:577917
[email protected]49639fa2011-12-20 23:22:417918 TestCompletionCallback callback;
[email protected]0877e3d2009-10-17 22:29:577919
7920 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417921 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0877e3d2009-10-17 22:29:577922
[email protected]49639fa2011-12-20 23:22:417923 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]0877e3d2009-10-17 22:29:577924 EXPECT_EQ(ERR_IO_PENDING, rv);
7925
7926 rv = callback.WaitForResult();
7927 EXPECT_EQ(OK, rv);
7928
7929 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:507930 ASSERT_TRUE(response != NULL);
[email protected]0877e3d2009-10-17 22:29:577931
[email protected]90499482013-06-01 00:39:507932 EXPECT_TRUE(response->headers.get() != NULL);
[email protected]0877e3d2009-10-17 22:29:577933 EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine());
7934
7935 std::string response_data;
7936 rv = ReadTransaction(trans.get(), &response_data);
7937 EXPECT_EQ(OK, rv);
7938 EXPECT_EQ("", response_data);
7939}
7940
7941// Make sure that a dropped connection while draining the body for auth
7942// restart does the right thing.
[email protected]23e482282013-06-14 16:08:027943TEST_P(HttpNetworkTransactionTest, DrainResetOK) {
[email protected]0877e3d2009-10-17 22:29:577944 HttpRequestInfo request;
7945 request.method = "GET";
7946 request.url = GURL("http://www.google.com/");
7947 request.load_flags = 0;
7948
7949 MockWrite data_writes1[] = {
7950 MockWrite("GET / HTTP/1.1\r\n"
7951 "Host: www.google.com\r\n"
7952 "Connection: keep-alive\r\n\r\n"),
7953 };
7954
7955 MockRead data_reads1[] = {
7956 MockRead("HTTP/1.1 401 Unauthorized\r\n"),
7957 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
7958 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
7959 MockRead("Content-Length: 14\r\n\r\n"),
7960 MockRead("Unauth"),
[email protected]8ddf8322012-02-23 18:08:067961 MockRead(ASYNC, ERR_CONNECTION_RESET),
[email protected]0877e3d2009-10-17 22:29:577962 };
7963
[email protected]31a2bfe2010-02-09 08:03:397964 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
7965 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:077966 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]0877e3d2009-10-17 22:29:577967
7968 // After calling trans->RestartWithAuth(), this is the request we should
7969 // be issuing -- the final header line contains the credentials.
7970 MockWrite data_writes2[] = {
7971 MockWrite("GET / HTTP/1.1\r\n"
7972 "Host: www.google.com\r\n"
7973 "Connection: keep-alive\r\n"
7974 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
7975 };
7976
7977 // Lastly, the server responds with the actual content.
7978 MockRead data_reads2[] = {
7979 MockRead("HTTP/1.1 200 OK\r\n"),
7980 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
7981 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:067982 MockRead(SYNCHRONOUS, OK),
[email protected]0877e3d2009-10-17 22:29:577983 };
7984
[email protected]31a2bfe2010-02-09 08:03:397985 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
7986 data_writes2, arraysize(data_writes2));
[email protected]bb88e1d32013-05-03 23:11:077987 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]3fe8d2f82013-10-17 08:56:077988 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]0877e3d2009-10-17 22:29:577989
[email protected]49639fa2011-12-20 23:22:417990 TestCompletionCallback callback1;
[email protected]0877e3d2009-10-17 22:29:577991
[email protected]262eec82013-03-19 21:01:367992 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:507993 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0b0bf032010-09-21 18:08:507994
[email protected]49639fa2011-12-20 23:22:417995 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]0877e3d2009-10-17 22:29:577996 EXPECT_EQ(ERR_IO_PENDING, rv);
7997
7998 rv = callback1.WaitForResult();
7999 EXPECT_EQ(OK, rv);
8000
8001 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:508002 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:048003 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
[email protected]0877e3d2009-10-17 22:29:578004
[email protected]49639fa2011-12-20 23:22:418005 TestCompletionCallback callback2;
[email protected]0877e3d2009-10-17 22:29:578006
[email protected]49639fa2011-12-20 23:22:418007 rv = trans->RestartWithAuth(
8008 AuthCredentials(kFoo, kBar), callback2.callback());
[email protected]0877e3d2009-10-17 22:29:578009 EXPECT_EQ(ERR_IO_PENDING, rv);
8010
8011 rv = callback2.WaitForResult();
8012 EXPECT_EQ(OK, rv);
8013
8014 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:508015 ASSERT_TRUE(response != NULL);
[email protected]0877e3d2009-10-17 22:29:578016 EXPECT_TRUE(response->auth_challenge.get() == NULL);
8017 EXPECT_EQ(100, response->headers->GetContentLength());
8018}
8019
8020// Test HTTPS connections going through a proxy that sends extra data.
[email protected]23e482282013-06-14 16:08:028021TEST_P(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) {
[email protected]bb88e1d32013-05-03 23:11:078022 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70"));
[email protected]0877e3d2009-10-17 22:29:578023
8024 HttpRequestInfo request;
8025 request.method = "GET";
8026 request.url = GURL("https://www.google.com/");
8027 request.load_flags = 0;
8028
8029 MockRead proxy_reads[] = {
8030 MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"),
[email protected]8ddf8322012-02-23 18:08:068031 MockRead(SYNCHRONOUS, OK)
[email protected]0877e3d2009-10-17 22:29:578032 };
8033
[email protected]31a2bfe2010-02-09 08:03:398034 StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0);
[email protected]8ddf8322012-02-23 18:08:068035 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]0877e3d2009-10-17 22:29:578036
[email protected]bb88e1d32013-05-03 23:11:078037 session_deps_.socket_factory->AddSocketDataProvider(&data);
8038 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]0877e3d2009-10-17 22:29:578039
[email protected]49639fa2011-12-20 23:22:418040 TestCompletionCallback callback;
[email protected]0877e3d2009-10-17 22:29:578041
[email protected]bb88e1d32013-05-03 23:11:078042 session_deps_.socket_factory->ResetNextMockIndexes();
[email protected]0877e3d2009-10-17 22:29:578043
[email protected]3fe8d2f82013-10-17 08:56:078044 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]0877e3d2009-10-17 22:29:578045 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:418046 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0877e3d2009-10-17 22:29:578047
[email protected]49639fa2011-12-20 23:22:418048 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]0877e3d2009-10-17 22:29:578049 EXPECT_EQ(ERR_IO_PENDING, rv);
8050
8051 rv = callback.WaitForResult();
8052 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv);
8053}
8054
[email protected]23e482282013-06-14 16:08:028055TEST_P(HttpNetworkTransactionTest, LargeContentLengthThenClose) {
[email protected]9492e4a2010-02-24 00:58:468056 HttpRequestInfo request;
8057 request.method = "GET";
8058 request.url = GURL("http://www.google.com/");
8059 request.load_flags = 0;
8060
[email protected]3fe8d2f82013-10-17 08:56:078061 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:278062 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:418063 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:278064
[email protected]e22e1362009-11-23 21:31:128065 MockRead data_reads[] = {
8066 MockRead("HTTP/1.0 200 OK\r\nContent-Length:6719476739\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:068067 MockRead(SYNCHRONOUS, OK),
[email protected]e22e1362009-11-23 21:31:128068 };
[email protected]9492e4a2010-02-24 00:58:468069
8070 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078071 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]9492e4a2010-02-24 00:58:468072
[email protected]49639fa2011-12-20 23:22:418073 TestCompletionCallback callback;
[email protected]9492e4a2010-02-24 00:58:468074
[email protected]49639fa2011-12-20 23:22:418075 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]9492e4a2010-02-24 00:58:468076 EXPECT_EQ(ERR_IO_PENDING, rv);
8077
8078 EXPECT_EQ(OK, callback.WaitForResult());
8079
8080 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:508081 ASSERT_TRUE(response != NULL);
[email protected]9492e4a2010-02-24 00:58:468082
[email protected]90499482013-06-01 00:39:508083 EXPECT_TRUE(response->headers.get() != NULL);
[email protected]9492e4a2010-02-24 00:58:468084 EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine());
8085
8086 std::string response_data;
8087 rv = ReadTransaction(trans.get(), &response_data);
[email protected]5543cbb2012-04-20 16:35:238088 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv);
[email protected]e22e1362009-11-23 21:31:128089}
8090
[email protected]23e482282013-06-14 16:08:028091TEST_P(HttpNetworkTransactionTest, UploadFileSmallerThanLength) {
[email protected]6cdfd7f2013-02-08 20:40:158092 base::FilePath temp_file_path;
[email protected]03d9afc02013-12-03 17:55:528093 ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path));
[email protected]95d88ffe2010-02-04 21:25:338094 const uint64 kFakeSize = 100000; // file is actually blank
[email protected]d98961652012-09-11 20:27:218095 UploadFileElementReader::ScopedOverridingContentLengthForTests
8096 overriding_content_length(kFakeSize);
[email protected]95d88ffe2010-02-04 21:25:338097
[email protected]b2d26cfd2012-12-11 10:36:068098 ScopedVector<UploadElementReader> element_readers;
8099 element_readers.push_back(
[email protected]cadac622013-06-11 16:46:368100 new UploadFileElementReader(base::MessageLoopProxy::current().get(),
8101 temp_file_path,
8102 0,
8103 kuint64max,
8104 base::Time()));
mmenkecbc2b712014-10-09 20:29:078105 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]329b68b2012-11-14 17:54:278106
8107 HttpRequestInfo request;
8108 request.method = "POST";
8109 request.url = GURL("http://www.google.com/upload");
8110 request.upload_data_stream = &upload_data_stream;
8111 request.load_flags = 0;
8112
[email protected]3fe8d2f82013-10-17 08:56:078113 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]329b68b2012-11-14 17:54:278114 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:418115 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]95d88ffe2010-02-04 21:25:338116
8117 MockRead data_reads[] = {
8118 MockRead("HTTP/1.0 200 OK\r\n\r\n"),
8119 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:068120 MockRead(SYNCHRONOUS, OK),
[email protected]95d88ffe2010-02-04 21:25:338121 };
[email protected]31a2bfe2010-02-09 08:03:398122 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078123 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]95d88ffe2010-02-04 21:25:338124
[email protected]49639fa2011-12-20 23:22:418125 TestCompletionCallback callback;
[email protected]95d88ffe2010-02-04 21:25:338126
[email protected]49639fa2011-12-20 23:22:418127 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]95d88ffe2010-02-04 21:25:338128 EXPECT_EQ(ERR_IO_PENDING, rv);
8129
8130 rv = callback.WaitForResult();
8131 EXPECT_EQ(OK, rv);
8132
8133 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:508134 ASSERT_TRUE(response != NULL);
[email protected]95d88ffe2010-02-04 21:25:338135
[email protected]90499482013-06-01 00:39:508136 EXPECT_TRUE(response->headers.get() != NULL);
[email protected]95d88ffe2010-02-04 21:25:338137 EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine());
8138
8139 std::string response_data;
8140 rv = ReadTransaction(trans.get(), &response_data);
8141 EXPECT_EQ(OK, rv);
8142 EXPECT_EQ("hello world", response_data);
8143
[email protected]dd3aa792013-07-16 19:10:238144 base::DeleteFile(temp_file_path, false);
[email protected]95d88ffe2010-02-04 21:25:338145}
8146
[email protected]23e482282013-06-14 16:08:028147TEST_P(HttpNetworkTransactionTest, UploadUnreadableFile) {
[email protected]6cdfd7f2013-02-08 20:40:158148 base::FilePath temp_file;
[email protected]03d9afc02013-12-03 17:55:528149 ASSERT_TRUE(base::CreateTemporaryFile(&temp_file));
[email protected]6624b4622010-03-29 19:58:368150 std::string temp_file_content("Unreadable file.");
[email protected]e5c2a22e2014-03-06 20:42:308151 ASSERT_TRUE(base::WriteFile(temp_file, temp_file_content.c_str(),
[email protected]6624b4622010-03-29 19:58:368152 temp_file_content.length()));
[email protected]92be8eb2014-08-07 22:57:118153 ASSERT_TRUE(base::MakeFileUnreadable(temp_file));
[email protected]6624b4622010-03-29 19:58:368154
[email protected]b2d26cfd2012-12-11 10:36:068155 ScopedVector<UploadElementReader> element_readers;
8156 element_readers.push_back(
[email protected]cadac622013-06-11 16:46:368157 new UploadFileElementReader(base::MessageLoopProxy::current().get(),
8158 temp_file,
8159 0,
8160 kuint64max,
8161 base::Time()));
mmenkecbc2b712014-10-09 20:29:078162 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]329b68b2012-11-14 17:54:278163
8164 HttpRequestInfo request;
8165 request.method = "POST";
8166 request.url = GURL("http://www.google.com/upload");
8167 request.upload_data_stream = &upload_data_stream;
8168 request.load_flags = 0;
8169
[email protected]999dd8c2013-11-12 06:45:548170 // If we try to upload an unreadable file, the transaction should fail.
[email protected]3fe8d2f82013-10-17 08:56:078171 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]329b68b2012-11-14 17:54:278172 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:418173 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]6624b4622010-03-29 19:58:368174
[email protected]999dd8c2013-11-12 06:45:548175 StaticSocketDataProvider data(NULL, 0, NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078176 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]6624b4622010-03-29 19:58:368177
[email protected]49639fa2011-12-20 23:22:418178 TestCompletionCallback callback;
[email protected]6624b4622010-03-29 19:58:368179
[email protected]49639fa2011-12-20 23:22:418180 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]6624b4622010-03-29 19:58:368181 EXPECT_EQ(ERR_IO_PENDING, rv);
8182
8183 rv = callback.WaitForResult();
[email protected]999dd8c2013-11-12 06:45:548184 EXPECT_EQ(ERR_ACCESS_DENIED, rv);
[email protected]6624b4622010-03-29 19:58:368185
8186 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]999dd8c2013-11-12 06:45:548187 EXPECT_FALSE(response);
[email protected]6624b4622010-03-29 19:58:368188
[email protected]dd3aa792013-07-16 19:10:238189 base::DeleteFile(temp_file, false);
[email protected]6624b4622010-03-29 19:58:368190}
8191
[email protected]02cad5d2013-10-02 08:14:038192TEST_P(HttpNetworkTransactionTest, CancelDuringInitRequestBody) {
8193 class FakeUploadElementReader : public UploadElementReader {
8194 public:
8195 FakeUploadElementReader() {}
dchengb03027d2014-10-21 12:00:208196 ~FakeUploadElementReader() override {}
[email protected]02cad5d2013-10-02 08:14:038197
8198 const CompletionCallback& callback() const { return callback_; }
8199
8200 // UploadElementReader overrides:
dchengb03027d2014-10-21 12:00:208201 int Init(const CompletionCallback& callback) override {
[email protected]02cad5d2013-10-02 08:14:038202 callback_ = callback;
8203 return ERR_IO_PENDING;
8204 }
dchengb03027d2014-10-21 12:00:208205 uint64 GetContentLength() const override { return 0; }
8206 uint64 BytesRemaining() const override { return 0; }
8207 int Read(IOBuffer* buf,
8208 int buf_length,
8209 const CompletionCallback& callback) override {
[email protected]02cad5d2013-10-02 08:14:038210 return ERR_FAILED;
8211 }
8212
8213 private:
8214 CompletionCallback callback_;
8215 };
8216
8217 FakeUploadElementReader* fake_reader = new FakeUploadElementReader;
8218 ScopedVector<UploadElementReader> element_readers;
8219 element_readers.push_back(fake_reader);
mmenkecbc2b712014-10-09 20:29:078220 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]02cad5d2013-10-02 08:14:038221
8222 HttpRequestInfo request;
8223 request.method = "POST";
8224 request.url = GURL("http://www.google.com/upload");
8225 request.upload_data_stream = &upload_data_stream;
8226 request.load_flags = 0;
8227
[email protected]3fe8d2f82013-10-17 08:56:078228 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]02cad5d2013-10-02 08:14:038229 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:418230 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02cad5d2013-10-02 08:14:038231
8232 StaticSocketDataProvider data;
8233 session_deps_.socket_factory->AddSocketDataProvider(&data);
8234
8235 TestCompletionCallback callback;
8236 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
8237 EXPECT_EQ(ERR_IO_PENDING, rv);
8238 base::MessageLoop::current()->RunUntilIdle();
8239
8240 // Transaction is pending on request body initialization.
8241 ASSERT_FALSE(fake_reader->callback().is_null());
8242
8243 // Return Init()'s result after the transaction gets destroyed.
8244 trans.reset();
8245 fake_reader->callback().Run(OK); // Should not crash.
8246}
8247
[email protected]aeefc9e82010-02-19 16:18:278248// Tests that changes to Auth realms are treated like auth rejections.
[email protected]23e482282013-06-14 16:08:028249TEST_P(HttpNetworkTransactionTest, ChangeAuthRealms) {
[email protected]aeefc9e82010-02-19 16:18:278250
8251 HttpRequestInfo request;
8252 request.method = "GET";
8253 request.url = GURL("http://www.google.com/");
8254 request.load_flags = 0;
8255
8256 // First transaction will request a resource and receive a Basic challenge
8257 // with realm="first_realm".
8258 MockWrite data_writes1[] = {
8259 MockWrite("GET / HTTP/1.1\r\n"
8260 "Host: www.google.com\r\n"
8261 "Connection: keep-alive\r\n"
8262 "\r\n"),
8263 };
8264 MockRead data_reads1[] = {
8265 MockRead("HTTP/1.1 401 Unauthorized\r\n"
8266 "WWW-Authenticate: Basic realm=\"first_realm\"\r\n"
8267 "\r\n"),
8268 };
8269
8270 // After calling trans->RestartWithAuth(), provide an Authentication header
8271 // for first_realm. The server will reject and provide a challenge with
8272 // second_realm.
8273 MockWrite data_writes2[] = {
8274 MockWrite("GET / HTTP/1.1\r\n"
8275 "Host: www.google.com\r\n"
8276 "Connection: keep-alive\r\n"
8277 "Authorization: Basic Zmlyc3Q6YmF6\r\n"
8278 "\r\n"),
8279 };
8280 MockRead data_reads2[] = {
8281 MockRead("HTTP/1.1 401 Unauthorized\r\n"
8282 "WWW-Authenticate: Basic realm=\"second_realm\"\r\n"
8283 "\r\n"),
8284 };
8285
8286 // This again fails, and goes back to first_realm. Make sure that the
8287 // entry is removed from cache.
8288 MockWrite data_writes3[] = {
8289 MockWrite("GET / HTTP/1.1\r\n"
8290 "Host: www.google.com\r\n"
8291 "Connection: keep-alive\r\n"
8292 "Authorization: Basic c2Vjb25kOmZvdQ==\r\n"
8293 "\r\n"),
8294 };
8295 MockRead data_reads3[] = {
8296 MockRead("HTTP/1.1 401 Unauthorized\r\n"
8297 "WWW-Authenticate: Basic realm=\"first_realm\"\r\n"
8298 "\r\n"),
8299 };
8300
8301 // Try one last time (with the correct password) and get the resource.
8302 MockWrite data_writes4[] = {
8303 MockWrite("GET / HTTP/1.1\r\n"
8304 "Host: www.google.com\r\n"
8305 "Connection: keep-alive\r\n"
8306 "Authorization: Basic Zmlyc3Q6YmFy\r\n"
8307 "\r\n"),
8308 };
8309 MockRead data_reads4[] = {
8310 MockRead("HTTP/1.1 200 OK\r\n"
8311 "Content-Type: text/html; charset=iso-8859-1\r\n"
[email protected]0b0bf032010-09-21 18:08:508312 "Content-Length: 5\r\n"
8313 "\r\n"
8314 "hello"),
[email protected]aeefc9e82010-02-19 16:18:278315 };
8316
8317 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
8318 data_writes1, arraysize(data_writes1));
8319 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
8320 data_writes2, arraysize(data_writes2));
8321 StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3),
8322 data_writes3, arraysize(data_writes3));
8323 StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4),
8324 data_writes4, arraysize(data_writes4));
[email protected]bb88e1d32013-05-03 23:11:078325 session_deps_.socket_factory->AddSocketDataProvider(&data1);
8326 session_deps_.socket_factory->AddSocketDataProvider(&data2);
8327 session_deps_.socket_factory->AddSocketDataProvider(&data3);
8328 session_deps_.socket_factory->AddSocketDataProvider(&data4);
[email protected]aeefc9e82010-02-19 16:18:278329
[email protected]49639fa2011-12-20 23:22:418330 TestCompletionCallback callback1;
[email protected]aeefc9e82010-02-19 16:18:278331
[email protected]3fe8d2f82013-10-17 08:56:078332 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]0b0bf032010-09-21 18:08:508333 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:418334 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0b0bf032010-09-21 18:08:508335
[email protected]aeefc9e82010-02-19 16:18:278336 // Issue the first request with Authorize headers. There should be a
8337 // password prompt for first_realm waiting to be filled in after the
8338 // transaction completes.
[email protected]49639fa2011-12-20 23:22:418339 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]aeefc9e82010-02-19 16:18:278340 EXPECT_EQ(ERR_IO_PENDING, rv);
8341 rv = callback1.WaitForResult();
8342 EXPECT_EQ(OK, rv);
8343 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:508344 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:048345 const AuthChallengeInfo* challenge = response->auth_challenge.get();
8346 ASSERT_FALSE(challenge == NULL);
8347 EXPECT_FALSE(challenge->is_proxy);
8348 EXPECT_EQ("www.google.com:80", challenge->challenger.ToString());
8349 EXPECT_EQ("first_realm", challenge->realm);
8350 EXPECT_EQ("basic", challenge->scheme);
[email protected]aeefc9e82010-02-19 16:18:278351
8352 // Issue the second request with an incorrect password. There should be a
8353 // password prompt for second_realm waiting to be filled in after the
8354 // transaction completes.
[email protected]49639fa2011-12-20 23:22:418355 TestCompletionCallback callback2;
8356 rv = trans->RestartWithAuth(
8357 AuthCredentials(kFirst, kBaz), callback2.callback());
[email protected]aeefc9e82010-02-19 16:18:278358 EXPECT_EQ(ERR_IO_PENDING, rv);
8359 rv = callback2.WaitForResult();
8360 EXPECT_EQ(OK, rv);
8361 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:508362 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:048363 challenge = response->auth_challenge.get();
8364 ASSERT_FALSE(challenge == NULL);
8365 EXPECT_FALSE(challenge->is_proxy);
8366 EXPECT_EQ("www.google.com:80", challenge->challenger.ToString());
8367 EXPECT_EQ("second_realm", challenge->realm);
8368 EXPECT_EQ("basic", challenge->scheme);
[email protected]aeefc9e82010-02-19 16:18:278369
8370 // Issue the third request with another incorrect password. There should be
8371 // a password prompt for first_realm waiting to be filled in. If the password
8372 // prompt is not present, it indicates that the HttpAuthCacheEntry for
8373 // first_realm was not correctly removed.
[email protected]49639fa2011-12-20 23:22:418374 TestCompletionCallback callback3;
8375 rv = trans->RestartWithAuth(
8376 AuthCredentials(kSecond, kFou), callback3.callback());
[email protected]aeefc9e82010-02-19 16:18:278377 EXPECT_EQ(ERR_IO_PENDING, rv);
8378 rv = callback3.WaitForResult();
8379 EXPECT_EQ(OK, rv);
8380 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:508381 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:048382 challenge = response->auth_challenge.get();
8383 ASSERT_FALSE(challenge == NULL);
8384 EXPECT_FALSE(challenge->is_proxy);
8385 EXPECT_EQ("www.google.com:80", challenge->challenger.ToString());
8386 EXPECT_EQ("first_realm", challenge->realm);
8387 EXPECT_EQ("basic", challenge->scheme);
[email protected]aeefc9e82010-02-19 16:18:278388
8389 // Issue the fourth request with the correct password and username.
[email protected]49639fa2011-12-20 23:22:418390 TestCompletionCallback callback4;
8391 rv = trans->RestartWithAuth(
8392 AuthCredentials(kFirst, kBar), callback4.callback());
[email protected]aeefc9e82010-02-19 16:18:278393 EXPECT_EQ(ERR_IO_PENDING, rv);
8394 rv = callback4.WaitForResult();
8395 EXPECT_EQ(OK, rv);
8396 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:508397 ASSERT_TRUE(response != NULL);
[email protected]aeefc9e82010-02-19 16:18:278398 EXPECT_TRUE(response->auth_challenge.get() == NULL);
8399}
8400
[email protected]23e482282013-06-14 16:08:028401TEST_P(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) {
[email protected]d7599122014-05-24 03:37:238402 session_deps_.next_protos = SpdyNextProtos();
8403 session_deps_.use_alternate_protocols = true;
[email protected]a2cb8122010-03-10 17:22:428404
[email protected]8a0fc822013-06-27 20:52:438405 std::string alternate_protocol_http_header =
8406 GetAlternateProtocolHttpHeader();
8407
[email protected]564b4912010-03-09 16:30:428408 MockRead data_reads[] = {
8409 MockRead("HTTP/1.1 200 OK\r\n"),
[email protected]8a0fc822013-06-27 20:52:438410 MockRead(alternate_protocol_http_header.c_str()),
[email protected]564b4912010-03-09 16:30:428411 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:068412 MockRead(SYNCHRONOUS, OK),
[email protected]564b4912010-03-09 16:30:428413 };
8414
8415 HttpRequestInfo request;
8416 request.method = "GET";
8417 request.url = GURL("http://www.google.com/");
8418 request.load_flags = 0;
8419
8420 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
8421
[email protected]bb88e1d32013-05-03 23:11:078422 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]564b4912010-03-09 16:30:428423
[email protected]49639fa2011-12-20 23:22:418424 TestCompletionCallback callback;
[email protected]564b4912010-03-09 16:30:428425
[email protected]bb88e1d32013-05-03 23:11:078426 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:368427 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:508428 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]564b4912010-03-09 16:30:428429
[email protected]49639fa2011-12-20 23:22:418430 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]564b4912010-03-09 16:30:428431 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]9e743cd2010-03-16 07:03:538432
[email protected]2fbaecf22010-07-22 22:20:358433 HostPortPair http_host_port_pair("www.google.com", 80);
[email protected]9801e3702014-03-07 09:33:558434 HttpServerProperties& http_server_properties =
[email protected]17291a022011-10-10 07:32:538435 *session->http_server_properties();
[email protected]564b4912010-03-09 16:30:428436 EXPECT_FALSE(
[email protected]17291a022011-10-10 07:32:538437 http_server_properties.HasAlternateProtocol(http_host_port_pair));
[email protected]564b4912010-03-09 16:30:428438
8439 EXPECT_EQ(OK, callback.WaitForResult());
8440
8441 const HttpResponseInfo* response = trans->GetResponseInfo();
8442 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:508443 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]564b4912010-03-09 16:30:428444 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
[email protected]65041fa2010-05-21 06:56:538445 EXPECT_FALSE(response->was_fetched_via_spdy);
8446 EXPECT_FALSE(response->was_npn_negotiated);
[email protected]564b4912010-03-09 16:30:428447
8448 std::string response_data;
8449 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
8450 EXPECT_EQ("hello world", response_data);
8451
[email protected]17291a022011-10-10 07:32:538452 ASSERT_TRUE(http_server_properties.HasAlternateProtocol(http_host_port_pair));
[email protected]287d9412014-07-08 23:01:008453 const AlternateProtocolInfo alternate =
[email protected]17291a022011-10-10 07:32:538454 http_server_properties.GetAlternateProtocol(http_host_port_pair);
[email protected]287d9412014-07-08 23:01:008455 AlternateProtocolInfo expected_alternate(
8456 443, AlternateProtocolFromNextProto(GetParam()), 1);
[email protected]564b4912010-03-09 16:30:428457 EXPECT_TRUE(expected_alternate.Equals(alternate));
8458}
8459
[email protected]23e482282013-06-14 16:08:028460TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:238461 MarkBrokenAlternateProtocolAndFallback) {
[email protected]d7599122014-05-24 03:37:238462 session_deps_.use_alternate_protocols = true;
[email protected]564b4912010-03-09 16:30:428463
8464 HttpRequestInfo request;
8465 request.method = "GET";
8466 request.url = GURL("http://www.google.com/");
8467 request.load_flags = 0;
8468
[email protected]d973e99a2012-02-17 21:02:368469 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED);
[email protected]564b4912010-03-09 16:30:428470 StaticSocketDataProvider first_data;
8471 first_data.set_connect_data(mock_connect);
[email protected]bb88e1d32013-05-03 23:11:078472 session_deps_.socket_factory->AddSocketDataProvider(&first_data);
[email protected]564b4912010-03-09 16:30:428473
8474 MockRead data_reads[] = {
8475 MockRead("HTTP/1.1 200 OK\r\n\r\n"),
8476 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:068477 MockRead(ASYNC, OK),
[email protected]564b4912010-03-09 16:30:428478 };
8479 StaticSocketDataProvider second_data(
8480 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078481 session_deps_.socket_factory->AddSocketDataProvider(&second_data);
[email protected]564b4912010-03-09 16:30:428482
[email protected]bb88e1d32013-05-03 23:11:078483 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]564b4912010-03-09 16:30:428484
[email protected]30d4c022013-07-18 22:58:168485 base::WeakPtr<HttpServerProperties> http_server_properties =
[email protected]17291a022011-10-10 07:32:538486 session->http_server_properties();
[email protected]3912662a32011-10-04 00:51:118487 // Port must be < 1024, or the header will be ignored (since initial port was
8488 // port 80 (another restricted port).
[email protected]17291a022011-10-10 07:32:538489 http_server_properties->SetAlternateProtocol(
[email protected]3912662a32011-10-04 00:51:118490 HostPortPair::FromURL(request.url),
8491 666 /* port is ignored by MockConnect anyway */,
[email protected]287d9412014-07-08 23:01:008492 AlternateProtocolFromNextProto(GetParam()), 1);
[email protected]564b4912010-03-09 16:30:428493
[email protected]262eec82013-03-19 21:01:368494 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:508495 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:418496 TestCompletionCallback callback;
[email protected]564b4912010-03-09 16:30:428497
[email protected]49639fa2011-12-20 23:22:418498 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]564b4912010-03-09 16:30:428499 EXPECT_EQ(ERR_IO_PENDING, rv);
8500 EXPECT_EQ(OK, callback.WaitForResult());
8501
8502 const HttpResponseInfo* response = trans->GetResponseInfo();
8503 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:508504 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]564b4912010-03-09 16:30:428505 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
8506
8507 std::string response_data;
8508 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
8509 EXPECT_EQ("hello world", response_data);
8510
[email protected]17291a022011-10-10 07:32:538511 ASSERT_TRUE(http_server_properties->HasAlternateProtocol(
[email protected]3912662a32011-10-04 00:51:118512 HostPortPair::FromURL(request.url)));
[email protected]287d9412014-07-08 23:01:008513 const AlternateProtocolInfo alternate =
[email protected]17291a022011-10-10 07:32:538514 http_server_properties->GetAlternateProtocol(
[email protected]3912662a32011-10-04 00:51:118515 HostPortPair::FromURL(request.url));
bnccbd55d5f2014-11-06 19:50:408516 EXPECT_TRUE(alternate.is_broken);
[email protected]564b4912010-03-09 16:30:428517}
8518
[email protected]23e482282013-06-14 16:08:028519TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:238520 AlternateProtocolPortRestrictedBlocked) {
[email protected]3912662a32011-10-04 00:51:118521 // Ensure that we're not allowed to redirect traffic via an alternate
8522 // protocol to an unrestricted (port >= 1024) when the original traffic was
8523 // on a restricted port (port < 1024). Ensure that we can redirect in all
8524 // other cases.
[email protected]d7599122014-05-24 03:37:238525 session_deps_.use_alternate_protocols = true;
[email protected]3912662a32011-10-04 00:51:118526
8527 HttpRequestInfo restricted_port_request;
8528 restricted_port_request.method = "GET";
8529 restricted_port_request.url = GURL("http://www.google.com:1023/");
8530 restricted_port_request.load_flags = 0;
8531
[email protected]d973e99a2012-02-17 21:02:368532 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED);
[email protected]3912662a32011-10-04 00:51:118533 StaticSocketDataProvider first_data;
8534 first_data.set_connect_data(mock_connect);
[email protected]bb88e1d32013-05-03 23:11:078535 session_deps_.socket_factory->AddSocketDataProvider(&first_data);
[email protected]3912662a32011-10-04 00:51:118536
8537 MockRead data_reads[] = {
8538 MockRead("HTTP/1.1 200 OK\r\n\r\n"),
8539 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:068540 MockRead(ASYNC, OK),
[email protected]3912662a32011-10-04 00:51:118541 };
8542 StaticSocketDataProvider second_data(
8543 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078544 session_deps_.socket_factory->AddSocketDataProvider(&second_data);
[email protected]3912662a32011-10-04 00:51:118545
[email protected]bb88e1d32013-05-03 23:11:078546 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]3912662a32011-10-04 00:51:118547
[email protected]30d4c022013-07-18 22:58:168548 base::WeakPtr<HttpServerProperties> http_server_properties =
[email protected]17291a022011-10-10 07:32:538549 session->http_server_properties();
[email protected]3912662a32011-10-04 00:51:118550 const int kUnrestrictedAlternatePort = 1024;
[email protected]17291a022011-10-10 07:32:538551 http_server_properties->SetAlternateProtocol(
[email protected]3912662a32011-10-04 00:51:118552 HostPortPair::FromURL(restricted_port_request.url),
8553 kUnrestrictedAlternatePort,
[email protected]287d9412014-07-08 23:01:008554 AlternateProtocolFromNextProto(GetParam()), 1);
[email protected]3912662a32011-10-04 00:51:118555
[email protected]262eec82013-03-19 21:01:368556 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:508557 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:418558 TestCompletionCallback callback;
[email protected]3912662a32011-10-04 00:51:118559
[email protected]49639fa2011-12-20 23:22:418560 int rv = trans->Start(
[email protected]262eec82013-03-19 21:01:368561 &restricted_port_request,
8562 callback.callback(), BoundNetLog());
[email protected]3912662a32011-10-04 00:51:118563 EXPECT_EQ(ERR_IO_PENDING, rv);
8564 // Invalid change to unrestricted port should fail.
8565 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult());
[email protected]c54c6962013-02-01 04:53:198566}
[email protected]3912662a32011-10-04 00:51:118567
[email protected]23e482282013-06-14 16:08:028568TEST_P(HttpNetworkTransactionTest,
[email protected]c54c6962013-02-01 04:53:198569 AlternateProtocolPortRestrictedPermitted) {
8570 // Ensure that we're allowed to redirect traffic via an alternate
8571 // protocol to an unrestricted (port >= 1024) when the original traffic was
8572 // on a restricted port (port < 1024) if we set
8573 // enable_user_alternate_protocol_ports.
8574
[email protected]d7599122014-05-24 03:37:238575 session_deps_.use_alternate_protocols = true;
[email protected]bb88e1d32013-05-03 23:11:078576 session_deps_.enable_user_alternate_protocol_ports = true;
[email protected]c54c6962013-02-01 04:53:198577
8578 HttpRequestInfo restricted_port_request;
8579 restricted_port_request.method = "GET";
8580 restricted_port_request.url = GURL("http://www.google.com:1023/");
8581 restricted_port_request.load_flags = 0;
8582
8583 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED);
8584 StaticSocketDataProvider first_data;
8585 first_data.set_connect_data(mock_connect);
[email protected]bb88e1d32013-05-03 23:11:078586 session_deps_.socket_factory->AddSocketDataProvider(&first_data);
[email protected]c54c6962013-02-01 04:53:198587
8588 MockRead data_reads[] = {
8589 MockRead("HTTP/1.1 200 OK\r\n\r\n"),
8590 MockRead("hello world"),
8591 MockRead(ASYNC, OK),
8592 };
8593 StaticSocketDataProvider second_data(
8594 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078595 session_deps_.socket_factory->AddSocketDataProvider(&second_data);
[email protected]c54c6962013-02-01 04:53:198596
[email protected]bb88e1d32013-05-03 23:11:078597 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]c54c6962013-02-01 04:53:198598
[email protected]30d4c022013-07-18 22:58:168599 base::WeakPtr<HttpServerProperties> http_server_properties =
[email protected]c54c6962013-02-01 04:53:198600 session->http_server_properties();
8601 const int kUnrestrictedAlternatePort = 1024;
8602 http_server_properties->SetAlternateProtocol(
8603 HostPortPair::FromURL(restricted_port_request.url),
8604 kUnrestrictedAlternatePort,
[email protected]287d9412014-07-08 23:01:008605 AlternateProtocolFromNextProto(GetParam()), 1);
[email protected]c54c6962013-02-01 04:53:198606
[email protected]262eec82013-03-19 21:01:368607 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:508608 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]c54c6962013-02-01 04:53:198609 TestCompletionCallback callback;
8610
8611 EXPECT_EQ(ERR_IO_PENDING, trans->Start(
[email protected]262eec82013-03-19 21:01:368612 &restricted_port_request,
8613 callback.callback(), BoundNetLog()));
[email protected]c54c6962013-02-01 04:53:198614 // Change to unrestricted port should succeed.
8615 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]3912662a32011-10-04 00:51:118616}
8617
[email protected]23e482282013-06-14 16:08:028618TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:238619 AlternateProtocolPortRestrictedAllowed) {
[email protected]3912662a32011-10-04 00:51:118620 // Ensure that we're not allowed to redirect traffic via an alternate
8621 // protocol to an unrestricted (port >= 1024) when the original traffic was
8622 // on a restricted port (port < 1024). Ensure that we can redirect in all
8623 // other cases.
[email protected]d7599122014-05-24 03:37:238624 session_deps_.use_alternate_protocols = true;
[email protected]3912662a32011-10-04 00:51:118625
8626 HttpRequestInfo restricted_port_request;
8627 restricted_port_request.method = "GET";
8628 restricted_port_request.url = GURL("http://www.google.com:1023/");
8629 restricted_port_request.load_flags = 0;
8630
[email protected]d973e99a2012-02-17 21:02:368631 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED);
[email protected]3912662a32011-10-04 00:51:118632 StaticSocketDataProvider first_data;
8633 first_data.set_connect_data(mock_connect);
[email protected]bb88e1d32013-05-03 23:11:078634 session_deps_.socket_factory->AddSocketDataProvider(&first_data);
[email protected]3912662a32011-10-04 00:51:118635
8636 MockRead data_reads[] = {
8637 MockRead("HTTP/1.1 200 OK\r\n\r\n"),
8638 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:068639 MockRead(ASYNC, OK),
[email protected]3912662a32011-10-04 00:51:118640 };
8641 StaticSocketDataProvider second_data(
8642 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078643 session_deps_.socket_factory->AddSocketDataProvider(&second_data);
[email protected]3912662a32011-10-04 00:51:118644
[email protected]bb88e1d32013-05-03 23:11:078645 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]3912662a32011-10-04 00:51:118646
[email protected]30d4c022013-07-18 22:58:168647 base::WeakPtr<HttpServerProperties> http_server_properties =
[email protected]17291a022011-10-10 07:32:538648 session->http_server_properties();
[email protected]3912662a32011-10-04 00:51:118649 const int kRestrictedAlternatePort = 80;
[email protected]17291a022011-10-10 07:32:538650 http_server_properties->SetAlternateProtocol(
[email protected]3912662a32011-10-04 00:51:118651 HostPortPair::FromURL(restricted_port_request.url),
8652 kRestrictedAlternatePort,
[email protected]287d9412014-07-08 23:01:008653 AlternateProtocolFromNextProto(GetParam()), 1);
[email protected]3912662a32011-10-04 00:51:118654
[email protected]262eec82013-03-19 21:01:368655 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:508656 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:418657 TestCompletionCallback callback;
[email protected]3912662a32011-10-04 00:51:118658
[email protected]49639fa2011-12-20 23:22:418659 int rv = trans->Start(
[email protected]262eec82013-03-19 21:01:368660 &restricted_port_request,
8661 callback.callback(), BoundNetLog());
[email protected]3912662a32011-10-04 00:51:118662 EXPECT_EQ(ERR_IO_PENDING, rv);
8663 // Valid change to restricted port should pass.
8664 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]3912662a32011-10-04 00:51:118665}
8666
[email protected]23e482282013-06-14 16:08:028667TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:238668 AlternateProtocolPortUnrestrictedAllowed1) {
[email protected]3912662a32011-10-04 00:51:118669 // Ensure that we're not allowed to redirect traffic via an alternate
8670 // protocol to an unrestricted (port >= 1024) when the original traffic was
8671 // on a restricted port (port < 1024). Ensure that we can redirect in all
8672 // other cases.
[email protected]d7599122014-05-24 03:37:238673 session_deps_.use_alternate_protocols = true;
[email protected]3912662a32011-10-04 00:51:118674
8675 HttpRequestInfo unrestricted_port_request;
8676 unrestricted_port_request.method = "GET";
8677 unrestricted_port_request.url = GURL("http://www.google.com:1024/");
8678 unrestricted_port_request.load_flags = 0;
8679
[email protected]d973e99a2012-02-17 21:02:368680 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED);
[email protected]3912662a32011-10-04 00:51:118681 StaticSocketDataProvider first_data;
8682 first_data.set_connect_data(mock_connect);
[email protected]bb88e1d32013-05-03 23:11:078683 session_deps_.socket_factory->AddSocketDataProvider(&first_data);
[email protected]3912662a32011-10-04 00:51:118684
8685 MockRead data_reads[] = {
8686 MockRead("HTTP/1.1 200 OK\r\n\r\n"),
8687 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:068688 MockRead(ASYNC, OK),
[email protected]3912662a32011-10-04 00:51:118689 };
8690 StaticSocketDataProvider second_data(
8691 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078692 session_deps_.socket_factory->AddSocketDataProvider(&second_data);
[email protected]3912662a32011-10-04 00:51:118693
[email protected]bb88e1d32013-05-03 23:11:078694 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]3912662a32011-10-04 00:51:118695
[email protected]30d4c022013-07-18 22:58:168696 base::WeakPtr<HttpServerProperties> http_server_properties =
[email protected]17291a022011-10-10 07:32:538697 session->http_server_properties();
[email protected]3912662a32011-10-04 00:51:118698 const int kRestrictedAlternatePort = 80;
[email protected]17291a022011-10-10 07:32:538699 http_server_properties->SetAlternateProtocol(
[email protected]3912662a32011-10-04 00:51:118700 HostPortPair::FromURL(unrestricted_port_request.url),
8701 kRestrictedAlternatePort,
[email protected]287d9412014-07-08 23:01:008702 AlternateProtocolFromNextProto(GetParam()), 1);
[email protected]3912662a32011-10-04 00:51:118703
[email protected]262eec82013-03-19 21:01:368704 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:508705 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:418706 TestCompletionCallback callback;
[email protected]3912662a32011-10-04 00:51:118707
[email protected]49639fa2011-12-20 23:22:418708 int rv = trans->Start(
8709 &unrestricted_port_request, callback.callback(), BoundNetLog());
[email protected]3912662a32011-10-04 00:51:118710 EXPECT_EQ(ERR_IO_PENDING, rv);
8711 // Valid change to restricted port should pass.
8712 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]3912662a32011-10-04 00:51:118713}
8714
[email protected]23e482282013-06-14 16:08:028715TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:238716 AlternateProtocolPortUnrestrictedAllowed2) {
[email protected]3912662a32011-10-04 00:51:118717 // Ensure that we're not allowed to redirect traffic via an alternate
8718 // protocol to an unrestricted (port >= 1024) when the original traffic was
8719 // on a restricted port (port < 1024). Ensure that we can redirect in all
8720 // other cases.
[email protected]d7599122014-05-24 03:37:238721 session_deps_.use_alternate_protocols = true;
[email protected]3912662a32011-10-04 00:51:118722
8723 HttpRequestInfo unrestricted_port_request;
8724 unrestricted_port_request.method = "GET";
8725 unrestricted_port_request.url = GURL("http://www.google.com:1024/");
8726 unrestricted_port_request.load_flags = 0;
8727
[email protected]d973e99a2012-02-17 21:02:368728 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED);
[email protected]3912662a32011-10-04 00:51:118729 StaticSocketDataProvider first_data;
8730 first_data.set_connect_data(mock_connect);
[email protected]bb88e1d32013-05-03 23:11:078731 session_deps_.socket_factory->AddSocketDataProvider(&first_data);
[email protected]3912662a32011-10-04 00:51:118732
8733 MockRead data_reads[] = {
8734 MockRead("HTTP/1.1 200 OK\r\n\r\n"),
8735 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:068736 MockRead(ASYNC, OK),
[email protected]3912662a32011-10-04 00:51:118737 };
8738 StaticSocketDataProvider second_data(
8739 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078740 session_deps_.socket_factory->AddSocketDataProvider(&second_data);
[email protected]3912662a32011-10-04 00:51:118741
[email protected]bb88e1d32013-05-03 23:11:078742 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]3912662a32011-10-04 00:51:118743
[email protected]30d4c022013-07-18 22:58:168744 base::WeakPtr<HttpServerProperties> http_server_properties =
[email protected]17291a022011-10-10 07:32:538745 session->http_server_properties();
[email protected]3912662a32011-10-04 00:51:118746 const int kUnrestrictedAlternatePort = 1024;
[email protected]17291a022011-10-10 07:32:538747 http_server_properties->SetAlternateProtocol(
[email protected]3912662a32011-10-04 00:51:118748 HostPortPair::FromURL(unrestricted_port_request.url),
8749 kUnrestrictedAlternatePort,
[email protected]287d9412014-07-08 23:01:008750 AlternateProtocolFromNextProto(GetParam()), 1);
[email protected]3912662a32011-10-04 00:51:118751
[email protected]262eec82013-03-19 21:01:368752 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:508753 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:418754 TestCompletionCallback callback;
[email protected]3912662a32011-10-04 00:51:118755
[email protected]49639fa2011-12-20 23:22:418756 int rv = trans->Start(
8757 &unrestricted_port_request, callback.callback(), BoundNetLog());
[email protected]3912662a32011-10-04 00:51:118758 EXPECT_EQ(ERR_IO_PENDING, rv);
8759 // Valid change to an unrestricted port should pass.
8760 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]3912662a32011-10-04 00:51:118761}
8762
[email protected]d7599122014-05-24 03:37:238763TEST_P(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) {
[email protected]eb6234e2012-01-19 01:50:028764 // Ensure that we're not allowed to redirect traffic via an alternate
8765 // protocol to an unsafe port, and that we resume the second
8766 // HttpStreamFactoryImpl::Job once the alternate protocol request fails.
[email protected]d7599122014-05-24 03:37:238767 session_deps_.use_alternate_protocols = true;
[email protected]eb6234e2012-01-19 01:50:028768
8769 HttpRequestInfo request;
8770 request.method = "GET";
8771 request.url = GURL("http://www.google.com/");
8772 request.load_flags = 0;
8773
8774 // The alternate protocol request will error out before we attempt to connect,
8775 // so only the standard HTTP request will try to connect.
8776 MockRead data_reads[] = {
8777 MockRead("HTTP/1.1 200 OK\r\n\r\n"),
8778 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:068779 MockRead(ASYNC, OK),
[email protected]eb6234e2012-01-19 01:50:028780 };
8781 StaticSocketDataProvider data(
8782 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078783 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]eb6234e2012-01-19 01:50:028784
[email protected]bb88e1d32013-05-03 23:11:078785 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]eb6234e2012-01-19 01:50:028786
[email protected]30d4c022013-07-18 22:58:168787 base::WeakPtr<HttpServerProperties> http_server_properties =
[email protected]eb6234e2012-01-19 01:50:028788 session->http_server_properties();
8789 const int kUnsafePort = 7;
8790 http_server_properties->SetAlternateProtocol(
8791 HostPortPair::FromURL(request.url),
8792 kUnsafePort,
[email protected]287d9412014-07-08 23:01:008793 AlternateProtocolFromNextProto(GetParam()), 1);
[email protected]eb6234e2012-01-19 01:50:028794
[email protected]262eec82013-03-19 21:01:368795 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:508796 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]eb6234e2012-01-19 01:50:028797 TestCompletionCallback callback;
8798
8799 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
8800 EXPECT_EQ(ERR_IO_PENDING, rv);
8801 // The HTTP request should succeed.
8802 EXPECT_EQ(OK, callback.WaitForResult());
8803
8804 // Disable alternate protocol before the asserts.
[email protected]d7599122014-05-24 03:37:238805 // HttpStreamFactory::set_use_alternate_protocols(false);
[email protected]eb6234e2012-01-19 01:50:028806
8807 const HttpResponseInfo* response = trans->GetResponseInfo();
8808 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:508809 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]eb6234e2012-01-19 01:50:028810 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
8811
8812 std::string response_data;
8813 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
8814 EXPECT_EQ("hello world", response_data);
8815}
8816
[email protected]23e482282013-06-14 16:08:028817TEST_P(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) {
[email protected]d7599122014-05-24 03:37:238818 session_deps_.use_alternate_protocols = true;
8819 session_deps_.next_protos = SpdyNextProtos();
[email protected]2ff8b312010-04-26 22:20:548820
8821 HttpRequestInfo request;
8822 request.method = "GET";
8823 request.url = GURL("http://www.google.com/");
8824 request.load_flags = 0;
8825
[email protected]8a0fc822013-06-27 20:52:438826 std::string alternate_protocol_http_header =
8827 GetAlternateProtocolHttpHeader();
8828
[email protected]2ff8b312010-04-26 22:20:548829 MockRead data_reads[] = {
8830 MockRead("HTTP/1.1 200 OK\r\n"),
[email protected]8a0fc822013-06-27 20:52:438831 MockRead(alternate_protocol_http_header.c_str()),
[email protected]2ff8b312010-04-26 22:20:548832 MockRead("hello world"),
[email protected]7a5378b2012-11-04 03:25:178833 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
8834 MockRead(ASYNC, OK)
[email protected]2ff8b312010-04-26 22:20:548835 };
8836
8837 StaticSocketDataProvider first_transaction(
8838 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078839 session_deps_.socket_factory->AddSocketDataProvider(&first_transaction);
[email protected]2ff8b312010-04-26 22:20:548840
[email protected]8ddf8322012-02-23 18:08:068841 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:028842 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:078843 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]2ff8b312010-04-26 22:20:548844
[email protected]cdf8f7e72013-05-23 10:56:468845 scoped_ptr<SpdyFrame> req(
8846 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
[email protected]e7f75092010-07-01 22:39:138847 MockWrite spdy_writes[] = { CreateMockWrite(*req) };
[email protected]2ff8b312010-04-26 22:20:548848
[email protected]23e482282013-06-14 16:08:028849 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
8850 scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]2ff8b312010-04-26 22:20:548851 MockRead spdy_reads[] = {
[email protected]e7f75092010-07-01 22:39:138852 CreateMockRead(*resp),
8853 CreateMockRead(*data),
[email protected]8ddf8322012-02-23 18:08:068854 MockRead(ASYNC, 0, 0),
[email protected]2ff8b312010-04-26 22:20:548855 };
8856
[email protected]dd54bd82012-07-19 23:44:578857 DelayedSocketData spdy_data(
8858 1, // wait for one write to finish before reading.
8859 spdy_reads, arraysize(spdy_reads),
8860 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:078861 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]2ff8b312010-04-26 22:20:548862
[email protected]d973e99a2012-02-17 21:02:368863 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING);
[email protected]2d6728692011-03-12 01:39:558864 StaticSocketDataProvider hanging_non_alternate_protocol_socket(
8865 NULL, 0, NULL, 0);
8866 hanging_non_alternate_protocol_socket.set_connect_data(
8867 never_finishing_connect);
[email protected]bb88e1d32013-05-03 23:11:078868 session_deps_.socket_factory->AddSocketDataProvider(
[email protected]2d6728692011-03-12 01:39:558869 &hanging_non_alternate_protocol_socket);
8870
[email protected]49639fa2011-12-20 23:22:418871 TestCompletionCallback callback;
[email protected]2ff8b312010-04-26 22:20:548872
[email protected]bb88e1d32013-05-03 23:11:078873 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:368874 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:508875 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]2ff8b312010-04-26 22:20:548876
[email protected]49639fa2011-12-20 23:22:418877 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]2ff8b312010-04-26 22:20:548878 EXPECT_EQ(ERR_IO_PENDING, rv);
8879 EXPECT_EQ(OK, callback.WaitForResult());
8880
8881 const HttpResponseInfo* response = trans->GetResponseInfo();
8882 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:508883 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]2ff8b312010-04-26 22:20:548884 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
8885
8886 std::string response_data;
8887 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
8888 EXPECT_EQ("hello world", response_data);
8889
[email protected]90499482013-06-01 00:39:508890 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]2ff8b312010-04-26 22:20:548891
[email protected]49639fa2011-12-20 23:22:418892 rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]2ff8b312010-04-26 22:20:548893 EXPECT_EQ(ERR_IO_PENDING, rv);
8894 EXPECT_EQ(OK, callback.WaitForResult());
8895
8896 response = trans->GetResponseInfo();
8897 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:508898 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]2ff8b312010-04-26 22:20:548899 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
[email protected]65041fa2010-05-21 06:56:538900 EXPECT_TRUE(response->was_fetched_via_spdy);
8901 EXPECT_TRUE(response->was_npn_negotiated);
[email protected]2ff8b312010-04-26 22:20:548902
8903 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
8904 EXPECT_EQ("hello!", response_data);
[email protected]2ff8b312010-04-26 22:20:548905}
8906
[email protected]23e482282013-06-14 16:08:028907TEST_P(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) {
[email protected]d7599122014-05-24 03:37:238908 session_deps_.use_alternate_protocols = true;
8909 session_deps_.next_protos = SpdyNextProtos();
[email protected]2d6728692011-03-12 01:39:558910
8911 HttpRequestInfo request;
8912 request.method = "GET";
8913 request.url = GURL("http://www.google.com/");
8914 request.load_flags = 0;
8915
[email protected]8a0fc822013-06-27 20:52:438916 std::string alternate_protocol_http_header =
8917 GetAlternateProtocolHttpHeader();
8918
[email protected]2d6728692011-03-12 01:39:558919 MockRead data_reads[] = {
8920 MockRead("HTTP/1.1 200 OK\r\n"),
[email protected]8a0fc822013-06-27 20:52:438921 MockRead(alternate_protocol_http_header.c_str()),
[email protected]2d6728692011-03-12 01:39:558922 MockRead("hello world"),
[email protected]7a5378b2012-11-04 03:25:178923 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
[email protected]8ddf8322012-02-23 18:08:068924 MockRead(ASYNC, OK),
[email protected]2d6728692011-03-12 01:39:558925 };
8926
8927 StaticSocketDataProvider first_transaction(
8928 data_reads, arraysize(data_reads), NULL, 0);
8929 // Socket 1 is the HTTP transaction with the Alternate-Protocol header.
[email protected]bb88e1d32013-05-03 23:11:078930 session_deps_.socket_factory->AddSocketDataProvider(&first_transaction);
[email protected]2d6728692011-03-12 01:39:558931
[email protected]d973e99a2012-02-17 21:02:368932 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING);
[email protected]2d6728692011-03-12 01:39:558933 StaticSocketDataProvider hanging_socket(
8934 NULL, 0, NULL, 0);
8935 hanging_socket.set_connect_data(never_finishing_connect);
8936 // Socket 2 and 3 are the hanging Alternate-Protocol and
8937 // non-Alternate-Protocol jobs from the 2nd transaction.
[email protected]bb88e1d32013-05-03 23:11:078938 session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket);
8939 session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket);
[email protected]2d6728692011-03-12 01:39:558940
[email protected]8ddf8322012-02-23 18:08:068941 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:028942 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:078943 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]2d6728692011-03-12 01:39:558944
[email protected]cdf8f7e72013-05-23 10:56:468945 scoped_ptr<SpdyFrame> req1(
8946 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
8947 scoped_ptr<SpdyFrame> req2(
8948 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true));
[email protected]2d6728692011-03-12 01:39:558949 MockWrite spdy_writes[] = {
8950 CreateMockWrite(*req1),
8951 CreateMockWrite(*req2),
8952 };
[email protected]23e482282013-06-14 16:08:028953 scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
8954 scoped_ptr<SpdyFrame> data1(spdy_util_.ConstructSpdyBodyFrame(1, true));
8955 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
8956 scoped_ptr<SpdyFrame> data2(spdy_util_.ConstructSpdyBodyFrame(3, true));
[email protected]2d6728692011-03-12 01:39:558957 MockRead spdy_reads[] = {
8958 CreateMockRead(*resp1),
8959 CreateMockRead(*data1),
8960 CreateMockRead(*resp2),
8961 CreateMockRead(*data2),
[email protected]8ddf8322012-02-23 18:08:068962 MockRead(ASYNC, 0, 0),
[email protected]2d6728692011-03-12 01:39:558963 };
8964
[email protected]dd54bd82012-07-19 23:44:578965 DelayedSocketData spdy_data(
8966 2, // wait for writes to finish before reading.
8967 spdy_reads, arraysize(spdy_reads),
8968 spdy_writes, arraysize(spdy_writes));
[email protected]2d6728692011-03-12 01:39:558969 // Socket 4 is the successful Alternate-Protocol for transaction 3.
[email protected]bb88e1d32013-05-03 23:11:078970 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]2d6728692011-03-12 01:39:558971
8972 // Socket 5 is the unsuccessful non-Alternate-Protocol for transaction 3.
[email protected]bb88e1d32013-05-03 23:11:078973 session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket);
[email protected]2d6728692011-03-12 01:39:558974
[email protected]bb88e1d32013-05-03 23:11:078975 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]49639fa2011-12-20 23:22:418976 TestCompletionCallback callback1;
[email protected]90499482013-06-01 00:39:508977 HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get());
[email protected]2d6728692011-03-12 01:39:558978
[email protected]49639fa2011-12-20 23:22:418979 int rv = trans1.Start(&request, callback1.callback(), BoundNetLog());
[email protected]2d6728692011-03-12 01:39:558980 EXPECT_EQ(ERR_IO_PENDING, rv);
8981 EXPECT_EQ(OK, callback1.WaitForResult());
8982
8983 const HttpResponseInfo* response = trans1.GetResponseInfo();
8984 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:508985 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]2d6728692011-03-12 01:39:558986 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
8987
8988 std::string response_data;
8989 ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data));
8990 EXPECT_EQ("hello world", response_data);
8991
[email protected]49639fa2011-12-20 23:22:418992 TestCompletionCallback callback2;
[email protected]90499482013-06-01 00:39:508993 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get());
[email protected]49639fa2011-12-20 23:22:418994 rv = trans2.Start(&request, callback2.callback(), BoundNetLog());
[email protected]2d6728692011-03-12 01:39:558995 EXPECT_EQ(ERR_IO_PENDING, rv);
8996
[email protected]49639fa2011-12-20 23:22:418997 TestCompletionCallback callback3;
[email protected]90499482013-06-01 00:39:508998 HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get());
[email protected]49639fa2011-12-20 23:22:418999 rv = trans3.Start(&request, callback3.callback(), BoundNetLog());
[email protected]2d6728692011-03-12 01:39:559000 EXPECT_EQ(ERR_IO_PENDING, rv);
9001
9002 EXPECT_EQ(OK, callback2.WaitForResult());
9003 EXPECT_EQ(OK, callback3.WaitForResult());
9004
9005 response = trans2.GetResponseInfo();
9006 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:509007 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]2d6728692011-03-12 01:39:559008 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
9009 EXPECT_TRUE(response->was_fetched_via_spdy);
9010 EXPECT_TRUE(response->was_npn_negotiated);
9011 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data));
9012 EXPECT_EQ("hello!", response_data);
9013
9014 response = trans3.GetResponseInfo();
9015 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:509016 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]2d6728692011-03-12 01:39:559017 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
9018 EXPECT_TRUE(response->was_fetched_via_spdy);
9019 EXPECT_TRUE(response->was_npn_negotiated);
9020 ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data));
9021 EXPECT_EQ("hello!", response_data);
[email protected]2d6728692011-03-12 01:39:559022}
9023
[email protected]23e482282013-06-14 16:08:029024TEST_P(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) {
[email protected]d7599122014-05-24 03:37:239025 session_deps_.use_alternate_protocols = true;
9026 session_deps_.next_protos = SpdyNextProtos();
[email protected]2d6728692011-03-12 01:39:559027
9028 HttpRequestInfo request;
9029 request.method = "GET";
9030 request.url = GURL("http://www.google.com/");
9031 request.load_flags = 0;
9032
[email protected]8a0fc822013-06-27 20:52:439033 std::string alternate_protocol_http_header =
9034 GetAlternateProtocolHttpHeader();
9035
[email protected]2d6728692011-03-12 01:39:559036 MockRead data_reads[] = {
9037 MockRead("HTTP/1.1 200 OK\r\n"),
[email protected]8a0fc822013-06-27 20:52:439038 MockRead(alternate_protocol_http_header.c_str()),
[email protected]2d6728692011-03-12 01:39:559039 MockRead("hello world"),
[email protected]7a5378b2012-11-04 03:25:179040 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
[email protected]8ddf8322012-02-23 18:08:069041 MockRead(ASYNC, OK),
[email protected]2d6728692011-03-12 01:39:559042 };
9043
9044 StaticSocketDataProvider first_transaction(
9045 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:079046 session_deps_.socket_factory->AddSocketDataProvider(&first_transaction);
[email protected]2d6728692011-03-12 01:39:559047
[email protected]8ddf8322012-02-23 18:08:069048 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:029049 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:079050 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]2d6728692011-03-12 01:39:559051
[email protected]d973e99a2012-02-17 21:02:369052 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING);
[email protected]2d6728692011-03-12 01:39:559053 StaticSocketDataProvider hanging_alternate_protocol_socket(
9054 NULL, 0, NULL, 0);
9055 hanging_alternate_protocol_socket.set_connect_data(
9056 never_finishing_connect);
[email protected]bb88e1d32013-05-03 23:11:079057 session_deps_.socket_factory->AddSocketDataProvider(
[email protected]2d6728692011-03-12 01:39:559058 &hanging_alternate_protocol_socket);
9059
9060 // 2nd request is just a copy of the first one, over HTTP again.
[email protected]bb88e1d32013-05-03 23:11:079061 session_deps_.socket_factory->AddSocketDataProvider(&first_transaction);
[email protected]2d6728692011-03-12 01:39:559062
[email protected]49639fa2011-12-20 23:22:419063 TestCompletionCallback callback;
[email protected]2d6728692011-03-12 01:39:559064
[email protected]bb88e1d32013-05-03 23:11:079065 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:369066 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:509067 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]2d6728692011-03-12 01:39:559068
[email protected]49639fa2011-12-20 23:22:419069 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]2d6728692011-03-12 01:39:559070 EXPECT_EQ(ERR_IO_PENDING, rv);
9071 EXPECT_EQ(OK, callback.WaitForResult());
9072
9073 const HttpResponseInfo* response = trans->GetResponseInfo();
9074 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:509075 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]2d6728692011-03-12 01:39:559076 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
9077
9078 std::string response_data;
9079 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
9080 EXPECT_EQ("hello world", response_data);
9081
[email protected]90499482013-06-01 00:39:509082 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]2d6728692011-03-12 01:39:559083
[email protected]49639fa2011-12-20 23:22:419084 rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]2d6728692011-03-12 01:39:559085 EXPECT_EQ(ERR_IO_PENDING, rv);
9086 EXPECT_EQ(OK, callback.WaitForResult());
9087
9088 response = trans->GetResponseInfo();
9089 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:509090 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]2d6728692011-03-12 01:39:559091 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
9092 EXPECT_FALSE(response->was_fetched_via_spdy);
9093 EXPECT_FALSE(response->was_npn_negotiated);
9094
9095 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
9096 EXPECT_EQ("hello world", response_data);
[email protected]2d6728692011-03-12 01:39:559097}
9098
[email protected]631f1322010-04-30 17:59:119099class CapturingProxyResolver : public ProxyResolver {
9100 public:
9101 CapturingProxyResolver() : ProxyResolver(false /* expects_pac_bytes */) {}
dchengb03027d2014-10-21 12:00:209102 ~CapturingProxyResolver() override {}
[email protected]631f1322010-04-30 17:59:119103
dchengb03027d2014-10-21 12:00:209104 int GetProxyForURL(const GURL& url,
9105 ProxyInfo* results,
9106 const CompletionCallback& callback,
9107 RequestHandle* request,
9108 const BoundNetLog& net_log) override {
[email protected]fae7669f2010-08-02 21:49:409109 ProxyServer proxy_server(ProxyServer::SCHEME_HTTP,
9110 HostPortPair("myproxy", 80));
[email protected]d911f1b2010-05-05 22:39:429111 results->UseProxyServer(proxy_server);
[email protected]631f1322010-04-30 17:59:119112 resolved_.push_back(url);
[email protected]d911f1b2010-05-05 22:39:429113 return OK;
[email protected]631f1322010-04-30 17:59:119114 }
9115
dchengb03027d2014-10-21 12:00:209116 void CancelRequest(RequestHandle request) override { NOTREACHED(); }
[email protected]631f1322010-04-30 17:59:119117
dchengb03027d2014-10-21 12:00:209118 LoadState GetLoadState(RequestHandle request) const override {
[email protected]f2c971f2011-11-08 00:33:179119 NOTREACHED();
9120 return LOAD_STATE_IDLE;
9121 }
9122
dchengb03027d2014-10-21 12:00:209123 void CancelSetPacScript() override { NOTREACHED(); }
[email protected]1e605472010-12-16 21:41:409124
dchengb03027d2014-10-21 12:00:209125 int SetPacScript(const scoped_refptr<ProxyResolverScriptData>&,
9126 const CompletionCallback& /*callback*/) override {
[email protected]d911f1b2010-05-05 22:39:429127 return OK;
[email protected]631f1322010-04-30 17:59:119128 }
9129
[email protected]24476402010-07-20 20:55:179130 const std::vector<GURL>& resolved() const { return resolved_; }
9131
9132 private:
[email protected]631f1322010-04-30 17:59:119133 std::vector<GURL> resolved_;
9134
9135 DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver);
9136};
9137
[email protected]23e482282013-06-14 16:08:029138TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:239139 UseAlternateProtocolForTunneledNpnSpdy) {
[email protected]d7599122014-05-24 03:37:239140 session_deps_.use_alternate_protocols = true;
9141 session_deps_.next_protos = SpdyNextProtos();
[email protected]631f1322010-04-30 17:59:119142
9143 ProxyConfig proxy_config;
[email protected]d911f1b2010-05-05 22:39:429144 proxy_config.set_auto_detect(true);
9145 proxy_config.set_pac_url(GURL("http://fooproxyurl"));
[email protected]2227c692010-05-04 15:36:119146
[email protected]631f1322010-04-30 17:59:119147 CapturingProxyResolver* capturing_proxy_resolver =
9148 new CapturingProxyResolver();
[email protected]bb88e1d32013-05-03 23:11:079149 session_deps_.proxy_service.reset(new ProxyService(
[email protected]66761b952010-06-25 21:30:389150 new ProxyConfigServiceFixed(proxy_config), capturing_proxy_resolver,
9151 NULL));
[email protected]029c83b62013-01-24 05:28:209152 CapturingNetLog net_log;
[email protected]bb88e1d32013-05-03 23:11:079153 session_deps_.net_log = &net_log;
[email protected]631f1322010-04-30 17:59:119154
9155 HttpRequestInfo request;
9156 request.method = "GET";
9157 request.url = GURL("http://www.google.com/");
9158 request.load_flags = 0;
9159
[email protected]8a0fc822013-06-27 20:52:439160 std::string alternate_protocol_http_header =
9161 GetAlternateProtocolHttpHeader();
9162
[email protected]631f1322010-04-30 17:59:119163 MockRead data_reads[] = {
9164 MockRead("HTTP/1.1 200 OK\r\n"),
[email protected]8a0fc822013-06-27 20:52:439165 MockRead(alternate_protocol_http_header.c_str()),
[email protected]631f1322010-04-30 17:59:119166 MockRead("hello world"),
[email protected]7a5378b2012-11-04 03:25:179167 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
[email protected]8ddf8322012-02-23 18:08:069168 MockRead(ASYNC, OK),
[email protected]631f1322010-04-30 17:59:119169 };
9170
9171 StaticSocketDataProvider first_transaction(
9172 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:079173 session_deps_.socket_factory->AddSocketDataProvider(&first_transaction);
[email protected]631f1322010-04-30 17:59:119174
[email protected]8ddf8322012-02-23 18:08:069175 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:029176 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:079177 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]631f1322010-04-30 17:59:119178
[email protected]cdf8f7e72013-05-23 10:56:469179 scoped_ptr<SpdyFrame> req(
9180 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
[email protected]631f1322010-04-30 17:59:119181 MockWrite spdy_writes[] = {
9182 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
9183 "Host: www.google.com\r\n"
[email protected]d911f1b2010-05-05 22:39:429184 "Proxy-Connection: keep-alive\r\n\r\n"), // 0
[email protected]cdf8f7e72013-05-23 10:56:469185 CreateMockWrite(*req), // 3
[email protected]631f1322010-04-30 17:59:119186 };
9187
[email protected]d911f1b2010-05-05 22:39:429188 const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n";
9189
[email protected]23e482282013-06-14 16:08:029190 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
9191 scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]631f1322010-04-30 17:59:119192 MockRead spdy_reads[] = {
[email protected]8ddf8322012-02-23 18:08:069193 MockRead(ASYNC, kCONNECTResponse, arraysize(kCONNECTResponse) - 1, 1), // 1
[email protected]e7f75092010-07-01 22:39:139194 CreateMockRead(*resp.get(), 4), // 2, 4
9195 CreateMockRead(*data.get(), 4), // 5
[email protected]8ddf8322012-02-23 18:08:069196 MockRead(ASYNC, 0, 0, 4), // 6
[email protected]631f1322010-04-30 17:59:119197 };
9198
[email protected]dd54bd82012-07-19 23:44:579199 OrderedSocketData spdy_data(
9200 spdy_reads, arraysize(spdy_reads),
9201 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:079202 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]631f1322010-04-30 17:59:119203
[email protected]d973e99a2012-02-17 21:02:369204 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING);
[email protected]2d6728692011-03-12 01:39:559205 StaticSocketDataProvider hanging_non_alternate_protocol_socket(
9206 NULL, 0, NULL, 0);
9207 hanging_non_alternate_protocol_socket.set_connect_data(
9208 never_finishing_connect);
[email protected]bb88e1d32013-05-03 23:11:079209 session_deps_.socket_factory->AddSocketDataProvider(
[email protected]2d6728692011-03-12 01:39:559210 &hanging_non_alternate_protocol_socket);
9211
[email protected]49639fa2011-12-20 23:22:419212 TestCompletionCallback callback;
[email protected]631f1322010-04-30 17:59:119213
[email protected]bb88e1d32013-05-03 23:11:079214 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:369215 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:509216 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]631f1322010-04-30 17:59:119217
[email protected]49639fa2011-12-20 23:22:419218 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]631f1322010-04-30 17:59:119219 EXPECT_EQ(ERR_IO_PENDING, rv);
9220 EXPECT_EQ(OK, callback.WaitForResult());
9221
9222 const HttpResponseInfo* response = trans->GetResponseInfo();
9223 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:509224 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]631f1322010-04-30 17:59:119225 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
[email protected]65041fa2010-05-21 06:56:539226 EXPECT_FALSE(response->was_fetched_via_spdy);
9227 EXPECT_FALSE(response->was_npn_negotiated);
[email protected]631f1322010-04-30 17:59:119228
9229 std::string response_data;
9230 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
9231 EXPECT_EQ("hello world", response_data);
9232
[email protected]90499482013-06-01 00:39:509233 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]631f1322010-04-30 17:59:119234
[email protected]49639fa2011-12-20 23:22:419235 rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]631f1322010-04-30 17:59:119236 EXPECT_EQ(ERR_IO_PENDING, rv);
9237 EXPECT_EQ(OK, callback.WaitForResult());
9238
9239 response = trans->GetResponseInfo();
9240 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:509241 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]631f1322010-04-30 17:59:119242 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
[email protected]65041fa2010-05-21 06:56:539243 EXPECT_TRUE(response->was_fetched_via_spdy);
9244 EXPECT_TRUE(response->was_npn_negotiated);
[email protected]631f1322010-04-30 17:59:119245
9246 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
9247 EXPECT_EQ("hello!", response_data);
[email protected]2d6728692011-03-12 01:39:559248 ASSERT_EQ(3u, capturing_proxy_resolver->resolved().size());
[email protected]d911f1b2010-05-05 22:39:429249 EXPECT_EQ("http://www.google.com/",
[email protected]631f1322010-04-30 17:59:119250 capturing_proxy_resolver->resolved()[0].spec());
[email protected]d911f1b2010-05-05 22:39:429251 EXPECT_EQ("https://www.google.com/",
9252 capturing_proxy_resolver->resolved()[1].spec());
[email protected]631f1322010-04-30 17:59:119253
[email protected]029c83b62013-01-24 05:28:209254 LoadTimingInfo load_timing_info;
9255 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
9256 TestLoadTimingNotReusedWithPac(load_timing_info,
9257 CONNECT_TIMING_HAS_SSL_TIMES);
[email protected]631f1322010-04-30 17:59:119258}
[email protected]631f1322010-04-30 17:59:119259
[email protected]23e482282013-06-14 16:08:029260TEST_P(HttpNetworkTransactionTest,
[email protected]2ff8b312010-04-26 22:20:549261 UseAlternateProtocolForNpnSpdyWithExistingSpdySession) {
[email protected]d7599122014-05-24 03:37:239262 session_deps_.use_alternate_protocols = true;
9263 session_deps_.next_protos = SpdyNextProtos();
[email protected]2ff8b312010-04-26 22:20:549264
9265 HttpRequestInfo request;
9266 request.method = "GET";
9267 request.url = GURL("http://www.google.com/");
9268 request.load_flags = 0;
9269
[email protected]8a0fc822013-06-27 20:52:439270 std::string alternate_protocol_http_header =
9271 GetAlternateProtocolHttpHeader();
9272
[email protected]2ff8b312010-04-26 22:20:549273 MockRead data_reads[] = {
9274 MockRead("HTTP/1.1 200 OK\r\n"),
[email protected]8a0fc822013-06-27 20:52:439275 MockRead(alternate_protocol_http_header.c_str()),
[email protected]2ff8b312010-04-26 22:20:549276 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:069277 MockRead(ASYNC, OK),
[email protected]2ff8b312010-04-26 22:20:549278 };
9279
9280 StaticSocketDataProvider first_transaction(
9281 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:079282 session_deps_.socket_factory->AddSocketDataProvider(&first_transaction);
[email protected]2ff8b312010-04-26 22:20:549283
[email protected]8ddf8322012-02-23 18:08:069284 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:029285 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:079286 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]2ff8b312010-04-26 22:20:549287
[email protected]cdf8f7e72013-05-23 10:56:469288 scoped_ptr<SpdyFrame> req(
9289 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
[email protected]e7f75092010-07-01 22:39:139290 MockWrite spdy_writes[] = { CreateMockWrite(*req) };
[email protected]2ff8b312010-04-26 22:20:549291
[email protected]23e482282013-06-14 16:08:029292 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
9293 scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]2ff8b312010-04-26 22:20:549294 MockRead spdy_reads[] = {
[email protected]e7f75092010-07-01 22:39:139295 CreateMockRead(*resp),
9296 CreateMockRead(*data),
[email protected]8ddf8322012-02-23 18:08:069297 MockRead(ASYNC, 0, 0),
[email protected]2ff8b312010-04-26 22:20:549298 };
9299
[email protected]dd54bd82012-07-19 23:44:579300 DelayedSocketData spdy_data(
9301 1, // wait for one write to finish before reading.
9302 spdy_reads, arraysize(spdy_reads),
9303 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:079304 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]2ff8b312010-04-26 22:20:549305
[email protected]83039bb2011-12-09 18:43:559306 TestCompletionCallback callback;
[email protected]2ff8b312010-04-26 22:20:549307
[email protected]bb88e1d32013-05-03 23:11:079308 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]2ff8b312010-04-26 22:20:549309
[email protected]262eec82013-03-19 21:01:369310 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:509311 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]2ff8b312010-04-26 22:20:549312
[email protected]49639fa2011-12-20 23:22:419313 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]2ff8b312010-04-26 22:20:549314 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]49639fa2011-12-20 23:22:419315 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]2ff8b312010-04-26 22:20:549316
9317 const HttpResponseInfo* response = trans->GetResponseInfo();
9318 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:509319 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]2ff8b312010-04-26 22:20:549320 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
9321
9322 std::string response_data;
9323 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
9324 EXPECT_EQ("hello world", response_data);
9325
9326 // Set up an initial SpdySession in the pool to reuse.
[email protected]02b0c342010-09-25 21:09:389327 HostPortPair host_port_pair("www.google.com", 443);
[email protected]e6d017652013-05-17 18:01:409328 SpdySessionKey key(host_port_pair, ProxyServer::Direct(),
[email protected]314b03992014-04-01 01:28:539329 PRIVACY_MODE_DISABLED);
[email protected]795cbf82013-07-22 09:37:279330 base::WeakPtr<SpdySession> spdy_session =
[email protected]41d64e82013-07-03 22:44:269331 CreateSecureSpdySession(session, key, BoundNetLog());
[email protected]02b0c342010-09-25 21:09:389332
[email protected]90499482013-06-01 00:39:509333 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]2ff8b312010-04-26 22:20:549334
[email protected]49639fa2011-12-20 23:22:419335 rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]2ff8b312010-04-26 22:20:549336 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]49639fa2011-12-20 23:22:419337 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]2ff8b312010-04-26 22:20:549338
9339 response = trans->GetResponseInfo();
9340 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:509341 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]2ff8b312010-04-26 22:20:549342 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
[email protected]65041fa2010-05-21 06:56:539343 EXPECT_TRUE(response->was_fetched_via_spdy);
9344 EXPECT_TRUE(response->was_npn_negotiated);
[email protected]2ff8b312010-04-26 22:20:549345
9346 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
9347 EXPECT_EQ("hello!", response_data);
[email protected]564b4912010-03-09 16:30:429348}
9349
[email protected]044de0642010-06-17 10:42:159350// GenerateAuthToken is a mighty big test.
9351// It tests all permutation of GenerateAuthToken behavior:
9352// - Synchronous and Asynchronous completion.
9353// - OK or error on completion.
9354// - Direct connection, non-authenticating proxy, and authenticating proxy.
9355// - HTTP or HTTPS backend (to include proxy tunneling).
9356// - Non-authenticating and authenticating backend.
9357//
[email protected]fe3b7dc2012-02-03 19:52:099358// In all, there are 44 reasonable permuations (for example, if there are
[email protected]044de0642010-06-17 10:42:159359// problems generating an auth token for an authenticating proxy, we don't
9360// need to test all permutations of the backend server).
9361//
9362// The test proceeds by going over each of the configuration cases, and
9363// potentially running up to three rounds in each of the tests. The TestConfig
9364// specifies both the configuration for the test as well as the expectations
9365// for the results.
[email protected]23e482282013-06-14 16:08:029366TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) {
[email protected]0b0bf032010-09-21 18:08:509367 static const char kServer[] = "http://www.example.com";
9368 static const char kSecureServer[] = "https://www.example.com";
9369 static const char kProxy[] = "myproxy:70";
[email protected]044de0642010-06-17 10:42:159370 const int kAuthErr = ERR_INVALID_AUTH_CREDENTIALS;
9371
9372 enum AuthTiming {
9373 AUTH_NONE,
9374 AUTH_SYNC,
9375 AUTH_ASYNC,
9376 };
9377
9378 const MockWrite kGet(
9379 "GET / HTTP/1.1\r\n"
9380 "Host: www.example.com\r\n"
9381 "Connection: keep-alive\r\n\r\n");
9382 const MockWrite kGetProxy(
9383 "GET http://www.example.com/ HTTP/1.1\r\n"
9384 "Host: www.example.com\r\n"
9385 "Proxy-Connection: keep-alive\r\n\r\n");
9386 const MockWrite kGetAuth(
9387 "GET / HTTP/1.1\r\n"
9388 "Host: www.example.com\r\n"
9389 "Connection: keep-alive\r\n"
9390 "Authorization: auth_token\r\n\r\n");
9391 const MockWrite kGetProxyAuth(
9392 "GET http://www.example.com/ HTTP/1.1\r\n"
9393 "Host: www.example.com\r\n"
9394 "Proxy-Connection: keep-alive\r\n"
9395 "Proxy-Authorization: auth_token\r\n\r\n");
9396 const MockWrite kGetAuthThroughProxy(
9397 "GET http://www.example.com/ HTTP/1.1\r\n"
9398 "Host: www.example.com\r\n"
9399 "Proxy-Connection: keep-alive\r\n"
9400 "Authorization: auth_token\r\n\r\n");
9401 const MockWrite kGetAuthWithProxyAuth(
9402 "GET http://www.example.com/ HTTP/1.1\r\n"
9403 "Host: www.example.com\r\n"
9404 "Proxy-Connection: keep-alive\r\n"
9405 "Proxy-Authorization: auth_token\r\n"
9406 "Authorization: auth_token\r\n\r\n");
9407 const MockWrite kConnect(
9408 "CONNECT www.example.com:443 HTTP/1.1\r\n"
9409 "Host: www.example.com\r\n"
9410 "Proxy-Connection: keep-alive\r\n\r\n");
9411 const MockWrite kConnectProxyAuth(
9412 "CONNECT www.example.com:443 HTTP/1.1\r\n"
9413 "Host: www.example.com\r\n"
9414 "Proxy-Connection: keep-alive\r\n"
9415 "Proxy-Authorization: auth_token\r\n\r\n");
9416
9417 const MockRead kSuccess(
9418 "HTTP/1.1 200 OK\r\n"
9419 "Content-Type: text/html; charset=iso-8859-1\r\n"
9420 "Content-Length: 3\r\n\r\n"
9421 "Yes");
9422 const MockRead kFailure(
9423 "Should not be called.");
9424 const MockRead kServerChallenge(
9425 "HTTP/1.1 401 Unauthorized\r\n"
9426 "WWW-Authenticate: Mock realm=server\r\n"
9427 "Content-Type: text/html; charset=iso-8859-1\r\n"
9428 "Content-Length: 14\r\n\r\n"
9429 "Unauthorized\r\n");
9430 const MockRead kProxyChallenge(
9431 "HTTP/1.1 407 Unauthorized\r\n"
9432 "Proxy-Authenticate: Mock realm=proxy\r\n"
9433 "Proxy-Connection: close\r\n"
9434 "Content-Type: text/html; charset=iso-8859-1\r\n"
9435 "Content-Length: 14\r\n\r\n"
9436 "Unauthorized\r\n");
9437 const MockRead kProxyConnected(
9438 "HTTP/1.1 200 Connection Established\r\n\r\n");
9439
9440 // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with
9441 // no constructors, but the C++ compiler on Windows warns about
9442 // unspecified data in compound literals. So, moved to using constructors,
9443 // and TestRound's created with the default constructor should not be used.
9444 struct TestRound {
9445 TestRound()
9446 : expected_rv(ERR_UNEXPECTED),
9447 extra_write(NULL),
9448 extra_read(NULL) {
9449 }
9450 TestRound(const MockWrite& write_arg, const MockRead& read_arg,
9451 int expected_rv_arg)
9452 : write(write_arg),
9453 read(read_arg),
9454 expected_rv(expected_rv_arg),
9455 extra_write(NULL),
9456 extra_read(NULL) {
9457 }
9458 TestRound(const MockWrite& write_arg, const MockRead& read_arg,
9459 int expected_rv_arg, const MockWrite* extra_write_arg,
[email protected]f871ee152012-07-27 19:02:019460 const MockRead* extra_read_arg)
[email protected]044de0642010-06-17 10:42:159461 : write(write_arg),
9462 read(read_arg),
9463 expected_rv(expected_rv_arg),
9464 extra_write(extra_write_arg),
9465 extra_read(extra_read_arg) {
9466 }
9467 MockWrite write;
9468 MockRead read;
9469 int expected_rv;
9470 const MockWrite* extra_write;
9471 const MockRead* extra_read;
9472 };
9473
9474 static const int kNoSSL = 500;
9475
9476 struct TestConfig {
9477 const char* proxy_url;
9478 AuthTiming proxy_auth_timing;
9479 int proxy_auth_rv;
9480 const char* server_url;
9481 AuthTiming server_auth_timing;
9482 int server_auth_rv;
9483 int num_auth_rounds;
9484 int first_ssl_round;
9485 TestRound rounds[3];
9486 } test_configs[] = {
9487 // Non-authenticating HTTP server with a direct connection.
9488 { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL,
9489 { TestRound(kGet, kSuccess, OK)}},
9490 // Authenticating HTTP server with a direct connection.
9491 { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL,
9492 { TestRound(kGet, kServerChallenge, OK),
9493 TestRound(kGetAuth, kSuccess, OK)}},
9494 { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL,
9495 { TestRound(kGet, kServerChallenge, OK),
9496 TestRound(kGetAuth, kFailure, kAuthErr)}},
9497 { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL,
9498 { TestRound(kGet, kServerChallenge, OK),
9499 TestRound(kGetAuth, kSuccess, OK)}},
9500 { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL,
9501 { TestRound(kGet, kServerChallenge, OK),
9502 TestRound(kGetAuth, kFailure, kAuthErr)}},
9503 // Non-authenticating HTTP server through a non-authenticating proxy.
9504 { kProxy, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL,
9505 { TestRound(kGetProxy, kSuccess, OK)}},
9506 // Authenticating HTTP server through a non-authenticating proxy.
9507 { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL,
9508 { TestRound(kGetProxy, kServerChallenge, OK),
9509 TestRound(kGetAuthThroughProxy, kSuccess, OK)}},
9510 { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL,
9511 { TestRound(kGetProxy, kServerChallenge, OK),
9512 TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}},
9513 { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL,
9514 { TestRound(kGetProxy, kServerChallenge, OK),
9515 TestRound(kGetAuthThroughProxy, kSuccess, OK)}},
9516 { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL,
9517 { TestRound(kGetProxy, kServerChallenge, OK),
9518 TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}},
9519 // Non-authenticating HTTP server through an authenticating proxy.
9520 { kProxy, AUTH_SYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL,
9521 { TestRound(kGetProxy, kProxyChallenge, OK),
9522 TestRound(kGetProxyAuth, kSuccess, OK)}},
9523 { kProxy, AUTH_SYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL,
9524 { TestRound(kGetProxy, kProxyChallenge, OK),
9525 TestRound(kGetProxyAuth, kFailure, kAuthErr)}},
9526 { kProxy, AUTH_ASYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL,
9527 { TestRound(kGetProxy, kProxyChallenge, OK),
9528 TestRound(kGetProxyAuth, kSuccess, OK)}},
9529 { kProxy, AUTH_ASYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL,
9530 { TestRound(kGetProxy, kProxyChallenge, OK),
9531 TestRound(kGetProxyAuth, kFailure, kAuthErr)}},
9532 // Authenticating HTTP server through an authenticating proxy.
9533 { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL,
9534 { TestRound(kGetProxy, kProxyChallenge, OK),
9535 TestRound(kGetProxyAuth, kServerChallenge, OK),
9536 TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}},
9537 { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL,
9538 { TestRound(kGetProxy, kProxyChallenge, OK),
9539 TestRound(kGetProxyAuth, kServerChallenge, OK),
9540 TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}},
9541 { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL,
9542 { TestRound(kGetProxy, kProxyChallenge, OK),
9543 TestRound(kGetProxyAuth, kServerChallenge, OK),
9544 TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}},
9545 { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL,
9546 { TestRound(kGetProxy, kProxyChallenge, OK),
9547 TestRound(kGetProxyAuth, kServerChallenge, OK),
9548 TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}},
9549 { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL,
9550 { TestRound(kGetProxy, kProxyChallenge, OK),
9551 TestRound(kGetProxyAuth, kServerChallenge, OK),
9552 TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}},
9553 { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL,
9554 { TestRound(kGetProxy, kProxyChallenge, OK),
9555 TestRound(kGetProxyAuth, kServerChallenge, OK),
9556 TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}},
9557 { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL,
9558 { TestRound(kGetProxy, kProxyChallenge, OK),
9559 TestRound(kGetProxyAuth, kServerChallenge, OK),
9560 TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}},
9561 { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL,
9562 { TestRound(kGetProxy, kProxyChallenge, OK),
9563 TestRound(kGetProxyAuth, kServerChallenge, OK),
9564 TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}},
9565 // Non-authenticating HTTPS server with a direct connection.
9566 { NULL, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0,
9567 { TestRound(kGet, kSuccess, OK)}},
9568 // Authenticating HTTPS server with a direct connection.
9569 { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0,
9570 { TestRound(kGet, kServerChallenge, OK),
9571 TestRound(kGetAuth, kSuccess, OK)}},
9572 { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0,
9573 { TestRound(kGet, kServerChallenge, OK),
9574 TestRound(kGetAuth, kFailure, kAuthErr)}},
9575 { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0,
9576 { TestRound(kGet, kServerChallenge, OK),
9577 TestRound(kGetAuth, kSuccess, OK)}},
9578 { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0,
9579 { TestRound(kGet, kServerChallenge, OK),
9580 TestRound(kGetAuth, kFailure, kAuthErr)}},
9581 // Non-authenticating HTTPS server with a non-authenticating proxy.
9582 { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0,
9583 { TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}},
9584 // Authenticating HTTPS server through a non-authenticating proxy.
9585 { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0,
9586 { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge),
9587 TestRound(kGetAuth, kSuccess, OK)}},
9588 { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0,
9589 { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge),
9590 TestRound(kGetAuth, kFailure, kAuthErr)}},
9591 { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0,
9592 { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge),
9593 TestRound(kGetAuth, kSuccess, OK)}},
9594 { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0,
9595 { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge),
9596 TestRound(kGetAuth, kFailure, kAuthErr)}},
9597 // Non-Authenticating HTTPS server through an authenticating proxy.
9598 { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1,
9599 { TestRound(kConnect, kProxyChallenge, OK),
9600 TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}},
9601 { kProxy, AUTH_SYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL,
9602 { TestRound(kConnect, kProxyChallenge, OK),
9603 TestRound(kConnectProxyAuth, kFailure, kAuthErr)}},
9604 { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1,
9605 { TestRound(kConnect, kProxyChallenge, OK),
9606 TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}},
9607 { kProxy, AUTH_ASYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL,
9608 { TestRound(kConnect, kProxyChallenge, OK),
9609 TestRound(kConnectProxyAuth, kFailure, kAuthErr)}},
9610 // Authenticating HTTPS server through an authenticating proxy.
9611 { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1,
9612 { TestRound(kConnect, kProxyChallenge, OK),
9613 TestRound(kConnectProxyAuth, kProxyConnected, OK,
9614 &kGet, &kServerChallenge),
9615 TestRound(kGetAuth, kSuccess, OK)}},
9616 { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1,
9617 { TestRound(kConnect, kProxyChallenge, OK),
9618 TestRound(kConnectProxyAuth, kProxyConnected, OK,
9619 &kGet, &kServerChallenge),
9620 TestRound(kGetAuth, kFailure, kAuthErr)}},
9621 { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1,
9622 { TestRound(kConnect, kProxyChallenge, OK),
9623 TestRound(kConnectProxyAuth, kProxyConnected, OK,
9624 &kGet, &kServerChallenge),
9625 TestRound(kGetAuth, kSuccess, OK)}},
9626 { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1,
9627 { TestRound(kConnect, kProxyChallenge, OK),
9628 TestRound(kConnectProxyAuth, kProxyConnected, OK,
9629 &kGet, &kServerChallenge),
9630 TestRound(kGetAuth, kFailure, kAuthErr)}},
9631 { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1,
9632 { TestRound(kConnect, kProxyChallenge, OK),
9633 TestRound(kConnectProxyAuth, kProxyConnected, OK,
9634 &kGet, &kServerChallenge),
9635 TestRound(kGetAuth, kSuccess, OK)}},
9636 { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1,
9637 { TestRound(kConnect, kProxyChallenge, OK),
9638 TestRound(kConnectProxyAuth, kProxyConnected, OK,
9639 &kGet, &kServerChallenge),
9640 TestRound(kGetAuth, kFailure, kAuthErr)}},
9641 { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1,
9642 { TestRound(kConnect, kProxyChallenge, OK),
9643 TestRound(kConnectProxyAuth, kProxyConnected, OK,
9644 &kGet, &kServerChallenge),
9645 TestRound(kGetAuth, kSuccess, OK)}},
9646 { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1,
9647 { TestRound(kConnect, kProxyChallenge, OK),
9648 TestRound(kConnectProxyAuth, kProxyConnected, OK,
9649 &kGet, &kServerChallenge),
9650 TestRound(kGetAuth, kFailure, kAuthErr)}},
9651 };
9652
viettrungluue4a8b882014-10-16 06:17:389653 for (size_t i = 0; i < arraysize(test_configs); ++i) {
[email protected]2d01c262011-08-11 23:07:089654 HttpAuthHandlerMock::Factory* auth_factory(
9655 new HttpAuthHandlerMock::Factory());
[email protected]bb88e1d32013-05-03 23:11:079656 session_deps_.http_auth_handler_factory.reset(auth_factory);
[email protected]044de0642010-06-17 10:42:159657 const TestConfig& test_config = test_configs[i];
[email protected]65d34382010-07-01 18:12:269658
9659 // Set up authentication handlers as necessary.
[email protected]044de0642010-06-17 10:42:159660 if (test_config.proxy_auth_timing != AUTH_NONE) {
[email protected]2d01c262011-08-11 23:07:089661 for (int n = 0; n < 2; n++) {
9662 HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock());
9663 std::string auth_challenge = "Mock realm=proxy";
9664 GURL origin(test_config.proxy_url);
[email protected]df41d0d82014-03-13 00:43:249665 HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(),
9666 auth_challenge.end());
[email protected]2d01c262011-08-11 23:07:089667 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY,
9668 origin, BoundNetLog());
9669 auth_handler->SetGenerateExpectation(
9670 test_config.proxy_auth_timing == AUTH_ASYNC,
9671 test_config.proxy_auth_rv);
9672 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY);
9673 }
[email protected]044de0642010-06-17 10:42:159674 }
9675 if (test_config.server_auth_timing != AUTH_NONE) {
[email protected]3fd9dae2010-06-21 11:39:009676 HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock());
[email protected]044de0642010-06-17 10:42:159677 std::string auth_challenge = "Mock realm=server";
9678 GURL origin(test_config.server_url);
[email protected]df41d0d82014-03-13 00:43:249679 HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(),
9680 auth_challenge.end());
[email protected]044de0642010-06-17 10:42:159681 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER,
9682 origin, BoundNetLog());
9683 auth_handler->SetGenerateExpectation(
9684 test_config.server_auth_timing == AUTH_ASYNC,
9685 test_config.server_auth_rv);
[email protected]2d01c262011-08-11 23:07:089686 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER);
[email protected]044de0642010-06-17 10:42:159687 }
9688 if (test_config.proxy_url) {
[email protected]bb88e1d32013-05-03 23:11:079689 session_deps_.proxy_service.reset(
[email protected]6104ea5d2011-04-27 21:37:129690 ProxyService::CreateFixed(test_config.proxy_url));
[email protected]044de0642010-06-17 10:42:159691 } else {
[email protected]bb88e1d32013-05-03 23:11:079692 session_deps_.proxy_service.reset(ProxyService::CreateDirect());
[email protected]044de0642010-06-17 10:42:159693 }
9694
9695 HttpRequestInfo request;
9696 request.method = "GET";
9697 request.url = GURL(test_config.server_url);
9698 request.load_flags = 0;
9699
[email protected]bb88e1d32013-05-03 23:11:079700 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
dcheng48459ac22014-08-26 00:46:419701 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
[email protected]044de0642010-06-17 10:42:159702
9703 for (int round = 0; round < test_config.num_auth_rounds; ++round) {
9704 const TestRound& read_write_round = test_config.rounds[round];
9705
9706 // Set up expected reads and writes.
9707 MockRead reads[2];
9708 reads[0] = read_write_round.read;
9709 size_t length_reads = 1;
9710 if (read_write_round.extra_read) {
9711 reads[1] = *read_write_round.extra_read;
9712 length_reads = 2;
9713 }
9714
9715 MockWrite writes[2];
9716 writes[0] = read_write_round.write;
9717 size_t length_writes = 1;
9718 if (read_write_round.extra_write) {
9719 writes[1] = *read_write_round.extra_write;
9720 length_writes = 2;
9721 }
9722 StaticSocketDataProvider data_provider(
9723 reads, length_reads, writes, length_writes);
[email protected]bb88e1d32013-05-03 23:11:079724 session_deps_.socket_factory->AddSocketDataProvider(&data_provider);
[email protected]044de0642010-06-17 10:42:159725
9726 // Add an SSL sequence if necessary.
[email protected]8ddf8322012-02-23 18:08:069727 SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK);
[email protected]044de0642010-06-17 10:42:159728 if (round >= test_config.first_ssl_round)
[email protected]bb88e1d32013-05-03 23:11:079729 session_deps_.socket_factory->AddSSLSocketDataProvider(
[email protected]044de0642010-06-17 10:42:159730 &ssl_socket_data_provider);
9731
9732 // Start or restart the transaction.
[email protected]49639fa2011-12-20 23:22:419733 TestCompletionCallback callback;
[email protected]044de0642010-06-17 10:42:159734 int rv;
9735 if (round == 0) {
[email protected]49639fa2011-12-20 23:22:419736 rv = trans.Start(&request, callback.callback(), BoundNetLog());
[email protected]044de0642010-06-17 10:42:159737 } else {
[email protected]49639fa2011-12-20 23:22:419738 rv = trans.RestartWithAuth(
9739 AuthCredentials(kFoo, kBar), callback.callback());
[email protected]044de0642010-06-17 10:42:159740 }
9741 if (rv == ERR_IO_PENDING)
9742 rv = callback.WaitForResult();
9743
9744 // Compare results with expected data.
9745 EXPECT_EQ(read_write_round.expected_rv, rv);
[email protected]0b0bf032010-09-21 18:08:509746 const HttpResponseInfo* response = trans.GetResponseInfo();
[email protected]044de0642010-06-17 10:42:159747 if (read_write_round.expected_rv == OK) {
[email protected]fe2255a2011-09-20 19:37:509748 ASSERT_TRUE(response != NULL);
[email protected]044de0642010-06-17 10:42:159749 } else {
9750 EXPECT_TRUE(response == NULL);
9751 EXPECT_EQ(round + 1, test_config.num_auth_rounds);
9752 continue;
9753 }
9754 if (round + 1 < test_config.num_auth_rounds) {
9755 EXPECT_FALSE(response->auth_challenge.get() == NULL);
9756 } else {
9757 EXPECT_TRUE(response->auth_challenge.get() == NULL);
9758 }
9759 }
[email protected]e5ae96a2010-04-14 20:12:459760 }
9761}
9762
[email protected]23e482282013-06-14 16:08:029763TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) {
[email protected]c871bce92010-07-15 21:51:149764 // Do multi-round authentication and make sure it works correctly.
[email protected]c871bce92010-07-15 21:51:149765 HttpAuthHandlerMock::Factory* auth_factory(
9766 new HttpAuthHandlerMock::Factory());
[email protected]bb88e1d32013-05-03 23:11:079767 session_deps_.http_auth_handler_factory.reset(auth_factory);
9768 session_deps_.proxy_service.reset(ProxyService::CreateDirect());
9769 session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1");
9770 session_deps_.host_resolver->set_synchronous_mode(true);
[email protected]c871bce92010-07-15 21:51:149771
9772 HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock());
9773 auth_handler->set_connection_based(true);
9774 std::string auth_challenge = "Mock realm=server";
9775 GURL origin("http://www.example.com");
[email protected]df41d0d82014-03-13 00:43:249776 HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(),
9777 auth_challenge.end());
[email protected]c871bce92010-07-15 21:51:149778 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER,
9779 origin, BoundNetLog());
[email protected]2d01c262011-08-11 23:07:089780 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER);
[email protected]c871bce92010-07-15 21:51:149781
[email protected]c871bce92010-07-15 21:51:149782 int rv = OK;
9783 const HttpResponseInfo* response = NULL;
9784 HttpRequestInfo request;
9785 request.method = "GET";
9786 request.url = origin;
9787 request.load_flags = 0;
[email protected]cb9bf6ca2011-01-28 13:15:279788
[email protected]bb88e1d32013-05-03 23:11:079789 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]7ef4cbbb2011-02-06 11:19:109790
9791 // Use a TCP Socket Pool with only one connection per group. This is used
9792 // to validate that the TCP socket is not released to the pool between
9793 // each round of multi-round authentication.
9794 HttpNetworkSessionPeer session_peer(session);
[email protected]ab739042011-04-07 15:22:289795 ClientSocketPoolHistograms transport_pool_histograms("SmallTCP");
9796 TransportClientSocketPool* transport_pool = new TransportClientSocketPool(
[email protected]7ef4cbbb2011-02-06 11:19:109797 50, // Max sockets for pool
9798 1, // Max sockets per group
[email protected]ab739042011-04-07 15:22:289799 &transport_pool_histograms,
[email protected]bb88e1d32013-05-03 23:11:079800 session_deps_.host_resolver.get(),
9801 session_deps_.socket_factory.get(),
9802 session_deps_.net_log);
[email protected]831e4a32013-11-14 02:14:449803 scoped_ptr<MockClientSocketPoolManager> mock_pool_manager(
9804 new MockClientSocketPoolManager);
[email protected]a42dbd142011-11-17 16:42:029805 mock_pool_manager->SetTransportSocketPool(transport_pool);
dchenge3d1ddc2014-10-15 19:30:519806 session_peer.SetClientSocketPoolManager(mock_pool_manager.Pass());
[email protected]7ef4cbbb2011-02-06 11:19:109807
[email protected]262eec82013-03-19 21:01:369808 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:509809 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:419810 TestCompletionCallback callback;
[email protected]c871bce92010-07-15 21:51:149811
9812 const MockWrite kGet(
9813 "GET / HTTP/1.1\r\n"
9814 "Host: www.example.com\r\n"
9815 "Connection: keep-alive\r\n\r\n");
9816 const MockWrite kGetAuth(
9817 "GET / HTTP/1.1\r\n"
9818 "Host: www.example.com\r\n"
9819 "Connection: keep-alive\r\n"
9820 "Authorization: auth_token\r\n\r\n");
9821
9822 const MockRead kServerChallenge(
9823 "HTTP/1.1 401 Unauthorized\r\n"
9824 "WWW-Authenticate: Mock realm=server\r\n"
9825 "Content-Type: text/html; charset=iso-8859-1\r\n"
9826 "Content-Length: 14\r\n\r\n"
9827 "Unauthorized\r\n");
9828 const MockRead kSuccess(
9829 "HTTP/1.1 200 OK\r\n"
9830 "Content-Type: text/html; charset=iso-8859-1\r\n"
9831 "Content-Length: 3\r\n\r\n"
9832 "Yes");
9833
9834 MockWrite writes[] = {
9835 // First round
9836 kGet,
9837 // Second round
9838 kGetAuth,
9839 // Third round
9840 kGetAuth,
[email protected]eca50e122010-09-11 14:03:309841 // Fourth round
[email protected]7ef4cbbb2011-02-06 11:19:109842 kGetAuth,
9843 // Competing request
9844 kGet,
[email protected]c871bce92010-07-15 21:51:149845 };
9846 MockRead reads[] = {
9847 // First round
9848 kServerChallenge,
9849 // Second round
9850 kServerChallenge,
9851 // Third round
[email protected]eca50e122010-09-11 14:03:309852 kServerChallenge,
9853 // Fourth round
[email protected]c871bce92010-07-15 21:51:149854 kSuccess,
[email protected]7ef4cbbb2011-02-06 11:19:109855 // Competing response
9856 kSuccess,
[email protected]c871bce92010-07-15 21:51:149857 };
9858 StaticSocketDataProvider data_provider(reads, arraysize(reads),
9859 writes, arraysize(writes));
[email protected]bb88e1d32013-05-03 23:11:079860 session_deps_.socket_factory->AddSocketDataProvider(&data_provider);
[email protected]c871bce92010-07-15 21:51:149861
[email protected]7ef4cbbb2011-02-06 11:19:109862 const char* const kSocketGroup = "www.example.com:80";
9863
9864 // First round of authentication.
[email protected]c871bce92010-07-15 21:51:149865 auth_handler->SetGenerateExpectation(false, OK);
[email protected]49639fa2011-12-20 23:22:419866 rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]c871bce92010-07-15 21:51:149867 if (rv == ERR_IO_PENDING)
9868 rv = callback.WaitForResult();
9869 EXPECT_EQ(OK, rv);
9870 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:509871 ASSERT_TRUE(response != NULL);
[email protected]c871bce92010-07-15 21:51:149872 EXPECT_FALSE(response->auth_challenge.get() == NULL);
[email protected]ab739042011-04-07 15:22:289873 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup));
[email protected]c871bce92010-07-15 21:51:149874
[email protected]7ef4cbbb2011-02-06 11:19:109875 // In between rounds, another request comes in for the same domain.
9876 // It should not be able to grab the TCP socket that trans has already
9877 // claimed.
9878 scoped_ptr<HttpTransaction> trans_compete(
[email protected]90499482013-06-01 00:39:509879 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:419880 TestCompletionCallback callback_compete;
9881 rv = trans_compete->Start(
9882 &request, callback_compete.callback(), BoundNetLog());
[email protected]7ef4cbbb2011-02-06 11:19:109883 EXPECT_EQ(ERR_IO_PENDING, rv);
9884 // callback_compete.WaitForResult at this point would stall forever,
9885 // since the HttpNetworkTransaction does not release the request back to
9886 // the pool until after authentication completes.
9887
9888 // Second round of authentication.
[email protected]c871bce92010-07-15 21:51:149889 auth_handler->SetGenerateExpectation(false, OK);
[email protected]49639fa2011-12-20 23:22:419890 rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback());
[email protected]c871bce92010-07-15 21:51:149891 if (rv == ERR_IO_PENDING)
9892 rv = callback.WaitForResult();
9893 EXPECT_EQ(OK, rv);
9894 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:509895 ASSERT_TRUE(response != NULL);
[email protected]c871bce92010-07-15 21:51:149896 EXPECT_TRUE(response->auth_challenge.get() == NULL);
[email protected]ab739042011-04-07 15:22:289897 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup));
[email protected]c871bce92010-07-15 21:51:149898
[email protected]7ef4cbbb2011-02-06 11:19:109899 // Third round of authentication.
[email protected]c871bce92010-07-15 21:51:149900 auth_handler->SetGenerateExpectation(false, OK);
[email protected]49639fa2011-12-20 23:22:419901 rv = trans->RestartWithAuth(AuthCredentials(), callback.callback());
[email protected]c871bce92010-07-15 21:51:149902 if (rv == ERR_IO_PENDING)
9903 rv = callback.WaitForResult();
9904 EXPECT_EQ(OK, rv);
9905 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:509906 ASSERT_TRUE(response != NULL);
[email protected]c871bce92010-07-15 21:51:149907 EXPECT_TRUE(response->auth_challenge.get() == NULL);
[email protected]ab739042011-04-07 15:22:289908 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup));
[email protected]eca50e122010-09-11 14:03:309909
[email protected]7ef4cbbb2011-02-06 11:19:109910 // Fourth round of authentication, which completes successfully.
[email protected]eca50e122010-09-11 14:03:309911 auth_handler->SetGenerateExpectation(false, OK);
[email protected]49639fa2011-12-20 23:22:419912 rv = trans->RestartWithAuth(AuthCredentials(), callback.callback());
[email protected]eca50e122010-09-11 14:03:309913 if (rv == ERR_IO_PENDING)
9914 rv = callback.WaitForResult();
9915 EXPECT_EQ(OK, rv);
9916 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:509917 ASSERT_TRUE(response != NULL);
[email protected]eca50e122010-09-11 14:03:309918 EXPECT_TRUE(response->auth_challenge.get() == NULL);
[email protected]ab739042011-04-07 15:22:289919 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup));
[email protected]7ef4cbbb2011-02-06 11:19:109920
9921 // Read the body since the fourth round was successful. This will also
9922 // release the socket back to the pool.
9923 scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50));
[email protected]90499482013-06-01 00:39:509924 rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback());
[email protected]7ef4cbbb2011-02-06 11:19:109925 if (rv == ERR_IO_PENDING)
9926 rv = callback.WaitForResult();
9927 EXPECT_EQ(3, rv);
[email protected]90499482013-06-01 00:39:509928 rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback());
[email protected]7ef4cbbb2011-02-06 11:19:109929 EXPECT_EQ(0, rv);
9930 // There are still 0 idle sockets, since the trans_compete transaction
9931 // will be handed it immediately after trans releases it to the group.
[email protected]ab739042011-04-07 15:22:289932 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup));
[email protected]7ef4cbbb2011-02-06 11:19:109933
9934 // The competing request can now finish. Wait for the headers and then
9935 // read the body.
9936 rv = callback_compete.WaitForResult();
9937 EXPECT_EQ(OK, rv);
[email protected]90499482013-06-01 00:39:509938 rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback());
[email protected]7ef4cbbb2011-02-06 11:19:109939 if (rv == ERR_IO_PENDING)
9940 rv = callback.WaitForResult();
9941 EXPECT_EQ(3, rv);
[email protected]90499482013-06-01 00:39:509942 rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback());
[email protected]7ef4cbbb2011-02-06 11:19:109943 EXPECT_EQ(0, rv);
9944
9945 // Finally, the socket is released to the group.
[email protected]ab739042011-04-07 15:22:289946 EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup));
[email protected]c871bce92010-07-15 21:51:149947}
9948
[email protected]65041fa2010-05-21 06:56:539949// This tests the case that a request is issued via http instead of spdy after
9950// npn is negotiated.
[email protected]23e482282013-06-14 16:08:029951TEST_P(HttpNetworkTransactionTest, NpnWithHttpOverSSL) {
[email protected]d7599122014-05-24 03:37:239952 session_deps_.use_alternate_protocols = true;
9953 NextProtoVector next_protos;
[email protected]0ce3af82013-07-22 16:17:169954 next_protos.push_back(kProtoHTTP11);
[email protected]d7599122014-05-24 03:37:239955 session_deps_.next_protos = next_protos;
9956
[email protected]65041fa2010-05-21 06:56:539957 HttpRequestInfo request;
9958 request.method = "GET";
9959 request.url = GURL("https://www.google.com/");
9960 request.load_flags = 0;
9961
9962 MockWrite data_writes[] = {
9963 MockWrite("GET / HTTP/1.1\r\n"
9964 "Host: www.google.com\r\n"
9965 "Connection: keep-alive\r\n\r\n"),
9966 };
9967
[email protected]8a0fc822013-06-27 20:52:439968 std::string alternate_protocol_http_header =
9969 GetAlternateProtocolHttpHeader();
9970
[email protected]65041fa2010-05-21 06:56:539971 MockRead data_reads[] = {
9972 MockRead("HTTP/1.1 200 OK\r\n"),
[email protected]8a0fc822013-06-27 20:52:439973 MockRead(alternate_protocol_http_header.c_str()),
[email protected]65041fa2010-05-21 06:56:539974 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:069975 MockRead(SYNCHRONOUS, OK),
[email protected]65041fa2010-05-21 06:56:539976 };
9977
[email protected]8ddf8322012-02-23 18:08:069978 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]65041fa2010-05-21 06:56:539979 ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated;
9980 ssl.next_proto = "http/1.1";
[email protected]8e3c78cb2012-03-31 03:58:469981 ssl.protocol_negotiated = kProtoHTTP11;
[email protected]65041fa2010-05-21 06:56:539982
[email protected]bb88e1d32013-05-03 23:11:079983 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]65041fa2010-05-21 06:56:539984
9985 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
9986 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:079987 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]65041fa2010-05-21 06:56:539988
[email protected]49639fa2011-12-20 23:22:419989 TestCompletionCallback callback;
[email protected]65041fa2010-05-21 06:56:539990
[email protected]bb88e1d32013-05-03 23:11:079991 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:369992 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:509993 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]65041fa2010-05-21 06:56:539994
[email protected]49639fa2011-12-20 23:22:419995 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]65041fa2010-05-21 06:56:539996
9997 EXPECT_EQ(ERR_IO_PENDING, rv);
9998 EXPECT_EQ(OK, callback.WaitForResult());
9999
10000 const HttpResponseInfo* response = trans->GetResponseInfo();
10001 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5010002 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]65041fa2010-05-21 06:56:5310003 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
10004
10005 std::string response_data;
10006 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
10007 EXPECT_EQ("hello world", response_data);
10008
10009 EXPECT_FALSE(response->was_fetched_via_spdy);
10010 EXPECT_TRUE(response->was_npn_negotiated);
[email protected]65041fa2010-05-21 06:56:5310011}
[email protected]26ef6582010-06-24 02:30:4710012
[email protected]23e482282013-06-14 16:08:0210013TEST_P(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) {
[email protected]26ef6582010-06-24 02:30:4710014 // Simulate the SSL handshake completing with an NPN negotiation
10015 // followed by an immediate server closing of the socket.
10016 // Fix crash: http://crbug.com/46369
[email protected]d7599122014-05-24 03:37:2310017 session_deps_.use_alternate_protocols = true;
10018 session_deps_.next_protos = SpdyNextProtos();
[email protected]26ef6582010-06-24 02:30:4710019
10020 HttpRequestInfo request;
10021 request.method = "GET";
10022 request.url = GURL("https://www.google.com/");
10023 request.load_flags = 0;
10024
[email protected]8ddf8322012-02-23 18:08:0610025 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0210026 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0710027 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]26ef6582010-06-24 02:30:4710028
[email protected]cdf8f7e72013-05-23 10:56:4610029 scoped_ptr<SpdyFrame> req(
10030 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
[email protected]e7f75092010-07-01 22:39:1310031 MockWrite spdy_writes[] = { CreateMockWrite(*req) };
[email protected]26ef6582010-06-24 02:30:4710032
10033 MockRead spdy_reads[] = {
[email protected]8ddf8322012-02-23 18:08:0610034 MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately.
[email protected]26ef6582010-06-24 02:30:4710035 };
10036
[email protected]dd54bd82012-07-19 23:44:5710037 DelayedSocketData spdy_data(
10038 0, // don't wait in this case, immediate hangup.
10039 spdy_reads, arraysize(spdy_reads),
10040 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:0710041 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]26ef6582010-06-24 02:30:4710042
[email protected]49639fa2011-12-20 23:22:4110043 TestCompletionCallback callback;
[email protected]26ef6582010-06-24 02:30:4710044
[email protected]bb88e1d32013-05-03 23:11:0710045 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:3610046 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:5010047 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]26ef6582010-06-24 02:30:4710048
[email protected]49639fa2011-12-20 23:22:4110049 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]26ef6582010-06-24 02:30:4710050 EXPECT_EQ(ERR_IO_PENDING, rv);
10051 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult());
[email protected]26ef6582010-06-24 02:30:4710052}
[email protected]65d34382010-07-01 18:12:2610053
[email protected]795cbf82013-07-22 09:37:2710054// A subclass of HttpAuthHandlerMock that records the request URL when
10055// it gets it. This is needed since the auth handler may get destroyed
10056// before we get a chance to query it.
10057class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock {
10058 public:
10059 explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {}
10060
dchengb03027d2014-10-21 12:00:2010061 ~UrlRecordingHttpAuthHandlerMock() override {}
[email protected]795cbf82013-07-22 09:37:2710062
10063 protected:
dchengb03027d2014-10-21 12:00:2010064 int GenerateAuthTokenImpl(const AuthCredentials* credentials,
10065 const HttpRequestInfo* request,
10066 const CompletionCallback& callback,
10067 std::string* auth_token) override {
[email protected]795cbf82013-07-22 09:37:2710068 *url_ = request->url;
10069 return HttpAuthHandlerMock::GenerateAuthTokenImpl(
10070 credentials, request, callback, auth_token);
10071 }
10072
10073 private:
10074 GURL* url_;
10075};
10076
[email protected]23e482282013-06-14 16:08:0210077TEST_P(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) {
[email protected]f45c1ee2010-08-03 00:54:3010078 // This test ensures that the URL passed into the proxy is upgraded
10079 // to https when doing an Alternate Protocol upgrade.
[email protected]d7599122014-05-24 03:37:2310080 session_deps_.use_alternate_protocols = true;
10081 session_deps_.next_protos = SpdyNextProtos();
[email protected]f45c1ee2010-08-03 00:54:3010082
[email protected]bb88e1d32013-05-03 23:11:0710083 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:2010084 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"));
10085 CapturingNetLog net_log;
[email protected]bb88e1d32013-05-03 23:11:0710086 session_deps_.net_log = &net_log;
[email protected]795cbf82013-07-22 09:37:2710087 GURL request_url;
10088 {
10089 HttpAuthHandlerMock::Factory* auth_factory =
10090 new HttpAuthHandlerMock::Factory();
10091 UrlRecordingHttpAuthHandlerMock* auth_handler =
10092 new UrlRecordingHttpAuthHandlerMock(&request_url);
10093 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY);
10094 auth_factory->set_do_init_from_challenge(true);
10095 session_deps_.http_auth_handler_factory.reset(auth_factory);
10096 }
[email protected]f45c1ee2010-08-03 00:54:3010097
10098 HttpRequestInfo request;
10099 request.method = "GET";
10100 request.url = GURL("http://www.google.com");
10101 request.load_flags = 0;
10102
10103 // First round goes unauthenticated through the proxy.
10104 MockWrite data_writes_1[] = {
10105 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
10106 "Host: www.google.com\r\n"
10107 "Proxy-Connection: keep-alive\r\n"
10108 "\r\n"),
10109 };
10110 MockRead data_reads_1[] = {
[email protected]8ddf8322012-02-23 18:08:0610111 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
bnc33b8cef42014-11-19 17:30:3810112 MockRead("HTTP/1.1 200 OK\r\n"),
10113 MockRead("Alternate-Protocol: 443:"),
10114 MockRead(GetAlternateProtocolFromParam()),
10115 MockRead("\r\n"),
10116 MockRead("Proxy-Connection: close\r\n"),
10117 MockRead("\r\n"),
[email protected]f45c1ee2010-08-03 00:54:3010118 };
10119 StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1),
10120 data_writes_1, arraysize(data_writes_1));
10121
10122 // Second round tries to tunnel to www.google.com due to the
10123 // Alternate-Protocol announcement in the first round. It fails due
10124 // to a proxy authentication challenge.
[email protected]394816e92010-08-03 07:38:5910125 // After the failure, a tunnel is established to www.google.com using
10126 // Proxy-Authorization headers. There is then a SPDY request round.
10127 //
[email protected]fe3b7dc2012-02-03 19:52:0910128 // NOTE: Despite the "Proxy-Connection: Close", these are done on the
10129 // same MockTCPClientSocket since the underlying HttpNetworkClientSocket
10130 // does a Disconnect and Connect on the same socket, rather than trying
10131 // to obtain a new one.
10132 //
[email protected]394816e92010-08-03 07:38:5910133 // NOTE: Originally, the proxy response to the second CONNECT request
10134 // simply returned another 407 so the unit test could skip the SSL connection
10135 // establishment and SPDY framing issues. Alas, the
10136 // retry-http-when-alternate-protocol fails logic kicks in, which was more
[email protected]f45c1ee2010-08-03 00:54:3010137 // complicated to set up expectations for than the SPDY session.
[email protected]394816e92010-08-03 07:38:5910138
[email protected]cdf8f7e72013-05-23 10:56:4610139 scoped_ptr<SpdyFrame> req(
10140 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
[email protected]23e482282013-06-14 16:08:0210141 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
10142 scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]f45c1ee2010-08-03 00:54:3010143
[email protected]394816e92010-08-03 07:38:5910144 MockWrite data_writes_2[] = {
10145 // First connection attempt without Proxy-Authorization.
10146 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
10147 "Host: www.google.com\r\n"
10148 "Proxy-Connection: keep-alive\r\n"
10149 "\r\n"),
10150
10151 // Second connection attempt with Proxy-Authorization.
[email protected]f45c1ee2010-08-03 00:54:3010152 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
10153 "Host: www.google.com\r\n"
10154 "Proxy-Connection: keep-alive\r\n"
10155 "Proxy-Authorization: auth_token\r\n"
10156 "\r\n"),
[email protected]f45c1ee2010-08-03 00:54:3010157
[email protected]394816e92010-08-03 07:38:5910158 // SPDY request
10159 CreateMockWrite(*req),
[email protected]f45c1ee2010-08-03 00:54:3010160 };
[email protected]394816e92010-08-03 07:38:5910161 const char kRejectConnectResponse[] = ("HTTP/1.1 407 Unauthorized\r\n"
10162 "Proxy-Authenticate: Mock\r\n"
10163 "Proxy-Connection: close\r\n"
10164 "\r\n");
10165 const char kAcceptConnectResponse[] = "HTTP/1.1 200 Connected\r\n\r\n";
10166 MockRead data_reads_2[] = {
10167 // First connection attempt fails
[email protected]8ddf8322012-02-23 18:08:0610168 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ, 1),
10169 MockRead(ASYNC, kRejectConnectResponse,
[email protected]394816e92010-08-03 07:38:5910170 arraysize(kRejectConnectResponse) - 1, 1),
10171
10172 // Second connection attempt passes
[email protected]8ddf8322012-02-23 18:08:0610173 MockRead(ASYNC, kAcceptConnectResponse,
[email protected]fe3b7dc2012-02-03 19:52:0910174 arraysize(kAcceptConnectResponse) -1, 4),
[email protected]394816e92010-08-03 07:38:5910175
10176 // SPDY response
[email protected]fe3b7dc2012-02-03 19:52:0910177 CreateMockRead(*resp.get(), 6),
10178 CreateMockRead(*data.get(), 6),
[email protected]8ddf8322012-02-23 18:08:0610179 MockRead(ASYNC, 0, 0, 6),
[email protected]394816e92010-08-03 07:38:5910180 };
[email protected]dd54bd82012-07-19 23:44:5710181 OrderedSocketData data_2(
10182 data_reads_2, arraysize(data_reads_2),
10183 data_writes_2, arraysize(data_writes_2));
[email protected]f45c1ee2010-08-03 00:54:3010184
[email protected]8ddf8322012-02-23 18:08:0610185 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0210186 ssl.SetNextProto(GetParam());
[email protected]f45c1ee2010-08-03 00:54:3010187
[email protected]d973e99a2012-02-17 21:02:3610188 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING);
[email protected]2d6728692011-03-12 01:39:5510189 StaticSocketDataProvider hanging_non_alternate_protocol_socket(
10190 NULL, 0, NULL, 0);
10191 hanging_non_alternate_protocol_socket.set_connect_data(
10192 never_finishing_connect);
10193
[email protected]bb88e1d32013-05-03 23:11:0710194 session_deps_.socket_factory->AddSocketDataProvider(&data_1);
10195 session_deps_.socket_factory->AddSocketDataProvider(&data_2);
10196 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
10197 session_deps_.socket_factory->AddSocketDataProvider(
[email protected]2d6728692011-03-12 01:39:5510198 &hanging_non_alternate_protocol_socket);
[email protected]bb88e1d32013-05-03 23:11:0710199 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]f45c1ee2010-08-03 00:54:3010200
10201 // First round should work and provide the Alternate-Protocol state.
[email protected]49639fa2011-12-20 23:22:4110202 TestCompletionCallback callback_1;
[email protected]262eec82013-03-19 21:01:3610203 scoped_ptr<HttpTransaction> trans_1(
[email protected]90499482013-06-01 00:39:5010204 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:4110205 int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog());
[email protected]f45c1ee2010-08-03 00:54:3010206 EXPECT_EQ(ERR_IO_PENDING, rv);
10207 EXPECT_EQ(OK, callback_1.WaitForResult());
10208
10209 // Second round should attempt a tunnel connect and get an auth challenge.
[email protected]49639fa2011-12-20 23:22:4110210 TestCompletionCallback callback_2;
[email protected]262eec82013-03-19 21:01:3610211 scoped_ptr<HttpTransaction> trans_2(
[email protected]90499482013-06-01 00:39:5010212 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:4110213 rv = trans_2->Start(&request, callback_2.callback(), BoundNetLog());
[email protected]f45c1ee2010-08-03 00:54:3010214 EXPECT_EQ(ERR_IO_PENDING, rv);
10215 EXPECT_EQ(OK, callback_2.WaitForResult());
10216 const HttpResponseInfo* response = trans_2->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:5010217 ASSERT_TRUE(response != NULL);
[email protected]f45c1ee2010-08-03 00:54:3010218 ASSERT_FALSE(response->auth_challenge.get() == NULL);
10219
10220 // Restart with auth. Tunnel should work and response received.
[email protected]49639fa2011-12-20 23:22:4110221 TestCompletionCallback callback_3;
10222 rv = trans_2->RestartWithAuth(
10223 AuthCredentials(kFoo, kBar), callback_3.callback());
[email protected]f45c1ee2010-08-03 00:54:3010224 EXPECT_EQ(ERR_IO_PENDING, rv);
10225 EXPECT_EQ(OK, callback_3.WaitForResult());
10226
10227 // After all that work, these two lines (or actually, just the scheme) are
10228 // what this test is all about. Make sure it happens correctly.
[email protected]f45c1ee2010-08-03 00:54:3010229 EXPECT_EQ("https", request_url.scheme());
10230 EXPECT_EQ("www.google.com", request_url.host());
10231
[email protected]029c83b62013-01-24 05:28:2010232 LoadTimingInfo load_timing_info;
10233 EXPECT_TRUE(trans_2->GetLoadTimingInfo(&load_timing_info));
10234 TestLoadTimingNotReusedWithPac(load_timing_info,
10235 CONNECT_TIMING_HAS_SSL_TIMES);
[email protected]8e6441ca2010-08-19 05:56:3810236}
10237
10238// Test that if we cancel the transaction as the connection is completing, that
10239// everything tears down correctly.
[email protected]23e482282013-06-14 16:08:0210240TEST_P(HttpNetworkTransactionTest, SimpleCancel) {
[email protected]8e6441ca2010-08-19 05:56:3810241 // Setup everything about the connection to complete synchronously, so that
10242 // after calling HttpNetworkTransaction::Start, the only thing we're waiting
10243 // for is the callback from the HttpStreamRequest.
10244 // Then cancel the transaction.
10245 // Verify that we don't crash.
[email protected]d973e99a2012-02-17 21:02:3610246 MockConnect mock_connect(SYNCHRONOUS, OK);
[email protected]8e6441ca2010-08-19 05:56:3810247 MockRead data_reads[] = {
[email protected]8ddf8322012-02-23 18:08:0610248 MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"),
10249 MockRead(SYNCHRONOUS, "hello world"),
10250 MockRead(SYNCHRONOUS, OK),
[email protected]8e6441ca2010-08-19 05:56:3810251 };
10252
[email protected]8e6441ca2010-08-19 05:56:3810253 HttpRequestInfo request;
10254 request.method = "GET";
10255 request.url = GURL("http://www.google.com/");
10256 request.load_flags = 0;
10257
[email protected]bb88e1d32013-05-03 23:11:0710258 session_deps_.host_resolver->set_synchronous_mode(true);
[email protected]3fe8d2f82013-10-17 08:56:0710259 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:2710260 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4110261 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:2710262
[email protected]8e6441ca2010-08-19 05:56:3810263 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
10264 data.set_connect_data(mock_connect);
[email protected]bb88e1d32013-05-03 23:11:0710265 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]8e6441ca2010-08-19 05:56:3810266
[email protected]49639fa2011-12-20 23:22:4110267 TestCompletionCallback callback;
[email protected]8e6441ca2010-08-19 05:56:3810268
[email protected]333bdf62012-06-08 22:57:2910269 CapturingBoundNetLog log;
[email protected]49639fa2011-12-20 23:22:4110270 int rv = trans->Start(&request, callback.callback(), log.bound());
[email protected]8e6441ca2010-08-19 05:56:3810271 EXPECT_EQ(ERR_IO_PENDING, rv);
10272 trans.reset(); // Cancel the transaction here.
10273
[email protected]2da659e2013-05-23 20:51:3410274 base::MessageLoop::current()->RunUntilIdle();
[email protected]f45c1ee2010-08-03 00:54:3010275}
10276
[email protected]ecab6e052014-05-16 14:58:1210277// Test that if a transaction is cancelled after receiving the headers, the
10278// stream is drained properly and added back to the socket pool. The main
10279// purpose of this test is to make sure that an HttpStreamParser can be read
10280// from after the HttpNetworkTransaction and the objects it owns have been
10281// deleted.
10282// See http://crbug.com/368418
10283TEST_P(HttpNetworkTransactionTest, CancelAfterHeaders) {
10284 MockRead data_reads[] = {
10285 MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"),
10286 MockRead(ASYNC, "Content-Length: 2\r\n"),
10287 MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"),
10288 MockRead(ASYNC, "1"),
10289 // 2 async reads are necessary to trigger a ReadResponseBody call after the
10290 // HttpNetworkTransaction has been deleted.
10291 MockRead(ASYNC, "2"),
10292 MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this.
10293 };
10294 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
10295 session_deps_.socket_factory->AddSocketDataProvider(&data);
10296
10297 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
10298
10299 {
10300 HttpRequestInfo request;
10301 request.method = "GET";
10302 request.url = GURL("http://www.google.com/");
10303 request.load_flags = 0;
10304
dcheng48459ac22014-08-26 00:46:4110305 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
[email protected]ecab6e052014-05-16 14:58:1210306 TestCompletionCallback callback;
10307
10308 int rv = trans.Start(&request, callback.callback(), BoundNetLog());
10309 EXPECT_EQ(ERR_IO_PENDING, rv);
10310 callback.WaitForResult();
10311
10312 const HttpResponseInfo* response = trans.GetResponseInfo();
10313 ASSERT_TRUE(response != NULL);
10314 EXPECT_TRUE(response->headers.get() != NULL);
10315 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
10316
10317 // The transaction and HttpRequestInfo are deleted.
10318 }
10319
10320 // Let the HttpResponseBodyDrainer drain the socket.
10321 base::MessageLoop::current()->RunUntilIdle();
10322
10323 // Socket should now be idle, waiting to be reused.
dcheng48459ac22014-08-26 00:46:4110324 EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get()));
[email protected]ecab6e052014-05-16 14:58:1210325}
10326
[email protected]76a505b2010-08-25 06:23:0010327// Test a basic GET request through a proxy.
[email protected]23e482282013-06-14 16:08:0210328TEST_P(HttpNetworkTransactionTest, ProxyGet) {
[email protected]bb88e1d32013-05-03 23:11:0710329 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:2010330 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"));
[email protected]333bdf62012-06-08 22:57:2910331 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:0710332 session_deps_.net_log = log.bound().net_log();
10333 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]76a505b2010-08-25 06:23:0010334
[email protected]76a505b2010-08-25 06:23:0010335 HttpRequestInfo request;
10336 request.method = "GET";
10337 request.url = GURL("http://www.google.com/");
10338
10339 MockWrite data_writes1[] = {
10340 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
10341 "Host: www.google.com\r\n"
10342 "Proxy-Connection: keep-alive\r\n\r\n"),
10343 };
10344
10345 MockRead data_reads1[] = {
10346 MockRead("HTTP/1.1 200 OK\r\n"),
10347 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
10348 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:0610349 MockRead(SYNCHRONOUS, OK),
[email protected]76a505b2010-08-25 06:23:0010350 };
10351
10352 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
10353 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:0710354 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]76a505b2010-08-25 06:23:0010355
[email protected]49639fa2011-12-20 23:22:4110356 TestCompletionCallback callback1;
[email protected]76a505b2010-08-25 06:23:0010357
[email protected]262eec82013-03-19 21:01:3610358 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:5010359 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]597a1ab2014-06-26 08:12:2710360 BeforeProxyHeadersSentHandler proxy_headers_handler;
10361 trans->SetBeforeProxyHeadersSentCallback(
10362 base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent,
10363 base::Unretained(&proxy_headers_handler)));
[email protected]0b0bf032010-09-21 18:08:5010364
[email protected]49639fa2011-12-20 23:22:4110365 int rv = trans->Start(&request, callback1.callback(), log.bound());
[email protected]76a505b2010-08-25 06:23:0010366 EXPECT_EQ(ERR_IO_PENDING, rv);
10367
10368 rv = callback1.WaitForResult();
10369 EXPECT_EQ(OK, rv);
10370
10371 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:5010372 ASSERT_TRUE(response != NULL);
[email protected]76a505b2010-08-25 06:23:0010373
10374 EXPECT_TRUE(response->headers->IsKeepAlive());
10375 EXPECT_EQ(200, response->headers->response_code());
10376 EXPECT_EQ(100, response->headers->GetContentLength());
10377 EXPECT_TRUE(response->was_fetched_via_proxy);
[email protected]d8fc4722014-06-13 13:17:1510378 EXPECT_TRUE(
10379 response->proxy_server.Equals(HostPortPair::FromString("myproxy:70")));
[email protected]597a1ab2014-06-26 08:12:2710380 EXPECT_TRUE(proxy_headers_handler.observed_before_proxy_headers_sent());
10381 EXPECT_EQ("myproxy:70", proxy_headers_handler.observed_proxy_server_uri());
[email protected]76a505b2010-08-25 06:23:0010382 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
[email protected]029c83b62013-01-24 05:28:2010383
10384 LoadTimingInfo load_timing_info;
10385 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
10386 TestLoadTimingNotReusedWithPac(load_timing_info,
10387 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY);
[email protected]76a505b2010-08-25 06:23:0010388}
10389
10390// Test a basic HTTPS GET request through a proxy.
[email protected]23e482282013-06-14 16:08:0210391TEST_P(HttpNetworkTransactionTest, ProxyTunnelGet) {
[email protected]bb88e1d32013-05-03 23:11:0710392 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:2010393 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"));
[email protected]333bdf62012-06-08 22:57:2910394 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:0710395 session_deps_.net_log = log.bound().net_log();
10396 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]76a505b2010-08-25 06:23:0010397
[email protected]76a505b2010-08-25 06:23:0010398 HttpRequestInfo request;
10399 request.method = "GET";
10400 request.url = GURL("https://www.google.com/");
10401
10402 // Since we have proxy, should try to establish tunnel.
10403 MockWrite data_writes1[] = {
10404 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
10405 "Host: www.google.com\r\n"
10406 "Proxy-Connection: keep-alive\r\n\r\n"),
10407
10408 MockWrite("GET / HTTP/1.1\r\n"
10409 "Host: www.google.com\r\n"
10410 "Connection: keep-alive\r\n\r\n"),
10411 };
10412
10413 MockRead data_reads1[] = {
10414 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"),
10415
10416 MockRead("HTTP/1.1 200 OK\r\n"),
10417 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
10418 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:0610419 MockRead(SYNCHRONOUS, OK),
[email protected]76a505b2010-08-25 06:23:0010420 };
10421
10422 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
10423 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:0710424 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]8ddf8322012-02-23 18:08:0610425 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]bb88e1d32013-05-03 23:11:0710426 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]76a505b2010-08-25 06:23:0010427
[email protected]49639fa2011-12-20 23:22:4110428 TestCompletionCallback callback1;
[email protected]76a505b2010-08-25 06:23:0010429
[email protected]262eec82013-03-19 21:01:3610430 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:5010431 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0b0bf032010-09-21 18:08:5010432
[email protected]49639fa2011-12-20 23:22:4110433 int rv = trans->Start(&request, callback1.callback(), log.bound());
[email protected]76a505b2010-08-25 06:23:0010434 EXPECT_EQ(ERR_IO_PENDING, rv);
10435
10436 rv = callback1.WaitForResult();
10437 EXPECT_EQ(OK, rv);
[email protected]f3da152d2012-06-02 01:00:5710438 net::CapturingNetLog::CapturedEntryList entries;
[email protected]b2fcd0e2010-12-01 15:19:4010439 log.GetEntries(&entries);
[email protected]76a505b2010-08-25 06:23:0010440 size_t pos = ExpectLogContainsSomewhere(
[email protected]b2fcd0e2010-12-01 15:19:4010441 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
[email protected]76a505b2010-08-25 06:23:0010442 NetLog::PHASE_NONE);
10443 ExpectLogContainsSomewhere(
[email protected]b2fcd0e2010-12-01 15:19:4010444 entries, pos,
[email protected]76a505b2010-08-25 06:23:0010445 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
10446 NetLog::PHASE_NONE);
10447
10448 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:5010449 ASSERT_TRUE(response != NULL);
[email protected]76a505b2010-08-25 06:23:0010450
10451 EXPECT_TRUE(response->headers->IsKeepAlive());
10452 EXPECT_EQ(200, response->headers->response_code());
10453 EXPECT_EQ(100, response->headers->GetContentLength());
10454 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
10455 EXPECT_TRUE(response->was_fetched_via_proxy);
[email protected]d8fc4722014-06-13 13:17:1510456 EXPECT_TRUE(
10457 response->proxy_server.Equals(HostPortPair::FromString("myproxy:70")));
[email protected]029c83b62013-01-24 05:28:2010458
10459 LoadTimingInfo load_timing_info;
10460 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
10461 TestLoadTimingNotReusedWithPac(load_timing_info,
10462 CONNECT_TIMING_HAS_SSL_TIMES);
[email protected]76a505b2010-08-25 06:23:0010463}
10464
10465// Test a basic HTTPS GET request through a proxy, but the server hangs up
10466// while establishing the tunnel.
[email protected]23e482282013-06-14 16:08:0210467TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetHangup) {
[email protected]bb88e1d32013-05-03 23:11:0710468 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70"));
[email protected]333bdf62012-06-08 22:57:2910469 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:0710470 session_deps_.net_log = log.bound().net_log();
10471 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]76a505b2010-08-25 06:23:0010472
[email protected]76a505b2010-08-25 06:23:0010473 HttpRequestInfo request;
10474 request.method = "GET";
10475 request.url = GURL("https://www.google.com/");
10476
10477 // Since we have proxy, should try to establish tunnel.
10478 MockWrite data_writes1[] = {
10479 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
10480 "Host: www.google.com\r\n"
10481 "Proxy-Connection: keep-alive\r\n\r\n"),
10482
10483 MockWrite("GET / HTTP/1.1\r\n"
10484 "Host: www.google.com\r\n"
10485 "Connection: keep-alive\r\n\r\n"),
10486 };
10487
10488 MockRead data_reads1[] = {
[email protected]8ddf8322012-02-23 18:08:0610489 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
[email protected]76a505b2010-08-25 06:23:0010490 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:0610491 MockRead(ASYNC, 0, 0), // EOF
[email protected]76a505b2010-08-25 06:23:0010492 };
10493
10494 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
10495 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:0710496 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]8ddf8322012-02-23 18:08:0610497 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]bb88e1d32013-05-03 23:11:0710498 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]76a505b2010-08-25 06:23:0010499
[email protected]49639fa2011-12-20 23:22:4110500 TestCompletionCallback callback1;
[email protected]76a505b2010-08-25 06:23:0010501
[email protected]262eec82013-03-19 21:01:3610502 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:5010503 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0b0bf032010-09-21 18:08:5010504
[email protected]49639fa2011-12-20 23:22:4110505 int rv = trans->Start(&request, callback1.callback(), log.bound());
[email protected]76a505b2010-08-25 06:23:0010506 EXPECT_EQ(ERR_IO_PENDING, rv);
10507
10508 rv = callback1.WaitForResult();
10509 EXPECT_EQ(ERR_EMPTY_RESPONSE, rv);
[email protected]f3da152d2012-06-02 01:00:5710510 net::CapturingNetLog::CapturedEntryList entries;
[email protected]b2fcd0e2010-12-01 15:19:4010511 log.GetEntries(&entries);
[email protected]76a505b2010-08-25 06:23:0010512 size_t pos = ExpectLogContainsSomewhere(
[email protected]b2fcd0e2010-12-01 15:19:4010513 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
[email protected]76a505b2010-08-25 06:23:0010514 NetLog::PHASE_NONE);
10515 ExpectLogContainsSomewhere(
[email protected]b2fcd0e2010-12-01 15:19:4010516 entries, pos,
[email protected]76a505b2010-08-25 06:23:0010517 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
10518 NetLog::PHASE_NONE);
10519}
10520
[email protected]749eefa82010-09-13 22:14:0310521// Test for crbug.com/55424.
[email protected]23e482282013-06-14 16:08:0210522TEST_P(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) {
[email protected]cdf8f7e72013-05-23 10:56:4610523 scoped_ptr<SpdyFrame> req(
10524 spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST));
[email protected]749eefa82010-09-13 22:14:0310525 MockWrite spdy_writes[] = { CreateMockWrite(*req) };
10526
[email protected]23e482282013-06-14 16:08:0210527 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
10528 scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]749eefa82010-09-13 22:14:0310529 MockRead spdy_reads[] = {
10530 CreateMockRead(*resp),
10531 CreateMockRead(*data),
[email protected]8ddf8322012-02-23 18:08:0610532 MockRead(ASYNC, 0, 0),
[email protected]749eefa82010-09-13 22:14:0310533 };
10534
[email protected]dd54bd82012-07-19 23:44:5710535 DelayedSocketData spdy_data(
10536 1, // wait for one write to finish before reading.
10537 spdy_reads, arraysize(spdy_reads),
10538 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:0710539 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]749eefa82010-09-13 22:14:0310540
[email protected]8ddf8322012-02-23 18:08:0610541 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0210542 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0710543 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]749eefa82010-09-13 22:14:0310544
[email protected]bb88e1d32013-05-03 23:11:0710545 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]749eefa82010-09-13 22:14:0310546
10547 // Set up an initial SpdySession in the pool to reuse.
[email protected]02b0c342010-09-25 21:09:3810548 HostPortPair host_port_pair("www.google.com", 443);
[email protected]e6d017652013-05-17 18:01:4010549 SpdySessionKey key(host_port_pair, ProxyServer::Direct(),
[email protected]314b03992014-04-01 01:28:5310550 PRIVACY_MODE_DISABLED);
[email protected]795cbf82013-07-22 09:37:2710551 base::WeakPtr<SpdySession> spdy_session =
[email protected]41d64e82013-07-03 22:44:2610552 CreateInsecureSpdySession(session, key, BoundNetLog());
[email protected]749eefa82010-09-13 22:14:0310553
10554 HttpRequestInfo request;
10555 request.method = "GET";
10556 request.url = GURL("https://www.google.com/");
10557 request.load_flags = 0;
10558
10559 // This is the important line that marks this as a preconnect.
10560 request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED;
10561
[email protected]262eec82013-03-19 21:01:3610562 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:5010563 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]749eefa82010-09-13 22:14:0310564
[email protected]41d64e82013-07-03 22:44:2610565 TestCompletionCallback callback;
[email protected]49639fa2011-12-20 23:22:4110566 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]749eefa82010-09-13 22:14:0310567 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]49639fa2011-12-20 23:22:4110568 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]749eefa82010-09-13 22:14:0310569}
10570
[email protected]73b8dd222010-11-11 19:55:2410571// Given a net error, cause that error to be returned from the first Write()
10572// call and verify that the HttpTransaction fails with that error.
[email protected]23e482282013-06-14 16:08:0210573void HttpNetworkTransactionTest::CheckErrorIsPassedBack(
[email protected]bb88e1d32013-05-03 23:11:0710574 int error, IoMode mode) {
[email protected]cb9bf6ca2011-01-28 13:15:2710575 net::HttpRequestInfo request_info;
10576 request_info.url = GURL("https://www.example.com/");
10577 request_info.method = "GET";
10578 request_info.load_flags = net::LOAD_NORMAL;
10579
[email protected]8ddf8322012-02-23 18:08:0610580 SSLSocketDataProvider ssl_data(mode, OK);
[email protected]73b8dd222010-11-11 19:55:2410581 net::MockWrite data_writes[] = {
[email protected]8ddf8322012-02-23 18:08:0610582 net::MockWrite(mode, error),
[email protected]73b8dd222010-11-11 19:55:2410583 };
10584 net::StaticSocketDataProvider data(NULL, 0,
10585 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:0710586 session_deps_.socket_factory->AddSocketDataProvider(&data);
10587 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data);
[email protected]73b8dd222010-11-11 19:55:2410588
[email protected]bb88e1d32013-05-03 23:11:0710589 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:3610590 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:5010591 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]73b8dd222010-11-11 19:55:2410592
[email protected]49639fa2011-12-20 23:22:4110593 TestCompletionCallback callback;
10594 int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog());
[email protected]73b8dd222010-11-11 19:55:2410595 if (rv == net::ERR_IO_PENDING)
10596 rv = callback.WaitForResult();
10597 ASSERT_EQ(error, rv);
10598}
10599
[email protected]23e482282013-06-14 16:08:0210600TEST_P(HttpNetworkTransactionTest, SSLWriteCertError) {
[email protected]73b8dd222010-11-11 19:55:2410601 // Just check a grab bag of cert errors.
10602 static const int kErrors[] = {
10603 ERR_CERT_COMMON_NAME_INVALID,
10604 ERR_CERT_AUTHORITY_INVALID,
10605 ERR_CERT_DATE_INVALID,
10606 };
10607 for (size_t i = 0; i < arraysize(kErrors); i++) {
[email protected]8ddf8322012-02-23 18:08:0610608 CheckErrorIsPassedBack(kErrors[i], ASYNC);
10609 CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS);
[email protected]73b8dd222010-11-11 19:55:2410610 }
10611}
10612
[email protected]bd0b6772011-01-11 19:59:3010613// Ensure that a client certificate is removed from the SSL client auth
10614// cache when:
10615// 1) No proxy is involved.
10616// 2) TLS False Start is disabled.
10617// 3) The initial TLS handshake requests a client certificate.
10618// 4) The client supplies an invalid/unacceptable certificate.
[email protected]23e482282013-06-14 16:08:0210619TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:2310620 ClientAuthCertCache_Direct_NoFalseStart) {
[email protected]cb9bf6ca2011-01-28 13:15:2710621 net::HttpRequestInfo request_info;
10622 request_info.url = GURL("https://www.example.com/");
10623 request_info.method = "GET";
10624 request_info.load_flags = net::LOAD_NORMAL;
10625
[email protected]bd0b6772011-01-11 19:59:3010626 scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo());
[email protected]791879c2013-12-17 07:22:4110627 cert_request->host_and_port = HostPortPair("www.example.com", 443);
[email protected]bd0b6772011-01-11 19:59:3010628
10629 // [ssl_]data1 contains the data for the first SSL handshake. When a
10630 // CertificateRequest is received for the first time, the handshake will
10631 // be aborted to allow the caller to provide a certificate.
[email protected]8ddf8322012-02-23 18:08:0610632 SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED);
[email protected]bd0b6772011-01-11 19:59:3010633 ssl_data1.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710634 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1);
[email protected]bd0b6772011-01-11 19:59:3010635 net::StaticSocketDataProvider data1(NULL, 0, NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710636 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]bd0b6772011-01-11 19:59:3010637
10638 // [ssl_]data2 contains the data for the second SSL handshake. When TLS
10639 // False Start is not being used, the result of the SSL handshake will be
10640 // returned as part of the SSLClientSocket::Connect() call. This test
10641 // matches the result of a server sending a handshake_failure alert,
10642 // rather than a Finished message, because it requires a client
10643 // certificate and none was supplied.
[email protected]8ddf8322012-02-23 18:08:0610644 SSLSocketDataProvider ssl_data2(ASYNC, net::ERR_SSL_PROTOCOL_ERROR);
[email protected]bd0b6772011-01-11 19:59:3010645 ssl_data2.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710646 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2);
[email protected]bd0b6772011-01-11 19:59:3010647 net::StaticSocketDataProvider data2(NULL, 0, NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710648 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]bd0b6772011-01-11 19:59:3010649
10650 // [ssl_]data3 contains the data for the third SSL handshake. When a
10651 // connection to a server fails during an SSL handshake,
[email protected]80c75f682012-05-26 16:22:1710652 // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous
10653 // connection was attempted with TLSv1.1. This is transparent to the caller
[email protected]bd0b6772011-01-11 19:59:3010654 // of the HttpNetworkTransaction. Because this test failure is due to
10655 // requiring a client certificate, this fallback handshake should also
10656 // fail.
[email protected]8ddf8322012-02-23 18:08:0610657 SSLSocketDataProvider ssl_data3(ASYNC, net::ERR_SSL_PROTOCOL_ERROR);
[email protected]bd0b6772011-01-11 19:59:3010658 ssl_data3.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710659 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3);
[email protected]bd0b6772011-01-11 19:59:3010660 net::StaticSocketDataProvider data3(NULL, 0, NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710661 session_deps_.socket_factory->AddSocketDataProvider(&data3);
[email protected]bd0b6772011-01-11 19:59:3010662
[email protected]80c75f682012-05-26 16:22:1710663 // [ssl_]data4 contains the data for the fourth SSL handshake. When a
10664 // connection to a server fails during an SSL handshake,
10665 // HttpNetworkTransaction will attempt to fallback to SSLv3 if the previous
10666 // connection was attempted with TLSv1. This is transparent to the caller
10667 // of the HttpNetworkTransaction. Because this test failure is due to
10668 // requiring a client certificate, this fallback handshake should also
10669 // fail.
10670 SSLSocketDataProvider ssl_data4(ASYNC, net::ERR_SSL_PROTOCOL_ERROR);
10671 ssl_data4.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710672 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4);
[email protected]80c75f682012-05-26 16:22:1710673 net::StaticSocketDataProvider data4(NULL, 0, NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710674 session_deps_.socket_factory->AddSocketDataProvider(&data4);
[email protected]80c75f682012-05-26 16:22:1710675
[email protected]7799de12013-05-30 05:52:5110676 // Need one more if TLSv1.2 is enabled.
10677 SSLSocketDataProvider ssl_data5(ASYNC, net::ERR_SSL_PROTOCOL_ERROR);
10678 ssl_data5.cert_request_info = cert_request.get();
10679 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5);
10680 net::StaticSocketDataProvider data5(NULL, 0, NULL, 0);
10681 session_deps_.socket_factory->AddSocketDataProvider(&data5);
10682
[email protected]bb88e1d32013-05-03 23:11:0710683 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:3610684 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:5010685 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]bd0b6772011-01-11 19:59:3010686
[email protected]bd0b6772011-01-11 19:59:3010687 // Begin the SSL handshake with the peer. This consumes ssl_data1.
[email protected]49639fa2011-12-20 23:22:4110688 TestCompletionCallback callback;
10689 int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog());
[email protected]bd0b6772011-01-11 19:59:3010690 ASSERT_EQ(net::ERR_IO_PENDING, rv);
10691
10692 // Complete the SSL handshake, which should abort due to requiring a
10693 // client certificate.
10694 rv = callback.WaitForResult();
10695 ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv);
10696
10697 // Indicate that no certificate should be supplied. From the perspective
10698 // of SSLClientCertCache, NULL is just as meaningful as a real
10699 // certificate, so this is the same as supply a
10700 // legitimate-but-unacceptable certificate.
[email protected]49639fa2011-12-20 23:22:4110701 rv = trans->RestartWithCertificate(NULL, callback.callback());
[email protected]bd0b6772011-01-11 19:59:3010702 ASSERT_EQ(net::ERR_IO_PENDING, rv);
10703
10704 // Ensure the certificate was added to the client auth cache before
10705 // allowing the connection to continue restarting.
10706 scoped_refptr<X509Certificate> client_cert;
[email protected]791879c2013-12-17 07:22:4110707 ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup(
10708 HostPortPair("www.example.com", 443), &client_cert));
[email protected]bd0b6772011-01-11 19:59:3010709 ASSERT_EQ(NULL, client_cert.get());
10710
10711 // Restart the handshake. This will consume ssl_data2, which fails, and
[email protected]80c75f682012-05-26 16:22:1710712 // then consume ssl_data3 and ssl_data4, both of which should also fail.
10713 // The result code is checked against what ssl_data4 should return.
[email protected]bd0b6772011-01-11 19:59:3010714 rv = callback.WaitForResult();
10715 ASSERT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv);
10716
10717 // Ensure that the client certificate is removed from the cache on a
10718 // handshake failure.
[email protected]791879c2013-12-17 07:22:4110719 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup(
10720 HostPortPair("www.example.com", 443), &client_cert));
[email protected]bd0b6772011-01-11 19:59:3010721}
10722
10723// Ensure that a client certificate is removed from the SSL client auth
10724// cache when:
10725// 1) No proxy is involved.
10726// 2) TLS False Start is enabled.
10727// 3) The initial TLS handshake requests a client certificate.
10728// 4) The client supplies an invalid/unacceptable certificate.
[email protected]23e482282013-06-14 16:08:0210729TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:2310730 ClientAuthCertCache_Direct_FalseStart) {
[email protected]cb9bf6ca2011-01-28 13:15:2710731 net::HttpRequestInfo request_info;
10732 request_info.url = GURL("https://www.example.com/");
10733 request_info.method = "GET";
10734 request_info.load_flags = net::LOAD_NORMAL;
10735
[email protected]bd0b6772011-01-11 19:59:3010736 scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo());
[email protected]791879c2013-12-17 07:22:4110737 cert_request->host_and_port = HostPortPair("www.example.com", 443);
[email protected]bd0b6772011-01-11 19:59:3010738
10739 // When TLS False Start is used, SSLClientSocket::Connect() calls will
10740 // return successfully after reading up to the peer's Certificate message.
10741 // This is to allow the caller to call SSLClientSocket::Write(), which can
10742 // enqueue application data to be sent in the same packet as the
10743 // ChangeCipherSpec and Finished messages.
10744 // The actual handshake will be finished when SSLClientSocket::Read() is
10745 // called, which expects to process the peer's ChangeCipherSpec and
10746 // Finished messages. If there was an error negotiating with the peer,
10747 // such as due to the peer requiring a client certificate when none was
10748 // supplied, the alert sent by the peer won't be processed until Read() is
10749 // called.
10750
10751 // Like the non-False Start case, when a client certificate is requested by
10752 // the peer, the handshake is aborted during the Connect() call.
10753 // [ssl_]data1 represents the initial SSL handshake with the peer.
[email protected]8ddf8322012-02-23 18:08:0610754 SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED);
[email protected]bd0b6772011-01-11 19:59:3010755 ssl_data1.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710756 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1);
[email protected]bd0b6772011-01-11 19:59:3010757 net::StaticSocketDataProvider data1(NULL, 0, NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710758 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]bd0b6772011-01-11 19:59:3010759
10760 // When a client certificate is supplied, Connect() will not be aborted
10761 // when the peer requests the certificate. Instead, the handshake will
10762 // artificially succeed, allowing the caller to write the HTTP request to
10763 // the socket. The handshake messages are not processed until Read() is
10764 // called, which then detects that the handshake was aborted, due to the
10765 // peer sending a handshake_failure because it requires a client
10766 // certificate.
[email protected]8ddf8322012-02-23 18:08:0610767 SSLSocketDataProvider ssl_data2(ASYNC, net::OK);
[email protected]bd0b6772011-01-11 19:59:3010768 ssl_data2.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710769 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2);
[email protected]bd0b6772011-01-11 19:59:3010770 net::MockRead data2_reads[] = {
[email protected]8ddf8322012-02-23 18:08:0610771 net::MockRead(ASYNC /* async */, net::ERR_SSL_PROTOCOL_ERROR),
[email protected]bd0b6772011-01-11 19:59:3010772 };
10773 net::StaticSocketDataProvider data2(
10774 data2_reads, arraysize(data2_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710775 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]bd0b6772011-01-11 19:59:3010776
10777 // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is
[email protected]80c75f682012-05-26 16:22:1710778 // the data for the SSL handshake once the TLSv1.1 connection falls back to
10779 // TLSv1. It has the same behaviour as [ssl_]data2.
[email protected]8ddf8322012-02-23 18:08:0610780 SSLSocketDataProvider ssl_data3(ASYNC, net::OK);
[email protected]bd0b6772011-01-11 19:59:3010781 ssl_data3.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710782 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3);
[email protected]bd0b6772011-01-11 19:59:3010783 net::StaticSocketDataProvider data3(
10784 data2_reads, arraysize(data2_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710785 session_deps_.socket_factory->AddSocketDataProvider(&data3);
[email protected]bd0b6772011-01-11 19:59:3010786
[email protected]80c75f682012-05-26 16:22:1710787 // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection
10788 // falls back to SSLv3. It has the same behaviour as [ssl_]data2.
10789 SSLSocketDataProvider ssl_data4(ASYNC, net::OK);
10790 ssl_data4.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710791 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4);
[email protected]80c75f682012-05-26 16:22:1710792 net::StaticSocketDataProvider data4(
10793 data2_reads, arraysize(data2_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710794 session_deps_.socket_factory->AddSocketDataProvider(&data4);
[email protected]80c75f682012-05-26 16:22:1710795
[email protected]7799de12013-05-30 05:52:5110796 // Need one more if TLSv1.2 is enabled.
10797 SSLSocketDataProvider ssl_data5(ASYNC, net::OK);
10798 ssl_data5.cert_request_info = cert_request.get();
10799 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5);
10800 net::StaticSocketDataProvider data5(
10801 data2_reads, arraysize(data2_reads), NULL, 0);
10802 session_deps_.socket_factory->AddSocketDataProvider(&data5);
10803
[email protected]bb88e1d32013-05-03 23:11:0710804 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:3610805 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:5010806 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]bd0b6772011-01-11 19:59:3010807
[email protected]bd0b6772011-01-11 19:59:3010808 // Begin the initial SSL handshake.
[email protected]49639fa2011-12-20 23:22:4110809 TestCompletionCallback callback;
10810 int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog());
[email protected]bd0b6772011-01-11 19:59:3010811 ASSERT_EQ(net::ERR_IO_PENDING, rv);
10812
10813 // Complete the SSL handshake, which should abort due to requiring a
10814 // client certificate.
10815 rv = callback.WaitForResult();
10816 ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv);
10817
10818 // Indicate that no certificate should be supplied. From the perspective
10819 // of SSLClientCertCache, NULL is just as meaningful as a real
10820 // certificate, so this is the same as supply a
10821 // legitimate-but-unacceptable certificate.
[email protected]49639fa2011-12-20 23:22:4110822 rv = trans->RestartWithCertificate(NULL, callback.callback());
[email protected]bd0b6772011-01-11 19:59:3010823 ASSERT_EQ(net::ERR_IO_PENDING, rv);
10824
10825 // Ensure the certificate was added to the client auth cache before
10826 // allowing the connection to continue restarting.
10827 scoped_refptr<X509Certificate> client_cert;
[email protected]791879c2013-12-17 07:22:4110828 ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup(
10829 HostPortPair("www.example.com", 443), &client_cert));
[email protected]bd0b6772011-01-11 19:59:3010830 ASSERT_EQ(NULL, client_cert.get());
10831
[email protected]bd0b6772011-01-11 19:59:3010832 // Restart the handshake. This will consume ssl_data2, which fails, and
[email protected]80c75f682012-05-26 16:22:1710833 // then consume ssl_data3 and ssl_data4, both of which should also fail.
10834 // The result code is checked against what ssl_data4 should return.
[email protected]bd0b6772011-01-11 19:59:3010835 rv = callback.WaitForResult();
10836 ASSERT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv);
10837
10838 // Ensure that the client certificate is removed from the cache on a
10839 // handshake failure.
[email protected]791879c2013-12-17 07:22:4110840 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup(
10841 HostPortPair("www.example.com", 443), &client_cert));
[email protected]bd0b6772011-01-11 19:59:3010842}
10843
[email protected]8c405132011-01-11 22:03:1810844// Ensure that a client certificate is removed from the SSL client auth
10845// cache when:
10846// 1) An HTTPS proxy is involved.
10847// 3) The HTTPS proxy requests a client certificate.
10848// 4) The client supplies an invalid/unacceptable certificate for the
10849// proxy.
10850// The test is repeated twice, first for connecting to an HTTPS endpoint,
10851// then for connecting to an HTTP endpoint.
[email protected]23e482282013-06-14 16:08:0210852TEST_P(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) {
[email protected]bb88e1d32013-05-03 23:11:0710853 session_deps_.proxy_service.reset(
[email protected]8c405132011-01-11 22:03:1810854 ProxyService::CreateFixed("https://proxy:70"));
[email protected]333bdf62012-06-08 22:57:2910855 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:0710856 session_deps_.net_log = log.bound().net_log();
[email protected]8c405132011-01-11 22:03:1810857
10858 scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo());
[email protected]791879c2013-12-17 07:22:4110859 cert_request->host_and_port = HostPortPair("proxy", 70);
[email protected]8c405132011-01-11 22:03:1810860
10861 // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of
10862 // [ssl_]data[1-3]. Rather than represending the endpoint
10863 // (www.example.com:443), they represent failures with the HTTPS proxy
10864 // (proxy:70).
[email protected]8ddf8322012-02-23 18:08:0610865 SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED);
[email protected]8c405132011-01-11 22:03:1810866 ssl_data1.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710867 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1);
[email protected]8c405132011-01-11 22:03:1810868 net::StaticSocketDataProvider data1(NULL, 0, NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710869 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]8c405132011-01-11 22:03:1810870
[email protected]8ddf8322012-02-23 18:08:0610871 SSLSocketDataProvider ssl_data2(ASYNC, net::ERR_SSL_PROTOCOL_ERROR);
[email protected]8c405132011-01-11 22:03:1810872 ssl_data2.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710873 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2);
[email protected]8c405132011-01-11 22:03:1810874 net::StaticSocketDataProvider data2(NULL, 0, NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710875 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]8c405132011-01-11 22:03:1810876
[email protected]80c75f682012-05-26 16:22:1710877 // TODO(wtc): find out why this unit test doesn't need [ssl_]data3.
10878#if 0
[email protected]8ddf8322012-02-23 18:08:0610879 SSLSocketDataProvider ssl_data3(ASYNC, net::ERR_SSL_PROTOCOL_ERROR);
[email protected]8c405132011-01-11 22:03:1810880 ssl_data3.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710881 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3);
[email protected]8c405132011-01-11 22:03:1810882 net::StaticSocketDataProvider data3(NULL, 0, NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710883 session_deps_.socket_factory->AddSocketDataProvider(&data3);
[email protected]80c75f682012-05-26 16:22:1710884#endif
[email protected]8c405132011-01-11 22:03:1810885
10886 net::HttpRequestInfo requests[2];
10887 requests[0].url = GURL("https://www.example.com/");
10888 requests[0].method = "GET";
10889 requests[0].load_flags = net::LOAD_NORMAL;
10890
10891 requests[1].url = GURL("http://www.example.com/");
10892 requests[1].method = "GET";
10893 requests[1].load_flags = net::LOAD_NORMAL;
10894
10895 for (size_t i = 0; i < arraysize(requests); ++i) {
[email protected]bb88e1d32013-05-03 23:11:0710896 session_deps_.socket_factory->ResetNextMockIndexes();
10897 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]8c405132011-01-11 22:03:1810898 scoped_ptr<HttpNetworkTransaction> trans(
[email protected]90499482013-06-01 00:39:5010899 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]8c405132011-01-11 22:03:1810900
10901 // Begin the SSL handshake with the proxy.
[email protected]49639fa2011-12-20 23:22:4110902 TestCompletionCallback callback;
10903 int rv = trans->Start(
10904 &requests[i], callback.callback(), net::BoundNetLog());
[email protected]8c405132011-01-11 22:03:1810905 ASSERT_EQ(net::ERR_IO_PENDING, rv);
10906
10907 // Complete the SSL handshake, which should abort due to requiring a
10908 // client certificate.
10909 rv = callback.WaitForResult();
10910 ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv);
10911
10912 // Indicate that no certificate should be supplied. From the perspective
10913 // of SSLClientCertCache, NULL is just as meaningful as a real
10914 // certificate, so this is the same as supply a
10915 // legitimate-but-unacceptable certificate.
[email protected]49639fa2011-12-20 23:22:4110916 rv = trans->RestartWithCertificate(NULL, callback.callback());
[email protected]8c405132011-01-11 22:03:1810917 ASSERT_EQ(net::ERR_IO_PENDING, rv);
10918
10919 // Ensure the certificate was added to the client auth cache before
10920 // allowing the connection to continue restarting.
10921 scoped_refptr<X509Certificate> client_cert;
[email protected]791879c2013-12-17 07:22:4110922 ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup(
10923 HostPortPair("proxy", 70), &client_cert));
[email protected]8c405132011-01-11 22:03:1810924 ASSERT_EQ(NULL, client_cert.get());
10925 // Ensure the certificate was NOT cached for the endpoint. This only
10926 // applies to HTTPS requests, but is fine to check for HTTP requests.
[email protected]791879c2013-12-17 07:22:4110927 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup(
10928 HostPortPair("www.example.com", 443), &client_cert));
[email protected]8c405132011-01-11 22:03:1810929
10930 // Restart the handshake. This will consume ssl_data2, which fails, and
10931 // then consume ssl_data3, which should also fail. The result code is
10932 // checked against what ssl_data3 should return.
10933 rv = callback.WaitForResult();
10934 ASSERT_EQ(net::ERR_PROXY_CONNECTION_FAILED, rv);
10935
10936 // Now that the new handshake has failed, ensure that the client
10937 // certificate was removed from the client auth cache.
[email protected]791879c2013-12-17 07:22:4110938 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup(
10939 HostPortPair("proxy", 70), &client_cert));
10940 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup(
10941 HostPortPair("www.example.com", 443), &client_cert));
[email protected]8c405132011-01-11 22:03:1810942 }
10943}
10944
[email protected]23e482282013-06-14 16:08:0210945// Unlike TEST/TEST_F, which are macros that expand to further macros,
10946// TEST_P is a macro that expands directly to code that stringizes the
10947// arguments. As a result, macros passed as parameters (such as prefix
10948// or test_case_name) will not be expanded by the preprocessor. To
10949// work around this, indirect the macro for TEST_P, so that the
10950// pre-processor will expand macros such as MAYBE_test_name before
10951// instantiating the test.
10952#define WRAPPED_TEST_P(test_case_name, test_name) \
10953 TEST_P(test_case_name, test_name)
10954
[email protected]45b170822012-05-04 21:18:1410955// Times out on Win7 dbg(2) bot. http://crbug.com/124776
10956#if defined(OS_WIN)
10957#define MAYBE_UseIPConnectionPooling DISABLED_UseIPConnectionPooling
10958#else
10959#define MAYBE_UseIPConnectionPooling UseIPConnectionPooling
10960#endif
[email protected]23e482282013-06-14 16:08:0210961WRAPPED_TEST_P(HttpNetworkTransactionTest, MAYBE_UseIPConnectionPooling) {
[email protected]d7599122014-05-24 03:37:2310962 session_deps_.use_alternate_protocols = true;
10963 session_deps_.next_protos = SpdyNextProtos();
[email protected]e3ceb682011-06-28 23:55:4610964
10965 // Set up a special HttpNetworkSession with a MockCachingHostResolver.
[email protected]bb88e1d32013-05-03 23:11:0710966 session_deps_.host_resolver.reset(new MockCachingHostResolver());
10967 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]b9ec6882011-07-01 07:40:2610968 SpdySessionPoolPeer pool_peer(session->spdy_session_pool());
10969 pool_peer.DisableDomainAuthenticationVerification();
[email protected]e3ceb682011-06-28 23:55:4610970
[email protected]8ddf8322012-02-23 18:08:0610971 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0210972 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0710973 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]e3ceb682011-06-28 23:55:4610974
[email protected]cdf8f7e72013-05-23 10:56:4610975 scoped_ptr<SpdyFrame> host1_req(
10976 spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST));
10977 scoped_ptr<SpdyFrame> host2_req(
10978 spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST));
[email protected]e3ceb682011-06-28 23:55:4610979 MockWrite spdy_writes[] = {
10980 CreateMockWrite(*host1_req, 1),
10981 CreateMockWrite(*host2_req, 4),
10982 };
[email protected]23e482282013-06-14 16:08:0210983 scoped_ptr<SpdyFrame> host1_resp(
10984 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
10985 scoped_ptr<SpdyFrame> host1_resp_body(
10986 spdy_util_.ConstructSpdyBodyFrame(1, true));
10987 scoped_ptr<SpdyFrame> host2_resp(
10988 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
10989 scoped_ptr<SpdyFrame> host2_resp_body(
10990 spdy_util_.ConstructSpdyBodyFrame(3, true));
[email protected]e3ceb682011-06-28 23:55:4610991 MockRead spdy_reads[] = {
10992 CreateMockRead(*host1_resp, 2),
10993 CreateMockRead(*host1_resp_body, 3),
10994 CreateMockRead(*host2_resp, 5),
10995 CreateMockRead(*host2_resp_body, 6),
[email protected]8ddf8322012-02-23 18:08:0610996 MockRead(ASYNC, 0, 7),
[email protected]e3ceb682011-06-28 23:55:4610997 };
10998
[email protected]d2b5f092012-06-08 23:55:0210999 IPAddressNumber ip;
11000 ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip));
11001 IPEndPoint peer_addr = IPEndPoint(ip, 443);
11002 MockConnect connect(ASYNC, OK, peer_addr);
[email protected]dd54bd82012-07-19 23:44:5711003 OrderedSocketData spdy_data(
11004 connect,
11005 spdy_reads, arraysize(spdy_reads),
11006 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:0711007 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]e3ceb682011-06-28 23:55:4611008
[email protected]aa22b242011-11-16 18:58:2911009 TestCompletionCallback callback;
[email protected]e3ceb682011-06-28 23:55:4611010 HttpRequestInfo request1;
11011 request1.method = "GET";
11012 request1.url = GURL("https://www.google.com/");
11013 request1.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011014 HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get());
[email protected]e3ceb682011-06-28 23:55:4611015
[email protected]49639fa2011-12-20 23:22:4111016 int rv = trans1.Start(&request1, callback.callback(), BoundNetLog());
[email protected]e3ceb682011-06-28 23:55:4611017 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]49639fa2011-12-20 23:22:4111018 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]e3ceb682011-06-28 23:55:4611019
11020 const HttpResponseInfo* response = trans1.GetResponseInfo();
11021 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5011022 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]e3ceb682011-06-28 23:55:4611023 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
11024
11025 std::string response_data;
11026 ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data));
11027 EXPECT_EQ("hello!", response_data);
11028
11029 // Preload www.gmail.com into HostCache.
11030 HostPortPair host_port("www.gmail.com", 443);
[email protected]5109c1952013-08-20 18:44:1011031 HostResolver::RequestInfo resolve_info(host_port);
[email protected]e3ceb682011-06-28 23:55:4611032 AddressList ignored;
[email protected]5109c1952013-08-20 18:44:1011033 rv = session_deps_.host_resolver->Resolve(resolve_info,
11034 DEFAULT_PRIORITY,
11035 &ignored,
11036 callback.callback(),
11037 NULL,
11038 BoundNetLog());
[email protected]6e78dfb2011-07-28 21:34:4711039 EXPECT_EQ(ERR_IO_PENDING, rv);
11040 rv = callback.WaitForResult();
11041 EXPECT_EQ(OK, rv);
[email protected]e3ceb682011-06-28 23:55:4611042
11043 HttpRequestInfo request2;
11044 request2.method = "GET";
11045 request2.url = GURL("https://www.gmail.com/");
11046 request2.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011047 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get());
[email protected]e3ceb682011-06-28 23:55:4611048
[email protected]49639fa2011-12-20 23:22:4111049 rv = trans2.Start(&request2, callback.callback(), BoundNetLog());
[email protected]e3ceb682011-06-28 23:55:4611050 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]49639fa2011-12-20 23:22:4111051 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]e3ceb682011-06-28 23:55:4611052
11053 response = trans2.GetResponseInfo();
11054 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5011055 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]e3ceb682011-06-28 23:55:4611056 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
11057 EXPECT_TRUE(response->was_fetched_via_spdy);
11058 EXPECT_TRUE(response->was_npn_negotiated);
11059 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data));
11060 EXPECT_EQ("hello!", response_data);
[email protected]e3ceb682011-06-28 23:55:4611061}
[email protected]45b170822012-05-04 21:18:1411062#undef MAYBE_UseIPConnectionPooling
[email protected]e3ceb682011-06-28 23:55:4611063
[email protected]23e482282013-06-14 16:08:0211064TEST_P(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) {
[email protected]d7599122014-05-24 03:37:2311065 session_deps_.use_alternate_protocols = true;
11066 session_deps_.next_protos = SpdyNextProtos();
[email protected]d2b5f092012-06-08 23:55:0211067
11068 // Set up a special HttpNetworkSession with a MockCachingHostResolver.
[email protected]bb88e1d32013-05-03 23:11:0711069 session_deps_.host_resolver.reset(new MockCachingHostResolver());
11070 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]d2b5f092012-06-08 23:55:0211071 SpdySessionPoolPeer pool_peer(session->spdy_session_pool());
11072 pool_peer.DisableDomainAuthenticationVerification();
11073
11074 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0211075 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0711076 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]d2b5f092012-06-08 23:55:0211077
[email protected]cdf8f7e72013-05-23 10:56:4611078 scoped_ptr<SpdyFrame> host1_req(
11079 spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST));
11080 scoped_ptr<SpdyFrame> host2_req(
11081 spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST));
[email protected]d2b5f092012-06-08 23:55:0211082 MockWrite spdy_writes[] = {
11083 CreateMockWrite(*host1_req, 1),
11084 CreateMockWrite(*host2_req, 4),
11085 };
[email protected]23e482282013-06-14 16:08:0211086 scoped_ptr<SpdyFrame> host1_resp(
11087 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11088 scoped_ptr<SpdyFrame> host1_resp_body(
11089 spdy_util_.ConstructSpdyBodyFrame(1, true));
11090 scoped_ptr<SpdyFrame> host2_resp(
11091 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
11092 scoped_ptr<SpdyFrame> host2_resp_body(
11093 spdy_util_.ConstructSpdyBodyFrame(3, true));
[email protected]d2b5f092012-06-08 23:55:0211094 MockRead spdy_reads[] = {
11095 CreateMockRead(*host1_resp, 2),
11096 CreateMockRead(*host1_resp_body, 3),
11097 CreateMockRead(*host2_resp, 5),
11098 CreateMockRead(*host2_resp_body, 6),
11099 MockRead(ASYNC, 0, 7),
11100 };
11101
11102 IPAddressNumber ip;
11103 ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip));
11104 IPEndPoint peer_addr = IPEndPoint(ip, 443);
11105 MockConnect connect(ASYNC, OK, peer_addr);
[email protected]dd54bd82012-07-19 23:44:5711106 OrderedSocketData spdy_data(
11107 connect,
11108 spdy_reads, arraysize(spdy_reads),
11109 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:0711110 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]d2b5f092012-06-08 23:55:0211111
11112 TestCompletionCallback callback;
11113 HttpRequestInfo request1;
11114 request1.method = "GET";
11115 request1.url = GURL("https://www.google.com/");
11116 request1.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011117 HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get());
[email protected]d2b5f092012-06-08 23:55:0211118
11119 int rv = trans1.Start(&request1, callback.callback(), BoundNetLog());
11120 EXPECT_EQ(ERR_IO_PENDING, rv);
11121 EXPECT_EQ(OK, callback.WaitForResult());
11122
11123 const HttpResponseInfo* response = trans1.GetResponseInfo();
11124 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5011125 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]d2b5f092012-06-08 23:55:0211126 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
11127
11128 std::string response_data;
11129 ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data));
11130 EXPECT_EQ("hello!", response_data);
11131
11132 HttpRequestInfo request2;
11133 request2.method = "GET";
11134 request2.url = GURL("https://www.gmail.com/");
11135 request2.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011136 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get());
[email protected]d2b5f092012-06-08 23:55:0211137
11138 rv = trans2.Start(&request2, callback.callback(), BoundNetLog());
11139 EXPECT_EQ(ERR_IO_PENDING, rv);
11140 EXPECT_EQ(OK, callback.WaitForResult());
11141
11142 response = trans2.GetResponseInfo();
11143 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5011144 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]d2b5f092012-06-08 23:55:0211145 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
11146 EXPECT_TRUE(response->was_fetched_via_spdy);
11147 EXPECT_TRUE(response->was_npn_negotiated);
11148 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data));
11149 EXPECT_EQ("hello!", response_data);
[email protected]d2b5f092012-06-08 23:55:0211150}
11151
[email protected]e3ceb682011-06-28 23:55:4611152class OneTimeCachingHostResolver : public net::HostResolver {
11153 public:
11154 explicit OneTimeCachingHostResolver(const HostPortPair& host_port)
11155 : host_port_(host_port) {}
dchengb03027d2014-10-21 12:00:2011156 ~OneTimeCachingHostResolver() override {}
[email protected]e3ceb682011-06-28 23:55:4611157
11158 RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); }
11159
11160 // HostResolver methods:
dchengb03027d2014-10-21 12:00:2011161 int Resolve(const RequestInfo& info,
11162 RequestPriority priority,
11163 AddressList* addresses,
11164 const CompletionCallback& callback,
11165 RequestHandle* out_req,
11166 const BoundNetLog& net_log) override {
[email protected]95a214c2011-08-04 21:50:4011167 return host_resolver_.Resolve(
[email protected]5109c1952013-08-20 18:44:1011168 info, priority, addresses, callback, out_req, net_log);
[email protected]95a214c2011-08-04 21:50:4011169 }
11170
dchengb03027d2014-10-21 12:00:2011171 int ResolveFromCache(const RequestInfo& info,
11172 AddressList* addresses,
11173 const BoundNetLog& net_log) override {
[email protected]95a214c2011-08-04 21:50:4011174 int rv = host_resolver_.ResolveFromCache(info, addresses, net_log);
11175 if (rv == OK && info.host_port_pair().Equals(host_port_))
[email protected]98e1cd012011-11-08 15:33:0911176 host_resolver_.GetHostCache()->clear();
[email protected]e3ceb682011-06-28 23:55:4611177 return rv;
11178 }
11179
dchengb03027d2014-10-21 12:00:2011180 void CancelRequest(RequestHandle req) override {
[email protected]e3ceb682011-06-28 23:55:4611181 host_resolver_.CancelRequest(req);
11182 }
11183
[email protected]46da33be2011-07-19 21:58:0411184 MockCachingHostResolver* GetMockHostResolver() {
11185 return &host_resolver_;
11186 }
11187
[email protected]e3ceb682011-06-28 23:55:4611188 private:
11189 MockCachingHostResolver host_resolver_;
11190 const HostPortPair host_port_;
11191};
11192
[email protected]45b170822012-05-04 21:18:1411193// Times out on Win7 dbg(2) bot. http://crbug.com/124776
11194#if defined(OS_WIN)
[email protected]bb88e1d32013-05-03 23:11:0711195#define MAYBE_UseIPConnectionPoolingWithHostCacheExpiration \
11196 DISABLED_UseIPConnectionPoolingWithHostCacheExpiration
[email protected]45b170822012-05-04 21:18:1411197#else
[email protected]bb88e1d32013-05-03 23:11:0711198#define MAYBE_UseIPConnectionPoolingWithHostCacheExpiration \
11199 UseIPConnectionPoolingWithHostCacheExpiration
[email protected]45b170822012-05-04 21:18:1411200#endif
[email protected]23e482282013-06-14 16:08:0211201WRAPPED_TEST_P(HttpNetworkTransactionTest,
11202 MAYBE_UseIPConnectionPoolingWithHostCacheExpiration) {
[email protected]23e482282013-06-14 16:08:0211203// Times out on Win7 dbg(2) bot. http://crbug.com/124776 . (MAYBE_
11204// prefix doesn't work with parametrized tests).
11205#if defined(OS_WIN)
11206 return;
[email protected]88c7b4be2014-03-19 23:04:0111207#else
[email protected]d7599122014-05-24 03:37:2311208 session_deps_.use_alternate_protocols = true;
11209 session_deps_.next_protos = SpdyNextProtos();
[email protected]e3ceb682011-06-28 23:55:4611210
11211 // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver.
[email protected]e3ceb682011-06-28 23:55:4611212 OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443));
[email protected]c6bf8152012-12-02 07:43:3411213 HttpNetworkSession::Params params =
[email protected]bb88e1d32013-05-03 23:11:0711214 SpdySessionDependencies::CreateSessionParams(&session_deps_);
[email protected]e3ceb682011-06-28 23:55:4611215 params.host_resolver = &host_resolver;
[email protected]bb88e1d32013-05-03 23:11:0711216 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]b9ec6882011-07-01 07:40:2611217 SpdySessionPoolPeer pool_peer(session->spdy_session_pool());
11218 pool_peer.DisableDomainAuthenticationVerification();
[email protected]e3ceb682011-06-28 23:55:4611219
[email protected]8ddf8322012-02-23 18:08:0611220 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0211221 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0711222 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]e3ceb682011-06-28 23:55:4611223
[email protected]cdf8f7e72013-05-23 10:56:4611224 scoped_ptr<SpdyFrame> host1_req(
11225 spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST));
11226 scoped_ptr<SpdyFrame> host2_req(
11227 spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST));
[email protected]e3ceb682011-06-28 23:55:4611228 MockWrite spdy_writes[] = {
11229 CreateMockWrite(*host1_req, 1),
11230 CreateMockWrite(*host2_req, 4),
11231 };
[email protected]23e482282013-06-14 16:08:0211232 scoped_ptr<SpdyFrame> host1_resp(
11233 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11234 scoped_ptr<SpdyFrame> host1_resp_body(
11235 spdy_util_.ConstructSpdyBodyFrame(1, true));
11236 scoped_ptr<SpdyFrame> host2_resp(
11237 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
11238 scoped_ptr<SpdyFrame> host2_resp_body(
11239 spdy_util_.ConstructSpdyBodyFrame(3, true));
[email protected]e3ceb682011-06-28 23:55:4611240 MockRead spdy_reads[] = {
11241 CreateMockRead(*host1_resp, 2),
11242 CreateMockRead(*host1_resp_body, 3),
11243 CreateMockRead(*host2_resp, 5),
11244 CreateMockRead(*host2_resp_body, 6),
[email protected]8ddf8322012-02-23 18:08:0611245 MockRead(ASYNC, 0, 7),
[email protected]e3ceb682011-06-28 23:55:4611246 };
11247
[email protected]d2b5f092012-06-08 23:55:0211248 IPAddressNumber ip;
11249 ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip));
11250 IPEndPoint peer_addr = IPEndPoint(ip, 443);
11251 MockConnect connect(ASYNC, OK, peer_addr);
[email protected]dd54bd82012-07-19 23:44:5711252 OrderedSocketData spdy_data(
11253 connect,
11254 spdy_reads, arraysize(spdy_reads),
11255 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:0711256 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]e3ceb682011-06-28 23:55:4611257
[email protected]aa22b242011-11-16 18:58:2911258 TestCompletionCallback callback;
[email protected]e3ceb682011-06-28 23:55:4611259 HttpRequestInfo request1;
11260 request1.method = "GET";
11261 request1.url = GURL("https://www.google.com/");
11262 request1.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011263 HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get());
[email protected]e3ceb682011-06-28 23:55:4611264
[email protected]49639fa2011-12-20 23:22:4111265 int rv = trans1.Start(&request1, callback.callback(), BoundNetLog());
[email protected]e3ceb682011-06-28 23:55:4611266 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]49639fa2011-12-20 23:22:4111267 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]e3ceb682011-06-28 23:55:4611268
11269 const HttpResponseInfo* response = trans1.GetResponseInfo();
11270 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5011271 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]e3ceb682011-06-28 23:55:4611272 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
11273
11274 std::string response_data;
11275 ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data));
11276 EXPECT_EQ("hello!", response_data);
11277
11278 // Preload cache entries into HostCache.
[email protected]5109c1952013-08-20 18:44:1011279 HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443));
[email protected]e3ceb682011-06-28 23:55:4611280 AddressList ignored;
[email protected]5109c1952013-08-20 18:44:1011281 rv = host_resolver.Resolve(resolve_info,
11282 DEFAULT_PRIORITY,
11283 &ignored,
11284 callback.callback(),
11285 NULL,
11286 BoundNetLog());
[email protected]6e78dfb2011-07-28 21:34:4711287 EXPECT_EQ(ERR_IO_PENDING, rv);
11288 rv = callback.WaitForResult();
11289 EXPECT_EQ(OK, rv);
[email protected]e3ceb682011-06-28 23:55:4611290
11291 HttpRequestInfo request2;
11292 request2.method = "GET";
11293 request2.url = GURL("https://www.gmail.com/");
11294 request2.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011295 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get());
[email protected]e3ceb682011-06-28 23:55:4611296
[email protected]49639fa2011-12-20 23:22:4111297 rv = trans2.Start(&request2, callback.callback(), BoundNetLog());
[email protected]e3ceb682011-06-28 23:55:4611298 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]49639fa2011-12-20 23:22:4111299 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]e3ceb682011-06-28 23:55:4611300
11301 response = trans2.GetResponseInfo();
11302 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5011303 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]e3ceb682011-06-28 23:55:4611304 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
11305 EXPECT_TRUE(response->was_fetched_via_spdy);
11306 EXPECT_TRUE(response->was_npn_negotiated);
11307 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data));
11308 EXPECT_EQ("hello!", response_data);
[email protected]88c7b4be2014-03-19 23:04:0111309#endif
[email protected]e3ceb682011-06-28 23:55:4611310}
[email protected]45b170822012-05-04 21:18:1411311#undef MAYBE_UseIPConnectionPoolingWithHostCacheExpiration
[email protected]e3ceb682011-06-28 23:55:4611312
[email protected]23e482282013-06-14 16:08:0211313TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) {
[email protected]8450d722012-07-02 19:14:0411314 const std::string https_url = "https://www.google.com/";
11315 const std::string http_url = "http://www.google.com:443/";
11316
11317 // SPDY GET for HTTPS URL
[email protected]cdf8f7e72013-05-23 10:56:4611318 scoped_ptr<SpdyFrame> req1(
11319 spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST));
[email protected]8450d722012-07-02 19:14:0411320
11321 MockWrite writes1[] = {
11322 CreateMockWrite(*req1, 0),
11323 };
11324
[email protected]23e482282013-06-14 16:08:0211325 scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11326 scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]8450d722012-07-02 19:14:0411327 MockRead reads1[] = {
11328 CreateMockRead(*resp1, 1),
11329 CreateMockRead(*body1, 2),
11330 MockRead(ASYNC, ERR_IO_PENDING, 3)
11331 };
11332
[email protected]dd54bd82012-07-19 23:44:5711333 DelayedSocketData data1(
11334 1, reads1, arraysize(reads1),
11335 writes1, arraysize(writes1));
[email protected]8450d722012-07-02 19:14:0411336 MockConnect connect_data1(ASYNC, OK);
[email protected]dd54bd82012-07-19 23:44:5711337 data1.set_connect_data(connect_data1);
[email protected]8450d722012-07-02 19:14:0411338
11339 // HTTP GET for the HTTP URL
11340 MockWrite writes2[] = {
11341 MockWrite(ASYNC, 4,
11342 "GET / HTTP/1.1\r\n"
11343 "Host: www.google.com:443\r\n"
11344 "Connection: keep-alive\r\n\r\n"),
11345 };
11346
11347 MockRead reads2[] = {
11348 MockRead(ASYNC, 5, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"),
11349 MockRead(ASYNC, 6, "hello"),
11350 MockRead(ASYNC, 7, OK),
11351 };
11352
[email protected]dd54bd82012-07-19 23:44:5711353 DelayedSocketData data2(
11354 1, reads2, arraysize(reads2),
11355 writes2, arraysize(writes2));
[email protected]8450d722012-07-02 19:14:0411356
[email protected]8450d722012-07-02 19:14:0411357 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0211358 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0711359 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
11360 session_deps_.socket_factory->AddSocketDataProvider(&data1);
11361 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]8450d722012-07-02 19:14:0411362
[email protected]bb88e1d32013-05-03 23:11:0711363 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]8450d722012-07-02 19:14:0411364
11365 // Start the first transaction to set up the SpdySession
11366 HttpRequestInfo request1;
11367 request1.method = "GET";
11368 request1.url = GURL(https_url);
[email protected]8450d722012-07-02 19:14:0411369 request1.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011370 HttpNetworkTransaction trans1(LOWEST, session.get());
[email protected]8450d722012-07-02 19:14:0411371 TestCompletionCallback callback1;
11372 EXPECT_EQ(ERR_IO_PENDING,
11373 trans1.Start(&request1, callback1.callback(), BoundNetLog()));
[email protected]2da659e2013-05-23 20:51:3411374 base::MessageLoop::current()->RunUntilIdle();
[email protected]8450d722012-07-02 19:14:0411375
11376 EXPECT_EQ(OK, callback1.WaitForResult());
11377 EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy);
11378
11379 // Now, start the HTTP request
11380 HttpRequestInfo request2;
11381 request2.method = "GET";
11382 request2.url = GURL(http_url);
[email protected]8450d722012-07-02 19:14:0411383 request2.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011384 HttpNetworkTransaction trans2(MEDIUM, session.get());
[email protected]8450d722012-07-02 19:14:0411385 TestCompletionCallback callback2;
11386 EXPECT_EQ(ERR_IO_PENDING,
11387 trans2.Start(&request2, callback2.callback(), BoundNetLog()));
[email protected]2da659e2013-05-23 20:51:3411388 base::MessageLoop::current()->RunUntilIdle();
[email protected]8450d722012-07-02 19:14:0411389
11390 EXPECT_EQ(OK, callback2.WaitForResult());
11391 EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy);
11392}
11393
[email protected]23e482282013-06-14 16:08:0211394TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) {
[email protected]8450d722012-07-02 19:14:0411395 const std::string https_url = "https://www.google.com/";
11396 const std::string http_url = "http://www.google.com:443/";
11397
11398 // SPDY GET for HTTPS URL (through CONNECT tunnel)
[email protected]9075f51c2013-08-15 17:53:5411399 scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(NULL, 0, 1,
11400 LOWEST));
[email protected]cdf8f7e72013-05-23 10:56:4611401 scoped_ptr<SpdyFrame> req1(
11402 spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST));
[email protected]23e482282013-06-14 16:08:0211403 scoped_ptr<SpdyFrame> wrapped_req1(
11404 spdy_util_.ConstructWrappedSpdyFrame(req1, 1));
[email protected]601e03f12014-04-06 16:26:3911405
11406 // SPDY GET for HTTP URL (through the proxy, but not the tunnel).
[email protected]745aa9c2014-06-27 02:21:2911407 SpdyHeaderBlock req2_block;
11408 req2_block[spdy_util_.GetMethodKey()] = "GET";
bnc33b8cef42014-11-19 17:30:3811409 req2_block[spdy_util_.GetPathKey()] = "/";
[email protected]745aa9c2014-06-27 02:21:2911410 req2_block[spdy_util_.GetHostKey()] = "www.google.com:443";
11411 req2_block[spdy_util_.GetSchemeKey()] = "http";
11412 spdy_util_.MaybeAddVersionHeader(&req2_block);
[email protected]601e03f12014-04-06 16:26:3911413 scoped_ptr<SpdyFrame> req2(
[email protected]745aa9c2014-06-27 02:21:2911414 spdy_util_.ConstructSpdySyn(3, req2_block, MEDIUM, false, true));
[email protected]8450d722012-07-02 19:14:0411415
11416 MockWrite writes1[] = {
11417 CreateMockWrite(*connect, 0),
11418 CreateMockWrite(*wrapped_req1, 2),
11419 CreateMockWrite(*req2, 5),
11420 };
11421
[email protected]23e482282013-06-14 16:08:0211422 scoped_ptr<SpdyFrame> conn_resp(
11423 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11424 scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11425 scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true));
11426 scoped_ptr<SpdyFrame> wrapped_resp1(
11427 spdy_util_.ConstructWrappedSpdyFrame(resp1, 1));
11428 scoped_ptr<SpdyFrame> wrapped_body1(
11429 spdy_util_.ConstructWrappedSpdyFrame(body1, 1));
11430 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
11431 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true));
[email protected]8450d722012-07-02 19:14:0411432 MockRead reads1[] = {
11433 CreateMockRead(*conn_resp, 1),
11434 CreateMockRead(*wrapped_resp1, 3),
11435 CreateMockRead(*wrapped_body1, 4),
11436 CreateMockRead(*resp2, 6),
11437 CreateMockRead(*body2, 7),
11438 MockRead(ASYNC, ERR_IO_PENDING, 8)
11439 };
11440
[email protected]dd54bd82012-07-19 23:44:5711441 DeterministicSocketData data1(reads1, arraysize(reads1),
11442 writes1, arraysize(writes1));
[email protected]8450d722012-07-02 19:14:0411443 MockConnect connect_data1(ASYNC, OK);
[email protected]dd54bd82012-07-19 23:44:5711444 data1.set_connect_data(connect_data1);
[email protected]8450d722012-07-02 19:14:0411445
[email protected]bb88e1d32013-05-03 23:11:0711446 session_deps_.proxy_service.reset(
[email protected]f6c63db52013-02-02 00:35:2211447 ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"));
11448 CapturingNetLog log;
[email protected]bb88e1d32013-05-03 23:11:0711449 session_deps_.net_log = &log;
[email protected]8450d722012-07-02 19:14:0411450 SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy
[email protected]23e482282013-06-14 16:08:0211451 ssl1.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0711452 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1);
[email protected]8450d722012-07-02 19:14:0411453 SSLSocketDataProvider ssl2(ASYNC, OK); // to the server
[email protected]23e482282013-06-14 16:08:0211454 ssl2.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0711455 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2);
11456 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data1);
[email protected]8450d722012-07-02 19:14:0411457
11458 scoped_refptr<HttpNetworkSession> session(
[email protected]bb88e1d32013-05-03 23:11:0711459 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_));
[email protected]8450d722012-07-02 19:14:0411460
11461 // Start the first transaction to set up the SpdySession
11462 HttpRequestInfo request1;
11463 request1.method = "GET";
11464 request1.url = GURL(https_url);
[email protected]8450d722012-07-02 19:14:0411465 request1.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011466 HttpNetworkTransaction trans1(LOWEST, session.get());
[email protected]8450d722012-07-02 19:14:0411467 TestCompletionCallback callback1;
11468 EXPECT_EQ(ERR_IO_PENDING,
11469 trans1.Start(&request1, callback1.callback(), BoundNetLog()));
[email protected]2da659e2013-05-23 20:51:3411470 base::MessageLoop::current()->RunUntilIdle();
[email protected]dd54bd82012-07-19 23:44:5711471 data1.RunFor(4);
[email protected]8450d722012-07-02 19:14:0411472
11473 EXPECT_EQ(OK, callback1.WaitForResult());
11474 EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy);
11475
[email protected]f6c63db52013-02-02 00:35:2211476 LoadTimingInfo load_timing_info1;
11477 EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1));
11478 TestLoadTimingNotReusedWithPac(load_timing_info1,
11479 CONNECT_TIMING_HAS_SSL_TIMES);
11480
[email protected]8450d722012-07-02 19:14:0411481 // Now, start the HTTP request
11482 HttpRequestInfo request2;
11483 request2.method = "GET";
11484 request2.url = GURL(http_url);
[email protected]8450d722012-07-02 19:14:0411485 request2.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011486 HttpNetworkTransaction trans2(MEDIUM, session.get());
[email protected]8450d722012-07-02 19:14:0411487 TestCompletionCallback callback2;
11488 EXPECT_EQ(ERR_IO_PENDING,
11489 trans2.Start(&request2, callback2.callback(), BoundNetLog()));
[email protected]2da659e2013-05-23 20:51:3411490 base::MessageLoop::current()->RunUntilIdle();
[email protected]dd54bd82012-07-19 23:44:5711491 data1.RunFor(3);
[email protected]8450d722012-07-02 19:14:0411492
11493 EXPECT_EQ(OK, callback2.WaitForResult());
11494 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy);
[email protected]f6c63db52013-02-02 00:35:2211495
11496 LoadTimingInfo load_timing_info2;
11497 EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2));
11498 // The established SPDY sessions is considered reused by the HTTP request.
11499 TestLoadTimingReusedWithPac(load_timing_info2);
11500 // HTTP requests over a SPDY session should have a different connection
11501 // socket_log_id than requests over a tunnel.
11502 EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id);
[email protected]8450d722012-07-02 19:14:0411503}
11504
[email protected]23e482282013-06-14 16:08:0211505TEST_P(HttpNetworkTransactionTest, UseSpdySessionForHttpWhenForced) {
[email protected]d7599122014-05-24 03:37:2311506 session_deps_.force_spdy_always = true;
[email protected]8450d722012-07-02 19:14:0411507 const std::string https_url = "https://www.google.com/";
11508 const std::string http_url = "http://www.google.com:443/";
11509
11510 // SPDY GET for HTTPS URL
[email protected]cdf8f7e72013-05-23 10:56:4611511 scoped_ptr<SpdyFrame> req1(
11512 spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST));
[email protected]8450d722012-07-02 19:14:0411513 // SPDY GET for the HTTP URL
[email protected]cdf8f7e72013-05-23 10:56:4611514 scoped_ptr<SpdyFrame> req2(
11515 spdy_util_.ConstructSpdyGet(http_url.c_str(), false, 3, MEDIUM));
[email protected]8450d722012-07-02 19:14:0411516
11517 MockWrite writes[] = {
11518 CreateMockWrite(*req1, 1),
11519 CreateMockWrite(*req2, 4),
11520 };
11521
[email protected]23e482282013-06-14 16:08:0211522 scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11523 scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true));
11524 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
11525 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true));
[email protected]8450d722012-07-02 19:14:0411526 MockRead reads[] = {
11527 CreateMockRead(*resp1, 2),
11528 CreateMockRead(*body1, 3),
11529 CreateMockRead(*resp2, 5),
11530 CreateMockRead(*body2, 6),
11531 MockRead(ASYNC, ERR_IO_PENDING, 7)
11532 };
11533
[email protected]dd54bd82012-07-19 23:44:5711534 OrderedSocketData data(reads, arraysize(reads),
11535 writes, arraysize(writes));
[email protected]8450d722012-07-02 19:14:0411536
[email protected]8450d722012-07-02 19:14:0411537 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0211538 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0711539 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
11540 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]8450d722012-07-02 19:14:0411541
[email protected]bb88e1d32013-05-03 23:11:0711542 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]8450d722012-07-02 19:14:0411543
11544 // Start the first transaction to set up the SpdySession
11545 HttpRequestInfo request1;
11546 request1.method = "GET";
11547 request1.url = GURL(https_url);
[email protected]8450d722012-07-02 19:14:0411548 request1.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011549 HttpNetworkTransaction trans1(LOWEST, session.get());
[email protected]8450d722012-07-02 19:14:0411550 TestCompletionCallback callback1;
11551 EXPECT_EQ(ERR_IO_PENDING,
11552 trans1.Start(&request1, callback1.callback(), BoundNetLog()));
[email protected]2da659e2013-05-23 20:51:3411553 base::MessageLoop::current()->RunUntilIdle();
[email protected]8450d722012-07-02 19:14:0411554
11555 EXPECT_EQ(OK, callback1.WaitForResult());
11556 EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy);
11557
11558 // Now, start the HTTP request
11559 HttpRequestInfo request2;
11560 request2.method = "GET";
11561 request2.url = GURL(http_url);
[email protected]8450d722012-07-02 19:14:0411562 request2.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011563 HttpNetworkTransaction trans2(MEDIUM, session.get());
[email protected]8450d722012-07-02 19:14:0411564 TestCompletionCallback callback2;
11565 EXPECT_EQ(ERR_IO_PENDING,
11566 trans2.Start(&request2, callback2.callback(), BoundNetLog()));
[email protected]2da659e2013-05-23 20:51:3411567 base::MessageLoop::current()->RunUntilIdle();
[email protected]8450d722012-07-02 19:14:0411568
11569 EXPECT_EQ(OK, callback2.WaitForResult());
11570 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy);
11571}
11572
[email protected]2d88e7d2012-07-19 17:55:1711573// Test that in the case where we have a SPDY session to a SPDY proxy
11574// that we do not pool other origins that resolve to the same IP when
11575// the certificate does not match the new origin.
11576// http://crbug.com/134690
[email protected]23e482282013-06-14 16:08:0211577TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) {
[email protected]2d88e7d2012-07-19 17:55:1711578 const std::string url1 = "http://www.google.com/";
11579 const std::string url2 = "https://mail.google.com/";
11580 const std::string ip_addr = "1.2.3.4";
11581
11582 // SPDY GET for HTTP URL (through SPDY proxy)
[email protected]23e482282013-06-14 16:08:0211583 scoped_ptr<SpdyHeaderBlock> headers(
11584 spdy_util_.ConstructGetHeaderBlockForProxy("http://www.google.com/"));
[email protected]745aa9c2014-06-27 02:21:2911585 scoped_ptr<SpdyFrame> req1(
11586 spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true));
[email protected]2d88e7d2012-07-19 17:55:1711587
11588 MockWrite writes1[] = {
11589 CreateMockWrite(*req1, 0),
11590 };
11591
[email protected]23e482282013-06-14 16:08:0211592 scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11593 scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]2d88e7d2012-07-19 17:55:1711594 MockRead reads1[] = {
11595 CreateMockRead(*resp1, 1),
11596 CreateMockRead(*body1, 2),
11597 MockRead(ASYNC, OK, 3) // EOF
11598 };
11599
11600 scoped_ptr<DeterministicSocketData> data1(
11601 new DeterministicSocketData(reads1, arraysize(reads1),
11602 writes1, arraysize(writes1)));
11603 IPAddressNumber ip;
11604 ASSERT_TRUE(ParseIPLiteralToNumber(ip_addr, &ip));
11605 IPEndPoint peer_addr = IPEndPoint(ip, 443);
11606 MockConnect connect_data1(ASYNC, OK, peer_addr);
11607 data1->set_connect_data(connect_data1);
11608
11609 // SPDY GET for HTTPS URL (direct)
[email protected]cdf8f7e72013-05-23 10:56:4611610 scoped_ptr<SpdyFrame> req2(
11611 spdy_util_.ConstructSpdyGet(url2.c_str(), false, 1, MEDIUM));
[email protected]2d88e7d2012-07-19 17:55:1711612
11613 MockWrite writes2[] = {
11614 CreateMockWrite(*req2, 0),
11615 };
11616
[email protected]23e482282013-06-14 16:08:0211617 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11618 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]2d88e7d2012-07-19 17:55:1711619 MockRead reads2[] = {
11620 CreateMockRead(*resp2, 1),
11621 CreateMockRead(*body2, 2),
11622 MockRead(ASYNC, OK, 3) // EOF
11623 };
11624
11625 scoped_ptr<DeterministicSocketData> data2(
11626 new DeterministicSocketData(reads2, arraysize(reads2),
11627 writes2, arraysize(writes2)));
11628 MockConnect connect_data2(ASYNC, OK);
11629 data2->set_connect_data(connect_data2);
11630
11631 // Set up a proxy config that sends HTTP requests to a proxy, and
11632 // all others direct.
11633 ProxyConfig proxy_config;
11634 proxy_config.proxy_rules().ParseFromString("http=https://proxy:443");
11635 CapturingProxyResolver* capturing_proxy_resolver =
11636 new CapturingProxyResolver();
[email protected]bb88e1d32013-05-03 23:11:0711637 session_deps_.proxy_service.reset(new ProxyService(
[email protected]2d88e7d2012-07-19 17:55:1711638 new ProxyConfigServiceFixed(proxy_config), capturing_proxy_resolver,
11639 NULL));
11640
11641 // Load a valid cert. Note, that this does not need to
11642 // be valid for proxy because the MockSSLClientSocket does
11643 // not actually verify it. But SpdySession will use this
11644 // to see if it is valid for the new origin
[email protected]6cdfd7f2013-02-08 20:40:1511645 base::FilePath certs_dir = GetTestCertsDirectory();
[email protected]2d88e7d2012-07-19 17:55:1711646 scoped_refptr<X509Certificate> server_cert(
11647 ImportCertFromFile(certs_dir, "ok_cert.pem"));
dcheng48459ac22014-08-26 00:46:4111648 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get());
[email protected]2d88e7d2012-07-19 17:55:1711649
11650 SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy
[email protected]23e482282013-06-14 16:08:0211651 ssl1.SetNextProto(GetParam());
[email protected]2d88e7d2012-07-19 17:55:1711652 ssl1.cert = server_cert;
[email protected]bb88e1d32013-05-03 23:11:0711653 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1);
11654 session_deps_.deterministic_socket_factory->AddSocketDataProvider(
11655 data1.get());
[email protected]2d88e7d2012-07-19 17:55:1711656
11657 SSLSocketDataProvider ssl2(ASYNC, OK); // to the server
[email protected]23e482282013-06-14 16:08:0211658 ssl2.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0711659 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2);
11660 session_deps_.deterministic_socket_factory->AddSocketDataProvider(
11661 data2.get());
[email protected]2d88e7d2012-07-19 17:55:1711662
[email protected]bb88e1d32013-05-03 23:11:0711663 session_deps_.host_resolver.reset(new MockCachingHostResolver());
11664 session_deps_.host_resolver->rules()->AddRule("mail.google.com", ip_addr);
11665 session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr);
[email protected]2d88e7d2012-07-19 17:55:1711666
11667 scoped_refptr<HttpNetworkSession> session(
[email protected]bb88e1d32013-05-03 23:11:0711668 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_));
[email protected]2d88e7d2012-07-19 17:55:1711669
11670 // Start the first transaction to set up the SpdySession
11671 HttpRequestInfo request1;
11672 request1.method = "GET";
11673 request1.url = GURL(url1);
[email protected]2d88e7d2012-07-19 17:55:1711674 request1.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011675 HttpNetworkTransaction trans1(LOWEST, session.get());
[email protected]2d88e7d2012-07-19 17:55:1711676 TestCompletionCallback callback1;
11677 ASSERT_EQ(ERR_IO_PENDING,
11678 trans1.Start(&request1, callback1.callback(), BoundNetLog()));
11679 data1->RunFor(3);
11680
11681 ASSERT_TRUE(callback1.have_result());
11682 EXPECT_EQ(OK, callback1.WaitForResult());
11683 EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy);
11684
11685 // Now, start the HTTP request
11686 HttpRequestInfo request2;
11687 request2.method = "GET";
11688 request2.url = GURL(url2);
[email protected]2d88e7d2012-07-19 17:55:1711689 request2.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011690 HttpNetworkTransaction trans2(MEDIUM, session.get());
[email protected]2d88e7d2012-07-19 17:55:1711691 TestCompletionCallback callback2;
11692 EXPECT_EQ(ERR_IO_PENDING,
11693 trans2.Start(&request2, callback2.callback(), BoundNetLog()));
[email protected]2da659e2013-05-23 20:51:3411694 base::MessageLoop::current()->RunUntilIdle();
[email protected]2d88e7d2012-07-19 17:55:1711695 data2->RunFor(3);
11696
11697 ASSERT_TRUE(callback2.have_result());
11698 EXPECT_EQ(OK, callback2.WaitForResult());
11699 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy);
11700}
11701
[email protected]85f97342013-04-17 06:12:2411702// Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED
11703// error) in SPDY session, removes the socket from pool and closes the SPDY
11704// session. Verify that new url's from the same HttpNetworkSession (and a new
11705// SpdySession) do work. http://crbug.com/224701
[email protected]23e482282013-06-14 16:08:0211706TEST_P(HttpNetworkTransactionTest, ErrorSocketNotConnected) {
[email protected]85f97342013-04-17 06:12:2411707 const std::string https_url = "https://www.google.com/";
11708
11709 MockRead reads1[] = {
11710 MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0)
11711 };
11712
11713 scoped_ptr<DeterministicSocketData> data1(
11714 new DeterministicSocketData(reads1, arraysize(reads1), NULL, 0));
11715 data1->SetStop(1);
11716
[email protected]cdf8f7e72013-05-23 10:56:4611717 scoped_ptr<SpdyFrame> req2(
11718 spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, MEDIUM));
[email protected]85f97342013-04-17 06:12:2411719 MockWrite writes2[] = {
11720 CreateMockWrite(*req2, 0),
11721 };
11722
[email protected]23e482282013-06-14 16:08:0211723 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11724 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]85f97342013-04-17 06:12:2411725 MockRead reads2[] = {
11726 CreateMockRead(*resp2, 1),
11727 CreateMockRead(*body2, 2),
11728 MockRead(ASYNC, OK, 3) // EOF
11729 };
11730
11731 scoped_ptr<DeterministicSocketData> data2(
11732 new DeterministicSocketData(reads2, arraysize(reads2),
11733 writes2, arraysize(writes2)));
11734
[email protected]85f97342013-04-17 06:12:2411735 SSLSocketDataProvider ssl1(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0211736 ssl1.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0711737 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1);
11738 session_deps_.deterministic_socket_factory->AddSocketDataProvider(
11739 data1.get());
[email protected]85f97342013-04-17 06:12:2411740
11741 SSLSocketDataProvider ssl2(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0211742 ssl2.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0711743 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2);
11744 session_deps_.deterministic_socket_factory->AddSocketDataProvider(
11745 data2.get());
[email protected]85f97342013-04-17 06:12:2411746
11747 scoped_refptr<HttpNetworkSession> session(
[email protected]bb88e1d32013-05-03 23:11:0711748 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_));
[email protected]85f97342013-04-17 06:12:2411749
11750 // Start the first transaction to set up the SpdySession and verify that
11751 // connection was closed.
11752 HttpRequestInfo request1;
11753 request1.method = "GET";
11754 request1.url = GURL(https_url);
11755 request1.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011756 HttpNetworkTransaction trans1(MEDIUM, session.get());
[email protected]85f97342013-04-17 06:12:2411757 TestCompletionCallback callback1;
11758 EXPECT_EQ(ERR_IO_PENDING,
11759 trans1.Start(&request1, callback1.callback(), BoundNetLog()));
[email protected]2da659e2013-05-23 20:51:3411760 base::MessageLoop::current()->RunUntilIdle();
[email protected]85f97342013-04-17 06:12:2411761 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback1.WaitForResult());
11762
11763 // Now, start the second request and make sure it succeeds.
11764 HttpRequestInfo request2;
11765 request2.method = "GET";
11766 request2.url = GURL(https_url);
11767 request2.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011768 HttpNetworkTransaction trans2(MEDIUM, session.get());
[email protected]85f97342013-04-17 06:12:2411769 TestCompletionCallback callback2;
11770 EXPECT_EQ(ERR_IO_PENDING,
11771 trans2.Start(&request2, callback2.callback(), BoundNetLog()));
[email protected]2da659e2013-05-23 20:51:3411772 base::MessageLoop::current()->RunUntilIdle();
[email protected]85f97342013-04-17 06:12:2411773 data2->RunFor(3);
11774
11775 ASSERT_TRUE(callback2.have_result());
11776 EXPECT_EQ(OK, callback2.WaitForResult());
11777 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy);
11778}
11779
[email protected]23e482282013-06-14 16:08:0211780TEST_P(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) {
[email protected]d7599122014-05-24 03:37:2311781 session_deps_.next_protos = SpdyNextProtos();
[email protected]483fa202013-05-14 01:07:0311782 ClientSocketPoolManager::set_max_sockets_per_group(
11783 HttpNetworkSession::NORMAL_SOCKET_POOL, 1);
11784 ClientSocketPoolManager::set_max_sockets_per_pool(
11785 HttpNetworkSession::NORMAL_SOCKET_POOL, 1);
11786
11787 // Use two different hosts with different IPs so they don't get pooled.
11788 session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1");
11789 session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2");
11790 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
11791
11792 SSLSocketDataProvider ssl1(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0211793 ssl1.SetNextProto(GetParam());
[email protected]483fa202013-05-14 01:07:0311794 SSLSocketDataProvider ssl2(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0211795 ssl2.SetNextProto(GetParam());
[email protected]483fa202013-05-14 01:07:0311796 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1);
11797 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2);
11798
[email protected]cdf8f7e72013-05-23 10:56:4611799 scoped_ptr<SpdyFrame> host1_req(spdy_util_.ConstructSpdyGet(
[email protected]483fa202013-05-14 01:07:0311800 "https://www.a.com", false, 1, DEFAULT_PRIORITY));
11801 MockWrite spdy1_writes[] = {
11802 CreateMockWrite(*host1_req, 1),
11803 };
[email protected]23e482282013-06-14 16:08:0211804 scoped_ptr<SpdyFrame> host1_resp(
11805 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11806 scoped_ptr<SpdyFrame> host1_resp_body(
11807 spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]483fa202013-05-14 01:07:0311808 MockRead spdy1_reads[] = {
11809 CreateMockRead(*host1_resp, 2),
11810 CreateMockRead(*host1_resp_body, 3),
11811 MockRead(ASYNC, ERR_IO_PENDING, 4),
11812 };
11813
11814 scoped_ptr<OrderedSocketData> spdy1_data(
11815 new OrderedSocketData(
11816 spdy1_reads, arraysize(spdy1_reads),
11817 spdy1_writes, arraysize(spdy1_writes)));
11818 session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get());
11819
[email protected]cdf8f7e72013-05-23 10:56:4611820 scoped_ptr<SpdyFrame> host2_req(spdy_util_.ConstructSpdyGet(
[email protected]483fa202013-05-14 01:07:0311821 "https://www.b.com", false, 1, DEFAULT_PRIORITY));
11822 MockWrite spdy2_writes[] = {
11823 CreateMockWrite(*host2_req, 1),
11824 };
[email protected]23e482282013-06-14 16:08:0211825 scoped_ptr<SpdyFrame> host2_resp(
11826 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11827 scoped_ptr<SpdyFrame> host2_resp_body(
11828 spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]483fa202013-05-14 01:07:0311829 MockRead spdy2_reads[] = {
11830 CreateMockRead(*host2_resp, 2),
11831 CreateMockRead(*host2_resp_body, 3),
11832 MockRead(ASYNC, ERR_IO_PENDING, 4),
11833 };
11834
11835 scoped_ptr<OrderedSocketData> spdy2_data(
11836 new OrderedSocketData(
11837 spdy2_reads, arraysize(spdy2_reads),
11838 spdy2_writes, arraysize(spdy2_writes)));
11839 session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get());
11840
11841 MockWrite http_write[] = {
11842 MockWrite("GET / HTTP/1.1\r\n"
11843 "Host: www.a.com\r\n"
11844 "Connection: keep-alive\r\n\r\n"),
11845 };
11846
11847 MockRead http_read[] = {
11848 MockRead("HTTP/1.1 200 OK\r\n"),
11849 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
11850 MockRead("Content-Length: 6\r\n\r\n"),
11851 MockRead("hello!"),
11852 };
11853 StaticSocketDataProvider http_data(http_read, arraysize(http_read),
11854 http_write, arraysize(http_write));
11855 session_deps_.socket_factory->AddSocketDataProvider(&http_data);
11856
11857 HostPortPair host_port_pair_a("www.a.com", 443);
[email protected]e6d017652013-05-17 18:01:4011858 SpdySessionKey spdy_session_key_a(
[email protected]314b03992014-04-01 01:28:5311859 host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED);
[email protected]483fa202013-05-14 01:07:0311860 EXPECT_FALSE(
[email protected]41d64e82013-07-03 22:44:2611861 HasSpdySession(session->spdy_session_pool(), spdy_session_key_a));
[email protected]483fa202013-05-14 01:07:0311862
11863 TestCompletionCallback callback;
11864 HttpRequestInfo request1;
11865 request1.method = "GET";
11866 request1.url = GURL("https://www.a.com/");
11867 request1.load_flags = 0;
11868 scoped_ptr<HttpNetworkTransaction> trans(
[email protected]90499482013-06-01 00:39:5011869 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]483fa202013-05-14 01:07:0311870
11871 int rv = trans->Start(&request1, callback.callback(), BoundNetLog());
11872 EXPECT_EQ(ERR_IO_PENDING, rv);
11873 EXPECT_EQ(OK, callback.WaitForResult());
11874
11875 const HttpResponseInfo* response = trans->GetResponseInfo();
11876 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5011877 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]483fa202013-05-14 01:07:0311878 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
11879 EXPECT_TRUE(response->was_fetched_via_spdy);
11880 EXPECT_TRUE(response->was_npn_negotiated);
11881
11882 std::string response_data;
11883 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
11884 EXPECT_EQ("hello!", response_data);
11885 trans.reset();
11886 EXPECT_TRUE(
[email protected]41d64e82013-07-03 22:44:2611887 HasSpdySession(session->spdy_session_pool(), spdy_session_key_a));
[email protected]483fa202013-05-14 01:07:0311888
11889 HostPortPair host_port_pair_b("www.b.com", 443);
[email protected]e6d017652013-05-17 18:01:4011890 SpdySessionKey spdy_session_key_b(
[email protected]314b03992014-04-01 01:28:5311891 host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED);
[email protected]483fa202013-05-14 01:07:0311892 EXPECT_FALSE(
[email protected]41d64e82013-07-03 22:44:2611893 HasSpdySession(session->spdy_session_pool(), spdy_session_key_b));
[email protected]483fa202013-05-14 01:07:0311894 HttpRequestInfo request2;
11895 request2.method = "GET";
11896 request2.url = GURL("https://www.b.com/");
11897 request2.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011898 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]483fa202013-05-14 01:07:0311899
11900 rv = trans->Start(&request2, callback.callback(), BoundNetLog());
11901 EXPECT_EQ(ERR_IO_PENDING, rv);
11902 EXPECT_EQ(OK, callback.WaitForResult());
11903
11904 response = trans->GetResponseInfo();
11905 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5011906 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]483fa202013-05-14 01:07:0311907 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
11908 EXPECT_TRUE(response->was_fetched_via_spdy);
11909 EXPECT_TRUE(response->was_npn_negotiated);
11910 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
11911 EXPECT_EQ("hello!", response_data);
11912 EXPECT_FALSE(
[email protected]41d64e82013-07-03 22:44:2611913 HasSpdySession(session->spdy_session_pool(), spdy_session_key_a));
[email protected]483fa202013-05-14 01:07:0311914 EXPECT_TRUE(
[email protected]41d64e82013-07-03 22:44:2611915 HasSpdySession(session->spdy_session_pool(), spdy_session_key_b));
[email protected]483fa202013-05-14 01:07:0311916
11917 HostPortPair host_port_pair_a1("www.a.com", 80);
[email protected]e6d017652013-05-17 18:01:4011918 SpdySessionKey spdy_session_key_a1(
[email protected]314b03992014-04-01 01:28:5311919 host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED);
[email protected]483fa202013-05-14 01:07:0311920 EXPECT_FALSE(
[email protected]41d64e82013-07-03 22:44:2611921 HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1));
[email protected]483fa202013-05-14 01:07:0311922 HttpRequestInfo request3;
11923 request3.method = "GET";
11924 request3.url = GURL("http://www.a.com/");
11925 request3.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011926 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]483fa202013-05-14 01:07:0311927
11928 rv = trans->Start(&request3, callback.callback(), BoundNetLog());
11929 EXPECT_EQ(ERR_IO_PENDING, rv);
11930 EXPECT_EQ(OK, callback.WaitForResult());
11931
11932 response = trans->GetResponseInfo();
11933 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5011934 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]483fa202013-05-14 01:07:0311935 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
11936 EXPECT_FALSE(response->was_fetched_via_spdy);
11937 EXPECT_FALSE(response->was_npn_negotiated);
11938 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
11939 EXPECT_EQ("hello!", response_data);
11940 EXPECT_FALSE(
[email protected]41d64e82013-07-03 22:44:2611941 HasSpdySession(session->spdy_session_pool(), spdy_session_key_a));
[email protected]483fa202013-05-14 01:07:0311942 EXPECT_FALSE(
[email protected]41d64e82013-07-03 22:44:2611943 HasSpdySession(session->spdy_session_pool(), spdy_session_key_b));
[email protected]483fa202013-05-14 01:07:0311944}
11945
[email protected]79e1fd62013-06-20 06:50:0411946TEST_P(HttpNetworkTransactionTest, HttpSyncConnectError) {
11947 HttpRequestInfo request;
11948 request.method = "GET";
11949 request.url = GURL("http://www.google.com/");
11950 request.load_flags = 0;
11951
[email protected]3fe8d2f82013-10-17 08:56:0711952 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]79e1fd62013-06-20 06:50:0411953 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4111954 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]79e1fd62013-06-20 06:50:0411955
11956 MockConnect mock_connect(SYNCHRONOUS, ERR_CONNECTION_REFUSED);
11957 StaticSocketDataProvider data;
11958 data.set_connect_data(mock_connect);
11959 session_deps_.socket_factory->AddSocketDataProvider(&data);
11960
11961 TestCompletionCallback callback;
11962
11963 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
11964 EXPECT_EQ(ERR_IO_PENDING, rv);
11965
11966 rv = callback.WaitForResult();
11967 EXPECT_EQ(ERR_CONNECTION_REFUSED, rv);
11968
11969 EXPECT_EQ(NULL, trans->GetResponseInfo());
11970
11971 // We don't care whether this succeeds or fails, but it shouldn't crash.
11972 HttpRequestHeaders request_headers;
11973 trans->GetFullRequestHeaders(&request_headers);
11974}
11975
11976TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) {
11977 HttpRequestInfo request;
11978 request.method = "GET";
11979 request.url = GURL("http://www.google.com/");
11980 request.load_flags = 0;
11981
[email protected]3fe8d2f82013-10-17 08:56:0711982 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]79e1fd62013-06-20 06:50:0411983 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4111984 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]79e1fd62013-06-20 06:50:0411985
11986 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED);
11987 StaticSocketDataProvider data;
11988 data.set_connect_data(mock_connect);
11989 session_deps_.socket_factory->AddSocketDataProvider(&data);
11990
11991 TestCompletionCallback callback;
11992
11993 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
11994 EXPECT_EQ(ERR_IO_PENDING, rv);
11995
11996 rv = callback.WaitForResult();
11997 EXPECT_EQ(ERR_CONNECTION_REFUSED, rv);
11998
11999 EXPECT_EQ(NULL, trans->GetResponseInfo());
12000
12001 // We don't care whether this succeeds or fails, but it shouldn't crash.
12002 HttpRequestHeaders request_headers;
12003 trans->GetFullRequestHeaders(&request_headers);
12004}
12005
12006TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) {
12007 HttpRequestInfo request;
12008 request.method = "GET";
12009 request.url = GURL("http://www.google.com/");
12010 request.load_flags = 0;
12011
[email protected]3fe8d2f82013-10-17 08:56:0712012 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]79e1fd62013-06-20 06:50:0412013 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4112014 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]79e1fd62013-06-20 06:50:0412015
12016 MockWrite data_writes[] = {
12017 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
12018 };
12019 MockRead data_reads[] = {
12020 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached.
12021 };
12022
12023 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
12024 data_writes, arraysize(data_writes));
12025 session_deps_.socket_factory->AddSocketDataProvider(&data);
12026
12027 TestCompletionCallback callback;
12028
12029 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
12030 EXPECT_EQ(ERR_IO_PENDING, rv);
12031
12032 rv = callback.WaitForResult();
12033 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
12034
12035 EXPECT_EQ(NULL, trans->GetResponseInfo());
12036
12037 HttpRequestHeaders request_headers;
12038 EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers));
12039 EXPECT_TRUE(request_headers.HasHeader("Host"));
12040}
12041
12042TEST_P(HttpNetworkTransactionTest, HttpAsyncWriteError) {
12043 HttpRequestInfo request;
12044 request.method = "GET";
12045 request.url = GURL("http://www.google.com/");
12046 request.load_flags = 0;
12047
[email protected]3fe8d2f82013-10-17 08:56:0712048 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]79e1fd62013-06-20 06:50:0412049 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4112050 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]79e1fd62013-06-20 06:50:0412051
12052 MockWrite data_writes[] = {
12053 MockWrite(ASYNC, ERR_CONNECTION_RESET),
12054 };
12055 MockRead data_reads[] = {
12056 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached.
12057 };
12058
12059 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
12060 data_writes, arraysize(data_writes));
12061 session_deps_.socket_factory->AddSocketDataProvider(&data);
12062
12063 TestCompletionCallback callback;
12064
12065 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
12066 EXPECT_EQ(ERR_IO_PENDING, rv);
12067
12068 rv = callback.WaitForResult();
12069 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
12070
12071 EXPECT_EQ(NULL, trans->GetResponseInfo());
12072
12073 HttpRequestHeaders request_headers;
12074 EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers));
12075 EXPECT_TRUE(request_headers.HasHeader("Host"));
12076}
12077
12078TEST_P(HttpNetworkTransactionTest, HttpSyncReadError) {
12079 HttpRequestInfo request;
12080 request.method = "GET";
12081 request.url = GURL("http://www.google.com/");
12082 request.load_flags = 0;
12083
[email protected]3fe8d2f82013-10-17 08:56:0712084 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]79e1fd62013-06-20 06:50:0412085 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4112086 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]79e1fd62013-06-20 06:50:0412087
12088 MockWrite data_writes[] = {
12089 MockWrite("GET / HTTP/1.1\r\n"
12090 "Host: www.google.com\r\n"
12091 "Connection: keep-alive\r\n\r\n"),
12092 };
12093 MockRead data_reads[] = {
12094 MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET),
12095 };
12096
12097 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
12098 data_writes, arraysize(data_writes));
12099 session_deps_.socket_factory->AddSocketDataProvider(&data);
12100
12101 TestCompletionCallback callback;
12102
12103 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
12104 EXPECT_EQ(ERR_IO_PENDING, rv);
12105
12106 rv = callback.WaitForResult();
12107 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
12108
12109 EXPECT_EQ(NULL, trans->GetResponseInfo());
12110
12111 HttpRequestHeaders request_headers;
12112 EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers));
12113 EXPECT_TRUE(request_headers.HasHeader("Host"));
12114}
12115
12116TEST_P(HttpNetworkTransactionTest, HttpAsyncReadError) {
12117 HttpRequestInfo request;
12118 request.method = "GET";
12119 request.url = GURL("http://www.google.com/");
12120 request.load_flags = 0;
12121
[email protected]3fe8d2f82013-10-17 08:56:0712122 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]79e1fd62013-06-20 06:50:0412123 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4112124 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]79e1fd62013-06-20 06:50:0412125
12126 MockWrite data_writes[] = {
12127 MockWrite("GET / HTTP/1.1\r\n"
12128 "Host: www.google.com\r\n"
12129 "Connection: keep-alive\r\n\r\n"),
12130 };
12131 MockRead data_reads[] = {
12132 MockRead(ASYNC, ERR_CONNECTION_RESET),
12133 };
12134
12135 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
12136 data_writes, arraysize(data_writes));
12137 session_deps_.socket_factory->AddSocketDataProvider(&data);
12138
12139 TestCompletionCallback callback;
12140
12141 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
12142 EXPECT_EQ(ERR_IO_PENDING, rv);
12143
12144 rv = callback.WaitForResult();
12145 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
12146
12147 EXPECT_EQ(NULL, trans->GetResponseInfo());
12148
12149 HttpRequestHeaders request_headers;
12150 EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers));
12151 EXPECT_TRUE(request_headers.HasHeader("Host"));
12152}
12153
12154TEST_P(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) {
12155 HttpRequestInfo request;
12156 request.method = "GET";
12157 request.url = GURL("http://www.google.com/");
12158 request.load_flags = 0;
12159 request.extra_headers.SetHeader("X-Foo", "bar");
12160
[email protected]3fe8d2f82013-10-17 08:56:0712161 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]79e1fd62013-06-20 06:50:0412162 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4112163 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]79e1fd62013-06-20 06:50:0412164
12165 MockWrite data_writes[] = {
12166 MockWrite("GET / HTTP/1.1\r\n"
12167 "Host: www.google.com\r\n"
12168 "Connection: keep-alive\r\n"
12169 "X-Foo: bar\r\n\r\n"),
12170 };
12171 MockRead data_reads[] = {
12172 MockRead("HTTP/1.1 200 OK\r\n"
12173 "Content-Length: 5\r\n\r\n"
12174 "hello"),
12175 MockRead(ASYNC, ERR_UNEXPECTED),
12176 };
12177
12178 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
12179 data_writes, arraysize(data_writes));
12180 session_deps_.socket_factory->AddSocketDataProvider(&data);
12181
12182 TestCompletionCallback callback;
12183
12184 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
12185 EXPECT_EQ(ERR_IO_PENDING, rv);
12186
12187 rv = callback.WaitForResult();
12188 EXPECT_EQ(OK, rv);
12189
12190 HttpRequestHeaders request_headers;
12191 EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers));
12192 std::string foo;
12193 EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo));
12194 EXPECT_EQ("bar", foo);
12195}
12196
[email protected]bf828982013-08-14 18:01:4712197namespace {
12198
yhiranoa7e05bb2014-11-06 05:40:3912199// Fake HttpStream that simply records calls to SetPriority().
12200class FakeStream : public HttpStream,
[email protected]e86839fd2013-08-14 18:29:0312201 public base::SupportsWeakPtr<FakeStream> {
12202 public:
12203 explicit FakeStream(RequestPriority priority) : priority_(priority) {}
dchengb03027d2014-10-21 12:00:2012204 ~FakeStream() override {}
[email protected]e86839fd2013-08-14 18:29:0312205
12206 RequestPriority priority() const { return priority_; }
12207
dchengb03027d2014-10-21 12:00:2012208 int InitializeStream(const HttpRequestInfo* request_info,
12209 RequestPriority priority,
12210 const BoundNetLog& net_log,
12211 const CompletionCallback& callback) override {
[email protected]e86839fd2013-08-14 18:29:0312212 return ERR_IO_PENDING;
12213 }
12214
dchengb03027d2014-10-21 12:00:2012215 int SendRequest(const HttpRequestHeaders& request_headers,
12216 HttpResponseInfo* response,
12217 const CompletionCallback& callback) override {
[email protected]e86839fd2013-08-14 18:29:0312218 ADD_FAILURE();
12219 return ERR_UNEXPECTED;
12220 }
12221
dchengb03027d2014-10-21 12:00:2012222 int ReadResponseHeaders(const CompletionCallback& callback) override {
[email protected]e86839fd2013-08-14 18:29:0312223 ADD_FAILURE();
12224 return ERR_UNEXPECTED;
12225 }
12226
dchengb03027d2014-10-21 12:00:2012227 int ReadResponseBody(IOBuffer* buf,
12228 int buf_len,
12229 const CompletionCallback& callback) override {
[email protected]e86839fd2013-08-14 18:29:0312230 ADD_FAILURE();
12231 return ERR_UNEXPECTED;
12232 }
12233
dchengb03027d2014-10-21 12:00:2012234 void Close(bool not_reusable) override {}
[email protected]e86839fd2013-08-14 18:29:0312235
dchengb03027d2014-10-21 12:00:2012236 bool IsResponseBodyComplete() const override {
[email protected]e86839fd2013-08-14 18:29:0312237 ADD_FAILURE();
12238 return false;
12239 }
12240
dchengb03027d2014-10-21 12:00:2012241 bool CanFindEndOfResponse() const override { return false; }
[email protected]e86839fd2013-08-14 18:29:0312242
dchengb03027d2014-10-21 12:00:2012243 bool IsConnectionReused() const override {
[email protected]e86839fd2013-08-14 18:29:0312244 ADD_FAILURE();
12245 return false;
12246 }
12247
dchengb03027d2014-10-21 12:00:2012248 void SetConnectionReused() override { ADD_FAILURE(); }
[email protected]e86839fd2013-08-14 18:29:0312249
dchengb03027d2014-10-21 12:00:2012250 bool IsConnectionReusable() const override {
[email protected]e86839fd2013-08-14 18:29:0312251 ADD_FAILURE();
12252 return false;
12253 }
12254
dchengb03027d2014-10-21 12:00:2012255 int64 GetTotalReceivedBytes() const override {
[email protected]bc92bc972013-12-13 08:32:5912256 ADD_FAILURE();
12257 return 0;
12258 }
12259
dchengb03027d2014-10-21 12:00:2012260 bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override {
[email protected]e86839fd2013-08-14 18:29:0312261 ADD_FAILURE();
12262 return false;
12263 }
12264
dchengb03027d2014-10-21 12:00:2012265 void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); }
12266
12267 void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override {
[email protected]e86839fd2013-08-14 18:29:0312268 ADD_FAILURE();
12269 }
12270
dchengb03027d2014-10-21 12:00:2012271 bool IsSpdyHttpStream() const override {
[email protected]e86839fd2013-08-14 18:29:0312272 ADD_FAILURE();
12273 return false;
12274 }
12275
dchengb03027d2014-10-21 12:00:2012276 void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); }
[email protected]e86839fd2013-08-14 18:29:0312277
dchengb03027d2014-10-21 12:00:2012278 void SetPriority(RequestPriority priority) override { priority_ = priority; }
[email protected]e86839fd2013-08-14 18:29:0312279
yhiranoa7e05bb2014-11-06 05:40:3912280 UploadProgress GetUploadProgress() const override { return UploadProgress(); }
12281
12282 HttpStream* RenewStreamForAuth() override { return NULL; }
12283
[email protected]e86839fd2013-08-14 18:29:0312284 private:
12285 RequestPriority priority_;
12286
12287 DISALLOW_COPY_AND_ASSIGN(FakeStream);
12288};
12289
12290// Fake HttpStreamRequest that simply records calls to SetPriority()
12291// and vends FakeStreams with its current priority.
[email protected]bf828982013-08-14 18:01:4712292class FakeStreamRequest : public HttpStreamRequest,
12293 public base::SupportsWeakPtr<FakeStreamRequest> {
12294 public:
[email protected]e86839fd2013-08-14 18:29:0312295 FakeStreamRequest(RequestPriority priority,
12296 HttpStreamRequest::Delegate* delegate)
12297 : priority_(priority),
[email protected]831e4a32013-11-14 02:14:4412298 delegate_(delegate),
12299 websocket_stream_create_helper_(NULL) {}
12300
12301 FakeStreamRequest(RequestPriority priority,
12302 HttpStreamRequest::Delegate* delegate,
12303 WebSocketHandshakeStreamBase::CreateHelper* create_helper)
12304 : priority_(priority),
12305 delegate_(delegate),
12306 websocket_stream_create_helper_(create_helper) {}
[email protected]e86839fd2013-08-14 18:29:0312307
dchengb03027d2014-10-21 12:00:2012308 ~FakeStreamRequest() override {}
[email protected]bf828982013-08-14 18:01:4712309
12310 RequestPriority priority() const { return priority_; }
12311
[email protected]831e4a32013-11-14 02:14:4412312 const WebSocketHandshakeStreamBase::CreateHelper*
12313 websocket_stream_create_helper() const {
12314 return websocket_stream_create_helper_;
12315 }
12316
[email protected]e86839fd2013-08-14 18:29:0312317 // Create a new FakeStream and pass it to the request's
12318 // delegate. Returns a weak pointer to the FakeStream.
12319 base::WeakPtr<FakeStream> FinishStreamRequest() {
12320 FakeStream* fake_stream = new FakeStream(priority_);
12321 // Do this before calling OnStreamReady() as OnStreamReady() may
12322 // immediately delete |fake_stream|.
12323 base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr();
12324 delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream);
12325 return weak_stream;
12326 }
12327
dchengb03027d2014-10-21 12:00:2012328 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override {
[email protected]bf828982013-08-14 18:01:4712329 ADD_FAILURE();
12330 return ERR_UNEXPECTED;
12331 }
12332
dchengb03027d2014-10-21 12:00:2012333 LoadState GetLoadState() const override {
[email protected]bf828982013-08-14 18:01:4712334 ADD_FAILURE();
12335 return LoadState();
12336 }
12337
dchengb03027d2014-10-21 12:00:2012338 void SetPriority(RequestPriority priority) override { priority_ = priority; }
[email protected]bf828982013-08-14 18:01:4712339
dchengb03027d2014-10-21 12:00:2012340 bool was_npn_negotiated() const override { return false; }
[email protected]bf828982013-08-14 18:01:4712341
dchengb03027d2014-10-21 12:00:2012342 NextProto protocol_negotiated() const override { return kProtoUnknown; }
[email protected]bf828982013-08-14 18:01:4712343
dchengb03027d2014-10-21 12:00:2012344 bool using_spdy() const override { return false; }
[email protected]bf828982013-08-14 18:01:4712345
12346 private:
12347 RequestPriority priority_;
[email protected]e86839fd2013-08-14 18:29:0312348 HttpStreamRequest::Delegate* const delegate_;
[email protected]831e4a32013-11-14 02:14:4412349 WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_;
[email protected]bf828982013-08-14 18:01:4712350
12351 DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest);
12352};
12353
12354// Fake HttpStreamFactory that vends FakeStreamRequests.
12355class FakeStreamFactory : public HttpStreamFactory {
12356 public:
12357 FakeStreamFactory() {}
dchengb03027d2014-10-21 12:00:2012358 ~FakeStreamFactory() override {}
[email protected]bf828982013-08-14 18:01:4712359
12360 // Returns a WeakPtr<> to the last HttpStreamRequest returned by
12361 // RequestStream() (which may be NULL if it was destroyed already).
12362 base::WeakPtr<FakeStreamRequest> last_stream_request() {
12363 return last_stream_request_;
12364 }
12365
dchengb03027d2014-10-21 12:00:2012366 HttpStreamRequest* RequestStream(const HttpRequestInfo& info,
12367 RequestPriority priority,
12368 const SSLConfig& server_ssl_config,
12369 const SSLConfig& proxy_ssl_config,
12370 HttpStreamRequest::Delegate* delegate,
12371 const BoundNetLog& net_log) override {
[email protected]e86839fd2013-08-14 18:29:0312372 FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate);
[email protected]bf828982013-08-14 18:01:4712373 last_stream_request_ = fake_request->AsWeakPtr();
12374 return fake_request;
12375 }
12376
dchengb03027d2014-10-21 12:00:2012377 HttpStreamRequest* RequestWebSocketHandshakeStream(
[email protected]bf828982013-08-14 18:01:4712378 const HttpRequestInfo& info,
12379 RequestPriority priority,
12380 const SSLConfig& server_ssl_config,
12381 const SSLConfig& proxy_ssl_config,
12382 HttpStreamRequest::Delegate* delegate,
[email protected]467086b2013-11-12 08:19:4612383 WebSocketHandshakeStreamBase::CreateHelper* create_helper,
mostynbba063d6032014-10-09 11:01:1312384 const BoundNetLog& net_log) override {
[email protected]831e4a32013-11-14 02:14:4412385 FakeStreamRequest* fake_request =
12386 new FakeStreamRequest(priority, delegate, create_helper);
12387 last_stream_request_ = fake_request->AsWeakPtr();
12388 return fake_request;
[email protected]bf828982013-08-14 18:01:4712389 }
12390
dchengb03027d2014-10-21 12:00:2012391 void PreconnectStreams(int num_streams,
12392 const HttpRequestInfo& info,
12393 RequestPriority priority,
12394 const SSLConfig& server_ssl_config,
12395 const SSLConfig& proxy_ssl_config) override {
[email protected]bf828982013-08-14 18:01:4712396 ADD_FAILURE();
12397 }
12398
dchengb03027d2014-10-21 12:00:2012399 const HostMappingRules* GetHostMappingRules() const override {
[email protected]bf828982013-08-14 18:01:4712400 ADD_FAILURE();
12401 return NULL;
12402 }
12403
12404 private:
12405 base::WeakPtr<FakeStreamRequest> last_stream_request_;
12406
12407 DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory);
12408};
12409
[email protected]831e4a32013-11-14 02:14:4412410// TODO(yhirano): Split this class out into a net/websockets file, if it is
12411// worth doing.
12412class FakeWebSocketStreamCreateHelper :
12413 public WebSocketHandshakeStreamBase::CreateHelper {
12414 public:
dchengb03027d2014-10-21 12:00:2012415 WebSocketHandshakeStreamBase* CreateBasicStream(
[email protected]7e841a52013-11-22 09:04:2112416 scoped_ptr<ClientSocketHandle> connection,
mostynbba063d6032014-10-09 11:01:1312417 bool using_proxy) override {
[email protected]831e4a32013-11-14 02:14:4412418 NOTREACHED();
12419 return NULL;
12420 }
12421
dchengb03027d2014-10-21 12:00:2012422 WebSocketHandshakeStreamBase* CreateSpdyStream(
[email protected]831e4a32013-11-14 02:14:4412423 const base::WeakPtr<SpdySession>& session,
mostynbba063d6032014-10-09 11:01:1312424 bool use_relative_url) override {
[email protected]831e4a32013-11-14 02:14:4412425 NOTREACHED();
12426 return NULL;
12427 };
12428
dchengb03027d2014-10-21 12:00:2012429 ~FakeWebSocketStreamCreateHelper() override {}
[email protected]831e4a32013-11-14 02:14:4412430
12431 virtual scoped_ptr<WebSocketStream> Upgrade() {
12432 NOTREACHED();
12433 return scoped_ptr<WebSocketStream>();
12434 }
12435};
12436
[email protected]bf828982013-08-14 18:01:4712437} // namespace
12438
12439// Make sure that HttpNetworkTransaction passes on its priority to its
12440// stream request on start.
12441TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) {
12442 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12443 HttpNetworkSessionPeer peer(session);
12444 FakeStreamFactory* fake_factory = new FakeStreamFactory();
[email protected]831e4a32013-11-14 02:14:4412445 peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory));
[email protected]bf828982013-08-14 18:01:4712446
dcheng48459ac22014-08-26 00:46:4112447 HttpNetworkTransaction trans(LOW, session.get());
[email protected]bf828982013-08-14 18:01:4712448
12449 ASSERT_TRUE(fake_factory->last_stream_request() == NULL);
12450
12451 HttpRequestInfo request;
12452 TestCompletionCallback callback;
12453 EXPECT_EQ(ERR_IO_PENDING,
12454 trans.Start(&request, callback.callback(), BoundNetLog()));
12455
12456 base::WeakPtr<FakeStreamRequest> fake_request =
12457 fake_factory->last_stream_request();
12458 ASSERT_TRUE(fake_request != NULL);
12459 EXPECT_EQ(LOW, fake_request->priority());
12460}
12461
12462// Make sure that HttpNetworkTransaction passes on its priority
12463// updates to its stream request.
12464TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriority) {
12465 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12466 HttpNetworkSessionPeer peer(session);
12467 FakeStreamFactory* fake_factory = new FakeStreamFactory();
[email protected]831e4a32013-11-14 02:14:4412468 peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory));
[email protected]bf828982013-08-14 18:01:4712469
dcheng48459ac22014-08-26 00:46:4112470 HttpNetworkTransaction trans(LOW, session.get());
[email protected]bf828982013-08-14 18:01:4712471
12472 HttpRequestInfo request;
12473 TestCompletionCallback callback;
12474 EXPECT_EQ(ERR_IO_PENDING,
12475 trans.Start(&request, callback.callback(), BoundNetLog()));
12476
12477 base::WeakPtr<FakeStreamRequest> fake_request =
12478 fake_factory->last_stream_request();
12479 ASSERT_TRUE(fake_request != NULL);
12480 EXPECT_EQ(LOW, fake_request->priority());
12481
12482 trans.SetPriority(LOWEST);
12483 ASSERT_TRUE(fake_request != NULL);
12484 EXPECT_EQ(LOWEST, fake_request->priority());
12485}
12486
[email protected]e86839fd2013-08-14 18:29:0312487// Make sure that HttpNetworkTransaction passes on its priority
12488// updates to its stream.
12489TEST_P(HttpNetworkTransactionTest, SetStreamPriority) {
12490 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12491 HttpNetworkSessionPeer peer(session);
12492 FakeStreamFactory* fake_factory = new FakeStreamFactory();
[email protected]831e4a32013-11-14 02:14:4412493 peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory));
[email protected]e86839fd2013-08-14 18:29:0312494
dcheng48459ac22014-08-26 00:46:4112495 HttpNetworkTransaction trans(LOW, session.get());
[email protected]e86839fd2013-08-14 18:29:0312496
12497 HttpRequestInfo request;
12498 TestCompletionCallback callback;
12499 EXPECT_EQ(ERR_IO_PENDING,
12500 trans.Start(&request, callback.callback(), BoundNetLog()));
12501
12502 base::WeakPtr<FakeStreamRequest> fake_request =
12503 fake_factory->last_stream_request();
12504 ASSERT_TRUE(fake_request != NULL);
12505 base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest();
12506 ASSERT_TRUE(fake_stream != NULL);
12507 EXPECT_EQ(LOW, fake_stream->priority());
12508
12509 trans.SetPriority(LOWEST);
12510 EXPECT_EQ(LOWEST, fake_stream->priority());
12511}
12512
[email protected]831e4a32013-11-14 02:14:4412513TEST_P(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) {
12514 // The same logic needs to be tested for both ws: and wss: schemes, but this
12515 // test is already parameterised on NextProto, so it uses a loop to verify
12516 // that the different schemes work.
12517 std::string test_cases[] = {"ws://www.google.com/", "wss://www.google.com/"};
12518 for (size_t i = 0; i < arraysize(test_cases); ++i) {
12519 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12520 HttpNetworkSessionPeer peer(session);
12521 FakeStreamFactory* fake_factory = new FakeStreamFactory();
12522 FakeWebSocketStreamCreateHelper websocket_stream_create_helper;
[email protected]0191b51c2013-11-18 10:55:2312523 peer.SetHttpStreamFactoryForWebSocket(
[email protected]831e4a32013-11-14 02:14:4412524 scoped_ptr<HttpStreamFactory>(fake_factory));
12525
dcheng48459ac22014-08-26 00:46:4112526 HttpNetworkTransaction trans(LOW, session.get());
[email protected]831e4a32013-11-14 02:14:4412527 trans.SetWebSocketHandshakeStreamCreateHelper(
12528 &websocket_stream_create_helper);
12529
12530 HttpRequestInfo request;
12531 TestCompletionCallback callback;
12532 request.method = "GET";
12533 request.url = GURL(test_cases[i]);
12534
12535 EXPECT_EQ(ERR_IO_PENDING,
12536 trans.Start(&request, callback.callback(), BoundNetLog()));
12537
12538 base::WeakPtr<FakeStreamRequest> fake_request =
12539 fake_factory->last_stream_request();
12540 ASSERT_TRUE(fake_request != NULL);
12541 EXPECT_EQ(&websocket_stream_create_helper,
12542 fake_request->websocket_stream_create_helper());
12543 }
12544}
12545
[email protected]043b68c82013-08-22 23:41:5212546// Tests that when a used socket is returned to the SSL socket pool, it's closed
12547// if the transport socket pool is stalled on the global socket limit.
12548TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) {
12549 ClientSocketPoolManager::set_max_sockets_per_group(
12550 HttpNetworkSession::NORMAL_SOCKET_POOL, 1);
12551 ClientSocketPoolManager::set_max_sockets_per_pool(
12552 HttpNetworkSession::NORMAL_SOCKET_POOL, 1);
12553
12554 // Set up SSL request.
12555
12556 HttpRequestInfo ssl_request;
12557 ssl_request.method = "GET";
12558 ssl_request.url = GURL("https://www.google.com/");
12559
12560 MockWrite ssl_writes[] = {
12561 MockWrite("GET / HTTP/1.1\r\n"
12562 "Host: www.google.com\r\n"
12563 "Connection: keep-alive\r\n\r\n"),
12564 };
12565 MockRead ssl_reads[] = {
12566 MockRead("HTTP/1.1 200 OK\r\n"),
12567 MockRead("Content-Length: 11\r\n\r\n"),
12568 MockRead("hello world"),
12569 MockRead(SYNCHRONOUS, OK),
12570 };
12571 StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads),
12572 ssl_writes, arraysize(ssl_writes));
12573 session_deps_.socket_factory->AddSocketDataProvider(&ssl_data);
12574
12575 SSLSocketDataProvider ssl(ASYNC, OK);
12576 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
12577
12578 // Set up HTTP request.
12579
12580 HttpRequestInfo http_request;
12581 http_request.method = "GET";
12582 http_request.url = GURL("http://www.google.com/");
12583
12584 MockWrite http_writes[] = {
12585 MockWrite("GET / HTTP/1.1\r\n"
12586 "Host: www.google.com\r\n"
12587 "Connection: keep-alive\r\n\r\n"),
12588 };
12589 MockRead http_reads[] = {
12590 MockRead("HTTP/1.1 200 OK\r\n"),
12591 MockRead("Content-Length: 7\r\n\r\n"),
12592 MockRead("falafel"),
12593 MockRead(SYNCHRONOUS, OK),
12594 };
12595 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads),
12596 http_writes, arraysize(http_writes));
12597 session_deps_.socket_factory->AddSocketDataProvider(&http_data);
12598
12599 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12600
12601 // Start the SSL request.
12602 TestCompletionCallback ssl_callback;
12603 scoped_ptr<HttpTransaction> ssl_trans(
12604 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
12605 ASSERT_EQ(ERR_IO_PENDING,
12606 ssl_trans->Start(&ssl_request, ssl_callback.callback(),
12607 BoundNetLog()));
12608
12609 // Start the HTTP request. Pool should stall.
12610 TestCompletionCallback http_callback;
12611 scoped_ptr<HttpTransaction> http_trans(
12612 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
12613 ASSERT_EQ(ERR_IO_PENDING,
12614 http_trans->Start(&http_request, http_callback.callback(),
12615 BoundNetLog()));
dcheng48459ac22014-08-26 00:46:4112616 EXPECT_TRUE(IsTransportSocketPoolStalled(session.get()));
[email protected]043b68c82013-08-22 23:41:5212617
12618 // Wait for response from SSL request.
12619 ASSERT_EQ(OK, ssl_callback.WaitForResult());
12620 std::string response_data;
12621 ASSERT_EQ(OK, ReadTransaction(ssl_trans.get(), &response_data));
12622 EXPECT_EQ("hello world", response_data);
12623
12624 // The SSL socket should automatically be closed, so the HTTP request can
12625 // start.
dcheng48459ac22014-08-26 00:46:4112626 EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get()));
12627 ASSERT_FALSE(IsTransportSocketPoolStalled(session.get()));
[email protected]043b68c82013-08-22 23:41:5212628
12629 // The HTTP request can now complete.
12630 ASSERT_EQ(OK, http_callback.WaitForResult());
12631 ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data));
12632 EXPECT_EQ("falafel", response_data);
12633
dcheng48459ac22014-08-26 00:46:4112634 EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get()));
[email protected]043b68c82013-08-22 23:41:5212635}
12636
12637// Tests that when a SSL connection is established but there's no corresponding
12638// request that needs it, the new socket is closed if the transport socket pool
12639// is stalled on the global socket limit.
12640TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) {
12641 ClientSocketPoolManager::set_max_sockets_per_group(
12642 HttpNetworkSession::NORMAL_SOCKET_POOL, 1);
12643 ClientSocketPoolManager::set_max_sockets_per_pool(
12644 HttpNetworkSession::NORMAL_SOCKET_POOL, 1);
12645
12646 // Set up an ssl request.
12647
12648 HttpRequestInfo ssl_request;
12649 ssl_request.method = "GET";
12650 ssl_request.url = GURL("https://www.foopy.com/");
12651
12652 // No data will be sent on the SSL socket.
12653 StaticSocketDataProvider ssl_data;
12654 session_deps_.socket_factory->AddSocketDataProvider(&ssl_data);
12655
12656 SSLSocketDataProvider ssl(ASYNC, OK);
12657 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
12658
12659 // Set up HTTP request.
12660
12661 HttpRequestInfo http_request;
12662 http_request.method = "GET";
12663 http_request.url = GURL("http://www.google.com/");
12664
12665 MockWrite http_writes[] = {
12666 MockWrite("GET / HTTP/1.1\r\n"
12667 "Host: www.google.com\r\n"
12668 "Connection: keep-alive\r\n\r\n"),
12669 };
12670 MockRead http_reads[] = {
12671 MockRead("HTTP/1.1 200 OK\r\n"),
12672 MockRead("Content-Length: 7\r\n\r\n"),
12673 MockRead("falafel"),
12674 MockRead(SYNCHRONOUS, OK),
12675 };
12676 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads),
12677 http_writes, arraysize(http_writes));
12678 session_deps_.socket_factory->AddSocketDataProvider(&http_data);
12679
12680 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12681
12682 // Preconnect an SSL socket. A preconnect is needed because connect jobs are
12683 // cancelled when a normal transaction is cancelled.
12684 net::HttpStreamFactory* http_stream_factory = session->http_stream_factory();
12685 net::SSLConfig ssl_config;
12686 session->ssl_config_service()->GetSSLConfig(&ssl_config);
12687 http_stream_factory->PreconnectStreams(1, ssl_request, DEFAULT_PRIORITY,
12688 ssl_config, ssl_config);
dcheng48459ac22014-08-26 00:46:4112689 EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get()));
[email protected]043b68c82013-08-22 23:41:5212690
12691 // Start the HTTP request. Pool should stall.
12692 TestCompletionCallback http_callback;
12693 scoped_ptr<HttpTransaction> http_trans(
12694 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
12695 ASSERT_EQ(ERR_IO_PENDING,
12696 http_trans->Start(&http_request, http_callback.callback(),
12697 BoundNetLog()));
dcheng48459ac22014-08-26 00:46:4112698 EXPECT_TRUE(IsTransportSocketPoolStalled(session.get()));
[email protected]043b68c82013-08-22 23:41:5212699
12700 // The SSL connection will automatically be closed once the connection is
12701 // established, to let the HTTP request start.
12702 ASSERT_EQ(OK, http_callback.WaitForResult());
12703 std::string response_data;
12704 ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data));
12705 EXPECT_EQ("falafel", response_data);
12706
dcheng48459ac22014-08-26 00:46:4112707 EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get()));
[email protected]043b68c82013-08-22 23:41:5212708}
12709
[email protected]02d74a02014-04-23 18:10:5412710TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) {
12711 ScopedVector<UploadElementReader> element_readers;
12712 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:0712713 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]02d74a02014-04-23 18:10:5412714
12715 HttpRequestInfo request;
12716 request.method = "POST";
12717 request.url = GURL("http://www.foo.com/");
12718 request.upload_data_stream = &upload_data_stream;
12719 request.load_flags = 0;
12720
12721 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12722 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4112723 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5412724 // Send headers successfully, but get an error while sending the body.
12725 MockWrite data_writes[] = {
12726 MockWrite("POST / HTTP/1.1\r\n"
12727 "Host: www.foo.com\r\n"
12728 "Connection: keep-alive\r\n"
12729 "Content-Length: 3\r\n\r\n"),
12730 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
12731 };
12732
12733 MockRead data_reads[] = {
12734 MockRead("HTTP/1.0 400 Not OK\r\n\r\n"),
12735 MockRead("hello world"),
12736 MockRead(SYNCHRONOUS, OK),
12737 };
12738 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
12739 arraysize(data_writes));
12740 session_deps_.socket_factory->AddSocketDataProvider(&data);
12741
12742 TestCompletionCallback callback;
12743
12744 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
12745 EXPECT_EQ(ERR_IO_PENDING, rv);
12746
12747 rv = callback.WaitForResult();
12748 EXPECT_EQ(OK, rv);
12749
12750 const HttpResponseInfo* response = trans->GetResponseInfo();
12751 ASSERT_TRUE(response != NULL);
12752
12753 EXPECT_TRUE(response->headers.get() != NULL);
12754 EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine());
12755
12756 std::string response_data;
12757 rv = ReadTransaction(trans.get(), &response_data);
12758 EXPECT_EQ(OK, rv);
12759 EXPECT_EQ("hello world", response_data);
12760}
12761
12762// This test makes sure the retry logic doesn't trigger when reading an error
12763// response from a server that rejected a POST with a CONNECTION_RESET.
12764TEST_P(HttpNetworkTransactionTest,
12765 PostReadsErrorResponseAfterResetOnReusedSocket) {
12766 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12767 MockWrite data_writes[] = {
12768 MockWrite("GET / HTTP/1.1\r\n"
12769 "Host: www.foo.com\r\n"
12770 "Connection: keep-alive\r\n\r\n"),
12771 MockWrite("POST / HTTP/1.1\r\n"
12772 "Host: www.foo.com\r\n"
12773 "Connection: keep-alive\r\n"
12774 "Content-Length: 3\r\n\r\n"),
12775 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
12776 };
12777
12778 MockRead data_reads[] = {
12779 MockRead("HTTP/1.1 200 Peachy\r\n"
12780 "Content-Length: 14\r\n\r\n"),
12781 MockRead("first response"),
12782 MockRead("HTTP/1.1 400 Not OK\r\n"
12783 "Content-Length: 15\r\n\r\n"),
12784 MockRead("second response"),
12785 MockRead(SYNCHRONOUS, OK),
12786 };
12787 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
12788 arraysize(data_writes));
12789 session_deps_.socket_factory->AddSocketDataProvider(&data);
12790
12791 TestCompletionCallback callback;
12792 HttpRequestInfo request1;
12793 request1.method = "GET";
12794 request1.url = GURL("http://www.foo.com/");
12795 request1.load_flags = 0;
12796
12797 scoped_ptr<HttpTransaction> trans1(
dcheng48459ac22014-08-26 00:46:4112798 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5412799 int rv = trans1->Start(&request1, callback.callback(), BoundNetLog());
12800 EXPECT_EQ(ERR_IO_PENDING, rv);
12801
12802 rv = callback.WaitForResult();
12803 EXPECT_EQ(OK, rv);
12804
12805 const HttpResponseInfo* response1 = trans1->GetResponseInfo();
12806 ASSERT_TRUE(response1 != NULL);
12807
12808 EXPECT_TRUE(response1->headers.get() != NULL);
12809 EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine());
12810
12811 std::string response_data1;
12812 rv = ReadTransaction(trans1.get(), &response_data1);
12813 EXPECT_EQ(OK, rv);
12814 EXPECT_EQ("first response", response_data1);
12815 // Delete the transaction to release the socket back into the socket pool.
12816 trans1.reset();
12817
12818 ScopedVector<UploadElementReader> element_readers;
12819 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:0712820 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]02d74a02014-04-23 18:10:5412821
12822 HttpRequestInfo request2;
12823 request2.method = "POST";
12824 request2.url = GURL("http://www.foo.com/");
12825 request2.upload_data_stream = &upload_data_stream;
12826 request2.load_flags = 0;
12827
12828 scoped_ptr<HttpTransaction> trans2(
dcheng48459ac22014-08-26 00:46:4112829 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5412830 rv = trans2->Start(&request2, callback.callback(), BoundNetLog());
12831 EXPECT_EQ(ERR_IO_PENDING, rv);
12832
12833 rv = callback.WaitForResult();
12834 EXPECT_EQ(OK, rv);
12835
12836 const HttpResponseInfo* response2 = trans2->GetResponseInfo();
12837 ASSERT_TRUE(response2 != NULL);
12838
12839 EXPECT_TRUE(response2->headers.get() != NULL);
12840 EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine());
12841
12842 std::string response_data2;
12843 rv = ReadTransaction(trans2.get(), &response_data2);
12844 EXPECT_EQ(OK, rv);
12845 EXPECT_EQ("second response", response_data2);
12846}
12847
12848TEST_P(HttpNetworkTransactionTest,
12849 PostReadsErrorResponseAfterResetPartialBodySent) {
12850 ScopedVector<UploadElementReader> element_readers;
12851 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:0712852 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]02d74a02014-04-23 18:10:5412853
12854 HttpRequestInfo request;
12855 request.method = "POST";
12856 request.url = GURL("http://www.foo.com/");
12857 request.upload_data_stream = &upload_data_stream;
12858 request.load_flags = 0;
12859
12860 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12861 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4112862 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5412863 // Send headers successfully, but get an error while sending the body.
12864 MockWrite data_writes[] = {
12865 MockWrite("POST / HTTP/1.1\r\n"
12866 "Host: www.foo.com\r\n"
12867 "Connection: keep-alive\r\n"
12868 "Content-Length: 3\r\n\r\n"
12869 "fo"),
12870 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
12871 };
12872
12873 MockRead data_reads[] = {
12874 MockRead("HTTP/1.0 400 Not OK\r\n\r\n"),
12875 MockRead("hello world"),
12876 MockRead(SYNCHRONOUS, OK),
12877 };
12878 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
12879 arraysize(data_writes));
12880 session_deps_.socket_factory->AddSocketDataProvider(&data);
12881
12882 TestCompletionCallback callback;
12883
12884 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
12885 EXPECT_EQ(ERR_IO_PENDING, rv);
12886
12887 rv = callback.WaitForResult();
12888 EXPECT_EQ(OK, rv);
12889
12890 const HttpResponseInfo* response = trans->GetResponseInfo();
12891 ASSERT_TRUE(response != NULL);
12892
12893 EXPECT_TRUE(response->headers.get() != NULL);
12894 EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine());
12895
12896 std::string response_data;
12897 rv = ReadTransaction(trans.get(), &response_data);
12898 EXPECT_EQ(OK, rv);
12899 EXPECT_EQ("hello world", response_data);
12900}
12901
12902// This tests the more common case than the previous test, where headers and
12903// body are not merged into a single request.
12904TEST_P(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) {
12905 ScopedVector<UploadElementReader> element_readers;
12906 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:0712907 ChunkedUploadDataStream upload_data_stream(0);
[email protected]02d74a02014-04-23 18:10:5412908
12909 HttpRequestInfo request;
12910 request.method = "POST";
12911 request.url = GURL("http://www.foo.com/");
12912 request.upload_data_stream = &upload_data_stream;
12913 request.load_flags = 0;
12914
12915 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12916 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4112917 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5412918 // Send headers successfully, but get an error while sending the body.
12919 MockWrite data_writes[] = {
12920 MockWrite("POST / HTTP/1.1\r\n"
12921 "Host: www.foo.com\r\n"
12922 "Connection: keep-alive\r\n"
12923 "Transfer-Encoding: chunked\r\n\r\n"),
12924 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
12925 };
12926
12927 MockRead data_reads[] = {
12928 MockRead("HTTP/1.0 400 Not OK\r\n\r\n"),
12929 MockRead("hello world"),
12930 MockRead(SYNCHRONOUS, OK),
12931 };
12932 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
12933 arraysize(data_writes));
12934 session_deps_.socket_factory->AddSocketDataProvider(&data);
12935
12936 TestCompletionCallback callback;
12937
12938 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
12939 EXPECT_EQ(ERR_IO_PENDING, rv);
12940 // Make sure the headers are sent before adding a chunk. This ensures that
12941 // they can't be merged with the body in a single send. Not currently
12942 // necessary since a chunked body is never merged with headers, but this makes
12943 // the test more future proof.
12944 base::RunLoop().RunUntilIdle();
12945
mmenkecbc2b712014-10-09 20:29:0712946 upload_data_stream.AppendData("last chunk", 10, true);
[email protected]02d74a02014-04-23 18:10:5412947
12948 rv = callback.WaitForResult();
12949 EXPECT_EQ(OK, rv);
12950
12951 const HttpResponseInfo* response = trans->GetResponseInfo();
12952 ASSERT_TRUE(response != NULL);
12953
12954 EXPECT_TRUE(response->headers.get() != NULL);
12955 EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine());
12956
12957 std::string response_data;
12958 rv = ReadTransaction(trans.get(), &response_data);
12959 EXPECT_EQ(OK, rv);
12960 EXPECT_EQ("hello world", response_data);
12961}
12962
12963TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) {
12964 ScopedVector<UploadElementReader> element_readers;
12965 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:0712966 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]02d74a02014-04-23 18:10:5412967
12968 HttpRequestInfo request;
12969 request.method = "POST";
12970 request.url = GURL("http://www.foo.com/");
12971 request.upload_data_stream = &upload_data_stream;
12972 request.load_flags = 0;
12973
12974 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12975 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4112976 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5412977
12978 MockWrite data_writes[] = {
12979 MockWrite("POST / HTTP/1.1\r\n"
12980 "Host: www.foo.com\r\n"
12981 "Connection: keep-alive\r\n"
12982 "Content-Length: 3\r\n\r\n"),
12983 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
12984 };
12985
12986 MockRead data_reads[] = {
12987 MockRead("HTTP/1.0 100 Continue\r\n\r\n"),
12988 MockRead("HTTP/1.0 400 Not OK\r\n\r\n"),
12989 MockRead("hello world"),
12990 MockRead(SYNCHRONOUS, OK),
12991 };
12992 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
12993 arraysize(data_writes));
12994 session_deps_.socket_factory->AddSocketDataProvider(&data);
12995
12996 TestCompletionCallback callback;
12997
12998 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
12999 EXPECT_EQ(ERR_IO_PENDING, rv);
13000
13001 rv = callback.WaitForResult();
13002 EXPECT_EQ(OK, rv);
13003
13004 const HttpResponseInfo* response = trans->GetResponseInfo();
13005 ASSERT_TRUE(response != NULL);
13006
13007 EXPECT_TRUE(response->headers.get() != NULL);
13008 EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine());
13009
13010 std::string response_data;
13011 rv = ReadTransaction(trans.get(), &response_data);
13012 EXPECT_EQ(OK, rv);
13013 EXPECT_EQ("hello world", response_data);
13014}
13015
13016TEST_P(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) {
13017 ScopedVector<UploadElementReader> element_readers;
13018 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:0713019 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]02d74a02014-04-23 18:10:5413020
13021 HttpRequestInfo request;
13022 request.method = "POST";
13023 request.url = GURL("http://www.foo.com/");
13024 request.upload_data_stream = &upload_data_stream;
13025 request.load_flags = 0;
13026
13027 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
13028 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4113029 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5413030 // Send headers successfully, but get an error while sending the body.
13031 MockWrite data_writes[] = {
13032 MockWrite("POST / HTTP/1.1\r\n"
13033 "Host: www.foo.com\r\n"
13034 "Connection: keep-alive\r\n"
13035 "Content-Length: 3\r\n\r\n"),
13036 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
13037 };
13038
13039 MockRead data_reads[] = {
13040 MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"),
13041 MockRead("hello world"),
13042 MockRead(SYNCHRONOUS, OK),
13043 };
13044 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
13045 arraysize(data_writes));
13046 session_deps_.socket_factory->AddSocketDataProvider(&data);
13047
13048 TestCompletionCallback callback;
13049
13050 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
13051 EXPECT_EQ(ERR_IO_PENDING, rv);
13052
13053 rv = callback.WaitForResult();
13054 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
13055
13056 const HttpResponseInfo* response = trans->GetResponseInfo();
13057 EXPECT_TRUE(response == NULL);
13058}
13059
13060TEST_P(HttpNetworkTransactionTest,
13061 PostIgnoresNonErrorResponseAfterResetAnd100) {
13062 ScopedVector<UploadElementReader> element_readers;
13063 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:0713064 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]02d74a02014-04-23 18:10:5413065
13066 HttpRequestInfo request;
13067 request.method = "POST";
13068 request.url = GURL("http://www.foo.com/");
13069 request.upload_data_stream = &upload_data_stream;
13070 request.load_flags = 0;
13071
13072 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
13073 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4113074 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5413075 // Send headers successfully, but get an error while sending the body.
13076 MockWrite data_writes[] = {
13077 MockWrite("POST / HTTP/1.1\r\n"
13078 "Host: www.foo.com\r\n"
13079 "Connection: keep-alive\r\n"
13080 "Content-Length: 3\r\n\r\n"),
13081 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
13082 };
13083
13084 MockRead data_reads[] = {
13085 MockRead("HTTP/1.0 100 Continue\r\n\r\n"),
13086 MockRead("HTTP/1.0 302 Redirect\r\n"),
13087 MockRead("Location: http://somewhere-else.com/\r\n"),
13088 MockRead("Content-Length: 0\r\n\r\n"),
13089 MockRead(SYNCHRONOUS, OK),
13090 };
13091 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
13092 arraysize(data_writes));
13093 session_deps_.socket_factory->AddSocketDataProvider(&data);
13094
13095 TestCompletionCallback callback;
13096
13097 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
13098 EXPECT_EQ(ERR_IO_PENDING, rv);
13099
13100 rv = callback.WaitForResult();
13101 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
13102
13103 const HttpResponseInfo* response = trans->GetResponseInfo();
13104 EXPECT_TRUE(response == NULL);
13105}
13106
13107TEST_P(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) {
13108 ScopedVector<UploadElementReader> element_readers;
13109 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:0713110 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]02d74a02014-04-23 18:10:5413111
13112 HttpRequestInfo request;
13113 request.method = "POST";
13114 request.url = GURL("http://www.foo.com/");
13115 request.upload_data_stream = &upload_data_stream;
13116 request.load_flags = 0;
13117
13118 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
13119 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4113120 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5413121 // Send headers successfully, but get an error while sending the body.
13122 MockWrite data_writes[] = {
13123 MockWrite("POST / HTTP/1.1\r\n"
13124 "Host: www.foo.com\r\n"
13125 "Connection: keep-alive\r\n"
13126 "Content-Length: 3\r\n\r\n"),
13127 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
13128 };
13129
13130 MockRead data_reads[] = {
13131 MockRead("HTTP 0.9 rocks!"),
13132 MockRead(SYNCHRONOUS, OK),
13133 };
13134 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
13135 arraysize(data_writes));
13136 session_deps_.socket_factory->AddSocketDataProvider(&data);
13137
13138 TestCompletionCallback callback;
13139
13140 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
13141 EXPECT_EQ(ERR_IO_PENDING, rv);
13142
13143 rv = callback.WaitForResult();
13144 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
13145
13146 const HttpResponseInfo* response = trans->GetResponseInfo();
13147 EXPECT_TRUE(response == NULL);
13148}
13149
13150TEST_P(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) {
13151 ScopedVector<UploadElementReader> element_readers;
13152 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:0713153 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]02d74a02014-04-23 18:10:5413154
13155 HttpRequestInfo request;
13156 request.method = "POST";
13157 request.url = GURL("http://www.foo.com/");
13158 request.upload_data_stream = &upload_data_stream;
13159 request.load_flags = 0;
13160
13161 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
13162 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4113163 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5413164 // Send headers successfully, but get an error while sending the body.
13165 MockWrite data_writes[] = {
13166 MockWrite("POST / HTTP/1.1\r\n"
13167 "Host: www.foo.com\r\n"
13168 "Connection: keep-alive\r\n"
13169 "Content-Length: 3\r\n\r\n"),
13170 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
13171 };
13172
13173 MockRead data_reads[] = {
13174 MockRead("HTTP/1.0 400 Not a Full Response\r\n"),
13175 MockRead(SYNCHRONOUS, OK),
13176 };
13177 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
13178 arraysize(data_writes));
13179 session_deps_.socket_factory->AddSocketDataProvider(&data);
13180
13181 TestCompletionCallback callback;
13182
13183 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
13184 EXPECT_EQ(ERR_IO_PENDING, rv);
13185
13186 rv = callback.WaitForResult();
13187 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
13188
13189 const HttpResponseInfo* response = trans->GetResponseInfo();
13190 EXPECT_TRUE(response == NULL);
13191}
13192
[email protected]89ceba9a2009-03-21 03:46:0613193} // namespace net