| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "net/base/capturing_net_log.h" | 9 #include "net/base/capturing_net_log.h" |
| 10 #include "net/base/net_log_unittest.h" | 10 #include "net/base/net_log_unittest.h" |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 socket_factory_.AddSocketDataProvider(&data); | 449 socket_factory_.AddSocketDataProvider(&data); |
| 450 SSLSocketDataProvider ssl(ASYNC, OK); | 450 SSLSocketDataProvider ssl(ASYNC, OK); |
| 451 socket_factory_.AddSSLSocketDataProvider(&ssl); | 451 socket_factory_.AddSSLSocketDataProvider(&ssl); |
| 452 | 452 |
| 453 CreateSession(); | 453 CreateSession(); |
| 454 | 454 |
| 455 SendRequestAndExpectHttpResponse("hello world"); | 455 SendRequestAndExpectHttpResponse("hello world"); |
| 456 } | 456 } |
| 457 | 457 |
| 458 TEST_F(QuicNetworkTransactionTest, UseAlternateProtocolForQuic) { | 458 TEST_F(QuicNetworkTransactionTest, UseAlternateProtocolForQuic) { |
| 459 HttpStreamFactory::EnableNpnSpdy(); // Enables QUIC too. | 459 HttpStreamFactory::EnableNpnSpdy3(); // Enables QUIC too. |
| 460 | 460 |
| 461 MockRead http_reads[] = { | 461 MockRead http_reads[] = { |
| 462 MockRead("HTTP/1.1 200 OK\r\n"), | 462 MockRead("HTTP/1.1 200 OK\r\n"), |
| 463 MockRead(kQuicAlternateProtocolHttpHeader), | 463 MockRead(kQuicAlternateProtocolHttpHeader), |
| 464 MockRead("hello world"), | 464 MockRead("hello world"), |
| 465 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | 465 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 466 MockRead(ASYNC, OK) | 466 MockRead(ASYNC, OK) |
| 467 }; | 467 }; |
| 468 | 468 |
| 469 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), | 469 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 CreateSession(); | 502 CreateSession(); |
| 503 | 503 |
| 504 SendRequestAndExpectHttpResponse("hello world"); | 504 SendRequestAndExpectHttpResponse("hello world"); |
| 505 SendRequestAndExpectQuicResponse("hello!"); | 505 SendRequestAndExpectQuicResponse("hello!"); |
| 506 } | 506 } |
| 507 | 507 |
| 508 TEST_F(QuicNetworkTransactionTest, UseAlternateProtocolForQuicForHttps) { | 508 TEST_F(QuicNetworkTransactionTest, UseAlternateProtocolForQuicForHttps) { |
| 509 params_.origin_to_force_quic_on = | 509 params_.origin_to_force_quic_on = |
| 510 HostPortPair::FromString("www.google.com:443"); | 510 HostPortPair::FromString("www.google.com:443"); |
| 511 params_.enable_quic_https = true; | 511 params_.enable_quic_https = true; |
| 512 HttpStreamFactory::EnableNpnSpdy(); // Enables QUIC too. | 512 HttpStreamFactory::EnableNpnSpdy3(); // Enables QUIC too. |
| 513 | 513 |
| 514 MockRead http_reads[] = { | 514 MockRead http_reads[] = { |
| 515 MockRead("HTTP/1.1 200 OK\r\n"), | 515 MockRead("HTTP/1.1 200 OK\r\n"), |
| 516 MockRead(kQuicAlternateProtocolHttpsHeader), | 516 MockRead(kQuicAlternateProtocolHttpsHeader), |
| 517 MockRead("hello world"), | 517 MockRead("hello world"), |
| 518 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | 518 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 519 MockRead(ASYNC, OK) | 519 MockRead(ASYNC, OK) |
| 520 }; | 520 }; |
| 521 | 521 |
| 522 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), | 522 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| (...skipping 29 matching lines...) Expand all Loading... |
| 552 // the alternate-protocol job will "win". | 552 // the alternate-protocol job will "win". |
| 553 AddHangingNonAlternateProtocolSocketData(); | 553 AddHangingNonAlternateProtocolSocketData(); |
| 554 | 554 |
| 555 CreateSession(); | 555 CreateSession(); |
| 556 | 556 |
| 557 // TODO(rtenneti): Test QUIC over HTTPS, GetSSLInfo(). | 557 // TODO(rtenneti): Test QUIC over HTTPS, GetSSLInfo(). |
| 558 SendRequestAndExpectHttpResponse("hello world"); | 558 SendRequestAndExpectHttpResponse("hello world"); |
| 559 } | 559 } |
| 560 | 560 |
| 561 TEST_F(QuicNetworkTransactionTest, HungAlternateProtocol) { | 561 TEST_F(QuicNetworkTransactionTest, HungAlternateProtocol) { |
| 562 HttpStreamFactory::EnableNpnSpdy(); // Enables QUIC too. | 562 HttpStreamFactory::EnableNpnSpdy3(); // Enables QUIC too. |
| 563 crypto_client_stream_factory_.set_handshake_mode( | 563 crypto_client_stream_factory_.set_handshake_mode( |
| 564 MockCryptoClientStream::COLD_START); | 564 MockCryptoClientStream::COLD_START); |
| 565 | 565 |
| 566 MockWrite http_writes[] = { | 566 MockWrite http_writes[] = { |
| 567 MockWrite(SYNCHRONOUS, 0, "GET / HTTP/1.1\r\n"), | 567 MockWrite(SYNCHRONOUS, 0, "GET / HTTP/1.1\r\n"), |
| 568 MockWrite(SYNCHRONOUS, 1, "Host: www.google.com\r\n"), | 568 MockWrite(SYNCHRONOUS, 1, "Host: www.google.com\r\n"), |
| 569 MockWrite(SYNCHRONOUS, 2, "Connection: keep-alive\r\n\r\n") | 569 MockWrite(SYNCHRONOUS, 2, "Connection: keep-alive\r\n\r\n") |
| 570 }; | 570 }; |
| 571 | 571 |
| 572 MockRead http_reads[] = { | 572 MockRead http_reads[] = { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 http_data2.StopAfter(arraysize(http_reads) + arraysize(http_writes)); | 611 http_data2.StopAfter(arraysize(http_reads) + arraysize(http_writes)); |
| 612 SendRequestAndExpectHttpResponse("hello world"); | 612 SendRequestAndExpectHttpResponse("hello world"); |
| 613 | 613 |
| 614 ASSERT_TRUE(http_data2.at_read_eof()); | 614 ASSERT_TRUE(http_data2.at_read_eof()); |
| 615 ASSERT_TRUE(http_data2.at_write_eof()); | 615 ASSERT_TRUE(http_data2.at_write_eof()); |
| 616 ASSERT_TRUE(!quic_data.at_read_eof()); | 616 ASSERT_TRUE(!quic_data.at_read_eof()); |
| 617 ASSERT_TRUE(!quic_data.at_write_eof()); | 617 ASSERT_TRUE(!quic_data.at_write_eof()); |
| 618 } | 618 } |
| 619 | 619 |
| 620 TEST_F(QuicNetworkTransactionTest, ZeroRTTWithHttpRace) { | 620 TEST_F(QuicNetworkTransactionTest, ZeroRTTWithHttpRace) { |
| 621 HttpStreamFactory::EnableNpnSpdy(); // Enables QUIC too. | 621 HttpStreamFactory::EnableNpnSpdy3(); // Enables QUIC too. |
| 622 | 622 |
| 623 scoped_ptr<QuicEncryptedPacket> req( | 623 scoped_ptr<QuicEncryptedPacket> req( |
| 624 ConstructDataPacket(1, 3, true, true, 0, | 624 ConstructDataPacket(1, 3, true, true, 0, |
| 625 GetRequestString("GET", "http", "/"))); | 625 GetRequestString("GET", "http", "/"))); |
| 626 scoped_ptr<QuicEncryptedPacket> ack(ConstructAckPacket(1, 0)); | 626 scoped_ptr<QuicEncryptedPacket> ack(ConstructAckPacket(1, 0)); |
| 627 | 627 |
| 628 MockWrite quic_writes[] = { | 628 MockWrite quic_writes[] = { |
| 629 MockWrite(SYNCHRONOUS, req->data(), req->length()), | 629 MockWrite(SYNCHRONOUS, req->data(), req->length()), |
| 630 MockWrite(SYNCHRONOUS, ack->data(), ack->length()), | 630 MockWrite(SYNCHRONOUS, ack->data(), ack->length()), |
| 631 }; | 631 }; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 648 // The non-alternate protocol job needs to hang in order to guarantee that | 648 // The non-alternate protocol job needs to hang in order to guarantee that |
| 649 // the alternate-protocol job will "win". | 649 // the alternate-protocol job will "win". |
| 650 AddHangingNonAlternateProtocolSocketData(); | 650 AddHangingNonAlternateProtocolSocketData(); |
| 651 | 651 |
| 652 CreateSession(); | 652 CreateSession(); |
| 653 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); | 653 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 654 SendRequestAndExpectQuicResponse("hello!"); | 654 SendRequestAndExpectQuicResponse("hello!"); |
| 655 } | 655 } |
| 656 | 656 |
| 657 TEST_F(QuicNetworkTransactionTest, ZeroRTTWithNoHttpRace) { | 657 TEST_F(QuicNetworkTransactionTest, ZeroRTTWithNoHttpRace) { |
| 658 HttpStreamFactory::EnableNpnSpdy(); // Enables QUIC too. | 658 HttpStreamFactory::EnableNpnSpdy3(); // Enables QUIC too. |
| 659 | 659 |
| 660 scoped_ptr<QuicEncryptedPacket> req( | 660 scoped_ptr<QuicEncryptedPacket> req( |
| 661 ConstructDataPacket(1, 3, true, true, 0, | 661 ConstructDataPacket(1, 3, true, true, 0, |
| 662 GetRequestString("GET", "http", "/"))); | 662 GetRequestString("GET", "http", "/"))); |
| 663 scoped_ptr<QuicEncryptedPacket> ack(ConstructAckPacket(1, 0)); | 663 scoped_ptr<QuicEncryptedPacket> ack(ConstructAckPacket(1, 0)); |
| 664 | 664 |
| 665 MockWrite quic_writes[] = { | 665 MockWrite quic_writes[] = { |
| 666 MockWrite(SYNCHRONOUS, req->data(), req->length()), | 666 MockWrite(SYNCHRONOUS, req->data(), req->length()), |
| 667 MockWrite(SYNCHRONOUS, ack->data(), ack->length()), | 667 MockWrite(SYNCHRONOUS, ack->data(), ack->length()), |
| 668 }; | 668 }; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 695 CompletionCallback(), | 695 CompletionCallback(), |
| 696 NULL, | 696 NULL, |
| 697 net_log_.bound()); | 697 net_log_.bound()); |
| 698 | 698 |
| 699 CreateSession(); | 699 CreateSession(); |
| 700 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); | 700 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 701 SendRequestAndExpectQuicResponse("hello!"); | 701 SendRequestAndExpectQuicResponse("hello!"); |
| 702 } | 702 } |
| 703 | 703 |
| 704 TEST_F(QuicNetworkTransactionTest, ZeroRTTWithConfirmationRequired) { | 704 TEST_F(QuicNetworkTransactionTest, ZeroRTTWithConfirmationRequired) { |
| 705 HttpStreamFactory::EnableNpnSpdy(); // Enables QUIC too. | 705 HttpStreamFactory::EnableNpnSpdy3(); // Enables QUIC too. |
| 706 | 706 |
| 707 scoped_ptr<QuicEncryptedPacket> req( | 707 scoped_ptr<QuicEncryptedPacket> req( |
| 708 ConstructDataPacket(1, 3, true, true, 0, | 708 ConstructDataPacket(1, 3, true, true, 0, |
| 709 GetRequestString("GET", "http", "/"))); | 709 GetRequestString("GET", "http", "/"))); |
| 710 scoped_ptr<QuicEncryptedPacket> ack(ConstructAckPacket(1, 0)); | 710 scoped_ptr<QuicEncryptedPacket> ack(ConstructAckPacket(1, 0)); |
| 711 | 711 |
| 712 MockWrite quic_writes[] = { | 712 MockWrite quic_writes[] = { |
| 713 MockWrite(SYNCHRONOUS, req->data(), req->length()), | 713 MockWrite(SYNCHRONOUS, req->data(), req->length()), |
| 714 MockWrite(SYNCHRONOUS, ack->data(), ack->length()), | 714 MockWrite(SYNCHRONOUS, ack->data(), ack->length()), |
| 715 }; | 715 }; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 TestCompletionCallback callback; | 754 TestCompletionCallback callback; |
| 755 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); | 755 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
| 756 EXPECT_EQ(ERR_IO_PENDING, rv); | 756 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 757 | 757 |
| 758 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( | 758 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 759 QuicSession::HANDSHAKE_CONFIRMED); | 759 QuicSession::HANDSHAKE_CONFIRMED); |
| 760 EXPECT_EQ(OK, callback.WaitForResult()); | 760 EXPECT_EQ(OK, callback.WaitForResult()); |
| 761 } | 761 } |
| 762 | 762 |
| 763 TEST_F(QuicNetworkTransactionTest, BrokenAlternateProtocol) { | 763 TEST_F(QuicNetworkTransactionTest, BrokenAlternateProtocol) { |
| 764 HttpStreamFactory::EnableNpnSpdy(); // Enables QUIC too. | 764 HttpStreamFactory::EnableNpnSpdy3(); // Enables QUIC too. |
| 765 | 765 |
| 766 // Alternate-protocol job | 766 // Alternate-protocol job |
| 767 scoped_ptr<QuicEncryptedPacket> close(ConstructConnectionClosePacket(1)); | 767 scoped_ptr<QuicEncryptedPacket> close(ConstructConnectionClosePacket(1)); |
| 768 MockRead quic_reads[] = { | 768 MockRead quic_reads[] = { |
| 769 MockRead(ASYNC, close->data(), close->length()), | 769 MockRead(ASYNC, close->data(), close->length()), |
| 770 MockRead(ASYNC, OK), // EOF | 770 MockRead(ASYNC, OK), // EOF |
| 771 }; | 771 }; |
| 772 StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), | 772 StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), |
| 773 NULL, 0); | 773 NULL, 0); |
| 774 socket_factory_.AddSocketDataProvider(&quic_data); | 774 socket_factory_.AddSocketDataProvider(&quic_data); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 785 NULL, 0); | 785 NULL, 0); |
| 786 socket_factory_.AddSocketDataProvider(&http_data); | 786 socket_factory_.AddSocketDataProvider(&http_data); |
| 787 | 787 |
| 788 CreateSession(); | 788 CreateSession(); |
| 789 AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); | 789 AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); |
| 790 SendRequestAndExpectHttpResponse("hello from http"); | 790 SendRequestAndExpectHttpResponse("hello from http"); |
| 791 ExpectBrokenAlternateProtocolMapping(); | 791 ExpectBrokenAlternateProtocolMapping(); |
| 792 } | 792 } |
| 793 | 793 |
| 794 TEST_F(QuicNetworkTransactionTest, BrokenAlternateProtocolReadError) { | 794 TEST_F(QuicNetworkTransactionTest, BrokenAlternateProtocolReadError) { |
| 795 HttpStreamFactory::EnableNpnSpdy(); // Enables QUIC too. | 795 HttpStreamFactory::EnableNpnSpdy3(); // Enables QUIC too. |
| 796 | 796 |
| 797 // Alternate-protocol job | 797 // Alternate-protocol job |
| 798 MockRead quic_reads[] = { | 798 MockRead quic_reads[] = { |
| 799 MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), | 799 MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), |
| 800 }; | 800 }; |
| 801 StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), | 801 StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), |
| 802 NULL, 0); | 802 NULL, 0); |
| 803 socket_factory_.AddSocketDataProvider(&quic_data); | 803 socket_factory_.AddSocketDataProvider(&quic_data); |
| 804 | 804 |
| 805 // Main job which will succeed even though the alternate job fails. | 805 // Main job which will succeed even though the alternate job fails. |
| 806 MockRead http_reads[] = { | 806 MockRead http_reads[] = { |
| 807 MockRead("HTTP/1.1 200 OK\r\n\r\n"), | 807 MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 808 MockRead("hello from http"), | 808 MockRead("hello from http"), |
| 809 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | 809 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 810 MockRead(ASYNC, OK) | 810 MockRead(ASYNC, OK) |
| 811 }; | 811 }; |
| 812 | 812 |
| 813 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), | 813 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 814 NULL, 0); | 814 NULL, 0); |
| 815 socket_factory_.AddSocketDataProvider(&http_data); | 815 socket_factory_.AddSocketDataProvider(&http_data); |
| 816 | 816 |
| 817 CreateSession(); | 817 CreateSession(); |
| 818 | 818 |
| 819 AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); | 819 AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); |
| 820 SendRequestAndExpectHttpResponse("hello from http"); | 820 SendRequestAndExpectHttpResponse("hello from http"); |
| 821 ExpectBrokenAlternateProtocolMapping(); | 821 ExpectBrokenAlternateProtocolMapping(); |
| 822 } | 822 } |
| 823 | 823 |
| 824 TEST_F(QuicNetworkTransactionTest, FailedZeroRttBrokenAlternateProtocol) { | 824 TEST_F(QuicNetworkTransactionTest, FailedZeroRttBrokenAlternateProtocol) { |
| 825 HttpStreamFactory::EnableNpnSpdy(); // Enables QUIC too. | 825 HttpStreamFactory::EnableNpnSpdy3(); // Enables QUIC too. |
| 826 | 826 |
| 827 // Alternate-protocol job | 827 // Alternate-protocol job |
| 828 MockRead quic_reads[] = { | 828 MockRead quic_reads[] = { |
| 829 MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), | 829 MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), |
| 830 }; | 830 }; |
| 831 StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), | 831 StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), |
| 832 NULL, 0); | 832 NULL, 0); |
| 833 socket_factory_.AddSocketDataProvider(&quic_data); | 833 socket_factory_.AddSocketDataProvider(&quic_data); |
| 834 | 834 |
| 835 AddHangingNonAlternateProtocolSocketData(); | 835 AddHangingNonAlternateProtocolSocketData(); |
| 836 | 836 |
| 837 CreateSession(); | 837 CreateSession(); |
| 838 | 838 |
| 839 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); | 839 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 840 | 840 |
| 841 scoped_ptr<HttpNetworkTransaction> trans( | 841 scoped_ptr<HttpNetworkTransaction> trans( |
| 842 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); | 842 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
| 843 TestCompletionCallback callback; | 843 TestCompletionCallback callback; |
| 844 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); | 844 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
| 845 EXPECT_EQ(ERR_IO_PENDING, rv); | 845 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 846 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); | 846 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
| 847 | 847 |
| 848 ExpectBrokenAlternateProtocolMapping(); | 848 ExpectBrokenAlternateProtocolMapping(); |
| 849 } | 849 } |
| 850 | 850 |
| 851 } // namespace test | 851 } // namespace test |
| 852 } // namespace net | 852 } // namespace net |
| OLD | NEW |