| 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/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 12 #include "chrome/test/base/in_process_browser_test.h" | 12 #include "chrome/test/base/in_process_browser_test.h" |
| 13 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
| 14 #include "components/autofill/browser/autofill_manager.h" | 14 #include "components/autofill/browser/autofill_manager.h" |
| 15 #include "components/autofill/browser/data_driven_test.h" | 15 #include "components/autofill/browser/data_driven_test.h" |
| 16 #include "components/autofill/browser/form_structure.h" | 16 #include "components/autofill/browser/form_structure.h" |
| 17 #include "components/autofill/content/browser/autofill_driver_impl.h" |
| 17 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
| 18 | 19 |
| 19 namespace autofill { | 20 namespace autofill { |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 const base::FilePath::CharType kTestName[] = FILE_PATH_LITERAL("heuristics"); | 23 const base::FilePath::CharType kTestName[] = FILE_PATH_LITERAL("heuristics"); |
| 23 | 24 |
| 24 // Convert the |html| snippet to a data URI. | 25 // Convert the |html| snippet to a data URI. |
| 25 GURL HTMLToDataURI(const std::string& html) { | 26 GURL HTMLToDataURI(const std::string& html) { |
| 26 return GURL(std::string("data:text/html;charset=utf-8,") + html); | 27 return GURL(std::string("data:text/html;charset=utf-8,") + html); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 52 } | 53 } |
| 53 | 54 |
| 54 FormStructureBrowserTest::~FormStructureBrowserTest() { | 55 FormStructureBrowserTest::~FormStructureBrowserTest() { |
| 55 } | 56 } |
| 56 | 57 |
| 57 void FormStructureBrowserTest::GenerateResults(const std::string& input, | 58 void FormStructureBrowserTest::GenerateResults(const std::string& input, |
| 58 std::string* output) { | 59 std::string* output) { |
| 59 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), | 60 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), |
| 60 HTMLToDataURI(input))); | 61 HTMLToDataURI(input))); |
| 61 | 62 |
| 62 AutofillManager* autofill_manager = AutofillManager::FromWebContents( | 63 AutofillDriverImpl* autofill_driver = AutofillDriverImpl::FromWebContents( |
| 63 browser()->tab_strip_model()->GetActiveWebContents()); | 64 browser()->tab_strip_model()->GetActiveWebContents()); |
| 65 ASSERT_NE(static_cast<AutofillDriverImpl*>(NULL), autofill_driver); |
| 66 AutofillManager* autofill_manager = autofill_driver->autofill_manager(); |
| 64 ASSERT_NE(static_cast<AutofillManager*>(NULL), autofill_manager); | 67 ASSERT_NE(static_cast<AutofillManager*>(NULL), autofill_manager); |
| 65 std::vector<FormStructure*> forms = autofill_manager->form_structures_.get(); | 68 std::vector<FormStructure*> forms = autofill_manager->form_structures_.get(); |
| 66 *output = FormStructureBrowserTest::FormStructuresToString(forms); | 69 *output = FormStructureBrowserTest::FormStructuresToString(forms); |
| 67 } | 70 } |
| 68 | 71 |
| 69 std::string FormStructureBrowserTest::FormStructuresToString( | 72 std::string FormStructureBrowserTest::FormStructuresToString( |
| 70 const std::vector<FormStructure*>& forms) { | 73 const std::vector<FormStructure*>& forms) { |
| 71 std::string forms_string; | 74 std::string forms_string; |
| 72 for (std::vector<FormStructure*>::const_iterator iter = forms.begin(); | 75 for (std::vector<FormStructure*>::const_iterator iter = forms.begin(); |
| 73 iter != forms.end(); | 76 iter != forms.end(); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest, | 260 IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest, |
| 258 MAYBE_DataDrivenHeuristics(20)) { | 261 MAYBE_DataDrivenHeuristics(20)) { |
| 259 const base::FilePath::CharType kFileNamePattern[] = | 262 const base::FilePath::CharType kFileNamePattern[] = |
| 260 FILE_PATH_LITERAL("20_*.html"); | 263 FILE_PATH_LITERAL("20_*.html"); |
| 261 RunDataDrivenTest(GetInputDirectory(kTestName), | 264 RunDataDrivenTest(GetInputDirectory(kTestName), |
| 262 GetOutputDirectory(kTestName), | 265 GetOutputDirectory(kTestName), |
| 263 kFileNamePattern); | 266 kFileNamePattern); |
| 264 } | 267 } |
| 265 | 268 |
| 266 } // namespace autofill | 269 } // namespace autofill |
| OLD | NEW |