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

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

Issue 2110563002: Use AutofillProfileComparator in place of ad-hoc merge logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@merge
Patch Set: Initial CL for review Created 4 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
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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <map> 7 #include <map>
8 #include <memory> 8 #include <memory>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 20 matching lines...) Expand all
31 #include "base/mac/foundation_util.h" 31 #include "base/mac/foundation_util.h"
32 #endif 32 #endif
33 33
34 namespace autofill { 34 namespace autofill {
35 35
36 namespace { 36 namespace {
37 37
38 const base::FilePath::CharType kTestName[] = FILE_PATH_LITERAL("merge"); 38 const base::FilePath::CharType kTestName[] = FILE_PATH_LITERAL("merge");
39 const base::FilePath::CharType kFileNamePattern[] = FILE_PATH_LITERAL("*.in"); 39 const base::FilePath::CharType kFileNamePattern[] = FILE_PATH_LITERAL("*.in");
40 40
41 const char kFieldSeparator[] = ": "; 41 const char kFieldSeparator[] = ":";
42 const char kProfileSeparator[] = "---"; 42 const char kProfileSeparator[] = "---";
43 const size_t kFieldOffset = arraysize(kFieldSeparator) - 1;
44 43
45 const ServerFieldType kProfileFieldTypes[] = {NAME_FIRST, 44 const ServerFieldType kProfileFieldTypes[] = {NAME_FIRST,
46 NAME_MIDDLE, 45 NAME_MIDDLE,
47 NAME_LAST, 46 NAME_LAST,
48 NAME_FULL, 47 NAME_FULL,
49 EMAIL_ADDRESS, 48 EMAIL_ADDRESS,
50 COMPANY_NAME, 49 COMPANY_NAME,
51 ADDRESS_HOME_STREET_ADDRESS, 50 ADDRESS_HOME_STREET_ADDRESS,
52 ADDRESS_HOME_CITY, 51 ADDRESS_HOME_CITY,
53 ADDRESS_HOME_STATE, 52 ADDRESS_HOME_STATE,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 std::string SerializeProfiles(const std::vector<AutofillProfile*>& profiles) { 88 std::string SerializeProfiles(const std::vector<AutofillProfile*>& profiles) {
90 std::string result; 89 std::string result;
91 for (size_t i = 0; i < profiles.size(); ++i) { 90 for (size_t i = 0; i < profiles.size(); ++i) {
92 result += kProfileSeparator; 91 result += kProfileSeparator;
93 result += "\n"; 92 result += "\n";
94 for (size_t j = 0; j < arraysize(kProfileFieldTypes); ++j) { 93 for (size_t j = 0; j < arraysize(kProfileFieldTypes); ++j) {
95 ServerFieldType type = kProfileFieldTypes[j]; 94 ServerFieldType type = kProfileFieldTypes[j];
96 base::string16 value = profiles[i]->GetRawInfo(type); 95 base::string16 value = profiles[i]->GetRawInfo(type);
97 result += AutofillType(type).ToString(); 96 result += AutofillType(type).ToString();
98 result += kFieldSeparator; 97 result += kFieldSeparator;
99 base::ReplaceFirstSubstringAfterOffset( 98 if (!value.empty()) {
Mathieu 2016/06/29 15:50:56 You will probably need to update https://cs.chromi
Roger McFarlane (Chromium) 2016/06/29 18:21:36 Done.
100 &value, 0, base::ASCIIToUTF16("\\n"), base::ASCIIToUTF16("\n")); 99 base::ReplaceFirstSubstringAfterOffset(
101 result += base::UTF16ToUTF8(value); 100 &value, 0, base::ASCIIToUTF16("\\n"), base::ASCIIToUTF16("\n"));
101 result += " ";
102 result += base::UTF16ToUTF8(value);
103 }
102 result += "\n"; 104 result += "\n";
103 } 105 }
104 } 106 }
105 107
108
sebsg 2016/06/29 08:57:03 nit: remove second whitespace.
Roger McFarlane (Chromium) 2016/06/29 18:21:36 Done.
106 return result; 109 return result;
107 } 110 }
108 111
109 class PersonalDataManagerMock : public PersonalDataManager { 112 class PersonalDataManagerMock : public PersonalDataManager {
110 public: 113 public:
111 PersonalDataManagerMock(); 114 PersonalDataManagerMock();
112 ~PersonalDataManagerMock() override; 115 ~PersonalDataManagerMock() override;
113 116
114 // Reset the saved profiles. 117 // Reset the saved profiles.
115 void Reset(); 118 void Reset();
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 profiles, "\n", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); 235 profiles, "\n", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
233 for (size_t i = 0; i < lines.size(); ++i) { 236 for (size_t i = 0; i < lines.size(); ++i) {
234 std::string line = lines[i]; 237 std::string line = lines[i];
235 if (line != kProfileSeparator) { 238 if (line != kProfileSeparator) {
236 // Add a field to the current profile. 239 // Add a field to the current profile.
237 size_t separator_pos = line.find(kFieldSeparator); 240 size_t separator_pos = line.find(kFieldSeparator);
238 ASSERT_NE(std::string::npos, separator_pos) 241 ASSERT_NE(std::string::npos, separator_pos)
239 << "Wrong format for separator on line " << i; 242 << "Wrong format for separator on line " << i;
240 base::string16 field_type = 243 base::string16 field_type =
241 base::UTF8ToUTF16(line.substr(0, separator_pos)); 244 base::UTF8ToUTF16(line.substr(0, separator_pos));
245 do {
246 ++separator_pos;
247 } while (separator_pos < line.size() && line[separator_pos] == ' ');
242 base::string16 value = 248 base::string16 value =
243 base::UTF8ToUTF16(line.substr(separator_pos + kFieldOffset)); 249 base::UTF8ToUTF16(line.substr(separator_pos));
244 base::ReplaceFirstSubstringAfterOffset( 250 base::ReplaceFirstSubstringAfterOffset(
245 &value, 0, base::ASCIIToUTF16("\\n"), base::ASCIIToUTF16("\n")); 251 &value, 0, base::ASCIIToUTF16("\\n"), base::ASCIIToUTF16("\n"));
246 252
247 FormFieldData field; 253 FormFieldData field;
248 field.label = field_type; 254 field.label = field_type;
249 field.name = field_type; 255 field.name = field_type;
250 field.value = value; 256 field.value = value;
251 field.form_control_type = "text"; 257 field.form_control_type = "text";
252 field.is_focusable = true; 258 field.is_focusable = true;
253 form.fields.push_back(field); 259 form.fields.push_back(field);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 return string_to_field_type_map_[str]; 293 return string_to_field_type_map_[str];
288 } 294 }
289 295
290 TEST_P(AutofillMergeTest, DataDrivenMergeProfiles) { 296 TEST_P(AutofillMergeTest, DataDrivenMergeProfiles) {
291 RunOneDataDrivenTest(GetParam(), GetOutputDirectory(kTestName)); 297 RunOneDataDrivenTest(GetParam(), GetOutputDirectory(kTestName));
292 } 298 }
293 299
294 INSTANTIATE_TEST_CASE_P(, AutofillMergeTest, testing::ValuesIn(GetTestFiles())); 300 INSTANTIATE_TEST_CASE_P(, AutofillMergeTest, testing::ValuesIn(GetTestFiles()));
295 301
296 } // namespace autofill 302 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698