| 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 "chrome/browser/ui/autofill/country_combobox_model.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include <memory> |
| 8 |
| 8 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/signin/account_tracker_service_factory.h" | 10 #include "chrome/browser/signin/account_tracker_service_factory.h" |
| 10 #include "chrome/browser/signin/signin_manager_factory.h" | 11 #include "chrome/browser/signin/signin_manager_factory.h" |
| 11 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
| 12 #include "components/autofill/core/browser/autofill_country.h" | 13 #include "components/autofill/core/browser/autofill_country.h" |
| 13 #include "components/autofill/core/browser/test_personal_data_manager.h" | 14 #include "components/autofill/core/browser/test_personal_data_manager.h" |
| 14 #include "components/signin/core/browser/account_tracker_service.h" | 15 #include "components/signin/core/browser/account_tracker_service.h" |
| 15 #include "components/signin/core/browser/signin_manager.h" | 16 #include "components/signin/core/browser/signin_manager.h" |
| 16 #include "content/public/test/test_browser_thread_bundle.h" | 17 #include "content/public/test/test_browser_thread_bundle.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 34 } | 35 } |
| 35 | 36 |
| 36 TestPersonalDataManager* manager() { return &manager_; } | 37 TestPersonalDataManager* manager() { return &manager_; } |
| 37 CountryComboboxModel* model() { return model_.get(); } | 38 CountryComboboxModel* model() { return model_.get(); } |
| 38 | 39 |
| 39 private: | 40 private: |
| 40 // NB: order is important here - |profile_| must go down after |manager_|. | 41 // NB: order is important here - |profile_| must go down after |manager_|. |
| 41 content::TestBrowserThreadBundle thread_bundle_; | 42 content::TestBrowserThreadBundle thread_bundle_; |
| 42 TestingProfile profile_; | 43 TestingProfile profile_; |
| 43 TestPersonalDataManager manager_; | 44 TestPersonalDataManager manager_; |
| 44 scoped_ptr<CountryComboboxModel> model_; | 45 std::unique_ptr<CountryComboboxModel> model_; |
| 45 }; | 46 }; |
| 46 | 47 |
| 47 TEST_F(CountryComboboxModelTest, DefaultCountryCode) { | 48 TEST_F(CountryComboboxModelTest, DefaultCountryCode) { |
| 48 std::string default_country = model()->GetDefaultCountryCode(); | 49 std::string default_country = model()->GetDefaultCountryCode(); |
| 49 EXPECT_EQ(manager()->GetDefaultCountryCodeForNewAddress(), default_country); | 50 EXPECT_EQ(manager()->GetDefaultCountryCodeForNewAddress(), default_country); |
| 50 | 51 |
| 51 AutofillCountry country(default_country, | 52 AutofillCountry country(default_country, |
| 52 g_browser_process->GetApplicationLocale()); | 53 g_browser_process->GetApplicationLocale()); |
| 53 EXPECT_EQ(country.name(), model()->GetItemAt(0)); | 54 EXPECT_EQ(country.name(), model()->GetItemAt(0)); |
| 54 } | 55 } |
| 55 | 56 |
| 56 TEST_F(CountryComboboxModelTest, AllCountriesHaveComponents) { | 57 TEST_F(CountryComboboxModelTest, AllCountriesHaveComponents) { |
| 57 ::i18n::addressinput::Localization localization; | 58 ::i18n::addressinput::Localization localization; |
| 58 std::string unused; | 59 std::string unused; |
| 59 for (int i = 0; i < model()->GetItemCount(); ++i) { | 60 for (int i = 0; i < model()->GetItemCount(); ++i) { |
| 60 if (model()->IsItemSeparatorAt(i)) | 61 if (model()->IsItemSeparatorAt(i)) |
| 61 continue; | 62 continue; |
| 62 | 63 |
| 63 std::string country_code = model()->countries()[i]->country_code(); | 64 std::string country_code = model()->countries()[i]->country_code(); |
| 64 std::vector< ::i18n::addressinput::AddressUiComponent> components = | 65 std::vector< ::i18n::addressinput::AddressUiComponent> components = |
| 65 ::i18n::addressinput::BuildComponents( | 66 ::i18n::addressinput::BuildComponents( |
| 66 country_code, localization, std::string(), &unused); | 67 country_code, localization, std::string(), &unused); |
| 67 EXPECT_FALSE(components.empty()); | 68 EXPECT_FALSE(components.empty()); |
| 68 } | 69 } |
| 69 } | 70 } |
| 70 | 71 |
| 71 } // namespace autofill | 72 } // namespace autofill |
| OLD | NEW |