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

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

Issue 112433004: Update uses of UTF conversions in chrome_frame/, chromeos/, components/ to use the base:: namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 12 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
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 <map> 5 #include <map>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 for (size_t i = 0; i < profiles.size(); ++i) { 63 for (size_t i = 0; i < profiles.size(); ++i) {
64 result += kProfileSeparator; 64 result += kProfileSeparator;
65 result += "\n"; 65 result += "\n";
66 for (size_t j = 0; j < arraysize(kProfileFieldTypes); ++j) { 66 for (size_t j = 0; j < arraysize(kProfileFieldTypes); ++j) {
67 ServerFieldType type = kProfileFieldTypes[j]; 67 ServerFieldType type = kProfileFieldTypes[j];
68 std::vector<base::string16> values; 68 std::vector<base::string16> values;
69 profiles[i]->GetRawMultiInfo(type, &values); 69 profiles[i]->GetRawMultiInfo(type, &values);
70 for (size_t k = 0; k < values.size(); ++k) { 70 for (size_t k = 0; k < values.size(); ++k) {
71 result += AutofillType(type).ToString(); 71 result += AutofillType(type).ToString();
72 result += kFieldSeparator; 72 result += kFieldSeparator;
73 result += UTF16ToUTF8(values[k]); 73 result += base::UTF16ToUTF8(values[k]);
74 result += "\n"; 74 result += "\n";
75 } 75 }
76 } 76 }
77 } 77 }
78 78
79 return result; 79 return result;
80 } 80 }
81 81
82 class PersonalDataManagerMock : public PersonalDataManager { 82 class PersonalDataManagerMock : public PersonalDataManager {
83 public: 83 public:
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 MergeProfiles(input, output); 178 MergeProfiles(input, output);
179 } 179 }
180 180
181 void AutofillMergeTest::MergeProfiles(const std::string& profiles, 181 void AutofillMergeTest::MergeProfiles(const std::string& profiles,
182 std::string* merged_profiles) { 182 std::string* merged_profiles) {
183 // Start with no saved profiles. 183 // Start with no saved profiles.
184 personal_data_.Reset(); 184 personal_data_.Reset();
185 185
186 // Create a test form. 186 // Create a test form.
187 FormData form; 187 FormData form;
188 form.name = ASCIIToUTF16("MyTestForm"); 188 form.name = base::ASCIIToUTF16("MyTestForm");
189 form.method = ASCIIToUTF16("POST"); 189 form.method = base::ASCIIToUTF16("POST");
190 form.origin = GURL("https://www.example.com/origin.html"); 190 form.origin = GURL("https://www.example.com/origin.html");
191 form.action = GURL("https://www.example.com/action.html"); 191 form.action = GURL("https://www.example.com/action.html");
192 form.user_submitted = true; 192 form.user_submitted = true;
193 193
194 // Parse the input line by line. 194 // Parse the input line by line.
195 std::vector<std::string> lines; 195 std::vector<std::string> lines;
196 Tokenize(profiles, "\n", &lines); 196 Tokenize(profiles, "\n", &lines);
197 for (size_t i = 0; i < lines.size(); ++i) { 197 for (size_t i = 0; i < lines.size(); ++i) {
198 std::string line = lines[i]; 198 std::string line = lines[i];
199 199
200 if (line != kProfileSeparator) { 200 if (line != kProfileSeparator) {
201 // Add a field to the current profile. 201 // Add a field to the current profile.
202 size_t separator_pos = line.find(kFieldSeparator); 202 size_t separator_pos = line.find(kFieldSeparator);
203 ASSERT_NE(std::string::npos, separator_pos); 203 ASSERT_NE(std::string::npos, separator_pos);
204 base::string16 field_type = UTF8ToUTF16(line.substr(0, separator_pos)); 204 base::string16 field_type =
205 base::UTF8ToUTF16(line.substr(0, separator_pos));
205 base::string16 value = 206 base::string16 value =
206 UTF8ToUTF16(line.substr(separator_pos + kFieldOffset)); 207 base::UTF8ToUTF16(line.substr(separator_pos + kFieldOffset));
207 208
208 FormFieldData field; 209 FormFieldData field;
209 field.label = field_type; 210 field.label = field_type;
210 field.name = field_type; 211 field.name = field_type;
211 field.value = value; 212 field.value = value;
212 field.form_control_type = "text"; 213 field.form_control_type = "text";
213 form.fields.push_back(field); 214 form.fields.push_back(field);
214 } 215 }
215 216
216 // The first line is always a profile separator, and the last profile is not 217 // The first line is always a profile separator, and the last profile is not
217 // followed by an explicit separator. 218 // followed by an explicit separator.
218 if ((i > 0 && line == kProfileSeparator) || i == lines.size() - 1) { 219 if ((i > 0 && line == kProfileSeparator) || i == lines.size() - 1) {
219 // Reached the end of a profile. Try to import it. 220 // Reached the end of a profile. Try to import it.
220 FormStructure form_structure(form); 221 FormStructure form_structure(form);
221 for (size_t i = 0; i < form_structure.field_count(); ++i) { 222 for (size_t i = 0; i < form_structure.field_count(); ++i) {
222 // Set the heuristic type for each field, which is currently serialized 223 // Set the heuristic type for each field, which is currently serialized
223 // into the field's name. 224 // into the field's name.
224 AutofillField* field = 225 AutofillField* field =
225 const_cast<AutofillField*>(form_structure.field(i)); 226 const_cast<AutofillField*>(form_structure.field(i));
226 ServerFieldType type = StringToFieldType(UTF16ToUTF8(field->name)); 227 ServerFieldType type =
228 StringToFieldType(base::UTF16ToUTF8(field->name));
227 field->set_heuristic_type(type); 229 field->set_heuristic_type(type);
228 } 230 }
229 231
230 // Import the profile. 232 // Import the profile.
231 scoped_ptr<CreditCard> imported_credit_card; 233 scoped_ptr<CreditCard> imported_credit_card;
232 personal_data_.ImportFormData(form_structure, &imported_credit_card); 234 personal_data_.ImportFormData(form_structure, &imported_credit_card);
233 EXPECT_EQ(static_cast<CreditCard*>(NULL), imported_credit_card.get()); 235 EXPECT_EQ(static_cast<CreditCard*>(NULL), imported_credit_card.get());
234 236
235 // Clear the |form| to start a new profile. 237 // Clear the |form| to start a new profile.
236 form.fields.clear(); 238 form.fields.clear();
237 } 239 }
238 } 240 }
239 241
240 *merged_profiles = SerializeProfiles(personal_data_.web_profiles()); 242 *merged_profiles = SerializeProfiles(personal_data_.web_profiles());
241 } 243 }
242 244
243 ServerFieldType AutofillMergeTest::StringToFieldType(const std::string& str) { 245 ServerFieldType AutofillMergeTest::StringToFieldType(const std::string& str) {
244 return string_to_field_type_map_[str]; 246 return string_to_field_type_map_[str];
245 } 247 }
246 248
247 TEST_F(AutofillMergeTest, DataDrivenMergeProfiles) { 249 TEST_F(AutofillMergeTest, DataDrivenMergeProfiles) {
248 RunDataDrivenTest(GetInputDirectory(kTestName), GetOutputDirectory(kTestName), 250 RunDataDrivenTest(GetInputDirectory(kTestName), GetOutputDirectory(kTestName),
249 kFileNamePattern); 251 kFileNamePattern);
250 } 252 }
251 253
252 } // namespace autofill 254 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698