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/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 "chrome/common/form_data.h" |
16 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" |
19 #include "webkit/forms/form_data.h" | |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 const FilePath::CharType kTestName[] = FILE_PATH_LITERAL("merge"); | 23 const FilePath::CharType kTestName[] = FILE_PATH_LITERAL("merge"); |
24 const FilePath::CharType kFileNamePattern[] = FILE_PATH_LITERAL("*.in"); | 24 const FilePath::CharType kFileNamePattern[] = FILE_PATH_LITERAL("*.in"); |
25 | 25 |
26 const char kFieldSeparator[] = ": "; | 26 const char kFieldSeparator[] = ": "; |
27 const char kProfileSeparator[] = "---"; | 27 const char kProfileSeparator[] = "---"; |
28 const size_t kFieldOffset = arraysize(kFieldSeparator) - 1; | 28 const size_t kFieldOffset = arraysize(kFieldSeparator) - 1; |
29 | 29 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 std::string* output) { | 148 std::string* output) { |
149 MergeProfiles(input, output); | 149 MergeProfiles(input, output); |
150 } | 150 } |
151 | 151 |
152 void AutofillMergeTest::MergeProfiles(const std::string& profiles, | 152 void AutofillMergeTest::MergeProfiles(const std::string& profiles, |
153 std::string* merged_profiles) { | 153 std::string* merged_profiles) { |
154 // Start with no saved profiles. | 154 // Start with no saved profiles. |
155 personal_data_.Reset(); | 155 personal_data_.Reset(); |
156 | 156 |
157 // Create a test form. | 157 // Create a test form. |
158 webkit::forms::FormData form; | 158 FormData form; |
159 form.name = ASCIIToUTF16("MyTestForm"); | 159 form.name = ASCIIToUTF16("MyTestForm"); |
160 form.method = ASCIIToUTF16("POST"); | 160 form.method = ASCIIToUTF16("POST"); |
161 form.origin = GURL("https://www.example.com/origin.html"); | 161 form.origin = GURL("https://www.example.com/origin.html"); |
162 form.action = GURL("https://www.example.com/action.html"); | 162 form.action = GURL("https://www.example.com/action.html"); |
163 form.user_submitted = true; | 163 form.user_submitted = true; |
164 | 164 |
165 // Parse the input line by line. | 165 // Parse the input line by line. |
166 std::vector<std::string> lines; | 166 std::vector<std::string> lines; |
167 Tokenize(profiles, "\n", &lines); | 167 Tokenize(profiles, "\n", &lines); |
168 for (size_t i = 0; i < lines.size(); ++i) { | 168 for (size_t i = 0; i < lines.size(); ++i) { |
169 std::string line = lines[i]; | 169 std::string line = lines[i]; |
170 | 170 |
171 if (line != kProfileSeparator) { | 171 if (line != kProfileSeparator) { |
172 // Add a field to the current profile. | 172 // Add a field to the current profile. |
173 size_t separator_pos = line.find(kFieldSeparator); | 173 size_t separator_pos = line.find(kFieldSeparator); |
174 ASSERT_NE(std::string::npos, separator_pos); | 174 ASSERT_NE(std::string::npos, separator_pos); |
175 string16 field_type = UTF8ToUTF16(line.substr(0, separator_pos)); | 175 string16 field_type = UTF8ToUTF16(line.substr(0, separator_pos)); |
176 string16 value = UTF8ToUTF16(line.substr(separator_pos + kFieldOffset)); | 176 string16 value = UTF8ToUTF16(line.substr(separator_pos + kFieldOffset)); |
177 | 177 |
178 webkit::forms::FormField field; | 178 FormFieldData field; |
179 field.label = field_type; | 179 field.label = field_type; |
180 field.name = field_type; | 180 field.name = field_type; |
181 field.value = value; | 181 field.value = value; |
182 field.form_control_type = ASCIIToUTF16("text"); | 182 field.form_control_type = ASCIIToUTF16("text"); |
183 form.fields.push_back(field); | 183 form.fields.push_back(field); |
184 } | 184 } |
185 | 185 |
186 // The first line is always a profile separator, and the last profile is not | 186 // The first line is always a profile separator, and the last profile is not |
187 // followed by an explicit separator. | 187 // followed by an explicit separator. |
188 if ((i > 0 && line == kProfileSeparator) || i == lines.size() - 1) { | 188 if ((i > 0 && line == kProfileSeparator) || i == lines.size() - 1) { |
(...skipping 19 matching lines...) Expand all Loading... |
208 } | 208 } |
209 } | 209 } |
210 | 210 |
211 *merged_profiles = SerializeProfiles(personal_data_.web_profiles()); | 211 *merged_profiles = SerializeProfiles(personal_data_.web_profiles()); |
212 } | 212 } |
213 | 213 |
214 TEST_F(AutofillMergeTest, DataDrivenMergeProfiles) { | 214 TEST_F(AutofillMergeTest, DataDrivenMergeProfiles) { |
215 RunDataDrivenTest(GetInputDirectory(kTestName), GetOutputDirectory(kTestName), | 215 RunDataDrivenTest(GetInputDirectory(kTestName), GetOutputDirectory(kTestName), |
216 kFileNamePattern); | 216 kFileNamePattern); |
217 } | 217 } |
OLD | NEW |