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

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

Issue 178263004: rAc - Only show countries we're able to fill in. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix android build Created 6 years, 9 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 3087 matching lines...) Expand 10 before | Expand all | Expand 10 after
3098 3098
3099 std::string partially_supported_country = "KR"; 3099 std::string partially_supported_country = "KR";
3100 ASSERT_FALSE(i18ninput::CountryIsFullySupported(partially_supported_country)); 3100 ASSERT_FALSE(i18ninput::CountryIsFullySupported(partially_supported_country));
3101 ASSERT_FALSE(controller()->MenuModelForSection(SECTION_BILLING)); 3101 ASSERT_FALSE(controller()->MenuModelForSection(SECTION_BILLING));
3102 3102
3103 AutofillProfile verified_profile(test::GetVerifiedProfile()); 3103 AutofillProfile verified_profile(test::GetVerifiedProfile());
3104 verified_profile.SetRawInfo(ADDRESS_HOME_COUNTRY, 3104 verified_profile.SetRawInfo(ADDRESS_HOME_COUNTRY,
3105 ASCIIToUTF16(partially_supported_country)); 3105 ASCIIToUTF16(partially_supported_country));
3106 controller()->GetTestingManager()->AddTestingProfile(&verified_profile); 3106 controller()->GetTestingManager()->AddTestingProfile(&verified_profile);
3107 3107
3108 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_BILLING)); 3108 EXPECT_FALSE(
3109 controller()->SuggestionStateForSection(SECTION_BILLING).visible);
3109 } 3110 }
3110 3111
3111 TEST_F(AutofillDialogControllerTest, CountryChangeUpdatesSection) { 3112 TEST_F(AutofillDialogControllerTest, CountryChangeUpdatesSection) {
3112 TestAutofillDialogView* view = controller()->GetView(); 3113 TestAutofillDialogView* view = controller()->GetView();
3113 view->ClearSectionUpdates(); 3114 view->ClearSectionUpdates();
3114 3115
3115 controller()->UserEditedOrActivatedInput(SECTION_SHIPPING, 3116 controller()->UserEditedOrActivatedInput(SECTION_SHIPPING,
3116 ADDRESS_HOME_COUNTRY, 3117 ADDRESS_HOME_COUNTRY,
3117 gfx::NativeView(), 3118 gfx::NativeView(),
3118 gfx::Rect(), 3119 gfx::Rect(),
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
3231 3232
3232 // Profiles saved while rules are unavailable shouldn't be verified. 3233 // Profiles saved while rules are unavailable shouldn't be verified.
3233 const AutofillProfile& imported_profile = 3234 const AutofillProfile& imported_profile =
3234 controller()->GetTestingManager()->imported_profile(); 3235 controller()->GetTestingManager()->imported_profile();
3235 ASSERT_EQ(imported_profile.GetRawInfo(NAME_FULL), 3236 ASSERT_EQ(imported_profile.GetRawInfo(NAME_FULL),
3236 full_profile.GetRawInfo(NAME_FULL)); 3237 full_profile.GetRawInfo(NAME_FULL));
3237 EXPECT_EQ(imported_profile.origin(), GURL(kSourceUrl).GetOrigin().spec()); 3238 EXPECT_EQ(imported_profile.origin(), GURL(kSourceUrl).GetOrigin().spec());
3238 EXPECT_FALSE(imported_profile.IsVerified()); 3239 EXPECT_FALSE(imported_profile.IsVerified());
3239 } 3240 }
3240 3241
3242 TEST_F(AutofillDialogControllerTest, LimitedCountryChoices) {
3243 ui::ComboboxModel* shipping_country_model =
3244 controller()->ComboboxModelForAutofillType(ADDRESS_HOME_COUNTRY);
3245 const int default_number_of_countries =
3246 shipping_country_model->GetItemCount();
3247 // We show a lot of countries by default, but the exact number doesn't matter.
3248 EXPECT_GT(default_number_of_countries, 50);
3249
3250 // Create a form data that simulates:
3251 // <select autocomplete="billing country">
3252 // <option value="AU">Down Under</option>
3253 // <option value="">fR</option> <!-- Case doesn't matter -->
3254 // <option value="GRMNY">Germany</option>
3255 // </select>
3256 // Only country codes are respected, whether they're in value or the option's
3257 // text content. Thus the first two options should be recognized.
3258 FormData form_data;
3259 FormFieldData field;
3260 field.autocomplete_attribute = "billing country";
3261 field.option_contents.push_back(ASCIIToUTF16("Down Under"));
3262 field.option_values.push_back(ASCIIToUTF16("AU"));
3263 field.option_contents.push_back(ASCIIToUTF16("Fr"));
3264 field.option_values.push_back(ASCIIToUTF16(""));
3265 field.option_contents.push_back(ASCIIToUTF16("Germany"));
3266 field.option_values.push_back(ASCIIToUTF16("GRMNY"));
3267 form_data.fields.push_back(field);
3268 ResetControllerWithFormData(form_data);
3269 controller()->Show();
3270
3271 // Shipping model shouldn't have changed.
3272 shipping_country_model =
3273 controller()->ComboboxModelForAutofillType(ADDRESS_HOME_COUNTRY);
3274 EXPECT_EQ(default_number_of_countries,
3275 shipping_country_model->GetItemCount());
3276 // Billing model now only has two items.
3277 ui::ComboboxModel* billing_country_model =
3278 controller()->ComboboxModelForAutofillType(ADDRESS_BILLING_COUNTRY);
3279 ASSERT_EQ(2, billing_country_model->GetItemCount());
3280 EXPECT_EQ(billing_country_model->GetItemAt(0), ASCIIToUTF16("Australia"));
3281 EXPECT_EQ(billing_country_model->GetItemAt(1), ASCIIToUTF16("France"));
3282
3283 // Make sure it also applies to profile suggestions.
3284 AutofillProfile us_profile(test::GetVerifiedProfile());
3285 us_profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US"));
3286 controller()->GetTestingManager()->AddTestingProfile(&us_profile);
3287 // Don't show a suggestion if the only one that exists is disabled.
3288 EXPECT_FALSE(
3289 controller()->SuggestionStateForSection(SECTION_BILLING).visible);
3290
3291 // Add a profile with an acceptable country; suggestion should be shown.
3292 ResetControllerWithFormData(form_data);
3293 controller()->Show();
3294 AutofillProfile au_profile(test::GetVerifiedProfile2());
3295 au_profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("AU"));
3296 controller()->GetTestingManager()->AddTestingProfile(&us_profile);
3297 controller()->GetTestingManager()->AddTestingProfile(&au_profile);
3298 ui::MenuModel* model = controller()->MenuModelForSection(SECTION_BILLING);
3299 ASSERT_TRUE(model);
3300 EXPECT_EQ(4, model->GetItemCount());
3301 EXPECT_FALSE(model->IsEnabledAt(0));
3302 EXPECT_TRUE(model->IsEnabledAt(1));
3303
3304 // Add <input type="text" autocomplete="billing country"></input>
3305 // This should open up selection of all countries again.
3306 FormFieldData field2;
3307 field2.autocomplete_attribute = "billing country";
3308 form_data.fields.push_back(field2);
3309 ResetControllerWithFormData(form_data);
3310 controller()->Show();
3311
3312 billing_country_model =
3313 controller()->ComboboxModelForAutofillType(ADDRESS_BILLING_COUNTRY);
3314 EXPECT_EQ(default_number_of_countries,
3315 billing_country_model->GetItemCount());
3316 }
3317
3241 } // namespace autofill 3318 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc ('k') | chrome/browser/ui/autofill/autofill_dialog_models.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698