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

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

Issue 2084903002: Moved BrowsingDataCounter and part of BrowsingDataCounterUtils to components. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed deps Created 4 years, 6 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
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/autofill_counter.h" 5 #include "chrome/browser/browsing_data/autofill_counter.h"
6 6
7 #include "base/guid.h" 7 #include "base/guid.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 BrowsingDataCounter::ResultInt num_addresses_; 191 BrowsingDataCounter::ResultInt num_addresses_;
192 192
193 DISALLOW_COPY_AND_ASSIGN(AutofillCounterTest); 193 DISALLOW_COPY_AND_ASSIGN(AutofillCounterTest);
194 }; 194 };
195 195
196 // Tests that the counter does not count when the form data deletion preference 196 // Tests that the counter does not count when the form data deletion preference
197 // is false. 197 // is false.
198 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, PrefIsFalse) { 198 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, PrefIsFalse) {
199 SetAutofillDeletionPref(false); 199 SetAutofillDeletionPref(false);
200 200
201 AutofillCounter counter; 201 Profile* profile = browser()->profile();
202 counter.Init(browser()->profile(), 202 AutofillCounter counter(profile);
203 base::Bind(&AutofillCounterTest::Callback, 203 counter.Init(
204 base::Unretained(this))); 204 profile->GetPrefs(), prefs::kDeleteTimePeriod,
205 base::Bind(&AutofillCounterTest::Callback, base::Unretained(this)));
205 counter.Restart(); 206 counter.Restart();
206 207
207 EXPECT_FALSE(counter.HasPendingQuery()); 208 EXPECT_FALSE(counter.HasPendingQuery());
208 } 209 }
209 210
210 // Tests that we count the correct number of autocomplete suggestions. 211 // Tests that we count the correct number of autocomplete suggestions.
211 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, AutocompleteSuggestions) { 212 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, AutocompleteSuggestions) {
212 AutofillCounter counter; 213 Profile* profile = browser()->profile();
213 counter.Init(browser()->profile(), 214 AutofillCounter counter(profile);
214 base::Bind(&AutofillCounterTest::Callback, 215 counter.Init(
215 base::Unretained(this))); 216 profile->GetPrefs(), prefs::kDeleteTimePeriod,
217 base::Bind(&AutofillCounterTest::Callback, base::Unretained(this)));
216 counter.Restart(); 218 counter.Restart();
217 WaitForCounting(); 219 WaitForCounting();
218 EXPECT_EQ(0, GetNumSuggestions()); 220 EXPECT_EQ(0, GetNumSuggestions());
219 221
220 AddAutocompleteSuggestion("email", "example@example.com"); 222 AddAutocompleteSuggestion("email", "example@example.com");
221 counter.Restart(); 223 counter.Restart();
222 WaitForCounting(); 224 WaitForCounting();
223 EXPECT_EQ(1, GetNumSuggestions()); 225 EXPECT_EQ(1, GetNumSuggestions());
224 226
225 AddAutocompleteSuggestion("tel", "+123456789"); 227 AddAutocompleteSuggestion("tel", "+123456789");
(...skipping 12 matching lines...) Expand all
238 EXPECT_EQ(2, GetNumSuggestions()); 240 EXPECT_EQ(2, GetNumSuggestions());
239 241
240 ClearAutocompleteSuggestions(); 242 ClearAutocompleteSuggestions();
241 counter.Restart(); 243 counter.Restart();
242 WaitForCounting(); 244 WaitForCounting();
243 EXPECT_EQ(0, GetNumSuggestions()); 245 EXPECT_EQ(0, GetNumSuggestions());
244 } 246 }
245 247
246 // Tests that we count the correct number of credit cards. 248 // Tests that we count the correct number of credit cards.
247 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, CreditCards) { 249 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, CreditCards) {
248 AutofillCounter counter; 250 Profile* profile = browser()->profile();
249 counter.Init(browser()->profile(), 251 AutofillCounter counter(profile);
250 base::Bind(&AutofillCounterTest::Callback, 252 counter.Init(
251 base::Unretained(this))); 253 profile->GetPrefs(), prefs::kDeleteTimePeriod,
254 base::Bind(&AutofillCounterTest::Callback, base::Unretained(this)));
252 counter.Restart(); 255 counter.Restart();
253 WaitForCounting(); 256 WaitForCounting();
254 EXPECT_EQ(0, GetNumCreditCards()); 257 EXPECT_EQ(0, GetNumCreditCards());
255 258
256 AddCreditCard("0000-0000-0000-0000", 1, 2015); 259 AddCreditCard("0000-0000-0000-0000", 1, 2015);
257 counter.Restart(); 260 counter.Restart();
258 WaitForCounting(); 261 WaitForCounting();
259 EXPECT_EQ(1, GetNumCreditCards()); 262 EXPECT_EQ(1, GetNumCreditCards());
260 263
261 AddCreditCard("0123-4567-8910-1112", 10, 2015); 264 AddCreditCard("0123-4567-8910-1112", 10, 2015);
(...skipping 12 matching lines...) Expand all
274 EXPECT_EQ(2, GetNumCreditCards()); 277 EXPECT_EQ(2, GetNumCreditCards());
275 278
276 ClearCreditCardsAndAddresses(); 279 ClearCreditCardsAndAddresses();
277 counter.Restart(); 280 counter.Restart();
278 WaitForCounting(); 281 WaitForCounting();
279 EXPECT_EQ(0, GetNumCreditCards()); 282 EXPECT_EQ(0, GetNumCreditCards());
280 } 283 }
281 284
282 // Tests that we count the correct number of addresses. 285 // Tests that we count the correct number of addresses.
283 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, Addresses) { 286 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, Addresses) {
284 AutofillCounter counter; 287 Profile* profile = browser()->profile();
285 counter.Init(browser()->profile(), 288 AutofillCounter counter(profile);
286 base::Bind(&AutofillCounterTest::Callback, 289 counter.Init(
287 base::Unretained(this))); 290 profile->GetPrefs(), prefs::kDeleteTimePeriod,
291 base::Bind(&AutofillCounterTest::Callback, base::Unretained(this)));
288 counter.Restart(); 292 counter.Restart();
289 WaitForCounting(); 293 WaitForCounting();
290 EXPECT_EQ(0, GetNumAddresses()); 294 EXPECT_EQ(0, GetNumAddresses());
291 295
292 AddAddress("John", "Doe", "Main Street 12345"); 296 AddAddress("John", "Doe", "Main Street 12345");
293 counter.Restart(); 297 counter.Restart();
294 WaitForCounting(); 298 WaitForCounting();
295 EXPECT_EQ(1, GetNumAddresses()); 299 EXPECT_EQ(1, GetNumAddresses());
296 300
297 AddAddress("Jane", "Smith", "Main Street 12346"); 301 AddAddress("Jane", "Smith", "Main Street 12346");
(...skipping 26 matching lines...) Expand all
324 AddAutocompleteSuggestion("tel", "+987654321"); 328 AddAutocompleteSuggestion("tel", "+987654321");
325 AddAutocompleteSuggestion("city", "Munich"); 329 AddAutocompleteSuggestion("city", "Munich");
326 330
327 AddCreditCard("0000-0000-0000-0000", 1, 2015); 331 AddCreditCard("0000-0000-0000-0000", 1, 2015);
328 AddCreditCard("1211-1098-7654-3210", 10, 2030); 332 AddCreditCard("1211-1098-7654-3210", 10, 2030);
329 333
330 AddAddress("John", "Doe", "Main Street 12345"); 334 AddAddress("John", "Doe", "Main Street 12345");
331 AddAddress("Jane", "Smith", "Main Street 12346"); 335 AddAddress("Jane", "Smith", "Main Street 12346");
332 AddAddress("John", "Smith", "Side Street 47"); 336 AddAddress("John", "Smith", "Side Street 47");
333 337
334 AutofillCounter counter; 338 Profile* profile = browser()->profile();
335 counter.Init(browser()->profile(), 339 AutofillCounter counter(profile);
336 base::Bind(&AutofillCounterTest::Callback, 340 counter.Init(
337 base::Unretained(this))); 341 profile->GetPrefs(), prefs::kDeleteTimePeriod,
342 base::Bind(&AutofillCounterTest::Callback, base::Unretained(this)));
338 counter.Restart(); 343 counter.Restart();
339 WaitForCounting(); 344 WaitForCounting();
340 EXPECT_EQ(5, GetNumSuggestions()); 345 EXPECT_EQ(5, GetNumSuggestions());
341 EXPECT_EQ(2, GetNumCreditCards()); 346 EXPECT_EQ(2, GetNumCreditCards());
342 EXPECT_EQ(3, GetNumAddresses()); 347 EXPECT_EQ(3, GetNumAddresses());
343 } 348 }
344 349
345 // Tests that the counting respects time ranges. 350 // Tests that the counting respects time ranges.
346 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, TimeRanges) { 351 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, TimeRanges) {
347 // This test makes time comparisons that are precise to a microsecond, but the 352 // This test makes time comparisons that are precise to a microsecond, but the
(...skipping 29 matching lines...) Expand all
377 const BrowsingDataCounter::ResultInt expected_num_suggestions; 382 const BrowsingDataCounter::ResultInt expected_num_suggestions;
378 const BrowsingDataCounter::ResultInt expected_num_credit_cards; 383 const BrowsingDataCounter::ResultInt expected_num_credit_cards;
379 const BrowsingDataCounter::ResultInt expected_num_addresses; 384 const BrowsingDataCounter::ResultInt expected_num_addresses;
380 } test_cases[] = { 385 } test_cases[] = {
381 { base::Time(), 2, 3, 3}, 386 { base::Time(), 2, 3, 3},
382 { time1, 2, 3, 3}, 387 { time1, 2, 3, 3},
383 { time2, 1, 2, 2}, 388 { time2, 1, 2, 2},
384 { time3, 1, 1, 0} 389 { time3, 1, 1, 0}
385 }; 390 };
386 391
387 AutofillCounter counter; 392 Profile* profile = browser()->profile();
388 counter.Init(browser()->profile(), 393 AutofillCounter counter(profile);
389 base::Bind(&AutofillCounterTest::Callback, 394 counter.Init(
390 base::Unretained(this))); 395 profile->GetPrefs(), prefs::kDeleteTimePeriod,
396 base::Bind(&AutofillCounterTest::Callback, base::Unretained(this)));
391 397
392 for (const TestCase& test_case : test_cases) { 398 for (const TestCase& test_case : test_cases) {
393 counter.SetPeriodStartForTesting(test_case.period_start); 399 counter.SetPeriodStartForTesting(test_case.period_start);
394 counter.Restart(); 400 counter.Restart();
395 WaitForCounting(); 401 WaitForCounting();
396 EXPECT_EQ(test_case.expected_num_suggestions, GetNumSuggestions()); 402 EXPECT_EQ(test_case.expected_num_suggestions, GetNumSuggestions());
397 EXPECT_EQ(test_case.expected_num_credit_cards, GetNumCreditCards()); 403 EXPECT_EQ(test_case.expected_num_credit_cards, GetNumCreditCards());
398 EXPECT_EQ(test_case.expected_num_addresses, GetNumAddresses()); 404 EXPECT_EQ(test_case.expected_num_addresses, GetNumAddresses());
399 } 405 }
400 } 406 }
401 407
402 } // namespace 408 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698