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

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc

Issue 322453003: autocomplete: support address-line3, address-level{1,2,3} (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test expectations Created 6 years, 6 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <map> 5 #include <map>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 const char kEditedBillingAddress[] = "123 edited billing address"; 86 const char kEditedBillingAddress[] = "123 edited billing address";
87 const char* kFieldsFromPage[] = 87 const char* kFieldsFromPage[] =
88 { "email", 88 { "email",
89 "cc-name", 89 "cc-name",
90 "cc-number", 90 "cc-number",
91 "cc-exp-month", 91 "cc-exp-month",
92 "cc-exp-year", 92 "cc-exp-year",
93 "cc-csc", 93 "cc-csc",
94 "billing name", 94 "billing name",
95 "billing address-line1", 95 "billing address-line1",
96 "billing locality", 96 "billing address-level2",
97 "billing region", 97 "billing address-level1",
98 "billing postal-code", 98 "billing postal-code",
99 "billing country", 99 "billing country",
100 "billing tel", 100 "billing tel",
101 "shipping name", 101 "shipping name",
102 "shipping address-line1", 102 "shipping address-line1",
103 "shipping locality", 103 "shipping address-level2",
104 "shipping region", 104 "shipping address-level1",
105 "shipping postal-code", 105 "shipping postal-code",
106 "shipping country", 106 "shipping country",
107 "shipping tel", 107 "shipping tel",
108 }; 108 };
109 const char kSettingsOrigin[] = "Chrome settings"; 109 const char kSettingsOrigin[] = "Chrome settings";
110 const char kTestCCNumberAmex[] = "376200000000002"; 110 const char kTestCCNumberAmex[] = "376200000000002";
111 const char kTestCCNumberVisa[] = "4111111111111111"; 111 const char kTestCCNumberVisa[] = "4111111111111111";
112 const char kTestCCNumberMaster[] = "5555555555554444"; 112 const char kTestCCNumberMaster[] = "5555555555554444";
113 const char kTestCCNumberDiscover[] = "6011111111111117"; 113 const char kTestCCNumberDiscover[] = "6011111111111117";
114 const char kTestCCNumberIncomplete[] = "4111111111"; 114 const char kTestCCNumberIncomplete[] = "4111111111";
(...skipping 2294 matching lines...) Expand 10 before | Expand all | Expand 10 after
2409 EXPECT_EQ( 2409 EXPECT_EQ(
2410 2, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount()); 2410 2, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount());
2411 } 2411 }
2412 2412
2413 TEST_F(AutofillDialogControllerTest, ShippingSectionCanBeHidden) { 2413 TEST_F(AutofillDialogControllerTest, ShippingSectionCanBeHidden) {
2414 FormFieldData email_field; 2414 FormFieldData email_field;
2415 email_field.autocomplete_attribute = "email"; 2415 email_field.autocomplete_attribute = "email";
2416 FormFieldData cc_field; 2416 FormFieldData cc_field;
2417 cc_field.autocomplete_attribute = "cc-number"; 2417 cc_field.autocomplete_attribute = "cc-number";
2418 FormFieldData billing_field; 2418 FormFieldData billing_field;
2419 billing_field.autocomplete_attribute = "billing region"; 2419 billing_field.autocomplete_attribute = "billing address-level1";
2420 2420
2421 FormData form_data; 2421 FormData form_data;
2422 form_data.fields.push_back(email_field); 2422 form_data.fields.push_back(email_field);
2423 form_data.fields.push_back(cc_field); 2423 form_data.fields.push_back(cc_field);
2424 form_data.fields.push_back(billing_field); 2424 form_data.fields.push_back(billing_field);
2425 2425
2426 AutofillProfile full_profile(test::GetVerifiedProfile()); 2426 AutofillProfile full_profile(test::GetVerifiedProfile());
2427 controller()->GetTestingManager()->AddTestingProfile(&full_profile); 2427 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
2428 SetUpControllerWithFormData(form_data); 2428 SetUpControllerWithFormData(form_data);
2429 2429
2430 SwitchToAutofill(); 2430 SwitchToAutofill();
2431 2431
2432 EXPECT_FALSE(controller()->SectionIsActive(SECTION_SHIPPING)); 2432 EXPECT_FALSE(controller()->SectionIsActive(SECTION_SHIPPING));
2433 2433
2434 FillCreditCardInputs(); 2434 FillCreditCardInputs();
2435 controller()->OnAccept(); 2435 controller()->OnAccept();
2436 EXPECT_TRUE(form_structure()); 2436 EXPECT_TRUE(form_structure());
2437 } 2437 }
2438 2438
2439 TEST_F(AutofillDialogControllerTest, ShippingSectionCanBeHiddenForWallet) { 2439 TEST_F(AutofillDialogControllerTest, ShippingSectionCanBeHiddenForWallet) {
2440 FormFieldData email_field; 2440 FormFieldData email_field;
2441 email_field.autocomplete_attribute = "email"; 2441 email_field.autocomplete_attribute = "email";
2442 FormFieldData cc_field; 2442 FormFieldData cc_field;
2443 cc_field.autocomplete_attribute = "cc-number"; 2443 cc_field.autocomplete_attribute = "cc-number";
2444 FormFieldData billing_field; 2444 FormFieldData billing_field;
2445 billing_field.autocomplete_attribute = "billing region"; 2445 billing_field.autocomplete_attribute = "billing address-level1";
2446 2446
2447 FormData form_data; 2447 FormData form_data;
2448 form_data.fields.push_back(email_field); 2448 form_data.fields.push_back(email_field);
2449 form_data.fields.push_back(cc_field); 2449 form_data.fields.push_back(cc_field);
2450 form_data.fields.push_back(billing_field); 2450 form_data.fields.push_back(billing_field);
2451 2451
2452 SetUpControllerWithFormData(form_data); 2452 SetUpControllerWithFormData(form_data);
2453 EXPECT_FALSE(controller()->SectionIsActive(SECTION_SHIPPING)); 2453 EXPECT_FALSE(controller()->SectionIsActive(SECTION_SHIPPING));
2454 EXPECT_FALSE(controller()->IsShippingAddressRequired()); 2454 EXPECT_FALSE(controller()->IsShippingAddressRequired());
2455 2455
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
3144 }; 3144 };
3145 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 3145 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
3146 for (size_t i = 0; i < arraysize(kSupportedCardIdrs); ++i) { 3146 for (size_t i = 0; i < arraysize(kSupportedCardIdrs); ++i) {
3147 SCOPED_TRACE(base::IntToString(i)); 3147 SCOPED_TRACE(base::IntToString(i));
3148 gfx::Image supported_card_icon = rb.GetImageNamed(kSupportedCardIdrs[i]); 3148 gfx::Image supported_card_icon = rb.GetImageNamed(kSupportedCardIdrs[i]);
3149 EXPECT_GE(placeholder_icon.Width(), supported_card_icon.Width()); 3149 EXPECT_GE(placeholder_icon.Width(), supported_card_icon.Width());
3150 EXPECT_GE(placeholder_icon.Height(), supported_card_icon.Height()); 3150 EXPECT_GE(placeholder_icon.Height(), supported_card_icon.Height());
3151 } 3151 }
3152 } 3152 }
3153 3153
3154 TEST_F(AutofillDialogControllerTest, NoPartiallySupportedCountriesSuggested) {
3155 SwitchToAutofill();
3156
3157 std::string partially_supported_country = "KR";
3158 ASSERT_FALSE(i18ninput::CountryIsFullySupported(partially_supported_country));
3159 ASSERT_FALSE(controller()->MenuModelForSection(SECTION_BILLING));
3160
3161 AutofillProfile verified_profile(test::GetVerifiedProfile());
3162 verified_profile.SetRawInfo(ADDRESS_HOME_COUNTRY,
3163 ASCIIToUTF16(partially_supported_country));
3164 controller()->GetTestingManager()->AddTestingProfile(&verified_profile);
3165
3166 EXPECT_FALSE(
3167 controller()->SuggestionStateForSection(SECTION_BILLING).visible);
3168 }
3169
3170 TEST_F(AutofillDialogControllerTest, CountryChangeUpdatesSection) { 3154 TEST_F(AutofillDialogControllerTest, CountryChangeUpdatesSection) {
3171 TestAutofillDialogView* view = controller()->GetView(); 3155 TestAutofillDialogView* view = controller()->GetView();
3172 view->ClearSectionUpdates(); 3156 view->ClearSectionUpdates();
3173 3157
3174 controller()->UserEditedOrActivatedInput(SECTION_SHIPPING, 3158 controller()->UserEditedOrActivatedInput(SECTION_SHIPPING,
3175 ADDRESS_HOME_COUNTRY, 3159 ADDRESS_HOME_COUNTRY,
3176 gfx::NativeView(), 3160 gfx::NativeView(),
3177 gfx::Rect(), 3161 gfx::Rect(),
3178 ASCIIToUTF16("Belarus"), 3162 ASCIIToUTF16("Belarus"),
3179 true); 3163 true);
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
3444 form_data.fields[0] = field; 3428 form_data.fields[0] = field;
3445 3429
3446 // Add MC to FormData; Wallet is enabled. 3430 // Add MC to FormData; Wallet is enabled.
3447 SetUpControllerWithFormData(form_data); 3431 SetUpControllerWithFormData(form_data);
3448 EXPECT_TRUE(controller()->IsPayingWithWallet()); 3432 EXPECT_TRUE(controller()->IsPayingWithWallet());
3449 // Even though Discover isn't in FormData, it's allowed because Wallet always 3433 // Even though Discover isn't in FormData, it's allowed because Wallet always
3450 // generates a MC Virtual card. 3434 // generates a MC Virtual card.
3451 ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberDiscover, true); 3435 ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberDiscover, true);
3452 } 3436 }
3453 3437
3454 TEST_F(AutofillDialogControllerTest, CountriesWithDependentLocalityHidden) {
3455 ui::ComboboxModel* model =
3456 controller()->ComboboxModelForAutofillType(ADDRESS_BILLING_COUNTRY);
3457 for (int i = 0; i < model->GetItemCount(); ++i) {
3458 EXPECT_NE(base::ASCIIToUTF16("China"), model->GetItemAt(i));
3459 EXPECT_NE(base::ASCIIToUTF16("South Korea"), model->GetItemAt(i));
3460 }
3461
3462 model = controller()->ComboboxModelForAutofillType(ADDRESS_HOME_COUNTRY);
3463 for (int i = 0; i < model->GetItemCount(); ++i) {
3464 EXPECT_NE(base::ASCIIToUTF16("China"), model->GetItemAt(i));
3465 EXPECT_NE(base::ASCIIToUTF16("South Korea"), model->GetItemAt(i));
3466 }
3467 }
3468
3469 TEST_F(AutofillDialogControllerTest, DontSuggestHiddenCountries) {
3470 SwitchToAutofill();
3471
3472 FieldValueMap outputs;
3473 outputs[ADDRESS_HOME_COUNTRY] = ASCIIToUTF16("US");
3474 controller()->GetView()->SetUserInput(SECTION_SHIPPING, outputs);
3475
3476 AutofillProfile cn_profile(test::GetVerifiedProfile());
3477 cn_profile.SetRawInfo(NAME_FULL, ASCIIToUTF16("Chinese User"));
3478 cn_profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("CN"));
3479 controller()->GetTestingManager()->AddTestingProfile(&cn_profile);
3480
3481 controller()->UserEditedOrActivatedInput(
3482 SECTION_SHIPPING,
3483 NAME_FULL,
3484 gfx::NativeView(),
3485 gfx::Rect(),
3486 cn_profile.GetRawInfo(NAME_FULL).substr(0, 1),
3487 true);
3488 EXPECT_EQ(UNKNOWN_TYPE, controller()->popup_input_type());
3489
3490 AutofillProfile us_profile(test::GetVerifiedProfile());
3491 us_profile.SetRawInfo(NAME_FULL, ASCIIToUTF16("American User"));
3492 ASSERT_NE(cn_profile.GetRawInfo(NAME_FULL)[0],
3493 us_profile.GetRawInfo(NAME_FULL)[0]);
3494 controller()->GetTestingManager()->AddTestingProfile(&us_profile);
3495
3496 controller()->UserEditedOrActivatedInput(
3497 SECTION_SHIPPING,
3498 NAME_FULL,
3499 gfx::NativeView(),
3500 gfx::Rect(),
3501 us_profile.GetRawInfo(NAME_FULL).substr(0, 1),
3502 true);
3503 EXPECT_EQ(NAME_FULL, controller()->popup_input_type());
3504 }
3505
3506 TEST_F(AutofillDialogControllerTest, SuggestCountrylessProfiles) { 3438 TEST_F(AutofillDialogControllerTest, SuggestCountrylessProfiles) {
3507 SwitchToAutofill(); 3439 SwitchToAutofill();
3508 3440
3509 FieldValueMap outputs; 3441 FieldValueMap outputs;
3510 outputs[ADDRESS_HOME_COUNTRY] = ASCIIToUTF16("US"); 3442 outputs[ADDRESS_HOME_COUNTRY] = ASCIIToUTF16("US");
3511 controller()->GetView()->SetUserInput(SECTION_SHIPPING, outputs); 3443 controller()->GetView()->SetUserInput(SECTION_SHIPPING, outputs);
3512 3444
3513 AutofillProfile profile(test::GetVerifiedProfile()); 3445 AutofillProfile profile(test::GetVerifiedProfile());
3514 profile.SetRawInfo(NAME_FULL, ASCIIToUTF16("The Man Without a Country")); 3446 profile.SetRawInfo(NAME_FULL, ASCIIToUTF16("The Man Without a Country"));
3515 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, base::string16()); 3447 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, base::string16());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
3567 EXPECT_EQ(ASCIIToUTF16("United States"), form_structure()->field(2)->value); 3499 EXPECT_EQ(ASCIIToUTF16("United States"), form_structure()->field(2)->value);
3568 EXPECT_EQ(ADDRESS_HOME_COUNTRY, 3500 EXPECT_EQ(ADDRESS_HOME_COUNTRY,
3569 form_structure()->field(3)->Type().GetStorableType()); 3501 form_structure()->field(3)->Type().GetStorableType());
3570 EXPECT_EQ(ASCIIToUTF16("US"), form_structure()->field(3)->value); 3502 EXPECT_EQ(ASCIIToUTF16("US"), form_structure()->field(3)->value);
3571 EXPECT_EQ(ADDRESS_HOME_COUNTRY, 3503 EXPECT_EQ(ADDRESS_HOME_COUNTRY,
3572 form_structure()->field(4)->Type().GetStorableType()); 3504 form_structure()->field(4)->Type().GetStorableType());
3573 EXPECT_EQ(ASCIIToUTF16("United States"), form_structure()->field(4)->value); 3505 EXPECT_EQ(ASCIIToUTF16("United States"), form_structure()->field(4)->value);
3574 } 3506 }
3575 3507
3576 } // namespace autofill 3508 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc ('k') | chrome/browser/ui/autofill/autofill_dialog_i18n_input.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698