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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 const base::FilePath::CharType kTestName[] = FILE_PATH_LITERAL("merge"); | 26 const base::FilePath::CharType kTestName[] = FILE_PATH_LITERAL("merge"); |
27 const base::FilePath::CharType kFileNamePattern[] = FILE_PATH_LITERAL("*.in"); | 27 const base::FilePath::CharType kFileNamePattern[] = FILE_PATH_LITERAL("*.in"); |
28 | 28 |
29 const char kFieldSeparator[] = ": "; | 29 const char kFieldSeparator[] = ": "; |
30 const char kProfileSeparator[] = "---"; | 30 const char kProfileSeparator[] = "---"; |
31 const size_t kFieldOffset = arraysize(kFieldSeparator) - 1; | 31 const size_t kFieldOffset = arraysize(kFieldSeparator) - 1; |
32 | 32 |
33 const AutofillFieldType kProfileFieldTypes[] = { | 33 const ServerFieldType kProfileFieldTypes[] = { |
34 NAME_FIRST, | 34 NAME_FIRST, |
35 NAME_MIDDLE, | 35 NAME_MIDDLE, |
36 NAME_LAST, | 36 NAME_LAST, |
37 EMAIL_ADDRESS, | 37 EMAIL_ADDRESS, |
38 COMPANY_NAME, | 38 COMPANY_NAME, |
39 ADDRESS_HOME_LINE1, | 39 ADDRESS_HOME_LINE1, |
40 ADDRESS_HOME_LINE2, | 40 ADDRESS_HOME_LINE2, |
41 ADDRESS_HOME_CITY, | 41 ADDRESS_HOME_CITY, |
42 ADDRESS_HOME_STATE, | 42 ADDRESS_HOME_STATE, |
43 ADDRESS_HOME_ZIP, | 43 ADDRESS_HOME_ZIP, |
(...skipping 12 matching lines...) Expand all Loading... |
56 return dir; | 56 return dir; |
57 } | 57 } |
58 | 58 |
59 // Serializes the |profiles| into a string. | 59 // Serializes the |profiles| into a string. |
60 std::string SerializeProfiles(const std::vector<AutofillProfile*>& profiles) { | 60 std::string SerializeProfiles(const std::vector<AutofillProfile*>& profiles) { |
61 std::string result; | 61 std::string result; |
62 for (size_t i = 0; i < profiles.size(); ++i) { | 62 for (size_t i = 0; i < profiles.size(); ++i) { |
63 result += kProfileSeparator; | 63 result += kProfileSeparator; |
64 result += "\n"; | 64 result += "\n"; |
65 for (size_t j = 0; j < arraysize(kProfileFieldTypes); ++j) { | 65 for (size_t j = 0; j < arraysize(kProfileFieldTypes); ++j) { |
66 AutofillFieldType type = kProfileFieldTypes[j]; | 66 ServerFieldType type = kProfileFieldTypes[j]; |
67 std::vector<base::string16> values; | 67 std::vector<base::string16> values; |
68 profiles[i]->GetRawMultiInfo(type, &values); | 68 profiles[i]->GetRawMultiInfo(type, &values); |
69 for (size_t k = 0; k < values.size(); ++k) { | 69 for (size_t k = 0; k < values.size(); ++k) { |
70 result += AutofillType::FieldTypeToString(type); | 70 result += AutofillType::FieldTypeToString(type); |
71 result += kFieldSeparator; | 71 result += kFieldSeparator; |
72 result += UTF16ToUTF8(values[k]); | 72 result += UTF16ToUTF8(values[k]); |
73 result += "\n"; | 73 result += "\n"; |
74 } | 74 } |
75 } | 75 } |
76 } | 76 } |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 // The first line is always a profile separator, and the last profile is not | 202 // The first line is always a profile separator, and the last profile is not |
203 // followed by an explicit separator. | 203 // followed by an explicit separator. |
204 if ((i > 0 && line == kProfileSeparator) || i == lines.size() - 1) { | 204 if ((i > 0 && line == kProfileSeparator) || i == lines.size() - 1) { |
205 // Reached the end of a profile. Try to import it. | 205 // Reached the end of a profile. Try to import it. |
206 FormStructure form_structure(form, std::string()); | 206 FormStructure form_structure(form, std::string()); |
207 for (size_t i = 0; i < form_structure.field_count(); ++i) { | 207 for (size_t i = 0; i < form_structure.field_count(); ++i) { |
208 // Set the heuristic type for each field, which is currently serialized | 208 // Set the heuristic type for each field, which is currently serialized |
209 // into the field's name. | 209 // into the field's name. |
210 AutofillField* field = | 210 AutofillField* field = |
211 const_cast<AutofillField*>(form_structure.field(i)); | 211 const_cast<AutofillField*>(form_structure.field(i)); |
212 AutofillFieldType type = | 212 ServerFieldType type = |
213 AutofillType::StringToFieldType(UTF16ToUTF8(field->name)); | 213 AutofillType::StringToFieldType(UTF16ToUTF8(field->name)); |
214 field->set_heuristic_type(type); | 214 field->set_heuristic_type(type); |
215 } | 215 } |
216 | 216 |
217 // Import the profile. | 217 // Import the profile. |
218 const CreditCard* imported_credit_card; | 218 const CreditCard* imported_credit_card; |
219 personal_data_.ImportFormData(form_structure, &imported_credit_card); | 219 personal_data_.ImportFormData(form_structure, &imported_credit_card); |
220 EXPECT_EQ(static_cast<const CreditCard*>(NULL), imported_credit_card); | 220 EXPECT_EQ(static_cast<const CreditCard*>(NULL), imported_credit_card); |
221 | 221 |
222 // Clear the |form| to start a new profile. | 222 // Clear the |form| to start a new profile. |
223 form.fields.clear(); | 223 form.fields.clear(); |
224 } | 224 } |
225 } | 225 } |
226 | 226 |
227 *merged_profiles = SerializeProfiles(personal_data_.web_profiles()); | 227 *merged_profiles = SerializeProfiles(personal_data_.web_profiles()); |
228 } | 228 } |
229 | 229 |
230 TEST_F(AutofillMergeTest, DataDrivenMergeProfiles) { | 230 TEST_F(AutofillMergeTest, DataDrivenMergeProfiles) { |
231 RunDataDrivenTest(GetInputDirectory(kTestName), GetOutputDirectory(kTestName), | 231 RunDataDrivenTest(GetInputDirectory(kTestName), GetOutputDirectory(kTestName), |
232 kFileNamePattern); | 232 kFileNamePattern); |
233 } | 233 } |
234 | 234 |
235 } // namespace autofill | 235 } // namespace autofill |
OLD | NEW |