| 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_
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 "base/test/test_simple_task_runner.h" |
| 14 #include "components/data_reduction_proxy/browser/data_reduction_proxy_delayed_p
ref_service.h" |
| 13 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names
.h" | 15 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names
.h" |
| 14 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h
" | 16 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h
" |
| 15 | 17 |
| 16 using testing::_; | 18 using testing::_; |
| 17 using testing::AnyNumber; | 19 using testing::AnyNumber; |
| 18 using testing::Return; | 20 using testing::Return; |
| 19 | 21 |
| 20 namespace { | 22 namespace { |
| 21 | 23 |
| 22 const char kProbeURLWithOKResponse[] = "http://ok.org/"; | 24 const char kProbeURLWithOKResponse[] = "http://ok.org/"; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 } | 78 } |
| 77 | 79 |
| 78 DataReductionProxySettingsTestBase::DataReductionProxySettingsTestBase() | 80 DataReductionProxySettingsTestBase::DataReductionProxySettingsTestBase() |
| 79 : testing::Test() { | 81 : testing::Test() { |
| 80 } | 82 } |
| 81 | 83 |
| 82 DataReductionProxySettingsTestBase::~DataReductionProxySettingsTestBase() {} | 84 DataReductionProxySettingsTestBase::~DataReductionProxySettingsTestBase() {} |
| 83 | 85 |
| 84 // testing::Test implementation: | 86 // testing::Test implementation: |
| 85 void DataReductionProxySettingsTestBase::SetUp() { | 87 void DataReductionProxySettingsTestBase::SetUp() { |
| 88 delayed_pref_service_ = new DataReductionProxyDelayedPrefService( |
| 89 &pref_service_, |
| 90 scoped_refptr<base::TestSimpleTaskRunner>( |
| 91 new base::TestSimpleTaskRunner()), |
| 92 base::TimeDelta()); |
| 86 PrefRegistrySimple* registry = pref_service_.registry(); | 93 PrefRegistrySimple* registry = pref_service_.registry(); |
| 87 registry->RegisterListPref(prefs::kDailyHttpOriginalContentLength); | 94 registry->RegisterListPref(prefs::kDailyHttpOriginalContentLength); |
| 88 registry->RegisterListPref(prefs::kDailyHttpReceivedContentLength); | 95 registry->RegisterListPref(prefs::kDailyHttpReceivedContentLength); |
| 89 registry->RegisterInt64Pref(prefs::kDailyHttpContentLengthLastUpdateDate, | 96 registry->RegisterInt64Pref(prefs::kDailyHttpContentLengthLastUpdateDate, |
| 90 0L); | 97 0L); |
| 91 registry->RegisterDictionaryPref(kProxy); | 98 registry->RegisterDictionaryPref(kProxy); |
| 92 registry->RegisterBooleanPref(prefs::kDataReductionProxyEnabled, false); | 99 registry->RegisterBooleanPref(prefs::kDataReductionProxyEnabled, false); |
| 93 registry->RegisterBooleanPref(prefs::kDataReductionProxyAltEnabled, false); | 100 registry->RegisterBooleanPref(prefs::kDataReductionProxyAltEnabled, false); |
| 94 registry->RegisterBooleanPref(prefs::kDataReductionProxyWasEnabledBefore, | 101 registry->RegisterBooleanPref(prefs::kDataReductionProxyWasEnabledBefore, |
| 95 false); | 102 false); |
| 96 //AddProxyToCommandLine(); | 103 //AddProxyToCommandLine(); |
| 97 ResetSettings(true, true, false, true, false); | 104 ResetSettings(true, true, false, true, false); |
| 98 | 105 |
| 99 ListPrefUpdate original_update(&pref_service_, | 106 ListPrefUpdate original_update(&pref_service_, |
| 100 prefs::kDailyHttpOriginalContentLength); | 107 prefs::kDailyHttpOriginalContentLength); |
| 101 ListPrefUpdate received_update(&pref_service_, | 108 ListPrefUpdate received_update(&pref_service_, |
| 102 prefs::kDailyHttpReceivedContentLength); | 109 prefs::kDailyHttpReceivedContentLength); |
| 103 for (int64 i = 0; i < kNumDaysInHistory; i++) { | 110 for (int64 i = 0; i < kNumDaysInHistory; i++) { |
| 104 original_update->Insert(0, | 111 original_update->Insert(0, |
| 105 new base::StringValue(base::Int64ToString(2 * i))); | 112 new base::StringValue(base::Int64ToString(2 * i))); |
| 106 received_update->Insert(0, new base::StringValue(base::Int64ToString(i))); | 113 received_update->Insert(0, new base::StringValue(base::Int64ToString(i))); |
| 107 } | 114 } |
| 108 last_update_time_ = base::Time::Now().LocalMidnight(); | 115 last_update_time_ = base::Time::Now().LocalMidnight(); |
| 109 pref_service_.SetInt64( | 116 delayed_pref_service_->SetInt64( |
| 110 prefs::kDailyHttpContentLengthLastUpdateDate, | 117 prefs::kDailyHttpContentLengthLastUpdateDate, |
| 111 last_update_time_.ToInternalValue()); | 118 last_update_time_.ToInternalValue()); |
| 112 expected_params_.reset(new TestDataReductionProxyParams( | 119 expected_params_.reset(new TestDataReductionProxyParams( |
| 113 DataReductionProxyParams::kAllowed | | 120 DataReductionProxyParams::kAllowed | |
| 114 DataReductionProxyParams::kFallbackAllowed | | 121 DataReductionProxyParams::kFallbackAllowed | |
| 115 DataReductionProxyParams::kPromoAllowed, | 122 DataReductionProxyParams::kPromoAllowed, |
| 116 TestDataReductionProxyParams::HAS_EVERYTHING & | 123 TestDataReductionProxyParams::HAS_EVERYTHING & |
| 117 ~TestDataReductionProxyParams::HAS_DEV_ORIGIN)); | 124 ~TestDataReductionProxyParams::HAS_DEV_ORIGIN)); |
| 118 } | 125 } |
| 119 | 126 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 139 EXPECT_CALL(*settings, GetOriginalProfilePrefs()) | 146 EXPECT_CALL(*settings, GetOriginalProfilePrefs()) |
| 140 .Times(AnyNumber()) | 147 .Times(AnyNumber()) |
| 141 .WillRepeatedly(Return(&pref_service_)); | 148 .WillRepeatedly(Return(&pref_service_)); |
| 142 EXPECT_CALL(*settings, GetLocalStatePrefs()) | 149 EXPECT_CALL(*settings, GetLocalStatePrefs()) |
| 143 .Times(AnyNumber()) | 150 .Times(AnyNumber()) |
| 144 .WillRepeatedly(Return(&pref_service_)); | 151 .WillRepeatedly(Return(&pref_service_)); |
| 145 EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck()).Times(0); | 152 EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck()).Times(0); |
| 146 EXPECT_CALL(*settings, GetURLFetcherForWarmup()).Times(0); | 153 EXPECT_CALL(*settings, GetURLFetcherForWarmup()).Times(0); |
| 147 EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0); | 154 EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0); |
| 148 settings_.reset(settings); | 155 settings_.reset(settings); |
| 156 settings_->SetDataReductionProxyDelayedPrefService( |
| 157 delayed_pref_service_->AsWeakPtr()); |
| 149 settings_->configurator_.reset(new TestDataReductionProxyConfig()); | 158 settings_->configurator_.reset(new TestDataReductionProxyConfig()); |
| 150 } | 159 } |
| 151 | 160 |
| 152 // Explicitly generate required instantiations. | 161 // Explicitly generate required instantiations. |
| 153 template void | 162 template void |
| 154 DataReductionProxySettingsTestBase::ResetSettings<DataReductionProxySettings>( | 163 DataReductionProxySettingsTestBase::ResetSettings<DataReductionProxySettings>( |
| 155 bool allowed, | 164 bool allowed, |
| 156 bool fallback_allowed, | 165 bool fallback_allowed, |
| 157 bool alt_allowed, | 166 bool alt_allowed, |
| 158 bool promo_allowed, | 167 bool promo_allowed, |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 true, | 305 true, |
| 297 enabled_at_startup ? 1 : 0); | 306 enabled_at_startup ? 1 : 0); |
| 298 scoped_ptr<DataReductionProxyConfigurator> configurator( | 307 scoped_ptr<DataReductionProxyConfigurator> configurator( |
| 299 new TestDataReductionProxyConfig()); | 308 new TestDataReductionProxyConfig()); |
| 300 settings_->SetProxyConfigurator(configurator.Pass()); | 309 settings_->SetProxyConfigurator(configurator.Pass()); |
| 301 scoped_refptr<net::TestURLRequestContextGetter> request_context = | 310 scoped_refptr<net::TestURLRequestContextGetter> request_context = |
| 302 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); | 311 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); |
| 303 | 312 |
| 304 settings_->InitDataReductionProxySettings( | 313 settings_->InitDataReductionProxySettings( |
| 305 &pref_service_, | 314 &pref_service_, |
| 306 &pref_service_, | |
| 307 request_context.get()); | 315 request_context.get()); |
| 308 settings_->SetOnDataReductionEnabledCallback( | 316 settings_->SetOnDataReductionEnabledCallback( |
| 309 base::Bind(&DataReductionProxySettingsTestBase:: | 317 base::Bind(&DataReductionProxySettingsTestBase:: |
| 310 RegisterSyntheticFieldTrialCallback, | 318 RegisterSyntheticFieldTrialCallback, |
| 311 base::Unretained(this))); | 319 base::Unretained(this))); |
| 312 | 320 |
| 313 base::MessageLoop::current()->RunUntilIdle(); | 321 base::MessageLoop::current()->RunUntilIdle(); |
| 314 CheckProxyConfigs(enabled_at_startup, false, false); | 322 CheckProxyConfigs(enabled_at_startup, false, false); |
| 315 EXPECT_EQ(enabled_at_startup, proxy_enabled_); | 323 EXPECT_EQ(enabled_at_startup, proxy_enabled_); |
| 316 } | 324 } |
| 317 | 325 |
| 318 } // namespace data_reduction_proxy | 326 } // namespace data_reduction_proxy |
| OLD | NEW |