Chromium Code Reviews| 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_sett ings.h" | 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.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/metrics/field_trial.h" | |
| 10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/test/test_simple_task_runner.h" | 12 #include "base/test/test_simple_task_runner.h" |
| 12 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf igurator_test_utils.h" | 13 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf igurator_test_utils.h" |
| 13 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings_test_utils.h" | 14 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings_test_utils.h" |
| 14 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" | 15 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" |
| 15 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h" | 16 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h" |
| 16 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc hes.h" | 17 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc hes.h" |
| 17 #include "net/http/http_auth.h" | 18 #include "net/http/http_auth.h" |
| 18 #include "net/http/http_auth_cache.h" | 19 #include "net/http/http_auth_cache.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 const char kProbeURLWithOKResponse[] = "http://ok.org/"; | 25 const char kProbeURLWithOKResponse[] = "http://ok.org/"; |
| 25 const char kProbeURLWithBadResponse[] = "http://bad.org/"; | 26 const char kProbeURLWithBadResponse[] = "http://bad.org/"; |
| 26 const char kProbeURLWithNoResponse[] = "http://no.org/"; | 27 const char kProbeURLWithNoResponse[] = "http://no.org/"; |
| 27 | 28 |
| 28 } // namespace | 29 } // namespace |
| 29 | 30 |
| 30 namespace data_reduction_proxy { | 31 namespace data_reduction_proxy { |
| 31 | 32 |
| 32 class DataReductionProxyStatisticsPrefs; | 33 class DataReductionProxyStatisticsPrefs; |
| 33 | 34 |
| 35 class BadEntropyProvider : public base::FieldTrial::EntropyProvider { | |
| 36 public: | |
| 37 ~BadEntropyProvider() override {} | |
| 38 | |
| 39 double GetEntropyForTrial(const std::string& trial_name, | |
| 40 uint32 randomization_seed) const override { | |
| 41 return 0.5; | |
| 42 } | |
| 43 }; | |
| 44 | |
| 34 class DataReductionProxySettingsTest | 45 class DataReductionProxySettingsTest |
| 35 : public ConcreteDataReductionProxySettingsTest< | 46 : public ConcreteDataReductionProxySettingsTest< |
| 36 DataReductionProxySettings> { | 47 DataReductionProxySettings> { |
| 37 }; | 48 }; |
| 38 | 49 |
| 39 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyOrigin) { | 50 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyOrigin) { |
| 40 // SetUp() adds the origin to the command line, which should be returned here. | 51 // SetUp() adds the origin to the command line, which should be returned here. |
| 41 std::string result = | 52 std::string result = |
| 42 settings_->params()->origin().ToURI(); | 53 settings_->params()->origin().ToURI(); |
| 43 EXPECT_EQ(expected_params_->DefaultOrigin(), result); | 54 EXPECT_EQ(expected_params_->DefaultOrigin(), result); |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 421 new base::TestSimpleTaskRunner()), | 432 new base::TestSimpleTaskRunner()), |
| 422 &net_log_, event_store_.get())); | 433 &net_log_, event_store_.get())); |
| 423 settings_->SetProxyConfigurator(configurator.get()); | 434 settings_->SetProxyConfigurator(configurator.get()); |
| 424 scoped_refptr<net::TestURLRequestContextGetter> request_context = | 435 scoped_refptr<net::TestURLRequestContextGetter> request_context = |
| 425 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); | 436 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); |
| 426 settings_->InitDataReductionProxySettings( | 437 settings_->InitDataReductionProxySettings( |
| 427 &pref_service_, | 438 &pref_service_, |
| 428 scoped_ptr<DataReductionProxyStatisticsPrefs>(), | 439 scoped_ptr<DataReductionProxyStatisticsPrefs>(), |
| 429 request_context.get(), | 440 request_context.get(), |
| 430 &net_log_, | 441 &net_log_, |
| 431 event_store_.get()); | 442 event_store_.get(), |
| 443 false); | |
| 432 settings_->SetOnDataReductionEnabledCallback( | 444 settings_->SetOnDataReductionEnabledCallback( |
| 433 base::Bind(&DataReductionProxySettingsTestBase:: | 445 base::Bind(&DataReductionProxySettingsTestBase:: |
| 434 RegisterSyntheticFieldTrialCallback, | 446 RegisterSyntheticFieldTrialCallback, |
| 435 base::Unretained(this))); | 447 base::Unretained(this))); |
| 436 | 448 |
| 437 base::MessageLoop::current()->RunUntilIdle(); | 449 base::MessageLoop::current()->RunUntilIdle(); |
| 438 } | 450 } |
| 439 | 451 |
| 452 TEST_F(DataReductionProxySettingsTest, CheckQUICFieldTrials) { | |
| 453 for (int i = 0; i < 2; ++i) { | |
| 454 bool enable_quic = i == 0; | |
| 455 // No call to |AddProxyToCommandLine()| was made, so the proxy feature | |
| 456 // should be unavailable. | |
| 457 base::MessageLoopForUI loop; | |
| 458 // Clear the command line. Setting flags can force the proxy to be allowed. | |
| 459 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL); | |
| 460 | |
| 461 ResetSettings(false, false, false, false, false); | |
| 462 MockSettings* settings = static_cast<MockSettings*>(settings_.get()); | |
| 463 EXPECT_FALSE(settings->params()->allowed()); | |
| 464 EXPECT_CALL(*settings, RecordStartupState(PROXY_NOT_AVAILABLE)); | |
| 465 | |
| 466 scoped_ptr<DataReductionProxyConfigurator> configurator( | |
| 467 new TestDataReductionProxyConfigurator( | |
| 468 scoped_refptr<base::TestSimpleTaskRunner>( | |
| 469 new base::TestSimpleTaskRunner()), | |
| 470 &net_log_, event_store_.get())); | |
| 471 settings_->SetProxyConfigurator(configurator.get()); | |
| 472 scoped_refptr<net::TestURLRequestContextGetter> request_context = | |
| 473 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); | |
| 474 | |
| 475 settings_->InitDataReductionProxySettings( | |
| 476 &pref_service_, | |
| 477 scoped_ptr<DataReductionProxyStatisticsPrefs>(), | |
| 478 request_context.get(), | |
| 479 &net_log_, | |
| 480 event_store_.get(), | |
| 481 false); | |
| 482 | |
| 483 base::FieldTrialList field_trial_list(new BadEntropyProvider()); | |
| 484 if (enable_quic){ | |
|
bengr
2015/02/19 23:30:45
add a space between ) and {
| |
| 485 base::FieldTrialList::CreateFieldTrial( | |
| 486 DataReductionProxyParams::GetQuicFieldTrialName(), | |
| 487 "Enabled"); | |
| 488 } else { | |
| 489 base::FieldTrialList::CreateFieldTrial( | |
| 490 DataReductionProxyParams::GetQuicFieldTrialName(), | |
| 491 "Disabled"); | |
| 492 } | |
| 493 settings_->params()->EnableQuic(enable_quic); | |
| 494 | |
| 495 settings_->SetOnDataReductionEnabledCallback( | |
| 496 base::Bind(&DataReductionProxySettingsTestBase:: | |
| 497 RegisterSyntheticFieldTrialCallback, | |
| 498 base::Unretained(this))); | |
| 499 | |
| 500 EXPECT_EQ(enable_quic, | |
| 501 settings->params()->origin().is_quic()) << i; | |
| 502 } | |
| 503 } | |
| 504 | |
| 440 } // namespace data_reduction_proxy | 505 } // namespace data_reduction_proxy |
| OLD | NEW |