OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "chrome/browser/ui/autofill/country_combobox_model.h" |
| 6 |
| 7 #include "components/autofill/core/browser/autofill_country.h" |
| 8 #include "components/autofill/core/browser/test_personal_data_manager.h" |
| 9 #include "testing/gmock/include/gmock/gmock.h" |
| 10 #include "testing/gmock_mutant.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 namespace autofill { |
| 14 |
| 15 namespace { |
| 16 |
| 17 const char kTestCountry[] = "AQ"; |
| 18 |
| 19 class MockObserver : public CountryComboboxModelObserver { |
| 20 public: |
| 21 MOCK_METHOD1(OnCountryComboboxModelChanged, void(CountryComboboxModel*)); |
| 22 }; |
| 23 |
| 24 } // namespace |
| 25 |
| 26 TEST(CountryComboboxModel, SelectCountryAndDefault) { |
| 27 TestPersonalDataManager manager; |
| 28 CountryComboboxModel model(manager); |
| 29 EXPECT_TRUE(model.IsDefaultIndexSelected()); |
| 30 |
| 31 MockObserver observer; |
| 32 model.AddCountryComboboxObserver(&observer); |
| 33 EXPECT_CALL(observer, OnCountryComboboxModelChanged(&model)).Times(2); |
| 34 |
| 35 const std::string default_country = model.GetSelectedCountryCode(); |
| 36 ASSERT_NE(default_country, kTestCountry); |
| 37 |
| 38 model.SelectCountry(kTestCountry); |
| 39 EXPECT_EQ(kTestCountry, model.GetSelectedCountryCode()); |
| 40 EXPECT_FALSE(model.IsDefaultIndexSelected()); |
| 41 |
| 42 // Selecting the default index should result in a selected index change. |
| 43 model.SelectDefaultIndex(); |
| 44 EXPECT_EQ(default_country, model.GetSelectedCountryCode()); |
| 45 EXPECT_TRUE(model.IsDefaultIndexSelected()); |
| 46 } |
| 47 |
| 48 TEST(CountryComboboxModel, RespectsManagersDefaultCountry) { |
| 49 TestPersonalDataManager manager; |
| 50 manager.set_timezone_country_code(kTestCountry); |
| 51 |
| 52 CountryComboboxModel model(manager); |
| 53 EXPECT_TRUE(model.IsDefaultIndexSelected()); |
| 54 EXPECT_EQ(kTestCountry, model.GetSelectedCountryCode()); |
| 55 } |
| 56 |
| 57 } // namespace autofill |
OLD | NEW |