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

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

Issue 772253003: Create an autofill Suggestion class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: self review 2 Created 6 years 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 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 <algorithm> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 2599 matching lines...) Expand 10 before | Expand all | Expand 10 after
2610 TEST_F(PersonalDataManagerTest, GetProfileSuggestions) { 2610 TEST_F(PersonalDataManagerTest, GetProfileSuggestions) {
2611 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com"); 2611 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com");
2612 test::SetProfileInfo(&profile, 2612 test::SetProfileInfo(&profile,
2613 "Marion", "Mitchell", "Morrison", 2613 "Marion", "Mitchell", "Morrison",
2614 "johnwayne@me.xyz", "Fox", 2614 "johnwayne@me.xyz", "Fox",
2615 "123 Zoo St.\nSecond Line\nThird line", "unit 5", "Hollywood", "CA", 2615 "123 Zoo St.\nSecond Line\nThird line", "unit 5", "Hollywood", "CA",
2616 "91601", "US", "12345678910"); 2616 "91601", "US", "12345678910");
2617 personal_data_->AddProfile(profile); 2617 personal_data_->AddProfile(profile);
2618 ResetPersonalDataManager(USER_MODE_NORMAL); 2618 ResetPersonalDataManager(USER_MODE_NORMAL);
2619 2619
2620 std::vector<base::string16> values; 2620 std::vector<Suggestion> suggestions;
2621 std::vector<base::string16> labels;
2622 std::vector<base::string16> icons;
2623 std::vector<PersonalDataManager::GUIDPair> guid_pairs;
2624 personal_data_->GetProfileSuggestions( 2621 personal_data_->GetProfileSuggestions(
2625 AutofillType(ADDRESS_HOME_STREET_ADDRESS), 2622 AutofillType(ADDRESS_HOME_STREET_ADDRESS),
2626 base::UTF8ToUTF16("123"), 2623 base::UTF8ToUTF16("123"),
2627 false, 2624 false,
2628 std::vector<ServerFieldType>(), 2625 std::vector<ServerFieldType>(),
2629 base::Bind(ReturnTrue), 2626 base::Bind(ReturnTrue),
2630 &values, 2627 &suggestions);
2631 &labels, 2628 ASSERT_FALSE(suggestions.empty());
2632 &icons, 2629 EXPECT_EQ(suggestions[0].value,
2633 &guid_pairs);
2634 ASSERT_FALSE(values.empty());
2635 EXPECT_EQ(values[0],
2636 base::UTF8ToUTF16("123 Zoo St., Second Line, Third line, unit 5")); 2630 base::UTF8ToUTF16("123 Zoo St., Second Line, Third line, unit 5"));
2637 } 2631 }
2638 2632
2639 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions) { 2633 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions) {
2640 // These GUIDs are reverse alphabetical to make validating expectations 2634 // These GUIDs are reverse alphabetical to make validating expectations
2641 // easier. 2635 // easier.
2642 CreditCard credit_card0("287151C8-6AB1-487C-9095-28E80BE5DA15", 2636 CreditCard credit_card0("287151C8-6AB1-487C-9095-28E80BE5DA15",
2643 "https://www.example.com"); 2637 "https://www.example.com");
2644 test::SetCreditCardInfo(&credit_card0, 2638 test::SetCreditCardInfo(&credit_card0,
2645 "Clyde Barrow", "347666888555" /* American Express */, "04", "2015"); 2639 "Clyde Barrow", "347666888555" /* American Express */, "04", "2015");
2646 personal_data_->AddCreditCard(credit_card0); 2640 personal_data_->AddCreditCard(credit_card0);
2647 2641
2648 CreditCard credit_card1("1141084B-72D7-4B73-90CF-3D6AC154673B", 2642 CreditCard credit_card1("1141084B-72D7-4B73-90CF-3D6AC154673B",
2649 "https://www.example.com"); 2643 "https://www.example.com");
2650 test::SetCreditCardInfo(&credit_card1, "John Dillinger", "", "01", "2010"); 2644 test::SetCreditCardInfo(&credit_card1, "John Dillinger", "", "01", "2010");
2651 personal_data_->AddCreditCard(credit_card1); 2645 personal_data_->AddCreditCard(credit_card1);
2652 2646
2653 CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B", 2647 CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B",
2654 "https://www.example.com"); 2648 "https://www.example.com");
2655 test::SetCreditCardInfo(&credit_card2, 2649 test::SetCreditCardInfo(&credit_card2,
2656 "Bonnie Parker", "518765432109" /* Mastercard */, "", ""); 2650 "Bonnie Parker", "518765432109" /* Mastercard */, "", "");
2657 personal_data_->AddCreditCard(credit_card2); 2651 personal_data_->AddCreditCard(credit_card2);
2658 2652
2659 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2653 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2660 .WillOnce(QuitMainMessageLoop()); 2654 .WillOnce(QuitMainMessageLoop());
2661 base::MessageLoop::current()->Run(); 2655 base::MessageLoop::current()->Run();
2662 2656
2663 // Sublabel is card number when filling name. 2657 // Sublabel is card number when filling name.
2664 std::vector<base::string16> values; 2658 std::vector<Suggestion> suggestions;
2665 std::vector<base::string16> labels;
2666 std::vector<base::string16> icons;
2667 std::vector<PersonalDataManager::GUIDPair> guid_pairs;
2668 personal_data_->GetCreditCardSuggestions( 2659 personal_data_->GetCreditCardSuggestions(
2669 AutofillType(CREDIT_CARD_NAME), 2660 AutofillType(CREDIT_CARD_NAME),
2670 base::string16(), 2661 base::string16(),
2671 &values, 2662 &suggestions);
2672 &labels, 2663 ASSERT_EQ(3U, suggestions.size());
2673 &icons, 2664 EXPECT_EQ(ASCIIToUTF16("Clyde Barrow"), suggestions[2].value);
2674 &guid_pairs); 2665 EXPECT_EQ(ASCIIToUTF16("*8555"), suggestions[2].label);
2675 ASSERT_EQ(3U, values.size()); 2666 EXPECT_EQ(ASCIIToUTF16("John Dillinger"), suggestions[1].value);
2676 ASSERT_EQ(values.size(), labels.size()); 2667 EXPECT_EQ(base::string16(), suggestions[1].label);
2677 EXPECT_EQ(ASCIIToUTF16("Clyde Barrow"), values[2]); 2668 EXPECT_EQ(ASCIIToUTF16("Bonnie Parker"), suggestions[0].value);
2678 EXPECT_EQ(ASCIIToUTF16("*8555"), labels[2]); 2669 EXPECT_EQ(ASCIIToUTF16("*2109"), suggestions[0].label);
2679 EXPECT_EQ(ASCIIToUTF16("John Dillinger"), values[1]);
2680 EXPECT_EQ(base::string16(), labels[1]);
2681 EXPECT_EQ(ASCIIToUTF16("Bonnie Parker"), values[0]);
2682 EXPECT_EQ(ASCIIToUTF16("*2109"), labels[0]);
2683 2670
2684 // Sublabel is expiration date when filling card number. 2671 // Sublabel is expiration date when filling card number.
2685 values.clear(); 2672 suggestions.clear();
2686 labels.clear();
2687 icons.clear();
2688 guid_pairs.clear();
2689 personal_data_->GetCreditCardSuggestions( 2673 personal_data_->GetCreditCardSuggestions(
2690 AutofillType(CREDIT_CARD_NUMBER), 2674 AutofillType(CREDIT_CARD_NUMBER),
2691 base::string16(), 2675 base::string16(),
2692 &values, 2676 &suggestions);
2693 &labels, 2677 ASSERT_EQ(2U, suggestions.size());
2694 &icons, 2678 EXPECT_EQ(ASCIIToUTF16("********8555"), suggestions[1].value);
2695 &guid_pairs); 2679 EXPECT_EQ(ASCIIToUTF16("04/15"), suggestions[1].label);
2696 ASSERT_EQ(2U, values.size()); 2680 EXPECT_EQ(ASCIIToUTF16("********2109"), suggestions[0].value);
2697 ASSERT_EQ(values.size(), labels.size()); 2681 EXPECT_EQ(base::string16(), suggestions[0].label);
2698 EXPECT_EQ(ASCIIToUTF16("********8555"), values[1]);
2699 EXPECT_EQ(ASCIIToUTF16("04/15"), labels[1]);
2700 EXPECT_EQ(ASCIIToUTF16("********2109"), values[0]);
2701 EXPECT_EQ(base::string16(), labels[0]);
2702 } 2682 }
2703 2683
2704 #if defined(OS_MACOSX) && !defined(OS_IOS) 2684 #if defined(OS_MACOSX) && !defined(OS_IOS)
2705 TEST_F(PersonalDataManagerTest, ShowAddressBookPrompt) { 2685 TEST_F(PersonalDataManagerTest, ShowAddressBookPrompt) {
2706 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()).Times(2); 2686 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()).Times(2);
2707 2687
2708 AutofillType type(ADDRESS_HOME_STREET_ADDRESS); 2688 AutofillType type(ADDRESS_HOME_STREET_ADDRESS);
2709 2689
2710 prefs_->SetBoolean(prefs::kAutofillEnabled, false); 2690 prefs_->SetBoolean(prefs::kAutofillEnabled, false);
2711 EXPECT_FALSE(personal_data_->ShouldShowAccessAddressBookSuggestion(type)); 2691 EXPECT_FALSE(personal_data_->ShouldShowAccessAddressBookSuggestion(type));
(...skipping 29 matching lines...) Expand all
2741 2721
2742 prefs_->SetInteger(prefs::kAutofillMacAddressBookShowedCount, 4); 2722 prefs_->SetInteger(prefs::kAutofillMacAddressBookShowedCount, 4);
2743 EXPECT_TRUE(personal_data_->ShouldShowAccessAddressBookSuggestion(type)); 2723 EXPECT_TRUE(personal_data_->ShouldShowAccessAddressBookSuggestion(type));
2744 2724
2745 prefs_->SetInteger(prefs::kAutofillMacAddressBookShowedCount, 6); 2725 prefs_->SetInteger(prefs::kAutofillMacAddressBookShowedCount, 6);
2746 EXPECT_FALSE(personal_data_->ShouldShowAccessAddressBookSuggestion(type)); 2726 EXPECT_FALSE(personal_data_->ShouldShowAccessAddressBookSuggestion(type));
2747 } 2727 }
2748 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 2728 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
2749 2729
2750 } // namespace autofill 2730 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698