Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Side by Side Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs_unittest.cc

Issue 2447013003: Remove unused DRP code for migrating prefs (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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> 7 #include <stdint.h>
8 8
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h" 10 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h"
11 #include "components/prefs/pref_registry_simple.h" 11 #include "components/prefs/pref_registry_simple.h"
12 #include "components/prefs/pref_service.h" 12 #include "components/prefs/pref_service.h"
13 #include "components/prefs/scoped_user_pref_update.h" 13 #include "components/prefs/scoped_user_pref_update.h"
14 #include "components/prefs/testing_pref_service.h" 14 #include "components/prefs/testing_pref_service.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace data_reduction_proxy { 17 namespace data_reduction_proxy {
18 18
19 class DataReductionProxyPrefsTest : public testing::Test { 19 class DataReductionProxyPrefsTest : public testing::Test {
20 public: 20 public:
21 void SetUp() override { 21 void SetUp() override {
22 RegisterPrefs(local_state_prefs_.registry()); 22 RegisterPrefs(local_state_prefs_.registry());
23 PrefRegistrySimple* profile_registry = profile_prefs_.registry(); 23 PrefRegistrySimple* profile_registry = profile_prefs_.registry();
24 RegisterPrefs(profile_registry); 24 RegisterPrefs(profile_registry);
25 profile_registry->RegisterBooleanPref(
26 prefs::kStatisticsPrefsMigrated, false);
27 } 25 }
28 26
29 PrefService* local_state_prefs() { 27 PrefService* local_state_prefs() {
30 return &local_state_prefs_; 28 return &local_state_prefs_;
31 } 29 }
32 30
33 PrefService* profile_prefs() { 31 PrefService* profile_prefs() {
34 return &profile_prefs_; 32 return &profile_prefs_;
35 } 33 }
36 34
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 prefs::kDailyOriginalContentLengthViaDataReductionProxy); 83 prefs::kDailyOriginalContentLengthViaDataReductionProxy);
86 registry->RegisterListPref(prefs::kDailyContentLengthViaDataReductionProxy); 84 registry->RegisterListPref(prefs::kDailyContentLengthViaDataReductionProxy);
87 registry->RegisterInt64Pref( 85 registry->RegisterInt64Pref(
88 prefs::kDailyHttpContentLengthLastUpdateDate, 0L); 86 prefs::kDailyHttpContentLengthLastUpdateDate, 0L);
89 } 87 }
90 88
91 TestingPrefServiceSimple local_state_prefs_; 89 TestingPrefServiceSimple local_state_prefs_;
92 TestingPrefServiceSimple profile_prefs_; 90 TestingPrefServiceSimple profile_prefs_;
93 }; 91 };
94 92
95 TEST_F(DataReductionProxyPrefsTest, TestMigration) {
96 local_state_prefs()->SetInt64(prefs::kHttpReceivedContentLength, 123L);
97 local_state_prefs()->SetInt64(prefs::kHttpOriginalContentLength, 234L);
98 local_state_prefs()->SetInt64(
99 prefs::kDailyHttpContentLengthLastUpdateDate, 345L);
100 InitializeList(
101 prefs::kDailyHttpOriginalContentLength, 0L, local_state_prefs());
102 InitializeList(
103 prefs::kDailyHttpReceivedContentLength, 1L, local_state_prefs());
104 InitializeList(
105 prefs::kDailyOriginalContentLengthWithDataReductionProxyEnabled,
106 2L,
107 local_state_prefs());
108 InitializeList(
109 prefs::kDailyContentLengthWithDataReductionProxyEnabled,
110 3L,
111 local_state_prefs());
112 InitializeList(
113 prefs::kDailyContentLengthHttpsWithDataReductionProxyEnabled,
114 4L,
115 local_state_prefs());
116 InitializeList(
117 prefs::kDailyContentLengthShortBypassWithDataReductionProxyEnabled,
118 5L,
119 local_state_prefs());
120 InitializeList(
121 prefs::kDailyContentLengthLongBypassWithDataReductionProxyEnabled,
122 6L,
123 local_state_prefs());
124 InitializeList(
125 prefs::kDailyContentLengthUnknownWithDataReductionProxyEnabled,
126 7L,
127 local_state_prefs());
128 InitializeList(
129 prefs::kDailyOriginalContentLengthViaDataReductionProxy,
130 8L,
131 local_state_prefs());
132 InitializeList(
133 prefs::kDailyContentLengthViaDataReductionProxy,
134 9L,
135 local_state_prefs());
136
137 EXPECT_EQ(0L, profile_prefs()->GetInt64(prefs::kHttpReceivedContentLength));
138 EXPECT_EQ(0L, profile_prefs()->GetInt64(prefs::kHttpOriginalContentLength));
139 EXPECT_EQ(0u, profile_prefs()->GetList(
140 prefs::kDailyHttpOriginalContentLength)->GetSize());
141 EXPECT_EQ(0u, profile_prefs()->GetList(
142 prefs::kDailyHttpReceivedContentLength)->GetSize());
143 EXPECT_EQ(0u, profile_prefs()->GetList(
144 prefs::kDailyOriginalContentLengthWithDataReductionProxyEnabled)->
145 GetSize());
146 EXPECT_EQ(0u, profile_prefs()->GetList(
147 prefs::kDailyContentLengthWithDataReductionProxyEnabled)->GetSize());
148 EXPECT_EQ(0u, profile_prefs()->GetList(
149 prefs::kDailyContentLengthHttpsWithDataReductionProxyEnabled)->GetSize());
150 EXPECT_EQ(0u, profile_prefs()->GetList(
151 prefs::kDailyContentLengthShortBypassWithDataReductionProxyEnabled)->
152 GetSize());
153 EXPECT_EQ(0u, profile_prefs()->GetList(
154 prefs::kDailyContentLengthLongBypassWithDataReductionProxyEnabled)->
155 GetSize());
156 EXPECT_EQ(0u, profile_prefs()->GetList(
157 prefs::kDailyContentLengthUnknownWithDataReductionProxyEnabled)->
158 GetSize());
159 EXPECT_EQ(0u, profile_prefs()->GetList(
160 prefs::kDailyOriginalContentLengthViaDataReductionProxy)->GetSize());
161 EXPECT_EQ(0u, profile_prefs()->GetList(
162 prefs::kDailyContentLengthViaDataReductionProxy)->GetSize());
163 EXPECT_EQ(0L, profile_prefs()->GetInt64(
164 prefs::kDailyHttpContentLengthLastUpdateDate));
165 EXPECT_FALSE(profile_prefs()->GetBoolean(prefs::kStatisticsPrefsMigrated));
166
167 data_reduction_proxy::MigrateStatisticsPrefs(local_state_prefs(),
168 profile_prefs());
169
170 EXPECT_EQ(123L, profile_prefs()->GetInt64(prefs::kHttpReceivedContentLength));
171 EXPECT_EQ(234L, profile_prefs()->GetInt64(prefs::kHttpOriginalContentLength));
172 VerifyList(prefs::kDailyHttpOriginalContentLength, 0L, profile_prefs());
173 VerifyList(prefs::kDailyHttpReceivedContentLength, 1L, profile_prefs());
174 VerifyList(
175 prefs::kDailyOriginalContentLengthWithDataReductionProxyEnabled,
176 2L,
177 profile_prefs());
178 VerifyList(
179 prefs::kDailyContentLengthWithDataReductionProxyEnabled,
180 3L,
181 profile_prefs());
182 VerifyList(
183 prefs::kDailyContentLengthHttpsWithDataReductionProxyEnabled,
184 4L,
185 profile_prefs());
186 VerifyList(
187 prefs::kDailyContentLengthShortBypassWithDataReductionProxyEnabled,
188 5L,
189 profile_prefs());
190 VerifyList(
191 prefs::kDailyContentLengthLongBypassWithDataReductionProxyEnabled,
192 6L,
193 profile_prefs());
194 VerifyList(
195 prefs::kDailyContentLengthUnknownWithDataReductionProxyEnabled,
196 7L,
197 profile_prefs());
198 VerifyList(
199 prefs::kDailyOriginalContentLengthViaDataReductionProxy,
200 8L,
201 profile_prefs());
202 VerifyList(
203 prefs::kDailyContentLengthViaDataReductionProxy,
204 9L,
205 profile_prefs());
206 EXPECT_EQ(345L, profile_prefs()->GetInt64(
207 prefs::kDailyHttpContentLengthLastUpdateDate));
208 EXPECT_TRUE(profile_prefs()->GetBoolean(prefs::kStatisticsPrefsMigrated));
209
210 // Migration should only happen once.
211 local_state_prefs()->SetInt64(prefs::kHttpReceivedContentLength, 456L);
212 data_reduction_proxy::MigrateStatisticsPrefs(local_state_prefs(),
213 profile_prefs());
214 EXPECT_EQ(123L, profile_prefs()->GetInt64(prefs::kHttpReceivedContentLength));
215 }
216
217 } // namespace data_reduction_proxy 93 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698