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

Side by Side Diff: chrome/browser/browsing_data/passwords_counter_browsertest.cc

Issue 2153863002: Move counters for passwords, history and autofill to components (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@separate_build_targets_in_components_bd
Patch Set: Addressed comments Created 4 years, 5 months 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
« no previous file with comments | « chrome/browser/browsing_data/passwords_counter.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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 "chrome/browser/browsing_data/passwords_counter.h" 5 #include "components/browsing_data/core/counters/passwords_counter.h"
6 6
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/password_manager/password_store_factory.h" 9 #include "chrome/browser/password_manager/password_store_factory.h"
10 #include "chrome/browser/sync/test/integration/passwords_helper.h" 10 #include "chrome/browser/sync/test/integration/passwords_helper.h"
11 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/test/base/in_process_browser_test.h" 12 #include "chrome/test/base/in_process_browser_test.h"
13 #include "components/autofill/core/common/password_form.h" 13 #include "components/autofill/core/common/password_form.h"
14 #include "components/browsing_data/core/browsing_data_utils.h" 14 #include "components/browsing_data/core/browsing_data_utils.h"
15 #include "components/browsing_data/core/pref_names.h" 15 #include "components/browsing_data/core/pref_names.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 // Tests that the counter correctly counts each individual credential on 129 // Tests that the counter correctly counts each individual credential on
130 // the same domain. 130 // the same domain.
131 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, SameDomain) { 131 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, SameDomain) {
132 AddLogin("https://www.google.com", "user1", false); 132 AddLogin("https://www.google.com", "user1", false);
133 AddLogin("https://www.google.com", "user2", false); 133 AddLogin("https://www.google.com", "user2", false);
134 AddLogin("https://www.google.com", "user3", false); 134 AddLogin("https://www.google.com", "user3", false);
135 AddLogin("https://www.chrome.com", "user1", false); 135 AddLogin("https://www.chrome.com", "user1", false);
136 AddLogin("https://www.chrome.com", "user2", false); 136 AddLogin("https://www.chrome.com", "user2", false);
137 137
138 Profile* profile = browser()->profile(); 138 Profile* profile = browser()->profile();
139 PasswordsCounter counter(profile); 139 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile(
140 profile, ServiceAccessType::EXPLICIT_ACCESS));
140 counter.Init(profile->GetPrefs(), base::Bind(&PasswordsCounterTest::Callback, 141 counter.Init(profile->GetPrefs(), base::Bind(&PasswordsCounterTest::Callback,
141 base::Unretained(this))); 142 base::Unretained(this)));
142 counter.Restart(); 143 counter.Restart();
143 144
144 WaitForCounting(); 145 WaitForCounting();
145 EXPECT_EQ(5u, GetResult()); 146 EXPECT_EQ(5u, GetResult());
146 } 147 }
147 148
148 // Tests that the counter doesn't count blacklisted entries. 149 // Tests that the counter doesn't count blacklisted entries.
149 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, Blacklisted) { 150 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, Blacklisted) {
150 AddLogin("https://www.google.com", "user1", false); 151 AddLogin("https://www.google.com", "user1", false);
151 AddLogin("https://www.google.com", "user2", true); 152 AddLogin("https://www.google.com", "user2", true);
152 AddLogin("https://www.chrome.com", "user3", true); 153 AddLogin("https://www.chrome.com", "user3", true);
153 154
154 Profile* profile = browser()->profile(); 155 Profile* profile = browser()->profile();
155 PasswordsCounter counter(profile); 156 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile(
157 profile, ServiceAccessType::EXPLICIT_ACCESS));
158
156 counter.Init(profile->GetPrefs(), base::Bind(&PasswordsCounterTest::Callback, 159 counter.Init(profile->GetPrefs(), base::Bind(&PasswordsCounterTest::Callback,
157 base::Unretained(this))); 160 base::Unretained(this)));
158 counter.Restart(); 161 counter.Restart();
159 162
160 WaitForCounting(); 163 WaitForCounting();
161 EXPECT_EQ(1u, GetResult()); 164 EXPECT_EQ(1u, GetResult());
162 } 165 }
163 166
164 // Tests that the counter starts counting automatically when the deletion 167 // Tests that the counter starts counting automatically when the deletion
165 // pref changes to true. 168 // pref changes to true.
166 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, PrefChanged) { 169 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, PrefChanged) {
167 SetPasswordsDeletionPref(false); 170 SetPasswordsDeletionPref(false);
168 AddLogin("https://www.google.com", "user", false); 171 AddLogin("https://www.google.com", "user", false);
169 AddLogin("https://www.chrome.com", "user", false); 172 AddLogin("https://www.chrome.com", "user", false);
170 173
171 Profile* profile = browser()->profile(); 174 Profile* profile = browser()->profile();
172 PasswordsCounter counter(profile); 175 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile(
176 profile, ServiceAccessType::EXPLICIT_ACCESS));
173 counter.Init(profile->GetPrefs(), base::Bind(&PasswordsCounterTest::Callback, 177 counter.Init(profile->GetPrefs(), base::Bind(&PasswordsCounterTest::Callback,
174 base::Unretained(this))); 178 base::Unretained(this)));
175 SetPasswordsDeletionPref(true); 179 SetPasswordsDeletionPref(true);
176 180
177 WaitForCounting(); 181 WaitForCounting();
178 EXPECT_EQ(2u, GetResult()); 182 EXPECT_EQ(2u, GetResult());
179 } 183 }
180 184
181 // Tests that the counter does not count passwords if the deletion 185 // Tests that the counter does not count passwords if the deletion
182 // preference is false. 186 // preference is false.
183 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, PrefIsFalse) { 187 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, PrefIsFalse) {
184 SetPasswordsDeletionPref(false); 188 SetPasswordsDeletionPref(false);
185 AddLogin("https://www.google.com", "user", false); 189 AddLogin("https://www.google.com", "user", false);
186 190
187 Profile* profile = browser()->profile(); 191 Profile* profile = browser()->profile();
188 PasswordsCounter counter(profile); 192 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile(
193 profile, ServiceAccessType::EXPLICIT_ACCESS));
189 counter.Init(profile->GetPrefs(), base::Bind(&PasswordsCounterTest::Callback, 194 counter.Init(profile->GetPrefs(), base::Bind(&PasswordsCounterTest::Callback,
190 base::Unretained(this))); 195 base::Unretained(this)));
191 counter.Restart(); 196 counter.Restart();
192 197
193 EXPECT_FALSE(counter.cancelable_task_tracker()->HasTrackedTasks()); 198 EXPECT_FALSE(counter.cancelable_task_tracker()->HasTrackedTasks());
194 } 199 }
195 200
196 // Tests that the counter starts counting automatically when 201 // Tests that the counter starts counting automatically when
197 // the password store changes. 202 // the password store changes.
198 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, StoreChanged) { 203 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, StoreChanged) {
199 AddLogin("https://www.google.com", "user", false); 204 AddLogin("https://www.google.com", "user", false);
200 205
201 Profile* profile = browser()->profile(); 206 Profile* profile = browser()->profile();
202 PasswordsCounter counter(profile); 207 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile(
208 profile, ServiceAccessType::EXPLICIT_ACCESS));
203 counter.Init(profile->GetPrefs(), base::Bind(&PasswordsCounterTest::Callback, 209 counter.Init(profile->GetPrefs(), base::Bind(&PasswordsCounterTest::Callback,
204 base::Unretained(this))); 210 base::Unretained(this)));
205 counter.Restart(); 211 counter.Restart();
206 212
207 WaitForCounting(); 213 WaitForCounting();
208 EXPECT_EQ(1u, GetResult()); 214 EXPECT_EQ(1u, GetResult());
209 215
210 AddLogin("https://www.chrome.com", "user", false); 216 AddLogin("https://www.chrome.com", "user", false);
211 WaitForCounting(); 217 WaitForCounting();
212 EXPECT_EQ(2u, GetResult()); 218 EXPECT_EQ(2u, GetResult());
213 219
214 RemoveLogin("https://www.chrome.com", "user", false); 220 RemoveLogin("https://www.chrome.com", "user", false);
215 WaitForCounting(); 221 WaitForCounting();
216 EXPECT_EQ(1u, GetResult()); 222 EXPECT_EQ(1u, GetResult());
217 } 223 }
218 224
219 // Tests that changing the deletion period restarts the counting, and that 225 // Tests that changing the deletion period restarts the counting, and that
220 // the result takes login creation dates into account. 226 // the result takes login creation dates into account.
221 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, PeriodChanged) { 227 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, PeriodChanged) {
222 AddLogin("https://www.google.com", "user", false); 228 AddLogin("https://www.google.com", "user", false);
223 RevertTimeInDays(2); 229 RevertTimeInDays(2);
224 AddLogin("https://example.com", "user1", false); 230 AddLogin("https://example.com", "user1", false);
225 RevertTimeInDays(3); 231 RevertTimeInDays(3);
226 AddLogin("https://example.com", "user2", false); 232 AddLogin("https://example.com", "user2", false);
227 RevertTimeInDays(30); 233 RevertTimeInDays(30);
228 AddLogin("https://www.chrome.com", "user", false); 234 AddLogin("https://www.chrome.com", "user", false);
229 235
230 Profile* profile = browser()->profile(); 236 Profile* profile = browser()->profile();
231 PasswordsCounter counter(profile); 237 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile(
238 profile, ServiceAccessType::EXPLICIT_ACCESS));
232 counter.Init(profile->GetPrefs(), base::Bind(&PasswordsCounterTest::Callback, 239 counter.Init(profile->GetPrefs(), base::Bind(&PasswordsCounterTest::Callback,
233 base::Unretained(this))); 240 base::Unretained(this)));
234 241
235 SetDeletionPeriodPref(browsing_data::LAST_HOUR); 242 SetDeletionPeriodPref(browsing_data::LAST_HOUR);
236 WaitForCounting(); 243 WaitForCounting();
237 EXPECT_EQ(1u, GetResult()); 244 EXPECT_EQ(1u, GetResult());
238 245
239 SetDeletionPeriodPref(browsing_data::LAST_DAY); 246 SetDeletionPeriodPref(browsing_data::LAST_DAY);
240 WaitForCounting(); 247 WaitForCounting();
241 EXPECT_EQ(1u, GetResult()); 248 EXPECT_EQ(1u, GetResult());
242 249
243 SetDeletionPeriodPref(browsing_data::LAST_WEEK); 250 SetDeletionPeriodPref(browsing_data::LAST_WEEK);
244 WaitForCounting(); 251 WaitForCounting();
245 EXPECT_EQ(3u, GetResult()); 252 EXPECT_EQ(3u, GetResult());
246 253
247 SetDeletionPeriodPref(browsing_data::FOUR_WEEKS); 254 SetDeletionPeriodPref(browsing_data::FOUR_WEEKS);
248 WaitForCounting(); 255 WaitForCounting();
249 EXPECT_EQ(3u, GetResult()); 256 EXPECT_EQ(3u, GetResult());
250 257
251 SetDeletionPeriodPref(browsing_data::EVERYTHING); 258 SetDeletionPeriodPref(browsing_data::EVERYTHING);
252 WaitForCounting(); 259 WaitForCounting();
253 EXPECT_EQ(4u, GetResult()); 260 EXPECT_EQ(4u, GetResult());
254 } 261 }
255 262
256 } // namespace 263 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data/passwords_counter.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698