OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "net/base/auth.h" | 10 #include "net/base/auth.h" |
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 scoped_ptr<spdy::SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 3, LOWEST)); | 572 scoped_ptr<spdy::SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 3, LOWEST)); |
573 scoped_ptr<spdy::SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 3)); | 573 scoped_ptr<spdy::SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 3)); |
574 scoped_ptr<spdy::SpdyFrame> body2(ConstructSpdyBodyFrame(3, false)); | 574 scoped_ptr<spdy::SpdyFrame> body2(ConstructSpdyBodyFrame(3, false)); |
575 scoped_ptr<spdy::SpdyFrame> fbody2(ConstructSpdyBodyFrame(3, true)); | 575 scoped_ptr<spdy::SpdyFrame> fbody2(ConstructSpdyBodyFrame(3, true)); |
576 | 576 |
577 scoped_ptr<spdy::SpdyFrame> req3(ConstructSpdyGet(NULL, 0, false, 5, LOWEST)); | 577 scoped_ptr<spdy::SpdyFrame> req3(ConstructSpdyGet(NULL, 0, false, 5, LOWEST)); |
578 scoped_ptr<spdy::SpdyFrame> resp3(ConstructSpdyGetSynReply(NULL, 0, 5)); | 578 scoped_ptr<spdy::SpdyFrame> resp3(ConstructSpdyGetSynReply(NULL, 0, 5)); |
579 scoped_ptr<spdy::SpdyFrame> body3(ConstructSpdyBodyFrame(5, false)); | 579 scoped_ptr<spdy::SpdyFrame> body3(ConstructSpdyBodyFrame(5, false)); |
580 scoped_ptr<spdy::SpdyFrame> fbody3(ConstructSpdyBodyFrame(5, true)); | 580 scoped_ptr<spdy::SpdyFrame> fbody3(ConstructSpdyBodyFrame(5, true)); |
581 | 581 |
582 MockWrite writes[] = { CreateMockWrite(*req), | 582 MockWrite writes[] = { |
583 CreateMockWrite(*req2), | 583 CreateMockWrite(*req), |
584 CreateMockWrite(*req3), | 584 CreateMockWrite(*req2), |
| 585 CreateMockWrite(*req3), |
585 }; | 586 }; |
586 MockRead reads[] = { | 587 MockRead reads[] = { |
587 CreateMockRead(*resp, 1), | 588 CreateMockRead(*resp, 1), |
588 CreateMockRead(*body), | 589 CreateMockRead(*body), |
589 CreateMockRead(*resp2, 4), | 590 CreateMockRead(*resp2, 4), |
590 CreateMockRead(*body2), | 591 CreateMockRead(*body2), |
591 CreateMockRead(*resp3, 7), | 592 CreateMockRead(*resp3, 7), |
592 CreateMockRead(*body3), | 593 CreateMockRead(*body3), |
593 | 594 |
594 CreateMockRead(*fbody), | 595 CreateMockRead(*fbody), |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 | 651 |
651 out.rv = ReadTransaction(trans1.get(), &out.response_data); | 652 out.rv = ReadTransaction(trans1.get(), &out.response_data); |
652 helper.VerifyDataConsumed(); | 653 helper.VerifyDataConsumed(); |
653 EXPECT_EQ(OK, out.rv); | 654 EXPECT_EQ(OK, out.rv); |
654 | 655 |
655 EXPECT_EQ(OK, out.rv); | 656 EXPECT_EQ(OK, out.rv); |
656 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 657 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
657 EXPECT_EQ("hello!hello!", out.response_data); | 658 EXPECT_EQ("hello!hello!", out.response_data); |
658 } | 659 } |
659 | 660 |
| 661 TEST_P(SpdyNetworkTransactionTest, TwoGetsLateBinding) { |
| 662 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
| 663 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 664 scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame(1, false)); |
| 665 scoped_ptr<spdy::SpdyFrame> fbody(ConstructSpdyBodyFrame(1, true)); |
| 666 |
| 667 scoped_ptr<spdy::SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 3, LOWEST)); |
| 668 scoped_ptr<spdy::SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 669 scoped_ptr<spdy::SpdyFrame> body2(ConstructSpdyBodyFrame(3, false)); |
| 670 scoped_ptr<spdy::SpdyFrame> fbody2(ConstructSpdyBodyFrame(3, true)); |
| 671 |
| 672 MockWrite writes[] = { |
| 673 CreateMockWrite(*req), |
| 674 CreateMockWrite(*req2), |
| 675 }; |
| 676 MockRead reads[] = { |
| 677 CreateMockRead(*resp, 1), |
| 678 CreateMockRead(*body), |
| 679 CreateMockRead(*resp2, 4), |
| 680 CreateMockRead(*body2), |
| 681 CreateMockRead(*fbody), |
| 682 CreateMockRead(*fbody2), |
| 683 MockRead(true, 0, 0), // EOF |
| 684 }; |
| 685 scoped_refptr<OrderedSocketData> data( |
| 686 new OrderedSocketData(reads, arraysize(reads), |
| 687 writes, arraysize(writes))); |
| 688 |
| 689 MockConnect never_finishing_connect(true, ERR_IO_PENDING); |
| 690 |
| 691 scoped_refptr<OrderedSocketData> data_placeholder( |
| 692 new OrderedSocketData(NULL, 0, NULL, 0)); |
| 693 data_placeholder->set_connect_data(never_finishing_connect); |
| 694 |
| 695 BoundNetLog log; |
| 696 TransactionHelperResult out; |
| 697 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
| 698 BoundNetLog(), GetParam()); |
| 699 helper.RunPreTestSetup(); |
| 700 helper.AddData(data.get()); |
| 701 // We require placeholder data because two get requests are sent out, so |
| 702 // there needs to be two sets of SSL connection data. |
| 703 helper.AddData(data_placeholder.get()); |
| 704 scoped_ptr<HttpNetworkTransaction> trans1( |
| 705 new HttpNetworkTransaction(helper.session())); |
| 706 scoped_ptr<HttpNetworkTransaction> trans2( |
| 707 new HttpNetworkTransaction(helper.session())); |
| 708 |
| 709 TestCompletionCallback callback1; |
| 710 TestCompletionCallback callback2; |
| 711 |
| 712 HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 713 HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 714 |
| 715 out.rv = trans1->Start(&httpreq1, &callback1, log); |
| 716 ASSERT_EQ(ERR_IO_PENDING, out.rv); |
| 717 out.rv = trans2->Start(&httpreq2, &callback2, log); |
| 718 ASSERT_EQ(ERR_IO_PENDING, out.rv); |
| 719 |
| 720 out.rv = callback1.WaitForResult(); |
| 721 ASSERT_EQ(OK, out.rv); |
| 722 out.rv = callback2.WaitForResult(); |
| 723 ASSERT_EQ(OK, out.rv); |
| 724 |
| 725 const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 726 EXPECT_TRUE(response1->headers != NULL); |
| 727 EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 728 out.status_line = response1->headers->GetStatusLine(); |
| 729 out.response_info = *response1; |
| 730 out.rv = ReadTransaction(trans1.get(), &out.response_data); |
| 731 EXPECT_EQ(OK, out.rv); |
| 732 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 733 EXPECT_EQ("hello!hello!", out.response_data); |
| 734 |
| 735 const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 736 EXPECT_TRUE(response2->headers != NULL); |
| 737 EXPECT_TRUE(response2->was_fetched_via_spdy); |
| 738 out.status_line = response2->headers->GetStatusLine(); |
| 739 out.response_info = *response2; |
| 740 out.rv = ReadTransaction(trans2.get(), &out.response_data); |
| 741 EXPECT_EQ(OK, out.rv); |
| 742 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 743 EXPECT_EQ("hello!hello!", out.response_data); |
| 744 |
| 745 helper.VerifyDataConsumed(); |
| 746 } |
| 747 |
| 748 TEST_P(SpdyNetworkTransactionTest, TwoGetsLateBindingFromPreconnect) { |
| 749 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
| 750 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 751 scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame(1, false)); |
| 752 scoped_ptr<spdy::SpdyFrame> fbody(ConstructSpdyBodyFrame(1, true)); |
| 753 |
| 754 scoped_ptr<spdy::SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 3, LOWEST)); |
| 755 scoped_ptr<spdy::SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 756 scoped_ptr<spdy::SpdyFrame> body2(ConstructSpdyBodyFrame(3, false)); |
| 757 scoped_ptr<spdy::SpdyFrame> fbody2(ConstructSpdyBodyFrame(3, true)); |
| 758 |
| 759 MockWrite writes[] = { |
| 760 CreateMockWrite(*req), |
| 761 CreateMockWrite(*req2), |
| 762 }; |
| 763 MockRead reads[] = { |
| 764 CreateMockRead(*resp, 1), |
| 765 CreateMockRead(*body), |
| 766 CreateMockRead(*resp2, 4), |
| 767 CreateMockRead(*body2), |
| 768 CreateMockRead(*fbody), |
| 769 CreateMockRead(*fbody2), |
| 770 MockRead(true, 0, 0), // EOF |
| 771 }; |
| 772 scoped_refptr<OrderedSocketData> preconnect_data( |
| 773 new OrderedSocketData(reads, arraysize(reads), |
| 774 writes, arraysize(writes))); |
| 775 |
| 776 MockConnect never_finishing_connect(true, ERR_IO_PENDING); |
| 777 |
| 778 scoped_refptr<OrderedSocketData> data_placeholder( |
| 779 new OrderedSocketData(NULL, 0, NULL, 0)); |
| 780 data_placeholder->set_connect_data(never_finishing_connect); |
| 781 |
| 782 BoundNetLog log; |
| 783 TransactionHelperResult out; |
| 784 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
| 785 BoundNetLog(), GetParam()); |
| 786 helper.RunPreTestSetup(); |
| 787 helper.AddData(preconnect_data.get()); |
| 788 // We require placeholder data because 3 connections are attempted (first is |
| 789 // the preconnect, 2nd and 3rd are the never finished connections. |
| 790 helper.AddData(data_placeholder.get()); |
| 791 helper.AddData(data_placeholder.get()); |
| 792 |
| 793 scoped_ptr<HttpNetworkTransaction> trans1( |
| 794 new HttpNetworkTransaction(helper.session())); |
| 795 scoped_ptr<HttpNetworkTransaction> trans2( |
| 796 new HttpNetworkTransaction(helper.session())); |
| 797 |
| 798 TestCompletionCallback callback1; |
| 799 TestCompletionCallback callback2; |
| 800 |
| 801 HttpRequestInfo httpreq = CreateGetRequest(); |
| 802 |
| 803 // Preconnect the first. |
| 804 SSLConfig preconnect_ssl_config; |
| 805 helper.session()->ssl_config_service()->GetSSLConfig(&preconnect_ssl_config); |
| 806 HttpStreamFactory* http_stream_factory = |
| 807 helper.session()->http_stream_factory(); |
| 808 if (http_stream_factory->next_protos()) { |
| 809 preconnect_ssl_config.next_protos = *http_stream_factory->next_protos(); |
| 810 } |
| 811 |
| 812 http_stream_factory->PreconnectStreams( |
| 813 1, httpreq, preconnect_ssl_config, log); |
| 814 |
| 815 out.rv = trans1->Start(&httpreq, &callback1, log); |
| 816 ASSERT_EQ(ERR_IO_PENDING, out.rv); |
| 817 out.rv = trans2->Start(&httpreq, &callback2, log); |
| 818 ASSERT_EQ(ERR_IO_PENDING, out.rv); |
| 819 |
| 820 out.rv = callback1.WaitForResult(); |
| 821 ASSERT_EQ(OK, out.rv); |
| 822 out.rv = callback2.WaitForResult(); |
| 823 ASSERT_EQ(OK, out.rv); |
| 824 |
| 825 const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 826 EXPECT_TRUE(response1->headers != NULL); |
| 827 EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 828 out.status_line = response1->headers->GetStatusLine(); |
| 829 out.response_info = *response1; |
| 830 out.rv = ReadTransaction(trans1.get(), &out.response_data); |
| 831 EXPECT_EQ(OK, out.rv); |
| 832 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 833 EXPECT_EQ("hello!hello!", out.response_data); |
| 834 |
| 835 const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 836 EXPECT_TRUE(response2->headers != NULL); |
| 837 EXPECT_TRUE(response2->was_fetched_via_spdy); |
| 838 out.status_line = response2->headers->GetStatusLine(); |
| 839 out.response_info = *response2; |
| 840 out.rv = ReadTransaction(trans2.get(), &out.response_data); |
| 841 EXPECT_EQ(OK, out.rv); |
| 842 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 843 EXPECT_EQ("hello!hello!", out.response_data); |
| 844 |
| 845 helper.VerifyDataConsumed(); |
| 846 } |
| 847 |
660 // Similar to ThreeGets above, however this test adds a SETTINGS | 848 // Similar to ThreeGets above, however this test adds a SETTINGS |
661 // frame. The SETTINGS frame is read during the IO loop waiting on | 849 // frame. The SETTINGS frame is read during the IO loop waiting on |
662 // the first transaction completion, and sets a maximum concurrent | 850 // the first transaction completion, and sets a maximum concurrent |
663 // stream limit of 1. This means that our IO loop exists after the | 851 // stream limit of 1. This means that our IO loop exists after the |
664 // second transaction completes, so we can assert on read_index(). | 852 // second transaction completes, so we can assert on read_index(). |
665 TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrent) { | 853 TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrent) { |
666 // Construct the request. | 854 // Construct the request. |
667 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 855 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
668 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | 856 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
669 scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame(1, false)); | 857 scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame(1, false)); |
(...skipping 4740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5410 | 5598 |
5411 VerifyStreamsClosed(helper); | 5599 VerifyStreamsClosed(helper); |
5412 | 5600 |
5413 // Verify the SYN_REPLY. | 5601 // Verify the SYN_REPLY. |
5414 EXPECT_TRUE(response.headers != NULL); | 5602 EXPECT_TRUE(response.headers != NULL); |
5415 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 5603 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
5416 } | 5604 } |
5417 } | 5605 } |
5418 | 5606 |
5419 } // namespace net | 5607 } // namespace net |
OLD | NEW |