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

Unified Diff: components/data_reduction_proxy/browser/data_reduction_proxy_metrics_unittest.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 nits 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 side-by-side diff with in-line comments
Download patch
Index: components/data_reduction_proxy/browser/data_reduction_proxy_metrics_unittest.cc
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_metrics_unittest.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_metrics_unittest.cc
index f1139776adbb3ec45f7c89c6a2cad632b9a4ffe4..0d24766d39c9b6322699b7b0693f2b4881a9b8fb 100644
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_metrics_unittest.cc
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_metrics_unittest.cc
@@ -4,12 +4,16 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
#include "base/prefs/pref_registry_simple.h"
#include "base/prefs/pref_service.h"
-#include "base/prefs/scoped_user_pref_update.h"
#include "base/prefs/testing_pref_service.h"
#include "base/strings/string_number_conversions.h"
+#include "base/test/test_simple_task_runner.h"
+#include "base/time/time.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_metrics.h"
+#include "components/data_reduction_proxy/browser/data_reduction_proxy_statistics_prefs.h"
#include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -37,6 +41,11 @@ class ChromeNetworkDataSavingMetricsTest : public testing::Test {
ChromeNetworkDataSavingMetricsTest() {}
virtual void SetUp() OVERRIDE {
+ statistics_prefs_.reset(new DataReductionProxyStatisticsPrefs(
+ &pref_service_,
+ scoped_refptr<base::TestSimpleTaskRunner>(
+ new base::TestSimpleTaskRunner()),
+ base::TimeDelta()));
PrefRegistrySimple* registry = pref_service_.registry();
registry->RegisterInt64Pref(
data_reduction_proxy::prefs::kHttpReceivedContentLength, 0);
@@ -77,6 +86,7 @@ class ChromeNetworkDataSavingMetricsTest : public testing::Test {
}
TestingPrefServiceSimple pref_service_;
+ scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs_;
};
TEST_F(ChromeNetworkDataSavingMetricsTest, TotalLengths) {
@@ -85,23 +95,23 @@ TEST_F(ChromeNetworkDataSavingMetricsTest, TotalLengths) {
UpdateContentLengthPrefs(
kReceivedLength, kOriginalLength,
- false, UNKNOWN_TYPE, &pref_service_);
+ false, UNKNOWN_TYPE, statistics_prefs_.get());
EXPECT_EQ(kReceivedLength,
- pref_service_.GetInt64(
+ statistics_prefs_->GetInt64(
data_reduction_proxy::prefs::kHttpReceivedContentLength));
EXPECT_EQ(kOriginalLength,
- pref_service_.GetInt64(
+ statistics_prefs_->GetInt64(
data_reduction_proxy::prefs::kHttpOriginalContentLength));
- // Record the same numbers again, and total lengths should be dobuled.
+ // Record the same numbers again, and total lengths should be doubled.
UpdateContentLengthPrefs(
kReceivedLength, kOriginalLength,
- false, UNKNOWN_TYPE, &pref_service_);
+ false, UNKNOWN_TYPE, statistics_prefs_.get());
EXPECT_EQ(kReceivedLength * 2,
- pref_service_.GetInt64(
+ statistics_prefs_->GetInt64(
data_reduction_proxy::prefs::kHttpReceivedContentLength));
EXPECT_EQ(kOriginalLength * 2,
- pref_service_.GetInt64(
+ statistics_prefs_->GetInt64(
data_reduction_proxy::prefs::kHttpOriginalContentLength));
}
@@ -142,7 +152,7 @@ class ChromeNetworkDailyDataSavingMetricsTest
// Create daily pref list of |kNumDaysInHistory| zero values.
void CreatePrefList(const char* pref) {
- ListPrefUpdate update(&pref_service_, pref);
+ base::ListValue* update = statistics_prefs_->GetList(pref);
update->Clear();
for (size_t i = 0; i < kNumDaysInHistory; ++i) {
update->Insert(0, new base::StringValue(base::Int64ToString(0)));
@@ -154,7 +164,7 @@ class ChromeNetworkDailyDataSavingMetricsTest
// at the beginning.
void VerifyPrefList(const char* pref, const int64* values, size_t count) {
ASSERT_GE(kNumDaysInHistory, count);
- ListPrefUpdate update(&pref_service_, pref);
+ base::ListValue* update = statistics_prefs_->GetList(pref);
ASSERT_EQ(kNumDaysInHistory, update->GetSize()) << "Pref: " << pref;
for (size_t i = 0; i < count; ++i) {
@@ -272,7 +282,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, OneResponse) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_.get());
VerifyDailyDataSavingContentLengthPrefLists(
original, 1, received, 1,
original, 1, received, 1,
@@ -287,7 +297,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, MultipleResponses) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
false, UNKNOWN_TYPE,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_.get());
VerifyDailyDataSavingContentLengthPrefLists(
original, 1, received, 1,
NULL, 0, NULL, 0, NULL, 0, NULL, 0);
@@ -295,7 +305,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, MultipleResponses) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, UNKNOWN_TYPE,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_.get());
original[0] += kOriginalLength;
received[0] += kReceivedLength;
int64 original_proxy_enabled[] = {kOriginalLength};
@@ -308,7 +318,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, MultipleResponses) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_.get());
original[0] += kOriginalLength;
received[0] += kReceivedLength;
original_proxy_enabled[0] += kOriginalLength;
@@ -322,7 +332,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, MultipleResponses) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
- true, UNKNOWN_TYPE, FakeNow(), &pref_service_);
+ true, UNKNOWN_TYPE, FakeNow(), statistics_prefs_.get());
original[0] += kOriginalLength;
received[0] += kReceivedLength;
original_proxy_enabled[0] += kOriginalLength;
@@ -334,7 +344,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, MultipleResponses) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
- false, UNKNOWN_TYPE, FakeNow(), &pref_service_);
+ false, UNKNOWN_TYPE, FakeNow(), statistics_prefs_.get());
original[0] += kOriginalLength;
received[0] += kReceivedLength;
VerifyDailyDataSavingContentLengthPrefLists(
@@ -353,7 +363,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, RequestType) {
UpdateContentLengthPrefsForDataReductionProxy(
kContentLength, kContentLength,
true, HTTPS,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_.get());
total_received[0] += kContentLength;
proxy_enabled_received[0] += kContentLength;
https_received[0] += kContentLength;
@@ -369,7 +379,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, RequestType) {
UpdateContentLengthPrefsForDataReductionProxy(
kContentLength, kContentLength,
false, HTTPS,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_.get());
total_received[0] += kContentLength;
VerifyDailyRequestTypeContentLengthPrefLists(
total_received, 1, total_received, 1,
@@ -382,7 +392,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, RequestType) {
UpdateContentLengthPrefsForDataReductionProxy(
kContentLength, kContentLength,
true, HTTPS,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_.get());
total_received[0] += kContentLength;
proxy_enabled_received[0] += kContentLength;
https_received[0] += kContentLength;
@@ -397,7 +407,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, RequestType) {
UpdateContentLengthPrefsForDataReductionProxy(
kContentLength, kContentLength,
true, SHORT_BYPASS,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_.get());
total_received[0] += kContentLength;
proxy_enabled_received[0] += kContentLength;
received[0] += kContentLength;
@@ -412,7 +422,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, RequestType) {
UpdateContentLengthPrefsForDataReductionProxy(
kContentLength, kContentLength,
true, LONG_BYPASS,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_.get());
total_received[0] += kContentLength;
proxy_enabled_received[0] += kContentLength;
VerifyDailyRequestTypeContentLengthPrefLists(
@@ -426,7 +436,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, RequestType) {
UpdateContentLengthPrefsForDataReductionProxy(
kContentLength, kContentLength,
true, UNKNOWN_TYPE,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_.get());
total_received[0] += kContentLength;
proxy_enabled_received[0] += kContentLength;
VerifyDailyRequestTypeContentLengthPrefLists(
@@ -445,7 +455,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, ForwardOneDay) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_.get());
// Forward one day.
SetFakeTimeDeltaInHours(24);
@@ -453,7 +463,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, ForwardOneDay) {
// Proxy not enabled. Not via proxy.
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
- false, UNKNOWN_TYPE, FakeNow(), &pref_service_);
+ false, UNKNOWN_TYPE, FakeNow(), statistics_prefs_.get());
int64 original[] = {kOriginalLength, kOriginalLength};
int64 received[] = {kReceivedLength, kReceivedLength};
@@ -472,7 +482,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, ForwardOneDay) {
// Proxy enabled. Not via proxy.
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
- true, UNKNOWN_TYPE, FakeNow(), &pref_service_);
+ true, UNKNOWN_TYPE, FakeNow(), statistics_prefs_.get());
original[1] += kOriginalLength;
received[1] += kReceivedLength;
original_with_data_reduction_proxy_enabled[1] += kOriginalLength;
@@ -489,7 +499,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, ForwardOneDay) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_.get());
original[1] += kOriginalLength;
received[1] += kReceivedLength;
original_with_data_reduction_proxy_enabled[1] += kOriginalLength;
@@ -514,7 +524,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, PartialDayTimeChange) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_.get());
VerifyDailyDataSavingContentLengthPrefLists(
original, 2, received, 2,
original, 2, received, 2,
@@ -526,7 +536,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, PartialDayTimeChange) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_.get());
original[1] += kOriginalLength;
received[1] += kReceivedLength;
VerifyDailyDataSavingContentLengthPrefLists(
@@ -539,7 +549,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, PartialDayTimeChange) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_.get());
int64 original2[] = {kOriginalLength * 2, kOriginalLength};
int64 received2[] = {kReceivedLength * 2, kReceivedLength};
VerifyDailyDataSavingContentLengthPrefLists(
@@ -554,7 +564,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, ForwardMultipleDays) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_.get());
// Forward three days.
SetFakeTimeDeltaInHours(3 * 24);
@@ -562,7 +572,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, ForwardMultipleDays) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_.get());
int64 original[] = {kOriginalLength, 0, 0, kOriginalLength};
int64 received[] = {kReceivedLength, 0, 0, kReceivedLength};
@@ -576,7 +586,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, ForwardMultipleDays) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_.get());
int64 original2[] = {
kOriginalLength, 0, 0, kOriginalLength, 0, 0, 0, kOriginalLength,
};
@@ -593,7 +603,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, ForwardMultipleDays) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_.get());
int64 original3[] = {kOriginalLength};
int64 received3[] = {kReceivedLength};
VerifyDailyDataSavingContentLengthPrefLists(
@@ -606,7 +616,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, ForwardMultipleDays) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_.get());
VerifyDailyDataSavingContentLengthPrefLists(
original3, 1, received3, 1,
original3, 1, received3, 1,
@@ -622,14 +632,14 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, BackwardAndForwardOneDay) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_.get());
// Backward one day.
SetFakeTimeDeltaInHours(-24);
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_.get());
original[0] += kOriginalLength;
received[0] += kReceivedLength;
VerifyDailyDataSavingContentLengthPrefLists(
@@ -642,7 +652,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, BackwardAndForwardOneDay) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_.get());
int64 original2[] = {kOriginalLength * 2, kOriginalLength};
int64 received2[] = {kReceivedLength * 2, kReceivedLength};
VerifyDailyDataSavingContentLengthPrefLists(
@@ -660,13 +670,13 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, BackwardTwoDays) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_.get());
// Backward two days.
SetFakeTimeDeltaInHours(-2 * 24);
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_.get());
VerifyDailyDataSavingContentLengthPrefLists(
original, 1, received, 1,
original, 1, received, 1,

Powered by Google App Engine
This is Rietveld 408576698