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_stats.h" | 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_bypa
ss_stats.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 default: | 80 default: |
81 NOTREACHED(); | 81 NOTREACHED(); |
82 return net::ProxyServer::FromURI("", net::ProxyServer::SCHEME_INVALID); | 82 return net::ProxyServer::FromURI("", net::ProxyServer::SCHEME_INVALID); |
83 } | 83 } |
84 } | 84 } |
85 | 85 |
86 } // namespace | 86 } // namespace |
87 | 87 |
88 class DataReductionProxyBypassStatsTest : public testing::Test { | 88 class DataReductionProxyBypassStatsTest : public testing::Test { |
89 public: | 89 public: |
90 DataReductionProxyBypassStatsTest() : context_(true) { | 90 DataReductionProxyBypassStatsTest() |
| 91 : context_(true), test_job_factory_(nullptr) { |
91 context_.Init(); | 92 context_.Init(); |
92 | 93 |
93 // The |test_job_factory_| takes ownership of the interceptor. | 94 // The |test_job_factory_| takes ownership of the interceptor. |
94 test_job_interceptor_ = new net::TestJobInterceptor(); | 95 test_job_interceptor_ = new net::TestJobInterceptor(); |
95 EXPECT_TRUE(test_job_factory_.SetProtocolHandler( | 96 test_job_factory_.reset(new net::URLRequestInterceptingJobFactory( |
96 url::kHttpScheme, base::WrapUnique(test_job_interceptor_))); | 97 net::URLRequestJobFactoryImpl::CreateWithHttpProtocolHandlers(), |
| 98 base::WrapUnique(test_job_interceptor_))); |
97 | 99 |
98 context_.set_job_factory(&test_job_factory_); | 100 context_.set_job_factory(test_job_factory_.get()); |
99 | 101 |
100 test_context_ = | 102 test_context_ = |
101 DataReductionProxyTestContext::Builder().WithMockConfig().Build(); | 103 DataReductionProxyTestContext::Builder().WithMockConfig().Build(); |
102 mock_url_request_ = context_.CreateRequest(GURL(), net::IDLE, &delegate_); | 104 mock_url_request_ = context_.CreateRequest(GURL(), net::IDLE, &delegate_); |
103 } | 105 } |
104 | 106 |
105 std::unique_ptr<net::URLRequest> CreateURLRequestWithResponseHeaders( | 107 std::unique_ptr<net::URLRequest> CreateURLRequestWithResponseHeaders( |
106 const GURL& url, | 108 const GURL& url, |
107 const std::string& response_headers) { | 109 const std::string& response_headers) { |
108 std::unique_ptr<net::URLRequest> fake_request = | 110 std::unique_ptr<net::URLRequest> fake_request = |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 test_context_->RunUntilIdle(); | 147 test_context_->RunUntilIdle(); |
146 } | 148 } |
147 | 149 |
148 private: | 150 private: |
149 base::MessageLoopForIO message_loop_; | 151 base::MessageLoopForIO message_loop_; |
150 net::TestURLRequestContext context_; | 152 net::TestURLRequestContext context_; |
151 net::TestDelegate delegate_; | 153 net::TestDelegate delegate_; |
152 std::unique_ptr<net::URLRequest> mock_url_request_; | 154 std::unique_ptr<net::URLRequest> mock_url_request_; |
153 // |test_job_interceptor_| is owned by |test_job_factory_|. | 155 // |test_job_interceptor_| is owned by |test_job_factory_|. |
154 net::TestJobInterceptor* test_job_interceptor_; | 156 net::TestJobInterceptor* test_job_interceptor_; |
155 net::URLRequestJobFactoryImpl test_job_factory_; | 157 std::unique_ptr<net::URLRequestJobFactory> test_job_factory_; |
156 std::unique_ptr<DataReductionProxyTestContext> test_context_; | 158 std::unique_ptr<DataReductionProxyTestContext> test_context_; |
157 }; | 159 }; |
158 | 160 |
159 TEST_F(DataReductionProxyBypassStatsTest, IsDataReductionProxyUnreachable) { | 161 TEST_F(DataReductionProxyBypassStatsTest, IsDataReductionProxyUnreachable) { |
160 net::ProxyServer fallback_proxy_server = | 162 net::ProxyServer fallback_proxy_server = |
161 net::ProxyServer::FromURI("foo.com", net::ProxyServer::SCHEME_HTTP); | 163 net::ProxyServer::FromURI("foo.com", net::ProxyServer::SCHEME_HTTP); |
162 data_reduction_proxy::DataReductionProxyTypeInfo proxy_info; | 164 data_reduction_proxy::DataReductionProxyTypeInfo proxy_info; |
163 struct TestCase { | 165 struct TestCase { |
164 bool fallback_proxy_server_is_data_reduction_proxy; | 166 bool fallback_proxy_server_is_data_reduction_proxy; |
165 bool was_proxy_used; | 167 bool was_proxy_used; |
(...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 kNextBody.c_str(), nullptr, nullptr); | 1091 kNextBody.c_str(), nullptr, nullptr); |
1090 histogram_tester.ExpectUniqueSample( | 1092 histogram_tester.ExpectUniqueSample( |
1091 "DataReductionProxy.BypassedBytes.NotBypassed", kNextBody.size(), 1); | 1093 "DataReductionProxy.BypassedBytes.NotBypassed", kNextBody.size(), 1); |
1092 ExpectOtherBypassedBytesHistogramsEmpty( | 1094 ExpectOtherBypassedBytesHistogramsEmpty( |
1093 histogram_tester, "DataReductionProxy.BypassedBytes.NotBypassed"); | 1095 histogram_tester, "DataReductionProxy.BypassedBytes.NotBypassed"); |
1094 } | 1096 } |
1095 } | 1097 } |
1096 } | 1098 } |
1097 | 1099 |
1098 } // namespace data_reduction_proxy | 1100 } // namespace data_reduction_proxy |
OLD | NEW |