Commit 6977524e authored by estade@chromium.org's avatar estade@chromium.org

Disable wallet in countries where it's not supported, take 2.

Only disable it if there's no indication the user might be interested in US addresses. App locale is not taken into account because many international users set theirs to en-US.

BUG=323641

Review URL: https://codereview.chromium.org/106033007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243735 0039d316-1c4b-4281-b951-d872f2087c98
parent a9808479
...@@ -736,10 +736,8 @@ bool AutofillDialogControllerImpl::ShouldShowSpinner() const { ...@@ -736,10 +736,8 @@ bool AutofillDialogControllerImpl::ShouldShowSpinner() const {
SignedInState() == REQUIRES_PASSIVE_SIGN_IN; SignedInState() == REQUIRES_PASSIVE_SIGN_IN;
} }
// TODO(estade): Only show account chooser for Wallet in the US.
// http://crbug.com/323641
bool AutofillDialogControllerImpl::ShouldShowAccountChooser() const { bool AutofillDialogControllerImpl::ShouldShowAccountChooser() const {
return !ShouldShowSpinner(); return !ShouldShowSpinner() && GetManager()->IsCountryOfInterest("US");
} }
bool AutofillDialogControllerImpl::ShouldShowSignInWebView() const { bool AutofillDialogControllerImpl::ShouldShowSignInWebView() const {
......
...@@ -2721,10 +2721,18 @@ TEST_F(AutofillDialogControllerTest, InputEditability) { ...@@ -2721,10 +2721,18 @@ TEST_F(AutofillDialogControllerTest, InputEditability) {
// When the default country is something besides US, wallet is not selected // When the default country is something besides US, wallet is not selected
// and the account chooser shouldn't be visible. // and the account chooser shouldn't be visible.
// TODO(estade): this is disabled until http://crbug.com/323641 is fixed. TEST_F(AutofillDialogControllerTest, HideWalletInOtherCountries) {
TEST_F(AutofillDialogControllerTest, DISABLED_HideWalletInOtherCountries) { // Addresses from different countries.
AutofillProfile us_profile(base::GenerateGUID(), kSettingsOrigin),
es_profile(base::GenerateGUID(), kSettingsOrigin),
es_profile2(base::GenerateGUID(), kSettingsOrigin);
us_profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US"));
es_profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("ES"));
es_profile2.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("ES"));
// If US is indicated (via timezone), show Wallet.
ResetControllerWithFormData(DefaultFormData()); ResetControllerWithFormData(DefaultFormData());
controller()->GetTestingManager()->set_default_country_code("US"); controller()->GetTestingManager()->set_timezone_country_code("US");
controller()->Show(); controller()->Show();
EXPECT_TRUE( EXPECT_TRUE(
controller()->AccountChooserModelForTesting()->WalletIsSelected()); controller()->AccountChooserModelForTesting()->WalletIsSelected());
...@@ -2734,11 +2742,47 @@ TEST_F(AutofillDialogControllerTest, DISABLED_HideWalletInOtherCountries) { ...@@ -2734,11 +2742,47 @@ TEST_F(AutofillDialogControllerTest, DISABLED_HideWalletInOtherCountries) {
EXPECT_TRUE( EXPECT_TRUE(
controller()->AccountChooserModelForTesting()->WalletIsSelected()); controller()->AccountChooserModelForTesting()->WalletIsSelected());
// If US is not indicated, don't show Wallet.
ResetControllerWithFormData(DefaultFormData()); ResetControllerWithFormData(DefaultFormData());
controller()->GetTestingManager()->set_default_country_code("ES"); controller()->GetTestingManager()->set_timezone_country_code("ES");
controller()->Show(); controller()->Show();
controller()->OnDidFetchWalletCookieValue(std::string());
controller()->OnDidGetWalletItems(CompleteAndValidWalletItems());
EXPECT_FALSE(controller()->ShouldShowAccountChooser()); EXPECT_FALSE(controller()->ShouldShowAccountChooser());
EXPECT_FALSE(
// If US is indicated (via a profile), show Wallet.
ResetControllerWithFormData(DefaultFormData());
controller()->GetTestingManager()->set_timezone_country_code("ES");
controller()->GetTestingManager()->AddTestingProfile(&us_profile);
controller()->Show();
controller()->OnDidFetchWalletCookieValue(std::string());
controller()->OnDidGetWalletItems(CompleteAndValidWalletItems());
EXPECT_TRUE(controller()->ShouldShowAccountChooser());
EXPECT_TRUE(
controller()->AccountChooserModelForTesting()->WalletIsSelected());
// Make sure the profile doesn't just override the timezone.
ResetControllerWithFormData(DefaultFormData());
controller()->GetTestingManager()->set_timezone_country_code("US");
controller()->GetTestingManager()->AddTestingProfile(&es_profile);
controller()->Show();
controller()->OnDidFetchWalletCookieValue(std::string());
controller()->OnDidGetWalletItems(CompleteAndValidWalletItems());
EXPECT_TRUE(controller()->ShouldShowAccountChooser());
EXPECT_TRUE(
controller()->AccountChooserModelForTesting()->WalletIsSelected());
// Only takes one US address to enable Wallet.
ResetControllerWithFormData(DefaultFormData());
controller()->GetTestingManager()->set_timezone_country_code("FR");
controller()->GetTestingManager()->AddTestingProfile(&es_profile);
controller()->GetTestingManager()->AddTestingProfile(&es_profile2);
controller()->GetTestingManager()->AddTestingProfile(&us_profile);
controller()->Show();
controller()->OnDidFetchWalletCookieValue(std::string());
controller()->OnDidGetWalletItems(CompleteAndValidWalletItems());
EXPECT_TRUE(controller()->ShouldShowAccountChooser());
EXPECT_TRUE(
controller()->AccountChooserModelForTesting()->WalletIsSelected()); controller()->AccountChooserModelForTesting()->WalletIsSelected());
} }
......
...@@ -682,6 +682,10 @@ bool PersonalDataManager::IsAutofillEnabled() const { ...@@ -682,6 +682,10 @@ bool PersonalDataManager::IsAutofillEnabled() const {
return pref_service_->GetBoolean(prefs::kAutofillEnabled); return pref_service_->GetBoolean(prefs::kAutofillEnabled);
} }
std::string PersonalDataManager::CountryCodeForCurrentTimezone() const {
return base::CountryCodeForCurrentTimezone();
}
// static // static
bool PersonalDataManager::IsValidLearnableProfile( bool PersonalDataManager::IsValidLearnableProfile(
const AutofillProfile& profile, const AutofillProfile& profile,
...@@ -745,6 +749,31 @@ std::string PersonalDataManager::MergeProfile( ...@@ -745,6 +749,31 @@ std::string PersonalDataManager::MergeProfile(
return guid; return guid;
} }
bool PersonalDataManager::IsCountryOfInterest(const std::string& country_code)
const {
DCHECK_EQ(2U, country_code.size());
const std::vector<AutofillProfile*>& profiles = web_profiles();
std::list<std::string> country_codes;
for (size_t i = 0; i < profiles.size(); ++i) {
country_codes.push_back(StringToLowerASCII(UTF16ToASCII(
profiles[i]->GetRawInfo(ADDRESS_HOME_COUNTRY))));
}
std::string timezone_country = CountryCodeForCurrentTimezone();
if (!timezone_country.empty())
country_codes.push_back(StringToLowerASCII(timezone_country));
// Only take the locale into consideration if all else fails.
if (country_codes.empty()) {
country_codes.push_back(StringToLowerASCII(
AutofillCountry::CountryCodeForLocale(app_locale())));
}
return std::find(country_codes.begin(), country_codes.end(),
StringToLowerASCII(country_code)) != country_codes.end();
}
const std::string& PersonalDataManager::GetDefaultCountryCodeForNewAddress() const std::string& PersonalDataManager::GetDefaultCountryCodeForNewAddress()
const { const {
if (default_country_code_.empty()) if (default_country_code_.empty())
...@@ -752,7 +781,7 @@ const std::string& PersonalDataManager::GetDefaultCountryCodeForNewAddress() ...@@ -752,7 +781,7 @@ const std::string& PersonalDataManager::GetDefaultCountryCodeForNewAddress()
// Failing that, guess based on system timezone. // Failing that, guess based on system timezone.
if (default_country_code_.empty()) if (default_country_code_.empty())
default_country_code_ = base::CountryCodeForCurrentTimezone(); default_country_code_ = CountryCodeForCurrentTimezone();
// Failing that, guess based on locale. // Failing that, guess based on locale.
if (default_country_code_.empty()) if (default_country_code_.empty())
......
...@@ -184,6 +184,12 @@ class PersonalDataManager : public WebDataServiceConsumer, ...@@ -184,6 +184,12 @@ class PersonalDataManager : public WebDataServiceConsumer,
const std::string& app_locale, const std::string& app_locale,
std::vector<AutofillProfile>* merged_profiles); std::vector<AutofillProfile>* merged_profiles);
// Returns true if |country_code| is a country that the user is likely to
// be associated with the user. More concretely, it checks if there are any
// addresses with this country or if the user's system timezone is in the
// given country.
virtual bool IsCountryOfInterest(const std::string& country_code) const;
// Returns our best guess for the country a user is likely to use when // Returns our best guess for the country a user is likely to use when
// inputting a new address. The value is calculated once and cached, so it // inputting a new address. The value is calculated once and cached, so it
// will only update when Chrome is restarted. // will only update when Chrome is restarted.
...@@ -255,6 +261,9 @@ class PersonalDataManager : public WebDataServiceConsumer, ...@@ -255,6 +261,9 @@ class PersonalDataManager : public WebDataServiceConsumer,
// Returns the value of the AutofillEnabled pref. // Returns the value of the AutofillEnabled pref.
virtual bool IsAutofillEnabled() const; virtual bool IsAutofillEnabled() const;
// Overrideable for testing.
virtual std::string CountryCodeForCurrentTimezone() const;
// For tests. // For tests.
const AutofillMetrics* metric_logger() const { return metric_logger_.get(); } const AutofillMetrics* metric_logger() const { return metric_logger_.get(); }
......
...@@ -9,8 +9,7 @@ ...@@ -9,8 +9,7 @@
namespace autofill { namespace autofill {
TestPersonalDataManager::TestPersonalDataManager() TestPersonalDataManager::TestPersonalDataManager()
: PersonalDataManager("en-US"), : PersonalDataManager("en-US") {}
default_country_code_("US") {}
TestPersonalDataManager::~TestPersonalDataManager() {} TestPersonalDataManager::~TestPersonalDataManager() {}
...@@ -31,6 +30,11 @@ const std::vector<AutofillProfile*>& TestPersonalDataManager::GetProfiles() ...@@ -31,6 +30,11 @@ const std::vector<AutofillProfile*>& TestPersonalDataManager::GetProfiles()
return profiles_; return profiles_;
} }
const std::vector<AutofillProfile*>& TestPersonalDataManager::web_profiles()
const {
return profiles_;
}
const std::vector<CreditCard*>& TestPersonalDataManager:: const std::vector<CreditCard*>& TestPersonalDataManager::
GetCreditCards() const { GetCreditCards() const {
return credit_cards_; return credit_cards_;
...@@ -48,9 +52,9 @@ std::string TestPersonalDataManager::SaveImportedCreditCard( ...@@ -48,9 +52,9 @@ std::string TestPersonalDataManager::SaveImportedCreditCard(
return imported_credit_card.guid(); return imported_credit_card.guid();
} }
const std::string& TestPersonalDataManager::GetDefaultCountryCodeForNewAddress() std::string TestPersonalDataManager::CountryCodeForCurrentTimezone()
const { const {
return default_country_code_; return timezone_country_code_;
} }
} // namespace autofill } // namespace autofill
...@@ -27,6 +27,7 @@ class TestPersonalDataManager : public PersonalDataManager { ...@@ -27,6 +27,7 @@ class TestPersonalDataManager : public PersonalDataManager {
void AddTestingCreditCard(CreditCard* credit_card); void AddTestingCreditCard(CreditCard* credit_card);
virtual const std::vector<AutofillProfile*>& GetProfiles() const OVERRIDE; virtual const std::vector<AutofillProfile*>& GetProfiles() const OVERRIDE;
virtual const std::vector<AutofillProfile*>& web_profiles() const OVERRIDE;
virtual const std::vector<CreditCard*>& GetCreditCards() const OVERRIDE; virtual const std::vector<CreditCard*>& GetCreditCards() const OVERRIDE;
virtual std::string SaveImportedProfile( virtual std::string SaveImportedProfile(
...@@ -34,11 +35,10 @@ class TestPersonalDataManager : public PersonalDataManager { ...@@ -34,11 +35,10 @@ class TestPersonalDataManager : public PersonalDataManager {
virtual std::string SaveImportedCreditCard( virtual std::string SaveImportedCreditCard(
const CreditCard& imported_credit_card) OVERRIDE; const CreditCard& imported_credit_card) OVERRIDE;
virtual const std::string& GetDefaultCountryCodeForNewAddress() const virtual std::string CountryCodeForCurrentTimezone() const OVERRIDE;
OVERRIDE;
void set_default_country_code(const std::string& default_country_code) { void set_timezone_country_code(const std::string& timezone_country_code) {
default_country_code_ = default_country_code; timezone_country_code_ = timezone_country_code;
} }
const AutofillProfile& imported_profile() { return imported_profile_; } const AutofillProfile& imported_profile() { return imported_profile_; }
...@@ -49,7 +49,7 @@ class TestPersonalDataManager : public PersonalDataManager { ...@@ -49,7 +49,7 @@ class TestPersonalDataManager : public PersonalDataManager {
std::vector<CreditCard*> credit_cards_; std::vector<CreditCard*> credit_cards_;
AutofillProfile imported_profile_; AutofillProfile imported_profile_;
CreditCard imported_credit_card_; CreditCard imported_credit_card_;
std::string default_country_code_; std::string timezone_country_code_;
}; };
} // namespace autofill } // namespace autofill
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment