OLD | NEW |
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 "components/autofill/core/browser/contact_info.h" | 5 #include "components/autofill/core/browser/contact_info.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/format_macros.h" |
8 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/stringprintf.h" |
9 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
10 #include "components/autofill/core/browser/autofill_type.h" | 12 #include "components/autofill/core/browser/autofill_type.h" |
11 #include "components/autofill/core/browser/field_types.h" | 13 #include "components/autofill/core/browser/field_types.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
13 | 15 |
14 using base::ASCIIToUTF16; | 16 using base::ASCIIToUTF16; |
15 | 17 |
16 namespace autofill { | 18 namespace autofill { |
17 | 19 |
18 TEST(NameInfoTest, SetFullName) { | 20 TEST(NameInfoTest, SetFullName) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 99 |
98 name.SetRawInfo(NAME_FIRST, ASCIIToUTF16("First")); | 100 name.SetRawInfo(NAME_FIRST, ASCIIToUTF16("First")); |
99 name.SetRawInfo(NAME_MIDDLE, ASCIIToUTF16("Middle")); | 101 name.SetRawInfo(NAME_MIDDLE, ASCIIToUTF16("Middle")); |
100 name.SetRawInfo(NAME_LAST, ASCIIToUTF16("Last")); | 102 name.SetRawInfo(NAME_LAST, ASCIIToUTF16("Last")); |
101 EXPECT_EQ(name.GetRawInfo(NAME_FIRST), ASCIIToUTF16("First")); | 103 EXPECT_EQ(name.GetRawInfo(NAME_FIRST), ASCIIToUTF16("First")); |
102 EXPECT_EQ(name.GetRawInfo(NAME_MIDDLE), ASCIIToUTF16("Middle")); | 104 EXPECT_EQ(name.GetRawInfo(NAME_MIDDLE), ASCIIToUTF16("Middle")); |
103 EXPECT_EQ(name.GetRawInfo(NAME_LAST), ASCIIToUTF16("Last")); | 105 EXPECT_EQ(name.GetRawInfo(NAME_LAST), ASCIIToUTF16("Last")); |
104 EXPECT_EQ(name.GetRawInfo(NAME_FULL), ASCIIToUTF16("First Middle Last")); | 106 EXPECT_EQ(name.GetRawInfo(NAME_FULL), ASCIIToUTF16("First Middle Last")); |
105 } | 107 } |
106 | 108 |
| 109 TEST(NameInfoTest, EqualsIgnoreCase) { |
| 110 struct TestCase { |
| 111 std::string starting_names[3]; |
| 112 std::string additional_names[3]; |
| 113 bool expected_result; |
| 114 }; |
| 115 |
| 116 struct TestCase test_cases[] = { |
| 117 // Identical name comparison. |
| 118 {{"Marion", "Mitchell", "Morrison"}, |
| 119 {"Marion", "Mitchell", "Morrison"}, |
| 120 true}, |
| 121 |
| 122 // Case-insensative comparisons. |
| 123 {{"Marion", "Mitchell", "Morrison"}, |
| 124 {"Marion", "Mitchell", "MORRISON"}, |
| 125 true}, |
| 126 {{"Marion", "Mitchell", "Morrison"}, |
| 127 {"MARION", "Mitchell", "MORRISON"}, |
| 128 true}, |
| 129 {{"Marion", "Mitchell", "Morrison"}, |
| 130 {"MARION", "MITCHELL", "MORRISON"}, |
| 131 true}, |
| 132 {{"Marion", "", "Mitchell Morrison"}, |
| 133 {"MARION", "", "MITCHELL MORRISON"}, |
| 134 true}, |
| 135 {{"Marion Mitchell", "", "Morrison"}, |
| 136 {"MARION MITCHELL", "", "MORRISON"}, |
| 137 true}, |
| 138 |
| 139 // Identical full names but different canonical forms. |
| 140 {{"Marion", "Mitchell", "Morrison"}, |
| 141 {"Marion", "", "Mitchell Morrison"}, |
| 142 false}, |
| 143 {{"Marion", "Mitchell", "Morrison"}, |
| 144 {"Marion Mitchell", "", "MORRISON"}, |
| 145 false}, |
| 146 |
| 147 // Different names. |
| 148 {{"Marion", "Mitchell", "Morrison"}, {"Marion", "M.", "Morrison"}, false}, |
| 149 {{"Marion", "Mitchell", "Morrison"}, {"MARION", "M.", "MORRISON"}, false}, |
| 150 {{"Marion", "Mitchell", "Morrison"}, |
| 151 {"David", "Mitchell", "Morrison"}, |
| 152 false}, |
| 153 }; |
| 154 |
| 155 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
| 156 SCOPED_TRACE(base::StringPrintf("i: %" PRIuS, i)); |
| 157 |
| 158 // Construct the starting_profile. |
| 159 NameInfo starting_profile; |
| 160 starting_profile.SetRawInfo(NAME_FIRST, |
| 161 ASCIIToUTF16(test_cases[i].starting_names[0])); |
| 162 starting_profile.SetRawInfo(NAME_MIDDLE, |
| 163 ASCIIToUTF16(test_cases[i].starting_names[1])); |
| 164 starting_profile.SetRawInfo(NAME_LAST, |
| 165 ASCIIToUTF16(test_cases[i].starting_names[2])); |
| 166 |
| 167 // Construct the additional_profile. |
| 168 NameInfo additional_profile; |
| 169 additional_profile.SetRawInfo( |
| 170 NAME_FIRST, ASCIIToUTF16(test_cases[i].additional_names[0])); |
| 171 additional_profile.SetRawInfo( |
| 172 NAME_MIDDLE, ASCIIToUTF16(test_cases[i].additional_names[1])); |
| 173 additional_profile.SetRawInfo( |
| 174 NAME_LAST, ASCIIToUTF16(test_cases[i].additional_names[2])); |
| 175 |
| 176 // Verify the test expectations. |
| 177 EXPECT_EQ(test_cases[i].expected_result, |
| 178 starting_profile.EqualsIgnoreCase(additional_profile)); |
| 179 } |
| 180 } |
| 181 |
107 } // namespace autofill | 182 } // namespace autofill |
OLD | NEW |