| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/ui/autofill/country_combobox_model.h" | 5 #include "components/autofill/core/browser/country_combobox_model.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "chrome/browser/browser_process.h" | |
| 10 #include "chrome/browser/signin/account_tracker_service_factory.h" | |
| 11 #include "chrome/browser/signin/signin_manager_factory.h" | |
| 12 #include "chrome/test/base/testing_profile.h" | |
| 13 #include "components/autofill/core/browser/autofill_country.h" | 9 #include "components/autofill/core/browser/autofill_country.h" |
| 10 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 14 #include "components/autofill/core/browser/test_personal_data_manager.h" | 11 #include "components/autofill/core/browser/test_personal_data_manager.h" |
| 15 #include "components/signin/core/browser/account_tracker_service.h" | 12 #include "components/prefs/pref_service.h" |
| 16 #include "components/signin/core/browser/signin_manager.h" | |
| 17 #include "content/public/test/test_browser_thread_bundle.h" | |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui
.h" | 14 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui
.h" |
| 20 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui
_component.h" | 15 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui
_component.h" |
| 21 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/localizati
on.h" | 16 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/localizati
on.h" |
| 22 | 17 |
| 23 namespace autofill { | 18 namespace autofill { |
| 24 | 19 |
| 25 class CountryComboboxModelTest : public testing::Test { | 20 class CountryComboboxModelTest : public testing::Test { |
| 26 public: | 21 public: |
| 27 CountryComboboxModelTest() { | 22 CountryComboboxModelTest() |
| 28 manager_.Init( | 23 : pref_service_(autofill::test::PrefServiceForTesting()) { |
| 29 NULL, profile_.GetPrefs(), | 24 manager_.SetTestingPrefService(pref_service_.get()); |
| 30 AccountTrackerServiceFactory::GetForProfile(&profile_), | |
| 31 SigninManagerFactory::GetForProfile(&profile_), false); | |
| 32 manager_.set_timezone_country_code("KR"); | 25 manager_.set_timezone_country_code("KR"); |
| 33 model_.reset(new CountryComboboxModel()); | 26 model_.reset(new CountryComboboxModel()); |
| 34 model_->SetCountries(manager_, base::Callback<bool(const std::string&)>()); | 27 model_->SetCountries(manager_, base::Callback<bool(const std::string&)>(), |
| 28 "en-US"); |
| 35 } | 29 } |
| 36 | 30 |
| 31 void TearDown() override { manager_.SetTestingPrefService(nullptr); } |
| 32 |
| 37 TestPersonalDataManager* manager() { return &manager_; } | 33 TestPersonalDataManager* manager() { return &manager_; } |
| 38 CountryComboboxModel* model() { return model_.get(); } | 34 CountryComboboxModel* model() { return model_.get(); } |
| 39 | 35 |
| 40 private: | 36 private: |
| 41 // NB: order is important here - |profile_| must go down after |manager_|. | |
| 42 content::TestBrowserThreadBundle thread_bundle_; | |
| 43 TestingProfile profile_; | |
| 44 TestPersonalDataManager manager_; | 37 TestPersonalDataManager manager_; |
| 38 std::unique_ptr<PrefService> pref_service_; |
| 45 std::unique_ptr<CountryComboboxModel> model_; | 39 std::unique_ptr<CountryComboboxModel> model_; |
| 46 }; | 40 }; |
| 47 | 41 |
| 48 TEST_F(CountryComboboxModelTest, DefaultCountryCode) { | 42 TEST_F(CountryComboboxModelTest, DefaultCountryCode) { |
| 49 std::string default_country = model()->GetDefaultCountryCode(); | 43 std::string default_country = model()->GetDefaultCountryCode(); |
| 50 EXPECT_EQ(manager()->GetDefaultCountryCodeForNewAddress(), default_country); | 44 EXPECT_EQ(manager()->GetDefaultCountryCodeForNewAddress(), default_country); |
| 51 | 45 |
| 52 AutofillCountry country(default_country, | 46 AutofillCountry country(default_country, "en-US"); |
| 53 g_browser_process->GetApplicationLocale()); | |
| 54 EXPECT_EQ(country.name(), model()->GetItemAt(0)); | 47 EXPECT_EQ(country.name(), model()->GetItemAt(0)); |
| 55 } | 48 } |
| 56 | 49 |
| 57 TEST_F(CountryComboboxModelTest, AllCountriesHaveComponents) { | 50 TEST_F(CountryComboboxModelTest, AllCountriesHaveComponents) { |
| 58 ::i18n::addressinput::Localization localization; | 51 ::i18n::addressinput::Localization localization; |
| 59 std::string unused; | 52 std::string unused; |
| 60 for (int i = 0; i < model()->GetItemCount(); ++i) { | 53 for (int i = 0; i < model()->GetItemCount(); ++i) { |
| 61 if (model()->IsItemSeparatorAt(i)) | 54 if (model()->IsItemSeparatorAt(i)) |
| 62 continue; | 55 continue; |
| 63 | 56 |
| 64 std::string country_code = model()->countries()[i]->country_code(); | 57 std::string country_code = model()->countries()[i]->country_code(); |
| 65 std::vector< ::i18n::addressinput::AddressUiComponent> components = | 58 std::vector<::i18n::addressinput::AddressUiComponent> components = |
| 66 ::i18n::addressinput::BuildComponents( | 59 ::i18n::addressinput::BuildComponents(country_code, localization, |
| 67 country_code, localization, std::string(), &unused); | 60 std::string(), &unused); |
| 68 EXPECT_FALSE(components.empty()) << " for country " << country_code; | 61 EXPECT_FALSE(components.empty()) << " for country " << country_code; |
| 69 } | 62 } |
| 70 } | 63 } |
| 71 | 64 |
| 72 } // namespace autofill | 65 } // namespace autofill |
| OLD | NEW |