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

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

Issue 6327020: Instantiate HttpRequestInfo before HttpNetworkTransaction in unit tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/valgrind/memcheck/suppressions.txt » ('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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/http/http_network_transaction.h" 5 #include "net/http/http_network_transaction.h"
6 6
7 #include <math.h> // ceil 7 #include <math.h> // ceil
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 struct SimpleGetHelperResult { 141 struct SimpleGetHelperResult {
142 int rv; 142 int rv;
143 std::string status_line; 143 std::string status_line;
144 std::string response_data; 144 std::string response_data;
145 }; 145 };
146 146
147 SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], 147 SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[],
148 size_t reads_count) { 148 size_t reads_count) {
149 SimpleGetHelperResult out; 149 SimpleGetHelperResult out;
150 150
151 SessionDependencies session_deps;
152 scoped_ptr<HttpTransaction> trans(
153 new HttpNetworkTransaction(CreateSession(&session_deps)));
154
155 HttpRequestInfo request; 151 HttpRequestInfo request;
156 request.method = "GET"; 152 request.method = "GET";
157 request.url = GURL("http://www.google.com/"); 153 request.url = GURL("http://www.google.com/");
158 request.load_flags = 0; 154 request.load_flags = 0;
159 155
156 SessionDependencies session_deps;
157 scoped_ptr<HttpTransaction> trans(
158 new HttpNetworkTransaction(CreateSession(&session_deps)));
159
160 StaticSocketDataProvider data(data_reads, reads_count, NULL, 0); 160 StaticSocketDataProvider data(data_reads, reads_count, NULL, 0);
161 session_deps.socket_factory.AddSocketDataProvider(&data); 161 session_deps.socket_factory.AddSocketDataProvider(&data);
162 162
163 TestCompletionCallback callback; 163 TestCompletionCallback callback;
164 164
165 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 165 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
166 EXPECT_TRUE(log.bound().IsLoggingAllEvents()); 166 EXPECT_TRUE(log.bound().IsLoggingAllEvents());
167 int rv = trans->Start(&request, &callback, log.bound()); 167 int rv = trans->Start(&request, &callback, log.bound());
168 EXPECT_EQ(ERR_IO_PENDING, rv); 168 EXPECT_EQ(ERR_IO_PENDING, rv);
169 169
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 SimpleGetHelperResult out = SimpleGetHelper(data_reads, 557 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
558 arraysize(data_reads)); 558 arraysize(data_reads));
559 EXPECT_EQ(OK, out.rv); 559 EXPECT_EQ(OK, out.rv);
560 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); 560 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
561 EXPECT_EQ("Hello world", out.response_data); 561 EXPECT_EQ("Hello world", out.response_data);
562 } 562 }
563 563
564 // Do a request using the HEAD method. Verify that we don't try to read the 564 // Do a request using the HEAD method. Verify that we don't try to read the
565 // message body (since HEAD has none). 565 // message body (since HEAD has none).
566 TEST_F(HttpNetworkTransactionTest, Head) { 566 TEST_F(HttpNetworkTransactionTest, Head) {
567 SessionDependencies session_deps;
568 scoped_ptr<HttpTransaction> trans(
569 new HttpNetworkTransaction(CreateSession(&session_deps)));
570
571 HttpRequestInfo request; 567 HttpRequestInfo request;
572 request.method = "HEAD"; 568 request.method = "HEAD";
573 request.url = GURL("http://www.google.com/"); 569 request.url = GURL("http://www.google.com/");
574 request.load_flags = 0; 570 request.load_flags = 0;
575 571
572 SessionDependencies session_deps;
573 scoped_ptr<HttpTransaction> trans(
574 new HttpNetworkTransaction(CreateSession(&session_deps)));
575
576 MockWrite data_writes1[] = { 576 MockWrite data_writes1[] = {
577 MockWrite("HEAD / HTTP/1.1\r\n" 577 MockWrite("HEAD / HTTP/1.1\r\n"
578 "Host: www.google.com\r\n" 578 "Host: www.google.com\r\n"
579 "Connection: keep-alive\r\n" 579 "Connection: keep-alive\r\n"
580 "Content-Length: 0\r\n\r\n"), 580 "Content-Length: 0\r\n\r\n"),
581 }; 581 };
582 MockRead data_reads1[] = { 582 MockRead data_reads1[] = {
583 MockRead("HTTP/1.1 404 Not Found\r\n"), 583 MockRead("HTTP/1.1 404 Not Found\r\n"),
584 MockRead("Server: Blah\r\n"), 584 MockRead("Server: Blah\r\n"),
585 MockRead("Content-Length: 1234\r\n\r\n"), 585 MockRead("Content-Length: 1234\r\n\r\n"),
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 MockRead(false, OK), 635 MockRead(false, OK),
636 }; 636 };
637 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 637 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
638 session_deps.socket_factory.AddSocketDataProvider(&data); 638 session_deps.socket_factory.AddSocketDataProvider(&data);
639 639
640 const char* const kExpectedResponseData[] = { 640 const char* const kExpectedResponseData[] = {
641 "hello", "world" 641 "hello", "world"
642 }; 642 };
643 643
644 for (int i = 0; i < 2; ++i) { 644 for (int i = 0; i < 2; ++i) {
645 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
646
647 HttpRequestInfo request; 645 HttpRequestInfo request;
648 request.method = "GET"; 646 request.method = "GET";
649 request.url = GURL("http://www.google.com/"); 647 request.url = GURL("http://www.google.com/");
650 request.load_flags = 0; 648 request.load_flags = 0;
651 649
650 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
651
652 TestCompletionCallback callback; 652 TestCompletionCallback callback;
653 653
654 int rv = trans->Start(&request, &callback, BoundNetLog()); 654 int rv = trans->Start(&request, &callback, BoundNetLog());
655 EXPECT_EQ(ERR_IO_PENDING, rv); 655 EXPECT_EQ(ERR_IO_PENDING, rv);
656 656
657 rv = callback.WaitForResult(); 657 rv = callback.WaitForResult();
658 EXPECT_EQ(OK, rv); 658 EXPECT_EQ(OK, rv);
659 659
660 const HttpResponseInfo* response = trans->GetResponseInfo(); 660 const HttpResponseInfo* response = trans->GetResponseInfo();
661 EXPECT_TRUE(response != NULL); 661 EXPECT_TRUE(response != NULL);
662 662
663 EXPECT_TRUE(response->headers != NULL); 663 EXPECT_TRUE(response->headers != NULL);
664 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 664 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
665 665
666 std::string response_data; 666 std::string response_data;
667 rv = ReadTransaction(trans.get(), &response_data); 667 rv = ReadTransaction(trans.get(), &response_data);
668 EXPECT_EQ(OK, rv); 668 EXPECT_EQ(OK, rv);
669 EXPECT_EQ(kExpectedResponseData[i], response_data); 669 EXPECT_EQ(kExpectedResponseData[i], response_data);
670 } 670 }
671 } 671 }
672 672
673 TEST_F(HttpNetworkTransactionTest, Ignores100) { 673 TEST_F(HttpNetworkTransactionTest, Ignores100) {
674 SessionDependencies session_deps;
675 scoped_ptr<HttpTransaction> trans(
676 new HttpNetworkTransaction(CreateSession(&session_deps)));
677
678 HttpRequestInfo request; 674 HttpRequestInfo request;
679 request.method = "POST"; 675 request.method = "POST";
680 request.url = GURL("http://www.foo.com/"); 676 request.url = GURL("http://www.foo.com/");
681 request.upload_data = new UploadData; 677 request.upload_data = new UploadData;
682 request.upload_data->AppendBytes("foo", 3); 678 request.upload_data->AppendBytes("foo", 3);
683 request.load_flags = 0; 679 request.load_flags = 0;
684 680
681 SessionDependencies session_deps;
682 scoped_ptr<HttpTransaction> trans(
683 new HttpNetworkTransaction(CreateSession(&session_deps)));
684
685 MockRead data_reads[] = { 685 MockRead data_reads[] = {
686 MockRead("HTTP/1.0 100 Continue\r\n\r\n"), 686 MockRead("HTTP/1.0 100 Continue\r\n\r\n"),
687 MockRead("HTTP/1.0 200 OK\r\n\r\n"), 687 MockRead("HTTP/1.0 200 OK\r\n\r\n"),
688 MockRead("hello world"), 688 MockRead("hello world"),
689 MockRead(false, OK), 689 MockRead(false, OK),
690 }; 690 };
691 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 691 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
692 session_deps.socket_factory.AddSocketDataProvider(&data); 692 session_deps.socket_factory.AddSocketDataProvider(&data);
693 693
694 TestCompletionCallback callback; 694 TestCompletionCallback callback;
(...skipping 13 matching lines...) Expand all
708 std::string response_data; 708 std::string response_data;
709 rv = ReadTransaction(trans.get(), &response_data); 709 rv = ReadTransaction(trans.get(), &response_data);
710 EXPECT_EQ(OK, rv); 710 EXPECT_EQ(OK, rv);
711 EXPECT_EQ("hello world", response_data); 711 EXPECT_EQ("hello world", response_data);
712 } 712 }
713 713
714 // This test is almost the same as Ignores100 above, but the response contains 714 // This test is almost the same as Ignores100 above, but the response contains
715 // a 102 instead of a 100. Also, instead of HTTP/1.0 the response is 715 // a 102 instead of a 100. Also, instead of HTTP/1.0 the response is
716 // HTTP/1.1 and the two status headers are read in one read. 716 // HTTP/1.1 and the two status headers are read in one read.
717 TEST_F(HttpNetworkTransactionTest, Ignores1xx) { 717 TEST_F(HttpNetworkTransactionTest, Ignores1xx) {
718 SessionDependencies session_deps;
719 scoped_ptr<HttpTransaction> trans(
720 new HttpNetworkTransaction(CreateSession(&session_deps)));
721
722 HttpRequestInfo request; 718 HttpRequestInfo request;
723 request.method = "GET"; 719 request.method = "GET";
724 request.url = GURL("http://www.foo.com/"); 720 request.url = GURL("http://www.foo.com/");
725 request.load_flags = 0; 721 request.load_flags = 0;
726 722
723 SessionDependencies session_deps;
724 scoped_ptr<HttpTransaction> trans(
725 new HttpNetworkTransaction(CreateSession(&session_deps)));
726
727 MockRead data_reads[] = { 727 MockRead data_reads[] = {
728 MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" 728 MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n"
729 "HTTP/1.1 200 OK\r\n\r\n"), 729 "HTTP/1.1 200 OK\r\n\r\n"),
730 MockRead("hello world"), 730 MockRead("hello world"),
731 MockRead(false, OK), 731 MockRead(false, OK),
732 }; 732 };
733 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 733 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
734 session_deps.socket_factory.AddSocketDataProvider(&data); 734 session_deps.socket_factory.AddSocketDataProvider(&data);
735 735
736 TestCompletionCallback callback; 736 TestCompletionCallback callback;
(...skipping 10 matching lines...) Expand all
747 EXPECT_TRUE(response->headers != NULL); 747 EXPECT_TRUE(response->headers != NULL);
748 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 748 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
749 749
750 std::string response_data; 750 std::string response_data;
751 rv = ReadTransaction(trans.get(), &response_data); 751 rv = ReadTransaction(trans.get(), &response_data);
752 EXPECT_EQ(OK, rv); 752 EXPECT_EQ(OK, rv);
753 EXPECT_EQ("hello world", response_data); 753 EXPECT_EQ("hello world", response_data);
754 } 754 }
755 755
756 TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { 756 TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) {
757 SessionDependencies session_deps;
758 scoped_ptr<HttpTransaction> trans(
759 new HttpNetworkTransaction(CreateSession(&session_deps)));
760
761 HttpRequestInfo request; 757 HttpRequestInfo request;
762 request.method = "POST"; 758 request.method = "POST";
763 request.url = GURL("http://www.foo.com/"); 759 request.url = GURL("http://www.foo.com/");
764 request.load_flags = 0; 760 request.load_flags = 0;
765 761
762 SessionDependencies session_deps;
763 scoped_ptr<HttpTransaction> trans(
764 new HttpNetworkTransaction(CreateSession(&session_deps)));
765
766 MockRead data_reads[] = { 766 MockRead data_reads[] = {
767 MockRead(false, "HTTP/1.0 100 Continue\r\n"), 767 MockRead(false, "HTTP/1.0 100 Continue\r\n"),
768 MockRead(true, 0), 768 MockRead(true, 0),
769 }; 769 };
770 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 770 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
771 session_deps.socket_factory.AddSocketDataProvider(&data); 771 session_deps.socket_factory.AddSocketDataProvider(&data);
772 772
773 TestCompletionCallback callback; 773 TestCompletionCallback callback;
774 774
775 int rv = trans->Start(&request, &callback, BoundNetLog()); 775 int rv = trans->Start(&request, &callback, BoundNetLog());
776 EXPECT_EQ(ERR_IO_PENDING, rv); 776 EXPECT_EQ(ERR_IO_PENDING, rv);
777 777
778 rv = callback.WaitForResult(); 778 rv = callback.WaitForResult();
779 EXPECT_EQ(OK, rv); 779 EXPECT_EQ(OK, rv);
780 780
781 std::string response_data; 781 std::string response_data;
782 rv = ReadTransaction(trans.get(), &response_data); 782 rv = ReadTransaction(trans.get(), &response_data);
783 EXPECT_EQ(OK, rv); 783 EXPECT_EQ(OK, rv);
784 EXPECT_EQ("", response_data); 784 EXPECT_EQ("", response_data);
785 } 785 }
786 786
787 TEST_F(HttpNetworkTransactionTest, EmptyResponse) { 787 TEST_F(HttpNetworkTransactionTest, EmptyResponse) {
788 SessionDependencies session_deps;
789 scoped_ptr<HttpTransaction> trans(
790 new HttpNetworkTransaction(CreateSession(&session_deps)));
791
792 HttpRequestInfo request; 788 HttpRequestInfo request;
793 request.method = "POST"; 789 request.method = "POST";
794 request.url = GURL("http://www.foo.com/"); 790 request.url = GURL("http://www.foo.com/");
795 request.load_flags = 0; 791 request.load_flags = 0;
796 792
793 SessionDependencies session_deps;
794 scoped_ptr<HttpTransaction> trans(
795 new HttpNetworkTransaction(CreateSession(&session_deps)));
796
797 MockRead data_reads[] = { 797 MockRead data_reads[] = {
798 MockRead(true, 0), 798 MockRead(true, 0),
799 }; 799 };
800 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 800 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
801 session_deps.socket_factory.AddSocketDataProvider(&data); 801 session_deps.socket_factory.AddSocketDataProvider(&data);
802 802
803 TestCompletionCallback callback; 803 TestCompletionCallback callback;
804 804
805 int rv = trans->Start(&request, &callback, BoundNetLog()); 805 int rv = trans->Start(&request, &callback, BoundNetLog());
806 EXPECT_EQ(ERR_IO_PENDING, rv); 806 EXPECT_EQ(ERR_IO_PENDING, rv);
807 807
808 rv = callback.WaitForResult(); 808 rv = callback.WaitForResult();
809 EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); 809 EXPECT_EQ(ERR_EMPTY_RESPONSE, rv);
810 } 810 }
811 811
812 // read_failure specifies a read failure that should cause the network 812 // read_failure specifies a read failure that should cause the network
813 // transaction to resend the request. 813 // transaction to resend the request.
814 void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( 814 void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest(
815 const MockRead& read_failure) { 815 const MockRead& read_failure) {
816 SessionDependencies session_deps;
817 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
818
819 HttpRequestInfo request; 816 HttpRequestInfo request;
820 request.method = "GET"; 817 request.method = "GET";
821 request.url = GURL("http://www.foo.com/"); 818 request.url = GURL("http://www.foo.com/");
822 request.load_flags = 0; 819 request.load_flags = 0;
823 820
821 SessionDependencies session_deps;
822 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
823
824 MockRead data1_reads[] = { 824 MockRead data1_reads[] = {
825 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), 825 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"),
826 MockRead("hello"), 826 MockRead("hello"),
827 read_failure, // Now, we reuse the connection and fail the first read. 827 read_failure, // Now, we reuse the connection and fail the first read.
828 }; 828 };
829 StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), NULL, 0); 829 StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), NULL, 0);
830 session_deps.socket_factory.AddSocketDataProvider(&data1); 830 session_deps.socket_factory.AddSocketDataProvider(&data1);
831 831
832 MockRead data2_reads[] = { 832 MockRead data2_reads[] = {
833 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), 833 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"),
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 MockRead read_failure(true, ERR_CONNECTION_RESET); 869 MockRead read_failure(true, ERR_CONNECTION_RESET);
870 KeepAliveConnectionResendRequestTest(read_failure); 870 KeepAliveConnectionResendRequestTest(read_failure);
871 } 871 }
872 872
873 TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { 873 TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) {
874 MockRead read_failure(false, OK); // EOF 874 MockRead read_failure(false, OK); // EOF
875 KeepAliveConnectionResendRequestTest(read_failure); 875 KeepAliveConnectionResendRequestTest(read_failure);
876 } 876 }
877 877
878 TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { 878 TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) {
879 SessionDependencies session_deps;
880 scoped_ptr<HttpTransaction> trans(
881 new HttpNetworkTransaction(CreateSession(&session_deps)));
882
883 HttpRequestInfo request; 879 HttpRequestInfo request;
884 request.method = "GET"; 880 request.method = "GET";
885 request.url = GURL("http://www.google.com/"); 881 request.url = GURL("http://www.google.com/");
886 request.load_flags = 0; 882 request.load_flags = 0;
887 883
884 SessionDependencies session_deps;
885 scoped_ptr<HttpTransaction> trans(
886 new HttpNetworkTransaction(CreateSession(&session_deps)));
887
888 MockRead data_reads[] = { 888 MockRead data_reads[] = {
889 MockRead(true, ERR_CONNECTION_RESET), 889 MockRead(true, ERR_CONNECTION_RESET),
890 MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used 890 MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used
891 MockRead("hello world"), 891 MockRead("hello world"),
892 MockRead(false, OK), 892 MockRead(false, OK),
893 }; 893 };
894 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 894 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
895 session_deps.socket_factory.AddSocketDataProvider(&data); 895 session_deps.socket_factory.AddSocketDataProvider(&data);
896 896
897 TestCompletionCallback callback; 897 TestCompletionCallback callback;
(...skipping 25 matching lines...) Expand all
923 MockRead(false, OK), 923 MockRead(false, OK),
924 }; 924 };
925 SimpleGetHelperResult out = SimpleGetHelper(data_reads, 925 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
926 arraysize(data_reads)); 926 arraysize(data_reads));
927 EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv); 927 EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv);
928 } 928 }
929 929
930 // Test that we correctly reuse a keep-alive connection after not explicitly 930 // Test that we correctly reuse a keep-alive connection after not explicitly
931 // reading the body. 931 // reading the body.
932 TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { 932 TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) {
933 SessionDependencies session_deps;
934 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
935
936 HttpRequestInfo request; 933 HttpRequestInfo request;
937 request.method = "GET"; 934 request.method = "GET";
938 request.url = GURL("http://www.foo.com/"); 935 request.url = GURL("http://www.foo.com/");
939 request.load_flags = 0; 936 request.load_flags = 0;
940 937
938 SessionDependencies session_deps;
939 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
940
941 // Note that because all these reads happen in the same 941 // Note that because all these reads happen in the same
942 // StaticSocketDataProvider, it shows that the same socket is being reused for 942 // StaticSocketDataProvider, it shows that the same socket is being reused for
943 // all transactions. 943 // all transactions.
944 MockRead data1_reads[] = { 944 MockRead data1_reads[] = {
945 MockRead("HTTP/1.1 204 No Content\r\n\r\n"), 945 MockRead("HTTP/1.1 204 No Content\r\n\r\n"),
946 MockRead("HTTP/1.1 205 Reset Content\r\n\r\n"), 946 MockRead("HTTP/1.1 205 Reset Content\r\n\r\n"),
947 MockRead("HTTP/1.1 304 Not Modified\r\n\r\n"), 947 MockRead("HTTP/1.1 304 Not Modified\r\n\r\n"),
948 MockRead("HTTP/1.1 302 Found\r\n" 948 MockRead("HTTP/1.1 302 Found\r\n"
949 "Content-Length: 0\r\n\r\n"), 949 "Content-Length: 0\r\n\r\n"),
950 MockRead("HTTP/1.1 302 Found\r\n" 950 MockRead("HTTP/1.1 302 Found\r\n"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 1018 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
1019 std::string response_data; 1019 std::string response_data;
1020 rv = ReadTransaction(trans.get(), &response_data); 1020 rv = ReadTransaction(trans.get(), &response_data);
1021 EXPECT_EQ(OK, rv); 1021 EXPECT_EQ(OK, rv);
1022 EXPECT_EQ("hello", response_data); 1022 EXPECT_EQ("hello", response_data);
1023 } 1023 }
1024 1024
1025 // Test the request-challenge-retry sequence for basic auth. 1025 // Test the request-challenge-retry sequence for basic auth.
1026 // (basic auth is the easiest to mock, because it has no randomness). 1026 // (basic auth is the easiest to mock, because it has no randomness).
1027 TEST_F(HttpNetworkTransactionTest, BasicAuth) { 1027 TEST_F(HttpNetworkTransactionTest, BasicAuth) {
1028 SessionDependencies session_deps;
1029 scoped_ptr<HttpTransaction> trans(
1030 new HttpNetworkTransaction(CreateSession(&session_deps)));
1031
1032 HttpRequestInfo request; 1028 HttpRequestInfo request;
1033 request.method = "GET"; 1029 request.method = "GET";
1034 request.url = GURL("http://www.google.com/"); 1030 request.url = GURL("http://www.google.com/");
1035 request.load_flags = 0; 1031 request.load_flags = 0;
1036 1032
1033 SessionDependencies session_deps;
1034 scoped_ptr<HttpTransaction> trans(
1035 new HttpNetworkTransaction(CreateSession(&session_deps)));
1036
1037 MockWrite data_writes1[] = { 1037 MockWrite data_writes1[] = {
1038 MockWrite("GET / HTTP/1.1\r\n" 1038 MockWrite("GET / HTTP/1.1\r\n"
1039 "Host: www.google.com\r\n" 1039 "Host: www.google.com\r\n"
1040 "Connection: keep-alive\r\n\r\n"), 1040 "Connection: keep-alive\r\n\r\n"),
1041 }; 1041 };
1042 1042
1043 MockRead data_reads1[] = { 1043 MockRead data_reads1[] = {
1044 MockRead("HTTP/1.0 401 Unauthorized\r\n"), 1044 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
1045 // Give a couple authenticate options (only the middle one is actually 1045 // Give a couple authenticate options (only the middle one is actually
1046 // supported). 1046 // supported).
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 rv = callback2.WaitForResult(); 1103 rv = callback2.WaitForResult();
1104 EXPECT_EQ(OK, rv); 1104 EXPECT_EQ(OK, rv);
1105 1105
1106 response = trans->GetResponseInfo(); 1106 response = trans->GetResponseInfo();
1107 EXPECT_FALSE(response == NULL); 1107 EXPECT_FALSE(response == NULL);
1108 EXPECT_TRUE(response->auth_challenge.get() == NULL); 1108 EXPECT_TRUE(response->auth_challenge.get() == NULL);
1109 EXPECT_EQ(100, response->headers->GetContentLength()); 1109 EXPECT_EQ(100, response->headers->GetContentLength());
1110 } 1110 }
1111 1111
1112 TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { 1112 TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) {
1113 SessionDependencies session_deps;
1114 scoped_ptr<HttpTransaction> trans(
1115 new HttpNetworkTransaction(CreateSession(&session_deps)));
1116
1117 HttpRequestInfo request; 1113 HttpRequestInfo request;
1118 request.method = "GET"; 1114 request.method = "GET";
1119 request.url = GURL("http://www.google.com/"); 1115 request.url = GURL("http://www.google.com/");
1120 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; 1116 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA;
1121 1117
1118 SessionDependencies session_deps;
1119 scoped_ptr<HttpTransaction> trans(
1120 new HttpNetworkTransaction(CreateSession(&session_deps)));
1121
1122 MockWrite data_writes[] = { 1122 MockWrite data_writes[] = {
1123 MockWrite("GET / HTTP/1.1\r\n" 1123 MockWrite("GET / HTTP/1.1\r\n"
1124 "Host: www.google.com\r\n" 1124 "Host: www.google.com\r\n"
1125 "Connection: keep-alive\r\n\r\n"), 1125 "Connection: keep-alive\r\n\r\n"),
1126 }; 1126 };
1127 1127
1128 MockRead data_reads[] = { 1128 MockRead data_reads[] = {
1129 MockRead("HTTP/1.0 401 Unauthorized\r\n"), 1129 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
1130 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), 1130 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
1131 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), 1131 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
(...skipping 14 matching lines...) Expand all
1146 EXPECT_EQ(0, rv); 1146 EXPECT_EQ(0, rv);
1147 1147
1148 const HttpResponseInfo* response = trans->GetResponseInfo(); 1148 const HttpResponseInfo* response = trans->GetResponseInfo();
1149 ASSERT_FALSE(response == NULL); 1149 ASSERT_FALSE(response == NULL);
1150 EXPECT_TRUE(response->auth_challenge.get() == NULL); 1150 EXPECT_TRUE(response->auth_challenge.get() == NULL);
1151 } 1151 }
1152 1152
1153 // Test the request-challenge-retry sequence for basic auth, over a keep-alive 1153 // Test the request-challenge-retry sequence for basic auth, over a keep-alive
1154 // connection. 1154 // connection.
1155 TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { 1155 TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) {
1156 SessionDependencies session_deps;
1157 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
1158
1159 HttpRequestInfo request; 1156 HttpRequestInfo request;
1160 request.method = "GET"; 1157 request.method = "GET";
1161 request.url = GURL("http://www.google.com/"); 1158 request.url = GURL("http://www.google.com/");
1162 request.load_flags = 0; 1159 request.load_flags = 0;
1163 1160
1161 SessionDependencies session_deps;
1162 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
1163
1164 MockWrite data_writes1[] = { 1164 MockWrite data_writes1[] = {
1165 MockWrite("GET / HTTP/1.1\r\n" 1165 MockWrite("GET / HTTP/1.1\r\n"
1166 "Host: www.google.com\r\n" 1166 "Host: www.google.com\r\n"
1167 "Connection: keep-alive\r\n\r\n"), 1167 "Connection: keep-alive\r\n\r\n"),
1168 1168
1169 // After calling trans->RestartWithAuth(), this is the request we should 1169 // After calling trans->RestartWithAuth(), this is the request we should
1170 // be issuing -- the final header line contains the credentials. 1170 // be issuing -- the final header line contains the credentials.
1171 MockWrite("GET / HTTP/1.1\r\n" 1171 MockWrite("GET / HTTP/1.1\r\n"
1172 "Host: www.google.com\r\n" 1172 "Host: www.google.com\r\n"
1173 "Connection: keep-alive\r\n" 1173 "Connection: keep-alive\r\n"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1221 1221
1222 response = trans->GetResponseInfo(); 1222 response = trans->GetResponseInfo();
1223 EXPECT_FALSE(response == NULL); 1223 EXPECT_FALSE(response == NULL);
1224 EXPECT_TRUE(response->auth_challenge.get() == NULL); 1224 EXPECT_TRUE(response->auth_challenge.get() == NULL);
1225 EXPECT_EQ(5, response->headers->GetContentLength()); 1225 EXPECT_EQ(5, response->headers->GetContentLength());
1226 } 1226 }
1227 1227
1228 // Test the request-challenge-retry sequence for basic auth, over a keep-alive 1228 // Test the request-challenge-retry sequence for basic auth, over a keep-alive
1229 // connection and with no response body to drain. 1229 // connection and with no response body to drain.
1230 TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { 1230 TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) {
1231 SessionDependencies session_deps;
1232 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
1233
1234 HttpRequestInfo request; 1231 HttpRequestInfo request;
1235 request.method = "GET"; 1232 request.method = "GET";
1236 request.url = GURL("http://www.google.com/"); 1233 request.url = GURL("http://www.google.com/");
1237 request.load_flags = 0; 1234 request.load_flags = 0;
1238 1235
1236 SessionDependencies session_deps;
1237 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
1238
1239 MockWrite data_writes1[] = { 1239 MockWrite data_writes1[] = {
1240 MockWrite("GET / HTTP/1.1\r\n" 1240 MockWrite("GET / HTTP/1.1\r\n"
1241 "Host: www.google.com\r\n" 1241 "Host: www.google.com\r\n"
1242 "Connection: keep-alive\r\n\r\n"), 1242 "Connection: keep-alive\r\n\r\n"),
1243 1243
1244 // After calling trans->RestartWithAuth(), this is the request we should 1244 // After calling trans->RestartWithAuth(), this is the request we should
1245 // be issuing -- the final header line contains the credentials. 1245 // be issuing -- the final header line contains the credentials.
1246 MockWrite("GET / HTTP/1.1\r\n" 1246 MockWrite("GET / HTTP/1.1\r\n"
1247 "Host: www.google.com\r\n" 1247 "Host: www.google.com\r\n"
1248 "Connection: keep-alive\r\n" 1248 "Connection: keep-alive\r\n"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 1294
1295 response = trans->GetResponseInfo(); 1295 response = trans->GetResponseInfo();
1296 EXPECT_FALSE(response == NULL); 1296 EXPECT_FALSE(response == NULL);
1297 EXPECT_TRUE(response->auth_challenge.get() == NULL); 1297 EXPECT_TRUE(response->auth_challenge.get() == NULL);
1298 EXPECT_EQ(5, response->headers->GetContentLength()); 1298 EXPECT_EQ(5, response->headers->GetContentLength());
1299 } 1299 }
1300 1300
1301 // Test the request-challenge-retry sequence for basic auth, over a keep-alive 1301 // Test the request-challenge-retry sequence for basic auth, over a keep-alive
1302 // connection and with a large response body to drain. 1302 // connection and with a large response body to drain.
1303 TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { 1303 TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) {
1304 SessionDependencies session_deps;
1305 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
1306
1307 HttpRequestInfo request; 1304 HttpRequestInfo request;
1308 request.method = "GET"; 1305 request.method = "GET";
1309 request.url = GURL("http://www.google.com/"); 1306 request.url = GURL("http://www.google.com/");
1310 request.load_flags = 0; 1307 request.load_flags = 0;
1311 1308
1309 SessionDependencies session_deps;
1310 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
1311
1312 MockWrite data_writes1[] = { 1312 MockWrite data_writes1[] = {
1313 MockWrite("GET / HTTP/1.1\r\n" 1313 MockWrite("GET / HTTP/1.1\r\n"
1314 "Host: www.google.com\r\n" 1314 "Host: www.google.com\r\n"
1315 "Connection: keep-alive\r\n\r\n"), 1315 "Connection: keep-alive\r\n\r\n"),
1316 1316
1317 // After calling trans->RestartWithAuth(), this is the request we should 1317 // After calling trans->RestartWithAuth(), this is the request we should
1318 // be issuing -- the final header line contains the credentials. 1318 // be issuing -- the final header line contains the credentials.
1319 MockWrite("GET / HTTP/1.1\r\n" 1319 MockWrite("GET / HTTP/1.1\r\n"
1320 "Host: www.google.com\r\n" 1320 "Host: www.google.com\r\n"
1321 "Connection: keep-alive\r\n" 1321 "Connection: keep-alive\r\n"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1375 1375
1376 response = trans->GetResponseInfo(); 1376 response = trans->GetResponseInfo();
1377 EXPECT_FALSE(response == NULL); 1377 EXPECT_FALSE(response == NULL);
1378 EXPECT_TRUE(response->auth_challenge.get() == NULL); 1378 EXPECT_TRUE(response->auth_challenge.get() == NULL);
1379 EXPECT_EQ(5, response->headers->GetContentLength()); 1379 EXPECT_EQ(5, response->headers->GetContentLength());
1380 } 1380 }
1381 1381
1382 // Test the request-challenge-retry sequence for basic auth, over a keep-alive 1382 // Test the request-challenge-retry sequence for basic auth, over a keep-alive
1383 // connection, but the server gets impatient and closes the connection. 1383 // connection, but the server gets impatient and closes the connection.
1384 TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { 1384 TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) {
1385 SessionDependencies session_deps;
1386 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
1387
1388 HttpRequestInfo request; 1385 HttpRequestInfo request;
1389 request.method = "GET"; 1386 request.method = "GET";
1390 request.url = GURL("http://www.google.com/"); 1387 request.url = GURL("http://www.google.com/");
1391 request.load_flags = 0; 1388 request.load_flags = 0;
1392 1389
1390 SessionDependencies session_deps;
1391 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
1392
1393 MockWrite data_writes1[] = { 1393 MockWrite data_writes1[] = {
1394 MockWrite("GET / HTTP/1.1\r\n" 1394 MockWrite("GET / HTTP/1.1\r\n"
1395 "Host: www.google.com\r\n" 1395 "Host: www.google.com\r\n"
1396 "Connection: keep-alive\r\n\r\n"), 1396 "Connection: keep-alive\r\n\r\n"),
1397 // This simulates the seemingly successful write to a closed connection 1397 // This simulates the seemingly successful write to a closed connection
1398 // if the bug is not fixed. 1398 // if the bug is not fixed.
1399 MockWrite("GET / HTTP/1.1\r\n" 1399 MockWrite("GET / HTTP/1.1\r\n"
1400 "Host: www.google.com\r\n" 1400 "Host: www.google.com\r\n"
1401 "Connection: keep-alive\r\n" 1401 "Connection: keep-alive\r\n"
1402 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), 1402 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1466 1466
1467 response = trans->GetResponseInfo(); 1467 response = trans->GetResponseInfo();
1468 ASSERT_FALSE(response == NULL); 1468 ASSERT_FALSE(response == NULL);
1469 EXPECT_TRUE(response->auth_challenge.get() == NULL); 1469 EXPECT_TRUE(response->auth_challenge.get() == NULL);
1470 EXPECT_EQ(5, response->headers->GetContentLength()); 1470 EXPECT_EQ(5, response->headers->GetContentLength());
1471 } 1471 }
1472 1472
1473 // Test the request-challenge-retry sequence for basic auth, over a connection 1473 // Test the request-challenge-retry sequence for basic auth, over a connection
1474 // that requires a restart when setting up an SSL tunnel. 1474 // that requires a restart when setting up an SSL tunnel.
1475 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAlive) { 1475 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAlive) {
1476 HttpRequestInfo request;
1477 request.method = "GET";
1478 request.url = GURL("https://www.google.com/");
1479 // when the no authentication data flag is set.
1480 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA;
1481
1476 // Configure against proxy server "myproxy:70". 1482 // Configure against proxy server "myproxy:70".
1477 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:70")); 1483 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:70"));
1478 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 1484 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
1479 session_deps.net_log = log.bound().net_log(); 1485 session_deps.net_log = log.bound().net_log();
1480 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 1486 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
1481 1487
1482 HttpRequestInfo request;
1483 request.method = "GET";
1484 request.url = GURL("https://www.google.com/");
1485 // when the no authentication data flag is set.
1486 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA;
1487
1488 // Since we have proxy, should try to establish tunnel. 1488 // Since we have proxy, should try to establish tunnel.
1489 MockWrite data_writes1[] = { 1489 MockWrite data_writes1[] = {
1490 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" 1490 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
1491 "Host: www.google.com\r\n" 1491 "Host: www.google.com\r\n"
1492 "Proxy-Connection: keep-alive\r\n\r\n"), 1492 "Proxy-Connection: keep-alive\r\n\r\n"),
1493 1493
1494 // After calling trans->RestartWithAuth(), this is the request we should 1494 // After calling trans->RestartWithAuth(), this is the request we should
1495 // be issuing -- the final header line contains the credentials. 1495 // be issuing -- the final header line contains the credentials.
1496 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" 1496 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
1497 "Host: www.google.com\r\n" 1497 "Host: www.google.com\r\n"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1576 // The password prompt info should not be set. 1576 // The password prompt info should not be set.
1577 EXPECT_TRUE(response->auth_challenge.get() == NULL); 1577 EXPECT_TRUE(response->auth_challenge.get() == NULL);
1578 1578
1579 trans.reset(); 1579 trans.reset();
1580 session->FlushSocketPools(); 1580 session->FlushSocketPools();
1581 } 1581 }
1582 1582
1583 // Test the request-challenge-retry sequence for basic auth, over a keep-alive 1583 // Test the request-challenge-retry sequence for basic auth, over a keep-alive
1584 // proxy connection, when setting up an SSL tunnel. 1584 // proxy connection, when setting up an SSL tunnel.
1585 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAlive) { 1585 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAlive) {
1586 HttpRequestInfo request;
1587 request.method = "GET";
1588 request.url = GURL("https://www.google.com/");
1589 // Ensure that proxy authentication is attempted even
1590 // when the no authentication data flag is set.
1591 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA;
1592
1586 // Configure against proxy server "myproxy:70". 1593 // Configure against proxy server "myproxy:70".
1587 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:70")); 1594 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:70"));
1588 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 1595 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
1589 session_deps.net_log = log.bound().net_log(); 1596 session_deps.net_log = log.bound().net_log();
1590 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 1597 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
1591 1598
1592 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); 1599 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
1593 1600
1594 HttpRequestInfo request;
1595 request.method = "GET";
1596 request.url = GURL("https://www.google.com/");
1597 // Ensure that proxy authentication is attempted even
1598 // when the no authentication data flag is set.
1599 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA;
1600
1601 // Since we have proxy, should try to establish tunnel. 1601 // Since we have proxy, should try to establish tunnel.
1602 MockWrite data_writes1[] = { 1602 MockWrite data_writes1[] = {
1603 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" 1603 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
1604 "Host: www.google.com\r\n" 1604 "Host: www.google.com\r\n"
1605 "Proxy-Connection: keep-alive\r\n\r\n"), 1605 "Proxy-Connection: keep-alive\r\n\r\n"),
1606 1606
1607 // After calling trans->RestartWithAuth(), this is the request we should 1607 // After calling trans->RestartWithAuth(), this is the request we should
1608 // be issuing -- the final header line contains the credentials. 1608 // be issuing -- the final header line contains the credentials.
1609 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" 1609 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
1610 "Host: www.google.com\r\n" 1610 "Host: www.google.com\r\n"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1690 EXPECT_EQ(L"basic", response->auth_challenge->scheme); 1690 EXPECT_EQ(L"basic", response->auth_challenge->scheme);
1691 1691
1692 // Flush the idle socket before the NetLog and HttpNetworkTransaction go 1692 // Flush the idle socket before the NetLog and HttpNetworkTransaction go
1693 // out of scope. 1693 // out of scope.
1694 session->FlushSocketPools(); 1694 session->FlushSocketPools();
1695 } 1695 }
1696 1696
1697 // Test that we don't read the response body when we fail to establish a tunnel, 1697 // Test that we don't read the response body when we fail to establish a tunnel,
1698 // even if the user cancels the proxy's auth attempt. 1698 // even if the user cancels the proxy's auth attempt.
1699 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { 1699 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) {
1700 HttpRequestInfo request;
1701 request.method = "GET";
1702 request.url = GURL("https://www.google.com/");
1703 request.load_flags = 0;
1704
1700 // Configure against proxy server "myproxy:70". 1705 // Configure against proxy server "myproxy:70".
1701 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:70")); 1706 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:70"));
1702 1707
1703 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 1708 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
1704 1709
1705 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); 1710 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
1706 1711
1707 HttpRequestInfo request;
1708 request.method = "GET";
1709 request.url = GURL("https://www.google.com/");
1710 request.load_flags = 0;
1711
1712 // Since we have proxy, should try to establish tunnel. 1712 // Since we have proxy, should try to establish tunnel.
1713 MockWrite data_writes[] = { 1713 MockWrite data_writes[] = {
1714 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" 1714 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
1715 "Host: www.google.com\r\n" 1715 "Host: www.google.com\r\n"
1716 "Proxy-Connection: keep-alive\r\n\r\n"), 1716 "Proxy-Connection: keep-alive\r\n\r\n"),
1717 }; 1717 };
1718 1718
1719 // The proxy responds to the connect with a 407. 1719 // The proxy responds to the connect with a 407.
1720 MockRead data_reads[] = { 1720 MockRead data_reads[] = {
1721 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), 1721 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
(...skipping 26 matching lines...) Expand all
1748 rv = ReadTransaction(trans.get(), &response_data); 1748 rv = ReadTransaction(trans.get(), &response_data);
1749 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); 1749 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv);
1750 1750
1751 // Flush the idle socket before the HttpNetworkTransaction goes out of scope. 1751 // Flush the idle socket before the HttpNetworkTransaction goes out of scope.
1752 session->FlushSocketPools(); 1752 session->FlushSocketPools();
1753 } 1753 }
1754 1754
1755 // Test when a server (non-proxy) returns a 407 (proxy-authenticate). 1755 // Test when a server (non-proxy) returns a 407 (proxy-authenticate).
1756 // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. 1756 // The request should fail with ERR_UNEXPECTED_PROXY_AUTH.
1757 TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { 1757 TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) {
1758 HttpRequestInfo request;
1759 request.method = "GET";
1760 request.url = GURL("http://www.google.com/");
1761 request.load_flags = 0;
1762
1758 // We are using a DIRECT connection (i.e. no proxy) for this session. 1763 // We are using a DIRECT connection (i.e. no proxy) for this session.
1759 SessionDependencies session_deps; 1764 SessionDependencies session_deps;
1760 scoped_ptr<HttpTransaction> trans( 1765 scoped_ptr<HttpTransaction> trans(
1761 new HttpNetworkTransaction(CreateSession(&session_deps))); 1766 new HttpNetworkTransaction(CreateSession(&session_deps)));
1762 1767
1763 HttpRequestInfo request;
1764 request.method = "GET";
1765 request.url = GURL("http://www.google.com/");
1766 request.load_flags = 0;
1767
1768 MockWrite data_writes1[] = { 1768 MockWrite data_writes1[] = {
1769 MockWrite("GET / HTTP/1.1\r\n" 1769 MockWrite("GET / HTTP/1.1\r\n"
1770 "Host: www.google.com\r\n" 1770 "Host: www.google.com\r\n"
1771 "Connection: keep-alive\r\n\r\n"), 1771 "Connection: keep-alive\r\n\r\n"),
1772 }; 1772 };
1773 1773
1774 MockRead data_reads1[] = { 1774 MockRead data_reads1[] = {
1775 MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), 1775 MockRead("HTTP/1.0 407 Proxy Auth required\r\n"),
1776 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), 1776 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
1777 // Large content-length -- won't matter, as connection will be reset. 1777 // Large content-length -- won't matter, as connection will be reset.
(...skipping 15 matching lines...) Expand all
1793 } 1793 }
1794 1794
1795 // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) 1795 // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication)
1796 // through a non-authenticating proxy. The request should fail with 1796 // through a non-authenticating proxy. The request should fail with
1797 // ERR_UNEXPECTED_PROXY_AUTH. 1797 // ERR_UNEXPECTED_PROXY_AUTH.
1798 // Note that it is impossible to detect if an HTTP server returns a 407 through 1798 // Note that it is impossible to detect if an HTTP server returns a 407 through
1799 // a non-authenticating proxy - there is nothing to indicate whether the 1799 // a non-authenticating proxy - there is nothing to indicate whether the
1800 // response came from the proxy or the server, so it is treated as if the proxy 1800 // response came from the proxy or the server, so it is treated as if the proxy
1801 // issued the challenge. 1801 // issued the challenge.
1802 TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { 1802 TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) {
1803 HttpRequestInfo request;
1804 request.method = "GET";
1805 request.url = GURL("https://www.google.com/");
1806
1803 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:70")); 1807 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:70"));
1804 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 1808 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
1805 session_deps.net_log = log.bound().net_log(); 1809 session_deps.net_log = log.bound().net_log();
1806 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 1810 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
1807 1811
1808 HttpRequestInfo request;
1809 request.method = "GET";
1810 request.url = GURL("https://www.google.com/");
1811
1812 // Since we have proxy, should try to establish tunnel. 1812 // Since we have proxy, should try to establish tunnel.
1813 MockWrite data_writes1[] = { 1813 MockWrite data_writes1[] = {
1814 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" 1814 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
1815 "Host: www.google.com\r\n" 1815 "Host: www.google.com\r\n"
1816 "Proxy-Connection: keep-alive\r\n\r\n"), 1816 "Proxy-Connection: keep-alive\r\n\r\n"),
1817 1817
1818 MockWrite("GET / HTTP/1.1\r\n" 1818 MockWrite("GET / HTTP/1.1\r\n"
1819 "Host: www.google.com\r\n" 1819 "Host: www.google.com\r\n"
1820 "Connection: keep-alive\r\n\r\n"), 1820 "Connection: keep-alive\r\n\r\n"),
1821 }; 1821 };
(...skipping 28 matching lines...) Expand all
1850 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, 1850 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
1851 NetLog::PHASE_NONE); 1851 NetLog::PHASE_NONE);
1852 ExpectLogContainsSomewhere( 1852 ExpectLogContainsSomewhere(
1853 entries, pos, 1853 entries, pos,
1854 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, 1854 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
1855 NetLog::PHASE_NONE); 1855 NetLog::PHASE_NONE);
1856 } 1856 }
1857 1857
1858 // Test a simple get through an HTTPS Proxy. 1858 // Test a simple get through an HTTPS Proxy.
1859 TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { 1859 TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) {
1860 HttpRequestInfo request;
1861 request.method = "GET";
1862 request.url = GURL("http://www.google.com/");
1863
1860 // Configure against https proxy server "proxy:70". 1864 // Configure against https proxy server "proxy:70".
1861 SessionDependencies session_deps(ProxyService::CreateFixed("https://proxy:70") ); 1865 SessionDependencies session_deps(ProxyService::CreateFixed("https://proxy:70") );
1862 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 1866 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
1863 session_deps.net_log = log.bound().net_log(); 1867 session_deps.net_log = log.bound().net_log();
1864 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 1868 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
1865 1869
1866 HttpRequestInfo request;
1867 request.method = "GET";
1868 request.url = GURL("http://www.google.com/");
1869
1870 // Since we have proxy, should use full url 1870 // Since we have proxy, should use full url
1871 MockWrite data_writes1[] = { 1871 MockWrite data_writes1[] = {
1872 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" 1872 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
1873 "Host: www.google.com\r\n" 1873 "Host: www.google.com\r\n"
1874 "Proxy-Connection: keep-alive\r\n\r\n"), 1874 "Proxy-Connection: keep-alive\r\n\r\n"),
1875 }; 1875 };
1876 1876
1877 MockRead data_reads1[] = { 1877 MockRead data_reads1[] = {
1878 MockRead("HTTP/1.1 200 OK\r\n"), 1878 MockRead("HTTP/1.1 200 OK\r\n"),
1879 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), 1879 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
(...skipping 24 matching lines...) Expand all
1904 EXPECT_EQ(200, response->headers->response_code()); 1904 EXPECT_EQ(200, response->headers->response_code());
1905 EXPECT_EQ(100, response->headers->GetContentLength()); 1905 EXPECT_EQ(100, response->headers->GetContentLength());
1906 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); 1906 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
1907 1907
1908 // The password prompt info should not be set. 1908 // The password prompt info should not be set.
1909 EXPECT_TRUE(response->auth_challenge.get() == NULL); 1909 EXPECT_TRUE(response->auth_challenge.get() == NULL);
1910 } 1910 }
1911 1911
1912 // Test a SPDY get through an HTTPS Proxy. 1912 // Test a SPDY get through an HTTPS Proxy.
1913 TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { 1913 TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) {
1914 HttpRequestInfo request;
1915 request.method = "GET";
1916 request.url = GURL("http://www.google.com/");
1917 request.load_flags = 0;
1918
1914 // Configure against https proxy server "proxy:70". 1919 // Configure against https proxy server "proxy:70".
1915 SessionDependencies session_deps(ProxyService::CreateFixed("https://proxy:70") ); 1920 SessionDependencies session_deps(ProxyService::CreateFixed("https://proxy:70") );
1916 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 1921 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
1917 session_deps.net_log = log.bound().net_log(); 1922 session_deps.net_log = log.bound().net_log();
1918 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 1923 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
1919 1924
1920 HttpRequestInfo request;
1921 request.method = "GET";
1922 request.url = GURL("http://www.google.com/");
1923 request.load_flags = 0;
1924
1925 // fetch http://www.google.com/ via SPDY 1925 // fetch http://www.google.com/ via SPDY
1926 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST, 1926 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST,
1927 false)); 1927 false));
1928 MockWrite spdy_writes[] = { CreateMockWrite(*req) }; 1928 MockWrite spdy_writes[] = { CreateMockWrite(*req) };
1929 1929
1930 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); 1930 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1));
1931 scoped_ptr<spdy::SpdyFrame> data(ConstructSpdyBodyFrame(1, true)); 1931 scoped_ptr<spdy::SpdyFrame> data(ConstructSpdyBodyFrame(1, true));
1932 MockRead spdy_reads[] = { 1932 MockRead spdy_reads[] = {
1933 CreateMockRead(*resp), 1933 CreateMockRead(*resp),
1934 CreateMockRead(*data), 1934 CreateMockRead(*data),
(...skipping 28 matching lines...) Expand all
1963 ASSERT_TRUE(response->headers != NULL); 1963 ASSERT_TRUE(response->headers != NULL);
1964 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 1964 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
1965 1965
1966 std::string response_data; 1966 std::string response_data;
1967 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); 1967 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
1968 EXPECT_EQ(net::kUploadData, response_data); 1968 EXPECT_EQ(net::kUploadData, response_data);
1969 } 1969 }
1970 1970
1971 // Test a SPDY get through an HTTPS Proxy. 1971 // Test a SPDY get through an HTTPS Proxy.
1972 TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { 1972 TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) {
1973 HttpRequestInfo request;
1974 request.method = "GET";
1975 request.url = GURL("http://www.google.com/");
1976 request.load_flags = 0;
1977
1973 // Configure against https proxy server "proxy:70". 1978 // Configure against https proxy server "proxy:70".
1974 SessionDependencies session_deps( 1979 SessionDependencies session_deps(
1975 ProxyService::CreateFixed("https://proxy:70")); 1980 ProxyService::CreateFixed("https://proxy:70"));
1976 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 1981 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
1977 session_deps.net_log = log.bound().net_log(); 1982 session_deps.net_log = log.bound().net_log();
1978 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 1983 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
1979 1984
1980 HttpRequestInfo request;
1981 request.method = "GET";
1982 request.url = GURL("http://www.google.com/");
1983 request.load_flags = 0;
1984
1985 // The first request will be a bare GET, the second request will be a 1985 // The first request will be a bare GET, the second request will be a
1986 // GET with a Proxy-Authorization header. 1986 // GET with a Proxy-Authorization header.
1987 scoped_ptr<spdy::SpdyFrame> req_get( 1987 scoped_ptr<spdy::SpdyFrame> req_get(
1988 ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); 1988 ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false));
1989 const char* const kExtraAuthorizationHeaders[] = { 1989 const char* const kExtraAuthorizationHeaders[] = {
1990 "proxy-authorization", 1990 "proxy-authorization",
1991 "Basic Zm9vOmJhcg==", 1991 "Basic Zm9vOmJhcg==",
1992 }; 1992 };
1993 scoped_ptr<spdy::SpdyFrame> req_get_authorization( 1993 scoped_ptr<spdy::SpdyFrame> req_get_authorization(
1994 ConstructSpdyGet( 1994 ConstructSpdyGet(
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
2070 2070
2071 ASSERT_TRUE(response_restart != NULL); 2071 ASSERT_TRUE(response_restart != NULL);
2072 ASSERT_TRUE(response_restart->headers != NULL); 2072 ASSERT_TRUE(response_restart->headers != NULL);
2073 EXPECT_EQ(200, response_restart->headers->response_code()); 2073 EXPECT_EQ(200, response_restart->headers->response_code());
2074 // The password prompt info should not be set. 2074 // The password prompt info should not be set.
2075 EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); 2075 EXPECT_TRUE(response_restart->auth_challenge.get() == NULL);
2076 } 2076 }
2077 2077
2078 // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. 2078 // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server.
2079 TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { 2079 TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) {
2080 HttpRequestInfo request;
2081 request.method = "GET";
2082 request.url = GURL("https://www.google.com/");
2083 request.load_flags = 0;
2084
2080 // Configure against https proxy server "proxy:70". 2085 // Configure against https proxy server "proxy:70".
2081 SessionDependencies session_deps(ProxyService::CreateFixed("https://proxy:70") ); 2086 SessionDependencies session_deps(ProxyService::CreateFixed("https://proxy:70") );
2082 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 2087 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
2083 session_deps.net_log = log.bound().net_log(); 2088 session_deps.net_log = log.bound().net_log();
2084 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 2089 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
2085 2090
2086 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); 2091 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
2087 2092
2088 HttpRequestInfo request;
2089 request.method = "GET";
2090 request.url = GURL("https://www.google.com/");
2091 request.load_flags = 0;
2092
2093 // CONNECT to www.google.com:443 via SPDY 2093 // CONNECT to www.google.com:443 via SPDY
2094 scoped_ptr<spdy::SpdyFrame> connect(ConstructSpdyConnect(NULL, 0, 1)); 2094 scoped_ptr<spdy::SpdyFrame> connect(ConstructSpdyConnect(NULL, 0, 1));
2095 // fetch https://www.google.com/ via HTTP 2095 // fetch https://www.google.com/ via HTTP
2096 2096
2097 const char get[] = "GET / HTTP/1.1\r\n" 2097 const char get[] = "GET / HTTP/1.1\r\n"
2098 "Host: www.google.com\r\n" 2098 "Host: www.google.com\r\n"
2099 "Connection: keep-alive\r\n\r\n"; 2099 "Connection: keep-alive\r\n\r\n";
2100 scoped_ptr<spdy::SpdyFrame> wrapped_get( 2100 scoped_ptr<spdy::SpdyFrame> wrapped_get(
2101 ConstructSpdyBodyFrame(1, get, strlen(get), false)); 2101 ConstructSpdyBodyFrame(1, get, strlen(get), false));
2102 MockWrite spdy_writes[] = { 2102 MockWrite spdy_writes[] = {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2148 ASSERT_TRUE(response->headers != NULL); 2148 ASSERT_TRUE(response->headers != NULL);
2149 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 2149 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
2150 2150
2151 std::string response_data; 2151 std::string response_data;
2152 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); 2152 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
2153 EXPECT_EQ("1234567890", response_data); 2153 EXPECT_EQ("1234567890", response_data);
2154 } 2154 }
2155 2155
2156 // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. 2156 // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server.
2157 TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { 2157 TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) {
2158 HttpRequestInfo request;
2159 request.method = "GET";
2160 request.url = GURL("https://www.google.com/");
2161 request.load_flags = 0;
2162
2158 // Configure against https proxy server "proxy:70". 2163 // Configure against https proxy server "proxy:70".
2159 SessionDependencies session_deps(ProxyService::CreateFixed("https://proxy:70") ); 2164 SessionDependencies session_deps(ProxyService::CreateFixed("https://proxy:70") );
2160 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 2165 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
2161 session_deps.net_log = log.bound().net_log(); 2166 session_deps.net_log = log.bound().net_log();
2162 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 2167 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
2163 2168
2164 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); 2169 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
2165 2170
2166 HttpRequestInfo request;
2167 request.method = "GET";
2168 request.url = GURL("https://www.google.com/");
2169 request.load_flags = 0;
2170
2171 // CONNECT to www.google.com:443 via SPDY 2171 // CONNECT to www.google.com:443 via SPDY
2172 scoped_ptr<spdy::SpdyFrame> connect(ConstructSpdyConnect(NULL, 0, 1)); 2172 scoped_ptr<spdy::SpdyFrame> connect(ConstructSpdyConnect(NULL, 0, 1));
2173 // fetch https://www.google.com/ via SPDY 2173 // fetch https://www.google.com/ via SPDY
2174 const char* const kMyUrl = "https://www.google.com/"; 2174 const char* const kMyUrl = "https://www.google.com/";
2175 scoped_ptr<spdy::SpdyFrame> get(ConstructSpdyGet(kMyUrl, false, 1, LOWEST)); 2175 scoped_ptr<spdy::SpdyFrame> get(ConstructSpdyGet(kMyUrl, false, 1, LOWEST));
2176 scoped_ptr<spdy::SpdyFrame> wrapped_get(ConstructWrappedSpdyFrame(get, 1)); 2176 scoped_ptr<spdy::SpdyFrame> wrapped_get(ConstructWrappedSpdyFrame(get, 1));
2177 MockWrite spdy_writes[] = { 2177 MockWrite spdy_writes[] = {
2178 CreateMockWrite(*connect, 1), 2178 CreateMockWrite(*connect, 1),
2179 CreateMockWrite(*wrapped_get, 3) 2179 CreateMockWrite(*wrapped_get, 3)
2180 }; 2180 };
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2222 ASSERT_TRUE(response->headers != NULL); 2222 ASSERT_TRUE(response->headers != NULL);
2223 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 2223 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
2224 2224
2225 std::string response_data; 2225 std::string response_data;
2226 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); 2226 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
2227 EXPECT_EQ(net::kUploadData, response_data); 2227 EXPECT_EQ(net::kUploadData, response_data);
2228 } 2228 }
2229 2229
2230 // Test a SPDY CONNECT failure through an HTTPS Proxy. 2230 // Test a SPDY CONNECT failure through an HTTPS Proxy.
2231 TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { 2231 TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) {
2232 HttpRequestInfo request;
2233 request.method = "GET";
2234 request.url = GURL("https://www.google.com/");
2235 request.load_flags = 0;
2236
2232 // Configure against https proxy server "proxy:70". 2237 // Configure against https proxy server "proxy:70".
2233 SessionDependencies session_deps(ProxyService::CreateFixed("https://proxy:70") ); 2238 SessionDependencies session_deps(ProxyService::CreateFixed("https://proxy:70") );
2234 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 2239 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
2235 session_deps.net_log = log.bound().net_log(); 2240 session_deps.net_log = log.bound().net_log();
2236 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 2241 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
2237 2242
2238 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); 2243 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
2239 2244
2240 HttpRequestInfo request;
2241 request.method = "GET";
2242 request.url = GURL("https://www.google.com/");
2243 request.load_flags = 0;
2244
2245 // CONNECT to www.google.com:443 via SPDY 2245 // CONNECT to www.google.com:443 via SPDY
2246 scoped_ptr<spdy::SpdyFrame> connect(ConstructSpdyConnect(NULL, 0, 1)); 2246 scoped_ptr<spdy::SpdyFrame> connect(ConstructSpdyConnect(NULL, 0, 1));
2247 scoped_ptr<spdy::SpdyFrame> get(ConstructSpdyRstStream(1, spdy::CANCEL)); 2247 scoped_ptr<spdy::SpdyFrame> get(ConstructSpdyRstStream(1, spdy::CANCEL));
2248 2248
2249 MockWrite spdy_writes[] = { 2249 MockWrite spdy_writes[] = {
2250 CreateMockWrite(*connect, 1), 2250 CreateMockWrite(*connect, 1),
2251 CreateMockWrite(*get, 3), 2251 CreateMockWrite(*get, 3),
2252 }; 2252 };
2253 2253
2254 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdySynReplyError(1)); 2254 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdySynReplyError(1));
(...skipping 28 matching lines...) Expand all
2283 rv = callback1.WaitForResult(); 2283 rv = callback1.WaitForResult();
2284 EXPECT_EQ(OK, rv); 2284 EXPECT_EQ(OK, rv);
2285 2285
2286 const HttpResponseInfo* response = trans->GetResponseInfo(); 2286 const HttpResponseInfo* response = trans->GetResponseInfo();
2287 ASSERT_FALSE(response == NULL); 2287 ASSERT_FALSE(response == NULL);
2288 EXPECT_EQ(500, response->headers->response_code()); 2288 EXPECT_EQ(500, response->headers->response_code());
2289 } 2289 }
2290 2290
2291 // Test the challenge-response-retry sequence through an HTTPS Proxy 2291 // Test the challenge-response-retry sequence through an HTTPS Proxy
2292 TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { 2292 TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) {
2293 HttpRequestInfo request;
2294 request.method = "GET";
2295 request.url = GURL("http://www.google.com/");
2296 // when the no authentication data flag is set.
2297 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA;
2298
2293 // Configure against https proxy server "proxy:70". 2299 // Configure against https proxy server "proxy:70".
2294 SessionDependencies session_deps(ProxyService::CreateFixed("https://proxy:70") ); 2300 SessionDependencies session_deps(ProxyService::CreateFixed("https://proxy:70") );
2295 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 2301 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
2296 session_deps.net_log = log.bound().net_log(); 2302 session_deps.net_log = log.bound().net_log();
2297 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 2303 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
2298 2304
2299 HttpRequestInfo request;
2300 request.method = "GET";
2301 request.url = GURL("http://www.google.com/");
2302 // when the no authentication data flag is set.
2303 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA;
2304
2305 // Since we have proxy, should use full url 2305 // Since we have proxy, should use full url
2306 MockWrite data_writes1[] = { 2306 MockWrite data_writes1[] = {
2307 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" 2307 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
2308 "Host: www.google.com\r\n" 2308 "Host: www.google.com\r\n"
2309 "Proxy-Connection: keep-alive\r\n\r\n"), 2309 "Proxy-Connection: keep-alive\r\n\r\n"),
2310 2310
2311 // After calling trans->RestartWithAuth(), this is the request we should 2311 // After calling trans->RestartWithAuth(), this is the request we should
2312 // be issuing -- the final header line contains the credentials. 2312 // be issuing -- the final header line contains the credentials.
2313 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" 2313 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
2314 "Host: www.google.com\r\n" 2314 "Host: www.google.com\r\n"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
2375 EXPECT_EQ(200, response->headers->response_code()); 2375 EXPECT_EQ(200, response->headers->response_code());
2376 EXPECT_EQ(100, response->headers->GetContentLength()); 2376 EXPECT_EQ(100, response->headers->GetContentLength());
2377 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); 2377 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
2378 2378
2379 // The password prompt info should not be set. 2379 // The password prompt info should not be set.
2380 EXPECT_TRUE(response->auth_challenge.get() == NULL); 2380 EXPECT_TRUE(response->auth_challenge.get() == NULL);
2381 } 2381 }
2382 2382
2383 void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( 2383 void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus(
2384 const MockRead& status, int expected_status) { 2384 const MockRead& status, int expected_status) {
2385 HttpRequestInfo request;
2386 request.method = "GET";
2387 request.url = GURL("https://www.google.com/");
2388 request.load_flags = 0;
2389
2385 // Configure against proxy server "myproxy:70". 2390 // Configure against proxy server "myproxy:70".
2386 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:70")); 2391 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:70"));
2387 2392
2388 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 2393 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
2389 2394
2390 HttpRequestInfo request;
2391 request.method = "GET";
2392 request.url = GURL("https://www.google.com/");
2393 request.load_flags = 0;
2394
2395 // Since we have proxy, should try to establish tunnel. 2395 // Since we have proxy, should try to establish tunnel.
2396 MockWrite data_writes[] = { 2396 MockWrite data_writes[] = {
2397 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" 2397 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
2398 "Host: www.google.com\r\n" 2398 "Host: www.google.com\r\n"
2399 "Proxy-Connection: keep-alive\r\n\r\n"), 2399 "Proxy-Connection: keep-alive\r\n\r\n"),
2400 }; 2400 };
2401 2401
2402 MockRead data_reads[] = { 2402 MockRead data_reads[] = {
2403 status, 2403 status,
2404 MockRead("Content-Length: 10\r\n\r\n"), 2404 MockRead("Content-Length: 10\r\n\r\n"),
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
2587 } 2587 }
2588 2588
2589 TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { 2589 TEST_F(HttpNetworkTransactionTest, ConnectStatus505) {
2590 ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); 2590 ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n"));
2591 } 2591 }
2592 2592
2593 // Test the flow when both the proxy server AND origin server require 2593 // Test the flow when both the proxy server AND origin server require
2594 // authentication. Again, this uses basic auth for both since that is 2594 // authentication. Again, this uses basic auth for both since that is
2595 // the simplest to mock. 2595 // the simplest to mock.
2596 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { 2596 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) {
2597 HttpRequestInfo request;
2598 request.method = "GET";
2599 request.url = GURL("http://www.google.com/");
2600 request.load_flags = 0;
2601
2597 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:70")); 2602 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:70"));
2598 2603
2599 // Configure against proxy server "myproxy:70". 2604 // Configure against proxy server "myproxy:70".
2600 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( 2605 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(
2601 CreateSession(&session_deps))); 2606 CreateSession(&session_deps)));
2602 2607
2603 HttpRequestInfo request;
2604 request.method = "GET";
2605 request.url = GURL("http://www.google.com/");
2606 request.load_flags = 0;
2607
2608 MockWrite data_writes1[] = { 2608 MockWrite data_writes1[] = {
2609 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" 2609 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
2610 "Host: www.google.com\r\n" 2610 "Host: www.google.com\r\n"
2611 "Proxy-Connection: keep-alive\r\n\r\n"), 2611 "Proxy-Connection: keep-alive\r\n\r\n"),
2612 }; 2612 };
2613 2613
2614 MockRead data_reads1[] = { 2614 MockRead data_reads1[] = {
2615 MockRead("HTTP/1.0 407 Unauthorized\r\n"), 2615 MockRead("HTTP/1.0 407 Unauthorized\r\n"),
2616 // Give a couple authenticate options (only the middle one is actually 2616 // Give a couple authenticate options (only the middle one is actually
2617 // supported). 2617 // supported).
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
2724 // For the NTLM implementation using SSPI, we skip the NTLM tests since we 2724 // For the NTLM implementation using SSPI, we skip the NTLM tests since we
2725 // can't hook into its internals to cause it to generate predictable NTLM 2725 // can't hook into its internals to cause it to generate predictable NTLM
2726 // authorization headers. 2726 // authorization headers.
2727 #if defined(NTLM_PORTABLE) 2727 #if defined(NTLM_PORTABLE)
2728 // The NTLM authentication unit tests were generated by capturing the HTTP 2728 // The NTLM authentication unit tests were generated by capturing the HTTP
2729 // requests and responses using Fiddler 2 and inspecting the generated random 2729 // requests and responses using Fiddler 2 and inspecting the generated random
2730 // bytes in the debugger. 2730 // bytes in the debugger.
2731 2731
2732 // Enter the correct password and authenticate successfully. 2732 // Enter the correct password and authenticate successfully.
2733 TEST_F(HttpNetworkTransactionTest, NTLMAuth1) { 2733 TEST_F(HttpNetworkTransactionTest, NTLMAuth1) {
2734 HttpRequestInfo request;
2735 request.method = "GET";
2736 request.url = GURL("http://172.22.68.17/kids/login.aspx");
2737 request.load_flags = 0;
2738
2734 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, 2739 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1,
2735 MockGetHostName); 2740 MockGetHostName);
2736 SessionDependencies session_deps; 2741 SessionDependencies session_deps;
2737 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 2742 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
2738 2743
2739 HttpRequestInfo request;
2740 request.method = "GET";
2741 request.url = GURL("http://172.22.68.17/kids/login.aspx");
2742 request.load_flags = 0;
2743
2744 MockWrite data_writes1[] = { 2744 MockWrite data_writes1[] = {
2745 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" 2745 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n"
2746 "Host: 172.22.68.17\r\n" 2746 "Host: 172.22.68.17\r\n"
2747 "Connection: keep-alive\r\n\r\n"), 2747 "Connection: keep-alive\r\n\r\n"),
2748 }; 2748 };
2749 2749
2750 MockRead data_reads1[] = { 2750 MockRead data_reads1[] = {
2751 MockRead("HTTP/1.1 401 Access Denied\r\n"), 2751 MockRead("HTTP/1.1 401 Access Denied\r\n"),
2752 // Negotiate and NTLM are often requested together. However, we only want 2752 // Negotiate and NTLM are often requested together. However, we only want
2753 // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip 2753 // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
2852 2852
2853 response = trans->GetResponseInfo(); 2853 response = trans->GetResponseInfo();
2854 ASSERT_FALSE(response == NULL); 2854 ASSERT_FALSE(response == NULL);
2855 2855
2856 EXPECT_TRUE(response->auth_challenge.get() == NULL); 2856 EXPECT_TRUE(response->auth_challenge.get() == NULL);
2857 EXPECT_EQ(13, response->headers->GetContentLength()); 2857 EXPECT_EQ(13, response->headers->GetContentLength());
2858 } 2858 }
2859 2859
2860 // Enter a wrong password, and then the correct one. 2860 // Enter a wrong password, and then the correct one.
2861 TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { 2861 TEST_F(HttpNetworkTransactionTest, NTLMAuth2) {
2862 HttpRequestInfo request;
2863 request.method = "GET";
2864 request.url = GURL("http://172.22.68.17/kids/login.aspx");
2865 request.load_flags = 0;
2866
2862 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, 2867 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2,
2863 MockGetHostName); 2868 MockGetHostName);
2864 SessionDependencies session_deps; 2869 SessionDependencies session_deps;
2865 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 2870 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
2866 2871
2867 HttpRequestInfo request;
2868 request.method = "GET";
2869 request.url = GURL("http://172.22.68.17/kids/login.aspx");
2870 request.load_flags = 0;
2871
2872 MockWrite data_writes1[] = { 2872 MockWrite data_writes1[] = {
2873 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" 2873 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n"
2874 "Host: 172.22.68.17\r\n" 2874 "Host: 172.22.68.17\r\n"
2875 "Connection: keep-alive\r\n\r\n"), 2875 "Connection: keep-alive\r\n\r\n"),
2876 }; 2876 };
2877 2877
2878 MockRead data_reads1[] = { 2878 MockRead data_reads1[] = {
2879 MockRead("HTTP/1.1 401 Access Denied\r\n"), 2879 MockRead("HTTP/1.1 401 Access Denied\r\n"),
2880 // Negotiate and NTLM are often requested together. However, we only want 2880 // Negotiate and NTLM are often requested together. However, we only want
2881 // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip 2881 // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
3059 response = trans->GetResponseInfo(); 3059 response = trans->GetResponseInfo();
3060 EXPECT_TRUE(response->auth_challenge.get() == NULL); 3060 EXPECT_TRUE(response->auth_challenge.get() == NULL);
3061 EXPECT_EQ(13, response->headers->GetContentLength()); 3061 EXPECT_EQ(13, response->headers->GetContentLength());
3062 } 3062 }
3063 #endif // NTLM_PORTABLE 3063 #endif // NTLM_PORTABLE
3064 3064
3065 // Test reading a server response which has only headers, and no body. 3065 // Test reading a server response which has only headers, and no body.
3066 // After some maximum number of bytes is consumed, the transaction should 3066 // After some maximum number of bytes is consumed, the transaction should
3067 // fail with ERR_RESPONSE_HEADERS_TOO_BIG. 3067 // fail with ERR_RESPONSE_HEADERS_TOO_BIG.
3068 TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { 3068 TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) {
3069 SessionDependencies session_deps;
3070 scoped_ptr<HttpTransaction> trans(
3071 new HttpNetworkTransaction(CreateSession(&session_deps)));
3072
3073 HttpRequestInfo request; 3069 HttpRequestInfo request;
3074 request.method = "GET"; 3070 request.method = "GET";
3075 request.url = GURL("http://www.google.com/"); 3071 request.url = GURL("http://www.google.com/");
3076 request.load_flags = 0; 3072 request.load_flags = 0;
3077 3073
3074 SessionDependencies session_deps;
3075 scoped_ptr<HttpTransaction> trans(
3076 new HttpNetworkTransaction(CreateSession(&session_deps)));
3077
3078 // Respond with 300 kb of headers (we should fail after 256 kb). 3078 // Respond with 300 kb of headers (we should fail after 256 kb).
3079 std::string large_headers_string; 3079 std::string large_headers_string;
3080 FillLargeHeadersString(&large_headers_string, 300 * 1024); 3080 FillLargeHeadersString(&large_headers_string, 300 * 1024);
3081 3081
3082 MockRead data_reads[] = { 3082 MockRead data_reads[] = {
3083 MockRead("HTTP/1.0 200 OK\r\n"), 3083 MockRead("HTTP/1.0 200 OK\r\n"),
3084 MockRead(true, large_headers_string.data(), large_headers_string.size()), 3084 MockRead(true, large_headers_string.data(), large_headers_string.size()),
3085 MockRead("\r\nBODY"), 3085 MockRead("\r\nBODY"),
3086 MockRead(false, OK), 3086 MockRead(false, OK),
3087 }; 3087 };
3088 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 3088 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
3089 session_deps.socket_factory.AddSocketDataProvider(&data); 3089 session_deps.socket_factory.AddSocketDataProvider(&data);
3090 3090
3091 TestCompletionCallback callback; 3091 TestCompletionCallback callback;
3092 3092
3093 int rv = trans->Start(&request, &callback, BoundNetLog()); 3093 int rv = trans->Start(&request, &callback, BoundNetLog());
3094 EXPECT_EQ(ERR_IO_PENDING, rv); 3094 EXPECT_EQ(ERR_IO_PENDING, rv);
3095 3095
3096 rv = callback.WaitForResult(); 3096 rv = callback.WaitForResult();
3097 EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, rv); 3097 EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, rv);
3098 3098
3099 const HttpResponseInfo* response = trans->GetResponseInfo(); 3099 const HttpResponseInfo* response = trans->GetResponseInfo();
3100 EXPECT_TRUE(response == NULL); 3100 EXPECT_TRUE(response == NULL);
3101 } 3101 }
3102 3102
3103 // Make sure that we don't try to reuse a TCPClientSocket when failing to 3103 // Make sure that we don't try to reuse a TCPClientSocket when failing to
3104 // establish tunnel. 3104 // establish tunnel.
3105 // http://code.google.com/p/chromium/issues/detail?id=3772 3105 // http://code.google.com/p/chromium/issues/detail?id=3772
3106 TEST_F(HttpNetworkTransactionTest, DontRecycleTCPSocketForSSLTunnel) { 3106 TEST_F(HttpNetworkTransactionTest, DontRecycleTCPSocketForSSLTunnel) {
3107 HttpRequestInfo request;
3108 request.method = "GET";
3109 request.url = GURL("https://www.google.com/");
3110 request.load_flags = 0;
3111
3107 // Configure against proxy server "myproxy:70". 3112 // Configure against proxy server "myproxy:70".
3108 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:70")); 3113 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:70"));
3109 3114
3110 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 3115 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
3111 3116
3112 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); 3117 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
3113 3118
3114 HttpRequestInfo request;
3115 request.method = "GET";
3116 request.url = GURL("https://www.google.com/");
3117 request.load_flags = 0;
3118
3119 // Since we have proxy, should try to establish tunnel. 3119 // Since we have proxy, should try to establish tunnel.
3120 MockWrite data_writes1[] = { 3120 MockWrite data_writes1[] = {
3121 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" 3121 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
3122 "Host: www.google.com\r\n" 3122 "Host: www.google.com\r\n"
3123 "Proxy-Connection: keep-alive\r\n\r\n"), 3123 "Proxy-Connection: keep-alive\r\n\r\n"),
3124 }; 3124 };
3125 3125
3126 // The proxy responds to the connect with a 404, using a persistent 3126 // The proxy responds to the connect with a 404, using a persistent
3127 // connection. Usually a proxy would return 501 (not implemented), 3127 // connection. Usually a proxy would return 501 (not implemented),
3128 // or 200 (tunnel established). 3128 // or 200 (tunnel established).
(...skipping 26 matching lines...) Expand all
3155 // the pool. 3155 // the pool.
3156 EXPECT_EQ(0, session->tcp_socket_pool()->IdleSocketCount()); 3156 EXPECT_EQ(0, session->tcp_socket_pool()->IdleSocketCount());
3157 trans.reset(); 3157 trans.reset();
3158 MessageLoop::current()->RunAllPending(); 3158 MessageLoop::current()->RunAllPending();
3159 // Make sure that the socket didn't get recycled after calling the destructor. 3159 // Make sure that the socket didn't get recycled after calling the destructor.
3160 EXPECT_EQ(0, session->tcp_socket_pool()->IdleSocketCount()); 3160 EXPECT_EQ(0, session->tcp_socket_pool()->IdleSocketCount());
3161 } 3161 }
3162 3162
3163 // Make sure that we recycle a socket after reading all of the response body. 3163 // Make sure that we recycle a socket after reading all of the response body.
3164 TEST_F(HttpNetworkTransactionTest, RecycleSocket) { 3164 TEST_F(HttpNetworkTransactionTest, RecycleSocket) {
3165 HttpRequestInfo request;
3166 request.method = "GET";
3167 request.url = GURL("http://www.google.com/");
3168 request.load_flags = 0;
3169
3165 SessionDependencies session_deps; 3170 SessionDependencies session_deps;
3166 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 3171 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
3167 3172
3168 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); 3173 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
3169 3174
3170 HttpRequestInfo request;
3171 request.method = "GET";
3172 request.url = GURL("http://www.google.com/");
3173 request.load_flags = 0;
3174
3175 MockRead data_reads[] = { 3175 MockRead data_reads[] = {
3176 // A part of the response body is received with the response headers. 3176 // A part of the response body is received with the response headers.
3177 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), 3177 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"),
3178 // The rest of the response body is received in two parts. 3178 // The rest of the response body is received in two parts.
3179 MockRead("lo"), 3179 MockRead("lo"),
3180 MockRead(" world"), 3180 MockRead(" world"),
3181 MockRead("junk"), // Should not be read!! 3181 MockRead("junk"), // Should not be read!!
3182 MockRead(false, OK), 3182 MockRead(false, OK),
3183 }; 3183 };
3184 3184
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
3365 // added to the connection pool asynchronously with a PostTask. 3365 // added to the connection pool asynchronously with a PostTask.
3366 MessageLoop::current()->RunAllPending(); 3366 MessageLoop::current()->RunAllPending();
3367 3367
3368 // We now check to make sure the socket was added back to the pool. 3368 // We now check to make sure the socket was added back to the pool.
3369 EXPECT_EQ(1, session->ssl_socket_pool()->IdleSocketCount()); 3369 EXPECT_EQ(1, session->ssl_socket_pool()->IdleSocketCount());
3370 } 3370 }
3371 3371
3372 // Make sure that we recycle a socket after a zero-length response. 3372 // Make sure that we recycle a socket after a zero-length response.
3373 // http://crbug.com/9880 3373 // http://crbug.com/9880
3374 TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { 3374 TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) {
3375 SessionDependencies session_deps;
3376 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
3377
3378 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
3379
3380 HttpRequestInfo request; 3375 HttpRequestInfo request;
3381 request.method = "GET"; 3376 request.method = "GET";
3382 request.url = GURL("http://www.google.com/csi?v=3&s=web&action=&" 3377 request.url = GURL("http://www.google.com/csi?v=3&s=web&action=&"
3383 "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" 3378 "tran=undefined&ei=mAXcSeegAo-SMurloeUN&"
3384 "e=17259,18167,19592,19773,19981,20133,20173,20233&" 3379 "e=17259,18167,19592,19773,19981,20133,20173,20233&"
3385 "rt=prt.2642,ol.2649,xjs.2951"); 3380 "rt=prt.2642,ol.2649,xjs.2951");
3386 request.load_flags = 0; 3381 request.load_flags = 0;
3387 3382
3383 SessionDependencies session_deps;
3384 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
3385
3386 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
3387
3388 MockRead data_reads[] = { 3388 MockRead data_reads[] = {
3389 MockRead("HTTP/1.1 204 No Content\r\n" 3389 MockRead("HTTP/1.1 204 No Content\r\n"
3390 "Content-Length: 0\r\n" 3390 "Content-Length: 0\r\n"
3391 "Content-Type: text/html\r\n\r\n"), 3391 "Content-Type: text/html\r\n\r\n"),
3392 MockRead("junk"), // Should not be read!! 3392 MockRead("junk"), // Should not be read!!
3393 MockRead(false, OK), 3393 MockRead(false, OK),
3394 }; 3394 };
3395 3395
3396 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 3396 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
3397 session_deps.socket_factory.AddSocketDataProvider(&data); 3397 session_deps.socket_factory.AddSocketDataProvider(&data);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
3510 rv = ReadTransaction(trans.get(), &response_data); 3510 rv = ReadTransaction(trans.get(), &response_data);
3511 EXPECT_EQ(OK, rv); 3511 EXPECT_EQ(OK, rv);
3512 EXPECT_EQ(kExpectedResponseData[i], response_data); 3512 EXPECT_EQ(kExpectedResponseData[i], response_data);
3513 } 3513 }
3514 } 3514 }
3515 3515
3516 // Test the request-challenge-retry sequence for basic auth when there is 3516 // Test the request-challenge-retry sequence for basic auth when there is
3517 // an identity in the URL. The request should be sent as normal, but when 3517 // an identity in the URL. The request should be sent as normal, but when
3518 // it fails the identity from the URL is used to answer the challenge. 3518 // it fails the identity from the URL is used to answer the challenge.
3519 TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { 3519 TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) {
3520 SessionDependencies session_deps;
3521 scoped_ptr<HttpTransaction> trans(
3522 new HttpNetworkTransaction(CreateSession(&session_deps)));
3523
3524 HttpRequestInfo request; 3520 HttpRequestInfo request;
3525 request.method = "GET"; 3521 request.method = "GET";
3526 // Note: the URL has a username:password in it. 3522 // Note: the URL has a username:password in it.
3527 request.url = GURL("http://foo:b@r@www.google.com/"); 3523 request.url = GURL("http://foo:b@r@www.google.com/");
3528 3524
3525 SessionDependencies session_deps;
3526 scoped_ptr<HttpTransaction> trans(
3527 new HttpNetworkTransaction(CreateSession(&session_deps)));
3528
3529 // The password contains an escaped character -- for this test to pass it 3529 // The password contains an escaped character -- for this test to pass it
3530 // will need to be unescaped by HttpNetworkTransaction. 3530 // will need to be unescaped by HttpNetworkTransaction.
3531 EXPECT_EQ("b%40r", request.url.password()); 3531 EXPECT_EQ("b%40r", request.url.password());
3532 3532
3533 request.load_flags = LOAD_NORMAL; 3533 request.load_flags = LOAD_NORMAL;
3534 3534
3535 MockWrite data_writes1[] = { 3535 MockWrite data_writes1[] = {
3536 MockWrite("GET / HTTP/1.1\r\n" 3536 MockWrite("GET / HTTP/1.1\r\n"
3537 "Host: www.google.com\r\n" 3537 "Host: www.google.com\r\n"
3538 "Connection: keep-alive\r\n\r\n"), 3538 "Connection: keep-alive\r\n\r\n"),
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
3592 EXPECT_EQ(100, response->headers->GetContentLength()); 3592 EXPECT_EQ(100, response->headers->GetContentLength());
3593 3593
3594 // Empty the current queue. 3594 // Empty the current queue.
3595 MessageLoop::current()->RunAllPending(); 3595 MessageLoop::current()->RunAllPending();
3596 } 3596 }
3597 3597
3598 // Test the request-challenge-retry sequence for basic auth when there is 3598 // Test the request-challenge-retry sequence for basic auth when there is
3599 // an incorrect identity in the URL. The identity from the URL should be used 3599 // an incorrect identity in the URL. The identity from the URL should be used
3600 // only once. 3600 // only once.
3601 TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { 3601 TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) {
3602 SessionDependencies session_deps;
3603 scoped_ptr<HttpTransaction> trans(
3604 new HttpNetworkTransaction(CreateSession(&session_deps)));
3605
3606 HttpRequestInfo request; 3602 HttpRequestInfo request;
3607 request.method = "GET"; 3603 request.method = "GET";
3608 // Note: the URL has a username:password in it. The password "baz" is 3604 // Note: the URL has a username:password in it. The password "baz" is
3609 // wrong (should be "bar"). 3605 // wrong (should be "bar").
3610 request.url = GURL("http://foo:baz@www.google.com/"); 3606 request.url = GURL("http://foo:baz@www.google.com/");
3611 3607
3612 request.load_flags = LOAD_NORMAL; 3608 request.load_flags = LOAD_NORMAL;
3613 3609
3610 SessionDependencies session_deps;
3611 scoped_ptr<HttpTransaction> trans(
3612 new HttpNetworkTransaction(CreateSession(&session_deps)));
3613
3614 MockWrite data_writes1[] = { 3614 MockWrite data_writes1[] = {
3615 MockWrite("GET / HTTP/1.1\r\n" 3615 MockWrite("GET / HTTP/1.1\r\n"
3616 "Host: www.google.com\r\n" 3616 "Host: www.google.com\r\n"
3617 "Connection: keep-alive\r\n\r\n"), 3617 "Connection: keep-alive\r\n\r\n"),
3618 }; 3618 };
3619 3619
3620 MockRead data_reads1[] = { 3620 MockRead data_reads1[] = {
3621 MockRead("HTTP/1.0 401 Unauthorized\r\n"), 3621 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
3622 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), 3622 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
3623 MockRead("Content-Length: 10\r\n\r\n"), 3623 MockRead("Content-Length: 10\r\n\r\n"),
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
3709 MessageLoop::current()->RunAllPending(); 3709 MessageLoop::current()->RunAllPending();
3710 } 3710 }
3711 3711
3712 // Test that previously tried username/passwords for a realm get re-used. 3712 // Test that previously tried username/passwords for a realm get re-used.
3713 TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { 3713 TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) {
3714 SessionDependencies session_deps; 3714 SessionDependencies session_deps;
3715 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 3715 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
3716 3716
3717 // Transaction 1: authenticate (foo, bar) on MyRealm1 3717 // Transaction 1: authenticate (foo, bar) on MyRealm1
3718 { 3718 {
3719 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
3720
3721 HttpRequestInfo request; 3719 HttpRequestInfo request;
3722 request.method = "GET"; 3720 request.method = "GET";
3723 request.url = GURL("http://www.google.com/x/y/z"); 3721 request.url = GURL("http://www.google.com/x/y/z");
3724 request.load_flags = 0; 3722 request.load_flags = 0;
3725 3723
3724 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
3725
3726 MockWrite data_writes1[] = { 3726 MockWrite data_writes1[] = {
3727 MockWrite("GET /x/y/z HTTP/1.1\r\n" 3727 MockWrite("GET /x/y/z HTTP/1.1\r\n"
3728 "Host: www.google.com\r\n" 3728 "Host: www.google.com\r\n"
3729 "Connection: keep-alive\r\n\r\n"), 3729 "Connection: keep-alive\r\n\r\n"),
3730 }; 3730 };
3731 3731
3732 MockRead data_reads1[] = { 3732 MockRead data_reads1[] = {
3733 MockRead("HTTP/1.0 401 Unauthorized\r\n"), 3733 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
3734 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), 3734 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
3735 MockRead("Content-Length: 10000\r\n\r\n"), 3735 MockRead("Content-Length: 10000\r\n\r\n"),
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
3788 response = trans->GetResponseInfo(); 3788 response = trans->GetResponseInfo();
3789 EXPECT_FALSE(response == NULL); 3789 EXPECT_FALSE(response == NULL);
3790 EXPECT_TRUE(response->auth_challenge.get() == NULL); 3790 EXPECT_TRUE(response->auth_challenge.get() == NULL);
3791 EXPECT_EQ(100, response->headers->GetContentLength()); 3791 EXPECT_EQ(100, response->headers->GetContentLength());
3792 } 3792 }
3793 3793
3794 // ------------------------------------------------------------------------ 3794 // ------------------------------------------------------------------------
3795 3795
3796 // Transaction 2: authenticate (foo2, bar2) on MyRealm2 3796 // Transaction 2: authenticate (foo2, bar2) on MyRealm2
3797 { 3797 {
3798 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
3799
3800 HttpRequestInfo request; 3798 HttpRequestInfo request;
3801 request.method = "GET"; 3799 request.method = "GET";
3802 // Note that Transaction 1 was at /x/y/z, so this is in the same 3800 // Note that Transaction 1 was at /x/y/z, so this is in the same
3803 // protection space as MyRealm1. 3801 // protection space as MyRealm1.
3804 request.url = GURL("http://www.google.com/x/y/a/b"); 3802 request.url = GURL("http://www.google.com/x/y/a/b");
3805 request.load_flags = 0; 3803 request.load_flags = 0;
3806 3804
3805 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
3806
3807 MockWrite data_writes1[] = { 3807 MockWrite data_writes1[] = {
3808 MockWrite("GET /x/y/a/b HTTP/1.1\r\n" 3808 MockWrite("GET /x/y/a/b HTTP/1.1\r\n"
3809 "Host: www.google.com\r\n" 3809 "Host: www.google.com\r\n"
3810 "Connection: keep-alive\r\n" 3810 "Connection: keep-alive\r\n"
3811 // Send preemptive authorization for MyRealm1 3811 // Send preemptive authorization for MyRealm1
3812 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), 3812 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
3813 }; 3813 };
3814 3814
3815 // The server didn't like the preemptive authorization, and 3815 // The server didn't like the preemptive authorization, and
3816 // challenges us for a different realm (MyRealm2). 3816 // challenges us for a different realm (MyRealm2).
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
3874 EXPECT_FALSE(response == NULL); 3874 EXPECT_FALSE(response == NULL);
3875 EXPECT_TRUE(response->auth_challenge.get() == NULL); 3875 EXPECT_TRUE(response->auth_challenge.get() == NULL);
3876 EXPECT_EQ(100, response->headers->GetContentLength()); 3876 EXPECT_EQ(100, response->headers->GetContentLength());
3877 } 3877 }
3878 3878
3879 // ------------------------------------------------------------------------ 3879 // ------------------------------------------------------------------------
3880 3880
3881 // Transaction 3: Resend a request in MyRealm's protection space -- 3881 // Transaction 3: Resend a request in MyRealm's protection space --
3882 // succeed with preemptive authorization. 3882 // succeed with preemptive authorization.
3883 { 3883 {
3884 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
3885
3886 HttpRequestInfo request; 3884 HttpRequestInfo request;
3887 request.method = "GET"; 3885 request.method = "GET";
3888 request.url = GURL("http://www.google.com/x/y/z2"); 3886 request.url = GURL("http://www.google.com/x/y/z2");
3889 request.load_flags = 0; 3887 request.load_flags = 0;
3890 3888
3889 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
3890
3891 MockWrite data_writes1[] = { 3891 MockWrite data_writes1[] = {
3892 MockWrite("GET /x/y/z2 HTTP/1.1\r\n" 3892 MockWrite("GET /x/y/z2 HTTP/1.1\r\n"
3893 "Host: www.google.com\r\n" 3893 "Host: www.google.com\r\n"
3894 "Connection: keep-alive\r\n" 3894 "Connection: keep-alive\r\n"
3895 // The authorization for MyRealm1 gets sent preemptively 3895 // The authorization for MyRealm1 gets sent preemptively
3896 // (since the url is in the same protection space) 3896 // (since the url is in the same protection space)
3897 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), 3897 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
3898 }; 3898 };
3899 3899
3900 // Sever accepts the preemptive authorization 3900 // Sever accepts the preemptive authorization
(...skipping 20 matching lines...) Expand all
3921 3921
3922 EXPECT_TRUE(response->auth_challenge.get() == NULL); 3922 EXPECT_TRUE(response->auth_challenge.get() == NULL);
3923 EXPECT_EQ(100, response->headers->GetContentLength()); 3923 EXPECT_EQ(100, response->headers->GetContentLength());
3924 } 3924 }
3925 3925
3926 // ------------------------------------------------------------------------ 3926 // ------------------------------------------------------------------------
3927 3927
3928 // Transaction 4: request another URL in MyRealm (however the 3928 // Transaction 4: request another URL in MyRealm (however the
3929 // url is not known to belong to the protection space, so no pre-auth). 3929 // url is not known to belong to the protection space, so no pre-auth).
3930 { 3930 {
3931 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
3932
3933 HttpRequestInfo request; 3931 HttpRequestInfo request;
3934 request.method = "GET"; 3932 request.method = "GET";
3935 request.url = GURL("http://www.google.com/x/1"); 3933 request.url = GURL("http://www.google.com/x/1");
3936 request.load_flags = 0; 3934 request.load_flags = 0;
3937 3935
3936 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
3937
3938 MockWrite data_writes1[] = { 3938 MockWrite data_writes1[] = {
3939 MockWrite("GET /x/1 HTTP/1.1\r\n" 3939 MockWrite("GET /x/1 HTTP/1.1\r\n"
3940 "Host: www.google.com\r\n" 3940 "Host: www.google.com\r\n"
3941 "Connection: keep-alive\r\n\r\n"), 3941 "Connection: keep-alive\r\n\r\n"),
3942 }; 3942 };
3943 3943
3944 MockRead data_reads1[] = { 3944 MockRead data_reads1[] = {
3945 MockRead("HTTP/1.0 401 Unauthorized\r\n"), 3945 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
3946 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), 3946 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
3947 MockRead("Content-Length: 10000\r\n\r\n"), 3947 MockRead("Content-Length: 10000\r\n\r\n"),
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
3990 EXPECT_FALSE(response == NULL); 3990 EXPECT_FALSE(response == NULL);
3991 EXPECT_TRUE(response->auth_challenge.get() == NULL); 3991 EXPECT_TRUE(response->auth_challenge.get() == NULL);
3992 EXPECT_EQ(100, response->headers->GetContentLength()); 3992 EXPECT_EQ(100, response->headers->GetContentLength());
3993 } 3993 }
3994 3994
3995 // ------------------------------------------------------------------------ 3995 // ------------------------------------------------------------------------
3996 3996
3997 // Transaction 5: request a URL in MyRealm, but the server rejects the 3997 // Transaction 5: request a URL in MyRealm, but the server rejects the
3998 // cached identity. Should invalidate and re-prompt. 3998 // cached identity. Should invalidate and re-prompt.
3999 { 3999 {
4000 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
4001
4002 HttpRequestInfo request; 4000 HttpRequestInfo request;
4003 request.method = "GET"; 4001 request.method = "GET";
4004 request.url = GURL("http://www.google.com/p/q/t"); 4002 request.url = GURL("http://www.google.com/p/q/t");
4005 request.load_flags = 0; 4003 request.load_flags = 0;
4006 4004
4005 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
4006
4007 MockWrite data_writes1[] = { 4007 MockWrite data_writes1[] = {
4008 MockWrite("GET /p/q/t HTTP/1.1\r\n" 4008 MockWrite("GET /p/q/t HTTP/1.1\r\n"
4009 "Host: www.google.com\r\n" 4009 "Host: www.google.com\r\n"
4010 "Connection: keep-alive\r\n\r\n"), 4010 "Connection: keep-alive\r\n\r\n"),
4011 }; 4011 };
4012 4012
4013 MockRead data_reads1[] = { 4013 MockRead data_reads1[] = {
4014 MockRead("HTTP/1.0 401 Unauthorized\r\n"), 4014 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
4015 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), 4015 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
4016 MockRead("Content-Length: 10000\r\n\r\n"), 4016 MockRead("Content-Length: 10000\r\n\r\n"),
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
4108 HttpAuthHandlerDigest::Factory* digest_factory = 4108 HttpAuthHandlerDigest::Factory* digest_factory =
4109 new HttpAuthHandlerDigest::Factory(); 4109 new HttpAuthHandlerDigest::Factory();
4110 HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = 4110 HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator =
4111 new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); 4111 new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef");
4112 digest_factory->set_nonce_generator(nonce_generator); 4112 digest_factory->set_nonce_generator(nonce_generator);
4113 session_deps.http_auth_handler_factory.reset(digest_factory); 4113 session_deps.http_auth_handler_factory.reset(digest_factory);
4114 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 4114 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
4115 4115
4116 // Transaction 1: authenticate (foo, bar) on MyRealm1 4116 // Transaction 1: authenticate (foo, bar) on MyRealm1
4117 { 4117 {
4118 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
4119
4120 HttpRequestInfo request; 4118 HttpRequestInfo request;
4121 request.method = "GET"; 4119 request.method = "GET";
4122 request.url = GURL("http://www.google.com/x/y/z"); 4120 request.url = GURL("http://www.google.com/x/y/z");
4123 request.load_flags = 0; 4121 request.load_flags = 0;
4124 4122
4123 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
4124
4125 MockWrite data_writes1[] = { 4125 MockWrite data_writes1[] = {
4126 MockWrite("GET /x/y/z HTTP/1.1\r\n" 4126 MockWrite("GET /x/y/z HTTP/1.1\r\n"
4127 "Host: www.google.com\r\n" 4127 "Host: www.google.com\r\n"
4128 "Connection: keep-alive\r\n\r\n"), 4128 "Connection: keep-alive\r\n\r\n"),
4129 }; 4129 };
4130 4130
4131 MockRead data_reads1[] = { 4131 MockRead data_reads1[] = {
4132 MockRead("HTTP/1.0 401 Unauthorized\r\n"), 4132 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
4133 MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " 4133 MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", "
4134 "algorithm=MD5, qop=\"auth\"\r\n\r\n"), 4134 "algorithm=MD5, qop=\"auth\"\r\n\r\n"),
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
4190 ASSERT_FALSE(response == NULL); 4190 ASSERT_FALSE(response == NULL);
4191 EXPECT_TRUE(response->auth_challenge.get() == NULL); 4191 EXPECT_TRUE(response->auth_challenge.get() == NULL);
4192 } 4192 }
4193 4193
4194 // ------------------------------------------------------------------------ 4194 // ------------------------------------------------------------------------
4195 4195
4196 // Transaction 2: Request another resource in digestive's protection space. 4196 // Transaction 2: Request another resource in digestive's protection space.
4197 // This will preemptively add an Authorization header which should have an 4197 // This will preemptively add an Authorization header which should have an
4198 // "nc" value of 2 (as compared to 1 in the first use. 4198 // "nc" value of 2 (as compared to 1 in the first use.
4199 { 4199 {
4200 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
4201
4202 HttpRequestInfo request; 4200 HttpRequestInfo request;
4203 request.method = "GET"; 4201 request.method = "GET";
4204 // Note that Transaction 1 was at /x/y/z, so this is in the same 4202 // Note that Transaction 1 was at /x/y/z, so this is in the same
4205 // protection space as digest. 4203 // protection space as digest.
4206 request.url = GURL("http://www.google.com/x/y/a/b"); 4204 request.url = GURL("http://www.google.com/x/y/a/b");
4207 request.load_flags = 0; 4205 request.load_flags = 0;
4208 4206
4207 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
4208
4209 MockWrite data_writes1[] = { 4209 MockWrite data_writes1[] = {
4210 MockWrite("GET /x/y/a/b HTTP/1.1\r\n" 4210 MockWrite("GET /x/y/a/b HTTP/1.1\r\n"
4211 "Host: www.google.com\r\n" 4211 "Host: www.google.com\r\n"
4212 "Connection: keep-alive\r\n" 4212 "Connection: keep-alive\r\n"
4213 "Authorization: Digest username=\"foo\", realm=\"digestive\", " 4213 "Authorization: Digest username=\"foo\", realm=\"digestive\", "
4214 "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " 4214 "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, "
4215 "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " 4215 "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, "
4216 "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), 4216 "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"),
4217 }; 4217 };
4218 4218
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
4279 EXPECT_TRUE(trans->request_headers_.IsEmpty()); 4279 EXPECT_TRUE(trans->request_headers_.IsEmpty());
4280 EXPECT_TRUE(response->auth_challenge.get() == NULL); 4280 EXPECT_TRUE(response->auth_challenge.get() == NULL);
4281 EXPECT_TRUE(response->headers.get() == NULL); 4281 EXPECT_TRUE(response->headers.get() == NULL);
4282 EXPECT_FALSE(response->was_cached); 4282 EXPECT_FALSE(response->was_cached);
4283 EXPECT_EQ(0, response->ssl_info.cert_status); 4283 EXPECT_EQ(0, response->ssl_info.cert_status);
4284 EXPECT_FALSE(response->vary_data.is_valid()); 4284 EXPECT_FALSE(response->vary_data.is_valid());
4285 } 4285 }
4286 4286
4287 // Test HTTPS connections to a site with a bad certificate 4287 // Test HTTPS connections to a site with a bad certificate
4288 TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { 4288 TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) {
4289 SessionDependencies session_deps;
4290 scoped_ptr<HttpTransaction> trans(
4291 new HttpNetworkTransaction(CreateSession(&session_deps)));
4292
4293 HttpRequestInfo request; 4289 HttpRequestInfo request;
4294 request.method = "GET"; 4290 request.method = "GET";
4295 request.url = GURL("https://www.google.com/"); 4291 request.url = GURL("https://www.google.com/");
4296 request.load_flags = 0; 4292 request.load_flags = 0;
4297 4293
4294 SessionDependencies session_deps;
4295 scoped_ptr<HttpTransaction> trans(
4296 new HttpNetworkTransaction(CreateSession(&session_deps)));
4297
4298 MockWrite data_writes[] = { 4298 MockWrite data_writes[] = {
4299 MockWrite("GET / HTTP/1.1\r\n" 4299 MockWrite("GET / HTTP/1.1\r\n"
4300 "Host: www.google.com\r\n" 4300 "Host: www.google.com\r\n"
4301 "Connection: keep-alive\r\n\r\n"), 4301 "Connection: keep-alive\r\n\r\n"),
4302 }; 4302 };
4303 4303
4304 MockRead data_reads[] = { 4304 MockRead data_reads[] = {
4305 MockRead("HTTP/1.0 200 OK\r\n"), 4305 MockRead("HTTP/1.0 200 OK\r\n"),
4306 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), 4306 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
4307 MockRead("Content-Length: 100\r\n\r\n"), 4307 MockRead("Content-Length: 100\r\n\r\n"),
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
4780 rv = callback.WaitForResult(); 4780 rv = callback.WaitForResult();
4781 EXPECT_EQ(OK, rv); 4781 EXPECT_EQ(OK, rv);
4782 4782
4783 const HttpResponseInfo* response = trans->GetResponseInfo(); 4783 const HttpResponseInfo* response = trans->GetResponseInfo();
4784 4784
4785 EXPECT_FALSE(response == NULL); 4785 EXPECT_FALSE(response == NULL);
4786 EXPECT_EQ(100, response->headers->GetContentLength()); 4786 EXPECT_EQ(100, response->headers->GetContentLength());
4787 } 4787 }
4788 4788
4789 TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { 4789 TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) {
4790 SessionDependencies session_deps;
4791 scoped_ptr<HttpTransaction> trans(
4792 new HttpNetworkTransaction(CreateSession(&session_deps)));
4793
4794 HttpRequestInfo request; 4790 HttpRequestInfo request;
4795 request.method = "GET"; 4791 request.method = "GET";
4796 request.url = GURL("http://www.google.com/"); 4792 request.url = GURL("http://www.google.com/");
4797 request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, 4793 request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent,
4798 "Chromium Ultra Awesome X Edition"); 4794 "Chromium Ultra Awesome X Edition");
4799 4795
4796 SessionDependencies session_deps;
4797 scoped_ptr<HttpTransaction> trans(
4798 new HttpNetworkTransaction(CreateSession(&session_deps)));
4799
4800 MockWrite data_writes[] = { 4800 MockWrite data_writes[] = {
4801 MockWrite("GET / HTTP/1.1\r\n" 4801 MockWrite("GET / HTTP/1.1\r\n"
4802 "Host: www.google.com\r\n" 4802 "Host: www.google.com\r\n"
4803 "Connection: keep-alive\r\n" 4803 "Connection: keep-alive\r\n"
4804 "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), 4804 "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"),
4805 }; 4805 };
4806 4806
4807 // Lastly, the server responds with the actual content. 4807 // Lastly, the server responds with the actual content.
4808 MockRead data_reads[] = { 4808 MockRead data_reads[] = {
4809 MockRead("HTTP/1.0 200 OK\r\n"), 4809 MockRead("HTTP/1.0 200 OK\r\n"),
4810 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), 4810 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
4811 MockRead("Content-Length: 100\r\n\r\n"), 4811 MockRead("Content-Length: 100\r\n\r\n"),
4812 MockRead(false, OK), 4812 MockRead(false, OK),
4813 }; 4813 };
4814 4814
4815 StaticSocketDataProvider data(data_reads, arraysize(data_reads), 4815 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
4816 data_writes, arraysize(data_writes)); 4816 data_writes, arraysize(data_writes));
4817 session_deps.socket_factory.AddSocketDataProvider(&data); 4817 session_deps.socket_factory.AddSocketDataProvider(&data);
4818 4818
4819 TestCompletionCallback callback; 4819 TestCompletionCallback callback;
4820 4820
4821 int rv = trans->Start(&request, &callback, BoundNetLog()); 4821 int rv = trans->Start(&request, &callback, BoundNetLog());
4822 EXPECT_EQ(ERR_IO_PENDING, rv); 4822 EXPECT_EQ(ERR_IO_PENDING, rv);
4823 4823
4824 rv = callback.WaitForResult(); 4824 rv = callback.WaitForResult();
4825 EXPECT_EQ(OK, rv); 4825 EXPECT_EQ(OK, rv);
4826 } 4826 }
4827 4827
4828 TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { 4828 TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) {
4829 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:70"));
4830 scoped_ptr<HttpTransaction> trans(
4831 new HttpNetworkTransaction(CreateSession(&session_deps)));
4832
4833 HttpRequestInfo request; 4829 HttpRequestInfo request;
4834 request.method = "GET"; 4830 request.method = "GET";
4835 request.url = GURL("https://www.google.com/"); 4831 request.url = GURL("https://www.google.com/");
4836 request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, 4832 request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent,
4837 "Chromium Ultra Awesome X Edition"); 4833 "Chromium Ultra Awesome X Edition");
4838 4834
4835 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:70"));
4836 scoped_ptr<HttpTransaction> trans(
4837 new HttpNetworkTransaction(CreateSession(&session_deps)));
4838
4839 MockWrite data_writes[] = { 4839 MockWrite data_writes[] = {
4840 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" 4840 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
4841 "Host: www.google.com\r\n" 4841 "Host: www.google.com\r\n"
4842 "Proxy-Connection: keep-alive\r\n" 4842 "Proxy-Connection: keep-alive\r\n"
4843 "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), 4843 "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"),
4844 }; 4844 };
4845 MockRead data_reads[] = { 4845 MockRead data_reads[] = {
4846 // Return an error, so the transaction stops here (this test isn't 4846 // Return an error, so the transaction stops here (this test isn't
4847 // interested in the rest). 4847 // interested in the rest).
4848 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), 4848 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
4849 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), 4849 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
4850 MockRead("Proxy-Connection: close\r\n\r\n"), 4850 MockRead("Proxy-Connection: close\r\n\r\n"),
4851 }; 4851 };
4852 4852
4853 StaticSocketDataProvider data(data_reads, arraysize(data_reads), 4853 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
4854 data_writes, arraysize(data_writes)); 4854 data_writes, arraysize(data_writes));
4855 session_deps.socket_factory.AddSocketDataProvider(&data); 4855 session_deps.socket_factory.AddSocketDataProvider(&data);
4856 4856
4857 TestCompletionCallback callback; 4857 TestCompletionCallback callback;
4858 4858
4859 int rv = trans->Start(&request, &callback, BoundNetLog()); 4859 int rv = trans->Start(&request, &callback, BoundNetLog());
4860 EXPECT_EQ(ERR_IO_PENDING, rv); 4860 EXPECT_EQ(ERR_IO_PENDING, rv);
4861 4861
4862 rv = callback.WaitForResult(); 4862 rv = callback.WaitForResult();
4863 EXPECT_EQ(OK, rv); 4863 EXPECT_EQ(OK, rv);
4864 } 4864 }
4865 4865
4866 TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { 4866 TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) {
4867 SessionDependencies session_deps;
4868 scoped_ptr<HttpTransaction> trans(
4869 new HttpNetworkTransaction(CreateSession(&session_deps)));
4870
4871 HttpRequestInfo request; 4867 HttpRequestInfo request;
4872 request.method = "GET"; 4868 request.method = "GET";
4873 request.url = GURL("http://www.google.com/"); 4869 request.url = GURL("http://www.google.com/");
4874 request.load_flags = 0; 4870 request.load_flags = 0;
4875 request.referrer = GURL("http://the.previous.site.com/"); 4871 request.referrer = GURL("http://the.previous.site.com/");
4876 4872
4873 SessionDependencies session_deps;
4874 scoped_ptr<HttpTransaction> trans(
4875 new HttpNetworkTransaction(CreateSession(&session_deps)));
4876
4877 MockWrite data_writes[] = { 4877 MockWrite data_writes[] = {
4878 MockWrite("GET / HTTP/1.1\r\n" 4878 MockWrite("GET / HTTP/1.1\r\n"
4879 "Host: www.google.com\r\n" 4879 "Host: www.google.com\r\n"
4880 "Connection: keep-alive\r\n" 4880 "Connection: keep-alive\r\n"
4881 "Referer: http://the.previous.site.com/\r\n\r\n"), 4881 "Referer: http://the.previous.site.com/\r\n\r\n"),
4882 }; 4882 };
4883 4883
4884 // Lastly, the server responds with the actual content. 4884 // Lastly, the server responds with the actual content.
4885 MockRead data_reads[] = { 4885 MockRead data_reads[] = {
4886 MockRead("HTTP/1.0 200 OK\r\n"), 4886 MockRead("HTTP/1.0 200 OK\r\n"),
4887 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), 4887 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
4888 MockRead("Content-Length: 100\r\n\r\n"), 4888 MockRead("Content-Length: 100\r\n\r\n"),
4889 MockRead(false, OK), 4889 MockRead(false, OK),
4890 }; 4890 };
4891 4891
4892 StaticSocketDataProvider data(data_reads, arraysize(data_reads), 4892 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
4893 data_writes, arraysize(data_writes)); 4893 data_writes, arraysize(data_writes));
4894 session_deps.socket_factory.AddSocketDataProvider(&data); 4894 session_deps.socket_factory.AddSocketDataProvider(&data);
4895 4895
4896 TestCompletionCallback callback; 4896 TestCompletionCallback callback;
4897 4897
4898 int rv = trans->Start(&request, &callback, BoundNetLog()); 4898 int rv = trans->Start(&request, &callback, BoundNetLog());
4899 EXPECT_EQ(ERR_IO_PENDING, rv); 4899 EXPECT_EQ(ERR_IO_PENDING, rv);
4900 4900
4901 rv = callback.WaitForResult(); 4901 rv = callback.WaitForResult();
4902 EXPECT_EQ(OK, rv); 4902 EXPECT_EQ(OK, rv);
4903 } 4903 }
4904 4904
4905 TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { 4905 TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) {
4906 HttpRequestInfo request;
4907 request.method = "POST";
4908 request.url = GURL("http://www.google.com/");
4909
4906 SessionDependencies session_deps; 4910 SessionDependencies session_deps;
4907 scoped_ptr<HttpTransaction> trans( 4911 scoped_ptr<HttpTransaction> trans(
4908 new HttpNetworkTransaction(CreateSession(&session_deps))); 4912 new HttpNetworkTransaction(CreateSession(&session_deps)));
4909 4913
4910 HttpRequestInfo request;
4911 request.method = "POST";
4912 request.url = GURL("http://www.google.com/");
4913
4914 MockWrite data_writes[] = { 4914 MockWrite data_writes[] = {
4915 MockWrite("POST / HTTP/1.1\r\n" 4915 MockWrite("POST / HTTP/1.1\r\n"
4916 "Host: www.google.com\r\n" 4916 "Host: www.google.com\r\n"
4917 "Connection: keep-alive\r\n" 4917 "Connection: keep-alive\r\n"
4918 "Content-Length: 0\r\n\r\n"), 4918 "Content-Length: 0\r\n\r\n"),
4919 }; 4919 };
4920 4920
4921 // Lastly, the server responds with the actual content. 4921 // Lastly, the server responds with the actual content.
4922 MockRead data_reads[] = { 4922 MockRead data_reads[] = {
4923 MockRead("HTTP/1.0 200 OK\r\n"), 4923 MockRead("HTTP/1.0 200 OK\r\n"),
4924 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), 4924 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
4925 MockRead("Content-Length: 100\r\n\r\n"), 4925 MockRead("Content-Length: 100\r\n\r\n"),
4926 MockRead(false, OK), 4926 MockRead(false, OK),
4927 }; 4927 };
4928 4928
4929 StaticSocketDataProvider data(data_reads, arraysize(data_reads), 4929 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
4930 data_writes, arraysize(data_writes)); 4930 data_writes, arraysize(data_writes));
4931 session_deps.socket_factory.AddSocketDataProvider(&data); 4931 session_deps.socket_factory.AddSocketDataProvider(&data);
4932 4932
4933 TestCompletionCallback callback; 4933 TestCompletionCallback callback;
4934 4934
4935 int rv = trans->Start(&request, &callback, BoundNetLog()); 4935 int rv = trans->Start(&request, &callback, BoundNetLog());
4936 EXPECT_EQ(ERR_IO_PENDING, rv); 4936 EXPECT_EQ(ERR_IO_PENDING, rv);
4937 4937
4938 rv = callback.WaitForResult(); 4938 rv = callback.WaitForResult();
4939 EXPECT_EQ(OK, rv); 4939 EXPECT_EQ(OK, rv);
4940 } 4940 }
4941 4941
4942 TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { 4942 TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) {
4943 HttpRequestInfo request;
4944 request.method = "PUT";
4945 request.url = GURL("http://www.google.com/");
4946
4943 SessionDependencies session_deps; 4947 SessionDependencies session_deps;
4944 scoped_ptr<HttpTransaction> trans( 4948 scoped_ptr<HttpTransaction> trans(
4945 new HttpNetworkTransaction(CreateSession(&session_deps))); 4949 new HttpNetworkTransaction(CreateSession(&session_deps)));
4946 4950
4947 HttpRequestInfo request;
4948 request.method = "PUT";
4949 request.url = GURL("http://www.google.com/");
4950
4951 MockWrite data_writes[] = { 4951 MockWrite data_writes[] = {
4952 MockWrite("PUT / HTTP/1.1\r\n" 4952 MockWrite("PUT / HTTP/1.1\r\n"
4953 "Host: www.google.com\r\n" 4953 "Host: www.google.com\r\n"
4954 "Connection: keep-alive\r\n" 4954 "Connection: keep-alive\r\n"
4955 "Content-Length: 0\r\n\r\n"), 4955 "Content-Length: 0\r\n\r\n"),
4956 }; 4956 };
4957 4957
4958 // Lastly, the server responds with the actual content. 4958 // Lastly, the server responds with the actual content.
4959 MockRead data_reads[] = { 4959 MockRead data_reads[] = {
4960 MockRead("HTTP/1.0 200 OK\r\n"), 4960 MockRead("HTTP/1.0 200 OK\r\n"),
4961 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), 4961 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
4962 MockRead("Content-Length: 100\r\n\r\n"), 4962 MockRead("Content-Length: 100\r\n\r\n"),
4963 MockRead(false, OK), 4963 MockRead(false, OK),
4964 }; 4964 };
4965 4965
4966 StaticSocketDataProvider data(data_reads, arraysize(data_reads), 4966 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
4967 data_writes, arraysize(data_writes)); 4967 data_writes, arraysize(data_writes));
4968 session_deps.socket_factory.AddSocketDataProvider(&data); 4968 session_deps.socket_factory.AddSocketDataProvider(&data);
4969 4969
4970 TestCompletionCallback callback; 4970 TestCompletionCallback callback;
4971 4971
4972 int rv = trans->Start(&request, &callback, BoundNetLog()); 4972 int rv = trans->Start(&request, &callback, BoundNetLog());
4973 EXPECT_EQ(ERR_IO_PENDING, rv); 4973 EXPECT_EQ(ERR_IO_PENDING, rv);
4974 4974
4975 rv = callback.WaitForResult(); 4975 rv = callback.WaitForResult();
4976 EXPECT_EQ(OK, rv); 4976 EXPECT_EQ(OK, rv);
4977 } 4977 }
4978 4978
4979 TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { 4979 TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) {
4980 HttpRequestInfo request;
4981 request.method = "HEAD";
4982 request.url = GURL("http://www.google.com/");
4983
4980 SessionDependencies session_deps; 4984 SessionDependencies session_deps;
4981 scoped_ptr<HttpTransaction> trans( 4985 scoped_ptr<HttpTransaction> trans(
4982 new HttpNetworkTransaction(CreateSession(&session_deps))); 4986 new HttpNetworkTransaction(CreateSession(&session_deps)));
4983 4987
4984 HttpRequestInfo request;
4985 request.method = "HEAD";
4986 request.url = GURL("http://www.google.com/");
4987
4988 MockWrite data_writes[] = { 4988 MockWrite data_writes[] = {
4989 MockWrite("HEAD / HTTP/1.1\r\n" 4989 MockWrite("HEAD / HTTP/1.1\r\n"
4990 "Host: www.google.com\r\n" 4990 "Host: www.google.com\r\n"
4991 "Connection: keep-alive\r\n" 4991 "Connection: keep-alive\r\n"
4992 "Content-Length: 0\r\n\r\n"), 4992 "Content-Length: 0\r\n\r\n"),
4993 }; 4993 };
4994 4994
4995 // Lastly, the server responds with the actual content. 4995 // Lastly, the server responds with the actual content.
4996 MockRead data_reads[] = { 4996 MockRead data_reads[] = {
4997 MockRead("HTTP/1.0 200 OK\r\n"), 4997 MockRead("HTTP/1.0 200 OK\r\n"),
4998 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), 4998 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
4999 MockRead("Content-Length: 100\r\n\r\n"), 4999 MockRead("Content-Length: 100\r\n\r\n"),
5000 MockRead(false, OK), 5000 MockRead(false, OK),
5001 }; 5001 };
5002 5002
5003 StaticSocketDataProvider data(data_reads, arraysize(data_reads), 5003 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
5004 data_writes, arraysize(data_writes)); 5004 data_writes, arraysize(data_writes));
5005 session_deps.socket_factory.AddSocketDataProvider(&data); 5005 session_deps.socket_factory.AddSocketDataProvider(&data);
5006 5006
5007 TestCompletionCallback callback; 5007 TestCompletionCallback callback;
5008 5008
5009 int rv = trans->Start(&request, &callback, BoundNetLog()); 5009 int rv = trans->Start(&request, &callback, BoundNetLog());
5010 EXPECT_EQ(ERR_IO_PENDING, rv); 5010 EXPECT_EQ(ERR_IO_PENDING, rv);
5011 5011
5012 rv = callback.WaitForResult(); 5012 rv = callback.WaitForResult();
5013 EXPECT_EQ(OK, rv); 5013 EXPECT_EQ(OK, rv);
5014 } 5014 }
5015 5015
5016 TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { 5016 TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) {
5017 SessionDependencies session_deps;
5018 scoped_ptr<HttpTransaction> trans(
5019 new HttpNetworkTransaction(CreateSession(&session_deps)));
5020
5021 HttpRequestInfo request; 5017 HttpRequestInfo request;
5022 request.method = "GET"; 5018 request.method = "GET";
5023 request.url = GURL("http://www.google.com/"); 5019 request.url = GURL("http://www.google.com/");
5024 request.load_flags = LOAD_BYPASS_CACHE; 5020 request.load_flags = LOAD_BYPASS_CACHE;
5025 5021
5022 SessionDependencies session_deps;
5023 scoped_ptr<HttpTransaction> trans(
5024 new HttpNetworkTransaction(CreateSession(&session_deps)));
5025
5026 MockWrite data_writes[] = { 5026 MockWrite data_writes[] = {
5027 MockWrite("GET / HTTP/1.1\r\n" 5027 MockWrite("GET / HTTP/1.1\r\n"
5028 "Host: www.google.com\r\n" 5028 "Host: www.google.com\r\n"
5029 "Connection: keep-alive\r\n" 5029 "Connection: keep-alive\r\n"
5030 "Pragma: no-cache\r\n" 5030 "Pragma: no-cache\r\n"
5031 "Cache-Control: no-cache\r\n\r\n"), 5031 "Cache-Control: no-cache\r\n\r\n"),
5032 }; 5032 };
5033 5033
5034 // Lastly, the server responds with the actual content. 5034 // Lastly, the server responds with the actual content.
5035 MockRead data_reads[] = { 5035 MockRead data_reads[] = {
(...skipping 11 matching lines...) Expand all
5047 5047
5048 int rv = trans->Start(&request, &callback, BoundNetLog()); 5048 int rv = trans->Start(&request, &callback, BoundNetLog());
5049 EXPECT_EQ(ERR_IO_PENDING, rv); 5049 EXPECT_EQ(ERR_IO_PENDING, rv);
5050 5050
5051 rv = callback.WaitForResult(); 5051 rv = callback.WaitForResult();
5052 EXPECT_EQ(OK, rv); 5052 EXPECT_EQ(OK, rv);
5053 } 5053 }
5054 5054
5055 TEST_F(HttpNetworkTransactionTest, 5055 TEST_F(HttpNetworkTransactionTest,
5056 BuildRequest_CacheControlValidateCache) { 5056 BuildRequest_CacheControlValidateCache) {
5057 SessionDependencies session_deps;
5058 scoped_ptr<HttpTransaction> trans(
5059 new HttpNetworkTransaction(CreateSession(&session_deps)));
5060
5061 HttpRequestInfo request; 5057 HttpRequestInfo request;
5062 request.method = "GET"; 5058 request.method = "GET";
5063 request.url = GURL("http://www.google.com/"); 5059 request.url = GURL("http://www.google.com/");
5064 request.load_flags = LOAD_VALIDATE_CACHE; 5060 request.load_flags = LOAD_VALIDATE_CACHE;
5065 5061
5062 SessionDependencies session_deps;
5063 scoped_ptr<HttpTransaction> trans(
5064 new HttpNetworkTransaction(CreateSession(&session_deps)));
5065
5066 MockWrite data_writes[] = { 5066 MockWrite data_writes[] = {
5067 MockWrite("GET / HTTP/1.1\r\n" 5067 MockWrite("GET / HTTP/1.1\r\n"
5068 "Host: www.google.com\r\n" 5068 "Host: www.google.com\r\n"
5069 "Connection: keep-alive\r\n" 5069 "Connection: keep-alive\r\n"
5070 "Cache-Control: max-age=0\r\n\r\n"), 5070 "Cache-Control: max-age=0\r\n\r\n"),
5071 }; 5071 };
5072 5072
5073 // Lastly, the server responds with the actual content. 5073 // Lastly, the server responds with the actual content.
5074 MockRead data_reads[] = { 5074 MockRead data_reads[] = {
5075 MockRead("HTTP/1.0 200 OK\r\n"), 5075 MockRead("HTTP/1.0 200 OK\r\n"),
5076 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), 5076 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
5077 MockRead("Content-Length: 100\r\n\r\n"), 5077 MockRead("Content-Length: 100\r\n\r\n"),
5078 MockRead(false, OK), 5078 MockRead(false, OK),
5079 }; 5079 };
5080 5080
5081 StaticSocketDataProvider data(data_reads, arraysize(data_reads), 5081 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
5082 data_writes, arraysize(data_writes)); 5082 data_writes, arraysize(data_writes));
5083 session_deps.socket_factory.AddSocketDataProvider(&data); 5083 session_deps.socket_factory.AddSocketDataProvider(&data);
5084 5084
5085 TestCompletionCallback callback; 5085 TestCompletionCallback callback;
5086 5086
5087 int rv = trans->Start(&request, &callback, BoundNetLog()); 5087 int rv = trans->Start(&request, &callback, BoundNetLog());
5088 EXPECT_EQ(ERR_IO_PENDING, rv); 5088 EXPECT_EQ(ERR_IO_PENDING, rv);
5089 5089
5090 rv = callback.WaitForResult(); 5090 rv = callback.WaitForResult();
5091 EXPECT_EQ(OK, rv); 5091 EXPECT_EQ(OK, rv);
5092 } 5092 }
5093 5093
5094 TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { 5094 TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) {
5095 SessionDependencies session_deps;
5096 scoped_ptr<HttpTransaction> trans(
5097 new HttpNetworkTransaction(CreateSession(&session_deps)));
5098
5099 HttpRequestInfo request; 5095 HttpRequestInfo request;
5100 request.method = "GET"; 5096 request.method = "GET";
5101 request.url = GURL("http://www.google.com/"); 5097 request.url = GURL("http://www.google.com/");
5102 request.extra_headers.SetHeader("FooHeader", "Bar"); 5098 request.extra_headers.SetHeader("FooHeader", "Bar");
5103 5099
5100 SessionDependencies session_deps;
5101 scoped_ptr<HttpTransaction> trans(
5102 new HttpNetworkTransaction(CreateSession(&session_deps)));
5103
5104 MockWrite data_writes[] = { 5104 MockWrite data_writes[] = {
5105 MockWrite("GET / HTTP/1.1\r\n" 5105 MockWrite("GET / HTTP/1.1\r\n"
5106 "Host: www.google.com\r\n" 5106 "Host: www.google.com\r\n"
5107 "Connection: keep-alive\r\n" 5107 "Connection: keep-alive\r\n"
5108 "FooHeader: Bar\r\n\r\n"), 5108 "FooHeader: Bar\r\n\r\n"),
5109 }; 5109 };
5110 5110
5111 // Lastly, the server responds with the actual content. 5111 // Lastly, the server responds with the actual content.
5112 MockRead data_reads[] = { 5112 MockRead data_reads[] = {
5113 MockRead("HTTP/1.0 200 OK\r\n"), 5113 MockRead("HTTP/1.0 200 OK\r\n"),
5114 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), 5114 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
5115 MockRead("Content-Length: 100\r\n\r\n"), 5115 MockRead("Content-Length: 100\r\n\r\n"),
5116 MockRead(false, OK), 5116 MockRead(false, OK),
5117 }; 5117 };
5118 5118
5119 StaticSocketDataProvider data(data_reads, arraysize(data_reads), 5119 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
5120 data_writes, arraysize(data_writes)); 5120 data_writes, arraysize(data_writes));
5121 session_deps.socket_factory.AddSocketDataProvider(&data); 5121 session_deps.socket_factory.AddSocketDataProvider(&data);
5122 5122
5123 TestCompletionCallback callback; 5123 TestCompletionCallback callback;
5124 5124
5125 int rv = trans->Start(&request, &callback, BoundNetLog()); 5125 int rv = trans->Start(&request, &callback, BoundNetLog());
5126 EXPECT_EQ(ERR_IO_PENDING, rv); 5126 EXPECT_EQ(ERR_IO_PENDING, rv);
5127 5127
5128 rv = callback.WaitForResult(); 5128 rv = callback.WaitForResult();
5129 EXPECT_EQ(OK, rv); 5129 EXPECT_EQ(OK, rv);
5130 } 5130 }
5131 5131
5132 TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { 5132 TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) {
5133 SessionDependencies session_deps;
5134 scoped_ptr<HttpTransaction> trans(
5135 new HttpNetworkTransaction(CreateSession(&session_deps)));
5136
5137 HttpRequestInfo request; 5133 HttpRequestInfo request;
5138 request.method = "GET"; 5134 request.method = "GET";
5139 request.url = GURL("http://www.google.com/"); 5135 request.url = GURL("http://www.google.com/");
5140 request.extra_headers.SetHeader("referer", "www.foo.com"); 5136 request.extra_headers.SetHeader("referer", "www.foo.com");
5141 request.extra_headers.SetHeader("hEllo", "Kitty"); 5137 request.extra_headers.SetHeader("hEllo", "Kitty");
5142 request.extra_headers.SetHeader("FoO", "bar"); 5138 request.extra_headers.SetHeader("FoO", "bar");
5143 5139
5140 SessionDependencies session_deps;
5141 scoped_ptr<HttpTransaction> trans(
5142 new HttpNetworkTransaction(CreateSession(&session_deps)));
5143
5144 MockWrite data_writes[] = { 5144 MockWrite data_writes[] = {
5145 MockWrite("GET / HTTP/1.1\r\n" 5145 MockWrite("GET / HTTP/1.1\r\n"
5146 "Host: www.google.com\r\n" 5146 "Host: www.google.com\r\n"
5147 "Connection: keep-alive\r\n" 5147 "Connection: keep-alive\r\n"
5148 "hEllo: Kitty\r\n" 5148 "hEllo: Kitty\r\n"
5149 "FoO: bar\r\n\r\n"), 5149 "FoO: bar\r\n\r\n"),
5150 }; 5150 };
5151 5151
5152 // Lastly, the server responds with the actual content. 5152 // Lastly, the server responds with the actual content.
5153 MockRead data_reads[] = { 5153 MockRead data_reads[] = {
(...skipping 10 matching lines...) Expand all
5164 TestCompletionCallback callback; 5164 TestCompletionCallback callback;
5165 5165
5166 int rv = trans->Start(&request, &callback, BoundNetLog()); 5166 int rv = trans->Start(&request, &callback, BoundNetLog());
5167 EXPECT_EQ(ERR_IO_PENDING, rv); 5167 EXPECT_EQ(ERR_IO_PENDING, rv);
5168 5168
5169 rv = callback.WaitForResult(); 5169 rv = callback.WaitForResult();
5170 EXPECT_EQ(OK, rv); 5170 EXPECT_EQ(OK, rv);
5171 } 5171 }
5172 5172
5173 TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { 5173 TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) {
5174 HttpRequestInfo request;
5175 request.method = "GET";
5176 request.url = GURL("http://www.google.com/");
5177 request.load_flags = 0;
5178
5174 SessionDependencies session_deps( 5179 SessionDependencies session_deps(
5175 ProxyService::CreateFixed("socks4://myproxy:1080")); 5180 ProxyService::CreateFixed("socks4://myproxy:1080"));
5176 5181
5177 scoped_ptr<HttpTransaction> trans( 5182 scoped_ptr<HttpTransaction> trans(
5178 new HttpNetworkTransaction(CreateSession(&session_deps))); 5183 new HttpNetworkTransaction(CreateSession(&session_deps)));
5179 5184
5180 HttpRequestInfo request;
5181 request.method = "GET";
5182 request.url = GURL("http://www.google.com/");
5183 request.load_flags = 0;
5184
5185 char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; 5185 char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 };
5186 char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; 5186 char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 };
5187 5187
5188 MockWrite data_writes[] = { 5188 MockWrite data_writes[] = {
5189 MockWrite(true, write_buffer, arraysize(write_buffer)), 5189 MockWrite(true, write_buffer, arraysize(write_buffer)),
5190 MockWrite("GET / HTTP/1.1\r\n" 5190 MockWrite("GET / HTTP/1.1\r\n"
5191 "Host: www.google.com\r\n" 5191 "Host: www.google.com\r\n"
5192 "Connection: keep-alive\r\n\r\n") 5192 "Connection: keep-alive\r\n\r\n")
5193 }; 5193 };
5194 5194
(...skipping 20 matching lines...) Expand all
5215 const HttpResponseInfo* response = trans->GetResponseInfo(); 5215 const HttpResponseInfo* response = trans->GetResponseInfo();
5216 EXPECT_FALSE(response == NULL); 5216 EXPECT_FALSE(response == NULL);
5217 5217
5218 std::string response_text; 5218 std::string response_text;
5219 rv = ReadTransaction(trans.get(), &response_text); 5219 rv = ReadTransaction(trans.get(), &response_text);
5220 EXPECT_EQ(OK, rv); 5220 EXPECT_EQ(OK, rv);
5221 EXPECT_EQ("Payload", response_text); 5221 EXPECT_EQ("Payload", response_text);
5222 } 5222 }
5223 5223
5224 TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { 5224 TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) {
5225 HttpRequestInfo request;
5226 request.method = "GET";
5227 request.url = GURL("https://www.google.com/");
5228 request.load_flags = 0;
5229
5225 SessionDependencies session_deps( 5230 SessionDependencies session_deps(
5226 ProxyService::CreateFixed("socks4://myproxy:1080")); 5231 ProxyService::CreateFixed("socks4://myproxy:1080"));
5227 5232
5228 scoped_ptr<HttpTransaction> trans( 5233 scoped_ptr<HttpTransaction> trans(
5229 new HttpNetworkTransaction(CreateSession(&session_deps))); 5234 new HttpNetworkTransaction(CreateSession(&session_deps)));
5230 5235
5231 HttpRequestInfo request;
5232 request.method = "GET";
5233 request.url = GURL("https://www.google.com/");
5234 request.load_flags = 0;
5235
5236 unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; 5236 unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 };
5237 unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; 5237 unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 };
5238 5238
5239 MockWrite data_writes[] = { 5239 MockWrite data_writes[] = {
5240 MockWrite(true, reinterpret_cast<char*>(write_buffer), 5240 MockWrite(true, reinterpret_cast<char*>(write_buffer),
5241 arraysize(write_buffer)), 5241 arraysize(write_buffer)),
5242 MockWrite("GET / HTTP/1.1\r\n" 5242 MockWrite("GET / HTTP/1.1\r\n"
5243 "Host: www.google.com\r\n" 5243 "Host: www.google.com\r\n"
5244 "Connection: keep-alive\r\n\r\n") 5244 "Connection: keep-alive\r\n\r\n")
5245 }; 5245 };
(...skipping 25 matching lines...) Expand all
5271 const HttpResponseInfo* response = trans->GetResponseInfo(); 5271 const HttpResponseInfo* response = trans->GetResponseInfo();
5272 EXPECT_FALSE(response == NULL); 5272 EXPECT_FALSE(response == NULL);
5273 5273
5274 std::string response_text; 5274 std::string response_text;
5275 rv = ReadTransaction(trans.get(), &response_text); 5275 rv = ReadTransaction(trans.get(), &response_text);
5276 EXPECT_EQ(OK, rv); 5276 EXPECT_EQ(OK, rv);
5277 EXPECT_EQ("Payload", response_text); 5277 EXPECT_EQ("Payload", response_text);
5278 } 5278 }
5279 5279
5280 TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { 5280 TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) {
5281 HttpRequestInfo request;
5282 request.method = "GET";
5283 request.url = GURL("http://www.google.com/");
5284 request.load_flags = 0;
5285
5281 SessionDependencies session_deps( 5286 SessionDependencies session_deps(
5282 ProxyService::CreateFixed("socks5://myproxy:1080")); 5287 ProxyService::CreateFixed("socks5://myproxy:1080"));
5283 5288
5284 scoped_ptr<HttpTransaction> trans( 5289 scoped_ptr<HttpTransaction> trans(
5285 new HttpNetworkTransaction(CreateSession(&session_deps))); 5290 new HttpNetworkTransaction(CreateSession(&session_deps)));
5286 5291
5287 HttpRequestInfo request;
5288 request.method = "GET";
5289 request.url = GURL("http://www.google.com/");
5290 request.load_flags = 0;
5291
5292 const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; 5292 const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 };
5293 const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; 5293 const char kSOCKS5GreetResponse[] = { 0x05, 0x00 };
5294 const char kSOCKS5OkRequest[] = { 5294 const char kSOCKS5OkRequest[] = {
5295 0x05, // Version 5295 0x05, // Version
5296 0x01, // Command (CONNECT) 5296 0x01, // Command (CONNECT)
5297 0x00, // Reserved. 5297 0x00, // Reserved.
5298 0x03, // Address type (DOMAINNAME). 5298 0x03, // Address type (DOMAINNAME).
5299 0x0E, // Length of domain (14) 5299 0x0E, // Length of domain (14)
5300 // Domain string: 5300 // Domain string:
5301 'w', 'w', 'w', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'c', 'o', 'm', 5301 'w', 'w', 'w', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'c', 'o', 'm',
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
5336 const HttpResponseInfo* response = trans->GetResponseInfo(); 5336 const HttpResponseInfo* response = trans->GetResponseInfo();
5337 EXPECT_FALSE(response == NULL); 5337 EXPECT_FALSE(response == NULL);
5338 5338
5339 std::string response_text; 5339 std::string response_text;
5340 rv = ReadTransaction(trans.get(), &response_text); 5340 rv = ReadTransaction(trans.get(), &response_text);
5341 EXPECT_EQ(OK, rv); 5341 EXPECT_EQ(OK, rv);
5342 EXPECT_EQ("Payload", response_text); 5342 EXPECT_EQ("Payload", response_text);
5343 } 5343 }
5344 5344
5345 TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { 5345 TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) {
5346 HttpRequestInfo request;
5347 request.method = "GET";
5348 request.url = GURL("https://www.google.com/");
5349 request.load_flags = 0;
5350
5346 SessionDependencies session_deps( 5351 SessionDependencies session_deps(
5347 ProxyService::CreateFixed("socks5://myproxy:1080")); 5352 ProxyService::CreateFixed("socks5://myproxy:1080"));
5348 5353
5349 scoped_ptr<HttpTransaction> trans( 5354 scoped_ptr<HttpTransaction> trans(
5350 new HttpNetworkTransaction(CreateSession(&session_deps))); 5355 new HttpNetworkTransaction(CreateSession(&session_deps)));
5351 5356
5352 HttpRequestInfo request;
5353 request.method = "GET";
5354 request.url = GURL("https://www.google.com/");
5355 request.load_flags = 0;
5356
5357 const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; 5357 const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 };
5358 const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; 5358 const char kSOCKS5GreetResponse[] = { 0x05, 0x00 };
5359 const unsigned char kSOCKS5OkRequest[] = { 5359 const unsigned char kSOCKS5OkRequest[] = {
5360 0x05, // Version 5360 0x05, // Version
5361 0x01, // Command (CONNECT) 5361 0x01, // Command (CONNECT)
5362 0x00, // Reserved. 5362 0x00, // Reserved.
5363 0x03, // Address type (DOMAINNAME). 5363 0x03, // Address type (DOMAINNAME).
5364 0x0E, // Length of domain (14) 5364 0x0E, // Length of domain (14)
5365 // Domain string: 5365 // Domain string:
5366 'w', 'w', 'w', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'c', 'o', 'm', 5366 'w', 'w', 'w', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'c', 'o', 'm',
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
5431 alternate_protocols->SetAlternateProtocolFor( 5431 alternate_protocols->SetAlternateProtocolFor(
5432 HostPortPair("host.with.alternate", 80), 443, 5432 HostPortPair("host.with.alternate", 80), 443,
5433 HttpAlternateProtocols::NPN_SPDY_2); 5433 HttpAlternateProtocols::NPN_SPDY_2);
5434 5434
5435 return session; 5435 return session;
5436 } 5436 }
5437 5437
5438 int GroupNameTransactionHelper( 5438 int GroupNameTransactionHelper(
5439 const std::string& url, 5439 const std::string& url,
5440 const scoped_refptr<HttpNetworkSession>& session) { 5440 const scoped_refptr<HttpNetworkSession>& session) {
5441 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
5442
5443 HttpRequestInfo request; 5441 HttpRequestInfo request;
5444 request.method = "GET"; 5442 request.method = "GET";
5445 request.url = GURL(url); 5443 request.url = GURL(url);
5446 request.load_flags = 0; 5444 request.load_flags = 0;
5447 5445
5446 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
5447
5448 TestCompletionCallback callback; 5448 TestCompletionCallback callback;
5449 5449
5450 // We do not complete this request, the dtor will clean the transaction up. 5450 // We do not complete this request, the dtor will clean the transaction up.
5451 return trans->Start(&request, &callback, BoundNetLog()); 5451 return trans->Start(&request, &callback, BoundNetLog());
5452 } 5452 }
5453 5453
5454 TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { 5454 TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) {
5455 const GroupNameTest tests[] = { 5455 const GroupNameTest tests[] = {
5456 { 5456 {
5457 "", // unused 5457 "", // unused
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
5629 ssl_conn_pool->last_group_name_received()); 5629 ssl_conn_pool->last_group_name_received());
5630 else 5630 else
5631 EXPECT_EQ(tests[i].expected_group_name, 5631 EXPECT_EQ(tests[i].expected_group_name,
5632 socks_conn_pool->last_group_name_received()); 5632 socks_conn_pool->last_group_name_received());
5633 } 5633 }
5634 5634
5635 HttpStreamFactory::set_use_alternate_protocols(false); 5635 HttpStreamFactory::set_use_alternate_protocols(false);
5636 } 5636 }
5637 5637
5638 TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { 5638 TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) {
5639 HttpRequestInfo request;
5640 request.method = "GET";
5641 request.url = GURL("http://www.google.com/");
5642
5639 SessionDependencies session_deps( 5643 SessionDependencies session_deps(
5640 ProxyService::CreateFixed("myproxy:70;foobar:80")); 5644 ProxyService::CreateFixed("myproxy:70;foobar:80"));
5641 5645
5642 // This simulates failure resolving all hostnames; that means we will fail 5646 // This simulates failure resolving all hostnames; that means we will fail
5643 // connecting to both proxies (myproxy:70 and foobar:80). 5647 // connecting to both proxies (myproxy:70 and foobar:80).
5644 session_deps.host_resolver->rules()->AddSimulatedFailure("*"); 5648 session_deps.host_resolver->rules()->AddSimulatedFailure("*");
5645 5649
5646 scoped_ptr<HttpTransaction> trans( 5650 scoped_ptr<HttpTransaction> trans(
5647 new HttpNetworkTransaction(CreateSession(&session_deps))); 5651 new HttpNetworkTransaction(CreateSession(&session_deps)));
5648 5652
5649 HttpRequestInfo request;
5650 request.method = "GET";
5651 request.url = GURL("http://www.google.com/");
5652
5653 TestCompletionCallback callback; 5653 TestCompletionCallback callback;
5654 5654
5655 int rv = trans->Start(&request, &callback, BoundNetLog()); 5655 int rv = trans->Start(&request, &callback, BoundNetLog());
5656 EXPECT_EQ(ERR_IO_PENDING, rv); 5656 EXPECT_EQ(ERR_IO_PENDING, rv);
5657 5657
5658 rv = callback.WaitForResult(); 5658 rv = callback.WaitForResult();
5659 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); 5659 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv);
5660 } 5660 }
5661 5661
5662 // Host resolution observer used by 5662 // Host resolution observer used by
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
5699 DISALLOW_COPY_AND_ASSIGN(ResolutionReferrerObserver); 5699 DISALLOW_COPY_AND_ASSIGN(ResolutionReferrerObserver);
5700 }; 5700 };
5701 5701
5702 // Make sure that when HostResolver::Resolve() is invoked, it passes through 5702 // Make sure that when HostResolver::Resolve() is invoked, it passes through
5703 // the "referrer". This is depended on by the DNS prefetch observer. 5703 // the "referrer". This is depended on by the DNS prefetch observer.
5704 TEST_F(HttpNetworkTransactionTest, ResolveMadeWithReferrer) { 5704 TEST_F(HttpNetworkTransactionTest, ResolveMadeWithReferrer) {
5705 GURL referrer = GURL("http://expected-referrer/"); 5705 GURL referrer = GURL("http://expected-referrer/");
5706 EXPECT_TRUE(referrer.is_valid()); 5706 EXPECT_TRUE(referrer.is_valid());
5707 ResolutionReferrerObserver resolution_observer(referrer); 5707 ResolutionReferrerObserver resolution_observer(referrer);
5708 5708
5709 // Issue a request, containing an HTTP referrer.
5710 HttpRequestInfo request;
5711 request.method = "GET";
5712 request.referrer = referrer;
5713 request.url = GURL("http://www.google.com/");
5714
5709 SessionDependencies session_deps; 5715 SessionDependencies session_deps;
5710 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( 5716 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(
5711 CreateSession(&session_deps))); 5717 CreateSession(&session_deps)));
5712 5718
5713 // Attach an observer to watch the host resolutions being made. 5719 // Attach an observer to watch the host resolutions being made.
5714 session_deps.host_resolver->AddObserver(&resolution_observer); 5720 session_deps.host_resolver->AddObserver(&resolution_observer);
5715 5721
5716 // Connect up a mock socket which will fail when reading. 5722 // Connect up a mock socket which will fail when reading.
5717 MockRead data_reads[] = { 5723 MockRead data_reads[] = {
5718 MockRead(false, ERR_FAILED), 5724 MockRead(false, ERR_FAILED),
5719 }; 5725 };
5720 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 5726 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
5721 session_deps.socket_factory.AddSocketDataProvider(&data); 5727 session_deps.socket_factory.AddSocketDataProvider(&data);
5722 5728
5723 // Issue a request, containing an HTTP referrer.
5724 HttpRequestInfo request;
5725 request.method = "GET";
5726 request.referrer = referrer;
5727 request.url = GURL("http://www.google.com/");
5728
5729 // Run the request until it fails reading from the socket. 5729 // Run the request until it fails reading from the socket.
5730 TestCompletionCallback callback; 5730 TestCompletionCallback callback;
5731 int rv = trans->Start(&request, &callback, BoundNetLog()); 5731 int rv = trans->Start(&request, &callback, BoundNetLog());
5732 EXPECT_EQ(ERR_IO_PENDING, rv); 5732 EXPECT_EQ(ERR_IO_PENDING, rv);
5733 rv = callback.WaitForResult(); 5733 rv = callback.WaitForResult();
5734 EXPECT_EQ(ERR_FAILED, rv); 5734 EXPECT_EQ(ERR_FAILED, rv);
5735 5735
5736 // Check that the host resolution observer saw |referrer|. 5736 // Check that the host resolution observer saw |referrer|.
5737 EXPECT_TRUE(resolution_observer.did_complete_with_expected_referrer()); 5737 EXPECT_TRUE(resolution_observer.did_complete_with_expected_referrer());
5738 } 5738 }
5739 5739
5740 // Base test to make sure that when the load flags for a request specify to 5740 // Base test to make sure that when the load flags for a request specify to
5741 // bypass the cache, the DNS cache is not used. 5741 // bypass the cache, the DNS cache is not used.
5742 void BypassHostCacheOnRefreshHelper(int load_flags) { 5742 void BypassHostCacheOnRefreshHelper(int load_flags) {
5743 // Issue a request, asking to bypass the cache(s).
5744 HttpRequestInfo request;
5745 request.method = "GET";
5746 request.load_flags = load_flags;
5747 request.url = GURL("http://www.google.com/");
5748
5743 SessionDependencies session_deps; 5749 SessionDependencies session_deps;
5744 5750
5745 // Select a host resolver that does caching. 5751 // Select a host resolver that does caching.
5746 session_deps.host_resolver.reset(new MockCachingHostResolver); 5752 session_deps.host_resolver.reset(new MockCachingHostResolver);
5747 5753
5748 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( 5754 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(
5749 CreateSession(&session_deps))); 5755 CreateSession(&session_deps)));
5750 5756
5751 // Warm up the host cache so it has an entry for "www.google.com" (by doing 5757 // Warm up the host cache so it has an entry for "www.google.com" (by doing
5752 // a synchronous lookup.) 5758 // a synchronous lookup.)
(...skipping 15 matching lines...) Expand all
5768 // we can tell if the next lookup hit the cache, or the "network". 5774 // we can tell if the next lookup hit the cache, or the "network".
5769 // (cache --> success, "network" --> failure). 5775 // (cache --> success, "network" --> failure).
5770 session_deps.host_resolver->rules()->AddSimulatedFailure("www.google.com"); 5776 session_deps.host_resolver->rules()->AddSimulatedFailure("www.google.com");
5771 5777
5772 // Connect up a mock socket which will fail with ERR_UNEXPECTED during the 5778 // Connect up a mock socket which will fail with ERR_UNEXPECTED during the
5773 // first read -- this won't be reached as the host resolution will fail first. 5779 // first read -- this won't be reached as the host resolution will fail first.
5774 MockRead data_reads[] = { MockRead(false, ERR_UNEXPECTED) }; 5780 MockRead data_reads[] = { MockRead(false, ERR_UNEXPECTED) };
5775 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 5781 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
5776 session_deps.socket_factory.AddSocketDataProvider(&data); 5782 session_deps.socket_factory.AddSocketDataProvider(&data);
5777 5783
5778 // Issue a request, asking to bypass the cache(s).
5779 HttpRequestInfo request;
5780 request.method = "GET";
5781 request.load_flags = load_flags;
5782 request.url = GURL("http://www.google.com/");
5783
5784 // Run the request. 5784 // Run the request.
5785 TestCompletionCallback callback; 5785 TestCompletionCallback callback;
5786 rv = trans->Start(&request, &callback, BoundNetLog()); 5786 rv = trans->Start(&request, &callback, BoundNetLog());
5787 ASSERT_EQ(ERR_IO_PENDING, rv); 5787 ASSERT_EQ(ERR_IO_PENDING, rv);
5788 rv = callback.WaitForResult(); 5788 rv = callback.WaitForResult();
5789 5789
5790 // If we bypassed the cache, we would have gotten a failure while resolving 5790 // If we bypassed the cache, we would have gotten a failure while resolving
5791 // "www.google.com". 5791 // "www.google.com".
5792 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); 5792 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv);
5793 } 5793 }
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
5989 new HttpNetworkTransaction(CreateSession(&session_deps))); 5989 new HttpNetworkTransaction(CreateSession(&session_deps)));
5990 5990
5991 int rv = trans->Start(&request, &callback, BoundNetLog()); 5991 int rv = trans->Start(&request, &callback, BoundNetLog());
5992 EXPECT_EQ(ERR_IO_PENDING, rv); 5992 EXPECT_EQ(ERR_IO_PENDING, rv);
5993 5993
5994 rv = callback.WaitForResult(); 5994 rv = callback.WaitForResult();
5995 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); 5995 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv);
5996 } 5996 }
5997 5997
5998 TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { 5998 TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) {
5999 SessionDependencies session_deps;
6000 scoped_ptr<HttpTransaction> trans(
6001 new HttpNetworkTransaction(CreateSession(&session_deps)));
6002
6003 HttpRequestInfo request; 5999 HttpRequestInfo request;
6004 request.method = "GET"; 6000 request.method = "GET";
6005 request.url = GURL("http://www.google.com/"); 6001 request.url = GURL("http://www.google.com/");
6006 request.load_flags = 0; 6002 request.load_flags = 0;
6007 6003
6004 SessionDependencies session_deps;
6005 scoped_ptr<HttpTransaction> trans(
6006 new HttpNetworkTransaction(CreateSession(&session_deps)));
6007
6008 MockRead data_reads[] = { 6008 MockRead data_reads[] = {
6009 MockRead("HTTP/1.0 200 OK\r\nContent-Length:6719476739\r\n\r\n"), 6009 MockRead("HTTP/1.0 200 OK\r\nContent-Length:6719476739\r\n\r\n"),
6010 MockRead(false, OK), 6010 MockRead(false, OK),
6011 }; 6011 };
6012 6012
6013 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 6013 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
6014 session_deps.socket_factory.AddSocketDataProvider(&data); 6014 session_deps.socket_factory.AddSocketDataProvider(&data);
6015 6015
6016 TestCompletionCallback callback; 6016 TestCompletionCallback callback;
6017 6017
6018 int rv = trans->Start(&request, &callback, BoundNetLog()); 6018 int rv = trans->Start(&request, &callback, BoundNetLog());
6019 EXPECT_EQ(ERR_IO_PENDING, rv); 6019 EXPECT_EQ(ERR_IO_PENDING, rv);
6020 6020
6021 EXPECT_EQ(OK, callback.WaitForResult()); 6021 EXPECT_EQ(OK, callback.WaitForResult());
6022 6022
6023 const HttpResponseInfo* response = trans->GetResponseInfo(); 6023 const HttpResponseInfo* response = trans->GetResponseInfo();
6024 EXPECT_TRUE(response != NULL); 6024 EXPECT_TRUE(response != NULL);
6025 6025
6026 EXPECT_TRUE(response->headers != NULL); 6026 EXPECT_TRUE(response->headers != NULL);
6027 EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); 6027 EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine());
6028 6028
6029 std::string response_data; 6029 std::string response_data;
6030 rv = ReadTransaction(trans.get(), &response_data); 6030 rv = ReadTransaction(trans.get(), &response_data);
6031 EXPECT_EQ(ERR_CONNECTION_CLOSED, rv); 6031 EXPECT_EQ(ERR_CONNECTION_CLOSED, rv);
6032 } 6032 }
6033 6033
6034 TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { 6034 TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) {
6035 SessionDependencies session_deps;
6036 scoped_ptr<HttpTransaction> trans(
6037 new HttpNetworkTransaction(CreateSession(&session_deps)));
6038
6039 HttpRequestInfo request; 6035 HttpRequestInfo request;
6040 request.method = "POST"; 6036 request.method = "POST";
6041 request.url = GURL("http://www.google.com/upload"); 6037 request.url = GURL("http://www.google.com/upload");
6042 request.upload_data = new UploadData; 6038 request.upload_data = new UploadData;
6043 request.load_flags = 0; 6039 request.load_flags = 0;
6044 6040
6041 SessionDependencies session_deps;
6042 scoped_ptr<HttpTransaction> trans(
6043 new HttpNetworkTransaction(CreateSession(&session_deps)));
6044
6045 FilePath temp_file_path; 6045 FilePath temp_file_path;
6046 ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file_path)); 6046 ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file_path));
6047 const uint64 kFakeSize = 100000; // file is actually blank 6047 const uint64 kFakeSize = 100000; // file is actually blank
6048 6048
6049 std::vector<UploadData::Element> elements; 6049 std::vector<UploadData::Element> elements;
6050 UploadData::Element element; 6050 UploadData::Element element;
6051 element.SetToFilePath(temp_file_path); 6051 element.SetToFilePath(temp_file_path);
6052 element.SetContentLength(kFakeSize); 6052 element.SetContentLength(kFakeSize);
6053 elements.push_back(element); 6053 elements.push_back(element);
6054 request.upload_data->SetElements(elements); 6054 request.upload_data->SetElements(elements);
(...skipping 23 matching lines...) Expand all
6078 6078
6079 std::string response_data; 6079 std::string response_data;
6080 rv = ReadTransaction(trans.get(), &response_data); 6080 rv = ReadTransaction(trans.get(), &response_data);
6081 EXPECT_EQ(OK, rv); 6081 EXPECT_EQ(OK, rv);
6082 EXPECT_EQ("hello world", response_data); 6082 EXPECT_EQ("hello world", response_data);
6083 6083
6084 file_util::Delete(temp_file_path, false); 6084 file_util::Delete(temp_file_path, false);
6085 } 6085 }
6086 6086
6087 TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { 6087 TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) {
6088 HttpRequestInfo request;
6089 request.method = "POST";
6090 request.url = GURL("http://www.google.com/upload");
6091 request.upload_data = new UploadData;
6092 request.load_flags = 0;
6093
6088 // If we try to upload an unreadable file, the network stack should report 6094 // If we try to upload an unreadable file, the network stack should report
6089 // the file size as zero and upload zero bytes for that file. 6095 // the file size as zero and upload zero bytes for that file.
6090 SessionDependencies session_deps; 6096 SessionDependencies session_deps;
6091 scoped_ptr<HttpTransaction> trans( 6097 scoped_ptr<HttpTransaction> trans(
6092 new HttpNetworkTransaction(CreateSession(&session_deps))); 6098 new HttpNetworkTransaction(CreateSession(&session_deps)));
6093 6099
6094 FilePath temp_file; 6100 FilePath temp_file;
6095 ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file)); 6101 ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file));
6096 std::string temp_file_content("Unreadable file."); 6102 std::string temp_file_content("Unreadable file.");
6097 ASSERT_TRUE(file_util::WriteFile(temp_file, temp_file_content.c_str(), 6103 ASSERT_TRUE(file_util::WriteFile(temp_file, temp_file_content.c_str(),
6098 temp_file_content.length())); 6104 temp_file_content.length()));
6099 ASSERT_TRUE(file_util::MakeFileUnreadable(temp_file)); 6105 ASSERT_TRUE(file_util::MakeFileUnreadable(temp_file));
6100 6106
6101 HttpRequestInfo request;
6102 request.method = "POST";
6103 request.url = GURL("http://www.google.com/upload");
6104 request.upload_data = new UploadData;
6105 request.load_flags = 0;
6106
6107 std::vector<UploadData::Element> elements; 6107 std::vector<UploadData::Element> elements;
6108 UploadData::Element element; 6108 UploadData::Element element;
6109 element.SetToFilePath(temp_file); 6109 element.SetToFilePath(temp_file);
6110 elements.push_back(element); 6110 elements.push_back(element);
6111 request.upload_data->SetElements(elements); 6111 request.upload_data->SetElements(elements);
6112 6112
6113 MockRead data_reads[] = { 6113 MockRead data_reads[] = {
6114 MockRead("HTTP/1.0 200 OK\r\n\r\n"), 6114 MockRead("HTTP/1.0 200 OK\r\n\r\n"),
6115 MockRead(false, OK), 6115 MockRead(false, OK),
6116 }; 6116 };
(...skipping 18 matching lines...) Expand all
6135 6135
6136 const HttpResponseInfo* response = trans->GetResponseInfo(); 6136 const HttpResponseInfo* response = trans->GetResponseInfo();
6137 EXPECT_TRUE(response != NULL); 6137 EXPECT_TRUE(response != NULL);
6138 EXPECT_TRUE(response->headers != NULL); 6138 EXPECT_TRUE(response->headers != NULL);
6139 EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); 6139 EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine());
6140 6140
6141 file_util::Delete(temp_file, false); 6141 file_util::Delete(temp_file, false);
6142 } 6142 }
6143 6143
6144 TEST_F(HttpNetworkTransactionTest, UnreadableUploadFileAfterAuthRestart) { 6144 TEST_F(HttpNetworkTransactionTest, UnreadableUploadFileAfterAuthRestart) {
6145 HttpRequestInfo request;
6146 request.method = "POST";
6147 request.url = GURL("http://www.google.com/upload");
6148 request.upload_data = new UploadData;
6149 request.load_flags = 0;
6150
6145 SessionDependencies session_deps; 6151 SessionDependencies session_deps;
6146 scoped_ptr<HttpTransaction> trans( 6152 scoped_ptr<HttpTransaction> trans(
6147 new HttpNetworkTransaction(CreateSession(&session_deps))); 6153 new HttpNetworkTransaction(CreateSession(&session_deps)));
6148 6154
6149 FilePath temp_file; 6155 FilePath temp_file;
6150 ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file)); 6156 ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file));
6151 std::string temp_file_contents("Unreadable file."); 6157 std::string temp_file_contents("Unreadable file.");
6152 std::string unreadable_contents(temp_file_contents.length(), '\0'); 6158 std::string unreadable_contents(temp_file_contents.length(), '\0');
6153 ASSERT_TRUE(file_util::WriteFile(temp_file, temp_file_contents.c_str(), 6159 ASSERT_TRUE(file_util::WriteFile(temp_file, temp_file_contents.c_str(),
6154 temp_file_contents.length())); 6160 temp_file_contents.length()));
6155 6161
6156 HttpRequestInfo request;
6157 request.method = "POST";
6158 request.url = GURL("http://www.google.com/upload");
6159 request.upload_data = new UploadData;
6160 request.load_flags = 0;
6161
6162 std::vector<UploadData::Element> elements; 6162 std::vector<UploadData::Element> elements;
6163 UploadData::Element element; 6163 UploadData::Element element;
6164 element.SetToFilePath(temp_file); 6164 element.SetToFilePath(temp_file);
6165 elements.push_back(element); 6165 elements.push_back(element);
6166 request.upload_data->SetElements(elements); 6166 request.upload_data->SetElements(elements);
6167 6167
6168 MockRead data_reads[] = { 6168 MockRead data_reads[] = {
6169 MockRead("HTTP/1.1 401 Unauthorized\r\n"), 6169 MockRead("HTTP/1.1 401 Unauthorized\r\n"),
6170 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), 6170 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
6171 MockRead("Content-Length: 0\r\n\r\n"), // No response body. 6171 MockRead("Content-Length: 0\r\n\r\n"), // No response body.
(...skipping 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after
7377 HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); 7377 HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock());
7378 auth_handler->set_connection_based(true); 7378 auth_handler->set_connection_based(true);
7379 std::string auth_challenge = "Mock realm=server"; 7379 std::string auth_challenge = "Mock realm=server";
7380 GURL origin("http://www.example.com"); 7380 GURL origin("http://www.example.com");
7381 HttpAuth::ChallengeTokenizer tokenizer(auth_challenge.begin(), 7381 HttpAuth::ChallengeTokenizer tokenizer(auth_challenge.begin(),
7382 auth_challenge.end()); 7382 auth_challenge.end());
7383 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, 7383 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER,
7384 origin, BoundNetLog()); 7384 origin, BoundNetLog());
7385 auth_factory->set_mock_handler(auth_handler, HttpAuth::AUTH_SERVER); 7385 auth_factory->set_mock_handler(auth_handler, HttpAuth::AUTH_SERVER);
7386 7386
7387 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
7388 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
7389
7390 int rv = OK; 7387 int rv = OK;
7391 const HttpResponseInfo* response = NULL; 7388 const HttpResponseInfo* response = NULL;
7392 HttpRequestInfo request; 7389 HttpRequestInfo request;
7393 request.method = "GET"; 7390 request.method = "GET";
7394 request.url = origin; 7391 request.url = origin;
7395 request.load_flags = 0; 7392 request.load_flags = 0;
7393
7394 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
7395 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
7396 TestCompletionCallback callback; 7396 TestCompletionCallback callback;
7397 7397
7398 const MockWrite kGet( 7398 const MockWrite kGet(
7399 "GET / HTTP/1.1\r\n" 7399 "GET / HTTP/1.1\r\n"
7400 "Host: www.example.com\r\n" 7400 "Host: www.example.com\r\n"
7401 "Connection: keep-alive\r\n\r\n"); 7401 "Connection: keep-alive\r\n\r\n");
7402 const MockWrite kGetAuth( 7402 const MockWrite kGetAuth(
7403 "GET / HTTP/1.1\r\n" 7403 "GET / HTTP/1.1\r\n"
7404 "Host: www.example.com\r\n" 7404 "Host: www.example.com\r\n"
7405 "Connection: keep-alive\r\n" 7405 "Connection: keep-alive\r\n"
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
7852 // for is the callback from the HttpStreamRequest. 7852 // for is the callback from the HttpStreamRequest.
7853 // Then cancel the transaction. 7853 // Then cancel the transaction.
7854 // Verify that we don't crash. 7854 // Verify that we don't crash.
7855 MockConnect mock_connect(false, OK); 7855 MockConnect mock_connect(false, OK);
7856 MockRead data_reads[] = { 7856 MockRead data_reads[] = {
7857 MockRead(false, "HTTP/1.0 200 OK\r\n\r\n"), 7857 MockRead(false, "HTTP/1.0 200 OK\r\n\r\n"),
7858 MockRead(false, "hello world"), 7858 MockRead(false, "hello world"),
7859 MockRead(false, OK), 7859 MockRead(false, OK),
7860 }; 7860 };
7861 7861
7862 HttpRequestInfo request;
7863 request.method = "GET";
7864 request.url = GURL("http://www.google.com/");
7865 request.load_flags = 0;
7866
7862 SessionDependencies session_deps; 7867 SessionDependencies session_deps;
7863 session_deps.host_resolver->set_synchronous_mode(true); 7868 session_deps.host_resolver->set_synchronous_mode(true);
7864 scoped_ptr<HttpTransaction> trans( 7869 scoped_ptr<HttpTransaction> trans(
7865 new HttpNetworkTransaction(CreateSession(&session_deps))); 7870 new HttpNetworkTransaction(CreateSession(&session_deps)));
7866 7871
7867 HttpRequestInfo request;
7868 request.method = "GET";
7869 request.url = GURL("http://www.google.com/");
7870 request.load_flags = 0;
7871
7872 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 7872 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
7873 data.set_connect_data(mock_connect); 7873 data.set_connect_data(mock_connect);
7874 session_deps.socket_factory.AddSocketDataProvider(&data); 7874 session_deps.socket_factory.AddSocketDataProvider(&data);
7875 7875
7876 TestCompletionCallback callback; 7876 TestCompletionCallback callback;
7877 7877
7878 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 7878 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
7879 int rv = trans->Start(&request, &callback, log.bound()); 7879 int rv = trans->Start(&request, &callback, log.bound());
7880 EXPECT_EQ(ERR_IO_PENDING, rv); 7880 EXPECT_EQ(ERR_IO_PENDING, rv);
7881 trans.reset(); // Cancel the transaction here. 7881 trans.reset(); // Cancel the transaction here.
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
8112 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session)); 8112 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session));
8113 8113
8114 int rv = trans->Start(&request, &callback, BoundNetLog()); 8114 int rv = trans->Start(&request, &callback, BoundNetLog());
8115 EXPECT_EQ(ERR_IO_PENDING, rv); 8115 EXPECT_EQ(ERR_IO_PENDING, rv);
8116 EXPECT_EQ(OK, callback.WaitForResult()); 8116 EXPECT_EQ(OK, callback.WaitForResult());
8117 } 8117 }
8118 8118
8119 // Given a net error, cause that error to be returned from the first Write() 8119 // Given a net error, cause that error to be returned from the first Write()
8120 // call and verify that the HttpTransaction fails with that error. 8120 // call and verify that the HttpTransaction fails with that error.
8121 static void CheckErrorIsPassedBack(int error, bool async) { 8121 static void CheckErrorIsPassedBack(int error, bool async) {
8122 net::HttpRequestInfo request_info;
8123 request_info.url = GURL("https://www.example.com/");
8124 request_info.method = "GET";
8125 request_info.load_flags = net::LOAD_NORMAL;
8126
8122 SessionDependencies session_deps; 8127 SessionDependencies session_deps;
8123 8128
8124 SSLSocketDataProvider ssl_data(async, OK); 8129 SSLSocketDataProvider ssl_data(async, OK);
8125 net::MockWrite data_writes[] = { 8130 net::MockWrite data_writes[] = {
8126 net::MockWrite(async, error), 8131 net::MockWrite(async, error),
8127 }; 8132 };
8128 net::StaticSocketDataProvider data(NULL, 0, 8133 net::StaticSocketDataProvider data(NULL, 0,
8129 data_writes, arraysize(data_writes)); 8134 data_writes, arraysize(data_writes));
8130 session_deps.socket_factory.AddSocketDataProvider(&data); 8135 session_deps.socket_factory.AddSocketDataProvider(&data);
8131 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_data); 8136 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_data);
8132 8137
8133 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 8138 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
8134 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session)); 8139 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session));
8135 8140
8136 net::HttpRequestInfo request_info;
8137 request_info.url = GURL("https://www.example.com/");
8138 request_info.method = "GET";
8139 request_info.load_flags = net::LOAD_NORMAL;
8140
8141 TestCompletionCallback callback; 8141 TestCompletionCallback callback;
8142 int rv = trans->Start(&request_info, &callback, net::BoundNetLog()); 8142 int rv = trans->Start(&request_info, &callback, net::BoundNetLog());
8143 if (rv == net::ERR_IO_PENDING) 8143 if (rv == net::ERR_IO_PENDING)
8144 rv = callback.WaitForResult(); 8144 rv = callback.WaitForResult();
8145 ASSERT_EQ(error, rv); 8145 ASSERT_EQ(error, rv);
8146 } 8146 }
8147 8147
8148 TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { 8148 TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) {
8149 // Just check a grab bag of cert errors. 8149 // Just check a grab bag of cert errors.
8150 static const int kErrors[] = { 8150 static const int kErrors[] = {
8151 ERR_CERT_COMMON_NAME_INVALID, 8151 ERR_CERT_COMMON_NAME_INVALID,
8152 ERR_CERT_AUTHORITY_INVALID, 8152 ERR_CERT_AUTHORITY_INVALID,
8153 ERR_CERT_DATE_INVALID, 8153 ERR_CERT_DATE_INVALID,
8154 }; 8154 };
8155 for (size_t i = 0; i < arraysize(kErrors); i++) { 8155 for (size_t i = 0; i < arraysize(kErrors); i++) {
8156 CheckErrorIsPassedBack(kErrors[i], false /* not async */); 8156 CheckErrorIsPassedBack(kErrors[i], false /* not async */);
8157 CheckErrorIsPassedBack(kErrors[i], true /* async */); 8157 CheckErrorIsPassedBack(kErrors[i], true /* async */);
8158 } 8158 }
8159 } 8159 }
8160 8160
8161 // Test that the transaction is restarted in the event of an NPN misprediction. 8161 // Test that the transaction is restarted in the event of an NPN misprediction.
8162 TEST_F(HttpNetworkTransactionTest, NPNMispredict) { 8162 TEST_F(HttpNetworkTransactionTest, NPNMispredict) {
8163 net::HttpRequestInfo request_info;
8164 request_info.url = GURL("https://www.example.com/");
8165 request_info.method = "GET";
8166 request_info.load_flags = net::LOAD_NORMAL;
8167
8163 SessionDependencies session_deps; 8168 SessionDependencies session_deps;
8164 8169
8165 SSLSocketDataProvider ssl_data1(true /* async */, OK); 8170 SSLSocketDataProvider ssl_data1(true /* async */, OK);
8166 SSLSocketDataProvider ssl_data2(true /* async */, OK); 8171 SSLSocketDataProvider ssl_data2(true /* async */, OK);
8167 8172
8168 net::MockWrite data1_writes[] = { 8173 net::MockWrite data1_writes[] = {
8169 net::MockWrite(true /* async */, ERR_SSL_SNAP_START_NPN_MISPREDICTION), 8174 net::MockWrite(true /* async */, ERR_SSL_SNAP_START_NPN_MISPREDICTION),
8170 }; 8175 };
8171 net::MockRead data2_reads[] = { 8176 net::MockRead data2_reads[] = {
8172 net::MockRead("HTTP/1.0 200 OK\r\n\r\n"), 8177 net::MockRead("HTTP/1.0 200 OK\r\n\r\n"),
(...skipping 11 matching lines...) Expand all
8184 data2_writes, arraysize(data2_writes)); 8189 data2_writes, arraysize(data2_writes));
8185 8190
8186 session_deps.socket_factory.AddSocketDataProvider(&data1); 8191 session_deps.socket_factory.AddSocketDataProvider(&data1);
8187 session_deps.socket_factory.AddSocketDataProvider(&data2); 8192 session_deps.socket_factory.AddSocketDataProvider(&data2);
8188 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_data1); 8193 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_data1);
8189 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_data2); 8194 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_data2);
8190 8195
8191 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 8196 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
8192 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session)); 8197 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session));
8193 8198
8194 net::HttpRequestInfo request_info;
8195 request_info.url = GURL("https://www.example.com/");
8196 request_info.method = "GET";
8197 request_info.load_flags = net::LOAD_NORMAL;
8198
8199 TestCompletionCallback callback; 8199 TestCompletionCallback callback;
8200 int rv = trans->Start(&request_info, &callback, net::BoundNetLog()); 8200 int rv = trans->Start(&request_info, &callback, net::BoundNetLog());
8201 if (rv == net::ERR_IO_PENDING) 8201 if (rv == net::ERR_IO_PENDING)
8202 rv = callback.WaitForResult(); 8202 rv = callback.WaitForResult();
8203 ASSERT_EQ(OK, rv); 8203 ASSERT_EQ(OK, rv);
8204 8204
8205 std::string contents; 8205 std::string contents;
8206 rv = ReadTransaction(trans.get(), &contents); 8206 rv = ReadTransaction(trans.get(), &contents);
8207 EXPECT_EQ(net::OK, rv); 8207 EXPECT_EQ(net::OK, rv);
8208 EXPECT_EQ("hello world", contents); 8208 EXPECT_EQ("hello world", contents);
8209 } 8209 }
8210 8210
8211 // Ensure that a client certificate is removed from the SSL client auth 8211 // Ensure that a client certificate is removed from the SSL client auth
8212 // cache when: 8212 // cache when:
8213 // 1) No proxy is involved. 8213 // 1) No proxy is involved.
8214 // 2) TLS False Start is disabled. 8214 // 2) TLS False Start is disabled.
8215 // 3) The initial TLS handshake requests a client certificate. 8215 // 3) The initial TLS handshake requests a client certificate.
8216 // 4) The client supplies an invalid/unacceptable certificate. 8216 // 4) The client supplies an invalid/unacceptable certificate.
8217 TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { 8217 TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) {
8218 net::HttpRequestInfo request_info;
8219 request_info.url = GURL("https://www.example.com/");
8220 request_info.method = "GET";
8221 request_info.load_flags = net::LOAD_NORMAL;
8222
8218 SessionDependencies session_deps; 8223 SessionDependencies session_deps;
8219 8224
8220 scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); 8225 scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo());
8221 cert_request->host_and_port = "www.example.com:443"; 8226 cert_request->host_and_port = "www.example.com:443";
8222 8227
8223 // [ssl_]data1 contains the data for the first SSL handshake. When a 8228 // [ssl_]data1 contains the data for the first SSL handshake. When a
8224 // CertificateRequest is received for the first time, the handshake will 8229 // CertificateRequest is received for the first time, the handshake will
8225 // be aborted to allow the caller to provide a certificate. 8230 // be aborted to allow the caller to provide a certificate.
8226 SSLSocketDataProvider ssl_data1(true /* async */, 8231 SSLSocketDataProvider ssl_data1(true /* async */,
8227 net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED); 8232 net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED);
(...skipping 25 matching lines...) Expand all
8253 SSLSocketDataProvider ssl_data3(true /* async */, 8258 SSLSocketDataProvider ssl_data3(true /* async */,
8254 net::ERR_SSL_PROTOCOL_ERROR); 8259 net::ERR_SSL_PROTOCOL_ERROR);
8255 ssl_data3.cert_request_info = cert_request.get(); 8260 ssl_data3.cert_request_info = cert_request.get();
8256 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_data3); 8261 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_data3);
8257 net::StaticSocketDataProvider data3(NULL, 0, NULL, 0); 8262 net::StaticSocketDataProvider data3(NULL, 0, NULL, 0);
8258 session_deps.socket_factory.AddSocketDataProvider(&data3); 8263 session_deps.socket_factory.AddSocketDataProvider(&data3);
8259 8264
8260 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 8265 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
8261 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session)); 8266 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session));
8262 8267
8263 net::HttpRequestInfo request_info;
8264 request_info.url = GURL("https://www.example.com/");
8265 request_info.method = "GET";
8266 request_info.load_flags = net::LOAD_NORMAL;
8267
8268 // Begin the SSL handshake with the peer. This consumes ssl_data1. 8268 // Begin the SSL handshake with the peer. This consumes ssl_data1.
8269 TestCompletionCallback callback; 8269 TestCompletionCallback callback;
8270 int rv = trans->Start(&request_info, &callback, net::BoundNetLog()); 8270 int rv = trans->Start(&request_info, &callback, net::BoundNetLog());
8271 ASSERT_EQ(net::ERR_IO_PENDING, rv); 8271 ASSERT_EQ(net::ERR_IO_PENDING, rv);
8272 8272
8273 // Complete the SSL handshake, which should abort due to requiring a 8273 // Complete the SSL handshake, which should abort due to requiring a
8274 // client certificate. 8274 // client certificate.
8275 rv = callback.WaitForResult(); 8275 rv = callback.WaitForResult();
8276 ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); 8276 ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv);
8277 8277
(...skipping 23 matching lines...) Expand all
8301 &client_cert)); 8301 &client_cert));
8302 } 8302 }
8303 8303
8304 // Ensure that a client certificate is removed from the SSL client auth 8304 // Ensure that a client certificate is removed from the SSL client auth
8305 // cache when: 8305 // cache when:
8306 // 1) No proxy is involved. 8306 // 1) No proxy is involved.
8307 // 2) TLS False Start is enabled. 8307 // 2) TLS False Start is enabled.
8308 // 3) The initial TLS handshake requests a client certificate. 8308 // 3) The initial TLS handshake requests a client certificate.
8309 // 4) The client supplies an invalid/unacceptable certificate. 8309 // 4) The client supplies an invalid/unacceptable certificate.
8310 TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { 8310 TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) {
8311 net::HttpRequestInfo request_info;
8312 request_info.url = GURL("https://www.example.com/");
8313 request_info.method = "GET";
8314 request_info.load_flags = net::LOAD_NORMAL;
8315
8311 SessionDependencies session_deps; 8316 SessionDependencies session_deps;
8312 8317
8313 scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); 8318 scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo());
8314 cert_request->host_and_port = "www.example.com:443"; 8319 cert_request->host_and_port = "www.example.com:443";
8315 8320
8316 // When TLS False Start is used, SSLClientSocket::Connect() calls will 8321 // When TLS False Start is used, SSLClientSocket::Connect() calls will
8317 // return successfully after reading up to the peer's Certificate message. 8322 // return successfully after reading up to the peer's Certificate message.
8318 // This is to allow the caller to call SSLClientSocket::Write(), which can 8323 // This is to allow the caller to call SSLClientSocket::Write(), which can
8319 // enqueue application data to be sent in the same packet as the 8324 // enqueue application data to be sent in the same packet as the
8320 // ChangeCipherSpec and Finished messages. 8325 // ChangeCipherSpec and Finished messages.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
8358 SSLSocketDataProvider ssl_data3(true /* async */, net::OK); 8363 SSLSocketDataProvider ssl_data3(true /* async */, net::OK);
8359 ssl_data3.cert_request_info = cert_request.get(); 8364 ssl_data3.cert_request_info = cert_request.get();
8360 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_data3); 8365 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_data3);
8361 net::StaticSocketDataProvider data3( 8366 net::StaticSocketDataProvider data3(
8362 data2_reads, arraysize(data2_reads), NULL, 0); 8367 data2_reads, arraysize(data2_reads), NULL, 0);
8363 session_deps.socket_factory.AddSocketDataProvider(&data3); 8368 session_deps.socket_factory.AddSocketDataProvider(&data3);
8364 8369
8365 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 8370 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
8366 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session)); 8371 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session));
8367 8372
8368 net::HttpRequestInfo request_info;
8369 request_info.url = GURL("https://www.example.com/");
8370 request_info.method = "GET";
8371 request_info.load_flags = net::LOAD_NORMAL;
8372
8373 // Begin the initial SSL handshake. 8373 // Begin the initial SSL handshake.
8374 TestCompletionCallback callback; 8374 TestCompletionCallback callback;
8375 int rv = trans->Start(&request_info, &callback, net::BoundNetLog()); 8375 int rv = trans->Start(&request_info, &callback, net::BoundNetLog());
8376 ASSERT_EQ(net::ERR_IO_PENDING, rv); 8376 ASSERT_EQ(net::ERR_IO_PENDING, rv);
8377 8377
8378 // Complete the SSL handshake, which should abort due to requiring a 8378 // Complete the SSL handshake, which should abort due to requiring a
8379 // client certificate. 8379 // client certificate.
8380 rv = callback.WaitForResult(); 8380 rv = callback.WaitForResult();
8381 ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); 8381 ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv);
8382 8382
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
8501 // Now that the new handshake has failed, ensure that the client 8501 // Now that the new handshake has failed, ensure that the client
8502 // certificate was removed from the client auth cache. 8502 // certificate was removed from the client auth cache.
8503 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup("proxy:70", 8503 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup("proxy:70",
8504 &client_cert)); 8504 &client_cert));
8505 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup("www.example.com:443", 8505 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup("www.example.com:443",
8506 &client_cert)); 8506 &client_cert));
8507 } 8507 }
8508 } 8508 }
8509 8509
8510 } // namespace net 8510 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | tools/valgrind/memcheck/suppressions.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698