Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: net/http/http_network_transaction_unittest.cc

Issue 1901533002: Implementation of network level throttler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Destroy transaction before session in QuicUploadWriteError. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/http_network_transaction.cc ('k') | net/http/http_stream_factory_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/http/http_network_transaction.h" 5 #include "net/http/http_network_transaction.h"
6 6
7 #include <math.h> // ceil 7 #include <math.h> // ceil
8 #include <stdarg.h> 8 #include <stdarg.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <limits> 11 #include <limits>
12 #include <memory> 12 #include <memory>
13 #include <set>
13 #include <string> 14 #include <string>
14 #include <utility> 15 #include <utility>
15 #include <vector> 16 #include <vector>
16 17
17 #include "base/compiler_specific.h" 18 #include "base/compiler_specific.h"
18 #include "base/files/file_path.h" 19 #include "base/files/file_path.h"
19 #include "base/files/file_util.h" 20 #include "base/files/file_util.h"
20 #include "base/json/json_writer.h" 21 #include "base/json/json_writer.h"
21 #include "base/logging.h" 22 #include "base/logging.h"
22 #include "base/macros.h" 23 #include "base/macros.h"
23 #include "base/memory/ptr_util.h" 24 #include "base/memory/ptr_util.h"
24 #include "base/memory/weak_ptr.h" 25 #include "base/memory/weak_ptr.h"
25 #include "base/run_loop.h" 26 #include "base/run_loop.h"
26 #include "base/strings/string_util.h" 27 #include "base/strings/string_util.h"
27 #include "base/strings/utf_string_conversions.h" 28 #include "base/strings/utf_string_conversions.h"
28 #include "base/test/test_file_util.h" 29 #include "base/test/test_file_util.h"
29 #include "base/threading/thread_task_runner_handle.h" 30 #include "base/threading/thread_task_runner_handle.h"
30 #include "net/base/auth.h" 31 #include "net/base/auth.h"
31 #include "net/base/chunked_upload_data_stream.h" 32 #include "net/base/chunked_upload_data_stream.h"
32 #include "net/base/completion_callback.h" 33 #include "net/base/completion_callback.h"
33 #include "net/base/elements_upload_data_stream.h" 34 #include "net/base/elements_upload_data_stream.h"
34 #include "net/base/load_timing_info.h" 35 #include "net/base/load_timing_info.h"
35 #include "net/base/load_timing_info_test_util.h" 36 #include "net/base/load_timing_info_test_util.h"
36 #include "net/base/net_errors.h" 37 #include "net/base/net_errors.h"
38 #include "net/base/network_throttle_manager.h"
37 #include "net/base/proxy_delegate.h" 39 #include "net/base/proxy_delegate.h"
38 #include "net/base/request_priority.h" 40 #include "net/base/request_priority.h"
39 #include "net/base/test_completion_callback.h" 41 #include "net/base/test_completion_callback.h"
40 #include "net/base/test_proxy_delegate.h" 42 #include "net/base/test_proxy_delegate.h"
41 #include "net/base/upload_bytes_element_reader.h" 43 #include "net/base/upload_bytes_element_reader.h"
42 #include "net/base/upload_file_element_reader.h" 44 #include "net/base/upload_file_element_reader.h"
43 #include "net/cert/mock_cert_verifier.h" 45 #include "net/cert/mock_cert_verifier.h"
44 #include "net/dns/host_cache.h" 46 #include "net/dns/host_cache.h"
45 #include "net/dns/mock_host_resolver.h" 47 #include "net/dns/mock_host_resolver.h"
46 #include "net/http/http_auth_challenge_tokenizer.h" 48 #include "net/http/http_auth_challenge_tokenizer.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 using net::test::IsOk; 104 using net::test::IsOk;
103 105
104 using base::ASCIIToUTF16; 106 using base::ASCIIToUTF16;
105 107
106 //----------------------------------------------------------------------------- 108 //-----------------------------------------------------------------------------
107 109
108 namespace net { 110 namespace net {
109 111
110 namespace { 112 namespace {
111 113
114 class TestNetworkStreamThrottler : public NetworkThrottleManager {
115 public:
116 TestNetworkStreamThrottler()
117 : throttle_new_requests_(false),
118 num_set_priority_calls_(0),
119 last_priority_set_(IDLE) {}
120
121 ~TestNetworkStreamThrottler() override {
122 EXPECT_TRUE(outstanding_throttles_.empty());
123 }
124
125 // NetworkThrottleManager
126 std::unique_ptr<Throttle> CreateThrottle(ThrottleDelegate* delegate,
127 RequestPriority priority,
128 bool ignore_limits) override {
129 std::unique_ptr<TestThrottle> test_throttle(
130 new TestThrottle(throttle_new_requests_, delegate, this));
131 outstanding_throttles_.insert(test_throttle.get());
132 return std::move(test_throttle);
133 }
134
135 void UnthrottleAllRequests() {
136 std::set<TestThrottle*> outstanding_throttles_copy(outstanding_throttles_);
137 for (auto& throttle : outstanding_throttles_copy) {
138 if (throttle->IsThrottled())
139 throttle->Unthrottle();
140 }
141 }
142
143 void set_throttle_new_requests(bool throttle_new_requests) {
144 throttle_new_requests_ = throttle_new_requests;
145 }
146
147 // Includes both throttled and unthrottled throttles.
148 size_t num_outstanding_requests() const {
149 return outstanding_throttles_.size();
150 }
151
152 int num_set_priority_calls() const { return num_set_priority_calls_; }
153 RequestPriority last_priority_set() const { return last_priority_set_; }
154 void set_priority_change_closure(
155 const base::Closure& priority_change_closure) {
156 priority_change_closure_ = priority_change_closure;
157 }
158
159 private:
160 class TestThrottle : public NetworkThrottleManager::Throttle {
161 public:
162 ~TestThrottle() override { throttler_->OnThrottleDestroyed(this); }
163
164 // Throttle
165 bool IsThrottled() const override { return throttled_; }
166 void SetPriority(RequestPriority priority) override {
167 throttler_->SetPriorityCalled(priority);
168 }
169
170 TestThrottle(bool throttled,
171 ThrottleDelegate* delegate,
172 TestNetworkStreamThrottler* throttler)
173 : throttled_(throttled), delegate_(delegate), throttler_(throttler) {}
174
175 void Unthrottle() {
176 EXPECT_TRUE(throttled_);
177
178 throttled_ = false;
179 delegate_->OnThrottleStateChanged();
180 }
181
182 bool throttled_;
183 ThrottleDelegate* delegate_;
184 TestNetworkStreamThrottler* throttler_;
185 };
186
187 void OnThrottleDestroyed(TestThrottle* throttle) {
188 EXPECT_NE(0u, outstanding_throttles_.count(throttle));
189 outstanding_throttles_.erase(throttle);
190 }
191
192 void SetPriorityCalled(RequestPriority priority) {
193 ++num_set_priority_calls_;
194 last_priority_set_ = priority;
195 if (!priority_change_closure_.is_null())
196 priority_change_closure_.Run();
197 }
198
199 // Includes both throttled and unthrottled throttles.
200 std::set<TestThrottle*> outstanding_throttles_;
201 bool throttle_new_requests_;
202 int num_set_priority_calls_;
203 RequestPriority last_priority_set_;
204 base::Closure priority_change_closure_;
205
206 DISALLOW_COPY_AND_ASSIGN(TestNetworkStreamThrottler);
207 };
208
112 const base::string16 kBar(ASCIIToUTF16("bar")); 209 const base::string16 kBar(ASCIIToUTF16("bar"));
113 const base::string16 kBar2(ASCIIToUTF16("bar2")); 210 const base::string16 kBar2(ASCIIToUTF16("bar2"));
114 const base::string16 kBar3(ASCIIToUTF16("bar3")); 211 const base::string16 kBar3(ASCIIToUTF16("bar3"));
115 const base::string16 kBaz(ASCIIToUTF16("baz")); 212 const base::string16 kBaz(ASCIIToUTF16("baz"));
116 const base::string16 kFirst(ASCIIToUTF16("first")); 213 const base::string16 kFirst(ASCIIToUTF16("first"));
117 const base::string16 kFoo(ASCIIToUTF16("foo")); 214 const base::string16 kFoo(ASCIIToUTF16("foo"));
118 const base::string16 kFoo2(ASCIIToUTF16("foo2")); 215 const base::string16 kFoo2(ASCIIToUTF16("foo2"));
119 const base::string16 kFoo3(ASCIIToUTF16("foo3")); 216 const base::string16 kFoo3(ASCIIToUTF16("foo3"));
120 const base::string16 kFou(ASCIIToUTF16("fou")); 217 const base::string16 kFou(ASCIIToUTF16("fou"));
121 const base::string16 kSecond(ASCIIToUTF16("second")); 218 const base::string16 kSecond(ASCIIToUTF16("second"));
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 headers->SetHeader("Origin", "http://www.example.org"); 347 headers->SetHeader("Origin", "http://www.example.org");
251 headers->SetHeader("Sec-WebSocket-Version", "13"); 348 headers->SetHeader("Sec-WebSocket-Version", "13");
252 headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); 349 headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ==");
253 } 350 }
254 351
255 std::unique_ptr<HttpNetworkSession> CreateSession( 352 std::unique_ptr<HttpNetworkSession> CreateSession(
256 SpdySessionDependencies* session_deps) { 353 SpdySessionDependencies* session_deps) {
257 return SpdySessionDependencies::SpdyCreateSession(session_deps); 354 return SpdySessionDependencies::SpdyCreateSession(session_deps);
258 } 355 }
259 356
357 // Note that the pointer written into |*throttler| will only be valid
358 // for the lifetime of the returned HttpNetworkSession.
359 std::unique_ptr<HttpNetworkSession> CreateSessionWithThrottler(
360 SpdySessionDependencies* session_deps,
361 TestNetworkStreamThrottler** throttler) {
362 std::unique_ptr<HttpNetworkSession> session(
363 SpdySessionDependencies::SpdyCreateSession(session_deps));
364
365 std::unique_ptr<TestNetworkStreamThrottler> owned_throttler(
366 new TestNetworkStreamThrottler);
367 *throttler = owned_throttler.get();
368
369 HttpNetworkSessionPeer peer(session.get());
370 peer.SetNetworkStreamThrottler(std::move(owned_throttler));
371
372 return session;
373 }
374
260 } // namespace 375 } // namespace
261 376
262 class HttpNetworkTransactionTest : public PlatformTest { 377 class HttpNetworkTransactionTest : public PlatformTest {
263 public: 378 public:
264 ~HttpNetworkTransactionTest() override { 379 ~HttpNetworkTransactionTest() override {
265 // Important to restore the per-pool limit first, since the pool limit must 380 // Important to restore the per-pool limit first, since the pool limit must
266 // always be greater than group limit, and the tests reduce both limits. 381 // always be greater than group limit, and the tests reduce both limits.
267 ClientSocketPoolManager::set_max_sockets_per_pool( 382 ClientSocketPoolManager::set_max_sockets_per_pool(
268 HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); 383 HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_);
269 ClientSocketPoolManager::set_max_sockets_per_group( 384 ClientSocketPoolManager::set_max_sockets_per_group(
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 const MockRead* read_failure, 436 const MockRead* read_failure,
322 bool use_spdy); 437 bool use_spdy);
323 438
324 SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], 439 SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[],
325 size_t data_count) { 440 size_t data_count) {
326 SimpleGetHelperResult out; 441 SimpleGetHelperResult out;
327 442
328 HttpRequestInfo request; 443 HttpRequestInfo request;
329 request.method = "GET"; 444 request.method = "GET";
330 request.url = GURL("http://www.example.org/"); 445 request.url = GURL("http://www.example.org/");
331 request.load_flags = 0;
332 446
333 BoundTestNetLog log; 447 BoundTestNetLog log;
334 session_deps_.net_log = log.bound().net_log(); 448 session_deps_.net_log = log.bound().net_log();
335 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 449 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
336 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 450 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
337 451
338 for (size_t i = 0; i < data_count; ++i) { 452 for (size_t i = 0; i < data_count; ++i) {
339 session_deps_.socket_factory->AddSocketDataProvider(data[i]); 453 session_deps_.socket_factory->AddSocketDataProvider(data[i]);
340 } 454 }
341 455
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 MockRead("HTTP/1.1 302 Redirect\r\n"), 1158 MockRead("HTTP/1.1 302 Redirect\r\n"),
1045 MockRead("Location: http://good.com/\r\n"), 1159 MockRead("Location: http://good.com/\r\n"),
1046 MockRead("Location: http://good.com/\r\n"), 1160 MockRead("Location: http://good.com/\r\n"),
1047 MockRead("Content-Length: 0\r\n\r\n"), 1161 MockRead("Content-Length: 0\r\n\r\n"),
1048 MockRead(SYNCHRONOUS, OK), 1162 MockRead(SYNCHRONOUS, OK),
1049 }; 1163 };
1050 1164
1051 HttpRequestInfo request; 1165 HttpRequestInfo request;
1052 request.method = "GET"; 1166 request.method = "GET";
1053 request.url = GURL("http://redirect.com/"); 1167 request.url = GURL("http://redirect.com/");
1054 request.load_flags = 0;
1055 1168
1056 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 1169 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
1057 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 1170 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
1058 1171
1059 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 1172 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
1060 session_deps_.socket_factory->AddSocketDataProvider(&data); 1173 session_deps_.socket_factory->AddSocketDataProvider(&data);
1061 1174
1062 TestCompletionCallback callback; 1175 TestCompletionCallback callback;
1063 1176
1064 int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); 1177 int rv = trans.Start(&request, callback.callback(), NetLogWithSource());
(...skipping 24 matching lines...) Expand all
1089 arraysize(data_reads)); 1202 arraysize(data_reads));
1090 EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); 1203 EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION));
1091 } 1204 }
1092 1205
1093 // Do a request using the HEAD method. Verify that we don't try to read the 1206 // Do a request using the HEAD method. Verify that we don't try to read the
1094 // message body (since HEAD has none). 1207 // message body (since HEAD has none).
1095 TEST_F(HttpNetworkTransactionTest, Head) { 1208 TEST_F(HttpNetworkTransactionTest, Head) {
1096 HttpRequestInfo request; 1209 HttpRequestInfo request;
1097 request.method = "HEAD"; 1210 request.method = "HEAD";
1098 request.url = GURL("http://www.example.org/"); 1211 request.url = GURL("http://www.example.org/");
1099 request.load_flags = 0;
1100 1212
1101 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 1213 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
1102 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 1214 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
1103 BeforeHeadersSentHandler headers_handler; 1215 BeforeHeadersSentHandler headers_handler;
1104 trans.SetBeforeHeadersSentCallback( 1216 trans.SetBeforeHeadersSentCallback(
1105 base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, 1217 base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent,
1106 base::Unretained(&headers_handler))); 1218 base::Unretained(&headers_handler)));
1107 1219
1108 MockWrite data_writes1[] = { 1220 MockWrite data_writes1[] = {
1109 MockWrite("HEAD / HTTP/1.1\r\n" 1221 MockWrite("HEAD / HTTP/1.1\r\n"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 session_deps_.socket_factory->AddSocketDataProvider(&data); 1282 session_deps_.socket_factory->AddSocketDataProvider(&data);
1171 1283
1172 const char* const kExpectedResponseData[] = { 1284 const char* const kExpectedResponseData[] = {
1173 "hello", "world" 1285 "hello", "world"
1174 }; 1286 };
1175 1287
1176 for (int i = 0; i < 2; ++i) { 1288 for (int i = 0; i < 2; ++i) {
1177 HttpRequestInfo request; 1289 HttpRequestInfo request;
1178 request.method = "GET"; 1290 request.method = "GET";
1179 request.url = GURL("http://www.example.org/"); 1291 request.url = GURL("http://www.example.org/");
1180 request.load_flags = 0;
1181 1292
1182 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 1293 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
1183 1294
1184 TestCompletionCallback callback; 1295 TestCompletionCallback callback;
1185 1296
1186 int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); 1297 int rv = trans.Start(&request, callback.callback(), NetLogWithSource());
1187 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 1298 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
1188 1299
1189 rv = callback.WaitForResult(); 1300 rv = callback.WaitForResult();
1190 EXPECT_THAT(rv, IsOk()); 1301 EXPECT_THAT(rv, IsOk());
(...skipping 15 matching lines...) Expand all
1206 TEST_F(HttpNetworkTransactionTest, Ignores100) { 1317 TEST_F(HttpNetworkTransactionTest, Ignores100) {
1207 std::vector<std::unique_ptr<UploadElementReader>> element_readers; 1318 std::vector<std::unique_ptr<UploadElementReader>> element_readers;
1208 element_readers.push_back( 1319 element_readers.push_back(
1209 base::MakeUnique<UploadBytesElementReader>("foo", 3)); 1320 base::MakeUnique<UploadBytesElementReader>("foo", 3));
1210 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); 1321 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0);
1211 1322
1212 HttpRequestInfo request; 1323 HttpRequestInfo request;
1213 request.method = "POST"; 1324 request.method = "POST";
1214 request.url = GURL("http://www.foo.com/"); 1325 request.url = GURL("http://www.foo.com/");
1215 request.upload_data_stream = &upload_data_stream; 1326 request.upload_data_stream = &upload_data_stream;
1216 request.load_flags = 0;
1217 1327
1218 // Check the upload progress returned before initialization is correct. 1328 // Check the upload progress returned before initialization is correct.
1219 UploadProgress progress = request.upload_data_stream->GetUploadProgress(); 1329 UploadProgress progress = request.upload_data_stream->GetUploadProgress();
1220 EXPECT_EQ(0u, progress.size()); 1330 EXPECT_EQ(0u, progress.size());
1221 EXPECT_EQ(0u, progress.position()); 1331 EXPECT_EQ(0u, progress.position());
1222 1332
1223 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 1333 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
1224 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 1334 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
1225 1335
1226 MockRead data_reads[] = { 1336 MockRead data_reads[] = {
(...skipping 25 matching lines...) Expand all
1252 EXPECT_EQ("hello world", response_data); 1362 EXPECT_EQ("hello world", response_data);
1253 } 1363 }
1254 1364
1255 // This test is almost the same as Ignores100 above, but the response contains 1365 // This test is almost the same as Ignores100 above, but the response contains
1256 // a 102 instead of a 100. Also, instead of HTTP/1.0 the response is 1366 // a 102 instead of a 100. Also, instead of HTTP/1.0 the response is
1257 // HTTP/1.1 and the two status headers are read in one read. 1367 // HTTP/1.1 and the two status headers are read in one read.
1258 TEST_F(HttpNetworkTransactionTest, Ignores1xx) { 1368 TEST_F(HttpNetworkTransactionTest, Ignores1xx) {
1259 HttpRequestInfo request; 1369 HttpRequestInfo request;
1260 request.method = "GET"; 1370 request.method = "GET";
1261 request.url = GURL("http://www.foo.com/"); 1371 request.url = GURL("http://www.foo.com/");
1262 request.load_flags = 0;
1263 1372
1264 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 1373 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
1265 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 1374 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
1266 1375
1267 MockRead data_reads[] = { 1376 MockRead data_reads[] = {
1268 MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" 1377 MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n"
1269 "HTTP/1.1 200 OK\r\n\r\n"), 1378 "HTTP/1.1 200 OK\r\n\r\n"),
1270 MockRead("hello world"), 1379 MockRead("hello world"),
1271 MockRead(SYNCHRONOUS, OK), 1380 MockRead(SYNCHRONOUS, OK),
1272 }; 1381 };
(...skipping 17 matching lines...) Expand all
1290 std::string response_data; 1399 std::string response_data;
1291 rv = ReadTransaction(&trans, &response_data); 1400 rv = ReadTransaction(&trans, &response_data);
1292 EXPECT_THAT(rv, IsOk()); 1401 EXPECT_THAT(rv, IsOk());
1293 EXPECT_EQ("hello world", response_data); 1402 EXPECT_EQ("hello world", response_data);
1294 } 1403 }
1295 1404
1296 TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { 1405 TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) {
1297 HttpRequestInfo request; 1406 HttpRequestInfo request;
1298 request.method = "POST"; 1407 request.method = "POST";
1299 request.url = GURL("http://www.foo.com/"); 1408 request.url = GURL("http://www.foo.com/");
1300 request.load_flags = 0;
1301 1409
1302 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 1410 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
1303 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 1411 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
1304 1412
1305 MockRead data_reads[] = { 1413 MockRead data_reads[] = {
1306 MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), 1414 MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"),
1307 MockRead(ASYNC, 0), 1415 MockRead(ASYNC, 0),
1308 }; 1416 };
1309 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 1417 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
1310 session_deps_.socket_factory->AddSocketDataProvider(&data); 1418 session_deps_.socket_factory->AddSocketDataProvider(&data);
1311 1419
1312 TestCompletionCallback callback; 1420 TestCompletionCallback callback;
1313 1421
1314 int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); 1422 int rv = trans.Start(&request, callback.callback(), NetLogWithSource());
1315 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 1423 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
1316 1424
1317 rv = callback.WaitForResult(); 1425 rv = callback.WaitForResult();
1318 EXPECT_THAT(rv, IsOk()); 1426 EXPECT_THAT(rv, IsOk());
1319 1427
1320 std::string response_data; 1428 std::string response_data;
1321 rv = ReadTransaction(&trans, &response_data); 1429 rv = ReadTransaction(&trans, &response_data);
1322 EXPECT_THAT(rv, IsOk()); 1430 EXPECT_THAT(rv, IsOk());
1323 EXPECT_EQ("", response_data); 1431 EXPECT_EQ("", response_data);
1324 } 1432 }
1325 1433
1326 TEST_F(HttpNetworkTransactionTest, EmptyResponse) { 1434 TEST_F(HttpNetworkTransactionTest, EmptyResponse) {
1327 HttpRequestInfo request; 1435 HttpRequestInfo request;
1328 request.method = "POST"; 1436 request.method = "POST";
1329 request.url = GURL("http://www.foo.com/"); 1437 request.url = GURL("http://www.foo.com/");
1330 request.load_flags = 0;
1331 1438
1332 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 1439 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
1333 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 1440 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
1334 1441
1335 MockRead data_reads[] = { 1442 MockRead data_reads[] = {
1336 MockRead(ASYNC, 0), 1443 MockRead(ASYNC, 0),
1337 }; 1444 };
1338 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 1445 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
1339 session_deps_.socket_factory->AddSocketDataProvider(&data); 1446 session_deps_.socket_factory->AddSocketDataProvider(&data);
1340 1447
1341 TestCompletionCallback callback; 1448 TestCompletionCallback callback;
1342 1449
1343 int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); 1450 int rv = trans.Start(&request, callback.callback(), NetLogWithSource());
1344 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 1451 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
1345 1452
1346 rv = callback.WaitForResult(); 1453 rv = callback.WaitForResult();
1347 EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); 1454 EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE));
1348 } 1455 }
1349 1456
1350 void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( 1457 void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest(
1351 const MockWrite* write_failure, 1458 const MockWrite* write_failure,
1352 const MockRead* read_failure) { 1459 const MockRead* read_failure) {
1353 HttpRequestInfo request; 1460 HttpRequestInfo request;
1354 request.method = "GET"; 1461 request.method = "GET";
1355 request.url = GURL("http://www.foo.com/"); 1462 request.url = GURL("http://www.foo.com/");
1356 request.load_flags = 0;
1357 1463
1358 TestNetLog net_log; 1464 TestNetLog net_log;
1359 session_deps_.net_log = &net_log; 1465 session_deps_.net_log = &net_log;
1360 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 1466 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
1361 1467
1362 // Written data for successfully sending both requests. 1468 // Written data for successfully sending both requests.
1363 MockWrite data1_writes[] = { 1469 MockWrite data1_writes[] = {
1364 MockWrite("GET / HTTP/1.1\r\n" 1470 MockWrite("GET / HTTP/1.1\r\n"
1365 "Host: www.foo.com\r\n" 1471 "Host: www.foo.com\r\n"
1366 "Connection: keep-alive\r\n\r\n"), 1472 "Connection: keep-alive\r\n\r\n"),
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1436 } 1542 }
1437 } 1543 }
1438 1544
1439 void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( 1545 void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest(
1440 const MockWrite* write_failure, 1546 const MockWrite* write_failure,
1441 const MockRead* read_failure, 1547 const MockRead* read_failure,
1442 bool use_spdy) { 1548 bool use_spdy) {
1443 HttpRequestInfo request; 1549 HttpRequestInfo request;
1444 request.method = "GET"; 1550 request.method = "GET";
1445 request.url = GURL("https://www.foo.com/"); 1551 request.url = GURL("https://www.foo.com/");
1446 request.load_flags = 0;
1447 1552
1448 TestNetLog net_log; 1553 TestNetLog net_log;
1449 session_deps_.net_log = &net_log; 1554 session_deps_.net_log = &net_log;
1450 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 1555 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
1451 1556
1452 SSLSocketDataProvider ssl1(ASYNC, OK); 1557 SSLSocketDataProvider ssl1(ASYNC, OK);
1453 SSLSocketDataProvider ssl2(ASYNC, OK); 1558 SSLSocketDataProvider ssl2(ASYNC, OK);
1454 if (use_spdy) { 1559 if (use_spdy) {
1455 ssl1.next_proto = kProtoHTTP2; 1560 ssl1.next_proto = kProtoHTTP2;
1456 ssl2.next_proto = kProtoHTTP2; 1561 ssl2.next_proto = kProtoHTTP2;
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
1630 1735
1631 TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { 1736 TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) {
1632 MockRead read_failure(ASYNC, OK); // EOF 1737 MockRead read_failure(ASYNC, OK); // EOF
1633 PreconnectErrorResendRequestTest(NULL, &read_failure, true); 1738 PreconnectErrorResendRequestTest(NULL, &read_failure, true);
1634 } 1739 }
1635 1740
1636 TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { 1741 TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) {
1637 HttpRequestInfo request; 1742 HttpRequestInfo request;
1638 request.method = "GET"; 1743 request.method = "GET";
1639 request.url = GURL("http://www.example.org/"); 1744 request.url = GURL("http://www.example.org/");
1640 request.load_flags = 0;
1641 1745
1642 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 1746 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
1643 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 1747 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
1644 1748
1645 MockRead data_reads[] = { 1749 MockRead data_reads[] = {
1646 MockRead(ASYNC, ERR_CONNECTION_RESET), 1750 MockRead(ASYNC, ERR_CONNECTION_RESET),
1647 MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used 1751 MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used
1648 MockRead("hello world"), 1752 MockRead("hello world"),
1649 MockRead(SYNCHRONOUS, OK), 1753 MockRead(SYNCHRONOUS, OK),
1650 }; 1754 };
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1686 } 1790 }
1687 1791
1688 // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression 1792 // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression
1689 // tests. There was a bug causing HttpNetworkTransaction to hang in the 1793 // tests. There was a bug causing HttpNetworkTransaction to hang in the
1690 // destructor in such situations. 1794 // destructor in such situations.
1691 // See http://crbug.com/154712 and http://crbug.com/156609. 1795 // See http://crbug.com/154712 and http://crbug.com/156609.
1692 TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { 1796 TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) {
1693 HttpRequestInfo request; 1797 HttpRequestInfo request;
1694 request.method = "GET"; 1798 request.method = "GET";
1695 request.url = GURL("http://www.example.org/"); 1799 request.url = GURL("http://www.example.org/");
1696 request.load_flags = 0;
1697 1800
1698 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 1801 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
1699 std::unique_ptr<HttpNetworkTransaction> trans( 1802 std::unique_ptr<HttpNetworkTransaction> trans(
1700 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 1803 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
1701 1804
1702 MockRead data_reads[] = { 1805 MockRead data_reads[] = {
1703 MockRead("HTTP/1.0 200 OK\r\n"), 1806 MockRead("HTTP/1.0 200 OK\r\n"),
1704 MockRead("Connection: keep-alive\r\n"), 1807 MockRead("Connection: keep-alive\r\n"),
1705 MockRead("Content-Length: 100\r\n\r\n"), 1808 MockRead("Content-Length: 100\r\n\r\n"),
1706 MockRead("hello"), 1809 MockRead("hello"),
(...skipping 20 matching lines...) Expand all
1727 1830
1728 trans.reset(); 1831 trans.reset();
1729 base::RunLoop().RunUntilIdle(); 1832 base::RunLoop().RunUntilIdle();
1730 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); 1833 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get()));
1731 } 1834 }
1732 1835
1733 TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { 1836 TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) {
1734 HttpRequestInfo request; 1837 HttpRequestInfo request;
1735 request.method = "GET"; 1838 request.method = "GET";
1736 request.url = GURL("http://www.example.org/"); 1839 request.url = GURL("http://www.example.org/");
1737 request.load_flags = 0;
1738 1840
1739 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 1841 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
1740 std::unique_ptr<HttpNetworkTransaction> trans( 1842 std::unique_ptr<HttpNetworkTransaction> trans(
1741 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 1843 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
1742 1844
1743 MockRead data_reads[] = { 1845 MockRead data_reads[] = {
1744 MockRead("HTTP/1.0 200 OK\r\n"), 1846 MockRead("HTTP/1.0 200 OK\r\n"),
1745 MockRead("Connection: keep-alive\r\n"), 1847 MockRead("Connection: keep-alive\r\n"),
1746 MockRead("Content-Length: 100\r\n\r\n"), 1848 MockRead("Content-Length: 100\r\n\r\n"),
1747 MockRead(SYNCHRONOUS, 0), 1849 MockRead(SYNCHRONOUS, 0),
(...skipping 19 matching lines...) Expand all
1767 base::RunLoop().RunUntilIdle(); 1869 base::RunLoop().RunUntilIdle();
1768 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); 1870 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get()));
1769 } 1871 }
1770 1872
1771 // Test that we correctly reuse a keep-alive connection after not explicitly 1873 // Test that we correctly reuse a keep-alive connection after not explicitly
1772 // reading the body. 1874 // reading the body.
1773 TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { 1875 TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) {
1774 HttpRequestInfo request; 1876 HttpRequestInfo request;
1775 request.method = "GET"; 1877 request.method = "GET";
1776 request.url = GURL("http://www.foo.com/"); 1878 request.url = GURL("http://www.foo.com/");
1777 request.load_flags = 0;
1778 1879
1779 TestNetLog net_log; 1880 TestNetLog net_log;
1780 session_deps_.net_log = &net_log; 1881 session_deps_.net_log = &net_log;
1781 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 1882 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
1782 1883
1783 const char* request_data = 1884 const char* request_data =
1784 "GET / HTTP/1.1\r\n" 1885 "GET / HTTP/1.1\r\n"
1785 "Host: www.foo.com\r\n" 1886 "Host: www.foo.com\r\n"
1786 "Connection: keep-alive\r\n\r\n"; 1887 "Connection: keep-alive\r\n\r\n";
1787 MockWrite data_writes[] = { 1888 MockWrite data_writes[] = {
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
2184 // There should be no idle sockets in the pool. 2285 // There should be no idle sockets in the pool.
2185 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); 2286 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get()));
2186 } 2287 }
2187 2288
2188 // Test the request-challenge-retry sequence for basic auth. 2289 // Test the request-challenge-retry sequence for basic auth.
2189 // (basic auth is the easiest to mock, because it has no randomness). 2290 // (basic auth is the easiest to mock, because it has no randomness).
2190 TEST_F(HttpNetworkTransactionTest, BasicAuth) { 2291 TEST_F(HttpNetworkTransactionTest, BasicAuth) {
2191 HttpRequestInfo request; 2292 HttpRequestInfo request;
2192 request.method = "GET"; 2293 request.method = "GET";
2193 request.url = GURL("http://www.example.org/"); 2294 request.url = GURL("http://www.example.org/");
2194 request.load_flags = 0;
2195 2295
2196 TestNetLog log; 2296 TestNetLog log;
2197 session_deps_.net_log = &log; 2297 session_deps_.net_log = &log;
2198 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 2298 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
2199 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 2299 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
2200 2300
2201 MockWrite data_writes1[] = { 2301 MockWrite data_writes1[] = {
2202 MockWrite( 2302 MockWrite(
2203 "GET / HTTP/1.1\r\n" 2303 "GET / HTTP/1.1\r\n"
2204 "Host: www.example.org\r\n" 2304 "Host: www.example.org\r\n"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
2291 EXPECT_FALSE(response->auth_challenge); 2391 EXPECT_FALSE(response->auth_challenge);
2292 EXPECT_EQ(100, response->headers->GetContentLength()); 2392 EXPECT_EQ(100, response->headers->GetContentLength());
2293 } 2393 }
2294 2394
2295 // Test the request-challenge-retry sequence for basic auth. 2395 // Test the request-challenge-retry sequence for basic auth.
2296 // (basic auth is the easiest to mock, because it has no randomness). 2396 // (basic auth is the easiest to mock, because it has no randomness).
2297 TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { 2397 TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) {
2298 HttpRequestInfo request; 2398 HttpRequestInfo request;
2299 request.method = "GET"; 2399 request.method = "GET";
2300 request.url = GURL("http://www.example.org/"); 2400 request.url = GURL("http://www.example.org/");
2301 request.load_flags = 0;
2302 2401
2303 TestNetLog log; 2402 TestNetLog log;
2304 MockHostResolver* resolver = new MockHostResolver(); 2403 MockHostResolver* resolver = new MockHostResolver();
2305 session_deps_.net_log = &log; 2404 session_deps_.net_log = &log;
2306 session_deps_.host_resolver.reset(resolver); 2405 session_deps_.host_resolver.reset(resolver);
2307 std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); 2406 std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_);
2308 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 2407 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
2309 2408
2310 resolver->rules()->ClearRules(); 2409 resolver->rules()->ClearRules();
2311 resolver->rules()->AddRule("www.example.org", "127.0.0.1"); 2410 resolver->rules()->AddRule("www.example.org", "127.0.0.1");
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
2456 // Test the request-challenge-retry sequence for basic auth, over a keep-alive 2555 // Test the request-challenge-retry sequence for basic auth, over a keep-alive
2457 // connection. 2556 // connection.
2458 TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { 2557 TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) {
2459 // On the second pass, the body read of the auth challenge is synchronous, so 2558 // On the second pass, the body read of the auth challenge is synchronous, so
2460 // IsConnectedAndIdle returns false. The socket should still be drained and 2559 // IsConnectedAndIdle returns false. The socket should still be drained and
2461 // reused. See http://crbug.com/544255. 2560 // reused. See http://crbug.com/544255.
2462 for (int i = 0; i < 2; ++i) { 2561 for (int i = 0; i < 2; ++i) {
2463 HttpRequestInfo request; 2562 HttpRequestInfo request;
2464 request.method = "GET"; 2563 request.method = "GET";
2465 request.url = GURL("http://www.example.org/"); 2564 request.url = GURL("http://www.example.org/");
2466 request.load_flags = 0;
2467 2565
2468 TestNetLog log; 2566 TestNetLog log;
2469 session_deps_.net_log = &log; 2567 session_deps_.net_log = &log;
2470 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 2568 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
2471 2569
2472 MockWrite data_writes[] = { 2570 MockWrite data_writes[] = {
2473 MockWrite(ASYNC, 0, 2571 MockWrite(ASYNC, 0,
2474 "GET / HTTP/1.1\r\n" 2572 "GET / HTTP/1.1\r\n"
2475 "Host: www.example.org\r\n" 2573 "Host: www.example.org\r\n"
2476 "Connection: keep-alive\r\n\r\n"), 2574 "Connection: keep-alive\r\n\r\n"),
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
2546 EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); 2644 EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes());
2547 } 2645 }
2548 } 2646 }
2549 2647
2550 // Test the request-challenge-retry sequence for basic auth, over a keep-alive 2648 // Test the request-challenge-retry sequence for basic auth, over a keep-alive
2551 // connection and with no response body to drain. 2649 // connection and with no response body to drain.
2552 TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { 2650 TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) {
2553 HttpRequestInfo request; 2651 HttpRequestInfo request;
2554 request.method = "GET"; 2652 request.method = "GET";
2555 request.url = GURL("http://www.example.org/"); 2653 request.url = GURL("http://www.example.org/");
2556 request.load_flags = 0;
2557 2654
2558 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 2655 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
2559 2656
2560 MockWrite data_writes1[] = { 2657 MockWrite data_writes1[] = {
2561 MockWrite("GET / HTTP/1.1\r\n" 2658 MockWrite("GET / HTTP/1.1\r\n"
2562 "Host: www.example.org\r\n" 2659 "Host: www.example.org\r\n"
2563 "Connection: keep-alive\r\n\r\n"), 2660 "Connection: keep-alive\r\n\r\n"),
2564 2661
2565 // After calling trans.RestartWithAuth(), this is the request we should 2662 // After calling trans.RestartWithAuth(), this is the request we should
2566 // be issuing -- the final header line contains the credentials. 2663 // be issuing -- the final header line contains the credentials.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2620 EXPECT_FALSE(response->auth_challenge); 2717 EXPECT_FALSE(response->auth_challenge);
2621 EXPECT_EQ(5, response->headers->GetContentLength()); 2718 EXPECT_EQ(5, response->headers->GetContentLength());
2622 } 2719 }
2623 2720
2624 // Test the request-challenge-retry sequence for basic auth, over a keep-alive 2721 // Test the request-challenge-retry sequence for basic auth, over a keep-alive
2625 // connection and with a large response body to drain. 2722 // connection and with a large response body to drain.
2626 TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { 2723 TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) {
2627 HttpRequestInfo request; 2724 HttpRequestInfo request;
2628 request.method = "GET"; 2725 request.method = "GET";
2629 request.url = GURL("http://www.example.org/"); 2726 request.url = GURL("http://www.example.org/");
2630 request.load_flags = 0;
2631 2727
2632 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 2728 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
2633 2729
2634 MockWrite data_writes1[] = { 2730 MockWrite data_writes1[] = {
2635 MockWrite("GET / HTTP/1.1\r\n" 2731 MockWrite("GET / HTTP/1.1\r\n"
2636 "Host: www.example.org\r\n" 2732 "Host: www.example.org\r\n"
2637 "Connection: keep-alive\r\n\r\n"), 2733 "Connection: keep-alive\r\n\r\n"),
2638 2734
2639 // After calling trans.RestartWithAuth(), this is the request we should 2735 // After calling trans.RestartWithAuth(), this is the request we should
2640 // be issuing -- the final header line contains the credentials. 2736 // be issuing -- the final header line contains the credentials.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
2702 EXPECT_FALSE(response->auth_challenge); 2798 EXPECT_FALSE(response->auth_challenge);
2703 EXPECT_EQ(5, response->headers->GetContentLength()); 2799 EXPECT_EQ(5, response->headers->GetContentLength());
2704 } 2800 }
2705 2801
2706 // Test the request-challenge-retry sequence for basic auth, over a keep-alive 2802 // Test the request-challenge-retry sequence for basic auth, over a keep-alive
2707 // connection, but the server gets impatient and closes the connection. 2803 // connection, but the server gets impatient and closes the connection.
2708 TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { 2804 TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) {
2709 HttpRequestInfo request; 2805 HttpRequestInfo request;
2710 request.method = "GET"; 2806 request.method = "GET";
2711 request.url = GURL("http://www.example.org/"); 2807 request.url = GURL("http://www.example.org/");
2712 request.load_flags = 0;
2713 2808
2714 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 2809 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
2715 2810
2716 MockWrite data_writes1[] = { 2811 MockWrite data_writes1[] = {
2717 MockWrite( 2812 MockWrite(
2718 "GET / HTTP/1.1\r\n" 2813 "GET / HTTP/1.1\r\n"
2719 "Host: www.example.org\r\n" 2814 "Host: www.example.org\r\n"
2720 "Connection: keep-alive\r\n\r\n"), 2815 "Connection: keep-alive\r\n\r\n"),
2721 // This simulates the seemingly successful write to a closed connection 2816 // This simulates the seemingly successful write to a closed connection
2722 // if the bug is not fixed. 2817 // if the bug is not fixed.
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after
3473 EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); 3568 EXPECT_THAT(ReadTransaction(&trans, &body), IsOk());
3474 EXPECT_EQ("hello", body); 3569 EXPECT_EQ("hello", body);
3475 } 3570 }
3476 3571
3477 // Test that we don't read the response body when we fail to establish a tunnel, 3572 // Test that we don't read the response body when we fail to establish a tunnel,
3478 // even if the user cancels the proxy's auth attempt. 3573 // even if the user cancels the proxy's auth attempt.
3479 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { 3574 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) {
3480 HttpRequestInfo request; 3575 HttpRequestInfo request;
3481 request.method = "GET"; 3576 request.method = "GET";
3482 request.url = GURL("https://www.example.org/"); 3577 request.url = GURL("https://www.example.org/");
3483 request.load_flags = 0;
3484 3578
3485 // Configure against proxy server "myproxy:70". 3579 // Configure against proxy server "myproxy:70".
3486 session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); 3580 session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70");
3487 3581
3488 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 3582 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
3489 3583
3490 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 3584 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
3491 3585
3492 // Since we have proxy, should try to establish tunnel. 3586 // Since we have proxy, should try to establish tunnel.
3493 MockWrite data_writes[] = { 3587 MockWrite data_writes[] = {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3531 // Flush the idle socket before the HttpNetworkTransaction goes out of scope. 3625 // Flush the idle socket before the HttpNetworkTransaction goes out of scope.
3532 session->CloseAllConnections(); 3626 session->CloseAllConnections();
3533 } 3627 }
3534 3628
3535 // Test that we don't pass extraneous headers from the proxy's response to the 3629 // Test that we don't pass extraneous headers from the proxy's response to the
3536 // caller when the proxy responds to CONNECT with 407. 3630 // caller when the proxy responds to CONNECT with 407.
3537 TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { 3631 TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) {
3538 HttpRequestInfo request; 3632 HttpRequestInfo request;
3539 request.method = "GET"; 3633 request.method = "GET";
3540 request.url = GURL("https://www.example.org/"); 3634 request.url = GURL("https://www.example.org/");
3541 request.load_flags = 0;
3542 3635
3543 // Configure against proxy server "myproxy:70". 3636 // Configure against proxy server "myproxy:70".
3544 session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); 3637 session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70");
3545 3638
3546 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 3639 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
3547 3640
3548 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 3641 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
3549 3642
3550 // Since we have proxy, should try to establish tunnel. 3643 // Since we have proxy, should try to establish tunnel.
3551 MockWrite data_writes[] = { 3644 MockWrite data_writes[] = {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
3592 // Flush the idle socket before the HttpNetworkTransaction goes out of scope. 3685 // Flush the idle socket before the HttpNetworkTransaction goes out of scope.
3593 session->CloseAllConnections(); 3686 session->CloseAllConnections();
3594 } 3687 }
3595 3688
3596 // Test when a server (non-proxy) returns a 407 (proxy-authenticate). 3689 // Test when a server (non-proxy) returns a 407 (proxy-authenticate).
3597 // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. 3690 // The request should fail with ERR_UNEXPECTED_PROXY_AUTH.
3598 TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { 3691 TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) {
3599 HttpRequestInfo request; 3692 HttpRequestInfo request;
3600 request.method = "GET"; 3693 request.method = "GET";
3601 request.url = GURL("http://www.example.org/"); 3694 request.url = GURL("http://www.example.org/");
3602 request.load_flags = 0;
3603 3695
3604 // We are using a DIRECT connection (i.e. no proxy) for this session. 3696 // We are using a DIRECT connection (i.e. no proxy) for this session.
3605 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 3697 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
3606 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 3698 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
3607 3699
3608 MockWrite data_writes1[] = { 3700 MockWrite data_writes1[] = {
3609 MockWrite( 3701 MockWrite(
3610 "GET / HTTP/1.1\r\n" 3702 "GET / HTTP/1.1\r\n"
3611 "Host: www.example.org\r\n" 3703 "Host: www.example.org\r\n"
3612 "Connection: keep-alive\r\n\r\n"), 3704 "Connection: keep-alive\r\n\r\n"),
(...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after
4525 4617
4526 // The password prompt info should not be set. 4618 // The password prompt info should not be set.
4527 EXPECT_FALSE(response->auth_challenge); 4619 EXPECT_FALSE(response->auth_challenge);
4528 } 4620 }
4529 4621
4530 // Test a SPDY get through an HTTPS Proxy. 4622 // Test a SPDY get through an HTTPS Proxy.
4531 TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { 4623 TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) {
4532 HttpRequestInfo request; 4624 HttpRequestInfo request;
4533 request.method = "GET"; 4625 request.method = "GET";
4534 request.url = GURL("http://www.example.org/"); 4626 request.url = GURL("http://www.example.org/");
4535 request.load_flags = 0;
4536 4627
4537 // Configure against https proxy server "proxy:70". 4628 // Configure against https proxy server "proxy:70".
4538 session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); 4629 session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70");
4539 BoundTestNetLog log; 4630 BoundTestNetLog log;
4540 session_deps_.net_log = log.bound().net_log(); 4631 session_deps_.net_log = log.bound().net_log();
4541 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 4632 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
4542 4633
4543 // fetch http://www.example.org/ via SPDY 4634 // fetch http://www.example.org/ via SPDY
4544 SpdySerializedFrame req( 4635 SpdySerializedFrame req(
4545 spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); 4636 spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
4585 EXPECT_EQ(kUploadData, response_data); 4676 EXPECT_EQ(kUploadData, response_data);
4586 } 4677 }
4587 4678
4588 // Verifies that a session which races and wins against the owning transaction 4679 // Verifies that a session which races and wins against the owning transaction
4589 // (completing prior to host resolution), doesn't fail the transaction. 4680 // (completing prior to host resolution), doesn't fail the transaction.
4590 // Regression test for crbug.com/334413. 4681 // Regression test for crbug.com/334413.
4591 TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { 4682 TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) {
4592 HttpRequestInfo request; 4683 HttpRequestInfo request;
4593 request.method = "GET"; 4684 request.method = "GET";
4594 request.url = GURL("http://www.example.org/"); 4685 request.url = GURL("http://www.example.org/");
4595 request.load_flags = 0;
4596 4686
4597 // Configure SPDY proxy server "proxy:70". 4687 // Configure SPDY proxy server "proxy:70".
4598 session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); 4688 session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70");
4599 BoundTestNetLog log; 4689 BoundTestNetLog log;
4600 session_deps_.net_log = log.bound().net_log(); 4690 session_deps_.net_log = log.bound().net_log();
4601 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 4691 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
4602 4692
4603 // Fetch http://www.example.org/ through the SPDY proxy. 4693 // Fetch http://www.example.org/ through the SPDY proxy.
4604 SpdySerializedFrame req( 4694 SpdySerializedFrame req(
4605 spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); 4695 spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
4653 std::string response_data; 4743 std::string response_data;
4654 ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); 4744 ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk());
4655 EXPECT_EQ(kUploadData, response_data); 4745 EXPECT_EQ(kUploadData, response_data);
4656 } 4746 }
4657 4747
4658 // Test a SPDY get through an HTTPS Proxy. 4748 // Test a SPDY get through an HTTPS Proxy.
4659 TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { 4749 TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) {
4660 HttpRequestInfo request; 4750 HttpRequestInfo request;
4661 request.method = "GET"; 4751 request.method = "GET";
4662 request.url = GURL("http://www.example.org/"); 4752 request.url = GURL("http://www.example.org/");
4663 request.load_flags = 0;
4664 4753
4665 // Configure against https proxy server "myproxy:70". 4754 // Configure against https proxy server "myproxy:70".
4666 session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); 4755 session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70");
4667 BoundTestNetLog log; 4756 BoundTestNetLog log;
4668 session_deps_.net_log = log.bound().net_log(); 4757 session_deps_.net_log = log.bound().net_log();
4669 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 4758 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
4670 4759
4671 // The first request will be a bare GET, the second request will be a 4760 // The first request will be a bare GET, the second request will be a
4672 // GET with a Proxy-Authorization header. 4761 // GET with a Proxy-Authorization header.
4673 spdy_util_.set_default_url(request.url); 4762 spdy_util_.set_default_url(request.url);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
4746 EXPECT_EQ(200, response_restart->headers->response_code()); 4835 EXPECT_EQ(200, response_restart->headers->response_code());
4747 // The password prompt info should not be set. 4836 // The password prompt info should not be set.
4748 EXPECT_FALSE(response_restart->auth_challenge); 4837 EXPECT_FALSE(response_restart->auth_challenge);
4749 } 4838 }
4750 4839
4751 // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. 4840 // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server.
4752 TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { 4841 TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) {
4753 HttpRequestInfo request; 4842 HttpRequestInfo request;
4754 request.method = "GET"; 4843 request.method = "GET";
4755 request.url = GURL("https://www.example.org/"); 4844 request.url = GURL("https://www.example.org/");
4756 request.load_flags = 0;
4757 4845
4758 // Configure against https proxy server "proxy:70". 4846 // Configure against https proxy server "proxy:70".
4759 session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); 4847 session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70");
4760 BoundTestNetLog log; 4848 BoundTestNetLog log;
4761 session_deps_.net_log = log.bound().net_log(); 4849 session_deps_.net_log = log.bound().net_log();
4762 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 4850 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
4763 4851
4764 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 4852 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
4765 4853
4766 // CONNECT to www.example.org:443 via SPDY 4854 // CONNECT to www.example.org:443 via SPDY
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
4829 EXPECT_EQ("1234567890", response_data); 4917 EXPECT_EQ("1234567890", response_data);
4830 } 4918 }
4831 4919
4832 // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. 4920 // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server.
4833 TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { 4921 TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) {
4834 SpdyTestUtil spdy_util_wrapped; 4922 SpdyTestUtil spdy_util_wrapped;
4835 4923
4836 HttpRequestInfo request; 4924 HttpRequestInfo request;
4837 request.method = "GET"; 4925 request.method = "GET";
4838 request.url = GURL("https://www.example.org/"); 4926 request.url = GURL("https://www.example.org/");
4839 request.load_flags = 0;
4840 4927
4841 // Configure against https proxy server "proxy:70". 4928 // Configure against https proxy server "proxy:70".
4842 session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); 4929 session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70");
4843 BoundTestNetLog log; 4930 BoundTestNetLog log;
4844 session_deps_.net_log = log.bound().net_log(); 4931 session_deps_.net_log = log.bound().net_log();
4845 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 4932 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
4846 4933
4847 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 4934 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
4848 4935
4849 // CONNECT to www.example.org:443 via SPDY 4936 // CONNECT to www.example.org:443 via SPDY
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
4916 std::string response_data; 5003 std::string response_data;
4917 ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); 5004 ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk());
4918 EXPECT_EQ(kUploadData, response_data); 5005 EXPECT_EQ(kUploadData, response_data);
4919 } 5006 }
4920 5007
4921 // Test a SPDY CONNECT failure through an HTTPS Proxy. 5008 // Test a SPDY CONNECT failure through an HTTPS Proxy.
4922 TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { 5009 TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) {
4923 HttpRequestInfo request; 5010 HttpRequestInfo request;
4924 request.method = "GET"; 5011 request.method = "GET";
4925 request.url = GURL("https://www.example.org/"); 5012 request.url = GURL("https://www.example.org/");
4926 request.load_flags = 0;
4927 5013
4928 // Configure against https proxy server "proxy:70". 5014 // Configure against https proxy server "proxy:70".
4929 session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); 5015 session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70");
4930 BoundTestNetLog log; 5016 BoundTestNetLog log;
4931 session_deps_.net_log = log.bound().net_log(); 5017 session_deps_.net_log = log.bound().net_log();
4932 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 5018 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
4933 5019
4934 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 5020 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
4935 5021
4936 // CONNECT to www.example.org:443 via SPDY 5022 // CONNECT to www.example.org:443 via SPDY
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
5414 5500
5415 // The password prompt info should not be set. 5501 // The password prompt info should not be set.
5416 EXPECT_FALSE(response->auth_challenge); 5502 EXPECT_FALSE(response->auth_challenge);
5417 } 5503 }
5418 5504
5419 void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( 5505 void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus(
5420 const MockRead& status, int expected_status) { 5506 const MockRead& status, int expected_status) {
5421 HttpRequestInfo request; 5507 HttpRequestInfo request;
5422 request.method = "GET"; 5508 request.method = "GET";
5423 request.url = GURL("https://www.example.org/"); 5509 request.url = GURL("https://www.example.org/");
5424 request.load_flags = 0;
5425 5510
5426 // Configure against proxy server "myproxy:70". 5511 // Configure against proxy server "myproxy:70".
5427 session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); 5512 session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70");
5428 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 5513 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
5429 5514
5430 // Since we have proxy, should try to establish tunnel. 5515 // Since we have proxy, should try to establish tunnel.
5431 MockWrite data_writes[] = { 5516 MockWrite data_writes[] = {
5432 MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" 5517 MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n"
5433 "Host: www.example.org:443\r\n" 5518 "Host: www.example.org:443\r\n"
5434 "Proxy-Connection: keep-alive\r\n\r\n"), 5519 "Proxy-Connection: keep-alive\r\n\r\n"),
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
5629 ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); 5714 ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n"));
5630 } 5715 }
5631 5716
5632 // Test the flow when both the proxy server AND origin server require 5717 // Test the flow when both the proxy server AND origin server require
5633 // authentication. Again, this uses basic auth for both since that is 5718 // authentication. Again, this uses basic auth for both since that is
5634 // the simplest to mock. 5719 // the simplest to mock.
5635 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { 5720 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) {
5636 HttpRequestInfo request; 5721 HttpRequestInfo request;
5637 request.method = "GET"; 5722 request.method = "GET";
5638 request.url = GURL("http://www.example.org/"); 5723 request.url = GURL("http://www.example.org/");
5639 request.load_flags = 0;
5640 5724
5641 // Configure against proxy server "myproxy:70". 5725 // Configure against proxy server "myproxy:70".
5642 session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); 5726 session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70");
5643 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 5727 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
5644 5728
5645 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 5729 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
5646 5730
5647 MockWrite data_writes1[] = { 5731 MockWrite data_writes1[] = {
5648 MockWrite( 5732 MockWrite(
5649 "GET http://www.example.org/ HTTP/1.1\r\n" 5733 "GET http://www.example.org/ HTTP/1.1\r\n"
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
5891 ASSERT_TRUE(response); 5975 ASSERT_TRUE(response);
5892 EXPECT_FALSE(response->auth_challenge); 5976 EXPECT_FALSE(response->auth_challenge);
5893 EXPECT_EQ(13, response->headers->GetContentLength()); 5977 EXPECT_EQ(13, response->headers->GetContentLength());
5894 } 5978 }
5895 5979
5896 // Enter a wrong password, and then the correct one. 5980 // Enter a wrong password, and then the correct one.
5897 TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { 5981 TEST_F(HttpNetworkTransactionTest, NTLMAuth2) {
5898 HttpRequestInfo request; 5982 HttpRequestInfo request;
5899 request.method = "GET"; 5983 request.method = "GET";
5900 request.url = GURL("http://172.22.68.17/kids/login.aspx"); 5984 request.url = GURL("http://172.22.68.17/kids/login.aspx");
5901 request.load_flags = 0;
5902 5985
5903 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, 5986 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2,
5904 MockGetHostName); 5987 MockGetHostName);
5905 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 5988 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
5906 5989
5907 MockWrite data_writes1[] = { 5990 MockWrite data_writes1[] = {
5908 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" 5991 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n"
5909 "Host: 172.22.68.17\r\n" 5992 "Host: 172.22.68.17\r\n"
5910 "Connection: keep-alive\r\n\r\n"), 5993 "Connection: keep-alive\r\n\r\n"),
5911 }; 5994 };
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
6092 } 6175 }
6093 #endif // NTLM_PORTABLE 6176 #endif // NTLM_PORTABLE
6094 6177
6095 // Test reading a server response which has only headers, and no body. 6178 // Test reading a server response which has only headers, and no body.
6096 // After some maximum number of bytes is consumed, the transaction should 6179 // After some maximum number of bytes is consumed, the transaction should
6097 // fail with ERR_RESPONSE_HEADERS_TOO_BIG. 6180 // fail with ERR_RESPONSE_HEADERS_TOO_BIG.
6098 TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { 6181 TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) {
6099 HttpRequestInfo request; 6182 HttpRequestInfo request;
6100 request.method = "GET"; 6183 request.method = "GET";
6101 request.url = GURL("http://www.example.org/"); 6184 request.url = GURL("http://www.example.org/");
6102 request.load_flags = 0;
6103 6185
6104 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 6186 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
6105 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 6187 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
6106 6188
6107 // Respond with 300 kb of headers (we should fail after 256 kb). 6189 // Respond with 300 kb of headers (we should fail after 256 kb).
6108 std::string large_headers_string; 6190 std::string large_headers_string;
6109 FillLargeHeadersString(&large_headers_string, 300 * 1024); 6191 FillLargeHeadersString(&large_headers_string, 300 * 1024);
6110 6192
6111 MockRead data_reads[] = { 6193 MockRead data_reads[] = {
6112 MockRead("HTTP/1.0 200 OK\r\n"), 6194 MockRead("HTTP/1.0 200 OK\r\n"),
(...skipping 13 matching lines...) Expand all
6126 EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); 6208 EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG));
6127 } 6209 }
6128 6210
6129 // Make sure that we don't try to reuse a TCPClientSocket when failing to 6211 // Make sure that we don't try to reuse a TCPClientSocket when failing to
6130 // establish tunnel. 6212 // establish tunnel.
6131 // http://code.google.com/p/chromium/issues/detail?id=3772 6213 // http://code.google.com/p/chromium/issues/detail?id=3772
6132 TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { 6214 TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) {
6133 HttpRequestInfo request; 6215 HttpRequestInfo request;
6134 request.method = "GET"; 6216 request.method = "GET";
6135 request.url = GURL("https://www.example.org/"); 6217 request.url = GURL("https://www.example.org/");
6136 request.load_flags = 0;
6137 6218
6138 // Configure against proxy server "myproxy:70". 6219 // Configure against proxy server "myproxy:70".
6139 session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); 6220 session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70");
6140 6221
6141 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 6222 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
6142 6223
6143 std::unique_ptr<HttpNetworkTransaction> trans( 6224 std::unique_ptr<HttpNetworkTransaction> trans(
6144 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 6225 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
6145 6226
6146 // Since we have proxy, should try to establish tunnel. 6227 // Since we have proxy, should try to establish tunnel.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
6182 base::RunLoop().RunUntilIdle(); 6263 base::RunLoop().RunUntilIdle();
6183 // Make sure that the socket didn't get recycled after calling the destructor. 6264 // Make sure that the socket didn't get recycled after calling the destructor.
6184 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); 6265 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get()));
6185 } 6266 }
6186 6267
6187 // Make sure that we recycle a socket after reading all of the response body. 6268 // Make sure that we recycle a socket after reading all of the response body.
6188 TEST_F(HttpNetworkTransactionTest, RecycleSocket) { 6269 TEST_F(HttpNetworkTransactionTest, RecycleSocket) {
6189 HttpRequestInfo request; 6270 HttpRequestInfo request;
6190 request.method = "GET"; 6271 request.method = "GET";
6191 request.url = GURL("http://www.example.org/"); 6272 request.url = GURL("http://www.example.org/");
6192 request.load_flags = 0;
6193 6273
6194 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 6274 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
6195 6275
6196 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 6276 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
6197 6277
6198 MockRead data_reads[] = { 6278 MockRead data_reads[] = {
6199 // A part of the response body is received with the response headers. 6279 // A part of the response body is received with the response headers.
6200 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), 6280 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"),
6201 // The rest of the response body is received in two parts. 6281 // The rest of the response body is received in two parts.
6202 MockRead("lo"), 6282 MockRead("lo"),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
6237 // We now check to make sure the socket was added back to the pool. 6317 // We now check to make sure the socket was added back to the pool.
6238 EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); 6318 EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get()));
6239 } 6319 }
6240 6320
6241 // Make sure that we recycle a SSL socket after reading all of the response 6321 // Make sure that we recycle a SSL socket after reading all of the response
6242 // body. 6322 // body.
6243 TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { 6323 TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) {
6244 HttpRequestInfo request; 6324 HttpRequestInfo request;
6245 request.method = "GET"; 6325 request.method = "GET";
6246 request.url = GURL("https://www.example.org/"); 6326 request.url = GURL("https://www.example.org/");
6247 request.load_flags = 0;
6248 6327
6249 MockWrite data_writes[] = { 6328 MockWrite data_writes[] = {
6250 MockWrite( 6329 MockWrite(
6251 "GET / HTTP/1.1\r\n" 6330 "GET / HTTP/1.1\r\n"
6252 "Host: www.example.org\r\n" 6331 "Host: www.example.org\r\n"
6253 "Connection: keep-alive\r\n\r\n"), 6332 "Connection: keep-alive\r\n\r\n"),
6254 }; 6333 };
6255 6334
6256 MockRead data_reads[] = { 6335 MockRead data_reads[] = {
6257 MockRead("HTTP/1.1 200 OK\r\n"), 6336 MockRead("HTTP/1.1 200 OK\r\n"),
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
6296 // We now check to make sure the socket was added back to the pool. 6375 // We now check to make sure the socket was added back to the pool.
6297 EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); 6376 EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get()));
6298 } 6377 }
6299 6378
6300 // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it 6379 // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it
6301 // from the pool and make sure that we recover okay. 6380 // from the pool and make sure that we recover okay.
6302 TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { 6381 TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) {
6303 HttpRequestInfo request; 6382 HttpRequestInfo request;
6304 request.method = "GET"; 6383 request.method = "GET";
6305 request.url = GURL("https://www.example.org/"); 6384 request.url = GURL("https://www.example.org/");
6306 request.load_flags = 0;
6307 6385
6308 MockWrite data_writes[] = { 6386 MockWrite data_writes[] = {
6309 MockWrite( 6387 MockWrite(
6310 "GET / HTTP/1.1\r\n" 6388 "GET / HTTP/1.1\r\n"
6311 "Host: www.example.org\r\n" 6389 "Host: www.example.org\r\n"
6312 "Connection: keep-alive\r\n\r\n"), 6390 "Connection: keep-alive\r\n\r\n"),
6313 MockWrite( 6391 MockWrite(
6314 "GET / HTTP/1.1\r\n" 6392 "GET / HTTP/1.1\r\n"
6315 "Host: www.example.org\r\n" 6393 "Host: www.example.org\r\n"
6316 "Connection: keep-alive\r\n\r\n"), 6394 "Connection: keep-alive\r\n\r\n"),
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
6527 // Make sure that we recycle a socket after a zero-length response. 6605 // Make sure that we recycle a socket after a zero-length response.
6528 // http://crbug.com/9880 6606 // http://crbug.com/9880
6529 TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { 6607 TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) {
6530 HttpRequestInfo request; 6608 HttpRequestInfo request;
6531 request.method = "GET"; 6609 request.method = "GET";
6532 request.url = GURL( 6610 request.url = GURL(
6533 "http://www.example.org/csi?v=3&s=web&action=&" 6611 "http://www.example.org/csi?v=3&s=web&action=&"
6534 "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" 6612 "tran=undefined&ei=mAXcSeegAo-SMurloeUN&"
6535 "e=17259,18167,19592,19773,19981,20133,20173,20233&" 6613 "e=17259,18167,19592,19773,19981,20133,20173,20233&"
6536 "rt=prt.2642,ol.2649,xjs.2951"); 6614 "rt=prt.2642,ol.2649,xjs.2951");
6537 request.load_flags = 0;
6538 6615
6539 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 6616 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
6540 6617
6541 MockRead data_reads[] = { 6618 MockRead data_reads[] = {
6542 MockRead("HTTP/1.1 204 No Content\r\n" 6619 MockRead("HTTP/1.1 204 No Content\r\n"
6543 "Content-Length: 0\r\n" 6620 "Content-Length: 0\r\n"
6544 "Content-Type: text/html\r\n\r\n"), 6621 "Content-Type: text/html\r\n\r\n"),
6545 MockRead("junk"), // Should not be read!! 6622 MockRead("junk"), // Should not be read!!
6546 MockRead(SYNCHRONOUS, OK), 6623 MockRead(SYNCHRONOUS, OK),
6547 }; 6624 };
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
6944 7021
6945 // Test that previously tried username/passwords for a realm get re-used. 7022 // Test that previously tried username/passwords for a realm get re-used.
6946 TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { 7023 TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) {
6947 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 7024 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
6948 7025
6949 // Transaction 1: authenticate (foo, bar) on MyRealm1 7026 // Transaction 1: authenticate (foo, bar) on MyRealm1
6950 { 7027 {
6951 HttpRequestInfo request; 7028 HttpRequestInfo request;
6952 request.method = "GET"; 7029 request.method = "GET";
6953 request.url = GURL("http://www.example.org/x/y/z"); 7030 request.url = GURL("http://www.example.org/x/y/z");
6954 request.load_flags = 0;
6955 7031
6956 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 7032 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
6957 7033
6958 MockWrite data_writes1[] = { 7034 MockWrite data_writes1[] = {
6959 MockWrite( 7035 MockWrite(
6960 "GET /x/y/z HTTP/1.1\r\n" 7036 "GET /x/y/z HTTP/1.1\r\n"
6961 "Host: www.example.org\r\n" 7037 "Host: www.example.org\r\n"
6962 "Connection: keep-alive\r\n\r\n"), 7038 "Connection: keep-alive\r\n\r\n"),
6963 }; 7039 };
6964 7040
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
7021 7097
7022 // ------------------------------------------------------------------------ 7098 // ------------------------------------------------------------------------
7023 7099
7024 // Transaction 2: authenticate (foo2, bar2) on MyRealm2 7100 // Transaction 2: authenticate (foo2, bar2) on MyRealm2
7025 { 7101 {
7026 HttpRequestInfo request; 7102 HttpRequestInfo request;
7027 request.method = "GET"; 7103 request.method = "GET";
7028 // Note that Transaction 1 was at /x/y/z, so this is in the same 7104 // Note that Transaction 1 was at /x/y/z, so this is in the same
7029 // protection space as MyRealm1. 7105 // protection space as MyRealm1.
7030 request.url = GURL("http://www.example.org/x/y/a/b"); 7106 request.url = GURL("http://www.example.org/x/y/a/b");
7031 request.load_flags = 0;
7032 7107
7033 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 7108 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
7034 7109
7035 MockWrite data_writes1[] = { 7110 MockWrite data_writes1[] = {
7036 MockWrite( 7111 MockWrite(
7037 "GET /x/y/a/b HTTP/1.1\r\n" 7112 "GET /x/y/a/b HTTP/1.1\r\n"
7038 "Host: www.example.org\r\n" 7113 "Host: www.example.org\r\n"
7039 "Connection: keep-alive\r\n" 7114 "Connection: keep-alive\r\n"
7040 // Send preemptive authorization for MyRealm1 7115 // Send preemptive authorization for MyRealm1
7041 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), 7116 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
7106 } 7181 }
7107 7182
7108 // ------------------------------------------------------------------------ 7183 // ------------------------------------------------------------------------
7109 7184
7110 // Transaction 3: Resend a request in MyRealm's protection space -- 7185 // Transaction 3: Resend a request in MyRealm's protection space --
7111 // succeed with preemptive authorization. 7186 // succeed with preemptive authorization.
7112 { 7187 {
7113 HttpRequestInfo request; 7188 HttpRequestInfo request;
7114 request.method = "GET"; 7189 request.method = "GET";
7115 request.url = GURL("http://www.example.org/x/y/z2"); 7190 request.url = GURL("http://www.example.org/x/y/z2");
7116 request.load_flags = 0;
7117 7191
7118 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 7192 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
7119 7193
7120 MockWrite data_writes1[] = { 7194 MockWrite data_writes1[] = {
7121 MockWrite( 7195 MockWrite(
7122 "GET /x/y/z2 HTTP/1.1\r\n" 7196 "GET /x/y/z2 HTTP/1.1\r\n"
7123 "Host: www.example.org\r\n" 7197 "Host: www.example.org\r\n"
7124 "Connection: keep-alive\r\n" 7198 "Connection: keep-alive\r\n"
7125 // The authorization for MyRealm1 gets sent preemptively 7199 // The authorization for MyRealm1 gets sent preemptively
7126 // (since the url is in the same protection space) 7200 // (since the url is in the same protection space)
(...skipping 27 matching lines...) Expand all
7154 } 7228 }
7155 7229
7156 // ------------------------------------------------------------------------ 7230 // ------------------------------------------------------------------------
7157 7231
7158 // Transaction 4: request another URL in MyRealm (however the 7232 // Transaction 4: request another URL in MyRealm (however the
7159 // url is not known to belong to the protection space, so no pre-auth). 7233 // url is not known to belong to the protection space, so no pre-auth).
7160 { 7234 {
7161 HttpRequestInfo request; 7235 HttpRequestInfo request;
7162 request.method = "GET"; 7236 request.method = "GET";
7163 request.url = GURL("http://www.example.org/x/1"); 7237 request.url = GURL("http://www.example.org/x/1");
7164 request.load_flags = 0;
7165 7238
7166 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 7239 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
7167 7240
7168 MockWrite data_writes1[] = { 7241 MockWrite data_writes1[] = {
7169 MockWrite( 7242 MockWrite(
7170 "GET /x/1 HTTP/1.1\r\n" 7243 "GET /x/1 HTTP/1.1\r\n"
7171 "Host: www.example.org\r\n" 7244 "Host: www.example.org\r\n"
7172 "Connection: keep-alive\r\n\r\n"), 7245 "Connection: keep-alive\r\n\r\n"),
7173 }; 7246 };
7174 7247
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
7225 } 7298 }
7226 7299
7227 // ------------------------------------------------------------------------ 7300 // ------------------------------------------------------------------------
7228 7301
7229 // Transaction 5: request a URL in MyRealm, but the server rejects the 7302 // Transaction 5: request a URL in MyRealm, but the server rejects the
7230 // cached identity. Should invalidate and re-prompt. 7303 // cached identity. Should invalidate and re-prompt.
7231 { 7304 {
7232 HttpRequestInfo request; 7305 HttpRequestInfo request;
7233 request.method = "GET"; 7306 request.method = "GET";
7234 request.url = GURL("http://www.example.org/p/q/t"); 7307 request.url = GURL("http://www.example.org/p/q/t");
7235 request.load_flags = 0;
7236 7308
7237 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 7309 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
7238 7310
7239 MockWrite data_writes1[] = { 7311 MockWrite data_writes1[] = {
7240 MockWrite( 7312 MockWrite(
7241 "GET /p/q/t HTTP/1.1\r\n" 7313 "GET /p/q/t HTTP/1.1\r\n"
7242 "Host: www.example.org\r\n" 7314 "Host: www.example.org\r\n"
7243 "Connection: keep-alive\r\n\r\n"), 7315 "Connection: keep-alive\r\n\r\n"),
7244 }; 7316 };
7245 7317
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
7339 new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); 7411 new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef");
7340 digest_factory->set_nonce_generator(nonce_generator); 7412 digest_factory->set_nonce_generator(nonce_generator);
7341 session_deps_.http_auth_handler_factory.reset(digest_factory); 7413 session_deps_.http_auth_handler_factory.reset(digest_factory);
7342 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 7414 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
7343 7415
7344 // Transaction 1: authenticate (foo, bar) on MyRealm1 7416 // Transaction 1: authenticate (foo, bar) on MyRealm1
7345 { 7417 {
7346 HttpRequestInfo request; 7418 HttpRequestInfo request;
7347 request.method = "GET"; 7419 request.method = "GET";
7348 request.url = GURL("http://www.example.org/x/y/z"); 7420 request.url = GURL("http://www.example.org/x/y/z");
7349 request.load_flags = 0;
7350 7421
7351 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 7422 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
7352 7423
7353 MockWrite data_writes1[] = { 7424 MockWrite data_writes1[] = {
7354 MockWrite( 7425 MockWrite(
7355 "GET /x/y/z HTTP/1.1\r\n" 7426 "GET /x/y/z HTTP/1.1\r\n"
7356 "Host: www.example.org\r\n" 7427 "Host: www.example.org\r\n"
7357 "Connection: keep-alive\r\n\r\n"), 7428 "Connection: keep-alive\r\n\r\n"),
7358 }; 7429 };
7359 7430
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
7419 7490
7420 // Transaction 2: Request another resource in digestive's protection space. 7491 // Transaction 2: Request another resource in digestive's protection space.
7421 // This will preemptively add an Authorization header which should have an 7492 // This will preemptively add an Authorization header which should have an
7422 // "nc" value of 2 (as compared to 1 in the first use. 7493 // "nc" value of 2 (as compared to 1 in the first use.
7423 { 7494 {
7424 HttpRequestInfo request; 7495 HttpRequestInfo request;
7425 request.method = "GET"; 7496 request.method = "GET";
7426 // Note that Transaction 1 was at /x/y/z, so this is in the same 7497 // Note that Transaction 1 was at /x/y/z, so this is in the same
7427 // protection space as digest. 7498 // protection space as digest.
7428 request.url = GURL("http://www.example.org/x/y/a/b"); 7499 request.url = GURL("http://www.example.org/x/y/a/b");
7429 request.load_flags = 0;
7430 7500
7431 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 7501 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
7432 7502
7433 MockWrite data_writes1[] = { 7503 MockWrite data_writes1[] = {
7434 MockWrite( 7504 MockWrite(
7435 "GET /x/y/a/b HTTP/1.1\r\n" 7505 "GET /x/y/a/b HTTP/1.1\r\n"
7436 "Host: www.example.org\r\n" 7506 "Host: www.example.org\r\n"
7437 "Connection: keep-alive\r\n" 7507 "Connection: keep-alive\r\n"
7438 "Authorization: Digest username=\"foo\", realm=\"digestive\", " 7508 "Authorization: Digest username=\"foo\", realm=\"digestive\", "
7439 "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " 7509 "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, "
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
7506 EXPECT_FALSE(response->was_cached); 7576 EXPECT_FALSE(response->was_cached);
7507 EXPECT_EQ(0U, response->ssl_info.cert_status); 7577 EXPECT_EQ(0U, response->ssl_info.cert_status);
7508 EXPECT_FALSE(response->vary_data.is_valid()); 7578 EXPECT_FALSE(response->vary_data.is_valid());
7509 } 7579 }
7510 7580
7511 // Test HTTPS connections to a site with a bad certificate 7581 // Test HTTPS connections to a site with a bad certificate
7512 TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { 7582 TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) {
7513 HttpRequestInfo request; 7583 HttpRequestInfo request;
7514 request.method = "GET"; 7584 request.method = "GET";
7515 request.url = GURL("https://www.example.org/"); 7585 request.url = GURL("https://www.example.org/");
7516 request.load_flags = 0;
7517 7586
7518 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 7587 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
7519 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 7588 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
7520 7589
7521 MockWrite data_writes[] = { 7590 MockWrite data_writes[] = {
7522 MockWrite( 7591 MockWrite(
7523 "GET / HTTP/1.1\r\n" 7592 "GET / HTTP/1.1\r\n"
7524 "Host: www.example.org\r\n" 7593 "Host: www.example.org\r\n"
7525 "Connection: keep-alive\r\n\r\n"), 7594 "Connection: keep-alive\r\n\r\n"),
7526 }; 7595 };
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
7564 } 7633 }
7565 7634
7566 // Test HTTPS connections to a site with a bad certificate, going through a 7635 // Test HTTPS connections to a site with a bad certificate, going through a
7567 // proxy 7636 // proxy
7568 TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { 7637 TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) {
7569 session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); 7638 session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70");
7570 7639
7571 HttpRequestInfo request; 7640 HttpRequestInfo request;
7572 request.method = "GET"; 7641 request.method = "GET";
7573 request.url = GURL("https://www.example.org/"); 7642 request.url = GURL("https://www.example.org/");
7574 request.load_flags = 0;
7575 7643
7576 MockWrite proxy_writes[] = { 7644 MockWrite proxy_writes[] = {
7577 MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" 7645 MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n"
7578 "Host: www.example.org:443\r\n" 7646 "Host: www.example.org:443\r\n"
7579 "Proxy-Connection: keep-alive\r\n\r\n"), 7647 "Proxy-Connection: keep-alive\r\n\r\n"),
7580 }; 7648 };
7581 7649
7582 MockRead proxy_reads[] = { 7650 MockRead proxy_reads[] = {
7583 MockRead("HTTP/1.0 200 Connected\r\n\r\n"), 7651 MockRead("HTTP/1.0 200 Connected\r\n\r\n"),
7584 MockRead(SYNCHRONOUS, OK) 7652 MockRead(SYNCHRONOUS, OK)
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
7645 // Test HTTPS connections to a site, going through an HTTPS proxy 7713 // Test HTTPS connections to a site, going through an HTTPS proxy
7646 TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { 7714 TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) {
7647 session_deps_.proxy_service = 7715 session_deps_.proxy_service =
7648 ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); 7716 ProxyService::CreateFixedFromPacResult("HTTPS proxy:70");
7649 TestNetLog net_log; 7717 TestNetLog net_log;
7650 session_deps_.net_log = &net_log; 7718 session_deps_.net_log = &net_log;
7651 7719
7652 HttpRequestInfo request; 7720 HttpRequestInfo request;
7653 request.method = "GET"; 7721 request.method = "GET";
7654 request.url = GURL("https://www.example.org/"); 7722 request.url = GURL("https://www.example.org/");
7655 request.load_flags = 0;
7656 7723
7657 MockWrite data_writes[] = { 7724 MockWrite data_writes[] = {
7658 MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" 7725 MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n"
7659 "Host: www.example.org:443\r\n" 7726 "Host: www.example.org:443\r\n"
7660 "Proxy-Connection: keep-alive\r\n\r\n"), 7727 "Proxy-Connection: keep-alive\r\n\r\n"),
7661 MockWrite("GET / HTTP/1.1\r\n" 7728 MockWrite("GET / HTTP/1.1\r\n"
7662 "Host: www.example.org\r\n" 7729 "Host: www.example.org\r\n"
7663 "Connection: keep-alive\r\n\r\n"), 7730 "Connection: keep-alive\r\n\r\n"),
7664 }; 7731 };
7665 7732
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
7709 // Test an HTTPS Proxy's ability to redirect a CONNECT request 7776 // Test an HTTPS Proxy's ability to redirect a CONNECT request
7710 TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { 7777 TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) {
7711 session_deps_.proxy_service = 7778 session_deps_.proxy_service =
7712 ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); 7779 ProxyService::CreateFixedFromPacResult("HTTPS proxy:70");
7713 TestNetLog net_log; 7780 TestNetLog net_log;
7714 session_deps_.net_log = &net_log; 7781 session_deps_.net_log = &net_log;
7715 7782
7716 HttpRequestInfo request; 7783 HttpRequestInfo request;
7717 request.method = "GET"; 7784 request.method = "GET";
7718 request.url = GURL("https://www.example.org/"); 7785 request.url = GURL("https://www.example.org/");
7719 request.load_flags = 0;
7720 7786
7721 MockWrite data_writes[] = { 7787 MockWrite data_writes[] = {
7722 MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" 7788 MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n"
7723 "Host: www.example.org:443\r\n" 7789 "Host: www.example.org:443\r\n"
7724 "Proxy-Connection: keep-alive\r\n\r\n"), 7790 "Proxy-Connection: keep-alive\r\n\r\n"),
7725 }; 7791 };
7726 7792
7727 MockRead data_reads[] = { 7793 MockRead data_reads[] = {
7728 MockRead("HTTP/1.1 302 Redirect\r\n"), 7794 MockRead("HTTP/1.1 302 Redirect\r\n"),
7729 MockRead("Location: http://login.example.com/\r\n"), 7795 MockRead("Location: http://login.example.com/\r\n"),
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
7781 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); 7847 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null());
7782 } 7848 }
7783 7849
7784 // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request 7850 // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request
7785 TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { 7851 TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) {
7786 session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); 7852 session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70");
7787 7853
7788 HttpRequestInfo request; 7854 HttpRequestInfo request;
7789 request.method = "GET"; 7855 request.method = "GET";
7790 request.url = GURL("https://www.example.org/"); 7856 request.url = GURL("https://www.example.org/");
7791 request.load_flags = 0;
7792 7857
7793 SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( 7858 SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect(
7794 NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); 7859 NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443)));
7795 SpdySerializedFrame goaway( 7860 SpdySerializedFrame goaway(
7796 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); 7861 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL));
7797 MockWrite data_writes[] = { 7862 MockWrite data_writes[] = {
7798 CreateMockWrite(conn, 0, SYNCHRONOUS), 7863 CreateMockWrite(conn, 0, SYNCHRONOUS),
7799 CreateMockWrite(goaway, 2, SYNCHRONOUS), 7864 CreateMockWrite(goaway, 2, SYNCHRONOUS),
7800 }; 7865 };
7801 7866
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
7837 EXPECT_EQ("http://login.example.com/", url); 7902 EXPECT_EQ("http://login.example.com/", url);
7838 } 7903 }
7839 7904
7840 // Test that an HTTPS proxy's response to a CONNECT request is filtered. 7905 // Test that an HTTPS proxy's response to a CONNECT request is filtered.
7841 TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { 7906 TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) {
7842 session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); 7907 session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70");
7843 7908
7844 HttpRequestInfo request; 7909 HttpRequestInfo request;
7845 request.method = "GET"; 7910 request.method = "GET";
7846 request.url = GURL("https://www.example.org/"); 7911 request.url = GURL("https://www.example.org/");
7847 request.load_flags = 0;
7848 7912
7849 MockWrite data_writes[] = { 7913 MockWrite data_writes[] = {
7850 MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" 7914 MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n"
7851 "Host: www.example.org:443\r\n" 7915 "Host: www.example.org:443\r\n"
7852 "Proxy-Connection: keep-alive\r\n\r\n"), 7916 "Proxy-Connection: keep-alive\r\n\r\n"),
7853 }; 7917 };
7854 7918
7855 MockRead data_reads[] = { 7919 MockRead data_reads[] = {
7856 MockRead("HTTP/1.1 404 Not Found\r\n"), 7920 MockRead("HTTP/1.1 404 Not Found\r\n"),
7857 MockRead("Content-Length: 23\r\n\r\n"), 7921 MockRead("Content-Length: 23\r\n\r\n"),
(...skipping 22 matching lines...) Expand all
7880 // TODO(juliatuttle): Anything else to check here? 7944 // TODO(juliatuttle): Anything else to check here?
7881 } 7945 }
7882 7946
7883 // Test that a SPDY proxy's response to a CONNECT request is filtered. 7947 // Test that a SPDY proxy's response to a CONNECT request is filtered.
7884 TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { 7948 TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) {
7885 session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); 7949 session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70");
7886 7950
7887 HttpRequestInfo request; 7951 HttpRequestInfo request;
7888 request.method = "GET"; 7952 request.method = "GET";
7889 request.url = GURL("https://www.example.org/"); 7953 request.url = GURL("https://www.example.org/");
7890 request.load_flags = 0;
7891 7954
7892 SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( 7955 SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect(
7893 NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); 7956 NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443)));
7894 SpdySerializedFrame rst( 7957 SpdySerializedFrame rst(
7895 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); 7958 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL));
7896 MockWrite data_writes[] = { 7959 MockWrite data_writes[] = {
7897 CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), 7960 CreateMockWrite(conn, 0), CreateMockWrite(rst, 3),
7898 }; 7961 };
7899 7962
7900 static const char* const kExtraHeaders[] = { 7963 static const char* const kExtraHeaders[] = {
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
8348 } 8411 }
8349 8412
8350 // Test HTTPS connections to a site with a bad certificate, going through an 8413 // Test HTTPS connections to a site with a bad certificate, going through an
8351 // HTTPS proxy 8414 // HTTPS proxy
8352 TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { 8415 TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) {
8353 session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); 8416 session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70");
8354 8417
8355 HttpRequestInfo request; 8418 HttpRequestInfo request;
8356 request.method = "GET"; 8419 request.method = "GET";
8357 request.url = GURL("https://www.example.org/"); 8420 request.url = GURL("https://www.example.org/");
8358 request.load_flags = 0;
8359 8421
8360 // Attempt to fetch the URL from a server with a bad cert 8422 // Attempt to fetch the URL from a server with a bad cert
8361 MockWrite bad_cert_writes[] = { 8423 MockWrite bad_cert_writes[] = {
8362 MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" 8424 MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n"
8363 "Host: www.example.org:443\r\n" 8425 "Host: www.example.org:443\r\n"
8364 "Proxy-Connection: keep-alive\r\n\r\n"), 8426 "Proxy-Connection: keep-alive\r\n\r\n"),
8365 }; 8427 };
8366 8428
8367 MockRead bad_cert_reads[] = { 8429 MockRead bad_cert_reads[] = {
8368 MockRead("HTTP/1.0 200 Connected\r\n\r\n"), 8430 MockRead("HTTP/1.0 200 Connected\r\n\r\n"),
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
8502 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 8564 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
8503 8565
8504 rv = callback.WaitForResult(); 8566 rv = callback.WaitForResult();
8505 EXPECT_THAT(rv, IsOk()); 8567 EXPECT_THAT(rv, IsOk());
8506 } 8568 }
8507 8569
8508 TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { 8570 TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) {
8509 HttpRequestInfo request; 8571 HttpRequestInfo request;
8510 request.method = "GET"; 8572 request.method = "GET";
8511 request.url = GURL("http://www.example.org/"); 8573 request.url = GURL("http://www.example.org/");
8512 request.load_flags = 0;
8513 request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, 8574 request.extra_headers.SetHeader(HttpRequestHeaders::kReferer,
8514 "http://the.previous.site.com/"); 8575 "http://the.previous.site.com/");
8515 8576
8516 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 8577 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
8517 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 8578 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
8518 8579
8519 MockWrite data_writes[] = { 8580 MockWrite data_writes[] = {
8520 MockWrite( 8581 MockWrite(
8521 "GET / HTTP/1.1\r\n" 8582 "GET / HTTP/1.1\r\n"
8522 "Host: www.example.org\r\n" 8583 "Host: www.example.org\r\n"
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
8808 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 8869 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
8809 8870
8810 rv = callback.WaitForResult(); 8871 rv = callback.WaitForResult();
8811 EXPECT_THAT(rv, IsOk()); 8872 EXPECT_THAT(rv, IsOk());
8812 } 8873 }
8813 8874
8814 TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { 8875 TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) {
8815 HttpRequestInfo request; 8876 HttpRequestInfo request;
8816 request.method = "GET"; 8877 request.method = "GET";
8817 request.url = GURL("http://www.example.org/"); 8878 request.url = GURL("http://www.example.org/");
8818 request.load_flags = 0;
8819 8879
8820 session_deps_.proxy_service = 8880 session_deps_.proxy_service =
8821 ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); 8881 ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080");
8822 TestNetLog net_log; 8882 TestNetLog net_log;
8823 session_deps_.net_log = &net_log; 8883 session_deps_.net_log = &net_log;
8824 8884
8825 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 8885 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
8826 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 8886 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
8827 8887
8828 char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; 8888 char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 };
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
8867 std::string response_text; 8927 std::string response_text;
8868 rv = ReadTransaction(&trans, &response_text); 8928 rv = ReadTransaction(&trans, &response_text);
8869 EXPECT_THAT(rv, IsOk()); 8929 EXPECT_THAT(rv, IsOk());
8870 EXPECT_EQ("Payload", response_text); 8930 EXPECT_EQ("Payload", response_text);
8871 } 8931 }
8872 8932
8873 TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { 8933 TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) {
8874 HttpRequestInfo request; 8934 HttpRequestInfo request;
8875 request.method = "GET"; 8935 request.method = "GET";
8876 request.url = GURL("https://www.example.org/"); 8936 request.url = GURL("https://www.example.org/");
8877 request.load_flags = 0;
8878 8937
8879 session_deps_.proxy_service = 8938 session_deps_.proxy_service =
8880 ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); 8939 ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080");
8881 TestNetLog net_log; 8940 TestNetLog net_log;
8882 session_deps_.net_log = &net_log; 8941 session_deps_.net_log = &net_log;
8883 8942
8884 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 8943 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
8885 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 8944 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
8886 8945
8887 unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; 8946 unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 };
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
8931 std::string response_text; 8990 std::string response_text;
8932 rv = ReadTransaction(&trans, &response_text); 8991 rv = ReadTransaction(&trans, &response_text);
8933 EXPECT_THAT(rv, IsOk()); 8992 EXPECT_THAT(rv, IsOk());
8934 EXPECT_EQ("Payload", response_text); 8993 EXPECT_EQ("Payload", response_text);
8935 } 8994 }
8936 8995
8937 TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { 8996 TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) {
8938 HttpRequestInfo request; 8997 HttpRequestInfo request;
8939 request.method = "GET"; 8998 request.method = "GET";
8940 request.url = GURL("http://www.example.org/"); 8999 request.url = GURL("http://www.example.org/");
8941 request.load_flags = 0;
8942 9000
8943 session_deps_.proxy_service = 9001 session_deps_.proxy_service =
8944 ProxyService::CreateFixed("socks4://myproxy:1080"); 9002 ProxyService::CreateFixed("socks4://myproxy:1080");
8945 TestNetLog net_log; 9003 TestNetLog net_log;
8946 session_deps_.net_log = &net_log; 9004 session_deps_.net_log = &net_log;
8947 9005
8948 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 9006 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
8949 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 9007 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
8950 9008
8951 char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; 9009 char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 };
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
8989 std::string response_text; 9047 std::string response_text;
8990 rv = ReadTransaction(&trans, &response_text); 9048 rv = ReadTransaction(&trans, &response_text);
8991 EXPECT_THAT(rv, IsOk()); 9049 EXPECT_THAT(rv, IsOk());
8992 EXPECT_EQ("Payload", response_text); 9050 EXPECT_EQ("Payload", response_text);
8993 } 9051 }
8994 9052
8995 TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { 9053 TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) {
8996 HttpRequestInfo request; 9054 HttpRequestInfo request;
8997 request.method = "GET"; 9055 request.method = "GET";
8998 request.url = GURL("http://www.example.org/"); 9056 request.url = GURL("http://www.example.org/");
8999 request.load_flags = 0;
9000 9057
9001 session_deps_.proxy_service = 9058 session_deps_.proxy_service =
9002 ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); 9059 ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080");
9003 TestNetLog net_log; 9060 TestNetLog net_log;
9004 session_deps_.net_log = &net_log; 9061 session_deps_.net_log = &net_log;
9005 9062
9006 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 9063 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
9007 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 9064 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
9008 9065
9009 const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; 9066 const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 };
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
9061 std::string response_text; 9118 std::string response_text;
9062 rv = ReadTransaction(&trans, &response_text); 9119 rv = ReadTransaction(&trans, &response_text);
9063 EXPECT_THAT(rv, IsOk()); 9120 EXPECT_THAT(rv, IsOk());
9064 EXPECT_EQ("Payload", response_text); 9121 EXPECT_EQ("Payload", response_text);
9065 } 9122 }
9066 9123
9067 TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { 9124 TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) {
9068 HttpRequestInfo request; 9125 HttpRequestInfo request;
9069 request.method = "GET"; 9126 request.method = "GET";
9070 request.url = GURL("https://www.example.org/"); 9127 request.url = GURL("https://www.example.org/");
9071 request.load_flags = 0;
9072 9128
9073 session_deps_.proxy_service = 9129 session_deps_.proxy_service =
9074 ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); 9130 ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080");
9075 TestNetLog net_log; 9131 TestNetLog net_log;
9076 session_deps_.net_log = &net_log; 9132 session_deps_.net_log = &net_log;
9077 9133
9078 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 9134 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
9079 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 9135 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
9080 9136
9081 const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; 9137 const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 };
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
9166 alternative_service, expiration); 9222 alternative_service, expiration);
9167 9223
9168 return session; 9224 return session;
9169 } 9225 }
9170 9226
9171 int GroupNameTransactionHelper(const std::string& url, 9227 int GroupNameTransactionHelper(const std::string& url,
9172 HttpNetworkSession* session) { 9228 HttpNetworkSession* session) {
9173 HttpRequestInfo request; 9229 HttpRequestInfo request;
9174 request.method = "GET"; 9230 request.method = "GET";
9175 request.url = GURL(url); 9231 request.url = GURL(url);
9176 request.load_flags = 0;
9177 9232
9178 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); 9233 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session);
9179 9234
9180 TestCompletionCallback callback; 9235 TestCompletionCallback callback;
9181 9236
9182 // We do not complete this request, the dtor will clean the transaction up. 9237 // We do not complete this request, the dtor will clean the transaction up.
9183 return trans.Start(&request, callback.callback(), NetLogWithSource()); 9238 return trans.Start(&request, callback.callback(), NetLogWithSource());
9184 } 9239 }
9185 9240
9186 } // namespace 9241 } // namespace
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
9480 9535
9481 TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { 9536 TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) {
9482 BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); 9537 BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE);
9483 } 9538 }
9484 9539
9485 // Make sure we can handle an error when writing the request. 9540 // Make sure we can handle an error when writing the request.
9486 TEST_F(HttpNetworkTransactionTest, RequestWriteError) { 9541 TEST_F(HttpNetworkTransactionTest, RequestWriteError) {
9487 HttpRequestInfo request; 9542 HttpRequestInfo request;
9488 request.method = "GET"; 9543 request.method = "GET";
9489 request.url = GURL("http://www.foo.com/"); 9544 request.url = GURL("http://www.foo.com/");
9490 request.load_flags = 0;
9491 9545
9492 MockWrite write_failure[] = { 9546 MockWrite write_failure[] = {
9493 MockWrite(ASYNC, ERR_CONNECTION_RESET), 9547 MockWrite(ASYNC, ERR_CONNECTION_RESET),
9494 }; 9548 };
9495 StaticSocketDataProvider data(NULL, 0, 9549 StaticSocketDataProvider data(NULL, 0,
9496 write_failure, arraysize(write_failure)); 9550 write_failure, arraysize(write_failure));
9497 session_deps_.socket_factory->AddSocketDataProvider(&data); 9551 session_deps_.socket_factory->AddSocketDataProvider(&data);
9498 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 9552 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
9499 9553
9500 TestCompletionCallback callback; 9554 TestCompletionCallback callback;
9501 9555
9502 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 9556 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
9503 9557
9504 int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); 9558 int rv = trans.Start(&request, callback.callback(), NetLogWithSource());
9505 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 9559 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
9506 9560
9507 rv = callback.WaitForResult(); 9561 rv = callback.WaitForResult();
9508 EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); 9562 EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET));
9509 9563
9510 IPEndPoint endpoint; 9564 IPEndPoint endpoint;
9511 EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); 9565 EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint));
9512 EXPECT_LT(0u, endpoint.address().size()); 9566 EXPECT_LT(0u, endpoint.address().size());
9513 } 9567 }
9514 9568
9515 // Check that a connection closed after the start of the headers finishes ok. 9569 // Check that a connection closed after the start of the headers finishes ok.
9516 TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { 9570 TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) {
9517 HttpRequestInfo request; 9571 HttpRequestInfo request;
9518 request.method = "GET"; 9572 request.method = "GET";
9519 request.url = GURL("http://www.foo.com/"); 9573 request.url = GURL("http://www.foo.com/");
9520 request.load_flags = 0;
9521 9574
9522 MockRead data_reads[] = { 9575 MockRead data_reads[] = {
9523 MockRead("HTTP/1."), 9576 MockRead("HTTP/1."),
9524 MockRead(SYNCHRONOUS, OK), 9577 MockRead(SYNCHRONOUS, OK),
9525 }; 9578 };
9526 9579
9527 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 9580 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
9528 session_deps_.socket_factory->AddSocketDataProvider(&data); 9581 session_deps_.socket_factory->AddSocketDataProvider(&data);
9529 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 9582 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
9530 9583
(...skipping 22 matching lines...) Expand all
9553 EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); 9606 EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint));
9554 EXPECT_LT(0u, endpoint.address().size()); 9607 EXPECT_LT(0u, endpoint.address().size());
9555 } 9608 }
9556 9609
9557 // Make sure that a dropped connection while draining the body for auth 9610 // Make sure that a dropped connection while draining the body for auth
9558 // restart does the right thing. 9611 // restart does the right thing.
9559 TEST_F(HttpNetworkTransactionTest, DrainResetOK) { 9612 TEST_F(HttpNetworkTransactionTest, DrainResetOK) {
9560 HttpRequestInfo request; 9613 HttpRequestInfo request;
9561 request.method = "GET"; 9614 request.method = "GET";
9562 request.url = GURL("http://www.example.org/"); 9615 request.url = GURL("http://www.example.org/");
9563 request.load_flags = 0;
9564 9616
9565 MockWrite data_writes1[] = { 9617 MockWrite data_writes1[] = {
9566 MockWrite( 9618 MockWrite(
9567 "GET / HTTP/1.1\r\n" 9619 "GET / HTTP/1.1\r\n"
9568 "Host: www.example.org\r\n" 9620 "Host: www.example.org\r\n"
9569 "Connection: keep-alive\r\n\r\n"), 9621 "Connection: keep-alive\r\n\r\n"),
9570 }; 9622 };
9571 9623
9572 MockRead data_reads1[] = { 9624 MockRead data_reads1[] = {
9573 MockRead("HTTP/1.1 401 Unauthorized\r\n"), 9625 MockRead("HTTP/1.1 401 Unauthorized\r\n"),
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
9633 EXPECT_EQ(100, response->headers->GetContentLength()); 9685 EXPECT_EQ(100, response->headers->GetContentLength());
9634 } 9686 }
9635 9687
9636 // Test HTTPS connections going through a proxy that sends extra data. 9688 // Test HTTPS connections going through a proxy that sends extra data.
9637 TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { 9689 TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) {
9638 session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); 9690 session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70");
9639 9691
9640 HttpRequestInfo request; 9692 HttpRequestInfo request;
9641 request.method = "GET"; 9693 request.method = "GET";
9642 request.url = GURL("https://www.example.org/"); 9694 request.url = GURL("https://www.example.org/");
9643 request.load_flags = 0;
9644 9695
9645 MockRead proxy_reads[] = { 9696 MockRead proxy_reads[] = {
9646 MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), 9697 MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"),
9647 MockRead(SYNCHRONOUS, OK) 9698 MockRead(SYNCHRONOUS, OK)
9648 }; 9699 };
9649 9700
9650 StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); 9701 StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0);
9651 SSLSocketDataProvider ssl(ASYNC, OK); 9702 SSLSocketDataProvider ssl(ASYNC, OK);
9652 9703
9653 session_deps_.socket_factory->AddSocketDataProvider(&data); 9704 session_deps_.socket_factory->AddSocketDataProvider(&data);
(...skipping 10 matching lines...) Expand all
9664 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 9715 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
9665 9716
9666 rv = callback.WaitForResult(); 9717 rv = callback.WaitForResult();
9667 EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); 9718 EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED));
9668 } 9719 }
9669 9720
9670 TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { 9721 TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) {
9671 HttpRequestInfo request; 9722 HttpRequestInfo request;
9672 request.method = "GET"; 9723 request.method = "GET";
9673 request.url = GURL("http://www.example.org/"); 9724 request.url = GURL("http://www.example.org/");
9674 request.load_flags = 0;
9675 9725
9676 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 9726 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
9677 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 9727 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
9678 9728
9679 MockRead data_reads[] = { 9729 MockRead data_reads[] = {
9680 MockRead("HTTP/1.0 200 OK\r\nContent-Length:6719476739\r\n\r\n"), 9730 MockRead("HTTP/1.0 200 OK\r\nContent-Length:6719476739\r\n\r\n"),
9681 MockRead(SYNCHRONOUS, OK), 9731 MockRead(SYNCHRONOUS, OK),
9682 }; 9732 };
9683 9733
9684 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 9734 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
(...skipping 27 matching lines...) Expand all
9712 std::vector<std::unique_ptr<UploadElementReader>> element_readers; 9762 std::vector<std::unique_ptr<UploadElementReader>> element_readers;
9713 element_readers.push_back(base::MakeUnique<UploadFileElementReader>( 9763 element_readers.push_back(base::MakeUnique<UploadFileElementReader>(
9714 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, 9764 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0,
9715 std::numeric_limits<uint64_t>::max(), base::Time())); 9765 std::numeric_limits<uint64_t>::max(), base::Time()));
9716 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); 9766 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0);
9717 9767
9718 HttpRequestInfo request; 9768 HttpRequestInfo request;
9719 request.method = "POST"; 9769 request.method = "POST";
9720 request.url = GURL("http://www.example.org/upload"); 9770 request.url = GURL("http://www.example.org/upload");
9721 request.upload_data_stream = &upload_data_stream; 9771 request.upload_data_stream = &upload_data_stream;
9722 request.load_flags = 0;
9723 9772
9724 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 9773 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
9725 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 9774 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
9726 9775
9727 MockRead data_reads[] = { 9776 MockRead data_reads[] = {
9728 MockRead("HTTP/1.0 200 OK\r\n\r\n"), 9777 MockRead("HTTP/1.0 200 OK\r\n\r\n"),
9729 MockRead("hello world"), 9778 MockRead("hello world"),
9730 MockRead(SYNCHRONOUS, OK), 9779 MockRead(SYNCHRONOUS, OK),
9731 }; 9780 };
9732 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 9781 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
(...skipping 26 matching lines...) Expand all
9759 std::vector<std::unique_ptr<UploadElementReader>> element_readers; 9808 std::vector<std::unique_ptr<UploadElementReader>> element_readers;
9760 element_readers.push_back(base::MakeUnique<UploadFileElementReader>( 9809 element_readers.push_back(base::MakeUnique<UploadFileElementReader>(
9761 base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, 9810 base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0,
9762 std::numeric_limits<uint64_t>::max(), base::Time())); 9811 std::numeric_limits<uint64_t>::max(), base::Time()));
9763 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); 9812 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0);
9764 9813
9765 HttpRequestInfo request; 9814 HttpRequestInfo request;
9766 request.method = "POST"; 9815 request.method = "POST";
9767 request.url = GURL("http://www.example.org/upload"); 9816 request.url = GURL("http://www.example.org/upload");
9768 request.upload_data_stream = &upload_data_stream; 9817 request.upload_data_stream = &upload_data_stream;
9769 request.load_flags = 0;
9770 9818
9771 // If we try to upload an unreadable file, the transaction should fail. 9819 // If we try to upload an unreadable file, the transaction should fail.
9772 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 9820 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
9773 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 9821 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
9774 9822
9775 StaticSocketDataProvider data(NULL, 0, NULL, 0); 9823 StaticSocketDataProvider data(NULL, 0, NULL, 0);
9776 session_deps_.socket_factory->AddSocketDataProvider(&data); 9824 session_deps_.socket_factory->AddSocketDataProvider(&data);
9777 9825
9778 TestCompletionCallback callback; 9826 TestCompletionCallback callback;
9779 9827
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
9813 9861
9814 FakeUploadElementReader* fake_reader = new FakeUploadElementReader; 9862 FakeUploadElementReader* fake_reader = new FakeUploadElementReader;
9815 std::vector<std::unique_ptr<UploadElementReader>> element_readers; 9863 std::vector<std::unique_ptr<UploadElementReader>> element_readers;
9816 element_readers.push_back(base::WrapUnique(fake_reader)); 9864 element_readers.push_back(base::WrapUnique(fake_reader));
9817 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); 9865 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0);
9818 9866
9819 HttpRequestInfo request; 9867 HttpRequestInfo request;
9820 request.method = "POST"; 9868 request.method = "POST";
9821 request.url = GURL("http://www.example.org/upload"); 9869 request.url = GURL("http://www.example.org/upload");
9822 request.upload_data_stream = &upload_data_stream; 9870 request.upload_data_stream = &upload_data_stream;
9823 request.load_flags = 0;
9824 9871
9825 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 9872 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
9826 std::unique_ptr<HttpNetworkTransaction> trans( 9873 std::unique_ptr<HttpNetworkTransaction> trans(
9827 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 9874 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
9828 9875
9829 StaticSocketDataProvider data; 9876 StaticSocketDataProvider data;
9830 session_deps_.socket_factory->AddSocketDataProvider(&data); 9877 session_deps_.socket_factory->AddSocketDataProvider(&data);
9831 9878
9832 TestCompletionCallback callback; 9879 TestCompletionCallback callback;
9833 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); 9880 int rv = trans->Start(&request, callback.callback(), NetLogWithSource());
9834 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 9881 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
9835 base::RunLoop().RunUntilIdle(); 9882 base::RunLoop().RunUntilIdle();
9836 9883
9837 // Transaction is pending on request body initialization. 9884 // Transaction is pending on request body initialization.
9838 ASSERT_FALSE(fake_reader->callback().is_null()); 9885 ASSERT_FALSE(fake_reader->callback().is_null());
9839 9886
9840 // Return Init()'s result after the transaction gets destroyed. 9887 // Return Init()'s result after the transaction gets destroyed.
9841 trans.reset(); 9888 trans.reset();
9842 fake_reader->callback().Run(OK); // Should not crash. 9889 fake_reader->callback().Run(OK); // Should not crash.
9843 } 9890 }
9844 9891
9845 // Tests that changes to Auth realms are treated like auth rejections. 9892 // Tests that changes to Auth realms are treated like auth rejections.
9846 TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { 9893 TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) {
9847 HttpRequestInfo request; 9894 HttpRequestInfo request;
9848 request.method = "GET"; 9895 request.method = "GET";
9849 request.url = GURL("http://www.example.org/"); 9896 request.url = GURL("http://www.example.org/");
9850 request.load_flags = 0;
9851 9897
9852 // First transaction will request a resource and receive a Basic challenge 9898 // First transaction will request a resource and receive a Basic challenge
9853 // with realm="first_realm". 9899 // with realm="first_realm".
9854 MockWrite data_writes1[] = { 9900 MockWrite data_writes1[] = {
9855 MockWrite( 9901 MockWrite(
9856 "GET / HTTP/1.1\r\n" 9902 "GET / HTTP/1.1\r\n"
9857 "Host: www.example.org\r\n" 9903 "Host: www.example.org\r\n"
9858 "Connection: keep-alive\r\n" 9904 "Connection: keep-alive\r\n"
9859 "\r\n"), 9905 "\r\n"),
9860 }; 9906 };
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
10002 MockRead("HTTP/1.1 200 OK\r\n"), 10048 MockRead("HTTP/1.1 200 OK\r\n"),
10003 MockRead(kAlternativeServiceHttpHeader), 10049 MockRead(kAlternativeServiceHttpHeader),
10004 MockRead("\r\n"), 10050 MockRead("\r\n"),
10005 MockRead("hello world"), 10051 MockRead("hello world"),
10006 MockRead(SYNCHRONOUS, OK), 10052 MockRead(SYNCHRONOUS, OK),
10007 }; 10053 };
10008 10054
10009 HttpRequestInfo request; 10055 HttpRequestInfo request;
10010 request.method = "GET"; 10056 request.method = "GET";
10011 request.url = GURL("https://www.example.org/"); 10057 request.url = GURL("https://www.example.org/");
10012 request.load_flags = 0;
10013 10058
10014 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 10059 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
10015 session_deps_.socket_factory->AddSocketDataProvider(&data); 10060 session_deps_.socket_factory->AddSocketDataProvider(&data);
10016 10061
10017 SSLSocketDataProvider ssl(ASYNC, OK); 10062 SSLSocketDataProvider ssl(ASYNC, OK);
10018 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 10063 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
10019 10064
10020 TestCompletionCallback callback; 10065 TestCompletionCallback callback;
10021 10066
10022 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 10067 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
10216 }; 10261 };
10217 StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); 10262 StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0);
10218 session_deps_.socket_factory->AddSocketDataProvider(&data); 10263 session_deps_.socket_factory->AddSocketDataProvider(&data);
10219 10264
10220 SSLSocketDataProvider ssl(ASYNC, OK); 10265 SSLSocketDataProvider ssl(ASYNC, OK);
10221 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 10266 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
10222 10267
10223 HttpRequestInfo request; 10268 HttpRequestInfo request;
10224 request.method = "GET"; 10269 request.method = "GET";
10225 request.url = GURL("https://www.example.org/"); 10270 request.url = GURL("https://www.example.org/");
10226 request.load_flags = 0;
10227 10271
10228 TestCompletionCallback callback; 10272 TestCompletionCallback callback;
10229 10273
10230 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 10274 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
10231 10275
10232 int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); 10276 int rv = trans.Start(&request, callback.callback(), NetLogWithSource());
10233 EXPECT_THAT(callback.GetResult(rv), IsOk()); 10277 EXPECT_THAT(callback.GetResult(rv), IsOk());
10234 10278
10235 const HttpResponseInfo* response = trans.GetResponseInfo(); 10279 const HttpResponseInfo* response = trans.GetResponseInfo();
10236 ASSERT_TRUE(response); 10280 ASSERT_TRUE(response);
(...skipping 16 matching lines...) Expand all
10253 MockRead("HTTP/1.1 200 OK\r\n"), 10297 MockRead("HTTP/1.1 200 OK\r\n"),
10254 MockRead("Alt-Svc: h2=\"www.example.com:443\","), 10298 MockRead("Alt-Svc: h2=\"www.example.com:443\","),
10255 MockRead("h2=\":1234\"\r\n\r\n"), 10299 MockRead("h2=\":1234\"\r\n\r\n"),
10256 MockRead("hello world"), 10300 MockRead("hello world"),
10257 MockRead(SYNCHRONOUS, OK), 10301 MockRead(SYNCHRONOUS, OK),
10258 }; 10302 };
10259 10303
10260 HttpRequestInfo request; 10304 HttpRequestInfo request;
10261 request.method = "GET"; 10305 request.method = "GET";
10262 request.url = GURL("https://www.example.org/"); 10306 request.url = GURL("https://www.example.org/");
10263 request.load_flags = 0;
10264 10307
10265 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 10308 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
10266 session_deps_.socket_factory->AddSocketDataProvider(&data); 10309 session_deps_.socket_factory->AddSocketDataProvider(&data);
10267 10310
10268 SSLSocketDataProvider ssl(ASYNC, OK); 10311 SSLSocketDataProvider ssl(ASYNC, OK);
10269 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 10312 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
10270 10313
10271 TestCompletionCallback callback; 10314 TestCompletionCallback callback;
10272 10315
10273 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 10316 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
10349 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 10392 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
10350 http_server_properties->SetAlternativeService(server, alternative_service, 10393 http_server_properties->SetAlternativeService(server, alternative_service,
10351 expiration); 10394 expiration);
10352 // Mark the QUIC alternative service as broken. 10395 // Mark the QUIC alternative service as broken.
10353 http_server_properties->MarkAlternativeServiceBroken(alternative_service); 10396 http_server_properties->MarkAlternativeServiceBroken(alternative_service);
10354 10397
10355 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 10398 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
10356 HttpRequestInfo request; 10399 HttpRequestInfo request;
10357 request.method = "GET"; 10400 request.method = "GET";
10358 request.url = GURL(origin_url); 10401 request.url = GURL(origin_url);
10359 request.load_flags = 0;
10360 TestCompletionCallback callback; 10402 TestCompletionCallback callback;
10361 NetErrorDetails details; 10403 NetErrorDetails details;
10362 EXPECT_FALSE(details.quic_broken); 10404 EXPECT_FALSE(details.quic_broken);
10363 10405
10364 trans.Start(&request, callback.callback(), NetLogWithSource()); 10406 trans.Start(&request, callback.callback(), NetLogWithSource());
10365 trans.PopulateNetErrorDetails(&details); 10407 trans.PopulateNetErrorDetails(&details);
10366 EXPECT_TRUE(details.quic_broken); 10408 EXPECT_TRUE(details.quic_broken);
10367 } 10409 }
10368 10410
10369 TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { 10411 TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
10423 // Mark one of the QUIC alternative service as broken. 10465 // Mark one of the QUIC alternative service as broken.
10424 http_server_properties->MarkAlternativeServiceBroken(alternative_service1); 10466 http_server_properties->MarkAlternativeServiceBroken(alternative_service1);
10425 10467
10426 const AlternativeServiceVector alternative_service_vector = 10468 const AlternativeServiceVector alternative_service_vector =
10427 http_server_properties->GetAlternativeServices(server); 10469 http_server_properties->GetAlternativeServices(server);
10428 10470
10429 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 10471 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
10430 HttpRequestInfo request; 10472 HttpRequestInfo request;
10431 request.method = "GET"; 10473 request.method = "GET";
10432 request.url = GURL(origin_url); 10474 request.url = GURL(origin_url);
10433 request.load_flags = 0;
10434 TestCompletionCallback callback; 10475 TestCompletionCallback callback;
10435 NetErrorDetails details; 10476 NetErrorDetails details;
10436 EXPECT_FALSE(details.quic_broken); 10477 EXPECT_FALSE(details.quic_broken);
10437 10478
10438 trans.Start(&request, callback.callback(), NetLogWithSource()); 10479 trans.Start(&request, callback.callback(), NetLogWithSource());
10439 trans.PopulateNetErrorDetails(&details); 10480 trans.PopulateNetErrorDetails(&details);
10440 EXPECT_FALSE(details.quic_broken); 10481 EXPECT_FALSE(details.quic_broken);
10441 } 10482 }
10442 10483
10443 TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { 10484 TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) {
10444 HttpRequestInfo request; 10485 HttpRequestInfo request;
10445 request.method = "GET"; 10486 request.method = "GET";
10446 request.url = GURL("https://www.example.org/"); 10487 request.url = GURL("https://www.example.org/");
10447 request.load_flags = 0;
10448 10488
10449 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); 10489 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED);
10450 StaticSocketDataProvider first_data; 10490 StaticSocketDataProvider first_data;
10451 first_data.set_connect_data(mock_connect); 10491 first_data.set_connect_data(mock_connect);
10452 session_deps_.socket_factory->AddSocketDataProvider(&first_data); 10492 session_deps_.socket_factory->AddSocketDataProvider(&first_data);
10453 SSLSocketDataProvider ssl_http11(ASYNC, OK); 10493 SSLSocketDataProvider ssl_http11(ASYNC, OK);
10454 ssl_http11.next_proto = kProtoHTTP11; 10494 ssl_http11.next_proto = kProtoHTTP11;
10455 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); 10495 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11);
10456 10496
10457 MockRead data_reads[] = { 10497 MockRead data_reads[] = {
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
10752 EXPECT_THAT(callback.WaitForResult(), IsOk()); 10792 EXPECT_THAT(callback.WaitForResult(), IsOk());
10753 } 10793 }
10754 10794
10755 // Ensure that we are not allowed to redirect traffic via an alternate protocol 10795 // Ensure that we are not allowed to redirect traffic via an alternate protocol
10756 // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job 10796 // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job
10757 // once the alternate protocol request fails. 10797 // once the alternate protocol request fails.
10758 TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { 10798 TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) {
10759 HttpRequestInfo request; 10799 HttpRequestInfo request;
10760 request.method = "GET"; 10800 request.method = "GET";
10761 request.url = GURL("http://www.example.org/"); 10801 request.url = GURL("http://www.example.org/");
10762 request.load_flags = 0;
10763 10802
10764 // The alternate protocol request will error out before we attempt to connect, 10803 // The alternate protocol request will error out before we attempt to connect,
10765 // so only the standard HTTP request will try to connect. 10804 // so only the standard HTTP request will try to connect.
10766 MockRead data_reads[] = { 10805 MockRead data_reads[] = {
10767 MockRead("HTTP/1.1 200 OK\r\n\r\n"), 10806 MockRead("HTTP/1.1 200 OK\r\n\r\n"),
10768 MockRead("hello world"), 10807 MockRead("hello world"),
10769 MockRead(ASYNC, OK), 10808 MockRead(ASYNC, OK),
10770 }; 10809 };
10771 StaticSocketDataProvider data( 10810 StaticSocketDataProvider data(
10772 data_reads, arraysize(data_reads), NULL, 0); 10811 data_reads, arraysize(data_reads), NULL, 0);
(...skipping 26 matching lines...) Expand all
10799 10838
10800 std::string response_data; 10839 std::string response_data;
10801 ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); 10840 ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk());
10802 EXPECT_EQ("hello world", response_data); 10841 EXPECT_EQ("hello world", response_data);
10803 } 10842 }
10804 10843
10805 TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { 10844 TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) {
10806 HttpRequestInfo request; 10845 HttpRequestInfo request;
10807 request.method = "GET"; 10846 request.method = "GET";
10808 request.url = GURL("https://www.example.org/"); 10847 request.url = GURL("https://www.example.org/");
10809 request.load_flags = 0;
10810 10848
10811 MockRead data_reads[] = { 10849 MockRead data_reads[] = {
10812 MockRead("HTTP/1.1 200 OK\r\n"), 10850 MockRead("HTTP/1.1 200 OK\r\n"),
10813 MockRead(kAlternativeServiceHttpHeader), 10851 MockRead(kAlternativeServiceHttpHeader),
10814 MockRead("\r\n"), 10852 MockRead("\r\n"),
10815 MockRead("hello world"), 10853 MockRead("hello world"),
10816 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), 10854 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
10817 MockRead(ASYNC, OK)}; 10855 MockRead(ASYNC, OK)};
10818 10856
10819 StaticSocketDataProvider first_transaction( 10857 StaticSocketDataProvider first_transaction(
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
10880 EXPECT_TRUE(response->was_alpn_negotiated); 10918 EXPECT_TRUE(response->was_alpn_negotiated);
10881 10919
10882 ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); 10920 ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk());
10883 EXPECT_EQ("hello!", response_data); 10921 EXPECT_EQ("hello!", response_data);
10884 } 10922 }
10885 10923
10886 TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { 10924 TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) {
10887 HttpRequestInfo request; 10925 HttpRequestInfo request;
10888 request.method = "GET"; 10926 request.method = "GET";
10889 request.url = GURL("https://www.example.org/"); 10927 request.url = GURL("https://www.example.org/");
10890 request.load_flags = 0;
10891 10928
10892 // First transaction receives Alt-Svc header over HTTP/1.1. 10929 // First transaction receives Alt-Svc header over HTTP/1.1.
10893 MockRead data_reads[] = { 10930 MockRead data_reads[] = {
10894 MockRead("HTTP/1.1 200 OK\r\n"), 10931 MockRead("HTTP/1.1 200 OK\r\n"),
10895 MockRead(kAlternativeServiceHttpHeader), 10932 MockRead(kAlternativeServiceHttpHeader),
10896 MockRead("\r\n"), 10933 MockRead("\r\n"),
10897 MockRead("hello world"), 10934 MockRead("hello world"),
10898 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), 10935 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
10899 MockRead(ASYNC, OK), 10936 MockRead(ASYNC, OK),
10900 }; 10937 };
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
10993 EXPECT_TRUE(response->was_fetched_via_spdy); 11030 EXPECT_TRUE(response->was_fetched_via_spdy);
10994 EXPECT_TRUE(response->was_alpn_negotiated); 11031 EXPECT_TRUE(response->was_alpn_negotiated);
10995 ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); 11032 ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk());
10996 EXPECT_EQ("hello!", response_data); 11033 EXPECT_EQ("hello!", response_data);
10997 } 11034 }
10998 11035
10999 TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { 11036 TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) {
11000 HttpRequestInfo request; 11037 HttpRequestInfo request;
11001 request.method = "GET"; 11038 request.method = "GET";
11002 request.url = GURL("https://www.example.org/"); 11039 request.url = GURL("https://www.example.org/");
11003 request.load_flags = 0;
11004 11040
11005 MockRead data_reads[] = { 11041 MockRead data_reads[] = {
11006 MockRead("HTTP/1.1 200 OK\r\n"), 11042 MockRead("HTTP/1.1 200 OK\r\n"),
11007 MockRead(kAlternativeServiceHttpHeader), 11043 MockRead(kAlternativeServiceHttpHeader),
11008 MockRead("\r\n"), 11044 MockRead("\r\n"),
11009 MockRead("hello world"), 11045 MockRead("hello world"),
11010 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), 11046 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
11011 MockRead(ASYNC, OK), 11047 MockRead(ASYNC, OK),
11012 }; 11048 };
11013 11049
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
11208 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), 11244 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config),
11209 base::MakeUnique<CapturingProxyResolverFactory>( 11245 base::MakeUnique<CapturingProxyResolverFactory>(
11210 &capturing_proxy_resolver), 11246 &capturing_proxy_resolver),
11211 NULL)); 11247 NULL));
11212 TestNetLog net_log; 11248 TestNetLog net_log;
11213 session_deps_.net_log = &net_log; 11249 session_deps_.net_log = &net_log;
11214 11250
11215 HttpRequestInfo request; 11251 HttpRequestInfo request;
11216 request.method = "GET"; 11252 request.method = "GET";
11217 request.url = GURL("https://www.example.org/"); 11253 request.url = GURL("https://www.example.org/");
11218 request.load_flags = 0;
11219 11254
11220 MockRead data_reads[] = { 11255 MockRead data_reads[] = {
11221 MockRead("HTTP/1.1 200 OK\r\n"), 11256 MockRead("HTTP/1.1 200 OK\r\n"),
11222 MockRead(kAlternativeServiceHttpHeader), 11257 MockRead(kAlternativeServiceHttpHeader),
11223 MockRead("\r\n"), 11258 MockRead("\r\n"),
11224 MockRead("hello world"), 11259 MockRead("hello world"),
11225 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), 11260 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
11226 MockRead(ASYNC, OK), 11261 MockRead(ASYNC, OK),
11227 }; 11262 };
11228 11263
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
11312 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); 11347 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
11313 TestLoadTimingNotReusedWithPac(load_timing_info, 11348 TestLoadTimingNotReusedWithPac(load_timing_info,
11314 CONNECT_TIMING_HAS_SSL_TIMES); 11349 CONNECT_TIMING_HAS_SSL_TIMES);
11315 } 11350 }
11316 11351
11317 TEST_F(HttpNetworkTransactionTest, 11352 TEST_F(HttpNetworkTransactionTest,
11318 UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { 11353 UseAlternativeServiceForNpnSpdyWithExistingSpdySession) {
11319 HttpRequestInfo request; 11354 HttpRequestInfo request;
11320 request.method = "GET"; 11355 request.method = "GET";
11321 request.url = GURL("https://www.example.org/"); 11356 request.url = GURL("https://www.example.org/");
11322 request.load_flags = 0;
11323 11357
11324 MockRead data_reads[] = { 11358 MockRead data_reads[] = {
11325 MockRead("HTTP/1.1 200 OK\r\n"), 11359 MockRead("HTTP/1.1 200 OK\r\n"),
11326 MockRead(kAlternativeServiceHttpHeader), 11360 MockRead(kAlternativeServiceHttpHeader),
11327 MockRead("\r\n"), 11361 MockRead("\r\n"),
11328 MockRead("hello world"), 11362 MockRead("hello world"),
11329 MockRead(ASYNC, OK), 11363 MockRead(ASYNC, OK),
11330 }; 11364 };
11331 11365
11332 StaticSocketDataProvider first_transaction( 11366 StaticSocketDataProvider first_transaction(
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after
12140 if (test_config.proxy_url) { 12174 if (test_config.proxy_url) {
12141 session_deps_.proxy_service = 12175 session_deps_.proxy_service =
12142 ProxyService::CreateFixed(test_config.proxy_url); 12176 ProxyService::CreateFixed(test_config.proxy_url);
12143 } else { 12177 } else {
12144 session_deps_.proxy_service = ProxyService::CreateDirect(); 12178 session_deps_.proxy_service = ProxyService::CreateDirect();
12145 } 12179 }
12146 12180
12147 HttpRequestInfo request; 12181 HttpRequestInfo request;
12148 request.method = "GET"; 12182 request.method = "GET";
12149 request.url = GURL(test_config.server_url); 12183 request.url = GURL(test_config.server_url);
12150 request.load_flags = 0;
12151 12184
12152 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 12185 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12153 12186
12154 SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); 12187 SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK);
12155 12188
12156 std::vector<std::vector<MockRead>> mock_reads(1); 12189 std::vector<std::vector<MockRead>> mock_reads(1);
12157 std::vector<std::vector<MockWrite>> mock_writes(1); 12190 std::vector<std::vector<MockWrite>> mock_writes(1);
12158 for (int round = 0; round < test_config.num_auth_rounds; ++round) { 12191 for (int round = 0; round < test_config.num_auth_rounds; ++round) {
12159 const TestRound& read_write_round = test_config.rounds[round]; 12192 const TestRound& read_write_round = test_config.rounds[round];
12160 12193
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
12244 SSLInfo empty_ssl_info; 12277 SSLInfo empty_ssl_info;
12245 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, 12278 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER,
12246 empty_ssl_info, origin, NetLogWithSource()); 12279 empty_ssl_info, origin, NetLogWithSource());
12247 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); 12280 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER);
12248 12281
12249 int rv = OK; 12282 int rv = OK;
12250 const HttpResponseInfo* response = NULL; 12283 const HttpResponseInfo* response = NULL;
12251 HttpRequestInfo request; 12284 HttpRequestInfo request;
12252 request.method = "GET"; 12285 request.method = "GET";
12253 request.url = origin; 12286 request.url = origin;
12254 request.load_flags = 0;
12255 12287
12256 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 12288 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12257 12289
12258 // Use a TCP Socket Pool with only one connection per group. This is used 12290 // Use a TCP Socket Pool with only one connection per group. This is used
12259 // to validate that the TCP socket is not released to the pool between 12291 // to validate that the TCP socket is not released to the pool between
12260 // each round of multi-round authentication. 12292 // each round of multi-round authentication.
12261 HttpNetworkSessionPeer session_peer(session.get()); 12293 HttpNetworkSessionPeer session_peer(session.get());
12262 TransportClientSocketPool* transport_pool = new TransportClientSocketPool( 12294 TransportClientSocketPool* transport_pool = new TransportClientSocketPool(
12263 50, // Max sockets for pool 12295 50, // Max sockets for pool
12264 1, // Max sockets per group 12296 1, // Max sockets per group
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
12407 // Finally, the socket is released to the group. 12439 // Finally, the socket is released to the group.
12408 EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); 12440 EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup));
12409 } 12441 }
12410 12442
12411 // This tests the case that a request is issued via http instead of spdy after 12443 // This tests the case that a request is issued via http instead of spdy after
12412 // npn is negotiated. 12444 // npn is negotiated.
12413 TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { 12445 TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) {
12414 HttpRequestInfo request; 12446 HttpRequestInfo request;
12415 request.method = "GET"; 12447 request.method = "GET";
12416 request.url = GURL("https://www.example.org/"); 12448 request.url = GURL("https://www.example.org/");
12417 request.load_flags = 0;
12418 12449
12419 MockWrite data_writes[] = { 12450 MockWrite data_writes[] = {
12420 MockWrite( 12451 MockWrite(
12421 "GET / HTTP/1.1\r\n" 12452 "GET / HTTP/1.1\r\n"
12422 "Host: www.example.org\r\n" 12453 "Host: www.example.org\r\n"
12423 "Connection: keep-alive\r\n\r\n"), 12454 "Connection: keep-alive\r\n\r\n"),
12424 }; 12455 };
12425 12456
12426 MockRead data_reads[] = { 12457 MockRead data_reads[] = {
12427 MockRead("HTTP/1.1 200 OK\r\n"), 12458 MockRead("HTTP/1.1 200 OK\r\n"),
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
12463 EXPECT_TRUE(response->was_alpn_negotiated); 12494 EXPECT_TRUE(response->was_alpn_negotiated);
12464 } 12495 }
12465 12496
12466 // Simulate the SSL handshake completing with an NPN negotiation followed by an 12497 // Simulate the SSL handshake completing with an NPN negotiation followed by an
12467 // immediate server closing of the socket. 12498 // immediate server closing of the socket.
12468 // Regression test for https://crbug.com/46369. 12499 // Regression test for https://crbug.com/46369.
12469 TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { 12500 TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) {
12470 HttpRequestInfo request; 12501 HttpRequestInfo request;
12471 request.method = "GET"; 12502 request.method = "GET";
12472 request.url = GURL("https://www.example.org/"); 12503 request.url = GURL("https://www.example.org/");
12473 request.load_flags = 0;
12474 12504
12475 SSLSocketDataProvider ssl(ASYNC, OK); 12505 SSLSocketDataProvider ssl(ASYNC, OK);
12476 ssl.next_proto = kProtoHTTP2; 12506 ssl.next_proto = kProtoHTTP2;
12477 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 12507 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
12478 12508
12479 SpdySerializedFrame req( 12509 SpdySerializedFrame req(
12480 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); 12510 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true));
12481 MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; 12511 MockWrite spdy_writes[] = {CreateMockWrite(req, 1)};
12482 12512
12483 MockRead spdy_reads[] = { 12513 MockRead spdy_reads[] = {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
12532 MockConnect mock_connect(SYNCHRONOUS, OK); 12562 MockConnect mock_connect(SYNCHRONOUS, OK);
12533 MockRead data_reads[] = { 12563 MockRead data_reads[] = {
12534 MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), 12564 MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"),
12535 MockRead(SYNCHRONOUS, "hello world"), 12565 MockRead(SYNCHRONOUS, "hello world"),
12536 MockRead(SYNCHRONOUS, OK), 12566 MockRead(SYNCHRONOUS, OK),
12537 }; 12567 };
12538 12568
12539 HttpRequestInfo request; 12569 HttpRequestInfo request;
12540 request.method = "GET"; 12570 request.method = "GET";
12541 request.url = GURL("http://www.example.org/"); 12571 request.url = GURL("http://www.example.org/");
12542 request.load_flags = 0;
12543 12572
12544 session_deps_.host_resolver->set_synchronous_mode(true); 12573 session_deps_.host_resolver->set_synchronous_mode(true);
12545 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 12574 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12546 std::unique_ptr<HttpNetworkTransaction> trans( 12575 std::unique_ptr<HttpNetworkTransaction> trans(
12547 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 12576 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
12548 12577
12549 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 12578 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
12550 data.set_connect_data(mock_connect); 12579 data.set_connect_data(mock_connect);
12551 session_deps_.socket_factory->AddSocketDataProvider(&data); 12580 session_deps_.socket_factory->AddSocketDataProvider(&data);
12552 12581
(...skipping 26 matching lines...) Expand all
12579 }; 12608 };
12580 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 12609 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
12581 session_deps_.socket_factory->AddSocketDataProvider(&data); 12610 session_deps_.socket_factory->AddSocketDataProvider(&data);
12582 12611
12583 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 12612 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12584 12613
12585 { 12614 {
12586 HttpRequestInfo request; 12615 HttpRequestInfo request;
12587 request.method = "GET"; 12616 request.method = "GET";
12588 request.url = GURL("http://www.example.org/"); 12617 request.url = GURL("http://www.example.org/");
12589 request.load_flags = 0;
12590 12618
12591 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 12619 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
12592 TestCompletionCallback callback; 12620 TestCompletionCallback callback;
12593 12621
12594 int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); 12622 int rv = trans.Start(&request, callback.callback(), NetLogWithSource());
12595 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 12623 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
12596 callback.WaitForResult(); 12624 callback.WaitForResult();
12597 12625
12598 const HttpResponseInfo* response = trans.GetResponseInfo(); 12626 const HttpResponseInfo* response = trans.GetResponseInfo();
12599 ASSERT_TRUE(response); 12627 ASSERT_TRUE(response);
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
12913 // Set up an initial SpdySession in the pool to reuse. 12941 // Set up an initial SpdySession in the pool to reuse.
12914 HostPortPair host_port_pair("www.example.org", 443); 12942 HostPortPair host_port_pair("www.example.org", 443);
12915 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), 12943 SpdySessionKey key(host_port_pair, ProxyServer::Direct(),
12916 PRIVACY_MODE_DISABLED); 12944 PRIVACY_MODE_DISABLED);
12917 base::WeakPtr<SpdySession> spdy_session = 12945 base::WeakPtr<SpdySession> spdy_session =
12918 CreateSecureSpdySession(session.get(), key, NetLogWithSource()); 12946 CreateSecureSpdySession(session.get(), key, NetLogWithSource());
12919 12947
12920 HttpRequestInfo request; 12948 HttpRequestInfo request;
12921 request.method = "GET"; 12949 request.method = "GET";
12922 request.url = GURL("https://www.example.org/"); 12950 request.url = GURL("https://www.example.org/");
12923 request.load_flags = 0;
12924 12951
12925 // This is the important line that marks this as a preconnect. 12952 // This is the important line that marks this as a preconnect.
12926 request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; 12953 request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED;
12927 12954
12928 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 12955 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
12929 12956
12930 TestCompletionCallback callback; 12957 TestCompletionCallback callback;
12931 int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); 12958 int rv = trans.Start(&request, callback.callback(), NetLogWithSource());
12932 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 12959 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
12933 EXPECT_THAT(callback.WaitForResult(), IsOk()); 12960 EXPECT_THAT(callback.WaitForResult(), IsOk());
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
13681 AlternativeService alternative_service( 13708 AlternativeService alternative_service(
13682 AlternateProtocolFromNextProto(kProtoHTTP2), alternative); 13709 AlternateProtocolFromNextProto(kProtoHTTP2), alternative);
13683 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 13710 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
13684 http_server_properties->SetAlternativeService(server, alternative_service, 13711 http_server_properties->SetAlternativeService(server, alternative_service,
13685 expiration); 13712 expiration);
13686 13713
13687 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 13714 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
13688 HttpRequestInfo request; 13715 HttpRequestInfo request;
13689 request.method = "GET"; 13716 request.method = "GET";
13690 request.url = GURL("https://www.example.org:443"); 13717 request.url = GURL("https://www.example.org:443");
13691 request.load_flags = 0;
13692 TestCompletionCallback callback; 13718 TestCompletionCallback callback;
13693 13719
13694 // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is 13720 // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is
13695 // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. 13721 // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED.
13696 int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); 13722 int rv = trans.Start(&request, callback.callback(), NetLogWithSource());
13697 EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); 13723 EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED));
13698 } 13724 }
13699 13725
13700 // A request to a server with an alternative service fires two Jobs: one to the 13726 // A request to a server with an alternative service fires two Jobs: one to the
13701 // server, and an alternate one to the alternative server. If the former 13727 // server, and an alternate one to the alternative server. If the former
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
14381 EXPECT_FALSE( 14407 EXPECT_FALSE(
14382 HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); 14408 HasSpdySession(session->spdy_session_pool(), spdy_session_key_a));
14383 EXPECT_FALSE( 14409 EXPECT_FALSE(
14384 HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); 14410 HasSpdySession(session->spdy_session_pool(), spdy_session_key_b));
14385 } 14411 }
14386 14412
14387 TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { 14413 TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) {
14388 HttpRequestInfo request; 14414 HttpRequestInfo request;
14389 request.method = "GET"; 14415 request.method = "GET";
14390 request.url = GURL("http://www.example.org/"); 14416 request.url = GURL("http://www.example.org/");
14391 request.load_flags = 0;
14392 14417
14393 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 14418 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
14394 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 14419 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
14395 14420
14396 MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); 14421 MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED);
14397 StaticSocketDataProvider data; 14422 StaticSocketDataProvider data;
14398 data.set_connect_data(mock_connect); 14423 data.set_connect_data(mock_connect);
14399 session_deps_.socket_factory->AddSocketDataProvider(&data); 14424 session_deps_.socket_factory->AddSocketDataProvider(&data);
14400 14425
14401 TestCompletionCallback callback; 14426 TestCompletionCallback callback;
(...skipping 15 matching lines...) Expand all
14417 14442
14418 IPEndPoint endpoint; 14443 IPEndPoint endpoint;
14419 EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); 14444 EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint));
14420 EXPECT_TRUE(endpoint.address().empty()); 14445 EXPECT_TRUE(endpoint.address().empty());
14421 } 14446 }
14422 14447
14423 TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { 14448 TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) {
14424 HttpRequestInfo request; 14449 HttpRequestInfo request;
14425 request.method = "GET"; 14450 request.method = "GET";
14426 request.url = GURL("http://www.example.org/"); 14451 request.url = GURL("http://www.example.org/");
14427 request.load_flags = 0;
14428 14452
14429 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 14453 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
14430 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 14454 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
14431 14455
14432 MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); 14456 MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED);
14433 StaticSocketDataProvider data; 14457 StaticSocketDataProvider data;
14434 data.set_connect_data(mock_connect); 14458 data.set_connect_data(mock_connect);
14435 session_deps_.socket_factory->AddSocketDataProvider(&data); 14459 session_deps_.socket_factory->AddSocketDataProvider(&data);
14436 14460
14437 TestCompletionCallback callback; 14461 TestCompletionCallback callback;
(...skipping 15 matching lines...) Expand all
14453 14477
14454 IPEndPoint endpoint; 14478 IPEndPoint endpoint;
14455 EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); 14479 EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint));
14456 EXPECT_TRUE(endpoint.address().empty()); 14480 EXPECT_TRUE(endpoint.address().empty());
14457 } 14481 }
14458 14482
14459 TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { 14483 TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) {
14460 HttpRequestInfo request; 14484 HttpRequestInfo request;
14461 request.method = "GET"; 14485 request.method = "GET";
14462 request.url = GURL("http://www.example.org/"); 14486 request.url = GURL("http://www.example.org/");
14463 request.load_flags = 0;
14464 14487
14465 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 14488 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
14466 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 14489 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
14467 14490
14468 MockWrite data_writes[] = { 14491 MockWrite data_writes[] = {
14469 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), 14492 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
14470 }; 14493 };
14471 MockRead data_reads[] = { 14494 MockRead data_reads[] = {
14472 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. 14495 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached.
14473 }; 14496 };
(...skipping 12 matching lines...) Expand all
14486 14509
14487 HttpRequestHeaders request_headers; 14510 HttpRequestHeaders request_headers;
14488 EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); 14511 EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers));
14489 EXPECT_TRUE(request_headers.HasHeader("Host")); 14512 EXPECT_TRUE(request_headers.HasHeader("Host"));
14490 } 14513 }
14491 14514
14492 TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { 14515 TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) {
14493 HttpRequestInfo request; 14516 HttpRequestInfo request;
14494 request.method = "GET"; 14517 request.method = "GET";
14495 request.url = GURL("http://www.example.org/"); 14518 request.url = GURL("http://www.example.org/");
14496 request.load_flags = 0;
14497 14519
14498 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 14520 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
14499 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 14521 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
14500 14522
14501 MockWrite data_writes[] = { 14523 MockWrite data_writes[] = {
14502 MockWrite(ASYNC, ERR_CONNECTION_RESET), 14524 MockWrite(ASYNC, ERR_CONNECTION_RESET),
14503 }; 14525 };
14504 MockRead data_reads[] = { 14526 MockRead data_reads[] = {
14505 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. 14527 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached.
14506 }; 14528 };
(...skipping 12 matching lines...) Expand all
14519 14541
14520 HttpRequestHeaders request_headers; 14542 HttpRequestHeaders request_headers;
14521 EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); 14543 EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers));
14522 EXPECT_TRUE(request_headers.HasHeader("Host")); 14544 EXPECT_TRUE(request_headers.HasHeader("Host"));
14523 } 14545 }
14524 14546
14525 TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { 14547 TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) {
14526 HttpRequestInfo request; 14548 HttpRequestInfo request;
14527 request.method = "GET"; 14549 request.method = "GET";
14528 request.url = GURL("http://www.example.org/"); 14550 request.url = GURL("http://www.example.org/");
14529 request.load_flags = 0;
14530 14551
14531 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 14552 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
14532 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 14553 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
14533 14554
14534 MockWrite data_writes[] = { 14555 MockWrite data_writes[] = {
14535 MockWrite( 14556 MockWrite(
14536 "GET / HTTP/1.1\r\n" 14557 "GET / HTTP/1.1\r\n"
14537 "Host: www.example.org\r\n" 14558 "Host: www.example.org\r\n"
14538 "Connection: keep-alive\r\n\r\n"), 14559 "Connection: keep-alive\r\n\r\n"),
14539 }; 14560 };
(...skipping 15 matching lines...) Expand all
14555 14576
14556 HttpRequestHeaders request_headers; 14577 HttpRequestHeaders request_headers;
14557 EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); 14578 EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers));
14558 EXPECT_TRUE(request_headers.HasHeader("Host")); 14579 EXPECT_TRUE(request_headers.HasHeader("Host"));
14559 } 14580 }
14560 14581
14561 TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { 14582 TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) {
14562 HttpRequestInfo request; 14583 HttpRequestInfo request;
14563 request.method = "GET"; 14584 request.method = "GET";
14564 request.url = GURL("http://www.example.org/"); 14585 request.url = GURL("http://www.example.org/");
14565 request.load_flags = 0;
14566 14586
14567 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 14587 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
14568 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 14588 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
14569 14589
14570 MockWrite data_writes[] = { 14590 MockWrite data_writes[] = {
14571 MockWrite( 14591 MockWrite(
14572 "GET / HTTP/1.1\r\n" 14592 "GET / HTTP/1.1\r\n"
14573 "Host: www.example.org\r\n" 14593 "Host: www.example.org\r\n"
14574 "Connection: keep-alive\r\n\r\n"), 14594 "Connection: keep-alive\r\n\r\n"),
14575 }; 14595 };
(...skipping 15 matching lines...) Expand all
14591 14611
14592 HttpRequestHeaders request_headers; 14612 HttpRequestHeaders request_headers;
14593 EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); 14613 EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers));
14594 EXPECT_TRUE(request_headers.HasHeader("Host")); 14614 EXPECT_TRUE(request_headers.HasHeader("Host"));
14595 } 14615 }
14596 14616
14597 TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { 14617 TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) {
14598 HttpRequestInfo request; 14618 HttpRequestInfo request;
14599 request.method = "GET"; 14619 request.method = "GET";
14600 request.url = GURL("http://www.example.org/"); 14620 request.url = GURL("http://www.example.org/");
14601 request.load_flags = 0;
14602 request.extra_headers.SetHeader("X-Foo", "bar"); 14621 request.extra_headers.SetHeader("X-Foo", "bar");
14603 14622
14604 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 14623 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
14605 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 14624 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
14606 14625
14607 MockWrite data_writes[] = { 14626 MockWrite data_writes[] = {
14608 MockWrite( 14627 MockWrite(
14609 "GET / HTTP/1.1\r\n" 14628 "GET / HTTP/1.1\r\n"
14610 "Host: www.example.org\r\n" 14629 "Host: www.example.org\r\n"
14611 "Connection: keep-alive\r\n" 14630 "Connection: keep-alive\r\n"
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
15280 TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { 15299 TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) {
15281 std::vector<std::unique_ptr<UploadElementReader>> element_readers; 15300 std::vector<std::unique_ptr<UploadElementReader>> element_readers;
15282 element_readers.push_back( 15301 element_readers.push_back(
15283 base::MakeUnique<UploadBytesElementReader>("foo", 3)); 15302 base::MakeUnique<UploadBytesElementReader>("foo", 3));
15284 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); 15303 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0);
15285 15304
15286 HttpRequestInfo request; 15305 HttpRequestInfo request;
15287 request.method = "POST"; 15306 request.method = "POST";
15288 request.url = GURL("http://www.foo.com/"); 15307 request.url = GURL("http://www.foo.com/");
15289 request.upload_data_stream = &upload_data_stream; 15308 request.upload_data_stream = &upload_data_stream;
15290 request.load_flags = 0;
15291 15309
15292 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 15310 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
15293 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 15311 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
15294 // Send headers successfully, but get an error while sending the body. 15312 // Send headers successfully, but get an error while sending the body.
15295 MockWrite data_writes[] = { 15313 MockWrite data_writes[] = {
15296 MockWrite("POST / HTTP/1.1\r\n" 15314 MockWrite("POST / HTTP/1.1\r\n"
15297 "Host: www.foo.com\r\n" 15315 "Host: www.foo.com\r\n"
15298 "Connection: keep-alive\r\n" 15316 "Connection: keep-alive\r\n"
15299 "Content-Length: 3\r\n\r\n"), 15317 "Content-Length: 3\r\n\r\n"),
15300 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), 15318 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
15419 PostReadsErrorResponseAfterResetPartialBodySent) { 15437 PostReadsErrorResponseAfterResetPartialBodySent) {
15420 std::vector<std::unique_ptr<UploadElementReader>> element_readers; 15438 std::vector<std::unique_ptr<UploadElementReader>> element_readers;
15421 element_readers.push_back( 15439 element_readers.push_back(
15422 base::MakeUnique<UploadBytesElementReader>("foo", 3)); 15440 base::MakeUnique<UploadBytesElementReader>("foo", 3));
15423 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); 15441 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0);
15424 15442
15425 HttpRequestInfo request; 15443 HttpRequestInfo request;
15426 request.method = "POST"; 15444 request.method = "POST";
15427 request.url = GURL("http://www.foo.com/"); 15445 request.url = GURL("http://www.foo.com/");
15428 request.upload_data_stream = &upload_data_stream; 15446 request.upload_data_stream = &upload_data_stream;
15429 request.load_flags = 0;
15430 15447
15431 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 15448 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
15432 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 15449 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
15433 // Send headers successfully, but get an error while sending the body. 15450 // Send headers successfully, but get an error while sending the body.
15434 MockWrite data_writes[] = { 15451 MockWrite data_writes[] = {
15435 MockWrite("POST / HTTP/1.1\r\n" 15452 MockWrite("POST / HTTP/1.1\r\n"
15436 "Host: www.foo.com\r\n" 15453 "Host: www.foo.com\r\n"
15437 "Connection: keep-alive\r\n" 15454 "Connection: keep-alive\r\n"
15438 "Content-Length: 3\r\n\r\n" 15455 "Content-Length: 3\r\n\r\n"
15439 "fo"), 15456 "fo"),
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
15471 15488
15472 // This tests the more common case than the previous test, where headers and 15489 // This tests the more common case than the previous test, where headers and
15473 // body are not merged into a single request. 15490 // body are not merged into a single request.
15474 TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { 15491 TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) {
15475 ChunkedUploadDataStream upload_data_stream(0); 15492 ChunkedUploadDataStream upload_data_stream(0);
15476 15493
15477 HttpRequestInfo request; 15494 HttpRequestInfo request;
15478 request.method = "POST"; 15495 request.method = "POST";
15479 request.url = GURL("http://www.foo.com/"); 15496 request.url = GURL("http://www.foo.com/");
15480 request.upload_data_stream = &upload_data_stream; 15497 request.upload_data_stream = &upload_data_stream;
15481 request.load_flags = 0;
15482 15498
15483 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 15499 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
15484 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 15500 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
15485 // Send headers successfully, but get an error while sending the body. 15501 // Send headers successfully, but get an error while sending the body.
15486 MockWrite data_writes[] = { 15502 MockWrite data_writes[] = {
15487 MockWrite("POST / HTTP/1.1\r\n" 15503 MockWrite("POST / HTTP/1.1\r\n"
15488 "Host: www.foo.com\r\n" 15504 "Host: www.foo.com\r\n"
15489 "Connection: keep-alive\r\n" 15505 "Connection: keep-alive\r\n"
15490 "Transfer-Encoding: chunked\r\n\r\n"), 15506 "Transfer-Encoding: chunked\r\n\r\n"),
15491 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), 15507 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
15530 TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { 15546 TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) {
15531 std::vector<std::unique_ptr<UploadElementReader>> element_readers; 15547 std::vector<std::unique_ptr<UploadElementReader>> element_readers;
15532 element_readers.push_back( 15548 element_readers.push_back(
15533 base::MakeUnique<UploadBytesElementReader>("foo", 3)); 15549 base::MakeUnique<UploadBytesElementReader>("foo", 3));
15534 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); 15550 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0);
15535 15551
15536 HttpRequestInfo request; 15552 HttpRequestInfo request;
15537 request.method = "POST"; 15553 request.method = "POST";
15538 request.url = GURL("http://www.foo.com/"); 15554 request.url = GURL("http://www.foo.com/");
15539 request.upload_data_stream = &upload_data_stream; 15555 request.upload_data_stream = &upload_data_stream;
15540 request.load_flags = 0;
15541 15556
15542 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 15557 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
15543 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 15558 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
15544 15559
15545 MockWrite data_writes[] = { 15560 MockWrite data_writes[] = {
15546 MockWrite("POST / HTTP/1.1\r\n" 15561 MockWrite("POST / HTTP/1.1\r\n"
15547 "Host: www.foo.com\r\n" 15562 "Host: www.foo.com\r\n"
15548 "Connection: keep-alive\r\n" 15563 "Connection: keep-alive\r\n"
15549 "Content-Length: 3\r\n\r\n"), 15564 "Content-Length: 3\r\n\r\n"),
15550 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), 15565 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
15583 TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { 15598 TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) {
15584 std::vector<std::unique_ptr<UploadElementReader>> element_readers; 15599 std::vector<std::unique_ptr<UploadElementReader>> element_readers;
15585 element_readers.push_back( 15600 element_readers.push_back(
15586 base::MakeUnique<UploadBytesElementReader>("foo", 3)); 15601 base::MakeUnique<UploadBytesElementReader>("foo", 3));
15587 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); 15602 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0);
15588 15603
15589 HttpRequestInfo request; 15604 HttpRequestInfo request;
15590 request.method = "POST"; 15605 request.method = "POST";
15591 request.url = GURL("http://www.foo.com/"); 15606 request.url = GURL("http://www.foo.com/");
15592 request.upload_data_stream = &upload_data_stream; 15607 request.upload_data_stream = &upload_data_stream;
15593 request.load_flags = 0;
15594 15608
15595 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 15609 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
15596 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 15610 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
15597 // Send headers successfully, but get an error while sending the body. 15611 // Send headers successfully, but get an error while sending the body.
15598 MockWrite data_writes[] = { 15612 MockWrite data_writes[] = {
15599 MockWrite("POST / HTTP/1.1\r\n" 15613 MockWrite("POST / HTTP/1.1\r\n"
15600 "Host: www.foo.com\r\n" 15614 "Host: www.foo.com\r\n"
15601 "Connection: keep-alive\r\n" 15615 "Connection: keep-alive\r\n"
15602 "Content-Length: 3\r\n\r\n"), 15616 "Content-Length: 3\r\n\r\n"),
15603 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), 15617 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
(...skipping 21 matching lines...) Expand all
15625 PostIgnoresNonErrorResponseAfterResetAnd100) { 15639 PostIgnoresNonErrorResponseAfterResetAnd100) {
15626 std::vector<std::unique_ptr<UploadElementReader>> element_readers; 15640 std::vector<std::unique_ptr<UploadElementReader>> element_readers;
15627 element_readers.push_back( 15641 element_readers.push_back(
15628 base::MakeUnique<UploadBytesElementReader>("foo", 3)); 15642 base::MakeUnique<UploadBytesElementReader>("foo", 3));
15629 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); 15643 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0);
15630 15644
15631 HttpRequestInfo request; 15645 HttpRequestInfo request;
15632 request.method = "POST"; 15646 request.method = "POST";
15633 request.url = GURL("http://www.foo.com/"); 15647 request.url = GURL("http://www.foo.com/");
15634 request.upload_data_stream = &upload_data_stream; 15648 request.upload_data_stream = &upload_data_stream;
15635 request.load_flags = 0;
15636 15649
15637 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 15650 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
15638 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 15651 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
15639 // Send headers successfully, but get an error while sending the body. 15652 // Send headers successfully, but get an error while sending the body.
15640 MockWrite data_writes[] = { 15653 MockWrite data_writes[] = {
15641 MockWrite("POST / HTTP/1.1\r\n" 15654 MockWrite("POST / HTTP/1.1\r\n"
15642 "Host: www.foo.com\r\n" 15655 "Host: www.foo.com\r\n"
15643 "Connection: keep-alive\r\n" 15656 "Connection: keep-alive\r\n"
15644 "Content-Length: 3\r\n\r\n"), 15657 "Content-Length: 3\r\n\r\n"),
15645 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), 15658 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
(...skipping 22 matching lines...) Expand all
15668 TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { 15681 TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) {
15669 std::vector<std::unique_ptr<UploadElementReader>> element_readers; 15682 std::vector<std::unique_ptr<UploadElementReader>> element_readers;
15670 element_readers.push_back( 15683 element_readers.push_back(
15671 base::MakeUnique<UploadBytesElementReader>("foo", 3)); 15684 base::MakeUnique<UploadBytesElementReader>("foo", 3));
15672 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); 15685 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0);
15673 15686
15674 HttpRequestInfo request; 15687 HttpRequestInfo request;
15675 request.method = "POST"; 15688 request.method = "POST";
15676 request.url = GURL("http://www.foo.com/"); 15689 request.url = GURL("http://www.foo.com/");
15677 request.upload_data_stream = &upload_data_stream; 15690 request.upload_data_stream = &upload_data_stream;
15678 request.load_flags = 0;
15679 15691
15680 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 15692 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
15681 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 15693 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
15682 // Send headers successfully, but get an error while sending the body. 15694 // Send headers successfully, but get an error while sending the body.
15683 MockWrite data_writes[] = { 15695 MockWrite data_writes[] = {
15684 MockWrite("POST / HTTP/1.1\r\n" 15696 MockWrite("POST / HTTP/1.1\r\n"
15685 "Host: www.foo.com\r\n" 15697 "Host: www.foo.com\r\n"
15686 "Connection: keep-alive\r\n" 15698 "Connection: keep-alive\r\n"
15687 "Content-Length: 3\r\n\r\n"), 15699 "Content-Length: 3\r\n\r\n"),
15688 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), 15700 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
(...skipping 19 matching lines...) Expand all
15708 TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { 15720 TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) {
15709 std::vector<std::unique_ptr<UploadElementReader>> element_readers; 15721 std::vector<std::unique_ptr<UploadElementReader>> element_readers;
15710 element_readers.push_back( 15722 element_readers.push_back(
15711 base::MakeUnique<UploadBytesElementReader>("foo", 3)); 15723 base::MakeUnique<UploadBytesElementReader>("foo", 3));
15712 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); 15724 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0);
15713 15725
15714 HttpRequestInfo request; 15726 HttpRequestInfo request;
15715 request.method = "POST"; 15727 request.method = "POST";
15716 request.url = GURL("http://www.foo.com/"); 15728 request.url = GURL("http://www.foo.com/");
15717 request.upload_data_stream = &upload_data_stream; 15729 request.upload_data_stream = &upload_data_stream;
15718 request.load_flags = 0;
15719 15730
15720 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 15731 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
15721 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 15732 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
15722 // Send headers successfully, but get an error while sending the body. 15733 // Send headers successfully, but get an error while sending the body.
15723 MockWrite data_writes[] = { 15734 MockWrite data_writes[] = {
15724 MockWrite("POST / HTTP/1.1\r\n" 15735 MockWrite("POST / HTTP/1.1\r\n"
15725 "Host: www.foo.com\r\n" 15736 "Host: www.foo.com\r\n"
15726 "Connection: keep-alive\r\n" 15737 "Connection: keep-alive\r\n"
15727 "Content-Length: 3\r\n\r\n"), 15738 "Content-Length: 3\r\n\r\n"),
15728 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), 15739 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
16058 16069
16059 std::string response_data; 16070 std::string response_data;
16060 EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); 16071 EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk());
16061 16072
16062 EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), 16073 EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)),
16063 trans.GetTotalSentBytes()); 16074 trans.GetTotalSentBytes());
16064 EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), 16075 EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)),
16065 trans.GetTotalReceivedBytes()); 16076 trans.GetTotalReceivedBytes());
16066 } 16077 }
16067 16078
16079 // Confirm that transactions whose throttle is created in (and stays in)
16080 // the unthrottled state are not blocked.
16081 TEST_F(HttpNetworkTransactionTest, ThrottlingUnthrottled) {
16082 TestNetworkStreamThrottler* throttler(nullptr);
16083 std::unique_ptr<HttpNetworkSession> session(
16084 CreateSessionWithThrottler(&session_deps_, &throttler));
16085
16086 // Send a simple request and make sure it goes through.
16087 HttpRequestInfo request;
16088 request.method = "GET";
16089 request.url = GURL("http://www.example.org/");
16090
16091 std::unique_ptr<HttpTransaction> trans(
16092 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
16093
16094 MockWrite data_writes[] = {
16095 MockWrite("GET / HTTP/1.1\r\n"
16096 "Host: www.example.org\r\n"
16097 "Connection: keep-alive\r\n\r\n"),
16098 };
16099 MockRead data_reads[] = {
16100 MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"),
16101 MockRead(SYNCHRONOUS, OK),
16102 };
16103 StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes,
16104 arraysize(data_writes));
16105 session_deps_.socket_factory->AddSocketDataProvider(&reads);
16106
16107 TestCompletionCallback callback;
16108 trans->Start(&request, callback.callback(), NetLogWithSource());
16109 EXPECT_EQ(OK, callback.WaitForResult());
16110 }
16111
16112 // Confirm requests can be blocked by a throttler, and are resumed
16113 // when the throttle is unblocked.
16114 TEST_F(HttpNetworkTransactionTest, ThrottlingBasic) {
16115 TestNetworkStreamThrottler* throttler(nullptr);
16116 std::unique_ptr<HttpNetworkSession> session(
16117 CreateSessionWithThrottler(&session_deps_, &throttler));
16118
16119 // Send a simple request and make sure it goes through.
16120 HttpRequestInfo request;
16121 request.method = "GET";
16122 request.url = GURL("http://www.example.org/");
16123
16124 MockWrite data_writes[] = {
16125 MockWrite("GET / HTTP/1.1\r\n"
16126 "Host: www.example.org\r\n"
16127 "Connection: keep-alive\r\n\r\n"),
16128 };
16129 MockRead data_reads[] = {
16130 MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"),
16131 MockRead(SYNCHRONOUS, OK),
16132 };
16133 StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes,
16134 arraysize(data_writes));
16135 session_deps_.socket_factory->AddSocketDataProvider(&reads);
16136
16137 // Start a request that will be throttled at start; confirm it
16138 // doesn't complete.
16139 throttler->set_throttle_new_requests(true);
16140 std::unique_ptr<HttpTransaction> trans(
16141 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
16142
16143 TestCompletionCallback callback;
16144 int rv = trans->Start(&request, callback.callback(), NetLogWithSource());
16145 EXPECT_EQ(ERR_IO_PENDING, rv);
16146
16147 base::RunLoop().RunUntilIdle();
16148 EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState());
16149 EXPECT_FALSE(callback.have_result());
16150
16151 // Confirm the request goes on to complete when unthrottled.
16152 throttler->UnthrottleAllRequests();
16153 base::RunLoop().RunUntilIdle();
16154 ASSERT_TRUE(callback.have_result());
16155 EXPECT_EQ(OK, callback.WaitForResult());
16156 }
16157
16158 // Destroy a request while it's throttled.
16159 TEST_F(HttpNetworkTransactionTest, ThrottlingDestruction) {
16160 TestNetworkStreamThrottler* throttler(nullptr);
16161 std::unique_ptr<HttpNetworkSession> session(
16162 CreateSessionWithThrottler(&session_deps_, &throttler));
16163
16164 // Send a simple request and make sure it goes through.
16165 HttpRequestInfo request;
16166 request.method = "GET";
16167 request.url = GURL("http://www.example.org/");
16168
16169 MockWrite data_writes[] = {
16170 MockWrite("GET / HTTP/1.1\r\n"
16171 "Host: www.example.org\r\n"
16172 "Connection: keep-alive\r\n\r\n"),
16173 };
16174 MockRead data_reads[] = {
16175 MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"),
16176 MockRead(SYNCHRONOUS, OK),
16177 };
16178 StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes,
16179 arraysize(data_writes));
16180 session_deps_.socket_factory->AddSocketDataProvider(&reads);
16181
16182 // Start a request that will be throttled at start; confirm it
16183 // doesn't complete.
16184 throttler->set_throttle_new_requests(true);
16185 std::unique_ptr<HttpTransaction> trans(
16186 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
16187
16188 TestCompletionCallback callback;
16189 int rv = trans->Start(&request, callback.callback(), NetLogWithSource());
16190 EXPECT_EQ(ERR_IO_PENDING, rv);
16191
16192 base::RunLoop().RunUntilIdle();
16193 EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState());
16194 EXPECT_FALSE(callback.have_result());
16195
16196 EXPECT_EQ(1u, throttler->num_outstanding_requests());
16197 trans.reset();
16198 EXPECT_EQ(0u, throttler->num_outstanding_requests());
16199 }
16200
16201 // Confirm the throttler receives SetPriority calls.
16202 TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySet) {
16203 TestNetworkStreamThrottler* throttler(nullptr);
16204 std::unique_ptr<HttpNetworkSession> session(
16205 CreateSessionWithThrottler(&session_deps_, &throttler));
16206
16207 // Send a simple request and make sure it goes through.
16208 HttpRequestInfo request;
16209 request.method = "GET";
16210 request.url = GURL("http://www.example.org/");
16211
16212 MockWrite data_writes[] = {
16213 MockWrite("GET / HTTP/1.1\r\n"
16214 "Host: www.example.org\r\n"
16215 "Connection: keep-alive\r\n\r\n"),
16216 };
16217 MockRead data_reads[] = {
16218 MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"),
16219 MockRead(SYNCHRONOUS, OK),
16220 };
16221 StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes,
16222 arraysize(data_writes));
16223 session_deps_.socket_factory->AddSocketDataProvider(&reads);
16224
16225 throttler->set_throttle_new_requests(true);
16226 std::unique_ptr<HttpTransaction> trans(
16227 new HttpNetworkTransaction(IDLE, session.get()));
16228 // Start the transaction to associate a throttle with it.
16229 TestCompletionCallback callback;
16230 int rv = trans->Start(&request, callback.callback(), NetLogWithSource());
16231 EXPECT_EQ(ERR_IO_PENDING, rv);
16232
16233 EXPECT_EQ(0, throttler->num_set_priority_calls());
16234 trans->SetPriority(LOW);
16235 EXPECT_EQ(1, throttler->num_set_priority_calls());
16236 EXPECT_EQ(LOW, throttler->last_priority_set());
16237
16238 throttler->UnthrottleAllRequests();
16239 base::RunLoop().RunUntilIdle();
16240 ASSERT_TRUE(callback.have_result());
16241 EXPECT_EQ(OK, callback.WaitForResult());
16242 }
16243
16244 // Confirm that unthrottling from a SetPriority call by the
16245 // throttler works properly.
16246 TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetUnthrottle) {
16247 TestNetworkStreamThrottler* throttler(nullptr);
16248 std::unique_ptr<HttpNetworkSession> session(
16249 CreateSessionWithThrottler(&session_deps_, &throttler));
16250
16251 // Send a simple request and make sure it goes through.
16252 HttpRequestInfo request;
16253 request.method = "GET";
16254 request.url = GURL("http://www.example.org/");
16255
16256 MockWrite data_writes[] = {
16257 MockWrite("GET / HTTP/1.1\r\n"
16258 "Host: www.example.org\r\n"
16259 "Connection: keep-alive\r\n\r\n"),
16260 };
16261 MockRead data_reads[] = {
16262 MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"),
16263 MockRead(SYNCHRONOUS, OK),
16264 };
16265 StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes,
16266 arraysize(data_writes));
16267 session_deps_.socket_factory->AddSocketDataProvider(&reads);
16268
16269 StaticSocketDataProvider reads1(data_reads, arraysize(data_reads),
16270 data_writes, arraysize(data_writes));
16271 session_deps_.socket_factory->AddSocketDataProvider(&reads1);
16272
16273 // Start a request that will be throttled at start; confirm it
16274 // doesn't complete.
16275 throttler->set_throttle_new_requests(true);
16276 std::unique_ptr<HttpTransaction> trans(
16277 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
16278
16279 TestCompletionCallback callback;
16280 int rv = trans->Start(&request, callback.callback(), NetLogWithSource());
16281 EXPECT_EQ(ERR_IO_PENDING, rv);
16282
16283 base::RunLoop().RunUntilIdle();
16284 EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState());
16285 EXPECT_FALSE(callback.have_result());
16286
16287 // Create a new request, call SetPriority on it to unthrottle,
16288 // and make sure that allows the original request to complete.
16289 std::unique_ptr<HttpTransaction> trans1(
16290 new HttpNetworkTransaction(LOW, session.get()));
16291 throttler->set_priority_change_closure(
16292 base::Bind(&TestNetworkStreamThrottler::UnthrottleAllRequests,
16293 base::Unretained(throttler)));
16294
16295 // Start the transaction to associate a throttle with it.
16296 TestCompletionCallback callback1;
16297 rv = trans1->Start(&request, callback1.callback(), NetLogWithSource());
16298 EXPECT_EQ(ERR_IO_PENDING, rv);
16299
16300 trans1->SetPriority(IDLE);
16301
16302 base::RunLoop().RunUntilIdle();
16303 ASSERT_TRUE(callback.have_result());
16304 EXPECT_EQ(OK, callback.WaitForResult());
16305 ASSERT_TRUE(callback1.have_result());
16306 EXPECT_EQ(OK, callback1.WaitForResult());
16307 }
16308
16309 // Transaction will be destroyed when the unique_ptr goes out of scope.
16310 void DestroyTransaction(std::unique_ptr<HttpTransaction> transaction) {}
16311
16312 // Confirm that destroying a transaction from a SetPriority call by the
16313 // throttler works properly.
16314 TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetDestroy) {
16315 TestNetworkStreamThrottler* throttler(nullptr);
16316 std::unique_ptr<HttpNetworkSession> session(
16317 CreateSessionWithThrottler(&session_deps_, &throttler));
16318
16319 // Send a simple request and make sure it goes through.
16320 HttpRequestInfo request;
16321 request.method = "GET";
16322 request.url = GURL("http://www.example.org/");
16323
16324 MockWrite data_writes[] = {
16325 MockWrite("GET / HTTP/1.1\r\n"
16326 "Host: www.example.org\r\n"
16327 "Connection: keep-alive\r\n\r\n"),
16328 };
16329 MockRead data_reads[] = {
16330 MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"),
16331 MockRead(SYNCHRONOUS, OK),
16332 };
16333 StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes,
16334 arraysize(data_writes));
16335 session_deps_.socket_factory->AddSocketDataProvider(&reads);
16336
16337 StaticSocketDataProvider reads1(data_reads, arraysize(data_reads),
16338 data_writes, arraysize(data_writes));
16339 session_deps_.socket_factory->AddSocketDataProvider(&reads1);
16340
16341 // Start a request that will be throttled at start; confirm it
16342 // doesn't complete.
16343 throttler->set_throttle_new_requests(true);
16344 std::unique_ptr<HttpTransaction> trans(
16345 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
16346
16347 TestCompletionCallback callback;
16348 int rv = trans->Start(&request, callback.callback(), NetLogWithSource());
16349 EXPECT_EQ(ERR_IO_PENDING, rv);
16350
16351 base::RunLoop().RunUntilIdle();
16352 EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState());
16353 EXPECT_FALSE(callback.have_result());
16354
16355 // Arrange for the set priority call on the above transaction to delete
16356 // the transaction.
16357 HttpTransaction* trans_ptr(trans.get());
16358 throttler->set_priority_change_closure(
16359 base::Bind(&DestroyTransaction, base::Passed(&trans)));
16360
16361 // Call it and check results (partially a "doesn't crash" test).
16362 trans_ptr->SetPriority(IDLE);
16363 trans_ptr = nullptr; // No longer a valid pointer.
16364
16365 base::RunLoop().RunUntilIdle();
16366 ASSERT_FALSE(callback.have_result());
16367 }
16368
16068 #if !defined(OS_IOS) 16369 #if !defined(OS_IOS)
16069 TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { 16370 TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) {
16070 const std::string https_url = "https://www.example.com"; 16371 const std::string https_url = "https://www.example.com";
16071 HttpRequestInfo request; 16372 HttpRequestInfo request;
16072 request.url = GURL(https_url); 16373 request.url = GURL(https_url);
16073 request.method = "GET"; 16374 request.method = "GET";
16074 16375
16075 SSLSocketDataProvider ssl(ASYNC, OK); 16376 SSLSocketDataProvider ssl(ASYNC, OK);
16076 ssl.token_binding_negotiated = true; 16377 ssl.token_binding_negotiated = true;
16077 ssl.token_binding_key_param = TB_PARAM_ECDSAP256; 16378 ssl.token_binding_key_param = TB_PARAM_ECDSAP256;
(...skipping 17 matching lines...) Expand all
16095 base::RunLoop().RunUntilIdle(); 16396 base::RunLoop().RunUntilIdle();
16096 16397
16097 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); 16398 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy);
16098 HttpRequestHeaders headers; 16399 HttpRequestHeaders headers;
16099 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); 16400 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers));
16100 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); 16401 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding));
16101 } 16402 }
16102 #endif // !defined(OS_IOS) 16403 #endif // !defined(OS_IOS)
16103 16404
16104 } // namespace net 16405 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_network_transaction.cc ('k') | net/http/http_stream_factory_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698