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

Side by Side Diff: components/autofill/core/browser/personal_data_manager_unittest.cc

Issue 1867523003: [Autofill] Suggest expired credit cards last. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 8 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 | « components/autofill/core/browser/personal_data_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/autofill/core/browser/personal_data_manager.h" 5 #include "components/autofill/core/browser/personal_data_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 base::TimeDelta::FromDays(10)); 243 base::TimeDelta::FromDays(10));
244 test::SetCreditCardInfo(&credit_card1, "John Dillinger", 244 test::SetCreditCardInfo(&credit_card1, "John Dillinger",
245 "423456789012" /* Visa */, "01", "2999"); 245 "423456789012" /* Visa */, "01", "2999");
246 personal_data_->AddCreditCard(credit_card1); 246 personal_data_->AddCreditCard(credit_card1);
247 247
248 CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B", 248 CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B",
249 "https://www.example.com"); 249 "https://www.example.com");
250 credit_card2.set_use_count(1); 250 credit_card2.set_use_count(1);
251 credit_card2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); 251 credit_card2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1));
252 test::SetCreditCardInfo(&credit_card2, "Bonnie Parker", 252 test::SetCreditCardInfo(&credit_card2, "Bonnie Parker",
253 "518765432109" /* Mastercard */, "", ""); 253 "518765432109" /* Mastercard */, "12", "3999");
254 personal_data_->AddCreditCard(credit_card2); 254 personal_data_->AddCreditCard(credit_card2);
255 255
256 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 256 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
257 .WillOnce(QuitMainMessageLoop()); 257 .WillOnce(QuitMainMessageLoop());
258 base::MessageLoop::current()->Run(); 258 base::MessageLoop::current()->Run();
259 259
260 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); 260 ASSERT_EQ(3U, personal_data_->GetCreditCards().size());
261 } 261 }
262 262
263 // Helper methods that simply forward the call to the private member (to avoid 263 // Helper methods that simply forward the call to the private member (to avoid
(...skipping 3069 matching lines...) Expand 10 before | Expand all | Expand 10 after
3333 ASSERT_EQ(5U, suggestions.size()); 3333 ASSERT_EQ(5U, suggestions.size());
3334 3334
3335 // All cards should be ordered as expected. 3335 // All cards should be ordered as expected.
3336 EXPECT_EQ(ASCIIToUTF16("Jesse James"), suggestions[0].value); 3336 EXPECT_EQ(ASCIIToUTF16("Jesse James"), suggestions[0].value);
3337 EXPECT_EQ(ASCIIToUTF16("John Dillinger"), suggestions[1].value); 3337 EXPECT_EQ(ASCIIToUTF16("John Dillinger"), suggestions[1].value);
3338 EXPECT_EQ(ASCIIToUTF16("Clyde Barrow"), suggestions[2].value); 3338 EXPECT_EQ(ASCIIToUTF16("Clyde Barrow"), suggestions[2].value);
3339 EXPECT_EQ(ASCIIToUTF16("Emmet Dalton"), suggestions[3].value); 3339 EXPECT_EQ(ASCIIToUTF16("Emmet Dalton"), suggestions[3].value);
3340 EXPECT_EQ(ASCIIToUTF16("Bonnie Parker"), suggestions[4].value); 3340 EXPECT_EQ(ASCIIToUTF16("Bonnie Parker"), suggestions[4].value);
3341 } 3341 }
3342 3342
3343 // Test that expired cards are ordered by frecency and are always suggested
3344 // after non expired cards even if they have a higher frecency score.
3345 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_ExpiredCards) {
3346 ASSERT_EQ(0U, personal_data_->GetCreditCards().size());
3347
3348 // Add a never used non expired credit card.
3349 CreditCard credit_card0("002149C1-EE28-4213-A3B9-DA243FFF021B",
3350 "https://www.example.com");
3351 test::SetCreditCardInfo(&credit_card0, "Bonnie Parker",
3352 "518765432109" /* Mastercard */, "04", "2999");
3353 personal_data_->AddCreditCard(credit_card0);
3354
3355 // Add an expired card with a higher frecency score.
3356 CreditCard credit_card1("287151C8-6AB1-487C-9095-28E80BE5DA15",
3357 "https://www.example.com");
3358 test::SetCreditCardInfo(&credit_card1, "Clyde Barrow",
3359 "347666888555" /* American Express */, "04", "1999");
3360 credit_card1.set_use_count(300);
3361 credit_card1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(10));
3362 personal_data_->AddCreditCard(credit_card1);
3363
3364 // Add an expired card with a lower frecency score.
3365 CreditCard credit_card2("1141084B-72D7-4B73-90CF-3D6AC154673B",
3366 "https://www.example.com");
3367 credit_card2.set_use_count(3);
3368 credit_card2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1));
3369 test::SetCreditCardInfo(&credit_card2, "John Dillinger",
3370 "423456789012" /* Visa */, "01", "1998");
3371 personal_data_->AddCreditCard(credit_card2);
3372
3373 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3374 .WillOnce(QuitMainMessageLoop());
3375 base::MessageLoop::current()->Run();
3376
3377 ASSERT_EQ(3U, personal_data_->GetCreditCards().size());
3378
3379 std::vector<Suggestion> suggestions =
3380 personal_data_->GetCreditCardSuggestions(
3381 AutofillType(CREDIT_CARD_NAME_FULL),
3382 /* field_contents= */ base::string16());
3383 ASSERT_EQ(3U, suggestions.size());
3384
3385 // The never used non expired card should be suggested first.
3386 EXPECT_EQ(ASCIIToUTF16("Bonnie Parker"), suggestions[0].value);
3387
3388 // The expired cards should be sorted by frecency
3389 EXPECT_EQ(ASCIIToUTF16("Clyde Barrow"), suggestions[1].value);
3390 EXPECT_EQ(ASCIIToUTF16("John Dillinger"), suggestions[2].value);
3391 }
3392
3343 // Test that a card that doesn't have a number is not shown in the suggestions 3393 // Test that a card that doesn't have a number is not shown in the suggestions
3344 // when querying credit cards by their number. 3394 // when querying credit cards by their number.
3345 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_NumberMissing) { 3395 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_NumberMissing) {
3346 // Create one normal credit card and one credit card with the number missing. 3396 // Create one normal credit card and one credit card with the number missing.
3347 ASSERT_EQ(0U, personal_data_->GetCreditCards().size()); 3397 ASSERT_EQ(0U, personal_data_->GetCreditCards().size());
3348 3398
3349 CreditCard credit_card0("287151C8-6AB1-487C-9095-28E80BE5DA15", 3399 CreditCard credit_card0("287151C8-6AB1-487C-9095-28E80BE5DA15",
3350 "https://www.example.com"); 3400 "https://www.example.com");
3351 test::SetCreditCardInfo(&credit_card0, "Clyde Barrow", 3401 test::SetCreditCardInfo(&credit_card0, "Clyde Barrow",
3352 "347666888555" /* American Express */, "04", "3999"); 3402 "347666888555" /* American Express */, "04", "3999");
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
4054 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), 4104 EXPECT_GT(base::TimeDelta::FromMilliseconds(500),
4055 base::Time::Now() - saved_profiles.front()->use_date()); 4105 base::Time::Now() - saved_profiles.front()->use_date());
4056 } 4106 }
4057 4107
4058 // Erase the profiles for the next test. 4108 // Erase the profiles for the next test.
4059 ResetProfiles(); 4109 ResetProfiles();
4060 } 4110 }
4061 } 4111 }
4062 4112
4063 } // namespace autofill 4113 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/personal_data_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698