OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/http/http_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
6 | 6 |
7 #include <math.h> // ceil | 7 #include <math.h> // ceil |
8 #include <stdarg.h> | 8 #include <stdarg.h> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 MockRead("Content-Length: 5\r\n\r\n"), | 684 MockRead("Content-Length: 5\r\n\r\n"), |
685 MockRead("Hello"), | 685 MockRead("Hello"), |
686 }; | 686 }; |
687 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | 687 SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
688 arraysize(data_reads)); | 688 arraysize(data_reads)); |
689 EXPECT_EQ(OK, out.rv); | 689 EXPECT_EQ(OK, out.rv); |
690 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 690 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
691 EXPECT_EQ("Hello", out.response_data); | 691 EXPECT_EQ("Hello", out.response_data); |
692 } | 692 } |
693 | 693 |
694 // Checks that two identical Content-Disposition headers result in an error. | 694 // Checks that two identical Content-Disposition headers result in no error. |
695 TEST_F(HttpNetworkTransactionSpdy3Test, | 695 TEST_F(HttpNetworkTransactionSpdy3Test, |
696 DuplicateIdenticalContentDispositionHeaders) { | 696 TwoIdenticalContentDispositionHeaders) { |
697 MockRead data_reads[] = { | 697 MockRead data_reads[] = { |
698 MockRead("HTTP/1.1 200 OK\r\n"), | 698 MockRead("HTTP/1.1 200 OK\r\n"), |
699 MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), | 699 MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
700 MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), | 700 MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
701 MockRead("Content-Length: 5\r\n\r\n"), | 701 MockRead("Content-Length: 5\r\n\r\n"), |
702 MockRead("Hello"), | 702 MockRead("Hello"), |
703 }; | 703 }; |
704 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | 704 SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
705 arraysize(data_reads)); | 705 arraysize(data_reads)); |
706 EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION, out.rv); | 706 EXPECT_EQ(OK, out.rv); |
| 707 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 708 EXPECT_EQ("Hello", out.response_data); |
707 } | 709 } |
708 | 710 |
709 // Checks that two distinct Content-Disposition headers result in an error. | 711 // Checks that two distinct Content-Disposition headers result in an error. |
710 TEST_F(HttpNetworkTransactionSpdy3Test, | 712 TEST_F(HttpNetworkTransactionSpdy3Test, TwoDistinctContentDispositionHeaders) { |
711 DuplicateDistinctContentDispositionHeaders) { | |
712 MockRead data_reads[] = { | 713 MockRead data_reads[] = { |
713 MockRead("HTTP/1.1 200 OK\r\n"), | 714 MockRead("HTTP/1.1 200 OK\r\n"), |
714 MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), | 715 MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
715 MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), | 716 MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
716 MockRead("Content-Length: 5\r\n\r\n"), | 717 MockRead("Content-Length: 5\r\n\r\n"), |
717 MockRead("Hello"), | 718 MockRead("Hello"), |
718 }; | 719 }; |
719 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | 720 SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
720 arraysize(data_reads)); | 721 arraysize(data_reads)); |
721 EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION, out.rv); | 722 EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION, out.rv); |
722 } | 723 } |
723 | 724 |
724 // Checks the behavior of a single Location header. | 725 // Checks that two identical Location headers result in no error. |
725 TEST_F(HttpNetworkTransactionSpdy3Test, SingleLocationHeader) { | 726 // Also tests Location header behavior. |
| 727 TEST_F(HttpNetworkTransactionSpdy3Test, TwoIdenticalLocationHeaders) { |
726 MockRead data_reads[] = { | 728 MockRead data_reads[] = { |
727 MockRead("HTTP/1.1 302 Redirect\r\n"), | 729 MockRead("HTTP/1.1 302 Redirect\r\n"), |
728 MockRead("Location: http://good.com/\r\n"), | 730 MockRead("Location: http://good.com/\r\n"), |
| 731 MockRead("Location: http://good.com/\r\n"), |
729 MockRead("Content-Length: 0\r\n\r\n"), | 732 MockRead("Content-Length: 0\r\n\r\n"), |
730 MockRead(SYNCHRONOUS, OK), | 733 MockRead(SYNCHRONOUS, OK), |
731 }; | 734 }; |
732 | 735 |
733 HttpRequestInfo request; | 736 HttpRequestInfo request; |
734 request.method = "GET"; | 737 request.method = "GET"; |
735 request.url = GURL("http://redirect.com/"); | 738 request.url = GURL("http://redirect.com/"); |
736 request.load_flags = 0; | 739 request.load_flags = 0; |
737 | 740 |
738 SessionDependencies session_deps; | 741 SessionDependencies session_deps; |
(...skipping 11 matching lines...) Expand all Loading... |
750 EXPECT_EQ(OK, callback.WaitForResult()); | 753 EXPECT_EQ(OK, callback.WaitForResult()); |
751 | 754 |
752 const HttpResponseInfo* response = trans->GetResponseInfo(); | 755 const HttpResponseInfo* response = trans->GetResponseInfo(); |
753 ASSERT_TRUE(response != NULL && response->headers != NULL); | 756 ASSERT_TRUE(response != NULL && response->headers != NULL); |
754 EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); | 757 EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
755 std::string url; | 758 std::string url; |
756 EXPECT_TRUE(response->headers->IsRedirect(&url)); | 759 EXPECT_TRUE(response->headers->IsRedirect(&url)); |
757 EXPECT_EQ("http://good.com/", url); | 760 EXPECT_EQ("http://good.com/", url); |
758 } | 761 } |
759 | 762 |
760 // Checks that two identical Location headers result in an error. | 763 // Checks that two distinct Location headers result in an error. |
761 TEST_F(HttpNetworkTransactionSpdy3Test, DuplicateIdenticalLocationHeaders) { | 764 TEST_F(HttpNetworkTransactionSpdy3Test, TwoDistinctLocationHeaders) { |
762 MockRead data_reads[] = { | 765 MockRead data_reads[] = { |
763 MockRead("HTTP/1.1 302 Redirect\r\n"), | 766 MockRead("HTTP/1.1 302 Redirect\r\n"), |
764 MockRead("Location: http://good.com/\r\n"), | 767 MockRead("Location: http://good.com/\r\n"), |
765 MockRead("Location: http://good.com/\r\n"), | |
766 MockRead("Content-Length: 0\r\n\r\n"), | |
767 MockRead(SYNCHRONOUS, OK), | |
768 }; | |
769 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | |
770 arraysize(data_reads)); | |
771 EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION, out.rv); | |
772 } | |
773 | |
774 // Checks that two distinct Location headers result in an error. | |
775 TEST_F(HttpNetworkTransactionSpdy3Test, DuplicateDistinctLocationHeaders) { | |
776 MockRead data_reads[] = { | |
777 MockRead("HTTP/1.1 302 Redirect\r\n"), | |
778 MockRead("Location: http://good.com/\r\n"), | |
779 MockRead("Location: http://evil.com/\r\n"), | 768 MockRead("Location: http://evil.com/\r\n"), |
780 MockRead("Content-Length: 0\r\n\r\n"), | 769 MockRead("Content-Length: 0\r\n\r\n"), |
781 MockRead(SYNCHRONOUS, OK), | 770 MockRead(SYNCHRONOUS, OK), |
782 }; | 771 }; |
783 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | 772 SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
784 arraysize(data_reads)); | 773 arraysize(data_reads)); |
785 EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION, out.rv); | 774 EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION, out.rv); |
786 } | 775 } |
787 | 776 |
788 // Do a request using the HEAD method. Verify that we don't try to read the | 777 // Do a request using the HEAD method. Verify that we don't try to read the |
(...skipping 8589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9378 StaticSocketDataProvider* data[] = { &data1, &data2 }; | 9367 StaticSocketDataProvider* data[] = { &data1, &data2 }; |
9379 | 9368 |
9380 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data)); | 9369 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data)); |
9381 | 9370 |
9382 EXPECT_EQ(OK, out.rv); | 9371 EXPECT_EQ(OK, out.rv); |
9383 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); | 9372 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
9384 EXPECT_EQ("hello world", out.response_data); | 9373 EXPECT_EQ("hello world", out.response_data); |
9385 } | 9374 } |
9386 | 9375 |
9387 } // namespace net | 9376 } // namespace net |
OLD | NEW |