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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/memory/scoped_ptr.h" |
8 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
9 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
11 #include "net/base/address_list.h" | 12 #include "net/base/address_list.h" |
12 #include "net/base/host_cache.h" | 13 #include "net/base/host_cache.h" |
13 #include "net/base/io_buffer.h" | 14 #include "net/base/io_buffer.h" |
14 #include "net/base/mock_host_resolver.h" | 15 #include "net/base/mock_host_resolver.h" |
15 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
16 #include "net/base/net_util.h" | 17 #include "net/base/net_util.h" |
17 #include "net/base/request_priority.h" | 18 #include "net/base/request_priority.h" |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 ExpectResponse("three.html", three_transaction, SYNCHRONOUS); | 221 ExpectResponse("three.html", three_transaction, SYNCHRONOUS); |
221 | 222 |
222 one_transaction.reset(); | 223 one_transaction.reset(); |
223 EXPECT_EQ(OK, four_callback.WaitForResult()); | 224 EXPECT_EQ(OK, four_callback.WaitForResult()); |
224 ExpectResponse("four.html", four_transaction, SYNCHRONOUS); | 225 ExpectResponse("four.html", four_transaction, SYNCHRONOUS); |
225 } | 226 } |
226 | 227 |
227 DeterministicMockClientSocketFactory factory_; | 228 DeterministicMockClientSocketFactory factory_; |
228 ClientSocketPoolHistograms histograms_; | 229 ClientSocketPoolHistograms histograms_; |
229 MockTransportClientSocketPool pool_; | 230 MockTransportClientSocketPool pool_; |
230 std::vector<scoped_refptr<DeterministicSocketData> > data_vector_; | 231 ScopedVector<DeterministicSocketData> data_vector_; |
231 TestCompletionCallback callback_; | 232 TestCompletionCallback callback_; |
232 ScopedVector<HttpRequestInfo> request_info_vector_; | 233 ScopedVector<HttpRequestInfo> request_info_vector_; |
233 bool default_pipelining_enabled_; | 234 bool default_pipelining_enabled_; |
234 | 235 |
235 SimpleProxyConfigService* proxy_config_service_; | 236 SimpleProxyConfigService* proxy_config_service_; |
236 scoped_ptr<ProxyService> proxy_service_; | 237 scoped_ptr<ProxyService> proxy_service_; |
237 MockHostResolver mock_resolver_; | 238 MockHostResolver mock_resolver_; |
238 scoped_refptr<SSLConfigService> ssl_config_; | 239 scoped_refptr<SSLConfigService> ssl_config_; |
239 scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory_; | 240 scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory_; |
240 HttpServerPropertiesImpl http_server_properties_; | 241 HttpServerPropertiesImpl http_server_properties_; |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 two_transaction.Start(GetRequestInfo("two.html"), | 826 two_transaction.Start(GetRequestInfo("two.html"), |
826 two_callback.callback(), BoundNetLog())); | 827 two_callback.callback(), BoundNetLog())); |
827 // Posted tasks should be: | 828 // Posted tasks should be: |
828 // 1. MockHostResolverBase::ResolveNow | 829 // 1. MockHostResolverBase::ResolveNow |
829 // 2. HttpStreamFactoryImpl::Job::OnStreamReadyCallback for job 1 | 830 // 2. HttpStreamFactoryImpl::Job::OnStreamReadyCallback for job 1 |
830 // 3. HttpStreamFactoryImpl::Job::OnStreamReadyCallback for job 2 | 831 // 3. HttpStreamFactoryImpl::Job::OnStreamReadyCallback for job 2 |
831 // | 832 // |
832 // We need to make sure that the response that triggers OnPipelineFeedback(OK) | 833 // We need to make sure that the response that triggers OnPipelineFeedback(OK) |
833 // is called in between when task #3 is scheduled and when it runs. The | 834 // is called in between when task #3 is scheduled and when it runs. The |
834 // DataRunnerObserver does that. | 835 // DataRunnerObserver does that. |
835 DataRunnerObserver observer(data_vector_[0].get(), 3); | 836 DataRunnerObserver observer(data_vector_[0], 3); |
836 MessageLoop::current()->AddTaskObserver(&observer); | 837 MessageLoop::current()->AddTaskObserver(&observer); |
837 data_vector_[0]->SetStop(4); | 838 data_vector_[0]->SetStop(4); |
838 MessageLoop::current()->RunAllPending(); | 839 MessageLoop::current()->RunAllPending(); |
839 data_vector_[0]->SetStop(10); | 840 data_vector_[0]->SetStop(10); |
840 | 841 |
841 EXPECT_EQ(OK, one_callback.WaitForResult()); | 842 EXPECT_EQ(OK, one_callback.WaitForResult()); |
842 ExpectResponse("one.html", one_transaction, SYNCHRONOUS); | 843 ExpectResponse("one.html", one_transaction, SYNCHRONOUS); |
843 EXPECT_EQ(OK, two_callback.WaitForResult()); | 844 EXPECT_EQ(OK, two_callback.WaitForResult()); |
844 ExpectResponse("two.html", two_transaction, SYNCHRONOUS); | 845 ExpectResponse("two.html", two_transaction, SYNCHRONOUS); |
845 } | 846 } |
846 | 847 |
847 TEST_F(HttpPipelinedNetworkTransactionTest, ProxyChangesWhileConnecting) { | 848 TEST_F(HttpPipelinedNetworkTransactionTest, ProxyChangesWhileConnecting) { |
848 Initialize(false); | 849 Initialize(false); |
849 | 850 |
850 scoped_refptr<DeterministicSocketData> data( | 851 scoped_ptr<DeterministicSocketData> data( |
851 new DeterministicSocketData(NULL, 0, NULL, 0)); | 852 new DeterministicSocketData(NULL, 0, NULL, 0)); |
852 data->set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); | 853 data->set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
853 factory_.AddSocketDataProvider(data); | 854 factory_.AddSocketDataProvider(data.get()); |
854 | 855 |
855 scoped_refptr<DeterministicSocketData> data2( | 856 scoped_ptr<DeterministicSocketData> data2( |
856 new DeterministicSocketData(NULL, 0, NULL, 0)); | 857 new DeterministicSocketData(NULL, 0, NULL, 0)); |
857 data2->set_connect_data(MockConnect(ASYNC, ERR_FAILED)); | 858 data2->set_connect_data(MockConnect(ASYNC, ERR_FAILED)); |
858 factory_.AddSocketDataProvider(data2); | 859 factory_.AddSocketDataProvider(data2.get()); |
859 | 860 |
860 HttpNetworkTransaction transaction(session_.get()); | 861 HttpNetworkTransaction transaction(session_.get()); |
861 EXPECT_EQ(ERR_IO_PENDING, | 862 EXPECT_EQ(ERR_IO_PENDING, |
862 transaction.Start(GetRequestInfo("test.html"), callback_.callback(), | 863 transaction.Start(GetRequestInfo("test.html"), callback_.callback(), |
863 BoundNetLog())); | 864 BoundNetLog())); |
864 | 865 |
865 proxy_config_service_->IncrementConfigId(); | 866 proxy_config_service_->IncrementConfigId(); |
866 | 867 |
867 EXPECT_EQ(ERR_FAILED, callback_.WaitForResult()); | 868 EXPECT_EQ(ERR_FAILED, callback_.WaitForResult()); |
868 } | 869 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 | 909 |
909 data_vector_[0]->RunFor(2); // 2 lines of headers. | 910 data_vector_[0]->RunFor(2); // 2 lines of headers. |
910 EXPECT_EQ(OK, two_callback.WaitForResult()); | 911 EXPECT_EQ(OK, two_callback.WaitForResult()); |
911 ExpectResponse("two.html", two_transaction, ASYNC); | 912 ExpectResponse("two.html", two_transaction, ASYNC); |
912 } | 913 } |
913 | 914 |
914 TEST_F(HttpPipelinedNetworkTransactionTest, | 915 TEST_F(HttpPipelinedNetworkTransactionTest, |
915 ForcedPipelineConnectionErrorFailsBoth) { | 916 ForcedPipelineConnectionErrorFailsBoth) { |
916 Initialize(true); | 917 Initialize(true); |
917 | 918 |
918 scoped_refptr<DeterministicSocketData> data( | 919 scoped_ptr<DeterministicSocketData> data( |
919 new DeterministicSocketData(NULL, 0, NULL, 0)); | 920 new DeterministicSocketData(NULL, 0, NULL, 0)); |
920 data->set_connect_data(MockConnect(ASYNC, ERR_FAILED)); | 921 data->set_connect_data(MockConnect(ASYNC, ERR_FAILED)); |
921 factory_.AddSocketDataProvider(data); | 922 factory_.AddSocketDataProvider(data.get()); |
922 | 923 |
923 scoped_ptr<HttpNetworkTransaction> one_transaction( | 924 scoped_ptr<HttpNetworkTransaction> one_transaction( |
924 new HttpNetworkTransaction(session_.get())); | 925 new HttpNetworkTransaction(session_.get())); |
925 TestCompletionCallback one_callback; | 926 TestCompletionCallback one_callback; |
926 EXPECT_EQ(ERR_IO_PENDING, | 927 EXPECT_EQ(ERR_IO_PENDING, |
927 one_transaction->Start(GetRequestInfo("one.html"), | 928 one_transaction->Start(GetRequestInfo("one.html"), |
928 one_callback.callback(), BoundNetLog())); | 929 one_callback.callback(), BoundNetLog())); |
929 | 930 |
930 HttpNetworkTransaction two_transaction(session_.get()); | 931 HttpNetworkTransaction two_transaction(session_.get()); |
931 TestCompletionCallback two_callback; | 932 TestCompletionCallback two_callback; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 "Host: localhost\r\n" | 989 "Host: localhost\r\n" |
989 "Connection: keep-alive\r\n\r\n" | 990 "Connection: keep-alive\r\n\r\n" |
990 "GET /four.html HTTP/1.1\r\n" | 991 "GET /four.html HTTP/1.1\r\n" |
991 "Host: localhost\r\n" | 992 "Host: localhost\r\n" |
992 "Connection: keep-alive\r\n\r\n" | 993 "Connection: keep-alive\r\n\r\n" |
993 ), | 994 ), |
994 }; | 995 }; |
995 MockRead reads[] = { | 996 MockRead reads[] = { |
996 MockRead(ASYNC, ERR_FAILED, 1), | 997 MockRead(ASYNC, ERR_FAILED, 1), |
997 }; | 998 }; |
998 scoped_refptr<DeterministicSocketData> data(new DeterministicSocketData( | 999 scoped_ptr<DeterministicSocketData> data(new DeterministicSocketData( |
999 reads, arraysize(reads), writes, arraysize(writes))); | 1000 reads, arraysize(reads), writes, arraysize(writes))); |
1000 data->set_connect_data(MockConnect(ASYNC, OK)); | 1001 data->set_connect_data(MockConnect(ASYNC, OK)); |
1001 factory_.AddSocketDataProvider(data); | 1002 factory_.AddSocketDataProvider(data.get()); |
1002 | 1003 |
1003 scoped_ptr<HttpNetworkTransaction> one_transaction( | 1004 scoped_ptr<HttpNetworkTransaction> one_transaction( |
1004 new HttpNetworkTransaction(session_.get())); | 1005 new HttpNetworkTransaction(session_.get())); |
1005 TestCompletionCallback one_callback; | 1006 TestCompletionCallback one_callback; |
1006 EXPECT_EQ(ERR_IO_PENDING, | 1007 EXPECT_EQ(ERR_IO_PENDING, |
1007 one_transaction->Start(GetRequestInfo("one.html"), | 1008 one_transaction->Start(GetRequestInfo("one.html"), |
1008 one_callback.callback(), BoundNetLog())); | 1009 one_callback.callback(), BoundNetLog())); |
1009 | 1010 |
1010 scoped_ptr<HttpNetworkTransaction> two_transaction( | 1011 scoped_ptr<HttpNetworkTransaction> two_transaction( |
1011 new HttpNetworkTransaction(session_.get())); | 1012 new HttpNetworkTransaction(session_.get())); |
(...skipping 22 matching lines...) Expand all Loading... |
1034 EXPECT_EQ(ERR_PIPELINE_EVICTION, two_callback.WaitForResult()); | 1035 EXPECT_EQ(ERR_PIPELINE_EVICTION, two_callback.WaitForResult()); |
1035 two_transaction.reset(); | 1036 two_transaction.reset(); |
1036 EXPECT_EQ(ERR_PIPELINE_EVICTION, three_callback.WaitForResult()); | 1037 EXPECT_EQ(ERR_PIPELINE_EVICTION, three_callback.WaitForResult()); |
1037 three_transaction.reset(); | 1038 three_transaction.reset(); |
1038 EXPECT_EQ(ERR_PIPELINE_EVICTION, four_callback.WaitForResult()); | 1039 EXPECT_EQ(ERR_PIPELINE_EVICTION, four_callback.WaitForResult()); |
1039 } | 1040 } |
1040 | 1041 |
1041 } // anonymous namespace | 1042 } // anonymous namespace |
1042 | 1043 |
1043 } // namespace net | 1044 } // namespace net |
OLD | NEW |