Index: chrome/browser/ui/autofill/country_combobox_model_unittest.cc |
diff --git a/chrome/browser/ui/autofill/country_combobox_model_unittest.cc b/chrome/browser/ui/autofill/country_combobox_model_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..74f0fb7f324a9b212690a3a5259cd88dbd384f39 |
--- /dev/null |
+++ b/chrome/browser/ui/autofill/country_combobox_model_unittest.cc |
@@ -0,0 +1,57 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/autofill/country_combobox_model.h" |
+ |
+#include "components/autofill/core/browser/autofill_country.h" |
+#include "components/autofill/core/browser/test_personal_data_manager.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
+#include "testing/gmock_mutant.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace autofill { |
+ |
+namespace { |
+ |
+const char kTestCountry[] = "AQ"; |
+ |
+class MockObserver : public CountryComboboxModelObserver { |
+ public: |
+ MOCK_METHOD1(OnCountryComboboxModelChanged, void(CountryComboboxModel*)); |
+}; |
+ |
+} // namespace |
+ |
+TEST(CountryComboboxModel, SelectCountryAndDefault) { |
+ TestPersonalDataManager manager; |
+ CountryComboboxModel model(manager); |
+ EXPECT_TRUE(model.IsDefaultIndexSelected()); |
+ |
+ MockObserver observer; |
+ model.AddCountryComboboxObserver(&observer); |
+ EXPECT_CALL(observer, OnCountryComboboxModelChanged(&model)).Times(2); |
+ |
+ const std::string default_country = model.GetSelectedCountryCode(); |
+ ASSERT_NE(default_country, kTestCountry); |
+ |
+ model.SelectCountry(kTestCountry); |
+ EXPECT_EQ(kTestCountry, model.GetSelectedCountryCode()); |
+ EXPECT_FALSE(model.IsDefaultIndexSelected()); |
+ |
+ // Selecting the default index should result in a selected index change. |
+ model.SelectDefaultIndex(); |
+ EXPECT_EQ(default_country, model.GetSelectedCountryCode()); |
+ EXPECT_TRUE(model.IsDefaultIndexSelected()); |
+} |
+ |
+TEST(CountryComboboxModel, RespectsManagersDefaultCountry) { |
+ TestPersonalDataManager manager; |
+ manager.set_timezone_country_code(kTestCountry); |
+ |
+ CountryComboboxModel model(manager); |
+ EXPECT_TRUE(model.IsDefaultIndexSelected()); |
+ EXPECT_EQ(kTestCountry, model.GetSelectedCountryCode()); |
+} |
+ |
+} // namespace autofill |