OLD | NEW |
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 <math.h> // ceil | 5 #include <math.h> // ceil |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
12 #include "net/base/completion_callback.h" | 12 #include "net/base/completion_callback.h" |
13 #include "net/base/mock_host_resolver.h" | 13 #include "net/base/mock_host_resolver.h" |
14 #include "net/base/request_priority.h" | 14 #include "net/base/request_priority.h" |
15 #include "net/base/ssl_config_service_defaults.h" | 15 #include "net/base/ssl_config_service_defaults.h" |
16 #include "net/base/ssl_info.h" | 16 #include "net/base/ssl_info.h" |
17 #include "net/base/test_completion_callback.h" | 17 #include "net/base/test_completion_callback.h" |
18 #include "net/base/upload_data.h" | 18 #include "net/base/upload_data.h" |
19 #include "net/spdy/spdy_session_pool.h" | |
20 #include "net/http/http_auth_handler_ntlm.h" | 19 #include "net/http/http_auth_handler_ntlm.h" |
21 #include "net/http/http_basic_stream.h" | 20 #include "net/http/http_basic_stream.h" |
22 #include "net/http/http_network_session.h" | 21 #include "net/http/http_network_session.h" |
23 #include "net/http/http_network_transaction.h" | 22 #include "net/http/http_network_transaction.h" |
24 #include "net/http/http_stream.h" | 23 #include "net/http/http_stream.h" |
25 #include "net/http/http_transaction_unittest.h" | 24 #include "net/http/http_transaction_unittest.h" |
26 #include "net/proxy/proxy_config_service_fixed.h" | 25 #include "net/proxy/proxy_config_service_fixed.h" |
27 #include "net/socket/client_socket_factory.h" | 26 #include "net/socket/client_socket_factory.h" |
28 #include "net/socket/socket_test_util.h" | 27 #include "net/socket/socket_test_util.h" |
29 #include "net/socket/ssl_client_socket.h" | 28 #include "net/socket/ssl_client_socket.h" |
| 29 #include "net/spdy/spdy_framer.h" |
| 30 #include "net/spdy/spdy_session.h" |
| 31 #include "net/spdy/spdy_session_pool.h" |
| 32 #include "net/spdy/spdy_test_util.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
31 #include "testing/platform_test.h" | 34 #include "testing/platform_test.h" |
32 | 35 |
33 //----------------------------------------------------------------------------- | 36 //----------------------------------------------------------------------------- |
34 | 37 |
35 namespace net { | 38 namespace net { |
36 | 39 |
37 // Helper to manage the lifetimes of the dependencies for a | 40 // Helper to manage the lifetimes of the dependencies for a |
38 // HttpNetworkTransaction. | 41 // HttpNetworkTransaction. |
39 class SessionDependencies { | 42 class SessionDependencies { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 session_deps->host_resolver, | 76 session_deps->host_resolver, |
74 session_deps->proxy_service, | 77 session_deps->proxy_service, |
75 &session_deps->socket_factory, | 78 &session_deps->socket_factory, |
76 session_deps->ssl_config_service, | 79 session_deps->ssl_config_service, |
77 session_deps->spdy_session_pool, | 80 session_deps->spdy_session_pool, |
78 session_deps->http_auth_handler_factory.get()); | 81 session_deps->http_auth_handler_factory.get()); |
79 } | 82 } |
80 | 83 |
81 class HttpNetworkTransactionTest : public PlatformTest { | 84 class HttpNetworkTransactionTest : public PlatformTest { |
82 public: | 85 public: |
| 86 virtual void SetUp() { |
| 87 spdy::SpdyFramer::set_enable_compression_default(false); |
| 88 } |
| 89 |
83 virtual void TearDown() { | 90 virtual void TearDown() { |
| 91 spdy::SpdyFramer::set_enable_compression_default(true); |
84 // Empty the current queue. | 92 // Empty the current queue. |
85 MessageLoop::current()->RunAllPending(); | 93 MessageLoop::current()->RunAllPending(); |
86 PlatformTest::TearDown(); | 94 PlatformTest::TearDown(); |
87 } | 95 } |
88 | 96 |
89 protected: | 97 protected: |
90 void KeepAliveConnectionResendRequestTest(const MockRead& read_failure); | 98 void KeepAliveConnectionResendRequestTest(const MockRead& read_failure); |
91 | 99 |
92 struct SimpleGetHelperResult { | 100 struct SimpleGetHelperResult { |
93 int rv; | 101 int rv; |
(...skipping 3573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3667 // Tests that for connection endpoints the group names are correctly set. | 3675 // Tests that for connection endpoints the group names are correctly set. |
3668 TEST_F(HttpNetworkTransactionTest, GroupNameForProxyConnections) { | 3676 TEST_F(HttpNetworkTransactionTest, GroupNameForProxyConnections) { |
3669 const struct { | 3677 const struct { |
3670 const std::string proxy_server; | 3678 const std::string proxy_server; |
3671 const std::string url; | 3679 const std::string url; |
3672 const std::string expected_group_name; | 3680 const std::string expected_group_name; |
3673 } tests[] = { | 3681 } tests[] = { |
3674 { | 3682 { |
3675 "", // no proxy (direct) | 3683 "", // no proxy (direct) |
3676 "http://www.google.com/direct", | 3684 "http://www.google.com/direct", |
3677 "http://www.google.com/", | 3685 "www.google.com:80", |
| 3686 }, |
| 3687 { |
| 3688 "", // no proxy (direct) |
| 3689 "http://[2001:1418:13:1::25]/direct", |
| 3690 "[2001:1418:13:1::25]:80", |
3678 }, | 3691 }, |
3679 { | 3692 { |
3680 "http_proxy", | 3693 "http_proxy", |
3681 "http://www.google.com/http_proxy_normal", | 3694 "http://www.google.com/http_proxy_normal", |
3682 "proxy/http_proxy:80/", | 3695 "proxy/http_proxy:80/", |
3683 }, | 3696 }, |
3684 { | 3697 { |
3685 "socks4://socks_proxy:1080", | 3698 "socks4://socks_proxy:1080", |
3686 "http://www.google.com/socks4_direct", | 3699 "http://www.google.com/socks4_direct", |
3687 "proxy/socks4://socks_proxy:1080/http://www.google.com/", | 3700 "proxy/socks4://socks_proxy:1080/www.google.com:80", |
3688 }, | 3701 }, |
3689 | 3702 |
3690 // SSL Tests | 3703 // SSL Tests |
3691 { | 3704 { |
3692 "", | 3705 "", |
3693 "https://www.google.com/direct_ssl", | 3706 "https://www.google.com/direct_ssl", |
3694 "https://www.google.com/", | 3707 "www.google.com:443", |
3695 }, | 3708 }, |
3696 { | 3709 { |
3697 "http_proxy", | 3710 "http_proxy", |
3698 "https://www.google.com/http_connect_ssl", | 3711 "https://www.google.com/http_connect_ssl", |
3699 "proxy/http_proxy:80/https://www.google.com/", | 3712 "proxy/http_proxy:80/www.google.com:443", |
3700 }, | 3713 }, |
3701 { | 3714 { |
3702 "socks4://socks_proxy:1080", | 3715 "socks4://socks_proxy:1080", |
3703 "https://www.google.com/socks4_ssl", | 3716 "https://www.google.com/socks4_ssl", |
3704 "proxy/socks4://socks_proxy:1080/https://www.google.com/", | 3717 "proxy/socks4://socks_proxy:1080/www.google.com:443", |
3705 }, | 3718 }, |
| 3719 { |
| 3720 "", // no proxy (direct) |
| 3721 "http://host.with.alternate/direct", |
| 3722 "host.with.alternate:443", |
| 3723 }, |
| 3724 |
| 3725 // TODO(willchan): Uncomment these tests when they work. |
| 3726 // { |
| 3727 // "http_proxy", |
| 3728 // "http://host.with.alternate/direct", |
| 3729 // "proxy/http_proxy:80/host.with.alternate:443", |
| 3730 // }, |
| 3731 // { |
| 3732 // "socks4://socks_proxy:1080", |
| 3733 // "http://host.with.alternate/direct", |
| 3734 // "proxy/socks4://socks_proxy:1080/host.with.alternate:443", |
| 3735 // }, |
3706 }; | 3736 }; |
3707 | 3737 |
| 3738 HttpNetworkTransaction::SetUseAlternateProtocols(true); |
| 3739 |
3708 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 3740 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
3709 SessionDependencies session_deps( | 3741 SessionDependencies session_deps( |
3710 CreateFixedProxyService(tests[i].proxy_server)); | 3742 CreateFixedProxyService(tests[i].proxy_server)); |
3711 | 3743 |
3712 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | 3744 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
3713 | 3745 |
| 3746 HttpAlternateProtocols* alternate_protocols = |
| 3747 session->mutable_alternate_protocols(); |
| 3748 alternate_protocols->SetAlternateProtocolFor( |
| 3749 HostPortPair("host.with.alternate", 80), 443, |
| 3750 HttpAlternateProtocols::NPN_SPDY_1); |
| 3751 |
3714 scoped_refptr<CaptureGroupNameTCPSocketPool> tcp_conn_pool( | 3752 scoped_refptr<CaptureGroupNameTCPSocketPool> tcp_conn_pool( |
3715 new CaptureGroupNameTCPSocketPool(session.get(), | 3753 new CaptureGroupNameTCPSocketPool(session.get(), |
3716 session->socket_factory())); | 3754 session->socket_factory())); |
3717 session->tcp_socket_pool_ = tcp_conn_pool.get(); | 3755 session->tcp_socket_pool_ = tcp_conn_pool.get(); |
3718 scoped_refptr<CaptureGroupNameSOCKSSocketPool> socks_conn_pool( | 3756 scoped_refptr<CaptureGroupNameSOCKSSocketPool> socks_conn_pool( |
3719 new CaptureGroupNameSOCKSSocketPool(session.get(), | 3757 new CaptureGroupNameSOCKSSocketPool(session.get(), |
3720 tcp_conn_pool.get())); | 3758 tcp_conn_pool.get())); |
3721 session->socks_socket_pool_ = socks_conn_pool.get(); | 3759 session->socks_socket_pool_ = socks_conn_pool.get(); |
3722 | 3760 |
3723 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); | 3761 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); |
3724 | 3762 |
3725 HttpRequestInfo request; | 3763 HttpRequestInfo request; |
3726 request.method = "GET"; | 3764 request.method = "GET"; |
3727 request.url = GURL(tests[i].url); | 3765 request.url = GURL(tests[i].url); |
3728 request.load_flags = 0; | 3766 request.load_flags = 0; |
3729 | 3767 |
3730 TestCompletionCallback callback; | 3768 TestCompletionCallback callback; |
3731 | 3769 |
3732 // We do not complete this request, the dtor will clean the transaction up. | 3770 // We do not complete this request, the dtor will clean the transaction up. |
3733 EXPECT_EQ(ERR_IO_PENDING, trans->Start(&request, &callback, NULL)); | 3771 EXPECT_EQ(ERR_IO_PENDING, trans->Start(&request, &callback, NULL)); |
3734 std::string allgroups = tcp_conn_pool->last_group_name_received() + | 3772 std::string allgroups = tcp_conn_pool->last_group_name_received() + |
3735 socks_conn_pool->last_group_name_received(); | 3773 socks_conn_pool->last_group_name_received(); |
3736 EXPECT_EQ(tests[i].expected_group_name, allgroups); | 3774 EXPECT_EQ(tests[i].expected_group_name, allgroups); |
3737 } | 3775 } |
| 3776 |
| 3777 HttpNetworkTransaction::SetUseAlternateProtocols(false); |
3738 } | 3778 } |
3739 | 3779 |
3740 TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { | 3780 TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
3741 SessionDependencies session_deps( | 3781 SessionDependencies session_deps( |
3742 CreateFixedProxyService("myproxy:70;foobar:80")); | 3782 CreateFixedProxyService("myproxy:70;foobar:80")); |
3743 | 3783 |
3744 // This simulates failure resolving all hostnames; that means we will fail | 3784 // This simulates failure resolving all hostnames; that means we will fail |
3745 // connecting to both proxies (myproxy:70 and foobar:80). | 3785 // connecting to both proxies (myproxy:70 and foobar:80). |
3746 session_deps.host_resolver->rules()->AddSimulatedFailure("*"); | 3786 session_deps.host_resolver->rules()->AddSimulatedFailure("*"); |
3747 | 3787 |
(...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4634 // ASSERT_TRUE(response->headers != NULL); | 4674 // ASSERT_TRUE(response->headers != NULL); |
4635 // EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 4675 // EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
4636 // | 4676 // |
4637 // std::string response_data; | 4677 // std::string response_data; |
4638 // ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 4678 // ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
4639 // EXPECT_EQ("hello world", response_data); | 4679 // EXPECT_EQ("hello world", response_data); |
4640 // } | 4680 // } |
4641 | 4681 |
4642 TEST_F(HttpNetworkTransactionTest, FailNpnSpdyAndFallback) { | 4682 TEST_F(HttpNetworkTransactionTest, FailNpnSpdyAndFallback) { |
4643 HttpNetworkTransaction::SetUseAlternateProtocols(true); | 4683 HttpNetworkTransaction::SetUseAlternateProtocols(true); |
| 4684 HttpNetworkTransaction::SetNextProtos( |
| 4685 "\x08http/1.1\x07http1.1\x06spdy/1\x04spdy"); |
4644 SessionDependencies session_deps; | 4686 SessionDependencies session_deps; |
4645 | 4687 |
4646 HttpRequestInfo request; | 4688 HttpRequestInfo request; |
4647 request.method = "GET"; | 4689 request.method = "GET"; |
4648 request.url = GURL("http://www.google.com/"); | 4690 request.url = GURL("http://www.google.com/"); |
4649 request.load_flags = 0; | 4691 request.load_flags = 0; |
4650 | 4692 |
4651 StaticSocketDataProvider first_tcp_connect; | 4693 StaticSocketDataProvider first_tcp_connect; |
4652 session_deps.socket_factory.AddSocketDataProvider(&first_tcp_connect); | 4694 session_deps.socket_factory.AddSocketDataProvider(&first_tcp_connect); |
4653 | 4695 |
(...skipping 29 matching lines...) Expand all Loading... |
4683 EXPECT_EQ(OK, callback.WaitForResult()); | 4725 EXPECT_EQ(OK, callback.WaitForResult()); |
4684 | 4726 |
4685 const HttpResponseInfo* response = trans->GetResponseInfo(); | 4727 const HttpResponseInfo* response = trans->GetResponseInfo(); |
4686 ASSERT_TRUE(response != NULL); | 4728 ASSERT_TRUE(response != NULL); |
4687 ASSERT_TRUE(response->headers != NULL); | 4729 ASSERT_TRUE(response->headers != NULL); |
4688 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 4730 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
4689 | 4731 |
4690 std::string response_data; | 4732 std::string response_data; |
4691 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 4733 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
4692 EXPECT_EQ("hello world", response_data); | 4734 EXPECT_EQ("hello world", response_data); |
| 4735 HttpNetworkTransaction::SetNextProtos(""); |
4693 HttpNetworkTransaction::SetUseAlternateProtocols(false); | 4736 HttpNetworkTransaction::SetUseAlternateProtocols(false); |
4694 } | 4737 } |
4695 | 4738 |
| 4739 TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
| 4740 HttpNetworkTransaction::SetUseAlternateProtocols(true); |
| 4741 HttpNetworkTransaction::SetNextProtos( |
| 4742 "\x08http/1.1\x07http1.1\x06spdy/1\x04spdy"); |
| 4743 SessionDependencies session_deps; |
| 4744 |
| 4745 HttpRequestInfo request; |
| 4746 request.method = "GET"; |
| 4747 request.url = GURL("http://www.google.com/"); |
| 4748 request.load_flags = 0; |
| 4749 |
| 4750 MockRead data_reads[] = { |
| 4751 MockRead("HTTP/1.1 200 OK\r\n"), |
| 4752 MockRead("Alternate-Protocol: 443:npn-spdy/1\r\n\r\n"), |
| 4753 MockRead("hello world"), |
| 4754 MockRead(true, OK), |
| 4755 }; |
| 4756 |
| 4757 StaticSocketDataProvider first_transaction( |
| 4758 data_reads, arraysize(data_reads), NULL, 0); |
| 4759 session_deps.socket_factory.AddSocketDataProvider(&first_transaction); |
| 4760 |
| 4761 SSLSocketDataProvider ssl(true, OK); |
| 4762 ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; |
| 4763 ssl.next_proto = "spdy/1"; |
| 4764 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); |
| 4765 |
| 4766 MockWrite spdy_writes[] = { |
| 4767 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), |
| 4768 arraysize(kGetSyn)), |
| 4769 }; |
| 4770 |
| 4771 MockRead spdy_reads[] = { |
| 4772 MockRead(true, reinterpret_cast<const char*>(kGetSynReply), |
| 4773 arraysize(kGetSynReply)), |
| 4774 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), |
| 4775 arraysize(kGetBodyFrame)), |
| 4776 MockRead(true, 0, 0), |
| 4777 }; |
| 4778 |
| 4779 scoped_refptr<DelayedSocketData> spdy_data( |
| 4780 new DelayedSocketData( |
| 4781 1, // wait for one write to finish before reading. |
| 4782 spdy_reads, arraysize(spdy_reads), |
| 4783 spdy_writes, arraysize(spdy_writes))); |
| 4784 session_deps.socket_factory.AddSocketDataProvider(spdy_data); |
| 4785 |
| 4786 TestCompletionCallback callback; |
| 4787 |
| 4788 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
| 4789 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session)); |
| 4790 |
| 4791 int rv = trans->Start(&request, &callback, NULL); |
| 4792 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4793 EXPECT_EQ(OK, callback.WaitForResult()); |
| 4794 |
| 4795 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4796 ASSERT_TRUE(response != NULL); |
| 4797 ASSERT_TRUE(response->headers != NULL); |
| 4798 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4799 |
| 4800 std::string response_data; |
| 4801 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 4802 EXPECT_EQ("hello world", response_data); |
| 4803 |
| 4804 trans.reset(new HttpNetworkTransaction(session)); |
| 4805 |
| 4806 rv = trans->Start(&request, &callback, NULL); |
| 4807 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4808 EXPECT_EQ(OK, callback.WaitForResult()); |
| 4809 |
| 4810 response = trans->GetResponseInfo(); |
| 4811 ASSERT_TRUE(response != NULL); |
| 4812 ASSERT_TRUE(response->headers != NULL); |
| 4813 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4814 |
| 4815 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 4816 EXPECT_EQ("hello!", response_data); |
| 4817 |
| 4818 HttpNetworkTransaction::SetNextProtos(""); |
| 4819 HttpNetworkTransaction::SetUseAlternateProtocols(false); |
| 4820 } |
| 4821 |
| 4822 TEST_F(HttpNetworkTransactionTest, |
| 4823 UseAlternateProtocolForNpnSpdyWithExistingSpdySession) { |
| 4824 HttpNetworkTransaction::SetUseAlternateProtocols(true); |
| 4825 HttpNetworkTransaction::SetNextProtos( |
| 4826 "\x08http/1.1\x07http1.1\x06spdy/1\x04spdy"); |
| 4827 SessionDependencies session_deps; |
| 4828 |
| 4829 HttpRequestInfo request; |
| 4830 request.method = "GET"; |
| 4831 request.url = GURL("http://www.google.com/"); |
| 4832 request.load_flags = 0; |
| 4833 |
| 4834 MockRead data_reads[] = { |
| 4835 MockRead("HTTP/1.1 200 OK\r\n"), |
| 4836 MockRead("Alternate-Protocol: 443:npn-spdy/1\r\n\r\n"), |
| 4837 MockRead("hello world"), |
| 4838 MockRead(true, OK), |
| 4839 }; |
| 4840 |
| 4841 StaticSocketDataProvider first_transaction( |
| 4842 data_reads, arraysize(data_reads), NULL, 0); |
| 4843 session_deps.socket_factory.AddSocketDataProvider(&first_transaction); |
| 4844 |
| 4845 SSLSocketDataProvider ssl(true, OK); |
| 4846 ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; |
| 4847 ssl.next_proto = "spdy/1"; |
| 4848 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); |
| 4849 |
| 4850 MockWrite spdy_writes[] = { |
| 4851 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), |
| 4852 arraysize(kGetSyn)), |
| 4853 }; |
| 4854 |
| 4855 MockRead spdy_reads[] = { |
| 4856 MockRead(true, reinterpret_cast<const char*>(kGetSynReply), |
| 4857 arraysize(kGetSynReply)), |
| 4858 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), |
| 4859 arraysize(kGetBodyFrame)), |
| 4860 MockRead(true, 0, 0), |
| 4861 }; |
| 4862 |
| 4863 scoped_refptr<DelayedSocketData> spdy_data( |
| 4864 new DelayedSocketData( |
| 4865 1, // wait for one write to finish before reading. |
| 4866 spdy_reads, arraysize(spdy_reads), |
| 4867 spdy_writes, arraysize(spdy_writes))); |
| 4868 session_deps.socket_factory.AddSocketDataProvider(spdy_data); |
| 4869 |
| 4870 TestCompletionCallback callback; |
| 4871 |
| 4872 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
| 4873 |
| 4874 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session)); |
| 4875 |
| 4876 int rv = trans->Start(&request, &callback, NULL); |
| 4877 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4878 EXPECT_EQ(OK, callback.WaitForResult()); |
| 4879 |
| 4880 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4881 ASSERT_TRUE(response != NULL); |
| 4882 ASSERT_TRUE(response->headers != NULL); |
| 4883 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4884 |
| 4885 std::string response_data; |
| 4886 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 4887 EXPECT_EQ("hello world", response_data); |
| 4888 |
| 4889 // Set up an initial SpdySession in the pool to reuse. |
| 4890 scoped_refptr<SpdySession> spdy_session = |
| 4891 session->spdy_session_pool()->Get(HostPortPair("www.google.com", 443), |
| 4892 session); |
| 4893 TCPSocketParams tcp_params("www.google.com", 443, MEDIUM, GURL(), false); |
| 4894 spdy_session->Connect( |
| 4895 "www.google.com:443", tcp_params, MEDIUM, BoundNetLog()); |
| 4896 |
| 4897 trans.reset(new HttpNetworkTransaction(session)); |
| 4898 |
| 4899 rv = trans->Start(&request, &callback, NULL); |
| 4900 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4901 EXPECT_EQ(OK, callback.WaitForResult()); |
| 4902 |
| 4903 response = trans->GetResponseInfo(); |
| 4904 ASSERT_TRUE(response != NULL); |
| 4905 ASSERT_TRUE(response->headers != NULL); |
| 4906 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4907 |
| 4908 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 4909 EXPECT_EQ("hello!", response_data); |
| 4910 |
| 4911 HttpNetworkTransaction::SetNextProtos(""); |
| 4912 HttpNetworkTransaction::SetUseAlternateProtocols(false); |
| 4913 } |
| 4914 |
4696 // MockAuthHandlerCanonical is used by the ResolveCanonicalName | 4915 // MockAuthHandlerCanonical is used by the ResolveCanonicalName |
4697 // HttpNetworkTransaction unit test below. Callers set up expectations for | 4916 // HttpNetworkTransaction unit test below. Callers set up expectations for |
4698 // whether the canonical name needs to be resolved. | 4917 // whether the canonical name needs to be resolved. |
4699 class MockAuthHandlerCanonical : public HttpAuthHandler { | 4918 class MockAuthHandlerCanonical : public HttpAuthHandler { |
4700 public: | 4919 public: |
4701 enum Resolve { | 4920 enum Resolve { |
4702 RESOLVE_INIT, | 4921 RESOLVE_INIT, |
4703 RESOLVE_SKIP, | 4922 RESOLVE_SKIP, |
4704 RESOLVE_SYNC, | 4923 RESOLVE_SYNC, |
4705 RESOLVE_ASYNC, | 4924 RESOLVE_ASYNC, |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4992 ASSERT_TRUE(response != NULL); | 5211 ASSERT_TRUE(response != NULL); |
4993 ASSERT_TRUE(response->headers != NULL); | 5212 ASSERT_TRUE(response->headers != NULL); |
4994 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 5213 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
4995 | 5214 |
4996 std::string response_data; | 5215 std::string response_data; |
4997 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 5216 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
4998 EXPECT_EQ("ok.", response_data); | 5217 EXPECT_EQ("ok.", response_data); |
4999 } | 5218 } |
5000 | 5219 |
5001 } // namespace net | 5220 } // namespace net |
OLD | NEW |