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