| 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) |
| 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 |
| 31 #endif // defined(OS_ANDROID) || defined(OS_IOS) |
| 32 |
| 30 } // namespace | 33 } // namespace |
| 31 | 34 |
| 32 namespace data_reduction_proxy { | 35 namespace data_reduction_proxy { |
| 33 | 36 |
| 34 // Test UpdateContentLengthPrefs. | 37 // Test UpdateContentLengthPrefs. |
| 35 class ChromeNetworkDataSavingMetricsTest : public testing::Test { | 38 class ChromeNetworkDataSavingMetricsTest : public testing::Test { |
| 36 protected: | 39 protected: |
| 37 ChromeNetworkDataSavingMetricsTest() {} | 40 ChromeNetworkDataSavingMetricsTest() {} |
| 38 | 41 |
| 39 virtual void SetUp() OVERRIDE { | 42 virtual void SetUp() OVERRIDE { |
| 40 PrefRegistrySimple* registry = pref_service_.registry(); | 43 PrefRegistrySimple* registry = pref_service_.registry(); |
| 41 registry->RegisterInt64Pref( | 44 registry->RegisterInt64Pref( |
| 42 data_reduction_proxy::prefs::kHttpReceivedContentLength, 0); | 45 data_reduction_proxy::prefs::kHttpReceivedContentLength, 0); |
| 43 registry->RegisterInt64Pref( | 46 registry->RegisterInt64Pref( |
| 44 data_reduction_proxy::prefs::kHttpOriginalContentLength, 0); | 47 data_reduction_proxy::prefs::kHttpOriginalContentLength, 0); |
| 45 | 48 |
| 49 #if defined(OS_ANDROID) || defined(OS_IOS) |
| 46 registry->RegisterListPref(data_reduction_proxy::prefs:: | 50 registry->RegisterListPref(data_reduction_proxy::prefs:: |
| 47 kDailyHttpOriginalContentLength); | 51 kDailyHttpOriginalContentLength); |
| 48 registry->RegisterListPref(data_reduction_proxy::prefs:: | 52 registry->RegisterListPref(data_reduction_proxy::prefs:: |
| 49 kDailyHttpReceivedContentLength); | 53 kDailyHttpReceivedContentLength); |
| 50 registry->RegisterListPref( | 54 registry->RegisterListPref( |
| 51 data_reduction_proxy::prefs:: | 55 data_reduction_proxy::prefs:: |
| 52 kDailyOriginalContentLengthWithDataReductionProxyEnabled); | 56 kDailyOriginalContentLengthWithDataReductionProxyEnabled); |
| 53 registry->RegisterListPref( | 57 registry->RegisterListPref( |
| 54 data_reduction_proxy::prefs:: | 58 data_reduction_proxy::prefs:: |
| 55 kDailyContentLengthWithDataReductionProxyEnabled); | 59 kDailyContentLengthWithDataReductionProxyEnabled); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 67 kDailyContentLengthUnknownWithDataReductionProxyEnabled); | 71 kDailyContentLengthUnknownWithDataReductionProxyEnabled); |
| 68 registry->RegisterListPref( | 72 registry->RegisterListPref( |
| 69 data_reduction_proxy::prefs:: | 73 data_reduction_proxy::prefs:: |
| 70 kDailyOriginalContentLengthViaDataReductionProxy); | 74 kDailyOriginalContentLengthViaDataReductionProxy); |
| 71 registry->RegisterListPref( | 75 registry->RegisterListPref( |
| 72 data_reduction_proxy::prefs:: | 76 data_reduction_proxy::prefs:: |
| 73 kDailyContentLengthViaDataReductionProxy); | 77 kDailyContentLengthViaDataReductionProxy); |
| 74 registry->RegisterInt64Pref( | 78 registry->RegisterInt64Pref( |
| 75 data_reduction_proxy::prefs:: | 79 data_reduction_proxy::prefs:: |
| 76 kDailyHttpContentLengthLastUpdateDate, 0L); | 80 kDailyHttpContentLengthLastUpdateDate, 0L); |
| 81 #endif // defined(OS_ANDROID) || defined(OS_IOS) |
| 77 } | 82 } |
| 78 | 83 |
| 79 TestingPrefServiceSimple pref_service_; | 84 TestingPrefServiceSimple pref_service_; |
| 80 }; | 85 }; |
| 81 | 86 |
| 82 TEST_F(ChromeNetworkDataSavingMetricsTest, TotalLengths) { | 87 TEST_F(ChromeNetworkDataSavingMetricsTest, TotalLengths) { |
| 83 const int64 kOriginalLength = 200; | 88 const int64 kOriginalLength = 200; |
| 84 const int64 kReceivedLength = 100; | 89 const int64 kReceivedLength = 100; |
| 85 | 90 |
| 86 UpdateContentLengthPrefs( | 91 UpdateContentLengthPrefs( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 98 kReceivedLength, kOriginalLength, | 103 kReceivedLength, kOriginalLength, |
| 99 false, UNKNOWN_TYPE, &pref_service_); | 104 false, UNKNOWN_TYPE, &pref_service_); |
| 100 EXPECT_EQ(kReceivedLength * 2, | 105 EXPECT_EQ(kReceivedLength * 2, |
| 101 pref_service_.GetInt64( | 106 pref_service_.GetInt64( |
| 102 data_reduction_proxy::prefs::kHttpReceivedContentLength)); | 107 data_reduction_proxy::prefs::kHttpReceivedContentLength)); |
| 103 EXPECT_EQ(kOriginalLength * 2, | 108 EXPECT_EQ(kOriginalLength * 2, |
| 104 pref_service_.GetInt64( | 109 pref_service_.GetInt64( |
| 105 data_reduction_proxy::prefs::kHttpOriginalContentLength)); | 110 data_reduction_proxy::prefs::kHttpOriginalContentLength)); |
| 106 } | 111 } |
| 107 | 112 |
| 113 #if defined(OS_ANDROID) || defined(OS_IOS) |
| 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 |
| 115 : public ChromeNetworkDataSavingMetricsTest { | 122 : public ChromeNetworkDataSavingMetricsTest { |
| 116 protected: | 123 protected: |
| 117 ChromeNetworkDailyDataSavingMetricsTest() { | 124 ChromeNetworkDailyDataSavingMetricsTest() { |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 } |
| 682 #endif // defined(OS_ANDROID) || defined(OS_IOS) |
| 675 | 683 |
| 676 } // namespace data_reduction_proxy | 684 } // namespace data_reduction_proxy |
| OLD | NEW |