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

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: merge 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 = personal_data_->GetProfileSuggestions(
2621 std::vector<base::string16> labels;
2622 std::vector<base::string16> icons;
2623 std::vector<PersonalDataManager::GUIDPair> guid_pairs;
2624 personal_data_->GetProfileSuggestions(
2625 AutofillType(ADDRESS_HOME_STREET_ADDRESS), 2621 AutofillType(ADDRESS_HOME_STREET_ADDRESS),
2626 base::UTF8ToUTF16("123"), 2622 base::UTF8ToUTF16("123"),
2627 false, 2623 false,
2628 std::vector<ServerFieldType>(), 2624 std::vector<ServerFieldType>(),
2629 base::Bind(ReturnTrue), 2625 base::Bind(ReturnTrue));
2630 &values, 2626 ASSERT_FALSE(suggestions.empty());
2631 &labels, 2627 EXPECT_EQ(suggestions[0].value,
2632 &icons,
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")); 2628 base::UTF8ToUTF16("123 Zoo St., Second Line, Third line, unit 5"));
2637 } 2629 }
2638 2630
2639 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions) { 2631 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions) {
2640 // These GUIDs are reverse alphabetical to make validating expectations 2632 // These GUIDs are reverse alphabetical to make validating expectations
2641 // easier. 2633 // easier.
2642 CreditCard credit_card0("287151C8-6AB1-487C-9095-28E80BE5DA15", 2634 CreditCard credit_card0("287151C8-6AB1-487C-9095-28E80BE5DA15",
2643 "https://www.example.com"); 2635 "https://www.example.com");
2644 test::SetCreditCardInfo(&credit_card0, 2636 test::SetCreditCardInfo(&credit_card0,
2645 "Clyde Barrow", "347666888555" /* American Express */, "04", "2015"); 2637 "Clyde Barrow", "347666888555" /* American Express */, "04", "2015");
2646 personal_data_->AddCreditCard(credit_card0); 2638 personal_data_->AddCreditCard(credit_card0);
2647 2639
2648 CreditCard credit_card1("1141084B-72D7-4B73-90CF-3D6AC154673B", 2640 CreditCard credit_card1("1141084B-72D7-4B73-90CF-3D6AC154673B",
2649 "https://www.example.com"); 2641 "https://www.example.com");
2650 test::SetCreditCardInfo(&credit_card1, "John Dillinger", "", "01", "2010"); 2642 test::SetCreditCardInfo(&credit_card1, "John Dillinger", "", "01", "2010");
2651 personal_data_->AddCreditCard(credit_card1); 2643 personal_data_->AddCreditCard(credit_card1);
2652 2644
2653 CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B", 2645 CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B",
2654 "https://www.example.com"); 2646 "https://www.example.com");
2655 test::SetCreditCardInfo(&credit_card2, 2647 test::SetCreditCardInfo(&credit_card2,
2656 "Bonnie Parker", "518765432109" /* Mastercard */, "", ""); 2648 "Bonnie Parker", "518765432109" /* Mastercard */, "", "");
2657 personal_data_->AddCreditCard(credit_card2); 2649 personal_data_->AddCreditCard(credit_card2);
2658 2650
2659 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2651 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2660 .WillOnce(QuitMainMessageLoop()); 2652 .WillOnce(QuitMainMessageLoop());
2661 base::MessageLoop::current()->Run(); 2653 base::MessageLoop::current()->Run();
2662 2654
2663 // Sublabel is card number when filling name. 2655 // Sublabel is card number when filling name.
2664 std::vector<base::string16> values; 2656 std::vector<Suggestion> suggestions =
2665 std::vector<base::string16> labels; 2657 personal_data_->GetCreditCardSuggestions(
2666 std::vector<base::string16> icons; 2658 AutofillType(CREDIT_CARD_NAME), base::string16());
2667 std::vector<PersonalDataManager::GUIDPair> guid_pairs; 2659 ASSERT_EQ(3U, suggestions.size());
2668 personal_data_->GetCreditCardSuggestions( 2660 EXPECT_EQ(ASCIIToUTF16("Clyde Barrow"), suggestions[2].value);
2669 AutofillType(CREDIT_CARD_NAME), 2661 EXPECT_EQ(ASCIIToUTF16("*8555"), suggestions[2].label);
2670 base::string16(), 2662 EXPECT_EQ(ASCIIToUTF16("John Dillinger"), suggestions[1].value);
2671 &values, 2663 EXPECT_EQ(base::string16(), suggestions[1].label);
2672 &labels, 2664 EXPECT_EQ(ASCIIToUTF16("Bonnie Parker"), suggestions[0].value);
2673 &icons, 2665 EXPECT_EQ(ASCIIToUTF16("*2109"), suggestions[0].label);
2674 &guid_pairs);
2675 ASSERT_EQ(3U, values.size());
2676 ASSERT_EQ(values.size(), labels.size());
2677 EXPECT_EQ(ASCIIToUTF16("Clyde Barrow"), values[2]);
2678 EXPECT_EQ(ASCIIToUTF16("*8555"), labels[2]);
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 2666
2684 // Sublabel is expiration date when filling card number. 2667 // Sublabel is expiration date when filling card number.
2685 values.clear(); 2668 suggestions = personal_data_->GetCreditCardSuggestions(
2686 labels.clear(); 2669 AutofillType(CREDIT_CARD_NUMBER), base::string16());
2687 icons.clear(); 2670 ASSERT_EQ(2U, suggestions.size());
2688 guid_pairs.clear(); 2671 EXPECT_EQ(ASCIIToUTF16("********8555"), suggestions[1].value);
2689 personal_data_->GetCreditCardSuggestions( 2672 EXPECT_EQ(ASCIIToUTF16("04/15"), suggestions[1].label);
2690 AutofillType(CREDIT_CARD_NUMBER), 2673 EXPECT_EQ(ASCIIToUTF16("********2109"), suggestions[0].value);
2691 base::string16(), 2674 EXPECT_EQ(base::string16(), suggestions[0].label);
2692 &values,
2693 &labels,
2694 &icons,
2695 &guid_pairs);
2696 ASSERT_EQ(2U, values.size());
2697 ASSERT_EQ(values.size(), labels.size());
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 } 2675 }
2703 2676
2704 #if defined(OS_MACOSX) && !defined(OS_IOS) 2677 #if defined(OS_MACOSX) && !defined(OS_IOS)
2705 TEST_F(PersonalDataManagerTest, ShowAddressBookPrompt) { 2678 TEST_F(PersonalDataManagerTest, ShowAddressBookPrompt) {
2706 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()).Times(2); 2679 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()).Times(2);
2707 2680
2708 AutofillType type(ADDRESS_HOME_STREET_ADDRESS); 2681 AutofillType type(ADDRESS_HOME_STREET_ADDRESS);
2709 2682
2710 prefs_->SetBoolean(prefs::kAutofillEnabled, false); 2683 prefs_->SetBoolean(prefs::kAutofillEnabled, false);
2711 EXPECT_FALSE(personal_data_->ShouldShowAccessAddressBookSuggestion(type)); 2684 EXPECT_FALSE(personal_data_->ShouldShowAccessAddressBookSuggestion(type));
(...skipping 29 matching lines...) Expand all
2741 2714
2742 prefs_->SetInteger(prefs::kAutofillMacAddressBookShowedCount, 4); 2715 prefs_->SetInteger(prefs::kAutofillMacAddressBookShowedCount, 4);
2743 EXPECT_TRUE(personal_data_->ShouldShowAccessAddressBookSuggestion(type)); 2716 EXPECT_TRUE(personal_data_->ShouldShowAccessAddressBookSuggestion(type));
2744 2717
2745 prefs_->SetInteger(prefs::kAutofillMacAddressBookShowedCount, 6); 2718 prefs_->SetInteger(prefs::kAutofillMacAddressBookShowedCount, 6);
2746 EXPECT_FALSE(personal_data_->ShouldShowAccessAddressBookSuggestion(type)); 2719 EXPECT_FALSE(personal_data_->ShouldShowAccessAddressBookSuggestion(type));
2747 } 2720 }
2748 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 2721 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
2749 2722
2750 } // namespace autofill 2723 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/personal_data_manager.cc ('k') | components/autofill/core/browser/suggestion.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698