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

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: . 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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 MOCK_METHOD0(LoadRiskFingerprintData, void()); 333 MOCK_METHOD0(LoadRiskFingerprintData, void());
334 using AutofillDialogControllerImpl::AccountChooserModelForTesting; 334 using AutofillDialogControllerImpl::AccountChooserModelForTesting;
335 using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData; 335 using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData;
336 using AutofillDialogControllerImpl::IsEditingExistingData; 336 using AutofillDialogControllerImpl::IsEditingExistingData;
337 using AutofillDialogControllerImpl::IsManuallyEditingSection; 337 using AutofillDialogControllerImpl::IsManuallyEditingSection;
338 using AutofillDialogControllerImpl::IsPayingWithWallet; 338 using AutofillDialogControllerImpl::IsPayingWithWallet;
339 using AutofillDialogControllerImpl::IsSubmitPausedOn; 339 using AutofillDialogControllerImpl::IsSubmitPausedOn;
340 using AutofillDialogControllerImpl::NOT_CHECKED; 340 using AutofillDialogControllerImpl::NOT_CHECKED;
341 using AutofillDialogControllerImpl::popup_input_type; 341 using AutofillDialogControllerImpl::popup_input_type;
342 using AutofillDialogControllerImpl::SignedInState; 342 using AutofillDialogControllerImpl::SignedInState;
343 using AutofillDialogControllerImpl::CountryComboboxModelForSection;
343 344
344 protected: 345 protected:
345 virtual PersonalDataManager* GetManager() const OVERRIDE { 346 virtual PersonalDataManager* GetManager() const OVERRIDE {
346 return const_cast<TestAutofillDialogController*>(this)-> 347 return const_cast<TestAutofillDialogController*>(this)->
347 GetTestingManager(); 348 GetTestingManager();
348 } 349 }
349 350
350 virtual AddressValidator* GetValidator() OVERRIDE { 351 virtual AddressValidator* GetValidator() OVERRIDE {
351 return &mock_validator_; 352 return &mock_validator_;
352 } 353 }
(...skipping 2748 matching lines...) Expand 10 before | Expand all | Expand 10 after
3101 3102
3102 std::string partially_supported_country = "KR"; 3103 std::string partially_supported_country = "KR";
3103 ASSERT_FALSE(i18ninput::CountryIsFullySupported(partially_supported_country)); 3104 ASSERT_FALSE(i18ninput::CountryIsFullySupported(partially_supported_country));
3104 ASSERT_FALSE(controller()->MenuModelForSection(SECTION_BILLING)); 3105 ASSERT_FALSE(controller()->MenuModelForSection(SECTION_BILLING));
3105 3106
3106 AutofillProfile verified_profile(test::GetVerifiedProfile()); 3107 AutofillProfile verified_profile(test::GetVerifiedProfile());
3107 verified_profile.SetRawInfo(ADDRESS_HOME_COUNTRY, 3108 verified_profile.SetRawInfo(ADDRESS_HOME_COUNTRY,
3108 ASCIIToUTF16(partially_supported_country)); 3109 ASCIIToUTF16(partially_supported_country));
3109 controller()->GetTestingManager()->AddTestingProfile(&verified_profile); 3110 controller()->GetTestingManager()->AddTestingProfile(&verified_profile);
3110 3111
3111 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_BILLING)); 3112 EXPECT_FALSE(
3113 controller()->SuggestionStateForSection(SECTION_BILLING).visible);
3112 } 3114 }
3113 3115
3114 class AutofillDialogControllerI18nTest : public AutofillDialogControllerTest { 3116 class AutofillDialogControllerI18nTest : public AutofillDialogControllerTest {
3115 private: 3117 private:
3116 i18ninput::ScopedEnableForTesting enabled_; 3118 i18ninput::ScopedEnableForTesting enabled_;
3117 }; 3119 };
3118 3120
3119 TEST_F(AutofillDialogControllerI18nTest, CountryChangeUpdatesSection) { 3121 TEST_F(AutofillDialogControllerI18nTest, CountryChangeUpdatesSection) {
3120 TestAutofillDialogView* view = controller()->GetView(); 3122 TestAutofillDialogView* view = controller()->GetView();
3121 view->ClearSectionUpdates(); 3123 view->ClearSectionUpdates();
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
3239 3241
3240 // Profiles saved while rules are unavailable shouldn't be verified. 3242 // Profiles saved while rules are unavailable shouldn't be verified.
3241 const AutofillProfile& imported_profile = 3243 const AutofillProfile& imported_profile =
3242 controller()->GetTestingManager()->imported_profile(); 3244 controller()->GetTestingManager()->imported_profile();
3243 ASSERT_EQ(imported_profile.GetRawInfo(NAME_FULL), 3245 ASSERT_EQ(imported_profile.GetRawInfo(NAME_FULL),
3244 full_profile.GetRawInfo(NAME_FULL)); 3246 full_profile.GetRawInfo(NAME_FULL));
3245 EXPECT_EQ(imported_profile.origin(), GURL(kSourceUrl).GetOrigin().spec()); 3247 EXPECT_EQ(imported_profile.origin(), GURL(kSourceUrl).GetOrigin().spec());
3246 EXPECT_FALSE(imported_profile.IsVerified()); 3248 EXPECT_FALSE(imported_profile.IsVerified());
3247 } 3249 }
3248 3250
3251 TEST_F(AutofillDialogControllerI18nTest, LimitedCountryChoices) {
3252 CountryComboboxModel* shipping_country_model =
3253 controller()->CountryComboboxModelForSection(SECTION_SHIPPING);
3254 const int default_number_of_countries =
3255 shipping_country_model->GetItemCount();
3256 // We show a lot of countries by default, but the exact number doesn't matter.
3257 EXPECT_GT(default_number_of_countries, 50);
3258
3259 // Create a form data that simulates:
3260 // <select autocomplete="billing country">
3261 // <option value="AU">Down Under</option>
3262 // <option value="GRMNY">Germany</option>
3263 // </select>
3264 // The first option has a valid value but unknown content. The second option
3265 // is the reverse (Germany's country code is DE). Either one should be
3266 // recognized due to the one functional component.
3267 FormData form_data;
3268 FormFieldData field;
3269 field.autocomplete_attribute = "billing country";
3270 field.option_contents.push_back(ASCIIToUTF16("Down Under"));
3271 field.option_values.push_back(ASCIIToUTF16("AU"));
3272 field.option_contents.push_back(ASCIIToUTF16("Germany"));
3273 field.option_values.push_back(ASCIIToUTF16("GRMNY"));
3274 form_data.fields.push_back(field);
3275 ResetControllerWithFormData(form_data);
3276 controller()->Show();
Dan Beam 2014/03/01 03:38:10 ^ any reason you're not just writing this as a bro
Evan Stade 2014/03/03 18:37:00 unit tests are preferable to browser tests
Dan Beam 2014/03/03 22:20:00 fine
3277
3278 // Shipping model shouldn't have changed.
3279 shipping_country_model =
3280 controller()->CountryComboboxModelForSection(SECTION_SHIPPING);
3281 EXPECT_EQ(default_number_of_countries,
3282 shipping_country_model->GetItemCount());
3283 // Billing model now only has two items.
3284 CountryComboboxModel* billing_country_model =
3285 controller()->CountryComboboxModelForSection(SECTION_BILLING);
3286 ASSERT_EQ(2, billing_country_model->GetItemCount());
3287 EXPECT_EQ(billing_country_model->GetItemAt(0), ASCIIToUTF16("Australia"));
3288 EXPECT_EQ(billing_country_model->GetItemAt(1), ASCIIToUTF16("Germany"));
3289
3290 // Make sure it also applies to profile suggestions.
3291 AutofillProfile verified_profile(test::GetVerifiedProfile());
3292 verified_profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US"));
Dan Beam 2014/03/01 03:38:10 ^ can you name this variable us_profile or america
Evan Stade 2014/03/04 00:11:30 Done.
3293 controller()->GetTestingManager()->AddTestingProfile(&verified_profile);
3294 // Don't show a suggestion if the only one that exists is disabled.
3295 EXPECT_FALSE(
3296 controller()->SuggestionStateForSection(SECTION_BILLING).visible);
3297
3298 // Add a profile with an acceptable country; suggestion should be shown.
3299 ResetControllerWithFormData(form_data);
3300 controller()->Show();
3301 AutofillProfile verified_profile2(test::GetVerifiedProfile2());
3302 verified_profile2.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("AU"));
3303 controller()->GetTestingManager()->AddTestingProfile(&verified_profile);
3304 controller()->GetTestingManager()->AddTestingProfile(&verified_profile2);
3305 ui::MenuModel* model = controller()->MenuModelForSection(SECTION_BILLING);
3306 ASSERT_TRUE(model);
3307 EXPECT_EQ(4, model->GetItemCount());
3308 EXPECT_FALSE(model->IsEnabledAt(0));
3309 EXPECT_TRUE(model->IsEnabledAt(1));
3310
3311 // Add <input type="text" autocomplete="billing country"></input>
3312 // This should open up selection of all countries again.
3313 FormFieldData field2;
3314 field2.autocomplete_attribute = "billing country";
3315 form_data.fields.push_back(field2);
3316 ResetControllerWithFormData(form_data);
3317 controller()->Show();
3318
3319 billing_country_model =
3320 controller()->CountryComboboxModelForSection(SECTION_BILLING);
3321 EXPECT_EQ(default_number_of_countries,
3322 billing_country_model->GetItemCount());
3323 }
3324
3249 } // namespace autofill 3325 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698