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

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

Issue 13701: Use automatic memory management for URLRequestContext's members.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years 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_session.h ('k') | net/http/http_transaction_winhttp.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <math.h> // ceil 5 #include <math.h> // ceil
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "net/base/client_socket_factory.h" 8 #include "net/base/client_socket_factory.h"
9 #include "net/base/test_completion_callback.h" 9 #include "net/base/test_completion_callback.h"
10 #include "net/base/upload_data.h" 10 #include "net/base/upload_data.h"
11 #include "net/http/http_network_session.h" 11 #include "net/http/http_network_session.h"
12 #include "net/http/http_network_transaction.h" 12 #include "net/http/http_network_transaction.h"
13 #include "net/http/http_transaction_unittest.h" 13 #include "net/http/http_transaction_unittest.h"
14 #include "net/proxy/proxy_resolver_fixed.h" 14 #include "net/proxy/proxy_resolver_fixed.h"
15 #include "net/proxy/proxy_resolver_null.h"
16 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
17 #include "testing/platform_test.h" 16 #include "testing/platform_test.h"
18 17
19 //----------------------------------------------------------------------------- 18 //-----------------------------------------------------------------------------
20 19
21 20
22 struct MockConnect { 21 struct MockConnect {
23 // Asynchronous connection success. 22 // Asynchronous connection success.
24 MockConnect() : async(true), result(net::OK) { } 23 MockConnect() : async(true), result(net::OK) { }
25 24
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 virtual net::SSLClientSocket* CreateSSLClientSocket( 192 virtual net::SSLClientSocket* CreateSSLClientSocket(
194 net::ClientSocket* transport_socket, 193 net::ClientSocket* transport_socket,
195 const std::string& hostname, 194 const std::string& hostname,
196 const net::SSLConfig& ssl_config) { 195 const net::SSLConfig& ssl_config) {
197 return NULL; 196 return NULL;
198 } 197 }
199 }; 198 };
200 199
201 MockClientSocketFactory mock_socket_factory; 200 MockClientSocketFactory mock_socket_factory;
202 201
203 // Create a proxy service which fails on all requests (falls back to direct). 202 net::HttpNetworkSession* CreateSessionWithProxy(const std::string& proxy) {
204 net::ProxyService* CreateNullProxyService() { 203 net::ProxyInfo proxy_info;
205 return new net::ProxyService(new net::ProxyResolverNull); 204 proxy_info.UseNamedProxy(proxy);
205 return new net::HttpNetworkSession(
206 new net::ProxyService(new net::ProxyResolverFixed(proxy_info)));
206 } 207 }
207 208
208 net::HttpNetworkSession* CreateSession(net::ProxyService* proxy_service) { 209 net::HttpNetworkSession* CreateSession() {
209 return new net::HttpNetworkSession(proxy_service); 210 return new net::HttpNetworkSession(net::ProxyService::CreateNull());
210 } 211 }
211 212
212 class HttpNetworkTransactionTest : public PlatformTest { 213 class HttpNetworkTransactionTest : public PlatformTest {
213 public: 214 public:
214 virtual void SetUp() { 215 virtual void SetUp() {
215 PlatformTest::SetUp(); 216 PlatformTest::SetUp();
216 mock_sockets[0] = NULL; 217 mock_sockets[0] = NULL;
217 mock_sockets_index = 0; 218 mock_sockets_index = 0;
218 } 219 }
219 220
220 virtual void TearDown() { 221 virtual void TearDown() {
221 // Empty the current queue. 222 // Empty the current queue.
222 MessageLoop::current()->RunAllPending(); 223 MessageLoop::current()->RunAllPending();
223 PlatformTest::TearDown(); 224 PlatformTest::TearDown();
224 } 225 }
225 226
226 protected: 227 protected:
227 void KeepAliveConnectionResendRequestTest(const MockRead& read_failure); 228 void KeepAliveConnectionResendRequestTest(const MockRead& read_failure);
228 }; 229 };
229 230
230 struct SimpleGetHelperResult { 231 struct SimpleGetHelperResult {
231 int rv; 232 int rv;
232 std::string status_line; 233 std::string status_line;
233 std::string response_data; 234 std::string response_data;
234 }; 235 };
235 236
236 SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[]) { 237 SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[]) {
237 SimpleGetHelperResult out; 238 SimpleGetHelperResult out;
238 239
239 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService());
240 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( 240 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction(
241 CreateSession(proxy_service.get()), &mock_socket_factory)); 241 CreateSession(), &mock_socket_factory));
242 242
243 net::HttpRequestInfo request; 243 net::HttpRequestInfo request;
244 request.method = "GET"; 244 request.method = "GET";
245 request.url = GURL("http://www.google.com/"); 245 request.url = GURL("http://www.google.com/");
246 request.load_flags = 0; 246 request.load_flags = 0;
247 247
248 MockSocket data; 248 MockSocket data;
249 data.reads = data_reads; 249 data.reads = data_reads;
250 mock_sockets[0] = &data; 250 mock_sockets[0] = &data;
251 mock_sockets[1] = NULL; 251 mock_sockets[1] = NULL;
(...skipping 30 matching lines...) Expand all
282 DCHECK(sizeof_data >= size); 282 DCHECK(sizeof_data >= size);
283 str->reserve(sizeof_data); 283 str->reserve(sizeof_data);
284 284
285 for (int i = 0; i < num_rows; ++i) 285 for (int i = 0; i < num_rows; ++i)
286 str->append(row, sizeof_row); 286 str->append(row, sizeof_row);
287 } 287 }
288 288
289 //----------------------------------------------------------------------------- 289 //-----------------------------------------------------------------------------
290 290
291 TEST_F(HttpNetworkTransactionTest, Basic) { 291 TEST_F(HttpNetworkTransactionTest, Basic) {
292 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService());
293 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( 292 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction(
294 CreateSession(proxy_service.get()), &mock_socket_factory)); 293 CreateSession(), &mock_socket_factory));
295 } 294 }
296 295
297 TEST_F(HttpNetworkTransactionTest, SimpleGET) { 296 TEST_F(HttpNetworkTransactionTest, SimpleGET) {
298 MockRead data_reads[] = { 297 MockRead data_reads[] = {
299 MockRead("HTTP/1.0 200 OK\r\n\r\n"), 298 MockRead("HTTP/1.0 200 OK\r\n\r\n"),
300 MockRead("hello world"), 299 MockRead("hello world"),
301 MockRead(false, net::OK), 300 MockRead(false, net::OK),
302 }; 301 };
303 SimpleGetHelperResult out = SimpleGetHelper(data_reads); 302 SimpleGetHelperResult out = SimpleGetHelper(data_reads);
304 EXPECT_EQ(net::OK, out.rv); 303 EXPECT_EQ(net::OK, out.rv);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 MockRead("junk"), // Should not be read!! 390 MockRead("junk"), // Should not be read!!
392 MockRead(false, net::OK), 391 MockRead(false, net::OK),
393 }; 392 };
394 SimpleGetHelperResult out = SimpleGetHelper(data_reads); 393 SimpleGetHelperResult out = SimpleGetHelper(data_reads);
395 EXPECT_EQ(net::OK, out.rv); 394 EXPECT_EQ(net::OK, out.rv);
396 EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); 395 EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line);
397 EXPECT_EQ("", out.response_data); 396 EXPECT_EQ("", out.response_data);
398 } 397 }
399 398
400 TEST_F(HttpNetworkTransactionTest, ReuseConnection) { 399 TEST_F(HttpNetworkTransactionTest, ReuseConnection) {
401 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService()); 400 scoped_refptr<net::HttpNetworkSession> session = CreateSession();
402 scoped_refptr<net::HttpNetworkSession> session =
403 CreateSession(proxy_service.get());
404 401
405 MockRead data_reads[] = { 402 MockRead data_reads[] = {
406 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), 403 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"),
407 MockRead("hello"), 404 MockRead("hello"),
408 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), 405 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"),
409 MockRead("world"), 406 MockRead("world"),
410 MockRead(false, net::OK), 407 MockRead(false, net::OK),
411 }; 408 };
412 MockSocket data; 409 MockSocket data;
413 data.reads = data_reads; 410 data.reads = data_reads;
(...skipping 28 matching lines...) Expand all
442 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 439 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
443 440
444 std::string response_data; 441 std::string response_data;
445 rv = ReadTransaction(trans.get(), &response_data); 442 rv = ReadTransaction(trans.get(), &response_data);
446 EXPECT_EQ(net::OK, rv); 443 EXPECT_EQ(net::OK, rv);
447 EXPECT_EQ(kExpectedResponseData[i], response_data); 444 EXPECT_EQ(kExpectedResponseData[i], response_data);
448 } 445 }
449 } 446 }
450 447
451 TEST_F(HttpNetworkTransactionTest, Ignores100) { 448 TEST_F(HttpNetworkTransactionTest, Ignores100) {
452 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService());
453 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( 449 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction(
454 CreateSession(proxy_service.get()), &mock_socket_factory)); 450 CreateSession(), &mock_socket_factory));
455 451
456 net::HttpRequestInfo request; 452 net::HttpRequestInfo request;
457 request.method = "POST"; 453 request.method = "POST";
458 request.url = GURL("http://www.foo.com/"); 454 request.url = GURL("http://www.foo.com/");
459 request.upload_data = new net::UploadData; 455 request.upload_data = new net::UploadData;
460 request.upload_data->AppendBytes("foo", 3); 456 request.upload_data->AppendBytes("foo", 3);
461 request.load_flags = 0; 457 request.load_flags = 0;
462 458
463 MockRead data_reads[] = { 459 MockRead data_reads[] = {
464 MockRead("HTTP/1.0 100 Continue\r\n\r\n"), 460 MockRead("HTTP/1.0 100 Continue\r\n\r\n"),
(...skipping 23 matching lines...) Expand all
488 std::string response_data; 484 std::string response_data;
489 rv = ReadTransaction(trans.get(), &response_data); 485 rv = ReadTransaction(trans.get(), &response_data);
490 EXPECT_EQ(net::OK, rv); 486 EXPECT_EQ(net::OK, rv);
491 EXPECT_EQ("hello world", response_data); 487 EXPECT_EQ("hello world", response_data);
492 } 488 }
493 489
494 // read_failure specifies a read failure that should cause the network 490 // read_failure specifies a read failure that should cause the network
495 // transaction to resend the request. 491 // transaction to resend the request.
496 void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( 492 void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest(
497 const MockRead& read_failure) { 493 const MockRead& read_failure) {
498 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService()); 494 scoped_refptr<net::HttpNetworkSession> session = CreateSession();
499 scoped_refptr<net::HttpNetworkSession> session =
500 CreateSession(proxy_service.get());
501 495
502 net::HttpRequestInfo request; 496 net::HttpRequestInfo request;
503 request.method = "GET"; 497 request.method = "GET";
504 request.url = GURL("http://www.foo.com/"); 498 request.url = GURL("http://www.foo.com/");
505 request.load_flags = 0; 499 request.load_flags = 0;
506 500
507 MockRead data1_reads[] = { 501 MockRead data1_reads[] = {
508 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), 502 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"),
509 MockRead("hello"), 503 MockRead("hello"),
510 read_failure, // Now, we reuse the connection and fail the first read. 504 read_failure, // Now, we reuse the connection and fail the first read.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 MockRead read_failure(true, net::ERR_CONNECTION_RESET); 549 MockRead read_failure(true, net::ERR_CONNECTION_RESET);
556 KeepAliveConnectionResendRequestTest(read_failure); 550 KeepAliveConnectionResendRequestTest(read_failure);
557 } 551 }
558 552
559 TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { 553 TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) {
560 MockRead read_failure(false, net::OK); // EOF 554 MockRead read_failure(false, net::OK); // EOF
561 KeepAliveConnectionResendRequestTest(read_failure); 555 KeepAliveConnectionResendRequestTest(read_failure);
562 } 556 }
563 557
564 TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { 558 TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) {
565 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService());
566 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( 559 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction(
567 CreateSession(proxy_service.get()), &mock_socket_factory)); 560 CreateSession(), &mock_socket_factory));
568 561
569 net::HttpRequestInfo request; 562 net::HttpRequestInfo request;
570 request.method = "GET"; 563 request.method = "GET";
571 request.url = GURL("http://www.google.com/"); 564 request.url = GURL("http://www.google.com/");
572 request.load_flags = 0; 565 request.load_flags = 0;
573 566
574 MockRead data_reads[] = { 567 MockRead data_reads[] = {
575 MockRead(true, net::ERR_CONNECTION_RESET), 568 MockRead(true, net::ERR_CONNECTION_RESET),
576 MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used 569 MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used
577 MockRead("hello world"), 570 MockRead("hello world"),
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 MockRead("hello world"), 603 MockRead("hello world"),
611 MockRead(false, net::OK), 604 MockRead(false, net::OK),
612 }; 605 };
613 SimpleGetHelperResult out = SimpleGetHelper(data_reads); 606 SimpleGetHelperResult out = SimpleGetHelper(data_reads);
614 EXPECT_EQ(net::ERR_EMPTY_RESPONSE, out.rv); 607 EXPECT_EQ(net::ERR_EMPTY_RESPONSE, out.rv);
615 } 608 }
616 609
617 // Test the request-challenge-retry sequence for basic auth. 610 // Test the request-challenge-retry sequence for basic auth.
618 // (basic auth is the easiest to mock, because it has no randomness). 611 // (basic auth is the easiest to mock, because it has no randomness).
619 TEST_F(HttpNetworkTransactionTest, BasicAuth) { 612 TEST_F(HttpNetworkTransactionTest, BasicAuth) {
620 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService());
621 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( 613 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction(
622 CreateSession(proxy_service.get()), &mock_socket_factory)); 614 CreateSession(), &mock_socket_factory));
623 615
624 net::HttpRequestInfo request; 616 net::HttpRequestInfo request;
625 request.method = "GET"; 617 request.method = "GET";
626 request.url = GURL("http://www.google.com/"); 618 request.url = GURL("http://www.google.com/");
627 request.load_flags = 0; 619 request.load_flags = 0;
628 620
629 MockWrite data_writes1[] = { 621 MockWrite data_writes1[] = {
630 MockWrite("GET / HTTP/1.1\r\n" 622 MockWrite("GET / HTTP/1.1\r\n"
631 "Host: www.google.com\r\n" 623 "Host: www.google.com\r\n"
632 "Connection: keep-alive\r\n\r\n"), 624 "Connection: keep-alive\r\n\r\n"),
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 response = trans->GetResponseInfo(); 694 response = trans->GetResponseInfo();
703 EXPECT_FALSE(response == NULL); 695 EXPECT_FALSE(response == NULL);
704 EXPECT_TRUE(response->auth_challenge.get() == NULL); 696 EXPECT_TRUE(response->auth_challenge.get() == NULL);
705 EXPECT_EQ(100, response->headers->GetContentLength()); 697 EXPECT_EQ(100, response->headers->GetContentLength());
706 } 698 }
707 699
708 // Test the flow when both the proxy server AND origin server require 700 // Test the flow when both the proxy server AND origin server require
709 // authentication. Again, this uses basic auth for both since that is 701 // authentication. Again, this uses basic auth for both since that is
710 // the simplest to mock. 702 // the simplest to mock.
711 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { 703 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) {
712 net::ProxyInfo proxy_info;
713 proxy_info.UseNamedProxy("myproxy:70");
714 net::ProxyService proxy_service(new net::ProxyResolverFixed(proxy_info));
715
716 // Configure against proxy server "myproxy:70". 704 // Configure against proxy server "myproxy:70".
717 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( 705 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction(
718 CreateSession(&proxy_service), 706 CreateSessionWithProxy("myproxy:70"), &mock_socket_factory));
719 &mock_socket_factory));
720 707
721 net::HttpRequestInfo request; 708 net::HttpRequestInfo request;
722 request.method = "GET"; 709 request.method = "GET";
723 request.url = GURL("http://www.google.com/"); 710 request.url = GURL("http://www.google.com/");
724 request.load_flags = 0; 711 request.load_flags = 0;
725 712
726 MockWrite data_writes1[] = { 713 MockWrite data_writes1[] = {
727 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" 714 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
728 "Host: www.google.com\r\n" 715 "Host: www.google.com\r\n"
729 "Proxy-Connection: keep-alive\r\n\r\n"), 716 "Proxy-Connection: keep-alive\r\n\r\n"),
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 828
842 response = trans->GetResponseInfo(); 829 response = trans->GetResponseInfo();
843 EXPECT_TRUE(response->auth_challenge.get() == NULL); 830 EXPECT_TRUE(response->auth_challenge.get() == NULL);
844 EXPECT_EQ(100, response->headers->GetContentLength()); 831 EXPECT_EQ(100, response->headers->GetContentLength());
845 } 832 }
846 833
847 // Test reading a server response which has only headers, and no body. 834 // Test reading a server response which has only headers, and no body.
848 // After some maximum number of bytes is consumed, the transaction should 835 // After some maximum number of bytes is consumed, the transaction should
849 // fail with ERR_RESPONSE_HEADERS_TOO_BIG. 836 // fail with ERR_RESPONSE_HEADERS_TOO_BIG.
850 TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { 837 TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) {
851 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService());
852 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( 838 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction(
853 CreateSession(proxy_service.get()), &mock_socket_factory)); 839 CreateSession(), &mock_socket_factory));
854 840
855 net::HttpRequestInfo request; 841 net::HttpRequestInfo request;
856 request.method = "GET"; 842 request.method = "GET";
857 request.url = GURL("http://www.google.com/"); 843 request.url = GURL("http://www.google.com/");
858 request.load_flags = 0; 844 request.load_flags = 0;
859 845
860 // Respond with 50 kb of headers (we should fail after 32 kb). 846 // Respond with 50 kb of headers (we should fail after 32 kb).
861 std::string large_headers_string; 847 std::string large_headers_string;
862 FillLargeHeadersString(&large_headers_string, 50 * 1024); 848 FillLargeHeadersString(&large_headers_string, 50 * 1024);
863 849
(...skipping 18 matching lines...) Expand all
882 868
883 const net::HttpResponseInfo* response = trans->GetResponseInfo(); 869 const net::HttpResponseInfo* response = trans->GetResponseInfo();
884 EXPECT_TRUE(response == NULL); 870 EXPECT_TRUE(response == NULL);
885 } 871 }
886 872
887 // Make sure that we don't try to reuse a TCPClientSocket when failing to 873 // Make sure that we don't try to reuse a TCPClientSocket when failing to
888 // establish tunnel. 874 // establish tunnel.
889 // http://code.google.com/p/chromium/issues/detail?id=3772 875 // http://code.google.com/p/chromium/issues/detail?id=3772
890 TEST_F(HttpNetworkTransactionTest, DontRecycleTCPSocketForSSLTunnel) { 876 TEST_F(HttpNetworkTransactionTest, DontRecycleTCPSocketForSSLTunnel) {
891 // Configure against proxy server "myproxy:70". 877 // Configure against proxy server "myproxy:70".
892 net::ProxyInfo proxy_info;
893 proxy_info.UseNamedProxy("myproxy:70");
894 net::ProxyService proxy_service(new net::ProxyResolverFixed(proxy_info));
895
896 scoped_refptr<net::HttpNetworkSession> session( 878 scoped_refptr<net::HttpNetworkSession> session(
897 CreateSession(&proxy_service)); 879 CreateSessionWithProxy("myproxy:70"));
898 880
899 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( 881 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction(
900 session.get(), &mock_socket_factory)); 882 session.get(), &mock_socket_factory));
901 883
902 net::HttpRequestInfo request; 884 net::HttpRequestInfo request;
903 request.method = "GET"; 885 request.method = "GET";
904 request.url = GURL("https://www.google.com/"); 886 request.url = GURL("https://www.google.com/");
905 request.load_flags = 0; 887 request.load_flags = 0;
906 888
907 // Since we have proxy, should try to establish tunnel. 889 // Since we have proxy, should try to establish tunnel.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 // Transaction 2: a POST request. Reuses the socket kept alive from 946 // Transaction 2: a POST request. Reuses the socket kept alive from
965 // transaction 1. The first attempts fails when writing the POST data. 947 // transaction 1. The first attempts fails when writing the POST data.
966 // This causes the transaction to retry with a new socket. The second 948 // This causes the transaction to retry with a new socket. The second
967 // attempt succeeds. 949 // attempt succeeds.
968 request[1].method = "POST"; 950 request[1].method = "POST";
969 request[1].url = GURL("http://www.google.com/login.cgi"); 951 request[1].url = GURL("http://www.google.com/login.cgi");
970 request[1].upload_data = new net::UploadData; 952 request[1].upload_data = new net::UploadData;
971 request[1].upload_data->AppendBytes("foo", 3); 953 request[1].upload_data->AppendBytes("foo", 3);
972 request[1].load_flags = 0; 954 request[1].load_flags = 0;
973 955
974 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService()); 956 scoped_refptr<net::HttpNetworkSession> session = CreateSession();
975 scoped_refptr<net::HttpNetworkSession> session =
976 CreateSession(proxy_service.get());
977 957
978 // The first socket is used for transaction 1 and the first attempt of 958 // The first socket is used for transaction 1 and the first attempt of
979 // transaction 2. 959 // transaction 2.
980 960
981 // The response of transaction 1. 961 // The response of transaction 1.
982 MockRead data_reads1[] = { 962 MockRead data_reads1[] = {
983 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), 963 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"),
984 MockRead("hello world"), 964 MockRead("hello world"),
985 MockRead(false, net::OK), 965 MockRead(false, net::OK),
986 }; 966 };
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 rv = ReadTransaction(trans.get(), &response_data); 1022 rv = ReadTransaction(trans.get(), &response_data);
1043 EXPECT_EQ(net::OK, rv); 1023 EXPECT_EQ(net::OK, rv);
1044 EXPECT_EQ(kExpectedResponseData[i], response_data); 1024 EXPECT_EQ(kExpectedResponseData[i], response_data);
1045 } 1025 }
1046 } 1026 }
1047 1027
1048 // Test the request-challenge-retry sequence for basic auth when there is 1028 // Test the request-challenge-retry sequence for basic auth when there is
1049 // an identity in the URL. The request should be sent as normal, but when 1029 // an identity in the URL. The request should be sent as normal, but when
1050 // it fails the identity from the URL is used to answer the challenge. 1030 // it fails the identity from the URL is used to answer the challenge.
1051 TEST_F(HttpNetworkTransactionTest, AuthIdentityInUrl) { 1031 TEST_F(HttpNetworkTransactionTest, AuthIdentityInUrl) {
1052 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService());
1053 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( 1032 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction(
1054 CreateSession(proxy_service.get()), &mock_socket_factory)); 1033 CreateSession(), &mock_socket_factory));
1055 1034
1056 net::HttpRequestInfo request; 1035 net::HttpRequestInfo request;
1057 request.method = "GET"; 1036 request.method = "GET";
1058 // Note: the URL has a username:password in it. 1037 // Note: the URL has a username:password in it.
1059 request.url = GURL("http://foo:bar@www.google.com/"); 1038 request.url = GURL("http://foo:bar@www.google.com/");
1060 request.load_flags = 0; 1039 request.load_flags = 0;
1061 1040
1062 MockWrite data_writes1[] = { 1041 MockWrite data_writes1[] = {
1063 MockWrite("GET / HTTP/1.1\r\n" 1042 MockWrite("GET / HTTP/1.1\r\n"
1064 "Host: www.google.com\r\n" 1043 "Host: www.google.com\r\n"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 EXPECT_TRUE(response->auth_challenge.get() == NULL); 1091 EXPECT_TRUE(response->auth_challenge.get() == NULL);
1113 1092
1114 EXPECT_EQ(100, response->headers->GetContentLength()); 1093 EXPECT_EQ(100, response->headers->GetContentLength());
1115 1094
1116 // Empty the current queue. 1095 // Empty the current queue.
1117 MessageLoop::current()->RunAllPending(); 1096 MessageLoop::current()->RunAllPending();
1118 } 1097 }
1119 1098
1120 // Test that previously tried username/passwords for a realm get re-used. 1099 // Test that previously tried username/passwords for a realm get re-used.
1121 TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { 1100 TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) {
1122 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService()); 1101 scoped_refptr<net::HttpNetworkSession> session = CreateSession();
1123 scoped_refptr<net::HttpNetworkSession> session =
1124 CreateSession(proxy_service.get());
1125 1102
1126 // Transaction 1: authenticate (foo, bar) on MyRealm1 1103 // Transaction 1: authenticate (foo, bar) on MyRealm1
1127 { 1104 {
1128 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( 1105 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction(
1129 session, &mock_socket_factory)); 1106 session, &mock_socket_factory));
1130 1107
1131 net::HttpRequestInfo request; 1108 net::HttpRequestInfo request;
1132 request.method = "GET"; 1109 request.method = "GET";
1133 request.url = GURL("http://www.google.com/x/y/z"); 1110 request.url = GURL("http://www.google.com/x/y/z");
1134 request.load_flags = 0; 1111 request.load_flags = 0;
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
1514 1491
1515 rv = callback2.WaitForResult(); 1492 rv = callback2.WaitForResult();
1516 EXPECT_EQ(net::OK, rv); 1493 EXPECT_EQ(net::OK, rv);
1517 1494
1518 response = trans->GetResponseInfo(); 1495 response = trans->GetResponseInfo();
1519 EXPECT_FALSE(response == NULL); 1496 EXPECT_FALSE(response == NULL);
1520 EXPECT_TRUE(response->auth_challenge.get() == NULL); 1497 EXPECT_TRUE(response->auth_challenge.get() == NULL);
1521 EXPECT_EQ(100, response->headers->GetContentLength()); 1498 EXPECT_EQ(100, response->headers->GetContentLength());
1522 } 1499 }
1523 } 1500 }
OLDNEW
« no previous file with comments | « net/http/http_network_session.h ('k') | net/http/http_transaction_winhttp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698