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