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

Unified 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, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc
diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc
index 3cb3adaf4fae14e06020121f467e6b0aeda7363a..55e16bc869ec80a338458f5b68fef6d0e8001c09 100644
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc
@@ -340,6 +340,7 @@ class TestAutofillDialogController
using AutofillDialogControllerImpl::NOT_CHECKED;
using AutofillDialogControllerImpl::popup_input_type;
using AutofillDialogControllerImpl::SignedInState;
+ using AutofillDialogControllerImpl::CountryComboboxModelForSection;
protected:
virtual PersonalDataManager* GetManager() const OVERRIDE {
@@ -3108,7 +3109,8 @@ TEST_F(AutofillDialogControllerTest, NoPartiallySupportedCountriesSuggested) {
ASCIIToUTF16(partially_supported_country));
controller()->GetTestingManager()->AddTestingProfile(&verified_profile);
- EXPECT_FALSE(controller()->MenuModelForSection(SECTION_BILLING));
+ EXPECT_FALSE(
+ controller()->SuggestionStateForSection(SECTION_BILLING).visible);
}
class AutofillDialogControllerI18nTest : public AutofillDialogControllerTest {
@@ -3246,4 +3248,78 @@ TEST_F(AutofillDialogControllerI18nTest, ValidButUnverifiedWhenRulesFail) {
EXPECT_FALSE(imported_profile.IsVerified());
}
+TEST_F(AutofillDialogControllerI18nTest, LimitedCountryChoices) {
+ CountryComboboxModel* shipping_country_model =
+ controller()->CountryComboboxModelForSection(SECTION_SHIPPING);
+ const int default_number_of_countries =
+ shipping_country_model->GetItemCount();
+ // We show a lot of countries by default, but the exact number doesn't matter.
+ EXPECT_GT(default_number_of_countries, 50);
+
+ // Create a form data that simulates:
+ // <select autocomplete="billing country">
+ // <option value="AU">Down Under</option>
+ // <option value="GRMNY">Germany</option>
+ // </select>
+ // The first option has a valid value but unknown content. The second option
+ // is the reverse (Germany's country code is DE). Either one should be
+ // recognized due to the one functional component.
+ FormData form_data;
+ FormFieldData field;
+ field.autocomplete_attribute = "billing country";
+ field.option_contents.push_back(ASCIIToUTF16("Down Under"));
+ field.option_values.push_back(ASCIIToUTF16("AU"));
+ field.option_contents.push_back(ASCIIToUTF16("Germany"));
+ field.option_values.push_back(ASCIIToUTF16("GRMNY"));
+ form_data.fields.push_back(field);
+ ResetControllerWithFormData(form_data);
+ 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
+
+ // Shipping model shouldn't have changed.
+ shipping_country_model =
+ controller()->CountryComboboxModelForSection(SECTION_SHIPPING);
+ EXPECT_EQ(default_number_of_countries,
+ shipping_country_model->GetItemCount());
+ // Billing model now only has two items.
+ CountryComboboxModel* billing_country_model =
+ controller()->CountryComboboxModelForSection(SECTION_BILLING);
+ ASSERT_EQ(2, billing_country_model->GetItemCount());
+ EXPECT_EQ(billing_country_model->GetItemAt(0), ASCIIToUTF16("Australia"));
+ EXPECT_EQ(billing_country_model->GetItemAt(1), ASCIIToUTF16("Germany"));
+
+ // Make sure it also applies to profile suggestions.
+ AutofillProfile verified_profile(test::GetVerifiedProfile());
+ 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.
+ controller()->GetTestingManager()->AddTestingProfile(&verified_profile);
+ // Don't show a suggestion if the only one that exists is disabled.
+ EXPECT_FALSE(
+ controller()->SuggestionStateForSection(SECTION_BILLING).visible);
+
+ // Add a profile with an acceptable country; suggestion should be shown.
+ ResetControllerWithFormData(form_data);
+ controller()->Show();
+ AutofillProfile verified_profile2(test::GetVerifiedProfile2());
+ verified_profile2.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("AU"));
+ controller()->GetTestingManager()->AddTestingProfile(&verified_profile);
+ controller()->GetTestingManager()->AddTestingProfile(&verified_profile2);
+ ui::MenuModel* model = controller()->MenuModelForSection(SECTION_BILLING);
+ ASSERT_TRUE(model);
+ EXPECT_EQ(4, model->GetItemCount());
+ EXPECT_FALSE(model->IsEnabledAt(0));
+ EXPECT_TRUE(model->IsEnabledAt(1));
+
+ // Add <input type="text" autocomplete="billing country"></input>
+ // This should open up selection of all countries again.
+ FormFieldData field2;
+ field2.autocomplete_attribute = "billing country";
+ form_data.fields.push_back(field2);
+ ResetControllerWithFormData(form_data);
+ controller()->Show();
+
+ billing_country_model =
+ controller()->CountryComboboxModelForSection(SECTION_BILLING);
+ EXPECT_EQ(default_number_of_countries,
+ billing_country_model->GetItemCount());
+}
+
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698