| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 // Serializes the |profiles| into a string. | 45 // Serializes the |profiles| into a string. |
| 46 std::string SerializeProfiles(const std::vector<AutofillProfile*>& profiles) { | 46 std::string SerializeProfiles(const std::vector<AutofillProfile*>& profiles) { |
| 47 std::string result; | 47 std::string result; |
| 48 for (size_t i = 0; i < profiles.size(); ++i) { | 48 for (size_t i = 0; i < profiles.size(); ++i) { |
| 49 result += kProfileSeparator; | 49 result += kProfileSeparator; |
| 50 result += "\n"; | 50 result += "\n"; |
| 51 for (size_t j = 0; j < arraysize(kProfileFieldTypes); ++j) { | 51 for (size_t j = 0; j < arraysize(kProfileFieldTypes); ++j) { |
| 52 AutofillFieldType type = kProfileFieldTypes[j]; | 52 AutofillFieldType type = kProfileFieldTypes[j]; |
| 53 std::vector<string16> values; | 53 std::vector<base::string16> values; |
| 54 profiles[i]->GetRawMultiInfo(type, &values); | 54 profiles[i]->GetRawMultiInfo(type, &values); |
| 55 for (size_t k = 0; k < values.size(); ++k) { | 55 for (size_t k = 0; k < values.size(); ++k) { |
| 56 result += AutofillType::FieldTypeToString(type); | 56 result += AutofillType::FieldTypeToString(type); |
| 57 result += kFieldSeparator; | 57 result += kFieldSeparator; |
| 58 result += UTF16ToUTF8(values[k]); | 58 result += UTF16ToUTF8(values[k]); |
| 59 result += "\n"; | 59 result += "\n"; |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 | 63 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 // Parse the input line by line. | 166 // Parse the input line by line. |
| 167 std::vector<std::string> lines; | 167 std::vector<std::string> lines; |
| 168 Tokenize(profiles, "\n", &lines); | 168 Tokenize(profiles, "\n", &lines); |
| 169 for (size_t i = 0; i < lines.size(); ++i) { | 169 for (size_t i = 0; i < lines.size(); ++i) { |
| 170 std::string line = lines[i]; | 170 std::string line = lines[i]; |
| 171 | 171 |
| 172 if (line != kProfileSeparator) { | 172 if (line != kProfileSeparator) { |
| 173 // Add a field to the current profile. | 173 // Add a field to the current profile. |
| 174 size_t separator_pos = line.find(kFieldSeparator); | 174 size_t separator_pos = line.find(kFieldSeparator); |
| 175 ASSERT_NE(std::string::npos, separator_pos); | 175 ASSERT_NE(std::string::npos, separator_pos); |
| 176 string16 field_type = UTF8ToUTF16(line.substr(0, separator_pos)); | 176 base::string16 field_type = UTF8ToUTF16(line.substr(0, separator_pos)); |
| 177 string16 value = UTF8ToUTF16(line.substr(separator_pos + kFieldOffset)); | 177 base::string16 value = |
| 178 UTF8ToUTF16(line.substr(separator_pos + kFieldOffset)); |
| 178 | 179 |
| 179 FormFieldData field; | 180 FormFieldData field; |
| 180 field.label = field_type; | 181 field.label = field_type; |
| 181 field.name = field_type; | 182 field.name = field_type; |
| 182 field.value = value; | 183 field.value = value; |
| 183 field.form_control_type = "text"; | 184 field.form_control_type = "text"; |
| 184 form.fields.push_back(field); | 185 form.fields.push_back(field); |
| 185 } | 186 } |
| 186 | 187 |
| 187 // The first line is always a profile separator, and the last profile is not | 188 // The first line is always a profile separator, and the last profile is not |
| (...skipping 21 matching lines...) Expand all Loading... |
| 209 } | 210 } |
| 210 } | 211 } |
| 211 | 212 |
| 212 *merged_profiles = SerializeProfiles(personal_data_.web_profiles()); | 213 *merged_profiles = SerializeProfiles(personal_data_.web_profiles()); |
| 213 } | 214 } |
| 214 | 215 |
| 215 TEST_F(AutofillMergeTest, DataDrivenMergeProfiles) { | 216 TEST_F(AutofillMergeTest, DataDrivenMergeProfiles) { |
| 216 RunDataDrivenTest(GetInputDirectory(kTestName), GetOutputDirectory(kTestName), | 217 RunDataDrivenTest(GetInputDirectory(kTestName), GetOutputDirectory(kTestName), |
| 217 kFileNamePattern); | 218 kFileNamePattern); |
| 218 } | 219 } |
| OLD | NEW |