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