| 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" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 EXPECT_CALL(*settings, GetOriginalProfilePrefs()) | 139 EXPECT_CALL(*settings, GetOriginalProfilePrefs()) |
| 140 .Times(AnyNumber()) | 140 .Times(AnyNumber()) |
| 141 .WillRepeatedly(Return(&pref_service_)); | 141 .WillRepeatedly(Return(&pref_service_)); |
| 142 EXPECT_CALL(*settings, GetLocalStatePrefs()) | 142 EXPECT_CALL(*settings, GetLocalStatePrefs()) |
| 143 .Times(AnyNumber()) | 143 .Times(AnyNumber()) |
| 144 .WillRepeatedly(Return(&pref_service_)); | 144 .WillRepeatedly(Return(&pref_service_)); |
| 145 EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck()).Times(0); | 145 EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck()).Times(0); |
| 146 EXPECT_CALL(*settings, GetURLFetcherForWarmup()).Times(0); | 146 EXPECT_CALL(*settings, GetURLFetcherForWarmup()).Times(0); |
| 147 EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0); | 147 EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0); |
| 148 settings_.reset(settings); | 148 settings_.reset(settings); |
| 149 settings_->configurator_.reset(new TestDataReductionProxyConfig()); | 149 configurator_.reset(new TestDataReductionProxyConfig()); |
| 150 settings_->configurator_ = configurator_.get(); |
| 150 } | 151 } |
| 151 | 152 |
| 152 // Explicitly generate required instantiations. | 153 // Explicitly generate required instantiations. |
| 153 template void | 154 template void |
| 154 DataReductionProxySettingsTestBase::ResetSettings<DataReductionProxySettings>( | 155 DataReductionProxySettingsTestBase::ResetSettings<DataReductionProxySettings>( |
| 155 bool allowed, | 156 bool allowed, |
| 156 bool fallback_allowed, | 157 bool fallback_allowed, |
| 157 bool alt_allowed, | 158 bool alt_allowed, |
| 158 bool promo_allowed, | 159 bool promo_allowed, |
| 159 bool holdback); | 160 bool holdback); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 const std::string& response, | 204 const std::string& response, |
| 204 ProbeURLFetchResult result, | 205 ProbeURLFetchResult result, |
| 205 bool success, | 206 bool success, |
| 206 int expected_calls); | 207 int expected_calls); |
| 207 | 208 |
| 208 void DataReductionProxySettingsTestBase::CheckProxyConfigs( | 209 void DataReductionProxySettingsTestBase::CheckProxyConfigs( |
| 209 bool expected_enabled, | 210 bool expected_enabled, |
| 210 bool expected_restricted, | 211 bool expected_restricted, |
| 211 bool expected_fallback_restricted) { | 212 bool expected_fallback_restricted) { |
| 212 TestDataReductionProxyConfig* config = | 213 TestDataReductionProxyConfig* config = |
| 213 static_cast<TestDataReductionProxyConfig*>( | 214 static_cast<TestDataReductionProxyConfig*>(settings_->configurator_); |
| 214 settings_->configurator_.get()); | |
| 215 ASSERT_EQ(expected_restricted, config->restricted_); | 215 ASSERT_EQ(expected_restricted, config->restricted_); |
| 216 ASSERT_EQ(expected_fallback_restricted, config->fallback_restricted_); | 216 ASSERT_EQ(expected_fallback_restricted, config->fallback_restricted_); |
| 217 ASSERT_EQ(expected_enabled, config->enabled_); | 217 ASSERT_EQ(expected_enabled, config->enabled_); |
| 218 } | 218 } |
| 219 | 219 |
| 220 void DataReductionProxySettingsTestBase::CheckProbe( | 220 void DataReductionProxySettingsTestBase::CheckProbe( |
| 221 bool initially_enabled, | 221 bool initially_enabled, |
| 222 const std::string& probe_url, | 222 const std::string& probe_url, |
| 223 const std::string& warmup_url, | 223 const std::string& warmup_url, |
| 224 const std::string& response, | 224 const std::string& response, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 bool enabled_at_startup) { | 290 bool enabled_at_startup) { |
| 291 base::MessageLoopForUI loop; | 291 base::MessageLoopForUI loop; |
| 292 SetProbeResult(kProbeURLWithOKResponse, | 292 SetProbeResult(kProbeURLWithOKResponse, |
| 293 kWarmupURLWithNoContentResponse, | 293 kWarmupURLWithNoContentResponse, |
| 294 "OK", | 294 "OK", |
| 295 FetchResult(enabled_at_startup, true), | 295 FetchResult(enabled_at_startup, true), |
| 296 true, | 296 true, |
| 297 enabled_at_startup ? 1 : 0); | 297 enabled_at_startup ? 1 : 0); |
| 298 scoped_ptr<DataReductionProxyConfigurator> configurator( | 298 scoped_ptr<DataReductionProxyConfigurator> configurator( |
| 299 new TestDataReductionProxyConfig()); | 299 new TestDataReductionProxyConfig()); |
| 300 settings_->SetProxyConfigurator(configurator.Pass()); | 300 settings_->SetProxyConfigurator(configurator.get()); |
| 301 scoped_refptr<net::TestURLRequestContextGetter> request_context = | 301 scoped_refptr<net::TestURLRequestContextGetter> request_context = |
| 302 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); | 302 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); |
| 303 | 303 |
| 304 settings_->InitDataReductionProxySettings( | 304 settings_->InitDataReductionProxySettings( |
| 305 &pref_service_, | 305 &pref_service_, |
| 306 &pref_service_, | 306 &pref_service_, |
| 307 request_context.get()); | 307 request_context.get()); |
| 308 settings_->SetOnDataReductionEnabledCallback( | 308 settings_->SetOnDataReductionEnabledCallback( |
| 309 base::Bind(&DataReductionProxySettingsTestBase:: | 309 base::Bind(&DataReductionProxySettingsTestBase:: |
| 310 RegisterSyntheticFieldTrialCallback, | 310 RegisterSyntheticFieldTrialCallback, |
| 311 base::Unretained(this))); | 311 base::Unretained(this))); |
| 312 | 312 |
| 313 base::MessageLoop::current()->RunUntilIdle(); | 313 base::MessageLoop::current()->RunUntilIdle(); |
| 314 CheckProxyConfigs(enabled_at_startup, false, false); | 314 CheckProxyConfigs(enabled_at_startup, false, false); |
| 315 EXPECT_EQ(enabled_at_startup, proxy_enabled_); | 315 EXPECT_EQ(enabled_at_startup, proxy_enabled_); |
| 316 } | 316 } |
| 317 | 317 |
| 318 } // namespace data_reduction_proxy | 318 } // namespace data_reduction_proxy |
| OLD | NEW |