OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/data_reduction_proxy/core/browser/data_reduction_proxy_bypa
ss_protocol.h" | 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_bypa
ss_protocol.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_bypa
ss_stats.h" |
14 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
ig_test_utils.h" | 15 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
ig_test_utils.h" |
15 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_inte
rceptor.h" | 16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_inte
rceptor.h" |
16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test
_utils.h" | 17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test
_utils.h" |
17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_usag
e_stats.h" | |
18 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade
rs.h" | 18 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade
rs.h" |
19 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s_test_utils.h" | 19 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s_test_utils.h" |
20 #include "net/base/completion_callback.h" | 20 #include "net/base/completion_callback.h" |
21 #include "net/base/host_port_pair.h" | 21 #include "net/base/host_port_pair.h" |
22 #include "net/base/load_flags.h" | 22 #include "net/base/load_flags.h" |
23 #include "net/base/network_change_notifier.h" | 23 #include "net/base/network_change_notifier.h" |
24 #include "net/base/network_delegate.h" | 24 #include "net/base/network_delegate.h" |
25 #include "net/http/http_response_headers.h" | 25 #include "net/http/http_response_headers.h" |
26 #include "net/http/http_transaction_test_util.h" | 26 #include "net/http/http_transaction_test_util.h" |
27 #include "net/proxy/proxy_server.h" | 27 #include "net/proxy/proxy_server.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 context_.reset(new TestURLRequestContext(true)); | 111 context_.reset(new TestURLRequestContext(true)); |
112 | 112 |
113 proxy_service_.reset(proxy_service); | 113 proxy_service_.reset(proxy_service); |
114 context_->set_client_socket_factory(&mock_socket_factory_); | 114 context_->set_client_socket_factory(&mock_socket_factory_); |
115 context_->set_proxy_service(proxy_service_.get()); | 115 context_->set_proxy_service(proxy_service_.get()); |
116 network_delegate_.reset(new net::TestNetworkDelegate()); | 116 network_delegate_.reset(new net::TestNetworkDelegate()); |
117 context_->set_network_delegate(network_delegate_.get()); | 117 context_->set_network_delegate(network_delegate_.get()); |
118 // This is needed to prevent the test context from adding language headers | 118 // This is needed to prevent the test context from adding language headers |
119 // to requests. | 119 // to requests. |
120 context_->set_http_user_agent_settings(&http_user_agent_settings_); | 120 context_->set_http_user_agent_settings(&http_user_agent_settings_); |
121 usage_stats_.reset(new DataReductionProxyUsageStats( | 121 bypass_stats_.reset(new DataReductionProxyBypassStats( |
122 test_context_->config(), | 122 test_context_->config(), |
123 test_context_->unreachable_callback(), | 123 test_context_->unreachable_callback(), |
124 test_context_->task_runner())); | 124 test_context_->task_runner())); |
125 | 125 |
126 DataReductionProxyInterceptor* interceptor = | 126 DataReductionProxyInterceptor* interceptor = |
127 new DataReductionProxyInterceptor(test_context_->config(), | 127 new DataReductionProxyInterceptor(test_context_->config(), |
128 usage_stats_.get(), | 128 bypass_stats_.get(), |
129 test_context_->event_store()); | 129 test_context_->event_store()); |
130 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory_impl( | 130 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory_impl( |
131 new net::URLRequestJobFactoryImpl()); | 131 new net::URLRequestJobFactoryImpl()); |
132 job_factory_.reset(new net::URLRequestInterceptingJobFactory( | 132 job_factory_.reset(new net::URLRequestInterceptingJobFactory( |
133 job_factory_impl.Pass(), make_scoped_ptr(interceptor))); | 133 job_factory_impl.Pass(), make_scoped_ptr(interceptor))); |
134 | 134 |
135 context_->set_job_factory(job_factory_.get()); | 135 context_->set_job_factory(job_factory_.get()); |
136 context_->Init(); | 136 context_->Init(); |
137 } | 137 } |
138 | 138 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 } | 323 } |
324 | 324 |
325 protected: | 325 protected: |
326 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 326 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
327 | 327 |
328 scoped_ptr<net::URLRequestInterceptor> simple_interceptor_; | 328 scoped_ptr<net::URLRequestInterceptor> simple_interceptor_; |
329 net::MockClientSocketFactory mock_socket_factory_; | 329 net::MockClientSocketFactory mock_socket_factory_; |
330 scoped_ptr<net::TestNetworkDelegate> network_delegate_; | 330 scoped_ptr<net::TestNetworkDelegate> network_delegate_; |
331 scoped_ptr<ProxyService> proxy_service_; | 331 scoped_ptr<ProxyService> proxy_service_; |
332 scoped_ptr<DataReductionProxyTestContext> test_context_; | 332 scoped_ptr<DataReductionProxyTestContext> test_context_; |
333 scoped_ptr<DataReductionProxyUsageStats> usage_stats_; | 333 scoped_ptr<DataReductionProxyBypassStats> bypass_stats_; |
334 net::StaticHttpUserAgentSettings http_user_agent_settings_; | 334 net::StaticHttpUserAgentSettings http_user_agent_settings_; |
335 | 335 |
336 scoped_ptr<net::URLRequestInterceptingJobFactory> job_factory_; | 336 scoped_ptr<net::URLRequestInterceptingJobFactory> job_factory_; |
337 scoped_ptr<TestURLRequestContext> context_; | 337 scoped_ptr<TestURLRequestContext> context_; |
338 }; | 338 }; |
339 | 339 |
340 // Tests that request are deemed idempotent or not according to the method used. | 340 // Tests that request are deemed idempotent or not according to the method used. |
341 TEST_F(DataReductionProxyProtocolTest, TestIdempotency) { | 341 TEST_F(DataReductionProxyProtocolTest, TestIdempotency) { |
342 net::TestURLRequestContext context; | 342 net::TestURLRequestContext context; |
343 const struct { | 343 const struct { |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
752 primary, net::ProxyServer::SCHEME_HTTP).ToPacString() + "; " + | 752 primary, net::ProxyServer::SCHEME_HTTP).ToPacString() + "; " + |
753 net::ProxyServer::FromURI( | 753 net::ProxyServer::FromURI( |
754 fallback, | 754 fallback, |
755 net::ProxyServer::SCHEME_HTTP).ToPacString() + "; DIRECT")); | 755 net::ProxyServer::SCHEME_HTTP).ToPacString() + "; DIRECT")); |
756 TestProxyFallback(tests[i].method, | 756 TestProxyFallback(tests[i].method, |
757 tests[i].first_response, | 757 tests[i].first_response, |
758 tests[i].expected_retry, | 758 tests[i].expected_retry, |
759 tests[i].generate_response_error, | 759 tests[i].generate_response_error, |
760 tests[i].expected_bad_proxy_count, | 760 tests[i].expected_bad_proxy_count, |
761 tests[i].expect_response_body); | 761 tests[i].expect_response_body); |
762 EXPECT_EQ(tests[i].expected_bypass_type, usage_stats_->GetBypassType()); | 762 EXPECT_EQ(tests[i].expected_bypass_type, bypass_stats_->GetBypassType()); |
763 // We should also observe the bad proxy in the retry list. | 763 // We should also observe the bad proxy in the retry list. |
764 TestBadProxies(tests[i].expected_bad_proxy_count, | 764 TestBadProxies(tests[i].expected_bad_proxy_count, |
765 tests[i].expected_duration, | 765 tests[i].expected_duration, |
766 primary, fallback); | 766 primary, fallback); |
767 } | 767 } |
768 } | 768 } |
769 | 769 |
770 TEST_F(DataReductionProxyProtocolTest, | 770 TEST_F(DataReductionProxyProtocolTest, |
771 RelaxedMissingViaHeaderOtherBypassLogic) { | 771 RelaxedMissingViaHeaderOtherBypassLogic) { |
772 std::string primary = test_context_->config()->test_params()->DefaultOrigin(); | 772 std::string primary = test_context_->config()->test_params()->DefaultOrigin(); |
(...skipping 14 matching lines...) Expand all Loading... |
787 // This response with the DRP via header should be accepted without causing a | 787 // This response with the DRP via header should be accepted without causing a |
788 // bypass. | 788 // bypass. |
789 TestProxyFallback("GET", | 789 TestProxyFallback("GET", |
790 "HTTP/1.1 200 OK\r\n" | 790 "HTTP/1.1 200 OK\r\n" |
791 "Server: proxy\r\n" | 791 "Server: proxy\r\n" |
792 "Via: 1.1 Chrome-Compression-Proxy\r\n\r\n", | 792 "Via: 1.1 Chrome-Compression-Proxy\r\n\r\n", |
793 false /* expected_retry */, | 793 false /* expected_retry */, |
794 false /* generate_response_error */, | 794 false /* generate_response_error */, |
795 0u /* expected_bad_proxy_count */, | 795 0u /* expected_bad_proxy_count */, |
796 true /* expect_response_body */); | 796 true /* expect_response_body */); |
797 EXPECT_EQ(BYPASS_EVENT_TYPE_MAX, usage_stats_->GetBypassType()); | 797 EXPECT_EQ(BYPASS_EVENT_TYPE_MAX, bypass_stats_->GetBypassType()); |
798 TestBadProxies(0u, -1, primary, fallback); | 798 TestBadProxies(0u, -1, primary, fallback); |
799 | 799 |
800 // This non-4xx response without the DRP via header should not cause a bypass | 800 // This non-4xx response without the DRP via header should not cause a bypass |
801 // because a DRP via header has been seen since the last network change. | 801 // because a DRP via header has been seen since the last network change. |
802 TestProxyFallback("GET", | 802 TestProxyFallback("GET", |
803 "HTTP/1.1 200 OK\r\n\r\n", | 803 "HTTP/1.1 200 OK\r\n\r\n", |
804 false /* expected_retry */, | 804 false /* expected_retry */, |
805 false /* generate_response_error */, | 805 false /* generate_response_error */, |
806 0u /* expected_bad_proxy_count */, | 806 0u /* expected_bad_proxy_count */, |
807 true /* expect_response_body */); | 807 true /* expect_response_body */); |
808 EXPECT_EQ(BYPASS_EVENT_TYPE_MAX, usage_stats_->GetBypassType()); | 808 EXPECT_EQ(BYPASS_EVENT_TYPE_MAX, bypass_stats_->GetBypassType()); |
809 TestBadProxies(0u, -1, primary, fallback); | 809 TestBadProxies(0u, -1, primary, fallback); |
810 | 810 |
811 // The first response after a network change is missing the DRP via header, so | 811 // The first response after a network change is missing the DRP via header, so |
812 // this should cause a bypass. | 812 // this should cause a bypass. |
813 net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 813 net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
814 test_context_->RunUntilIdle(); | 814 test_context_->RunUntilIdle(); |
815 TestProxyFallback("GET", | 815 TestProxyFallback("GET", |
816 "HTTP/1.1 200 OK\r\n\r\n", | 816 "HTTP/1.1 200 OK\r\n\r\n", |
817 true /* expected_retry */, | 817 true /* expected_retry */, |
818 false /* generate_response_error */, | 818 false /* generate_response_error */, |
819 1u /* expected_bad_proxy_count */, | 819 1u /* expected_bad_proxy_count */, |
820 true /* expect_response_body */); | 820 true /* expect_response_body */); |
821 EXPECT_EQ(BYPASS_EVENT_TYPE_MISSING_VIA_HEADER_OTHER, | 821 EXPECT_EQ(BYPASS_EVENT_TYPE_MISSING_VIA_HEADER_OTHER, |
822 usage_stats_->GetBypassType()); | 822 bypass_stats_->GetBypassType()); |
823 TestBadProxies(1u, 0, primary, fallback); | 823 TestBadProxies(1u, 0, primary, fallback); |
824 } | 824 } |
825 | 825 |
826 TEST_F(DataReductionProxyProtocolTest, | 826 TEST_F(DataReductionProxyProtocolTest, |
827 ProxyBypassIgnoredOnDirectConnection) { | 827 ProxyBypassIgnoredOnDirectConnection) { |
828 // Verify that a Chrome-Proxy header is ignored when returned from a directly | 828 // Verify that a Chrome-Proxy header is ignored when returned from a directly |
829 // connected origin server. | 829 // connected origin server. |
830 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult("DIRECT")); | 830 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult("DIRECT")); |
831 | 831 |
832 MockRead data_reads[] = { | 832 MockRead data_reads[] = { |
(...skipping 27 matching lines...) Expand all Loading... |
860 EXPECT_EQ(net::URLRequestStatus::SUCCESS, r->status().status()); | 860 EXPECT_EQ(net::URLRequestStatus::SUCCESS, r->status().status()); |
861 EXPECT_EQ(net::OK, r->status().error()); | 861 EXPECT_EQ(net::OK, r->status().error()); |
862 | 862 |
863 EXPECT_EQ("Bypass message", d.data_received()); | 863 EXPECT_EQ("Bypass message", d.data_received()); |
864 | 864 |
865 // We should have no entries in our bad proxy list. | 865 // We should have no entries in our bad proxy list. |
866 TestBadProxies(0, -1, "", ""); | 866 TestBadProxies(0, -1, "", ""); |
867 } | 867 } |
868 | 868 |
869 } // namespace data_reduction_proxy | 869 } // namespace data_reduction_proxy |
OLD | NEW |