Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Side by Side Diff: components/data_reduction_proxy/browser/data_reduction_proxy_settings_test_utils.cc

Issue 473723002: Update data reduction proxy statistics prefs less often on desktop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tooManyWritesPatch
Patch Set: Fixing BUILD.gn and includes Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 void TestDataReductionProxyConfig::Disable() { 73 void TestDataReductionProxyConfig::Disable() {
70 enabled_ = false; 74 enabled_ = false;
71 restricted_ = false; 75 restricted_ = false;
72 fallback_restricted_ = false; 76 fallback_restricted_ = false;
73 origin_ = ""; 77 origin_ = "";
74 fallback_origin_ = ""; 78 fallback_origin_ = "";
75 ssl_origin_ = ""; 79 ssl_origin_ = "";
76 } 80 }
77 81
78 DataReductionProxySettingsTestBase::DataReductionProxySettingsTestBase() 82 DataReductionProxySettingsTestBase::DataReductionProxySettingsTestBase()
79 : testing::Test() { 83 : testing::Test() {}
80 }
81 84
82 DataReductionProxySettingsTestBase::~DataReductionProxySettingsTestBase() {} 85 DataReductionProxySettingsTestBase::~DataReductionProxySettingsTestBase() {}
83 86
84 // testing::Test implementation: 87 // testing::Test implementation:
85 void DataReductionProxySettingsTestBase::SetUp() { 88 void DataReductionProxySettingsTestBase::SetUp() {
86 PrefRegistrySimple* registry = pref_service_.registry(); 89 PrefRegistrySimple* registry = pref_service_.registry();
87 registry->RegisterListPref(prefs::kDailyHttpOriginalContentLength); 90 registry->RegisterListPref(prefs::kDailyHttpOriginalContentLength);
88 registry->RegisterListPref(prefs::kDailyHttpReceivedContentLength); 91 registry->RegisterListPref(prefs::kDailyHttpReceivedContentLength);
89 registry->RegisterInt64Pref(prefs::kDailyHttpContentLengthLastUpdateDate, 92 registry->RegisterInt64Pref(prefs::kDailyHttpContentLengthLastUpdateDate,
90 0L); 93 0L);
91 registry->RegisterDictionaryPref(kProxy); 94 registry->RegisterDictionaryPref(kProxy);
92 registry->RegisterBooleanPref(prefs::kDataReductionProxyEnabled, false); 95 registry->RegisterBooleanPref(prefs::kDataReductionProxyEnabled, false);
93 registry->RegisterBooleanPref(prefs::kDataReductionProxyAltEnabled, false); 96 registry->RegisterBooleanPref(prefs::kDataReductionProxyAltEnabled, false);
94 registry->RegisterBooleanPref(prefs::kDataReductionProxyWasEnabledBefore, 97 registry->RegisterBooleanPref(prefs::kDataReductionProxyWasEnabledBefore,
95 false); 98 false);
99
100 statistics_prefs_.reset(new DataReductionProxyStatisticsPrefs(
101 &pref_service_,
102 scoped_refptr<base::TestSimpleTaskRunner>(
103 new base::TestSimpleTaskRunner()),
104 base::TimeDelta()));
105
96 //AddProxyToCommandLine(); 106 //AddProxyToCommandLine();
97 ResetSettings(true, true, false, true, false); 107 ResetSettings(true, true, false, true, false);
98 108
99 ListPrefUpdate original_update(&pref_service_, 109 ListPrefUpdate original_update(&pref_service_,
100 prefs::kDailyHttpOriginalContentLength); 110 prefs::kDailyHttpOriginalContentLength);
101 ListPrefUpdate received_update(&pref_service_, 111 ListPrefUpdate received_update(&pref_service_,
102 prefs::kDailyHttpReceivedContentLength); 112 prefs::kDailyHttpReceivedContentLength);
103 for (int64 i = 0; i < kNumDaysInHistory; i++) { 113 for (int64 i = 0; i < kNumDaysInHistory; i++) {
104 original_update->Insert(0, 114 original_update->Insert(0,
105 new base::StringValue(base::Int64ToString(2 * i))); 115 new base::StringValue(base::Int64ToString(2 * i)));
106 received_update->Insert(0, new base::StringValue(base::Int64ToString(i))); 116 received_update->Insert(0, new base::StringValue(base::Int64ToString(i)));
107 } 117 }
108 last_update_time_ = base::Time::Now().LocalMidnight(); 118 last_update_time_ = base::Time::Now().LocalMidnight();
109 pref_service_.SetInt64( 119 statistics_prefs_->SetInt64(
110 prefs::kDailyHttpContentLengthLastUpdateDate, 120 prefs::kDailyHttpContentLengthLastUpdateDate,
111 last_update_time_.ToInternalValue()); 121 last_update_time_.ToInternalValue());
112 expected_params_.reset(new TestDataReductionProxyParams( 122 expected_params_.reset(new TestDataReductionProxyParams(
113 DataReductionProxyParams::kAllowed | 123 DataReductionProxyParams::kAllowed |
114 DataReductionProxyParams::kFallbackAllowed | 124 DataReductionProxyParams::kFallbackAllowed |
115 DataReductionProxyParams::kPromoAllowed, 125 DataReductionProxyParams::kPromoAllowed,
116 TestDataReductionProxyParams::HAS_EVERYTHING & 126 TestDataReductionProxyParams::HAS_EVERYTHING &
117 ~TestDataReductionProxyParams::HAS_DEV_ORIGIN)); 127 ~TestDataReductionProxyParams::HAS_DEV_ORIGIN));
118 } 128 }
119 129
(...skipping 21 matching lines...) Expand all
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, GetURLFetcherForWarmup()).Times(0); 156 EXPECT_CALL(*settings, GetURLFetcherForWarmup()).Times(0);
147 EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0); 157 EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0);
148 settings_.reset(settings); 158 settings_.reset(settings);
149 configurator_.reset(new TestDataReductionProxyConfig()); 159 configurator_.reset(new TestDataReductionProxyConfig());
150 settings_->configurator_ = configurator_.get(); 160 settings_->configurator_ = configurator_.get();
161 settings_->SetDataReductionProxyStatisticsPrefs(statistics_prefs_.get());
151 } 162 }
152 163
153 // Explicitly generate required instantiations. 164 // Explicitly generate required instantiations.
154 template void 165 template void
155 DataReductionProxySettingsTestBase::ResetSettings<DataReductionProxySettings>( 166 DataReductionProxySettingsTestBase::ResetSettings<DataReductionProxySettings>(
156 bool allowed, 167 bool allowed,
157 bool fallback_allowed, 168 bool fallback_allowed,
158 bool alt_allowed, 169 bool alt_allowed,
159 bool promo_allowed, 170 bool promo_allowed,
160 bool holdback); 171 bool holdback);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 true, 307 true,
297 enabled_at_startup ? 1 : 0); 308 enabled_at_startup ? 1 : 0);
298 scoped_ptr<DataReductionProxyConfigurator> configurator( 309 scoped_ptr<DataReductionProxyConfigurator> configurator(
299 new TestDataReductionProxyConfig()); 310 new TestDataReductionProxyConfig());
300 settings_->SetProxyConfigurator(configurator.get()); 311 settings_->SetProxyConfigurator(configurator.get());
301 scoped_refptr<net::TestURLRequestContextGetter> request_context = 312 scoped_refptr<net::TestURLRequestContextGetter> request_context =
302 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); 313 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current());
303 314
304 settings_->InitDataReductionProxySettings( 315 settings_->InitDataReductionProxySettings(
305 &pref_service_, 316 &pref_service_,
306 &pref_service_,
307 request_context.get()); 317 request_context.get());
308 settings_->SetOnDataReductionEnabledCallback( 318 settings_->SetOnDataReductionEnabledCallback(
309 base::Bind(&DataReductionProxySettingsTestBase:: 319 base::Bind(&DataReductionProxySettingsTestBase::
310 RegisterSyntheticFieldTrialCallback, 320 RegisterSyntheticFieldTrialCallback,
311 base::Unretained(this))); 321 base::Unretained(this)));
312 322
313 base::MessageLoop::current()->RunUntilIdle(); 323 base::MessageLoop::current()->RunUntilIdle();
314 CheckProxyConfigs(enabled_at_startup, false, false); 324 CheckProxyConfigs(enabled_at_startup, false, false);
315 EXPECT_EQ(enabled_at_startup, proxy_enabled_); 325 EXPECT_EQ(enabled_at_startup, proxy_enabled_);
316 } 326 }
317 327
318 } // namespace data_reduction_proxy 328 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698