Index: components/autofill/core/browser/autofill_field_unittest.cc |
diff --git a/components/autofill/core/browser/autofill_field_unittest.cc b/components/autofill/core/browser/autofill_field_unittest.cc |
index fa10822aa1c0210ac82fb724c0bd9faad825953d..78b4eeed133436e94995873e49c90aaa493bda31 100644 |
--- a/components/autofill/core/browser/autofill_field_unittest.cc |
+++ b/components/autofill/core/browser/autofill_field_unittest.cc |
@@ -622,5 +622,29 @@ TEST(AutofillFieldTest, FillCreditCardNumberWithUnequalSizeSplits) { |
EXPECT_EQ(ASCIIToUTF16(test.card_number_), cc_number_full.value); |
} |
+TEST(AutofillFieldTest, GetCreditCardNumberValue) { |
+ std::string card_number("5187654321098765"); |
+ std::string expectations[] = {"5187", "6543", "2109", "8765"}; |
+ size_t total_spilts = 4; |
Ilya Sherman
2014/10/13 23:33:37
nit: Please use the arraysize macro to compute thi
Pritam Nikam
2014/10/15 09:12:11
Done.
|
+ int max_lengths[] = {4, 4, 4, 4}; |
+ |
+ for (size_t i = 0; i < total_spilts; ++i) { |
+ AutofillField cc_number_part; |
+ cc_number_part.set_heuristic_type(CREDIT_CARD_NUMBER); |
+ cc_number_part.max_length = max_lengths[i]; |
+ cc_number_part.set_credit_card_number_offset(4 * i); |
+ |
+ // Retrive the value for |cc_number_part|. |
+ base::string16 actual = AutofillField::GetCreditCardNumberValue( |
+ cc_number_part, ASCIIToUTF16(card_number)); |
+ |
+ // Enforce the field's |max_length| constrain. |
Ilya Sherman
2014/10/13 23:33:37
nit: "constrain" -> "constraint". Also, please me
Pritam Nikam
2014/10/15 09:12:10
Done.
|
+ actual = actual.substr(0, max_lengths[i]); |
+ |
+ // Verify for expected results. |
+ EXPECT_EQ(ASCIIToUTF16(expectations[i]), actual); |
+ } |
+} |
Ilya Sherman
2014/10/13 23:33:37
Please also test the behavior if the offset is equ
Pritam Nikam
2014/10/15 09:12:10
Done.
|
+ |
} // namespace |
} // namespace autofill |