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

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

Issue 2849523003: Add billing address as a mandatory field of Payments credit cards. (Closed)
Patch Set: Components Unittests fix Created 3 years, 7 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 65
66 void ClearAutocompleteSuggestions() { 66 void ClearAutocompleteSuggestions() {
67 web_data_service_->RemoveFormElementsAddedBetween( 67 web_data_service_->RemoveFormElementsAddedBetween(
68 base::Time(), base::Time::Max()); 68 base::Time(), base::Time::Max());
69 } 69 }
70 70
71 // Credit cards -------------------------------------------------------------- 71 // Credit cards --------------------------------------------------------------
72 72
73 void AddCreditCard(const char* card_number, 73 void AddCreditCard(const char* card_number,
74 const char* exp_month, 74 const char* exp_month,
75 const char* exp_year) { 75 const char* exp_year,
76 const char* billing_address_id) {
76 autofill::CreditCard card; 77 autofill::CreditCard card;
77 autofill::test::SetCreditCardInfo(&card, nullptr, card_number, exp_month, 78 autofill::test::SetCreditCardInfo(&card, nullptr, card_number, exp_month,
78 exp_year); 79 exp_year, billing_address_id);
79 credit_card_ids_.push_back(card.guid()); 80 credit_card_ids_.push_back(card.guid());
80 web_data_service_->AddCreditCard(card); 81 web_data_service_->AddCreditCard(card);
81 } 82 }
82 83
83 void RemoveLastCreditCard() { 84 void RemoveLastCreditCard() {
84 web_data_service_->RemoveCreditCard(credit_card_ids_.back()); 85 web_data_service_->RemoveCreditCard(credit_card_ids_.back());
85 credit_card_ids_.pop_back(); 86 credit_card_ids_.pop_back();
86 } 87 }
87 88
88 // Addresses ----------------------------------------------------------------- 89 // Addresses -----------------------------------------------------------------
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, CreditCards) { 265 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, CreditCards) {
265 Profile* profile = browser()->profile(); 266 Profile* profile = browser()->profile();
266 browsing_data::AutofillCounter counter(GetWebDataService(), nullptr); 267 browsing_data::AutofillCounter counter(GetWebDataService(), nullptr);
267 counter.Init( 268 counter.Init(
268 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED, 269 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED,
269 base::Bind(&AutofillCounterTest::Callback, base::Unretained(this))); 270 base::Bind(&AutofillCounterTest::Callback, base::Unretained(this)));
270 counter.Restart(); 271 counter.Restart();
271 WaitForCounting(); 272 WaitForCounting();
272 EXPECT_EQ(0, GetNumCreditCards()); 273 EXPECT_EQ(0, GetNumCreditCards());
273 274
274 AddCreditCard("0000-0000-0000-0000", "1", "2015"); 275 AddCreditCard("0000-0000-0000-0000", "1", "2015", "1");
275 counter.Restart(); 276 counter.Restart();
276 WaitForCounting(); 277 WaitForCounting();
277 EXPECT_EQ(1, GetNumCreditCards()); 278 EXPECT_EQ(1, GetNumCreditCards());
278 279
279 AddCreditCard("0123-4567-8910-1112", "10", "2015"); 280 AddCreditCard("0123-4567-8910-1112", "10", "2015", "1");
280 counter.Restart(); 281 counter.Restart();
281 WaitForCounting(); 282 WaitForCounting();
282 EXPECT_EQ(2, GetNumCreditCards()); 283 EXPECT_EQ(2, GetNumCreditCards());
283 284
284 AddCreditCard("1211-1098-7654-3210", "10", "2030"); 285 AddCreditCard("1211-1098-7654-3210", "10", "2030", "1");
285 counter.Restart(); 286 counter.Restart();
286 WaitForCounting(); 287 WaitForCounting();
287 EXPECT_EQ(3, GetNumCreditCards()); 288 EXPECT_EQ(3, GetNumCreditCards());
288 289
289 RemoveLastCreditCard(); 290 RemoveLastCreditCard();
290 counter.Restart(); 291 counter.Restart();
291 WaitForCounting(); 292 WaitForCounting();
292 EXPECT_EQ(2, GetNumCreditCards()); 293 EXPECT_EQ(2, GetNumCreditCards());
293 294
294 ClearCreditCardsAndAddresses(); 295 ClearCreditCardsAndAddresses();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 337
337 // Tests that we return the correct complex result when counting more than 338 // Tests that we return the correct complex result when counting more than
338 // one type of items. 339 // one type of items.
339 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, ComplexResult) { 340 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, ComplexResult) {
340 AddAutocompleteSuggestion("email", "example@example.com"); 341 AddAutocompleteSuggestion("email", "example@example.com");
341 AddAutocompleteSuggestion("zip", "12345"); 342 AddAutocompleteSuggestion("zip", "12345");
342 AddAutocompleteSuggestion("tel", "+123456789"); 343 AddAutocompleteSuggestion("tel", "+123456789");
343 AddAutocompleteSuggestion("tel", "+987654321"); 344 AddAutocompleteSuggestion("tel", "+987654321");
344 AddAutocompleteSuggestion("city", "Munich"); 345 AddAutocompleteSuggestion("city", "Munich");
345 346
346 AddCreditCard("0000-0000-0000-0000", "1", "2015"); 347 AddCreditCard("0000-0000-0000-0000", "1", "2015", "1");
347 AddCreditCard("1211-1098-7654-3210", "10", "2030"); 348 AddCreditCard("1211-1098-7654-3210", "10", "2030", "1");
348 349
349 AddAddress("John", "Doe", "Main Street 12345"); 350 AddAddress("John", "Doe", "Main Street 12345");
350 AddAddress("Jane", "Smith", "Main Street 12346"); 351 AddAddress("Jane", "Smith", "Main Street 12346");
351 AddAddress("John", "Smith", "Side Street 47"); 352 AddAddress("John", "Smith", "Side Street 47");
352 353
353 Profile* profile = browser()->profile(); 354 Profile* profile = browser()->profile();
354 browsing_data::AutofillCounter counter(GetWebDataService(), nullptr); 355 browsing_data::AutofillCounter counter(GetWebDataService(), nullptr);
355 counter.Init( 356 counter.Init(
356 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED, 357 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED,
357 base::Bind(&AutofillCounterTest::Callback, base::Unretained(this))); 358 base::Bind(&AutofillCounterTest::Callback, base::Unretained(this)));
358 counter.Restart(); 359 counter.Restart();
359 WaitForCounting(); 360 WaitForCounting();
360 EXPECT_EQ(5, GetNumSuggestions()); 361 EXPECT_EQ(5, GetNumSuggestions());
361 EXPECT_EQ(2, GetNumCreditCards()); 362 EXPECT_EQ(2, GetNumCreditCards());
362 EXPECT_EQ(3, GetNumAddresses()); 363 EXPECT_EQ(3, GetNumAddresses());
363 } 364 }
364 365
365 // Tests that the counting respects time ranges. 366 // Tests that the counting respects time ranges.
366 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, TimeRanges) { 367 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, TimeRanges) {
367 // This test makes time comparisons that are precise to a microsecond, but the 368 // This test makes time comparisons that are precise to a microsecond, but the
368 // database uses the time_t format which is only precise to a second. 369 // database uses the time_t format which is only precise to a second.
369 // Make sure we use timestamps rounded to a second. 370 // Make sure we use timestamps rounded to a second.
370 base::Time time1 = base::Time::FromTimeT(base::Time::Now().ToTimeT()); 371 base::Time time1 = base::Time::FromTimeT(base::Time::Now().ToTimeT());
371 372
372 AddAutocompleteSuggestion("email", "example@example.com"); 373 AddAutocompleteSuggestion("email", "example@example.com");
373 AddCreditCard("0000-0000-0000-0000", "1", "2015"); 374 AddCreditCard("0000-0000-0000-0000", "1", "2015", "1");
374 AddAddress("John", "Doe", "Main Street 12345"); 375 AddAddress("John", "Doe", "Main Street 12345");
375 WaitForDBThread(); 376 WaitForDBThread();
376 377
377 // Skip at least a second has passed and add another batch. 378 // Skip at least a second has passed and add another batch.
378 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1)); 379 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
379 base::Time time2 = base::Time::FromTimeT(base::Time::Now().ToTimeT()); 380 base::Time time2 = base::Time::FromTimeT(base::Time::Now().ToTimeT());
380 381
381 AddCreditCard("0123-4567-8910-1112", "10", "2015"); 382 AddCreditCard("0123-4567-8910-1112", "10", "2015", "1");
382 AddAddress("Jane", "Smith", "Main Street 12346"); 383 AddAddress("Jane", "Smith", "Main Street 12346");
383 AddAddress("John", "Smith", "Side Street 47"); 384 AddAddress("John", "Smith", "Side Street 47");
384 WaitForDBThread(); 385 WaitForDBThread();
385 386
386 // Skip at least a second has passed and add another batch. 387 // Skip at least a second has passed and add another batch.
387 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1)); 388 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
388 base::Time time3 = base::Time::FromTimeT(base::Time::Now().ToTimeT()); 389 base::Time time3 = base::Time::FromTimeT(base::Time::Now().ToTimeT());
389 390
390 AddAutocompleteSuggestion("tel", "+987654321"); 391 AddAutocompleteSuggestion("tel", "+987654321");
391 AddCreditCard("1211-1098-7654-3210", "10", "2030"); 392 AddCreditCard("1211-1098-7654-3210", "10", "2030", "1");
392 WaitForDBThread(); 393 WaitForDBThread();
393 394
394 // Test the results for different starting points. 395 // Test the results for different starting points.
395 struct TestCase { 396 struct TestCase {
396 const base::Time period_start; 397 const base::Time period_start;
397 const browsing_data::BrowsingDataCounter::ResultInt 398 const browsing_data::BrowsingDataCounter::ResultInt
398 expected_num_suggestions; 399 expected_num_suggestions;
399 const browsing_data::BrowsingDataCounter::ResultInt 400 const browsing_data::BrowsingDataCounter::ResultInt
400 expected_num_credit_cards; 401 expected_num_credit_cards;
401 const browsing_data::BrowsingDataCounter::ResultInt expected_num_addresses; 402 const browsing_data::BrowsingDataCounter::ResultInt expected_num_addresses;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 WaitForCountingOrConfirmFinished(); 484 WaitForCountingOrConfirmFinished();
484 EXPECT_TRUE(AutofillSyncEnabled()); 485 EXPECT_TRUE(AutofillSyncEnabled());
485 486
486 // Stopping the Sync service triggers a restart. 487 // Stopping the Sync service triggers a restart.
487 sync_service->RequestStop(syncer::SyncService::CLEAR_DATA); 488 sync_service->RequestStop(syncer::SyncService::CLEAR_DATA);
488 WaitForCountingOrConfirmFinished(); 489 WaitForCountingOrConfirmFinished();
489 EXPECT_FALSE(AutofillSyncEnabled()); 490 EXPECT_FALSE(AutofillSyncEnabled());
490 } 491 }
491 492
492 } // namespace 493 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698