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

Side by Side 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, 7 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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 "components/autofill/core/browser/address_combobox_model.h"
6
7 #include "components/autofill/core/browser/autofill_test_utils.h"
8 #include "components/autofill/core/browser/test_personal_data_manager.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/region_dat a.h"
11
12 namespace autofill {
13
14 namespace {
15 const char kAppLocale[] = "fr-CA";
16 }
17
18 TEST(AddressComboboxModelTest, Empty) {
19 TestPersonalDataManager test_personal_data_manager;
20
21 AddressComboboxModel model(test_personal_data_manager, kAppLocale);
22 EXPECT_EQ(1, model.GetItemCount());
23 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.
24 EXPECT_TRUE(model.GetItemIdentifierAt(0).empty());
25 EXPECT_EQ(-1, model.GetIndexOfIdentifier("Anything"));
26 }
27
28 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
29 TestPersonalDataManager test_personal_data_manager;
30 AutofillProfile profile1(test::GetFullProfile());
31 AutofillProfile profile2(test::GetFullProfile2());
32 test_personal_data_manager.AddTestingProfile(&profile1);
33 test_personal_data_manager.AddTestingProfile(&profile2);
34
35 AddressComboboxModel model(test_personal_data_manager, kAppLocale);
36 EXPECT_EQ(4, model.GetItemCount());
37 EXPECT_FALSE(model.IsItemSeparatorAt(0));
38 EXPECT_TRUE(model.IsItemSeparatorAt(1));
39 EXPECT_TRUE(model.GetItemIdentifierAt(0).empty());
40 EXPECT_TRUE(model.GetItemIdentifierAt(1).empty());
41 EXPECT_EQ(-1, model.GetIndexOfIdentifier("Anything"));
42 // 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.
43 if (profile1.guid() == model.GetItemIdentifierAt(2)) {
44 EXPECT_EQ(profile2.guid(), model.GetItemIdentifierAt(3));
45 EXPECT_EQ(2, model.GetIndexOfIdentifier(profile1.guid()));
46 EXPECT_EQ(3, model.GetIndexOfIdentifier(profile2.guid()));
47 } else {
48 EXPECT_EQ(profile1.guid(), model.GetItemIdentifierAt(3));
49 EXPECT_EQ(profile2.guid(), model.GetItemIdentifierAt(2));
50 EXPECT_EQ(3, model.GetIndexOfIdentifier(profile1.guid()));
51 EXPECT_EQ(2, model.GetIndexOfIdentifier(profile2.guid()));
52 }
53 }
54
55 TEST(AddressComboboxModelTest, AddAnAddress) {
56 TestPersonalDataManager test_personal_data_manager;
57 AutofillProfile profile1(test::GetFullProfile());
58 test_personal_data_manager.AddTestingProfile(&profile1);
59
60 AddressComboboxModel model(test_personal_data_manager, kAppLocale);
61 EXPECT_EQ(3, model.GetItemCount());
62 EXPECT_EQ(profile1.guid(), model.GetItemIdentifierAt(2));
63 EXPECT_EQ(2, model.GetIndexOfIdentifier(profile1.guid()));
64
65 AutofillProfile profile2(test::GetFullProfile2());
66 int new_profile_index = model.AddNewProfile(profile2);
67 EXPECT_EQ(3, new_profile_index);
68 EXPECT_EQ(4, model.GetItemCount());
69 EXPECT_EQ(profile2.guid(), model.GetItemIdentifierAt(3));
70 EXPECT_EQ(3, model.GetIndexOfIdentifier(profile2.guid()));
71
72 // First profile shouldn't have changed, here the order is guaranteed.
73 EXPECT_EQ(profile1.guid(), model.GetItemIdentifierAt(2));
74 EXPECT_EQ(2, model.GetIndexOfIdentifier(profile1.guid()));
75 }
76
77 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698