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

Side by Side Diff: components/autofill/core/browser/autofill_profile_unittest.cc

Issue 261993006: Modified to allow to preserve two-word string in first-name and last-name in autofill profile. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/guid.h" 6 #include "base/guid.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 profile.SetInfo(AutofillType(ADDRESS_HOME_STATE), 891 profile.SetInfo(AutofillType(ADDRESS_HOME_STATE),
892 ASCIIToUTF16("CA"), 892 ASCIIToUTF16("CA"),
893 "en-US"); 893 "en-US");
894 EXPECT_FALSE(profile.GetInfo(full_address, "en-US").empty()); 894 EXPECT_FALSE(profile.GetInfo(full_address, "en-US").empty());
895 profile.SetInfo(AutofillType(ADDRESS_HOME_COUNTRY), 895 profile.SetInfo(AutofillType(ADDRESS_HOME_COUNTRY),
896 base::string16(), 896 base::string16(),
897 "en-US"); 897 "en-US");
898 EXPECT_TRUE(profile.GetInfo(full_address, "en-US").empty()); 898 EXPECT_TRUE(profile.GetInfo(full_address, "en-US").empty());
899 } 899 }
900 900
901 TEST(AutofillProfileTest, OverwriteOrAppendNames) {
902 AutofillProfile a(base::GenerateGUID(), "https://www.example.com");
903 test::SetProfileInfo(&a,
904 "Marion",
905 "Mitchell",
906 "Morrison",
907 "marion@me.xyz",
908 "Fox",
909 "123 Zoo St.",
910 "unit 5",
911 "Hollywood",
912 "CA",
913 "91601",
914 "US",
915 "12345678910");
Ilya Sherman 2014/05/31 00:34:41 nit: Please only set the relevant fields, i.e. the
Pritam Nikam 2014/05/31 10:30:41 Done.
916
917 NameInfo name;
918 std::vector<NameInfo> names;
919 std::vector<base::string16> name_list;
920
921 a.GetRawMultiInfo(NAME_FULL, &name_list);
922 ASSERT_EQ(1U, name_list.size());
923
924 // Case 1: Identical full names
925 // Case 1A: Prefer with more info - 2 word last-name
926 // overwrite existing name as {first||last1 last2}
927 name.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Marion"));
928 name.SetRawInfo(NAME_MIDDLE, base::string16());
929 name.SetRawInfo(NAME_LAST, ASCIIToUTF16("Mitchell Morrison"));
930 names.push_back(name);
931
932 a.OverwriteOrAppendNames(names);
933 a.GetRawMultiInfo(NAME_FULL, &name_list);
934 ASSERT_EQ(1U, name_list.size());
935
936 // Case 1B: profile name with parsed tokens pased as first_, middle_ & last_
937 // Don't add to the list - {first|middle|last}
938 base::string16 full_name = name.GetRawInfo(NAME_FULL);
939 name.SetRawInfo(NAME_FULL, full_name);
940 names[0] = name;
941
942 a.OverwriteOrAppendNames(names);
943 a.GetRawMultiInfo(NAME_FULL, &name_list);
944 ASSERT_EQ(1U, name_list.size());
945
946 // Case 1C: Prefer with more info - 2 word first-name
947 // append as new name to the list - {first1 first2||last}
948 name.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Marion Mitchell"));
949 name.SetRawInfo(NAME_MIDDLE, base::string16());
950 name.SetRawInfo(NAME_LAST, ASCIIToUTF16("Morrison"));
951 names[0] = name;
952
953 a.OverwriteOrAppendNames(names);
954 a.GetRawMultiInfo(NAME_FULL, &name_list);
955 ASSERT_EQ(2U, name_list.size());
956
957 // Case 2: Unique names
958 // append name to the list
959 name.SetRawInfo(NAME_FULL, ASCIIToUTF16("Marion M. Morrison"));
960 names[0] = name;
961
962 a.OverwriteOrAppendNames(names);
963 a.GetRawMultiInfo(NAME_FULL, &name_list);
964 ASSERT_EQ(3U, name_list.size());
965 }
Ilya Sherman 2014/05/31 00:34:41 This test code is somewhat fragile and hard to fol
Pritam Nikam 2014/05/31 10:30:41 Done.
901 } // namespace autofill 966 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698