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

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: Undo BUILD.gn and fix aw_browser_context 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..7c89c998284e67922d73cf32fd756bc99cd2dc3a 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.
class ChromeNetworkDataSavingMetricsTest : public testing::Test {
protected:
- ChromeNetworkDataSavingMetricsTest() {}
+ ChromeNetworkDataSavingMetricsTest()
+ : statistics_prefs_(new DataReductionProxyStatisticsPrefs(
+ &pref_service_,
+ scoped_refptr<base::TestSimpleTaskRunner>(
+ new base::TestSimpleTaskRunner()),
+ base::TimeDelta())) {}
virtual void SetUp() OVERRIDE {
PrefRegistrySimple* registry = pref_service_.registry();
@@ -77,6 +83,7 @@ class ChromeNetworkDataSavingMetricsTest : public testing::Test {
}
TestingPrefServiceSimple pref_service_;
+ DataReductionProxyStatisticsPrefs* statistics_prefs_;
};
TEST_F(ChromeNetworkDataSavingMetricsTest, TotalLengths) {
@@ -85,23 +92,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 +149,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 +161,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 +279,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 +294,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 +302,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 +315,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 +329,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 +341,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 +360,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 +376,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 +389,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 +404,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 +419,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 +433,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 +452,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 +460,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 +479,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 +496,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 +521,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 +533,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 +546,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 +561,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 +569,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 +583,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 +600,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 +613,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 +629,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 +649,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 +667,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