| OLD | NEW |
| 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 3090 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3101 | 3101 |
| 3102 std::string partially_supported_country = "KR"; | 3102 std::string partially_supported_country = "KR"; |
| 3103 ASSERT_FALSE(i18ninput::CountryIsFullySupported(partially_supported_country)); | 3103 ASSERT_FALSE(i18ninput::CountryIsFullySupported(partially_supported_country)); |
| 3104 ASSERT_FALSE(controller()->MenuModelForSection(SECTION_BILLING)); | 3104 ASSERT_FALSE(controller()->MenuModelForSection(SECTION_BILLING)); |
| 3105 | 3105 |
| 3106 AutofillProfile verified_profile(test::GetVerifiedProfile()); | 3106 AutofillProfile verified_profile(test::GetVerifiedProfile()); |
| 3107 verified_profile.SetRawInfo(ADDRESS_HOME_COUNTRY, | 3107 verified_profile.SetRawInfo(ADDRESS_HOME_COUNTRY, |
| 3108 ASCIIToUTF16(partially_supported_country)); | 3108 ASCIIToUTF16(partially_supported_country)); |
| 3109 controller()->GetTestingManager()->AddTestingProfile(&verified_profile); | 3109 controller()->GetTestingManager()->AddTestingProfile(&verified_profile); |
| 3110 | 3110 |
| 3111 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_BILLING)); | 3111 EXPECT_FALSE( |
| 3112 controller()->SuggestionStateForSection(SECTION_BILLING).visible); |
| 3112 } | 3113 } |
| 3113 | 3114 |
| 3114 class AutofillDialogControllerI18nTest : public AutofillDialogControllerTest { | 3115 class AutofillDialogControllerI18nTest : public AutofillDialogControllerTest { |
| 3115 private: | 3116 private: |
| 3116 i18ninput::ScopedEnableForTesting enabled_; | 3117 i18ninput::ScopedEnableForTesting enabled_; |
| 3117 }; | 3118 }; |
| 3118 | 3119 |
| 3119 TEST_F(AutofillDialogControllerI18nTest, CountryChangeUpdatesSection) { | 3120 TEST_F(AutofillDialogControllerI18nTest, CountryChangeUpdatesSection) { |
| 3120 TestAutofillDialogView* view = controller()->GetView(); | 3121 TestAutofillDialogView* view = controller()->GetView(); |
| 3121 view->ClearSectionUpdates(); | 3122 view->ClearSectionUpdates(); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3239 | 3240 |
| 3240 // Profiles saved while rules are unavailable shouldn't be verified. | 3241 // Profiles saved while rules are unavailable shouldn't be verified. |
| 3241 const AutofillProfile& imported_profile = | 3242 const AutofillProfile& imported_profile = |
| 3242 controller()->GetTestingManager()->imported_profile(); | 3243 controller()->GetTestingManager()->imported_profile(); |
| 3243 ASSERT_EQ(imported_profile.GetRawInfo(NAME_FULL), | 3244 ASSERT_EQ(imported_profile.GetRawInfo(NAME_FULL), |
| 3244 full_profile.GetRawInfo(NAME_FULL)); | 3245 full_profile.GetRawInfo(NAME_FULL)); |
| 3245 EXPECT_EQ(imported_profile.origin(), GURL(kSourceUrl).GetOrigin().spec()); | 3246 EXPECT_EQ(imported_profile.origin(), GURL(kSourceUrl).GetOrigin().spec()); |
| 3246 EXPECT_FALSE(imported_profile.IsVerified()); | 3247 EXPECT_FALSE(imported_profile.IsVerified()); |
| 3247 } | 3248 } |
| 3248 | 3249 |
| 3250 TEST_F(AutofillDialogControllerI18nTest, LimitedCountryChoices) { |
| 3251 ui::ComboboxModel* shipping_country_model = |
| 3252 controller()->ComboboxModelForAutofillType(ADDRESS_HOME_COUNTRY); |
| 3253 const int default_number_of_countries = |
| 3254 shipping_country_model->GetItemCount(); |
| 3255 // We show a lot of countries by default, but the exact number doesn't matter. |
| 3256 EXPECT_GT(default_number_of_countries, 50); |
| 3257 |
| 3258 // Create a form data that simulates: |
| 3259 // <select autocomplete="billing country"> |
| 3260 // <option value="AU">Down Under</option> |
| 3261 // <option value="">fR</option> <!-- Case doesn't matter --> |
| 3262 // <option value="GRMNY">Germany</option> |
| 3263 // </select> |
| 3264 // Only country codes are respected, whether they're in value or the option's |
| 3265 // text content. Thus the first two options should be recognized. |
| 3266 FormData form_data; |
| 3267 FormFieldData field; |
| 3268 field.autocomplete_attribute = "billing country"; |
| 3269 field.option_contents.push_back(ASCIIToUTF16("Down Under")); |
| 3270 field.option_values.push_back(ASCIIToUTF16("AU")); |
| 3271 field.option_contents.push_back(ASCIIToUTF16("Fr")); |
| 3272 field.option_values.push_back(ASCIIToUTF16("")); |
| 3273 field.option_contents.push_back(ASCIIToUTF16("Germany")); |
| 3274 field.option_values.push_back(ASCIIToUTF16("GRMNY")); |
| 3275 form_data.fields.push_back(field); |
| 3276 ResetControllerWithFormData(form_data); |
| 3277 controller()->Show(); |
| 3278 |
| 3279 // Shipping model shouldn't have changed. |
| 3280 shipping_country_model = |
| 3281 controller()->ComboboxModelForAutofillType(ADDRESS_HOME_COUNTRY); |
| 3282 EXPECT_EQ(default_number_of_countries, |
| 3283 shipping_country_model->GetItemCount()); |
| 3284 // Billing model now only has two items. |
| 3285 ui::ComboboxModel* billing_country_model = |
| 3286 controller()->ComboboxModelForAutofillType(ADDRESS_BILLING_COUNTRY); |
| 3287 ASSERT_EQ(2, billing_country_model->GetItemCount()); |
| 3288 EXPECT_EQ(billing_country_model->GetItemAt(0), ASCIIToUTF16("Australia")); |
| 3289 EXPECT_EQ(billing_country_model->GetItemAt(1), ASCIIToUTF16("France")); |
| 3290 |
| 3291 // Make sure it also applies to profile suggestions. |
| 3292 AutofillProfile us_profile(test::GetVerifiedProfile()); |
| 3293 us_profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); |
| 3294 controller()->GetTestingManager()->AddTestingProfile(&us_profile); |
| 3295 // Don't show a suggestion if the only one that exists is disabled. |
| 3296 EXPECT_FALSE( |
| 3297 controller()->SuggestionStateForSection(SECTION_BILLING).visible); |
| 3298 |
| 3299 // Add a profile with an acceptable country; suggestion should be shown. |
| 3300 ResetControllerWithFormData(form_data); |
| 3301 controller()->Show(); |
| 3302 AutofillProfile au_profile(test::GetVerifiedProfile2()); |
| 3303 au_profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("AU")); |
| 3304 controller()->GetTestingManager()->AddTestingProfile(&us_profile); |
| 3305 controller()->GetTestingManager()->AddTestingProfile(&au_profile); |
| 3306 ui::MenuModel* model = controller()->MenuModelForSection(SECTION_BILLING); |
| 3307 ASSERT_TRUE(model); |
| 3308 EXPECT_EQ(4, model->GetItemCount()); |
| 3309 EXPECT_FALSE(model->IsEnabledAt(0)); |
| 3310 EXPECT_TRUE(model->IsEnabledAt(1)); |
| 3311 |
| 3312 // Add <input type="text" autocomplete="billing country"></input> |
| 3313 // This should open up selection of all countries again. |
| 3314 FormFieldData field2; |
| 3315 field2.autocomplete_attribute = "billing country"; |
| 3316 form_data.fields.push_back(field2); |
| 3317 ResetControllerWithFormData(form_data); |
| 3318 controller()->Show(); |
| 3319 |
| 3320 billing_country_model = |
| 3321 controller()->ComboboxModelForAutofillType(ADDRESS_BILLING_COUNTRY); |
| 3322 EXPECT_EQ(default_number_of_countries, |
| 3323 billing_country_model->GetItemCount()); |
| 3324 } |
| 3325 |
| 3249 } // namespace autofill | 3326 } // namespace autofill |
| OLD | NEW |