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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
10 #include "base/prefs/scoped_user_pref_update.h" | 10 #include "base/prefs/scoped_user_pref_update.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 registry->RegisterListPref(prefs::kDailyHttpOriginalContentLength); | 86 registry->RegisterListPref(prefs::kDailyHttpOriginalContentLength); |
87 registry->RegisterListPref(prefs::kDailyHttpReceivedContentLength); | 87 registry->RegisterListPref(prefs::kDailyHttpReceivedContentLength); |
88 registry->RegisterInt64Pref(prefs::kDailyHttpContentLengthLastUpdateDate, | 88 registry->RegisterInt64Pref(prefs::kDailyHttpContentLengthLastUpdateDate, |
89 0L); | 89 0L); |
90 registry->RegisterDictionaryPref(kProxy); | 90 registry->RegisterDictionaryPref(kProxy); |
91 registry->RegisterBooleanPref(prefs::kDataReductionProxyEnabled, false); | 91 registry->RegisterBooleanPref(prefs::kDataReductionProxyEnabled, false); |
92 registry->RegisterBooleanPref(prefs::kDataReductionProxyAltEnabled, false); | 92 registry->RegisterBooleanPref(prefs::kDataReductionProxyAltEnabled, false); |
93 registry->RegisterBooleanPref(prefs::kDataReductionProxyWasEnabledBefore, | 93 registry->RegisterBooleanPref(prefs::kDataReductionProxyWasEnabledBefore, |
94 false); | 94 false); |
95 //AddProxyToCommandLine(); | 95 //AddProxyToCommandLine(); |
96 ResetSettings(true, true, false, true); | 96 ResetSettings(true, true, false, true, false); |
97 | 97 |
98 ListPrefUpdate original_update(&pref_service_, | 98 ListPrefUpdate original_update(&pref_service_, |
99 prefs::kDailyHttpOriginalContentLength); | 99 prefs::kDailyHttpOriginalContentLength); |
100 ListPrefUpdate received_update(&pref_service_, | 100 ListPrefUpdate received_update(&pref_service_, |
101 prefs::kDailyHttpReceivedContentLength); | 101 prefs::kDailyHttpReceivedContentLength); |
102 for (int64 i = 0; i < kNumDaysInHistory; i++) { | 102 for (int64 i = 0; i < kNumDaysInHistory; i++) { |
103 original_update->Insert(0, | 103 original_update->Insert(0, |
104 new base::StringValue(base::Int64ToString(2 * i))); | 104 new base::StringValue(base::Int64ToString(2 * i))); |
105 received_update->Insert(0, new base::StringValue(base::Int64ToString(i))); | 105 received_update->Insert(0, new base::StringValue(base::Int64ToString(i))); |
106 } | 106 } |
107 last_update_time_ = base::Time::Now().LocalMidnight(); | 107 last_update_time_ = base::Time::Now().LocalMidnight(); |
108 pref_service_.SetInt64( | 108 pref_service_.SetInt64( |
109 prefs::kDailyHttpContentLengthLastUpdateDate, | 109 prefs::kDailyHttpContentLengthLastUpdateDate, |
110 last_update_time_.ToInternalValue()); | 110 last_update_time_.ToInternalValue()); |
111 expected_params_.reset(new TestDataReductionProxyParams( | 111 expected_params_.reset(new TestDataReductionProxyParams( |
112 DataReductionProxyParams::kAllowed | | 112 DataReductionProxyParams::kAllowed | |
113 DataReductionProxyParams::kFallbackAllowed | | 113 DataReductionProxyParams::kFallbackAllowed | |
114 DataReductionProxyParams::kPromoAllowed, | 114 DataReductionProxyParams::kPromoAllowed, |
115 TestDataReductionProxyParams::HAS_EVERYTHING & | 115 TestDataReductionProxyParams::HAS_EVERYTHING & |
116 ~TestDataReductionProxyParams::HAS_DEV_ORIGIN)); | 116 ~TestDataReductionProxyParams::HAS_DEV_ORIGIN)); |
117 } | 117 } |
118 | 118 |
119 template <class C> | 119 template <class C> |
120 void DataReductionProxySettingsTestBase::ResetSettings(bool allowed, | 120 void DataReductionProxySettingsTestBase::ResetSettings(bool allowed, |
121 bool fallback_allowed, | 121 bool fallback_allowed, |
122 bool alt_allowed, | 122 bool alt_allowed, |
123 bool promo_allowed) { | 123 bool promo_allowed, |
| 124 bool holdback) { |
124 int flags = 0; | 125 int flags = 0; |
125 if (allowed) | 126 if (allowed) |
126 flags |= DataReductionProxyParams::kAllowed; | 127 flags |= DataReductionProxyParams::kAllowed; |
127 if (fallback_allowed) | 128 if (fallback_allowed) |
128 flags |= DataReductionProxyParams::kFallbackAllowed; | 129 flags |= DataReductionProxyParams::kFallbackAllowed; |
129 if (alt_allowed) | 130 if (alt_allowed) |
130 flags |= DataReductionProxyParams::kAlternativeAllowed; | 131 flags |= DataReductionProxyParams::kAlternativeAllowed; |
131 if (promo_allowed) | 132 if (promo_allowed) |
132 flags |= DataReductionProxyParams::kPromoAllowed; | 133 flags |= DataReductionProxyParams::kPromoAllowed; |
| 134 if (holdback) |
| 135 flags |= DataReductionProxyParams::kHoldback; |
133 MockDataReductionProxySettings<C>* settings = | 136 MockDataReductionProxySettings<C>* settings = |
134 new MockDataReductionProxySettings<C>(flags); | 137 new MockDataReductionProxySettings<C>(flags); |
135 EXPECT_CALL(*settings, GetOriginalProfilePrefs()) | 138 EXPECT_CALL(*settings, GetOriginalProfilePrefs()) |
136 .Times(AnyNumber()) | 139 .Times(AnyNumber()) |
137 .WillRepeatedly(Return(&pref_service_)); | 140 .WillRepeatedly(Return(&pref_service_)); |
138 EXPECT_CALL(*settings, GetLocalStatePrefs()) | 141 EXPECT_CALL(*settings, GetLocalStatePrefs()) |
139 .Times(AnyNumber()) | 142 .Times(AnyNumber()) |
140 .WillRepeatedly(Return(&pref_service_)); | 143 .WillRepeatedly(Return(&pref_service_)); |
141 EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck()).Times(0); | 144 EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck()).Times(0); |
142 EXPECT_CALL(*settings, GetURLFetcherForWarmup()).Times(0); | 145 EXPECT_CALL(*settings, GetURLFetcherForWarmup()).Times(0); |
143 EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0); | 146 EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0); |
144 settings_.reset(settings); | 147 settings_.reset(settings); |
145 settings_->configurator_.reset(new TestDataReductionProxyConfig()); | 148 settings_->configurator_.reset(new TestDataReductionProxyConfig()); |
146 } | 149 } |
147 | 150 |
148 // Explicitly generate required instantiations. | 151 // Explicitly generate required instantiations. |
149 template void | 152 template void |
150 DataReductionProxySettingsTestBase::ResetSettings<DataReductionProxySettings>( | 153 DataReductionProxySettingsTestBase::ResetSettings<DataReductionProxySettings>( |
151 bool allowed, bool fallback_allowed, bool alt_allowed, bool promo_allowed); | 154 bool allowed, |
| 155 bool fallback_allowed, |
| 156 bool alt_allowed, |
| 157 bool promo_allowed, |
| 158 bool holdback); |
152 | 159 |
153 template <class C> | 160 template <class C> |
154 void DataReductionProxySettingsTestBase::SetProbeResult( | 161 void DataReductionProxySettingsTestBase::SetProbeResult( |
155 const std::string& test_url, | 162 const std::string& test_url, |
156 const std::string& warmup_test_url, | 163 const std::string& warmup_test_url, |
157 const std::string& response, | 164 const std::string& response, |
158 ProbeURLFetchResult result, | 165 ProbeURLFetchResult result, |
159 bool success, | 166 bool success, |
160 int expected_calls) { | 167 int expected_calls) { |
161 MockDataReductionProxySettings<C>* settings = | 168 MockDataReductionProxySettings<C>* settings = |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); | 301 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); |
295 settings_->InitDataReductionProxySettings(&pref_service_, | 302 settings_->InitDataReductionProxySettings(&pref_service_, |
296 &pref_service_, | 303 &pref_service_, |
297 request_context.get()); | 304 request_context.get()); |
298 | 305 |
299 base::MessageLoop::current()->RunUntilIdle(); | 306 base::MessageLoop::current()->RunUntilIdle(); |
300 CheckProxyConfigs(enabled_at_startup, false, false); | 307 CheckProxyConfigs(enabled_at_startup, false, false); |
301 } | 308 } |
302 | 309 |
303 } // namespace data_reduction_proxy | 310 } // namespace data_reduction_proxy |
OLD | NEW |