Fix build break
[chromium-blink-merge.git] / chrome / browser / autofill / form_structure_browsertest.cc
blob9e087275b4927f1e16acb7e869e2567b2ba1d81d
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
3 // found in the LICENSE file.
5 #include <vector>
7 #include "base/files/file_path.h"
8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/test/base/in_process_browser_test.h"
13 #include "chrome/test/base/ui_test_utils.h"
14 #include "components/autofill/browser/autofill_manager.h"
15 #include "components/autofill/browser/data_driven_test.h"
16 #include "components/autofill/browser/form_structure.h"
17 #include "googleurl/src/gurl.h"
19 namespace autofill {
20 namespace {
22 const base::FilePath::CharType kTestName[] = FILE_PATH_LITERAL("heuristics");
24 // Convert the |html| snippet to a data URI.
25 GURL HTMLToDataURI(const std::string& html) {
26 return GURL(std::string("data:text/html;charset=utf-8,") + html);
29 } // namespace
31 // A data-driven test for verifying Autofill heuristics. Each input is an HTML
32 // file that contains one or more forms. The corresponding output file lists the
33 // heuristically detected type for eachfield.
34 class FormStructureBrowserTest : public InProcessBrowserTest,
35 public DataDrivenTest {
36 protected:
37 FormStructureBrowserTest();
38 virtual ~FormStructureBrowserTest();
40 // DataDrivenTest:
41 virtual void GenerateResults(const std::string& input,
42 std::string* output) OVERRIDE;
44 // Serializes the given |forms| into a string.
45 std::string FormStructuresToString(const std::vector<FormStructure*>& forms);
47 private:
48 DISALLOW_COPY_AND_ASSIGN(FormStructureBrowserTest);
51 FormStructureBrowserTest::FormStructureBrowserTest() {
54 FormStructureBrowserTest::~FormStructureBrowserTest() {
57 void FormStructureBrowserTest::GenerateResults(const std::string& input,
58 std::string* output) {
59 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
60 HTMLToDataURI(input)));
62 AutofillManager* autofill_manager = AutofillManager::FromWebContents(
63 browser()->tab_strip_model()->GetActiveWebContents());
64 ASSERT_NE(static_cast<AutofillManager*>(NULL), autofill_manager);
65 std::vector<FormStructure*> forms = autofill_manager->form_structures_.get();
66 *output = FormStructureBrowserTest::FormStructuresToString(forms);
69 std::string FormStructureBrowserTest::FormStructuresToString(
70 const std::vector<FormStructure*>& forms) {
71 std::string forms_string;
72 for (std::vector<FormStructure*>::const_iterator iter = forms.begin();
73 iter != forms.end();
74 ++iter) {
76 for (std::vector<AutofillField*>::const_iterator field_iter =
77 (*iter)->begin();
78 field_iter != (*iter)->end();
79 ++field_iter) {
80 forms_string += AutofillType::FieldTypeToString((*field_iter)->type());
81 forms_string += " | " + UTF16ToUTF8((*field_iter)->name);
82 forms_string += " | " + UTF16ToUTF8((*field_iter)->label);
83 forms_string += " | " + UTF16ToUTF8((*field_iter)->value);
84 forms_string += "\n";
87 return forms_string;
90 // Heuristics tests timeout on Windows. See http://crbug.com/85276
91 // Also on ChromeOS/Aura. See crbug.com/173621
92 #if defined(OS_WIN) || defined(USE_AURA)
93 #define MAYBE_DataDrivenHeuristics(n) DISABLED_DataDrivenHeuristics##n
94 #else
95 #define MAYBE_DataDrivenHeuristics(n) DataDrivenHeuristics##n
96 #endif
97 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest, DataDrivenHeuristics00) {
98 const base::FilePath::CharType kFileNamePattern[] =
99 FILE_PATH_LITERAL("00_*.html");
100 RunDataDrivenTest(GetInputDirectory(kTestName),
101 GetOutputDirectory(kTestName),
102 kFileNamePattern);
105 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest, DataDrivenHeuristics01) {
106 const base::FilePath::CharType kFileNamePattern[] =
107 FILE_PATH_LITERAL("01_*.html");
108 RunDataDrivenTest(GetInputDirectory(kTestName),
109 GetOutputDirectory(kTestName),
110 kFileNamePattern);
113 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
114 MAYBE_DataDrivenHeuristics(02)) {
115 const base::FilePath::CharType kFileNamePattern[] =
116 FILE_PATH_LITERAL("02_*.html");
117 RunDataDrivenTest(GetInputDirectory(kTestName),
118 GetOutputDirectory(kTestName),
119 kFileNamePattern);
122 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
123 MAYBE_DataDrivenHeuristics(03)) {
124 const base::FilePath::CharType kFileNamePattern[] =
125 FILE_PATH_LITERAL("03_*.html");
126 RunDataDrivenTest(GetInputDirectory(kTestName),
127 GetOutputDirectory(kTestName),
128 kFileNamePattern);
131 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
132 MAYBE_DataDrivenHeuristics(04)) {
133 const base::FilePath::CharType kFileNamePattern[] =
134 FILE_PATH_LITERAL("04_*.html");
135 RunDataDrivenTest(GetInputDirectory(kTestName),
136 GetOutputDirectory(kTestName),
137 kFileNamePattern);
140 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
141 MAYBE_DataDrivenHeuristics(05)) {
142 const base::FilePath::CharType kFileNamePattern[] =
143 FILE_PATH_LITERAL("05_*.html");
144 RunDataDrivenTest(GetInputDirectory(kTestName),
145 GetOutputDirectory(kTestName),
146 kFileNamePattern);
149 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
150 MAYBE_DataDrivenHeuristics(06)) {
151 const base::FilePath::CharType kFileNamePattern[] =
152 FILE_PATH_LITERAL("06_*.html");
153 RunDataDrivenTest(GetInputDirectory(kTestName),
154 GetOutputDirectory(kTestName),
155 kFileNamePattern);
158 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
159 MAYBE_DataDrivenHeuristics(07)) {
160 const base::FilePath::CharType kFileNamePattern[] =
161 FILE_PATH_LITERAL("07_*.html");
162 RunDataDrivenTest(GetInputDirectory(kTestName),
163 GetOutputDirectory(kTestName),
164 kFileNamePattern);
167 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
168 MAYBE_DataDrivenHeuristics(08)) {
169 const base::FilePath::CharType kFileNamePattern[] =
170 FILE_PATH_LITERAL("08_*.html");
171 RunDataDrivenTest(GetInputDirectory(kTestName),
172 GetOutputDirectory(kTestName),
173 kFileNamePattern);
176 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
177 MAYBE_DataDrivenHeuristics(09)) {
178 const base::FilePath::CharType kFileNamePattern[] =
179 FILE_PATH_LITERAL("09_*.html");
180 RunDataDrivenTest(GetInputDirectory(kTestName),
181 GetOutputDirectory(kTestName),
182 kFileNamePattern);
185 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
186 MAYBE_DataDrivenHeuristics(10)) {
187 const base::FilePath::CharType kFileNamePattern[] =
188 FILE_PATH_LITERAL("10_*.html");
189 RunDataDrivenTest(GetInputDirectory(kTestName),
190 GetOutputDirectory(kTestName),
191 kFileNamePattern);
194 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
195 MAYBE_DataDrivenHeuristics(11)) {
196 const base::FilePath::CharType kFileNamePattern[] =
197 FILE_PATH_LITERAL("11_*.html");
198 RunDataDrivenTest(GetInputDirectory(kTestName),
199 GetOutputDirectory(kTestName),
200 kFileNamePattern);
203 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
204 MAYBE_DataDrivenHeuristics(12)) {
205 const base::FilePath::CharType kFileNamePattern[] =
206 FILE_PATH_LITERAL("12_*.html");
207 RunDataDrivenTest(GetInputDirectory(kTestName),
208 GetOutputDirectory(kTestName),
209 kFileNamePattern);
212 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
213 MAYBE_DataDrivenHeuristics(13)) {
214 const base::FilePath::CharType kFileNamePattern[] =
215 FILE_PATH_LITERAL("13_*.html");
216 RunDataDrivenTest(GetInputDirectory(kTestName),
217 GetOutputDirectory(kTestName),
218 kFileNamePattern);
221 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
222 MAYBE_DataDrivenHeuristics(14)) {
223 const base::FilePath::CharType kFileNamePattern[] =
224 FILE_PATH_LITERAL("14_*.html");
225 RunDataDrivenTest(GetInputDirectory(kTestName),
226 GetOutputDirectory(kTestName),
227 kFileNamePattern);
230 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
231 MAYBE_DataDrivenHeuristics(15)) {
232 const base::FilePath::CharType kFileNamePattern[] =
233 FILE_PATH_LITERAL("15_*.html");
234 RunDataDrivenTest(GetInputDirectory(kTestName),
235 GetOutputDirectory(kTestName),
236 kFileNamePattern);
239 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
240 MAYBE_DataDrivenHeuristics(16)) {
241 const base::FilePath::CharType kFileNamePattern[] =
242 FILE_PATH_LITERAL("16_*.html");
243 RunDataDrivenTest(GetInputDirectory(kTestName),
244 GetOutputDirectory(kTestName),
245 kFileNamePattern);
248 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
249 MAYBE_DataDrivenHeuristics(17)) {
250 const base::FilePath::CharType kFileNamePattern[] =
251 FILE_PATH_LITERAL("17_*.html");
252 RunDataDrivenTest(GetInputDirectory(kTestName),
253 GetOutputDirectory(kTestName),
254 kFileNamePattern);
257 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
258 MAYBE_DataDrivenHeuristics(20)) {
259 const base::FilePath::CharType kFileNamePattern[] =
260 FILE_PATH_LITERAL("20_*.html");
261 RunDataDrivenTest(GetInputDirectory(kTestName),
262 GetOutputDirectory(kTestName),
263 kFileNamePattern);
266 } // namespace autofill