Update mojo surfaces bindings and mojo/cc/ glue
[chromium-blink-merge.git] / chrome / browser / autofill / form_structure_browsertest.cc
blobed186a911ff9ec95ea1d6b054162745e07d95faf
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/path_service.h"
9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/common/chrome_paths.h"
14 #include "chrome/test/base/in_process_browser_test.h"
15 #include "chrome/test/base/ui_test_utils.h"
16 #include "components/autofill/content/browser/content_autofill_driver.h"
17 #include "components/autofill/core/browser/autofill_manager.h"
18 #include "components/autofill/core/browser/data_driven_test.h"
19 #include "components/autofill/core/browser/form_structure.h"
20 #include "url/gurl.h"
22 namespace autofill {
23 namespace {
25 const base::FilePath::CharType kTestName[] = FILE_PATH_LITERAL("heuristics");
27 // Convert the |html| snippet to a data URI.
28 GURL HTMLToDataURI(const std::string& html) {
29 return GURL(std::string("data:text/html;charset=utf-8,") + html);
32 const base::FilePath& GetTestDataDir() {
33 CR_DEFINE_STATIC_LOCAL(base::FilePath, dir, ());
34 if (dir.empty())
35 PathService::Get(chrome::DIR_TEST_DATA, &dir);
36 return dir;
39 } // namespace
41 // A data-driven test for verifying Autofill heuristics. Each input is an HTML
42 // file that contains one or more forms. The corresponding output file lists the
43 // heuristically detected type for eachfield.
44 class FormStructureBrowserTest : public InProcessBrowserTest,
45 public DataDrivenTest {
46 protected:
47 FormStructureBrowserTest();
48 virtual ~FormStructureBrowserTest();
50 // DataDrivenTest:
51 virtual void GenerateResults(const std::string& input,
52 std::string* output) OVERRIDE;
54 // Serializes the given |forms| into a string.
55 std::string FormStructuresToString(const std::vector<FormStructure*>& forms);
57 private:
58 DISALLOW_COPY_AND_ASSIGN(FormStructureBrowserTest);
61 FormStructureBrowserTest::FormStructureBrowserTest()
62 : DataDrivenTest(GetTestDataDir()) {
65 FormStructureBrowserTest::~FormStructureBrowserTest() {
68 void FormStructureBrowserTest::GenerateResults(const std::string& input,
69 std::string* output) {
70 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
71 HTMLToDataURI(input)));
73 ContentAutofillDriver* autofill_driver =
74 ContentAutofillDriver::FromWebContents(
75 browser()->tab_strip_model()->GetActiveWebContents());
76 ASSERT_NE(static_cast<ContentAutofillDriver*>(NULL), autofill_driver);
77 AutofillManager* autofill_manager = autofill_driver->autofill_manager();
78 ASSERT_NE(static_cast<AutofillManager*>(NULL), autofill_manager);
79 std::vector<FormStructure*> forms = autofill_manager->form_structures_.get();
80 *output = FormStructureBrowserTest::FormStructuresToString(forms);
83 std::string FormStructureBrowserTest::FormStructuresToString(
84 const std::vector<FormStructure*>& forms) {
85 std::string forms_string;
86 for (std::vector<FormStructure*>::const_iterator iter = forms.begin();
87 iter != forms.end();
88 ++iter) {
90 for (std::vector<AutofillField*>::const_iterator field_iter =
91 (*iter)->begin();
92 field_iter != (*iter)->end();
93 ++field_iter) {
94 forms_string += (*field_iter)->Type().ToString();
95 forms_string += " | " + base::UTF16ToUTF8((*field_iter)->name);
96 forms_string += " | " + base::UTF16ToUTF8((*field_iter)->label);
97 forms_string += " | " + base::UTF16ToUTF8((*field_iter)->value);
98 forms_string += "\n";
101 return forms_string;
104 // Heuristics tests timeout on Windows. See http://crbug.com/85276
105 // Also on ChromeOS/Aura. See crbug.com/173621
106 // On Linux too. See crbug.com/323093
107 #if defined(USE_AURA)
108 #define MAYBE_DataDrivenHeuristics(n) DISABLED_DataDrivenHeuristics##n
109 #else
110 #define MAYBE_DataDrivenHeuristics(n) DataDrivenHeuristics##n
111 #endif
112 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest, DataDrivenHeuristics00) {
113 const base::FilePath::CharType kFileNamePattern[] =
114 FILE_PATH_LITERAL("00_*.html");
115 RunDataDrivenTest(GetInputDirectory(kTestName),
116 GetOutputDirectory(kTestName),
117 kFileNamePattern);
120 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest, DataDrivenHeuristics01) {
121 const base::FilePath::CharType kFileNamePattern[] =
122 FILE_PATH_LITERAL("01_*.html");
123 RunDataDrivenTest(GetInputDirectory(kTestName),
124 GetOutputDirectory(kTestName),
125 kFileNamePattern);
128 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
129 MAYBE_DataDrivenHeuristics(02)) {
130 const base::FilePath::CharType kFileNamePattern[] =
131 FILE_PATH_LITERAL("02_*.html");
132 RunDataDrivenTest(GetInputDirectory(kTestName),
133 GetOutputDirectory(kTestName),
134 kFileNamePattern);
137 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
138 MAYBE_DataDrivenHeuristics(03)) {
139 const base::FilePath::CharType kFileNamePattern[] =
140 FILE_PATH_LITERAL("03_*.html");
141 RunDataDrivenTest(GetInputDirectory(kTestName),
142 GetOutputDirectory(kTestName),
143 kFileNamePattern);
146 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
147 MAYBE_DataDrivenHeuristics(04)) {
148 const base::FilePath::CharType kFileNamePattern[] =
149 FILE_PATH_LITERAL("04_*.html");
150 RunDataDrivenTest(GetInputDirectory(kTestName),
151 GetOutputDirectory(kTestName),
152 kFileNamePattern);
155 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
156 MAYBE_DataDrivenHeuristics(05)) {
157 const base::FilePath::CharType kFileNamePattern[] =
158 FILE_PATH_LITERAL("05_*.html");
159 RunDataDrivenTest(GetInputDirectory(kTestName),
160 GetOutputDirectory(kTestName),
161 kFileNamePattern);
164 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
165 MAYBE_DataDrivenHeuristics(06)) {
166 const base::FilePath::CharType kFileNamePattern[] =
167 FILE_PATH_LITERAL("06_*.html");
168 RunDataDrivenTest(GetInputDirectory(kTestName),
169 GetOutputDirectory(kTestName),
170 kFileNamePattern);
173 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
174 MAYBE_DataDrivenHeuristics(07)) {
175 const base::FilePath::CharType kFileNamePattern[] =
176 FILE_PATH_LITERAL("07_*.html");
177 RunDataDrivenTest(GetInputDirectory(kTestName),
178 GetOutputDirectory(kTestName),
179 kFileNamePattern);
182 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
183 MAYBE_DataDrivenHeuristics(08)) {
184 const base::FilePath::CharType kFileNamePattern[] =
185 FILE_PATH_LITERAL("08_*.html");
186 RunDataDrivenTest(GetInputDirectory(kTestName),
187 GetOutputDirectory(kTestName),
188 kFileNamePattern);
191 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
192 MAYBE_DataDrivenHeuristics(09)) {
193 const base::FilePath::CharType kFileNamePattern[] =
194 FILE_PATH_LITERAL("09_*.html");
195 RunDataDrivenTest(GetInputDirectory(kTestName),
196 GetOutputDirectory(kTestName),
197 kFileNamePattern);
200 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
201 MAYBE_DataDrivenHeuristics(10)) {
202 const base::FilePath::CharType kFileNamePattern[] =
203 FILE_PATH_LITERAL("10_*.html");
204 RunDataDrivenTest(GetInputDirectory(kTestName),
205 GetOutputDirectory(kTestName),
206 kFileNamePattern);
209 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
210 MAYBE_DataDrivenHeuristics(11)) {
211 const base::FilePath::CharType kFileNamePattern[] =
212 FILE_PATH_LITERAL("11_*.html");
213 RunDataDrivenTest(GetInputDirectory(kTestName),
214 GetOutputDirectory(kTestName),
215 kFileNamePattern);
218 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
219 MAYBE_DataDrivenHeuristics(12)) {
220 const base::FilePath::CharType kFileNamePattern[] =
221 FILE_PATH_LITERAL("12_*.html");
222 RunDataDrivenTest(GetInputDirectory(kTestName),
223 GetOutputDirectory(kTestName),
224 kFileNamePattern);
227 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
228 MAYBE_DataDrivenHeuristics(13)) {
229 const base::FilePath::CharType kFileNamePattern[] =
230 FILE_PATH_LITERAL("13_*.html");
231 RunDataDrivenTest(GetInputDirectory(kTestName),
232 GetOutputDirectory(kTestName),
233 kFileNamePattern);
236 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
237 MAYBE_DataDrivenHeuristics(14)) {
238 const base::FilePath::CharType kFileNamePattern[] =
239 FILE_PATH_LITERAL("14_*.html");
240 RunDataDrivenTest(GetInputDirectory(kTestName),
241 GetOutputDirectory(kTestName),
242 kFileNamePattern);
245 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
246 MAYBE_DataDrivenHeuristics(15)) {
247 const base::FilePath::CharType kFileNamePattern[] =
248 FILE_PATH_LITERAL("15_*.html");
249 RunDataDrivenTest(GetInputDirectory(kTestName),
250 GetOutputDirectory(kTestName),
251 kFileNamePattern);
254 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
255 MAYBE_DataDrivenHeuristics(16)) {
256 const base::FilePath::CharType kFileNamePattern[] =
257 FILE_PATH_LITERAL("16_*.html");
258 RunDataDrivenTest(GetInputDirectory(kTestName),
259 GetOutputDirectory(kTestName),
260 kFileNamePattern);
263 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
264 MAYBE_DataDrivenHeuristics(17)) {
265 const base::FilePath::CharType kFileNamePattern[] =
266 FILE_PATH_LITERAL("17_*.html");
267 RunDataDrivenTest(GetInputDirectory(kTestName),
268 GetOutputDirectory(kTestName),
269 kFileNamePattern);
272 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
273 MAYBE_DataDrivenHeuristics(20)) {
274 const base::FilePath::CharType kFileNamePattern[] =
275 FILE_PATH_LITERAL("20_*.html");
276 RunDataDrivenTest(GetInputDirectory(kTestName),
277 GetOutputDirectory(kTestName),
278 kFileNamePattern);
281 } // namespace autofill