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

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

Issue 2249773002: Scan card holder name. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 "components/browsing_data/core/counters/autofill_counter.h" 5 #include "components/browsing_data/core/counters/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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 base::ASCIIToUTF16(value)); 59 base::ASCIIToUTF16(value));
60 } 60 }
61 61
62 void ClearAutocompleteSuggestions() { 62 void ClearAutocompleteSuggestions() {
63 web_data_service_->RemoveFormElementsAddedBetween( 63 web_data_service_->RemoveFormElementsAddedBetween(
64 base::Time(), base::Time::Max()); 64 base::Time(), base::Time::Max());
65 } 65 }
66 66
67 // Credit cards -------------------------------------------------------------- 67 // Credit cards --------------------------------------------------------------
68 68
69 void AddCreditCard(const std::string& card_number, 69 void AddCreditCard(const std::string& card_holder_name,
70 const std::string& card_number,
70 int exp_month, 71 int exp_month,
71 int exp_year) { 72 int exp_year) {
72 autofill::CreditCard card( 73 autofill::CreditCard card(base::ASCIIToUTF16(card_holder_name),
73 base::ASCIIToUTF16(card_number), exp_month, exp_year); 74 base::ASCIIToUTF16(card_number), exp_month,
75 exp_year);
74 std::string id = base::GenerateGUID(); 76 std::string id = base::GenerateGUID();
75 credit_card_ids_.push_back(id); 77 credit_card_ids_.push_back(id);
76 card.set_guid(id); 78 card.set_guid(id);
77 web_data_service_->AddCreditCard(card); 79 web_data_service_->AddCreditCard(card);
78 } 80 }
79 81
80 void RemoveLastCreditCard() { 82 void RemoveLastCreditCard() {
81 web_data_service_->RemoveCreditCard(credit_card_ids_.back()); 83 web_data_service_->RemoveCreditCard(credit_card_ids_.back());
82 credit_card_ids_.pop_back(); 84 credit_card_ids_.pop_back();
83 } 85 }
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 // Tests that we count the correct number of credit cards. 257 // Tests that we count the correct number of credit cards.
256 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, CreditCards) { 258 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, CreditCards) {
257 Profile* profile = browser()->profile(); 259 Profile* profile = browser()->profile();
258 browsing_data::AutofillCounter counter(GetWebDataService()); 260 browsing_data::AutofillCounter counter(GetWebDataService());
259 counter.Init(profile->GetPrefs(), base::Bind(&AutofillCounterTest::Callback, 261 counter.Init(profile->GetPrefs(), base::Bind(&AutofillCounterTest::Callback,
260 base::Unretained(this))); 262 base::Unretained(this)));
261 counter.Restart(); 263 counter.Restart();
262 WaitForCounting(); 264 WaitForCounting();
263 EXPECT_EQ(0, GetNumCreditCards()); 265 EXPECT_EQ(0, GetNumCreditCards());
264 266
265 AddCreditCard("0000-0000-0000-0000", 1, 2015); 267 AddCreditCard("Alice", "0000-0000-0000-0000", 1, 2015);
266 counter.Restart(); 268 counter.Restart();
267 WaitForCounting(); 269 WaitForCounting();
268 EXPECT_EQ(1, GetNumCreditCards()); 270 EXPECT_EQ(1, GetNumCreditCards());
269 271
270 AddCreditCard("0123-4567-8910-1112", 10, 2015); 272 AddCreditCard("Bob", "0123-4567-8910-1112", 10, 2015);
271 counter.Restart(); 273 counter.Restart();
272 WaitForCounting(); 274 WaitForCounting();
273 EXPECT_EQ(2, GetNumCreditCards()); 275 EXPECT_EQ(2, GetNumCreditCards());
274 276
275 AddCreditCard("1211-1098-7654-3210", 10, 2030); 277 AddCreditCard("Carol", "1211-1098-7654-3210", 10, 2030);
276 counter.Restart(); 278 counter.Restart();
277 WaitForCounting(); 279 WaitForCounting();
278 EXPECT_EQ(3, GetNumCreditCards()); 280 EXPECT_EQ(3, GetNumCreditCards());
279 281
280 RemoveLastCreditCard(); 282 RemoveLastCreditCard();
281 counter.Restart(); 283 counter.Restart();
282 WaitForCounting(); 284 WaitForCounting();
283 EXPECT_EQ(2, GetNumCreditCards()); 285 EXPECT_EQ(2, GetNumCreditCards());
284 286
285 ClearCreditCardsAndAddresses(); 287 ClearCreditCardsAndAddresses();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 328
327 // Tests that we return the correct complex result when counting more than 329 // Tests that we return the correct complex result when counting more than
328 // one type of items. 330 // one type of items.
329 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, ComplexResult) { 331 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, ComplexResult) {
330 AddAutocompleteSuggestion("email", "example@example.com"); 332 AddAutocompleteSuggestion("email", "example@example.com");
331 AddAutocompleteSuggestion("zip", "12345"); 333 AddAutocompleteSuggestion("zip", "12345");
332 AddAutocompleteSuggestion("tel", "+123456789"); 334 AddAutocompleteSuggestion("tel", "+123456789");
333 AddAutocompleteSuggestion("tel", "+987654321"); 335 AddAutocompleteSuggestion("tel", "+987654321");
334 AddAutocompleteSuggestion("city", "Munich"); 336 AddAutocompleteSuggestion("city", "Munich");
335 337
336 AddCreditCard("0000-0000-0000-0000", 1, 2015); 338 AddCreditCard("Alice", "0000-0000-0000-0000", 1, 2015);
337 AddCreditCard("1211-1098-7654-3210", 10, 2030); 339 AddCreditCard("Bob", "1211-1098-7654-3210", 10, 2030);
338 340
339 AddAddress("John", "Doe", "Main Street 12345"); 341 AddAddress("John", "Doe", "Main Street 12345");
340 AddAddress("Jane", "Smith", "Main Street 12346"); 342 AddAddress("Jane", "Smith", "Main Street 12346");
341 AddAddress("John", "Smith", "Side Street 47"); 343 AddAddress("John", "Smith", "Side Street 47");
342 344
343 Profile* profile = browser()->profile(); 345 Profile* profile = browser()->profile();
344 browsing_data::AutofillCounter counter(GetWebDataService()); 346 browsing_data::AutofillCounter counter(GetWebDataService());
345 counter.Init(profile->GetPrefs(), base::Bind(&AutofillCounterTest::Callback, 347 counter.Init(profile->GetPrefs(), base::Bind(&AutofillCounterTest::Callback,
346 base::Unretained(this))); 348 base::Unretained(this)));
347 counter.Restart(); 349 counter.Restart();
348 WaitForCounting(); 350 WaitForCounting();
349 EXPECT_EQ(5, GetNumSuggestions()); 351 EXPECT_EQ(5, GetNumSuggestions());
350 EXPECT_EQ(2, GetNumCreditCards()); 352 EXPECT_EQ(2, GetNumCreditCards());
351 EXPECT_EQ(3, GetNumAddresses()); 353 EXPECT_EQ(3, GetNumAddresses());
352 } 354 }
353 355
354 // Tests that the counting respects time ranges. 356 // Tests that the counting respects time ranges.
355 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, TimeRanges) { 357 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, TimeRanges) {
356 // This test makes time comparisons that are precise to a microsecond, but the 358 // This test makes time comparisons that are precise to a microsecond, but the
357 // database uses the time_t format which is only precise to a second. 359 // database uses the time_t format which is only precise to a second.
358 // Make sure we use timestamps rounded to a second. 360 // Make sure we use timestamps rounded to a second.
359 base::Time time1 = base::Time::FromTimeT(base::Time::Now().ToTimeT()); 361 base::Time time1 = base::Time::FromTimeT(base::Time::Now().ToTimeT());
360 362
361 AddAutocompleteSuggestion("email", "example@example.com"); 363 AddAutocompleteSuggestion("email", "example@example.com");
362 AddCreditCard("0000-0000-0000-0000", 1, 2015); 364 AddCreditCard("Alice", "0000-0000-0000-0000", 1, 2015);
363 AddAddress("John", "Doe", "Main Street 12345"); 365 AddAddress("John", "Doe", "Main Street 12345");
364 WaitForDBThread(); 366 WaitForDBThread();
365 367
366 // Skip at least a second has passed and add another batch. 368 // Skip at least a second has passed and add another batch.
367 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1)); 369 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
368 base::Time time2 = base::Time::FromTimeT(base::Time::Now().ToTimeT()); 370 base::Time time2 = base::Time::FromTimeT(base::Time::Now().ToTimeT());
369 371
370 AddCreditCard("0123-4567-8910-1112", 10, 2015); 372 AddCreditCard("Bob", "0123-4567-8910-1112", 10, 2015);
371 AddAddress("Jane", "Smith", "Main Street 12346"); 373 AddAddress("Jane", "Smith", "Main Street 12346");
372 AddAddress("John", "Smith", "Side Street 47"); 374 AddAddress("John", "Smith", "Side Street 47");
373 WaitForDBThread(); 375 WaitForDBThread();
374 376
375 // Skip at least a second has passed and add another batch. 377 // Skip at least a second has passed and add another batch.
376 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1)); 378 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
377 base::Time time3 = base::Time::FromTimeT(base::Time::Now().ToTimeT()); 379 base::Time time3 = base::Time::FromTimeT(base::Time::Now().ToTimeT());
378 380
379 AddAutocompleteSuggestion("tel", "+987654321"); 381 AddAutocompleteSuggestion("tel", "+987654321");
380 AddCreditCard("1211-1098-7654-3210", 10, 2030); 382 AddCreditCard("Carol", "1211-1098-7654-3210", 10, 2030);
381 WaitForDBThread(); 383 WaitForDBThread();
382 384
383 // Test the results for different starting points. 385 // Test the results for different starting points.
384 struct TestCase { 386 struct TestCase {
385 const base::Time period_start; 387 const base::Time period_start;
386 const browsing_data::BrowsingDataCounter::ResultInt 388 const browsing_data::BrowsingDataCounter::ResultInt
387 expected_num_suggestions; 389 expected_num_suggestions;
388 const browsing_data::BrowsingDataCounter::ResultInt 390 const browsing_data::BrowsingDataCounter::ResultInt
389 expected_num_credit_cards; 391 expected_num_credit_cards;
390 const browsing_data::BrowsingDataCounter::ResultInt expected_num_addresses; 392 const browsing_data::BrowsingDataCounter::ResultInt expected_num_addresses;
(...skipping 13 matching lines...) Expand all
404 counter.SetPeriodStartForTesting(test_case.period_start); 406 counter.SetPeriodStartForTesting(test_case.period_start);
405 counter.Restart(); 407 counter.Restart();
406 WaitForCounting(); 408 WaitForCounting();
407 EXPECT_EQ(test_case.expected_num_suggestions, GetNumSuggestions()); 409 EXPECT_EQ(test_case.expected_num_suggestions, GetNumSuggestions());
408 EXPECT_EQ(test_case.expected_num_credit_cards, GetNumCreditCards()); 410 EXPECT_EQ(test_case.expected_num_credit_cards, GetNumCreditCards());
409 EXPECT_EQ(test_case.expected_num_addresses, GetNumAddresses()); 411 EXPECT_EQ(test_case.expected_num_addresses, GetNumAddresses());
410 } 412 }
411 } 413 }
412 414
413 } // namespace 415 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698