Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
| 7 #include "base/prefs/pref_registry_simple.h" | 7 #include "base/prefs/pref_registry_simple.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/prefs/scoped_user_pref_update.h" | |
| 10 #include "base/prefs/testing_pref_service.h" | 9 #include "base/prefs/testing_pref_service.h" |
| 11 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/test/test_simple_task_runner.h" | |
| 12 #include "base/time/time.h" | |
| 12 #include "components/data_reduction_proxy/browser/data_reduction_proxy_metrics.h " | 13 #include "components/data_reduction_proxy/browser/data_reduction_proxy_metrics.h " |
| 13 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names .h" | 14 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names .h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 const size_t kNumDaysInHistory = 60; | 19 const size_t kNumDaysInHistory = 60; |
| 19 | 20 |
| 20 int64 GetListPrefInt64Value( | 21 int64 GetListPrefInt64Value( |
| 21 const base::ListValue& list_update, size_t index) { | 22 const base::ListValue& list_update, size_t index) { |
| 22 std::string string_value; | 23 std::string string_value; |
| 23 EXPECT_TRUE(list_update.GetString(index, &string_value)); | 24 EXPECT_TRUE(list_update.GetString(index, &string_value)); |
| 24 | 25 |
| 25 int64 value = 0; | 26 int64 value = 0; |
| 26 EXPECT_TRUE(base::StringToInt64(string_value, &value)); | 27 EXPECT_TRUE(base::StringToInt64(string_value, &value)); |
| 27 return value; | 28 return value; |
| 28 } | 29 } |
| 29 | 30 |
| 30 } // namespace | 31 } // namespace |
| 31 | 32 |
| 32 namespace data_reduction_proxy { | 33 namespace data_reduction_proxy { |
| 33 | 34 |
| 34 // Test UpdateContentLengthPrefs. | 35 // 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
| |
| 35 class ChromeNetworkDataSavingMetricsTest : public testing::Test { | 36 class ChromeNetworkDataSavingMetricsTest : public testing::Test { |
| 36 protected: | 37 protected: |
| 37 ChromeNetworkDataSavingMetricsTest() {} | 38 ChromeNetworkDataSavingMetricsTest() |
| 39 : statistics_prefs_(new DataReductionProxyStatisticsPrefs( | |
| 40 &pref_service_, | |
|
bengr
2014/08/28 21:38:34
Indentation is wrong.
megjablon
2014/08/30 01:10:04
Done.
| |
| 41 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.
| |
| 42 new base::TestSimpleTaskRunner()), | |
| 43 commit_delay_)) {} | |
| 38 | 44 |
| 39 virtual void SetUp() OVERRIDE { | 45 virtual void SetUp() OVERRIDE { |
| 40 PrefRegistrySimple* registry = pref_service_.registry(); | 46 PrefRegistrySimple* registry = pref_service_.registry(); |
| 41 registry->RegisterInt64Pref( | 47 registry->RegisterInt64Pref( |
| 42 data_reduction_proxy::prefs::kHttpReceivedContentLength, 0); | 48 data_reduction_proxy::prefs::kHttpReceivedContentLength, 0); |
| 43 registry->RegisterInt64Pref( | 49 registry->RegisterInt64Pref( |
| 44 data_reduction_proxy::prefs::kHttpOriginalContentLength, 0); | 50 data_reduction_proxy::prefs::kHttpOriginalContentLength, 0); |
| 45 | 51 |
| 46 registry->RegisterListPref(data_reduction_proxy::prefs:: | 52 registry->RegisterListPref(data_reduction_proxy::prefs:: |
| 47 kDailyHttpOriginalContentLength); | 53 kDailyHttpOriginalContentLength); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 67 kDailyContentLengthUnknownWithDataReductionProxyEnabled); | 73 kDailyContentLengthUnknownWithDataReductionProxyEnabled); |
| 68 registry->RegisterListPref( | 74 registry->RegisterListPref( |
| 69 data_reduction_proxy::prefs:: | 75 data_reduction_proxy::prefs:: |
| 70 kDailyOriginalContentLengthViaDataReductionProxy); | 76 kDailyOriginalContentLengthViaDataReductionProxy); |
| 71 registry->RegisterListPref( | 77 registry->RegisterListPref( |
| 72 data_reduction_proxy::prefs:: | 78 data_reduction_proxy::prefs:: |
| 73 kDailyContentLengthViaDataReductionProxy); | 79 kDailyContentLengthViaDataReductionProxy); |
| 74 registry->RegisterInt64Pref( | 80 registry->RegisterInt64Pref( |
| 75 data_reduction_proxy::prefs:: | 81 data_reduction_proxy::prefs:: |
| 76 kDailyHttpContentLengthLastUpdateDate, 0L); | 82 kDailyHttpContentLengthLastUpdateDate, 0L); |
| 83 if (commit_delay_ != base::TimeDelta()) | |
| 84 statistics_prefs_->Init(); | |
| 77 } | 85 } |
| 78 | 86 |
| 87 #if defined(OS_ANDROID) || defined(OS_IOS) | |
| 88 base::TimeDelta commit_delay_ = base::TimeDelta(); | |
| 89 #else | |
| 90 base::TimeDelta commit_delay_ = base::TimeDelta::FromMinutes(60); | |
| 91 #endif | |
| 79 TestingPrefServiceSimple pref_service_; | 92 TestingPrefServiceSimple pref_service_; |
| 93 DataReductionProxyStatisticsPrefs* statistics_prefs_; | |
| 80 }; | 94 }; |
| 81 | 95 |
| 82 TEST_F(ChromeNetworkDataSavingMetricsTest, TotalLengths) { | 96 TEST_F(ChromeNetworkDataSavingMetricsTest, TotalLengths) { |
| 83 const int64 kOriginalLength = 200; | 97 const int64 kOriginalLength = 200; |
| 84 const int64 kReceivedLength = 100; | 98 const int64 kReceivedLength = 100; |
| 85 | 99 |
| 86 UpdateContentLengthPrefs( | 100 UpdateContentLengthPrefs( |
| 87 kReceivedLength, kOriginalLength, | 101 kReceivedLength, kOriginalLength, |
| 88 false, UNKNOWN_TYPE, &pref_service_); | 102 false, UNKNOWN_TYPE, statistics_prefs_); |
| 89 EXPECT_EQ(kReceivedLength, | 103 EXPECT_EQ(kReceivedLength, |
| 90 pref_service_.GetInt64( | 104 statistics_prefs_->GetInt64( |
| 91 data_reduction_proxy::prefs::kHttpReceivedContentLength)); | 105 data_reduction_proxy::prefs::kHttpReceivedContentLength)); |
| 92 EXPECT_EQ(kOriginalLength, | 106 EXPECT_EQ(kOriginalLength, |
| 93 pref_service_.GetInt64( | 107 statistics_prefs_->GetInt64( |
| 94 data_reduction_proxy::prefs::kHttpOriginalContentLength)); | 108 data_reduction_proxy::prefs::kHttpOriginalContentLength)); |
| 95 | 109 |
| 96 // Record the same numbers again, and total lengths should be dobuled. | 110 // Record the same numbers again, and total lengths should be doubled. |
| 97 UpdateContentLengthPrefs( | 111 UpdateContentLengthPrefs( |
| 98 kReceivedLength, kOriginalLength, | 112 kReceivedLength, kOriginalLength, |
| 99 false, UNKNOWN_TYPE, &pref_service_); | 113 false, UNKNOWN_TYPE, statistics_prefs_); |
| 100 EXPECT_EQ(kReceivedLength * 2, | 114 EXPECT_EQ(kReceivedLength * 2, |
| 101 pref_service_.GetInt64( | 115 statistics_prefs_->GetInt64( |
| 102 data_reduction_proxy::prefs::kHttpReceivedContentLength)); | 116 data_reduction_proxy::prefs::kHttpReceivedContentLength)); |
| 103 EXPECT_EQ(kOriginalLength * 2, | 117 EXPECT_EQ(kOriginalLength * 2, |
| 104 pref_service_.GetInt64( | 118 statistics_prefs_->GetInt64( |
| 105 data_reduction_proxy::prefs::kHttpOriginalContentLength)); | 119 data_reduction_proxy::prefs::kHttpOriginalContentLength)); |
| 106 } | 120 } |
| 107 | 121 |
| 108 // The initial last update time used in test. There is no leap second a few | 122 // The initial last update time used in test. There is no leap second a few |
| 109 // days around this time used in the test. | 123 // days around this time used in the test. |
| 110 // Note: No time zone is specified. Local time will be assumed by | 124 // Note: No time zone is specified. Local time will be assumed by |
| 111 // base::Time::FromString below. | 125 // base::Time::FromString below. |
| 112 const char kLastUpdateTime[] = "Wed, 18 Sep 2013 03:45:26"; | 126 const char kLastUpdateTime[] = "Wed, 18 Sep 2013 03:45:26"; |
| 113 | 127 |
| 114 class ChromeNetworkDailyDataSavingMetricsTest | 128 class ChromeNetworkDailyDataSavingMetricsTest |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 135 void SetFakeTimeDeltaInHours(int hours) { | 149 void SetFakeTimeDeltaInHours(int hours) { |
| 136 now_delta_ = base::TimeDelta::FromHours(hours); | 150 now_delta_ = base::TimeDelta::FromHours(hours); |
| 137 } | 151 } |
| 138 | 152 |
| 139 void AddFakeTimeDeltaInHours(int hours) { | 153 void AddFakeTimeDeltaInHours(int hours) { |
| 140 now_delta_ += base::TimeDelta::FromHours(hours); | 154 now_delta_ += base::TimeDelta::FromHours(hours); |
| 141 } | 155 } |
| 142 | 156 |
| 143 // Create daily pref list of |kNumDaysInHistory| zero values. | 157 // Create daily pref list of |kNumDaysInHistory| zero values. |
| 144 void CreatePrefList(const char* pref) { | 158 void CreatePrefList(const char* pref) { |
| 145 ListPrefUpdate update(&pref_service_, pref); | 159 base::ListValue* update = statistics_prefs_->GetList(pref); |
| 146 update->Clear(); | 160 update->Clear(); |
| 147 for (size_t i = 0; i < kNumDaysInHistory; ++i) { | 161 for (size_t i = 0; i < kNumDaysInHistory; ++i) { |
| 148 update->Insert(0, new base::StringValue(base::Int64ToString(0))); | 162 update->Insert(0, new base::StringValue(base::Int64ToString(0))); |
| 149 } | 163 } |
| 150 } | 164 } |
| 151 | 165 |
| 152 // Verify the pref list values are equal to the given values. | 166 // Verify the pref list values are equal to the given values. |
| 153 // If the count of values is less than kNumDaysInHistory, zeros are assumed | 167 // If the count of values is less than kNumDaysInHistory, zeros are assumed |
| 154 // at the beginning. | 168 // at the beginning. |
| 155 void VerifyPrefList(const char* pref, const int64* values, size_t count) { | 169 void VerifyPrefList(const char* pref, const int64* values, size_t count) { |
| 156 ASSERT_GE(kNumDaysInHistory, count); | 170 ASSERT_GE(kNumDaysInHistory, count); |
| 157 ListPrefUpdate update(&pref_service_, pref); | 171 base::ListValue* update = statistics_prefs_->GetList(pref); |
| 158 ASSERT_EQ(kNumDaysInHistory, update->GetSize()) << "Pref: " << pref; | 172 ASSERT_EQ(kNumDaysInHistory, update->GetSize()) << "Pref: " << pref; |
| 159 | 173 |
| 160 for (size_t i = 0; i < count; ++i) { | 174 for (size_t i = 0; i < count; ++i) { |
| 161 EXPECT_EQ( | 175 EXPECT_EQ( |
| 162 values[i], | 176 values[i], |
| 163 GetListPrefInt64Value(*update, kNumDaysInHistory - count + i)) | 177 GetListPrefInt64Value(*update, kNumDaysInHistory - count + i)) |
| 164 << "index=" << (kNumDaysInHistory - count + i); | 178 << "index=" << (kNumDaysInHistory - count + i); |
| 165 } | 179 } |
| 166 for (size_t i = 0; i < kNumDaysInHistory - count; ++i) { | 180 for (size_t i = 0; i < kNumDaysInHistory - count; ++i) { |
| 167 EXPECT_EQ(0, GetListPrefInt64Value(*update, i)) << "index=" << i; | 181 EXPECT_EQ(0, GetListPrefInt64Value(*update, i)) << "index=" << i; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 | 279 |
| 266 TEST_F(ChromeNetworkDailyDataSavingMetricsTest, OneResponse) { | 280 TEST_F(ChromeNetworkDailyDataSavingMetricsTest, OneResponse) { |
| 267 const int64 kOriginalLength = 200; | 281 const int64 kOriginalLength = 200; |
| 268 const int64 kReceivedLength = 100; | 282 const int64 kReceivedLength = 100; |
| 269 int64 original[] = {kOriginalLength}; | 283 int64 original[] = {kOriginalLength}; |
| 270 int64 received[] = {kReceivedLength}; | 284 int64 received[] = {kReceivedLength}; |
| 271 | 285 |
| 272 UpdateContentLengthPrefsForDataReductionProxy( | 286 UpdateContentLengthPrefsForDataReductionProxy( |
| 273 kReceivedLength, kOriginalLength, | 287 kReceivedLength, kOriginalLength, |
| 274 true, VIA_DATA_REDUCTION_PROXY, | 288 true, VIA_DATA_REDUCTION_PROXY, |
| 275 FakeNow(), &pref_service_); | 289 FakeNow(), statistics_prefs_); |
| 276 VerifyDailyDataSavingContentLengthPrefLists( | 290 VerifyDailyDataSavingContentLengthPrefLists( |
| 277 original, 1, received, 1, | 291 original, 1, received, 1, |
| 278 original, 1, received, 1, | 292 original, 1, received, 1, |
| 279 original, 1, received, 1); | 293 original, 1, received, 1); |
| 280 } | 294 } |
| 281 | 295 |
| 282 TEST_F(ChromeNetworkDailyDataSavingMetricsTest, MultipleResponses) { | 296 TEST_F(ChromeNetworkDailyDataSavingMetricsTest, MultipleResponses) { |
| 283 const int64 kOriginalLength = 150; | 297 const int64 kOriginalLength = 150; |
| 284 const int64 kReceivedLength = 100; | 298 const int64 kReceivedLength = 100; |
| 285 int64 original[] = {kOriginalLength}; | 299 int64 original[] = {kOriginalLength}; |
| 286 int64 received[] = {kReceivedLength}; | 300 int64 received[] = {kReceivedLength}; |
| 287 UpdateContentLengthPrefsForDataReductionProxy( | 301 UpdateContentLengthPrefsForDataReductionProxy( |
| 288 kReceivedLength, kOriginalLength, | 302 kReceivedLength, kOriginalLength, |
| 289 false, UNKNOWN_TYPE, | 303 false, UNKNOWN_TYPE, |
| 290 FakeNow(), &pref_service_); | 304 FakeNow(), statistics_prefs_); |
| 291 VerifyDailyDataSavingContentLengthPrefLists( | 305 VerifyDailyDataSavingContentLengthPrefLists( |
| 292 original, 1, received, 1, | 306 original, 1, received, 1, |
| 293 NULL, 0, NULL, 0, NULL, 0, NULL, 0); | 307 NULL, 0, NULL, 0, NULL, 0, NULL, 0); |
| 294 | 308 |
| 295 UpdateContentLengthPrefsForDataReductionProxy( | 309 UpdateContentLengthPrefsForDataReductionProxy( |
| 296 kReceivedLength, kOriginalLength, | 310 kReceivedLength, kOriginalLength, |
| 297 true, UNKNOWN_TYPE, | 311 true, UNKNOWN_TYPE, |
| 298 FakeNow(), &pref_service_); | 312 FakeNow(), statistics_prefs_); |
| 299 original[0] += kOriginalLength; | 313 original[0] += kOriginalLength; |
| 300 received[0] += kReceivedLength; | 314 received[0] += kReceivedLength; |
| 301 int64 original_proxy_enabled[] = {kOriginalLength}; | 315 int64 original_proxy_enabled[] = {kOriginalLength}; |
| 302 int64 received_proxy_enabled[] = {kReceivedLength}; | 316 int64 received_proxy_enabled[] = {kReceivedLength}; |
| 303 VerifyDailyDataSavingContentLengthPrefLists( | 317 VerifyDailyDataSavingContentLengthPrefLists( |
| 304 original, 1, received, 1, | 318 original, 1, received, 1, |
| 305 original_proxy_enabled, 1, received_proxy_enabled, 1, | 319 original_proxy_enabled, 1, received_proxy_enabled, 1, |
| 306 NULL, 0, NULL, 0); | 320 NULL, 0, NULL, 0); |
| 307 | 321 |
| 308 UpdateContentLengthPrefsForDataReductionProxy( | 322 UpdateContentLengthPrefsForDataReductionProxy( |
| 309 kReceivedLength, kOriginalLength, | 323 kReceivedLength, kOriginalLength, |
| 310 true, VIA_DATA_REDUCTION_PROXY, | 324 true, VIA_DATA_REDUCTION_PROXY, |
| 311 FakeNow(), &pref_service_); | 325 FakeNow(), statistics_prefs_); |
| 312 original[0] += kOriginalLength; | 326 original[0] += kOriginalLength; |
| 313 received[0] += kReceivedLength; | 327 received[0] += kReceivedLength; |
| 314 original_proxy_enabled[0] += kOriginalLength; | 328 original_proxy_enabled[0] += kOriginalLength; |
| 315 received_proxy_enabled[0] += kReceivedLength; | 329 received_proxy_enabled[0] += kReceivedLength; |
| 316 int64 original_via_proxy[] = {kOriginalLength}; | 330 int64 original_via_proxy[] = {kOriginalLength}; |
| 317 int64 received_via_proxy[] = {kReceivedLength}; | 331 int64 received_via_proxy[] = {kReceivedLength}; |
| 318 VerifyDailyDataSavingContentLengthPrefLists( | 332 VerifyDailyDataSavingContentLengthPrefLists( |
| 319 original, 1, received, 1, | 333 original, 1, received, 1, |
| 320 original_proxy_enabled, 1, received_proxy_enabled, 1, | 334 original_proxy_enabled, 1, received_proxy_enabled, 1, |
| 321 original_via_proxy, 1, received_via_proxy, 1); | 335 original_via_proxy, 1, received_via_proxy, 1); |
| 322 | 336 |
| 323 UpdateContentLengthPrefsForDataReductionProxy( | 337 UpdateContentLengthPrefsForDataReductionProxy( |
| 324 kReceivedLength, kOriginalLength, | 338 kReceivedLength, kOriginalLength, |
| 325 true, UNKNOWN_TYPE, FakeNow(), &pref_service_); | 339 true, UNKNOWN_TYPE, FakeNow(), statistics_prefs_); |
| 326 original[0] += kOriginalLength; | 340 original[0] += kOriginalLength; |
| 327 received[0] += kReceivedLength; | 341 received[0] += kReceivedLength; |
| 328 original_proxy_enabled[0] += kOriginalLength; | 342 original_proxy_enabled[0] += kOriginalLength; |
| 329 received_proxy_enabled[0] += kReceivedLength; | 343 received_proxy_enabled[0] += kReceivedLength; |
| 330 VerifyDailyDataSavingContentLengthPrefLists( | 344 VerifyDailyDataSavingContentLengthPrefLists( |
| 331 original, 1, received, 1, | 345 original, 1, received, 1, |
| 332 original_proxy_enabled, 1, received_proxy_enabled, 1, | 346 original_proxy_enabled, 1, received_proxy_enabled, 1, |
| 333 original_via_proxy, 1, received_via_proxy, 1); | 347 original_via_proxy, 1, received_via_proxy, 1); |
| 334 | 348 |
| 335 UpdateContentLengthPrefsForDataReductionProxy( | 349 UpdateContentLengthPrefsForDataReductionProxy( |
| 336 kReceivedLength, kOriginalLength, | 350 kReceivedLength, kOriginalLength, |
| 337 false, UNKNOWN_TYPE, FakeNow(), &pref_service_); | 351 false, UNKNOWN_TYPE, FakeNow(), statistics_prefs_); |
| 338 original[0] += kOriginalLength; | 352 original[0] += kOriginalLength; |
| 339 received[0] += kReceivedLength; | 353 received[0] += kReceivedLength; |
| 340 VerifyDailyDataSavingContentLengthPrefLists( | 354 VerifyDailyDataSavingContentLengthPrefLists( |
| 341 original, 1, received, 1, | 355 original, 1, received, 1, |
| 342 original_proxy_enabled, 1, received_proxy_enabled, 1, | 356 original_proxy_enabled, 1, received_proxy_enabled, 1, |
| 343 original_via_proxy, 1, received_via_proxy, 1); | 357 original_via_proxy, 1, received_via_proxy, 1); |
| 344 } | 358 } |
| 345 | 359 |
| 346 TEST_F(ChromeNetworkDailyDataSavingMetricsTest, RequestType) { | 360 TEST_F(ChromeNetworkDailyDataSavingMetricsTest, RequestType) { |
| 347 const int64 kContentLength = 200; | 361 const int64 kContentLength = 200; |
| 348 int64 received[] = {0}; | 362 int64 received[] = {0}; |
| 349 int64 https_received[] = {0}; | 363 int64 https_received[] = {0}; |
| 350 int64 total_received[] = {0}; | 364 int64 total_received[] = {0}; |
| 351 int64 proxy_enabled_received[] = {0}; | 365 int64 proxy_enabled_received[] = {0}; |
| 352 | 366 |
| 353 UpdateContentLengthPrefsForDataReductionProxy( | 367 UpdateContentLengthPrefsForDataReductionProxy( |
| 354 kContentLength, kContentLength, | 368 kContentLength, kContentLength, |
| 355 true, HTTPS, | 369 true, HTTPS, |
| 356 FakeNow(), &pref_service_); | 370 FakeNow(), statistics_prefs_); |
| 357 total_received[0] += kContentLength; | 371 total_received[0] += kContentLength; |
| 358 proxy_enabled_received[0] += kContentLength; | 372 proxy_enabled_received[0] += kContentLength; |
| 359 https_received[0] += kContentLength; | 373 https_received[0] += kContentLength; |
| 360 VerifyDailyRequestTypeContentLengthPrefLists( | 374 VerifyDailyRequestTypeContentLengthPrefLists( |
| 361 total_received, 1, total_received, 1, | 375 total_received, 1, total_received, 1, |
| 362 proxy_enabled_received, 1, proxy_enabled_received, 1, | 376 proxy_enabled_received, 1, proxy_enabled_received, 1, |
| 363 https_received, 1, | 377 https_received, 1, |
| 364 received, 0, // short bypass | 378 received, 0, // short bypass |
| 365 received, 0, // long bypass | 379 received, 0, // long bypass |
| 366 received, 0); // unknown | 380 received, 0); // unknown |
| 367 | 381 |
| 368 // Data reduction proxy is not enabled. | 382 // Data reduction proxy is not enabled. |
| 369 UpdateContentLengthPrefsForDataReductionProxy( | 383 UpdateContentLengthPrefsForDataReductionProxy( |
| 370 kContentLength, kContentLength, | 384 kContentLength, kContentLength, |
| 371 false, HTTPS, | 385 false, HTTPS, |
| 372 FakeNow(), &pref_service_); | 386 FakeNow(), statistics_prefs_); |
| 373 total_received[0] += kContentLength; | 387 total_received[0] += kContentLength; |
| 374 VerifyDailyRequestTypeContentLengthPrefLists( | 388 VerifyDailyRequestTypeContentLengthPrefLists( |
| 375 total_received, 1, total_received, 1, | 389 total_received, 1, total_received, 1, |
| 376 proxy_enabled_received, 1, proxy_enabled_received, 1, | 390 proxy_enabled_received, 1, proxy_enabled_received, 1, |
| 377 https_received, 1, | 391 https_received, 1, |
| 378 received, 0, // short bypass | 392 received, 0, // short bypass |
| 379 received, 0, // long bypass | 393 received, 0, // long bypass |
| 380 received, 0); // unknown | 394 received, 0); // unknown |
| 381 | 395 |
| 382 UpdateContentLengthPrefsForDataReductionProxy( | 396 UpdateContentLengthPrefsForDataReductionProxy( |
| 383 kContentLength, kContentLength, | 397 kContentLength, kContentLength, |
| 384 true, HTTPS, | 398 true, HTTPS, |
| 385 FakeNow(), &pref_service_); | 399 FakeNow(), statistics_prefs_); |
| 386 total_received[0] += kContentLength; | 400 total_received[0] += kContentLength; |
| 387 proxy_enabled_received[0] += kContentLength; | 401 proxy_enabled_received[0] += kContentLength; |
| 388 https_received[0] += kContentLength; | 402 https_received[0] += kContentLength; |
| 389 VerifyDailyRequestTypeContentLengthPrefLists( | 403 VerifyDailyRequestTypeContentLengthPrefLists( |
| 390 total_received, 1, total_received, 1, | 404 total_received, 1, total_received, 1, |
| 391 proxy_enabled_received, 1, proxy_enabled_received, 1, | 405 proxy_enabled_received, 1, proxy_enabled_received, 1, |
| 392 https_received, 1, | 406 https_received, 1, |
| 393 received, 0, // short bypass | 407 received, 0, // short bypass |
| 394 received, 0, // long bypass | 408 received, 0, // long bypass |
| 395 received, 0); // unknown | 409 received, 0); // unknown |
| 396 | 410 |
| 397 UpdateContentLengthPrefsForDataReductionProxy( | 411 UpdateContentLengthPrefsForDataReductionProxy( |
| 398 kContentLength, kContentLength, | 412 kContentLength, kContentLength, |
| 399 true, SHORT_BYPASS, | 413 true, SHORT_BYPASS, |
| 400 FakeNow(), &pref_service_); | 414 FakeNow(), statistics_prefs_); |
| 401 total_received[0] += kContentLength; | 415 total_received[0] += kContentLength; |
| 402 proxy_enabled_received[0] += kContentLength; | 416 proxy_enabled_received[0] += kContentLength; |
| 403 received[0] += kContentLength; | 417 received[0] += kContentLength; |
| 404 VerifyDailyRequestTypeContentLengthPrefLists( | 418 VerifyDailyRequestTypeContentLengthPrefLists( |
| 405 total_received, 1, total_received, 1, | 419 total_received, 1, total_received, 1, |
| 406 proxy_enabled_received, 1, proxy_enabled_received, 1, | 420 proxy_enabled_received, 1, proxy_enabled_received, 1, |
| 407 https_received, 1, | 421 https_received, 1, |
| 408 received, 1, // short bypass | 422 received, 1, // short bypass |
| 409 received, 0, // long bypass | 423 received, 0, // long bypass |
| 410 received, 0); // unknown | 424 received, 0); // unknown |
| 411 | 425 |
| 412 UpdateContentLengthPrefsForDataReductionProxy( | 426 UpdateContentLengthPrefsForDataReductionProxy( |
| 413 kContentLength, kContentLength, | 427 kContentLength, kContentLength, |
| 414 true, LONG_BYPASS, | 428 true, LONG_BYPASS, |
| 415 FakeNow(), &pref_service_); | 429 FakeNow(), statistics_prefs_); |
| 416 total_received[0] += kContentLength; | 430 total_received[0] += kContentLength; |
| 417 proxy_enabled_received[0] += kContentLength; | 431 proxy_enabled_received[0] += kContentLength; |
| 418 VerifyDailyRequestTypeContentLengthPrefLists( | 432 VerifyDailyRequestTypeContentLengthPrefLists( |
| 419 total_received, 1, total_received, 1, // total | 433 total_received, 1, total_received, 1, // total |
| 420 proxy_enabled_received, 1, proxy_enabled_received, 1, | 434 proxy_enabled_received, 1, proxy_enabled_received, 1, |
| 421 https_received, 1, | 435 https_received, 1, |
| 422 received, 1, // short bypass | 436 received, 1, // short bypass |
| 423 received, 1, // long bypass | 437 received, 1, // long bypass |
| 424 received, 0); // unknown | 438 received, 0); // unknown |
| 425 | 439 |
| 426 UpdateContentLengthPrefsForDataReductionProxy( | 440 UpdateContentLengthPrefsForDataReductionProxy( |
| 427 kContentLength, kContentLength, | 441 kContentLength, kContentLength, |
| 428 true, UNKNOWN_TYPE, | 442 true, UNKNOWN_TYPE, |
| 429 FakeNow(), &pref_service_); | 443 FakeNow(), statistics_prefs_); |
| 430 total_received[0] += kContentLength; | 444 total_received[0] += kContentLength; |
| 431 proxy_enabled_received[0] += kContentLength; | 445 proxy_enabled_received[0] += kContentLength; |
| 432 VerifyDailyRequestTypeContentLengthPrefLists( | 446 VerifyDailyRequestTypeContentLengthPrefLists( |
| 433 total_received, 1, total_received, 1, | 447 total_received, 1, total_received, 1, |
| 434 proxy_enabled_received, 1, proxy_enabled_received, 1, | 448 proxy_enabled_received, 1, proxy_enabled_received, 1, |
| 435 https_received, 1, | 449 https_received, 1, |
| 436 received, 1, // short bypass | 450 received, 1, // short bypass |
| 437 received, 1, // long bypass | 451 received, 1, // long bypass |
| 438 received, 1); // unknown | 452 received, 1); // unknown |
| 439 } | 453 } |
| 440 | 454 |
| 441 TEST_F(ChromeNetworkDailyDataSavingMetricsTest, ForwardOneDay) { | 455 TEST_F(ChromeNetworkDailyDataSavingMetricsTest, ForwardOneDay) { |
| 442 const int64 kOriginalLength = 200; | 456 const int64 kOriginalLength = 200; |
| 443 const int64 kReceivedLength = 100; | 457 const int64 kReceivedLength = 100; |
| 444 | 458 |
| 445 UpdateContentLengthPrefsForDataReductionProxy( | 459 UpdateContentLengthPrefsForDataReductionProxy( |
| 446 kReceivedLength, kOriginalLength, | 460 kReceivedLength, kOriginalLength, |
| 447 true, VIA_DATA_REDUCTION_PROXY, | 461 true, VIA_DATA_REDUCTION_PROXY, |
| 448 FakeNow(), &pref_service_); | 462 FakeNow(), statistics_prefs_); |
| 449 | 463 |
| 450 // Forward one day. | 464 // Forward one day. |
| 451 SetFakeTimeDeltaInHours(24); | 465 SetFakeTimeDeltaInHours(24); |
| 452 | 466 |
| 453 // Proxy not enabled. Not via proxy. | 467 // Proxy not enabled. Not via proxy. |
| 454 UpdateContentLengthPrefsForDataReductionProxy( | 468 UpdateContentLengthPrefsForDataReductionProxy( |
| 455 kReceivedLength, kOriginalLength, | 469 kReceivedLength, kOriginalLength, |
| 456 false, UNKNOWN_TYPE, FakeNow(), &pref_service_); | 470 false, UNKNOWN_TYPE, FakeNow(), statistics_prefs_); |
| 457 | 471 |
| 458 int64 original[] = {kOriginalLength, kOriginalLength}; | 472 int64 original[] = {kOriginalLength, kOriginalLength}; |
| 459 int64 received[] = {kReceivedLength, kReceivedLength}; | 473 int64 received[] = {kReceivedLength, kReceivedLength}; |
| 460 int64 original_with_data_reduction_proxy_enabled[] = {kOriginalLength, 0}; | 474 int64 original_with_data_reduction_proxy_enabled[] = {kOriginalLength, 0}; |
| 461 int64 received_with_data_reduction_proxy_enabled[] = {kReceivedLength, 0}; | 475 int64 received_with_data_reduction_proxy_enabled[] = {kReceivedLength, 0}; |
| 462 int64 original_via_data_reduction_proxy[] = {kOriginalLength, 0}; | 476 int64 original_via_data_reduction_proxy[] = {kOriginalLength, 0}; |
| 463 int64 received_via_data_reduction_proxy[] = {kReceivedLength, 0}; | 477 int64 received_via_data_reduction_proxy[] = {kReceivedLength, 0}; |
| 464 VerifyDailyDataSavingContentLengthPrefLists( | 478 VerifyDailyDataSavingContentLengthPrefLists( |
| 465 original, 2, | 479 original, 2, |
| 466 received, 2, | 480 received, 2, |
| 467 original_with_data_reduction_proxy_enabled, 2, | 481 original_with_data_reduction_proxy_enabled, 2, |
| 468 received_with_data_reduction_proxy_enabled, 2, | 482 received_with_data_reduction_proxy_enabled, 2, |
| 469 original_via_data_reduction_proxy, 2, | 483 original_via_data_reduction_proxy, 2, |
| 470 received_via_data_reduction_proxy, 2); | 484 received_via_data_reduction_proxy, 2); |
| 471 | 485 |
| 472 // Proxy enabled. Not via proxy. | 486 // Proxy enabled. Not via proxy. |
| 473 UpdateContentLengthPrefsForDataReductionProxy( | 487 UpdateContentLengthPrefsForDataReductionProxy( |
| 474 kReceivedLength, kOriginalLength, | 488 kReceivedLength, kOriginalLength, |
| 475 true, UNKNOWN_TYPE, FakeNow(), &pref_service_); | 489 true, UNKNOWN_TYPE, FakeNow(), statistics_prefs_); |
| 476 original[1] += kOriginalLength; | 490 original[1] += kOriginalLength; |
| 477 received[1] += kReceivedLength; | 491 received[1] += kReceivedLength; |
| 478 original_with_data_reduction_proxy_enabled[1] += kOriginalLength; | 492 original_with_data_reduction_proxy_enabled[1] += kOriginalLength; |
| 479 received_with_data_reduction_proxy_enabled[1] += kReceivedLength; | 493 received_with_data_reduction_proxy_enabled[1] += kReceivedLength; |
| 480 VerifyDailyDataSavingContentLengthPrefLists( | 494 VerifyDailyDataSavingContentLengthPrefLists( |
| 481 original, 2, | 495 original, 2, |
| 482 received, 2, | 496 received, 2, |
| 483 original_with_data_reduction_proxy_enabled, 2, | 497 original_with_data_reduction_proxy_enabled, 2, |
| 484 received_with_data_reduction_proxy_enabled, 2, | 498 received_with_data_reduction_proxy_enabled, 2, |
| 485 original_via_data_reduction_proxy, 2, | 499 original_via_data_reduction_proxy, 2, |
| 486 received_via_data_reduction_proxy, 2); | 500 received_via_data_reduction_proxy, 2); |
| 487 | 501 |
| 488 // Proxy enabled and via proxy. | 502 // Proxy enabled and via proxy. |
| 489 UpdateContentLengthPrefsForDataReductionProxy( | 503 UpdateContentLengthPrefsForDataReductionProxy( |
| 490 kReceivedLength, kOriginalLength, | 504 kReceivedLength, kOriginalLength, |
| 491 true, VIA_DATA_REDUCTION_PROXY, | 505 true, VIA_DATA_REDUCTION_PROXY, |
| 492 FakeNow(), &pref_service_); | 506 FakeNow(), statistics_prefs_); |
| 493 original[1] += kOriginalLength; | 507 original[1] += kOriginalLength; |
| 494 received[1] += kReceivedLength; | 508 received[1] += kReceivedLength; |
| 495 original_with_data_reduction_proxy_enabled[1] += kOriginalLength; | 509 original_with_data_reduction_proxy_enabled[1] += kOriginalLength; |
| 496 received_with_data_reduction_proxy_enabled[1] += kReceivedLength; | 510 received_with_data_reduction_proxy_enabled[1] += kReceivedLength; |
| 497 original_via_data_reduction_proxy[1] += kOriginalLength; | 511 original_via_data_reduction_proxy[1] += kOriginalLength; |
| 498 received_via_data_reduction_proxy[1] += kReceivedLength; | 512 received_via_data_reduction_proxy[1] += kReceivedLength; |
| 499 VerifyDailyDataSavingContentLengthPrefLists( | 513 VerifyDailyDataSavingContentLengthPrefLists( |
| 500 original, 2, | 514 original, 2, |
| 501 received, 2, | 515 received, 2, |
| 502 original_with_data_reduction_proxy_enabled, 2, | 516 original_with_data_reduction_proxy_enabled, 2, |
| 503 received_with_data_reduction_proxy_enabled, 2, | 517 received_with_data_reduction_proxy_enabled, 2, |
| 504 original_via_data_reduction_proxy, 2, | 518 original_via_data_reduction_proxy, 2, |
| 505 received_via_data_reduction_proxy, 2); | 519 received_via_data_reduction_proxy, 2); |
| 506 } | 520 } |
| 507 | 521 |
| 508 TEST_F(ChromeNetworkDailyDataSavingMetricsTest, PartialDayTimeChange) { | 522 TEST_F(ChromeNetworkDailyDataSavingMetricsTest, PartialDayTimeChange) { |
| 509 const int64 kOriginalLength = 200; | 523 const int64 kOriginalLength = 200; |
| 510 const int64 kReceivedLength = 100; | 524 const int64 kReceivedLength = 100; |
| 511 int64 original[] = {0, kOriginalLength}; | 525 int64 original[] = {0, kOriginalLength}; |
| 512 int64 received[] = {0, kReceivedLength}; | 526 int64 received[] = {0, kReceivedLength}; |
| 513 | 527 |
| 514 UpdateContentLengthPrefsForDataReductionProxy( | 528 UpdateContentLengthPrefsForDataReductionProxy( |
| 515 kReceivedLength, kOriginalLength, | 529 kReceivedLength, kOriginalLength, |
| 516 true, VIA_DATA_REDUCTION_PROXY, | 530 true, VIA_DATA_REDUCTION_PROXY, |
| 517 FakeNow(), &pref_service_); | 531 FakeNow(), statistics_prefs_); |
| 518 VerifyDailyDataSavingContentLengthPrefLists( | 532 VerifyDailyDataSavingContentLengthPrefLists( |
| 519 original, 2, received, 2, | 533 original, 2, received, 2, |
| 520 original, 2, received, 2, | 534 original, 2, received, 2, |
| 521 original, 2, received, 2); | 535 original, 2, received, 2); |
| 522 | 536 |
| 523 // Forward 10 hours, stay in the same day. | 537 // Forward 10 hours, stay in the same day. |
| 524 // See kLastUpdateTime: "Now" in test is 03:45am. | 538 // See kLastUpdateTime: "Now" in test is 03:45am. |
| 525 SetFakeTimeDeltaInHours(10); | 539 SetFakeTimeDeltaInHours(10); |
| 526 UpdateContentLengthPrefsForDataReductionProxy( | 540 UpdateContentLengthPrefsForDataReductionProxy( |
| 527 kReceivedLength, kOriginalLength, | 541 kReceivedLength, kOriginalLength, |
| 528 true, VIA_DATA_REDUCTION_PROXY, | 542 true, VIA_DATA_REDUCTION_PROXY, |
| 529 FakeNow(), &pref_service_); | 543 FakeNow(), statistics_prefs_); |
| 530 original[1] += kOriginalLength; | 544 original[1] += kOriginalLength; |
| 531 received[1] += kReceivedLength; | 545 received[1] += kReceivedLength; |
| 532 VerifyDailyDataSavingContentLengthPrefLists( | 546 VerifyDailyDataSavingContentLengthPrefLists( |
| 533 original, 2, received, 2, | 547 original, 2, received, 2, |
| 534 original, 2, received, 2, | 548 original, 2, received, 2, |
| 535 original, 2, received, 2); | 549 original, 2, received, 2); |
| 536 | 550 |
| 537 // Forward 11 more hours, comes to tomorrow. | 551 // Forward 11 more hours, comes to tomorrow. |
| 538 AddFakeTimeDeltaInHours(11); | 552 AddFakeTimeDeltaInHours(11); |
| 539 UpdateContentLengthPrefsForDataReductionProxy( | 553 UpdateContentLengthPrefsForDataReductionProxy( |
| 540 kReceivedLength, kOriginalLength, | 554 kReceivedLength, kOriginalLength, |
| 541 true, VIA_DATA_REDUCTION_PROXY, | 555 true, VIA_DATA_REDUCTION_PROXY, |
| 542 FakeNow(), &pref_service_); | 556 FakeNow(), statistics_prefs_); |
| 543 int64 original2[] = {kOriginalLength * 2, kOriginalLength}; | 557 int64 original2[] = {kOriginalLength * 2, kOriginalLength}; |
| 544 int64 received2[] = {kReceivedLength * 2, kReceivedLength}; | 558 int64 received2[] = {kReceivedLength * 2, kReceivedLength}; |
| 545 VerifyDailyDataSavingContentLengthPrefLists( | 559 VerifyDailyDataSavingContentLengthPrefLists( |
| 546 original2, 2, received2, 2, | 560 original2, 2, received2, 2, |
| 547 original2, 2, received2, 2, | 561 original2, 2, received2, 2, |
| 548 original2, 2, received2, 2); | 562 original2, 2, received2, 2); |
| 549 } | 563 } |
| 550 | 564 |
| 551 TEST_F(ChromeNetworkDailyDataSavingMetricsTest, ForwardMultipleDays) { | 565 TEST_F(ChromeNetworkDailyDataSavingMetricsTest, ForwardMultipleDays) { |
| 552 const int64 kOriginalLength = 200; | 566 const int64 kOriginalLength = 200; |
| 553 const int64 kReceivedLength = 100; | 567 const int64 kReceivedLength = 100; |
| 554 UpdateContentLengthPrefsForDataReductionProxy( | 568 UpdateContentLengthPrefsForDataReductionProxy( |
| 555 kReceivedLength, kOriginalLength, | 569 kReceivedLength, kOriginalLength, |
| 556 true, VIA_DATA_REDUCTION_PROXY, | 570 true, VIA_DATA_REDUCTION_PROXY, |
| 557 FakeNow(), &pref_service_); | 571 FakeNow(), statistics_prefs_); |
| 558 | 572 |
| 559 // Forward three days. | 573 // Forward three days. |
| 560 SetFakeTimeDeltaInHours(3 * 24); | 574 SetFakeTimeDeltaInHours(3 * 24); |
| 561 | 575 |
| 562 UpdateContentLengthPrefsForDataReductionProxy( | 576 UpdateContentLengthPrefsForDataReductionProxy( |
| 563 kReceivedLength, kOriginalLength, | 577 kReceivedLength, kOriginalLength, |
| 564 true, VIA_DATA_REDUCTION_PROXY, | 578 true, VIA_DATA_REDUCTION_PROXY, |
| 565 FakeNow(), &pref_service_); | 579 FakeNow(), statistics_prefs_); |
| 566 | 580 |
| 567 int64 original[] = {kOriginalLength, 0, 0, kOriginalLength}; | 581 int64 original[] = {kOriginalLength, 0, 0, kOriginalLength}; |
| 568 int64 received[] = {kReceivedLength, 0, 0, kReceivedLength}; | 582 int64 received[] = {kReceivedLength, 0, 0, kReceivedLength}; |
| 569 VerifyDailyDataSavingContentLengthPrefLists( | 583 VerifyDailyDataSavingContentLengthPrefLists( |
| 570 original, 4, received, 4, | 584 original, 4, received, 4, |
| 571 original, 4, received, 4, | 585 original, 4, received, 4, |
| 572 original, 4, received, 4); | 586 original, 4, received, 4); |
| 573 | 587 |
| 574 // Forward four more days. | 588 // Forward four more days. |
| 575 AddFakeTimeDeltaInHours(4 * 24); | 589 AddFakeTimeDeltaInHours(4 * 24); |
| 576 UpdateContentLengthPrefsForDataReductionProxy( | 590 UpdateContentLengthPrefsForDataReductionProxy( |
| 577 kReceivedLength, kOriginalLength, | 591 kReceivedLength, kOriginalLength, |
| 578 true, VIA_DATA_REDUCTION_PROXY, | 592 true, VIA_DATA_REDUCTION_PROXY, |
| 579 FakeNow(), &pref_service_); | 593 FakeNow(), statistics_prefs_); |
| 580 int64 original2[] = { | 594 int64 original2[] = { |
| 581 kOriginalLength, 0, 0, kOriginalLength, 0, 0, 0, kOriginalLength, | 595 kOriginalLength, 0, 0, kOriginalLength, 0, 0, 0, kOriginalLength, |
| 582 }; | 596 }; |
| 583 int64 received2[] = { | 597 int64 received2[] = { |
| 584 kReceivedLength, 0, 0, kReceivedLength, 0, 0, 0, kReceivedLength, | 598 kReceivedLength, 0, 0, kReceivedLength, 0, 0, 0, kReceivedLength, |
| 585 }; | 599 }; |
| 586 VerifyDailyDataSavingContentLengthPrefLists( | 600 VerifyDailyDataSavingContentLengthPrefLists( |
| 587 original2, 8, received2, 8, | 601 original2, 8, received2, 8, |
| 588 original2, 8, received2, 8, | 602 original2, 8, received2, 8, |
| 589 original2, 8, received2, 8); | 603 original2, 8, received2, 8); |
| 590 | 604 |
| 591 // Forward |kNumDaysInHistory| more days. | 605 // Forward |kNumDaysInHistory| more days. |
| 592 AddFakeTimeDeltaInHours(kNumDaysInHistory * 24); | 606 AddFakeTimeDeltaInHours(kNumDaysInHistory * 24); |
| 593 UpdateContentLengthPrefsForDataReductionProxy( | 607 UpdateContentLengthPrefsForDataReductionProxy( |
| 594 kReceivedLength, kOriginalLength, | 608 kReceivedLength, kOriginalLength, |
| 595 true, VIA_DATA_REDUCTION_PROXY, | 609 true, VIA_DATA_REDUCTION_PROXY, |
| 596 FakeNow(), &pref_service_); | 610 FakeNow(), statistics_prefs_); |
| 597 int64 original3[] = {kOriginalLength}; | 611 int64 original3[] = {kOriginalLength}; |
| 598 int64 received3[] = {kReceivedLength}; | 612 int64 received3[] = {kReceivedLength}; |
| 599 VerifyDailyDataSavingContentLengthPrefLists( | 613 VerifyDailyDataSavingContentLengthPrefLists( |
| 600 original3, 1, received3, 1, | 614 original3, 1, received3, 1, |
| 601 original3, 1, received3, 1, | 615 original3, 1, received3, 1, |
| 602 original3, 1, received3, 1); | 616 original3, 1, received3, 1); |
| 603 | 617 |
| 604 // Forward |kNumDaysInHistory| + 1 more days. | 618 // Forward |kNumDaysInHistory| + 1 more days. |
| 605 AddFakeTimeDeltaInHours((kNumDaysInHistory + 1)* 24); | 619 AddFakeTimeDeltaInHours((kNumDaysInHistory + 1)* 24); |
| 606 UpdateContentLengthPrefsForDataReductionProxy( | 620 UpdateContentLengthPrefsForDataReductionProxy( |
| 607 kReceivedLength, kOriginalLength, | 621 kReceivedLength, kOriginalLength, |
| 608 true, VIA_DATA_REDUCTION_PROXY, | 622 true, VIA_DATA_REDUCTION_PROXY, |
| 609 FakeNow(), &pref_service_); | 623 FakeNow(), statistics_prefs_); |
| 610 VerifyDailyDataSavingContentLengthPrefLists( | 624 VerifyDailyDataSavingContentLengthPrefLists( |
| 611 original3, 1, received3, 1, | 625 original3, 1, received3, 1, |
| 612 original3, 1, received3, 1, | 626 original3, 1, received3, 1, |
| 613 original3, 1, received3, 1); | 627 original3, 1, received3, 1); |
| 614 } | 628 } |
| 615 | 629 |
| 616 TEST_F(ChromeNetworkDailyDataSavingMetricsTest, BackwardAndForwardOneDay) { | 630 TEST_F(ChromeNetworkDailyDataSavingMetricsTest, BackwardAndForwardOneDay) { |
| 617 const int64 kOriginalLength = 200; | 631 const int64 kOriginalLength = 200; |
| 618 const int64 kReceivedLength = 100; | 632 const int64 kReceivedLength = 100; |
| 619 int64 original[] = {kOriginalLength}; | 633 int64 original[] = {kOriginalLength}; |
| 620 int64 received[] = {kReceivedLength}; | 634 int64 received[] = {kReceivedLength}; |
| 621 | 635 |
| 622 UpdateContentLengthPrefsForDataReductionProxy( | 636 UpdateContentLengthPrefsForDataReductionProxy( |
| 623 kReceivedLength, kOriginalLength, | 637 kReceivedLength, kOriginalLength, |
| 624 true, VIA_DATA_REDUCTION_PROXY, | 638 true, VIA_DATA_REDUCTION_PROXY, |
| 625 FakeNow(), &pref_service_); | 639 FakeNow(), statistics_prefs_); |
| 626 | 640 |
| 627 // Backward one day. | 641 // Backward one day. |
| 628 SetFakeTimeDeltaInHours(-24); | 642 SetFakeTimeDeltaInHours(-24); |
| 629 UpdateContentLengthPrefsForDataReductionProxy( | 643 UpdateContentLengthPrefsForDataReductionProxy( |
| 630 kReceivedLength, kOriginalLength, | 644 kReceivedLength, kOriginalLength, |
| 631 true, VIA_DATA_REDUCTION_PROXY, | 645 true, VIA_DATA_REDUCTION_PROXY, |
| 632 FakeNow(), &pref_service_); | 646 FakeNow(), statistics_prefs_); |
| 633 original[0] += kOriginalLength; | 647 original[0] += kOriginalLength; |
| 634 received[0] += kReceivedLength; | 648 received[0] += kReceivedLength; |
| 635 VerifyDailyDataSavingContentLengthPrefLists( | 649 VerifyDailyDataSavingContentLengthPrefLists( |
| 636 original, 1, received, 1, | 650 original, 1, received, 1, |
| 637 original, 1, received, 1, | 651 original, 1, received, 1, |
| 638 original, 1, received, 1); | 652 original, 1, received, 1); |
| 639 | 653 |
| 640 // Then, Forward one day | 654 // Then, Forward one day |
| 641 AddFakeTimeDeltaInHours(24); | 655 AddFakeTimeDeltaInHours(24); |
| 642 UpdateContentLengthPrefsForDataReductionProxy( | 656 UpdateContentLengthPrefsForDataReductionProxy( |
| 643 kReceivedLength, kOriginalLength, | 657 kReceivedLength, kOriginalLength, |
| 644 true, VIA_DATA_REDUCTION_PROXY, | 658 true, VIA_DATA_REDUCTION_PROXY, |
| 645 FakeNow(), &pref_service_); | 659 FakeNow(), statistics_prefs_); |
| 646 int64 original2[] = {kOriginalLength * 2, kOriginalLength}; | 660 int64 original2[] = {kOriginalLength * 2, kOriginalLength}; |
| 647 int64 received2[] = {kReceivedLength * 2, kReceivedLength}; | 661 int64 received2[] = {kReceivedLength * 2, kReceivedLength}; |
| 648 VerifyDailyDataSavingContentLengthPrefLists( | 662 VerifyDailyDataSavingContentLengthPrefLists( |
| 649 original2, 2, received2, 2, | 663 original2, 2, received2, 2, |
| 650 original2, 2, received2, 2, | 664 original2, 2, received2, 2, |
| 651 original2, 2, received2, 2); | 665 original2, 2, received2, 2); |
| 652 } | 666 } |
| 653 | 667 |
| 654 TEST_F(ChromeNetworkDailyDataSavingMetricsTest, BackwardTwoDays) { | 668 TEST_F(ChromeNetworkDailyDataSavingMetricsTest, BackwardTwoDays) { |
| 655 const int64 kOriginalLength = 200; | 669 const int64 kOriginalLength = 200; |
| 656 const int64 kReceivedLength = 100; | 670 const int64 kReceivedLength = 100; |
| 657 int64 original[] = {kOriginalLength}; | 671 int64 original[] = {kOriginalLength}; |
| 658 int64 received[] = {kReceivedLength}; | 672 int64 received[] = {kReceivedLength}; |
| 659 | 673 |
| 660 UpdateContentLengthPrefsForDataReductionProxy( | 674 UpdateContentLengthPrefsForDataReductionProxy( |
| 661 kReceivedLength, kOriginalLength, | 675 kReceivedLength, kOriginalLength, |
| 662 true, VIA_DATA_REDUCTION_PROXY, | 676 true, VIA_DATA_REDUCTION_PROXY, |
| 663 FakeNow(), &pref_service_); | 677 FakeNow(), statistics_prefs_); |
| 664 // Backward two days. | 678 // Backward two days. |
| 665 SetFakeTimeDeltaInHours(-2 * 24); | 679 SetFakeTimeDeltaInHours(-2 * 24); |
| 666 UpdateContentLengthPrefsForDataReductionProxy( | 680 UpdateContentLengthPrefsForDataReductionProxy( |
| 667 kReceivedLength, kOriginalLength, | 681 kReceivedLength, kOriginalLength, |
| 668 true, VIA_DATA_REDUCTION_PROXY, | 682 true, VIA_DATA_REDUCTION_PROXY, |
| 669 FakeNow(), &pref_service_); | 683 FakeNow(), statistics_prefs_); |
| 670 VerifyDailyDataSavingContentLengthPrefLists( | 684 VerifyDailyDataSavingContentLengthPrefLists( |
| 671 original, 1, received, 1, | 685 original, 1, received, 1, |
| 672 original, 1, received, 1, | 686 original, 1, received, 1, |
| 673 original, 1, received, 1); | 687 original, 1, received, 1); |
| 674 } | 688 } |
| 675 | 689 |
| 676 } // namespace data_reduction_proxy | 690 } // namespace data_reduction_proxy |
| OLD | NEW |