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

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

Issue 24246016: Make HttpNetworkTransaction no longer own a reference to HttpNetworkSession. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Response to wtc's comments Created 7 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 | Annotate | Revision Log
« no previous file with comments | « net/http/http_network_transaction.cc ('k') | no next file » | 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 <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 size_t data_count) { 282 size_t data_count) {
283 SimpleGetHelperResult out; 283 SimpleGetHelperResult out;
284 284
285 HttpRequestInfo request; 285 HttpRequestInfo request;
286 request.method = "GET"; 286 request.method = "GET";
287 request.url = GURL("http://www.google.com/"); 287 request.url = GURL("http://www.google.com/");
288 request.load_flags = 0; 288 request.load_flags = 0;
289 289
290 CapturingBoundNetLog log; 290 CapturingBoundNetLog log;
291 session_deps_.net_log = log.bound().net_log(); 291 session_deps_.net_log = log.bound().net_log();
292 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
292 scoped_ptr<HttpTransaction> trans( 293 scoped_ptr<HttpTransaction> trans(
293 new HttpNetworkTransaction(DEFAULT_PRIORITY, 294 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
294 CreateSession(&session_deps_)));
295 295
296 for (size_t i = 0; i < data_count; ++i) { 296 for (size_t i = 0; i < data_count; ++i) {
297 session_deps_.socket_factory->AddSocketDataProvider(data[i]); 297 session_deps_.socket_factory->AddSocketDataProvider(data[i]);
298 } 298 }
299 299
300 TestCompletionCallback callback; 300 TestCompletionCallback callback;
301 301
302 EXPECT_TRUE(log.bound().IsLoggingAllEvents()); 302 EXPECT_TRUE(log.bound().IsLoggingAllEvents());
303 int rv = trans->Start(&request, callback.callback(), log.bound()); 303 int rv = trans->Start(&request, callback.callback(), log.bound());
304 EXPECT_EQ(ERR_IO_PENDING, rv); 304 EXPECT_EQ(ERR_IO_PENDING, rv);
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 EXPECT_FALSE(auth_challenge->is_proxy); 559 EXPECT_FALSE(auth_challenge->is_proxy);
560 EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); 560 EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString());
561 EXPECT_EQ(std::string(), auth_challenge->realm); 561 EXPECT_EQ(std::string(), auth_challenge->realm);
562 EXPECT_EQ("ntlm", auth_challenge->scheme); 562 EXPECT_EQ("ntlm", auth_challenge->scheme);
563 return true; 563 return true;
564 } 564 }
565 565
566 } // namespace 566 } // namespace
567 567
568 TEST_P(HttpNetworkTransactionTest, Basic) { 568 TEST_P(HttpNetworkTransactionTest, Basic) {
569 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
569 scoped_ptr<HttpTransaction> trans( 570 scoped_ptr<HttpTransaction> trans(
570 new HttpNetworkTransaction(DEFAULT_PRIORITY, 571 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
571 CreateSession(&session_deps_)));
572 } 572 }
573 573
574 TEST_P(HttpNetworkTransactionTest, SimpleGET) { 574 TEST_P(HttpNetworkTransactionTest, SimpleGET) {
575 MockRead data_reads[] = { 575 MockRead data_reads[] = {
576 MockRead("HTTP/1.0 200 OK\r\n\r\n"), 576 MockRead("HTTP/1.0 200 OK\r\n\r\n"),
577 MockRead("hello world"), 577 MockRead("hello world"),
578 MockRead(SYNCHRONOUS, OK), 578 MockRead(SYNCHRONOUS, OK),
579 }; 579 };
580 SimpleGetHelperResult out = SimpleGetHelper(data_reads, 580 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
581 arraysize(data_reads)); 581 arraysize(data_reads));
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 MockRead("Location: http://good.com/\r\n"), 854 MockRead("Location: http://good.com/\r\n"),
855 MockRead("Content-Length: 0\r\n\r\n"), 855 MockRead("Content-Length: 0\r\n\r\n"),
856 MockRead(SYNCHRONOUS, OK), 856 MockRead(SYNCHRONOUS, OK),
857 }; 857 };
858 858
859 HttpRequestInfo request; 859 HttpRequestInfo request;
860 request.method = "GET"; 860 request.method = "GET";
861 request.url = GURL("http://redirect.com/"); 861 request.url = GURL("http://redirect.com/");
862 request.load_flags = 0; 862 request.load_flags = 0;
863 863
864 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
864 scoped_ptr<HttpTransaction> trans( 865 scoped_ptr<HttpTransaction> trans(
865 new HttpNetworkTransaction(DEFAULT_PRIORITY, 866 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
866 CreateSession(&session_deps_)));
867 867
868 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 868 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
869 session_deps_.socket_factory->AddSocketDataProvider(&data); 869 session_deps_.socket_factory->AddSocketDataProvider(&data);
870 870
871 TestCompletionCallback callback; 871 TestCompletionCallback callback;
872 872
873 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 873 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
874 EXPECT_EQ(ERR_IO_PENDING, rv); 874 EXPECT_EQ(ERR_IO_PENDING, rv);
875 875
876 EXPECT_EQ(OK, callback.WaitForResult()); 876 EXPECT_EQ(OK, callback.WaitForResult());
(...skipping 21 matching lines...) Expand all
898 } 898 }
899 899
900 // Do a request using the HEAD method. Verify that we don't try to read the 900 // Do a request using the HEAD method. Verify that we don't try to read the
901 // message body (since HEAD has none). 901 // message body (since HEAD has none).
902 TEST_P(HttpNetworkTransactionTest, Head) { 902 TEST_P(HttpNetworkTransactionTest, Head) {
903 HttpRequestInfo request; 903 HttpRequestInfo request;
904 request.method = "HEAD"; 904 request.method = "HEAD";
905 request.url = GURL("http://www.google.com/"); 905 request.url = GURL("http://www.google.com/");
906 request.load_flags = 0; 906 request.load_flags = 0;
907 907
908 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
908 scoped_ptr<HttpTransaction> trans( 909 scoped_ptr<HttpTransaction> trans(
909 new HttpNetworkTransaction(DEFAULT_PRIORITY, 910 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
910 CreateSession(&session_deps_)));
911 911
912 MockWrite data_writes1[] = { 912 MockWrite data_writes1[] = {
913 MockWrite("HEAD / HTTP/1.1\r\n" 913 MockWrite("HEAD / HTTP/1.1\r\n"
914 "Host: www.google.com\r\n" 914 "Host: www.google.com\r\n"
915 "Connection: keep-alive\r\n" 915 "Connection: keep-alive\r\n"
916 "Content-Length: 0\r\n\r\n"), 916 "Content-Length: 0\r\n\r\n"),
917 }; 917 };
918 MockRead data_reads1[] = { 918 MockRead data_reads1[] = {
919 MockRead("HTTP/1.1 404 Not Found\r\n"), 919 MockRead("HTTP/1.1 404 Not Found\r\n"),
920 MockRead("Server: Blah\r\n"), 920 MockRead("Server: Blah\r\n"),
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 ScopedVector<UploadElementReader> element_readers; 1010 ScopedVector<UploadElementReader> element_readers;
1011 element_readers.push_back(new UploadBytesElementReader("foo", 3)); 1011 element_readers.push_back(new UploadBytesElementReader("foo", 3));
1012 UploadDataStream upload_data_stream(element_readers.Pass(), 0); 1012 UploadDataStream upload_data_stream(element_readers.Pass(), 0);
1013 1013
1014 HttpRequestInfo request; 1014 HttpRequestInfo request;
1015 request.method = "POST"; 1015 request.method = "POST";
1016 request.url = GURL("http://www.foo.com/"); 1016 request.url = GURL("http://www.foo.com/");
1017 request.upload_data_stream = &upload_data_stream; 1017 request.upload_data_stream = &upload_data_stream;
1018 request.load_flags = 0; 1018 request.load_flags = 0;
1019 1019
1020 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
1020 scoped_ptr<HttpTransaction> trans( 1021 scoped_ptr<HttpTransaction> trans(
1021 new HttpNetworkTransaction(DEFAULT_PRIORITY, 1022 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
1022 CreateSession(&session_deps_)));
1023 1023
1024 MockRead data_reads[] = { 1024 MockRead data_reads[] = {
1025 MockRead("HTTP/1.0 100 Continue\r\n\r\n"), 1025 MockRead("HTTP/1.0 100 Continue\r\n\r\n"),
1026 MockRead("HTTP/1.0 200 OK\r\n\r\n"), 1026 MockRead("HTTP/1.0 200 OK\r\n\r\n"),
1027 MockRead("hello world"), 1027 MockRead("hello world"),
1028 MockRead(SYNCHRONOUS, OK), 1028 MockRead(SYNCHRONOUS, OK),
1029 }; 1029 };
1030 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 1030 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
1031 session_deps_.socket_factory->AddSocketDataProvider(&data); 1031 session_deps_.socket_factory->AddSocketDataProvider(&data);
1032 1032
(...skipping 19 matching lines...) Expand all
1052 1052
1053 // This test is almost the same as Ignores100 above, but the response contains 1053 // This test is almost the same as Ignores100 above, but the response contains
1054 // a 102 instead of a 100. Also, instead of HTTP/1.0 the response is 1054 // a 102 instead of a 100. Also, instead of HTTP/1.0 the response is
1055 // HTTP/1.1 and the two status headers are read in one read. 1055 // HTTP/1.1 and the two status headers are read in one read.
1056 TEST_P(HttpNetworkTransactionTest, Ignores1xx) { 1056 TEST_P(HttpNetworkTransactionTest, Ignores1xx) {
1057 HttpRequestInfo request; 1057 HttpRequestInfo request;
1058 request.method = "GET"; 1058 request.method = "GET";
1059 request.url = GURL("http://www.foo.com/"); 1059 request.url = GURL("http://www.foo.com/");
1060 request.load_flags = 0; 1060 request.load_flags = 0;
1061 1061
1062 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
1062 scoped_ptr<HttpTransaction> trans( 1063 scoped_ptr<HttpTransaction> trans(
1063 new HttpNetworkTransaction(DEFAULT_PRIORITY, 1064 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
1064 CreateSession(&session_deps_)));
1065 1065
1066 MockRead data_reads[] = { 1066 MockRead data_reads[] = {
1067 MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" 1067 MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n"
1068 "HTTP/1.1 200 OK\r\n\r\n"), 1068 "HTTP/1.1 200 OK\r\n\r\n"),
1069 MockRead("hello world"), 1069 MockRead("hello world"),
1070 MockRead(SYNCHRONOUS, OK), 1070 MockRead(SYNCHRONOUS, OK),
1071 }; 1071 };
1072 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 1072 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
1073 session_deps_.socket_factory->AddSocketDataProvider(&data); 1073 session_deps_.socket_factory->AddSocketDataProvider(&data);
1074 1074
(...skipping 16 matching lines...) Expand all
1091 EXPECT_EQ(OK, rv); 1091 EXPECT_EQ(OK, rv);
1092 EXPECT_EQ("hello world", response_data); 1092 EXPECT_EQ("hello world", response_data);
1093 } 1093 }
1094 1094
1095 TEST_P(HttpNetworkTransactionTest, Incomplete100ThenEOF) { 1095 TEST_P(HttpNetworkTransactionTest, Incomplete100ThenEOF) {
1096 HttpRequestInfo request; 1096 HttpRequestInfo request;
1097 request.method = "POST"; 1097 request.method = "POST";
1098 request.url = GURL("http://www.foo.com/"); 1098 request.url = GURL("http://www.foo.com/");
1099 request.load_flags = 0; 1099 request.load_flags = 0;
1100 1100
1101 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
1101 scoped_ptr<HttpTransaction> trans( 1102 scoped_ptr<HttpTransaction> trans(
1102 new HttpNetworkTransaction(DEFAULT_PRIORITY, 1103 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
1103 CreateSession(&session_deps_)));
1104 1104
1105 MockRead data_reads[] = { 1105 MockRead data_reads[] = {
1106 MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), 1106 MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"),
1107 MockRead(ASYNC, 0), 1107 MockRead(ASYNC, 0),
1108 }; 1108 };
1109 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 1109 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
1110 session_deps_.socket_factory->AddSocketDataProvider(&data); 1110 session_deps_.socket_factory->AddSocketDataProvider(&data);
1111 1111
1112 TestCompletionCallback callback; 1112 TestCompletionCallback callback;
1113 1113
1114 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 1114 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
1115 EXPECT_EQ(ERR_IO_PENDING, rv); 1115 EXPECT_EQ(ERR_IO_PENDING, rv);
1116 1116
1117 rv = callback.WaitForResult(); 1117 rv = callback.WaitForResult();
1118 EXPECT_EQ(OK, rv); 1118 EXPECT_EQ(OK, rv);
1119 1119
1120 std::string response_data; 1120 std::string response_data;
1121 rv = ReadTransaction(trans.get(), &response_data); 1121 rv = ReadTransaction(trans.get(), &response_data);
1122 EXPECT_EQ(OK, rv); 1122 EXPECT_EQ(OK, rv);
1123 EXPECT_EQ("", response_data); 1123 EXPECT_EQ("", response_data);
1124 } 1124 }
1125 1125
1126 TEST_P(HttpNetworkTransactionTest, EmptyResponse) { 1126 TEST_P(HttpNetworkTransactionTest, EmptyResponse) {
1127 HttpRequestInfo request; 1127 HttpRequestInfo request;
1128 request.method = "POST"; 1128 request.method = "POST";
1129 request.url = GURL("http://www.foo.com/"); 1129 request.url = GURL("http://www.foo.com/");
1130 request.load_flags = 0; 1130 request.load_flags = 0;
1131 1131
1132 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
1132 scoped_ptr<HttpTransaction> trans( 1133 scoped_ptr<HttpTransaction> trans(
1133 new HttpNetworkTransaction(DEFAULT_PRIORITY, 1134 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
1134 CreateSession(&session_deps_))); 1135
1135 1136
1136 MockRead data_reads[] = { 1137 MockRead data_reads[] = {
1137 MockRead(ASYNC, 0), 1138 MockRead(ASYNC, 0),
1138 }; 1139 };
1139 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 1140 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
1140 session_deps_.socket_factory->AddSocketDataProvider(&data); 1141 session_deps_.socket_factory->AddSocketDataProvider(&data);
1141 1142
1142 TestCompletionCallback callback; 1143 TestCompletionCallback callback;
1143 1144
1144 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 1145 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1252 MockRead read_failure(SYNCHRONOUS, OK); // EOF 1253 MockRead read_failure(SYNCHRONOUS, OK); // EOF
1253 KeepAliveConnectionResendRequestTest(NULL, &read_failure); 1254 KeepAliveConnectionResendRequestTest(NULL, &read_failure);
1254 } 1255 }
1255 1256
1256 TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { 1257 TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) {
1257 HttpRequestInfo request; 1258 HttpRequestInfo request;
1258 request.method = "GET"; 1259 request.method = "GET";
1259 request.url = GURL("http://www.google.com/"); 1260 request.url = GURL("http://www.google.com/");
1260 request.load_flags = 0; 1261 request.load_flags = 0;
1261 1262
1263 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
1262 scoped_ptr<HttpTransaction> trans( 1264 scoped_ptr<HttpTransaction> trans(
1263 new HttpNetworkTransaction(DEFAULT_PRIORITY, 1265 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
1264 CreateSession(&session_deps_)));
1265 1266
1266 MockRead data_reads[] = { 1267 MockRead data_reads[] = {
1267 MockRead(ASYNC, ERR_CONNECTION_RESET), 1268 MockRead(ASYNC, ERR_CONNECTION_RESET),
1268 MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used 1269 MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used
1269 MockRead("hello world"), 1270 MockRead("hello world"),
1270 MockRead(SYNCHRONOUS, OK), 1271 MockRead(SYNCHRONOUS, OK),
1271 }; 1272 };
1272 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 1273 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
1273 session_deps_.socket_factory->AddSocketDataProvider(&data); 1274 session_deps_.socket_factory->AddSocketDataProvider(&data);
1274 1275
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1500 // Test the request-challenge-retry sequence for basic auth. 1501 // Test the request-challenge-retry sequence for basic auth.
1501 // (basic auth is the easiest to mock, because it has no randomness). 1502 // (basic auth is the easiest to mock, because it has no randomness).
1502 TEST_P(HttpNetworkTransactionTest, BasicAuth) { 1503 TEST_P(HttpNetworkTransactionTest, BasicAuth) {
1503 HttpRequestInfo request; 1504 HttpRequestInfo request;
1504 request.method = "GET"; 1505 request.method = "GET";
1505 request.url = GURL("http://www.google.com/"); 1506 request.url = GURL("http://www.google.com/");
1506 request.load_flags = 0; 1507 request.load_flags = 0;
1507 1508
1508 CapturingNetLog log; 1509 CapturingNetLog log;
1509 session_deps_.net_log = &log; 1510 session_deps_.net_log = &log;
1511 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
1510 scoped_ptr<HttpTransaction> trans( 1512 scoped_ptr<HttpTransaction> trans(
1511 new HttpNetworkTransaction(DEFAULT_PRIORITY, 1513 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
1512 CreateSession(&session_deps_)));
1513 1514
1514 MockWrite data_writes1[] = { 1515 MockWrite data_writes1[] = {
1515 MockWrite("GET / HTTP/1.1\r\n" 1516 MockWrite("GET / HTTP/1.1\r\n"
1516 "Host: www.google.com\r\n" 1517 "Host: www.google.com\r\n"
1517 "Connection: keep-alive\r\n\r\n"), 1518 "Connection: keep-alive\r\n\r\n"),
1518 }; 1519 };
1519 1520
1520 MockRead data_reads1[] = { 1521 MockRead data_reads1[] = {
1521 MockRead("HTTP/1.0 401 Unauthorized\r\n"), 1522 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
1522 // Give a couple authenticate options (only the middle one is actually 1523 // Give a couple authenticate options (only the middle one is actually
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1593 EXPECT_TRUE(response->auth_challenge.get() == NULL); 1594 EXPECT_TRUE(response->auth_challenge.get() == NULL);
1594 EXPECT_EQ(100, response->headers->GetContentLength()); 1595 EXPECT_EQ(100, response->headers->GetContentLength());
1595 } 1596 }
1596 1597
1597 TEST_P(HttpNetworkTransactionTest, DoNotSendAuth) { 1598 TEST_P(HttpNetworkTransactionTest, DoNotSendAuth) {
1598 HttpRequestInfo request; 1599 HttpRequestInfo request;
1599 request.method = "GET"; 1600 request.method = "GET";
1600 request.url = GURL("http://www.google.com/"); 1601 request.url = GURL("http://www.google.com/");
1601 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; 1602 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA;
1602 1603
1604 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
1603 scoped_ptr<HttpTransaction> trans( 1605 scoped_ptr<HttpTransaction> trans(
1604 new HttpNetworkTransaction(DEFAULT_PRIORITY, 1606 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
1605 CreateSession(&session_deps_)));
1606 1607
1607 MockWrite data_writes[] = { 1608 MockWrite data_writes[] = {
1608 MockWrite("GET / HTTP/1.1\r\n" 1609 MockWrite("GET / HTTP/1.1\r\n"
1609 "Host: www.google.com\r\n" 1610 "Host: www.google.com\r\n"
1610 "Connection: keep-alive\r\n\r\n"), 1611 "Connection: keep-alive\r\n\r\n"),
1611 }; 1612 };
1612 1613
1613 MockRead data_reads[] = { 1614 MockRead data_reads[] = {
1614 MockRead("HTTP/1.0 401 Unauthorized\r\n"), 1615 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
1615 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), 1616 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
2256 2257
2257 // Test when a server (non-proxy) returns a 407 (proxy-authenticate). 2258 // Test when a server (non-proxy) returns a 407 (proxy-authenticate).
2258 // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. 2259 // The request should fail with ERR_UNEXPECTED_PROXY_AUTH.
2259 TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) { 2260 TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) {
2260 HttpRequestInfo request; 2261 HttpRequestInfo request;
2261 request.method = "GET"; 2262 request.method = "GET";
2262 request.url = GURL("http://www.google.com/"); 2263 request.url = GURL("http://www.google.com/");
2263 request.load_flags = 0; 2264 request.load_flags = 0;
2264 2265
2265 // We are using a DIRECT connection (i.e. no proxy) for this session. 2266 // We are using a DIRECT connection (i.e. no proxy) for this session.
2267 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
2266 scoped_ptr<HttpTransaction> trans( 2268 scoped_ptr<HttpTransaction> trans(
2267 new HttpNetworkTransaction(DEFAULT_PRIORITY, 2269 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
2268 CreateSession(&session_deps_)));
2269 2270
2270 MockWrite data_writes1[] = { 2271 MockWrite data_writes1[] = {
2271 MockWrite("GET / HTTP/1.1\r\n" 2272 MockWrite("GET / HTTP/1.1\r\n"
2272 "Host: www.google.com\r\n" 2273 "Host: www.google.com\r\n"
2273 "Connection: keep-alive\r\n\r\n"), 2274 "Connection: keep-alive\r\n\r\n"),
2274 }; 2275 };
2275 2276
2276 MockRead data_reads1[] = { 2277 MockRead data_reads1[] = {
2277 MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), 2278 MockRead("HTTP/1.0 407 Proxy Auth required\r\n"),
2278 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), 2279 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
(...skipping 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after
3522 3523
3523 void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( 3524 void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus(
3524 const MockRead& status, int expected_status) { 3525 const MockRead& status, int expected_status) {
3525 HttpRequestInfo request; 3526 HttpRequestInfo request;
3526 request.method = "GET"; 3527 request.method = "GET";
3527 request.url = GURL("https://www.google.com/"); 3528 request.url = GURL("https://www.google.com/");
3528 request.load_flags = 0; 3529 request.load_flags = 0;
3529 3530
3530 // Configure against proxy server "myproxy:70". 3531 // Configure against proxy server "myproxy:70".
3531 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); 3532 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70"));
3532
3533 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 3533 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
3534 3534
3535 // Since we have proxy, should try to establish tunnel. 3535 // Since we have proxy, should try to establish tunnel.
3536 MockWrite data_writes[] = { 3536 MockWrite data_writes[] = {
3537 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" 3537 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
3538 "Host: www.google.com\r\n" 3538 "Host: www.google.com\r\n"
3539 "Proxy-Connection: keep-alive\r\n\r\n"), 3539 "Proxy-Connection: keep-alive\r\n\r\n"),
3540 }; 3540 };
3541 3541
3542 MockRead data_reads[] = { 3542 MockRead data_reads[] = {
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
3734 3734
3735 // Test the flow when both the proxy server AND origin server require 3735 // Test the flow when both the proxy server AND origin server require
3736 // authentication. Again, this uses basic auth for both since that is 3736 // authentication. Again, this uses basic auth for both since that is
3737 // the simplest to mock. 3737 // the simplest to mock.
3738 TEST_P(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { 3738 TEST_P(HttpNetworkTransactionTest, BasicAuthProxyThenServer) {
3739 HttpRequestInfo request; 3739 HttpRequestInfo request;
3740 request.method = "GET"; 3740 request.method = "GET";
3741 request.url = GURL("http://www.google.com/"); 3741 request.url = GURL("http://www.google.com/");
3742 request.load_flags = 0; 3742 request.load_flags = 0;
3743 3743
3744 // Configure against proxy server "myproxy:70".
3744 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); 3745 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70"));
3746 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
3745 3747
3746 // Configure against proxy server "myproxy:70". 3748 scoped_ptr<HttpTransaction> trans(
3747 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(DEFAULT_PRIORITY, 3749 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
3748 CreateSession(&session_deps_)));
3749 3750
3750 MockWrite data_writes1[] = { 3751 MockWrite data_writes1[] = {
3751 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" 3752 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
3752 "Host: www.google.com\r\n" 3753 "Host: www.google.com\r\n"
3753 "Proxy-Connection: keep-alive\r\n\r\n"), 3754 "Proxy-Connection: keep-alive\r\n\r\n"),
3754 }; 3755 };
3755 3756
3756 MockRead data_reads1[] = { 3757 MockRead data_reads1[] = {
3757 MockRead("HTTP/1.0 407 Unauthorized\r\n"), 3758 MockRead("HTTP/1.0 407 Unauthorized\r\n"),
3758 // Give a couple authenticate options (only the middle one is actually 3759 // Give a couple authenticate options (only the middle one is actually
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
4194 4195
4195 // Test reading a server response which has only headers, and no body. 4196 // Test reading a server response which has only headers, and no body.
4196 // After some maximum number of bytes is consumed, the transaction should 4197 // After some maximum number of bytes is consumed, the transaction should
4197 // fail with ERR_RESPONSE_HEADERS_TOO_BIG. 4198 // fail with ERR_RESPONSE_HEADERS_TOO_BIG.
4198 TEST_P(HttpNetworkTransactionTest, LargeHeadersNoBody) { 4199 TEST_P(HttpNetworkTransactionTest, LargeHeadersNoBody) {
4199 HttpRequestInfo request; 4200 HttpRequestInfo request;
4200 request.method = "GET"; 4201 request.method = "GET";
4201 request.url = GURL("http://www.google.com/"); 4202 request.url = GURL("http://www.google.com/");
4202 request.load_flags = 0; 4203 request.load_flags = 0;
4203 4204
4205 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
4204 scoped_ptr<HttpTransaction> trans( 4206 scoped_ptr<HttpTransaction> trans(
4205 new HttpNetworkTransaction(DEFAULT_PRIORITY, 4207 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
4206 CreateSession(&session_deps_)));
4207 4208
4208 // Respond with 300 kb of headers (we should fail after 256 kb). 4209 // Respond with 300 kb of headers (we should fail after 256 kb).
4209 std::string large_headers_string; 4210 std::string large_headers_string;
4210 FillLargeHeadersString(&large_headers_string, 300 * 1024); 4211 FillLargeHeadersString(&large_headers_string, 300 * 1024);
4211 4212
4212 MockRead data_reads[] = { 4213 MockRead data_reads[] = {
4213 MockRead("HTTP/1.0 200 OK\r\n"), 4214 MockRead("HTTP/1.0 200 OK\r\n"),
4214 MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), 4215 MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()),
4215 MockRead("\r\nBODY"), 4216 MockRead("\r\nBODY"),
4216 MockRead(SYNCHRONOUS, OK), 4217 MockRead(SYNCHRONOUS, OK),
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
4649 4650
4650 // Test the request-challenge-retry sequence for basic auth when there is 4651 // Test the request-challenge-retry sequence for basic auth when there is
4651 // an identity in the URL. The request should be sent as normal, but when 4652 // an identity in the URL. The request should be sent as normal, but when
4652 // it fails the identity from the URL is used to answer the challenge. 4653 // it fails the identity from the URL is used to answer the challenge.
4653 TEST_P(HttpNetworkTransactionTest, AuthIdentityInURL) { 4654 TEST_P(HttpNetworkTransactionTest, AuthIdentityInURL) {
4654 HttpRequestInfo request; 4655 HttpRequestInfo request;
4655 request.method = "GET"; 4656 request.method = "GET";
4656 request.url = GURL("http://foo:b@r@www.google.com/"); 4657 request.url = GURL("http://foo:b@r@www.google.com/");
4657 request.load_flags = LOAD_NORMAL; 4658 request.load_flags = LOAD_NORMAL;
4658 4659
4660 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
4659 scoped_ptr<HttpTransaction> trans( 4661 scoped_ptr<HttpTransaction> trans(
4660 new HttpNetworkTransaction(DEFAULT_PRIORITY, 4662 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
4661 CreateSession(&session_deps_)));
4662 4663
4663 // The password contains an escaped character -- for this test to pass it 4664 // The password contains an escaped character -- for this test to pass it
4664 // will need to be unescaped by HttpNetworkTransaction. 4665 // will need to be unescaped by HttpNetworkTransaction.
4665 EXPECT_EQ("b%40r", request.url.password()); 4666 EXPECT_EQ("b%40r", request.url.password());
4666 4667
4667 MockWrite data_writes1[] = { 4668 MockWrite data_writes1[] = {
4668 MockWrite("GET / HTTP/1.1\r\n" 4669 MockWrite("GET / HTTP/1.1\r\n"
4669 "Host: www.google.com\r\n" 4670 "Host: www.google.com\r\n"
4670 "Connection: keep-alive\r\n\r\n"), 4671 "Connection: keep-alive\r\n\r\n"),
4671 }; 4672 };
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
4730 // once. 4731 // once.
4731 TEST_P(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { 4732 TEST_P(HttpNetworkTransactionTest, WrongAuthIdentityInURL) {
4732 HttpRequestInfo request; 4733 HttpRequestInfo request;
4733 request.method = "GET"; 4734 request.method = "GET";
4734 // Note: the URL has a username:password in it. The password "baz" is 4735 // Note: the URL has a username:password in it. The password "baz" is
4735 // wrong (should be "bar"). 4736 // wrong (should be "bar").
4736 request.url = GURL("http://foo:baz@www.google.com/"); 4737 request.url = GURL("http://foo:baz@www.google.com/");
4737 4738
4738 request.load_flags = LOAD_NORMAL; 4739 request.load_flags = LOAD_NORMAL;
4739 4740
4741 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
4740 scoped_ptr<HttpTransaction> trans( 4742 scoped_ptr<HttpTransaction> trans(
4741 new HttpNetworkTransaction(DEFAULT_PRIORITY, 4743 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
4742 CreateSession(&session_deps_)));
4743 4744
4744 MockWrite data_writes1[] = { 4745 MockWrite data_writes1[] = {
4745 MockWrite("GET / HTTP/1.1\r\n" 4746 MockWrite("GET / HTTP/1.1\r\n"
4746 "Host: www.google.com\r\n" 4747 "Host: www.google.com\r\n"
4747 "Connection: keep-alive\r\n\r\n"), 4748 "Connection: keep-alive\r\n\r\n"),
4748 }; 4749 };
4749 4750
4750 MockRead data_reads1[] = { 4751 MockRead data_reads1[] = {
4751 MockRead("HTTP/1.0 401 Unauthorized\r\n"), 4752 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
4752 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), 4753 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
5349 5350
5350 const HttpResponseInfo* response = trans->GetResponseInfo(); 5351 const HttpResponseInfo* response = trans->GetResponseInfo();
5351 ASSERT_TRUE(response != NULL); 5352 ASSERT_TRUE(response != NULL);
5352 EXPECT_TRUE(response->auth_challenge.get() == NULL); 5353 EXPECT_TRUE(response->auth_challenge.get() == NULL);
5353 } 5354 }
5354 } 5355 }
5355 5356
5356 // Test the ResetStateForRestart() private method. 5357 // Test the ResetStateForRestart() private method.
5357 TEST_P(HttpNetworkTransactionTest, ResetStateForRestart) { 5358 TEST_P(HttpNetworkTransactionTest, ResetStateForRestart) {
5358 // Create a transaction (the dependencies aren't important). 5359 // Create a transaction (the dependencies aren't important).
5360 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
5359 scoped_ptr<HttpNetworkTransaction> trans( 5361 scoped_ptr<HttpNetworkTransaction> trans(
5360 new HttpNetworkTransaction(DEFAULT_PRIORITY, 5362 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
5361 CreateSession(&session_deps_)));
5362 5363
5363 // Setup some state (which we expect ResetStateForRestart() will clear). 5364 // Setup some state (which we expect ResetStateForRestart() will clear).
5364 trans->read_buf_ = new IOBuffer(15); 5365 trans->read_buf_ = new IOBuffer(15);
5365 trans->read_buf_len_ = 15; 5366 trans->read_buf_len_ = 15;
5366 trans->request_headers_.SetHeader("Authorization", "NTLM"); 5367 trans->request_headers_.SetHeader("Authorization", "NTLM");
5367 5368
5368 // Setup state in response_ 5369 // Setup state in response_
5369 HttpResponseInfo* response = &trans->response_; 5370 HttpResponseInfo* response = &trans->response_;
5370 response->auth_challenge = new AuthChallengeInfo(); 5371 response->auth_challenge = new AuthChallengeInfo();
5371 response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. 5372 response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical.
(...skipping 24 matching lines...) Expand all
5396 EXPECT_FALSE(response->vary_data.is_valid()); 5397 EXPECT_FALSE(response->vary_data.is_valid());
5397 } 5398 }
5398 5399
5399 // Test HTTPS connections to a site with a bad certificate 5400 // Test HTTPS connections to a site with a bad certificate
5400 TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificate) { 5401 TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificate) {
5401 HttpRequestInfo request; 5402 HttpRequestInfo request;
5402 request.method = "GET"; 5403 request.method = "GET";
5403 request.url = GURL("https://www.google.com/"); 5404 request.url = GURL("https://www.google.com/");
5404 request.load_flags = 0; 5405 request.load_flags = 0;
5405 5406
5407 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
5406 scoped_ptr<HttpTransaction> trans( 5408 scoped_ptr<HttpTransaction> trans(
5407 new HttpNetworkTransaction(DEFAULT_PRIORITY, 5409 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
5408 CreateSession(&session_deps_)));
5409 5410
5410 MockWrite data_writes[] = { 5411 MockWrite data_writes[] = {
5411 MockWrite("GET / HTTP/1.1\r\n" 5412 MockWrite("GET / HTTP/1.1\r\n"
5412 "Host: www.google.com\r\n" 5413 "Host: www.google.com\r\n"
5413 "Connection: keep-alive\r\n\r\n"), 5414 "Connection: keep-alive\r\n\r\n"),
5414 }; 5415 };
5415 5416
5416 MockRead data_reads[] = { 5417 MockRead data_reads[] = {
5417 MockRead("HTTP/1.0 200 OK\r\n"), 5418 MockRead("HTTP/1.0 200 OK\r\n"),
5418 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), 5419 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
5500 session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); 5501 session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate);
5501 session_deps_.socket_factory->AddSocketDataProvider(&data); 5502 session_deps_.socket_factory->AddSocketDataProvider(&data);
5502 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); 5503 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad);
5503 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 5504 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
5504 5505
5505 TestCompletionCallback callback; 5506 TestCompletionCallback callback;
5506 5507
5507 for (int i = 0; i < 2; i++) { 5508 for (int i = 0; i < 2; i++) {
5508 session_deps_.socket_factory->ResetNextMockIndexes(); 5509 session_deps_.socket_factory->ResetNextMockIndexes();
5509 5510
5511 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
5510 scoped_ptr<HttpTransaction> trans( 5512 scoped_ptr<HttpTransaction> trans(
5511 new HttpNetworkTransaction(DEFAULT_PRIORITY, 5513 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
5512 CreateSession(&session_deps_)));
5513 5514
5514 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 5515 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
5515 EXPECT_EQ(ERR_IO_PENDING, rv); 5516 EXPECT_EQ(ERR_IO_PENDING, rv);
5516 5517
5517 rv = callback.WaitForResult(); 5518 rv = callback.WaitForResult();
5518 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); 5519 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv);
5519 5520
5520 rv = trans->RestartIgnoringLastError(callback.callback()); 5521 rv = trans->RestartIgnoringLastError(callback.callback());
5521 EXPECT_EQ(ERR_IO_PENDING, rv); 5522 EXPECT_EQ(ERR_IO_PENDING, rv);
5522 5523
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
5564 data_writes, arraysize(data_writes)); 5565 data_writes, arraysize(data_writes));
5565 SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy 5566 SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy
5566 SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel 5567 SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel
5567 5568
5568 session_deps_.socket_factory->AddSocketDataProvider(&data); 5569 session_deps_.socket_factory->AddSocketDataProvider(&data);
5569 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); 5570 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl);
5570 session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); 5571 session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl);
5571 5572
5572 TestCompletionCallback callback; 5573 TestCompletionCallback callback;
5573 5574
5575 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
5574 scoped_ptr<HttpTransaction> trans( 5576 scoped_ptr<HttpTransaction> trans(
5575 new HttpNetworkTransaction(DEFAULT_PRIORITY, 5577 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
5576 CreateSession(&session_deps_)));
5577 5578
5578 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 5579 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
5579 EXPECT_EQ(ERR_IO_PENDING, rv); 5580 EXPECT_EQ(ERR_IO_PENDING, rv);
5580 5581
5581 rv = callback.WaitForResult(); 5582 rv = callback.WaitForResult();
5582 EXPECT_EQ(OK, rv); 5583 EXPECT_EQ(OK, rv);
5583 const HttpResponseInfo* response = trans->GetResponseInfo(); 5584 const HttpResponseInfo* response = trans->GetResponseInfo();
5584 5585
5585 ASSERT_TRUE(response != NULL); 5586 ASSERT_TRUE(response != NULL);
5586 5587
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
5622 5623
5623 StaticSocketDataProvider data(data_reads, arraysize(data_reads), 5624 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
5624 data_writes, arraysize(data_writes)); 5625 data_writes, arraysize(data_writes));
5625 SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy 5626 SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy
5626 5627
5627 session_deps_.socket_factory->AddSocketDataProvider(&data); 5628 session_deps_.socket_factory->AddSocketDataProvider(&data);
5628 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); 5629 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl);
5629 5630
5630 TestCompletionCallback callback; 5631 TestCompletionCallback callback;
5631 5632
5633 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
5632 scoped_ptr<HttpTransaction> trans( 5634 scoped_ptr<HttpTransaction> trans(
5633 new HttpNetworkTransaction(DEFAULT_PRIORITY, 5635 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
5634 CreateSession(&session_deps_)));
5635 5636
5636 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 5637 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
5637 EXPECT_EQ(ERR_IO_PENDING, rv); 5638 EXPECT_EQ(ERR_IO_PENDING, rv);
5638 5639
5639 rv = callback.WaitForResult(); 5640 rv = callback.WaitForResult();
5640 EXPECT_EQ(OK, rv); 5641 EXPECT_EQ(OK, rv);
5641 const HttpResponseInfo* response = trans->GetResponseInfo(); 5642 const HttpResponseInfo* response = trans->GetResponseInfo();
5642 5643
5643 ASSERT_TRUE(response != NULL); 5644 ASSERT_TRUE(response != NULL);
5644 5645
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
5707 data_reads, arraysize(data_reads), 5708 data_reads, arraysize(data_reads),
5708 data_writes, arraysize(data_writes)); 5709 data_writes, arraysize(data_writes));
5709 SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy 5710 SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy
5710 proxy_ssl.SetNextProto(GetParam()); 5711 proxy_ssl.SetNextProto(GetParam());
5711 5712
5712 session_deps_.socket_factory->AddSocketDataProvider(&data); 5713 session_deps_.socket_factory->AddSocketDataProvider(&data);
5713 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); 5714 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl);
5714 5715
5715 TestCompletionCallback callback; 5716 TestCompletionCallback callback;
5716 5717
5718 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
5717 scoped_ptr<HttpTransaction> trans( 5719 scoped_ptr<HttpTransaction> trans(
5718 new HttpNetworkTransaction(DEFAULT_PRIORITY, 5720 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
5719 CreateSession(&session_deps_)));
5720 5721
5721 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 5722 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
5722 EXPECT_EQ(ERR_IO_PENDING, rv); 5723 EXPECT_EQ(ERR_IO_PENDING, rv);
5723 5724
5724 rv = callback.WaitForResult(); 5725 rv = callback.WaitForResult();
5725 EXPECT_EQ(OK, rv); 5726 EXPECT_EQ(OK, rv);
5726 const HttpResponseInfo* response = trans->GetResponseInfo(); 5727 const HttpResponseInfo* response = trans->GetResponseInfo();
5727 5728
5728 ASSERT_TRUE(response != NULL); 5729 ASSERT_TRUE(response != NULL);
5729 5730
(...skipping 29 matching lines...) Expand all
5759 5760
5760 StaticSocketDataProvider data(data_reads, arraysize(data_reads), 5761 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
5761 data_writes, arraysize(data_writes)); 5762 data_writes, arraysize(data_writes));
5762 SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy 5763 SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy
5763 5764
5764 session_deps_.socket_factory->AddSocketDataProvider(&data); 5765 session_deps_.socket_factory->AddSocketDataProvider(&data);
5765 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); 5766 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl);
5766 5767
5767 TestCompletionCallback callback; 5768 TestCompletionCallback callback;
5768 5769
5770 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
5769 scoped_ptr<HttpTransaction> trans( 5771 scoped_ptr<HttpTransaction> trans(
5770 new HttpNetworkTransaction(DEFAULT_PRIORITY, 5772 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
5771 CreateSession(&session_deps_)));
5772 5773
5773 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 5774 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
5774 EXPECT_EQ(ERR_IO_PENDING, rv); 5775 EXPECT_EQ(ERR_IO_PENDING, rv);
5775 5776
5776 rv = callback.WaitForResult(); 5777 rv = callback.WaitForResult();
5777 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); 5778 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv);
5778 5779
5779 // TODO(ttuttle): Anything else to check here? 5780 // TODO(ttuttle): Anything else to check here?
5780 } 5781 }
5781 5782
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
5820 data_reads, arraysize(data_reads), 5821 data_reads, arraysize(data_reads),
5821 data_writes, arraysize(data_writes)); 5822 data_writes, arraysize(data_writes));
5822 SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy 5823 SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy
5823 proxy_ssl.SetNextProto(GetParam()); 5824 proxy_ssl.SetNextProto(GetParam());
5824 5825
5825 session_deps_.socket_factory->AddSocketDataProvider(&data); 5826 session_deps_.socket_factory->AddSocketDataProvider(&data);
5826 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); 5827 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl);
5827 5828
5828 TestCompletionCallback callback; 5829 TestCompletionCallback callback;
5829 5830
5831 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
5830 scoped_ptr<HttpTransaction> trans( 5832 scoped_ptr<HttpTransaction> trans(
5831 new HttpNetworkTransaction(DEFAULT_PRIORITY, 5833 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
5832 CreateSession(&session_deps_)));
5833 5834
5834 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 5835 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
5835 EXPECT_EQ(ERR_IO_PENDING, rv); 5836 EXPECT_EQ(ERR_IO_PENDING, rv);
5836 5837
5837 rv = callback.WaitForResult(); 5838 rv = callback.WaitForResult();
5838 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); 5839 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv);
5839 5840
5840 // TODO(ttuttle): Anything else to check here? 5841 // TODO(ttuttle): Anything else to check here?
5841 } 5842 }
5842 5843
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
6245 session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); 6246 session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate);
6246 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); 6247 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad);
6247 6248
6248 // SSL to the proxy, then CONNECT request, then valid SSL certificate 6249 // SSL to the proxy, then CONNECT request, then valid SSL certificate
6249 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 6250 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
6250 session_deps_.socket_factory->AddSocketDataProvider(&data); 6251 session_deps_.socket_factory->AddSocketDataProvider(&data);
6251 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 6252 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
6252 6253
6253 TestCompletionCallback callback; 6254 TestCompletionCallback callback;
6254 6255
6256 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
6255 scoped_ptr<HttpTransaction> trans( 6257 scoped_ptr<HttpTransaction> trans(
6256 new HttpNetworkTransaction(DEFAULT_PRIORITY, 6258 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
6257 CreateSession(&session_deps_)));
6258 6259
6259 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 6260 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
6260 EXPECT_EQ(ERR_IO_PENDING, rv); 6261 EXPECT_EQ(ERR_IO_PENDING, rv);
6261 6262
6262 rv = callback.WaitForResult(); 6263 rv = callback.WaitForResult();
6263 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); 6264 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv);
6264 6265
6265 rv = trans->RestartIgnoringLastError(callback.callback()); 6266 rv = trans->RestartIgnoringLastError(callback.callback());
6266 EXPECT_EQ(ERR_IO_PENDING, rv); 6267 EXPECT_EQ(ERR_IO_PENDING, rv);
6267 6268
6268 rv = callback.WaitForResult(); 6269 rv = callback.WaitForResult();
6269 EXPECT_EQ(OK, rv); 6270 EXPECT_EQ(OK, rv);
6270 6271
6271 const HttpResponseInfo* response = trans->GetResponseInfo(); 6272 const HttpResponseInfo* response = trans->GetResponseInfo();
6272 6273
6273 ASSERT_TRUE(response != NULL); 6274 ASSERT_TRUE(response != NULL);
6274 EXPECT_EQ(100, response->headers->GetContentLength()); 6275 EXPECT_EQ(100, response->headers->GetContentLength());
6275 } 6276 }
6276 6277
6277 TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgent) { 6278 TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgent) {
6278 HttpRequestInfo request; 6279 HttpRequestInfo request;
6279 request.method = "GET"; 6280 request.method = "GET";
6280 request.url = GURL("http://www.google.com/"); 6281 request.url = GURL("http://www.google.com/");
6281 request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, 6282 request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent,
6282 "Chromium Ultra Awesome X Edition"); 6283 "Chromium Ultra Awesome X Edition");
6283 6284
6285 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
6284 scoped_ptr<HttpTransaction> trans( 6286 scoped_ptr<HttpTransaction> trans(
6285 new HttpNetworkTransaction(DEFAULT_PRIORITY, 6287 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
6286 CreateSession(&session_deps_)));
6287 6288
6288 MockWrite data_writes[] = { 6289 MockWrite data_writes[] = {
6289 MockWrite("GET / HTTP/1.1\r\n" 6290 MockWrite("GET / HTTP/1.1\r\n"
6290 "Host: www.google.com\r\n" 6291 "Host: www.google.com\r\n"
6291 "Connection: keep-alive\r\n" 6292 "Connection: keep-alive\r\n"
6292 "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), 6293 "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"),
6293 }; 6294 };
6294 6295
6295 // Lastly, the server responds with the actual content. 6296 // Lastly, the server responds with the actual content.
6296 MockRead data_reads[] = { 6297 MockRead data_reads[] = {
(...skipping 17 matching lines...) Expand all
6314 } 6315 }
6315 6316
6316 TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { 6317 TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) {
6317 HttpRequestInfo request; 6318 HttpRequestInfo request;
6318 request.method = "GET"; 6319 request.method = "GET";
6319 request.url = GURL("https://www.google.com/"); 6320 request.url = GURL("https://www.google.com/");
6320 request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, 6321 request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent,
6321 "Chromium Ultra Awesome X Edition"); 6322 "Chromium Ultra Awesome X Edition");
6322 6323
6323 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); 6324 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70"));
6325 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
6324 scoped_ptr<HttpTransaction> trans( 6326 scoped_ptr<HttpTransaction> trans(
6325 new HttpNetworkTransaction(DEFAULT_PRIORITY, 6327 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
6326 CreateSession(&session_deps_)));
6327 6328
6328 MockWrite data_writes[] = { 6329 MockWrite data_writes[] = {
6329 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" 6330 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
6330 "Host: www.google.com\r\n" 6331 "Host: www.google.com\r\n"
6331 "Proxy-Connection: keep-alive\r\n" 6332 "Proxy-Connection: keep-alive\r\n"
6332 "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), 6333 "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"),
6333 }; 6334 };
6334 MockRead data_reads[] = { 6335 MockRead data_reads[] = {
6335 // Return an error, so the transaction stops here (this test isn't 6336 // Return an error, so the transaction stops here (this test isn't
6336 // interested in the rest). 6337 // interested in the rest).
(...skipping 16 matching lines...) Expand all
6353 } 6354 }
6354 6355
6355 TEST_P(HttpNetworkTransactionTest, BuildRequest_Referer) { 6356 TEST_P(HttpNetworkTransactionTest, BuildRequest_Referer) {
6356 HttpRequestInfo request; 6357 HttpRequestInfo request;
6357 request.method = "GET"; 6358 request.method = "GET";
6358 request.url = GURL("http://www.google.com/"); 6359 request.url = GURL("http://www.google.com/");
6359 request.load_flags = 0; 6360 request.load_flags = 0;
6360 request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, 6361 request.extra_headers.SetHeader(HttpRequestHeaders::kReferer,
6361 "http://the.previous.site.com/"); 6362 "http://the.previous.site.com/");
6362 6363
6364 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
6363 scoped_ptr<HttpTransaction> trans( 6365 scoped_ptr<HttpTransaction> trans(
6364 new HttpNetworkTransaction(DEFAULT_PRIORITY, 6366 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
6365 CreateSession(&session_deps_)));
6366 6367
6367 MockWrite data_writes[] = { 6368 MockWrite data_writes[] = {
6368 MockWrite("GET / HTTP/1.1\r\n" 6369 MockWrite("GET / HTTP/1.1\r\n"
6369 "Host: www.google.com\r\n" 6370 "Host: www.google.com\r\n"
6370 "Connection: keep-alive\r\n" 6371 "Connection: keep-alive\r\n"
6371 "Referer: http://the.previous.site.com/\r\n\r\n"), 6372 "Referer: http://the.previous.site.com/\r\n\r\n"),
6372 }; 6373 };
6373 6374
6374 // Lastly, the server responds with the actual content. 6375 // Lastly, the server responds with the actual content.
6375 MockRead data_reads[] = { 6376 MockRead data_reads[] = {
(...skipping 14 matching lines...) Expand all
6390 6391
6391 rv = callback.WaitForResult(); 6392 rv = callback.WaitForResult();
6392 EXPECT_EQ(OK, rv); 6393 EXPECT_EQ(OK, rv);
6393 } 6394 }
6394 6395
6395 TEST_P(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { 6396 TEST_P(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) {
6396 HttpRequestInfo request; 6397 HttpRequestInfo request;
6397 request.method = "POST"; 6398 request.method = "POST";
6398 request.url = GURL("http://www.google.com/"); 6399 request.url = GURL("http://www.google.com/");
6399 6400
6401 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
6400 scoped_ptr<HttpTransaction> trans( 6402 scoped_ptr<HttpTransaction> trans(
6401 new HttpNetworkTransaction(DEFAULT_PRIORITY, 6403 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
6402 CreateSession(&session_deps_)));
6403 6404
6404 MockWrite data_writes[] = { 6405 MockWrite data_writes[] = {
6405 MockWrite("POST / HTTP/1.1\r\n" 6406 MockWrite("POST / HTTP/1.1\r\n"
6406 "Host: www.google.com\r\n" 6407 "Host: www.google.com\r\n"
6407 "Connection: keep-alive\r\n" 6408 "Connection: keep-alive\r\n"
6408 "Content-Length: 0\r\n\r\n"), 6409 "Content-Length: 0\r\n\r\n"),
6409 }; 6410 };
6410 6411
6411 // Lastly, the server responds with the actual content. 6412 // Lastly, the server responds with the actual content.
6412 MockRead data_reads[] = { 6413 MockRead data_reads[] = {
(...skipping 14 matching lines...) Expand all
6427 6428
6428 rv = callback.WaitForResult(); 6429 rv = callback.WaitForResult();
6429 EXPECT_EQ(OK, rv); 6430 EXPECT_EQ(OK, rv);
6430 } 6431 }
6431 6432
6432 TEST_P(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { 6433 TEST_P(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) {
6433 HttpRequestInfo request; 6434 HttpRequestInfo request;
6434 request.method = "PUT"; 6435 request.method = "PUT";
6435 request.url = GURL("http://www.google.com/"); 6436 request.url = GURL("http://www.google.com/");
6436 6437
6438 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
6437 scoped_ptr<HttpTransaction> trans( 6439 scoped_ptr<HttpTransaction> trans(
6438 new HttpNetworkTransaction(DEFAULT_PRIORITY, 6440 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
6439 CreateSession(&session_deps_)));
6440 6441
6441 MockWrite data_writes[] = { 6442 MockWrite data_writes[] = {
6442 MockWrite("PUT / HTTP/1.1\r\n" 6443 MockWrite("PUT / HTTP/1.1\r\n"
6443 "Host: www.google.com\r\n" 6444 "Host: www.google.com\r\n"
6444 "Connection: keep-alive\r\n" 6445 "Connection: keep-alive\r\n"
6445 "Content-Length: 0\r\n\r\n"), 6446 "Content-Length: 0\r\n\r\n"),
6446 }; 6447 };
6447 6448
6448 // Lastly, the server responds with the actual content. 6449 // Lastly, the server responds with the actual content.
6449 MockRead data_reads[] = { 6450 MockRead data_reads[] = {
(...skipping 14 matching lines...) Expand all
6464 6465
6465 rv = callback.WaitForResult(); 6466 rv = callback.WaitForResult();
6466 EXPECT_EQ(OK, rv); 6467 EXPECT_EQ(OK, rv);
6467 } 6468 }
6468 6469
6469 TEST_P(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { 6470 TEST_P(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) {
6470 HttpRequestInfo request; 6471 HttpRequestInfo request;
6471 request.method = "HEAD"; 6472 request.method = "HEAD";
6472 request.url = GURL("http://www.google.com/"); 6473 request.url = GURL("http://www.google.com/");
6473 6474
6475 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
6474 scoped_ptr<HttpTransaction> trans( 6476 scoped_ptr<HttpTransaction> trans(
6475 new HttpNetworkTransaction(DEFAULT_PRIORITY, 6477 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
6476 CreateSession(&session_deps_)));
6477 6478
6478 MockWrite data_writes[] = { 6479 MockWrite data_writes[] = {
6479 MockWrite("HEAD / HTTP/1.1\r\n" 6480 MockWrite("HEAD / HTTP/1.1\r\n"
6480 "Host: www.google.com\r\n" 6481 "Host: www.google.com\r\n"
6481 "Connection: keep-alive\r\n" 6482 "Connection: keep-alive\r\n"
6482 "Content-Length: 0\r\n\r\n"), 6483 "Content-Length: 0\r\n\r\n"),
6483 }; 6484 };
6484 6485
6485 // Lastly, the server responds with the actual content. 6486 // Lastly, the server responds with the actual content.
6486 MockRead data_reads[] = { 6487 MockRead data_reads[] = {
(...skipping 15 matching lines...) Expand all
6502 rv = callback.WaitForResult(); 6503 rv = callback.WaitForResult();
6503 EXPECT_EQ(OK, rv); 6504 EXPECT_EQ(OK, rv);
6504 } 6505 }
6505 6506
6506 TEST_P(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { 6507 TEST_P(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) {
6507 HttpRequestInfo request; 6508 HttpRequestInfo request;
6508 request.method = "GET"; 6509 request.method = "GET";
6509 request.url = GURL("http://www.google.com/"); 6510 request.url = GURL("http://www.google.com/");
6510 request.load_flags = LOAD_BYPASS_CACHE; 6511 request.load_flags = LOAD_BYPASS_CACHE;
6511 6512
6513 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
6512 scoped_ptr<HttpTransaction> trans( 6514 scoped_ptr<HttpTransaction> trans(
6513 new HttpNetworkTransaction(DEFAULT_PRIORITY, 6515 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
6514 CreateSession(&session_deps_)));
6515 6516
6516 MockWrite data_writes[] = { 6517 MockWrite data_writes[] = {
6517 MockWrite("GET / HTTP/1.1\r\n" 6518 MockWrite("GET / HTTP/1.1\r\n"
6518 "Host: www.google.com\r\n" 6519 "Host: www.google.com\r\n"
6519 "Connection: keep-alive\r\n" 6520 "Connection: keep-alive\r\n"
6520 "Pragma: no-cache\r\n" 6521 "Pragma: no-cache\r\n"
6521 "Cache-Control: no-cache\r\n\r\n"), 6522 "Cache-Control: no-cache\r\n\r\n"),
6522 }; 6523 };
6523 6524
6524 // Lastly, the server responds with the actual content. 6525 // Lastly, the server responds with the actual content.
(...skipping 17 matching lines...) Expand all
6542 EXPECT_EQ(OK, rv); 6543 EXPECT_EQ(OK, rv);
6543 } 6544 }
6544 6545
6545 TEST_P(HttpNetworkTransactionTest, 6546 TEST_P(HttpNetworkTransactionTest,
6546 BuildRequest_CacheControlValidateCache) { 6547 BuildRequest_CacheControlValidateCache) {
6547 HttpRequestInfo request; 6548 HttpRequestInfo request;
6548 request.method = "GET"; 6549 request.method = "GET";
6549 request.url = GURL("http://www.google.com/"); 6550 request.url = GURL("http://www.google.com/");
6550 request.load_flags = LOAD_VALIDATE_CACHE; 6551 request.load_flags = LOAD_VALIDATE_CACHE;
6551 6552
6553 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
6552 scoped_ptr<HttpTransaction> trans( 6554 scoped_ptr<HttpTransaction> trans(
6553 new HttpNetworkTransaction(DEFAULT_PRIORITY, 6555 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
6554 CreateSession(&session_deps_)));
6555 6556
6556 MockWrite data_writes[] = { 6557 MockWrite data_writes[] = {
6557 MockWrite("GET / HTTP/1.1\r\n" 6558 MockWrite("GET / HTTP/1.1\r\n"
6558 "Host: www.google.com\r\n" 6559 "Host: www.google.com\r\n"
6559 "Connection: keep-alive\r\n" 6560 "Connection: keep-alive\r\n"
6560 "Cache-Control: max-age=0\r\n\r\n"), 6561 "Cache-Control: max-age=0\r\n\r\n"),
6561 }; 6562 };
6562 6563
6563 // Lastly, the server responds with the actual content. 6564 // Lastly, the server responds with the actual content.
6564 MockRead data_reads[] = { 6565 MockRead data_reads[] = {
(...skipping 15 matching lines...) Expand all
6580 rv = callback.WaitForResult(); 6581 rv = callback.WaitForResult();
6581 EXPECT_EQ(OK, rv); 6582 EXPECT_EQ(OK, rv);
6582 } 6583 }
6583 6584
6584 TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { 6585 TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) {
6585 HttpRequestInfo request; 6586 HttpRequestInfo request;
6586 request.method = "GET"; 6587 request.method = "GET";
6587 request.url = GURL("http://www.google.com/"); 6588 request.url = GURL("http://www.google.com/");
6588 request.extra_headers.SetHeader("FooHeader", "Bar"); 6589 request.extra_headers.SetHeader("FooHeader", "Bar");
6589 6590
6591 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
6590 scoped_ptr<HttpTransaction> trans( 6592 scoped_ptr<HttpTransaction> trans(
6591 new HttpNetworkTransaction(DEFAULT_PRIORITY, 6593 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
6592 CreateSession(&session_deps_)));
6593 6594
6594 MockWrite data_writes[] = { 6595 MockWrite data_writes[] = {
6595 MockWrite("GET / HTTP/1.1\r\n" 6596 MockWrite("GET / HTTP/1.1\r\n"
6596 "Host: www.google.com\r\n" 6597 "Host: www.google.com\r\n"
6597 "Connection: keep-alive\r\n" 6598 "Connection: keep-alive\r\n"
6598 "FooHeader: Bar\r\n\r\n"), 6599 "FooHeader: Bar\r\n\r\n"),
6599 }; 6600 };
6600 6601
6601 // Lastly, the server responds with the actual content. 6602 // Lastly, the server responds with the actual content.
6602 MockRead data_reads[] = { 6603 MockRead data_reads[] = {
(...skipping 17 matching lines...) Expand all
6620 } 6621 }
6621 6622
6622 TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { 6623 TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) {
6623 HttpRequestInfo request; 6624 HttpRequestInfo request;
6624 request.method = "GET"; 6625 request.method = "GET";
6625 request.url = GURL("http://www.google.com/"); 6626 request.url = GURL("http://www.google.com/");
6626 request.extra_headers.SetHeader("referer", "www.foo.com"); 6627 request.extra_headers.SetHeader("referer", "www.foo.com");
6627 request.extra_headers.SetHeader("hEllo", "Kitty"); 6628 request.extra_headers.SetHeader("hEllo", "Kitty");
6628 request.extra_headers.SetHeader("FoO", "bar"); 6629 request.extra_headers.SetHeader("FoO", "bar");
6629 6630
6631 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
6630 scoped_ptr<HttpTransaction> trans( 6632 scoped_ptr<HttpTransaction> trans(
6631 new HttpNetworkTransaction(DEFAULT_PRIORITY, 6633 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
6632 CreateSession(&session_deps_)));
6633 6634
6634 MockWrite data_writes[] = { 6635 MockWrite data_writes[] = {
6635 MockWrite("GET / HTTP/1.1\r\n" 6636 MockWrite("GET / HTTP/1.1\r\n"
6636 "Host: www.google.com\r\n" 6637 "Host: www.google.com\r\n"
6637 "Connection: keep-alive\r\n" 6638 "Connection: keep-alive\r\n"
6638 "referer: www.foo.com\r\n" 6639 "referer: www.foo.com\r\n"
6639 "hEllo: Kitty\r\n" 6640 "hEllo: Kitty\r\n"
6640 "FoO: bar\r\n\r\n"), 6641 "FoO: bar\r\n\r\n"),
6641 }; 6642 };
6642 6643
(...skipping 22 matching lines...) Expand all
6665 HttpRequestInfo request; 6666 HttpRequestInfo request;
6666 request.method = "GET"; 6667 request.method = "GET";
6667 request.url = GURL("http://www.google.com/"); 6668 request.url = GURL("http://www.google.com/");
6668 request.load_flags = 0; 6669 request.load_flags = 0;
6669 6670
6670 session_deps_.proxy_service.reset( 6671 session_deps_.proxy_service.reset(
6671 ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080")); 6672 ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"));
6672 CapturingNetLog net_log; 6673 CapturingNetLog net_log;
6673 session_deps_.net_log = &net_log; 6674 session_deps_.net_log = &net_log;
6674 6675
6676 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
6675 scoped_ptr<HttpTransaction> trans( 6677 scoped_ptr<HttpTransaction> trans(
6676 new HttpNetworkTransaction(DEFAULT_PRIORITY, 6678 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
6677 CreateSession(&session_deps_)));
6678 6679
6679 char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; 6680 char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 };
6680 char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; 6681 char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 };
6681 6682
6682 MockWrite data_writes[] = { 6683 MockWrite data_writes[] = {
6683 MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), 6684 MockWrite(ASYNC, write_buffer, arraysize(write_buffer)),
6684 MockWrite("GET / HTTP/1.1\r\n" 6685 MockWrite("GET / HTTP/1.1\r\n"
6685 "Host: www.google.com\r\n" 6686 "Host: www.google.com\r\n"
6686 "Connection: keep-alive\r\n\r\n") 6687 "Connection: keep-alive\r\n\r\n")
6687 }; 6688 };
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
6724 HttpRequestInfo request; 6725 HttpRequestInfo request;
6725 request.method = "GET"; 6726 request.method = "GET";
6726 request.url = GURL("https://www.google.com/"); 6727 request.url = GURL("https://www.google.com/");
6727 request.load_flags = 0; 6728 request.load_flags = 0;
6728 6729
6729 session_deps_.proxy_service.reset( 6730 session_deps_.proxy_service.reset(
6730 ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080")); 6731 ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"));
6731 CapturingNetLog net_log; 6732 CapturingNetLog net_log;
6732 session_deps_.net_log = &net_log; 6733 session_deps_.net_log = &net_log;
6733 6734
6735 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
6734 scoped_ptr<HttpTransaction> trans( 6736 scoped_ptr<HttpTransaction> trans(
6735 new HttpNetworkTransaction(DEFAULT_PRIORITY, 6737 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
6736 CreateSession(&session_deps_)));
6737 6738
6738 unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; 6739 unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 };
6739 unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; 6740 unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 };
6740 6741
6741 MockWrite data_writes[] = { 6742 MockWrite data_writes[] = {
6742 MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), 6743 MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer),
6743 arraysize(write_buffer)), 6744 arraysize(write_buffer)),
6744 MockWrite("GET / HTTP/1.1\r\n" 6745 MockWrite("GET / HTTP/1.1\r\n"
6745 "Host: www.google.com\r\n" 6746 "Host: www.google.com\r\n"
6746 "Connection: keep-alive\r\n\r\n") 6747 "Connection: keep-alive\r\n\r\n")
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
6788 HttpRequestInfo request; 6789 HttpRequestInfo request;
6789 request.method = "GET"; 6790 request.method = "GET";
6790 request.url = GURL("http://www.google.com/"); 6791 request.url = GURL("http://www.google.com/");
6791 request.load_flags = 0; 6792 request.load_flags = 0;
6792 6793
6793 session_deps_.proxy_service.reset( 6794 session_deps_.proxy_service.reset(
6794 ProxyService::CreateFixed("socks4://myproxy:1080")); 6795 ProxyService::CreateFixed("socks4://myproxy:1080"));
6795 CapturingNetLog net_log; 6796 CapturingNetLog net_log;
6796 session_deps_.net_log = &net_log; 6797 session_deps_.net_log = &net_log;
6797 6798
6799 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
6798 scoped_ptr<HttpTransaction> trans( 6800 scoped_ptr<HttpTransaction> trans(
6799 new HttpNetworkTransaction(DEFAULT_PRIORITY, 6801 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
6800 CreateSession(&session_deps_)));
6801 6802
6802 char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; 6803 char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 };
6803 char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; 6804 char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 };
6804 6805
6805 MockWrite data_writes[] = { 6806 MockWrite data_writes[] = {
6806 MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), 6807 MockWrite(ASYNC, write_buffer, arraysize(write_buffer)),
6807 MockWrite("GET / HTTP/1.1\r\n" 6808 MockWrite("GET / HTTP/1.1\r\n"
6808 "Host: www.google.com\r\n" 6809 "Host: www.google.com\r\n"
6809 "Connection: keep-alive\r\n\r\n") 6810 "Connection: keep-alive\r\n\r\n")
6810 }; 6811 };
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
6847 HttpRequestInfo request; 6848 HttpRequestInfo request;
6848 request.method = "GET"; 6849 request.method = "GET";
6849 request.url = GURL("http://www.google.com/"); 6850 request.url = GURL("http://www.google.com/");
6850 request.load_flags = 0; 6851 request.load_flags = 0;
6851 6852
6852 session_deps_.proxy_service.reset( 6853 session_deps_.proxy_service.reset(
6853 ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080")); 6854 ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"));
6854 CapturingNetLog net_log; 6855 CapturingNetLog net_log;
6855 session_deps_.net_log = &net_log; 6856 session_deps_.net_log = &net_log;
6856 6857
6858 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
6857 scoped_ptr<HttpTransaction> trans( 6859 scoped_ptr<HttpTransaction> trans(
6858 new HttpNetworkTransaction(DEFAULT_PRIORITY, 6860 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
6859 CreateSession(&session_deps_)));
6860 6861
6861 const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; 6862 const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 };
6862 const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; 6863 const char kSOCKS5GreetResponse[] = { 0x05, 0x00 };
6863 const char kSOCKS5OkRequest[] = { 6864 const char kSOCKS5OkRequest[] = {
6864 0x05, // Version 6865 0x05, // Version
6865 0x01, // Command (CONNECT) 6866 0x01, // Command (CONNECT)
6866 0x00, // Reserved. 6867 0x00, // Reserved.
6867 0x03, // Address type (DOMAINNAME). 6868 0x03, // Address type (DOMAINNAME).
6868 0x0E, // Length of domain (14) 6869 0x0E, // Length of domain (14)
6869 // Domain string: 6870 // Domain string:
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
6920 HttpRequestInfo request; 6921 HttpRequestInfo request;
6921 request.method = "GET"; 6922 request.method = "GET";
6922 request.url = GURL("https://www.google.com/"); 6923 request.url = GURL("https://www.google.com/");
6923 request.load_flags = 0; 6924 request.load_flags = 0;
6924 6925
6925 session_deps_.proxy_service.reset( 6926 session_deps_.proxy_service.reset(
6926 ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080")); 6927 ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"));
6927 CapturingNetLog net_log; 6928 CapturingNetLog net_log;
6928 session_deps_.net_log = &net_log; 6929 session_deps_.net_log = &net_log;
6929 6930
6931 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
6930 scoped_ptr<HttpTransaction> trans( 6932 scoped_ptr<HttpTransaction> trans(
6931 new HttpNetworkTransaction(DEFAULT_PRIORITY, 6933 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
6932 CreateSession(&session_deps_)));
6933 6934
6934 const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; 6935 const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 };
6935 const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; 6936 const char kSOCKS5GreetResponse[] = { 0x05, 0x00 };
6936 const unsigned char kSOCKS5OkRequest[] = { 6937 const unsigned char kSOCKS5OkRequest[] = {
6937 0x05, // Version 6938 0x05, // Version
6938 0x01, // Command (CONNECT) 6939 0x01, // Command (CONNECT)
6939 0x00, // Reserved. 6940 0x00, // Reserved.
6940 0x03, // Address type (DOMAINNAME). 6941 0x03, // Address type (DOMAINNAME).
6941 0x0E, // Length of domain (14) 6942 0x0E, // Length of domain (14)
6942 // Domain string: 6943 // Domain string:
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
7248 request.method = "GET"; 7249 request.method = "GET";
7249 request.url = GURL("http://www.google.com/"); 7250 request.url = GURL("http://www.google.com/");
7250 7251
7251 session_deps_.proxy_service.reset( 7252 session_deps_.proxy_service.reset(
7252 ProxyService::CreateFixed("myproxy:70;foobar:80")); 7253 ProxyService::CreateFixed("myproxy:70;foobar:80"));
7253 7254
7254 // This simulates failure resolving all hostnames; that means we will fail 7255 // This simulates failure resolving all hostnames; that means we will fail
7255 // connecting to both proxies (myproxy:70 and foobar:80). 7256 // connecting to both proxies (myproxy:70 and foobar:80).
7256 session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); 7257 session_deps_.host_resolver->rules()->AddSimulatedFailure("*");
7257 7258
7259 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
7258 scoped_ptr<HttpTransaction> trans( 7260 scoped_ptr<HttpTransaction> trans(
7259 new HttpNetworkTransaction(DEFAULT_PRIORITY, 7261 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
7260 CreateSession(&session_deps_)));
7261 7262
7262 TestCompletionCallback callback; 7263 TestCompletionCallback callback;
7263 7264
7264 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 7265 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
7265 EXPECT_EQ(ERR_IO_PENDING, rv); 7266 EXPECT_EQ(ERR_IO_PENDING, rv);
7266 7267
7267 rv = callback.WaitForResult(); 7268 rv = callback.WaitForResult();
7268 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); 7269 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv);
7269 } 7270 }
7270 7271
7271 // Base test to make sure that when the load flags for a request specify to 7272 // Base test to make sure that when the load flags for a request specify to
7272 // bypass the cache, the DNS cache is not used. 7273 // bypass the cache, the DNS cache is not used.
7273 void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( 7274 void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper(
7274 int load_flags) { 7275 int load_flags) {
7275 // Issue a request, asking to bypass the cache(s). 7276 // Issue a request, asking to bypass the cache(s).
7276 HttpRequestInfo request; 7277 HttpRequestInfo request;
7277 request.method = "GET"; 7278 request.method = "GET";
7278 request.load_flags = load_flags; 7279 request.load_flags = load_flags;
7279 request.url = GURL("http://www.google.com/"); 7280 request.url = GURL("http://www.google.com/");
7280 7281
7281 // Select a host resolver that does caching. 7282 // Select a host resolver that does caching.
7282 session_deps_.host_resolver.reset(new MockCachingHostResolver); 7283 session_deps_.host_resolver.reset(new MockCachingHostResolver);
7283 7284
7284 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(DEFAULT_PRIORITY, 7285 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
7285 CreateSession(&session_deps_))); 7286 scoped_ptr<HttpTransaction> trans(
7287 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
7286 7288
7287 // Warm up the host cache so it has an entry for "www.google.com". 7289 // Warm up the host cache so it has an entry for "www.google.com".
7288 AddressList addrlist; 7290 AddressList addrlist;
7289 TestCompletionCallback callback; 7291 TestCompletionCallback callback;
7290 int rv = session_deps_.host_resolver->Resolve( 7292 int rv = session_deps_.host_resolver->Resolve(
7291 HostResolver::RequestInfo(HostPortPair("www.google.com", 80)), 7293 HostResolver::RequestInfo(HostPortPair("www.google.com", 80)),
7292 DEFAULT_PRIORITY, 7294 DEFAULT_PRIORITY,
7293 &addrlist, 7295 &addrlist,
7294 callback.callback(), 7296 callback.callback(),
7295 NULL, 7297 NULL,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
7339 TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { 7341 TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) {
7340 BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); 7342 BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE);
7341 } 7343 }
7342 7344
7343 TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { 7345 TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) {
7344 BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); 7346 BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE);
7345 } 7347 }
7346 7348
7347 // Make sure we can handle an error when writing the request. 7349 // Make sure we can handle an error when writing the request.
7348 TEST_P(HttpNetworkTransactionTest, RequestWriteError) { 7350 TEST_P(HttpNetworkTransactionTest, RequestWriteError) {
7349 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
7350
7351 HttpRequestInfo request; 7351 HttpRequestInfo request;
7352 request.method = "GET"; 7352 request.method = "GET";
7353 request.url = GURL("http://www.foo.com/"); 7353 request.url = GURL("http://www.foo.com/");
7354 request.load_flags = 0; 7354 request.load_flags = 0;
7355 7355
7356 MockWrite write_failure[] = { 7356 MockWrite write_failure[] = {
7357 MockWrite(ASYNC, ERR_CONNECTION_RESET), 7357 MockWrite(ASYNC, ERR_CONNECTION_RESET),
7358 }; 7358 };
7359 StaticSocketDataProvider data(NULL, 0, 7359 StaticSocketDataProvider data(NULL, 0,
7360 write_failure, arraysize(write_failure)); 7360 write_failure, arraysize(write_failure));
7361 session_deps_.socket_factory->AddSocketDataProvider(&data); 7361 session_deps_.socket_factory->AddSocketDataProvider(&data);
7362 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
7362 7363
7363 TestCompletionCallback callback; 7364 TestCompletionCallback callback;
7364 7365
7365 scoped_ptr<HttpTransaction> trans( 7366 scoped_ptr<HttpTransaction> trans(
7366 new HttpNetworkTransaction(DEFAULT_PRIORITY, 7367 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
7367 CreateSession(&session_deps_)));
7368 7368
7369 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 7369 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
7370 EXPECT_EQ(ERR_IO_PENDING, rv); 7370 EXPECT_EQ(ERR_IO_PENDING, rv);
7371 7371
7372 rv = callback.WaitForResult(); 7372 rv = callback.WaitForResult();
7373 EXPECT_EQ(ERR_CONNECTION_RESET, rv); 7373 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
7374 } 7374 }
7375 7375
7376 // Check that a connection closed after the start of the headers finishes ok. 7376 // Check that a connection closed after the start of the headers finishes ok.
7377 TEST_P(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { 7377 TEST_P(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) {
7378 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
7379
7380 HttpRequestInfo request; 7378 HttpRequestInfo request;
7381 request.method = "GET"; 7379 request.method = "GET";
7382 request.url = GURL("http://www.foo.com/"); 7380 request.url = GURL("http://www.foo.com/");
7383 request.load_flags = 0; 7381 request.load_flags = 0;
7384 7382
7385 MockRead data_reads[] = { 7383 MockRead data_reads[] = {
7386 MockRead("HTTP/1."), 7384 MockRead("HTTP/1."),
7387 MockRead(SYNCHRONOUS, OK), 7385 MockRead(SYNCHRONOUS, OK),
7388 }; 7386 };
7389 7387
7390 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 7388 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
7391 session_deps_.socket_factory->AddSocketDataProvider(&data); 7389 session_deps_.socket_factory->AddSocketDataProvider(&data);
7390 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
7392 7391
7393 TestCompletionCallback callback; 7392 TestCompletionCallback callback;
7394 7393
7395 scoped_ptr<HttpTransaction> trans( 7394 scoped_ptr<HttpTransaction> trans(
7396 new HttpNetworkTransaction(DEFAULT_PRIORITY, 7395 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
7397 CreateSession(&session_deps_)));
7398 7396
7399 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 7397 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
7400 EXPECT_EQ(ERR_IO_PENDING, rv); 7398 EXPECT_EQ(ERR_IO_PENDING, rv);
7401 7399
7402 rv = callback.WaitForResult(); 7400 rv = callback.WaitForResult();
7403 EXPECT_EQ(OK, rv); 7401 EXPECT_EQ(OK, rv);
7404 7402
7405 const HttpResponseInfo* response = trans->GetResponseInfo(); 7403 const HttpResponseInfo* response = trans->GetResponseInfo();
7406 ASSERT_TRUE(response != NULL); 7404 ASSERT_TRUE(response != NULL);
7407 7405
7408 EXPECT_TRUE(response->headers.get() != NULL); 7406 EXPECT_TRUE(response->headers.get() != NULL);
7409 EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); 7407 EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine());
7410 7408
7411 std::string response_data; 7409 std::string response_data;
7412 rv = ReadTransaction(trans.get(), &response_data); 7410 rv = ReadTransaction(trans.get(), &response_data);
7413 EXPECT_EQ(OK, rv); 7411 EXPECT_EQ(OK, rv);
7414 EXPECT_EQ("", response_data); 7412 EXPECT_EQ("", response_data);
7415 } 7413 }
7416 7414
7417 // Make sure that a dropped connection while draining the body for auth 7415 // Make sure that a dropped connection while draining the body for auth
7418 // restart does the right thing. 7416 // restart does the right thing.
7419 TEST_P(HttpNetworkTransactionTest, DrainResetOK) { 7417 TEST_P(HttpNetworkTransactionTest, DrainResetOK) {
7420 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
7421
7422 HttpRequestInfo request; 7418 HttpRequestInfo request;
7423 request.method = "GET"; 7419 request.method = "GET";
7424 request.url = GURL("http://www.google.com/"); 7420 request.url = GURL("http://www.google.com/");
7425 request.load_flags = 0; 7421 request.load_flags = 0;
7426 7422
7427 MockWrite data_writes1[] = { 7423 MockWrite data_writes1[] = {
7428 MockWrite("GET / HTTP/1.1\r\n" 7424 MockWrite("GET / HTTP/1.1\r\n"
7429 "Host: www.google.com\r\n" 7425 "Host: www.google.com\r\n"
7430 "Connection: keep-alive\r\n\r\n"), 7426 "Connection: keep-alive\r\n\r\n"),
7431 }; 7427 };
7432 7428
7433 MockRead data_reads1[] = { 7429 MockRead data_reads1[] = {
7434 MockRead("HTTP/1.1 401 Unauthorized\r\n"), 7430 MockRead("HTTP/1.1 401 Unauthorized\r\n"),
7435 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), 7431 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
7436 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), 7432 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
7437 MockRead("Content-Length: 14\r\n\r\n"), 7433 MockRead("Content-Length: 14\r\n\r\n"),
7438 MockRead("Unauth"), 7434 MockRead("Unauth"),
7439 MockRead(ASYNC, ERR_CONNECTION_RESET), 7435 MockRead(ASYNC, ERR_CONNECTION_RESET),
7440 }; 7436 };
7441 7437
7442 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), 7438 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
7443 data_writes1, arraysize(data_writes1)); 7439 data_writes1, arraysize(data_writes1));
7444 session_deps_.socket_factory->AddSocketDataProvider(&data1); 7440 session_deps_.socket_factory->AddSocketDataProvider(&data1);
7441 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
7445 7442
7446 // After calling trans->RestartWithAuth(), this is the request we should 7443 // After calling trans->RestartWithAuth(), this is the request we should
7447 // be issuing -- the final header line contains the credentials. 7444 // be issuing -- the final header line contains the credentials.
7448 MockWrite data_writes2[] = { 7445 MockWrite data_writes2[] = {
7449 MockWrite("GET / HTTP/1.1\r\n" 7446 MockWrite("GET / HTTP/1.1\r\n"
7450 "Host: www.google.com\r\n" 7447 "Host: www.google.com\r\n"
7451 "Connection: keep-alive\r\n" 7448 "Connection: keep-alive\r\n"
7452 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), 7449 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
7453 }; 7450 };
7454 7451
7455 // Lastly, the server responds with the actual content. 7452 // Lastly, the server responds with the actual content.
7456 MockRead data_reads2[] = { 7453 MockRead data_reads2[] = {
7457 MockRead("HTTP/1.1 200 OK\r\n"), 7454 MockRead("HTTP/1.1 200 OK\r\n"),
7458 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), 7455 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
7459 MockRead("Content-Length: 100\r\n\r\n"), 7456 MockRead("Content-Length: 100\r\n\r\n"),
7460 MockRead(SYNCHRONOUS, OK), 7457 MockRead(SYNCHRONOUS, OK),
7461 }; 7458 };
7462 7459
7463 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), 7460 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
7464 data_writes2, arraysize(data_writes2)); 7461 data_writes2, arraysize(data_writes2));
7465 session_deps_.socket_factory->AddSocketDataProvider(&data2); 7462 session_deps_.socket_factory->AddSocketDataProvider(&data2);
wtc 2013/10/16 18:12:44 Nit: if you want to wait until we are done setting
mmenke 2013/10/16 18:17:53 Done. While there's no need to abort the CQ job,
7466 7463
7467 TestCompletionCallback callback1; 7464 TestCompletionCallback callback1;
7468 7465
7469 scoped_ptr<HttpTransaction> trans( 7466 scoped_ptr<HttpTransaction> trans(
7470 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 7467 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
7471 7468
7472 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); 7469 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
7473 EXPECT_EQ(ERR_IO_PENDING, rv); 7470 EXPECT_EQ(ERR_IO_PENDING, rv);
7474 7471
7475 rv = callback1.WaitForResult(); 7472 rv = callback1.WaitForResult();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
7511 StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); 7508 StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0);
7512 SSLSocketDataProvider ssl(ASYNC, OK); 7509 SSLSocketDataProvider ssl(ASYNC, OK);
7513 7510
7514 session_deps_.socket_factory->AddSocketDataProvider(&data); 7511 session_deps_.socket_factory->AddSocketDataProvider(&data);
7515 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 7512 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
7516 7513
7517 TestCompletionCallback callback; 7514 TestCompletionCallback callback;
7518 7515
7519 session_deps_.socket_factory->ResetNextMockIndexes(); 7516 session_deps_.socket_factory->ResetNextMockIndexes();
7520 7517
7518 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
7521 scoped_ptr<HttpTransaction> trans( 7519 scoped_ptr<HttpTransaction> trans(
7522 new HttpNetworkTransaction(DEFAULT_PRIORITY, 7520 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
7523 CreateSession(&session_deps_)));
7524 7521
7525 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 7522 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
7526 EXPECT_EQ(ERR_IO_PENDING, rv); 7523 EXPECT_EQ(ERR_IO_PENDING, rv);
7527 7524
7528 rv = callback.WaitForResult(); 7525 rv = callback.WaitForResult();
7529 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); 7526 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv);
7530 } 7527 }
7531 7528
7532 TEST_P(HttpNetworkTransactionTest, LargeContentLengthThenClose) { 7529 TEST_P(HttpNetworkTransactionTest, LargeContentLengthThenClose) {
7533 HttpRequestInfo request; 7530 HttpRequestInfo request;
7534 request.method = "GET"; 7531 request.method = "GET";
7535 request.url = GURL("http://www.google.com/"); 7532 request.url = GURL("http://www.google.com/");
7536 request.load_flags = 0; 7533 request.load_flags = 0;
7537 7534
7535 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
7538 scoped_ptr<HttpTransaction> trans( 7536 scoped_ptr<HttpTransaction> trans(
7539 new HttpNetworkTransaction(DEFAULT_PRIORITY, 7537 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
7540 CreateSession(&session_deps_)));
7541 7538
7542 MockRead data_reads[] = { 7539 MockRead data_reads[] = {
7543 MockRead("HTTP/1.0 200 OK\r\nContent-Length:6719476739\r\n\r\n"), 7540 MockRead("HTTP/1.0 200 OK\r\nContent-Length:6719476739\r\n\r\n"),
7544 MockRead(SYNCHRONOUS, OK), 7541 MockRead(SYNCHRONOUS, OK),
7545 }; 7542 };
7546 7543
7547 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 7544 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
7548 session_deps_.socket_factory->AddSocketDataProvider(&data); 7545 session_deps_.socket_factory->AddSocketDataProvider(&data);
7549 7546
7550 TestCompletionCallback callback; 7547 TestCompletionCallback callback;
(...skipping 29 matching lines...) Expand all
7580 kuint64max, 7577 kuint64max,
7581 base::Time())); 7578 base::Time()));
7582 UploadDataStream upload_data_stream(element_readers.Pass(), 0); 7579 UploadDataStream upload_data_stream(element_readers.Pass(), 0);
7583 7580
7584 HttpRequestInfo request; 7581 HttpRequestInfo request;
7585 request.method = "POST"; 7582 request.method = "POST";
7586 request.url = GURL("http://www.google.com/upload"); 7583 request.url = GURL("http://www.google.com/upload");
7587 request.upload_data_stream = &upload_data_stream; 7584 request.upload_data_stream = &upload_data_stream;
7588 request.load_flags = 0; 7585 request.load_flags = 0;
7589 7586
7587 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
7590 scoped_ptr<HttpTransaction> trans( 7588 scoped_ptr<HttpTransaction> trans(
7591 new HttpNetworkTransaction(DEFAULT_PRIORITY, 7589 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
7592 CreateSession(&session_deps_)));
7593 7590
7594 MockRead data_reads[] = { 7591 MockRead data_reads[] = {
7595 MockRead("HTTP/1.0 200 OK\r\n\r\n"), 7592 MockRead("HTTP/1.0 200 OK\r\n\r\n"),
7596 MockRead("hello world"), 7593 MockRead("hello world"),
7597 MockRead(SYNCHRONOUS, OK), 7594 MockRead(SYNCHRONOUS, OK),
7598 }; 7595 };
7599 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 7596 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
7600 session_deps_.socket_factory->AddSocketDataProvider(&data); 7597 session_deps_.socket_factory->AddSocketDataProvider(&data);
7601 7598
7602 TestCompletionCallback callback; 7599 TestCompletionCallback callback;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
7639 UploadDataStream upload_data_stream(element_readers.Pass(), 0); 7636 UploadDataStream upload_data_stream(element_readers.Pass(), 0);
7640 7637
7641 HttpRequestInfo request; 7638 HttpRequestInfo request;
7642 request.method = "POST"; 7639 request.method = "POST";
7643 request.url = GURL("http://www.google.com/upload"); 7640 request.url = GURL("http://www.google.com/upload");
7644 request.upload_data_stream = &upload_data_stream; 7641 request.upload_data_stream = &upload_data_stream;
7645 request.load_flags = 0; 7642 request.load_flags = 0;
7646 7643
7647 // If we try to upload an unreadable file, the network stack should report 7644 // If we try to upload an unreadable file, the network stack should report
7648 // the file size as zero and upload zero bytes for that file. 7645 // the file size as zero and upload zero bytes for that file.
7646 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
7649 scoped_ptr<HttpTransaction> trans( 7647 scoped_ptr<HttpTransaction> trans(
7650 new HttpNetworkTransaction(DEFAULT_PRIORITY, 7648 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
7651 CreateSession(&session_deps_)));
7652 7649
7653 MockRead data_reads[] = { 7650 MockRead data_reads[] = {
7654 MockRead("HTTP/1.0 200 OK\r\n\r\n"), 7651 MockRead("HTTP/1.0 200 OK\r\n\r\n"),
7655 MockRead(SYNCHRONOUS, OK), 7652 MockRead(SYNCHRONOUS, OK),
7656 }; 7653 };
7657 MockWrite data_writes[] = { 7654 MockWrite data_writes[] = {
7658 MockWrite("POST /upload HTTP/1.1\r\n" 7655 MockWrite("POST /upload HTTP/1.1\r\n"
7659 "Host: www.google.com\r\n" 7656 "Host: www.google.com\r\n"
7660 "Connection: keep-alive\r\n" 7657 "Connection: keep-alive\r\n"
7661 "Content-Length: 0\r\n\r\n"), 7658 "Content-Length: 0\r\n\r\n"),
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
7697 kuint64max, 7694 kuint64max,
7698 base::Time())); 7695 base::Time()));
7699 UploadDataStream upload_data_stream(element_readers.Pass(), 0); 7696 UploadDataStream upload_data_stream(element_readers.Pass(), 0);
7700 7697
7701 HttpRequestInfo request; 7698 HttpRequestInfo request;
7702 request.method = "POST"; 7699 request.method = "POST";
7703 request.url = GURL("http://www.google.com/upload"); 7700 request.url = GURL("http://www.google.com/upload");
7704 request.upload_data_stream = &upload_data_stream; 7701 request.upload_data_stream = &upload_data_stream;
7705 request.load_flags = 0; 7702 request.load_flags = 0;
7706 7703
7704 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
7707 scoped_ptr<HttpTransaction> trans( 7705 scoped_ptr<HttpTransaction> trans(
7708 new HttpNetworkTransaction(DEFAULT_PRIORITY, 7706 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
7709 CreateSession(&session_deps_)));
7710 7707
7711 MockRead data_reads[] = { 7708 MockRead data_reads[] = {
7712 MockRead("HTTP/1.1 401 Unauthorized\r\n"), 7709 MockRead("HTTP/1.1 401 Unauthorized\r\n"),
7713 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), 7710 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
7714 MockRead("Content-Length: 0\r\n\r\n"), // No response body. 7711 MockRead("Content-Length: 0\r\n\r\n"), // No response body.
7715 7712
7716 MockRead("HTTP/1.1 200 OK\r\n"), 7713 MockRead("HTTP/1.1 200 OK\r\n"),
7717 MockRead("Content-Length: 0\r\n\r\n"), 7714 MockRead("Content-Length: 0\r\n\r\n"),
7718 MockRead(SYNCHRONOUS, OK), 7715 MockRead(SYNCHRONOUS, OK),
7719 }; 7716 };
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
7801 ScopedVector<UploadElementReader> element_readers; 7798 ScopedVector<UploadElementReader> element_readers;
7802 element_readers.push_back(fake_reader); 7799 element_readers.push_back(fake_reader);
7803 UploadDataStream upload_data_stream(element_readers.Pass(), 0); 7800 UploadDataStream upload_data_stream(element_readers.Pass(), 0);
7804 7801
7805 HttpRequestInfo request; 7802 HttpRequestInfo request;
7806 request.method = "POST"; 7803 request.method = "POST";
7807 request.url = GURL("http://www.google.com/upload"); 7804 request.url = GURL("http://www.google.com/upload");
7808 request.upload_data_stream = &upload_data_stream; 7805 request.upload_data_stream = &upload_data_stream;
7809 request.load_flags = 0; 7806 request.load_flags = 0;
7810 7807
7808 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
7811 scoped_ptr<HttpTransaction> trans( 7809 scoped_ptr<HttpTransaction> trans(
7812 new HttpNetworkTransaction(DEFAULT_PRIORITY, 7810 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
7813 CreateSession(&session_deps_)));
7814 7811
7815 StaticSocketDataProvider data; 7812 StaticSocketDataProvider data;
7816 session_deps_.socket_factory->AddSocketDataProvider(&data); 7813 session_deps_.socket_factory->AddSocketDataProvider(&data);
7817 7814
7818 TestCompletionCallback callback; 7815 TestCompletionCallback callback;
7819 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 7816 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
7820 EXPECT_EQ(ERR_IO_PENDING, rv); 7817 EXPECT_EQ(ERR_IO_PENDING, rv);
7821 base::MessageLoop::current()->RunUntilIdle(); 7818 base::MessageLoop::current()->RunUntilIdle();
7822 7819
7823 // Transaction is pending on request body initialization. 7820 // Transaction is pending on request body initialization.
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
7905 data_writes3, arraysize(data_writes3)); 7902 data_writes3, arraysize(data_writes3));
7906 StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), 7903 StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4),
7907 data_writes4, arraysize(data_writes4)); 7904 data_writes4, arraysize(data_writes4));
7908 session_deps_.socket_factory->AddSocketDataProvider(&data1); 7905 session_deps_.socket_factory->AddSocketDataProvider(&data1);
7909 session_deps_.socket_factory->AddSocketDataProvider(&data2); 7906 session_deps_.socket_factory->AddSocketDataProvider(&data2);
7910 session_deps_.socket_factory->AddSocketDataProvider(&data3); 7907 session_deps_.socket_factory->AddSocketDataProvider(&data3);
7911 session_deps_.socket_factory->AddSocketDataProvider(&data4); 7908 session_deps_.socket_factory->AddSocketDataProvider(&data4);
7912 7909
7913 TestCompletionCallback callback1; 7910 TestCompletionCallback callback1;
7914 7911
7912 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
7915 scoped_ptr<HttpTransaction> trans( 7913 scoped_ptr<HttpTransaction> trans(
7916 new HttpNetworkTransaction(DEFAULT_PRIORITY, 7914 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
7917 CreateSession(&session_deps_)));
7918 7915
7919 // Issue the first request with Authorize headers. There should be a 7916 // Issue the first request with Authorize headers. There should be a
7920 // password prompt for first_realm waiting to be filled in after the 7917 // password prompt for first_realm waiting to be filled in after the
7921 // transaction completes. 7918 // transaction completes.
7922 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); 7919 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
7923 EXPECT_EQ(ERR_IO_PENDING, rv); 7920 EXPECT_EQ(ERR_IO_PENDING, rv);
7924 rv = callback1.WaitForResult(); 7921 rv = callback1.WaitForResult();
7925 EXPECT_EQ(OK, rv); 7922 EXPECT_EQ(OK, rv);
7926 const HttpResponseInfo* response = trans->GetResponseInfo(); 7923 const HttpResponseInfo* response = trans->GetResponseInfo();
7927 ASSERT_TRUE(response != NULL); 7924 ASSERT_TRUE(response != NULL);
(...skipping 1352 matching lines...) Expand 10 before | Expand all | Expand 10 after
9280 } else { 9277 } else {
9281 session_deps_.proxy_service.reset(ProxyService::CreateDirect()); 9278 session_deps_.proxy_service.reset(ProxyService::CreateDirect());
9282 } 9279 }
9283 9280
9284 HttpRequestInfo request; 9281 HttpRequestInfo request;
9285 request.method = "GET"; 9282 request.method = "GET";
9286 request.url = GURL(test_config.server_url); 9283 request.url = GURL(test_config.server_url);
9287 request.load_flags = 0; 9284 request.load_flags = 0;
9288 9285
9289 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 9286 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
9290 HttpNetworkTransaction trans( 9287 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session);
9291 DEFAULT_PRIORITY, CreateSession(&session_deps_));
9292 9288
9293 for (int round = 0; round < test_config.num_auth_rounds; ++round) { 9289 for (int round = 0; round < test_config.num_auth_rounds; ++round) {
9294 const TestRound& read_write_round = test_config.rounds[round]; 9290 const TestRound& read_write_round = test_config.rounds[round];
9295 9291
9296 // Set up expected reads and writes. 9292 // Set up expected reads and writes.
9297 MockRead reads[2]; 9293 MockRead reads[2];
9298 reads[0] = read_write_round.read; 9294 reads[0] = read_write_round.read;
9299 size_t length_reads = 1; 9295 size_t length_reads = 1;
9300 if (read_write_round.extra_read) { 9296 if (read_write_round.extra_read) {
9301 reads[1] = *read_write_round.extra_read; 9297 reads[1] = *read_write_round.extra_read;
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
9836 MockRead(SYNCHRONOUS, "hello world"), 9832 MockRead(SYNCHRONOUS, "hello world"),
9837 MockRead(SYNCHRONOUS, OK), 9833 MockRead(SYNCHRONOUS, OK),
9838 }; 9834 };
9839 9835
9840 HttpRequestInfo request; 9836 HttpRequestInfo request;
9841 request.method = "GET"; 9837 request.method = "GET";
9842 request.url = GURL("http://www.google.com/"); 9838 request.url = GURL("http://www.google.com/");
9843 request.load_flags = 0; 9839 request.load_flags = 0;
9844 9840
9845 session_deps_.host_resolver->set_synchronous_mode(true); 9841 session_deps_.host_resolver->set_synchronous_mode(true);
9842 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
9846 scoped_ptr<HttpTransaction> trans( 9843 scoped_ptr<HttpTransaction> trans(
9847 new HttpNetworkTransaction(DEFAULT_PRIORITY, 9844 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
9848 CreateSession(&session_deps_)));
9849 9845
9850 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 9846 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
9851 data.set_connect_data(mock_connect); 9847 data.set_connect_data(mock_connect);
9852 session_deps_.socket_factory->AddSocketDataProvider(&data); 9848 session_deps_.socket_factory->AddSocketDataProvider(&data);
9853 9849
9854 TestCompletionCallback callback; 9850 TestCompletionCallback callback;
9855 9851
9856 CapturingBoundNetLog log; 9852 CapturingBoundNetLog log;
9857 int rv = trans->Start(&request, callback.callback(), log.bound()); 9853 int rv = trans->Start(&request, callback.callback(), log.bound());
9858 EXPECT_EQ(ERR_IO_PENDING, rv); 9854 EXPECT_EQ(ERR_IO_PENDING, rv);
(...skipping 1659 matching lines...) Expand 10 before | Expand all | Expand 10 after
11518 EXPECT_FALSE( 11514 EXPECT_FALSE(
11519 HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); 11515 HasSpdySession(session->spdy_session_pool(), spdy_session_key_b));
11520 } 11516 }
11521 11517
11522 TEST_P(HttpNetworkTransactionTest, HttpSyncConnectError) { 11518 TEST_P(HttpNetworkTransactionTest, HttpSyncConnectError) {
11523 HttpRequestInfo request; 11519 HttpRequestInfo request;
11524 request.method = "GET"; 11520 request.method = "GET";
11525 request.url = GURL("http://www.google.com/"); 11521 request.url = GURL("http://www.google.com/");
11526 request.load_flags = 0; 11522 request.load_flags = 0;
11527 11523
11524 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
11528 scoped_ptr<HttpTransaction> trans( 11525 scoped_ptr<HttpTransaction> trans(
11529 new HttpNetworkTransaction(DEFAULT_PRIORITY, 11526 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
11530 CreateSession(&session_deps_)));
11531 11527
11532 MockConnect mock_connect(SYNCHRONOUS, ERR_CONNECTION_REFUSED); 11528 MockConnect mock_connect(SYNCHRONOUS, ERR_CONNECTION_REFUSED);
11533 StaticSocketDataProvider data; 11529 StaticSocketDataProvider data;
11534 data.set_connect_data(mock_connect); 11530 data.set_connect_data(mock_connect);
11535 session_deps_.socket_factory->AddSocketDataProvider(&data); 11531 session_deps_.socket_factory->AddSocketDataProvider(&data);
11536 11532
11537 TestCompletionCallback callback; 11533 TestCompletionCallback callback;
11538 11534
11539 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 11535 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
11540 EXPECT_EQ(ERR_IO_PENDING, rv); 11536 EXPECT_EQ(ERR_IO_PENDING, rv);
11541 11537
11542 rv = callback.WaitForResult(); 11538 rv = callback.WaitForResult();
11543 EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); 11539 EXPECT_EQ(ERR_CONNECTION_REFUSED, rv);
11544 11540
11545 EXPECT_EQ(NULL, trans->GetResponseInfo()); 11541 EXPECT_EQ(NULL, trans->GetResponseInfo());
11546 11542
11547 // We don't care whether this succeeds or fails, but it shouldn't crash. 11543 // We don't care whether this succeeds or fails, but it shouldn't crash.
11548 HttpRequestHeaders request_headers; 11544 HttpRequestHeaders request_headers;
11549 trans->GetFullRequestHeaders(&request_headers); 11545 trans->GetFullRequestHeaders(&request_headers);
11550 } 11546 }
11551 11547
11552 TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) { 11548 TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) {
11553 HttpRequestInfo request; 11549 HttpRequestInfo request;
11554 request.method = "GET"; 11550 request.method = "GET";
11555 request.url = GURL("http://www.google.com/"); 11551 request.url = GURL("http://www.google.com/");
11556 request.load_flags = 0; 11552 request.load_flags = 0;
11557 11553
11554 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
11558 scoped_ptr<HttpTransaction> trans( 11555 scoped_ptr<HttpTransaction> trans(
11559 new HttpNetworkTransaction(DEFAULT_PRIORITY, 11556 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
11560 CreateSession(&session_deps_)));
11561 11557
11562 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); 11558 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED);
11563 StaticSocketDataProvider data; 11559 StaticSocketDataProvider data;
11564 data.set_connect_data(mock_connect); 11560 data.set_connect_data(mock_connect);
11565 session_deps_.socket_factory->AddSocketDataProvider(&data); 11561 session_deps_.socket_factory->AddSocketDataProvider(&data);
11566 11562
11567 TestCompletionCallback callback; 11563 TestCompletionCallback callback;
11568 11564
11569 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 11565 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
11570 EXPECT_EQ(ERR_IO_PENDING, rv); 11566 EXPECT_EQ(ERR_IO_PENDING, rv);
11571 11567
11572 rv = callback.WaitForResult(); 11568 rv = callback.WaitForResult();
11573 EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); 11569 EXPECT_EQ(ERR_CONNECTION_REFUSED, rv);
11574 11570
11575 EXPECT_EQ(NULL, trans->GetResponseInfo()); 11571 EXPECT_EQ(NULL, trans->GetResponseInfo());
11576 11572
11577 // We don't care whether this succeeds or fails, but it shouldn't crash. 11573 // We don't care whether this succeeds or fails, but it shouldn't crash.
11578 HttpRequestHeaders request_headers; 11574 HttpRequestHeaders request_headers;
11579 trans->GetFullRequestHeaders(&request_headers); 11575 trans->GetFullRequestHeaders(&request_headers);
11580 } 11576 }
11581 11577
11582 TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) { 11578 TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) {
11583 HttpRequestInfo request; 11579 HttpRequestInfo request;
11584 request.method = "GET"; 11580 request.method = "GET";
11585 request.url = GURL("http://www.google.com/"); 11581 request.url = GURL("http://www.google.com/");
11586 request.load_flags = 0; 11582 request.load_flags = 0;
11587 11583
11584 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
11588 scoped_ptr<HttpTransaction> trans( 11585 scoped_ptr<HttpTransaction> trans(
11589 new HttpNetworkTransaction(DEFAULT_PRIORITY, 11586 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
11590 CreateSession(&session_deps_)));
11591 11587
11592 MockWrite data_writes[] = { 11588 MockWrite data_writes[] = {
11593 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), 11589 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
11594 }; 11590 };
11595 MockRead data_reads[] = { 11591 MockRead data_reads[] = {
11596 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. 11592 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached.
11597 }; 11593 };
11598 11594
11599 StaticSocketDataProvider data(data_reads, arraysize(data_reads), 11595 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
11600 data_writes, arraysize(data_writes)); 11596 data_writes, arraysize(data_writes));
(...skipping 13 matching lines...) Expand all
11614 EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); 11610 EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers));
11615 EXPECT_TRUE(request_headers.HasHeader("Host")); 11611 EXPECT_TRUE(request_headers.HasHeader("Host"));
11616 } 11612 }
11617 11613
11618 TEST_P(HttpNetworkTransactionTest, HttpAsyncWriteError) { 11614 TEST_P(HttpNetworkTransactionTest, HttpAsyncWriteError) {
11619 HttpRequestInfo request; 11615 HttpRequestInfo request;
11620 request.method = "GET"; 11616 request.method = "GET";
11621 request.url = GURL("http://www.google.com/"); 11617 request.url = GURL("http://www.google.com/");
11622 request.load_flags = 0; 11618 request.load_flags = 0;
11623 11619
11620 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
11624 scoped_ptr<HttpTransaction> trans( 11621 scoped_ptr<HttpTransaction> trans(
11625 new HttpNetworkTransaction(DEFAULT_PRIORITY, 11622 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
11626 CreateSession(&session_deps_)));
11627 11623
11628 MockWrite data_writes[] = { 11624 MockWrite data_writes[] = {
11629 MockWrite(ASYNC, ERR_CONNECTION_RESET), 11625 MockWrite(ASYNC, ERR_CONNECTION_RESET),
11630 }; 11626 };
11631 MockRead data_reads[] = { 11627 MockRead data_reads[] = {
11632 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. 11628 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached.
11633 }; 11629 };
11634 11630
11635 StaticSocketDataProvider data(data_reads, arraysize(data_reads), 11631 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
11636 data_writes, arraysize(data_writes)); 11632 data_writes, arraysize(data_writes));
(...skipping 13 matching lines...) Expand all
11650 EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); 11646 EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers));
11651 EXPECT_TRUE(request_headers.HasHeader("Host")); 11647 EXPECT_TRUE(request_headers.HasHeader("Host"));
11652 } 11648 }
11653 11649
11654 TEST_P(HttpNetworkTransactionTest, HttpSyncReadError) { 11650 TEST_P(HttpNetworkTransactionTest, HttpSyncReadError) {
11655 HttpRequestInfo request; 11651 HttpRequestInfo request;
11656 request.method = "GET"; 11652 request.method = "GET";
11657 request.url = GURL("http://www.google.com/"); 11653 request.url = GURL("http://www.google.com/");
11658 request.load_flags = 0; 11654 request.load_flags = 0;
11659 11655
11656 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
11660 scoped_ptr<HttpTransaction> trans( 11657 scoped_ptr<HttpTransaction> trans(
11661 new HttpNetworkTransaction(DEFAULT_PRIORITY, 11658 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
11662 CreateSession(&session_deps_)));
11663 11659
11664 MockWrite data_writes[] = { 11660 MockWrite data_writes[] = {
11665 MockWrite("GET / HTTP/1.1\r\n" 11661 MockWrite("GET / HTTP/1.1\r\n"
11666 "Host: www.google.com\r\n" 11662 "Host: www.google.com\r\n"
11667 "Connection: keep-alive\r\n\r\n"), 11663 "Connection: keep-alive\r\n\r\n"),
11668 }; 11664 };
11669 MockRead data_reads[] = { 11665 MockRead data_reads[] = {
11670 MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), 11666 MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET),
11671 }; 11667 };
11672 11668
(...skipping 15 matching lines...) Expand all
11688 EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); 11684 EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers));
11689 EXPECT_TRUE(request_headers.HasHeader("Host")); 11685 EXPECT_TRUE(request_headers.HasHeader("Host"));
11690 } 11686 }
11691 11687
11692 TEST_P(HttpNetworkTransactionTest, HttpAsyncReadError) { 11688 TEST_P(HttpNetworkTransactionTest, HttpAsyncReadError) {
11693 HttpRequestInfo request; 11689 HttpRequestInfo request;
11694 request.method = "GET"; 11690 request.method = "GET";
11695 request.url = GURL("http://www.google.com/"); 11691 request.url = GURL("http://www.google.com/");
11696 request.load_flags = 0; 11692 request.load_flags = 0;
11697 11693
11694 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
11698 scoped_ptr<HttpTransaction> trans( 11695 scoped_ptr<HttpTransaction> trans(
11699 new HttpNetworkTransaction(DEFAULT_PRIORITY, 11696 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
11700 CreateSession(&session_deps_)));
11701 11697
11702 MockWrite data_writes[] = { 11698 MockWrite data_writes[] = {
11703 MockWrite("GET / HTTP/1.1\r\n" 11699 MockWrite("GET / HTTP/1.1\r\n"
11704 "Host: www.google.com\r\n" 11700 "Host: www.google.com\r\n"
11705 "Connection: keep-alive\r\n\r\n"), 11701 "Connection: keep-alive\r\n\r\n"),
11706 }; 11702 };
11707 MockRead data_reads[] = { 11703 MockRead data_reads[] = {
11708 MockRead(ASYNC, ERR_CONNECTION_RESET), 11704 MockRead(ASYNC, ERR_CONNECTION_RESET),
11709 }; 11705 };
11710 11706
(...skipping 16 matching lines...) Expand all
11727 EXPECT_TRUE(request_headers.HasHeader("Host")); 11723 EXPECT_TRUE(request_headers.HasHeader("Host"));
11728 } 11724 }
11729 11725
11730 TEST_P(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { 11726 TEST_P(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) {
11731 HttpRequestInfo request; 11727 HttpRequestInfo request;
11732 request.method = "GET"; 11728 request.method = "GET";
11733 request.url = GURL("http://www.google.com/"); 11729 request.url = GURL("http://www.google.com/");
11734 request.load_flags = 0; 11730 request.load_flags = 0;
11735 request.extra_headers.SetHeader("X-Foo", "bar"); 11731 request.extra_headers.SetHeader("X-Foo", "bar");
11736 11732
11733 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
11737 scoped_ptr<HttpTransaction> trans( 11734 scoped_ptr<HttpTransaction> trans(
11738 new HttpNetworkTransaction(DEFAULT_PRIORITY, 11735 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
11739 CreateSession(&session_deps_)));
11740 11736
11741 MockWrite data_writes[] = { 11737 MockWrite data_writes[] = {
11742 MockWrite("GET / HTTP/1.1\r\n" 11738 MockWrite("GET / HTTP/1.1\r\n"
11743 "Host: www.google.com\r\n" 11739 "Host: www.google.com\r\n"
11744 "Connection: keep-alive\r\n" 11740 "Connection: keep-alive\r\n"
11745 "X-Foo: bar\r\n\r\n"), 11741 "X-Foo: bar\r\n\r\n"),
11746 }; 11742 };
11747 MockRead data_reads[] = { 11743 MockRead data_reads[] = {
11748 MockRead("HTTP/1.1 200 OK\r\n" 11744 MockRead("HTTP/1.1 200 OK\r\n"
11749 "Content-Length: 5\r\n\r\n" 11745 "Content-Length: 5\r\n\r\n"
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
12223 // established, to let the HTTP request start. 12219 // established, to let the HTTP request start.
12224 ASSERT_EQ(OK, http_callback.WaitForResult()); 12220 ASSERT_EQ(OK, http_callback.WaitForResult());
12225 std::string response_data; 12221 std::string response_data;
12226 ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); 12222 ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data));
12227 EXPECT_EQ("falafel", response_data); 12223 EXPECT_EQ("falafel", response_data);
12228 12224
12229 EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session)); 12225 EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session));
12230 } 12226 }
12231 12227
12232 } // namespace net 12228 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_network_transaction.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698