Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "components/autofill/core/browser/autofill_field.h" | 5 #include "components/autofill/core/browser/autofill_field.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 | 252 |
| 253 // Credit card related field. | 253 // Credit card related field. |
| 254 field.set_heuristic_type(CREDIT_CARD_NUMBER); | 254 field.set_heuristic_type(CREDIT_CARD_NUMBER); |
| 255 AutofillField::FillFormField(field, ASCIIToUTF16("4111111111111111"), "en-US", | 255 AutofillField::FillFormField(field, ASCIIToUTF16("4111111111111111"), "en-US", |
| 256 "en-US", &field); | 256 "en-US", &field); |
| 257 | 257 |
| 258 // Verify that the field is filled. | 258 // Verify that the field is filled. |
| 259 EXPECT_EQ(ASCIIToUTF16("4111111111111111"), field.value); | 259 EXPECT_EQ(ASCIIToUTF16("4111111111111111"), field.value); |
| 260 } | 260 } |
| 261 | 261 |
| 262 TEST(AutofillFieldTest, FillPhoneNumber) { | 262 TEST(AutofillFieldTest, FillPhoneNumber) { |
|
Mathieu
2016/01/26 14:43:02
Maybe I'm spoiled by your other changes, but can w
sebsg
2016/01/26 23:56:26
It's a good habit to take. It's so much easier to
Mathieu
2016/01/27 14:30:49
Thanks!
sebsg
2016/01/27 21:01:21
Acknowledged.
| |
| 263 AutofillField field; | 263 AutofillField field; |
| 264 field.SetHtmlType(HTML_TYPE_TEL_LOCAL_PREFIX, HtmlFieldMode()); | 264 field.SetHtmlType(HTML_TYPE_TEL_LOCAL_PREFIX, HtmlFieldMode()); |
| 265 | 265 |
| 266 // Fill with a non-phone number; should fill normally. | 266 // Fill with a non-phone number; should fill normally. |
| 267 AutofillField::FillFormField( | 267 AutofillField::FillFormField( |
| 268 field, ASCIIToUTF16("Oh hai"), "en-US", "en-US", &field); | 268 field, ASCIIToUTF16("Oh hai"), "en-US", "en-US", &field); |
| 269 EXPECT_EQ(ASCIIToUTF16("Oh hai"), field.value); | 269 EXPECT_EQ(ASCIIToUTF16("Oh hai"), field.value); |
| 270 | 270 |
| 271 // Fill with a phone number; should fill just the prefix. | 271 // Fill with a phone number; should fill just the prefix. |
| 272 AutofillField::FillFormField( | 272 AutofillField::FillFormField( |
| 273 field, ASCIIToUTF16("5551234"), "en-US", "en-US", &field); | 273 field, ASCIIToUTF16("5551234"), "en-US", "en-US", &field); |
| 274 EXPECT_EQ(ASCIIToUTF16("555"), field.value); | 274 EXPECT_EQ(ASCIIToUTF16("555"), field.value); |
| 275 | 275 |
| 276 // Now reset the type, and set a max-length instead. | 276 // Now reset the type, and set a max-length the size of a suffix. |
| 277 field.SetHtmlType(HTML_TYPE_UNSPECIFIED, HtmlFieldMode()); | 277 field.SetHtmlType(HTML_TYPE_UNSPECIFIED, HtmlFieldMode()); |
| 278 field.set_heuristic_type(PHONE_HOME_NUMBER); | 278 field.set_heuristic_type(PHONE_HOME_NUMBER); |
| 279 field.max_length = 4; | 279 field.max_length = 4; |
| 280 | 280 |
| 281 // Fill with a phone-number; should fill just the suffix. | 281 // Fill with a phone-number; should fill just the suffix. |
| 282 AutofillField::FillFormField( | 282 AutofillField::FillFormField( |
| 283 field, ASCIIToUTF16("5551234"), "en-US", "en-US", &field); | 283 field, ASCIIToUTF16("5551234"), "en-US", "en-US", &field); |
| 284 EXPECT_EQ(ASCIIToUTF16("1234"), field.value); | 284 EXPECT_EQ(ASCIIToUTF16("1234"), field.value); |
| 285 | |
| 286 // Now reset the type, and set a max-length of 10. | |
| 287 field.SetHtmlType(HTML_TYPE_UNSPECIFIED, HtmlFieldMode()); | |
|
Mathieu
2016/01/26 14:43:02
HTML_TYPE_TEL?
https://code.google.com/p/chromiu
sebsg
2016/01/26 23:56:26
Done.
| |
| 288 field.set_heuristic_type(PHONE_HOME_WHOLE_NUMBER); | |
| 289 field.max_length = 10; | |
| 290 | |
| 291 // Fill with a whole phone number including country code. The number should | |
| 292 // fill without the country code. | |
| 293 AutofillField::FillFormField(field, ASCIIToUTF16("15141254578"), "en-US", | |
| 294 "en-US", &field); | |
| 295 EXPECT_EQ(ASCIIToUTF16("5141254578"), field.value); | |
| 285 } | 296 } |
| 286 | 297 |
| 287 TEST(AutofillFieldTest, FillSelectControlByValue) { | 298 TEST(AutofillFieldTest, FillSelectControlByValue) { |
| 288 std::vector<const char*> kOptions = { | 299 std::vector<const char*> kOptions = { |
| 289 "Eenie", "Meenie", "Miney", "Mo", | 300 "Eenie", "Meenie", "Miney", "Mo", |
| 290 }; | 301 }; |
| 291 AutofillField field(GenerateSelectFieldWithOptions(kOptions, kOptions.size()), | 302 AutofillField field(GenerateSelectFieldWithOptions(kOptions, kOptions.size()), |
| 292 base::string16()); | 303 base::string16()); |
| 293 | 304 |
| 294 // Set semantically empty contents for each option, so that only the values | 305 // Set semantically empty contents for each option, so that only the values |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 801 index = kBadIndex; | 812 index = kBadIndex; |
| 802 ret = AutofillField::FindValueInSelectControl( | 813 ret = AutofillField::FindValueInSelectControl( |
| 803 field, UTF8ToUTF16("NoVaScOtIa"), &index); | 814 field, UTF8ToUTF16("NoVaScOtIa"), &index); |
| 804 EXPECT_TRUE(ret); | 815 EXPECT_TRUE(ret); |
| 805 EXPECT_EQ(2U, index); | 816 EXPECT_EQ(2U, index); |
| 806 } | 817 } |
| 807 } | 818 } |
| 808 | 819 |
| 809 } // namespace | 820 } // namespace |
| 810 } // namespace autofill | 821 } // namespace autofill |
| OLD | NEW |