Chromium Code Reviews| Index: chrome/browser/autofill/form_structure_browsertest.cc |
| =================================================================== |
| --- chrome/browser/autofill/form_structure_browsertest.cc (revision 67097) |
| +++ chrome/browser/autofill/form_structure_browsertest.cc (working copy) |
| @@ -4,20 +4,68 @@ |
| #include <vector> |
| +#include "base/file_path.h" |
| +#include "base/path_service.h" |
| +#include "base/string_util.h" |
| +#include "base/utf_string_conversions.h" |
| #include "chrome/browser/autofill/autofill_manager.h" |
| #include "chrome/browser/autofill/form_structure.h" |
| #include "chrome/browser/tab_contents/tab_contents.h" |
| #include "chrome/browser/ui/browser.h" |
| +#include "chrome/common/chrome_paths.h" |
| #include "chrome/test/in_process_browser_test.h" |
| #include "chrome/test/ui_test_utils.h" |
| #include "googleurl/src/gurl.h" |
| -// Test class for verifying proper form structure as determined by AutoFill |
| -// heuristics. After a test loads HTML content with a call to |NavigateToURL| |
| -// the |AutoFillManager| associated with the tab contents is queried for the |
| -// form structures that were loaded and parsed. |
| -// These form structures are serialized to string form and compared with |
| -// expected results. |
| +namespace { |
| + |
| + FilePath GetInputFileDirectory() { |
|
dhollowa
2010/12/15 03:20:45
These functions should not be indented. See http:
vivianz
2010/12/15 23:31:37
On 2010/12/15 03:20:45, dhollowa wrote:
Done.
|
| + FilePath test_data_dir_; |
| + PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); |
| + test_data_dir_ = test_data_dir_.AppendASCII("autofill_heuristics") |
| + .AppendASCII("input"); |
| + return test_data_dir_; |
| + } |
| + |
| + FilePath GetOutputFileDirectory() { |
| + FilePath test_data_dir_; |
| + PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); |
| + test_data_dir_ = test_data_dir_.AppendASCII("autofill_heuristics") |
| + .AppendASCII("output"); |
| + return test_data_dir_; |
| + } |
| + |
| + // Write |outputcontent| to |outputfile|. Returns true on success. |
| + bool WriteFile(const FilePath& outputfile, |
|
dhollowa
2010/12/15 03:20:45
Let's rename |outputfile| to |file|, and |outputco
vivianz
2010/12/15 23:31:37
On 2010/12/15 03:20:45, dhollowa wrote:
Done.
|
| + const std::string& outputcontent) { |
| + int write_size = file_util::WriteFile(outputfile, outputcontent.c_str(), |
| + outputcontent.length()); |
| + return write_size == static_cast<int>(outputcontent.length()); |
| + } |
| + |
| + // Convert |input_str| to URL format, and return the converted string. |
| + const std::string ConvertToURLFormat(std::string& input_str) { |
|
dhollowa
2010/12/15 03:20:45
Let's change the input parameter to: const std::st
vivianz
2010/12/15 23:31:37
On 2010/12/15 03:20:45, dhollowa wrote:
Done.
|
| + const std::string find_html_header_str( |
| + "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n" |
| + "<html>\n <head>\n <title></title>\n" |
| + " </head>\n <body>\n"); |
| + const std::string replace_str("data:text/html;charset=utf-8,"); |
| + |
| + ReplaceSubstringsAfterOffset(&input_str, 0, find_html_header_str, |
| + replace_str); |
| + return input_str; |
| + } |
| +} // namespace |
| + |
| +// Test class for verifying proper international form structure as determined |
|
dhollowa
2010/12/15 03:20:45
This code is not i18n-specific. Let's change this
vivianz
2010/12/15 23:31:37
On 2010/12/15 03:20:45, dhollowa wrote:
remove al
|
| +// by AutoFill heuristics. A test inputs each i18n form file |
| +// (form_[language_code].html) from input directory, then loads its HTML |
| +// content with a call to |NavigateToURL|, the |AutoFillManager| associated |
| +// with the tab contents is queried for the form structures that were loaded |
| +// and parsed. These form structures are serialized to string form. If this is |
| +// the first time test is run, a gold test result file is generated in output |
| +// directory, else the form structures are compared again the existing gold |
| +// result file. |
| class FormStructureBrowserTest : public InProcessBrowserTest { |
| public: |
| FormStructureBrowserTest() {} |
| @@ -51,8 +99,6 @@ |
| for (std::vector<FormStructure*>::const_iterator iter = forms.begin(); |
| iter != forms.end(); |
| ++iter) { |
| - forms_string += (*iter)->source_url().spec(); |
| - forms_string += "\n"; |
| for (std::vector<AutoFillField*>::const_iterator field_iter = |
| (*iter)->begin(); |
| @@ -162,55 +208,50 @@ |
| default: |
| NOTREACHED() << "Invalid AutoFillFieldType value."; |
| } |
| - |
| return std::string(); |
| } |
| -IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest, BasicFormStructure) { |
| - ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| - ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| - browser(), GURL("data:text/html;charset=utf-8," |
| - "<form action=\"http://www.google.com/\" method=\"POST\">" |
| - "<label for=\"firstname\">First name:</label>" |
| - " <input type=\"text\" id=\"firstname\"/><br />" |
| - "<label for=\"lastname\">Last name:</label>" |
| - " <input type=\"text\" id=\"lastname\" /><br />" |
| - "<label for=\"address1\">Address line 1:</label>" |
| - " <input type=\"text\" id=\"address1\" /><br />" |
| - "<label for=\"address2\">Address line 2:</label>" |
| - " <input type=\"text\" id=\"address2\" /><br />" |
| - "<label for=\"city\">City:</label>" |
| - " <input type=\"text\" id=\"city\" /><br />" |
| - "</form>"))); |
| +IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest, HTMLFiles) { |
| + FilePath input_file_path = GetInputFileDirectory(); |
| + file_util::FileEnumerator input_file_enumerator(input_file_path, |
| + false, file_util::FileEnumerator::FILES); |
|
dhollowa
2010/12/15 03:20:45
Let's add the filter "*.html" to limit processing
vivianz
2010/12/15 23:31:37
On 2010/12/15 03:20:45, dhollowa wrote:
Done.
|
| + |
| + for (input_file_path = input_file_enumerator.Next(); |
| + !input_file_path.empty(); |
| + input_file_path = input_file_enumerator.Next()) { |
| + std::string input_file_source; |
| + |
| + ASSERT_TRUE(file_util::ReadFileToString(input_file_path, |
| + &input_file_source)); |
| + input_file_source = ConvertToURLFormat(input_file_source); |
| - ASSERT_NO_FATAL_FAILURE(ui_test_utils::ClickOnView(browser(), |
| - VIEW_ID_TAB_CONTAINER)); |
| - ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), |
| - VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| + ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| + ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| + browser(), GURL(UTF8ToUTF16(input_file_source)))); |
|
Ilya Sherman
2010/12/15 10:58:32
nit: I don't believe we need UTF8ToUTF16 here.
vivianz
2010/12/15 23:31:37
On 2010/12/15 10:58:32, Ilya Sherman wrote:
I thi
Ilya Sherman
2010/12/16 00:24:03
The GURL documentation [1] indicates std::string i
vivianz
2010/12/16 02:00:14
On 2010/12/16 00:24:03, Ilya Sherman wrote:
actau
|
| - AutoFillManager* autofill_manager = |
| - browser()->GetSelectedTabContents()->GetAutoFillManager(); |
| - ASSERT_NE(static_cast<AutoFillManager*>(NULL), autofill_manager); |
| - std::vector<FormStructure*> forms = GetFormStructures(*autofill_manager); |
| - std::string expected("data:text/html;charset=utf-8," |
| - "<form action=\"http://www.google.com/\"" |
| - " method=\"POST\">" |
| - "<label for=\"firstname\">First name:</label>" |
| - " <input type=\"text\" id=\"firstname\"/><br />" |
| - "<label for=\"lastname\">Last name:</label>" |
| - " <input type=\"text\" id=\"lastname\" /><br />" |
| - "<label for=\"address1\">Address line 1:</label>" |
| - " <input type=\"text\" id=\"address1\" /><br />" |
| - "<label for=\"address2\">Address line 2:</label>" |
| - " <input type=\"text\" id=\"address2\" /><br />" |
| - "<label for=\"city\">City:</label>" |
| - " <input type=\"text\" id=\"city\" /><br />" |
| - "</form>\n" |
| - "NAME_FIRST\n" |
| - "NAME_LAST\n" |
| - "ADDRESS_HOME_LINE1\n" |
| - "ADDRESS_HOME_LINE2\n" |
| - "ADDRESS_HOME_CITY\n"); |
| + ASSERT_NO_FATAL_FAILURE(ui_test_utils::ClickOnView(browser(), |
| + VIEW_ID_TAB_CONTAINER)); |
|
Ilya Sherman
2010/12/15 10:58:32
nit: Please preserve the indentation here. The se
vivianz
2010/12/15 23:31:37
On 2010/12/15 10:58:32, Ilya Sherman wrote:
Done.
|
| + ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), |
| + VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| - EXPECT_EQ(expected, FormStructureBrowserTest::FormStructuresToString(forms)); |
| + AutoFillManager* autofill_manager = |
| + browser()->GetSelectedTabContents()->GetAutoFillManager(); |
| + ASSERT_NE(static_cast<AutoFillManager*>(NULL), autofill_manager); |
| + std::vector<FormStructure*> forms = GetFormStructures(*autofill_manager); |
| + |
| + FilePath output_file_directory = GetOutputFileDirectory(); |
| + FilePath output_file_path = output_file_directory.Append(input_file_path |
| + .BaseName().StripTrailingSeparators().ReplaceExtension( |
| + FILE_PATH_LITERAL(".out"))); |
|
Ilya Sherman
2010/12/15 10:58:32
nit: I would prefer the following formatting (each
vivianz
2010/12/15 23:31:37
On 2010/12/15 10:58:32, Ilya Sherman wrote:
Done.
|
| + |
| + std::string output_file_source; |
| + if (file_util::ReadFileToString(output_file_path, &output_file_source)) { |
| + EXPECT_EQ(output_file_source, |
|
dhollowa
2010/12/15 15:24:01
I ran this through the trybots and we're getting f
vivianz
2010/12/15 23:31:37
On 2010/12/15 15:24:01, dhollowa wrote:
my bad, I
vivianz
2010/12/15 23:31:37
On 2010/12/15 15:24:01, dhollowa wrote:
my bad, I
|
| + FormStructureBrowserTest::FormStructuresToString(forms)); |
| + |
| + } else { |
| + ASSERT_TRUE(WriteFile(output_file_path, |
| + FormStructureBrowserTest::FormStructuresToString(forms))); |
|
Ilya Sherman
2010/12/15 10:58:32
nit: Arguments to a function should be aligned. I
vivianz
2010/12/15 23:31:37
On 2010/12/15 10:58:32, Ilya Sherman wrote:
Done.
|
| + } |
| + } |
| } |