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

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: Addressed bengr comments Created 6 years, 4 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..38a395d1a79c10be2702cd01d842a268666b9934 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
@@ -6,9 +6,10 @@
#include "base/compiler_specific.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/common/data_reduction_proxy_pref_names.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -34,7 +35,12 @@ namespace data_reduction_proxy {
// Test UpdateContentLengthPrefs.
bengr 2014/08/28 21:38:35 You need a test that the metrics are committed to
megjablon 2014/08/30 01:10:04 For these tests I'll just have the pref service go
class ChromeNetworkDataSavingMetricsTest : public testing::Test {
protected:
- ChromeNetworkDataSavingMetricsTest() {}
+ ChromeNetworkDataSavingMetricsTest()
+ : statistics_prefs_(new DataReductionProxyStatisticsPrefs(
+ &pref_service_,
bengr 2014/08/28 21:38:34 Indentation is wrong.
megjablon 2014/08/30 01:10:04 Done.
+ scoped_refptr<base::TestSimpleTaskRunner>(
bengr 2014/08/28 21:38:35 #include "base/memory/ref_counted.h"
megjablon 2014/08/30 01:10:04 Done.
+ new base::TestSimpleTaskRunner()),
+ commit_delay_)) {}
virtual void SetUp() OVERRIDE {
PrefRegistrySimple* registry = pref_service_.registry();
@@ -74,9 +80,17 @@ class ChromeNetworkDataSavingMetricsTest : public testing::Test {
registry->RegisterInt64Pref(
data_reduction_proxy::prefs::
kDailyHttpContentLengthLastUpdateDate, 0L);
+ if (commit_delay_ != base::TimeDelta())
+ statistics_prefs_->Init();
}
+#if defined(OS_ANDROID) || defined(OS_IOS)
+ base::TimeDelta commit_delay_ = base::TimeDelta();
+#else
+ base::TimeDelta commit_delay_ = base::TimeDelta::FromMinutes(60);
+#endif
TestingPrefServiceSimple pref_service_;
+ DataReductionProxyStatisticsPrefs* statistics_prefs_;
};
TEST_F(ChromeNetworkDataSavingMetricsTest, TotalLengths) {
@@ -85,23 +99,23 @@ TEST_F(ChromeNetworkDataSavingMetricsTest, TotalLengths) {
UpdateContentLengthPrefs(
kReceivedLength, kOriginalLength,
- false, UNKNOWN_TYPE, &pref_service_);
+ false, UNKNOWN_TYPE, statistics_prefs_);
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_);
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 +156,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 +168,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 +286,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, OneResponse) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_);
VerifyDailyDataSavingContentLengthPrefLists(
original, 1, received, 1,
original, 1, received, 1,
@@ -287,7 +301,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, MultipleResponses) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
false, UNKNOWN_TYPE,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_);
VerifyDailyDataSavingContentLengthPrefLists(
original, 1, received, 1,
NULL, 0, NULL, 0, NULL, 0, NULL, 0);
@@ -295,7 +309,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, MultipleResponses) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, UNKNOWN_TYPE,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_);
original[0] += kOriginalLength;
received[0] += kReceivedLength;
int64 original_proxy_enabled[] = {kOriginalLength};
@@ -308,7 +322,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, MultipleResponses) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_);
original[0] += kOriginalLength;
received[0] += kReceivedLength;
original_proxy_enabled[0] += kOriginalLength;
@@ -322,7 +336,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, MultipleResponses) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
- true, UNKNOWN_TYPE, FakeNow(), &pref_service_);
+ true, UNKNOWN_TYPE, FakeNow(), statistics_prefs_);
original[0] += kOriginalLength;
received[0] += kReceivedLength;
original_proxy_enabled[0] += kOriginalLength;
@@ -334,7 +348,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, MultipleResponses) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
- false, UNKNOWN_TYPE, FakeNow(), &pref_service_);
+ false, UNKNOWN_TYPE, FakeNow(), statistics_prefs_);
original[0] += kOriginalLength;
received[0] += kReceivedLength;
VerifyDailyDataSavingContentLengthPrefLists(
@@ -353,7 +367,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, RequestType) {
UpdateContentLengthPrefsForDataReductionProxy(
kContentLength, kContentLength,
true, HTTPS,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_);
total_received[0] += kContentLength;
proxy_enabled_received[0] += kContentLength;
https_received[0] += kContentLength;
@@ -369,7 +383,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, RequestType) {
UpdateContentLengthPrefsForDataReductionProxy(
kContentLength, kContentLength,
false, HTTPS,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_);
total_received[0] += kContentLength;
VerifyDailyRequestTypeContentLengthPrefLists(
total_received, 1, total_received, 1,
@@ -382,7 +396,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, RequestType) {
UpdateContentLengthPrefsForDataReductionProxy(
kContentLength, kContentLength,
true, HTTPS,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_);
total_received[0] += kContentLength;
proxy_enabled_received[0] += kContentLength;
https_received[0] += kContentLength;
@@ -397,7 +411,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, RequestType) {
UpdateContentLengthPrefsForDataReductionProxy(
kContentLength, kContentLength,
true, SHORT_BYPASS,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_);
total_received[0] += kContentLength;
proxy_enabled_received[0] += kContentLength;
received[0] += kContentLength;
@@ -412,7 +426,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, RequestType) {
UpdateContentLengthPrefsForDataReductionProxy(
kContentLength, kContentLength,
true, LONG_BYPASS,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_);
total_received[0] += kContentLength;
proxy_enabled_received[0] += kContentLength;
VerifyDailyRequestTypeContentLengthPrefLists(
@@ -426,7 +440,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, RequestType) {
UpdateContentLengthPrefsForDataReductionProxy(
kContentLength, kContentLength,
true, UNKNOWN_TYPE,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_);
total_received[0] += kContentLength;
proxy_enabled_received[0] += kContentLength;
VerifyDailyRequestTypeContentLengthPrefLists(
@@ -445,7 +459,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, ForwardOneDay) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_);
// Forward one day.
SetFakeTimeDeltaInHours(24);
@@ -453,7 +467,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_);
int64 original[] = {kOriginalLength, kOriginalLength};
int64 received[] = {kReceivedLength, kReceivedLength};
@@ -472,7 +486,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_);
original[1] += kOriginalLength;
received[1] += kReceivedLength;
original_with_data_reduction_proxy_enabled[1] += kOriginalLength;
@@ -489,7 +503,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, ForwardOneDay) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_);
original[1] += kOriginalLength;
received[1] += kReceivedLength;
original_with_data_reduction_proxy_enabled[1] += kOriginalLength;
@@ -514,7 +528,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, PartialDayTimeChange) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_);
VerifyDailyDataSavingContentLengthPrefLists(
original, 2, received, 2,
original, 2, received, 2,
@@ -526,7 +540,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, PartialDayTimeChange) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_);
original[1] += kOriginalLength;
received[1] += kReceivedLength;
VerifyDailyDataSavingContentLengthPrefLists(
@@ -539,7 +553,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, PartialDayTimeChange) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_);
int64 original2[] = {kOriginalLength * 2, kOriginalLength};
int64 received2[] = {kReceivedLength * 2, kReceivedLength};
VerifyDailyDataSavingContentLengthPrefLists(
@@ -554,7 +568,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, ForwardMultipleDays) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_);
// Forward three days.
SetFakeTimeDeltaInHours(3 * 24);
@@ -562,7 +576,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, ForwardMultipleDays) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_);
int64 original[] = {kOriginalLength, 0, 0, kOriginalLength};
int64 received[] = {kReceivedLength, 0, 0, kReceivedLength};
@@ -576,7 +590,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, ForwardMultipleDays) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_);
int64 original2[] = {
kOriginalLength, 0, 0, kOriginalLength, 0, 0, 0, kOriginalLength,
};
@@ -593,7 +607,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, ForwardMultipleDays) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_);
int64 original3[] = {kOriginalLength};
int64 received3[] = {kReceivedLength};
VerifyDailyDataSavingContentLengthPrefLists(
@@ -606,7 +620,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, ForwardMultipleDays) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_);
VerifyDailyDataSavingContentLengthPrefLists(
original3, 1, received3, 1,
original3, 1, received3, 1,
@@ -622,14 +636,14 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, BackwardAndForwardOneDay) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_);
// Backward one day.
SetFakeTimeDeltaInHours(-24);
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_);
original[0] += kOriginalLength;
received[0] += kReceivedLength;
VerifyDailyDataSavingContentLengthPrefLists(
@@ -642,7 +656,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, BackwardAndForwardOneDay) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_);
int64 original2[] = {kOriginalLength * 2, kOriginalLength};
int64 received2[] = {kReceivedLength * 2, kReceivedLength};
VerifyDailyDataSavingContentLengthPrefLists(
@@ -660,13 +674,13 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest, BackwardTwoDays) {
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_);
// Backward two days.
SetFakeTimeDeltaInHours(-2 * 24);
UpdateContentLengthPrefsForDataReductionProxy(
kReceivedLength, kOriginalLength,
true, VIA_DATA_REDUCTION_PROXY,
- FakeNow(), &pref_service_);
+ FakeNow(), statistics_prefs_);
VerifyDailyDataSavingContentLengthPrefLists(
original, 1, received, 1,
original, 1, received, 1,

Powered by Google App Engine
This is Rietveld 408576698