OLD | NEW |
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/completion_callback.h" | 9 #include "net/base/completion_callback.h" |
10 #include "net/base/ssl_client_socket.h" | 10 #include "net/base/ssl_client_socket.h" |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 return ProxyService::CreateNull(); | 344 return ProxyService::CreateNull(); |
345 } | 345 } |
346 | 346 |
347 ProxyService* CreateFixedProxyService(const std::string& proxy) { | 347 ProxyService* CreateFixedProxyService(const std::string& proxy) { |
348 net::ProxyConfig proxy_config; | 348 net::ProxyConfig proxy_config; |
349 proxy_config.proxy_rules.ParseFromString(proxy); | 349 proxy_config.proxy_rules.ParseFromString(proxy); |
350 return ProxyService::Create(&proxy_config); | 350 return ProxyService::Create(&proxy_config); |
351 } | 351 } |
352 | 352 |
353 | 353 |
354 HttpNetworkSession* CreateSession(ProxyService* proxy_service, | 354 HttpNetworkSession* CreateSession(ProxyService* proxy_service) { |
355 ClientSocketFactory* client_socket_factory) { | 355 return new HttpNetworkSession(proxy_service); |
356 return new HttpNetworkSession(proxy_service, client_socket_factory); | |
357 } | 356 } |
358 | 357 |
359 class HttpNetworkTransactionTest : public PlatformTest { | 358 class HttpNetworkTransactionTest : public PlatformTest { |
360 public: | 359 public: |
361 virtual void SetUp() { | 360 virtual void SetUp() { |
362 PlatformTest::SetUp(); | 361 PlatformTest::SetUp(); |
363 mock_sockets[0] = NULL; | 362 mock_sockets[0] = NULL; |
364 mock_sockets_index = 0; | 363 mock_sockets_index = 0; |
365 mock_ssl_sockets_index = 0; | 364 mock_ssl_sockets_index = 0; |
366 } | 365 } |
(...skipping 11 matching lines...) Expand all Loading... |
378 struct SimpleGetHelperResult { | 377 struct SimpleGetHelperResult { |
379 int rv; | 378 int rv; |
380 std::string status_line; | 379 std::string status_line; |
381 std::string response_data; | 380 std::string response_data; |
382 }; | 381 }; |
383 | 382 |
384 SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[]) { | 383 SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[]) { |
385 SimpleGetHelperResult out; | 384 SimpleGetHelperResult out; |
386 | 385 |
387 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 386 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
388 scoped_ptr<HttpTransaction> trans( | 387 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
389 new HttpNetworkTransaction( | 388 CreateSession(proxy_service.get()), &mock_socket_factory)); |
390 CreateSession(proxy_service.get(), &mock_socket_factory), | |
391 &mock_socket_factory)); | |
392 | 389 |
393 HttpRequestInfo request; | 390 HttpRequestInfo request; |
394 request.method = "GET"; | 391 request.method = "GET"; |
395 request.url = GURL("http://www.google.com/"); | 392 request.url = GURL("http://www.google.com/"); |
396 request.load_flags = 0; | 393 request.load_flags = 0; |
397 | 394 |
398 MockSocket data; | 395 MockSocket data; |
399 data.reads = data_reads; | 396 data.reads = data_reads; |
400 mock_sockets[0] = &data; | 397 mock_sockets[0] = &data; |
401 mock_sockets[1] = NULL; | 398 mock_sockets[1] = NULL; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 } | 459 } |
463 | 460 |
464 std::string MockGetHostName() { | 461 std::string MockGetHostName() { |
465 return "WTC-WIN7"; | 462 return "WTC-WIN7"; |
466 } | 463 } |
467 | 464 |
468 //----------------------------------------------------------------------------- | 465 //----------------------------------------------------------------------------- |
469 | 466 |
470 TEST_F(HttpNetworkTransactionTest, Basic) { | 467 TEST_F(HttpNetworkTransactionTest, Basic) { |
471 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 468 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
472 scoped_ptr<HttpTransaction> trans( | 469 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
473 new HttpNetworkTransaction( | 470 CreateSession(proxy_service.get()), &mock_socket_factory)); |
474 CreateSession(proxy_service.get(), &mock_socket_factory), | |
475 &mock_socket_factory)); | |
476 } | 471 } |
477 | 472 |
478 TEST_F(HttpNetworkTransactionTest, SimpleGET) { | 473 TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
479 MockRead data_reads[] = { | 474 MockRead data_reads[] = { |
480 MockRead("HTTP/1.0 200 OK\r\n\r\n"), | 475 MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
481 MockRead("hello world"), | 476 MockRead("hello world"), |
482 MockRead(false, OK), | 477 MockRead(false, OK), |
483 }; | 478 }; |
484 SimpleGetHelperResult out = SimpleGetHelper(data_reads); | 479 SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
485 EXPECT_EQ(OK, out.rv); | 480 EXPECT_EQ(OK, out.rv); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 SimpleGetHelperResult out = SimpleGetHelper(data_reads); | 570 SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
576 EXPECT_EQ(OK, out.rv); | 571 EXPECT_EQ(OK, out.rv); |
577 EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); | 572 EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
578 EXPECT_EQ("", out.response_data); | 573 EXPECT_EQ("", out.response_data); |
579 } | 574 } |
580 | 575 |
581 // Do a request using the HEAD method. Verify that we don't try to read the | 576 // Do a request using the HEAD method. Verify that we don't try to read the |
582 // message body (since HEAD has none). | 577 // message body (since HEAD has none). |
583 TEST_F(HttpNetworkTransactionTest, Head) { | 578 TEST_F(HttpNetworkTransactionTest, Head) { |
584 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 579 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
585 scoped_ptr<HttpTransaction> trans( | 580 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
586 new HttpNetworkTransaction( | 581 CreateSession(proxy_service.get()), &mock_socket_factory)); |
587 CreateSession(proxy_service.get(), &mock_socket_factory), | |
588 &mock_socket_factory)); | |
589 | 582 |
590 HttpRequestInfo request; | 583 HttpRequestInfo request; |
591 request.method = "HEAD"; | 584 request.method = "HEAD"; |
592 request.url = GURL("http://www.google.com/"); | 585 request.url = GURL("http://www.google.com/"); |
593 request.load_flags = 0; | 586 request.load_flags = 0; |
594 | 587 |
595 MockWrite data_writes1[] = { | 588 MockWrite data_writes1[] = { |
596 MockWrite("HEAD / HTTP/1.1\r\n" | 589 MockWrite("HEAD / HTTP/1.1\r\n" |
597 "Host: www.google.com\r\n" | 590 "Host: www.google.com\r\n" |
598 "Connection: keep-alive\r\n" | 591 "Connection: keep-alive\r\n" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 // (despite non-zero content-length). | 633 // (despite non-zero content-length). |
641 std::string response_data; | 634 std::string response_data; |
642 rv = ReadTransaction(trans.get(), &response_data); | 635 rv = ReadTransaction(trans.get(), &response_data); |
643 EXPECT_EQ(OK, rv); | 636 EXPECT_EQ(OK, rv); |
644 EXPECT_EQ("", response_data); | 637 EXPECT_EQ("", response_data); |
645 } | 638 } |
646 | 639 |
647 TEST_F(HttpNetworkTransactionTest, ReuseConnection) { | 640 TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
648 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 641 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
649 scoped_refptr<HttpNetworkSession> session = | 642 scoped_refptr<HttpNetworkSession> session = |
650 CreateSession(proxy_service.get(), &mock_socket_factory); | 643 CreateSession(proxy_service.get()); |
651 | 644 |
652 MockRead data_reads[] = { | 645 MockRead data_reads[] = { |
653 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), | 646 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
654 MockRead("hello"), | 647 MockRead("hello"), |
655 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), | 648 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
656 MockRead("world"), | 649 MockRead("world"), |
657 MockRead(false, OK), | 650 MockRead(false, OK), |
658 }; | 651 }; |
659 MockSocket data; | 652 MockSocket data; |
660 data.reads = data_reads; | 653 data.reads = data_reads; |
(...skipping 29 matching lines...) Expand all Loading... |
690 | 683 |
691 std::string response_data; | 684 std::string response_data; |
692 rv = ReadTransaction(trans.get(), &response_data); | 685 rv = ReadTransaction(trans.get(), &response_data); |
693 EXPECT_EQ(OK, rv); | 686 EXPECT_EQ(OK, rv); |
694 EXPECT_EQ(kExpectedResponseData[i], response_data); | 687 EXPECT_EQ(kExpectedResponseData[i], response_data); |
695 } | 688 } |
696 } | 689 } |
697 | 690 |
698 TEST_F(HttpNetworkTransactionTest, Ignores100) { | 691 TEST_F(HttpNetworkTransactionTest, Ignores100) { |
699 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 692 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
700 scoped_ptr<HttpTransaction> trans( | 693 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
701 new HttpNetworkTransaction( | 694 CreateSession(proxy_service.get()), &mock_socket_factory)); |
702 CreateSession(proxy_service.get(), &mock_socket_factory), | |
703 &mock_socket_factory)); | |
704 | 695 |
705 HttpRequestInfo request; | 696 HttpRequestInfo request; |
706 request.method = "POST"; | 697 request.method = "POST"; |
707 request.url = GURL("http://www.foo.com/"); | 698 request.url = GURL("http://www.foo.com/"); |
708 request.upload_data = new UploadData; | 699 request.upload_data = new UploadData; |
709 request.upload_data->AppendBytes("foo", 3); | 700 request.upload_data->AppendBytes("foo", 3); |
710 request.load_flags = 0; | 701 request.load_flags = 0; |
711 | 702 |
712 MockRead data_reads[] = { | 703 MockRead data_reads[] = { |
713 MockRead("HTTP/1.0 100 Continue\r\n\r\n"), | 704 MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
(...skipping 24 matching lines...) Expand all Loading... |
738 rv = ReadTransaction(trans.get(), &response_data); | 729 rv = ReadTransaction(trans.get(), &response_data); |
739 EXPECT_EQ(OK, rv); | 730 EXPECT_EQ(OK, rv); |
740 EXPECT_EQ("hello world", response_data); | 731 EXPECT_EQ("hello world", response_data); |
741 } | 732 } |
742 | 733 |
743 // This test is almost the same as Ignores100 above, but the response contains | 734 // This test is almost the same as Ignores100 above, but the response contains |
744 // a 102 instead of a 100. Also, instead of HTTP/1.0 the response is | 735 // a 102 instead of a 100. Also, instead of HTTP/1.0 the response is |
745 // HTTP/1.1. | 736 // HTTP/1.1. |
746 TEST_F(HttpNetworkTransactionTest, Ignores1xx) { | 737 TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
747 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 738 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
748 scoped_ptr<HttpTransaction> trans( | 739 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
749 new HttpNetworkTransaction( | 740 CreateSession(proxy_service.get()), &mock_socket_factory)); |
750 CreateSession(proxy_service.get(), &mock_socket_factory), | |
751 &mock_socket_factory)); | |
752 | 741 |
753 HttpRequestInfo request; | 742 HttpRequestInfo request; |
754 request.method = "GET"; | 743 request.method = "GET"; |
755 request.url = GURL("http://www.foo.com/"); | 744 request.url = GURL("http://www.foo.com/"); |
756 request.load_flags = 0; | 745 request.load_flags = 0; |
757 | 746 |
758 MockRead data_reads[] = { | 747 MockRead data_reads[] = { |
759 MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n"), | 748 MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n"), |
760 MockRead("HTTP/1.1 200 OK\r\n\r\n"), | 749 MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
761 MockRead("hello world"), | 750 MockRead("hello world"), |
(...skipping 23 matching lines...) Expand all Loading... |
785 EXPECT_EQ(OK, rv); | 774 EXPECT_EQ(OK, rv); |
786 EXPECT_EQ("hello world", response_data); | 775 EXPECT_EQ("hello world", response_data); |
787 } | 776 } |
788 | 777 |
789 // read_failure specifies a read failure that should cause the network | 778 // read_failure specifies a read failure that should cause the network |
790 // transaction to resend the request. | 779 // transaction to resend the request. |
791 void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( | 780 void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
792 const MockRead& read_failure) { | 781 const MockRead& read_failure) { |
793 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 782 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
794 scoped_refptr<HttpNetworkSession> session = | 783 scoped_refptr<HttpNetworkSession> session = |
795 CreateSession(proxy_service.get(), &mock_socket_factory); | 784 CreateSession(proxy_service.get()); |
796 | 785 |
797 HttpRequestInfo request; | 786 HttpRequestInfo request; |
798 request.method = "GET"; | 787 request.method = "GET"; |
799 request.url = GURL("http://www.foo.com/"); | 788 request.url = GURL("http://www.foo.com/"); |
800 request.load_flags = 0; | 789 request.load_flags = 0; |
801 | 790 |
802 MockRead data1_reads[] = { | 791 MockRead data1_reads[] = { |
803 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), | 792 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
804 MockRead("hello"), | 793 MockRead("hello"), |
805 read_failure, // Now, we reuse the connection and fail the first read. | 794 read_failure, // Now, we reuse the connection and fail the first read. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 KeepAliveConnectionResendRequestTest(read_failure); | 840 KeepAliveConnectionResendRequestTest(read_failure); |
852 } | 841 } |
853 | 842 |
854 TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { | 843 TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
855 MockRead read_failure(false, OK); // EOF | 844 MockRead read_failure(false, OK); // EOF |
856 KeepAliveConnectionResendRequestTest(read_failure); | 845 KeepAliveConnectionResendRequestTest(read_failure); |
857 } | 846 } |
858 | 847 |
859 TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { | 848 TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
860 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 849 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
861 scoped_ptr<HttpTransaction> trans( | 850 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
862 new HttpNetworkTransaction( | 851 CreateSession(proxy_service.get()), &mock_socket_factory)); |
863 CreateSession(proxy_service.get(), &mock_socket_factory), | |
864 &mock_socket_factory)); | |
865 | 852 |
866 HttpRequestInfo request; | 853 HttpRequestInfo request; |
867 request.method = "GET"; | 854 request.method = "GET"; |
868 request.url = GURL("http://www.google.com/"); | 855 request.url = GURL("http://www.google.com/"); |
869 request.load_flags = 0; | 856 request.load_flags = 0; |
870 | 857 |
871 MockRead data_reads[] = { | 858 MockRead data_reads[] = { |
872 MockRead(true, ERR_CONNECTION_RESET), | 859 MockRead(true, ERR_CONNECTION_RESET), |
873 MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used | 860 MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
874 MockRead("hello world"), | 861 MockRead("hello world"), |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 MockRead(false, OK), | 895 MockRead(false, OK), |
909 }; | 896 }; |
910 SimpleGetHelperResult out = SimpleGetHelper(data_reads); | 897 SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
911 EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv); | 898 EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv); |
912 } | 899 } |
913 | 900 |
914 // Test the request-challenge-retry sequence for basic auth. | 901 // Test the request-challenge-retry sequence for basic auth. |
915 // (basic auth is the easiest to mock, because it has no randomness). | 902 // (basic auth is the easiest to mock, because it has no randomness). |
916 TEST_F(HttpNetworkTransactionTest, BasicAuth) { | 903 TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
917 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 904 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
918 scoped_ptr<HttpTransaction> trans( | 905 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
919 new HttpNetworkTransaction( | 906 CreateSession(proxy_service.get()), &mock_socket_factory)); |
920 CreateSession(proxy_service.get(), &mock_socket_factory), | |
921 &mock_socket_factory)); | |
922 | 907 |
923 HttpRequestInfo request; | 908 HttpRequestInfo request; |
924 request.method = "GET"; | 909 request.method = "GET"; |
925 request.url = GURL("http://www.google.com/"); | 910 request.url = GURL("http://www.google.com/"); |
926 request.load_flags = 0; | 911 request.load_flags = 0; |
927 | 912 |
928 MockWrite data_writes1[] = { | 913 MockWrite data_writes1[] = { |
929 MockWrite("GET / HTTP/1.1\r\n" | 914 MockWrite("GET / HTTP/1.1\r\n" |
930 "Host: www.google.com\r\n" | 915 "Host: www.google.com\r\n" |
931 "Connection: keep-alive\r\n\r\n"), | 916 "Connection: keep-alive\r\n\r\n"), |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1001 response = trans->GetResponseInfo(); | 986 response = trans->GetResponseInfo(); |
1002 EXPECT_FALSE(response == NULL); | 987 EXPECT_FALSE(response == NULL); |
1003 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 988 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
1004 EXPECT_EQ(100, response->headers->GetContentLength()); | 989 EXPECT_EQ(100, response->headers->GetContentLength()); |
1005 } | 990 } |
1006 | 991 |
1007 // Test the request-challenge-retry sequence for basic auth, over a keep-alive | 992 // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
1008 // connection. | 993 // connection. |
1009 TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { | 994 TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
1010 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 995 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
1011 scoped_ptr<HttpTransaction> trans( | 996 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
1012 new HttpNetworkTransaction( | 997 CreateSession(proxy_service.get()), &mock_socket_factory)); |
1013 CreateSession(proxy_service.get(), &mock_socket_factory), | |
1014 &mock_socket_factory)); | |
1015 | 998 |
1016 HttpRequestInfo request; | 999 HttpRequestInfo request; |
1017 request.method = "GET"; | 1000 request.method = "GET"; |
1018 request.url = GURL("http://www.google.com/"); | 1001 request.url = GURL("http://www.google.com/"); |
1019 request.load_flags = 0; | 1002 request.load_flags = 0; |
1020 | 1003 |
1021 MockWrite data_writes1[] = { | 1004 MockWrite data_writes1[] = { |
1022 MockWrite("GET / HTTP/1.1\r\n" | 1005 MockWrite("GET / HTTP/1.1\r\n" |
1023 "Host: www.google.com\r\n" | 1006 "Host: www.google.com\r\n" |
1024 "Connection: keep-alive\r\n\r\n"), | 1007 "Connection: keep-alive\r\n\r\n"), |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1081 response = trans->GetResponseInfo(); | 1064 response = trans->GetResponseInfo(); |
1082 EXPECT_FALSE(response == NULL); | 1065 EXPECT_FALSE(response == NULL); |
1083 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 1066 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
1084 EXPECT_EQ(100, response->headers->GetContentLength()); | 1067 EXPECT_EQ(100, response->headers->GetContentLength()); |
1085 } | 1068 } |
1086 | 1069 |
1087 // Test the request-challenge-retry sequence for basic auth, over a keep-alive | 1070 // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
1088 // connection and with no response body to drain. | 1071 // connection and with no response body to drain. |
1089 TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { | 1072 TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
1090 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 1073 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
1091 scoped_ptr<HttpTransaction> trans( | 1074 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
1092 new HttpNetworkTransaction( | 1075 CreateSession(proxy_service.get()), &mock_socket_factory)); |
1093 CreateSession(proxy_service.get(), &mock_socket_factory), | |
1094 &mock_socket_factory)); | |
1095 | 1076 |
1096 HttpRequestInfo request; | 1077 HttpRequestInfo request; |
1097 request.method = "GET"; | 1078 request.method = "GET"; |
1098 request.url = GURL("http://www.google.com/"); | 1079 request.url = GURL("http://www.google.com/"); |
1099 request.load_flags = 0; | 1080 request.load_flags = 0; |
1100 | 1081 |
1101 MockWrite data_writes1[] = { | 1082 MockWrite data_writes1[] = { |
1102 MockWrite("GET / HTTP/1.1\r\n" | 1083 MockWrite("GET / HTTP/1.1\r\n" |
1103 "Host: www.google.com\r\n" | 1084 "Host: www.google.com\r\n" |
1104 "Connection: keep-alive\r\n\r\n"), | 1085 "Connection: keep-alive\r\n\r\n"), |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1164 response = trans->GetResponseInfo(); | 1145 response = trans->GetResponseInfo(); |
1165 EXPECT_FALSE(response == NULL); | 1146 EXPECT_FALSE(response == NULL); |
1166 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 1147 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
1167 EXPECT_EQ(100, response->headers->GetContentLength()); | 1148 EXPECT_EQ(100, response->headers->GetContentLength()); |
1168 } | 1149 } |
1169 | 1150 |
1170 // Test the request-challenge-retry sequence for basic auth, over a keep-alive | 1151 // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
1171 // connection and with a large response body to drain. | 1152 // connection and with a large response body to drain. |
1172 TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { | 1153 TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
1173 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 1154 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
1174 scoped_ptr<HttpTransaction> trans( | 1155 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
1175 new HttpNetworkTransaction( | 1156 CreateSession(proxy_service.get()), &mock_socket_factory)); |
1176 CreateSession(proxy_service.get(), &mock_socket_factory), | |
1177 &mock_socket_factory)); | |
1178 | 1157 |
1179 HttpRequestInfo request; | 1158 HttpRequestInfo request; |
1180 request.method = "GET"; | 1159 request.method = "GET"; |
1181 request.url = GURL("http://www.google.com/"); | 1160 request.url = GURL("http://www.google.com/"); |
1182 request.load_flags = 0; | 1161 request.load_flags = 0; |
1183 | 1162 |
1184 MockWrite data_writes1[] = { | 1163 MockWrite data_writes1[] = { |
1185 MockWrite("GET / HTTP/1.1\r\n" | 1164 MockWrite("GET / HTTP/1.1\r\n" |
1186 "Host: www.google.com\r\n" | 1165 "Host: www.google.com\r\n" |
1187 "Connection: keep-alive\r\n\r\n"), | 1166 "Connection: keep-alive\r\n\r\n"), |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1254 } | 1233 } |
1255 | 1234 |
1256 // Test the request-challenge-retry sequence for basic auth, over a keep-alive | 1235 // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
1257 // proxy connection, when setting up an SSL tunnel. | 1236 // proxy connection, when setting up an SSL tunnel. |
1258 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAlive) { | 1237 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAlive) { |
1259 // Configure against proxy server "myproxy:70". | 1238 // Configure against proxy server "myproxy:70". |
1260 scoped_ptr<ProxyService> proxy_service( | 1239 scoped_ptr<ProxyService> proxy_service( |
1261 CreateFixedProxyService("myproxy:70")); | 1240 CreateFixedProxyService("myproxy:70")); |
1262 | 1241 |
1263 scoped_refptr<HttpNetworkSession> session( | 1242 scoped_refptr<HttpNetworkSession> session( |
1264 CreateSession(proxy_service.get(), &mock_socket_factory)); | 1243 CreateSession(proxy_service.get())); |
1265 | 1244 |
1266 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 1245 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
1267 session.get(), &mock_socket_factory)); | 1246 session.get(), &mock_socket_factory)); |
1268 | 1247 |
1269 HttpRequestInfo request; | 1248 HttpRequestInfo request; |
1270 request.method = "GET"; | 1249 request.method = "GET"; |
1271 request.url = GURL("https://www.google.com/"); | 1250 request.url = GURL("https://www.google.com/"); |
1272 request.load_flags = 0; | 1251 request.load_flags = 0; |
1273 | 1252 |
1274 // Since we have proxy, should try to establish tunnel. | 1253 // Since we have proxy, should try to establish tunnel. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1357 } | 1336 } |
1358 | 1337 |
1359 // Test that we don't read the response body when we fail to establish a tunnel, | 1338 // Test that we don't read the response body when we fail to establish a tunnel, |
1360 // even if the user cancels the proxy's auth attempt. | 1339 // even if the user cancels the proxy's auth attempt. |
1361 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { | 1340 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
1362 // Configure against proxy server "myproxy:70". | 1341 // Configure against proxy server "myproxy:70". |
1363 scoped_ptr<ProxyService> proxy_service( | 1342 scoped_ptr<ProxyService> proxy_service( |
1364 CreateFixedProxyService("myproxy:70")); | 1343 CreateFixedProxyService("myproxy:70")); |
1365 | 1344 |
1366 scoped_refptr<HttpNetworkSession> session( | 1345 scoped_refptr<HttpNetworkSession> session( |
1367 CreateSession(proxy_service.get(), &mock_socket_factory)); | 1346 CreateSession(proxy_service.get())); |
1368 | 1347 |
1369 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 1348 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
1370 session.get(), &mock_socket_factory)); | 1349 session.get(), &mock_socket_factory)); |
1371 | 1350 |
1372 HttpRequestInfo request; | 1351 HttpRequestInfo request; |
1373 request.method = "GET"; | 1352 request.method = "GET"; |
1374 request.url = GURL("https://www.google.com/"); | 1353 request.url = GURL("https://www.google.com/"); |
1375 request.load_flags = 0; | 1354 request.load_flags = 0; |
1376 | 1355 |
1377 // Since we have proxy, should try to establish tunnel. | 1356 // Since we have proxy, should try to establish tunnel. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1415 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); | 1394 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
1416 } | 1395 } |
1417 | 1396 |
1418 static void ConnectStatusHelperWithExpectedStatus( | 1397 static void ConnectStatusHelperWithExpectedStatus( |
1419 const MockRead& status, int expected_status) { | 1398 const MockRead& status, int expected_status) { |
1420 // Configure against proxy server "myproxy:70". | 1399 // Configure against proxy server "myproxy:70". |
1421 scoped_ptr<ProxyService> proxy_service( | 1400 scoped_ptr<ProxyService> proxy_service( |
1422 CreateFixedProxyService("myproxy:70")); | 1401 CreateFixedProxyService("myproxy:70")); |
1423 | 1402 |
1424 scoped_refptr<HttpNetworkSession> session( | 1403 scoped_refptr<HttpNetworkSession> session( |
1425 CreateSession(proxy_service.get(), &mock_socket_factory)); | 1404 CreateSession(proxy_service.get())); |
1426 | 1405 |
1427 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 1406 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
1428 session.get(), &mock_socket_factory)); | 1407 session.get(), &mock_socket_factory)); |
1429 | 1408 |
1430 HttpRequestInfo request; | 1409 HttpRequestInfo request; |
1431 request.method = "GET"; | 1410 request.method = "GET"; |
1432 request.url = GURL("https://www.google.com/"); | 1411 request.url = GURL("https://www.google.com/"); |
1433 request.load_flags = 0; | 1412 request.load_flags = 0; |
1434 | 1413 |
1435 // Since we have proxy, should try to establish tunnel. | 1414 // Since we have proxy, should try to establish tunnel. |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1631 | 1610 |
1632 // Test the flow when both the proxy server AND origin server require | 1611 // Test the flow when both the proxy server AND origin server require |
1633 // authentication. Again, this uses basic auth for both since that is | 1612 // authentication. Again, this uses basic auth for both since that is |
1634 // the simplest to mock. | 1613 // the simplest to mock. |
1635 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { | 1614 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
1636 scoped_ptr<ProxyService> proxy_service( | 1615 scoped_ptr<ProxyService> proxy_service( |
1637 CreateFixedProxyService("myproxy:70")); | 1616 CreateFixedProxyService("myproxy:70")); |
1638 | 1617 |
1639 // Configure against proxy server "myproxy:70". | 1618 // Configure against proxy server "myproxy:70". |
1640 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 1619 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
1641 CreateSession(proxy_service.get(), &mock_socket_factory), | 1620 CreateSession(proxy_service.get()), |
1642 &mock_socket_factory)); | 1621 &mock_socket_factory)); |
1643 | 1622 |
1644 HttpRequestInfo request; | 1623 HttpRequestInfo request; |
1645 request.method = "GET"; | 1624 request.method = "GET"; |
1646 request.url = GURL("http://www.google.com/"); | 1625 request.url = GURL("http://www.google.com/"); |
1647 request.load_flags = 0; | 1626 request.load_flags = 0; |
1648 | 1627 |
1649 MockWrite data_writes1[] = { | 1628 MockWrite data_writes1[] = { |
1650 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" | 1629 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
1651 "Host: www.google.com\r\n" | 1630 "Host: www.google.com\r\n" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1770 // The NTLM authentication unit tests were generated by capturing the HTTP | 1749 // The NTLM authentication unit tests were generated by capturing the HTTP |
1771 // requests and responses using Fiddler 2 and inspecting the generated random | 1750 // requests and responses using Fiddler 2 and inspecting the generated random |
1772 // bytes in the debugger. | 1751 // bytes in the debugger. |
1773 | 1752 |
1774 // Enter the correct password and authenticate successfully. | 1753 // Enter the correct password and authenticate successfully. |
1775 TEST_F(HttpNetworkTransactionTest, NTLMAuth1) { | 1754 TEST_F(HttpNetworkTransactionTest, NTLMAuth1) { |
1776 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, | 1755 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
1777 MockGetHostName); | 1756 MockGetHostName); |
1778 | 1757 |
1779 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 1758 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
1780 scoped_ptr<HttpTransaction> trans( | 1759 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
1781 new HttpNetworkTransaction( | 1760 CreateSession(proxy_service.get()), &mock_socket_factory)); |
1782 CreateSession(proxy_service.get(), &mock_socket_factory), | |
1783 &mock_socket_factory)); | |
1784 | 1761 |
1785 HttpRequestInfo request; | 1762 HttpRequestInfo request; |
1786 request.method = "GET"; | 1763 request.method = "GET"; |
1787 request.url = GURL("http://172.22.68.17/kids/login.aspx"); | 1764 request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
1788 request.load_flags = 0; | 1765 request.load_flags = 0; |
1789 | 1766 |
1790 MockWrite data_writes1[] = { | 1767 MockWrite data_writes1[] = { |
1791 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" | 1768 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
1792 "Host: 172.22.68.17\r\n" | 1769 "Host: 172.22.68.17\r\n" |
1793 "Connection: keep-alive\r\n\r\n"), | 1770 "Connection: keep-alive\r\n\r\n"), |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1900 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 1877 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
1901 EXPECT_EQ(13, response->headers->GetContentLength()); | 1878 EXPECT_EQ(13, response->headers->GetContentLength()); |
1902 } | 1879 } |
1903 | 1880 |
1904 // Enter a wrong password, and then the correct one. | 1881 // Enter a wrong password, and then the correct one. |
1905 TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { | 1882 TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { |
1906 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, | 1883 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
1907 MockGetHostName); | 1884 MockGetHostName); |
1908 | 1885 |
1909 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 1886 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
1910 scoped_ptr<HttpTransaction> trans( | 1887 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
1911 new HttpNetworkTransaction( | 1888 CreateSession(proxy_service.get()), &mock_socket_factory)); |
1912 CreateSession(proxy_service.get(), &mock_socket_factory), | |
1913 &mock_socket_factory)); | |
1914 | 1889 |
1915 HttpRequestInfo request; | 1890 HttpRequestInfo request; |
1916 request.method = "GET"; | 1891 request.method = "GET"; |
1917 request.url = GURL("http://172.22.68.17/kids/login.aspx"); | 1892 request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
1918 request.load_flags = 0; | 1893 request.load_flags = 0; |
1919 | 1894 |
1920 MockWrite data_writes1[] = { | 1895 MockWrite data_writes1[] = { |
1921 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" | 1896 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
1922 "Host: 172.22.68.17\r\n" | 1897 "Host: 172.22.68.17\r\n" |
1923 "Connection: keep-alive\r\n\r\n"), | 1898 "Connection: keep-alive\r\n\r\n"), |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2111 response = trans->GetResponseInfo(); | 2086 response = trans->GetResponseInfo(); |
2112 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 2087 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
2113 EXPECT_EQ(13, response->headers->GetContentLength()); | 2088 EXPECT_EQ(13, response->headers->GetContentLength()); |
2114 } | 2089 } |
2115 | 2090 |
2116 // Test reading a server response which has only headers, and no body. | 2091 // Test reading a server response which has only headers, and no body. |
2117 // After some maximum number of bytes is consumed, the transaction should | 2092 // After some maximum number of bytes is consumed, the transaction should |
2118 // fail with ERR_RESPONSE_HEADERS_TOO_BIG. | 2093 // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
2119 TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { | 2094 TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
2120 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 2095 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
2121 scoped_ptr<HttpTransaction> trans( | 2096 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
2122 new HttpNetworkTransaction( | 2097 CreateSession(proxy_service.get()), &mock_socket_factory)); |
2123 CreateSession(proxy_service.get(), &mock_socket_factory), | |
2124 &mock_socket_factory)); | |
2125 | 2098 |
2126 HttpRequestInfo request; | 2099 HttpRequestInfo request; |
2127 request.method = "GET"; | 2100 request.method = "GET"; |
2128 request.url = GURL("http://www.google.com/"); | 2101 request.url = GURL("http://www.google.com/"); |
2129 request.load_flags = 0; | 2102 request.load_flags = 0; |
2130 | 2103 |
2131 // Respond with 50 kb of headers (we should fail after 32 kb). | 2104 // Respond with 50 kb of headers (we should fail after 32 kb). |
2132 std::string large_headers_string; | 2105 std::string large_headers_string; |
2133 FillLargeHeadersString(&large_headers_string, 50 * 1024); | 2106 FillLargeHeadersString(&large_headers_string, 50 * 1024); |
2134 | 2107 |
(...skipping 22 matching lines...) Expand all Loading... |
2157 | 2130 |
2158 // Make sure that we don't try to reuse a TCPClientSocket when failing to | 2131 // Make sure that we don't try to reuse a TCPClientSocket when failing to |
2159 // establish tunnel. | 2132 // establish tunnel. |
2160 // http://code.google.com/p/chromium/issues/detail?id=3772 | 2133 // http://code.google.com/p/chromium/issues/detail?id=3772 |
2161 TEST_F(HttpNetworkTransactionTest, DontRecycleTCPSocketForSSLTunnel) { | 2134 TEST_F(HttpNetworkTransactionTest, DontRecycleTCPSocketForSSLTunnel) { |
2162 // Configure against proxy server "myproxy:70". | 2135 // Configure against proxy server "myproxy:70". |
2163 scoped_ptr<ProxyService> proxy_service( | 2136 scoped_ptr<ProxyService> proxy_service( |
2164 CreateFixedProxyService("myproxy:70")); | 2137 CreateFixedProxyService("myproxy:70")); |
2165 | 2138 |
2166 scoped_refptr<HttpNetworkSession> session( | 2139 scoped_refptr<HttpNetworkSession> session( |
2167 CreateSession(proxy_service.get(), &mock_socket_factory)); | 2140 CreateSession(proxy_service.get())); |
2168 | 2141 |
2169 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 2142 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
2170 session.get(), &mock_socket_factory)); | 2143 session.get(), &mock_socket_factory)); |
2171 | 2144 |
2172 HttpRequestInfo request; | 2145 HttpRequestInfo request; |
2173 request.method = "GET"; | 2146 request.method = "GET"; |
2174 request.url = GURL("https://www.google.com/"); | 2147 request.url = GURL("https://www.google.com/"); |
2175 request.load_flags = 0; | 2148 request.load_flags = 0; |
2176 | 2149 |
2177 // Since we have proxy, should try to establish tunnel. | 2150 // Since we have proxy, should try to establish tunnel. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2216 trans.reset(); | 2189 trans.reset(); |
2217 MessageLoop::current()->RunAllPending(); | 2190 MessageLoop::current()->RunAllPending(); |
2218 // Make sure that the socket didn't get recycled after calling the destructor. | 2191 // Make sure that the socket didn't get recycled after calling the destructor. |
2219 EXPECT_EQ(0, session->connection_pool()->idle_socket_count()); | 2192 EXPECT_EQ(0, session->connection_pool()->idle_socket_count()); |
2220 } | 2193 } |
2221 | 2194 |
2222 // Make sure that we recycle a socket after reading all of the response body. | 2195 // Make sure that we recycle a socket after reading all of the response body. |
2223 TEST_F(HttpNetworkTransactionTest, RecycleSocket) { | 2196 TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
2224 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 2197 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
2225 scoped_refptr<HttpNetworkSession> session( | 2198 scoped_refptr<HttpNetworkSession> session( |
2226 CreateSession(proxy_service.get(), &mock_socket_factory)); | 2199 CreateSession(proxy_service.get())); |
2227 | 2200 |
2228 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 2201 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
2229 session.get(), &mock_socket_factory)); | 2202 session.get(), &mock_socket_factory)); |
2230 | 2203 |
2231 HttpRequestInfo request; | 2204 HttpRequestInfo request; |
2232 request.method = "GET"; | 2205 request.method = "GET"; |
2233 request.url = GURL("http://www.google.com/"); | 2206 request.url = GURL("http://www.google.com/"); |
2234 request.load_flags = 0; | 2207 request.load_flags = 0; |
2235 | 2208 |
2236 MockRead data_reads[] = { | 2209 MockRead data_reads[] = { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2276 | 2249 |
2277 // We now check to make sure the socket was added back to the pool. | 2250 // We now check to make sure the socket was added back to the pool. |
2278 EXPECT_EQ(1, session->connection_pool()->idle_socket_count()); | 2251 EXPECT_EQ(1, session->connection_pool()->idle_socket_count()); |
2279 } | 2252 } |
2280 | 2253 |
2281 // Make sure that we recycle a socket after a zero-length response. | 2254 // Make sure that we recycle a socket after a zero-length response. |
2282 // http://crbug.com/9880 | 2255 // http://crbug.com/9880 |
2283 TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { | 2256 TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
2284 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 2257 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
2285 scoped_refptr<HttpNetworkSession> session( | 2258 scoped_refptr<HttpNetworkSession> session( |
2286 CreateSession(proxy_service.get(), &mock_socket_factory)); | 2259 CreateSession(proxy_service.get())); |
2287 | 2260 |
2288 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 2261 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
2289 session.get(), &mock_socket_factory)); | 2262 session.get(), &mock_socket_factory)); |
2290 | 2263 |
2291 HttpRequestInfo request; | 2264 HttpRequestInfo request; |
2292 request.method = "GET"; | 2265 request.method = "GET"; |
2293 request.url = GURL("http://www.google.com/csi?v=3&s=web&action=&" | 2266 request.url = GURL("http://www.google.com/csi?v=3&s=web&action=&" |
2294 "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" | 2267 "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
2295 "e=17259,18167,19592,19773,19981,20133,20173,20233&" | 2268 "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
2296 "rt=prt.2642,ol.2649,xjs.2951"); | 2269 "rt=prt.2642,ol.2649,xjs.2951"); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2351 // This causes the transaction to retry with a new socket. The second | 2324 // This causes the transaction to retry with a new socket. The second |
2352 // attempt succeeds. | 2325 // attempt succeeds. |
2353 request[1].method = "POST"; | 2326 request[1].method = "POST"; |
2354 request[1].url = GURL("http://www.google.com/login.cgi"); | 2327 request[1].url = GURL("http://www.google.com/login.cgi"); |
2355 request[1].upload_data = new UploadData; | 2328 request[1].upload_data = new UploadData; |
2356 request[1].upload_data->AppendBytes("foo", 3); | 2329 request[1].upload_data->AppendBytes("foo", 3); |
2357 request[1].load_flags = 0; | 2330 request[1].load_flags = 0; |
2358 | 2331 |
2359 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 2332 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
2360 scoped_refptr<HttpNetworkSession> session = | 2333 scoped_refptr<HttpNetworkSession> session = |
2361 CreateSession(proxy_service.get(), &mock_socket_factory); | 2334 CreateSession(proxy_service.get()); |
2362 | 2335 |
2363 // The first socket is used for transaction 1 and the first attempt of | 2336 // The first socket is used for transaction 1 and the first attempt of |
2364 // transaction 2. | 2337 // transaction 2. |
2365 | 2338 |
2366 // The response of transaction 1. | 2339 // The response of transaction 1. |
2367 MockRead data_reads1[] = { | 2340 MockRead data_reads1[] = { |
2368 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), | 2341 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
2369 MockRead("hello world"), | 2342 MockRead("hello world"), |
2370 MockRead(false, OK), | 2343 MockRead(false, OK), |
2371 }; | 2344 }; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2428 EXPECT_EQ(OK, rv); | 2401 EXPECT_EQ(OK, rv); |
2429 EXPECT_EQ(kExpectedResponseData[i], response_data); | 2402 EXPECT_EQ(kExpectedResponseData[i], response_data); |
2430 } | 2403 } |
2431 } | 2404 } |
2432 | 2405 |
2433 // Test the request-challenge-retry sequence for basic auth when there is | 2406 // Test the request-challenge-retry sequence for basic auth when there is |
2434 // an identity in the URL. The request should be sent as normal, but when | 2407 // an identity in the URL. The request should be sent as normal, but when |
2435 // it fails the identity from the URL is used to answer the challenge. | 2408 // it fails the identity from the URL is used to answer the challenge. |
2436 TEST_F(HttpNetworkTransactionTest, AuthIdentityInUrl) { | 2409 TEST_F(HttpNetworkTransactionTest, AuthIdentityInUrl) { |
2437 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 2410 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
2438 scoped_ptr<HttpTransaction> trans( | 2411 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
2439 new HttpNetworkTransaction( | 2412 CreateSession(proxy_service.get()), &mock_socket_factory)); |
2440 CreateSession(proxy_service.get(), &mock_socket_factory), | |
2441 &mock_socket_factory)); | |
2442 | 2413 |
2443 HttpRequestInfo request; | 2414 HttpRequestInfo request; |
2444 request.method = "GET"; | 2415 request.method = "GET"; |
2445 // Note: the URL has a username:password in it. | 2416 // Note: the URL has a username:password in it. |
2446 request.url = GURL("http://foo:bar@www.google.com/"); | 2417 request.url = GURL("http://foo:bar@www.google.com/"); |
2447 request.load_flags = 0; | 2418 request.load_flags = 0; |
2448 | 2419 |
2449 MockWrite data_writes1[] = { | 2420 MockWrite data_writes1[] = { |
2450 MockWrite("GET / HTTP/1.1\r\n" | 2421 MockWrite("GET / HTTP/1.1\r\n" |
2451 "Host: www.google.com\r\n" | 2422 "Host: www.google.com\r\n" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2509 EXPECT_EQ(100, response->headers->GetContentLength()); | 2480 EXPECT_EQ(100, response->headers->GetContentLength()); |
2510 | 2481 |
2511 // Empty the current queue. | 2482 // Empty the current queue. |
2512 MessageLoop::current()->RunAllPending(); | 2483 MessageLoop::current()->RunAllPending(); |
2513 } | 2484 } |
2514 | 2485 |
2515 // Test that previously tried username/passwords for a realm get re-used. | 2486 // Test that previously tried username/passwords for a realm get re-used. |
2516 TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { | 2487 TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
2517 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 2488 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
2518 scoped_refptr<HttpNetworkSession> session = | 2489 scoped_refptr<HttpNetworkSession> session = |
2519 CreateSession(proxy_service.get(), &mock_socket_factory); | 2490 CreateSession(proxy_service.get()); |
2520 | 2491 |
2521 // Transaction 1: authenticate (foo, bar) on MyRealm1 | 2492 // Transaction 1: authenticate (foo, bar) on MyRealm1 |
2522 { | 2493 { |
2523 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 2494 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
2524 session, &mock_socket_factory)); | 2495 session, &mock_socket_factory)); |
2525 | 2496 |
2526 HttpRequestInfo request; | 2497 HttpRequestInfo request; |
2527 request.method = "GET"; | 2498 request.method = "GET"; |
2528 request.url = GURL("http://www.google.com/x/y/z"); | 2499 request.url = GURL("http://www.google.com/x/y/z"); |
2529 request.load_flags = 0; | 2500 request.load_flags = 0; |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2930 EXPECT_FALSE(response == NULL); | 2901 EXPECT_FALSE(response == NULL); |
2931 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 2902 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
2932 EXPECT_EQ(100, response->headers->GetContentLength()); | 2903 EXPECT_EQ(100, response->headers->GetContentLength()); |
2933 } | 2904 } |
2934 } | 2905 } |
2935 | 2906 |
2936 // Test the ResetStateForRestart() private method. | 2907 // Test the ResetStateForRestart() private method. |
2937 TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { | 2908 TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
2938 // Create a transaction (the dependencies aren't important). | 2909 // Create a transaction (the dependencies aren't important). |
2939 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 2910 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
2940 scoped_ptr<HttpNetworkTransaction> trans( | 2911 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction( |
2941 new HttpNetworkTransaction( | 2912 CreateSession(proxy_service.get()), &mock_socket_factory)); |
2942 CreateSession(proxy_service.get(), &mock_socket_factory), | |
2943 &mock_socket_factory)); | |
2944 | 2913 |
2945 // Setup some state (which we expect ResetStateForRestart() will clear). | 2914 // Setup some state (which we expect ResetStateForRestart() will clear). |
2946 trans->header_buf_->Realloc(10); | 2915 trans->header_buf_->Realloc(10); |
2947 trans->header_buf_capacity_ = 10; | 2916 trans->header_buf_capacity_ = 10; |
2948 trans->header_buf_len_ = 3; | 2917 trans->header_buf_len_ = 3; |
2949 trans->header_buf_body_offset_ = 11; | 2918 trans->header_buf_body_offset_ = 11; |
2950 trans->header_buf_http_offset_ = 0; | 2919 trans->header_buf_http_offset_ = 0; |
2951 trans->response_body_length_ = 100; | 2920 trans->response_body_length_ = 100; |
2952 trans->response_body_read_ = 1; | 2921 trans->response_body_read_ = 1; |
2953 trans->read_buf_ = new IOBuffer(15); | 2922 trans->read_buf_ = new IOBuffer(15); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2990 EXPECT_EQ(false, trans->response_.was_cached); | 2959 EXPECT_EQ(false, trans->response_.was_cached); |
2991 EXPECT_EQ(base::kInvalidPlatformFileValue, | 2960 EXPECT_EQ(base::kInvalidPlatformFileValue, |
2992 trans->response_.response_data_file); | 2961 trans->response_.response_data_file); |
2993 EXPECT_EQ(0, trans->response_.ssl_info.cert_status); | 2962 EXPECT_EQ(0, trans->response_.ssl_info.cert_status); |
2994 EXPECT_FALSE(trans->response_.vary_data.is_valid()); | 2963 EXPECT_FALSE(trans->response_.vary_data.is_valid()); |
2995 } | 2964 } |
2996 | 2965 |
2997 // Test HTTPS connections to a site with a bad certificate | 2966 // Test HTTPS connections to a site with a bad certificate |
2998 TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { | 2967 TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
2999 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 2968 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
3000 scoped_ptr<HttpTransaction> trans( | 2969 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
3001 new HttpNetworkTransaction( | 2970 CreateSession(proxy_service.get()), &mock_socket_factory)); |
3002 CreateSession(proxy_service.get(), &mock_socket_factory), | |
3003 &mock_socket_factory)); | |
3004 | 2971 |
3005 HttpRequestInfo request; | 2972 HttpRequestInfo request; |
3006 request.method = "GET"; | 2973 request.method = "GET"; |
3007 request.url = GURL("https://www.google.com/"); | 2974 request.url = GURL("https://www.google.com/"); |
3008 request.load_flags = 0; | 2975 request.load_flags = 0; |
3009 | 2976 |
3010 MockWrite data_writes[] = { | 2977 MockWrite data_writes[] = { |
3011 MockWrite("GET / HTTP/1.1\r\n" | 2978 MockWrite("GET / HTTP/1.1\r\n" |
3012 "Host: www.google.com\r\n" | 2979 "Host: www.google.com\r\n" |
3013 "Connection: keep-alive\r\n\r\n"), | 2980 "Connection: keep-alive\r\n\r\n"), |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3102 mock_ssl_sockets[0] = &ssl_bad; | 3069 mock_ssl_sockets[0] = &ssl_bad; |
3103 mock_ssl_sockets[1] = &ssl; | 3070 mock_ssl_sockets[1] = &ssl; |
3104 mock_ssl_sockets[2] = NULL; | 3071 mock_ssl_sockets[2] = NULL; |
3105 | 3072 |
3106 TestCompletionCallback callback; | 3073 TestCompletionCallback callback; |
3107 | 3074 |
3108 for (int i = 0; i < 2; i++) { | 3075 for (int i = 0; i < 2; i++) { |
3109 mock_sockets_index = 0; | 3076 mock_sockets_index = 0; |
3110 mock_ssl_sockets_index = 0; | 3077 mock_ssl_sockets_index = 0; |
3111 | 3078 |
3112 scoped_ptr<HttpTransaction> trans( | 3079 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
3113 new HttpNetworkTransaction( | 3080 CreateSession(proxy_service.get()), &mock_socket_factory)); |
3114 CreateSession(proxy_service.get(), &mock_socket_factory), | |
3115 &mock_socket_factory)); | |
3116 | 3081 |
3117 int rv = trans->Start(&request, &callback); | 3082 int rv = trans->Start(&request, &callback); |
3118 EXPECT_EQ(ERR_IO_PENDING, rv); | 3083 EXPECT_EQ(ERR_IO_PENDING, rv); |
3119 | 3084 |
3120 rv = callback.WaitForResult(); | 3085 rv = callback.WaitForResult(); |
3121 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); | 3086 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
3122 | 3087 |
3123 rv = trans->RestartIgnoringLastError(&callback); | 3088 rv = trans->RestartIgnoringLastError(&callback); |
3124 EXPECT_EQ(ERR_IO_PENDING, rv); | 3089 EXPECT_EQ(ERR_IO_PENDING, rv); |
3125 | 3090 |
3126 rv = callback.WaitForResult(); | 3091 rv = callback.WaitForResult(); |
3127 EXPECT_EQ(OK, rv); | 3092 EXPECT_EQ(OK, rv); |
3128 | 3093 |
3129 const HttpResponseInfo* response = trans->GetResponseInfo(); | 3094 const HttpResponseInfo* response = trans->GetResponseInfo(); |
3130 | 3095 |
3131 EXPECT_FALSE(response == NULL); | 3096 EXPECT_FALSE(response == NULL); |
3132 EXPECT_EQ(100, response->headers->GetContentLength()); | 3097 EXPECT_EQ(100, response->headers->GetContentLength()); |
3133 } | 3098 } |
3134 } | 3099 } |
3135 | 3100 |
3136 TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { | 3101 TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
3137 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 3102 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
3138 scoped_ptr<HttpTransaction> trans( | 3103 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
3139 new HttpNetworkTransaction( | 3104 CreateSession(proxy_service.get()), &mock_socket_factory)); |
3140 CreateSession(proxy_service.get(), &mock_socket_factory), | |
3141 &mock_socket_factory)); | |
3142 | 3105 |
3143 HttpRequestInfo request; | 3106 HttpRequestInfo request; |
3144 request.method = "GET"; | 3107 request.method = "GET"; |
3145 request.url = GURL("http://www.google.com/"); | 3108 request.url = GURL("http://www.google.com/"); |
3146 request.user_agent = "Chromium Ultra Awesome X Edition"; | 3109 request.user_agent = "Chromium Ultra Awesome X Edition"; |
3147 | 3110 |
3148 MockWrite data_writes[] = { | 3111 MockWrite data_writes[] = { |
3149 MockWrite("GET / HTTP/1.1\r\n" | 3112 MockWrite("GET / HTTP/1.1\r\n" |
3150 "Host: www.google.com\r\n" | 3113 "Host: www.google.com\r\n" |
3151 "Connection: keep-alive\r\n" | 3114 "Connection: keep-alive\r\n" |
(...skipping 18 matching lines...) Expand all Loading... |
3170 | 3133 |
3171 int rv = trans->Start(&request, &callback); | 3134 int rv = trans->Start(&request, &callback); |
3172 EXPECT_EQ(ERR_IO_PENDING, rv); | 3135 EXPECT_EQ(ERR_IO_PENDING, rv); |
3173 | 3136 |
3174 rv = callback.WaitForResult(); | 3137 rv = callback.WaitForResult(); |
3175 EXPECT_EQ(OK, rv); | 3138 EXPECT_EQ(OK, rv); |
3176 } | 3139 } |
3177 | 3140 |
3178 TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { | 3141 TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
3179 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 3142 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
3180 scoped_ptr<HttpTransaction> trans( | 3143 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
3181 new HttpNetworkTransaction( | 3144 CreateSession(proxy_service.get()), &mock_socket_factory)); |
3182 CreateSession(proxy_service.get(), &mock_socket_factory), | |
3183 &mock_socket_factory)); | |
3184 | 3145 |
3185 HttpRequestInfo request; | 3146 HttpRequestInfo request; |
3186 request.method = "GET"; | 3147 request.method = "GET"; |
3187 request.url = GURL("http://www.google.com/"); | 3148 request.url = GURL("http://www.google.com/"); |
3188 request.load_flags = 0; | 3149 request.load_flags = 0; |
3189 request.referrer = GURL("http://the.previous.site.com/"); | 3150 request.referrer = GURL("http://the.previous.site.com/"); |
3190 | 3151 |
3191 MockWrite data_writes[] = { | 3152 MockWrite data_writes[] = { |
3192 MockWrite("GET / HTTP/1.1\r\n" | 3153 MockWrite("GET / HTTP/1.1\r\n" |
3193 "Host: www.google.com\r\n" | 3154 "Host: www.google.com\r\n" |
(...skipping 19 matching lines...) Expand all Loading... |
3213 | 3174 |
3214 int rv = trans->Start(&request, &callback); | 3175 int rv = trans->Start(&request, &callback); |
3215 EXPECT_EQ(ERR_IO_PENDING, rv); | 3176 EXPECT_EQ(ERR_IO_PENDING, rv); |
3216 | 3177 |
3217 rv = callback.WaitForResult(); | 3178 rv = callback.WaitForResult(); |
3218 EXPECT_EQ(OK, rv); | 3179 EXPECT_EQ(OK, rv); |
3219 } | 3180 } |
3220 | 3181 |
3221 TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { | 3182 TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
3222 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 3183 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
3223 scoped_ptr<HttpTransaction> trans( | 3184 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
3224 new HttpNetworkTransaction( | 3185 CreateSession(proxy_service.get()), &mock_socket_factory)); |
3225 CreateSession(proxy_service.get(), &mock_socket_factory), | |
3226 &mock_socket_factory)); | |
3227 | 3186 |
3228 HttpRequestInfo request; | 3187 HttpRequestInfo request; |
3229 request.method = "POST"; | 3188 request.method = "POST"; |
3230 request.url = GURL("http://www.google.com/"); | 3189 request.url = GURL("http://www.google.com/"); |
3231 | 3190 |
3232 MockWrite data_writes[] = { | 3191 MockWrite data_writes[] = { |
3233 MockWrite("POST / HTTP/1.1\r\n" | 3192 MockWrite("POST / HTTP/1.1\r\n" |
3234 "Host: www.google.com\r\n" | 3193 "Host: www.google.com\r\n" |
3235 "Connection: keep-alive\r\n" | 3194 "Connection: keep-alive\r\n" |
3236 "Content-Length: 0\r\n\r\n"), | 3195 "Content-Length: 0\r\n\r\n"), |
(...skipping 17 matching lines...) Expand all Loading... |
3254 | 3213 |
3255 int rv = trans->Start(&request, &callback); | 3214 int rv = trans->Start(&request, &callback); |
3256 EXPECT_EQ(ERR_IO_PENDING, rv); | 3215 EXPECT_EQ(ERR_IO_PENDING, rv); |
3257 | 3216 |
3258 rv = callback.WaitForResult(); | 3217 rv = callback.WaitForResult(); |
3259 EXPECT_EQ(OK, rv); | 3218 EXPECT_EQ(OK, rv); |
3260 } | 3219 } |
3261 | 3220 |
3262 TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { | 3221 TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
3263 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 3222 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
3264 scoped_ptr<HttpTransaction> trans( | 3223 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
3265 new HttpNetworkTransaction( | 3224 CreateSession(proxy_service.get()), &mock_socket_factory)); |
3266 CreateSession(proxy_service.get(), &mock_socket_factory), | |
3267 &mock_socket_factory)); | |
3268 | 3225 |
3269 HttpRequestInfo request; | 3226 HttpRequestInfo request; |
3270 request.method = "PUT"; | 3227 request.method = "PUT"; |
3271 request.url = GURL("http://www.google.com/"); | 3228 request.url = GURL("http://www.google.com/"); |
3272 | 3229 |
3273 MockWrite data_writes[] = { | 3230 MockWrite data_writes[] = { |
3274 MockWrite("PUT / HTTP/1.1\r\n" | 3231 MockWrite("PUT / HTTP/1.1\r\n" |
3275 "Host: www.google.com\r\n" | 3232 "Host: www.google.com\r\n" |
3276 "Connection: keep-alive\r\n" | 3233 "Connection: keep-alive\r\n" |
3277 "Content-Length: 0\r\n\r\n"), | 3234 "Content-Length: 0\r\n\r\n"), |
(...skipping 17 matching lines...) Expand all Loading... |
3295 | 3252 |
3296 int rv = trans->Start(&request, &callback); | 3253 int rv = trans->Start(&request, &callback); |
3297 EXPECT_EQ(ERR_IO_PENDING, rv); | 3254 EXPECT_EQ(ERR_IO_PENDING, rv); |
3298 | 3255 |
3299 rv = callback.WaitForResult(); | 3256 rv = callback.WaitForResult(); |
3300 EXPECT_EQ(OK, rv); | 3257 EXPECT_EQ(OK, rv); |
3301 } | 3258 } |
3302 | 3259 |
3303 TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { | 3260 TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
3304 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 3261 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
3305 scoped_ptr<HttpTransaction> trans( | 3262 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
3306 new HttpNetworkTransaction( | 3263 CreateSession(proxy_service.get()), &mock_socket_factory)); |
3307 CreateSession(proxy_service.get(), &mock_socket_factory), | |
3308 &mock_socket_factory)); | |
3309 | 3264 |
3310 HttpRequestInfo request; | 3265 HttpRequestInfo request; |
3311 request.method = "HEAD"; | 3266 request.method = "HEAD"; |
3312 request.url = GURL("http://www.google.com/"); | 3267 request.url = GURL("http://www.google.com/"); |
3313 | 3268 |
3314 MockWrite data_writes[] = { | 3269 MockWrite data_writes[] = { |
3315 MockWrite("HEAD / HTTP/1.1\r\n" | 3270 MockWrite("HEAD / HTTP/1.1\r\n" |
3316 "Host: www.google.com\r\n" | 3271 "Host: www.google.com\r\n" |
3317 "Connection: keep-alive\r\n" | 3272 "Connection: keep-alive\r\n" |
3318 "Content-Length: 0\r\n\r\n"), | 3273 "Content-Length: 0\r\n\r\n"), |
(...skipping 17 matching lines...) Expand all Loading... |
3336 | 3291 |
3337 int rv = trans->Start(&request, &callback); | 3292 int rv = trans->Start(&request, &callback); |
3338 EXPECT_EQ(ERR_IO_PENDING, rv); | 3293 EXPECT_EQ(ERR_IO_PENDING, rv); |
3339 | 3294 |
3340 rv = callback.WaitForResult(); | 3295 rv = callback.WaitForResult(); |
3341 EXPECT_EQ(OK, rv); | 3296 EXPECT_EQ(OK, rv); |
3342 } | 3297 } |
3343 | 3298 |
3344 TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { | 3299 TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
3345 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 3300 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
3346 scoped_ptr<HttpTransaction> trans( | 3301 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
3347 new HttpNetworkTransaction( | 3302 CreateSession(proxy_service.get()), &mock_socket_factory)); |
3348 CreateSession(proxy_service.get(), &mock_socket_factory), | |
3349 &mock_socket_factory)); | |
3350 | 3303 |
3351 HttpRequestInfo request; | 3304 HttpRequestInfo request; |
3352 request.method = "GET"; | 3305 request.method = "GET"; |
3353 request.url = GURL("http://www.google.com/"); | 3306 request.url = GURL("http://www.google.com/"); |
3354 request.load_flags = LOAD_BYPASS_CACHE; | 3307 request.load_flags = LOAD_BYPASS_CACHE; |
3355 | 3308 |
3356 MockWrite data_writes[] = { | 3309 MockWrite data_writes[] = { |
3357 MockWrite("GET / HTTP/1.1\r\n" | 3310 MockWrite("GET / HTTP/1.1\r\n" |
3358 "Host: www.google.com\r\n" | 3311 "Host: www.google.com\r\n" |
3359 "Connection: keep-alive\r\n" | 3312 "Connection: keep-alive\r\n" |
(...skipping 20 matching lines...) Expand all Loading... |
3380 int rv = trans->Start(&request, &callback); | 3333 int rv = trans->Start(&request, &callback); |
3381 EXPECT_EQ(ERR_IO_PENDING, rv); | 3334 EXPECT_EQ(ERR_IO_PENDING, rv); |
3382 | 3335 |
3383 rv = callback.WaitForResult(); | 3336 rv = callback.WaitForResult(); |
3384 EXPECT_EQ(OK, rv); | 3337 EXPECT_EQ(OK, rv); |
3385 } | 3338 } |
3386 | 3339 |
3387 TEST_F(HttpNetworkTransactionTest, | 3340 TEST_F(HttpNetworkTransactionTest, |
3388 BuildRequest_CacheControlValidateCache) { | 3341 BuildRequest_CacheControlValidateCache) { |
3389 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 3342 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
3390 scoped_ptr<HttpTransaction> trans( | 3343 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
3391 new HttpNetworkTransaction( | 3344 CreateSession(proxy_service.get()), &mock_socket_factory)); |
3392 CreateSession(proxy_service.get(), &mock_socket_factory), | |
3393 &mock_socket_factory)); | |
3394 | 3345 |
3395 HttpRequestInfo request; | 3346 HttpRequestInfo request; |
3396 request.method = "GET"; | 3347 request.method = "GET"; |
3397 request.url = GURL("http://www.google.com/"); | 3348 request.url = GURL("http://www.google.com/"); |
3398 request.load_flags = LOAD_VALIDATE_CACHE; | 3349 request.load_flags = LOAD_VALIDATE_CACHE; |
3399 | 3350 |
3400 MockWrite data_writes[] = { | 3351 MockWrite data_writes[] = { |
3401 MockWrite("GET / HTTP/1.1\r\n" | 3352 MockWrite("GET / HTTP/1.1\r\n" |
3402 "Host: www.google.com\r\n" | 3353 "Host: www.google.com\r\n" |
3403 "Connection: keep-alive\r\n" | 3354 "Connection: keep-alive\r\n" |
(...skipping 18 matching lines...) Expand all Loading... |
3422 | 3373 |
3423 int rv = trans->Start(&request, &callback); | 3374 int rv = trans->Start(&request, &callback); |
3424 EXPECT_EQ(ERR_IO_PENDING, rv); | 3375 EXPECT_EQ(ERR_IO_PENDING, rv); |
3425 | 3376 |
3426 rv = callback.WaitForResult(); | 3377 rv = callback.WaitForResult(); |
3427 EXPECT_EQ(OK, rv); | 3378 EXPECT_EQ(OK, rv); |
3428 } | 3379 } |
3429 | 3380 |
3430 TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { | 3381 TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
3431 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 3382 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
3432 scoped_ptr<HttpTransaction> trans( | 3383 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
3433 new HttpNetworkTransaction( | 3384 CreateSession(proxy_service.get()), &mock_socket_factory)); |
3434 CreateSession(proxy_service.get(), &mock_socket_factory), | |
3435 &mock_socket_factory)); | |
3436 | 3385 |
3437 HttpRequestInfo request; | 3386 HttpRequestInfo request; |
3438 request.method = "GET"; | 3387 request.method = "GET"; |
3439 request.url = GURL("http://www.google.com/"); | 3388 request.url = GURL("http://www.google.com/"); |
3440 request.extra_headers = "FooHeader: Bar\r\n"; | 3389 request.extra_headers = "FooHeader: Bar\r\n"; |
3441 | 3390 |
3442 MockWrite data_writes[] = { | 3391 MockWrite data_writes[] = { |
3443 MockWrite("GET / HTTP/1.1\r\n" | 3392 MockWrite("GET / HTTP/1.1\r\n" |
3444 "Host: www.google.com\r\n" | 3393 "Host: www.google.com\r\n" |
3445 "Connection: keep-alive\r\n" | 3394 "Connection: keep-alive\r\n" |
(...skipping 17 matching lines...) Expand all Loading... |
3463 TestCompletionCallback callback; | 3412 TestCompletionCallback callback; |
3464 | 3413 |
3465 int rv = trans->Start(&request, &callback); | 3414 int rv = trans->Start(&request, &callback); |
3466 EXPECT_EQ(ERR_IO_PENDING, rv); | 3415 EXPECT_EQ(ERR_IO_PENDING, rv); |
3467 | 3416 |
3468 rv = callback.WaitForResult(); | 3417 rv = callback.WaitForResult(); |
3469 EXPECT_EQ(OK, rv); | 3418 EXPECT_EQ(OK, rv); |
3470 } | 3419 } |
3471 | 3420 |
3472 } // namespace net | 3421 } // namespace net |
OLD | NEW |