| 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" | 9 #include "base/prefs/scoped_user_pref_update.h" |
| 10 #include "base/prefs/testing_pref_service.h" | 10 #include "base/prefs/testing_pref_service.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "components/data_reduction_proxy/browser/data_reduction_proxy_metrics.h
" | 12 #include "components/data_reduction_proxy/browser/data_reduction_proxy_metrics.h
" |
| 13 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names
.h" | 13 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names
.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 #if defined(OS_ANDROID) || defined(OS_IOS) | |
| 19 const size_t kNumDaysInHistory = 60; | 18 const size_t kNumDaysInHistory = 60; |
| 20 | 19 |
| 21 int64 GetListPrefInt64Value( | 20 int64 GetListPrefInt64Value( |
| 22 const base::ListValue& list_update, size_t index) { | 21 const base::ListValue& list_update, size_t index) { |
| 23 std::string string_value; | 22 std::string string_value; |
| 24 EXPECT_TRUE(list_update.GetString(index, &string_value)); | 23 EXPECT_TRUE(list_update.GetString(index, &string_value)); |
| 25 | 24 |
| 26 int64 value = 0; | 25 int64 value = 0; |
| 27 EXPECT_TRUE(base::StringToInt64(string_value, &value)); | 26 EXPECT_TRUE(base::StringToInt64(string_value, &value)); |
| 28 return value; | 27 return value; |
| 29 } | 28 } |
| 30 | 29 |
| 31 #endif // defined(OS_ANDROID) || defined(OS_IOS) | |
| 32 | |
| 33 } // namespace | 30 } // namespace |
| 34 | 31 |
| 35 namespace data_reduction_proxy { | 32 namespace data_reduction_proxy { |
| 36 | 33 |
| 37 // Test UpdateContentLengthPrefs. | 34 // Test UpdateContentLengthPrefs. |
| 38 class ChromeNetworkDataSavingMetricsTest : public testing::Test { | 35 class ChromeNetworkDataSavingMetricsTest : public testing::Test { |
| 39 protected: | 36 protected: |
| 40 ChromeNetworkDataSavingMetricsTest() {} | 37 ChromeNetworkDataSavingMetricsTest() {} |
| 41 | 38 |
| 42 virtual void SetUp() OVERRIDE { | 39 virtual void SetUp() OVERRIDE { |
| 43 PrefRegistrySimple* registry = pref_service_.registry(); | 40 PrefRegistrySimple* registry = pref_service_.registry(); |
| 44 registry->RegisterInt64Pref( | 41 registry->RegisterInt64Pref( |
| 45 data_reduction_proxy::prefs::kHttpReceivedContentLength, 0); | 42 data_reduction_proxy::prefs::kHttpReceivedContentLength, 0); |
| 46 registry->RegisterInt64Pref( | 43 registry->RegisterInt64Pref( |
| 47 data_reduction_proxy::prefs::kHttpOriginalContentLength, 0); | 44 data_reduction_proxy::prefs::kHttpOriginalContentLength, 0); |
| 48 | 45 |
| 49 #if defined(OS_ANDROID) || defined(OS_IOS) | |
| 50 registry->RegisterListPref(data_reduction_proxy::prefs:: | 46 registry->RegisterListPref(data_reduction_proxy::prefs:: |
| 51 kDailyHttpOriginalContentLength); | 47 kDailyHttpOriginalContentLength); |
| 52 registry->RegisterListPref(data_reduction_proxy::prefs:: | 48 registry->RegisterListPref(data_reduction_proxy::prefs:: |
| 53 kDailyHttpReceivedContentLength); | 49 kDailyHttpReceivedContentLength); |
| 54 registry->RegisterListPref( | 50 registry->RegisterListPref( |
| 55 data_reduction_proxy::prefs:: | 51 data_reduction_proxy::prefs:: |
| 56 kDailyOriginalContentLengthWithDataReductionProxyEnabled); | 52 kDailyOriginalContentLengthWithDataReductionProxyEnabled); |
| 57 registry->RegisterListPref( | 53 registry->RegisterListPref( |
| 58 data_reduction_proxy::prefs:: | 54 data_reduction_proxy::prefs:: |
| 59 kDailyContentLengthWithDataReductionProxyEnabled); | 55 kDailyContentLengthWithDataReductionProxyEnabled); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 71 kDailyContentLengthUnknownWithDataReductionProxyEnabled); | 67 kDailyContentLengthUnknownWithDataReductionProxyEnabled); |
| 72 registry->RegisterListPref( | 68 registry->RegisterListPref( |
| 73 data_reduction_proxy::prefs:: | 69 data_reduction_proxy::prefs:: |
| 74 kDailyOriginalContentLengthViaDataReductionProxy); | 70 kDailyOriginalContentLengthViaDataReductionProxy); |
| 75 registry->RegisterListPref( | 71 registry->RegisterListPref( |
| 76 data_reduction_proxy::prefs:: | 72 data_reduction_proxy::prefs:: |
| 77 kDailyContentLengthViaDataReductionProxy); | 73 kDailyContentLengthViaDataReductionProxy); |
| 78 registry->RegisterInt64Pref( | 74 registry->RegisterInt64Pref( |
| 79 data_reduction_proxy::prefs:: | 75 data_reduction_proxy::prefs:: |
| 80 kDailyHttpContentLengthLastUpdateDate, 0L); | 76 kDailyHttpContentLengthLastUpdateDate, 0L); |
| 81 #endif // defined(OS_ANDROID) || defined(OS_IOS) | |
| 82 } | 77 } |
| 83 | 78 |
| 84 TestingPrefServiceSimple pref_service_; | 79 TestingPrefServiceSimple pref_service_; |
| 85 }; | 80 }; |
| 86 | 81 |
| 87 TEST_F(ChromeNetworkDataSavingMetricsTest, TotalLengths) { | 82 TEST_F(ChromeNetworkDataSavingMetricsTest, TotalLengths) { |
| 88 const int64 kOriginalLength = 200; | 83 const int64 kOriginalLength = 200; |
| 89 const int64 kReceivedLength = 100; | 84 const int64 kReceivedLength = 100; |
| 90 | 85 |
| 91 UpdateContentLengthPrefs( | 86 UpdateContentLengthPrefs( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 103 kReceivedLength, kOriginalLength, | 98 kReceivedLength, kOriginalLength, |
| 104 false, UNKNOWN_TYPE, &pref_service_); | 99 false, UNKNOWN_TYPE, &pref_service_); |
| 105 EXPECT_EQ(kReceivedLength * 2, | 100 EXPECT_EQ(kReceivedLength * 2, |
| 106 pref_service_.GetInt64( | 101 pref_service_.GetInt64( |
| 107 data_reduction_proxy::prefs::kHttpReceivedContentLength)); | 102 data_reduction_proxy::prefs::kHttpReceivedContentLength)); |
| 108 EXPECT_EQ(kOriginalLength * 2, | 103 EXPECT_EQ(kOriginalLength * 2, |
| 109 pref_service_.GetInt64( | 104 pref_service_.GetInt64( |
| 110 data_reduction_proxy::prefs::kHttpOriginalContentLength)); | 105 data_reduction_proxy::prefs::kHttpOriginalContentLength)); |
| 111 } | 106 } |
| 112 | 107 |
| 113 #if defined(OS_ANDROID) || defined(OS_IOS) | |
| 114 | |
| 115 // The initial last update time used in test. There is no leap second a few | 108 // The initial last update time used in test. There is no leap second a few |
| 116 // days around this time used in the test. | 109 // days around this time used in the test. |
| 117 // Note: No time zone is specified. Local time will be assumed by | 110 // Note: No time zone is specified. Local time will be assumed by |
| 118 // base::Time::FromString below. | 111 // base::Time::FromString below. |
| 119 const char kLastUpdateTime[] = "Wed, 18 Sep 2013 03:45:26"; | 112 const char kLastUpdateTime[] = "Wed, 18 Sep 2013 03:45:26"; |
| 120 | 113 |
| 121 class ChromeNetworkDailyDataSavingMetricsTest | 114 class ChromeNetworkDailyDataSavingMetricsTest |
| 122 : public ChromeNetworkDataSavingMetricsTest { | 115 : public ChromeNetworkDataSavingMetricsTest { |
| 123 protected: | 116 protected: |
| 124 ChromeNetworkDailyDataSavingMetricsTest() { | 117 ChromeNetworkDailyDataSavingMetricsTest() { |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 SetFakeTimeDeltaInHours(-2 * 24); | 665 SetFakeTimeDeltaInHours(-2 * 24); |
| 673 UpdateContentLengthPrefsForDataReductionProxy( | 666 UpdateContentLengthPrefsForDataReductionProxy( |
| 674 kReceivedLength, kOriginalLength, | 667 kReceivedLength, kOriginalLength, |
| 675 true, VIA_DATA_REDUCTION_PROXY, | 668 true, VIA_DATA_REDUCTION_PROXY, |
| 676 FakeNow(), &pref_service_); | 669 FakeNow(), &pref_service_); |
| 677 VerifyDailyDataSavingContentLengthPrefLists( | 670 VerifyDailyDataSavingContentLengthPrefLists( |
| 678 original, 1, received, 1, | 671 original, 1, received, 1, |
| 679 original, 1, received, 1, | 672 original, 1, received, 1, |
| 680 original, 1, received, 1); | 673 original, 1, received, 1); |
| 681 } | 674 } |
| 682 #endif // defined(OS_ANDROID) || defined(OS_IOS) | |
| 683 | 675 |
| 684 } // namespace data_reduction_proxy | 676 } // namespace data_reduction_proxy |
| OLD | NEW |