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,59 @@ |
| #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" |
| +namespace { |
| + |
| +FilePath GetInputFileDirectory() { |
| + 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"); |
|
Ilya Sherman
2010/12/16 00:24:03
nit: this line is still indented two extra spaces
vivianz
2010/12/16 02:00:14
On 2010/12/16 00:24:03, Ilya Sherman wrote:
Done.
|
| + return test_data_dir_; |
| +} |
| + |
| +// Write |content| to |file|. Returns true on success. |
| +bool WriteFile(const FilePath& file, const std::string& content) { |
| + int write_size = file_util::WriteFile(file, content.c_str(), |
| + content.length()); |
|
Ilya Sherman
2010/12/16 00:24:03
nit: this line is still indented two extra spaces
vivianz
2010/12/16 02:00:14
On 2010/12/16 00:24:03, Ilya Sherman wrote:
Done.
|
| + return write_size == static_cast<int>(content.length()); |
| +} |
| + |
| +// Convert |html| to URL format, and return the converted string. |
| +const std::string ConvertToURLFormat(const std::string& html) { |
| + return std::string("data:text/html;charset=utf-8,") + html; |
| +} |
| + |
| +} // namespace |
| + |
| // 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. |
| +// heuristics. A test inputs each form file(e.g. form_[language_code].html), |
| +// loads its HTMLcontent 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 result file. |
| class FormStructureBrowserTest : public InProcessBrowserTest { |
| public: |
| FormStructureBrowserTest() {} |
| @@ -51,8 +90,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(); |
| @@ -62,7 +99,7 @@ |
| if (!*field_iter) |
| break; |
| forms_string += AutoFillFieldTypeToString((*field_iter)->type()); |
| - forms_string += "\n"; |
| + forms_string += " "; |
|
GeorgeY
2010/12/16 00:46:42
Isn't it easier to do
svn pset svn:eol-style LF ch
dhollowa
2010/12/16 01:10:22
Yes, this should return to "\n". And we should ad
vivianz
2010/12/16 02:00:14
On 2010/12/16 00:46:42, GeorgeY wrote:
ok, sounds
vivianz
2010/12/16 02:00:14
On 2010/12/16 01:10:22, dhollowa wrote:
let's try
dhollowa
2010/12/16 16:35:53
Looks like the svn props didn't work. I'm still s
|
| } |
| } |
| return forms_string; |
| @@ -162,55 +199,52 @@ |
| 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, FILE_PATH_LITERAL("*.html")); |
| + |
| + 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)))); |
| - 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)); |
| + ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), |
| + VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
|
Ilya Sherman
2010/12/16 00:24:03
nit: please either indent VIEW_ID_TAB... to align
vivianz
2010/12/16 02:00:14
On 2010/12/16 00:24:03, Ilya Sherman wrote:
Done.
|
| - 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"))); |
| + |
| + std::string output_file_source; |
| + if (file_util::ReadFileToString(output_file_path, &output_file_source)) { |
| + EXPECT_EQ(output_file_source, |
|
dhollowa
2010/12/16 01:10:22
This will change to:
EXPECT_TRUE(CompareText(..
|
| + FormStructureBrowserTest::FormStructuresToString(forms)); |
| + |
| + } else { |
| + ASSERT_TRUE(WriteFile( |
| + output_file_path, |
| + FormStructureBrowserTest::FormStructuresToString(forms))); |
| + } |
| + } |
| } |