Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(578)

Unified Diff: components/autofill/core/browser/address_combobox_model_unittest.cc

Issue 2849523003: Add billing address as a mandatory field of Payments credit cards. (Closed)
Patch Set: Added AddressComboboxModel unittests and fixed more compile issues. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/autofill/core/browser/address_combobox_model_unittest.cc
diff --git a/components/autofill/core/browser/address_combobox_model_unittest.cc b/components/autofill/core/browser/address_combobox_model_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7be2fa0a0fde897e370fe7328826486b1b37ac66
--- /dev/null
+++ b/components/autofill/core/browser/address_combobox_model_unittest.cc
@@ -0,0 +1,77 @@
+// Copyright 2017 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 "components/autofill/core/browser/address_combobox_model.h"
+
+#include "components/autofill/core/browser/autofill_test_utils.h"
+#include "components/autofill/core/browser/test_personal_data_manager.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/libaddressinput/src/cpp/include/libaddressinput/region_data.h"
+
+namespace autofill {
+
+namespace {
+const char kAppLocale[] = "fr-CA";
+}
+
+TEST(AddressComboboxModelTest, Empty) {
+ TestPersonalDataManager test_personal_data_manager;
+
+ AddressComboboxModel model(test_personal_data_manager, kAppLocale);
+ EXPECT_EQ(1, model.GetItemCount());
+ EXPECT_FALSE(model.IsItemSeparatorAt(0));
sebsg 2017/05/02 22:58:55 Can you also check that it's not at (1)?
MAD 2017/05/03 16:15:19 I can't since there's only one item. :-)
sebsg 2017/05/03 19:19:29 That makes sense :P
MAD 2017/05/03 23:50:47 Acknowledged.
+ EXPECT_TRUE(model.GetItemIdentifierAt(0).empty());
+ EXPECT_EQ(-1, model.GetIndexOfIdentifier("Anything"));
+}
+
+TEST(AddressComboboxModelTest, TwoAddresses) {
sebsg 2017/05/02 22:58:55 Can you also add a test with only one address? Tha
MAD 2017/05/03 16:15:19 We kind of do that in the test where we add a seco
+ TestPersonalDataManager test_personal_data_manager;
+ AutofillProfile profile1(test::GetFullProfile());
+ AutofillProfile profile2(test::GetFullProfile2());
+ test_personal_data_manager.AddTestingProfile(&profile1);
+ test_personal_data_manager.AddTestingProfile(&profile2);
+
+ AddressComboboxModel model(test_personal_data_manager, kAppLocale);
+ EXPECT_EQ(4, model.GetItemCount());
+ EXPECT_FALSE(model.IsItemSeparatorAt(0));
+ EXPECT_TRUE(model.IsItemSeparatorAt(1));
+ EXPECT_TRUE(model.GetItemIdentifierAt(0).empty());
+ EXPECT_TRUE(model.GetItemIdentifierAt(1).empty());
+ EXPECT_EQ(-1, model.GetIndexOfIdentifier("Anything"));
+ // The order is not guaranteed.
sebsg 2017/05/02 22:58:55 Since you get profiles to suggest to get the billi
MAD 2017/05/03 16:15:19 Cool! Thanks... Done.
+ if (profile1.guid() == model.GetItemIdentifierAt(2)) {
+ EXPECT_EQ(profile2.guid(), model.GetItemIdentifierAt(3));
+ EXPECT_EQ(2, model.GetIndexOfIdentifier(profile1.guid()));
+ EXPECT_EQ(3, model.GetIndexOfIdentifier(profile2.guid()));
+ } else {
+ EXPECT_EQ(profile1.guid(), model.GetItemIdentifierAt(3));
+ EXPECT_EQ(profile2.guid(), model.GetItemIdentifierAt(2));
+ EXPECT_EQ(3, model.GetIndexOfIdentifier(profile1.guid()));
+ EXPECT_EQ(2, model.GetIndexOfIdentifier(profile2.guid()));
+ }
+}
+
+TEST(AddressComboboxModelTest, AddAnAddress) {
+ TestPersonalDataManager test_personal_data_manager;
+ AutofillProfile profile1(test::GetFullProfile());
+ test_personal_data_manager.AddTestingProfile(&profile1);
+
+ AddressComboboxModel model(test_personal_data_manager, kAppLocale);
+ EXPECT_EQ(3, model.GetItemCount());
+ EXPECT_EQ(profile1.guid(), model.GetItemIdentifierAt(2));
+ EXPECT_EQ(2, model.GetIndexOfIdentifier(profile1.guid()));
+
+ AutofillProfile profile2(test::GetFullProfile2());
+ int new_profile_index = model.AddNewProfile(profile2);
+ EXPECT_EQ(3, new_profile_index);
+ EXPECT_EQ(4, model.GetItemCount());
+ EXPECT_EQ(profile2.guid(), model.GetItemIdentifierAt(3));
+ EXPECT_EQ(3, model.GetIndexOfIdentifier(profile2.guid()));
+
+ // First profile shouldn't have changed, here the order is guaranteed.
+ EXPECT_EQ(profile1.guid(), model.GetItemIdentifierAt(2));
+ EXPECT_EQ(2, model.GetIndexOfIdentifier(profile1.guid()));
+}
+
+} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698