Add unit test for the Settings API Bubble.
[chromium-blink-merge.git] / chrome / browser / ui / autofill / country_combobox_model_unittest.cc
blob56ebd857c0e53aec66b2ce5b106e848a80788a69
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/autofill/country_combobox_model.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/test/base/testing_profile.h"
10 #include "components/autofill/core/browser/autofill_country.h"
11 #include "components/autofill/core/browser/test_personal_data_manager.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_ui.h"
14 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_ui_component.h"
16 namespace autofill {
18 class CountryComboboxModelTest : public testing::Test {
19 public:
20 CountryComboboxModelTest() {
21 manager_.Init(NULL, profile_.GetPrefs(), false);
22 manager_.set_timezone_country_code("KR");
23 model_.reset(new CountryComboboxModel(
24 manager_, base::Callback<bool(const std::string&)>()));
27 TestPersonalDataManager* manager() { return &manager_; }
28 CountryComboboxModel* model() { return model_.get(); }
30 private:
31 // NB: order is important here - |profile_| must go down after |manager_|.
32 TestingProfile profile_;
33 TestPersonalDataManager manager_;
34 scoped_ptr<CountryComboboxModel> model_;
37 TEST_F(CountryComboboxModelTest, DefaultCountryCode) {
38 std::string default_country = model()->GetDefaultCountryCode();
39 EXPECT_EQ(manager()->GetDefaultCountryCodeForNewAddress(), default_country);
41 AutofillCountry country(default_country,
42 g_browser_process->GetApplicationLocale());
43 EXPECT_EQ(country.name(), model()->GetItemAt(0));
46 TEST_F(CountryComboboxModelTest, AllCountriesHaveComponents) {
47 for (int i = 0; i < model()->GetItemCount(); ++i) {
48 if (model()->IsItemSeparatorAt(i))
49 continue;
51 std::string country_code = model()->countries()[i]->country_code();
52 std::vector< ::i18n::addressinput::AddressUiComponent> components =
53 ::i18n::addressinput::BuildComponents(
54 country_code, std::string(), NULL);
55 EXPECT_FALSE(components.empty());
59 } // namespace autofill