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 "components/data_reduction_proxy/core/browser/data_reduction_proxy_pref
s.h" | 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_pref
s.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
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" | 11 #include "base/prefs/scoped_user_pref_update.h" |
10 #include "base/prefs/testing_pref_service.h" | 12 #include "base/prefs/testing_pref_service.h" |
11 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
12 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_
names.h" | 14 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_
names.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
14 | 16 |
15 namespace data_reduction_proxy { | 17 namespace data_reduction_proxy { |
16 | 18 |
17 class DataReductionProxyPrefsTest : public testing::Test { | 19 class DataReductionProxyPrefsTest : public testing::Test { |
18 public: | 20 public: |
19 void SetUp() override { | 21 void SetUp() override { |
20 RegisterPrefs(local_state_prefs_.registry()); | 22 RegisterPrefs(local_state_prefs_.registry()); |
21 PrefRegistrySimple* profile_registry = profile_prefs_.registry(); | 23 PrefRegistrySimple* profile_registry = profile_prefs_.registry(); |
22 RegisterPrefs(profile_registry); | 24 RegisterPrefs(profile_registry); |
23 profile_registry->RegisterBooleanPref( | 25 profile_registry->RegisterBooleanPref( |
24 prefs::kStatisticsPrefsMigrated, false); | 26 prefs::kStatisticsPrefsMigrated, false); |
25 } | 27 } |
26 | 28 |
27 PrefService* local_state_prefs() { | 29 PrefService* local_state_prefs() { |
28 return &local_state_prefs_; | 30 return &local_state_prefs_; |
29 } | 31 } |
30 | 32 |
31 PrefService* profile_prefs() { | 33 PrefService* profile_prefs() { |
32 return &profile_prefs_; | 34 return &profile_prefs_; |
33 } | 35 } |
34 | 36 |
35 // Initializes a list with ten string representations of successive int64 | 37 // Initializes a list with ten string representations of successive int64_t |
36 // values, starting with |starting_value|. | 38 // values, starting with |starting_value|. |
37 void InitializeList(const char* pref_name, | 39 void InitializeList(const char* pref_name, |
38 int64 starting_value, | 40 int64_t starting_value, |
39 PrefService* pref_service) { | 41 PrefService* pref_service) { |
40 ListPrefUpdate list(local_state_prefs(), pref_name); | 42 ListPrefUpdate list(local_state_prefs(), pref_name); |
41 for (int64 i = 0; i < 10L; ++i) { | 43 for (int64_t i = 0; i < 10L; ++i) { |
42 list->Set(i, new base::StringValue( | 44 list->Set(i, new base::StringValue( |
43 base::Int64ToString(i + starting_value))); | 45 base::Int64ToString(i + starting_value))); |
44 } | 46 } |
45 } | 47 } |
46 | 48 |
47 // Verifies that ten string repreentations of successive int64 values starting | 49 // Verifies that ten string repreentations of successive int64_t values |
48 // with |starting_value| are found in the |ListValue| with the associated | 50 // starting with |starting_value| are found in the |ListValue| with the |
49 // |pref_name|. | 51 // associated |pref_name|. |
50 void VerifyList(const char* pref_name, | 52 void VerifyList(const char* pref_name, |
51 int64 starting_value, | 53 int64_t starting_value, |
52 PrefService* pref_service) { | 54 PrefService* pref_service) { |
53 const base::ListValue* list_value = pref_service->GetList(pref_name); | 55 const base::ListValue* list_value = pref_service->GetList(pref_name); |
54 for (int64 i = 0; i < 10L; ++i) { | 56 for (int64_t i = 0; i < 10L; ++i) { |
55 std::string string_value; | 57 std::string string_value; |
56 int64 value; | 58 int64_t value; |
57 list_value->GetString(i, &string_value); | 59 list_value->GetString(i, &string_value); |
58 base::StringToInt64(string_value, &value); | 60 base::StringToInt64(string_value, &value); |
59 EXPECT_EQ(i + starting_value, value); | 61 EXPECT_EQ(i + starting_value, value); |
60 } | 62 } |
61 } | 63 } |
62 | 64 |
63 private: | 65 private: |
64 void RegisterPrefs(PrefRegistrySimple* registry) { | 66 void RegisterPrefs(PrefRegistrySimple* registry) { |
65 registry->RegisterInt64Pref(prefs::kHttpReceivedContentLength, 0); | 67 registry->RegisterInt64Pref(prefs::kHttpReceivedContentLength, 0); |
66 registry->RegisterInt64Pref(prefs::kHttpOriginalContentLength, 0); | 68 registry->RegisterInt64Pref(prefs::kHttpOriginalContentLength, 0); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 EXPECT_TRUE(profile_prefs()->GetBoolean(prefs::kStatisticsPrefsMigrated)); | 208 EXPECT_TRUE(profile_prefs()->GetBoolean(prefs::kStatisticsPrefsMigrated)); |
207 | 209 |
208 // Migration should only happen once. | 210 // Migration should only happen once. |
209 local_state_prefs()->SetInt64(prefs::kHttpReceivedContentLength, 456L); | 211 local_state_prefs()->SetInt64(prefs::kHttpReceivedContentLength, 456L); |
210 data_reduction_proxy::MigrateStatisticsPrefs(local_state_prefs(), | 212 data_reduction_proxy::MigrateStatisticsPrefs(local_state_prefs(), |
211 profile_prefs()); | 213 profile_prefs()); |
212 EXPECT_EQ(123L, profile_prefs()->GetInt64(prefs::kHttpReceivedContentLength)); | 214 EXPECT_EQ(123L, profile_prefs()->GetInt64(prefs::kHttpReceivedContentLength)); |
213 } | 215 } |
214 | 216 |
215 } // namespace data_reduction_proxy | 217 } // namespace data_reduction_proxy |
OLD | NEW |