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 "base/time/time.h" |
| 15 #include "components/data_reduction_proxy/browser/data_reduction_proxy_prefs.h" |
| 16 #include "components/data_reduction_proxy/browser/data_reduction_proxy_statistic
s_prefs.h" |
13 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names
.h" | 17 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names
.h" |
14 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h
" | 18 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h
" |
15 | 19 |
16 using testing::_; | 20 using testing::_; |
17 using testing::AnyNumber; | 21 using testing::AnyNumber; |
18 using testing::Return; | 22 using testing::Return; |
19 | 23 |
20 namespace { | 24 namespace { |
21 | 25 |
22 const char kProbeURLWithOKResponse[] = "http://ok.org/"; | 26 const char kProbeURLWithOKResponse[] = "http://ok.org/"; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 void TestDataReductionProxyConfig::Disable() { | 72 void TestDataReductionProxyConfig::Disable() { |
69 enabled_ = false; | 73 enabled_ = false; |
70 restricted_ = false; | 74 restricted_ = false; |
71 fallback_restricted_ = false; | 75 fallback_restricted_ = false; |
72 origin_ = ""; | 76 origin_ = ""; |
73 fallback_origin_ = ""; | 77 fallback_origin_ = ""; |
74 ssl_origin_ = ""; | 78 ssl_origin_ = ""; |
75 } | 79 } |
76 | 80 |
77 DataReductionProxySettingsTestBase::DataReductionProxySettingsTestBase() | 81 DataReductionProxySettingsTestBase::DataReductionProxySettingsTestBase() |
78 : testing::Test() { | 82 : testing::Test() {} |
79 } | |
80 | 83 |
81 DataReductionProxySettingsTestBase::~DataReductionProxySettingsTestBase() {} | 84 DataReductionProxySettingsTestBase::~DataReductionProxySettingsTestBase() {} |
82 | 85 |
83 // testing::Test implementation: | 86 // testing::Test implementation: |
84 void DataReductionProxySettingsTestBase::SetUp() { | 87 void DataReductionProxySettingsTestBase::SetUp() { |
85 PrefRegistrySimple* registry = pref_service_.registry(); | 88 PrefRegistrySimple* registry = pref_service_.registry(); |
86 registry->RegisterListPref(prefs::kDailyHttpOriginalContentLength); | 89 registry->RegisterListPref(prefs::kDailyHttpOriginalContentLength); |
87 registry->RegisterListPref(prefs::kDailyHttpReceivedContentLength); | 90 registry->RegisterListPref(prefs::kDailyHttpReceivedContentLength); |
88 registry->RegisterInt64Pref(prefs::kDailyHttpContentLengthLastUpdateDate, | 91 registry->RegisterInt64Pref(prefs::kDailyHttpContentLengthLastUpdateDate, |
89 0L); | 92 0L); |
90 registry->RegisterDictionaryPref(kProxy); | 93 registry->RegisterDictionaryPref(kProxy); |
91 registry->RegisterBooleanPref(prefs::kDataReductionProxyEnabled, false); | 94 registry->RegisterBooleanPref(prefs::kDataReductionProxyEnabled, false); |
92 registry->RegisterBooleanPref(prefs::kDataReductionProxyAltEnabled, false); | 95 registry->RegisterBooleanPref(prefs::kDataReductionProxyAltEnabled, false); |
93 registry->RegisterBooleanPref(prefs::kDataReductionProxyWasEnabledBefore, | 96 registry->RegisterBooleanPref(prefs::kDataReductionProxyWasEnabledBefore, |
94 false); | 97 false); |
| 98 |
| 99 statistics_prefs_.reset(new DataReductionProxyStatisticsPrefs( |
| 100 &pref_service_, |
| 101 scoped_refptr<base::TestSimpleTaskRunner>( |
| 102 new base::TestSimpleTaskRunner()), |
| 103 base::TimeDelta())); |
| 104 |
95 //AddProxyToCommandLine(); | 105 //AddProxyToCommandLine(); |
96 ResetSettings(true, true, false, true, false); | 106 ResetSettings(true, true, false, true, false); |
97 | 107 |
98 ListPrefUpdate original_update(&pref_service_, | 108 ListPrefUpdate original_update(&pref_service_, |
99 prefs::kDailyHttpOriginalContentLength); | 109 prefs::kDailyHttpOriginalContentLength); |
100 ListPrefUpdate received_update(&pref_service_, | 110 ListPrefUpdate received_update(&pref_service_, |
101 prefs::kDailyHttpReceivedContentLength); | 111 prefs::kDailyHttpReceivedContentLength); |
102 for (int64 i = 0; i < kNumDaysInHistory; i++) { | 112 for (int64 i = 0; i < kNumDaysInHistory; i++) { |
103 original_update->Insert(0, | 113 original_update->Insert(0, |
104 new base::StringValue(base::Int64ToString(2 * i))); | 114 new base::StringValue(base::Int64ToString(2 * i))); |
105 received_update->Insert(0, new base::StringValue(base::Int64ToString(i))); | 115 received_update->Insert(0, new base::StringValue(base::Int64ToString(i))); |
106 } | 116 } |
107 last_update_time_ = base::Time::Now().LocalMidnight(); | 117 last_update_time_ = base::Time::Now().LocalMidnight(); |
108 pref_service_.SetInt64( | 118 statistics_prefs_->SetInt64( |
109 prefs::kDailyHttpContentLengthLastUpdateDate, | 119 prefs::kDailyHttpContentLengthLastUpdateDate, |
110 last_update_time_.ToInternalValue()); | 120 last_update_time_.ToInternalValue()); |
111 expected_params_.reset(new TestDataReductionProxyParams( | 121 expected_params_.reset(new TestDataReductionProxyParams( |
112 DataReductionProxyParams::kAllowed | | 122 DataReductionProxyParams::kAllowed | |
113 DataReductionProxyParams::kFallbackAllowed | | 123 DataReductionProxyParams::kFallbackAllowed | |
114 DataReductionProxyParams::kPromoAllowed, | 124 DataReductionProxyParams::kPromoAllowed, |
115 TestDataReductionProxyParams::HAS_EVERYTHING & | 125 TestDataReductionProxyParams::HAS_EVERYTHING & |
116 ~TestDataReductionProxyParams::HAS_DEV_ORIGIN & | 126 ~TestDataReductionProxyParams::HAS_DEV_ORIGIN & |
117 ~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN)); | 127 ~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN)); |
118 } | 128 } |
(...skipping 21 matching lines...) Expand all Loading... |
140 .Times(AnyNumber()) | 150 .Times(AnyNumber()) |
141 .WillRepeatedly(Return(&pref_service_)); | 151 .WillRepeatedly(Return(&pref_service_)); |
142 EXPECT_CALL(*settings, GetLocalStatePrefs()) | 152 EXPECT_CALL(*settings, GetLocalStatePrefs()) |
143 .Times(AnyNumber()) | 153 .Times(AnyNumber()) |
144 .WillRepeatedly(Return(&pref_service_)); | 154 .WillRepeatedly(Return(&pref_service_)); |
145 EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck()).Times(0); | 155 EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck()).Times(0); |
146 EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0); | 156 EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0); |
147 settings_.reset(settings); | 157 settings_.reset(settings); |
148 configurator_.reset(new TestDataReductionProxyConfig()); | 158 configurator_.reset(new TestDataReductionProxyConfig()); |
149 settings_->configurator_ = configurator_.get(); | 159 settings_->configurator_ = configurator_.get(); |
| 160 settings_->SetDataReductionProxyStatisticsPrefs(statistics_prefs_.get()); |
150 } | 161 } |
151 | 162 |
152 // Explicitly generate required instantiations. | 163 // Explicitly generate required instantiations. |
153 template void | 164 template void |
154 DataReductionProxySettingsTestBase::ResetSettings<DataReductionProxySettings>( | 165 DataReductionProxySettingsTestBase::ResetSettings<DataReductionProxySettings>( |
155 bool allowed, | 166 bool allowed, |
156 bool fallback_allowed, | 167 bool fallback_allowed, |
157 bool alt_allowed, | 168 bool alt_allowed, |
158 bool promo_allowed, | 169 bool promo_allowed, |
159 bool holdback); | 170 bool holdback); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 true, | 288 true, |
278 enabled_at_startup ? 1 : 0); | 289 enabled_at_startup ? 1 : 0); |
279 scoped_ptr<DataReductionProxyConfigurator> configurator( | 290 scoped_ptr<DataReductionProxyConfigurator> configurator( |
280 new TestDataReductionProxyConfig()); | 291 new TestDataReductionProxyConfig()); |
281 settings_->SetProxyConfigurator(configurator.get()); | 292 settings_->SetProxyConfigurator(configurator.get()); |
282 scoped_refptr<net::TestURLRequestContextGetter> request_context = | 293 scoped_refptr<net::TestURLRequestContextGetter> request_context = |
283 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); | 294 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); |
284 | 295 |
285 settings_->InitDataReductionProxySettings( | 296 settings_->InitDataReductionProxySettings( |
286 &pref_service_, | 297 &pref_service_, |
287 &pref_service_, | |
288 request_context.get()); | 298 request_context.get()); |
289 settings_->SetOnDataReductionEnabledCallback( | 299 settings_->SetOnDataReductionEnabledCallback( |
290 base::Bind(&DataReductionProxySettingsTestBase:: | 300 base::Bind(&DataReductionProxySettingsTestBase:: |
291 RegisterSyntheticFieldTrialCallback, | 301 RegisterSyntheticFieldTrialCallback, |
292 base::Unretained(this))); | 302 base::Unretained(this))); |
293 | 303 |
294 base::MessageLoop::current()->RunUntilIdle(); | 304 base::MessageLoop::current()->RunUntilIdle(); |
295 CheckProxyConfigs(enabled_at_startup, false, false); | 305 CheckProxyConfigs(enabled_at_startup, false, false); |
296 EXPECT_EQ(enabled_at_startup, proxy_enabled_); | 306 EXPECT_EQ(enabled_at_startup, proxy_enabled_); |
297 } | 307 } |
298 | 308 |
299 } // namespace data_reduction_proxy | 309 } // namespace data_reduction_proxy |
OLD | NEW |