diff options
author | dbeam@chromium.org <dbeam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-06 19:22:39 +0000 |
---|---|---|
committer | dbeam@chromium.org <dbeam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-06 19:22:39 +0000 |
commit | fb2605a4f532fbe739e3c93fc530254f28838bc6 (patch) | |
tree | 02f2282ed66733006ceda32873c20296146f589c | |
parent | 7a54bf4ba03877c2af8eeb9468f8a12dad19213a (diff) | |
download | chromium_src-fb2605a4f532fbe739e3c93fc530254f28838bc6.zip chromium_src-fb2605a4f532fbe739e3c93fc530254f28838bc6.tar.gz chromium_src-fb2605a4f532fbe739e3c93fc530254f28838bc6.tar.bz2 |
rAc: enable i18n by default, allow it to be disabled via
--disable-autofill-address-i18n.
R=estade@chromium.org
BUG=317839
TEST=country combobox shows up without flags, tests pass
Review URL: https://codereview.chromium.org/155263002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@249469 0039d316-1c4b-4281-b951-d872f2087c98
7 files changed, 40 insertions, 100 deletions
diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc index 3dfe808..51d48bc 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc @@ -619,76 +619,6 @@ IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, FillInputFromAutofill) { } } -// For now, no matter what, the country must always be US. See -// http://crbug.com/247518 -IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, - FillInputFromForeignProfile) { - AutofillProfile full_profile(test::GetFullProfile()); - full_profile.SetInfo(AutofillType(ADDRESS_HOME_COUNTRY), - ASCIIToUTF16("France"), "en-US"); - controller()->GetTestingManager()->AddTestingProfile(&full_profile); - - // Select "Add new shipping address...". - ui::MenuModel* model = controller()->MenuModelForSection(SECTION_SHIPPING); - model->ActivatedAt(model->GetItemCount() - 2); - ASSERT_TRUE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); - - const DetailInputs& inputs = - controller()->RequestedFieldsForSection(SECTION_SHIPPING); - const ServerFieldType triggering_type = inputs[0].type; - base::string16 value = full_profile.GetRawInfo(triggering_type); - scoped_ptr<AutofillDialogViewTester> view = GetViewTester(); - view->SetTextContentsOfInput(triggering_type, - value.substr(0, value.size() / 2)); - view->ActivateInput(triggering_type); - - ASSERT_EQ(triggering_type, controller()->popup_input_type()); - controller()->DidAcceptSuggestion(base::string16(), 0); - - // All inputs should be filled. - AutofillProfileWrapper wrapper(&full_profile); - for (size_t i = 0; i < inputs.size(); ++i) { - const ServerFieldType type = inputs[i].type; - base::string16 expectation = - AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY ? - ASCIIToUTF16("United States") : wrapper.GetInfo(AutofillType(type)); - EXPECT_EQ(expectation, view->GetTextContentsOfInput(type)); - } - - // Now simulate some user edits and try again. - std::vector<base::string16> expectations; - for (size_t i = 0; i < inputs.size(); ++i) { - if (controller()->ComboboxModelForAutofillType(inputs[i].type)) { - expectations.push_back(base::string16()); - continue; - } - base::string16 users_input = i % 2 == 0 ? base::string16() - : ASCIIToUTF16("dummy"); - view->SetTextContentsOfInput(inputs[i].type, users_input); - // Empty inputs should be filled, others should be left alone. - base::string16 expectation = - inputs[i].type == triggering_type || users_input.empty() ? - wrapper.GetInfo(AutofillType(inputs[i].type)) : - users_input; - if (AutofillType(inputs[i].type).GetStorableType() == ADDRESS_HOME_COUNTRY) - expectation = ASCIIToUTF16("United States"); - - expectations.push_back(expectation); - } - - view->SetTextContentsOfInput(triggering_type, - value.substr(0, value.size() / 2)); - view->ActivateInput(triggering_type); - ASSERT_EQ(triggering_type, controller()->popup_input_type()); - controller()->DidAcceptSuggestion(base::string16(), 0); - - for (size_t i = 0; i < inputs.size(); ++i) { - if (controller()->ComboboxModelForAutofillType(inputs[i].type)) - continue; - EXPECT_EQ(expectations[i], view->GetTextContentsOfInput(inputs[i].type)); - } -} - // This test makes sure that picking a profile variant in the Autofill // popup works as expected. IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, @@ -1448,9 +1378,9 @@ class AutofillDialogControllerI18nTest : public AutofillDialogControllerTest { AutofillDialogControllerI18nTest() {} virtual ~AutofillDialogControllerI18nTest() {} - virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { - command_line->AppendSwitch(::switches::kEnableAutofillAddressI18n); - CHECK(i18ninput::Enabled()); + virtual void SetUp() OVERRIDE { + i18ninput::EnableForTesting(); + AutofillDialogControllerTest::SetUp(); } protected: diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc index babb594..f73b8f2 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc @@ -573,6 +573,7 @@ class AutofillDialogControllerTest : public ChromeRenderViewHostTestHarness { const std::string& cc_number, bool should_pass) { FieldValueMap outputs; + outputs[ADDRESS_BILLING_COUNTRY] = ASCIIToUTF16("United States"); outputs[CREDIT_CARD_NUMBER] = UTF8ToUTF16(cc_number); ValidityMessages messages = controller()->InputsAreValid(section, outputs); @@ -787,6 +788,7 @@ TEST_F(AutofillDialogControllerTest, ExpirationDateValidity) { exp_month_model->GetItemAt(exp_month_model->GetItemCount() - 1); FieldValueMap outputs; + outputs[ADDRESS_BILLING_COUNTRY] = ASCIIToUTF16("United States"); outputs[CREDIT_CARD_EXP_MONTH] = default_month_value; outputs[CREDIT_CARD_EXP_4_DIGIT_YEAR] = default_year_value; @@ -814,8 +816,10 @@ TEST_F(AutofillDialogControllerTest, BillingNameValidation) { // Construct FieldValueMap from AutofillProfile data. SwitchToAutofill(); - // Input an empty billing name. FieldValueMap outputs; + outputs[ADDRESS_BILLING_COUNTRY] = ASCIIToUTF16("United States"); + + // Input an empty billing name. outputs[NAME_BILLING_FULL] = base::string16(); ValidityMessages messages = controller()->InputsAreValid(SECTION_BILLING, outputs); @@ -836,31 +840,29 @@ TEST_F(AutofillDialogControllerTest, BillingNameValidation) { controller()->OnDidGetWalletItems(wallet_items.Pass()); // Input an empty billing name. Data source should not change this behavior. - FieldValueMap wallet_outputs; - wallet_outputs[NAME_BILLING_FULL] = base::string16(); - messages = controller()->InputsAreValid(SECTION_CC_BILLING, wallet_outputs); + outputs[NAME_BILLING_FULL] = base::string16(); + messages = controller()->InputsAreValid(SECTION_CC_BILLING, outputs); EXPECT_TRUE(HasUnsureError(messages, NAME_BILLING_FULL)); // Input a one name billing name. Wallet does not currently support this. - wallet_outputs[NAME_BILLING_FULL] = ASCIIToUTF16("Bob"); - messages = controller()->InputsAreValid(SECTION_CC_BILLING, wallet_outputs); + outputs[NAME_BILLING_FULL] = ASCIIToUTF16("Bob"); + messages = controller()->InputsAreValid(SECTION_CC_BILLING, outputs); EXPECT_TRUE(messages.HasSureError(NAME_BILLING_FULL)); // Input a two name billing name. - wallet_outputs[NAME_BILLING_FULL] = ASCIIToUTF16("Bob Barker"); - messages = controller()->InputsAreValid(SECTION_CC_BILLING, wallet_outputs); + outputs[NAME_BILLING_FULL] = ASCIIToUTF16("Bob Barker"); + messages = controller()->InputsAreValid(SECTION_CC_BILLING, outputs); EXPECT_FALSE(HasAnyError(messages, NAME_BILLING_FULL)); // Input a more than two name billing name. - wallet_outputs[NAME_BILLING_FULL] = - ASCIIToUTF16("John Jacob Jingleheimer Schmidt"), - messages = controller()->InputsAreValid(SECTION_CC_BILLING, wallet_outputs); + outputs[NAME_BILLING_FULL] = ASCIIToUTF16("John Jacob Jingleheimer Schmidt"), + messages = controller()->InputsAreValid(SECTION_CC_BILLING, outputs); EXPECT_FALSE(HasAnyError(messages, NAME_BILLING_FULL)); // Input a billing name with lots of crazy whitespace. - wallet_outputs[NAME_BILLING_FULL] = + outputs[NAME_BILLING_FULL] = ASCIIToUTF16(" \\n\\r John \\n Jacob Jingleheimer \\t Schmidt "), - messages = controller()->InputsAreValid(SECTION_CC_BILLING, wallet_outputs); + messages = controller()->InputsAreValid(SECTION_CC_BILLING, outputs); EXPECT_FALSE(HasAnyError(messages, NAME_BILLING_FULL)); } @@ -2978,10 +2980,8 @@ TEST_F(AutofillDialogControllerTest, IconReservedForCreditCardField) { class AutofillDialogControllerI18nTest : public AutofillDialogControllerTest { public: - // AutofillDialogControllerTest implementation. virtual void SetUp() OVERRIDE { - CommandLine* command_line = CommandLine::ForCurrentProcess(); - command_line->AppendSwitch(::switches::kEnableAutofillAddressI18n); + i18ninput::EnableForTesting(); AutofillDialogControllerTest::SetUp(); } }; diff --git a/chrome/browser/ui/autofill/autofill_dialog_i18n_input.cc b/chrome/browser/ui/autofill/autofill_dialog_i18n_input.cc index fdc758e..3a843f9 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_i18n_input.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_i18n_input.cc @@ -23,6 +23,8 @@ namespace i18ninput { namespace { +static bool g_enabled_for_testing_ = false; + using base::UTF16ToUTF8; using ::i18n::addressinput::AddressData; using ::i18n::addressinput::AddressField; @@ -38,8 +40,15 @@ DetailInput::Length LengthFromHint(AddressUiComponent::LengthHint hint) { } // namespace bool Enabled() { + if (g_enabled_for_testing_) + return true; + CommandLine* command_line = CommandLine::ForCurrentProcess(); - return command_line->HasSwitch(::switches::kEnableAutofillAddressI18n); + return !command_line->HasSwitch(::switches::kDisableAutofillAddressI18n); +} + +void EnableForTesting() { + g_enabled_for_testing_ = true; } void BuildAddressInputs(common::AddressType address_type, diff --git a/chrome/browser/ui/autofill/autofill_dialog_i18n_input.h b/chrome/browser/ui/autofill/autofill_dialog_i18n_input.h index c1b4e72..7cd0ddd 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_i18n_input.h +++ b/chrome/browser/ui/autofill/autofill_dialog_i18n_input.h @@ -30,6 +30,9 @@ namespace i18ninput { // Returns true if the internationalized address input is enabled. bool Enabled(); +// Call this to force Enabled() to always return true while testing. +void EnableForTesting(); + // Builds internationalized address input fields for |country_code| and adds // them (at most 13) to |inputs|. |address_type| is which kind of address to // build (e.g. billing or shipping). diff --git a/chrome/browser/ui/autofill/autofill_dialog_i18n_input_unittest.cc b/chrome/browser/ui/autofill/autofill_dialog_i18n_input_unittest.cc index aacbb99..e6b4f94 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_i18n_input_unittest.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_i18n_input_unittest.cc @@ -18,13 +18,11 @@ const size_t kNumberOfAddressLinesUS = 7; } // namespace -TEST(AutofillDialogI18nInput, DisabledByDefaultEnabledByFlag) { - EXPECT_FALSE(Enabled()); - +TEST(AutofillDialogI18nInput, FlagFlipsEnabled) { + bool enabled = Enabled(); CommandLine* command_line = CommandLine::ForCurrentProcess(); - command_line->AppendSwitch(::switches::kEnableAutofillAddressI18n); - - EXPECT_TRUE(Enabled()); + command_line->AppendSwitch(::switches::kDisableAutofillAddressI18n); + EXPECT_NE(enabled, Enabled()); } TEST(AutofillDialogI18nInput, USShippingAddress) { diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index 7efb66e..300604c 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -270,6 +270,9 @@ const char kDisableAsyncDns[] = "disable-async-dns"; const char kDisableAuthNegotiateCnameLookup[] = "disable-auth-negotiate-cname-lookup"; +// Disables the i18n address input widget for the requestAutocomplete() dialog. +const char kDisableAutofillAddressI18n[] = "disable-autofill-address-i18n"; + // Disables background mode (background apps will not keep chrome running in // the background). const char kDisableBackgroundMode[] = "disable-background-mode"; @@ -559,9 +562,6 @@ const char kEnableAsyncDns[] = "enable-async-dns"; // HttpAuthHandlerNegotiate::CreateSPN for more background. const char kEnableAuthNegotiatePort[] = "enable-auth-negotiate-port"; -// Enables the i18n address input widget for the requestAutocomplete() dialog. -const char kEnableAutofillAddressI18n[] = "enable-autofill-address-i18n"; - // Enable using a public suffix based domain matching for autofill of passwords. const char kEnablePasswordAutofillPublicSuffixDomainMatching[] = "enable-password-autofill-public-suffix-domain-matching"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index b0afd4e..730d14e 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -85,6 +85,7 @@ extern const char kDiagnosticsFormat[]; extern const char kDiagnosticsRecovery[]; extern const char kDisableAsyncDns[]; extern const char kDisableAuthNegotiateCnameLookup[]; +extern const char kDisableAutofillAddressI18n[]; extern const char kDisableBackgroundMode[]; extern const char kDisableBackgroundNetworking[]; extern const char kDisableBundledPpapiFlash[]; @@ -164,7 +165,6 @@ extern const char kEnableAppWindowControls[]; extern const char kEnableAppsShowOnFirstPaint[]; extern const char kEnableAsyncDns[]; extern const char kEnableAuthNegotiatePort[]; -extern const char kEnableAutofillAddressI18n[]; extern const char kEnableAutologin[]; extern const char kEnableBenchmarking[]; extern const char kEnableClientHints[]; |