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/browser/data_reduction_proxy_settings.
h" | 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.
h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/md5.h" | 8 #include "base/md5.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 const char kDataReductionProxyDev[] = "http://foo-dev.com:80"; | 24 const char kDataReductionProxyDev[] = "http://foo-dev.com:80"; |
25 const char kDataReductionProxyFallback[] = "http://bar.com:80"; | 25 const char kDataReductionProxyFallback[] = "http://bar.com:80"; |
26 const char kDataReductionProxyKey[] = "12345"; | 26 const char kDataReductionProxyKey[] = "12345"; |
27 const char kDataReductionProxyAlt[] = "https://alt.com:443/"; | 27 const char kDataReductionProxyAlt[] = "https://alt.com:443/"; |
28 const char kDataReductionProxyAltFallback[] = "http://alt2.com:80"; | 28 const char kDataReductionProxyAltFallback[] = "http://alt2.com:80"; |
29 const char kDataReductionProxySSL[] = "http://ssl.com:80"; | 29 const char kDataReductionProxySSL[] = "http://ssl.com:80"; |
30 | 30 |
31 const char kProbeURLWithOKResponse[] = "http://ok.org/"; | 31 const char kProbeURLWithOKResponse[] = "http://ok.org/"; |
32 const char kProbeURLWithBadResponse[] = "http://bad.org/"; | 32 const char kProbeURLWithBadResponse[] = "http://bad.org/"; |
33 const char kProbeURLWithNoResponse[] = "http://no.org/"; | 33 const char kProbeURLWithNoResponse[] = "http://no.org/"; |
| 34 const char kWarmingURLWithNoContentResponse[] = "http://warm.org/"; |
34 | 35 |
35 } // namespace | 36 } // namespace |
36 | 37 |
37 namespace data_reduction_proxy { | 38 namespace data_reduction_proxy { |
38 | 39 |
39 class DataReductionProxySettingsTest | 40 class DataReductionProxySettingsTest |
40 : public ConcreteDataReductionProxySettingsTest< | 41 : public ConcreteDataReductionProxySettingsTest< |
41 DataReductionProxySettings> { | 42 DataReductionProxySettings> { |
42 }; | 43 }; |
43 | 44 |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 prefs::kDataReductionProxyEnabled, | 303 prefs::kDataReductionProxyEnabled, |
303 settings_->GetOriginalProfilePrefs()); | 304 settings_->GetOriginalProfilePrefs()); |
304 settings_->data_reduction_proxy_alternative_enabled_.Init( | 305 settings_->data_reduction_proxy_alternative_enabled_.Init( |
305 prefs::kDataReductionProxyAltEnabled, | 306 prefs::kDataReductionProxyAltEnabled, |
306 settings_->GetOriginalProfilePrefs()); | 307 settings_->GetOriginalProfilePrefs()); |
307 | 308 |
308 // TODO(bengr): Test enabling/disabling while a probe is outstanding. | 309 // TODO(bengr): Test enabling/disabling while a probe is outstanding. |
309 base::MessageLoopForUI loop; | 310 base::MessageLoopForUI loop; |
310 // The proxy is enabled and unrestructed initially. | 311 // The proxy is enabled and unrestructed initially. |
311 // Request succeeded but with bad response, expect proxy to be restricted. | 312 // Request succeeded but with bad response, expect proxy to be restricted. |
312 CheckProbe(true, kProbeURLWithBadResponse, "Bad", true, true, true, false); | 313 CheckProbe(true, |
| 314 kProbeURLWithBadResponse, |
| 315 kWarmingURLWithNoContentResponse, |
| 316 "Bad", |
| 317 true, |
| 318 true, |
| 319 true, |
| 320 false); |
313 // Request succeeded with valid response, expect proxy to be unrestricted. | 321 // Request succeeded with valid response, expect proxy to be unrestricted. |
314 CheckProbe(true, kProbeURLWithOKResponse, "OK", true, true, false, false); | 322 CheckProbe(true, |
| 323 kProbeURLWithOKResponse, |
| 324 kWarmingURLWithNoContentResponse, |
| 325 "OK", |
| 326 true, |
| 327 true, |
| 328 false, |
| 329 false); |
315 // Request failed, expect proxy to be enabled but restricted. | 330 // Request failed, expect proxy to be enabled but restricted. |
316 CheckProbe(true, kProbeURLWithNoResponse, "", false, true, true, false); | 331 CheckProbe(true, |
| 332 kProbeURLWithNoResponse, |
| 333 kWarmingURLWithNoContentResponse, |
| 334 "", |
| 335 false, |
| 336 true, |
| 337 true, |
| 338 false); |
317 // The proxy is disabled initially. Probes should not be emitted to change | 339 // The proxy is disabled initially. Probes should not be emitted to change |
318 // state. | 340 // state. |
319 CheckProbe(false, kProbeURLWithOKResponse, "OK", true, false, false, false); | 341 CheckProbe(false, |
| 342 kProbeURLWithOKResponse, |
| 343 kWarmingURLWithNoContentResponse, |
| 344 "OK", |
| 345 true, |
| 346 false, |
| 347 false, |
| 348 false); |
320 } | 349 } |
321 | 350 |
322 TEST_F(DataReductionProxySettingsTest, TestOnIPAddressChanged) { | 351 TEST_F(DataReductionProxySettingsTest, TestOnIPAddressChanged) { |
323 base::MessageLoopForUI loop; | 352 base::MessageLoopForUI loop; |
324 // The proxy is enabled initially. | 353 // The proxy is enabled initially. |
325 pref_service_.SetBoolean(prefs::kDataReductionProxyEnabled, true); | 354 pref_service_.SetBoolean(prefs::kDataReductionProxyEnabled, true); |
326 settings_->spdy_proxy_auth_enabled_.Init( | 355 settings_->spdy_proxy_auth_enabled_.Init( |
327 prefs::kDataReductionProxyEnabled, | 356 prefs::kDataReductionProxyEnabled, |
328 settings_->GetOriginalProfilePrefs()); | 357 settings_->GetOriginalProfilePrefs()); |
329 settings_->data_reduction_proxy_alternative_enabled_.Init( | 358 settings_->data_reduction_proxy_alternative_enabled_.Init( |
330 prefs::kDataReductionProxyAltEnabled, | 359 prefs::kDataReductionProxyAltEnabled, |
331 settings_->GetOriginalProfilePrefs()); | 360 settings_->GetOriginalProfilePrefs()); |
332 settings_->enabled_by_user_ = true; | 361 settings_->enabled_by_user_ = true; |
333 settings_->restricted_by_carrier_ = false; | 362 settings_->restricted_by_carrier_ = false; |
334 settings_->SetProxyConfigs(true, false, false, true); | 363 settings_->SetProxyConfigs(true, false, false, true); |
335 // IP address change triggers a probe that succeeds. Proxy remains | 364 // IP address change triggers a probe that succeeds. Proxy remains |
336 // unrestricted. | 365 // unrestricted. |
337 CheckProbeOnIPChange(kProbeURLWithOKResponse, "OK", true, false, false); | 366 CheckProbeOnIPChange(kProbeURLWithOKResponse, |
| 367 kWarmingURLWithNoContentResponse, |
| 368 "OK", |
| 369 true, |
| 370 false, |
| 371 false); |
338 // IP address change triggers a probe that fails. Proxy is restricted. | 372 // IP address change triggers a probe that fails. Proxy is restricted. |
339 CheckProbeOnIPChange(kProbeURLWithBadResponse, "Bad", true, true, false); | 373 CheckProbeOnIPChange(kProbeURLWithBadResponse, |
| 374 kWarmingURLWithNoContentResponse, |
| 375 "Bad", |
| 376 true, |
| 377 true, |
| 378 false); |
340 // IP address change triggers a probe that fails. Proxy remains restricted. | 379 // IP address change triggers a probe that fails. Proxy remains restricted. |
341 CheckProbeOnIPChange(kProbeURLWithBadResponse, "Bad", true, true, false); | 380 CheckProbeOnIPChange(kProbeURLWithBadResponse, |
| 381 kWarmingURLWithNoContentResponse, |
| 382 "Bad", |
| 383 true, |
| 384 true, |
| 385 false); |
342 // IP address change triggers a probe that succeed. Proxy is unrestricted. | 386 // IP address change triggers a probe that succeed. Proxy is unrestricted. |
343 CheckProbeOnIPChange(kProbeURLWithBadResponse, "OK", true, false, false); | 387 CheckProbeOnIPChange(kProbeURLWithBadResponse, |
| 388 kWarmingURLWithNoContentResponse, |
| 389 "OK", |
| 390 true, |
| 391 false, |
| 392 false); |
344 } | 393 } |
345 | 394 |
346 TEST_F(DataReductionProxySettingsTest, TestOnProxyEnabledPrefChange) { | 395 TEST_F(DataReductionProxySettingsTest, TestOnProxyEnabledPrefChange) { |
347 settings_->InitPrefMembers(); | 396 settings_->InitPrefMembers(); |
348 base::MessageLoopForUI loop; | 397 base::MessageLoopForUI loop; |
349 // The proxy is enabled initially. | 398 // The proxy is enabled initially. |
350 settings_->enabled_by_user_ = true; | 399 settings_->enabled_by_user_ = true; |
351 settings_->SetProxyConfigs(true, false, false, true); | 400 settings_->SetProxyConfigs(true, false, false, true); |
352 // The pref is disabled, so correspondingly should be the proxy. | 401 // The pref is disabled, so correspondingly should be the proxy. |
353 CheckOnPrefChange(false, false, false); | 402 CheckOnPrefChange(false, false, false); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 scoped_refptr<net::TestURLRequestContextGetter> request_context = | 463 scoped_refptr<net::TestURLRequestContextGetter> request_context = |
415 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); | 464 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); |
416 settings_->InitDataReductionProxySettings(&pref_service_, | 465 settings_->InitDataReductionProxySettings(&pref_service_, |
417 &pref_service_, | 466 &pref_service_, |
418 request_context.get()); | 467 request_context.get()); |
419 | 468 |
420 base::MessageLoop::current()->RunUntilIdle(); | 469 base::MessageLoop::current()->RunUntilIdle(); |
421 } | 470 } |
422 | 471 |
423 } // namespace data_reduction_proxy | 472 } // namespace data_reduction_proxy |
OLD | NEW |