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

Side by Side Diff: chrome/browser/autofill/autofill_profile_unittest.cc

Issue 2835026: Added inferred labels implementation. Label inferred from the person name + d... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/autofill/autofill_profile.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "app/l10n_util.h"
5 #include "base/basictypes.h" 6 #include "base/basictypes.h"
6 #include "base/scoped_ptr.h" 7 #include "base/scoped_ptr.h"
8 #include "base/stl_util-inl.h"
7 #include "base/string16.h" 9 #include "base/string16.h"
8 #include "chrome/browser/autofill/autofill_common_unittest.h" 10 #include "chrome/browser/autofill/autofill_common_unittest.h"
9 #include "chrome/browser/autofill/autofill_profile.h" 11 #include "chrome/browser/autofill/autofill_profile.h"
12 #include "grit/generated_resources.h"
10 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
11 14
12 namespace { 15 namespace {
13 16
14 // Tests different possibilities for summary string generation. 17 // Tests different possibilities for summary string generation.
15 // Based on existence of first name, last name, and address line 1. 18 // Based on existence of first name, last name, and address line 1.
16 TEST(AutoFillProfileTest, PreviewSummaryString) { 19 TEST(AutoFillProfileTest, PreviewSummaryString) {
17 // Case 0/null: "" 20 // Case 0/null: ""
18 AutoFillProfile profile0(string16(), 0); 21 AutoFillProfile profile0(string16(), 0);
19 string16 summary0 = profile0.PreviewSummary(); 22 string16 summary0 = profile0.PreviewSummary();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 80
78 // Case 7: "<firstname> <lastname>, <address>" 81 // Case 7: "<firstname> <lastname>, <address>"
79 AutoFillProfile profile7(string16(), 0); 82 AutoFillProfile profile7(string16(), 0);
80 autofill_unittest::SetProfileInfo(&profile7, "Billing", "Marion", "Mitchell", 83 autofill_unittest::SetProfileInfo(&profile7, "Billing", "Marion", "Mitchell",
81 "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", 84 "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5",
82 "Hollywood", "CA", "91601", "US", "12345678910", "01987654321"); 85 "Hollywood", "CA", "91601", "US", "12345678910", "01987654321");
83 string16 summary7 = profile7.PreviewSummary(); 86 string16 summary7 = profile7.PreviewSummary();
84 EXPECT_EQ(string16(ASCIIToUTF16("Marion Morrison, 123 Zoo St.")), summary7); 87 EXPECT_EQ(string16(ASCIIToUTF16("Marion Morrison, 123 Zoo St.")), summary7);
85 } 88 }
86 89
90 TEST(AutoFillProfileTest, AdjustInferredLabels) {
91 std::vector<AutoFillProfile*> profiles;
92 profiles.push_back(new AutoFillProfile(string16(), 0));
93 autofill_unittest::SetProfileInfo(
94 profiles[0],
95 "",
96 "John",
97 "",
98 "Doe",
99 "johndoe@hades.com",
100 "Underworld",
101 "666 Erebus St.",
102 "",
103 "Elysium", "CA",
104 "91111",
105 "US",
106 "11111111111",
107 "22222222222");
108 profiles.push_back(new AutoFillProfile(string16(), 0));
109 autofill_unittest::SetProfileInfo(
110 profiles[1],
111 "",
112 "Jane",
113 "",
114 "Doe",
115 "janedoe@tertium.com",
116 "Pluto Inc.",
117 "123 Letha Shore.",
118 "",
119 "Dis", "CA",
120 "91222",
121 "US",
122 "12345678910",
123 "01987654321");
124 // As labels are empty they are adjusted the first time.
125 EXPECT_TRUE(AutoFillProfile::AdjustInferredLabels(&profiles));
126 // No need to adjust them anymore.
127 EXPECT_FALSE(AutoFillProfile::AdjustInferredLabels(&profiles));
128 EXPECT_EQ(string16(ASCIIToUTF16("John Doe, 666 Erebus St.")),
129 profiles[0]->Label());
130 EXPECT_EQ(string16(ASCIIToUTF16("Jane Doe, 123 Letha Shore.")),
131 profiles[1]->Label());
132
133 profiles.push_back(new AutoFillProfile(string16(), 0));
134 autofill_unittest::SetProfileInfo(
135 profiles[2],
136 "",
137 "John",
138 "",
139 "Doe",
140 "johndoe@tertium.com",
141 "Underworld",
142 "666 Erebus St.",
143 "",
144 "Elysium", "CA",
145 "91111",
146 "US",
147 "11111111111",
148 "22222222222");
149 EXPECT_TRUE(AutoFillProfile::AdjustInferredLabels(&profiles));
150
151 // Profile 0 and 2 inferred label now includes an e-mail.
152 EXPECT_EQ(string16(
153 ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@hades.com")),
154 profiles[0]->Label());
155 EXPECT_EQ(string16(ASCIIToUTF16("Jane Doe, 123 Letha Shore.")),
156 profiles[1]->Label());
157 EXPECT_EQ(string16(
158 ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@tertium.com")),
159 profiles[2]->Label());
160
161 delete profiles[2];
162 profiles.pop_back();
163
164 profiles.push_back(new AutoFillProfile(string16(), 0));
165 autofill_unittest::SetProfileInfo(
166 profiles[2],
167 "",
168 "John",
169 "",
170 "Doe",
171 "johndoe@hades.com",
172 "Underworld",
173 "666 Erebus St.",
174 "",
175 "Elysium", "CA",
176 "91111",
177 "US",
178 "11111111111",
179 "33333333333"); // Fax is different
180
181 EXPECT_TRUE(AutoFillProfile::AdjustInferredLabels(&profiles));
182
183 // Profile 0 and 2 inferred label now includes a fax number.
184 EXPECT_EQ(string16(ASCIIToUTF16(
185 "John Doe, 666 Erebus St., fax:#22222222222")),
186 profiles[0]->Label());
187 EXPECT_EQ(string16(ASCIIToUTF16("Jane Doe, 123 Letha Shore.")),
188 profiles[1]->Label());
189 EXPECT_EQ(string16(ASCIIToUTF16(
190 "John Doe, 666 Erebus St., fax:#33333333333")),
191 profiles[2]->Label());
192
193 profiles.push_back(new AutoFillProfile(string16(), 0));
194 autofill_unittest::SetProfileInfo(
195 profiles[3],
196 "",
197 "John",
198 "",
199 "Doe",
200 "johndoe@hades.com",
201 "Underworld",
202 "666 Erebus St.",
203 "",
204 "Elysium", "CA",
205 "91111",
206 "US",
207 "44444444444", // Phone is different for some.
208 "33333333333"); // Fax is different for some.
209
210 EXPECT_TRUE(AutoFillProfile::AdjustInferredLabels(&profiles));
211
212 EXPECT_EQ(string16(ASCIIToUTF16("John Doe, 666 Erebus St., 11111111111,"
213 " fax:#22222222222")),
214 profiles[0]->Label());
215 EXPECT_EQ(string16(ASCIIToUTF16("Jane Doe, 123 Letha Shore.")),
216 profiles[1]->Label());
217 EXPECT_EQ(string16(ASCIIToUTF16("John Doe, 666 Erebus St., 11111111111,"
218 " fax:#33333333333")),
219 profiles[2]->Label());
220 // This one differs from other ones by unique phone, so no need for extra
221 // information.
222 EXPECT_EQ(string16(ASCIIToUTF16("John Doe, 666 Erebus St., 44444444444")),
223 profiles[3]->Label());
224
225 profiles.push_back(new AutoFillProfile(string16(), 0));
226 autofill_unittest::SetProfileInfo(
227 profiles[4],
228 "",
229 "John",
230 "",
231 "Doe",
232 "johndoe@styx.com", // E-Mail is different for some.
233 "Underworld",
234 "666 Erebus St.",
235 "",
236 "Elysium", "CA",
237 "91111",
238 "US",
239 "44444444444", // Phone is different for some.
240 "33333333333"); // Fax is different for some.
241
242 EXPECT_TRUE(AutoFillProfile::AdjustInferredLabels(&profiles));
243
244 EXPECT_EQ(string16(ASCIIToUTF16(
245 "John Doe, 666 Erebus St., johndoe@hades.com,"
246 " 11111111111, fax:#22222222222")),
247 profiles[0]->Label());
248 EXPECT_EQ(string16(ASCIIToUTF16("Jane Doe, 123 Letha Shore.")),
249 profiles[1]->Label());
250 EXPECT_EQ(string16(ASCIIToUTF16(
251 "John Doe, 666 Erebus St., johndoe@hades.com,"
252 " 11111111111, fax:#33333333333")),
253 profiles[2]->Label());
254 EXPECT_EQ(string16(ASCIIToUTF16(
255 "John Doe, 666 Erebus St., johndoe@hades.com,"
256 " 44444444444, fax:#33333333333")),
257 profiles[3]->Label());
258 // This one differs from other ones by unique e-mail, so no need for extra
259 // information.
260 EXPECT_EQ(string16(ASCIIToUTF16(
261 "John Doe, 666 Erebus St., johndoe@styx.com")),
262 profiles[4]->Label());
263
264 EXPECT_FALSE(AutoFillProfile::AdjustInferredLabels(&profiles));
265
266 // Clean up.
267 STLDeleteContainerPointers(profiles.begin(), profiles.end());
268 }
269
87 TEST(AutoFillProfileTest, IsSubsetOf) { 270 TEST(AutoFillProfileTest, IsSubsetOf) {
88 scoped_ptr<AutoFillProfile> a, b; 271 scoped_ptr<AutoFillProfile> a, b;
89 272
90 // |a| is a subset of |b|. 273 // |a| is a subset of |b|.
91 a.reset(new AutoFillProfile); 274 a.reset(new AutoFillProfile);
92 b.reset(new AutoFillProfile); 275 b.reset(new AutoFillProfile);
93 autofill_unittest::SetProfileInfo(a.get(), "label1", "Thomas", NULL, 276 autofill_unittest::SetProfileInfo(a.get(), "label1", "Thomas", NULL,
94 "Jefferson", "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, 277 "Jefferson", "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL,
95 NULL, NULL, NULL, NULL); 278 NULL, NULL, NULL, NULL);
96 autofill_unittest::SetProfileInfo(b.get(), "label2", "Thomas", NULL, 279 autofill_unittest::SetProfileInfo(b.get(), "label2", "Thomas", NULL,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 autofill_unittest::SetProfileInfo(&expected_a, "label1", "Jimmy", NULL, 362 autofill_unittest::SetProfileInfo(&expected_a, "label1", "Jimmy", NULL,
180 "Madison", "constitutionalist@gmail.com", "United States Government", 363 "Madison", "constitutionalist@gmail.com", "United States Government",
181 "Monticello", NULL, "Charlottesville", "Virginia", "22902", NULL, 364 "Monticello", NULL, "Charlottesville", "Virginia", "22902", NULL,
182 "12134759123", "19384284720"); 365 "12134759123", "19384284720");
183 EXPECT_EQ(expected_a, *a); 366 EXPECT_EQ(expected_a, *a);
184 EXPECT_EQ(expected_b, *b); 367 EXPECT_EQ(expected_b, *b);
185 } 368 }
186 369
187 } // namespace 370 } // namespace
188 371
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_profile.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698