Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(753)

Side by Side Diff: components/data_reduction_proxy/browser/data_reduction_proxy_settings_test_utils.cc

Issue 548993002: Removed connection warmup logic from data reduction proxy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/browser/data_reduction_proxy_settings_ test_utils.h" 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings_ test_utils.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/prefs/pref_registry_simple.h" 10 #include "base/prefs/pref_registry_simple.h"
11 #include "base/prefs/scoped_user_pref_update.h" 11 #include "base/prefs/scoped_user_pref_update.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names .h" 13 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names .h"
14 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h " 14 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h "
15 15
16 using testing::_; 16 using testing::_;
17 using testing::AnyNumber; 17 using testing::AnyNumber;
18 using testing::Return; 18 using testing::Return;
19 19
20 namespace { 20 namespace {
21 21
22 const char kProbeURLWithOKResponse[] = "http://ok.org/"; 22 const char kProbeURLWithOKResponse[] = "http://ok.org/";
23 const char kWarmupURLWithNoContentResponse[] = "http://warm.org/";
24 23
25 const char kProxy[] = "proxy"; 24 const char kProxy[] = "proxy";
26 25
27 } // namespace 26 } // namespace
28 27
29 namespace data_reduction_proxy { 28 namespace data_reduction_proxy {
30 29
31 // Transform "normal"-looking headers (\n-separated) to the appropriate 30 // Transform "normal"-looking headers (\n-separated) to the appropriate
32 // input format for ParseRawHeaders (\0-separated). 31 // input format for ParseRawHeaders (\0-separated).
33 void HeadersToRaw(std::string* headers) { 32 void HeadersToRaw(std::string* headers) {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 flags |= DataReductionProxyParams::kHoldback; 136 flags |= DataReductionProxyParams::kHoldback;
138 MockDataReductionProxySettings<C>* settings = 137 MockDataReductionProxySettings<C>* settings =
139 new MockDataReductionProxySettings<C>(flags); 138 new MockDataReductionProxySettings<C>(flags);
140 EXPECT_CALL(*settings, GetOriginalProfilePrefs()) 139 EXPECT_CALL(*settings, GetOriginalProfilePrefs())
141 .Times(AnyNumber()) 140 .Times(AnyNumber())
142 .WillRepeatedly(Return(&pref_service_)); 141 .WillRepeatedly(Return(&pref_service_));
143 EXPECT_CALL(*settings, GetLocalStatePrefs()) 142 EXPECT_CALL(*settings, GetLocalStatePrefs())
144 .Times(AnyNumber()) 143 .Times(AnyNumber())
145 .WillRepeatedly(Return(&pref_service_)); 144 .WillRepeatedly(Return(&pref_service_));
146 EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck()).Times(0); 145 EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck()).Times(0);
147 EXPECT_CALL(*settings, GetURLFetcherForWarmup()).Times(0);
148 EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0); 146 EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0);
149 settings_.reset(settings); 147 settings_.reset(settings);
150 configurator_.reset(new TestDataReductionProxyConfig()); 148 configurator_.reset(new TestDataReductionProxyConfig());
151 settings_->configurator_ = configurator_.get(); 149 settings_->configurator_ = configurator_.get();
152 } 150 }
153 151
154 // Explicitly generate required instantiations. 152 // Explicitly generate required instantiations.
155 template void 153 template void
156 DataReductionProxySettingsTestBase::ResetSettings<DataReductionProxySettings>( 154 DataReductionProxySettingsTestBase::ResetSettings<DataReductionProxySettings>(
157 bool allowed, 155 bool allowed,
158 bool fallback_allowed, 156 bool fallback_allowed,
159 bool alt_allowed, 157 bool alt_allowed,
160 bool promo_allowed, 158 bool promo_allowed,
161 bool holdback); 159 bool holdback);
162 160
163 template <class C> 161 template <class C>
164 void DataReductionProxySettingsTestBase::SetProbeResult( 162 void DataReductionProxySettingsTestBase::SetProbeResult(
165 const std::string& test_url, 163 const std::string& test_url,
166 const std::string& warmup_test_url,
167 const std::string& response, 164 const std::string& response,
168 ProbeURLFetchResult result, 165 ProbeURLFetchResult result,
169 bool success, 166 bool success,
170 int expected_calls) { 167 int expected_calls) {
171 MockDataReductionProxySettings<C>* settings = 168 MockDataReductionProxySettings<C>* settings =
172 static_cast<MockDataReductionProxySettings<C>*>(settings_.get()); 169 static_cast<MockDataReductionProxySettings<C>*>(settings_.get());
173 if (0 == expected_calls) { 170 if (0 == expected_calls) {
174 EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck()).Times(0); 171 EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck()).Times(0);
175 EXPECT_CALL(*settings, GetURLFetcherForWarmup()).Times(0);
176 EXPECT_CALL(*settings, RecordProbeURLFetchResult(_)).Times(0); 172 EXPECT_CALL(*settings, RecordProbeURLFetchResult(_)).Times(0);
177 } else { 173 } else {
178 EXPECT_CALL(*settings, RecordProbeURLFetchResult(result)).Times(1); 174 EXPECT_CALL(*settings, RecordProbeURLFetchResult(result)).Times(1);
179 EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck()) 175 EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck())
180 .Times(expected_calls) 176 .Times(expected_calls)
181 .WillRepeatedly(Return(new net::FakeURLFetcher( 177 .WillRepeatedly(Return(new net::FakeURLFetcher(
182 GURL(test_url), 178 GURL(test_url),
183 settings, 179 settings,
184 response, 180 response,
185 success ? net::HTTP_OK : net::HTTP_INTERNAL_SERVER_ERROR, 181 success ? net::HTTP_OK : net::HTTP_INTERNAL_SERVER_ERROR,
186 success ? net::URLRequestStatus::SUCCESS : 182 success ? net::URLRequestStatus::SUCCESS :
187 net::URLRequestStatus::FAILED))); 183 net::URLRequestStatus::FAILED)));
188 EXPECT_CALL(*settings, GetURLFetcherForWarmup())
189 .Times(expected_calls)
190 .WillRepeatedly(Return(new net::FakeURLFetcher(
191 GURL(warmup_test_url),
192 settings,
193 "",
194 success ? net::HTTP_NO_CONTENT : net::HTTP_INTERNAL_SERVER_ERROR,
195 success ? net::URLRequestStatus::SUCCESS :
196 net::URLRequestStatus::FAILED)));
197 } 184 }
198 } 185 }
199 186
200 // Explicitly generate required instantiations. 187 // Explicitly generate required instantiations.
201 template void 188 template void
202 DataReductionProxySettingsTestBase::SetProbeResult<DataReductionProxySettings>( 189 DataReductionProxySettingsTestBase::SetProbeResult<DataReductionProxySettings>(
203 const std::string& test_url, 190 const std::string& test_url,
204 const std::string& warmup_test_url,
205 const std::string& response, 191 const std::string& response,
206 ProbeURLFetchResult result, 192 ProbeURLFetchResult result,
207 bool success, 193 bool success,
208 int expected_calls); 194 int expected_calls);
209 195
210 void DataReductionProxySettingsTestBase::CheckProxyConfigs( 196 void DataReductionProxySettingsTestBase::CheckProxyConfigs(
211 bool expected_enabled, 197 bool expected_enabled,
212 bool expected_restricted, 198 bool expected_restricted,
213 bool expected_fallback_restricted) { 199 bool expected_fallback_restricted) {
214 TestDataReductionProxyConfig* config = 200 TestDataReductionProxyConfig* config =
215 static_cast<TestDataReductionProxyConfig*>(settings_->configurator_); 201 static_cast<TestDataReductionProxyConfig*>(settings_->configurator_);
216 ASSERT_EQ(expected_restricted, config->restricted_); 202 ASSERT_EQ(expected_restricted, config->restricted_);
217 ASSERT_EQ(expected_fallback_restricted, config->fallback_restricted_); 203 ASSERT_EQ(expected_fallback_restricted, config->fallback_restricted_);
218 ASSERT_EQ(expected_enabled, config->enabled_); 204 ASSERT_EQ(expected_enabled, config->enabled_);
219 } 205 }
220 206
221 void DataReductionProxySettingsTestBase::CheckProbe( 207 void DataReductionProxySettingsTestBase::CheckProbe(
222 bool initially_enabled, 208 bool initially_enabled,
223 const std::string& probe_url, 209 const std::string& probe_url,
224 const std::string& warmup_url,
225 const std::string& response, 210 const std::string& response,
226 bool request_succeeded, 211 bool request_succeeded,
227 bool expected_enabled, 212 bool expected_enabled,
228 bool expected_restricted, 213 bool expected_restricted,
229 bool expected_fallback_restricted) { 214 bool expected_fallback_restricted) {
230 pref_service_.SetBoolean(prefs::kDataReductionProxyEnabled, 215 pref_service_.SetBoolean(prefs::kDataReductionProxyEnabled,
231 initially_enabled); 216 initially_enabled);
232 if (initially_enabled) 217 if (initially_enabled)
233 settings_->enabled_by_user_ = true; 218 settings_->enabled_by_user_ = true;
234 settings_->restricted_by_carrier_ = false; 219 settings_->restricted_by_carrier_ = false;
235 SetProbeResult(probe_url, 220 SetProbeResult(probe_url,
236 warmup_url,
237 response, 221 response,
238 FetchResult(initially_enabled, 222 FetchResult(initially_enabled,
239 request_succeeded && (response == "OK")), 223 request_succeeded && (response == "OK")),
240 request_succeeded, 224 request_succeeded,
241 initially_enabled ? 1 : 0); 225 initially_enabled ? 1 : 0);
242 settings_->MaybeActivateDataReductionProxy(false); 226 settings_->MaybeActivateDataReductionProxy(false);
243 base::MessageLoop::current()->RunUntilIdle(); 227 base::MessageLoop::current()->RunUntilIdle();
244 CheckProxyConfigs(expected_enabled, 228 CheckProxyConfigs(expected_enabled,
245 expected_restricted, 229 expected_restricted,
246 expected_fallback_restricted); 230 expected_fallback_restricted);
247 } 231 }
248 232
249 void DataReductionProxySettingsTestBase::CheckProbeOnIPChange( 233 void DataReductionProxySettingsTestBase::CheckProbeOnIPChange(
250 const std::string& probe_url, 234 const std::string& probe_url,
251 const std::string& warmup_url,
252 const std::string& response, 235 const std::string& response,
253 bool request_succeeded, 236 bool request_succeeded,
254 bool expected_restricted, 237 bool expected_restricted,
255 bool expected_fallback_restricted) { 238 bool expected_fallback_restricted) {
256 SetProbeResult(probe_url, 239 SetProbeResult(probe_url,
257 warmup_url,
258 response, 240 response,
259 FetchResult(!settings_->restricted_by_carrier_, 241 FetchResult(!settings_->restricted_by_carrier_,
260 request_succeeded && (response == "OK")), 242 request_succeeded && (response == "OK")),
261 request_succeeded, 243 request_succeeded,
262 1); 244 1);
263 settings_->OnIPAddressChanged(); 245 settings_->OnIPAddressChanged();
264 base::MessageLoop::current()->RunUntilIdle(); 246 base::MessageLoop::current()->RunUntilIdle();
265 CheckProxyConfigs(true, expected_restricted, expected_fallback_restricted); 247 CheckProxyConfigs(true, expected_restricted, expected_fallback_restricted);
266 } 248 }
267 249
268 void DataReductionProxySettingsTestBase::CheckOnPrefChange( 250 void DataReductionProxySettingsTestBase::CheckOnPrefChange(
269 bool enabled, 251 bool enabled,
270 bool expected_enabled, 252 bool expected_enabled,
271 bool managed) { 253 bool managed) {
272 // Always have a sucessful probe for pref change tests. 254 // Always have a sucessful probe for pref change tests.
273 SetProbeResult(kProbeURLWithOKResponse, 255 SetProbeResult(kProbeURLWithOKResponse,
274 kWarmupURLWithNoContentResponse,
275 "OK", 256 "OK",
276 FetchResult(enabled, true), 257 FetchResult(enabled, true),
277 true, 258 true,
278 expected_enabled ? 1 : 0); 259 expected_enabled ? 1 : 0);
279 if (managed) { 260 if (managed) {
280 pref_service_.SetManagedPref(prefs::kDataReductionProxyEnabled, 261 pref_service_.SetManagedPref(prefs::kDataReductionProxyEnabled,
281 new base::FundamentalValue(enabled)); 262 new base::FundamentalValue(enabled));
282 } else { 263 } else {
283 pref_service_.SetBoolean(prefs::kDataReductionProxyEnabled, enabled); 264 pref_service_.SetBoolean(prefs::kDataReductionProxyEnabled, enabled);
284 } 265 }
285 base::MessageLoop::current()->RunUntilIdle(); 266 base::MessageLoop::current()->RunUntilIdle();
286 // Never expect the proxy to be restricted for pref change tests. 267 // Never expect the proxy to be restricted for pref change tests.
287 CheckProxyConfigs(expected_enabled, false, false); 268 CheckProxyConfigs(expected_enabled, false, false);
288 } 269 }
289 270
290 void DataReductionProxySettingsTestBase::CheckInitDataReductionProxy( 271 void DataReductionProxySettingsTestBase::CheckInitDataReductionProxy(
291 bool enabled_at_startup) { 272 bool enabled_at_startup) {
292 base::MessageLoopForUI loop; 273 base::MessageLoopForUI loop;
293 SetProbeResult(kProbeURLWithOKResponse, 274 SetProbeResult(kProbeURLWithOKResponse,
294 kWarmupURLWithNoContentResponse,
295 "OK", 275 "OK",
296 FetchResult(enabled_at_startup, true), 276 FetchResult(enabled_at_startup, true),
297 true, 277 true,
298 enabled_at_startup ? 1 : 0); 278 enabled_at_startup ? 1 : 0);
299 scoped_ptr<DataReductionProxyConfigurator> configurator( 279 scoped_ptr<DataReductionProxyConfigurator> configurator(
300 new TestDataReductionProxyConfig()); 280 new TestDataReductionProxyConfig());
301 settings_->SetProxyConfigurator(configurator.get()); 281 settings_->SetProxyConfigurator(configurator.get());
302 scoped_refptr<net::TestURLRequestContextGetter> request_context = 282 scoped_refptr<net::TestURLRequestContextGetter> request_context =
303 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); 283 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current());
304 284
305 settings_->InitDataReductionProxySettings( 285 settings_->InitDataReductionProxySettings(
306 &pref_service_, 286 &pref_service_,
307 &pref_service_, 287 &pref_service_,
308 request_context.get()); 288 request_context.get());
309 settings_->SetOnDataReductionEnabledCallback( 289 settings_->SetOnDataReductionEnabledCallback(
310 base::Bind(&DataReductionProxySettingsTestBase:: 290 base::Bind(&DataReductionProxySettingsTestBase::
311 RegisterSyntheticFieldTrialCallback, 291 RegisterSyntheticFieldTrialCallback,
312 base::Unretained(this))); 292 base::Unretained(this)));
313 293
314 base::MessageLoop::current()->RunUntilIdle(); 294 base::MessageLoop::current()->RunUntilIdle();
315 CheckProxyConfigs(enabled_at_startup, false, false); 295 CheckProxyConfigs(enabled_at_startup, false, false);
316 EXPECT_EQ(enabled_at_startup, proxy_enabled_); 296 EXPECT_EQ(enabled_at_startup, proxy_enabled_);
317 } 297 }
318 298
319 } // namespace data_reduction_proxy 299 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698