OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/file_path.h" | 8 #include "base/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" |
11 #include "chrome/browser/autofill/autofill_common_test.h" | 11 #include "chrome/browser/autofill/autofill_common_test.h" |
12 #include "chrome/browser/autofill/autofill_type.h" | 12 #include "chrome/browser/autofill/autofill_type.h" |
13 #include "chrome/browser/autofill/data_driven_test.h" | 13 #include "chrome/browser/autofill/data_driven_test.h" |
14 #include "chrome/browser/autofill/form_structure.h" | 14 #include "chrome/browser/autofill/form_structure.h" |
15 #include "chrome/browser/autofill/personal_data_manager.h" | 15 #include "chrome/browser/autofill/personal_data_manager.h" |
16 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" |
18 #include "webkit/glue/form_data.h" | 19 #include "webkit/glue/form_data.h" |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 // TODO(isherman): Pull in the equivalent named constant from WebKit, without | |
23 // breaking the shared-lib build. | |
24 const int kDefaultMaxLength = 0x80000; | |
25 | |
26 const FilePath::CharType kTestName[] = FILE_PATH_LITERAL("merge"); | 23 const FilePath::CharType kTestName[] = FILE_PATH_LITERAL("merge"); |
27 const FilePath::CharType kFileNamePattern[] = FILE_PATH_LITERAL("*.in"); | 24 const FilePath::CharType kFileNamePattern[] = FILE_PATH_LITERAL("*.in"); |
28 | 25 |
29 const char kFieldSeparator[] = ": "; | 26 const char kFieldSeparator[] = ": "; |
30 const char kProfileSeparator[] = "---"; | 27 const char kProfileSeparator[] = "---"; |
31 const size_t kFieldOffset = arraysize(kFieldSeparator) - 1; | 28 const size_t kFieldOffset = arraysize(kFieldSeparator) - 1; |
32 | 29 |
33 const AutoFillFieldType kProfileFieldTypes[] = { | 30 const AutoFillFieldType kProfileFieldTypes[] = { |
34 NAME_FIRST, | 31 NAME_FIRST, |
35 NAME_MIDDLE, | 32 NAME_MIDDLE, |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 // Add a field to the current profile. | 174 // Add a field to the current profile. |
178 size_t separator_pos = line.find(kFieldSeparator); | 175 size_t separator_pos = line.find(kFieldSeparator); |
179 ASSERT_NE(std::string::npos, separator_pos); | 176 ASSERT_NE(std::string::npos, separator_pos); |
180 string16 field_type = UTF8ToUTF16(line.substr(0, separator_pos)); | 177 string16 field_type = UTF8ToUTF16(line.substr(0, separator_pos)); |
181 string16 value = UTF8ToUTF16(line.substr(separator_pos + kFieldOffset)); | 178 string16 value = UTF8ToUTF16(line.substr(separator_pos + kFieldOffset)); |
182 | 179 |
183 webkit_glue::FormField field(field_type, | 180 webkit_glue::FormField field(field_type, |
184 field_type, | 181 field_type, |
185 value, | 182 value, |
186 ASCIIToUTF16("text"), | 183 ASCIIToUTF16("text"), |
187 kDefaultMaxLength, | 184 WebKit::WebInputElement::defaultMaxLength(), |
188 false); | 185 false); |
189 form.fields.push_back(field); | 186 form.fields.push_back(field); |
190 } | 187 } |
191 | 188 |
192 // The first line is always a profile separator, and the last profile is not | 189 // The first line is always a profile separator, and the last profile is not |
193 // followed by an explicit separator. | 190 // followed by an explicit separator. |
194 if ((i > 0 && line == kProfileSeparator) || | 191 if ((i > 0 && line == kProfileSeparator) || |
195 i == lines.size() - 1) { | 192 i == lines.size() - 1) { |
196 // Reached the end of a profile. Try to import it. | 193 // Reached the end of a profile. Try to import it. |
197 FormStructure form_structure(form); | 194 FormStructure form_structure(form); |
(...skipping 18 matching lines...) Expand all Loading... |
216 } | 213 } |
217 } | 214 } |
218 | 215 |
219 *merged_profiles = SerializeProfiles(personal_data_->web_profiles()); | 216 *merged_profiles = SerializeProfiles(personal_data_->web_profiles()); |
220 } | 217 } |
221 | 218 |
222 TEST_F(AutoFillMergeTest, DataDrivenMergeProfiles) { | 219 TEST_F(AutoFillMergeTest, DataDrivenMergeProfiles) { |
223 RunDataDrivenTest(GetInputDirectory(kTestName), GetOutputDirectory(kTestName), | 220 RunDataDrivenTest(GetInputDirectory(kTestName), GetOutputDirectory(kTestName), |
224 kFileNamePattern); | 221 kFileNamePattern); |
225 } | 222 } |
OLD | NEW |