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

Side by Side Diff: chrome/browser/autofill/form_structure_browsertest.cc

Issue 12260054: [Autofill] Enable heuristic detection of credit card issuer fields. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 10 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
« no previous file with comments | « chrome/browser/autofill/form_field.cc ('k') | chrome/browser/autofill/name_field.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/command_line.h"
8 #include "base/file_path.h" 7 #include "base/file_path.h"
9 #include "base/string_util.h" 8 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/autofill/autofill_manager.h" 10 #include "chrome/browser/autofill/autofill_manager.h"
12 #include "chrome/browser/autofill/data_driven_test.h" 11 #include "chrome/browser/autofill/data_driven_test.h"
13 #include "chrome/browser/autofill/form_structure.h" 12 #include "chrome/browser/autofill/form_structure.h"
14 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" 14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/test/base/in_process_browser_test.h" 15 #include "chrome/test/base/in_process_browser_test.h"
18 #include "chrome/test/base/ui_test_utils.h" 16 #include "chrome/test/base/ui_test_utils.h"
19 #include "googleurl/src/gurl.h" 17 #include "googleurl/src/gurl.h"
20 18
21 namespace { 19 namespace {
22 20
23 const base::FilePath::CharType kTestName[] = FILE_PATH_LITERAL("heuristics"); 21 const base::FilePath::CharType kTestName[] = FILE_PATH_LITERAL("heuristics");
24 22
25 // Convert the |html| snippet to a data URI. 23 // Convert the |html| snippet to a data URI.
26 GURL HTMLToDataURI(const std::string& html) { 24 GURL HTMLToDataURI(const std::string& html) {
27 return GURL(std::string("data:text/html;charset=utf-8,") + html); 25 return GURL(std::string("data:text/html;charset=utf-8,") + html);
28 } 26 }
29 27
30 } // namespace 28 } // namespace
31 29
32 // A data-driven test for verifying Autofill heuristics. Each input is an HTML 30 // A data-driven test for verifying Autofill heuristics. Each input is an HTML
33 // file that contains one or more forms. The corresponding output file lists the 31 // file that contains one or more forms. The corresponding output file lists the
34 // heuristically detected type for eachfield. 32 // heuristically detected type for eachfield.
35 class FormStructureBrowserTest : public InProcessBrowserTest, 33 class FormStructureBrowserTest : public InProcessBrowserTest,
36 public DataDrivenTest { 34 public DataDrivenTest {
37 protected: 35 protected:
38 FormStructureBrowserTest(); 36 FormStructureBrowserTest();
39 virtual ~FormStructureBrowserTest(); 37 virtual ~FormStructureBrowserTest();
40 38
41 // InProcessBrowserTest:
42 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
43
44 // DataDrivenTest: 39 // DataDrivenTest:
45 virtual void GenerateResults(const std::string& input, 40 virtual void GenerateResults(const std::string& input,
46 std::string* output) OVERRIDE; 41 std::string* output) OVERRIDE;
47 42
48 // Serializes the given |forms| into a string. 43 // Serializes the given |forms| into a string.
49 std::string FormStructuresToString(const std::vector<FormStructure*>& forms); 44 std::string FormStructuresToString(const std::vector<FormStructure*>& forms);
50 45
51 private: 46 private:
52 DISALLOW_COPY_AND_ASSIGN(FormStructureBrowserTest); 47 DISALLOW_COPY_AND_ASSIGN(FormStructureBrowserTest);
53 }; 48 };
54 49
55 FormStructureBrowserTest::FormStructureBrowserTest() { 50 FormStructureBrowserTest::FormStructureBrowserTest() {
56 } 51 }
57 52
58 FormStructureBrowserTest::~FormStructureBrowserTest() { 53 FormStructureBrowserTest::~FormStructureBrowserTest() {
59 } 54 }
60 55
61 void FormStructureBrowserTest::SetUpCommandLine(CommandLine* command_line) {
62 // Include new field types and heuristics in the regression test.
63 command_line->AppendSwitch(switches::kEnableNewAutofillHeuristics);
64 }
65
66 void FormStructureBrowserTest::GenerateResults(const std::string& input, 56 void FormStructureBrowserTest::GenerateResults(const std::string& input,
67 std::string* output) { 57 std::string* output) {
68 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), 58 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
69 HTMLToDataURI(input))); 59 HTMLToDataURI(input)));
70 60
71 AutofillManager* autofill_manager = AutofillManager::FromWebContents( 61 AutofillManager* autofill_manager = AutofillManager::FromWebContents(
72 browser()->tab_strip_model()->GetActiveWebContents()); 62 browser()->tab_strip_model()->GetActiveWebContents());
73 ASSERT_NE(static_cast<AutofillManager*>(NULL), autofill_manager); 63 ASSERT_NE(static_cast<AutofillManager*>(NULL), autofill_manager);
74 std::vector<FormStructure*> forms = autofill_manager->form_structures_.get(); 64 std::vector<FormStructure*> forms = autofill_manager->form_structures_.get();
75 *output = FormStructureBrowserTest::FormStructuresToString(forms); 65 *output = FormStructureBrowserTest::FormStructuresToString(forms);
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 } 254 }
265 255
266 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest, 256 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest,
267 MAYBE_DataDrivenHeuristics(20)) { 257 MAYBE_DataDrivenHeuristics(20)) {
268 const base::FilePath::CharType kFileNamePattern[] = 258 const base::FilePath::CharType kFileNamePattern[] =
269 FILE_PATH_LITERAL("20_*.html"); 259 FILE_PATH_LITERAL("20_*.html");
270 RunDataDrivenTest(GetInputDirectory(kTestName), 260 RunDataDrivenTest(GetInputDirectory(kTestName),
271 GetOutputDirectory(kTestName), 261 GetOutputDirectory(kTestName),
272 kFileNamePattern); 262 kFileNamePattern);
273 } 263 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/form_field.cc ('k') | chrome/browser/autofill/name_field.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698