| 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 <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 Loading... |
| 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 Loading... |
| 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()) { |
| 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 |
| 106 return result; | 108 return result; |
| 107 } | 109 } |
| 108 | 110 |
| 109 class PersonalDataManagerMock : public PersonalDataManager { | 111 class PersonalDataManagerMock : public PersonalDataManager { |
| 110 public: | 112 public: |
| 111 PersonalDataManagerMock(); | 113 PersonalDataManagerMock(); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 profiles, "\n", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | 234 profiles, "\n", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| 233 for (size_t i = 0; i < lines.size(); ++i) { | 235 for (size_t i = 0; i < lines.size(); ++i) { |
| 234 std::string line = lines[i]; | 236 std::string line = lines[i]; |
| 235 if (line != kProfileSeparator) { | 237 if (line != kProfileSeparator) { |
| 236 // Add a field to the current profile. | 238 // Add a field to the current profile. |
| 237 size_t separator_pos = line.find(kFieldSeparator); | 239 size_t separator_pos = line.find(kFieldSeparator); |
| 238 ASSERT_NE(std::string::npos, separator_pos) | 240 ASSERT_NE(std::string::npos, separator_pos) |
| 239 << "Wrong format for separator on line " << i; | 241 << "Wrong format for separator on line " << i; |
| 240 base::string16 field_type = | 242 base::string16 field_type = |
| 241 base::UTF8ToUTF16(line.substr(0, separator_pos)); | 243 base::UTF8ToUTF16(line.substr(0, separator_pos)); |
| 244 do { |
| 245 ++separator_pos; |
| 246 } while (separator_pos < line.size() && line[separator_pos] == ' '); |
| 242 base::string16 value = | 247 base::string16 value = |
| 243 base::UTF8ToUTF16(line.substr(separator_pos + kFieldOffset)); | 248 base::UTF8ToUTF16(line.substr(separator_pos)); |
| 244 base::ReplaceFirstSubstringAfterOffset( | 249 base::ReplaceFirstSubstringAfterOffset( |
| 245 &value, 0, base::ASCIIToUTF16("\\n"), base::ASCIIToUTF16("\n")); | 250 &value, 0, base::ASCIIToUTF16("\\n"), base::ASCIIToUTF16("\n")); |
| 246 | 251 |
| 247 FormFieldData field; | 252 FormFieldData field; |
| 248 field.label = field_type; | 253 field.label = field_type; |
| 249 field.name = field_type; | 254 field.name = field_type; |
| 250 field.value = value; | 255 field.value = value; |
| 251 field.form_control_type = "text"; | 256 field.form_control_type = "text"; |
| 252 field.is_focusable = true; | 257 field.is_focusable = true; |
| 253 form.fields.push_back(field); | 258 form.fields.push_back(field); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 return string_to_field_type_map_[str]; | 292 return string_to_field_type_map_[str]; |
| 288 } | 293 } |
| 289 | 294 |
| 290 TEST_P(AutofillMergeTest, DataDrivenMergeProfiles) { | 295 TEST_P(AutofillMergeTest, DataDrivenMergeProfiles) { |
| 291 RunOneDataDrivenTest(GetParam(), GetOutputDirectory(kTestName)); | 296 RunOneDataDrivenTest(GetParam(), GetOutputDirectory(kTestName)); |
| 292 } | 297 } |
| 293 | 298 |
| 294 INSTANTIATE_TEST_CASE_P(, AutofillMergeTest, testing::ValuesIn(GetTestFiles())); | 299 INSTANTIATE_TEST_CASE_P(, AutofillMergeTest, testing::ValuesIn(GetTestFiles())); |
| 295 | 300 |
| 296 } // namespace autofill | 301 } // namespace autofill |
| OLD | NEW |