| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/autofill/data_model_wrapper.h" | |
| 6 | |
| 7 #include <memory> | |
| 8 | |
| 9 #include "base/guid.h" | |
| 10 #include "base/strings/string_number_conversions.h" | |
| 11 #include "base/strings/utf_string_conversions.h" | |
| 12 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" | |
| 13 #include "components/autofill/core/browser/autofill_profile.h" | |
| 14 #include "components/autofill/core/browser/autofill_test_utils.h" | |
| 15 #include "components/autofill/core/browser/credit_card.h" | |
| 16 #include "components/autofill/core/browser/field_types.h" | |
| 17 #include "testing/gtest/include/gtest/gtest.h" | |
| 18 | |
| 19 using base::ASCIIToUTF16; | |
| 20 | |
| 21 namespace autofill { | |
| 22 | |
| 23 TEST(AutofillCreditCardWrapperTest, GetInfoCreditCardExpMonth) { | |
| 24 CreditCard card; | |
| 25 MonthComboboxModel model; | |
| 26 for (int month = 1; month <= 12; ++month) { | |
| 27 card.SetRawInfo(CREDIT_CARD_EXP_MONTH, base::IntToString16(month)); | |
| 28 AutofillCreditCardWrapper wrapper(&card); | |
| 29 EXPECT_EQ(model.GetItemAt(month), | |
| 30 wrapper.GetInfo(AutofillType(CREDIT_CARD_EXP_MONTH))); | |
| 31 } | |
| 32 } | |
| 33 | |
| 34 TEST(AutofillCreditCardWrapperTest, GetDisplayTextEmptyWhenExpired) { | |
| 35 CreditCard card; | |
| 36 card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("1")); | |
| 37 card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("2010")); | |
| 38 card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("4111111111111111")); | |
| 39 AutofillCreditCardWrapper wrapper(&card); | |
| 40 base::string16 unused, unused2; | |
| 41 EXPECT_FALSE(wrapper.GetDisplayText(&unused, &unused2)); | |
| 42 } | |
| 43 | |
| 44 TEST(AutofillCreditCardWrapperTest, GetDisplayTextEmptyWhenInvalid) { | |
| 45 CreditCard card; | |
| 46 card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("12")); | |
| 47 card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("9999")); | |
| 48 card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("41111")); | |
| 49 AutofillCreditCardWrapper wrapper(&card); | |
| 50 base::string16 unused, unused2; | |
| 51 EXPECT_FALSE(wrapper.GetDisplayText(&unused, &unused2)); | |
| 52 } | |
| 53 | |
| 54 TEST(AutofillCreditCardWrapperTest, GetDisplayTextNotEmptyWhenValid) { | |
| 55 CreditCard card; | |
| 56 card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("12")); | |
| 57 card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("9999")); | |
| 58 card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("4111111111111111")); | |
| 59 AutofillCreditCardWrapper wrapper(&card); | |
| 60 base::string16 unused, unused2; | |
| 61 EXPECT_TRUE(wrapper.GetDisplayText(&unused, &unused2)); | |
| 62 } | |
| 63 | |
| 64 TEST(DataModelWrapperTest, GetDisplayText) { | |
| 65 AutofillProfile profile = test::GetFullProfile(); | |
| 66 base::string16 vertical, horizontal; | |
| 67 EXPECT_TRUE( | |
| 68 AutofillProfileWrapper(&profile).GetDisplayText(&horizontal, &vertical)); | |
| 69 EXPECT_EQ(ASCIIToUTF16( | |
| 70 "John H. Doe, 666 Erebus St., Apt 8, Elysium, CA 91111\n" | |
| 71 "johndoe@hades.com\n" | |
| 72 "1 650-211-1111"), | |
| 73 horizontal); | |
| 74 EXPECT_EQ(ASCIIToUTF16( | |
| 75 "John H. Doe\n" | |
| 76 "666 Erebus St.\n" | |
| 77 "Apt 8\n" | |
| 78 "Elysium, CA 91111\n" | |
| 79 "johndoe@hades.com\n" | |
| 80 "1 650-211-1111"), | |
| 81 vertical); | |
| 82 | |
| 83 // A Japanese address. | |
| 84 AutofillProfile foreign_profile( | |
| 85 base::GenerateGUID(), "http://www.example.com/"); | |
| 86 foreign_profile.SetRawInfo( | |
| 87 ADDRESS_HOME_COUNTRY, ASCIIToUTF16("JP")); | |
| 88 foreign_profile.SetRawInfo( | |
| 89 ADDRESS_HOME_STATE, | |
| 90 base::WideToUTF16(L"\u6771\u4EAC\u90FD")); | |
| 91 foreign_profile.SetRawInfo( | |
| 92 ADDRESS_HOME_CITY, | |
| 93 base::WideToUTF16(L"\u6E0B\u8C37\u533A")); | |
| 94 foreign_profile.SetRawInfo( | |
| 95 ADDRESS_HOME_DEPENDENT_LOCALITY, | |
| 96 base::WideToUTF16(L"\uC911\uAD6C")); | |
| 97 foreign_profile.SetRawInfo( | |
| 98 ADDRESS_HOME_STREET_ADDRESS, | |
| 99 base::WideToUTF16( | |
| 100 L"\u685C\u4E18\u753A26-1\n" | |
| 101 L"\u30BB\u30EB\u30EA\u30A2\u30F3\u30BF\u30EF\u30FC6\u968E")); | |
| 102 foreign_profile.SetRawInfo( | |
| 103 NAME_FULL, | |
| 104 base::WideToUTF16(L"\u6751\u4E0A \u7F8E\u7D00")); | |
| 105 foreign_profile.SetRawInfo(ADDRESS_HOME_ZIP, base::ASCIIToUTF16("150-8512")); | |
| 106 foreign_profile.SetRawInfo( | |
| 107 PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("+81-3-6384-9000")); | |
| 108 | |
| 109 EXPECT_TRUE(AutofillProfileWrapper(&foreign_profile).GetDisplayText( | |
| 110 &horizontal, &vertical)); | |
| 111 EXPECT_EQ( | |
| 112 base::WideToUTF16( | |
| 113 L"\u3012150-8512\n" | |
| 114 L"\u6771\u4EAC\u90FD\u6E0B\u8C37\u533A\n" | |
| 115 L"\u685C\u4E18\u753A26-1\n" | |
| 116 L"\u30BB\u30EB\u30EA\u30A2\u30F3\u30BF\u30EF\u30FC6\u968E\n" | |
| 117 L"\u6751\u4E0A \u7F8E\u7D00\n" | |
| 118 L"+81-3-6384-9000"), | |
| 119 vertical); | |
| 120 // TODO(estade): we should also verify that |horizontal| is correct, but right | |
| 121 // now it uses the incorrect address line separator. See: | |
| 122 // http://crbug.com/270261 | |
| 123 } | |
| 124 | |
| 125 TEST(DataModelWrapperTest, GetDisplayPhoneNumber) { | |
| 126 const base::string16 national_unformatted = ASCIIToUTF16("3104567890"); | |
| 127 const base::string16 national_formatted = ASCIIToUTF16("(310) 456-7890"); | |
| 128 const base::string16 international_unformatted = ASCIIToUTF16("13104567890"); | |
| 129 const base::string16 international_unformatted_with_plus = | |
| 130 ASCIIToUTF16("+13104567890"); | |
| 131 const base::string16 international_formatted = ASCIIToUTF16("1 310-456-7890"); | |
| 132 const base::string16 user_formatted = ASCIIToUTF16("310.456 78 90"); | |
| 133 | |
| 134 // Autofill numbers that are unformatted get formatted either nationally or | |
| 135 // internationally depending on the presence of a country code. Formatted | |
| 136 // numbers stay formatted. | |
| 137 AutofillProfile profile(test::GetVerifiedProfile()); | |
| 138 AutofillProfileWrapper profile_wrapper(&profile); | |
| 139 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, international_unformatted); | |
| 140 EXPECT_EQ(international_formatted, | |
| 141 profile_wrapper.GetInfoForDisplay( | |
| 142 AutofillType(PHONE_HOME_WHOLE_NUMBER))); | |
| 143 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, | |
| 144 international_unformatted_with_plus); | |
| 145 EXPECT_EQ( | |
| 146 international_formatted, | |
| 147 profile_wrapper.GetInfoForDisplay(AutofillType(PHONE_HOME_WHOLE_NUMBER))); | |
| 148 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, national_unformatted); | |
| 149 EXPECT_EQ(national_formatted, | |
| 150 profile_wrapper.GetInfoForDisplay( | |
| 151 AutofillType(PHONE_HOME_WHOLE_NUMBER))); | |
| 152 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, national_formatted); | |
| 153 EXPECT_EQ(national_formatted, | |
| 154 profile_wrapper.GetInfoForDisplay( | |
| 155 AutofillType(PHONE_HOME_WHOLE_NUMBER))); | |
| 156 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, user_formatted); | |
| 157 EXPECT_EQ(user_formatted, | |
| 158 profile_wrapper.GetInfoForDisplay( | |
| 159 AutofillType(PHONE_HOME_WHOLE_NUMBER))); | |
| 160 } | |
| 161 | |
| 162 } // namespace autofill | |
| OLD | NEW |