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

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: Addressed bengr comments 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 "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" 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
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 statistics_prefs_.reset(new DataReductionProxyStatisticsPrefs(
89 &pref_service_,
90 scoped_refptr<base::TestSimpleTaskRunner>(
91 new base::TestSimpleTaskRunner()),
92 commit_delay_));
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 if (commit_delay_ != base::TimeDelta()) {
117 statistics_prefs_->InitInt64Pref(
118 prefs::kDailyHttpContentLengthLastUpdateDate);
119 statistics_prefs_->InitListPref(prefs::kDailyHttpOriginalContentLength);
120 statistics_prefs_->InitListPref(prefs::kDailyHttpReceivedContentLength);
121 }
122 statistics_prefs_->SetInt64(
110 prefs::kDailyHttpContentLengthLastUpdateDate, 123 prefs::kDailyHttpContentLengthLastUpdateDate,
111 last_update_time_.ToInternalValue()); 124 last_update_time_.ToInternalValue());
112 expected_params_.reset(new TestDataReductionProxyParams( 125 expected_params_.reset(new TestDataReductionProxyParams(
113 DataReductionProxyParams::kAllowed | 126 DataReductionProxyParams::kAllowed |
114 DataReductionProxyParams::kFallbackAllowed | 127 DataReductionProxyParams::kFallbackAllowed |
115 DataReductionProxyParams::kPromoAllowed, 128 DataReductionProxyParams::kPromoAllowed,
116 TestDataReductionProxyParams::HAS_EVERYTHING & 129 TestDataReductionProxyParams::HAS_EVERYTHING &
117 ~TestDataReductionProxyParams::HAS_DEV_ORIGIN)); 130 ~TestDataReductionProxyParams::HAS_DEV_ORIGIN));
118 } 131 }
119 132
(...skipping 21 matching lines...) Expand all
141 .WillRepeatedly(Return(&pref_service_)); 154 .WillRepeatedly(Return(&pref_service_));
142 EXPECT_CALL(*settings, GetLocalStatePrefs()) 155 EXPECT_CALL(*settings, GetLocalStatePrefs())
143 .Times(AnyNumber()) 156 .Times(AnyNumber())
144 .WillRepeatedly(Return(&pref_service_)); 157 .WillRepeatedly(Return(&pref_service_));
145 EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck()).Times(0); 158 EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck()).Times(0);
146 EXPECT_CALL(*settings, GetURLFetcherForWarmup()).Times(0); 159 EXPECT_CALL(*settings, GetURLFetcherForWarmup()).Times(0);
147 EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0); 160 EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0);
148 settings_.reset(settings); 161 settings_.reset(settings);
149 configurator_.reset(new TestDataReductionProxyConfig()); 162 configurator_.reset(new TestDataReductionProxyConfig());
150 settings_->configurator_ = configurator_.get(); 163 settings_->configurator_ = configurator_.get();
164 settings_->SetDataReductionProxyStatisticsPrefs(
165 statistics_prefs_.get());
bengr 2014/08/28 21:38:35 Can this fit on the previous line?
megjablon 2014/08/30 01:10:04 Done.
151 } 166 }
152 167
153 // Explicitly generate required instantiations. 168 // Explicitly generate required instantiations.
154 template void 169 template void
155 DataReductionProxySettingsTestBase::ResetSettings<DataReductionProxySettings>( 170 DataReductionProxySettingsTestBase::ResetSettings<DataReductionProxySettings>(
156 bool allowed, 171 bool allowed,
157 bool fallback_allowed, 172 bool fallback_allowed,
158 bool alt_allowed, 173 bool alt_allowed,
159 bool promo_allowed, 174 bool promo_allowed,
160 bool holdback); 175 bool holdback);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 true, 311 true,
297 enabled_at_startup ? 1 : 0); 312 enabled_at_startup ? 1 : 0);
298 scoped_ptr<DataReductionProxyConfigurator> configurator( 313 scoped_ptr<DataReductionProxyConfigurator> configurator(
299 new TestDataReductionProxyConfig()); 314 new TestDataReductionProxyConfig());
300 settings_->SetProxyConfigurator(configurator.get()); 315 settings_->SetProxyConfigurator(configurator.get());
301 scoped_refptr<net::TestURLRequestContextGetter> request_context = 316 scoped_refptr<net::TestURLRequestContextGetter> request_context =
302 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); 317 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current());
303 318
304 settings_->InitDataReductionProxySettings( 319 settings_->InitDataReductionProxySettings(
305 &pref_service_, 320 &pref_service_,
306 &pref_service_,
307 request_context.get()); 321 request_context.get());
308 settings_->SetOnDataReductionEnabledCallback( 322 settings_->SetOnDataReductionEnabledCallback(
309 base::Bind(&DataReductionProxySettingsTestBase:: 323 base::Bind(&DataReductionProxySettingsTestBase::
310 RegisterSyntheticFieldTrialCallback, 324 RegisterSyntheticFieldTrialCallback,
311 base::Unretained(this))); 325 base::Unretained(this)));
312 326
313 base::MessageLoop::current()->RunUntilIdle(); 327 base::MessageLoop::current()->RunUntilIdle();
314 CheckProxyConfigs(enabled_at_startup, false, false); 328 CheckProxyConfigs(enabled_at_startup, false, false);
315 EXPECT_EQ(enabled_at_startup, proxy_enabled_); 329 EXPECT_EQ(enabled_at_startup, proxy_enabled_);
316 } 330 }
317 331
318 } // namespace data_reduction_proxy 332 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698